2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gtkiconview.h"
25 #include "gtkiconviewprivate.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrenderer.h"
29 #include "gtkcellareabox.h"
30 #include "gtkcellareacontext.h"
31 #include "gtkcellrenderertext.h"
32 #include "gtkcellrendererpixbuf.h"
33 #include "gtkorientable.h"
34 #include "gtkmarshalers.h"
35 #include "gtkbindings.h"
39 #include "gtkaccessible.h"
40 #include "gtkwindow.h"
42 #include "gtkcombobox.h"
43 #include "gtkscrollable.h"
44 #include "gtksizerequest.h"
45 #include "gtktreednd.h"
46 #include "gtktypebuiltins.h"
47 #include "gtkprivate.h"
48 #include "a11y/gtkiconviewaccessible.h"
53 * @short_description: A widget which displays a list of icons in a grid
55 * #GtkIconView provides an alternative view on a #GtkTreeModel.
56 * It displays the model as a grid of icons with labels. Like
57 * #GtkTreeView, it allows to select one or multiple items
58 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
59 * In addition to selection with the arrow keys, #GtkIconView supports
60 * rubberband selection, which is controlled by dragging the pointer.
62 * Note that if the tree model is backed by an actual tree store (as
63 * opposed to a flat list where the mapping to icons is obvious),
64 * #GtkIconView will only display the first level of the tree and
65 * ignore the tree's branches.
68 #define SCROLL_EDGE_SIZE 15
70 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
72 typedef struct _GtkIconViewChild GtkIconViewChild;
73 struct _GtkIconViewChild
101 PROP_ITEM_ORIENTATION,
114 /* For scrollable interface */
122 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
123 static void gtk_icon_view_dispose (GObject *object);
124 static GObject *gtk_icon_view_constructor (GType type,
125 guint n_construct_properties,
126 GObjectConstructParam *construct_properties);
127 static void gtk_icon_view_set_property (GObject *object,
131 static void gtk_icon_view_get_property (GObject *object,
135 /* GtkWidget vfuncs */
136 static void gtk_icon_view_destroy (GtkWidget *widget);
137 static void gtk_icon_view_realize (GtkWidget *widget);
138 static void gtk_icon_view_unrealize (GtkWidget *widget);
139 static void gtk_icon_view_style_updated (GtkWidget *widget);
140 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
141 GtkStateFlags previous_state);
142 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
145 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
148 static void gtk_icon_view_size_allocate (GtkWidget *widget,
149 GtkAllocation *allocation);
150 static gboolean gtk_icon_view_draw (GtkWidget *widget,
152 static gboolean gtk_icon_view_motion (GtkWidget *widget,
153 GdkEventMotion *event);
154 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
155 GdkEventButton *event);
156 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
157 GdkEventButton *event);
158 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
160 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
164 /* GtkContainer vfuncs */
165 static void gtk_icon_view_remove (GtkContainer *container,
167 static void gtk_icon_view_forall (GtkContainer *container,
168 gboolean include_internals,
169 GtkCallback callback,
170 gpointer callback_data);
172 /* GtkIconView vfuncs */
173 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
174 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
175 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
176 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
177 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
179 /* Internal functions */
180 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
181 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
182 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
183 GtkAdjustment *adjustment);
184 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
185 GtkAdjustment *adjustment);
186 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
187 GtkIconView *icon_view);
188 static void gtk_icon_view_layout (GtkIconView *icon_view);
189 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
191 GtkIconViewItem *item,
194 gboolean draw_focus);
195 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
197 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
199 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
200 GtkIconViewItem *item);
201 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
202 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
206 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
207 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
208 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
209 GtkIconViewItem *item,
214 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
215 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
216 static void gtk_icon_view_update_rubberband (gpointer data);
217 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
218 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
219 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
222 GtkMovementStep step,
224 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
225 GtkMovementStep step,
227 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
229 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
231 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
233 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
235 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
236 GtkIconViewItem *item);
237 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
238 GtkIconViewItem *anchor,
239 GtkIconViewItem *cursor);
241 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
242 GtkCellArea *cell_area);
244 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
246 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
247 GtkIconViewItem *item);
249 static void gtk_icon_view_add_editable (GtkCellArea *area,
250 GtkCellRenderer *renderer,
251 GtkCellEditable *editable,
252 GdkRectangle *cell_area,
254 GtkIconView *icon_view);
255 static void gtk_icon_view_remove_editable (GtkCellArea *area,
256 GtkCellRenderer *renderer,
257 GtkCellEditable *editable,
258 GtkIconView *icon_view);
259 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
261 GtkIconView *icon_view);
262 static void update_text_cell (GtkIconView *icon_view);
263 static void update_pixbuf_cell (GtkIconView *icon_view);
265 /* Source side drag signals */
266 static void gtk_icon_view_drag_begin (GtkWidget *widget,
267 GdkDragContext *context);
268 static void gtk_icon_view_drag_end (GtkWidget *widget,
269 GdkDragContext *context);
270 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
271 GdkDragContext *context,
272 GtkSelectionData *selection_data,
275 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
276 GdkDragContext *context);
278 /* Target side drag signals */
279 static void gtk_icon_view_drag_leave (GtkWidget *widget,
280 GdkDragContext *context,
282 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
283 GdkDragContext *context,
287 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
288 GdkDragContext *context,
292 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
293 GdkDragContext *context,
296 GtkSelectionData *selection_data,
299 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
300 GdkEventMotion *event);
302 static void remove_scroll_timeout (GtkIconView *icon_view);
305 static GtkBuildableIface *parent_buildable_iface;
306 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
307 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
310 const gchar *tagname,
311 GMarkupParser *parser,
313 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
316 const gchar *tagname,
319 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
321 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
322 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
323 gtk_icon_view_cell_layout_init)
324 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
325 gtk_icon_view_buildable_init)
326 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
329 gtk_icon_view_class_init (GtkIconViewClass *klass)
331 GObjectClass *gobject_class;
332 GtkWidgetClass *widget_class;
333 GtkContainerClass *container_class;
334 GtkBindingSet *binding_set;
336 binding_set = gtk_binding_set_by_class (klass);
338 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
340 gobject_class = (GObjectClass *) klass;
341 widget_class = (GtkWidgetClass *) klass;
342 container_class = (GtkContainerClass *) klass;
344 gobject_class->constructor = gtk_icon_view_constructor;
345 gobject_class->dispose = gtk_icon_view_dispose;
346 gobject_class->set_property = gtk_icon_view_set_property;
347 gobject_class->get_property = gtk_icon_view_get_property;
349 widget_class->destroy = gtk_icon_view_destroy;
350 widget_class->realize = gtk_icon_view_realize;
351 widget_class->unrealize = gtk_icon_view_unrealize;
352 widget_class->style_updated = gtk_icon_view_style_updated;
353 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
354 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
355 widget_class->size_allocate = gtk_icon_view_size_allocate;
356 widget_class->draw = gtk_icon_view_draw;
357 widget_class->motion_notify_event = gtk_icon_view_motion;
358 widget_class->button_press_event = gtk_icon_view_button_press;
359 widget_class->button_release_event = gtk_icon_view_button_release;
360 widget_class->key_press_event = gtk_icon_view_key_press;
361 widget_class->key_release_event = gtk_icon_view_key_release;
362 widget_class->drag_begin = gtk_icon_view_drag_begin;
363 widget_class->drag_end = gtk_icon_view_drag_end;
364 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
365 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
366 widget_class->drag_leave = gtk_icon_view_drag_leave;
367 widget_class->drag_motion = gtk_icon_view_drag_motion;
368 widget_class->drag_drop = gtk_icon_view_drag_drop;
369 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
370 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
372 container_class->remove = gtk_icon_view_remove;
373 container_class->forall = gtk_icon_view_forall;
375 klass->select_all = gtk_icon_view_real_select_all;
376 klass->unselect_all = gtk_icon_view_real_unselect_all;
377 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
378 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
379 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
380 klass->move_cursor = gtk_icon_view_real_move_cursor;
384 * GtkIconView:selection-mode:
386 * The ::selection-mode property specifies the selection mode of
387 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
388 * is enabled, for the other modes, only keyboard selection is possible.
392 g_object_class_install_property (gobject_class,
394 g_param_spec_enum ("selection-mode",
395 P_("Selection mode"),
396 P_("The selection mode"),
397 GTK_TYPE_SELECTION_MODE,
398 GTK_SELECTION_SINGLE,
399 GTK_PARAM_READWRITE));
402 * GtkIconView:pixbuf-column:
404 * The ::pixbuf-column property contains the number of the model column
405 * containing the pixbufs which are displayed. The pixbuf column must be
406 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
407 * display of pixbufs.
411 g_object_class_install_property (gobject_class,
413 g_param_spec_int ("pixbuf-column",
415 P_("Model column used to retrieve the icon pixbuf from"),
417 GTK_PARAM_READWRITE));
420 * GtkIconView:text-column:
422 * The ::text-column property contains the number of the model column
423 * containing the texts which are displayed. The text column must be
424 * of type #G_TYPE_STRING. If this property and the :markup-column
425 * property are both set to -1, no texts are displayed.
429 g_object_class_install_property (gobject_class,
431 g_param_spec_int ("text-column",
433 P_("Model column used to retrieve the text from"),
435 GTK_PARAM_READWRITE));
439 * GtkIconView:markup-column:
441 * The ::markup-column property contains the number of the model column
442 * containing markup information to be displayed. The markup column must be
443 * of type #G_TYPE_STRING. If this property and the :text-column property
444 * are both set to column numbers, it overrides the text column.
445 * If both are set to -1, no texts are displayed.
449 g_object_class_install_property (gobject_class,
451 g_param_spec_int ("markup-column",
453 P_("Model column used to retrieve the text if using Pango markup"),
455 GTK_PARAM_READWRITE));
457 g_object_class_install_property (gobject_class,
459 g_param_spec_object ("model",
460 P_("Icon View Model"),
461 P_("The model for the icon view"),
463 GTK_PARAM_READWRITE));
466 * GtkIconView:columns:
468 * The columns property contains the number of the columns in which the
469 * items should be displayed. If it is -1, the number of columns will
470 * be chosen automatically to fill the available area.
474 g_object_class_install_property (gobject_class,
476 g_param_spec_int ("columns",
477 P_("Number of columns"),
478 P_("Number of columns to display"),
480 GTK_PARAM_READWRITE));
484 * GtkIconView:item-width:
486 * The item-width property specifies the width to use for each item.
487 * If it is set to -1, the icon view will automatically determine a
488 * suitable item size.
492 g_object_class_install_property (gobject_class,
494 g_param_spec_int ("item-width",
495 P_("Width for each item"),
496 P_("The width used for each item"),
498 GTK_PARAM_READWRITE));
501 * GtkIconView:spacing:
503 * The spacing property specifies the space which is inserted between
504 * the cells (i.e. the icon and the text) of an item.
508 g_object_class_install_property (gobject_class,
510 g_param_spec_int ("spacing",
512 P_("Space which is inserted between cells of an item"),
514 GTK_PARAM_READWRITE));
517 * GtkIconView:row-spacing:
519 * The row-spacing property specifies the space which is inserted between
520 * the rows of the icon view.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_int ("row-spacing",
528 P_("Space which is inserted between grid rows"),
530 GTK_PARAM_READWRITE));
533 * GtkIconView:column-spacing:
535 * The column-spacing property specifies the space which is inserted between
536 * the columns of the icon view.
540 g_object_class_install_property (gobject_class,
542 g_param_spec_int ("column-spacing",
543 P_("Column Spacing"),
544 P_("Space which is inserted between grid columns"),
546 GTK_PARAM_READWRITE));
549 * GtkIconView:margin:
551 * The margin property specifies the space which is inserted
552 * at the edges of the icon view.
556 g_object_class_install_property (gobject_class,
558 g_param_spec_int ("margin",
560 P_("Space which is inserted at the edges of the icon view"),
562 GTK_PARAM_READWRITE));
565 * GtkIconView:item-orientation:
567 * The item-orientation property specifies how the cells (i.e. the icon and
568 * the text) of the item are positioned relative to each other.
572 g_object_class_install_property (gobject_class,
573 PROP_ITEM_ORIENTATION,
574 g_param_spec_enum ("item-orientation",
575 P_("Item Orientation"),
576 P_("How the text and icon of each item are positioned relative to each other"),
577 GTK_TYPE_ORIENTATION,
578 GTK_ORIENTATION_VERTICAL,
579 GTK_PARAM_READWRITE));
582 * GtkIconView:reorderable:
584 * The reorderable property specifies if the items can be reordered
589 g_object_class_install_property (gobject_class,
591 g_param_spec_boolean ("reorderable",
593 P_("View is reorderable"),
597 g_object_class_install_property (gobject_class,
599 g_param_spec_int ("tooltip-column",
600 P_("Tooltip Column"),
601 P_("The column in the model containing the tooltip texts for the items"),
605 GTK_PARAM_READWRITE));
608 * GtkIconView:item-padding:
610 * The item-padding property specifies the padding around each
611 * of the icon view's item.
615 g_object_class_install_property (gobject_class,
617 g_param_spec_int ("item-padding",
619 P_("Padding around icon view items"),
621 GTK_PARAM_READWRITE));
624 * GtkIconView:cell-area:
626 * The #GtkCellArea used to layout cell renderers for this view.
628 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
629 * a #GtkCellAreaBox will be used.
633 g_object_class_install_property (gobject_class,
635 g_param_spec_object ("cell-area",
637 P_("The GtkCellArea used to layout cells"),
639 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
641 /* Scrollable interface properties */
642 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
643 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
644 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
645 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
647 /* Style properties */
648 gtk_widget_class_install_style_property (widget_class,
649 g_param_spec_boxed ("selection-box-color",
650 P_("Selection Box Color"),
651 P_("Color of the selection box"),
653 GTK_PARAM_READABLE));
655 gtk_widget_class_install_style_property (widget_class,
656 g_param_spec_uchar ("selection-box-alpha",
657 P_("Selection Box Alpha"),
658 P_("Opacity of the selection box"),
661 GTK_PARAM_READABLE));
665 * GtkIconView::item-activated:
666 * @iconview: the object on which the signal is emitted
667 * @path: the #GtkTreePath for the activated item
669 * The ::item-activated signal is emitted when the method
670 * gtk_icon_view_item_activated() is called or the user double
671 * clicks an item. It is also emitted when a non-editable item
672 * is selected and one of the keys: Space, Return or Enter is
675 icon_view_signals[ITEM_ACTIVATED] =
676 g_signal_new (I_("item-activated"),
677 G_TYPE_FROM_CLASS (gobject_class),
679 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
681 g_cclosure_marshal_VOID__BOXED,
686 * GtkIconView::selection-changed:
687 * @iconview: the object on which the signal is emitted
689 * The ::selection-changed signal is emitted when the selection
690 * (i.e. the set of selected items) changes.
692 icon_view_signals[SELECTION_CHANGED] =
693 g_signal_new (I_("selection-changed"),
694 G_TYPE_FROM_CLASS (gobject_class),
696 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
698 g_cclosure_marshal_VOID__VOID,
702 * GtkIconView::select-all:
703 * @iconview: the object on which the signal is emitted
705 * A <link linkend="keybinding-signals">keybinding signal</link>
706 * which gets emitted when the user selects all items.
708 * Applications should not connect to it, but may emit it with
709 * g_signal_emit_by_name() if they need to control selection
712 * The default binding for this signal is Ctrl-a.
714 icon_view_signals[SELECT_ALL] =
715 g_signal_new (I_("select-all"),
716 G_TYPE_FROM_CLASS (gobject_class),
717 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
718 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
720 g_cclosure_marshal_VOID__VOID,
724 * GtkIconView::unselect-all:
725 * @iconview: the object on which the signal is emitted
727 * A <link linkend="keybinding-signals">keybinding signal</link>
728 * which gets emitted when the user unselects all items.
730 * Applications should not connect to it, but may emit it with
731 * g_signal_emit_by_name() if they need to control selection
734 * The default binding for this signal is Ctrl-Shift-a.
736 icon_view_signals[UNSELECT_ALL] =
737 g_signal_new (I_("unselect-all"),
738 G_TYPE_FROM_CLASS (gobject_class),
739 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
740 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
742 g_cclosure_marshal_VOID__VOID,
746 * GtkIconView::select-cursor-item:
747 * @iconview: the object on which the signal is emitted
749 * A <link linkend="keybinding-signals">keybinding signal</link>
750 * which gets emitted when the user selects the item that is currently
753 * Applications should not connect to it, but may emit it with
754 * g_signal_emit_by_name() if they need to control selection
757 * There is no default binding for this signal.
759 icon_view_signals[SELECT_CURSOR_ITEM] =
760 g_signal_new (I_("select-cursor-item"),
761 G_TYPE_FROM_CLASS (gobject_class),
762 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
763 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
765 g_cclosure_marshal_VOID__VOID,
769 * GtkIconView::toggle-cursor-item:
770 * @iconview: the object on which the signal is emitted
772 * A <link linkend="keybinding-signals">keybinding signal</link>
773 * which gets emitted when the user toggles whether the currently
774 * focused item is selected or not. The exact effect of this
775 * depend on the selection mode.
777 * Applications should not connect to it, but may emit it with
778 * g_signal_emit_by_name() if they need to control selection
781 * There is no default binding for this signal is Ctrl-Space.
783 icon_view_signals[TOGGLE_CURSOR_ITEM] =
784 g_signal_new (I_("toggle-cursor-item"),
785 G_TYPE_FROM_CLASS (gobject_class),
786 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
787 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
789 g_cclosure_marshal_VOID__VOID,
793 * GtkIconView::activate-cursor-item:
794 * @iconview: the object on which the signal is emitted
796 * A <link linkend="keybinding-signals">keybinding signal</link>
797 * which gets emitted when the user activates the currently
800 * Applications should not connect to it, but may emit it with
801 * g_signal_emit_by_name() if they need to control activation
804 * The default bindings for this signal are Space, Return and Enter.
806 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
807 g_signal_new (I_("activate-cursor-item"),
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
812 _gtk_marshal_BOOLEAN__VOID,
816 * GtkIconView::move-cursor:
817 * @iconview: the object which received the signal
818 * @step: the granularity of the move, as a #GtkMovementStep
819 * @count: the number of @step units to move
821 * The ::move-cursor signal is a
822 * <link linkend="keybinding-signals">keybinding signal</link>
823 * which gets emitted when the user initiates a cursor movement.
825 * Applications should not connect to it, but may emit it with
826 * g_signal_emit_by_name() if they need to control the cursor
829 * The default bindings for this signal include
831 * <listitem>Arrow keys which move by individual steps</listitem>
832 * <listitem>Home/End keys which move to the first/last item</listitem>
833 * <listitem>PageUp/PageDown which move by "pages"</listitem>
836 * All of these will extend the selection when combined with
837 * the Shift modifier.
839 icon_view_signals[MOVE_CURSOR] =
840 g_signal_new (I_("move-cursor"),
841 G_TYPE_FROM_CLASS (gobject_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
845 _gtk_marshal_BOOLEAN__ENUM_INT,
847 GTK_TYPE_MOVEMENT_STEP,
851 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
853 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
855 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
856 "toggle-cursor-item", 0);
857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
858 "toggle-cursor-item", 0);
860 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
861 "activate-cursor-item", 0);
862 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
863 "activate-cursor-item", 0);
864 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
865 "activate-cursor-item", 0);
866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
867 "activate-cursor-item", 0);
868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
869 "activate-cursor-item", 0);
871 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
872 GTK_MOVEMENT_DISPLAY_LINES, -1);
873 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
874 GTK_MOVEMENT_DISPLAY_LINES, -1);
876 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
877 GTK_MOVEMENT_DISPLAY_LINES, 1);
878 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
879 GTK_MOVEMENT_DISPLAY_LINES, 1);
881 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
882 GTK_MOVEMENT_DISPLAY_LINES, -1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
888 GTK_MOVEMENT_BUFFER_ENDS, -1);
889 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
890 GTK_MOVEMENT_BUFFER_ENDS, -1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
893 GTK_MOVEMENT_BUFFER_ENDS, 1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
895 GTK_MOVEMENT_BUFFER_ENDS, 1);
897 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
898 GTK_MOVEMENT_PAGES, -1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
900 GTK_MOVEMENT_PAGES, -1);
902 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
903 GTK_MOVEMENT_PAGES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
905 GTK_MOVEMENT_PAGES, 1);
907 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
908 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
910 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
912 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
913 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
914 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
915 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
917 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
921 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
923 parent_buildable_iface = g_type_interface_peek_parent (iface);
924 iface->add_child = _gtk_cell_layout_buildable_add_child;
925 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
926 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
930 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
932 iface->get_area = gtk_icon_view_cell_layout_get_area;
936 gtk_icon_view_init (GtkIconView *icon_view)
938 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
942 icon_view->priv->width = 0;
943 icon_view->priv->height = 0;
944 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
945 icon_view->priv->pressed_button = -1;
946 icon_view->priv->press_start_x = -1;
947 icon_view->priv->press_start_y = -1;
948 icon_view->priv->text_column = -1;
949 icon_view->priv->markup_column = -1;
950 icon_view->priv->pixbuf_column = -1;
951 icon_view->priv->text_cell = NULL;
952 icon_view->priv->pixbuf_cell = NULL;
953 icon_view->priv->tooltip_column = -1;
955 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
957 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
959 icon_view->priv->columns = -1;
960 icon_view->priv->item_width = -1;
961 icon_view->priv->spacing = 0;
962 icon_view->priv->row_spacing = 6;
963 icon_view->priv->column_spacing = 6;
964 icon_view->priv->margin = 6;
965 icon_view->priv->item_padding = 6;
967 icon_view->priv->draw_focus = TRUE;
969 icon_view->priv->row_contexts =
970 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
973 /* GObject methods */
975 gtk_icon_view_constructor (GType type,
976 guint n_construct_properties,
977 GObjectConstructParam *construct_properties)
979 GtkIconView *icon_view;
982 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
983 (type, n_construct_properties, construct_properties);
985 icon_view = (GtkIconView *) object;
987 gtk_icon_view_ensure_cell_area (icon_view, NULL);
993 gtk_icon_view_dispose (GObject *object)
995 GtkIconView *icon_view;
996 GtkIconViewPrivate *priv;
998 icon_view = GTK_ICON_VIEW (object);
999 priv = icon_view->priv;
1001 if (priv->cell_area_context)
1003 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1004 priv->context_changed_id = 0;
1006 g_object_unref (priv->cell_area_context);
1007 priv->cell_area_context = NULL;
1010 if (priv->row_contexts)
1012 g_ptr_array_free (priv->row_contexts, TRUE);
1013 priv->row_contexts = NULL;
1016 if (priv->cell_area)
1018 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1020 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1021 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1022 priv->add_editable_id = 0;
1023 priv->remove_editable_id = 0;
1025 g_object_unref (priv->cell_area);
1026 priv->cell_area = NULL;
1029 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1033 gtk_icon_view_set_property (GObject *object,
1035 const GValue *value,
1038 GtkIconView *icon_view;
1041 icon_view = GTK_ICON_VIEW (object);
1045 case PROP_SELECTION_MODE:
1046 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1048 case PROP_PIXBUF_COLUMN:
1049 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1051 case PROP_TEXT_COLUMN:
1052 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1054 case PROP_MARKUP_COLUMN:
1055 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1058 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1060 case PROP_ITEM_ORIENTATION:
1061 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1064 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1066 case PROP_ITEM_WIDTH:
1067 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1070 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1072 case PROP_ROW_SPACING:
1073 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1075 case PROP_COLUMN_SPACING:
1076 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1079 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1081 case PROP_REORDERABLE:
1082 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1085 case PROP_TOOLTIP_COLUMN:
1086 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1089 case PROP_ITEM_PADDING:
1090 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1093 case PROP_CELL_AREA:
1094 /* Construct-only, can only be assigned once */
1095 area = g_value_get_object (value);
1098 if (icon_view->priv->cell_area != NULL)
1100 g_warning ("cell-area has already been set, ignoring construct property");
1101 g_object_ref_sink (area);
1102 g_object_unref (area);
1105 gtk_icon_view_ensure_cell_area (icon_view, area);
1109 case PROP_HADJUSTMENT:
1110 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1112 case PROP_VADJUSTMENT:
1113 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1115 case PROP_HSCROLL_POLICY:
1116 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1117 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1119 case PROP_VSCROLL_POLICY:
1120 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1121 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1125 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1131 gtk_icon_view_get_property (GObject *object,
1136 GtkIconView *icon_view;
1138 icon_view = GTK_ICON_VIEW (object);
1142 case PROP_SELECTION_MODE:
1143 g_value_set_enum (value, icon_view->priv->selection_mode);
1145 case PROP_PIXBUF_COLUMN:
1146 g_value_set_int (value, icon_view->priv->pixbuf_column);
1148 case PROP_TEXT_COLUMN:
1149 g_value_set_int (value, icon_view->priv->text_column);
1151 case PROP_MARKUP_COLUMN:
1152 g_value_set_int (value, icon_view->priv->markup_column);
1155 g_value_set_object (value, icon_view->priv->model);
1157 case PROP_ITEM_ORIENTATION:
1158 g_value_set_enum (value, icon_view->priv->item_orientation);
1161 g_value_set_int (value, icon_view->priv->columns);
1163 case PROP_ITEM_WIDTH:
1164 g_value_set_int (value, icon_view->priv->item_width);
1167 g_value_set_int (value, icon_view->priv->spacing);
1169 case PROP_ROW_SPACING:
1170 g_value_set_int (value, icon_view->priv->row_spacing);
1172 case PROP_COLUMN_SPACING:
1173 g_value_set_int (value, icon_view->priv->column_spacing);
1176 g_value_set_int (value, icon_view->priv->margin);
1178 case PROP_REORDERABLE:
1179 g_value_set_boolean (value, icon_view->priv->reorderable);
1181 case PROP_TOOLTIP_COLUMN:
1182 g_value_set_int (value, icon_view->priv->tooltip_column);
1185 case PROP_ITEM_PADDING:
1186 g_value_set_int (value, icon_view->priv->item_padding);
1189 case PROP_CELL_AREA:
1190 g_value_set_object (value, icon_view->priv->cell_area);
1193 case PROP_HADJUSTMENT:
1194 g_value_set_object (value, icon_view->priv->hadjustment);
1196 case PROP_VADJUSTMENT:
1197 g_value_set_object (value, icon_view->priv->vadjustment);
1199 case PROP_HSCROLL_POLICY:
1200 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1202 case PROP_VSCROLL_POLICY:
1203 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1212 /* GtkWidget methods */
1214 gtk_icon_view_destroy (GtkWidget *widget)
1216 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1218 gtk_icon_view_set_model (icon_view, NULL);
1220 if (icon_view->priv->layout_idle_id != 0)
1222 g_source_remove (icon_view->priv->layout_idle_id);
1223 icon_view->priv->layout_idle_id = 0;
1226 if (icon_view->priv->scroll_to_path != NULL)
1228 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1229 icon_view->priv->scroll_to_path = NULL;
1232 remove_scroll_timeout (icon_view);
1234 if (icon_view->priv->hadjustment != NULL)
1236 g_object_unref (icon_view->priv->hadjustment);
1237 icon_view->priv->hadjustment = NULL;
1240 if (icon_view->priv->vadjustment != NULL)
1242 g_object_unref (icon_view->priv->vadjustment);
1243 icon_view->priv->vadjustment = NULL;
1246 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1250 gtk_icon_view_realize (GtkWidget *widget)
1252 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1253 GtkAllocation allocation;
1255 GdkWindowAttr attributes;
1256 gint attributes_mask;
1257 GtkStyleContext *context;
1259 gtk_widget_set_realized (widget, TRUE);
1261 gtk_widget_get_allocation (widget, &allocation);
1263 /* Make the main, clipping window */
1264 attributes.window_type = GDK_WINDOW_CHILD;
1265 attributes.x = allocation.x;
1266 attributes.y = allocation.y;
1267 attributes.width = allocation.width;
1268 attributes.height = allocation.height;
1269 attributes.wclass = GDK_INPUT_OUTPUT;
1270 attributes.visual = gtk_widget_get_visual (widget);
1271 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1273 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1275 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1276 &attributes, attributes_mask);
1277 gtk_widget_set_window (widget, window);
1278 gdk_window_set_user_data (window, widget);
1280 gtk_widget_get_allocation (widget, &allocation);
1282 /* Make the window for the icon view */
1285 attributes.width = MAX (icon_view->priv->width, allocation.width);
1286 attributes.height = MAX (icon_view->priv->height, allocation.height);
1287 attributes.event_mask = (GDK_EXPOSURE_MASK |
1289 GDK_POINTER_MOTION_MASK |
1290 GDK_BUTTON_PRESS_MASK |
1291 GDK_BUTTON_RELEASE_MASK |
1292 GDK_KEY_PRESS_MASK |
1293 GDK_KEY_RELEASE_MASK) |
1294 gtk_widget_get_events (widget);
1296 icon_view->priv->bin_window = gdk_window_new (window,
1297 &attributes, attributes_mask);
1298 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1300 context = gtk_widget_get_style_context (widget);
1302 gtk_style_context_save (context);
1303 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1304 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1305 gtk_style_context_restore (context);
1307 gdk_window_show (icon_view->priv->bin_window);
1311 gtk_icon_view_unrealize (GtkWidget *widget)
1313 GtkIconView *icon_view;
1315 icon_view = GTK_ICON_VIEW (widget);
1317 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1318 gdk_window_destroy (icon_view->priv->bin_window);
1319 icon_view->priv->bin_window = NULL;
1321 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1325 _gtk_icon_view_update_background (GtkIconView *icon_view)
1327 GtkWidget *widget = GTK_WIDGET (icon_view);
1329 if (gtk_widget_get_realized (widget))
1331 GtkStyleContext *context;
1333 context = gtk_widget_get_style_context (widget);
1335 gtk_style_context_save (context);
1336 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1338 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1339 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1341 gtk_style_context_restore (context);
1346 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1347 GtkStateFlags previous_state)
1349 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1350 gtk_widget_queue_draw (widget);
1354 gtk_icon_view_style_updated (GtkWidget *widget)
1356 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1358 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1359 gtk_widget_queue_resize (widget);
1363 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1367 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1371 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1375 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1379 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1383 for (list = icon_view->priv->children; list; list = list->next)
1385 GtkIconViewChild *child = list->data;
1387 /* totally ignore our child's requisition */
1388 gtk_widget_size_allocate (child->widget, &child->area);
1393 gtk_icon_view_size_allocate (GtkWidget *widget,
1394 GtkAllocation *allocation)
1396 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1398 gtk_widget_set_allocation (widget, allocation);
1400 if (gtk_widget_get_realized (widget))
1402 gdk_window_move_resize (gtk_widget_get_window (widget),
1403 allocation->x, allocation->y,
1404 allocation->width, allocation->height);
1405 gdk_window_resize (icon_view->priv->bin_window,
1406 MAX (icon_view->priv->width, allocation->width),
1407 MAX (icon_view->priv->height, allocation->height));
1410 gtk_icon_view_layout (icon_view);
1412 gtk_icon_view_allocate_children (icon_view);
1414 /* Delay signal emission */
1415 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1416 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1418 gtk_icon_view_set_hadjustment_values (icon_view);
1419 gtk_icon_view_set_vadjustment_values (icon_view);
1421 if (gtk_widget_get_realized (widget) &&
1422 icon_view->priv->scroll_to_path)
1425 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1426 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1427 icon_view->priv->scroll_to_path = NULL;
1429 gtk_icon_view_scroll_to_path (icon_view, path,
1430 icon_view->priv->scroll_to_use_align,
1431 icon_view->priv->scroll_to_row_align,
1432 icon_view->priv->scroll_to_col_align);
1433 gtk_tree_path_free (path);
1436 /* Emit any pending signals now */
1437 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1438 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1442 gtk_icon_view_draw (GtkWidget *widget,
1445 GtkIconView *icon_view;
1449 GtkIconViewDropPosition dest_pos;
1450 GtkIconViewItem *dest_item = NULL;
1452 icon_view = GTK_ICON_VIEW (widget);
1454 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1459 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1461 cairo_set_line_width (cr, 1.);
1463 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1467 dest_index = gtk_tree_path_get_indices (path)[0];
1468 gtk_tree_path_free (path);
1473 for (icons = icon_view->priv->items; icons; icons = icons->next)
1475 GtkIconViewItem *item = icons->data;
1476 GdkRectangle paint_area;
1478 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1479 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1480 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1481 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1485 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1488 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1490 gtk_icon_view_paint_item (icon_view, cr, item,
1491 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1492 icon_view->priv->draw_focus);
1494 if (dest_index == item->index)
1502 dest_pos != GTK_ICON_VIEW_NO_DROP)
1504 GtkStyleContext *context;
1505 GtkStateFlags state;
1506 GdkRectangle rect = { 0 };
1508 context = gtk_widget_get_style_context (widget);
1509 state = gtk_widget_get_state_flags (widget);
1513 case GTK_ICON_VIEW_DROP_INTO:
1514 rect = dest_item->cell_area;
1516 case GTK_ICON_VIEW_DROP_ABOVE:
1517 rect.x = dest_item->cell_area.x;
1518 rect.y = dest_item->cell_area.y - 1;
1519 rect.width = dest_item->cell_area.width;
1522 case GTK_ICON_VIEW_DROP_LEFT:
1523 rect.x = dest_item->cell_area.x - 1;
1524 rect.y = dest_item->cell_area.y;
1526 rect.height = dest_item->cell_area.height;
1528 case GTK_ICON_VIEW_DROP_BELOW:
1529 rect.x = dest_item->cell_area.x;
1530 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1531 rect.width = dest_item->cell_area.width;
1534 case GTK_ICON_VIEW_DROP_RIGHT:
1535 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1536 rect.y = dest_item->cell_area.y;
1538 rect.height = dest_item->cell_area.height;
1539 case GTK_ICON_VIEW_NO_DROP: ;
1543 gtk_style_context_set_state (context, state);
1544 gtk_render_focus (context, cr,
1546 rect.width, rect.height);
1549 if (icon_view->priv->doing_rubberband)
1550 gtk_icon_view_paint_rubberband (icon_view, cr);
1554 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1558 rubberband_scroll_timeout (gpointer data)
1560 GtkIconView *icon_view = data;
1562 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1563 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1564 icon_view->priv->scroll_value_diff);
1566 gtk_icon_view_update_rubberband (icon_view);
1572 gtk_icon_view_motion (GtkWidget *widget,
1573 GdkEventMotion *event)
1575 GtkAllocation allocation;
1576 GtkIconView *icon_view;
1579 icon_view = GTK_ICON_VIEW (widget);
1581 gtk_icon_view_maybe_begin_drag (icon_view, event);
1583 if (icon_view->priv->doing_rubberband)
1585 gtk_icon_view_update_rubberband (widget);
1587 abs_y = event->y - icon_view->priv->height *
1588 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1589 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1590 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1592 gtk_widget_get_allocation (widget, &allocation);
1594 if (abs_y < 0 || abs_y > allocation.height)
1597 icon_view->priv->scroll_value_diff = abs_y;
1599 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1601 icon_view->priv->event_last_x = event->x;
1602 icon_view->priv->event_last_y = event->y;
1604 if (icon_view->priv->scroll_timeout_id == 0)
1605 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1609 remove_scroll_timeout (icon_view);
1613 GtkIconViewItem *item, *last_prelight_item;
1614 GtkCellRenderer *cell = NULL;
1616 last_prelight_item = icon_view->priv->last_prelight;
1617 item = _gtk_icon_view_get_item_at_coords (icon_view,
1624 item->prelight = TRUE;
1625 gtk_icon_view_queue_draw_item (icon_view, item);
1628 if (last_prelight_item != NULL &&
1629 last_prelight_item != item)
1631 last_prelight_item->prelight = FALSE;
1632 gtk_icon_view_queue_draw_item (icon_view,
1633 icon_view->priv->last_prelight);
1636 icon_view->priv->last_prelight = item;
1643 gtk_icon_view_remove (GtkContainer *container,
1646 GtkIconView *icon_view;
1647 GtkIconViewChild *child = NULL;
1650 icon_view = GTK_ICON_VIEW (container);
1652 tmp_list = icon_view->priv->children;
1655 child = tmp_list->data;
1656 if (child->widget == widget)
1658 gtk_widget_unparent (widget);
1660 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1661 g_list_free_1 (tmp_list);
1666 tmp_list = tmp_list->next;
1671 gtk_icon_view_forall (GtkContainer *container,
1672 gboolean include_internals,
1673 GtkCallback callback,
1674 gpointer callback_data)
1676 GtkIconView *icon_view;
1677 GtkIconViewChild *child = NULL;
1680 icon_view = GTK_ICON_VIEW (container);
1682 tmp_list = icon_view->priv->children;
1685 child = tmp_list->data;
1686 tmp_list = tmp_list->next;
1688 (* callback) (child->widget, callback_data);
1693 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1694 GtkIconViewItem *item)
1697 AtkObject *item_obj;
1699 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1702 item_obj = atk_object_ref_accessible_child (obj, item->index);
1703 if (item_obj != NULL)
1705 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1706 g_object_unref (item_obj);
1712 gtk_icon_view_add_editable (GtkCellArea *area,
1713 GtkCellRenderer *renderer,
1714 GtkCellEditable *editable,
1715 GdkRectangle *cell_area,
1717 GtkIconView *icon_view)
1719 GtkIconViewChild *child;
1720 GtkWidget *widget = GTK_WIDGET (editable);
1722 child = g_new (GtkIconViewChild, 1);
1724 child->widget = widget;
1725 child->area.x = cell_area->x;
1726 child->area.y = cell_area->y;
1727 child->area.width = cell_area->width;
1728 child->area.height = cell_area->height;
1730 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1732 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1733 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1735 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1739 gtk_icon_view_remove_editable (GtkCellArea *area,
1740 GtkCellRenderer *renderer,
1741 GtkCellEditable *editable,
1742 GtkIconView *icon_view)
1746 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1747 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1749 gtk_container_remove (GTK_CONTAINER (icon_view),
1750 GTK_WIDGET (editable));
1752 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1753 gtk_icon_view_queue_draw_path (icon_view, path);
1754 gtk_tree_path_free (path);
1758 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1760 GtkIconView *icon_view)
1762 if (!strcmp (pspec->name, "minimum-width") ||
1763 !strcmp (pspec->name, "natural-width") ||
1764 !strcmp (pspec->name, "minimum-height") ||
1765 !strcmp (pspec->name, "natural-height"))
1766 gtk_icon_view_invalidate_sizes (icon_view);
1770 * gtk_icon_view_set_cursor:
1771 * @icon_view: A #GtkIconView
1772 * @path: A #GtkTreePath
1773 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1774 * @start_editing: %TRUE if the specified cell should start being edited.
1776 * Sets the current keyboard focus to be at @path, and selects it. This is
1777 * useful when you want to focus the user's attention on a particular item.
1778 * If @cell is not %NULL, then focus is given to the cell specified by
1779 * it. Additionally, if @start_editing is %TRUE, then editing should be
1780 * started in the specified cell.
1782 * This function is often followed by <literal>gtk_widget_grab_focus
1783 * (icon_view)</literal> in order to give keyboard focus to the widget.
1784 * Please note that editing can only happen when the widget is realized.
1789 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1791 GtkCellRenderer *cell,
1792 gboolean start_editing)
1794 GtkIconViewItem *item = NULL;
1796 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1797 g_return_if_fail (path != NULL);
1798 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1800 if (icon_view->priv->cell_area)
1801 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1803 if (gtk_tree_path_get_depth (path) == 1)
1804 item = g_list_nth_data (icon_view->priv->items,
1805 gtk_tree_path_get_indices(path)[0]);
1810 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
1811 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1813 if (start_editing &&
1814 icon_view->priv->cell_area)
1816 GtkCellAreaContext *context;
1818 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1819 _gtk_icon_view_set_cell_data (icon_view, item);
1820 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1821 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1822 0 /* XXX flags */, TRUE);
1827 * gtk_icon_view_get_cursor:
1828 * @icon_view: A #GtkIconView
1829 * @path: (out) (allow-none): Return location for the current cursor path,
1831 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1833 * Fills in @path and @cell with the current cursor path and cell.
1834 * If the cursor isn't currently set, then *@path will be %NULL.
1835 * If no cell currently has focus, then *@cell will be %NULL.
1837 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1839 * Return value: %TRUE if the cursor is set.
1844 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1846 GtkCellRenderer **cell)
1848 GtkIconViewItem *item;
1850 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1852 item = icon_view->priv->cursor_item;
1857 *path = gtk_tree_path_new_from_indices (item->index, -1);
1862 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1863 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1865 return (item != NULL);
1869 gtk_icon_view_button_press (GtkWidget *widget,
1870 GdkEventButton *event)
1872 GtkIconView *icon_view;
1873 GtkIconViewItem *item;
1874 gboolean dirty = FALSE;
1875 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1877 icon_view = GTK_ICON_VIEW (widget);
1879 if (event->window != icon_view->priv->bin_window)
1882 if (!gtk_widget_has_focus (widget))
1883 gtk_widget_grab_focus (widget);
1885 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1887 GdkModifierType extend_mod_mask;
1888 GdkModifierType modify_mod_mask;
1891 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
1894 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
1896 item = _gtk_icon_view_get_item_at_coords (icon_view,
1902 * We consider only the the cells' area as the item area if the
1903 * item is not selected, but if it *is* selected, the complete
1904 * selection rectangle is considered to be part of the item.
1906 if (item != NULL && (cell != NULL || item->selected))
1910 if (gtk_cell_renderer_is_activatable (cell))
1914 gtk_icon_view_scroll_to_item (icon_view, item);
1916 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1918 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1920 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1921 (event->state & extend_mod_mask))
1923 gtk_icon_view_unselect_all_internal (icon_view);
1925 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1926 if (!icon_view->priv->anchor_item)
1927 icon_view->priv->anchor_item = item;
1929 gtk_icon_view_select_all_between (icon_view,
1930 icon_view->priv->anchor_item,
1936 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1937 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1938 (event->state & modify_mod_mask))
1940 item->selected = !item->selected;
1941 gtk_icon_view_queue_draw_item (icon_view, item);
1946 gtk_icon_view_unselect_all_internal (icon_view);
1948 item->selected = TRUE;
1949 gtk_icon_view_queue_draw_item (icon_view, item);
1952 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1953 icon_view->priv->anchor_item = item;
1956 /* Save press to possibly begin a drag */
1957 if (icon_view->priv->pressed_button < 0)
1959 icon_view->priv->pressed_button = event->button;
1960 icon_view->priv->press_start_x = event->x;
1961 icon_view->priv->press_start_y = event->y;
1964 if (!icon_view->priv->last_single_clicked)
1965 icon_view->priv->last_single_clicked = item;
1967 /* cancel the current editing, if it exists */
1968 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1970 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
1972 GtkCellAreaContext *context;
1974 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1976 _gtk_icon_view_set_cell_data (icon_view, item);
1977 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1978 GTK_WIDGET (icon_view),
1979 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
1984 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1985 !(event->state & modify_mod_mask))
1987 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1990 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1991 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
1994 /* don't draw keyboard focus around an clicked-on item */
1995 icon_view->priv->draw_focus = FALSE;
1998 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2000 item = _gtk_icon_view_get_item_at_coords (icon_view,
2005 if (item && item == icon_view->priv->last_single_clicked)
2009 path = gtk_tree_path_new_from_indices (item->index, -1);
2010 gtk_icon_view_item_activated (icon_view, path);
2011 gtk_tree_path_free (path);
2014 icon_view->priv->last_single_clicked = NULL;
2015 icon_view->priv->pressed_button = -1;
2019 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2021 return event->button == 1;
2025 gtk_icon_view_button_release (GtkWidget *widget,
2026 GdkEventButton *event)
2028 GtkIconView *icon_view;
2030 icon_view = GTK_ICON_VIEW (widget);
2032 if (icon_view->priv->pressed_button == event->button)
2033 icon_view->priv->pressed_button = -1;
2035 gtk_icon_view_stop_rubberbanding (icon_view);
2037 remove_scroll_timeout (icon_view);
2043 gtk_icon_view_key_press (GtkWidget *widget,
2046 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2048 if (icon_view->priv->doing_rubberband)
2050 if (event->keyval == GDK_KEY_Escape)
2051 gtk_icon_view_stop_rubberbanding (icon_view);
2056 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2060 gtk_icon_view_key_release (GtkWidget *widget,
2063 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2065 if (icon_view->priv->doing_rubberband)
2068 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2072 gtk_icon_view_update_rubberband (gpointer data)
2074 GtkIconView *icon_view;
2076 GdkRectangle old_area;
2077 GdkRectangle new_area;
2078 GdkRectangle common;
2079 cairo_region_t *invalid_region;
2081 icon_view = GTK_ICON_VIEW (data);
2083 gdk_window_get_device_position (icon_view->priv->bin_window,
2084 icon_view->priv->rubberband_device,
2090 old_area.x = MIN (icon_view->priv->rubberband_x1,
2091 icon_view->priv->rubberband_x2);
2092 old_area.y = MIN (icon_view->priv->rubberband_y1,
2093 icon_view->priv->rubberband_y2);
2094 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2095 icon_view->priv->rubberband_x1) + 1;
2096 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2097 icon_view->priv->rubberband_y1) + 1;
2099 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2100 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2101 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2102 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2104 invalid_region = cairo_region_create_rectangle (&old_area);
2105 cairo_region_union_rectangle (invalid_region, &new_area);
2107 gdk_rectangle_intersect (&old_area, &new_area, &common);
2108 if (common.width > 2 && common.height > 2)
2110 cairo_region_t *common_region;
2112 /* make sure the border is invalidated */
2118 common_region = cairo_region_create_rectangle (&common);
2120 cairo_region_subtract (invalid_region, common_region);
2121 cairo_region_destroy (common_region);
2124 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2126 cairo_region_destroy (invalid_region);
2128 icon_view->priv->rubberband_x2 = x;
2129 icon_view->priv->rubberband_y2 = y;
2131 gtk_icon_view_update_rubberband_selection (icon_view);
2135 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2142 if (icon_view->priv->rubberband_device)
2145 for (items = icon_view->priv->items; items; items = items->next)
2147 GtkIconViewItem *item = items->data;
2149 item->selected_before_rubberbanding = item->selected;
2152 icon_view->priv->rubberband_x1 = x;
2153 icon_view->priv->rubberband_y1 = y;
2154 icon_view->priv->rubberband_x2 = x;
2155 icon_view->priv->rubberband_y2 = y;
2157 icon_view->priv->doing_rubberband = TRUE;
2158 icon_view->priv->rubberband_device = device;
2160 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2164 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2166 if (!icon_view->priv->doing_rubberband)
2169 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2170 icon_view->priv->rubberband_device);
2172 icon_view->priv->doing_rubberband = FALSE;
2173 icon_view->priv->rubberband_device = NULL;
2175 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2179 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2182 gint x, y, width, height;
2183 gboolean dirty = FALSE;
2185 x = MIN (icon_view->priv->rubberband_x1,
2186 icon_view->priv->rubberband_x2);
2187 y = MIN (icon_view->priv->rubberband_y1,
2188 icon_view->priv->rubberband_y2);
2189 width = ABS (icon_view->priv->rubberband_x1 -
2190 icon_view->priv->rubberband_x2);
2191 height = ABS (icon_view->priv->rubberband_y1 -
2192 icon_view->priv->rubberband_y2);
2194 for (items = icon_view->priv->items; items; items = items->next)
2196 GtkIconViewItem *item = items->data;
2200 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2201 x, y, width, height);
2203 selected = is_in ^ item->selected_before_rubberbanding;
2205 if (item->selected != selected)
2207 item->selected = selected;
2209 gtk_icon_view_queue_draw_item (icon_view, item);
2214 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2219 GdkRectangle hit_rect;
2224 hit_test (GtkCellRenderer *renderer,
2225 const GdkRectangle *cell_area,
2226 const GdkRectangle *cell_background,
2229 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2230 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2231 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2232 MAX (data->hit_rect.y, cell_area->y) > 0)
2235 return (data->hit != FALSE);
2239 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2240 GtkIconViewItem *item,
2246 HitTestData data = { { x, y, width, height }, FALSE };
2247 GtkCellAreaContext *context;
2248 GdkRectangle *item_area = (GdkRectangle *)item;
2250 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2251 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2254 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2256 _gtk_icon_view_set_cell_data (icon_view, item);
2257 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2258 GTK_WIDGET (icon_view),
2259 item_area, item_area,
2260 (GtkCellAllocCallback)hit_test, &data);
2266 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2268 gboolean dirty = FALSE;
2271 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2274 for (items = icon_view->priv->items; items; items = items->next)
2276 GtkIconViewItem *item = items->data;
2280 item->selected = FALSE;
2282 gtk_icon_view_queue_draw_item (icon_view, item);
2283 gtk_icon_view_item_selected_changed (icon_view, item);
2291 /* GtkIconView signals */
2293 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2295 gtk_icon_view_select_all (icon_view);
2299 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2301 gtk_icon_view_unselect_all (icon_view);
2305 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2307 gtk_icon_view_unselect_all (icon_view);
2309 if (icon_view->priv->cursor_item != NULL)
2310 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2314 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2317 GtkCellAreaContext *context;
2319 if (!icon_view->priv->cursor_item)
2322 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2324 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2325 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2326 GTK_WIDGET (icon_view),
2327 (GdkRectangle *)icon_view->priv->cursor_item,
2331 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2332 gtk_icon_view_item_activated (icon_view, path);
2333 gtk_tree_path_free (path);
2339 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2341 if (!icon_view->priv->cursor_item)
2344 switch (icon_view->priv->selection_mode)
2346 case GTK_SELECTION_NONE:
2348 case GTK_SELECTION_BROWSE:
2349 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2351 case GTK_SELECTION_SINGLE:
2352 if (icon_view->priv->cursor_item->selected)
2353 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2355 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2357 case GTK_SELECTION_MULTIPLE:
2358 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2359 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2361 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2362 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2367 /* Internal functions */
2369 gtk_icon_view_process_updates (GtkIconView *icon_view)
2371 /* Prior to drawing, we check if a layout has been scheduled. If so,
2372 * do it now that all cell view items have valid sizes before we proceeed
2373 * (and resize the bin_window if required).
2375 if (icon_view->priv->layout_idle_id != 0)
2376 gtk_icon_view_layout (icon_view);
2378 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2382 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2384 GtkAllocation allocation;
2385 GtkAdjustment *adj = icon_view->priv->hadjustment;
2386 gdouble old_page_size;
2392 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2394 old_value = gtk_adjustment_get_value (adj);
2395 old_upper = gtk_adjustment_get_upper (adj);
2396 old_page_size = gtk_adjustment_get_page_size (adj);
2397 new_upper = MAX (allocation.width, icon_view->priv->width);
2399 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2401 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2402 /* Quick explanation:
2403 * In LTR locales, leftmost portion of visible rectangle should stay
2404 * fixed, which means left edge of scrollbar thumb should remain fixed
2405 * and thus adjustment's value should stay the same.
2407 * In RTL locales, we want to keep rightmost portion of visible
2408 * rectangle fixed. This means right edge of thumb should remain fixed.
2409 * In this case, upper - value - page_size should remain constant.
2411 new_value = (new_upper - allocation.width) -
2412 (old_upper - old_value - old_page_size);
2413 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2416 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2418 gtk_adjustment_configure (adj,
2422 allocation.width * 0.1,
2423 allocation.width * 0.9,
2428 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2430 GtkAllocation allocation;
2431 GtkAdjustment *adj = icon_view->priv->vadjustment;
2433 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2435 gtk_adjustment_configure (adj,
2436 gtk_adjustment_get_value (adj),
2438 MAX (allocation.height, icon_view->priv->height),
2439 allocation.height * 0.1,
2440 allocation.height * 0.9,
2445 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2446 GtkAdjustment *adjustment)
2448 GtkIconViewPrivate *priv = icon_view->priv;
2451 if (adjustment && priv->hadjustment == adjustment)
2454 if (priv->hadjustment != NULL)
2456 g_signal_handlers_disconnect_matched (priv->hadjustment,
2457 G_SIGNAL_MATCH_DATA,
2458 0, 0, NULL, NULL, icon_view);
2459 g_object_unref (priv->hadjustment);
2463 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2466 g_signal_connect (adjustment, "value-changed",
2467 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2468 priv->hadjustment = g_object_ref_sink (adjustment);
2469 gtk_icon_view_set_hadjustment_values (icon_view);
2471 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2472 _gtk_icon_view_accessible_set_adjustment (atk_obj,
2473 GTK_ORIENTATION_HORIZONTAL,
2476 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2480 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2481 GtkAdjustment *adjustment)
2483 GtkIconViewPrivate *priv = icon_view->priv;
2486 if (adjustment && priv->vadjustment == adjustment)
2489 if (priv->vadjustment != NULL)
2491 g_signal_handlers_disconnect_matched (priv->vadjustment,
2492 G_SIGNAL_MATCH_DATA,
2493 0, 0, NULL, NULL, icon_view);
2494 g_object_unref (priv->vadjustment);
2498 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2501 g_signal_connect (adjustment, "value-changed",
2502 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2503 priv->vadjustment = g_object_ref_sink (adjustment);
2504 gtk_icon_view_set_vadjustment_values (icon_view);
2506 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2507 _gtk_icon_view_accessible_set_adjustment (atk_obj,
2508 GTK_ORIENTATION_VERTICAL,
2511 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2515 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2516 GtkIconView *icon_view)
2518 GtkIconViewPrivate *priv = icon_view->priv;
2520 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2522 gdk_window_move (priv->bin_window,
2523 - gtk_adjustment_get_value (priv->hadjustment),
2524 - gtk_adjustment_get_value (priv->vadjustment));
2526 if (icon_view->priv->doing_rubberband)
2527 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2529 gtk_icon_view_process_updates (icon_view);
2534 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2539 gint *maximum_width)
2541 GtkAllocation allocation;
2542 GtkCellAreaContext *context;
2543 GtkIconViewPrivate *priv = icon_view->priv;
2544 GtkWidget *widget = GTK_WIDGET (icon_view);
2545 gint x, current_width;
2546 GList *items, *last_item;
2548 gint max_height = 0;
2551 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2559 current_width += 2 * priv->margin;
2561 gtk_widget_get_allocation (widget, &allocation);
2563 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2564 g_ptr_array_add (priv->row_contexts, context);
2566 /* In the first loop we iterate horizontally until we hit allocation width
2567 * and collect the aligned height-for-width */
2571 GtkIconViewItem *item = items->data;
2572 GdkRectangle *item_area = (GdkRectangle *)item;
2574 item_area->width = item_width;
2576 current_width += item_area->width + icon_view->priv->item_padding * 2;
2578 if (items != first_item)
2580 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2581 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2585 /* Get this item's particular width & height (all alignments are cached by now) */
2586 _gtk_icon_view_set_cell_data (icon_view, item);
2587 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2592 current_width += icon_view->priv->column_spacing;
2594 item_area->y = *y + icon_view->priv->item_padding;
2595 item_area->x = x + icon_view->priv->item_padding;
2597 x = current_width - icon_view->priv->margin;
2599 if (current_width > *maximum_width)
2600 *maximum_width = current_width;
2606 items = items->next;
2611 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2612 gtk_cell_area_context_allocate (context, item_width, max_height);
2614 /* In the second loop the item height has been aligned and derived and
2615 * we just set the height and handle rtl layout */
2616 for (items = first_item; items != last_item; items = items->next)
2618 GtkIconViewItem *item = items->data;
2619 GdkRectangle *item_area = (GdkRectangle *)item;
2623 item_area->x = *maximum_width - item_area->width - item_area->x;
2624 item->col = col - 1 - item->col;
2627 /* All items in the same row get the same height */
2628 item_area->height = max_height;
2631 /* Adjust the new y coordinate. */
2632 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2638 adjust_wrap_width (GtkIconView *icon_view)
2640 if (icon_view->priv->text_cell)
2642 gint wrap_width = 50;
2644 /* Here we go with the same old guess, try the icon size and set double
2645 * the size of the first icon found in the list, naive but works much
2647 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2649 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2650 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2651 GTK_WIDGET (icon_view),
2654 wrap_width = MAX (wrap_width * 2, 50);
2657 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2658 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2663 gtk_icon_view_layout (GtkIconView *icon_view)
2665 GtkAllocation allocation;
2668 gint y = 0, maximum_width = 0;
2671 gboolean size_changed = FALSE;
2673 if (icon_view->priv->layout_idle_id != 0)
2675 g_source_remove (icon_view->priv->layout_idle_id);
2676 icon_view->priv->layout_idle_id = 0;
2679 if (icon_view->priv->model == NULL)
2682 widget = GTK_WIDGET (icon_view);
2684 item_width = icon_view->priv->item_width;
2686 /* Update the wrap width for the text cell before going and requesting sizes */
2687 adjust_wrap_width (icon_view);
2689 /* Update the context widths for any invalidated items */
2690 gtk_icon_view_cache_widths (icon_view);
2692 /* Fetch the new item width if needed */
2694 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2697 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2699 icons = icon_view->priv->items;
2700 y += icon_view->priv->margin;
2703 /* Clear the per row contexts */
2704 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2708 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2710 &y, &maximum_width);
2713 while (icons != NULL);
2715 if (maximum_width != icon_view->priv->width)
2717 icon_view->priv->width = maximum_width;
2718 size_changed = TRUE;
2721 y += icon_view->priv->margin;
2723 if (y != icon_view->priv->height)
2725 icon_view->priv->height = y;
2726 size_changed = TRUE;
2729 gtk_icon_view_set_hadjustment_values (icon_view);
2730 gtk_icon_view_set_vadjustment_values (icon_view);
2733 gtk_widget_queue_resize_no_redraw (widget);
2735 gtk_widget_get_allocation (widget, &allocation);
2736 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2737 gdk_window_resize (icon_view->priv->bin_window,
2738 MAX (icon_view->priv->width, allocation.width),
2739 MAX (icon_view->priv->height, allocation.height));
2741 if (icon_view->priv->scroll_to_path)
2745 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2746 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2747 icon_view->priv->scroll_to_path = NULL;
2749 gtk_icon_view_scroll_to_path (icon_view, path,
2750 icon_view->priv->scroll_to_use_align,
2751 icon_view->priv->scroll_to_row_align,
2752 icon_view->priv->scroll_to_col_align);
2753 gtk_tree_path_free (path);
2756 gtk_widget_queue_draw (widget);
2759 /* This ensures that all widths have been cached in the
2760 * context and we have proper alignments to go on.
2763 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2767 g_signal_handler_block (icon_view->priv->cell_area_context,
2768 icon_view->priv->context_changed_id);
2770 for (items = icon_view->priv->items; items; items = items->next)
2772 GtkIconViewItem *item = items->data;
2774 /* Only fetch the width of items with invalidated sizes */
2775 if (item->cell_area.width < 0)
2777 _gtk_icon_view_set_cell_data (icon_view, item);
2778 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2779 icon_view->priv->cell_area_context,
2780 GTK_WIDGET (icon_view), NULL, NULL);
2784 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2785 icon_view->priv->context_changed_id);
2789 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2791 /* Clear all item sizes */
2792 g_list_foreach (icon_view->priv->items,
2793 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2795 /* Reset the context */
2796 if (icon_view->priv->cell_area_context)
2798 g_signal_handler_block (icon_view->priv->cell_area_context,
2799 icon_view->priv->context_changed_id);
2800 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2801 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2802 icon_view->priv->context_changed_id);
2805 /* Re-layout the items */
2806 gtk_icon_view_queue_layout (icon_view);
2810 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2812 item->cell_area.width = -1;
2813 item->cell_area.height = -1;
2817 gtk_icon_view_paint_item (GtkIconView *icon_view,
2819 GtkIconViewItem *item,
2822 gboolean draw_focus)
2824 GdkRectangle cell_area;
2825 GtkStateFlags state = 0;
2826 GtkCellRendererState flags = 0;
2827 GtkStyleContext *style_context;
2828 GtkWidget *widget = GTK_WIDGET (icon_view);
2829 GtkIconViewPrivate *priv = icon_view->priv;
2830 GtkCellAreaContext *context;
2832 if (priv->model == NULL)
2835 _gtk_icon_view_set_cell_data (icon_view, item);
2837 style_context = gtk_widget_get_style_context (widget);
2839 gtk_style_context_save (style_context);
2840 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2841 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2845 if (gtk_widget_has_focus (widget) &&
2846 item == icon_view->priv->cursor_item)
2848 state |= GTK_STATE_FLAG_FOCUSED;
2849 flags |= GTK_CELL_RENDERER_FOCUSED;
2852 state |= GTK_STATE_FLAG_SELECTED;
2853 flags |= GTK_CELL_RENDERER_SELECTED;
2858 state |= GTK_STATE_FLAG_PRELIGHT;
2859 flags |= GTK_CELL_RENDERER_PRELIT;
2862 gtk_style_context_set_state (style_context, state);
2866 gtk_render_background (style_context, cr,
2867 x - icon_view->priv->item_padding,
2868 y - icon_view->priv->item_padding,
2869 item->cell_area.width + icon_view->priv->item_padding * 2,
2870 item->cell_area.height + icon_view->priv->item_padding * 2);
2871 gtk_render_frame (style_context, cr,
2872 x - icon_view->priv->item_padding,
2873 y - icon_view->priv->item_padding,
2874 item->cell_area.width + icon_view->priv->item_padding * 2,
2875 item->cell_area.height + icon_view->priv->item_padding * 2);
2880 cell_area.width = item->cell_area.width;
2881 cell_area.height = item->cell_area.height;
2883 context = g_ptr_array_index (priv->row_contexts, item->row);
2884 gtk_cell_area_render (priv->cell_area, context,
2885 widget, cr, &cell_area, &cell_area, flags,
2888 gtk_style_context_restore (style_context);
2892 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2895 GtkStyleContext *context;
2900 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2901 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2902 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2903 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2905 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2907 gtk_style_context_save (context);
2908 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2910 gdk_cairo_rectangle (cr, &rect);
2913 gtk_render_background (context, cr,
2915 rect.width, rect.height);
2916 gtk_render_frame (context, cr,
2918 rect.width, rect.height);
2920 gtk_style_context_restore (context);
2925 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2931 index = gtk_tree_path_get_indices (path)[0];
2933 for (l = icon_view->priv->items; l; l = l->next)
2935 GtkIconViewItem *item = l->data;
2937 if (item->index == index)
2939 gtk_icon_view_queue_draw_item (icon_view, item);
2946 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2947 GtkIconViewItem *item)
2950 GdkRectangle *item_area = (GdkRectangle *)item;
2952 rect.x = item_area->x - icon_view->priv->item_padding;
2953 rect.y = item_area->y - icon_view->priv->item_padding;
2954 rect.width = item_area->width + icon_view->priv->item_padding * 2;
2955 rect.height = item_area->height + icon_view->priv->item_padding * 2;
2957 if (icon_view->priv->bin_window)
2958 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2962 layout_callback (gpointer user_data)
2964 GtkIconView *icon_view;
2966 icon_view = GTK_ICON_VIEW (user_data);
2968 icon_view->priv->layout_idle_id = 0;
2970 gtk_icon_view_layout (icon_view);
2976 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2978 if (icon_view->priv->layout_idle_id != 0)
2981 icon_view->priv->layout_idle_id =
2982 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
2983 layout_callback, icon_view, NULL);
2987 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2988 GtkIconViewItem *item,
2989 GtkCellRenderer *cursor_cell)
2992 AtkObject *item_obj;
2993 AtkObject *cursor_item_obj;
2995 /* When hitting this path from keynav, the focus cell is
2996 * already set, we dont need to notify the atk object
2997 * but we still need to queue the draw here (in the case
2998 * that the focus cell changes but not the cursor item).
3000 gtk_icon_view_queue_draw_item (icon_view, item);
3002 if (icon_view->priv->cursor_item == item &&
3003 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3006 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3007 if (icon_view->priv->cursor_item != NULL)
3009 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3012 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3013 if (cursor_item_obj != NULL)
3014 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3017 icon_view->priv->cursor_item = item;
3020 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3023 /* Make sure there is a cell in focus initially */
3024 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3025 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3028 /* Notify that accessible focus object has changed */
3029 item_obj = atk_object_ref_accessible_child (obj, item->index);
3031 if (item_obj != NULL)
3033 atk_focus_tracker_notify (item_obj);
3034 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3035 g_object_unref (item_obj);
3040 static GtkIconViewItem *
3041 gtk_icon_view_item_new (void)
3043 GtkIconViewItem *item;
3045 item = g_slice_new0 (GtkIconViewItem);
3047 item->cell_area.width = -1;
3048 item->cell_area.height = -1;
3054 gtk_icon_view_item_free (GtkIconViewItem *item)
3056 g_return_if_fail (item != NULL);
3058 g_slice_free (GtkIconViewItem, item);
3062 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3065 gboolean only_in_cell,
3066 GtkCellRenderer **cell_at_pos)
3071 *cell_at_pos = NULL;
3073 for (items = icon_view->priv->items; items; items = items->next)
3075 GtkIconViewItem *item = items->data;
3076 GdkRectangle *item_area = (GdkRectangle *)item;
3078 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3079 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3080 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3081 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3083 if (only_in_cell || cell_at_pos)
3085 GtkCellRenderer *cell = NULL;
3086 GtkCellAreaContext *context;
3088 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3089 _gtk_icon_view_set_cell_data (icon_view, item);
3091 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3092 y >= item_area->y && y <= item_area->y + item_area->height)
3093 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3094 GTK_WIDGET (icon_view),
3099 *cell_at_pos = cell;
3102 return cell != NULL ? item : NULL;
3113 _gtk_icon_view_select_item (GtkIconView *icon_view,
3114 GtkIconViewItem *item)
3116 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3117 g_return_if_fail (item != NULL);
3122 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3124 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3125 gtk_icon_view_unselect_all_internal (icon_view);
3127 item->selected = TRUE;
3129 gtk_icon_view_item_selected_changed (icon_view, item);
3130 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3132 gtk_icon_view_queue_draw_item (icon_view, item);
3137 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3138 GtkIconViewItem *item)
3140 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3141 g_return_if_fail (item != NULL);
3143 if (!item->selected)
3146 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3147 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3150 item->selected = FALSE;
3152 gtk_icon_view_item_selected_changed (icon_view, item);
3153 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3155 gtk_icon_view_queue_draw_item (icon_view, item);
3159 verify_items (GtkIconView *icon_view)
3164 for (items = icon_view->priv->items; items; items = items->next)
3166 GtkIconViewItem *item = items->data;
3168 if (item->index != i)
3169 g_error ("List item does not match its index: "
3170 "item index %d and list index %d\n", item->index, i);
3177 gtk_icon_view_row_changed (GtkTreeModel *model,
3182 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3184 /* ignore changes in branches */
3185 if (gtk_tree_path_get_depth (path) > 1)
3188 /* An icon view subclass might add it's own model and populate
3189 * things at init() time instead of waiting for the constructor()
3192 if (icon_view->priv->cell_area)
3193 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3195 /* Here we can use a "grow-only" strategy for optimization
3196 * and only invalidate a single item and queue a relayout
3197 * instead of invalidating the whole thing.
3199 * For now GtkIconView still cant deal with huge models
3200 * so just invalidate the whole thing when the model
3203 gtk_icon_view_invalidate_sizes (icon_view);
3205 verify_items (icon_view);
3209 gtk_icon_view_row_inserted (GtkTreeModel *model,
3214 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3216 GtkIconViewItem *item;
3217 gboolean iters_persist;
3220 /* ignore changes in branches */
3221 if (gtk_tree_path_get_depth (path) > 1)
3224 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3226 index = gtk_tree_path_get_indices(path)[0];
3228 item = gtk_icon_view_item_new ();
3233 item->index = index;
3235 /* FIXME: We can be more efficient here,
3236 we can store a tail pointer and use that when
3237 appending (which is a rather common operation)
3239 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3242 list = g_list_nth (icon_view->priv->items, index + 1);
3243 for (; list; list = list->next)
3250 verify_items (icon_view);
3252 gtk_icon_view_queue_layout (icon_view);
3256 gtk_icon_view_row_deleted (GtkTreeModel *model,
3260 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3262 GtkIconViewItem *item;
3264 gboolean emit = FALSE;
3266 /* ignore changes in branches */
3267 if (gtk_tree_path_get_depth (path) > 1)
3270 index = gtk_tree_path_get_indices(path)[0];
3272 list = g_list_nth (icon_view->priv->items, index);
3275 if (icon_view->priv->cell_area)
3276 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3278 if (item == icon_view->priv->anchor_item)
3279 icon_view->priv->anchor_item = NULL;
3281 if (item == icon_view->priv->cursor_item)
3282 icon_view->priv->cursor_item = NULL;
3284 if (item == icon_view->priv->last_prelight)
3285 icon_view->priv->last_prelight = NULL;
3290 gtk_icon_view_item_free (item);
3292 for (next = list->next; next; next = next->next)
3299 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3301 verify_items (icon_view);
3303 gtk_icon_view_queue_layout (icon_view);
3306 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3310 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3311 GtkTreePath *parent,
3316 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3319 GList *items = NULL, *list;
3320 GtkIconViewItem **item_array;
3323 /* ignore changes in branches */
3327 if (icon_view->priv->cell_area)
3328 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3330 length = gtk_tree_model_iter_n_children (model, NULL);
3332 order = g_new (gint, length);
3333 for (i = 0; i < length; i++)
3334 order [new_order[i]] = i;
3336 item_array = g_new (GtkIconViewItem *, length);
3337 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3338 item_array[order[i]] = list->data;
3341 for (i = length - 1; i >= 0; i--)
3343 item_array[i]->index = i;
3344 items = g_list_prepend (items, item_array[i]);
3347 g_free (item_array);
3348 g_list_free (icon_view->priv->items);
3349 icon_view->priv->items = items;
3351 gtk_icon_view_queue_layout (icon_view);
3353 verify_items (icon_view);
3357 gtk_icon_view_build_items (GtkIconView *icon_view)
3361 gboolean iters_persist;
3362 GList *items = NULL;
3364 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3366 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3374 GtkIconViewItem *item = gtk_icon_view_item_new ();
3383 items = g_list_prepend (items, item);
3385 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3387 icon_view->priv->items = g_list_reverse (items);
3391 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3394 GtkMovementStep step,
3398 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3399 I_("move-cursor"), 2,
3403 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3408 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3411 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3416 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3423 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3424 GtkMovementStep step,
3427 GdkModifierType state;
3429 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3430 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3431 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3432 step == GTK_MOVEMENT_DISPLAY_LINES ||
3433 step == GTK_MOVEMENT_PAGES ||
3434 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3436 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3439 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3440 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3442 if (gtk_get_current_event_state (&state))
3444 GdkModifierType extend_mod_mask;
3445 GdkModifierType modify_mod_mask;
3448 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3449 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3451 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3452 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3454 if ((state & modify_mod_mask) == modify_mod_mask)
3455 icon_view->priv->modify_selection_pressed = TRUE;
3456 if ((state & extend_mod_mask) == extend_mod_mask)
3457 icon_view->priv->extend_selection_pressed = TRUE;
3459 /* else we assume not pressed */
3463 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3464 case GTK_MOVEMENT_VISUAL_POSITIONS:
3465 gtk_icon_view_move_cursor_left_right (icon_view, count);
3467 case GTK_MOVEMENT_DISPLAY_LINES:
3468 gtk_icon_view_move_cursor_up_down (icon_view, count);
3470 case GTK_MOVEMENT_PAGES:
3471 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3473 case GTK_MOVEMENT_BUFFER_ENDS:
3474 gtk_icon_view_move_cursor_start_end (icon_view, count);
3477 g_assert_not_reached ();
3480 icon_view->priv->modify_selection_pressed = FALSE;
3481 icon_view->priv->extend_selection_pressed = FALSE;
3483 icon_view->priv->draw_focus = TRUE;
3488 static GtkIconViewItem *
3489 find_item (GtkIconView *icon_view,
3490 GtkIconViewItem *current,
3496 GtkIconViewItem *item;
3498 /* FIXME: this could be more efficient
3500 row = current->row + row_ofs;
3501 col = current->col + col_ofs;
3503 for (items = icon_view->priv->items; items; items = items->next)
3506 if (item->row == row && item->col == col)
3513 static GtkIconViewItem *
3514 find_item_page_up_down (GtkIconView *icon_view,
3515 GtkIconViewItem *current,
3522 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3524 item = g_list_find (icon_view->priv->items, current);
3529 for (next = item->next; next; next = next->next)
3531 if (((GtkIconViewItem *)next->data)->col == col)
3534 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3544 for (next = item->prev; next; next = next->prev)
3546 if (((GtkIconViewItem *)next->data)->col == col)
3549 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3563 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3564 GtkIconViewItem *anchor,
3565 GtkIconViewItem *cursor)
3568 GtkIconViewItem *item;
3569 gint row1, row2, col1, col2;
3570 gboolean dirty = FALSE;
3572 if (anchor->row < cursor->row)
3583 if (anchor->col < cursor->col)
3594 for (items = icon_view->priv->items; items; items = items->next)
3598 if (row1 <= item->row && item->row <= row2 &&
3599 col1 <= item->col && item->col <= col2)
3601 if (!item->selected)
3604 item->selected = TRUE;
3605 gtk_icon_view_item_selected_changed (icon_view, item);
3607 gtk_icon_view_queue_draw_item (icon_view, item);
3615 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3618 GtkIconViewItem *item;
3619 GtkCellRenderer *cell = NULL;
3620 gboolean dirty = FALSE;
3622 GtkDirectionType direction;
3624 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3627 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3629 if (!icon_view->priv->cursor_item)
3634 list = icon_view->priv->items;
3636 list = g_list_last (icon_view->priv->items);
3642 /* Give focus to the first cell initially */
3643 _gtk_icon_view_set_cell_data (icon_view, item);
3644 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3653 item = icon_view->priv->cursor_item;
3654 step = count > 0 ? 1 : -1;
3656 /* Save the current focus cell in case we hit the edge */
3657 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3661 _gtk_icon_view_set_cell_data (icon_view, item);
3663 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3666 item = find_item (icon_view, item, step, 0);
3672 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3674 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3676 gtk_widget_child_focus (toplevel,
3677 direction == GTK_DIR_UP ?
3678 GTK_DIR_TAB_BACKWARD :
3679 GTK_DIR_TAB_FORWARD);
3683 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3687 if (icon_view->priv->modify_selection_pressed ||
3688 !icon_view->priv->extend_selection_pressed ||
3689 !icon_view->priv->anchor_item ||
3690 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3691 icon_view->priv->anchor_item = item;
3693 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3694 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3696 if (!icon_view->priv->modify_selection_pressed &&
3697 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3699 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3700 dirty = gtk_icon_view_select_all_between (icon_view,
3701 icon_view->priv->anchor_item,
3705 gtk_icon_view_scroll_to_item (icon_view, item);
3708 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3712 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3715 GtkIconViewItem *item;
3716 gboolean dirty = FALSE;
3718 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3721 if (!icon_view->priv->cursor_item)
3726 list = icon_view->priv->items;
3728 list = g_list_last (icon_view->priv->items);
3730 item = list ? list->data : NULL;
3733 item = find_item_page_up_down (icon_view,
3734 icon_view->priv->cursor_item,
3737 if (item == icon_view->priv->cursor_item)
3738 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3743 if (icon_view->priv->modify_selection_pressed ||
3744 !icon_view->priv->extend_selection_pressed ||
3745 !icon_view->priv->anchor_item ||
3746 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3747 icon_view->priv->anchor_item = item;
3749 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3751 if (!icon_view->priv->modify_selection_pressed &&
3752 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3754 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3755 dirty = gtk_icon_view_select_all_between (icon_view,
3756 icon_view->priv->anchor_item,
3760 gtk_icon_view_scroll_to_item (icon_view, item);
3763 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3767 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3770 GtkIconViewItem *item;
3771 GtkCellRenderer *cell = NULL;
3772 gboolean dirty = FALSE;
3774 GtkDirectionType direction;
3776 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3779 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3781 if (!icon_view->priv->cursor_item)
3786 list = icon_view->priv->items;
3788 list = g_list_last (icon_view->priv->items);
3794 /* Give focus to the first cell initially */
3795 _gtk_icon_view_set_cell_data (icon_view, item);
3796 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3805 item = icon_view->priv->cursor_item;
3806 step = count > 0 ? 1 : -1;
3808 /* Save the current focus cell in case we hit the edge */
3809 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3813 _gtk_icon_view_set_cell_data (icon_view, item);
3815 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3818 item = find_item (icon_view, item, 0, step);
3824 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3826 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3828 gtk_widget_child_focus (toplevel,
3829 direction == GTK_DIR_LEFT ?
3830 GTK_DIR_TAB_BACKWARD :
3831 GTK_DIR_TAB_FORWARD);
3835 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3839 if (icon_view->priv->modify_selection_pressed ||
3840 !icon_view->priv->extend_selection_pressed ||
3841 !icon_view->priv->anchor_item ||
3842 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3843 icon_view->priv->anchor_item = item;
3845 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3846 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3848 if (!icon_view->priv->modify_selection_pressed &&
3849 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3851 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3852 dirty = gtk_icon_view_select_all_between (icon_view,
3853 icon_view->priv->anchor_item,
3857 gtk_icon_view_scroll_to_item (icon_view, item);
3860 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3864 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3867 GtkIconViewItem *item;
3869 gboolean dirty = FALSE;
3871 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3875 list = icon_view->priv->items;
3877 list = g_list_last (icon_view->priv->items);
3879 item = list ? list->data : NULL;
3881 if (item == icon_view->priv->cursor_item)
3882 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3887 if (icon_view->priv->modify_selection_pressed ||
3888 !icon_view->priv->extend_selection_pressed ||
3889 !icon_view->priv->anchor_item ||
3890 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3891 icon_view->priv->anchor_item = item;
3893 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3895 if (!icon_view->priv->modify_selection_pressed &&
3896 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3898 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3899 dirty = gtk_icon_view_select_all_between (icon_view,
3900 icon_view->priv->anchor_item,
3904 gtk_icon_view_scroll_to_item (icon_view, item);
3907 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3911 * gtk_icon_view_scroll_to_path:
3912 * @icon_view: A #GtkIconView.
3913 * @path: The path of the item to move to.
3914 * @use_align: whether to use alignment arguments, or %FALSE.
3915 * @row_align: The vertical alignment of the item specified by @path.
3916 * @col_align: The horizontal alignment of the item specified by @path.
3918 * Moves the alignments of @icon_view to the position specified by @path.
3919 * @row_align determines where the row is placed, and @col_align determines
3920 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3921 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3924 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3925 * tree does the minimum amount of work to scroll the item onto the screen.
3926 * This means that the item will be scrolled to the edge closest to its current
3927 * position. If the item is currently visible on the screen, nothing is done.
3929 * This function only works if the model is set, and @path is a valid row on
3930 * the model. If the model changes before the @icon_view is realized, the
3931 * centered path will be modified to reflect this change.
3936 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3942 GtkIconViewItem *item = NULL;
3945 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3946 g_return_if_fail (path != NULL);
3947 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3948 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3950 widget = GTK_WIDGET (icon_view);
3952 if (gtk_tree_path_get_depth (path) > 0)
3953 item = g_list_nth_data (icon_view->priv->items,
3954 gtk_tree_path_get_indices(path)[0]);
3956 if (!item || item->cell_area.width < 0 ||
3957 !gtk_widget_get_realized (widget))
3959 if (icon_view->priv->scroll_to_path)
3960 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3962 icon_view->priv->scroll_to_path = NULL;
3965 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3967 icon_view->priv->scroll_to_use_align = use_align;
3968 icon_view->priv->scroll_to_row_align = row_align;
3969 icon_view->priv->scroll_to_col_align = col_align;
3976 GtkAllocation allocation;
3979 GdkRectangle item_area =
3981 item->cell_area.x - icon_view->priv->item_padding,
3982 item->cell_area.y - icon_view->priv->item_padding,
3983 item->cell_area.width + icon_view->priv->item_padding * 2,
3984 item->cell_area.height + icon_view->priv->item_padding * 2
3987 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3989 gtk_widget_get_allocation (widget, &allocation);
3991 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
3993 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3994 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
3996 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
3998 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3999 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4001 gtk_adjustment_changed (icon_view->priv->hadjustment);
4002 gtk_adjustment_changed (icon_view->priv->vadjustment);
4005 gtk_icon_view_scroll_to_item (icon_view, item);
4010 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4011 GtkIconViewItem *item)
4013 GtkIconViewPrivate *priv = icon_view->priv;
4014 GtkWidget *widget = GTK_WIDGET (icon_view);
4015 GtkAdjustment *hadj, *vadj;
4016 GtkAllocation allocation;
4018 GdkRectangle item_area;
4020 item_area.x = item->cell_area.x - priv->item_padding;
4021 item_area.y = item->cell_area.y - priv->item_padding;
4022 item_area.width = item->cell_area.width + priv->item_padding * 2;
4023 item_area.height = item->cell_area.height + priv->item_padding * 2;
4025 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4026 gtk_widget_get_allocation (widget, &allocation);
4028 hadj = icon_view->priv->hadjustment;
4029 vadj = icon_view->priv->vadjustment;
4031 if (y + item_area.y < 0)
4032 gtk_adjustment_set_value (vadj,
4033 gtk_adjustment_get_value (vadj)
4035 else if (y + item_area.y + item_area.height > allocation.height)
4036 gtk_adjustment_set_value (vadj,
4037 gtk_adjustment_get_value (vadj)
4038 + y + item_area.y + item_area.height - allocation.height);
4040 if (x + item_area.x < 0)
4041 gtk_adjustment_set_value (hadj,
4042 gtk_adjustment_get_value (hadj)
4044 else if (x + item_area.x + item_area.width > allocation.width)
4045 gtk_adjustment_set_value (hadj,
4046 gtk_adjustment_get_value (hadj)
4047 + x + item_area.x + item_area.width - allocation.width);
4049 gtk_adjustment_changed (hadj);
4050 gtk_adjustment_changed (vadj);
4053 /* GtkCellLayout implementation */
4056 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4057 GtkCellArea *cell_area)
4059 GtkIconViewPrivate *priv = icon_view->priv;
4061 if (priv->cell_area)
4065 priv->cell_area = cell_area;
4067 priv->cell_area = gtk_cell_area_box_new ();
4069 g_object_ref_sink (priv->cell_area);
4071 if (GTK_IS_ORIENTABLE (priv->cell_area))
4072 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4074 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4076 priv->add_editable_id =
4077 g_signal_connect (priv->cell_area, "add-editable",
4078 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4079 priv->remove_editable_id =
4080 g_signal_connect (priv->cell_area, "remove-editable",
4081 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4082 priv->context_changed_id =
4083 g_signal_connect (priv->cell_area_context, "notify",
4084 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4086 update_text_cell (icon_view);
4087 update_pixbuf_cell (icon_view);
4090 static GtkCellArea *
4091 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4093 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4094 GtkIconViewPrivate *priv = icon_view->priv;
4096 if (G_UNLIKELY (!priv->cell_area))
4097 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4099 return icon_view->priv->cell_area;
4103 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4104 GtkIconViewItem *item)
4106 gboolean iters_persist;
4109 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4115 path = gtk_tree_path_new_from_indices (item->index, -1);
4116 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4118 gtk_tree_path_free (path);
4123 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4124 icon_view->priv->model,
4125 &iter, FALSE, FALSE);
4134 * gtk_icon_view_new:
4136 * Creates a new #GtkIconView widget
4138 * Return value: A newly created #GtkIconView widget
4143 gtk_icon_view_new (void)
4145 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4149 * gtk_icon_view_new_with_area:
4150 * @area: the #GtkCellArea to use to layout cells
4152 * Creates a new #GtkIconView widget using the
4153 * specified @area to layout cells inside the icons.
4155 * Return value: A newly created #GtkIconView widget
4160 gtk_icon_view_new_with_area (GtkCellArea *area)
4162 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4166 * gtk_icon_view_new_with_model:
4167 * @model: The model.
4169 * Creates a new #GtkIconView widget with the model @model.
4171 * Return value: A newly created #GtkIconView widget.
4176 gtk_icon_view_new_with_model (GtkTreeModel *model)
4178 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4182 * gtk_icon_view_convert_widget_to_bin_window_coords:
4183 * @icon_view: a #GtkIconView
4184 * @wx: X coordinate relative to the widget
4185 * @wy: Y coordinate relative to the widget
4186 * @bx: (out): return location for bin_window X coordinate
4187 * @by: (out): return location for bin_window Y coordinate
4189 * Converts widget coordinates to coordinates for the bin_window,
4190 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4195 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4203 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4205 if (icon_view->priv->bin_window)
4206 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4217 * gtk_icon_view_get_path_at_pos:
4218 * @icon_view: A #GtkIconView.
4219 * @x: The x position to be identified
4220 * @y: The y position to be identified
4222 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4223 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4224 * the cell at the specified position.
4225 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4226 * widget coordinates to bin_window coordinates.
4228 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4229 * if no icon exists at that position.
4234 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4238 GtkIconViewItem *item;
4241 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4243 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4248 path = gtk_tree_path_new_from_indices (item->index, -1);
4254 * gtk_icon_view_get_item_at_pos:
4255 * @icon_view: A #GtkIconView.
4256 * @x: The x position to be identified
4257 * @y: The y position to be identified
4258 * @path: (out) (allow-none): Return location for the path, or %NULL
4259 * @cell: (out) (allow-none): Return location for the renderer
4260 * responsible for the cell at (@x, @y), or %NULL
4262 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4263 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4264 * obtains the cell at the specified position. The returned path should
4265 * be freed with gtk_tree_path_free().
4266 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4267 * widget coordinates to bin_window coordinates.
4269 * Return value: %TRUE if an item exists at the specified position
4274 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4278 GtkCellRenderer **cell)
4280 GtkIconViewItem *item;
4281 GtkCellRenderer *renderer = NULL;
4283 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4285 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4290 *path = gtk_tree_path_new_from_indices (item->index, -1);
4298 return (item != NULL);
4302 * gtk_icon_view_set_tooltip_item:
4303 * @icon_view: a #GtkIconView
4304 * @tooltip: a #GtkTooltip
4305 * @path: a #GtkTreePath
4307 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4308 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4309 * See also gtk_tooltip_set_tip_area().
4314 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4315 GtkTooltip *tooltip,
4318 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4319 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4321 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4325 * gtk_icon_view_set_tooltip_cell:
4326 * @icon_view: a #GtkIconView
4327 * @tooltip: a #GtkTooltip
4328 * @path: a #GtkTreePath
4329 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4331 * Sets the tip area of @tooltip to the area which @cell occupies in
4332 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4334 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4339 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4340 GtkTooltip *tooltip,
4342 GtkCellRenderer *cell)
4345 GtkIconViewItem *item = NULL;
4348 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4349 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4350 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4352 if (gtk_tree_path_get_depth (path) > 0)
4353 item = g_list_nth_data (icon_view->priv->items,
4354 gtk_tree_path_get_indices(path)[0]);
4361 GtkCellAreaContext *context;
4363 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4364 _gtk_icon_view_set_cell_data (icon_view, item);
4365 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4366 GTK_WIDGET (icon_view),
4367 cell, (GdkRectangle *)item, &rect);
4371 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4372 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4373 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4374 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4377 if (icon_view->priv->bin_window)
4379 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4384 gtk_tooltip_set_tip_area (tooltip, &rect);
4389 * gtk_icon_view_get_tooltip_context:
4390 * @icon_view: an #GtkIconView
4391 * @x: (inout): the x coordinate (relative to widget coordinates)
4392 * @y: (inout): the y coordinate (relative to widget coordinates)
4393 * @keyboard_tip: whether this is a keyboard tooltip or not
4394 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4395 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4396 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4398 * This function is supposed to be used in a #GtkWidget::query-tooltip
4399 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4400 * which are received in the signal handler, should be passed to this
4401 * function without modification.
4403 * The return value indicates whether there is an icon view item at the given
4404 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4405 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4406 * @model, @path and @iter which have been provided will be set to point to
4407 * that row and the corresponding model. @x and @y will always be converted
4408 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4410 * Return value: whether or not the given tooltip context points to a item
4415 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4418 gboolean keyboard_tip,
4419 GtkTreeModel **model,
4423 GtkTreePath *tmppath = NULL;
4425 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4426 g_return_val_if_fail (x != NULL, FALSE);
4427 g_return_val_if_fail (y != NULL, FALSE);
4431 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4438 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4441 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4446 *model = gtk_icon_view_get_model (icon_view);
4449 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4455 gtk_tree_path_free (tmppath);
4461 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4464 gboolean keyboard_tip,
4465 GtkTooltip *tooltip,
4471 GtkTreeModel *model;
4472 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4474 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4477 &model, &path, &iter))
4480 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4484 gtk_tree_path_free (path);
4488 gtk_tooltip_set_markup (tooltip, str);
4489 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4491 gtk_tree_path_free (path);
4499 * gtk_icon_view_set_tooltip_column:
4500 * @icon_view: a #GtkIconView
4501 * @column: an integer, which is a valid column number for @icon_view's model
4503 * If you only plan to have simple (text-only) tooltips on full items, you
4504 * can use this function to have #GtkIconView handle these automatically
4505 * for you. @column should be set to the column in @icon_view's model
4506 * containing the tooltip texts, or -1 to disable this feature.
4508 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4509 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4511 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4512 * so &, <, etc have to be escaped in the text.
4517 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4520 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4522 if (column == icon_view->priv->tooltip_column)
4527 g_signal_handlers_disconnect_by_func (icon_view,
4528 gtk_icon_view_set_tooltip_query_cb,
4530 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4534 if (icon_view->priv->tooltip_column == -1)
4536 g_signal_connect (icon_view, "query-tooltip",
4537 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4538 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4542 icon_view->priv->tooltip_column = column;
4543 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4547 * gtk_icon_view_get_tooltip_column:
4548 * @icon_view: a #GtkIconView
4550 * Returns the column of @icon_view's model which is being used for
4551 * displaying tooltips on @icon_view's rows.
4553 * Return value: the index of the tooltip column that is currently being
4554 * used, or -1 if this is disabled.
4559 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4561 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4563 return icon_view->priv->tooltip_column;
4567 * gtk_icon_view_get_visible_range:
4568 * @icon_view: A #GtkIconView
4569 * @start_path: (out) (allow-none): Return location for start of region,
4571 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4573 * Sets @start_path and @end_path to be the first and last visible path.
4574 * Note that there may be invisible paths in between.
4576 * Both paths should be freed with gtk_tree_path_free() after use.
4578 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4583 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4584 GtkTreePath **start_path,
4585 GtkTreePath **end_path)
4587 gint start_index = -1;
4588 gint end_index = -1;
4591 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4593 if (icon_view->priv->hadjustment == NULL ||
4594 icon_view->priv->vadjustment == NULL)
4597 if (start_path == NULL && end_path == NULL)
4600 for (icons = icon_view->priv->items; icons; icons = icons->next)
4602 GtkIconViewItem *item = icons->data;
4603 GdkRectangle *item_area = (GdkRectangle *)item;
4605 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4606 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4608 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4609 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4611 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4612 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4614 if (start_index == -1)
4615 start_index = item->index;
4616 end_index = item->index;
4620 if (start_path && start_index != -1)
4621 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4622 if (end_path && end_index != -1)
4623 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4625 return start_index != -1;
4629 * gtk_icon_view_selected_foreach:
4630 * @icon_view: A #GtkIconView.
4631 * @func: (scope call): The function to call for each selected icon.
4632 * @data: User data to pass to the function.
4634 * Calls a function for each selected icon. Note that the model or
4635 * selection cannot be modified from within this function.
4640 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4641 GtkIconViewForeachFunc func,
4646 for (list = icon_view->priv->items; list; list = list->next)
4648 GtkIconViewItem *item = list->data;
4649 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4652 (* func) (icon_view, path, data);
4654 gtk_tree_path_free (path);
4659 * gtk_icon_view_set_selection_mode:
4660 * @icon_view: A #GtkIconView.
4661 * @mode: The selection mode
4663 * Sets the selection mode of the @icon_view.
4668 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4669 GtkSelectionMode mode)
4671 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4673 if (mode == icon_view->priv->selection_mode)
4676 if (mode == GTK_SELECTION_NONE ||
4677 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4678 gtk_icon_view_unselect_all (icon_view);
4680 icon_view->priv->selection_mode = mode;
4682 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4686 * gtk_icon_view_get_selection_mode:
4687 * @icon_view: A #GtkIconView.
4689 * Gets the selection mode of the @icon_view.
4691 * Return value: the current selection mode
4696 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4698 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4700 return icon_view->priv->selection_mode;
4704 * gtk_icon_view_set_model:
4705 * @icon_view: A #GtkIconView.
4706 * @model: (allow-none): The model.
4708 * Sets the model for a #GtkIconView.
4709 * If the @icon_view already has a model set, it will remove
4710 * it before setting the new model. If @model is %NULL, then
4711 * it will unset the old model.
4716 gtk_icon_view_set_model (GtkIconView *icon_view,
4717 GtkTreeModel *model)
4719 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4720 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4722 if (icon_view->priv->model == model)
4725 if (icon_view->priv->scroll_to_path)
4727 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4728 icon_view->priv->scroll_to_path = NULL;
4731 /* The area can be NULL while disposing */
4732 if (icon_view->priv->cell_area)
4733 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4739 if (icon_view->priv->pixbuf_column != -1)
4741 column_type = gtk_tree_model_get_column_type (model,
4742 icon_view->priv->pixbuf_column);
4744 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4747 if (icon_view->priv->text_column != -1)
4749 column_type = gtk_tree_model_get_column_type (model,
4750 icon_view->priv->text_column);
4752 g_return_if_fail (column_type == G_TYPE_STRING);
4755 if (icon_view->priv->markup_column != -1)
4757 column_type = gtk_tree_model_get_column_type (model,
4758 icon_view->priv->markup_column);
4760 g_return_if_fail (column_type == G_TYPE_STRING);
4765 if (icon_view->priv->model)
4767 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4768 gtk_icon_view_row_changed,
4770 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4771 gtk_icon_view_row_inserted,
4773 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4774 gtk_icon_view_row_deleted,
4776 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4777 gtk_icon_view_rows_reordered,
4780 g_object_unref (icon_view->priv->model);
4782 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4783 g_list_free (icon_view->priv->items);
4784 icon_view->priv->items = NULL;
4785 icon_view->priv->anchor_item = NULL;
4786 icon_view->priv->cursor_item = NULL;
4787 icon_view->priv->last_single_clicked = NULL;
4788 icon_view->priv->last_prelight = NULL;
4789 icon_view->priv->width = 0;
4790 icon_view->priv->height = 0;
4793 icon_view->priv->model = model;
4795 if (icon_view->priv->model)
4797 g_object_ref (icon_view->priv->model);
4798 g_signal_connect (icon_view->priv->model,
4800 G_CALLBACK (gtk_icon_view_row_changed),
4802 g_signal_connect (icon_view->priv->model,
4804 G_CALLBACK (gtk_icon_view_row_inserted),
4806 g_signal_connect (icon_view->priv->model,
4808 G_CALLBACK (gtk_icon_view_row_deleted),
4810 g_signal_connect (icon_view->priv->model,
4812 G_CALLBACK (gtk_icon_view_rows_reordered),
4815 gtk_icon_view_build_items (icon_view);
4817 gtk_icon_view_layout (icon_view);
4820 g_object_notify (G_OBJECT (icon_view), "model");
4822 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4823 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4827 * gtk_icon_view_get_model:
4828 * @icon_view: a #GtkIconView
4830 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4833 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4834 * currently being used.
4839 gtk_icon_view_get_model (GtkIconView *icon_view)
4841 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4843 return icon_view->priv->model;
4847 update_text_cell (GtkIconView *icon_view)
4849 if (!icon_view->priv->cell_area)
4852 if (icon_view->priv->text_column == -1 &&
4853 icon_view->priv->markup_column == -1)
4855 if (icon_view->priv->text_cell != NULL)
4857 gtk_cell_area_remove (icon_view->priv->cell_area,
4858 icon_view->priv->text_cell);
4859 icon_view->priv->text_cell = NULL;
4864 if (icon_view->priv->text_cell == NULL)
4866 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4868 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4871 if (icon_view->priv->markup_column != -1)
4872 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4873 icon_view->priv->text_cell,
4874 "markup", icon_view->priv->markup_column,
4877 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4878 icon_view->priv->text_cell,
4879 "text", icon_view->priv->text_column,
4882 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4883 g_object_set (icon_view->priv->text_cell,
4884 "alignment", PANGO_ALIGN_CENTER,
4885 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4890 g_object_set (icon_view->priv->text_cell,
4891 "alignment", PANGO_ALIGN_LEFT,
4892 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4900 update_pixbuf_cell (GtkIconView *icon_view)
4902 if (!icon_view->priv->cell_area)
4905 if (icon_view->priv->pixbuf_column == -1)
4907 if (icon_view->priv->pixbuf_cell != NULL)
4909 gtk_cell_area_remove (icon_view->priv->cell_area,
4910 icon_view->priv->pixbuf_cell);
4912 icon_view->priv->pixbuf_cell = NULL;
4917 if (icon_view->priv->pixbuf_cell == NULL)
4919 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4921 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4924 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4925 icon_view->priv->pixbuf_cell,
4926 "pixbuf", icon_view->priv->pixbuf_column,
4929 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4930 g_object_set (icon_view->priv->pixbuf_cell,
4935 g_object_set (icon_view->priv->pixbuf_cell,
4943 * gtk_icon_view_set_text_column:
4944 * @icon_view: A #GtkIconView.
4945 * @column: A column in the currently used model, or -1 to display no text
4947 * Sets the column with text for @icon_view to be @column. The text
4948 * column must be of type #G_TYPE_STRING.
4953 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4956 if (column == icon_view->priv->text_column)
4960 icon_view->priv->text_column = -1;
4963 if (icon_view->priv->model != NULL)
4967 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4969 g_return_if_fail (column_type == G_TYPE_STRING);
4972 icon_view->priv->text_column = column;
4975 if (icon_view->priv->cell_area)
4976 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4978 update_text_cell (icon_view);
4980 gtk_icon_view_invalidate_sizes (icon_view);
4982 g_object_notify (G_OBJECT (icon_view), "text-column");
4986 * gtk_icon_view_get_text_column:
4987 * @icon_view: A #GtkIconView.
4989 * Returns the column with text for @icon_view.
4991 * Returns: the text column, or -1 if it's unset.
4996 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4998 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5000 return icon_view->priv->text_column;
5004 * gtk_icon_view_set_markup_column:
5005 * @icon_view: A #GtkIconView.
5006 * @column: A column in the currently used model, or -1 to display no text
5008 * Sets the column with markup information for @icon_view to be
5009 * @column. The markup column must be of type #G_TYPE_STRING.
5010 * If the markup column is set to something, it overrides
5011 * the text column set by gtk_icon_view_set_text_column().
5016 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5019 if (column == icon_view->priv->markup_column)
5023 icon_view->priv->markup_column = -1;
5026 if (icon_view->priv->model != NULL)
5030 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5032 g_return_if_fail (column_type == G_TYPE_STRING);
5035 icon_view->priv->markup_column = column;
5038 if (icon_view->priv->cell_area)
5039 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5041 update_text_cell (icon_view);
5043 gtk_icon_view_invalidate_sizes (icon_view);
5045 g_object_notify (G_OBJECT (icon_view), "markup-column");
5049 * gtk_icon_view_get_markup_column:
5050 * @icon_view: A #GtkIconView.
5052 * Returns the column with markup text for @icon_view.
5054 * Returns: the markup column, or -1 if it's unset.
5059 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5061 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5063 return icon_view->priv->markup_column;
5067 * gtk_icon_view_set_pixbuf_column:
5068 * @icon_view: A #GtkIconView.
5069 * @column: A column in the currently used model, or -1 to disable
5071 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5072 * column must be of type #GDK_TYPE_PIXBUF
5077 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5080 if (column == icon_view->priv->pixbuf_column)
5084 icon_view->priv->pixbuf_column = -1;
5087 if (icon_view->priv->model != NULL)
5091 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5093 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5096 icon_view->priv->pixbuf_column = column;
5099 if (icon_view->priv->cell_area)
5100 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5102 update_pixbuf_cell (icon_view);
5104 gtk_icon_view_invalidate_sizes (icon_view);
5106 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5111 * gtk_icon_view_get_pixbuf_column:
5112 * @icon_view: A #GtkIconView.
5114 * Returns the column with pixbufs for @icon_view.
5116 * Returns: the pixbuf column, or -1 if it's unset.
5121 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5123 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5125 return icon_view->priv->pixbuf_column;
5129 * gtk_icon_view_select_path:
5130 * @icon_view: A #GtkIconView.
5131 * @path: The #GtkTreePath to be selected.
5133 * Selects the row at @path.
5138 gtk_icon_view_select_path (GtkIconView *icon_view,
5141 GtkIconViewItem *item = NULL;
5143 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5144 g_return_if_fail (icon_view->priv->model != NULL);
5145 g_return_if_fail (path != NULL);
5147 if (gtk_tree_path_get_depth (path) > 0)
5148 item = g_list_nth_data (icon_view->priv->items,
5149 gtk_tree_path_get_indices(path)[0]);
5152 _gtk_icon_view_select_item (icon_view, item);
5156 * gtk_icon_view_unselect_path:
5157 * @icon_view: A #GtkIconView.
5158 * @path: The #GtkTreePath to be unselected.
5160 * Unselects the row at @path.
5165 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5168 GtkIconViewItem *item;
5170 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5171 g_return_if_fail (icon_view->priv->model != NULL);
5172 g_return_if_fail (path != NULL);
5174 item = g_list_nth_data (icon_view->priv->items,
5175 gtk_tree_path_get_indices(path)[0]);
5180 _gtk_icon_view_unselect_item (icon_view, item);
5184 * gtk_icon_view_get_selected_items:
5185 * @icon_view: A #GtkIconView.
5187 * Creates a list of paths of all selected items. Additionally, if you are
5188 * planning on modifying the model after calling this function, you may
5189 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5190 * To do this, you can use gtk_tree_row_reference_new().
5192 * To free the return value, use:
5194 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5195 * g_list_free (list);
5198 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5203 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5206 GList *selected = NULL;
5208 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5210 for (list = icon_view->priv->items; list != NULL; list = list->next)
5212 GtkIconViewItem *item = list->data;
5216 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5218 selected = g_list_prepend (selected, path);
5226 * gtk_icon_view_select_all:
5227 * @icon_view: A #GtkIconView.
5229 * Selects all the icons. @icon_view must has its selection mode set
5230 * to #GTK_SELECTION_MULTIPLE.
5235 gtk_icon_view_select_all (GtkIconView *icon_view)
5238 gboolean dirty = FALSE;
5240 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5242 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5245 for (items = icon_view->priv->items; items; items = items->next)
5247 GtkIconViewItem *item = items->data;
5249 if (!item->selected)
5252 item->selected = TRUE;
5253 gtk_icon_view_queue_draw_item (icon_view, item);
5258 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5262 * gtk_icon_view_unselect_all:
5263 * @icon_view: A #GtkIconView.
5265 * Unselects all the icons.
5270 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5272 gboolean dirty = FALSE;
5274 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5276 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5279 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5282 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5286 * gtk_icon_view_path_is_selected:
5287 * @icon_view: A #GtkIconView.
5288 * @path: A #GtkTreePath to check selection on.
5290 * Returns %TRUE if the icon pointed to by @path is currently
5291 * selected. If @path does not point to a valid location, %FALSE is returned.
5293 * Return value: %TRUE if @path is selected.
5298 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5301 GtkIconViewItem *item;
5303 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5304 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5305 g_return_val_if_fail (path != NULL, FALSE);
5307 item = g_list_nth_data (icon_view->priv->items,
5308 gtk_tree_path_get_indices(path)[0]);
5313 return item->selected;
5317 * gtk_icon_view_get_item_row:
5318 * @icon_view: a #GtkIconView
5319 * @path: the #GtkTreePath of the item
5321 * Gets the row in which the item @path is currently
5322 * displayed. Row numbers start at 0.
5324 * Returns: The row in which the item is displayed
5329 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5332 GtkIconViewItem *item;
5334 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5335 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5336 g_return_val_if_fail (path != NULL, -1);
5338 item = g_list_nth_data (icon_view->priv->items,
5339 gtk_tree_path_get_indices(path)[0]);
5348 * gtk_icon_view_get_item_column:
5349 * @icon_view: a #GtkIconView
5350 * @path: the #GtkTreePath of the item
5352 * Gets the column in which the item @path is currently
5353 * displayed. Column numbers start at 0.
5355 * Returns: The column in which the item is displayed
5360 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5363 GtkIconViewItem *item;
5365 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5366 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5367 g_return_val_if_fail (path != NULL, -1);
5369 item = g_list_nth_data (icon_view->priv->items,
5370 gtk_tree_path_get_indices(path)[0]);
5379 * gtk_icon_view_item_activated:
5380 * @icon_view: A #GtkIconView
5381 * @path: The #GtkTreePath to be activated
5383 * Activates the item determined by @path.
5388 gtk_icon_view_item_activated (GtkIconView *icon_view,
5391 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5392 g_return_if_fail (path != NULL);
5394 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5398 * gtk_icon_view_set_item_orientation:
5399 * @icon_view: a #GtkIconView
5400 * @orientation: the relative position of texts and icons
5402 * Sets the ::item-orientation property which determines whether the labels
5403 * are drawn beside the icons instead of below.
5408 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5409 GtkOrientation orientation)
5411 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5413 if (icon_view->priv->item_orientation != orientation)
5415 icon_view->priv->item_orientation = orientation;
5417 if (icon_view->priv->cell_area)
5419 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5420 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5421 icon_view->priv->item_orientation);
5423 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5426 gtk_icon_view_invalidate_sizes (icon_view);
5428 update_text_cell (icon_view);
5429 update_pixbuf_cell (icon_view);
5431 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5436 * gtk_icon_view_get_item_orientation:
5437 * @icon_view: a #GtkIconView
5439 * Returns the value of the ::item-orientation property which determines
5440 * whether the labels are drawn beside the icons instead of below.
5442 * Return value: the relative position of texts and icons
5447 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5449 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5450 GTK_ORIENTATION_VERTICAL);
5452 return icon_view->priv->item_orientation;
5456 * gtk_icon_view_set_columns:
5457 * @icon_view: a #GtkIconView
5458 * @columns: the number of columns
5460 * Sets the ::columns property which determines in how
5461 * many columns the icons are arranged. If @columns is
5462 * -1, the number of columns will be chosen automatically
5463 * to fill the available area.
5468 gtk_icon_view_set_columns (GtkIconView *icon_view,
5471 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5473 if (icon_view->priv->columns != columns)
5475 icon_view->priv->columns = columns;
5477 if (icon_view->priv->cell_area)
5478 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5480 gtk_icon_view_queue_layout (icon_view);
5482 g_object_notify (G_OBJECT (icon_view), "columns");
5487 * gtk_icon_view_get_columns:
5488 * @icon_view: a #GtkIconView
5490 * Returns the value of the ::columns property.
5492 * Return value: the number of columns, or -1
5497 gtk_icon_view_get_columns (GtkIconView *icon_view)
5499 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5501 return icon_view->priv->columns;
5505 * gtk_icon_view_set_item_width:
5506 * @icon_view: a #GtkIconView
5507 * @item_width: the width for each item
5509 * Sets the ::item-width property which specifies the width
5510 * to use for each item. If it is set to -1, the icon view will
5511 * automatically determine a suitable item size.
5516 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5519 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5521 if (icon_view->priv->item_width != item_width)
5523 icon_view->priv->item_width = item_width;
5525 if (icon_view->priv->cell_area)
5526 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5528 gtk_icon_view_invalidate_sizes (icon_view);
5530 update_text_cell (icon_view);
5532 g_object_notify (G_OBJECT (icon_view), "item-width");
5537 * gtk_icon_view_get_item_width:
5538 * @icon_view: a #GtkIconView
5540 * Returns the value of the ::item-width property.
5542 * Return value: the width of a single item, or -1
5547 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5549 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5551 return icon_view->priv->item_width;
5556 * gtk_icon_view_set_spacing:
5557 * @icon_view: a #GtkIconView
5558 * @spacing: the spacing
5560 * Sets the ::spacing property which specifies the space
5561 * which is inserted between the cells (i.e. the icon and
5562 * the text) of an item.
5567 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5570 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5572 if (icon_view->priv->spacing != spacing)
5574 icon_view->priv->spacing = spacing;
5576 if (icon_view->priv->cell_area)
5577 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5579 gtk_icon_view_invalidate_sizes (icon_view);
5581 g_object_notify (G_OBJECT (icon_view), "spacing");
5586 * gtk_icon_view_get_spacing:
5587 * @icon_view: a #GtkIconView
5589 * Returns the value of the ::spacing property.
5591 * Return value: the space between cells
5596 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5598 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5600 return icon_view->priv->spacing;
5604 * gtk_icon_view_set_row_spacing:
5605 * @icon_view: a #GtkIconView
5606 * @row_spacing: the row spacing
5608 * Sets the ::row-spacing property which specifies the space
5609 * which is inserted between the rows of the icon view.
5614 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5617 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5619 if (icon_view->priv->row_spacing != row_spacing)
5621 icon_view->priv->row_spacing = row_spacing;
5623 if (icon_view->priv->cell_area)
5624 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5626 gtk_icon_view_invalidate_sizes (icon_view);
5628 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5633 * gtk_icon_view_get_row_spacing:
5634 * @icon_view: a #GtkIconView
5636 * Returns the value of the ::row-spacing property.
5638 * Return value: the space between rows
5643 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5645 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5647 return icon_view->priv->row_spacing;
5651 * gtk_icon_view_set_column_spacing:
5652 * @icon_view: a #GtkIconView
5653 * @column_spacing: the column spacing
5655 * Sets the ::column-spacing property which specifies the space
5656 * which is inserted between the columns of the icon view.
5661 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5662 gint column_spacing)
5664 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5666 if (icon_view->priv->column_spacing != column_spacing)
5668 icon_view->priv->column_spacing = column_spacing;
5670 if (icon_view->priv->cell_area)
5671 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5673 gtk_icon_view_invalidate_sizes (icon_view);
5675 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5680 * gtk_icon_view_get_column_spacing:
5681 * @icon_view: a #GtkIconView
5683 * Returns the value of the ::column-spacing property.
5685 * Return value: the space between columns
5690 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5692 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5694 return icon_view->priv->column_spacing;
5698 * gtk_icon_view_set_margin:
5699 * @icon_view: a #GtkIconView
5700 * @margin: the margin
5702 * Sets the ::margin property which specifies the space
5703 * which is inserted at the top, bottom, left and right
5709 gtk_icon_view_set_margin (GtkIconView *icon_view,
5712 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5714 if (icon_view->priv->margin != margin)
5716 icon_view->priv->margin = margin;
5718 if (icon_view->priv->cell_area)
5719 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5721 gtk_icon_view_invalidate_sizes (icon_view);
5723 g_object_notify (G_OBJECT (icon_view), "margin");
5728 * gtk_icon_view_get_margin:
5729 * @icon_view: a #GtkIconView
5731 * Returns the value of the ::margin property.
5733 * Return value: the space at the borders
5738 gtk_icon_view_get_margin (GtkIconView *icon_view)
5740 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5742 return icon_view->priv->margin;
5746 * gtk_icon_view_set_item_padding:
5747 * @icon_view: a #GtkIconView
5748 * @item_padding: the item padding
5750 * Sets the #GtkIconView:item-padding property which specifies the padding
5751 * around each of the icon view's items.
5756 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5759 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5761 if (icon_view->priv->item_padding != item_padding)
5763 icon_view->priv->item_padding = item_padding;
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 g_object_notify (G_OBJECT (icon_view), "item-padding");
5775 * gtk_icon_view_get_item_padding:
5776 * @icon_view: a #GtkIconView
5778 * Returns the value of the ::item-padding property.
5780 * Return value: the padding around items
5785 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5787 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5789 return icon_view->priv->item_padding;
5792 /* Get/set whether drag_motion requested the drag data and
5793 * drag_data_received should thus not actually insert the data,
5794 * since the data doesn't result from a drop.
5797 set_status_pending (GdkDragContext *context,
5798 GdkDragAction suggested_action)
5800 g_object_set_data (G_OBJECT (context),
5801 I_("gtk-icon-view-status-pending"),
5802 GINT_TO_POINTER (suggested_action));
5805 static GdkDragAction
5806 get_status_pending (GdkDragContext *context)
5808 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5809 "gtk-icon-view-status-pending"));
5813 unset_reorderable (GtkIconView *icon_view)
5815 if (icon_view->priv->reorderable)
5817 icon_view->priv->reorderable = FALSE;
5818 g_object_notify (G_OBJECT (icon_view), "reorderable");
5823 set_source_row (GdkDragContext *context,
5824 GtkTreeModel *model,
5825 GtkTreePath *source_row)
5828 g_object_set_data_full (G_OBJECT (context),
5829 I_("gtk-icon-view-source-row"),
5830 gtk_tree_row_reference_new (model, source_row),
5831 (GDestroyNotify) gtk_tree_row_reference_free);
5833 g_object_set_data_full (G_OBJECT (context),
5834 I_("gtk-icon-view-source-row"),
5839 get_source_row (GdkDragContext *context)
5841 GtkTreeRowReference *ref;
5843 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5846 return gtk_tree_row_reference_get_path (ref);
5853 GtkTreeRowReference *dest_row;
5854 gboolean empty_view_drop;
5855 gboolean drop_append_mode;
5859 dest_row_free (gpointer data)
5861 DestRow *dr = (DestRow *)data;
5863 gtk_tree_row_reference_free (dr->dest_row);
5868 set_dest_row (GdkDragContext *context,
5869 GtkTreeModel *model,
5870 GtkTreePath *dest_row,
5871 gboolean empty_view_drop,
5872 gboolean drop_append_mode)
5878 g_object_set_data_full (G_OBJECT (context),
5879 I_("gtk-icon-view-dest-row"),
5884 dr = g_new0 (DestRow, 1);
5886 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5887 dr->empty_view_drop = empty_view_drop;
5888 dr->drop_append_mode = drop_append_mode;
5889 g_object_set_data_full (G_OBJECT (context),
5890 I_("gtk-icon-view-dest-row"),
5891 dr, (GDestroyNotify) dest_row_free);
5895 get_dest_row (GdkDragContext *context)
5899 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5903 GtkTreePath *path = NULL;
5906 path = gtk_tree_row_reference_get_path (dr->dest_row);
5907 else if (dr->empty_view_drop)
5908 path = gtk_tree_path_new_from_indices (0, -1);
5912 if (path && dr->drop_append_mode)
5913 gtk_tree_path_next (path);
5922 check_model_dnd (GtkTreeModel *model,
5923 GType required_iface,
5924 const gchar *signal)
5926 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5928 g_warning ("You must override the default '%s' handler "
5929 "on GtkIconView when using models that don't support "
5930 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5931 "is to connect to '%s' and call "
5932 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5933 "the default handler from running. Look at the source code "
5934 "for the default handler in gtkiconview.c to get an idea what "
5935 "your handler should do. (gtkiconview.c is in the GTK+ source "
5936 "code.) If you're using GTK+ from a language other than C, "
5937 "there may be a more natural way to override default handlers, e.g. via derivation.",
5938 signal, g_type_name (required_iface), signal);
5946 remove_scroll_timeout (GtkIconView *icon_view)
5948 if (icon_view->priv->scroll_timeout_id != 0)
5950 g_source_remove (icon_view->priv->scroll_timeout_id);
5952 icon_view->priv->scroll_timeout_id = 0;
5957 gtk_icon_view_autoscroll (GtkIconView *icon_view,
5961 gint px, py, x, y, width, height;
5962 gint hoffset, voffset;
5964 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5966 gdk_window_get_device_position (window, device, &px, &py, NULL);
5967 gdk_window_get_geometry (window, &x, &y, &width, &height);
5969 /* see if we are near the edge. */
5970 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5972 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5974 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5976 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5979 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5980 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5983 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5984 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5988 GtkIconView *icon_view;
5993 drag_scroll_timeout (gpointer datap)
5995 DragScrollData *data = datap;
5997 gtk_icon_view_autoscroll (data->icon_view, data->device);
6003 drag_scroll_data_free (DragScrollData *data)
6005 g_slice_free (DragScrollData, data);
6009 set_destination (GtkIconView *icon_view,
6010 GdkDragContext *context,
6013 GdkDragAction *suggested_action,
6017 GtkTreePath *path = NULL;
6018 GtkIconViewDropPosition pos;
6019 GtkIconViewDropPosition old_pos;
6020 GtkTreePath *old_dest_path = NULL;
6021 gboolean can_drop = FALSE;
6023 widget = GTK_WIDGET (icon_view);
6025 *suggested_action = 0;
6028 if (!icon_view->priv->dest_set)
6030 /* someone unset us as a drag dest, note that if
6031 * we return FALSE drag_leave isn't called
6034 gtk_icon_view_set_drag_dest_item (icon_view,
6036 GTK_ICON_VIEW_DROP_LEFT);
6038 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6040 return FALSE; /* no longer a drop site */
6043 *target = gtk_drag_dest_find_target (widget, context,
6044 gtk_drag_dest_get_target_list (widget));
6045 if (*target == GDK_NONE)
6048 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6051 GtkTreeModel *model;
6053 /* the row got dropped on empty space, let's setup a special case
6057 gtk_tree_path_free (path);
6059 model = gtk_icon_view_get_model (icon_view);
6061 n_children = gtk_tree_model_iter_n_children (model, NULL);
6064 pos = GTK_ICON_VIEW_DROP_BELOW;
6065 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6069 pos = GTK_ICON_VIEW_DROP_ABOVE;
6070 path = gtk_tree_path_new_from_indices (0, -1);
6080 gtk_icon_view_get_drag_dest_item (icon_view,
6085 gtk_tree_path_free (old_dest_path);
6087 if (TRUE /* FIXME if the location droppable predicate */)
6095 GtkWidget *source_widget;
6097 *suggested_action = gdk_drag_context_get_suggested_action (context);
6098 source_widget = gtk_drag_get_source_widget (context);
6100 if (source_widget == widget)
6102 /* Default to MOVE, unless the user has
6103 * pressed ctrl or shift to affect available actions
6105 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6106 *suggested_action = GDK_ACTION_MOVE;
6109 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6114 /* can't drop here */
6115 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6117 GTK_ICON_VIEW_DROP_LEFT);
6121 gtk_tree_path_free (path);
6127 get_logical_destination (GtkIconView *icon_view,
6128 gboolean *drop_append_mode)
6130 /* adjust path to point to the row the drop goes in front of */
6131 GtkTreePath *path = NULL;
6132 GtkIconViewDropPosition pos;
6134 *drop_append_mode = FALSE;
6136 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6141 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6142 pos == GTK_ICON_VIEW_DROP_BELOW)
6145 GtkTreeModel *model = icon_view->priv->model;
6147 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6148 !gtk_tree_model_iter_next (model, &iter))
6149 *drop_append_mode = TRUE;
6152 *drop_append_mode = FALSE;
6153 gtk_tree_path_next (path);
6161 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6162 GdkEventMotion *event)
6164 GtkWidget *widget = GTK_WIDGET (icon_view);
6165 GdkDragContext *context;
6166 GtkTreePath *path = NULL;
6168 GtkTreeModel *model;
6169 gboolean retval = FALSE;
6171 if (!icon_view->priv->source_set)
6174 if (icon_view->priv->pressed_button < 0)
6177 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6178 icon_view->priv->press_start_x,
6179 icon_view->priv->press_start_y,
6180 event->x, event->y))
6183 model = gtk_icon_view_get_model (icon_view);
6188 button = icon_view->priv->pressed_button;
6189 icon_view->priv->pressed_button = -1;
6191 path = gtk_icon_view_get_path_at_pos (icon_view,
6192 icon_view->priv->press_start_x,
6193 icon_view->priv->press_start_y);
6198 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6199 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6203 /* FIXME Check whether we're a start button, if not return FALSE and
6207 /* Now we can begin the drag */
6211 context = gtk_drag_begin (widget,
6212 gtk_drag_source_get_target_list (widget),
6213 icon_view->priv->source_actions,
6217 set_source_row (context, model, path);
6221 gtk_tree_path_free (path);
6226 /* Source side drag signals */
6228 gtk_icon_view_drag_begin (GtkWidget *widget,
6229 GdkDragContext *context)
6231 GtkIconView *icon_view;
6232 GtkIconViewItem *item;
6233 cairo_surface_t *icon;
6237 icon_view = GTK_ICON_VIEW (widget);
6239 /* if the user uses a custom DnD impl, we don't set the icon here */
6240 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6243 item = _gtk_icon_view_get_item_at_coords (icon_view,
6244 icon_view->priv->press_start_x,
6245 icon_view->priv->press_start_y,
6249 g_return_if_fail (item != NULL);
6251 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6252 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6254 path = gtk_tree_path_new_from_indices (item->index, -1);
6255 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6256 gtk_tree_path_free (path);
6258 cairo_surface_set_device_offset (icon, -x, -y);
6260 gtk_drag_set_icon_surface (context, icon);
6262 cairo_surface_destroy (icon);
6266 gtk_icon_view_drag_end (GtkWidget *widget,
6267 GdkDragContext *context)
6273 gtk_icon_view_drag_data_get (GtkWidget *widget,
6274 GdkDragContext *context,
6275 GtkSelectionData *selection_data,
6279 GtkIconView *icon_view;
6280 GtkTreeModel *model;
6281 GtkTreePath *source_row;
6283 icon_view = GTK_ICON_VIEW (widget);
6284 model = gtk_icon_view_get_model (icon_view);
6289 if (!icon_view->priv->source_set)
6292 source_row = get_source_row (context);
6294 if (source_row == NULL)
6297 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6298 * any model; for DragSource models there are some other targets
6302 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6303 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6308 /* If drag_data_get does nothing, try providing row data. */
6309 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6310 gtk_tree_set_row_drag_data (selection_data,
6315 gtk_tree_path_free (source_row);
6319 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6320 GdkDragContext *context)
6322 GtkTreeModel *model;
6323 GtkIconView *icon_view;
6324 GtkTreePath *source_row;
6326 icon_view = GTK_ICON_VIEW (widget);
6327 model = gtk_icon_view_get_model (icon_view);
6329 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6332 if (!icon_view->priv->source_set)
6335 source_row = get_source_row (context);
6337 if (source_row == NULL)
6340 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6343 gtk_tree_path_free (source_row);
6345 set_source_row (context, NULL, NULL);
6348 /* Target side drag signals */
6350 gtk_icon_view_drag_leave (GtkWidget *widget,
6351 GdkDragContext *context,
6354 GtkIconView *icon_view;
6356 icon_view = GTK_ICON_VIEW (widget);
6358 /* unset any highlight row */
6359 gtk_icon_view_set_drag_dest_item (icon_view,
6361 GTK_ICON_VIEW_DROP_LEFT);
6363 remove_scroll_timeout (icon_view);
6367 gtk_icon_view_drag_motion (GtkWidget *widget,
6368 GdkDragContext *context,
6373 GtkTreePath *path = NULL;
6374 GtkIconViewDropPosition pos;
6375 GtkIconView *icon_view;
6376 GdkDragAction suggested_action = 0;
6380 icon_view = GTK_ICON_VIEW (widget);
6382 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6385 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6387 /* we only know this *after* set_desination_row */
6388 empty = icon_view->priv->empty_view_drop;
6390 if (path == NULL && !empty)
6392 /* Can't drop here. */
6393 gdk_drag_status (context, 0, time);
6397 if (icon_view->priv->scroll_timeout_id == 0)
6399 DragScrollData *data = g_slice_new (DragScrollData);
6400 data->icon_view = icon_view;
6401 data->device = gdk_drag_context_get_device (context);
6403 icon_view->priv->scroll_timeout_id =
6404 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6407 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6409 /* Request data so we can use the source row when
6410 * determining whether to accept the drop
6412 set_status_pending (context, suggested_action);
6413 gtk_drag_get_data (widget, context, target, time);
6417 set_status_pending (context, 0);
6418 gdk_drag_status (context, suggested_action, time);
6423 gtk_tree_path_free (path);
6429 gtk_icon_view_drag_drop (GtkWidget *widget,
6430 GdkDragContext *context,
6435 GtkIconView *icon_view;
6437 GdkDragAction suggested_action = 0;
6438 GdkAtom target = GDK_NONE;
6439 GtkTreeModel *model;
6440 gboolean drop_append_mode;
6442 icon_view = GTK_ICON_VIEW (widget);
6443 model = gtk_icon_view_get_model (icon_view);
6445 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6447 if (!icon_view->priv->dest_set)
6450 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6453 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6456 path = get_logical_destination (icon_view, &drop_append_mode);
6458 if (target != GDK_NONE && path != NULL)
6460 /* in case a motion had requested drag data, change things so we
6461 * treat drag data receives as a drop.
6463 set_status_pending (context, 0);
6464 set_dest_row (context, model, path,
6465 icon_view->priv->empty_view_drop, drop_append_mode);
6469 gtk_tree_path_free (path);
6471 /* Unset this thing */
6472 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6474 if (target != GDK_NONE)
6476 gtk_drag_get_data (widget, context, target, time);
6484 gtk_icon_view_drag_data_received (GtkWidget *widget,
6485 GdkDragContext *context,
6488 GtkSelectionData *selection_data,
6493 gboolean accepted = FALSE;
6494 GtkTreeModel *model;
6495 GtkIconView *icon_view;
6496 GtkTreePath *dest_row;
6497 GdkDragAction suggested_action;
6498 gboolean drop_append_mode;
6500 icon_view = GTK_ICON_VIEW (widget);
6501 model = gtk_icon_view_get_model (icon_view);
6503 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6506 if (!icon_view->priv->dest_set)
6509 suggested_action = get_status_pending (context);
6511 if (suggested_action)
6513 /* We are getting this data due to a request in drag_motion,
6514 * rather than due to a request in drag_drop, so we are just
6515 * supposed to call drag_status, not actually paste in the
6518 path = get_logical_destination (icon_view, &drop_append_mode);
6521 suggested_action = 0;
6523 if (suggested_action)
6525 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6528 suggested_action = 0;
6531 gdk_drag_status (context, suggested_action, time);
6534 gtk_tree_path_free (path);
6536 /* If you can't drop, remove user drop indicator until the next motion */
6537 if (suggested_action == 0)
6538 gtk_icon_view_set_drag_dest_item (icon_view,
6540 GTK_ICON_VIEW_DROP_LEFT);
6545 dest_row = get_dest_row (context);
6547 if (dest_row == NULL)
6550 if (gtk_selection_data_get_length (selection_data) >= 0)
6552 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6558 gtk_drag_finish (context,
6560 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6563 gtk_tree_path_free (dest_row);
6566 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6569 /* Drag-and-Drop support */
6571 * gtk_icon_view_enable_model_drag_source:
6572 * @icon_view: a #GtkIconTreeView
6573 * @start_button_mask: Mask of allowed buttons to start drag
6574 * @targets: (array length=n_targets): the table of targets that the drag will
6576 * @n_targets: the number of items in @targets
6577 * @actions: the bitmask of possible actions for a drag from this
6580 * Turns @icon_view into a drag source for automatic DND. Calling this
6581 * method sets #GtkIconView:reorderable to %FALSE.
6586 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6587 GdkModifierType start_button_mask,
6588 const GtkTargetEntry *targets,
6590 GdkDragAction actions)
6592 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6594 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6596 icon_view->priv->start_button_mask = start_button_mask;
6597 icon_view->priv->source_actions = actions;
6599 icon_view->priv->source_set = TRUE;
6601 unset_reorderable (icon_view);
6605 * gtk_icon_view_enable_model_drag_dest:
6606 * @icon_view: a #GtkIconView
6607 * @targets: (array length=n_targets): the table of targets that the drag will
6609 * @n_targets: the number of items in @targets
6610 * @actions: the bitmask of possible actions for a drag to this
6613 * Turns @icon_view into a drop destination for automatic DND. Calling this
6614 * method sets #GtkIconView:reorderable to %FALSE.
6619 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6620 const GtkTargetEntry *targets,
6622 GdkDragAction actions)
6624 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6626 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6628 icon_view->priv->dest_actions = actions;
6630 icon_view->priv->dest_set = TRUE;
6632 unset_reorderable (icon_view);
6636 * gtk_icon_view_unset_model_drag_source:
6637 * @icon_view: a #GtkIconView
6639 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6640 * method sets #GtkIconView:reorderable to %FALSE.
6645 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6647 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6649 if (icon_view->priv->source_set)
6651 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6652 icon_view->priv->source_set = FALSE;
6655 unset_reorderable (icon_view);
6659 * gtk_icon_view_unset_model_drag_dest:
6660 * @icon_view: a #GtkIconView
6662 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6663 * method sets #GtkIconView:reorderable to %FALSE.
6668 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6670 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6672 if (icon_view->priv->dest_set)
6674 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6675 icon_view->priv->dest_set = FALSE;
6678 unset_reorderable (icon_view);
6681 /* These are useful to implement your own custom stuff. */
6683 * gtk_icon_view_set_drag_dest_item:
6684 * @icon_view: a #GtkIconView
6685 * @path: (allow-none): The path of the item to highlight, or %NULL.
6686 * @pos: Specifies where to drop, relative to the item
6688 * Sets the item that is highlighted for feedback.
6693 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6695 GtkIconViewDropPosition pos)
6697 /* Note; this function is exported to allow a custom DND
6698 * implementation, so it can't touch TreeViewDragInfo
6701 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6703 if (icon_view->priv->dest_item)
6705 GtkTreePath *current_path;
6706 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6707 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6708 icon_view->priv->dest_item = NULL;
6710 gtk_icon_view_queue_draw_path (icon_view, current_path);
6711 gtk_tree_path_free (current_path);
6714 /* special case a drop on an empty model */
6715 icon_view->priv->empty_view_drop = FALSE;
6716 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6717 && gtk_tree_path_get_depth (path) == 1
6718 && gtk_tree_path_get_indices (path)[0] == 0)
6722 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6725 if (n_children == 0)
6726 icon_view->priv->empty_view_drop = TRUE;
6729 icon_view->priv->dest_pos = pos;
6733 icon_view->priv->dest_item =
6734 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6735 icon_view->priv->model, path);
6737 gtk_icon_view_queue_draw_path (icon_view, path);
6742 * gtk_icon_view_get_drag_dest_item:
6743 * @icon_view: a #GtkIconView
6744 * @path: (out) (allow-none): Return location for the path of
6745 * the highlighted item, or %NULL.
6746 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6748 * Gets information about the item that is highlighted for feedback.
6753 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6755 GtkIconViewDropPosition *pos)
6757 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6761 if (icon_view->priv->dest_item)
6762 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6768 *pos = icon_view->priv->dest_pos;
6772 * gtk_icon_view_get_dest_item_at_pos:
6773 * @icon_view: a #GtkIconView
6774 * @drag_x: the position to determine the destination item for
6775 * @drag_y: the position to determine the destination item for
6776 * @path: (out) (allow-none): Return location for the path of the item,
6778 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6780 * Determines the destination item for a given position.
6782 * Return value: whether there is an item at the given position.
6787 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6791 GtkIconViewDropPosition *pos)
6793 GtkIconViewItem *item;
6795 /* Note; this function is exported to allow a custom DND
6796 * implementation, so it can't touch TreeViewDragInfo
6799 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6800 g_return_val_if_fail (drag_x >= 0, FALSE);
6801 g_return_val_if_fail (drag_y >= 0, FALSE);
6802 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6808 item = _gtk_icon_view_get_item_at_coords (icon_view,
6809 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6810 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6817 *path = gtk_tree_path_new_from_indices (item->index, -1);
6821 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6822 *pos = GTK_ICON_VIEW_DROP_LEFT;
6823 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6824 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6825 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6826 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6827 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6828 *pos = GTK_ICON_VIEW_DROP_BELOW;
6830 *pos = GTK_ICON_VIEW_DROP_INTO;
6837 * gtk_icon_view_create_drag_icon:
6838 * @icon_view: a #GtkIconView
6839 * @path: a #GtkTreePath in @icon_view
6841 * Creates a #cairo_surface_t representation of the item at @path.
6842 * This image is used for a drag icon.
6844 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6849 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6853 GtkStyleContext *context;
6855 cairo_surface_t *surface;
6859 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6860 g_return_val_if_fail (path != NULL, NULL);
6862 widget = GTK_WIDGET (icon_view);
6863 context = gtk_widget_get_style_context (widget);
6865 if (!gtk_widget_get_realized (widget))
6868 index = gtk_tree_path_get_indices (path)[0];
6870 for (l = icon_view->priv->items; l; l = l->next)
6872 GtkIconViewItem *item = l->data;
6874 if (index == item->index)
6876 GdkRectangle rect = {
6877 item->cell_area.x - icon_view->priv->item_padding,
6878 item->cell_area.y - icon_view->priv->item_padding,
6879 item->cell_area.width + icon_view->priv->item_padding * 2,
6880 item->cell_area.height + icon_view->priv->item_padding * 2
6883 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6884 CAIRO_CONTENT_COLOR,
6888 cr = cairo_create (surface);
6889 cairo_set_line_width (cr, 1.);
6891 gtk_render_background (context, cr, 0, 0,
6892 rect.width + 2, rect.height + 2);
6896 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6899 gtk_icon_view_paint_item (icon_view, cr, item,
6900 icon_view->priv->item_padding + 1,
6901 icon_view->priv->item_padding + 1, FALSE);
6905 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6906 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6919 * gtk_icon_view_get_reorderable:
6920 * @icon_view: a #GtkIconView
6922 * Retrieves whether the user can reorder the list via drag-and-drop.
6923 * See gtk_icon_view_set_reorderable().
6925 * Return value: %TRUE if the list can be reordered.
6930 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6932 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6934 return icon_view->priv->reorderable;
6937 static const GtkTargetEntry item_targets[] = {
6938 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6943 * gtk_icon_view_set_reorderable:
6944 * @icon_view: A #GtkIconView.
6945 * @reorderable: %TRUE, if the list of items can be reordered.
6947 * This function is a convenience function to allow you to reorder models that
6948 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6949 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6950 * the user can reorder the model by dragging and dropping rows. The
6951 * developer can listen to these changes by connecting to the model's
6952 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6953 * the icon view as a drag source and destination. Therefore, drag and
6954 * drop can not be used in a reorderable view for any other purpose.
6956 * This function does not give you any degree of control over the order -- any
6957 * reordering is allowed. If more control is needed, you should probably
6958 * handle drag and drop manually.
6963 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6964 gboolean reorderable)
6966 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6968 reorderable = reorderable != FALSE;
6970 if (icon_view->priv->reorderable == reorderable)
6975 gtk_icon_view_enable_model_drag_source (icon_view,
6978 G_N_ELEMENTS (item_targets),
6980 gtk_icon_view_enable_model_drag_dest (icon_view,
6982 G_N_ELEMENTS (item_targets),
6987 gtk_icon_view_unset_model_drag_source (icon_view);
6988 gtk_icon_view_unset_model_drag_dest (icon_view);
6991 icon_view->priv->reorderable = reorderable;
6993 g_object_notify (G_OBJECT (icon_view), "reorderable");
6997 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
6998 GtkBuilder *builder,
7000 const gchar *tagname,
7001 GMarkupParser *parser,
7004 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7005 tagname, parser, data))
7008 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7009 tagname, parser, data);
7013 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7014 GtkBuilder *builder,
7016 const gchar *tagname,
7019 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7020 child, tagname, data))
7021 parent_buildable_iface->custom_tag_end (buildable, builder,
7022 child, tagname, data);