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/gtkiconviewaccessibleprivate.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,
114 PROP_ACTIVATE_ON_SINGLE_CLICK
118 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
119 static void gtk_icon_view_dispose (GObject *object);
120 static GObject *gtk_icon_view_constructor (GType type,
121 guint n_construct_properties,
122 GObjectConstructParam *construct_properties);
123 static void gtk_icon_view_set_property (GObject *object,
127 static void gtk_icon_view_get_property (GObject *object,
131 /* GtkWidget vfuncs */
132 static void gtk_icon_view_destroy (GtkWidget *widget);
133 static void gtk_icon_view_realize (GtkWidget *widget);
134 static void gtk_icon_view_unrealize (GtkWidget *widget);
135 static void gtk_icon_view_style_updated (GtkWidget *widget);
136 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
137 GtkStateFlags previous_state);
138 static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
139 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
142 static void gtk_icon_view_get_preferred_width_for_height
147 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
150 static void gtk_icon_view_get_preferred_height_for_width
155 static void gtk_icon_view_size_allocate (GtkWidget *widget,
156 GtkAllocation *allocation);
157 static gboolean gtk_icon_view_draw (GtkWidget *widget,
159 static gboolean gtk_icon_view_motion (GtkWidget *widget,
160 GdkEventMotion *event);
161 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
162 GdkEventButton *event);
163 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
164 GdkEventButton *event);
165 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
167 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
171 /* GtkContainer vfuncs */
172 static void gtk_icon_view_remove (GtkContainer *container,
174 static void gtk_icon_view_forall (GtkContainer *container,
175 gboolean include_internals,
176 GtkCallback callback,
177 gpointer callback_data);
179 /* GtkIconView vfuncs */
180 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
181 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
182 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
183 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
184 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
186 /* Internal functions */
187 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
188 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
189 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
190 GtkAdjustment *adjustment);
191 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
192 GtkAdjustment *adjustment);
193 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
194 GtkIconView *icon_view);
195 static void gtk_icon_view_layout (GtkIconView *icon_view);
196 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
198 GtkIconViewItem *item,
201 gboolean draw_focus);
202 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
204 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
206 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
207 GtkIconViewItem *item);
208 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
212 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
213 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
214 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
215 GtkIconViewItem *item,
220 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
221 static void gtk_icon_view_update_rubberband (gpointer data);
222 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
223 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
224 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
227 GtkMovementStep step,
229 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
230 GtkMovementStep step,
232 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
234 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
236 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
238 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
240 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
241 GtkIconViewItem *item);
242 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
243 GtkIconViewItem *anchor,
244 GtkIconViewItem *cursor);
246 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
247 GtkCellArea *cell_area);
249 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
251 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
252 GtkIconViewItem *item);
254 static void gtk_icon_view_add_editable (GtkCellArea *area,
255 GtkCellRenderer *renderer,
256 GtkCellEditable *editable,
257 GdkRectangle *cell_area,
259 GtkIconView *icon_view);
260 static void gtk_icon_view_remove_editable (GtkCellArea *area,
261 GtkCellRenderer *renderer,
262 GtkCellEditable *editable,
263 GtkIconView *icon_view);
264 static void update_text_cell (GtkIconView *icon_view);
265 static void update_pixbuf_cell (GtkIconView *icon_view);
267 /* Source side drag signals */
268 static void gtk_icon_view_drag_begin (GtkWidget *widget,
269 GdkDragContext *context);
270 static void gtk_icon_view_drag_end (GtkWidget *widget,
271 GdkDragContext *context);
272 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
273 GdkDragContext *context,
274 GtkSelectionData *selection_data,
277 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
278 GdkDragContext *context);
280 /* Target side drag signals */
281 static void gtk_icon_view_drag_leave (GtkWidget *widget,
282 GdkDragContext *context,
284 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
285 GdkDragContext *context,
289 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
290 GdkDragContext *context,
294 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
295 GdkDragContext *context,
298 GtkSelectionData *selection_data,
301 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
302 GdkEventMotion *event);
304 static void remove_scroll_timeout (GtkIconView *icon_view);
307 static GtkBuildableIface *parent_buildable_iface;
308 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
309 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
312 const gchar *tagname,
313 GMarkupParser *parser,
315 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
318 const gchar *tagname,
321 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
323 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
324 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
325 gtk_icon_view_cell_layout_init)
326 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
327 gtk_icon_view_buildable_init)
328 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
331 gtk_icon_view_class_init (GtkIconViewClass *klass)
333 GObjectClass *gobject_class;
334 GtkWidgetClass *widget_class;
335 GtkContainerClass *container_class;
336 GtkBindingSet *binding_set;
338 binding_set = gtk_binding_set_by_class (klass);
340 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
342 gobject_class = (GObjectClass *) klass;
343 widget_class = (GtkWidgetClass *) klass;
344 container_class = (GtkContainerClass *) klass;
346 gobject_class->constructor = gtk_icon_view_constructor;
347 gobject_class->dispose = gtk_icon_view_dispose;
348 gobject_class->set_property = gtk_icon_view_set_property;
349 gobject_class->get_property = gtk_icon_view_get_property;
351 widget_class->destroy = gtk_icon_view_destroy;
352 widget_class->realize = gtk_icon_view_realize;
353 widget_class->unrealize = gtk_icon_view_unrealize;
354 widget_class->style_updated = gtk_icon_view_style_updated;
355 widget_class->get_request_mode = gtk_icon_view_get_request_mode;
356 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
357 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
358 widget_class->get_preferred_width_for_height = gtk_icon_view_get_preferred_width_for_height;
359 widget_class->get_preferred_height_for_width = gtk_icon_view_get_preferred_height_for_width;
360 widget_class->size_allocate = gtk_icon_view_size_allocate;
361 widget_class->draw = gtk_icon_view_draw;
362 widget_class->motion_notify_event = gtk_icon_view_motion;
363 widget_class->button_press_event = gtk_icon_view_button_press;
364 widget_class->button_release_event = gtk_icon_view_button_release;
365 widget_class->key_press_event = gtk_icon_view_key_press;
366 widget_class->key_release_event = gtk_icon_view_key_release;
367 widget_class->drag_begin = gtk_icon_view_drag_begin;
368 widget_class->drag_end = gtk_icon_view_drag_end;
369 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
370 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
371 widget_class->drag_leave = gtk_icon_view_drag_leave;
372 widget_class->drag_motion = gtk_icon_view_drag_motion;
373 widget_class->drag_drop = gtk_icon_view_drag_drop;
374 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
375 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
377 container_class->remove = gtk_icon_view_remove;
378 container_class->forall = gtk_icon_view_forall;
380 klass->select_all = gtk_icon_view_real_select_all;
381 klass->unselect_all = gtk_icon_view_real_unselect_all;
382 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
383 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
384 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
385 klass->move_cursor = gtk_icon_view_real_move_cursor;
389 * GtkIconView:selection-mode:
391 * The ::selection-mode property specifies the selection mode of
392 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
393 * is enabled, for the other modes, only keyboard selection is possible.
397 g_object_class_install_property (gobject_class,
399 g_param_spec_enum ("selection-mode",
400 P_("Selection mode"),
401 P_("The selection mode"),
402 GTK_TYPE_SELECTION_MODE,
403 GTK_SELECTION_SINGLE,
404 GTK_PARAM_READWRITE));
407 * GtkIconView:pixbuf-column:
409 * The ::pixbuf-column property contains the number of the model column
410 * containing the pixbufs which are displayed. The pixbuf column must be
411 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
412 * display of pixbufs.
416 g_object_class_install_property (gobject_class,
418 g_param_spec_int ("pixbuf-column",
420 P_("Model column used to retrieve the icon pixbuf from"),
422 GTK_PARAM_READWRITE));
425 * GtkIconView:text-column:
427 * The ::text-column property contains the number of the model column
428 * containing the texts which are displayed. The text column must be
429 * of type #G_TYPE_STRING. If this property and the :markup-column
430 * property are both set to -1, no texts are displayed.
434 g_object_class_install_property (gobject_class,
436 g_param_spec_int ("text-column",
438 P_("Model column used to retrieve the text from"),
440 GTK_PARAM_READWRITE));
444 * GtkIconView:markup-column:
446 * The ::markup-column property contains the number of the model column
447 * containing markup information to be displayed. The markup column must be
448 * of type #G_TYPE_STRING. If this property and the :text-column property
449 * are both set to column numbers, it overrides the text column.
450 * If both are set to -1, no texts are displayed.
454 g_object_class_install_property (gobject_class,
456 g_param_spec_int ("markup-column",
458 P_("Model column used to retrieve the text if using Pango markup"),
460 GTK_PARAM_READWRITE));
462 g_object_class_install_property (gobject_class,
464 g_param_spec_object ("model",
465 P_("Icon View Model"),
466 P_("The model for the icon view"),
468 GTK_PARAM_READWRITE));
471 * GtkIconView:columns:
473 * The columns property contains the number of the columns in which the
474 * items should be displayed. If it is -1, the number of columns will
475 * be chosen automatically to fill the available area.
479 g_object_class_install_property (gobject_class,
481 g_param_spec_int ("columns",
482 P_("Number of columns"),
483 P_("Number of columns to display"),
485 GTK_PARAM_READWRITE));
489 * GtkIconView:item-width:
491 * The item-width property specifies the width to use for each item.
492 * If it is set to -1, the icon view will automatically determine a
493 * suitable item size.
497 g_object_class_install_property (gobject_class,
499 g_param_spec_int ("item-width",
500 P_("Width for each item"),
501 P_("The width used for each item"),
503 GTK_PARAM_READWRITE));
506 * GtkIconView:spacing:
508 * The spacing property specifies the space which is inserted between
509 * the cells (i.e. the icon and the text) of an item.
513 g_object_class_install_property (gobject_class,
515 g_param_spec_int ("spacing",
517 P_("Space which is inserted between cells of an item"),
519 GTK_PARAM_READWRITE));
522 * GtkIconView:row-spacing:
524 * The row-spacing property specifies the space which is inserted between
525 * the rows of the icon view.
529 g_object_class_install_property (gobject_class,
531 g_param_spec_int ("row-spacing",
533 P_("Space which is inserted between grid rows"),
535 GTK_PARAM_READWRITE));
538 * GtkIconView:column-spacing:
540 * The column-spacing property specifies the space which is inserted between
541 * the columns of the icon view.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_int ("column-spacing",
548 P_("Column Spacing"),
549 P_("Space which is inserted between grid columns"),
551 GTK_PARAM_READWRITE));
554 * GtkIconView:margin:
556 * The margin property specifies the space which is inserted
557 * at the edges of the icon view.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_int ("margin",
565 P_("Space which is inserted at the edges of the icon view"),
567 GTK_PARAM_READWRITE));
570 * GtkIconView:item-orientation:
572 * The item-orientation property specifies how the cells (i.e. the icon and
573 * the text) of the item are positioned relative to each other.
577 g_object_class_install_property (gobject_class,
578 PROP_ITEM_ORIENTATION,
579 g_param_spec_enum ("item-orientation",
580 P_("Item Orientation"),
581 P_("How the text and icon of each item are positioned relative to each other"),
582 GTK_TYPE_ORIENTATION,
583 GTK_ORIENTATION_VERTICAL,
584 GTK_PARAM_READWRITE));
587 * GtkIconView:reorderable:
589 * The reorderable property specifies if the items can be reordered
594 g_object_class_install_property (gobject_class,
596 g_param_spec_boolean ("reorderable",
598 P_("View is reorderable"),
602 g_object_class_install_property (gobject_class,
604 g_param_spec_int ("tooltip-column",
605 P_("Tooltip Column"),
606 P_("The column in the model containing the tooltip texts for the items"),
610 GTK_PARAM_READWRITE));
613 * GtkIconView:item-padding:
615 * The item-padding property specifies the padding around each
616 * of the icon view's item.
620 g_object_class_install_property (gobject_class,
622 g_param_spec_int ("item-padding",
624 P_("Padding around icon view items"),
626 GTK_PARAM_READWRITE));
629 * GtkIconView:cell-area:
631 * The #GtkCellArea used to layout cell renderers for this view.
633 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
634 * a #GtkCellAreaBox will be used.
638 g_object_class_install_property (gobject_class,
640 g_param_spec_object ("cell-area",
642 P_("The GtkCellArea used to layout cells"),
644 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
647 * GtkIconView:activate-on-single-click:
649 * The activate-on-single-click property specifies whether the "item-activated" signal
650 * will be emitted after a single click.
654 g_object_class_install_property (gobject_class,
655 PROP_ACTIVATE_ON_SINGLE_CLICK,
656 g_param_spec_boolean ("activate-on-single-click",
657 P_("Activate on Single Click"),
658 P_("Activate row on a single click"),
660 GTK_PARAM_READWRITE));
662 /* Scrollable interface properties */
663 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
664 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
665 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
666 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
668 /* Style properties */
669 gtk_widget_class_install_style_property (widget_class,
670 g_param_spec_boxed ("selection-box-color",
671 P_("Selection Box Color"),
672 P_("Color of the selection box"),
674 GTK_PARAM_READABLE));
676 gtk_widget_class_install_style_property (widget_class,
677 g_param_spec_uchar ("selection-box-alpha",
678 P_("Selection Box Alpha"),
679 P_("Opacity of the selection box"),
682 GTK_PARAM_READABLE));
686 * GtkIconView::item-activated:
687 * @iconview: the object on which the signal is emitted
688 * @path: the #GtkTreePath for the activated item
690 * The ::item-activated signal is emitted when the method
691 * gtk_icon_view_item_activated() is called, when the user double
692 * clicks an item with the "activate-on-single-click" property set
693 * to %FALSE, or when the user single clicks an item when the
694 * "activate-on-single-click" property set to %TRUE. It is also
695 * emitted when a non-editable item is selected and one of the keys:
696 * Space, Return or Enter is pressed.
698 icon_view_signals[ITEM_ACTIVATED] =
699 g_signal_new (I_("item-activated"),
700 G_TYPE_FROM_CLASS (gobject_class),
702 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
704 g_cclosure_marshal_VOID__BOXED,
709 * GtkIconView::selection-changed:
710 * @iconview: the object on which the signal is emitted
712 * The ::selection-changed signal is emitted when the selection
713 * (i.e. the set of selected items) changes.
715 icon_view_signals[SELECTION_CHANGED] =
716 g_signal_new (I_("selection-changed"),
717 G_TYPE_FROM_CLASS (gobject_class),
719 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
721 g_cclosure_marshal_VOID__VOID,
725 * GtkIconView::select-all:
726 * @iconview: the object on which the signal is emitted
728 * A <link linkend="keybinding-signals">keybinding signal</link>
729 * which gets emitted when the user selects all items.
731 * Applications should not connect to it, but may emit it with
732 * g_signal_emit_by_name() if they need to control selection
735 * The default binding for this signal is Ctrl-a.
737 icon_view_signals[SELECT_ALL] =
738 g_signal_new (I_("select-all"),
739 G_TYPE_FROM_CLASS (gobject_class),
740 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
741 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
743 g_cclosure_marshal_VOID__VOID,
747 * GtkIconView::unselect-all:
748 * @iconview: the object on which the signal is emitted
750 * A <link linkend="keybinding-signals">keybinding signal</link>
751 * which gets emitted when the user unselects all items.
753 * Applications should not connect to it, but may emit it with
754 * g_signal_emit_by_name() if they need to control selection
757 * The default binding for this signal is Ctrl-Shift-a.
759 icon_view_signals[UNSELECT_ALL] =
760 g_signal_new (I_("unselect-all"),
761 G_TYPE_FROM_CLASS (gobject_class),
762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
763 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
765 g_cclosure_marshal_VOID__VOID,
769 * GtkIconView::select-cursor-item:
770 * @iconview: the object on which the signal is emitted
772 * A <link linkend="keybinding-signals">keybinding signal</link>
773 * which gets emitted when the user selects the item that is currently
776 * Applications should not connect to it, but may emit it with
777 * g_signal_emit_by_name() if they need to control selection
780 * There is no default binding for this signal.
782 icon_view_signals[SELECT_CURSOR_ITEM] =
783 g_signal_new (I_("select-cursor-item"),
784 G_TYPE_FROM_CLASS (gobject_class),
785 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
786 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
788 g_cclosure_marshal_VOID__VOID,
792 * GtkIconView::toggle-cursor-item:
793 * @iconview: the object on which the signal is emitted
795 * A <link linkend="keybinding-signals">keybinding signal</link>
796 * which gets emitted when the user toggles whether the currently
797 * focused item is selected or not. The exact effect of this
798 * depend on the selection mode.
800 * Applications should not connect to it, but may emit it with
801 * g_signal_emit_by_name() if they need to control selection
804 * There is no default binding for this signal is Ctrl-Space.
806 icon_view_signals[TOGGLE_CURSOR_ITEM] =
807 g_signal_new (I_("toggle-cursor-item"),
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
812 g_cclosure_marshal_VOID__VOID,
816 * GtkIconView::activate-cursor-item:
817 * @iconview: the object on which the signal is emitted
819 * A <link linkend="keybinding-signals">keybinding signal</link>
820 * which gets emitted when the user activates the currently
823 * Applications should not connect to it, but may emit it with
824 * g_signal_emit_by_name() if they need to control activation
827 * The default bindings for this signal are Space, Return and Enter.
829 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
830 g_signal_new (I_("activate-cursor-item"),
831 G_TYPE_FROM_CLASS (gobject_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
835 _gtk_marshal_BOOLEAN__VOID,
839 * GtkIconView::move-cursor:
840 * @iconview: the object which received the signal
841 * @step: the granularity of the move, as a #GtkMovementStep
842 * @count: the number of @step units to move
844 * The ::move-cursor signal is a
845 * <link linkend="keybinding-signals">keybinding signal</link>
846 * which gets emitted when the user initiates a cursor movement.
848 * Applications should not connect to it, but may emit it with
849 * g_signal_emit_by_name() if they need to control the cursor
852 * The default bindings for this signal include
854 * <listitem>Arrow keys which move by individual steps</listitem>
855 * <listitem>Home/End keys which move to the first/last item</listitem>
856 * <listitem>PageUp/PageDown which move by "pages"</listitem>
859 * All of these will extend the selection when combined with
860 * the Shift modifier.
862 icon_view_signals[MOVE_CURSOR] =
863 g_signal_new (I_("move-cursor"),
864 G_TYPE_FROM_CLASS (gobject_class),
865 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
866 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
868 _gtk_marshal_BOOLEAN__ENUM_INT,
870 GTK_TYPE_MOVEMENT_STEP,
874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
876 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
878 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
879 "toggle-cursor-item", 0);
880 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
881 "toggle-cursor-item", 0);
883 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
884 "activate-cursor-item", 0);
885 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
886 "activate-cursor-item", 0);
887 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
888 "activate-cursor-item", 0);
889 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
890 "activate-cursor-item", 0);
891 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
892 "activate-cursor-item", 0);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
895 GTK_MOVEMENT_DISPLAY_LINES, -1);
896 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
897 GTK_MOVEMENT_DISPLAY_LINES, -1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
900 GTK_MOVEMENT_DISPLAY_LINES, 1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
902 GTK_MOVEMENT_DISPLAY_LINES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
905 GTK_MOVEMENT_DISPLAY_LINES, -1);
907 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
908 GTK_MOVEMENT_DISPLAY_LINES, 1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
911 GTK_MOVEMENT_BUFFER_ENDS, -1);
912 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
913 GTK_MOVEMENT_BUFFER_ENDS, -1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
916 GTK_MOVEMENT_BUFFER_ENDS, 1);
917 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
918 GTK_MOVEMENT_BUFFER_ENDS, 1);
920 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
921 GTK_MOVEMENT_PAGES, -1);
922 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
923 GTK_MOVEMENT_PAGES, -1);
925 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
926 GTK_MOVEMENT_PAGES, 1);
927 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
928 GTK_MOVEMENT_PAGES, 1);
930 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
931 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
932 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
933 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
935 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
936 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
937 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
938 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
940 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
944 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
946 parent_buildable_iface = g_type_interface_peek_parent (iface);
947 iface->add_child = _gtk_cell_layout_buildable_add_child;
948 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
949 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
953 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
955 iface->get_area = gtk_icon_view_cell_layout_get_area;
959 gtk_icon_view_init (GtkIconView *icon_view)
961 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
965 icon_view->priv->width = 0;
966 icon_view->priv->height = 0;
967 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
968 icon_view->priv->pressed_button = -1;
969 icon_view->priv->press_start_x = -1;
970 icon_view->priv->press_start_y = -1;
971 icon_view->priv->text_column = -1;
972 icon_view->priv->markup_column = -1;
973 icon_view->priv->pixbuf_column = -1;
974 icon_view->priv->text_cell = NULL;
975 icon_view->priv->pixbuf_cell = NULL;
976 icon_view->priv->tooltip_column = -1;
978 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
980 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
982 icon_view->priv->columns = -1;
983 icon_view->priv->item_width = -1;
984 icon_view->priv->spacing = 0;
985 icon_view->priv->row_spacing = 6;
986 icon_view->priv->column_spacing = 6;
987 icon_view->priv->margin = 6;
988 icon_view->priv->item_padding = 6;
989 icon_view->priv->activate_on_single_click = FALSE;
991 icon_view->priv->draw_focus = TRUE;
993 icon_view->priv->row_contexts =
994 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
996 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (icon_view)),
997 GTK_STYLE_CLASS_VIEW);
1000 /* GObject methods */
1002 gtk_icon_view_constructor (GType type,
1003 guint n_construct_properties,
1004 GObjectConstructParam *construct_properties)
1006 GtkIconView *icon_view;
1009 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1010 (type, n_construct_properties, construct_properties);
1012 icon_view = (GtkIconView *) object;
1014 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1020 gtk_icon_view_dispose (GObject *object)
1022 GtkIconView *icon_view;
1023 GtkIconViewPrivate *priv;
1025 icon_view = GTK_ICON_VIEW (object);
1026 priv = icon_view->priv;
1028 if (priv->cell_area_context)
1030 g_object_unref (priv->cell_area_context);
1031 priv->cell_area_context = NULL;
1034 if (priv->row_contexts)
1036 g_ptr_array_free (priv->row_contexts, TRUE);
1037 priv->row_contexts = NULL;
1040 if (priv->cell_area)
1042 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1044 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1045 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1046 priv->add_editable_id = 0;
1047 priv->remove_editable_id = 0;
1049 g_object_unref (priv->cell_area);
1050 priv->cell_area = NULL;
1053 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1057 gtk_icon_view_set_property (GObject *object,
1059 const GValue *value,
1062 GtkIconView *icon_view;
1065 icon_view = GTK_ICON_VIEW (object);
1069 case PROP_SELECTION_MODE:
1070 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1072 case PROP_PIXBUF_COLUMN:
1073 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1075 case PROP_TEXT_COLUMN:
1076 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1078 case PROP_MARKUP_COLUMN:
1079 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1082 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1084 case PROP_ITEM_ORIENTATION:
1085 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1088 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1090 case PROP_ITEM_WIDTH:
1091 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1094 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1096 case PROP_ROW_SPACING:
1097 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1099 case PROP_COLUMN_SPACING:
1100 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1103 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1105 case PROP_REORDERABLE:
1106 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1109 case PROP_TOOLTIP_COLUMN:
1110 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1113 case PROP_ITEM_PADDING:
1114 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1117 case PROP_ACTIVATE_ON_SINGLE_CLICK:
1118 gtk_icon_view_set_activate_on_single_click (icon_view, g_value_get_boolean (value));
1121 case PROP_CELL_AREA:
1122 /* Construct-only, can only be assigned once */
1123 area = g_value_get_object (value);
1126 if (icon_view->priv->cell_area != NULL)
1128 g_warning ("cell-area has already been set, ignoring construct property");
1129 g_object_ref_sink (area);
1130 g_object_unref (area);
1133 gtk_icon_view_ensure_cell_area (icon_view, area);
1137 case PROP_HADJUSTMENT:
1138 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1140 case PROP_VADJUSTMENT:
1141 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1143 case PROP_HSCROLL_POLICY:
1144 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1145 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1147 case PROP_VSCROLL_POLICY:
1148 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1149 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1159 gtk_icon_view_get_property (GObject *object,
1164 GtkIconView *icon_view;
1166 icon_view = GTK_ICON_VIEW (object);
1170 case PROP_SELECTION_MODE:
1171 g_value_set_enum (value, icon_view->priv->selection_mode);
1173 case PROP_PIXBUF_COLUMN:
1174 g_value_set_int (value, icon_view->priv->pixbuf_column);
1176 case PROP_TEXT_COLUMN:
1177 g_value_set_int (value, icon_view->priv->text_column);
1179 case PROP_MARKUP_COLUMN:
1180 g_value_set_int (value, icon_view->priv->markup_column);
1183 g_value_set_object (value, icon_view->priv->model);
1185 case PROP_ITEM_ORIENTATION:
1186 g_value_set_enum (value, icon_view->priv->item_orientation);
1189 g_value_set_int (value, icon_view->priv->columns);
1191 case PROP_ITEM_WIDTH:
1192 g_value_set_int (value, icon_view->priv->item_width);
1195 g_value_set_int (value, icon_view->priv->spacing);
1197 case PROP_ROW_SPACING:
1198 g_value_set_int (value, icon_view->priv->row_spacing);
1200 case PROP_COLUMN_SPACING:
1201 g_value_set_int (value, icon_view->priv->column_spacing);
1204 g_value_set_int (value, icon_view->priv->margin);
1206 case PROP_REORDERABLE:
1207 g_value_set_boolean (value, icon_view->priv->reorderable);
1209 case PROP_TOOLTIP_COLUMN:
1210 g_value_set_int (value, icon_view->priv->tooltip_column);
1213 case PROP_ITEM_PADDING:
1214 g_value_set_int (value, icon_view->priv->item_padding);
1217 case PROP_ACTIVATE_ON_SINGLE_CLICK:
1218 g_value_set_boolean (value, icon_view->priv->activate_on_single_click);
1221 case PROP_CELL_AREA:
1222 g_value_set_object (value, icon_view->priv->cell_area);
1225 case PROP_HADJUSTMENT:
1226 g_value_set_object (value, icon_view->priv->hadjustment);
1228 case PROP_VADJUSTMENT:
1229 g_value_set_object (value, icon_view->priv->vadjustment);
1231 case PROP_HSCROLL_POLICY:
1232 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1234 case PROP_VSCROLL_POLICY:
1235 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1244 /* GtkWidget methods */
1246 gtk_icon_view_destroy (GtkWidget *widget)
1248 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1250 gtk_icon_view_set_model (icon_view, NULL);
1252 if (icon_view->priv->scroll_to_path != NULL)
1254 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1255 icon_view->priv->scroll_to_path = NULL;
1258 remove_scroll_timeout (icon_view);
1260 if (icon_view->priv->hadjustment != NULL)
1262 g_object_unref (icon_view->priv->hadjustment);
1263 icon_view->priv->hadjustment = NULL;
1266 if (icon_view->priv->vadjustment != NULL)
1268 g_object_unref (icon_view->priv->vadjustment);
1269 icon_view->priv->vadjustment = NULL;
1272 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1276 gtk_icon_view_realize (GtkWidget *widget)
1278 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1279 GtkAllocation allocation;
1281 GdkWindowAttr attributes;
1282 gint attributes_mask;
1283 GtkStyleContext *context;
1285 gtk_widget_set_realized (widget, TRUE);
1287 gtk_widget_get_allocation (widget, &allocation);
1289 /* Make the main, clipping window */
1290 attributes.window_type = GDK_WINDOW_CHILD;
1291 attributes.x = allocation.x;
1292 attributes.y = allocation.y;
1293 attributes.width = allocation.width;
1294 attributes.height = allocation.height;
1295 attributes.wclass = GDK_INPUT_OUTPUT;
1296 attributes.visual = gtk_widget_get_visual (widget);
1297 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1299 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1301 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1302 &attributes, attributes_mask);
1303 gtk_widget_set_window (widget, window);
1304 gtk_widget_register_window (widget, window);
1306 gtk_widget_get_allocation (widget, &allocation);
1308 /* Make the window for the icon view */
1311 attributes.width = MAX (icon_view->priv->width, allocation.width);
1312 attributes.height = MAX (icon_view->priv->height, allocation.height);
1313 attributes.event_mask = (GDK_EXPOSURE_MASK |
1315 GDK_SMOOTH_SCROLL_MASK |
1316 GDK_POINTER_MOTION_MASK |
1317 GDK_BUTTON_PRESS_MASK |
1318 GDK_BUTTON_RELEASE_MASK |
1319 GDK_KEY_PRESS_MASK |
1320 GDK_KEY_RELEASE_MASK) |
1321 gtk_widget_get_events (widget);
1323 icon_view->priv->bin_window = gdk_window_new (window,
1324 &attributes, attributes_mask);
1325 gtk_widget_register_window (widget, icon_view->priv->bin_window);
1327 context = gtk_widget_get_style_context (widget);
1328 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1329 gtk_style_context_set_background (context, window);
1331 gdk_window_show (icon_view->priv->bin_window);
1335 gtk_icon_view_unrealize (GtkWidget *widget)
1337 GtkIconView *icon_view;
1339 icon_view = GTK_ICON_VIEW (widget);
1341 gtk_widget_unregister_window (widget, icon_view->priv->bin_window);
1342 gdk_window_destroy (icon_view->priv->bin_window);
1343 icon_view->priv->bin_window = NULL;
1345 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1349 _gtk_icon_view_update_background (GtkIconView *icon_view)
1351 GtkWidget *widget = GTK_WIDGET (icon_view);
1353 if (gtk_widget_get_realized (widget))
1355 GtkStyleContext *context;
1357 context = gtk_widget_get_style_context (widget);
1358 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1359 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1364 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1365 GtkStateFlags previous_state)
1367 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1368 gtk_widget_queue_draw (widget);
1372 gtk_icon_view_style_updated (GtkWidget *widget)
1374 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1376 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1377 gtk_widget_queue_resize (widget);
1381 gtk_icon_view_get_n_items (GtkIconView *icon_view)
1383 GtkIconViewPrivate *priv = icon_view->priv;
1385 if (priv->model == NULL)
1388 return gtk_tree_model_iter_n_children (priv->model, NULL);
1392 adjust_wrap_width (GtkIconView *icon_view)
1394 if (icon_view->priv->text_cell)
1396 gint wrap_width = 50;
1398 /* Here we go with the same old guess, try the icon size and set double
1399 * the size of the first icon found in the list, naive but works much
1401 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
1403 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
1404 GTK_WIDGET (icon_view),
1407 wrap_width = MAX (wrap_width * 2, 50);
1410 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
1411 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
1415 /* General notes about layout
1417 * The icon view is layouted like this:
1419 * +----------+ s +----------+
1420 * | padding | p | padding |
1421 * | +------+ | a | +------+ |
1422 * | | cell | | c | | cell | |
1423 * | +------+ | i | +------+ |
1425 * +----------+ g +----------+
1427 * In size request and allocation code, there are 3 sizes that are used:
1429 * This is the size returned by gtk_cell_area_get_preferred_foo(). In places
1430 * where code is interacting with the cell area and renderers this is useful.
1432 * This is the cell size plus the item padding on each side.
1434 * This is the padded size plus the spacing. This is what's used for most
1435 * calculations because it can (ab)use the following formula:
1436 * iconview_size = 2 * margin + n_items * spaced_size - spacing
1437 * So when reading this code and fixing my bugs where I confuse these two, be
1438 * aware of this distinction.
1441 cell_area_get_preferred_size (GtkIconView *icon_view,
1442 GtkCellAreaContext *context,
1443 GtkOrientation orientation,
1448 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1451 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1453 GTK_WIDGET (icon_view),
1457 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1459 GTK_WIDGET (icon_view),
1465 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1467 GTK_WIDGET (icon_view),
1471 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1473 GTK_WIDGET (icon_view),
1479 gtk_icon_view_is_empty (GtkIconView *icon_view)
1481 return icon_view->priv->items == NULL;
1485 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1486 GtkOrientation orientation,
1491 GtkIconViewPrivate *priv = icon_view->priv;
1492 GtkCellAreaContext *context;
1495 g_assert (!gtk_icon_view_is_empty (icon_view));
1497 context = gtk_cell_area_create_context (priv->cell_area);
1499 for_size -= 2 * priv->item_padding;
1503 /* This is necessary for the context to work properly */
1504 for (items = priv->items; items; items = items->next)
1506 GtkIconViewItem *item = items->data;
1508 _gtk_icon_view_set_cell_data (icon_view, item);
1509 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1513 for (items = priv->items; items; items = items->next)
1515 GtkIconViewItem *item = items->data;
1517 _gtk_icon_view_set_cell_data (icon_view, item);
1518 if (items == priv->items)
1519 adjust_wrap_width (icon_view);
1520 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1523 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1526 gtk_cell_area_context_get_preferred_width_for_height (context,
1530 gtk_cell_area_context_get_preferred_width (context,
1536 gtk_cell_area_context_get_preferred_height_for_width (context,
1540 gtk_cell_area_context_get_preferred_height (context,
1544 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1547 *minimum = MAX (*minimum, priv->item_width);
1549 *natural = *minimum;
1553 *minimum = MAX (1, *minimum + 2 * priv->item_padding);
1555 *natural = MAX (1, *natural + 2 * priv->item_padding);
1557 g_object_unref (context);
1561 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1562 GtkOrientation orientation,
1565 gint *min_item_size,
1567 gint *max_item_size)
1569 GtkIconViewPrivate *priv = icon_view->priv;
1570 int minimum, natural, spacing;
1572 g_return_if_fail (min_item_size == NULL || min_items != NULL);
1573 g_return_if_fail (max_item_size == NULL || max_items != NULL);
1574 g_return_if_fail (!gtk_icon_view_is_empty (icon_view));
1576 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1578 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1579 spacing = priv->column_spacing;
1581 spacing = priv->row_spacing;
1583 size -= 2 * priv->margin;
1588 if (priv->columns > 0)
1590 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1593 *min_items = priv->columns;
1595 *max_items = priv->columns;
1599 int n_items = gtk_icon_view_get_n_items (icon_view);
1602 *min_items = (n_items + priv->columns - 1) / priv->columns;
1604 *max_items = (n_items + priv->columns - 1) / priv->columns;
1611 if (size <= minimum)
1614 *max_items = size / minimum;
1619 if (size <= natural)
1622 *min_items = size / natural;
1628 *min_item_size = size / *min_items;
1629 *min_item_size = CLAMP (*min_item_size, minimum, natural);
1630 *min_item_size -= spacing;
1631 *min_item_size -= 2 * priv->item_padding;
1636 *max_item_size = size / *max_items;
1637 *max_item_size = CLAMP (*max_item_size, minimum, natural);
1638 *max_item_size -= spacing;
1639 *max_item_size -= 2 * priv->item_padding;
1643 static GtkSizeRequestMode
1644 gtk_icon_view_get_request_mode (GtkWidget *widget)
1646 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1650 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1654 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1655 GtkIconViewPrivate *priv = icon_view->priv;
1656 int item_min, item_nat;
1658 if (gtk_icon_view_is_empty (icon_view))
1660 *minimum = *natural = 2 * priv->margin;
1664 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1666 if (priv->columns > 0)
1668 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1669 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1673 int n_items = gtk_icon_view_get_n_items (icon_view);
1675 *minimum = item_min;
1676 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1679 *minimum += 2 * priv->margin;
1680 *natural += 2 * priv->margin;
1684 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1689 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1690 GtkIconViewPrivate *priv = icon_view->priv;
1691 int item_min, item_nat, rows, row_height, n_items;
1693 if (gtk_icon_view_is_empty (icon_view))
1695 *minimum = *natural = 2 * priv->margin;
1699 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, &row_height, NULL, NULL);
1700 n_items = gtk_icon_view_get_n_items (icon_view);
1702 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, row_height, &item_min, &item_nat);
1703 *minimum = (item_min + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1704 *natural = (item_nat + priv->column_spacing) * ((n_items + rows - 1) / rows) - priv->column_spacing;
1706 *minimum += 2 * priv->margin;
1707 *natural += 2 * priv->margin;
1711 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1715 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1716 GtkIconViewPrivate *priv = icon_view->priv;
1717 int item_min, item_nat, n_items;
1719 if (gtk_icon_view_is_empty (icon_view))
1721 *minimum = *natural = 2 * priv->margin;
1725 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1726 n_items = gtk_icon_view_get_n_items (icon_view);
1728 if (priv->columns > 0)
1730 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1732 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1733 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1737 *minimum = item_min;
1738 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1741 *minimum += 2 * priv->margin;
1742 *natural += 2 * priv->margin;
1746 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1751 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1752 GtkIconViewPrivate *priv = icon_view->priv;
1753 int item_min, item_nat, columns, column_width, n_items;
1755 if (gtk_icon_view_is_empty (icon_view))
1757 *minimum = *natural = 2 * priv->margin;
1761 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, NULL, &columns, &column_width);
1762 n_items = gtk_icon_view_get_n_items (icon_view);
1764 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, column_width, &item_min, &item_nat);
1765 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1766 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1768 *minimum += 2 * priv->margin;
1769 *natural += 2 * priv->margin;
1773 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1777 for (list = icon_view->priv->children; list; list = list->next)
1779 GtkIconViewChild *child = list->data;
1781 /* totally ignore our child's requisition */
1782 gtk_widget_size_allocate (child->widget, &child->area);
1787 gtk_icon_view_size_allocate (GtkWidget *widget,
1788 GtkAllocation *allocation)
1790 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1792 gtk_widget_set_allocation (widget, allocation);
1794 gtk_icon_view_layout (icon_view);
1796 if (gtk_widget_get_realized (widget))
1798 gdk_window_move_resize (gtk_widget_get_window (widget),
1799 allocation->x, allocation->y,
1800 allocation->width, allocation->height);
1801 gdk_window_resize (icon_view->priv->bin_window,
1802 MAX (icon_view->priv->width, allocation->width),
1803 MAX (icon_view->priv->height, allocation->height));
1806 gtk_icon_view_allocate_children (icon_view);
1808 /* Delay signal emission */
1809 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1810 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1812 gtk_icon_view_set_hadjustment_values (icon_view);
1813 gtk_icon_view_set_vadjustment_values (icon_view);
1815 if (gtk_widget_get_realized (widget) &&
1816 icon_view->priv->scroll_to_path)
1819 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1820 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1821 icon_view->priv->scroll_to_path = NULL;
1823 gtk_icon_view_scroll_to_path (icon_view, path,
1824 icon_view->priv->scroll_to_use_align,
1825 icon_view->priv->scroll_to_row_align,
1826 icon_view->priv->scroll_to_col_align);
1827 gtk_tree_path_free (path);
1830 /* Emit any pending signals now */
1831 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1832 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1836 gtk_icon_view_draw (GtkWidget *widget,
1839 GtkIconView *icon_view;
1843 GtkIconViewDropPosition dest_pos;
1844 GtkIconViewItem *dest_item = NULL;
1845 GtkStyleContext *context;
1847 icon_view = GTK_ICON_VIEW (widget);
1849 context = gtk_widget_get_style_context (widget);
1850 gtk_render_background (context, cr,
1852 gtk_widget_get_allocated_width (widget),
1853 gtk_widget_get_allocated_height (widget));
1855 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1860 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1862 cairo_set_line_width (cr, 1.);
1864 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1868 dest_index = gtk_tree_path_get_indices (path)[0];
1869 gtk_tree_path_free (path);
1874 for (icons = icon_view->priv->items; icons; icons = icons->next)
1876 GtkIconViewItem *item = icons->data;
1877 GdkRectangle paint_area;
1879 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1880 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1881 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1882 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1886 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1889 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1891 gtk_icon_view_paint_item (icon_view, cr, item,
1892 item->cell_area.x, item->cell_area.y,
1893 icon_view->priv->draw_focus);
1895 if (dest_index == item->index)
1903 dest_pos != GTK_ICON_VIEW_NO_DROP)
1905 GtkStyleContext *context;
1906 GdkRectangle rect = { 0 };
1908 context = gtk_widget_get_style_context (widget);
1912 case GTK_ICON_VIEW_DROP_INTO:
1913 rect = dest_item->cell_area;
1915 case GTK_ICON_VIEW_DROP_ABOVE:
1916 rect.x = dest_item->cell_area.x;
1917 rect.y = dest_item->cell_area.y - 1;
1918 rect.width = dest_item->cell_area.width;
1921 case GTK_ICON_VIEW_DROP_LEFT:
1922 rect.x = dest_item->cell_area.x - 1;
1923 rect.y = dest_item->cell_area.y;
1925 rect.height = dest_item->cell_area.height;
1927 case GTK_ICON_VIEW_DROP_BELOW:
1928 rect.x = dest_item->cell_area.x;
1929 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1930 rect.width = dest_item->cell_area.width;
1933 case GTK_ICON_VIEW_DROP_RIGHT:
1934 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1935 rect.y = dest_item->cell_area.y;
1937 rect.height = dest_item->cell_area.height;
1938 case GTK_ICON_VIEW_NO_DROP: ;
1942 gtk_render_focus (context, cr,
1944 rect.width, rect.height);
1947 if (icon_view->priv->doing_rubberband)
1948 gtk_icon_view_paint_rubberband (icon_view, cr);
1952 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1956 rubberband_scroll_timeout (gpointer data)
1958 GtkIconView *icon_view = data;
1960 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1961 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1962 icon_view->priv->scroll_value_diff);
1964 gtk_icon_view_update_rubberband (icon_view);
1970 gtk_icon_view_motion (GtkWidget *widget,
1971 GdkEventMotion *event)
1973 GtkAllocation allocation;
1974 GtkIconView *icon_view;
1977 icon_view = GTK_ICON_VIEW (widget);
1979 gtk_icon_view_maybe_begin_drag (icon_view, event);
1981 if (icon_view->priv->doing_rubberband)
1983 gtk_icon_view_update_rubberband (widget);
1985 abs_y = event->y - icon_view->priv->height *
1986 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1987 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1988 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1990 gtk_widget_get_allocation (widget, &allocation);
1992 if (abs_y < 0 || abs_y > allocation.height)
1995 icon_view->priv->scroll_value_diff = abs_y;
1997 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1999 icon_view->priv->event_last_x = event->x;
2000 icon_view->priv->event_last_y = event->y;
2002 if (icon_view->priv->scroll_timeout_id == 0)
2003 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
2007 remove_scroll_timeout (icon_view);
2011 GtkIconViewItem *item, *last_prelight_item;
2012 GtkCellRenderer *cell = NULL;
2014 last_prelight_item = icon_view->priv->last_prelight;
2015 item = _gtk_icon_view_get_item_at_coords (icon_view,
2022 item->prelight = TRUE;
2023 gtk_icon_view_queue_draw_item (icon_view, item);
2026 if (last_prelight_item != NULL &&
2027 last_prelight_item != item)
2029 last_prelight_item->prelight = FALSE;
2030 gtk_icon_view_queue_draw_item (icon_view,
2031 icon_view->priv->last_prelight);
2034 icon_view->priv->last_prelight = item;
2041 gtk_icon_view_remove (GtkContainer *container,
2044 GtkIconView *icon_view;
2045 GtkIconViewChild *child = NULL;
2048 icon_view = GTK_ICON_VIEW (container);
2050 tmp_list = icon_view->priv->children;
2053 child = tmp_list->data;
2054 if (child->widget == widget)
2056 gtk_widget_unparent (widget);
2058 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
2059 g_list_free_1 (tmp_list);
2064 tmp_list = tmp_list->next;
2069 gtk_icon_view_forall (GtkContainer *container,
2070 gboolean include_internals,
2071 GtkCallback callback,
2072 gpointer callback_data)
2074 GtkIconView *icon_view;
2075 GtkIconViewChild *child = NULL;
2078 icon_view = GTK_ICON_VIEW (container);
2080 tmp_list = icon_view->priv->children;
2083 child = tmp_list->data;
2084 tmp_list = tmp_list->next;
2086 (* callback) (child->widget, callback_data);
2091 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
2092 GtkIconViewItem *item)
2095 AtkObject *item_obj;
2097 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2100 item_obj = atk_object_ref_accessible_child (obj, item->index);
2101 if (item_obj != NULL)
2103 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
2104 g_object_unref (item_obj);
2110 gtk_icon_view_add_editable (GtkCellArea *area,
2111 GtkCellRenderer *renderer,
2112 GtkCellEditable *editable,
2113 GdkRectangle *cell_area,
2115 GtkIconView *icon_view)
2117 GtkIconViewChild *child;
2118 GtkWidget *widget = GTK_WIDGET (editable);
2120 child = g_new (GtkIconViewChild, 1);
2122 child->widget = widget;
2123 child->area.x = cell_area->x;
2124 child->area.y = cell_area->y;
2125 child->area.width = cell_area->width;
2126 child->area.height = cell_area->height;
2128 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
2130 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2131 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
2133 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2137 gtk_icon_view_remove_editable (GtkCellArea *area,
2138 GtkCellRenderer *renderer,
2139 GtkCellEditable *editable,
2140 GtkIconView *icon_view)
2144 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2145 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2147 gtk_container_remove (GTK_CONTAINER (icon_view),
2148 GTK_WIDGET (editable));
2150 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2151 gtk_icon_view_queue_draw_path (icon_view, path);
2152 gtk_tree_path_free (path);
2156 * gtk_icon_view_set_cursor:
2157 * @icon_view: A #GtkIconView
2158 * @path: A #GtkTreePath
2159 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2160 * @start_editing: %TRUE if the specified cell should start being edited.
2162 * Sets the current keyboard focus to be at @path, and selects it. This is
2163 * useful when you want to focus the user's attention on a particular item.
2164 * If @cell is not %NULL, then focus is given to the cell specified by
2165 * it. Additionally, if @start_editing is %TRUE, then editing should be
2166 * started in the specified cell.
2168 * This function is often followed by <literal>gtk_widget_grab_focus
2169 * (icon_view)</literal> in order to give keyboard focus to the widget.
2170 * Please note that editing can only happen when the widget is realized.
2175 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2177 GtkCellRenderer *cell,
2178 gboolean start_editing)
2180 GtkIconViewItem *item = NULL;
2182 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2183 g_return_if_fail (path != NULL);
2184 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2186 if (icon_view->priv->cell_area)
2187 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2189 if (gtk_tree_path_get_depth (path) == 1)
2190 item = g_list_nth_data (icon_view->priv->items,
2191 gtk_tree_path_get_indices(path)[0]);
2196 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2197 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2199 if (start_editing &&
2200 icon_view->priv->cell_area)
2202 GtkCellAreaContext *context;
2204 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2205 _gtk_icon_view_set_cell_data (icon_view, item);
2206 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2207 GTK_WIDGET (icon_view), &item->cell_area,
2208 0 /* XXX flags */, TRUE);
2213 * gtk_icon_view_get_cursor:
2214 * @icon_view: A #GtkIconView
2215 * @path: (out) (allow-none): Return location for the current cursor path,
2217 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2219 * Fills in @path and @cell with the current cursor path and cell.
2220 * If the cursor isn't currently set, then *@path will be %NULL.
2221 * If no cell currently has focus, then *@cell will be %NULL.
2223 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2225 * Return value: %TRUE if the cursor is set.
2230 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2232 GtkCellRenderer **cell)
2234 GtkIconViewItem *item;
2236 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2238 item = icon_view->priv->cursor_item;
2243 *path = gtk_tree_path_new_from_indices (item->index, -1);
2248 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2249 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2251 return (item != NULL);
2255 gtk_icon_view_button_press (GtkWidget *widget,
2256 GdkEventButton *event)
2258 GtkIconView *icon_view;
2259 GtkIconViewItem *item;
2260 gboolean dirty = FALSE;
2261 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2263 icon_view = GTK_ICON_VIEW (widget);
2265 if (event->window != icon_view->priv->bin_window)
2268 if (!gtk_widget_has_focus (widget))
2269 gtk_widget_grab_focus (widget);
2271 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2273 GdkModifierType extend_mod_mask;
2274 GdkModifierType modify_mod_mask;
2277 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2280 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2282 item = _gtk_icon_view_get_item_at_coords (icon_view,
2288 * We consider only the cells' area as the item area if the
2289 * item is not selected, but if it *is* selected, the complete
2290 * selection rectangle is considered to be part of the item.
2292 if (item != NULL && (cell != NULL || item->selected))
2296 if (gtk_cell_renderer_is_activatable (cell))
2300 gtk_icon_view_scroll_to_item (icon_view, item);
2302 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2304 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2306 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2307 (event->state & extend_mod_mask))
2309 gtk_icon_view_unselect_all_internal (icon_view);
2311 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2312 if (!icon_view->priv->anchor_item)
2313 icon_view->priv->anchor_item = item;
2315 gtk_icon_view_select_all_between (icon_view,
2316 icon_view->priv->anchor_item,
2322 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2323 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2324 (event->state & modify_mod_mask))
2326 item->selected = !item->selected;
2327 gtk_icon_view_queue_draw_item (icon_view, item);
2332 gtk_icon_view_unselect_all_internal (icon_view);
2334 item->selected = TRUE;
2335 gtk_icon_view_queue_draw_item (icon_view, item);
2338 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2339 icon_view->priv->anchor_item = item;
2342 /* Save press to possibly begin a drag */
2343 if (icon_view->priv->pressed_button < 0)
2345 icon_view->priv->pressed_button = event->button;
2346 icon_view->priv->press_start_x = event->x;
2347 icon_view->priv->press_start_y = event->y;
2350 if (!icon_view->priv->last_single_clicked)
2351 icon_view->priv->last_single_clicked = item;
2353 /* cancel the current editing, if it exists */
2354 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2356 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2358 GtkCellAreaContext *context;
2360 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2362 _gtk_icon_view_set_cell_data (icon_view, item);
2363 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2364 GTK_WIDGET (icon_view),
2365 &item->cell_area, 0/* XXX flags */, FALSE);
2370 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2371 !(event->state & modify_mod_mask))
2373 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2376 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2377 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2380 /* don't draw keyboard focus around an clicked-on item */
2381 icon_view->priv->draw_focus = FALSE;
2384 if (!icon_view->priv->activate_on_single_click
2385 && event->button == GDK_BUTTON_PRIMARY
2386 && event->type == GDK_2BUTTON_PRESS)
2388 item = _gtk_icon_view_get_item_at_coords (icon_view,
2393 if (item && item == icon_view->priv->last_single_clicked)
2397 path = gtk_tree_path_new_from_indices (item->index, -1);
2398 gtk_icon_view_item_activated (icon_view, path);
2399 gtk_tree_path_free (path);
2402 icon_view->priv->last_single_clicked = NULL;
2403 icon_view->priv->pressed_button = -1;
2407 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2409 return event->button == GDK_BUTTON_PRIMARY;
2413 button_event_modifies_selection (GdkEventButton *event)
2415 return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
2419 gtk_icon_view_button_release (GtkWidget *widget,
2420 GdkEventButton *event)
2422 GtkIconView *icon_view;
2424 icon_view = GTK_ICON_VIEW (widget);
2426 if (icon_view->priv->pressed_button == event->button)
2427 icon_view->priv->pressed_button = -1;
2429 gtk_icon_view_stop_rubberbanding (icon_view);
2431 remove_scroll_timeout (icon_view);
2433 if (event->button == GDK_BUTTON_PRIMARY
2434 && icon_view->priv->activate_on_single_click
2435 && !button_event_modifies_selection (event)
2436 && icon_view->priv->last_single_clicked != NULL)
2438 GtkIconViewItem *item;
2440 item = _gtk_icon_view_get_item_at_coords (icon_view,
2444 if (item == icon_view->priv->last_single_clicked)
2447 path = gtk_tree_path_new_from_indices (item->index, -1);
2448 gtk_icon_view_item_activated (icon_view, path);
2449 gtk_tree_path_free (path);
2452 icon_view->priv->last_single_clicked = NULL;
2459 gtk_icon_view_key_press (GtkWidget *widget,
2462 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2464 if (icon_view->priv->doing_rubberband)
2466 if (event->keyval == GDK_KEY_Escape)
2467 gtk_icon_view_stop_rubberbanding (icon_view);
2472 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2476 gtk_icon_view_key_release (GtkWidget *widget,
2479 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2481 if (icon_view->priv->doing_rubberband)
2484 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2488 gtk_icon_view_update_rubberband (gpointer data)
2490 GtkIconView *icon_view;
2492 GdkRectangle old_area;
2493 GdkRectangle new_area;
2494 GdkRectangle common;
2495 cairo_region_t *invalid_region;
2497 icon_view = GTK_ICON_VIEW (data);
2499 gdk_window_get_device_position (icon_view->priv->bin_window,
2500 icon_view->priv->rubberband_device,
2506 old_area.x = MIN (icon_view->priv->rubberband_x1,
2507 icon_view->priv->rubberband_x2);
2508 old_area.y = MIN (icon_view->priv->rubberband_y1,
2509 icon_view->priv->rubberband_y2);
2510 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2511 icon_view->priv->rubberband_x1) + 1;
2512 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2513 icon_view->priv->rubberband_y1) + 1;
2515 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2516 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2517 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2518 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2520 invalid_region = cairo_region_create_rectangle (&old_area);
2521 cairo_region_union_rectangle (invalid_region, &new_area);
2523 gdk_rectangle_intersect (&old_area, &new_area, &common);
2524 if (common.width > 2 && common.height > 2)
2526 cairo_region_t *common_region;
2528 /* make sure the border is invalidated */
2534 common_region = cairo_region_create_rectangle (&common);
2536 cairo_region_subtract (invalid_region, common_region);
2537 cairo_region_destroy (common_region);
2540 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2542 cairo_region_destroy (invalid_region);
2544 icon_view->priv->rubberband_x2 = x;
2545 icon_view->priv->rubberband_y2 = y;
2547 gtk_icon_view_update_rubberband_selection (icon_view);
2551 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2558 if (icon_view->priv->rubberband_device)
2561 for (items = icon_view->priv->items; items; items = items->next)
2563 GtkIconViewItem *item = items->data;
2565 item->selected_before_rubberbanding = item->selected;
2568 icon_view->priv->rubberband_x1 = x;
2569 icon_view->priv->rubberband_y1 = y;
2570 icon_view->priv->rubberband_x2 = x;
2571 icon_view->priv->rubberband_y2 = y;
2573 icon_view->priv->doing_rubberband = TRUE;
2574 icon_view->priv->rubberband_device = device;
2576 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2580 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2582 if (!icon_view->priv->doing_rubberband)
2585 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2586 icon_view->priv->rubberband_device);
2588 icon_view->priv->doing_rubberband = FALSE;
2589 icon_view->priv->rubberband_device = NULL;
2591 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2595 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2598 gint x, y, width, height;
2599 gboolean dirty = FALSE;
2601 x = MIN (icon_view->priv->rubberband_x1,
2602 icon_view->priv->rubberband_x2);
2603 y = MIN (icon_view->priv->rubberband_y1,
2604 icon_view->priv->rubberband_y2);
2605 width = ABS (icon_view->priv->rubberband_x1 -
2606 icon_view->priv->rubberband_x2);
2607 height = ABS (icon_view->priv->rubberband_y1 -
2608 icon_view->priv->rubberband_y2);
2610 for (items = icon_view->priv->items; items; items = items->next)
2612 GtkIconViewItem *item = items->data;
2616 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2617 x, y, width, height);
2619 selected = is_in ^ item->selected_before_rubberbanding;
2621 if (item->selected != selected)
2623 item->selected = selected;
2625 gtk_icon_view_queue_draw_item (icon_view, item);
2630 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2635 GdkRectangle hit_rect;
2640 hit_test (GtkCellRenderer *renderer,
2641 const GdkRectangle *cell_area,
2642 const GdkRectangle *cell_background,
2645 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2646 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2647 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2648 MAX (data->hit_rect.y, cell_area->y) > 0)
2651 return (data->hit != FALSE);
2655 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2656 GtkIconViewItem *item,
2662 HitTestData data = { { x, y, width, height }, FALSE };
2663 GtkCellAreaContext *context;
2664 GdkRectangle *item_area = &item->cell_area;
2666 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2667 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2670 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2672 _gtk_icon_view_set_cell_data (icon_view, item);
2673 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2674 GTK_WIDGET (icon_view),
2675 item_area, item_area,
2676 (GtkCellAllocCallback)hit_test, &data);
2682 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2684 gboolean dirty = FALSE;
2687 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2690 for (items = icon_view->priv->items; items; items = items->next)
2692 GtkIconViewItem *item = items->data;
2696 item->selected = FALSE;
2698 gtk_icon_view_queue_draw_item (icon_view, item);
2699 gtk_icon_view_item_selected_changed (icon_view, item);
2707 /* GtkIconView signals */
2709 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2711 gtk_icon_view_select_all (icon_view);
2715 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2717 gtk_icon_view_unselect_all (icon_view);
2721 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2723 gtk_icon_view_unselect_all (icon_view);
2725 if (icon_view->priv->cursor_item != NULL)
2726 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2730 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2733 GtkCellAreaContext *context;
2735 if (!icon_view->priv->cursor_item)
2738 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2740 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2741 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2742 GTK_WIDGET (icon_view),
2743 &icon_view->priv->cursor_item->cell_area,
2747 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2748 gtk_icon_view_item_activated (icon_view, path);
2749 gtk_tree_path_free (path);
2755 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2757 if (!icon_view->priv->cursor_item)
2760 switch (icon_view->priv->selection_mode)
2762 case GTK_SELECTION_NONE:
2764 case GTK_SELECTION_BROWSE:
2765 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2767 case GTK_SELECTION_SINGLE:
2768 if (icon_view->priv->cursor_item->selected)
2769 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2771 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2773 case GTK_SELECTION_MULTIPLE:
2774 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2775 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2777 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2778 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2784 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2786 GtkAllocation allocation;
2787 GtkAdjustment *adj = icon_view->priv->hadjustment;
2788 gdouble old_page_size;
2794 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2796 old_value = gtk_adjustment_get_value (adj);
2797 old_upper = gtk_adjustment_get_upper (adj);
2798 old_page_size = gtk_adjustment_get_page_size (adj);
2799 new_upper = MAX (allocation.width, icon_view->priv->width);
2801 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2803 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2804 /* Quick explanation:
2805 * In LTR locales, leftmost portion of visible rectangle should stay
2806 * fixed, which means left edge of scrollbar thumb should remain fixed
2807 * and thus adjustment's value should stay the same.
2809 * In RTL locales, we want to keep rightmost portion of visible
2810 * rectangle fixed. This means right edge of thumb should remain fixed.
2811 * In this case, upper - value - page_size should remain constant.
2813 new_value = (new_upper - allocation.width) -
2814 (old_upper - old_value - old_page_size);
2815 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2818 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2820 gtk_adjustment_configure (adj,
2824 allocation.width * 0.1,
2825 allocation.width * 0.9,
2830 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2832 GtkAllocation allocation;
2833 GtkAdjustment *adj = icon_view->priv->vadjustment;
2835 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2837 gtk_adjustment_configure (adj,
2838 gtk_adjustment_get_value (adj),
2840 MAX (allocation.height, icon_view->priv->height),
2841 allocation.height * 0.1,
2842 allocation.height * 0.9,
2847 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2848 GtkAdjustment *adjustment)
2850 GtkIconViewPrivate *priv = icon_view->priv;
2852 if (adjustment && priv->hadjustment == adjustment)
2855 if (priv->hadjustment != NULL)
2857 g_signal_handlers_disconnect_matched (priv->hadjustment,
2858 G_SIGNAL_MATCH_DATA,
2859 0, 0, NULL, NULL, icon_view);
2860 g_object_unref (priv->hadjustment);
2864 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2867 g_signal_connect (adjustment, "value-changed",
2868 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2869 priv->hadjustment = g_object_ref_sink (adjustment);
2870 gtk_icon_view_set_hadjustment_values (icon_view);
2872 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2876 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2877 GtkAdjustment *adjustment)
2879 GtkIconViewPrivate *priv = icon_view->priv;
2881 if (adjustment && priv->vadjustment == adjustment)
2884 if (priv->vadjustment != NULL)
2886 g_signal_handlers_disconnect_matched (priv->vadjustment,
2887 G_SIGNAL_MATCH_DATA,
2888 0, 0, NULL, NULL, icon_view);
2889 g_object_unref (priv->vadjustment);
2893 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2896 g_signal_connect (adjustment, "value-changed",
2897 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2898 priv->vadjustment = g_object_ref_sink (adjustment);
2899 gtk_icon_view_set_vadjustment_values (icon_view);
2901 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2905 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2906 GtkIconView *icon_view)
2908 GtkIconViewPrivate *priv = icon_view->priv;
2910 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2912 gdk_window_move (priv->bin_window,
2913 - gtk_adjustment_get_value (priv->hadjustment),
2914 - gtk_adjustment_get_value (priv->vadjustment));
2916 if (icon_view->priv->doing_rubberband)
2917 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2919 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2924 compare_sizes (gconstpointer p1,
2928 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2929 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2933 gtk_icon_view_layout (GtkIconView *icon_view)
2935 GtkIconViewPrivate *priv = icon_view->priv;
2936 GtkWidget *widget = GTK_WIDGET (icon_view);
2938 gint item_width; /* this doesn't include item_padding */
2939 gint n_columns, n_rows, n_items;
2941 GtkRequestedSize *sizes;
2944 if (gtk_icon_view_is_empty (icon_view))
2947 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2948 n_items = gtk_icon_view_get_n_items (icon_view);
2950 gtk_icon_view_compute_n_items_for_size (icon_view,
2951 GTK_ORIENTATION_HORIZONTAL,
2952 gtk_widget_get_allocated_width (widget),
2954 &n_columns, &item_width);
2955 n_rows = (n_items + n_columns - 1) / n_columns;
2957 priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
2958 priv->width += 2 * priv->margin;
2959 priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget));
2961 /* Clear the per row contexts */
2962 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2964 gtk_cell_area_context_reset (priv->cell_area_context);
2965 /* because layouting is complicated. We designed an API
2966 * that is O(N²) and nonsensical.
2967 * And we're proud of it. */
2968 for (items = priv->items; items; items = items->next)
2970 _gtk_icon_view_set_cell_data (icon_view, items->data);
2971 gtk_cell_area_get_preferred_width (priv->cell_area,
2972 priv->cell_area_context,
2977 sizes = g_newa (GtkRequestedSize, n_rows);
2978 items = priv->items;
2979 priv->height = priv->margin;
2981 /* Collect the heights for all rows */
2982 for (row = 0; row < n_rows; row++)
2984 GtkCellAreaContext *context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2985 g_ptr_array_add (priv->row_contexts, context);
2987 for (col = 0; col < n_columns && items; col++, items = items->next)
2989 GtkIconViewItem *item = items->data;
2991 _gtk_icon_view_set_cell_data (icon_view, item);
2992 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2999 sizes[row].data = GINT_TO_POINTER (row);
3000 gtk_cell_area_context_get_preferred_height_for_width (context,
3002 &sizes[row].minimum_size,
3003 &sizes[row].natural_size);
3004 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
3007 priv->height -= priv->row_spacing;
3008 priv->height += priv->margin;
3009 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
3011 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
3015 /* Actually allocate the rows */
3016 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
3018 items = priv->items;
3019 priv->height = priv->margin;
3021 for (row = 0; row < n_rows; row++)
3023 GtkCellAreaContext *context = g_ptr_array_index (priv->row_contexts, row);
3024 gtk_cell_area_context_allocate (context, item_width, sizes[row].minimum_size);
3026 priv->height += priv->item_padding;
3028 for (col = 0; col < n_columns && items; col++, items = items->next)
3030 GtkIconViewItem *item = items->data;
3032 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
3033 item->cell_area.width = item_width;
3034 item->cell_area.y = priv->height;
3035 item->cell_area.height = sizes[row].minimum_size;
3040 item->cell_area.x = priv->width - item_width - item->cell_area.x;
3041 item->col = n_columns - 1 - col;
3045 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
3048 priv->height -= priv->row_spacing;
3049 priv->height += priv->margin;
3050 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
3054 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3056 /* Clear all item sizes */
3057 g_list_foreach (icon_view->priv->items,
3058 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3060 /* Re-layout the items */
3061 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3065 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3067 item->cell_area.width = -1;
3068 item->cell_area.height = -1;
3072 gtk_icon_view_paint_item (GtkIconView *icon_view,
3074 GtkIconViewItem *item,
3077 gboolean draw_focus)
3079 GdkRectangle cell_area;
3080 GtkStateFlags state = 0;
3081 GtkCellRendererState flags = 0;
3082 GtkStyleContext *style_context;
3083 GtkWidget *widget = GTK_WIDGET (icon_view);
3084 GtkIconViewPrivate *priv = icon_view->priv;
3085 GtkCellAreaContext *context;
3087 if (priv->model == NULL || item->cell_area.width <= 0 || item->cell_area.height <= 0)
3090 _gtk_icon_view_set_cell_data (icon_view, item);
3092 style_context = gtk_widget_get_style_context (widget);
3093 state = gtk_widget_get_state_flags (widget);
3095 gtk_style_context_save (style_context);
3096 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
3098 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
3100 if ((state & GTK_STATE_FLAG_FOCUSED) &&
3101 item == icon_view->priv->cursor_item)
3102 flags |= GTK_CELL_RENDERER_FOCUSED;
3106 state |= GTK_STATE_FLAG_SELECTED;
3107 flags |= GTK_CELL_RENDERER_SELECTED;
3112 state |= GTK_STATE_FLAG_PRELIGHT;
3113 flags |= GTK_CELL_RENDERER_PRELIT;
3116 gtk_style_context_set_state (style_context, state);
3120 gtk_render_background (style_context, cr,
3121 x - icon_view->priv->item_padding,
3122 y - icon_view->priv->item_padding,
3123 item->cell_area.width + icon_view->priv->item_padding * 2,
3124 item->cell_area.height + icon_view->priv->item_padding * 2);
3125 gtk_render_frame (style_context, cr,
3126 x - icon_view->priv->item_padding,
3127 y - icon_view->priv->item_padding,
3128 item->cell_area.width + icon_view->priv->item_padding * 2,
3129 item->cell_area.height + icon_view->priv->item_padding * 2);
3134 cell_area.width = item->cell_area.width;
3135 cell_area.height = item->cell_area.height;
3137 context = g_ptr_array_index (priv->row_contexts, item->row);
3138 gtk_cell_area_render (priv->cell_area, context,
3139 widget, cr, &cell_area, &cell_area, flags,
3142 gtk_style_context_restore (style_context);
3146 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3149 GtkStyleContext *context;
3154 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3155 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3156 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3157 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3159 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3161 gtk_style_context_save (context);
3162 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3164 gdk_cairo_rectangle (cr, &rect);
3167 gtk_render_background (context, cr,
3169 rect.width, rect.height);
3170 gtk_render_frame (context, cr,
3172 rect.width, rect.height);
3174 gtk_style_context_restore (context);
3179 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3185 index = gtk_tree_path_get_indices (path)[0];
3187 for (l = icon_view->priv->items; l; l = l->next)
3189 GtkIconViewItem *item = l->data;
3191 if (item->index == index)
3193 gtk_icon_view_queue_draw_item (icon_view, item);
3200 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3201 GtkIconViewItem *item)
3204 GdkRectangle *item_area = &item->cell_area;
3206 rect.x = item_area->x - icon_view->priv->item_padding;
3207 rect.y = item_area->y - icon_view->priv->item_padding;
3208 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3209 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3211 if (icon_view->priv->bin_window)
3212 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3216 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3217 GtkIconViewItem *item,
3218 GtkCellRenderer *cursor_cell)
3221 AtkObject *item_obj;
3222 AtkObject *cursor_item_obj;
3224 /* When hitting this path from keynav, the focus cell is
3225 * already set, we dont need to notify the atk object
3226 * but we still need to queue the draw here (in the case
3227 * that the focus cell changes but not the cursor item).
3229 gtk_icon_view_queue_draw_item (icon_view, item);
3231 if (icon_view->priv->cursor_item == item &&
3232 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3235 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3236 if (icon_view->priv->cursor_item != NULL)
3238 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3241 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3242 if (cursor_item_obj != NULL)
3243 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3246 icon_view->priv->cursor_item = item;
3249 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3252 /* Make sure there is a cell in focus initially */
3253 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3254 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3257 /* Notify that accessible focus object has changed */
3258 item_obj = atk_object_ref_accessible_child (obj, item->index);
3260 if (item_obj != NULL)
3262 atk_focus_tracker_notify (item_obj);
3263 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3264 g_object_unref (item_obj);
3269 static GtkIconViewItem *
3270 gtk_icon_view_item_new (void)
3272 GtkIconViewItem *item;
3274 item = g_slice_new0 (GtkIconViewItem);
3276 item->cell_area.width = -1;
3277 item->cell_area.height = -1;
3283 gtk_icon_view_item_free (GtkIconViewItem *item)
3285 g_return_if_fail (item != NULL);
3287 g_slice_free (GtkIconViewItem, item);
3291 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3294 gboolean only_in_cell,
3295 GtkCellRenderer **cell_at_pos)
3300 *cell_at_pos = NULL;
3302 for (items = icon_view->priv->items; items; items = items->next)
3304 GtkIconViewItem *item = items->data;
3305 GdkRectangle *item_area = &item->cell_area;
3307 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3308 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3309 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3310 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3312 if (only_in_cell || cell_at_pos)
3314 GtkCellRenderer *cell = NULL;
3315 GtkCellAreaContext *context;
3317 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3318 _gtk_icon_view_set_cell_data (icon_view, item);
3320 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3321 y >= item_area->y && y <= item_area->y + item_area->height)
3322 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3323 GTK_WIDGET (icon_view),
3328 *cell_at_pos = cell;
3331 return cell != NULL ? item : NULL;
3342 _gtk_icon_view_select_item (GtkIconView *icon_view,
3343 GtkIconViewItem *item)
3345 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3346 g_return_if_fail (item != NULL);
3351 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3353 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3354 gtk_icon_view_unselect_all_internal (icon_view);
3356 item->selected = TRUE;
3358 gtk_icon_view_item_selected_changed (icon_view, item);
3359 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3361 gtk_icon_view_queue_draw_item (icon_view, item);
3366 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3367 GtkIconViewItem *item)
3369 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3370 g_return_if_fail (item != NULL);
3372 if (!item->selected)
3375 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3376 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3379 item->selected = FALSE;
3381 gtk_icon_view_item_selected_changed (icon_view, item);
3382 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3384 gtk_icon_view_queue_draw_item (icon_view, item);
3388 verify_items (GtkIconView *icon_view)
3393 for (items = icon_view->priv->items; items; items = items->next)
3395 GtkIconViewItem *item = items->data;
3397 if (item->index != i)
3398 g_error ("List item does not match its index: "
3399 "item index %d and list index %d\n", item->index, i);
3406 gtk_icon_view_row_changed (GtkTreeModel *model,
3411 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3413 /* ignore changes in branches */
3414 if (gtk_tree_path_get_depth (path) > 1)
3417 /* An icon view subclass might add it's own model and populate
3418 * things at init() time instead of waiting for the constructor()
3421 if (icon_view->priv->cell_area)
3422 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3424 /* Here we can use a "grow-only" strategy for optimization
3425 * and only invalidate a single item and queue a relayout
3426 * instead of invalidating the whole thing.
3428 * For now GtkIconView still cant deal with huge models
3429 * so just invalidate the whole thing when the model
3432 gtk_icon_view_invalidate_sizes (icon_view);
3434 verify_items (icon_view);
3438 gtk_icon_view_row_inserted (GtkTreeModel *model,
3443 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3445 GtkIconViewItem *item;
3448 /* ignore changes in branches */
3449 if (gtk_tree_path_get_depth (path) > 1)
3452 index = gtk_tree_path_get_indices(path)[0];
3454 item = gtk_icon_view_item_new ();
3456 item->index = index;
3458 /* FIXME: We can be more efficient here,
3459 we can store a tail pointer and use that when
3460 appending (which is a rather common operation)
3462 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3465 list = g_list_nth (icon_view->priv->items, index + 1);
3466 for (; list; list = list->next)
3473 verify_items (icon_view);
3475 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3479 gtk_icon_view_row_deleted (GtkTreeModel *model,
3483 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3485 GtkIconViewItem *item;
3487 gboolean emit = FALSE;
3489 /* ignore changes in branches */
3490 if (gtk_tree_path_get_depth (path) > 1)
3493 index = gtk_tree_path_get_indices(path)[0];
3495 list = g_list_nth (icon_view->priv->items, index);
3498 if (icon_view->priv->cell_area)
3499 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3501 if (item == icon_view->priv->anchor_item)
3502 icon_view->priv->anchor_item = NULL;
3504 if (item == icon_view->priv->cursor_item)
3505 icon_view->priv->cursor_item = NULL;
3507 if (item == icon_view->priv->last_prelight)
3508 icon_view->priv->last_prelight = NULL;
3513 gtk_icon_view_item_free (item);
3515 for (next = list->next; next; next = next->next)
3522 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3524 verify_items (icon_view);
3526 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3529 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3533 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3534 GtkTreePath *parent,
3539 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3542 GList *items = NULL, *list;
3543 GtkIconViewItem **item_array;
3546 /* ignore changes in branches */
3550 if (icon_view->priv->cell_area)
3551 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3553 length = gtk_tree_model_iter_n_children (model, NULL);
3555 order = g_new (gint, length);
3556 for (i = 0; i < length; i++)
3557 order [new_order[i]] = i;
3559 item_array = g_new (GtkIconViewItem *, length);
3560 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3561 item_array[order[i]] = list->data;
3564 for (i = length - 1; i >= 0; i--)
3566 item_array[i]->index = i;
3567 items = g_list_prepend (items, item_array[i]);
3570 g_free (item_array);
3571 g_list_free (icon_view->priv->items);
3572 icon_view->priv->items = items;
3574 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3576 verify_items (icon_view);
3580 gtk_icon_view_build_items (GtkIconView *icon_view)
3584 GList *items = NULL;
3586 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3594 GtkIconViewItem *item = gtk_icon_view_item_new ();
3600 items = g_list_prepend (items, item);
3602 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3604 icon_view->priv->items = g_list_reverse (items);
3608 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3611 GtkMovementStep step,
3615 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3616 I_("move-cursor"), 2,
3620 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3625 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3628 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3633 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3640 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3641 GtkMovementStep step,
3644 GdkModifierType state;
3646 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3647 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3648 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3649 step == GTK_MOVEMENT_DISPLAY_LINES ||
3650 step == GTK_MOVEMENT_PAGES ||
3651 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3653 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3656 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3657 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3659 if (gtk_get_current_event_state (&state))
3661 GdkModifierType extend_mod_mask;
3662 GdkModifierType modify_mod_mask;
3665 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3666 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3668 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3669 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3671 if ((state & modify_mod_mask) == modify_mod_mask)
3672 icon_view->priv->modify_selection_pressed = TRUE;
3673 if ((state & extend_mod_mask) == extend_mod_mask)
3674 icon_view->priv->extend_selection_pressed = TRUE;
3676 /* else we assume not pressed */
3680 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3681 case GTK_MOVEMENT_VISUAL_POSITIONS:
3682 gtk_icon_view_move_cursor_left_right (icon_view, count);
3684 case GTK_MOVEMENT_DISPLAY_LINES:
3685 gtk_icon_view_move_cursor_up_down (icon_view, count);
3687 case GTK_MOVEMENT_PAGES:
3688 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3690 case GTK_MOVEMENT_BUFFER_ENDS:
3691 gtk_icon_view_move_cursor_start_end (icon_view, count);
3694 g_assert_not_reached ();
3697 icon_view->priv->modify_selection_pressed = FALSE;
3698 icon_view->priv->extend_selection_pressed = FALSE;
3700 icon_view->priv->draw_focus = TRUE;
3705 static GtkIconViewItem *
3706 find_item (GtkIconView *icon_view,
3707 GtkIconViewItem *current,
3713 GtkIconViewItem *item;
3715 /* FIXME: this could be more efficient
3717 row = current->row + row_ofs;
3718 col = current->col + col_ofs;
3720 for (items = icon_view->priv->items; items; items = items->next)
3723 if (item->row == row && item->col == col)
3730 static GtkIconViewItem *
3731 find_item_page_up_down (GtkIconView *icon_view,
3732 GtkIconViewItem *current,
3739 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3741 item = g_list_find (icon_view->priv->items, current);
3746 for (next = item->next; next; next = next->next)
3748 if (((GtkIconViewItem *)next->data)->col == col)
3751 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3761 for (next = item->prev; next; next = next->prev)
3763 if (((GtkIconViewItem *)next->data)->col == col)
3766 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3780 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3781 GtkIconViewItem *anchor,
3782 GtkIconViewItem *cursor)
3785 GtkIconViewItem *item;
3786 gint row1, row2, col1, col2;
3787 gboolean dirty = FALSE;
3789 if (anchor->row < cursor->row)
3800 if (anchor->col < cursor->col)
3811 for (items = icon_view->priv->items; items; items = items->next)
3815 if (row1 <= item->row && item->row <= row2 &&
3816 col1 <= item->col && item->col <= col2)
3818 if (!item->selected)
3821 item->selected = TRUE;
3822 gtk_icon_view_item_selected_changed (icon_view, item);
3824 gtk_icon_view_queue_draw_item (icon_view, item);
3832 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3835 GtkIconViewItem *item;
3836 GtkCellRenderer *cell = NULL;
3837 gboolean dirty = FALSE;
3839 GtkDirectionType direction;
3841 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3844 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3846 if (!icon_view->priv->cursor_item)
3851 list = icon_view->priv->items;
3853 list = g_list_last (icon_view->priv->items);
3859 /* Give focus to the first cell initially */
3860 _gtk_icon_view_set_cell_data (icon_view, item);
3861 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3870 item = icon_view->priv->cursor_item;
3871 step = count > 0 ? 1 : -1;
3873 /* Save the current focus cell in case we hit the edge */
3874 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3878 _gtk_icon_view_set_cell_data (icon_view, item);
3880 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3883 item = find_item (icon_view, item, step, 0);
3889 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3891 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3893 gtk_widget_child_focus (toplevel,
3894 direction == GTK_DIR_UP ?
3895 GTK_DIR_TAB_BACKWARD :
3896 GTK_DIR_TAB_FORWARD);
3900 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3904 if (icon_view->priv->modify_selection_pressed ||
3905 !icon_view->priv->extend_selection_pressed ||
3906 !icon_view->priv->anchor_item ||
3907 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3908 icon_view->priv->anchor_item = item;
3910 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3911 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3913 if (!icon_view->priv->modify_selection_pressed &&
3914 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3916 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3917 dirty = gtk_icon_view_select_all_between (icon_view,
3918 icon_view->priv->anchor_item,
3922 gtk_icon_view_scroll_to_item (icon_view, item);
3925 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3929 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3932 GtkIconViewItem *item;
3933 gboolean dirty = FALSE;
3935 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3938 if (!icon_view->priv->cursor_item)
3943 list = icon_view->priv->items;
3945 list = g_list_last (icon_view->priv->items);
3947 item = list ? list->data : NULL;
3950 item = find_item_page_up_down (icon_view,
3951 icon_view->priv->cursor_item,
3954 if (item == icon_view->priv->cursor_item)
3955 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3960 if (icon_view->priv->modify_selection_pressed ||
3961 !icon_view->priv->extend_selection_pressed ||
3962 !icon_view->priv->anchor_item ||
3963 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3964 icon_view->priv->anchor_item = item;
3966 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3968 if (!icon_view->priv->modify_selection_pressed &&
3969 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3971 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3972 dirty = gtk_icon_view_select_all_between (icon_view,
3973 icon_view->priv->anchor_item,
3977 gtk_icon_view_scroll_to_item (icon_view, item);
3980 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3984 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3987 GtkIconViewItem *item;
3988 GtkCellRenderer *cell = NULL;
3989 gboolean dirty = FALSE;
3991 GtkDirectionType direction;
3993 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3996 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3998 if (!icon_view->priv->cursor_item)
4003 list = icon_view->priv->items;
4005 list = g_list_last (icon_view->priv->items);
4011 /* Give focus to the first cell initially */
4012 _gtk_icon_view_set_cell_data (icon_view, item);
4013 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
4022 item = icon_view->priv->cursor_item;
4023 step = count > 0 ? 1 : -1;
4025 /* Save the current focus cell in case we hit the edge */
4026 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
4030 _gtk_icon_view_set_cell_data (icon_view, item);
4032 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
4035 item = find_item (icon_view, item, 0, step);
4041 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4043 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4045 gtk_widget_child_focus (toplevel,
4046 direction == GTK_DIR_LEFT ?
4047 GTK_DIR_TAB_BACKWARD :
4048 GTK_DIR_TAB_FORWARD);
4052 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
4056 if (icon_view->priv->modify_selection_pressed ||
4057 !icon_view->priv->extend_selection_pressed ||
4058 !icon_view->priv->anchor_item ||
4059 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4060 icon_view->priv->anchor_item = item;
4062 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
4063 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
4065 if (!icon_view->priv->modify_selection_pressed &&
4066 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4068 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4069 dirty = gtk_icon_view_select_all_between (icon_view,
4070 icon_view->priv->anchor_item,
4074 gtk_icon_view_scroll_to_item (icon_view, item);
4077 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4081 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4084 GtkIconViewItem *item;
4086 gboolean dirty = FALSE;
4088 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4092 list = icon_view->priv->items;
4094 list = g_list_last (icon_view->priv->items);
4096 item = list ? list->data : NULL;
4098 if (item == icon_view->priv->cursor_item)
4099 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4104 if (icon_view->priv->modify_selection_pressed ||
4105 !icon_view->priv->extend_selection_pressed ||
4106 !icon_view->priv->anchor_item ||
4107 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4108 icon_view->priv->anchor_item = item;
4110 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4112 if (!icon_view->priv->modify_selection_pressed &&
4113 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4115 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4116 dirty = gtk_icon_view_select_all_between (icon_view,
4117 icon_view->priv->anchor_item,
4121 gtk_icon_view_scroll_to_item (icon_view, item);
4124 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4128 * gtk_icon_view_scroll_to_path:
4129 * @icon_view: A #GtkIconView.
4130 * @path: The path of the item to move to.
4131 * @use_align: whether to use alignment arguments, or %FALSE.
4132 * @row_align: The vertical alignment of the item specified by @path.
4133 * @col_align: The horizontal alignment of the item specified by @path.
4135 * Moves the alignments of @icon_view to the position specified by @path.
4136 * @row_align determines where the row is placed, and @col_align determines
4137 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4138 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4141 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4142 * tree does the minimum amount of work to scroll the item onto the screen.
4143 * This means that the item will be scrolled to the edge closest to its current
4144 * position. If the item is currently visible on the screen, nothing is done.
4146 * This function only works if the model is set, and @path is a valid row on
4147 * the model. If the model changes before the @icon_view is realized, the
4148 * centered path will be modified to reflect this change.
4153 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4159 GtkIconViewItem *item = NULL;
4162 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4163 g_return_if_fail (path != NULL);
4164 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4165 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4167 widget = GTK_WIDGET (icon_view);
4169 if (gtk_tree_path_get_depth (path) > 0)
4170 item = g_list_nth_data (icon_view->priv->items,
4171 gtk_tree_path_get_indices(path)[0]);
4173 if (!item || item->cell_area.width < 0 ||
4174 !gtk_widget_get_realized (widget))
4176 if (icon_view->priv->scroll_to_path)
4177 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4179 icon_view->priv->scroll_to_path = NULL;
4182 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4184 icon_view->priv->scroll_to_use_align = use_align;
4185 icon_view->priv->scroll_to_row_align = row_align;
4186 icon_view->priv->scroll_to_col_align = col_align;
4193 GtkAllocation allocation;
4196 GdkRectangle item_area =
4198 item->cell_area.x - icon_view->priv->item_padding,
4199 item->cell_area.y - icon_view->priv->item_padding,
4200 item->cell_area.width + icon_view->priv->item_padding * 2,
4201 item->cell_area.height + icon_view->priv->item_padding * 2
4204 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4206 gtk_widget_get_allocation (widget, &allocation);
4208 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4210 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4211 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4213 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4215 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4216 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4218 gtk_adjustment_changed (icon_view->priv->hadjustment);
4219 gtk_adjustment_changed (icon_view->priv->vadjustment);
4222 gtk_icon_view_scroll_to_item (icon_view, item);
4227 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4228 GtkIconViewItem *item)
4230 GtkIconViewPrivate *priv = icon_view->priv;
4231 GtkWidget *widget = GTK_WIDGET (icon_view);
4232 GtkAdjustment *hadj, *vadj;
4233 GtkAllocation allocation;
4235 GdkRectangle item_area;
4237 item_area.x = item->cell_area.x - priv->item_padding;
4238 item_area.y = item->cell_area.y - priv->item_padding;
4239 item_area.width = item->cell_area.width + priv->item_padding * 2;
4240 item_area.height = item->cell_area.height + priv->item_padding * 2;
4242 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4243 gtk_widget_get_allocation (widget, &allocation);
4245 hadj = icon_view->priv->hadjustment;
4246 vadj = icon_view->priv->vadjustment;
4248 if (y + item_area.y < 0)
4249 gtk_adjustment_set_value (vadj,
4250 gtk_adjustment_get_value (vadj)
4252 else if (y + item_area.y + item_area.height > allocation.height)
4253 gtk_adjustment_set_value (vadj,
4254 gtk_adjustment_get_value (vadj)
4255 + y + item_area.y + item_area.height - allocation.height);
4257 if (x + item_area.x < 0)
4258 gtk_adjustment_set_value (hadj,
4259 gtk_adjustment_get_value (hadj)
4261 else if (x + item_area.x + item_area.width > allocation.width)
4262 gtk_adjustment_set_value (hadj,
4263 gtk_adjustment_get_value (hadj)
4264 + x + item_area.x + item_area.width - allocation.width);
4266 gtk_adjustment_changed (hadj);
4267 gtk_adjustment_changed (vadj);
4270 /* GtkCellLayout implementation */
4273 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4274 GtkCellArea *cell_area)
4276 GtkIconViewPrivate *priv = icon_view->priv;
4278 if (priv->cell_area)
4282 priv->cell_area = cell_area;
4284 priv->cell_area = gtk_cell_area_box_new ();
4286 g_object_ref_sink (priv->cell_area);
4288 if (GTK_IS_ORIENTABLE (priv->cell_area))
4289 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4291 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4293 priv->add_editable_id =
4294 g_signal_connect (priv->cell_area, "add-editable",
4295 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4296 priv->remove_editable_id =
4297 g_signal_connect (priv->cell_area, "remove-editable",
4298 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4300 update_text_cell (icon_view);
4301 update_pixbuf_cell (icon_view);
4304 static GtkCellArea *
4305 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4307 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4308 GtkIconViewPrivate *priv = icon_view->priv;
4310 if (G_UNLIKELY (!priv->cell_area))
4311 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4313 return icon_view->priv->cell_area;
4317 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4318 GtkIconViewItem *item)
4323 path = gtk_tree_path_new_from_indices (item->index, -1);
4324 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4326 gtk_tree_path_free (path);
4328 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4329 icon_view->priv->model,
4330 &iter, FALSE, FALSE);
4339 * gtk_icon_view_new:
4341 * Creates a new #GtkIconView widget
4343 * Return value: A newly created #GtkIconView widget
4348 gtk_icon_view_new (void)
4350 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4354 * gtk_icon_view_new_with_area:
4355 * @area: the #GtkCellArea to use to layout cells
4357 * Creates a new #GtkIconView widget using the
4358 * specified @area to layout cells inside the icons.
4360 * Return value: A newly created #GtkIconView widget
4365 gtk_icon_view_new_with_area (GtkCellArea *area)
4367 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4371 * gtk_icon_view_new_with_model:
4372 * @model: The model.
4374 * Creates a new #GtkIconView widget with the model @model.
4376 * Return value: A newly created #GtkIconView widget.
4381 gtk_icon_view_new_with_model (GtkTreeModel *model)
4383 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4387 * gtk_icon_view_convert_widget_to_bin_window_coords:
4388 * @icon_view: a #GtkIconView
4389 * @wx: X coordinate relative to the widget
4390 * @wy: Y coordinate relative to the widget
4391 * @bx: (out): return location for bin_window X coordinate
4392 * @by: (out): return location for bin_window Y coordinate
4394 * Converts widget coordinates to coordinates for the bin_window,
4395 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4400 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4408 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4410 if (icon_view->priv->bin_window)
4411 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4422 * gtk_icon_view_get_path_at_pos:
4423 * @icon_view: A #GtkIconView.
4424 * @x: The x position to be identified
4425 * @y: The y position to be identified
4427 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4428 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4429 * the cell at the specified position.
4430 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4431 * widget coordinates to bin_window coordinates.
4433 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4434 * if no icon exists at that position.
4439 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4443 GtkIconViewItem *item;
4446 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4448 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4453 path = gtk_tree_path_new_from_indices (item->index, -1);
4459 * gtk_icon_view_get_item_at_pos:
4460 * @icon_view: A #GtkIconView.
4461 * @x: The x position to be identified
4462 * @y: The y position to be identified
4463 * @path: (out) (allow-none): Return location for the path, or %NULL
4464 * @cell: (out) (allow-none): Return location for the renderer
4465 * responsible for the cell at (@x, @y), or %NULL
4467 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4468 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4469 * obtains the cell at the specified position. The returned path should
4470 * be freed with gtk_tree_path_free().
4471 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4472 * widget coordinates to bin_window coordinates.
4474 * Return value: %TRUE if an item exists at the specified position
4479 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4483 GtkCellRenderer **cell)
4485 GtkIconViewItem *item;
4486 GtkCellRenderer *renderer = NULL;
4488 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4490 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4495 *path = gtk_tree_path_new_from_indices (item->index, -1);
4503 return (item != NULL);
4507 * gtk_icon_view_get_cell_rect:
4508 * @icon_view: a #GtkIconView
4509 * @path: a #GtkTreePath
4510 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4511 * @rect: (out): rectangle to fill with cell rect
4513 * Fills the bounding rectangle in widget coordinates for the cell specified by
4514 * @path and @cell. If @cell is %NULL the main cell area is used.
4516 * This function is only valid if @icon_view is realized.
4518 * Return value: %FALSE if there is no such item, %TRUE otherwise
4523 gtk_icon_view_get_cell_rect (GtkIconView *icon_view,
4525 GtkCellRenderer *cell,
4528 GtkIconViewItem *item = NULL;
4531 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4532 g_return_val_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell), FALSE);
4534 if (gtk_tree_path_get_depth (path) > 0)
4535 item = g_list_nth_data (icon_view->priv->items,
4536 gtk_tree_path_get_indices(path)[0]);
4543 GtkCellAreaContext *context;
4545 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4546 _gtk_icon_view_set_cell_data (icon_view, item);
4547 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4548 GTK_WIDGET (icon_view),
4549 cell, &item->cell_area, rect);
4553 rect->x = item->cell_area.x - icon_view->priv->item_padding;
4554 rect->y = item->cell_area.y - icon_view->priv->item_padding;
4555 rect->width = item->cell_area.width + icon_view->priv->item_padding * 2;
4556 rect->height = item->cell_area.height + icon_view->priv->item_padding * 2;
4559 if (icon_view->priv->bin_window)
4561 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4570 * gtk_icon_view_set_tooltip_item:
4571 * @icon_view: a #GtkIconView
4572 * @tooltip: a #GtkTooltip
4573 * @path: a #GtkTreePath
4575 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4576 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4577 * See also gtk_tooltip_set_tip_area().
4582 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4583 GtkTooltip *tooltip,
4586 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4587 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4589 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4593 * gtk_icon_view_set_tooltip_cell:
4594 * @icon_view: a #GtkIconView
4595 * @tooltip: a #GtkTooltip
4596 * @path: a #GtkTreePath
4597 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4599 * Sets the tip area of @tooltip to the area which @cell occupies in
4600 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4602 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4607 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4608 GtkTooltip *tooltip,
4610 GtkCellRenderer *cell)
4614 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4615 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4616 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4618 if (!gtk_icon_view_get_cell_rect (icon_view, path, cell, &rect))
4621 gtk_tooltip_set_tip_area (tooltip, &rect);
4626 * gtk_icon_view_get_tooltip_context:
4627 * @icon_view: an #GtkIconView
4628 * @x: (inout): the x coordinate (relative to widget coordinates)
4629 * @y: (inout): the y coordinate (relative to widget coordinates)
4630 * @keyboard_tip: whether this is a keyboard tooltip or not
4631 * @model: (out) (allow-none) (transfer none): a pointer to receive a
4632 * #GtkTreeModel or %NULL
4633 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4634 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4636 * This function is supposed to be used in a #GtkWidget::query-tooltip
4637 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4638 * which are received in the signal handler, should be passed to this
4639 * function without modification.
4641 * The return value indicates whether there is an icon view item at the given
4642 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4643 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4644 * @model, @path and @iter which have been provided will be set to point to
4645 * that row and the corresponding model. @x and @y will always be converted
4646 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4648 * Return value: whether or not the given tooltip context points to a item
4653 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4656 gboolean keyboard_tip,
4657 GtkTreeModel **model,
4661 GtkTreePath *tmppath = NULL;
4663 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4664 g_return_val_if_fail (x != NULL, FALSE);
4665 g_return_val_if_fail (y != NULL, FALSE);
4669 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4676 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4679 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4684 *model = gtk_icon_view_get_model (icon_view);
4687 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4693 gtk_tree_path_free (tmppath);
4699 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4702 gboolean keyboard_tip,
4703 GtkTooltip *tooltip,
4709 GtkTreeModel *model;
4710 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4712 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4715 &model, &path, &iter))
4718 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4722 gtk_tree_path_free (path);
4726 gtk_tooltip_set_markup (tooltip, str);
4727 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4729 gtk_tree_path_free (path);
4737 * gtk_icon_view_set_tooltip_column:
4738 * @icon_view: a #GtkIconView
4739 * @column: an integer, which is a valid column number for @icon_view's model
4741 * If you only plan to have simple (text-only) tooltips on full items, you
4742 * can use this function to have #GtkIconView handle these automatically
4743 * for you. @column should be set to the column in @icon_view's model
4744 * containing the tooltip texts, or -1 to disable this feature.
4746 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4747 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4749 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4750 * so &, <, etc have to be escaped in the text.
4755 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4758 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4760 if (column == icon_view->priv->tooltip_column)
4765 g_signal_handlers_disconnect_by_func (icon_view,
4766 gtk_icon_view_set_tooltip_query_cb,
4768 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4772 if (icon_view->priv->tooltip_column == -1)
4774 g_signal_connect (icon_view, "query-tooltip",
4775 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4776 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4780 icon_view->priv->tooltip_column = column;
4781 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4785 * gtk_icon_view_get_tooltip_column:
4786 * @icon_view: a #GtkIconView
4788 * Returns the column of @icon_view's model which is being used for
4789 * displaying tooltips on @icon_view's rows.
4791 * Return value: the index of the tooltip column that is currently being
4792 * used, or -1 if this is disabled.
4797 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4799 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4801 return icon_view->priv->tooltip_column;
4805 * gtk_icon_view_get_visible_range:
4806 * @icon_view: A #GtkIconView
4807 * @start_path: (out) (allow-none): Return location for start of region,
4809 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4811 * Sets @start_path and @end_path to be the first and last visible path.
4812 * Note that there may be invisible paths in between.
4814 * Both paths should be freed with gtk_tree_path_free() after use.
4816 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4821 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4822 GtkTreePath **start_path,
4823 GtkTreePath **end_path)
4825 gint start_index = -1;
4826 gint end_index = -1;
4829 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4831 if (icon_view->priv->hadjustment == NULL ||
4832 icon_view->priv->vadjustment == NULL)
4835 if (start_path == NULL && end_path == NULL)
4838 for (icons = icon_view->priv->items; icons; icons = icons->next)
4840 GtkIconViewItem *item = icons->data;
4841 GdkRectangle *item_area = &item->cell_area;
4843 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4844 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4846 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4847 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4849 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4850 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4852 if (start_index == -1)
4853 start_index = item->index;
4854 end_index = item->index;
4858 if (start_path && start_index != -1)
4859 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4860 if (end_path && end_index != -1)
4861 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4863 return start_index != -1;
4867 * gtk_icon_view_selected_foreach:
4868 * @icon_view: A #GtkIconView.
4869 * @func: (scope call): The function to call for each selected icon.
4870 * @data: User data to pass to the function.
4872 * Calls a function for each selected icon. Note that the model or
4873 * selection cannot be modified from within this function.
4878 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4879 GtkIconViewForeachFunc func,
4884 for (list = icon_view->priv->items; list; list = list->next)
4886 GtkIconViewItem *item = list->data;
4887 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4890 (* func) (icon_view, path, data);
4892 gtk_tree_path_free (path);
4897 * gtk_icon_view_set_selection_mode:
4898 * @icon_view: A #GtkIconView.
4899 * @mode: The selection mode
4901 * Sets the selection mode of the @icon_view.
4906 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4907 GtkSelectionMode mode)
4909 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4911 if (mode == icon_view->priv->selection_mode)
4914 if (mode == GTK_SELECTION_NONE ||
4915 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4916 gtk_icon_view_unselect_all (icon_view);
4918 icon_view->priv->selection_mode = mode;
4920 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4924 * gtk_icon_view_get_selection_mode:
4925 * @icon_view: A #GtkIconView.
4927 * Gets the selection mode of the @icon_view.
4929 * Return value: the current selection mode
4934 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4936 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4938 return icon_view->priv->selection_mode;
4942 * gtk_icon_view_set_model:
4943 * @icon_view: A #GtkIconView.
4944 * @model: (allow-none): The model.
4946 * Sets the model for a #GtkIconView.
4947 * If the @icon_view already has a model set, it will remove
4948 * it before setting the new model. If @model is %NULL, then
4949 * it will unset the old model.
4954 gtk_icon_view_set_model (GtkIconView *icon_view,
4955 GtkTreeModel *model)
4959 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4960 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4962 if (icon_view->priv->model == model)
4965 if (icon_view->priv->scroll_to_path)
4967 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4968 icon_view->priv->scroll_to_path = NULL;
4971 /* The area can be NULL while disposing */
4972 if (icon_view->priv->cell_area)
4973 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4975 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4981 if (icon_view->priv->pixbuf_column != -1)
4983 column_type = gtk_tree_model_get_column_type (model,
4984 icon_view->priv->pixbuf_column);
4986 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4989 if (icon_view->priv->text_column != -1)
4991 column_type = gtk_tree_model_get_column_type (model,
4992 icon_view->priv->text_column);
4994 g_return_if_fail (column_type == G_TYPE_STRING);
4997 if (icon_view->priv->markup_column != -1)
4999 column_type = gtk_tree_model_get_column_type (model,
5000 icon_view->priv->markup_column);
5002 g_return_if_fail (column_type == G_TYPE_STRING);
5007 if (icon_view->priv->model)
5009 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5010 gtk_icon_view_row_changed,
5012 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5013 gtk_icon_view_row_inserted,
5015 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5016 gtk_icon_view_row_deleted,
5018 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5019 gtk_icon_view_rows_reordered,
5022 g_object_unref (icon_view->priv->model);
5024 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
5025 icon_view->priv->items = NULL;
5026 icon_view->priv->anchor_item = NULL;
5027 icon_view->priv->cursor_item = NULL;
5028 icon_view->priv->last_single_clicked = NULL;
5029 icon_view->priv->last_prelight = NULL;
5030 icon_view->priv->width = 0;
5031 icon_view->priv->height = 0;
5034 icon_view->priv->model = model;
5036 if (icon_view->priv->model)
5038 g_object_ref (icon_view->priv->model);
5039 g_signal_connect (icon_view->priv->model,
5041 G_CALLBACK (gtk_icon_view_row_changed),
5043 g_signal_connect (icon_view->priv->model,
5045 G_CALLBACK (gtk_icon_view_row_inserted),
5047 g_signal_connect (icon_view->priv->model,
5049 G_CALLBACK (gtk_icon_view_row_deleted),
5051 g_signal_connect (icon_view->priv->model,
5053 G_CALLBACK (gtk_icon_view_rows_reordered),
5056 gtk_icon_view_build_items (icon_view);
5059 g_object_notify (G_OBJECT (icon_view), "model");
5062 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5064 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5068 * gtk_icon_view_get_model:
5069 * @icon_view: a #GtkIconView
5071 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5074 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5075 * currently being used.
5080 gtk_icon_view_get_model (GtkIconView *icon_view)
5082 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5084 return icon_view->priv->model;
5088 update_text_cell (GtkIconView *icon_view)
5090 if (!icon_view->priv->cell_area)
5093 if (icon_view->priv->text_column == -1 &&
5094 icon_view->priv->markup_column == -1)
5096 if (icon_view->priv->text_cell != NULL)
5098 gtk_cell_area_remove (icon_view->priv->cell_area,
5099 icon_view->priv->text_cell);
5100 icon_view->priv->text_cell = NULL;
5105 if (icon_view->priv->text_cell == NULL)
5107 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
5109 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
5112 if (icon_view->priv->markup_column != -1)
5113 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5114 icon_view->priv->text_cell,
5115 "markup", icon_view->priv->markup_column,
5118 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5119 icon_view->priv->text_cell,
5120 "text", icon_view->priv->text_column,
5123 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5124 g_object_set (icon_view->priv->text_cell,
5125 "alignment", PANGO_ALIGN_CENTER,
5126 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5131 g_object_set (icon_view->priv->text_cell,
5132 "alignment", PANGO_ALIGN_LEFT,
5133 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5141 update_pixbuf_cell (GtkIconView *icon_view)
5143 if (!icon_view->priv->cell_area)
5146 if (icon_view->priv->pixbuf_column == -1)
5148 if (icon_view->priv->pixbuf_cell != NULL)
5150 gtk_cell_area_remove (icon_view->priv->cell_area,
5151 icon_view->priv->pixbuf_cell);
5153 icon_view->priv->pixbuf_cell = NULL;
5158 if (icon_view->priv->pixbuf_cell == NULL)
5160 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5162 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5165 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5166 icon_view->priv->pixbuf_cell,
5167 "pixbuf", icon_view->priv->pixbuf_column,
5170 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5171 g_object_set (icon_view->priv->pixbuf_cell,
5176 g_object_set (icon_view->priv->pixbuf_cell,
5184 * gtk_icon_view_set_text_column:
5185 * @icon_view: A #GtkIconView.
5186 * @column: A column in the currently used model, or -1 to display no text
5188 * Sets the column with text for @icon_view to be @column. The text
5189 * column must be of type #G_TYPE_STRING.
5194 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5197 if (column == icon_view->priv->text_column)
5201 icon_view->priv->text_column = -1;
5204 if (icon_view->priv->model != NULL)
5208 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5210 g_return_if_fail (column_type == G_TYPE_STRING);
5213 icon_view->priv->text_column = column;
5216 if (icon_view->priv->cell_area)
5217 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5219 update_text_cell (icon_view);
5221 gtk_icon_view_invalidate_sizes (icon_view);
5223 g_object_notify (G_OBJECT (icon_view), "text-column");
5227 * gtk_icon_view_get_text_column:
5228 * @icon_view: A #GtkIconView.
5230 * Returns the column with text for @icon_view.
5232 * Returns: the text column, or -1 if it's unset.
5237 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5239 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5241 return icon_view->priv->text_column;
5245 * gtk_icon_view_set_markup_column:
5246 * @icon_view: A #GtkIconView.
5247 * @column: A column in the currently used model, or -1 to display no text
5249 * Sets the column with markup information for @icon_view to be
5250 * @column. The markup column must be of type #G_TYPE_STRING.
5251 * If the markup column is set to something, it overrides
5252 * the text column set by gtk_icon_view_set_text_column().
5257 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5260 if (column == icon_view->priv->markup_column)
5264 icon_view->priv->markup_column = -1;
5267 if (icon_view->priv->model != NULL)
5271 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5273 g_return_if_fail (column_type == G_TYPE_STRING);
5276 icon_view->priv->markup_column = column;
5279 if (icon_view->priv->cell_area)
5280 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5282 update_text_cell (icon_view);
5284 gtk_icon_view_invalidate_sizes (icon_view);
5286 g_object_notify (G_OBJECT (icon_view), "markup-column");
5290 * gtk_icon_view_get_markup_column:
5291 * @icon_view: A #GtkIconView.
5293 * Returns the column with markup text for @icon_view.
5295 * Returns: the markup column, or -1 if it's unset.
5300 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5302 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5304 return icon_view->priv->markup_column;
5308 * gtk_icon_view_set_pixbuf_column:
5309 * @icon_view: A #GtkIconView.
5310 * @column: A column in the currently used model, or -1 to disable
5312 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5313 * column must be of type #GDK_TYPE_PIXBUF
5318 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5321 if (column == icon_view->priv->pixbuf_column)
5325 icon_view->priv->pixbuf_column = -1;
5328 if (icon_view->priv->model != NULL)
5332 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5334 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5337 icon_view->priv->pixbuf_column = column;
5340 if (icon_view->priv->cell_area)
5341 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5343 update_pixbuf_cell (icon_view);
5345 gtk_icon_view_invalidate_sizes (icon_view);
5347 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5352 * gtk_icon_view_get_pixbuf_column:
5353 * @icon_view: A #GtkIconView.
5355 * Returns the column with pixbufs for @icon_view.
5357 * Returns: the pixbuf column, or -1 if it's unset.
5362 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5364 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5366 return icon_view->priv->pixbuf_column;
5370 * gtk_icon_view_select_path:
5371 * @icon_view: A #GtkIconView.
5372 * @path: The #GtkTreePath to be selected.
5374 * Selects the row at @path.
5379 gtk_icon_view_select_path (GtkIconView *icon_view,
5382 GtkIconViewItem *item = NULL;
5384 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5385 g_return_if_fail (icon_view->priv->model != NULL);
5386 g_return_if_fail (path != NULL);
5388 if (gtk_tree_path_get_depth (path) > 0)
5389 item = g_list_nth_data (icon_view->priv->items,
5390 gtk_tree_path_get_indices(path)[0]);
5393 _gtk_icon_view_select_item (icon_view, item);
5397 * gtk_icon_view_unselect_path:
5398 * @icon_view: A #GtkIconView.
5399 * @path: The #GtkTreePath to be unselected.
5401 * Unselects the row at @path.
5406 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5409 GtkIconViewItem *item;
5411 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5412 g_return_if_fail (icon_view->priv->model != NULL);
5413 g_return_if_fail (path != NULL);
5415 item = g_list_nth_data (icon_view->priv->items,
5416 gtk_tree_path_get_indices(path)[0]);
5421 _gtk_icon_view_unselect_item (icon_view, item);
5425 * gtk_icon_view_get_selected_items:
5426 * @icon_view: A #GtkIconView.
5428 * Creates a list of paths of all selected items. Additionally, if you are
5429 * planning on modifying the model after calling this function, you may
5430 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5431 * To do this, you can use gtk_tree_row_reference_new().
5433 * To free the return value, use:
5435 * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
5438 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5443 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5446 GList *selected = NULL;
5448 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5450 for (list = icon_view->priv->items; list != NULL; list = list->next)
5452 GtkIconViewItem *item = list->data;
5456 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5458 selected = g_list_prepend (selected, path);
5466 * gtk_icon_view_select_all:
5467 * @icon_view: A #GtkIconView.
5469 * Selects all the icons. @icon_view must has its selection mode set
5470 * to #GTK_SELECTION_MULTIPLE.
5475 gtk_icon_view_select_all (GtkIconView *icon_view)
5478 gboolean dirty = FALSE;
5480 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5482 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5485 for (items = icon_view->priv->items; items; items = items->next)
5487 GtkIconViewItem *item = items->data;
5489 if (!item->selected)
5492 item->selected = TRUE;
5493 gtk_icon_view_queue_draw_item (icon_view, item);
5498 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5502 * gtk_icon_view_unselect_all:
5503 * @icon_view: A #GtkIconView.
5505 * Unselects all the icons.
5510 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5512 gboolean dirty = FALSE;
5514 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5516 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5519 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5522 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5526 * gtk_icon_view_path_is_selected:
5527 * @icon_view: A #GtkIconView.
5528 * @path: A #GtkTreePath to check selection on.
5530 * Returns %TRUE if the icon pointed to by @path is currently
5531 * selected. If @path does not point to a valid location, %FALSE is returned.
5533 * Return value: %TRUE if @path is selected.
5538 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5541 GtkIconViewItem *item;
5543 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5544 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5545 g_return_val_if_fail (path != NULL, FALSE);
5547 item = g_list_nth_data (icon_view->priv->items,
5548 gtk_tree_path_get_indices(path)[0]);
5553 return item->selected;
5557 * gtk_icon_view_get_item_row:
5558 * @icon_view: a #GtkIconView
5559 * @path: the #GtkTreePath of the item
5561 * Gets the row in which the item @path is currently
5562 * displayed. Row numbers start at 0.
5564 * Returns: The row in which the item is displayed
5569 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5572 GtkIconViewItem *item;
5574 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5575 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5576 g_return_val_if_fail (path != NULL, -1);
5578 item = g_list_nth_data (icon_view->priv->items,
5579 gtk_tree_path_get_indices(path)[0]);
5588 * gtk_icon_view_get_item_column:
5589 * @icon_view: a #GtkIconView
5590 * @path: the #GtkTreePath of the item
5592 * Gets the column in which the item @path is currently
5593 * displayed. Column numbers start at 0.
5595 * Returns: The column in which the item is displayed
5600 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5603 GtkIconViewItem *item;
5605 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5606 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5607 g_return_val_if_fail (path != NULL, -1);
5609 item = g_list_nth_data (icon_view->priv->items,
5610 gtk_tree_path_get_indices(path)[0]);
5619 * gtk_icon_view_item_activated:
5620 * @icon_view: A #GtkIconView
5621 * @path: The #GtkTreePath to be activated
5623 * Activates the item determined by @path.
5628 gtk_icon_view_item_activated (GtkIconView *icon_view,
5631 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5632 g_return_if_fail (path != NULL);
5634 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5638 * gtk_icon_view_set_item_orientation:
5639 * @icon_view: a #GtkIconView
5640 * @orientation: the relative position of texts and icons
5642 * Sets the ::item-orientation property which determines whether the labels
5643 * are drawn beside the icons instead of below.
5648 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5649 GtkOrientation orientation)
5651 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5653 if (icon_view->priv->item_orientation != orientation)
5655 icon_view->priv->item_orientation = orientation;
5657 if (icon_view->priv->cell_area)
5659 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5660 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5661 icon_view->priv->item_orientation);
5663 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5666 gtk_icon_view_invalidate_sizes (icon_view);
5668 update_text_cell (icon_view);
5669 update_pixbuf_cell (icon_view);
5671 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5676 * gtk_icon_view_get_item_orientation:
5677 * @icon_view: a #GtkIconView
5679 * Returns the value of the ::item-orientation property which determines
5680 * whether the labels are drawn beside the icons instead of below.
5682 * Return value: the relative position of texts and icons
5687 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5689 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5690 GTK_ORIENTATION_VERTICAL);
5692 return icon_view->priv->item_orientation;
5696 * gtk_icon_view_set_columns:
5697 * @icon_view: a #GtkIconView
5698 * @columns: the number of columns
5700 * Sets the ::columns property which determines in how
5701 * many columns the icons are arranged. If @columns is
5702 * -1, the number of columns will be chosen automatically
5703 * to fill the available area.
5708 gtk_icon_view_set_columns (GtkIconView *icon_view,
5711 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5713 if (icon_view->priv->columns != columns)
5715 icon_view->priv->columns = columns;
5717 if (icon_view->priv->cell_area)
5718 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5720 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5722 g_object_notify (G_OBJECT (icon_view), "columns");
5727 * gtk_icon_view_get_columns:
5728 * @icon_view: a #GtkIconView
5730 * Returns the value of the ::columns property.
5732 * Return value: the number of columns, or -1
5737 gtk_icon_view_get_columns (GtkIconView *icon_view)
5739 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5741 return icon_view->priv->columns;
5745 * gtk_icon_view_set_item_width:
5746 * @icon_view: a #GtkIconView
5747 * @item_width: the width for each item
5749 * Sets the ::item-width property which specifies the width
5750 * to use for each item. If it is set to -1, the icon view will
5751 * automatically determine a suitable item size.
5756 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5759 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5761 if (icon_view->priv->item_width != item_width)
5763 icon_view->priv->item_width = item_width;
5765 if (icon_view->priv->cell_area)
5766 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5768 gtk_icon_view_invalidate_sizes (icon_view);
5770 update_text_cell (icon_view);
5772 g_object_notify (G_OBJECT (icon_view), "item-width");
5777 * gtk_icon_view_get_item_width:
5778 * @icon_view: a #GtkIconView
5780 * Returns the value of the ::item-width property.
5782 * Return value: the width of a single item, or -1
5787 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5789 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5791 return icon_view->priv->item_width;
5796 * gtk_icon_view_set_spacing:
5797 * @icon_view: a #GtkIconView
5798 * @spacing: the spacing
5800 * Sets the ::spacing property which specifies the space
5801 * which is inserted between the cells (i.e. the icon and
5802 * the text) of an item.
5807 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5810 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5812 if (icon_view->priv->spacing != spacing)
5814 icon_view->priv->spacing = spacing;
5816 if (icon_view->priv->cell_area)
5817 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5819 gtk_icon_view_invalidate_sizes (icon_view);
5821 g_object_notify (G_OBJECT (icon_view), "spacing");
5826 * gtk_icon_view_get_spacing:
5827 * @icon_view: a #GtkIconView
5829 * Returns the value of the ::spacing property.
5831 * Return value: the space between cells
5836 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5838 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5840 return icon_view->priv->spacing;
5844 * gtk_icon_view_set_row_spacing:
5845 * @icon_view: a #GtkIconView
5846 * @row_spacing: the row spacing
5848 * Sets the ::row-spacing property which specifies the space
5849 * which is inserted between the rows of the icon view.
5854 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5857 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5859 if (icon_view->priv->row_spacing != row_spacing)
5861 icon_view->priv->row_spacing = row_spacing;
5863 if (icon_view->priv->cell_area)
5864 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5866 gtk_icon_view_invalidate_sizes (icon_view);
5868 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5873 * gtk_icon_view_get_row_spacing:
5874 * @icon_view: a #GtkIconView
5876 * Returns the value of the ::row-spacing property.
5878 * Return value: the space between rows
5883 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5885 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5887 return icon_view->priv->row_spacing;
5891 * gtk_icon_view_set_column_spacing:
5892 * @icon_view: a #GtkIconView
5893 * @column_spacing: the column spacing
5895 * Sets the ::column-spacing property which specifies the space
5896 * which is inserted between the columns of the icon view.
5901 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5902 gint column_spacing)
5904 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5906 if (icon_view->priv->column_spacing != column_spacing)
5908 icon_view->priv->column_spacing = column_spacing;
5910 if (icon_view->priv->cell_area)
5911 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5913 gtk_icon_view_invalidate_sizes (icon_view);
5915 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5920 * gtk_icon_view_get_column_spacing:
5921 * @icon_view: a #GtkIconView
5923 * Returns the value of the ::column-spacing property.
5925 * Return value: the space between columns
5930 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5932 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5934 return icon_view->priv->column_spacing;
5938 * gtk_icon_view_set_margin:
5939 * @icon_view: a #GtkIconView
5940 * @margin: the margin
5942 * Sets the ::margin property which specifies the space
5943 * which is inserted at the top, bottom, left and right
5949 gtk_icon_view_set_margin (GtkIconView *icon_view,
5952 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5954 if (icon_view->priv->margin != margin)
5956 icon_view->priv->margin = margin;
5958 if (icon_view->priv->cell_area)
5959 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5961 gtk_icon_view_invalidate_sizes (icon_view);
5963 g_object_notify (G_OBJECT (icon_view), "margin");
5968 * gtk_icon_view_get_margin:
5969 * @icon_view: a #GtkIconView
5971 * Returns the value of the ::margin property.
5973 * Return value: the space at the borders
5978 gtk_icon_view_get_margin (GtkIconView *icon_view)
5980 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5982 return icon_view->priv->margin;
5986 * gtk_icon_view_set_item_padding:
5987 * @icon_view: a #GtkIconView
5988 * @item_padding: the item padding
5990 * Sets the #GtkIconView:item-padding property which specifies the padding
5991 * around each of the icon view's items.
5996 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5999 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6001 if (icon_view->priv->item_padding != item_padding)
6003 icon_view->priv->item_padding = item_padding;
6005 if (icon_view->priv->cell_area)
6006 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
6008 gtk_icon_view_invalidate_sizes (icon_view);
6010 g_object_notify (G_OBJECT (icon_view), "item-padding");
6015 * gtk_icon_view_get_item_padding:
6016 * @icon_view: a #GtkIconView
6018 * Returns the value of the ::item-padding property.
6020 * Return value: the padding around items
6025 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6027 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6029 return icon_view->priv->item_padding;
6032 /* Get/set whether drag_motion requested the drag data and
6033 * drag_data_received should thus not actually insert the data,
6034 * since the data doesn't result from a drop.
6037 set_status_pending (GdkDragContext *context,
6038 GdkDragAction suggested_action)
6040 g_object_set_data (G_OBJECT (context),
6041 I_("gtk-icon-view-status-pending"),
6042 GINT_TO_POINTER (suggested_action));
6045 static GdkDragAction
6046 get_status_pending (GdkDragContext *context)
6048 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6049 "gtk-icon-view-status-pending"));
6053 unset_reorderable (GtkIconView *icon_view)
6055 if (icon_view->priv->reorderable)
6057 icon_view->priv->reorderable = FALSE;
6058 g_object_notify (G_OBJECT (icon_view), "reorderable");
6063 set_source_row (GdkDragContext *context,
6064 GtkTreeModel *model,
6065 GtkTreePath *source_row)
6068 g_object_set_data_full (G_OBJECT (context),
6069 I_("gtk-icon-view-source-row"),
6070 gtk_tree_row_reference_new (model, source_row),
6071 (GDestroyNotify) gtk_tree_row_reference_free);
6073 g_object_set_data_full (G_OBJECT (context),
6074 I_("gtk-icon-view-source-row"),
6079 get_source_row (GdkDragContext *context)
6081 GtkTreeRowReference *ref;
6083 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6086 return gtk_tree_row_reference_get_path (ref);
6093 GtkTreeRowReference *dest_row;
6094 gboolean empty_view_drop;
6095 gboolean drop_append_mode;
6099 dest_row_free (gpointer data)
6101 DestRow *dr = (DestRow *)data;
6103 gtk_tree_row_reference_free (dr->dest_row);
6108 set_dest_row (GdkDragContext *context,
6109 GtkTreeModel *model,
6110 GtkTreePath *dest_row,
6111 gboolean empty_view_drop,
6112 gboolean drop_append_mode)
6118 g_object_set_data_full (G_OBJECT (context),
6119 I_("gtk-icon-view-dest-row"),
6124 dr = g_new0 (DestRow, 1);
6126 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6127 dr->empty_view_drop = empty_view_drop;
6128 dr->drop_append_mode = drop_append_mode;
6129 g_object_set_data_full (G_OBJECT (context),
6130 I_("gtk-icon-view-dest-row"),
6131 dr, (GDestroyNotify) dest_row_free);
6135 get_dest_row (GdkDragContext *context)
6139 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6143 GtkTreePath *path = NULL;
6146 path = gtk_tree_row_reference_get_path (dr->dest_row);
6147 else if (dr->empty_view_drop)
6148 path = gtk_tree_path_new_from_indices (0, -1);
6152 if (path && dr->drop_append_mode)
6153 gtk_tree_path_next (path);
6162 check_model_dnd (GtkTreeModel *model,
6163 GType required_iface,
6164 const gchar *signal)
6166 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6168 g_warning ("You must override the default '%s' handler "
6169 "on GtkIconView when using models that don't support "
6170 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6171 "is to connect to '%s' and call "
6172 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6173 "the default handler from running. Look at the source code "
6174 "for the default handler in gtkiconview.c to get an idea what "
6175 "your handler should do. (gtkiconview.c is in the GTK+ source "
6176 "code.) If you're using GTK+ from a language other than C, "
6177 "there may be a more natural way to override default handlers, e.g. via derivation.",
6178 signal, g_type_name (required_iface), signal);
6186 remove_scroll_timeout (GtkIconView *icon_view)
6188 if (icon_view->priv->scroll_timeout_id != 0)
6190 g_source_remove (icon_view->priv->scroll_timeout_id);
6192 icon_view->priv->scroll_timeout_id = 0;
6197 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6201 gint px, py, width, height;
6202 gint hoffset, voffset;
6204 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6206 gdk_window_get_device_position (window, device, &px, &py, NULL);
6207 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6209 /* see if we are near the edge. */
6210 voffset = py - 2 * SCROLL_EDGE_SIZE;
6212 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6214 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6216 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6219 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6220 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6223 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6224 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6228 GtkIconView *icon_view;
6233 drag_scroll_timeout (gpointer datap)
6235 DragScrollData *data = datap;
6237 gtk_icon_view_autoscroll (data->icon_view, data->device);
6243 drag_scroll_data_free (DragScrollData *data)
6245 g_slice_free (DragScrollData, data);
6249 set_destination (GtkIconView *icon_view,
6250 GdkDragContext *context,
6253 GdkDragAction *suggested_action,
6257 GtkTreePath *path = NULL;
6258 GtkIconViewDropPosition pos;
6259 GtkIconViewDropPosition old_pos;
6260 GtkTreePath *old_dest_path = NULL;
6261 gboolean can_drop = FALSE;
6263 widget = GTK_WIDGET (icon_view);
6265 *suggested_action = 0;
6268 if (!icon_view->priv->dest_set)
6270 /* someone unset us as a drag dest, note that if
6271 * we return FALSE drag_leave isn't called
6274 gtk_icon_view_set_drag_dest_item (icon_view,
6276 GTK_ICON_VIEW_DROP_LEFT);
6278 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6280 return FALSE; /* no longer a drop site */
6283 *target = gtk_drag_dest_find_target (widget, context,
6284 gtk_drag_dest_get_target_list (widget));
6285 if (*target == GDK_NONE)
6288 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6291 GtkTreeModel *model;
6293 /* the row got dropped on empty space, let's setup a special case
6297 gtk_tree_path_free (path);
6299 model = gtk_icon_view_get_model (icon_view);
6301 n_children = gtk_tree_model_iter_n_children (model, NULL);
6304 pos = GTK_ICON_VIEW_DROP_BELOW;
6305 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6309 pos = GTK_ICON_VIEW_DROP_ABOVE;
6310 path = gtk_tree_path_new_from_indices (0, -1);
6320 gtk_icon_view_get_drag_dest_item (icon_view,
6325 gtk_tree_path_free (old_dest_path);
6327 if (TRUE /* FIXME if the location droppable predicate */)
6335 GtkWidget *source_widget;
6337 *suggested_action = gdk_drag_context_get_suggested_action (context);
6338 source_widget = gtk_drag_get_source_widget (context);
6340 if (source_widget == widget)
6342 /* Default to MOVE, unless the user has
6343 * pressed ctrl or shift to affect available actions
6345 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6346 *suggested_action = GDK_ACTION_MOVE;
6349 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6354 /* can't drop here */
6355 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6357 GTK_ICON_VIEW_DROP_LEFT);
6361 gtk_tree_path_free (path);
6367 get_logical_destination (GtkIconView *icon_view,
6368 gboolean *drop_append_mode)
6370 /* adjust path to point to the row the drop goes in front of */
6371 GtkTreePath *path = NULL;
6372 GtkIconViewDropPosition pos;
6374 *drop_append_mode = FALSE;
6376 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6381 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6382 pos == GTK_ICON_VIEW_DROP_BELOW)
6385 GtkTreeModel *model = icon_view->priv->model;
6387 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6388 !gtk_tree_model_iter_next (model, &iter))
6389 *drop_append_mode = TRUE;
6392 *drop_append_mode = FALSE;
6393 gtk_tree_path_next (path);
6401 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6402 GdkEventMotion *event)
6404 GtkWidget *widget = GTK_WIDGET (icon_view);
6405 GdkDragContext *context;
6406 GtkTreePath *path = NULL;
6408 GtkTreeModel *model;
6409 gboolean retval = FALSE;
6411 if (!icon_view->priv->source_set)
6414 if (icon_view->priv->pressed_button < 0)
6417 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6418 icon_view->priv->press_start_x,
6419 icon_view->priv->press_start_y,
6420 event->x, event->y))
6423 model = gtk_icon_view_get_model (icon_view);
6428 button = icon_view->priv->pressed_button;
6429 icon_view->priv->pressed_button = -1;
6431 path = gtk_icon_view_get_path_at_pos (icon_view,
6432 icon_view->priv->press_start_x,
6433 icon_view->priv->press_start_y);
6438 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6439 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6443 /* FIXME Check whether we're a start button, if not return FALSE and
6447 /* Now we can begin the drag */
6451 context = gtk_drag_begin (widget,
6452 gtk_drag_source_get_target_list (widget),
6453 icon_view->priv->source_actions,
6457 set_source_row (context, model, path);
6461 gtk_tree_path_free (path);
6466 /* Source side drag signals */
6468 gtk_icon_view_drag_begin (GtkWidget *widget,
6469 GdkDragContext *context)
6471 GtkIconView *icon_view;
6472 GtkIconViewItem *item;
6473 cairo_surface_t *icon;
6477 icon_view = GTK_ICON_VIEW (widget);
6479 /* if the user uses a custom DnD impl, we don't set the icon here */
6480 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6483 item = _gtk_icon_view_get_item_at_coords (icon_view,
6484 icon_view->priv->press_start_x,
6485 icon_view->priv->press_start_y,
6489 g_return_if_fail (item != NULL);
6491 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6492 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6494 path = gtk_tree_path_new_from_indices (item->index, -1);
6495 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6496 gtk_tree_path_free (path);
6498 cairo_surface_set_device_offset (icon, -x, -y);
6500 gtk_drag_set_icon_surface (context, icon);
6502 cairo_surface_destroy (icon);
6506 gtk_icon_view_drag_end (GtkWidget *widget,
6507 GdkDragContext *context)
6513 gtk_icon_view_drag_data_get (GtkWidget *widget,
6514 GdkDragContext *context,
6515 GtkSelectionData *selection_data,
6519 GtkIconView *icon_view;
6520 GtkTreeModel *model;
6521 GtkTreePath *source_row;
6523 icon_view = GTK_ICON_VIEW (widget);
6524 model = gtk_icon_view_get_model (icon_view);
6529 if (!icon_view->priv->source_set)
6532 source_row = get_source_row (context);
6534 if (source_row == NULL)
6537 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6538 * any model; for DragSource models there are some other targets
6542 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6543 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6548 /* If drag_data_get does nothing, try providing row data. */
6549 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6550 gtk_tree_set_row_drag_data (selection_data,
6555 gtk_tree_path_free (source_row);
6559 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6560 GdkDragContext *context)
6562 GtkTreeModel *model;
6563 GtkIconView *icon_view;
6564 GtkTreePath *source_row;
6566 icon_view = GTK_ICON_VIEW (widget);
6567 model = gtk_icon_view_get_model (icon_view);
6569 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6572 if (!icon_view->priv->source_set)
6575 source_row = get_source_row (context);
6577 if (source_row == NULL)
6580 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6583 gtk_tree_path_free (source_row);
6585 set_source_row (context, NULL, NULL);
6588 /* Target side drag signals */
6590 gtk_icon_view_drag_leave (GtkWidget *widget,
6591 GdkDragContext *context,
6594 GtkIconView *icon_view;
6596 icon_view = GTK_ICON_VIEW (widget);
6598 /* unset any highlight row */
6599 gtk_icon_view_set_drag_dest_item (icon_view,
6601 GTK_ICON_VIEW_DROP_LEFT);
6603 remove_scroll_timeout (icon_view);
6607 gtk_icon_view_drag_motion (GtkWidget *widget,
6608 GdkDragContext *context,
6613 GtkTreePath *path = NULL;
6614 GtkIconViewDropPosition pos;
6615 GtkIconView *icon_view;
6616 GdkDragAction suggested_action = 0;
6620 icon_view = GTK_ICON_VIEW (widget);
6622 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6625 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6627 /* we only know this *after* set_desination_row */
6628 empty = icon_view->priv->empty_view_drop;
6630 if (path == NULL && !empty)
6632 /* Can't drop here. */
6633 gdk_drag_status (context, 0, time);
6637 if (icon_view->priv->scroll_timeout_id == 0)
6639 DragScrollData *data = g_slice_new (DragScrollData);
6640 data->icon_view = icon_view;
6641 data->device = gdk_drag_context_get_device (context);
6643 icon_view->priv->scroll_timeout_id =
6644 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6647 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6649 /* Request data so we can use the source row when
6650 * determining whether to accept the drop
6652 set_status_pending (context, suggested_action);
6653 gtk_drag_get_data (widget, context, target, time);
6657 set_status_pending (context, 0);
6658 gdk_drag_status (context, suggested_action, time);
6663 gtk_tree_path_free (path);
6669 gtk_icon_view_drag_drop (GtkWidget *widget,
6670 GdkDragContext *context,
6675 GtkIconView *icon_view;
6677 GdkDragAction suggested_action = 0;
6678 GdkAtom target = GDK_NONE;
6679 GtkTreeModel *model;
6680 gboolean drop_append_mode;
6682 icon_view = GTK_ICON_VIEW (widget);
6683 model = gtk_icon_view_get_model (icon_view);
6685 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6687 if (!icon_view->priv->dest_set)
6690 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6693 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6696 path = get_logical_destination (icon_view, &drop_append_mode);
6698 if (target != GDK_NONE && path != NULL)
6700 /* in case a motion had requested drag data, change things so we
6701 * treat drag data receives as a drop.
6703 set_status_pending (context, 0);
6704 set_dest_row (context, model, path,
6705 icon_view->priv->empty_view_drop, drop_append_mode);
6709 gtk_tree_path_free (path);
6711 /* Unset this thing */
6712 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6714 if (target != GDK_NONE)
6716 gtk_drag_get_data (widget, context, target, time);
6724 gtk_icon_view_drag_data_received (GtkWidget *widget,
6725 GdkDragContext *context,
6728 GtkSelectionData *selection_data,
6733 gboolean accepted = FALSE;
6734 GtkTreeModel *model;
6735 GtkIconView *icon_view;
6736 GtkTreePath *dest_row;
6737 GdkDragAction suggested_action;
6738 gboolean drop_append_mode;
6740 icon_view = GTK_ICON_VIEW (widget);
6741 model = gtk_icon_view_get_model (icon_view);
6743 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6746 if (!icon_view->priv->dest_set)
6749 suggested_action = get_status_pending (context);
6751 if (suggested_action)
6753 /* We are getting this data due to a request in drag_motion,
6754 * rather than due to a request in drag_drop, so we are just
6755 * supposed to call drag_status, not actually paste in the
6758 path = get_logical_destination (icon_view, &drop_append_mode);
6761 suggested_action = 0;
6763 if (suggested_action)
6765 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6768 suggested_action = 0;
6771 gdk_drag_status (context, suggested_action, time);
6774 gtk_tree_path_free (path);
6776 /* If you can't drop, remove user drop indicator until the next motion */
6777 if (suggested_action == 0)
6778 gtk_icon_view_set_drag_dest_item (icon_view,
6780 GTK_ICON_VIEW_DROP_LEFT);
6785 dest_row = get_dest_row (context);
6787 if (dest_row == NULL)
6790 if (gtk_selection_data_get_length (selection_data) >= 0)
6792 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6798 gtk_drag_finish (context,
6800 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6803 gtk_tree_path_free (dest_row);
6806 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6809 /* Drag-and-Drop support */
6811 * gtk_icon_view_enable_model_drag_source:
6812 * @icon_view: a #GtkIconView
6813 * @start_button_mask: Mask of allowed buttons to start drag
6814 * @targets: (array length=n_targets): the table of targets that the drag will
6816 * @n_targets: the number of items in @targets
6817 * @actions: the bitmask of possible actions for a drag from this
6820 * Turns @icon_view into a drag source for automatic DND. Calling this
6821 * method sets #GtkIconView:reorderable to %FALSE.
6826 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6827 GdkModifierType start_button_mask,
6828 const GtkTargetEntry *targets,
6830 GdkDragAction actions)
6832 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6834 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6836 icon_view->priv->start_button_mask = start_button_mask;
6837 icon_view->priv->source_actions = actions;
6839 icon_view->priv->source_set = TRUE;
6841 unset_reorderable (icon_view);
6845 * gtk_icon_view_enable_model_drag_dest:
6846 * @icon_view: a #GtkIconView
6847 * @targets: (array length=n_targets): the table of targets that the drag will
6849 * @n_targets: the number of items in @targets
6850 * @actions: the bitmask of possible actions for a drag to this
6853 * Turns @icon_view into a drop destination for automatic DND. Calling this
6854 * method sets #GtkIconView:reorderable to %FALSE.
6859 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6860 const GtkTargetEntry *targets,
6862 GdkDragAction actions)
6864 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6866 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6868 icon_view->priv->dest_actions = actions;
6870 icon_view->priv->dest_set = TRUE;
6872 unset_reorderable (icon_view);
6876 * gtk_icon_view_unset_model_drag_source:
6877 * @icon_view: a #GtkIconView
6879 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6880 * method sets #GtkIconView:reorderable to %FALSE.
6885 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6887 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6889 if (icon_view->priv->source_set)
6891 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6892 icon_view->priv->source_set = FALSE;
6895 unset_reorderable (icon_view);
6899 * gtk_icon_view_unset_model_drag_dest:
6900 * @icon_view: a #GtkIconView
6902 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6903 * method sets #GtkIconView:reorderable to %FALSE.
6908 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6910 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6912 if (icon_view->priv->dest_set)
6914 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6915 icon_view->priv->dest_set = FALSE;
6918 unset_reorderable (icon_view);
6921 /* These are useful to implement your own custom stuff. */
6923 * gtk_icon_view_set_drag_dest_item:
6924 * @icon_view: a #GtkIconView
6925 * @path: (allow-none): The path of the item to highlight, or %NULL.
6926 * @pos: Specifies where to drop, relative to the item
6928 * Sets the item that is highlighted for feedback.
6933 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6935 GtkIconViewDropPosition pos)
6937 /* Note; this function is exported to allow a custom DND
6938 * implementation, so it can't touch TreeViewDragInfo
6941 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6943 if (icon_view->priv->dest_item)
6945 GtkTreePath *current_path;
6946 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6947 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6948 icon_view->priv->dest_item = NULL;
6950 gtk_icon_view_queue_draw_path (icon_view, current_path);
6951 gtk_tree_path_free (current_path);
6954 /* special case a drop on an empty model */
6955 icon_view->priv->empty_view_drop = FALSE;
6956 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6957 && gtk_tree_path_get_depth (path) == 1
6958 && gtk_tree_path_get_indices (path)[0] == 0)
6962 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6965 if (n_children == 0)
6966 icon_view->priv->empty_view_drop = TRUE;
6969 icon_view->priv->dest_pos = pos;
6973 icon_view->priv->dest_item =
6974 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6975 icon_view->priv->model, path);
6977 gtk_icon_view_queue_draw_path (icon_view, path);
6982 * gtk_icon_view_get_drag_dest_item:
6983 * @icon_view: a #GtkIconView
6984 * @path: (out) (allow-none): Return location for the path of
6985 * the highlighted item, or %NULL.
6986 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6988 * Gets information about the item that is highlighted for feedback.
6993 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6995 GtkIconViewDropPosition *pos)
6997 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7001 if (icon_view->priv->dest_item)
7002 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7008 *pos = icon_view->priv->dest_pos;
7012 * gtk_icon_view_get_dest_item_at_pos:
7013 * @icon_view: a #GtkIconView
7014 * @drag_x: the position to determine the destination item for
7015 * @drag_y: the position to determine the destination item for
7016 * @path: (out) (allow-none): Return location for the path of the item,
7018 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
7020 * Determines the destination item for a given position.
7022 * Return value: whether there is an item at the given position.
7027 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7031 GtkIconViewDropPosition *pos)
7033 GtkIconViewItem *item;
7035 /* Note; this function is exported to allow a custom DND
7036 * implementation, so it can't touch TreeViewDragInfo
7039 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7040 g_return_val_if_fail (drag_x >= 0, FALSE);
7041 g_return_val_if_fail (drag_y >= 0, FALSE);
7042 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7048 item = _gtk_icon_view_get_item_at_coords (icon_view,
7049 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
7050 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
7057 *path = gtk_tree_path_new_from_indices (item->index, -1);
7061 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
7062 *pos = GTK_ICON_VIEW_DROP_LEFT;
7063 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
7064 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7065 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
7066 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7067 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
7068 *pos = GTK_ICON_VIEW_DROP_BELOW;
7070 *pos = GTK_ICON_VIEW_DROP_INTO;
7077 * gtk_icon_view_create_drag_icon:
7078 * @icon_view: a #GtkIconView
7079 * @path: a #GtkTreePath in @icon_view
7081 * Creates a #cairo_surface_t representation of the item at @path.
7082 * This image is used for a drag icon.
7084 * Return value: (transfer full): a newly-allocated surface of the drag icon.
7089 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7093 GtkStyleContext *context;
7095 cairo_surface_t *surface;
7099 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7100 g_return_val_if_fail (path != NULL, NULL);
7102 widget = GTK_WIDGET (icon_view);
7103 context = gtk_widget_get_style_context (widget);
7105 if (!gtk_widget_get_realized (widget))
7108 index = gtk_tree_path_get_indices (path)[0];
7110 for (l = icon_view->priv->items; l; l = l->next)
7112 GtkIconViewItem *item = l->data;
7114 if (index == item->index)
7116 GdkRectangle rect = {
7117 item->cell_area.x - icon_view->priv->item_padding,
7118 item->cell_area.y - icon_view->priv->item_padding,
7119 item->cell_area.width + icon_view->priv->item_padding * 2,
7120 item->cell_area.height + icon_view->priv->item_padding * 2
7123 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7124 CAIRO_CONTENT_COLOR,
7128 cr = cairo_create (surface);
7129 cairo_set_line_width (cr, 1.);
7131 gtk_render_background (context, cr, 0, 0,
7132 rect.width + 2, rect.height + 2);
7136 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7139 gtk_icon_view_paint_item (icon_view, cr, item,
7140 icon_view->priv->item_padding + 1,
7141 icon_view->priv->item_padding + 1, FALSE);
7145 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7146 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7159 * gtk_icon_view_get_reorderable:
7160 * @icon_view: a #GtkIconView
7162 * Retrieves whether the user can reorder the list via drag-and-drop.
7163 * See gtk_icon_view_set_reorderable().
7165 * Return value: %TRUE if the list can be reordered.
7170 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7172 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7174 return icon_view->priv->reorderable;
7177 static const GtkTargetEntry item_targets[] = {
7178 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7183 * gtk_icon_view_set_reorderable:
7184 * @icon_view: A #GtkIconView.
7185 * @reorderable: %TRUE, if the list of items can be reordered.
7187 * This function is a convenience function to allow you to reorder models that
7188 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7189 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7190 * the user can reorder the model by dragging and dropping rows. The
7191 * developer can listen to these changes by connecting to the model's
7192 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7193 * the icon view as a drag source and destination. Therefore, drag and
7194 * drop can not be used in a reorderable view for any other purpose.
7196 * This function does not give you any degree of control over the order -- any
7197 * reordering is allowed. If more control is needed, you should probably
7198 * handle drag and drop manually.
7203 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7204 gboolean reorderable)
7206 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7208 reorderable = reorderable != FALSE;
7210 if (icon_view->priv->reorderable == reorderable)
7215 gtk_icon_view_enable_model_drag_source (icon_view,
7218 G_N_ELEMENTS (item_targets),
7220 gtk_icon_view_enable_model_drag_dest (icon_view,
7222 G_N_ELEMENTS (item_targets),
7227 gtk_icon_view_unset_model_drag_source (icon_view);
7228 gtk_icon_view_unset_model_drag_dest (icon_view);
7231 icon_view->priv->reorderable = reorderable;
7233 g_object_notify (G_OBJECT (icon_view), "reorderable");
7237 * gtk_icon_view_set_activate_on_single_click:
7238 * @icon_view: a #GtkIconView
7239 * @single: %TRUE to emit item-activated on a single click
7241 * Causes the #GtkIconView::item-activated signal to be emitted on
7242 * a single click instead of a double click.
7247 gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
7250 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7252 single = single != FALSE;
7254 if (icon_view->priv->activate_on_single_click == single)
7257 icon_view->priv->activate_on_single_click = single;
7258 g_object_notify (G_OBJECT (icon_view), "activate-on-single-click");
7262 * gtk_icon_view_get_activate_on_single_click:
7263 * @icon_view: a #GtkIconView
7265 * Gets the setting set by gtk_icon_view_set_activate_on_single_click().
7267 * Return value: %TRUE if item-activated will be emitted on a single click
7272 gtk_icon_view_get_activate_on_single_click (GtkIconView *icon_view)
7274 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7276 return icon_view->priv->activate_on_single_click;
7280 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7281 GtkBuilder *builder,
7283 const gchar *tagname,
7284 GMarkupParser *parser,
7287 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7288 tagname, parser, data))
7291 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7292 tagname, parser, data);
7296 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7297 GtkBuilder *builder,
7299 const gchar *tagname,
7302 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7303 child, tagname, data))
7304 parent_buildable_iface->custom_tag_end (buildable, builder,
7305 child, tagname, data);