2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 #include "gtkiconview.h"
23 #include "gtkiconviewprivate.h"
25 #include "gtkadjustment.h"
26 #include "gtkcelllayout.h"
27 #include "gtkcellrenderer.h"
28 #include "gtkcellareabox.h"
29 #include "gtkcellareacontext.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkorientable.h"
33 #include "gtkmarshalers.h"
34 #include "gtkbindings.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtkscrollable.h"
43 #include "gtksizerequest.h"
44 #include "gtktreednd.h"
45 #include "gtktypebuiltins.h"
46 #include "gtkprivate.h"
47 #include "a11y/gtkiconviewaccessible.h"
52 * @short_description: A widget which displays a list of icons in a grid
54 * #GtkIconView provides an alternative view on a #GtkTreeModel.
55 * It displays the model as a grid of icons with labels. Like
56 * #GtkTreeView, it allows to select one or multiple items
57 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
58 * In addition to selection with the arrow keys, #GtkIconView supports
59 * rubberband selection, which is controlled by dragging the pointer.
61 * Note that if the tree model is backed by an actual tree store (as
62 * opposed to a flat list where the mapping to icons is obvious),
63 * #GtkIconView will only display the first level of the tree and
64 * ignore the tree's branches.
67 #define SCROLL_EDGE_SIZE 15
69 typedef struct _GtkIconViewChild GtkIconViewChild;
70 struct _GtkIconViewChild
98 PROP_ITEM_ORIENTATION,
111 /* For scrollable interface */
119 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
120 static void gtk_icon_view_dispose (GObject *object);
121 static GObject *gtk_icon_view_constructor (GType type,
122 guint n_construct_properties,
123 GObjectConstructParam *construct_properties);
124 static void gtk_icon_view_set_property (GObject *object,
128 static void gtk_icon_view_get_property (GObject *object,
132 /* GtkWidget vfuncs */
133 static void gtk_icon_view_destroy (GtkWidget *widget);
134 static void gtk_icon_view_realize (GtkWidget *widget);
135 static void gtk_icon_view_unrealize (GtkWidget *widget);
136 static void gtk_icon_view_style_updated (GtkWidget *widget);
137 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
138 GtkStateFlags previous_state);
139 static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
140 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
143 static void gtk_icon_view_get_preferred_width_for_height
148 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
151 static void gtk_icon_view_get_preferred_height_for_width
156 static void gtk_icon_view_size_allocate (GtkWidget *widget,
157 GtkAllocation *allocation);
158 static gboolean gtk_icon_view_draw (GtkWidget *widget,
160 static gboolean gtk_icon_view_motion (GtkWidget *widget,
161 GdkEventMotion *event);
162 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
163 GdkEventButton *event);
164 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
165 GdkEventButton *event);
166 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
168 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
172 /* GtkContainer vfuncs */
173 static void gtk_icon_view_remove (GtkContainer *container,
175 static void gtk_icon_view_forall (GtkContainer *container,
176 gboolean include_internals,
177 GtkCallback callback,
178 gpointer callback_data);
180 /* GtkIconView vfuncs */
181 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
182 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
183 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
184 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
185 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
187 /* Internal functions */
188 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
189 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
190 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
191 GtkAdjustment *adjustment);
192 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
193 GtkAdjustment *adjustment);
194 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
195 GtkIconView *icon_view);
196 static void gtk_icon_view_layout (GtkIconView *icon_view);
197 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
199 GtkIconViewItem *item,
202 gboolean draw_focus);
203 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
205 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
207 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
208 GtkIconViewItem *item);
209 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
213 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
214 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
215 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
216 GtkIconViewItem *item,
221 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
222 static void gtk_icon_view_update_rubberband (gpointer data);
223 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
224 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
225 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
228 GtkMovementStep step,
230 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
231 GtkMovementStep step,
233 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
235 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
237 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
239 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
241 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
242 GtkIconViewItem *item);
243 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
244 GtkIconViewItem *anchor,
245 GtkIconViewItem *cursor);
247 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
248 GtkCellArea *cell_area);
250 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
252 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
253 GtkIconViewItem *item);
255 static void gtk_icon_view_add_editable (GtkCellArea *area,
256 GtkCellRenderer *renderer,
257 GtkCellEditable *editable,
258 GdkRectangle *cell_area,
260 GtkIconView *icon_view);
261 static void gtk_icon_view_remove_editable (GtkCellArea *area,
262 GtkCellRenderer *renderer,
263 GtkCellEditable *editable,
264 GtkIconView *icon_view);
265 static void update_text_cell (GtkIconView *icon_view);
266 static void update_pixbuf_cell (GtkIconView *icon_view);
268 /* Source side drag signals */
269 static void gtk_icon_view_drag_begin (GtkWidget *widget,
270 GdkDragContext *context);
271 static void gtk_icon_view_drag_end (GtkWidget *widget,
272 GdkDragContext *context);
273 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
274 GdkDragContext *context,
275 GtkSelectionData *selection_data,
278 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
279 GdkDragContext *context);
281 /* Target side drag signals */
282 static void gtk_icon_view_drag_leave (GtkWidget *widget,
283 GdkDragContext *context,
285 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
286 GdkDragContext *context,
290 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
291 GdkDragContext *context,
295 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
296 GdkDragContext *context,
299 GtkSelectionData *selection_data,
302 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
303 GdkEventMotion *event);
305 static void remove_scroll_timeout (GtkIconView *icon_view);
308 static GtkBuildableIface *parent_buildable_iface;
309 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
310 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
313 const gchar *tagname,
314 GMarkupParser *parser,
316 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
319 const gchar *tagname,
322 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
324 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
325 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
326 gtk_icon_view_cell_layout_init)
327 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
328 gtk_icon_view_buildable_init)
329 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
332 gtk_icon_view_class_init (GtkIconViewClass *klass)
334 GObjectClass *gobject_class;
335 GtkWidgetClass *widget_class;
336 GtkContainerClass *container_class;
337 GtkBindingSet *binding_set;
339 binding_set = gtk_binding_set_by_class (klass);
341 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
343 gobject_class = (GObjectClass *) klass;
344 widget_class = (GtkWidgetClass *) klass;
345 container_class = (GtkContainerClass *) klass;
347 gobject_class->constructor = gtk_icon_view_constructor;
348 gobject_class->dispose = gtk_icon_view_dispose;
349 gobject_class->set_property = gtk_icon_view_set_property;
350 gobject_class->get_property = gtk_icon_view_get_property;
352 widget_class->destroy = gtk_icon_view_destroy;
353 widget_class->realize = gtk_icon_view_realize;
354 widget_class->unrealize = gtk_icon_view_unrealize;
355 widget_class->style_updated = gtk_icon_view_style_updated;
356 widget_class->get_request_mode = gtk_icon_view_get_request_mode;
357 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
358 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
359 widget_class->get_preferred_width_for_height = gtk_icon_view_get_preferred_width_for_height;
360 widget_class->get_preferred_height_for_width = gtk_icon_view_get_preferred_height_for_width;
361 widget_class->size_allocate = gtk_icon_view_size_allocate;
362 widget_class->draw = gtk_icon_view_draw;
363 widget_class->motion_notify_event = gtk_icon_view_motion;
364 widget_class->button_press_event = gtk_icon_view_button_press;
365 widget_class->button_release_event = gtk_icon_view_button_release;
366 widget_class->key_press_event = gtk_icon_view_key_press;
367 widget_class->key_release_event = gtk_icon_view_key_release;
368 widget_class->drag_begin = gtk_icon_view_drag_begin;
369 widget_class->drag_end = gtk_icon_view_drag_end;
370 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
371 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
372 widget_class->drag_leave = gtk_icon_view_drag_leave;
373 widget_class->drag_motion = gtk_icon_view_drag_motion;
374 widget_class->drag_drop = gtk_icon_view_drag_drop;
375 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
376 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
378 container_class->remove = gtk_icon_view_remove;
379 container_class->forall = gtk_icon_view_forall;
381 klass->select_all = gtk_icon_view_real_select_all;
382 klass->unselect_all = gtk_icon_view_real_unselect_all;
383 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
384 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
385 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
386 klass->move_cursor = gtk_icon_view_real_move_cursor;
390 * GtkIconView:selection-mode:
392 * The ::selection-mode property specifies the selection mode of
393 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
394 * is enabled, for the other modes, only keyboard selection is possible.
398 g_object_class_install_property (gobject_class,
400 g_param_spec_enum ("selection-mode",
401 P_("Selection mode"),
402 P_("The selection mode"),
403 GTK_TYPE_SELECTION_MODE,
404 GTK_SELECTION_SINGLE,
405 GTK_PARAM_READWRITE));
408 * GtkIconView:pixbuf-column:
410 * The ::pixbuf-column property contains the number of the model column
411 * containing the pixbufs which are displayed. The pixbuf column must be
412 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
413 * display of pixbufs.
417 g_object_class_install_property (gobject_class,
419 g_param_spec_int ("pixbuf-column",
421 P_("Model column used to retrieve the icon pixbuf from"),
423 GTK_PARAM_READWRITE));
426 * GtkIconView:text-column:
428 * The ::text-column property contains the number of the model column
429 * containing the texts which are displayed. The text column must be
430 * of type #G_TYPE_STRING. If this property and the :markup-column
431 * property are both set to -1, no texts are displayed.
435 g_object_class_install_property (gobject_class,
437 g_param_spec_int ("text-column",
439 P_("Model column used to retrieve the text from"),
441 GTK_PARAM_READWRITE));
445 * GtkIconView:markup-column:
447 * The ::markup-column property contains the number of the model column
448 * containing markup information to be displayed. The markup column must be
449 * of type #G_TYPE_STRING. If this property and the :text-column property
450 * are both set to column numbers, it overrides the text column.
451 * If both are set to -1, no texts are displayed.
455 g_object_class_install_property (gobject_class,
457 g_param_spec_int ("markup-column",
459 P_("Model column used to retrieve the text if using Pango markup"),
461 GTK_PARAM_READWRITE));
463 g_object_class_install_property (gobject_class,
465 g_param_spec_object ("model",
466 P_("Icon View Model"),
467 P_("The model for the icon view"),
469 GTK_PARAM_READWRITE));
472 * GtkIconView:columns:
474 * The columns property contains the number of the columns in which the
475 * items should be displayed. If it is -1, the number of columns will
476 * be chosen automatically to fill the available area.
480 g_object_class_install_property (gobject_class,
482 g_param_spec_int ("columns",
483 P_("Number of columns"),
484 P_("Number of columns to display"),
486 GTK_PARAM_READWRITE));
490 * GtkIconView:item-width:
492 * The item-width property specifies the width to use for each item.
493 * If it is set to -1, the icon view will automatically determine a
494 * suitable item size.
498 g_object_class_install_property (gobject_class,
500 g_param_spec_int ("item-width",
501 P_("Width for each item"),
502 P_("The width used for each item"),
504 GTK_PARAM_READWRITE));
507 * GtkIconView:spacing:
509 * The spacing property specifies the space which is inserted between
510 * the cells (i.e. the icon and the text) of an item.
514 g_object_class_install_property (gobject_class,
516 g_param_spec_int ("spacing",
518 P_("Space which is inserted between cells of an item"),
520 GTK_PARAM_READWRITE));
523 * GtkIconView:row-spacing:
525 * The row-spacing property specifies the space which is inserted between
526 * the rows of the icon view.
530 g_object_class_install_property (gobject_class,
532 g_param_spec_int ("row-spacing",
534 P_("Space which is inserted between grid rows"),
536 GTK_PARAM_READWRITE));
539 * GtkIconView:column-spacing:
541 * The column-spacing property specifies the space which is inserted between
542 * the columns of the icon view.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_int ("column-spacing",
549 P_("Column Spacing"),
550 P_("Space which is inserted between grid columns"),
552 GTK_PARAM_READWRITE));
555 * GtkIconView:margin:
557 * The margin property specifies the space which is inserted
558 * at the edges of the icon view.
562 g_object_class_install_property (gobject_class,
564 g_param_spec_int ("margin",
566 P_("Space which is inserted at the edges of the icon view"),
568 GTK_PARAM_READWRITE));
571 * GtkIconView:item-orientation:
573 * The item-orientation property specifies how the cells (i.e. the icon and
574 * the text) of the item are positioned relative to each other.
578 g_object_class_install_property (gobject_class,
579 PROP_ITEM_ORIENTATION,
580 g_param_spec_enum ("item-orientation",
581 P_("Item Orientation"),
582 P_("How the text and icon of each item are positioned relative to each other"),
583 GTK_TYPE_ORIENTATION,
584 GTK_ORIENTATION_VERTICAL,
585 GTK_PARAM_READWRITE));
588 * GtkIconView:reorderable:
590 * The reorderable property specifies if the items can be reordered
595 g_object_class_install_property (gobject_class,
597 g_param_spec_boolean ("reorderable",
599 P_("View is reorderable"),
603 g_object_class_install_property (gobject_class,
605 g_param_spec_int ("tooltip-column",
606 P_("Tooltip Column"),
607 P_("The column in the model containing the tooltip texts for the items"),
611 GTK_PARAM_READWRITE));
614 * GtkIconView:item-padding:
616 * The item-padding property specifies the padding around each
617 * of the icon view's item.
621 g_object_class_install_property (gobject_class,
623 g_param_spec_int ("item-padding",
625 P_("Padding around icon view items"),
627 GTK_PARAM_READWRITE));
630 * GtkIconView:cell-area:
632 * The #GtkCellArea used to layout cell renderers for this view.
634 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
635 * a #GtkCellAreaBox will be used.
639 g_object_class_install_property (gobject_class,
641 g_param_spec_object ("cell-area",
643 P_("The GtkCellArea used to layout cells"),
645 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
647 /* Scrollable interface properties */
648 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
649 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
650 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
651 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
653 /* Style properties */
654 gtk_widget_class_install_style_property (widget_class,
655 g_param_spec_boxed ("selection-box-color",
656 P_("Selection Box Color"),
657 P_("Color of the selection box"),
659 GTK_PARAM_READABLE));
661 gtk_widget_class_install_style_property (widget_class,
662 g_param_spec_uchar ("selection-box-alpha",
663 P_("Selection Box Alpha"),
664 P_("Opacity of the selection box"),
667 GTK_PARAM_READABLE));
671 * GtkIconView::item-activated:
672 * @iconview: the object on which the signal is emitted
673 * @path: the #GtkTreePath for the activated item
675 * The ::item-activated signal is emitted when the method
676 * gtk_icon_view_item_activated() is called or the user double
677 * clicks an item. It is also emitted when a non-editable item
678 * is selected and one of the keys: Space, Return or Enter is
681 icon_view_signals[ITEM_ACTIVATED] =
682 g_signal_new (I_("item-activated"),
683 G_TYPE_FROM_CLASS (gobject_class),
685 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
687 g_cclosure_marshal_VOID__BOXED,
692 * GtkIconView::selection-changed:
693 * @iconview: the object on which the signal is emitted
695 * The ::selection-changed signal is emitted when the selection
696 * (i.e. the set of selected items) changes.
698 icon_view_signals[SELECTION_CHANGED] =
699 g_signal_new (I_("selection-changed"),
700 G_TYPE_FROM_CLASS (gobject_class),
702 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
704 g_cclosure_marshal_VOID__VOID,
708 * GtkIconView::select-all:
709 * @iconview: the object on which the signal is emitted
711 * A <link linkend="keybinding-signals">keybinding signal</link>
712 * which gets emitted when the user selects all items.
714 * Applications should not connect to it, but may emit it with
715 * g_signal_emit_by_name() if they need to control selection
718 * The default binding for this signal is Ctrl-a.
720 icon_view_signals[SELECT_ALL] =
721 g_signal_new (I_("select-all"),
722 G_TYPE_FROM_CLASS (gobject_class),
723 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
724 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
726 g_cclosure_marshal_VOID__VOID,
730 * GtkIconView::unselect-all:
731 * @iconview: the object on which the signal is emitted
733 * A <link linkend="keybinding-signals">keybinding signal</link>
734 * which gets emitted when the user unselects all items.
736 * Applications should not connect to it, but may emit it with
737 * g_signal_emit_by_name() if they need to control selection
740 * The default binding for this signal is Ctrl-Shift-a.
742 icon_view_signals[UNSELECT_ALL] =
743 g_signal_new (I_("unselect-all"),
744 G_TYPE_FROM_CLASS (gobject_class),
745 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
746 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
748 g_cclosure_marshal_VOID__VOID,
752 * GtkIconView::select-cursor-item:
753 * @iconview: the object on which the signal is emitted
755 * A <link linkend="keybinding-signals">keybinding signal</link>
756 * which gets emitted when the user selects the item that is currently
759 * Applications should not connect to it, but may emit it with
760 * g_signal_emit_by_name() if they need to control selection
763 * There is no default binding for this signal.
765 icon_view_signals[SELECT_CURSOR_ITEM] =
766 g_signal_new (I_("select-cursor-item"),
767 G_TYPE_FROM_CLASS (gobject_class),
768 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
769 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
771 g_cclosure_marshal_VOID__VOID,
775 * GtkIconView::toggle-cursor-item:
776 * @iconview: the object on which the signal is emitted
778 * A <link linkend="keybinding-signals">keybinding signal</link>
779 * which gets emitted when the user toggles whether the currently
780 * focused item is selected or not. The exact effect of this
781 * depend on the selection mode.
783 * Applications should not connect to it, but may emit it with
784 * g_signal_emit_by_name() if they need to control selection
787 * There is no default binding for this signal is Ctrl-Space.
789 icon_view_signals[TOGGLE_CURSOR_ITEM] =
790 g_signal_new (I_("toggle-cursor-item"),
791 G_TYPE_FROM_CLASS (gobject_class),
792 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
793 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
795 g_cclosure_marshal_VOID__VOID,
799 * GtkIconView::activate-cursor-item:
800 * @iconview: the object on which the signal is emitted
802 * A <link linkend="keybinding-signals">keybinding signal</link>
803 * which gets emitted when the user activates the currently
806 * Applications should not connect to it, but may emit it with
807 * g_signal_emit_by_name() if they need to control activation
810 * The default bindings for this signal are Space, Return and Enter.
812 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
813 g_signal_new (I_("activate-cursor-item"),
814 G_TYPE_FROM_CLASS (gobject_class),
815 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
816 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
818 _gtk_marshal_BOOLEAN__VOID,
822 * GtkIconView::move-cursor:
823 * @iconview: the object which received the signal
824 * @step: the granularity of the move, as a #GtkMovementStep
825 * @count: the number of @step units to move
827 * The ::move-cursor signal is a
828 * <link linkend="keybinding-signals">keybinding signal</link>
829 * which gets emitted when the user initiates a cursor movement.
831 * Applications should not connect to it, but may emit it with
832 * g_signal_emit_by_name() if they need to control the cursor
835 * The default bindings for this signal include
837 * <listitem>Arrow keys which move by individual steps</listitem>
838 * <listitem>Home/End keys which move to the first/last item</listitem>
839 * <listitem>PageUp/PageDown which move by "pages"</listitem>
842 * All of these will extend the selection when combined with
843 * the Shift modifier.
845 icon_view_signals[MOVE_CURSOR] =
846 g_signal_new (I_("move-cursor"),
847 G_TYPE_FROM_CLASS (gobject_class),
848 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
849 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
851 _gtk_marshal_BOOLEAN__ENUM_INT,
853 GTK_TYPE_MOVEMENT_STEP,
857 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
859 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
861 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
862 "toggle-cursor-item", 0);
863 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
864 "toggle-cursor-item", 0);
866 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
867 "activate-cursor-item", 0);
868 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
869 "activate-cursor-item", 0);
870 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
871 "activate-cursor-item", 0);
872 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
873 "activate-cursor-item", 0);
874 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
875 "activate-cursor-item", 0);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
878 GTK_MOVEMENT_DISPLAY_LINES, -1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
883 GTK_MOVEMENT_DISPLAY_LINES, 1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
888 GTK_MOVEMENT_DISPLAY_LINES, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
891 GTK_MOVEMENT_DISPLAY_LINES, 1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
894 GTK_MOVEMENT_BUFFER_ENDS, -1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
896 GTK_MOVEMENT_BUFFER_ENDS, -1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
899 GTK_MOVEMENT_BUFFER_ENDS, 1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
901 GTK_MOVEMENT_BUFFER_ENDS, 1);
903 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
904 GTK_MOVEMENT_PAGES, -1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
906 GTK_MOVEMENT_PAGES, -1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
909 GTK_MOVEMENT_PAGES, 1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
911 GTK_MOVEMENT_PAGES, 1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
914 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
916 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
918 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
919 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
920 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
921 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
923 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ICON_VIEW_ACCESSIBLE);
927 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
929 parent_buildable_iface = g_type_interface_peek_parent (iface);
930 iface->add_child = _gtk_cell_layout_buildable_add_child;
931 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
932 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
936 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
938 iface->get_area = gtk_icon_view_cell_layout_get_area;
942 gtk_icon_view_init (GtkIconView *icon_view)
944 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
948 icon_view->priv->width = 0;
949 icon_view->priv->height = 0;
950 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
951 icon_view->priv->pressed_button = -1;
952 icon_view->priv->press_start_x = -1;
953 icon_view->priv->press_start_y = -1;
954 icon_view->priv->text_column = -1;
955 icon_view->priv->markup_column = -1;
956 icon_view->priv->pixbuf_column = -1;
957 icon_view->priv->text_cell = NULL;
958 icon_view->priv->pixbuf_cell = NULL;
959 icon_view->priv->tooltip_column = -1;
961 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
963 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
965 icon_view->priv->columns = -1;
966 icon_view->priv->item_width = -1;
967 icon_view->priv->spacing = 0;
968 icon_view->priv->row_spacing = 6;
969 icon_view->priv->column_spacing = 6;
970 icon_view->priv->margin = 6;
971 icon_view->priv->item_padding = 6;
973 icon_view->priv->draw_focus = TRUE;
975 icon_view->priv->row_contexts =
976 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
979 /* GObject methods */
981 gtk_icon_view_constructor (GType type,
982 guint n_construct_properties,
983 GObjectConstructParam *construct_properties)
985 GtkIconView *icon_view;
988 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
989 (type, n_construct_properties, construct_properties);
991 icon_view = (GtkIconView *) object;
993 gtk_icon_view_ensure_cell_area (icon_view, NULL);
999 gtk_icon_view_dispose (GObject *object)
1001 GtkIconView *icon_view;
1002 GtkIconViewPrivate *priv;
1004 icon_view = GTK_ICON_VIEW (object);
1005 priv = icon_view->priv;
1007 if (priv->cell_area_context)
1009 g_object_unref (priv->cell_area_context);
1010 priv->cell_area_context = NULL;
1013 if (priv->row_contexts)
1015 g_ptr_array_free (priv->row_contexts, TRUE);
1016 priv->row_contexts = NULL;
1019 if (priv->cell_area)
1021 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1023 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1024 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1025 priv->add_editable_id = 0;
1026 priv->remove_editable_id = 0;
1028 g_object_unref (priv->cell_area);
1029 priv->cell_area = NULL;
1032 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1036 gtk_icon_view_set_property (GObject *object,
1038 const GValue *value,
1041 GtkIconView *icon_view;
1044 icon_view = GTK_ICON_VIEW (object);
1048 case PROP_SELECTION_MODE:
1049 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1051 case PROP_PIXBUF_COLUMN:
1052 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1054 case PROP_TEXT_COLUMN:
1055 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1057 case PROP_MARKUP_COLUMN:
1058 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1061 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1063 case PROP_ITEM_ORIENTATION:
1064 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1067 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1069 case PROP_ITEM_WIDTH:
1070 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1073 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1075 case PROP_ROW_SPACING:
1076 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1078 case PROP_COLUMN_SPACING:
1079 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1082 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1084 case PROP_REORDERABLE:
1085 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1088 case PROP_TOOLTIP_COLUMN:
1089 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1092 case PROP_ITEM_PADDING:
1093 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1096 case PROP_CELL_AREA:
1097 /* Construct-only, can only be assigned once */
1098 area = g_value_get_object (value);
1101 if (icon_view->priv->cell_area != NULL)
1103 g_warning ("cell-area has already been set, ignoring construct property");
1104 g_object_ref_sink (area);
1105 g_object_unref (area);
1108 gtk_icon_view_ensure_cell_area (icon_view, area);
1112 case PROP_HADJUSTMENT:
1113 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1115 case PROP_VADJUSTMENT:
1116 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1118 case PROP_HSCROLL_POLICY:
1119 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1120 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1122 case PROP_VSCROLL_POLICY:
1123 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1124 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1128 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1134 gtk_icon_view_get_property (GObject *object,
1139 GtkIconView *icon_view;
1141 icon_view = GTK_ICON_VIEW (object);
1145 case PROP_SELECTION_MODE:
1146 g_value_set_enum (value, icon_view->priv->selection_mode);
1148 case PROP_PIXBUF_COLUMN:
1149 g_value_set_int (value, icon_view->priv->pixbuf_column);
1151 case PROP_TEXT_COLUMN:
1152 g_value_set_int (value, icon_view->priv->text_column);
1154 case PROP_MARKUP_COLUMN:
1155 g_value_set_int (value, icon_view->priv->markup_column);
1158 g_value_set_object (value, icon_view->priv->model);
1160 case PROP_ITEM_ORIENTATION:
1161 g_value_set_enum (value, icon_view->priv->item_orientation);
1164 g_value_set_int (value, icon_view->priv->columns);
1166 case PROP_ITEM_WIDTH:
1167 g_value_set_int (value, icon_view->priv->item_width);
1170 g_value_set_int (value, icon_view->priv->spacing);
1172 case PROP_ROW_SPACING:
1173 g_value_set_int (value, icon_view->priv->row_spacing);
1175 case PROP_COLUMN_SPACING:
1176 g_value_set_int (value, icon_view->priv->column_spacing);
1179 g_value_set_int (value, icon_view->priv->margin);
1181 case PROP_REORDERABLE:
1182 g_value_set_boolean (value, icon_view->priv->reorderable);
1184 case PROP_TOOLTIP_COLUMN:
1185 g_value_set_int (value, icon_view->priv->tooltip_column);
1188 case PROP_ITEM_PADDING:
1189 g_value_set_int (value, icon_view->priv->item_padding);
1192 case PROP_CELL_AREA:
1193 g_value_set_object (value, icon_view->priv->cell_area);
1196 case PROP_HADJUSTMENT:
1197 g_value_set_object (value, icon_view->priv->hadjustment);
1199 case PROP_VADJUSTMENT:
1200 g_value_set_object (value, icon_view->priv->vadjustment);
1202 case PROP_HSCROLL_POLICY:
1203 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1205 case PROP_VSCROLL_POLICY:
1206 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1215 /* GtkWidget methods */
1217 gtk_icon_view_destroy (GtkWidget *widget)
1219 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1221 gtk_icon_view_set_model (icon_view, NULL);
1223 if (icon_view->priv->scroll_to_path != NULL)
1225 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1226 icon_view->priv->scroll_to_path = NULL;
1229 remove_scroll_timeout (icon_view);
1231 if (icon_view->priv->hadjustment != NULL)
1233 g_object_unref (icon_view->priv->hadjustment);
1234 icon_view->priv->hadjustment = NULL;
1237 if (icon_view->priv->vadjustment != NULL)
1239 g_object_unref (icon_view->priv->vadjustment);
1240 icon_view->priv->vadjustment = NULL;
1243 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1247 gtk_icon_view_realize (GtkWidget *widget)
1249 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1250 GtkAllocation allocation;
1252 GdkWindowAttr attributes;
1253 gint attributes_mask;
1254 GtkStyleContext *context;
1256 gtk_widget_set_realized (widget, TRUE);
1258 gtk_widget_get_allocation (widget, &allocation);
1260 /* Make the main, clipping window */
1261 attributes.window_type = GDK_WINDOW_CHILD;
1262 attributes.x = allocation.x;
1263 attributes.y = allocation.y;
1264 attributes.width = allocation.width;
1265 attributes.height = allocation.height;
1266 attributes.wclass = GDK_INPUT_OUTPUT;
1267 attributes.visual = gtk_widget_get_visual (widget);
1268 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1270 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1272 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1273 &attributes, attributes_mask);
1274 gtk_widget_set_window (widget, window);
1275 gdk_window_set_user_data (window, widget);
1277 gtk_widget_get_allocation (widget, &allocation);
1279 /* Make the window for the icon view */
1282 attributes.width = MAX (icon_view->priv->width, allocation.width);
1283 attributes.height = MAX (icon_view->priv->height, allocation.height);
1284 attributes.event_mask = (GDK_EXPOSURE_MASK |
1286 GDK_SMOOTH_SCROLL_MASK |
1287 GDK_POINTER_MOTION_MASK |
1288 GDK_BUTTON_PRESS_MASK |
1289 GDK_BUTTON_RELEASE_MASK |
1290 GDK_KEY_PRESS_MASK |
1291 GDK_KEY_RELEASE_MASK) |
1292 gtk_widget_get_events (widget);
1294 icon_view->priv->bin_window = gdk_window_new (window,
1295 &attributes, attributes_mask);
1296 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1298 context = gtk_widget_get_style_context (widget);
1300 gtk_style_context_save (context);
1301 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1302 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1303 gtk_style_context_set_background (context, window);
1304 gtk_style_context_restore (context);
1306 gdk_window_show (icon_view->priv->bin_window);
1310 gtk_icon_view_unrealize (GtkWidget *widget)
1312 GtkIconView *icon_view;
1314 icon_view = GTK_ICON_VIEW (widget);
1316 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1317 gdk_window_destroy (icon_view->priv->bin_window);
1318 icon_view->priv->bin_window = NULL;
1320 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1324 _gtk_icon_view_update_background (GtkIconView *icon_view)
1326 GtkWidget *widget = GTK_WIDGET (icon_view);
1328 if (gtk_widget_get_realized (widget))
1330 GtkStyleContext *context;
1332 context = gtk_widget_get_style_context (widget);
1334 gtk_style_context_save (context);
1335 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1337 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1338 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1340 gtk_style_context_restore (context);
1345 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1346 GtkStateFlags previous_state)
1348 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1349 gtk_widget_queue_draw (widget);
1353 gtk_icon_view_style_updated (GtkWidget *widget)
1355 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1357 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1358 gtk_widget_queue_resize (widget);
1362 gtk_icon_view_get_n_items (GtkIconView *icon_view)
1364 GtkIconViewPrivate *priv = icon_view->priv;
1366 if (priv->model == NULL)
1369 return gtk_tree_model_iter_n_children (priv->model, NULL);
1373 adjust_wrap_width (GtkIconView *icon_view)
1375 if (icon_view->priv->text_cell)
1377 gint wrap_width = 50;
1379 /* Here we go with the same old guess, try the icon size and set double
1380 * the size of the first icon found in the list, naive but works much
1382 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
1384 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
1385 GTK_WIDGET (icon_view),
1388 wrap_width = MAX (wrap_width * 2, 50);
1391 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
1392 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
1397 cell_area_get_preferred_size (GtkIconView *icon_view,
1398 GtkCellAreaContext *context,
1399 GtkOrientation orientation,
1404 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1407 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1409 GTK_WIDGET (icon_view),
1413 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1415 GTK_WIDGET (icon_view),
1421 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1423 GTK_WIDGET (icon_view),
1427 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1429 GTK_WIDGET (icon_view),
1435 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1436 GtkOrientation orientation,
1441 GtkIconViewPrivate *priv = icon_view->priv;
1442 GtkCellAreaContext *context;
1445 context = gtk_cell_area_create_context (priv->cell_area);
1447 for_size -= 2 * priv->item_padding;
1451 /* This is necessary for the context to work properly */
1452 for (items = priv->items; items; items = items->next)
1454 GtkIconViewItem *item = items->data;
1456 _gtk_icon_view_set_cell_data (icon_view, item);
1457 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1461 for (items = priv->items; items; items = items->next)
1463 GtkIconViewItem *item = items->data;
1465 _gtk_icon_view_set_cell_data (icon_view, item);
1466 if (items == priv->items)
1467 adjust_wrap_width (icon_view);
1468 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1471 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1474 gtk_cell_area_context_get_preferred_width_for_height (context,
1478 gtk_cell_area_context_get_preferred_width (context,
1484 gtk_cell_area_context_get_preferred_height_for_width (context,
1488 gtk_cell_area_context_get_preferred_height (context,
1492 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1495 *minimum = MAX (*minimum, priv->item_width);
1497 *natural = *minimum;
1501 *minimum += 2 * priv->item_padding;
1503 *natural += 2 * priv->item_padding;
1505 g_object_unref (context);
1509 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1510 GtkOrientation orientation,
1513 gint *min_item_size,
1515 gint *max_item_size)
1517 GtkIconViewPrivate *priv = icon_view->priv;
1518 int minimum, natural, spacing;
1520 g_return_if_fail (min_item_size == NULL || min_items != NULL);
1521 g_return_if_fail (max_item_size == NULL || max_items != NULL);
1523 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1525 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1526 spacing = priv->column_spacing;
1528 spacing = priv->row_spacing;
1530 size -= 2 * priv->margin;
1535 if (priv->columns > 0)
1537 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1540 *min_items = priv->columns;
1542 *max_items = priv->columns;
1546 int n_items = gtk_icon_view_get_n_items (icon_view);
1549 *min_items = (n_items + priv->columns - 1) / priv->columns;
1551 *max_items = (n_items + priv->columns - 1) / priv->columns;
1558 if (size <= minimum)
1561 *max_items = size / minimum;
1566 if (size <= natural)
1569 *min_items = size / natural;
1575 *min_item_size = size / *min_items;
1576 *min_item_size = MIN (*min_item_size, natural);
1577 *min_item_size -= spacing;
1578 *min_item_size -= 2 * priv->item_padding;
1583 *max_item_size = size / *max_items;
1584 *max_item_size = MIN (*max_item_size, natural);
1585 *max_item_size -= spacing;
1586 *max_item_size -= 2 * priv->item_padding;
1590 static GtkSizeRequestMode
1591 gtk_icon_view_get_request_mode (GtkWidget *widget)
1593 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1597 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1601 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1602 GtkIconViewPrivate *priv = icon_view->priv;
1603 int item_min, item_nat;
1605 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1607 if (priv->columns > 0)
1609 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1610 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1614 int n_items = gtk_icon_view_get_n_items (icon_view);
1623 *minimum = item_min;
1624 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1628 *minimum += 2 * priv->margin;
1629 *natural += 2 * priv->margin;
1633 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1638 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1639 GtkIconViewPrivate *priv = icon_view->priv;
1640 int item_min, item_nat, rows, row_height, n_items;
1642 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, &row_height, NULL, NULL);
1643 n_items = gtk_icon_view_get_n_items (icon_view);
1645 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, row_height, &item_min, &item_nat);
1646 *minimum = item_min * ((n_items + rows - 1) / rows);
1647 *natural = item_nat * ((n_items + rows - 1) / rows);
1649 *minimum += 2 * priv->margin;
1650 *natural += 2 * priv->margin;
1654 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1658 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1659 GtkIconViewPrivate *priv = icon_view->priv;
1660 int item_min, item_nat, n_items;
1662 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1663 n_items = gtk_icon_view_get_n_items (icon_view);
1665 if (priv->columns > 0)
1667 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1669 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1670 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1681 *minimum = item_min;
1682 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1686 *minimum += 2 * priv->margin;
1687 *natural += 2 * priv->margin;
1691 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1696 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1697 GtkIconViewPrivate *priv = icon_view->priv;
1698 int item_min, item_nat, columns, column_width, n_items;
1700 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, NULL, &columns, &column_width);
1701 n_items = gtk_icon_view_get_n_items (icon_view);
1703 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, column_width, &item_min, &item_nat);
1704 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1705 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1707 *minimum += 2 * priv->margin;
1708 *natural += 2 * priv->margin;
1712 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1716 for (list = icon_view->priv->children; list; list = list->next)
1718 GtkIconViewChild *child = list->data;
1720 /* totally ignore our child's requisition */
1721 gtk_widget_size_allocate (child->widget, &child->area);
1726 gtk_icon_view_size_allocate (GtkWidget *widget,
1727 GtkAllocation *allocation)
1729 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1731 gtk_widget_set_allocation (widget, allocation);
1733 gtk_icon_view_layout (icon_view);
1735 if (gtk_widget_get_realized (widget))
1737 gdk_window_move_resize (gtk_widget_get_window (widget),
1738 allocation->x, allocation->y,
1739 allocation->width, allocation->height);
1740 gdk_window_resize (icon_view->priv->bin_window,
1741 MAX (icon_view->priv->width, allocation->width),
1742 MAX (icon_view->priv->height, allocation->height));
1745 gtk_icon_view_allocate_children (icon_view);
1747 /* Delay signal emission */
1748 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1749 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1751 gtk_icon_view_set_hadjustment_values (icon_view);
1752 gtk_icon_view_set_vadjustment_values (icon_view);
1754 if (gtk_widget_get_realized (widget) &&
1755 icon_view->priv->scroll_to_path)
1758 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1759 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1760 icon_view->priv->scroll_to_path = NULL;
1762 gtk_icon_view_scroll_to_path (icon_view, path,
1763 icon_view->priv->scroll_to_use_align,
1764 icon_view->priv->scroll_to_row_align,
1765 icon_view->priv->scroll_to_col_align);
1766 gtk_tree_path_free (path);
1769 /* Emit any pending signals now */
1770 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1771 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1775 gtk_icon_view_draw (GtkWidget *widget,
1778 GtkIconView *icon_view;
1782 GtkIconViewDropPosition dest_pos;
1783 GtkIconViewItem *dest_item = NULL;
1785 icon_view = GTK_ICON_VIEW (widget);
1787 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1792 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1794 cairo_set_line_width (cr, 1.);
1796 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1800 dest_index = gtk_tree_path_get_indices (path)[0];
1801 gtk_tree_path_free (path);
1806 for (icons = icon_view->priv->items; icons; icons = icons->next)
1808 GtkIconViewItem *item = icons->data;
1809 GdkRectangle paint_area;
1811 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1812 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1813 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1814 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1818 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1821 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1823 gtk_icon_view_paint_item (icon_view, cr, item,
1824 item->cell_area.x, item->cell_area.y,
1825 icon_view->priv->draw_focus);
1827 if (dest_index == item->index)
1835 dest_pos != GTK_ICON_VIEW_NO_DROP)
1837 GtkStyleContext *context;
1838 GdkRectangle rect = { 0 };
1840 context = gtk_widget_get_style_context (widget);
1844 case GTK_ICON_VIEW_DROP_INTO:
1845 rect = dest_item->cell_area;
1847 case GTK_ICON_VIEW_DROP_ABOVE:
1848 rect.x = dest_item->cell_area.x;
1849 rect.y = dest_item->cell_area.y - 1;
1850 rect.width = dest_item->cell_area.width;
1853 case GTK_ICON_VIEW_DROP_LEFT:
1854 rect.x = dest_item->cell_area.x - 1;
1855 rect.y = dest_item->cell_area.y;
1857 rect.height = dest_item->cell_area.height;
1859 case GTK_ICON_VIEW_DROP_BELOW:
1860 rect.x = dest_item->cell_area.x;
1861 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1862 rect.width = dest_item->cell_area.width;
1865 case GTK_ICON_VIEW_DROP_RIGHT:
1866 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1867 rect.y = dest_item->cell_area.y;
1869 rect.height = dest_item->cell_area.height;
1870 case GTK_ICON_VIEW_NO_DROP: ;
1874 gtk_render_focus (context, cr,
1876 rect.width, rect.height);
1879 if (icon_view->priv->doing_rubberband)
1880 gtk_icon_view_paint_rubberband (icon_view, cr);
1884 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1888 rubberband_scroll_timeout (gpointer data)
1890 GtkIconView *icon_view = data;
1892 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1893 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1894 icon_view->priv->scroll_value_diff);
1896 gtk_icon_view_update_rubberband (icon_view);
1902 gtk_icon_view_motion (GtkWidget *widget,
1903 GdkEventMotion *event)
1905 GtkAllocation allocation;
1906 GtkIconView *icon_view;
1909 icon_view = GTK_ICON_VIEW (widget);
1911 gtk_icon_view_maybe_begin_drag (icon_view, event);
1913 if (icon_view->priv->doing_rubberband)
1915 gtk_icon_view_update_rubberband (widget);
1917 abs_y = event->y - icon_view->priv->height *
1918 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1919 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1920 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1922 gtk_widget_get_allocation (widget, &allocation);
1924 if (abs_y < 0 || abs_y > allocation.height)
1927 icon_view->priv->scroll_value_diff = abs_y;
1929 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1931 icon_view->priv->event_last_x = event->x;
1932 icon_view->priv->event_last_y = event->y;
1934 if (icon_view->priv->scroll_timeout_id == 0)
1935 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1939 remove_scroll_timeout (icon_view);
1943 GtkIconViewItem *item, *last_prelight_item;
1944 GtkCellRenderer *cell = NULL;
1946 last_prelight_item = icon_view->priv->last_prelight;
1947 item = _gtk_icon_view_get_item_at_coords (icon_view,
1954 item->prelight = TRUE;
1955 gtk_icon_view_queue_draw_item (icon_view, item);
1958 if (last_prelight_item != NULL &&
1959 last_prelight_item != item)
1961 last_prelight_item->prelight = FALSE;
1962 gtk_icon_view_queue_draw_item (icon_view,
1963 icon_view->priv->last_prelight);
1966 icon_view->priv->last_prelight = item;
1973 gtk_icon_view_remove (GtkContainer *container,
1976 GtkIconView *icon_view;
1977 GtkIconViewChild *child = NULL;
1980 icon_view = GTK_ICON_VIEW (container);
1982 tmp_list = icon_view->priv->children;
1985 child = tmp_list->data;
1986 if (child->widget == widget)
1988 gtk_widget_unparent (widget);
1990 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1991 g_list_free_1 (tmp_list);
1996 tmp_list = tmp_list->next;
2001 gtk_icon_view_forall (GtkContainer *container,
2002 gboolean include_internals,
2003 GtkCallback callback,
2004 gpointer callback_data)
2006 GtkIconView *icon_view;
2007 GtkIconViewChild *child = NULL;
2010 icon_view = GTK_ICON_VIEW (container);
2012 tmp_list = icon_view->priv->children;
2015 child = tmp_list->data;
2016 tmp_list = tmp_list->next;
2018 (* callback) (child->widget, callback_data);
2023 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
2024 GtkIconViewItem *item)
2027 AtkObject *item_obj;
2029 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2032 item_obj = atk_object_ref_accessible_child (obj, item->index);
2033 if (item_obj != NULL)
2035 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
2036 g_object_unref (item_obj);
2042 gtk_icon_view_add_editable (GtkCellArea *area,
2043 GtkCellRenderer *renderer,
2044 GtkCellEditable *editable,
2045 GdkRectangle *cell_area,
2047 GtkIconView *icon_view)
2049 GtkIconViewChild *child;
2050 GtkWidget *widget = GTK_WIDGET (editable);
2052 child = g_new (GtkIconViewChild, 1);
2054 child->widget = widget;
2055 child->area.x = cell_area->x;
2056 child->area.y = cell_area->y;
2057 child->area.width = cell_area->width;
2058 child->area.height = cell_area->height;
2060 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
2062 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2063 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
2065 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2069 gtk_icon_view_remove_editable (GtkCellArea *area,
2070 GtkCellRenderer *renderer,
2071 GtkCellEditable *editable,
2072 GtkIconView *icon_view)
2076 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2077 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2079 gtk_container_remove (GTK_CONTAINER (icon_view),
2080 GTK_WIDGET (editable));
2082 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2083 gtk_icon_view_queue_draw_path (icon_view, path);
2084 gtk_tree_path_free (path);
2088 * gtk_icon_view_set_cursor:
2089 * @icon_view: A #GtkIconView
2090 * @path: A #GtkTreePath
2091 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2092 * @start_editing: %TRUE if the specified cell should start being edited.
2094 * Sets the current keyboard focus to be at @path, and selects it. This is
2095 * useful when you want to focus the user's attention on a particular item.
2096 * If @cell is not %NULL, then focus is given to the cell specified by
2097 * it. Additionally, if @start_editing is %TRUE, then editing should be
2098 * started in the specified cell.
2100 * This function is often followed by <literal>gtk_widget_grab_focus
2101 * (icon_view)</literal> in order to give keyboard focus to the widget.
2102 * Please note that editing can only happen when the widget is realized.
2107 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2109 GtkCellRenderer *cell,
2110 gboolean start_editing)
2112 GtkIconViewItem *item = NULL;
2114 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2115 g_return_if_fail (path != NULL);
2116 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2118 if (icon_view->priv->cell_area)
2119 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2121 if (gtk_tree_path_get_depth (path) == 1)
2122 item = g_list_nth_data (icon_view->priv->items,
2123 gtk_tree_path_get_indices(path)[0]);
2128 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2129 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2131 if (start_editing &&
2132 icon_view->priv->cell_area)
2134 GtkCellAreaContext *context;
2136 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2137 _gtk_icon_view_set_cell_data (icon_view, item);
2138 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2139 GTK_WIDGET (icon_view), &item->cell_area,
2140 0 /* XXX flags */, TRUE);
2145 * gtk_icon_view_get_cursor:
2146 * @icon_view: A #GtkIconView
2147 * @path: (out) (allow-none): Return location for the current cursor path,
2149 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2151 * Fills in @path and @cell with the current cursor path and cell.
2152 * If the cursor isn't currently set, then *@path will be %NULL.
2153 * If no cell currently has focus, then *@cell will be %NULL.
2155 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2157 * Return value: %TRUE if the cursor is set.
2162 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2164 GtkCellRenderer **cell)
2166 GtkIconViewItem *item;
2168 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2170 item = icon_view->priv->cursor_item;
2175 *path = gtk_tree_path_new_from_indices (item->index, -1);
2180 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2181 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2183 return (item != NULL);
2187 gtk_icon_view_button_press (GtkWidget *widget,
2188 GdkEventButton *event)
2190 GtkIconView *icon_view;
2191 GtkIconViewItem *item;
2192 gboolean dirty = FALSE;
2193 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2195 icon_view = GTK_ICON_VIEW (widget);
2197 if (event->window != icon_view->priv->bin_window)
2200 if (!gtk_widget_has_focus (widget))
2201 gtk_widget_grab_focus (widget);
2203 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2205 GdkModifierType extend_mod_mask;
2206 GdkModifierType modify_mod_mask;
2209 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2212 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2214 item = _gtk_icon_view_get_item_at_coords (icon_view,
2220 * We consider only the the cells' area as the item area if the
2221 * item is not selected, but if it *is* selected, the complete
2222 * selection rectangle is considered to be part of the item.
2224 if (item != NULL && (cell != NULL || item->selected))
2228 if (gtk_cell_renderer_is_activatable (cell))
2232 gtk_icon_view_scroll_to_item (icon_view, item);
2234 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2236 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2238 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2239 (event->state & extend_mod_mask))
2241 gtk_icon_view_unselect_all_internal (icon_view);
2243 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2244 if (!icon_view->priv->anchor_item)
2245 icon_view->priv->anchor_item = item;
2247 gtk_icon_view_select_all_between (icon_view,
2248 icon_view->priv->anchor_item,
2254 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2255 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2256 (event->state & modify_mod_mask))
2258 item->selected = !item->selected;
2259 gtk_icon_view_queue_draw_item (icon_view, item);
2264 gtk_icon_view_unselect_all_internal (icon_view);
2266 item->selected = TRUE;
2267 gtk_icon_view_queue_draw_item (icon_view, item);
2270 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2271 icon_view->priv->anchor_item = item;
2274 /* Save press to possibly begin a drag */
2275 if (icon_view->priv->pressed_button < 0)
2277 icon_view->priv->pressed_button = event->button;
2278 icon_view->priv->press_start_x = event->x;
2279 icon_view->priv->press_start_y = event->y;
2282 if (!icon_view->priv->last_single_clicked)
2283 icon_view->priv->last_single_clicked = item;
2285 /* cancel the current editing, if it exists */
2286 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2288 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2290 GtkCellAreaContext *context;
2292 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2294 _gtk_icon_view_set_cell_data (icon_view, item);
2295 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2296 GTK_WIDGET (icon_view),
2297 &item->cell_area, 0/* XXX flags */, FALSE);
2302 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2303 !(event->state & modify_mod_mask))
2305 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2308 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2309 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2312 /* don't draw keyboard focus around an clicked-on item */
2313 icon_view->priv->draw_focus = FALSE;
2316 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
2318 item = _gtk_icon_view_get_item_at_coords (icon_view,
2323 if (item && item == icon_view->priv->last_single_clicked)
2327 path = gtk_tree_path_new_from_indices (item->index, -1);
2328 gtk_icon_view_item_activated (icon_view, path);
2329 gtk_tree_path_free (path);
2332 icon_view->priv->last_single_clicked = NULL;
2333 icon_view->priv->pressed_button = -1;
2337 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2339 return event->button == GDK_BUTTON_PRIMARY;
2343 gtk_icon_view_button_release (GtkWidget *widget,
2344 GdkEventButton *event)
2346 GtkIconView *icon_view;
2348 icon_view = GTK_ICON_VIEW (widget);
2350 if (icon_view->priv->pressed_button == event->button)
2351 icon_view->priv->pressed_button = -1;
2353 gtk_icon_view_stop_rubberbanding (icon_view);
2355 remove_scroll_timeout (icon_view);
2361 gtk_icon_view_key_press (GtkWidget *widget,
2364 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2366 if (icon_view->priv->doing_rubberband)
2368 if (event->keyval == GDK_KEY_Escape)
2369 gtk_icon_view_stop_rubberbanding (icon_view);
2374 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2378 gtk_icon_view_key_release (GtkWidget *widget,
2381 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2383 if (icon_view->priv->doing_rubberband)
2386 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2390 gtk_icon_view_update_rubberband (gpointer data)
2392 GtkIconView *icon_view;
2394 GdkRectangle old_area;
2395 GdkRectangle new_area;
2396 GdkRectangle common;
2397 cairo_region_t *invalid_region;
2399 icon_view = GTK_ICON_VIEW (data);
2401 gdk_window_get_device_position (icon_view->priv->bin_window,
2402 icon_view->priv->rubberband_device,
2408 old_area.x = MIN (icon_view->priv->rubberband_x1,
2409 icon_view->priv->rubberband_x2);
2410 old_area.y = MIN (icon_view->priv->rubberband_y1,
2411 icon_view->priv->rubberband_y2);
2412 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2413 icon_view->priv->rubberband_x1) + 1;
2414 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2415 icon_view->priv->rubberband_y1) + 1;
2417 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2418 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2419 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2420 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2422 invalid_region = cairo_region_create_rectangle (&old_area);
2423 cairo_region_union_rectangle (invalid_region, &new_area);
2425 gdk_rectangle_intersect (&old_area, &new_area, &common);
2426 if (common.width > 2 && common.height > 2)
2428 cairo_region_t *common_region;
2430 /* make sure the border is invalidated */
2436 common_region = cairo_region_create_rectangle (&common);
2438 cairo_region_subtract (invalid_region, common_region);
2439 cairo_region_destroy (common_region);
2442 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2444 cairo_region_destroy (invalid_region);
2446 icon_view->priv->rubberband_x2 = x;
2447 icon_view->priv->rubberband_y2 = y;
2449 gtk_icon_view_update_rubberband_selection (icon_view);
2453 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2460 if (icon_view->priv->rubberband_device)
2463 for (items = icon_view->priv->items; items; items = items->next)
2465 GtkIconViewItem *item = items->data;
2467 item->selected_before_rubberbanding = item->selected;
2470 icon_view->priv->rubberband_x1 = x;
2471 icon_view->priv->rubberband_y1 = y;
2472 icon_view->priv->rubberband_x2 = x;
2473 icon_view->priv->rubberband_y2 = y;
2475 icon_view->priv->doing_rubberband = TRUE;
2476 icon_view->priv->rubberband_device = device;
2478 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2482 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2484 if (!icon_view->priv->doing_rubberband)
2487 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2488 icon_view->priv->rubberband_device);
2490 icon_view->priv->doing_rubberband = FALSE;
2491 icon_view->priv->rubberband_device = NULL;
2493 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2497 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2500 gint x, y, width, height;
2501 gboolean dirty = FALSE;
2503 x = MIN (icon_view->priv->rubberband_x1,
2504 icon_view->priv->rubberband_x2);
2505 y = MIN (icon_view->priv->rubberband_y1,
2506 icon_view->priv->rubberband_y2);
2507 width = ABS (icon_view->priv->rubberband_x1 -
2508 icon_view->priv->rubberband_x2);
2509 height = ABS (icon_view->priv->rubberband_y1 -
2510 icon_view->priv->rubberband_y2);
2512 for (items = icon_view->priv->items; items; items = items->next)
2514 GtkIconViewItem *item = items->data;
2518 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2519 x, y, width, height);
2521 selected = is_in ^ item->selected_before_rubberbanding;
2523 if (item->selected != selected)
2525 item->selected = selected;
2527 gtk_icon_view_queue_draw_item (icon_view, item);
2532 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2537 GdkRectangle hit_rect;
2542 hit_test (GtkCellRenderer *renderer,
2543 const GdkRectangle *cell_area,
2544 const GdkRectangle *cell_background,
2547 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2548 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2549 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2550 MAX (data->hit_rect.y, cell_area->y) > 0)
2553 return (data->hit != FALSE);
2557 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2558 GtkIconViewItem *item,
2564 HitTestData data = { { x, y, width, height }, FALSE };
2565 GtkCellAreaContext *context;
2566 GdkRectangle *item_area = &item->cell_area;
2568 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2569 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2572 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2574 _gtk_icon_view_set_cell_data (icon_view, item);
2575 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2576 GTK_WIDGET (icon_view),
2577 item_area, item_area,
2578 (GtkCellAllocCallback)hit_test, &data);
2584 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2586 gboolean dirty = FALSE;
2589 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2592 for (items = icon_view->priv->items; items; items = items->next)
2594 GtkIconViewItem *item = items->data;
2598 item->selected = FALSE;
2600 gtk_icon_view_queue_draw_item (icon_view, item);
2601 gtk_icon_view_item_selected_changed (icon_view, item);
2609 /* GtkIconView signals */
2611 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2613 gtk_icon_view_select_all (icon_view);
2617 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2619 gtk_icon_view_unselect_all (icon_view);
2623 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2625 gtk_icon_view_unselect_all (icon_view);
2627 if (icon_view->priv->cursor_item != NULL)
2628 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2632 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2635 GtkCellAreaContext *context;
2637 if (!icon_view->priv->cursor_item)
2640 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2642 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2643 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2644 GTK_WIDGET (icon_view),
2645 &icon_view->priv->cursor_item->cell_area,
2649 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2650 gtk_icon_view_item_activated (icon_view, path);
2651 gtk_tree_path_free (path);
2657 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2659 if (!icon_view->priv->cursor_item)
2662 switch (icon_view->priv->selection_mode)
2664 case GTK_SELECTION_NONE:
2666 case GTK_SELECTION_BROWSE:
2667 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2669 case GTK_SELECTION_SINGLE:
2670 if (icon_view->priv->cursor_item->selected)
2671 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2673 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2675 case GTK_SELECTION_MULTIPLE:
2676 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2677 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2679 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2680 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2686 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2688 GtkAllocation allocation;
2689 GtkAdjustment *adj = icon_view->priv->hadjustment;
2690 gdouble old_page_size;
2696 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2698 old_value = gtk_adjustment_get_value (adj);
2699 old_upper = gtk_adjustment_get_upper (adj);
2700 old_page_size = gtk_adjustment_get_page_size (adj);
2701 new_upper = MAX (allocation.width, icon_view->priv->width);
2703 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2705 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2706 /* Quick explanation:
2707 * In LTR locales, leftmost portion of visible rectangle should stay
2708 * fixed, which means left edge of scrollbar thumb should remain fixed
2709 * and thus adjustment's value should stay the same.
2711 * In RTL locales, we want to keep rightmost portion of visible
2712 * rectangle fixed. This means right edge of thumb should remain fixed.
2713 * In this case, upper - value - page_size should remain constant.
2715 new_value = (new_upper - allocation.width) -
2716 (old_upper - old_value - old_page_size);
2717 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2720 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2722 gtk_adjustment_configure (adj,
2726 allocation.width * 0.1,
2727 allocation.width * 0.9,
2732 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2734 GtkAllocation allocation;
2735 GtkAdjustment *adj = icon_view->priv->vadjustment;
2737 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2739 gtk_adjustment_configure (adj,
2740 gtk_adjustment_get_value (adj),
2742 MAX (allocation.height, icon_view->priv->height),
2743 allocation.height * 0.1,
2744 allocation.height * 0.9,
2749 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2750 GtkAdjustment *adjustment)
2752 GtkIconViewPrivate *priv = icon_view->priv;
2754 if (adjustment && priv->hadjustment == adjustment)
2757 if (priv->hadjustment != NULL)
2759 g_signal_handlers_disconnect_matched (priv->hadjustment,
2760 G_SIGNAL_MATCH_DATA,
2761 0, 0, NULL, NULL, icon_view);
2762 g_object_unref (priv->hadjustment);
2766 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2769 g_signal_connect (adjustment, "value-changed",
2770 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2771 priv->hadjustment = g_object_ref_sink (adjustment);
2772 gtk_icon_view_set_hadjustment_values (icon_view);
2774 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2778 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2779 GtkAdjustment *adjustment)
2781 GtkIconViewPrivate *priv = icon_view->priv;
2783 if (adjustment && priv->vadjustment == adjustment)
2786 if (priv->vadjustment != NULL)
2788 g_signal_handlers_disconnect_matched (priv->vadjustment,
2789 G_SIGNAL_MATCH_DATA,
2790 0, 0, NULL, NULL, icon_view);
2791 g_object_unref (priv->vadjustment);
2795 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2798 g_signal_connect (adjustment, "value-changed",
2799 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2800 priv->vadjustment = g_object_ref_sink (adjustment);
2801 gtk_icon_view_set_vadjustment_values (icon_view);
2803 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2807 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2808 GtkIconView *icon_view)
2810 GtkIconViewPrivate *priv = icon_view->priv;
2812 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2814 gdk_window_move (priv->bin_window,
2815 - gtk_adjustment_get_value (priv->hadjustment),
2816 - gtk_adjustment_get_value (priv->vadjustment));
2818 if (icon_view->priv->doing_rubberband)
2819 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2821 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2826 compare_sizes (gconstpointer p1,
2830 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2831 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2835 gtk_icon_view_layout (GtkIconView *icon_view)
2837 GtkIconViewPrivate *priv = icon_view->priv;
2838 GtkWidget *widget = GTK_WIDGET (icon_view);
2840 gint item_width; /* this doesn't include item_padding */
2841 gint n_columns, n_rows, n_items;
2843 GtkRequestedSize *sizes;
2846 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2849 n_items = gtk_icon_view_get_n_items (icon_view);
2851 gtk_icon_view_compute_n_items_for_size (icon_view,
2852 GTK_ORIENTATION_HORIZONTAL,
2853 gtk_widget_get_allocated_width (widget),
2855 &n_columns, &item_width);
2856 n_rows = (n_items + n_columns - 1) / n_columns;
2858 priv->width = n_columns * (item_width + 2 * priv->item_padding + priv->column_spacing) - priv->column_spacing;
2859 priv->width += 2 * priv->margin;
2860 priv->width = MAX (priv->width, gtk_widget_get_allocated_width (widget));
2862 /* Clear the per row contexts */
2863 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2865 gtk_cell_area_context_reset (priv->cell_area_context);
2866 /* because layouting is complicated. We designed an API
2867 * that is O(N²) and nonsensical.
2868 * And we're proud of it. */
2869 for (items = priv->items; items; items = items->next)
2871 _gtk_icon_view_set_cell_data (icon_view, items->data);
2872 gtk_cell_area_get_preferred_width (priv->cell_area,
2873 priv->cell_area_context,
2878 sizes = g_newa (GtkRequestedSize, n_rows);
2879 items = priv->items;
2880 priv->height = priv->margin;
2882 /* Collect the heights for all rows */
2883 for (row = 0; row < n_rows; row++)
2885 GtkCellAreaContext *context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2886 g_ptr_array_add (priv->row_contexts, context);
2888 for (col = 0; col < n_columns && items; col++, items = items->next)
2890 GtkIconViewItem *item = items->data;
2892 _gtk_icon_view_set_cell_data (icon_view, item);
2893 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2900 sizes[row].data = GINT_TO_POINTER (row);
2901 gtk_cell_area_context_get_preferred_height_for_width (context,
2903 &sizes[row].minimum_size,
2904 &sizes[row].natural_size);
2905 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2908 priv->height -= priv->row_spacing;
2909 priv->height += priv->margin;
2910 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2912 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2916 /* Actually allocate the rows */
2917 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2919 items = priv->items;
2920 priv->height = priv->margin;
2922 for (row = 0; row < n_rows; row++)
2924 GtkCellAreaContext *context = g_ptr_array_index (priv->row_contexts, row);
2925 gtk_cell_area_context_allocate (context, item_width, sizes[row].minimum_size);
2927 priv->height += priv->item_padding;
2929 for (col = 0; col < n_columns && items; col++, items = items->next)
2931 GtkIconViewItem *item = items->data;
2933 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2934 item->cell_area.width = item_width;
2935 item->cell_area.y = priv->height;
2936 item->cell_area.height = sizes[row].minimum_size;
2941 item->cell_area.x = priv->width - item_width - item->cell_area.x;
2942 item->col = n_columns - 1 - col;
2946 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
2949 priv->height -= priv->row_spacing;
2950 priv->height += priv->margin;
2951 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
2955 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2957 /* Clear all item sizes */
2958 g_list_foreach (icon_view->priv->items,
2959 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2961 /* Re-layout the items */
2962 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
2966 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2968 item->cell_area.width = -1;
2969 item->cell_area.height = -1;
2973 gtk_icon_view_paint_item (GtkIconView *icon_view,
2975 GtkIconViewItem *item,
2978 gboolean draw_focus)
2980 GdkRectangle cell_area;
2981 GtkStateFlags state = 0;
2982 GtkCellRendererState flags = 0;
2983 GtkStyleContext *style_context;
2984 GtkWidget *widget = GTK_WIDGET (icon_view);
2985 GtkIconViewPrivate *priv = icon_view->priv;
2986 GtkCellAreaContext *context;
2988 if (priv->model == NULL || item->cell_area.width <= 0 || item->cell_area.height <= 0)
2991 _gtk_icon_view_set_cell_data (icon_view, item);
2993 style_context = gtk_widget_get_style_context (widget);
2994 state = gtk_widget_get_state_flags (widget);
2996 gtk_style_context_save (style_context);
2997 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2998 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
3000 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
3004 if ((state & GTK_STATE_FLAG_FOCUSED) &&
3005 item == icon_view->priv->cursor_item)
3007 flags |= GTK_CELL_RENDERER_FOCUSED;
3010 state |= GTK_STATE_FLAG_SELECTED;
3011 flags |= GTK_CELL_RENDERER_SELECTED;
3016 state |= GTK_STATE_FLAG_PRELIGHT;
3017 flags |= GTK_CELL_RENDERER_PRELIT;
3020 gtk_style_context_set_state (style_context, state);
3024 gtk_render_background (style_context, cr,
3025 x - icon_view->priv->item_padding,
3026 y - icon_view->priv->item_padding,
3027 item->cell_area.width + icon_view->priv->item_padding * 2,
3028 item->cell_area.height + icon_view->priv->item_padding * 2);
3029 gtk_render_frame (style_context, cr,
3030 x - icon_view->priv->item_padding,
3031 y - icon_view->priv->item_padding,
3032 item->cell_area.width + icon_view->priv->item_padding * 2,
3033 item->cell_area.height + icon_view->priv->item_padding * 2);
3038 cell_area.width = item->cell_area.width;
3039 cell_area.height = item->cell_area.height;
3041 context = g_ptr_array_index (priv->row_contexts, item->row);
3042 gtk_cell_area_render (priv->cell_area, context,
3043 widget, cr, &cell_area, &cell_area, flags,
3046 gtk_style_context_restore (style_context);
3050 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3053 GtkStyleContext *context;
3058 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3059 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3060 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3061 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3063 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3065 gtk_style_context_save (context);
3066 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3068 gdk_cairo_rectangle (cr, &rect);
3071 gtk_render_background (context, cr,
3073 rect.width, rect.height);
3074 gtk_render_frame (context, cr,
3076 rect.width, rect.height);
3078 gtk_style_context_restore (context);
3083 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3089 index = gtk_tree_path_get_indices (path)[0];
3091 for (l = icon_view->priv->items; l; l = l->next)
3093 GtkIconViewItem *item = l->data;
3095 if (item->index == index)
3097 gtk_icon_view_queue_draw_item (icon_view, item);
3104 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3105 GtkIconViewItem *item)
3108 GdkRectangle *item_area = &item->cell_area;
3110 rect.x = item_area->x - icon_view->priv->item_padding;
3111 rect.y = item_area->y - icon_view->priv->item_padding;
3112 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3113 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3115 if (icon_view->priv->bin_window)
3116 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3120 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3121 GtkIconViewItem *item,
3122 GtkCellRenderer *cursor_cell)
3125 AtkObject *item_obj;
3126 AtkObject *cursor_item_obj;
3128 /* When hitting this path from keynav, the focus cell is
3129 * already set, we dont need to notify the atk object
3130 * but we still need to queue the draw here (in the case
3131 * that the focus cell changes but not the cursor item).
3133 gtk_icon_view_queue_draw_item (icon_view, item);
3135 if (icon_view->priv->cursor_item == item &&
3136 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3139 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3140 if (icon_view->priv->cursor_item != NULL)
3142 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3145 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3146 if (cursor_item_obj != NULL)
3147 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3150 icon_view->priv->cursor_item = item;
3153 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3156 /* Make sure there is a cell in focus initially */
3157 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3158 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3161 /* Notify that accessible focus object has changed */
3162 item_obj = atk_object_ref_accessible_child (obj, item->index);
3164 if (item_obj != NULL)
3166 atk_focus_tracker_notify (item_obj);
3167 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3168 g_object_unref (item_obj);
3173 static GtkIconViewItem *
3174 gtk_icon_view_item_new (void)
3176 GtkIconViewItem *item;
3178 item = g_slice_new0 (GtkIconViewItem);
3180 item->cell_area.width = -1;
3181 item->cell_area.height = -1;
3187 gtk_icon_view_item_free (GtkIconViewItem *item)
3189 g_return_if_fail (item != NULL);
3191 g_slice_free (GtkIconViewItem, item);
3195 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3198 gboolean only_in_cell,
3199 GtkCellRenderer **cell_at_pos)
3204 *cell_at_pos = NULL;
3206 for (items = icon_view->priv->items; items; items = items->next)
3208 GtkIconViewItem *item = items->data;
3209 GdkRectangle *item_area = &item->cell_area;
3211 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3212 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3213 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3214 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3216 if (only_in_cell || cell_at_pos)
3218 GtkCellRenderer *cell = NULL;
3219 GtkCellAreaContext *context;
3221 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3222 _gtk_icon_view_set_cell_data (icon_view, item);
3224 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3225 y >= item_area->y && y <= item_area->y + item_area->height)
3226 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3227 GTK_WIDGET (icon_view),
3232 *cell_at_pos = cell;
3235 return cell != NULL ? item : NULL;
3246 _gtk_icon_view_select_item (GtkIconView *icon_view,
3247 GtkIconViewItem *item)
3249 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3250 g_return_if_fail (item != NULL);
3255 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3257 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3258 gtk_icon_view_unselect_all_internal (icon_view);
3260 item->selected = TRUE;
3262 gtk_icon_view_item_selected_changed (icon_view, item);
3263 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3265 gtk_icon_view_queue_draw_item (icon_view, item);
3270 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3271 GtkIconViewItem *item)
3273 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3274 g_return_if_fail (item != NULL);
3276 if (!item->selected)
3279 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3280 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3283 item->selected = FALSE;
3285 gtk_icon_view_item_selected_changed (icon_view, item);
3286 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3288 gtk_icon_view_queue_draw_item (icon_view, item);
3292 verify_items (GtkIconView *icon_view)
3297 for (items = icon_view->priv->items; items; items = items->next)
3299 GtkIconViewItem *item = items->data;
3301 if (item->index != i)
3302 g_error ("List item does not match its index: "
3303 "item index %d and list index %d\n", item->index, i);
3310 gtk_icon_view_row_changed (GtkTreeModel *model,
3315 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3317 /* ignore changes in branches */
3318 if (gtk_tree_path_get_depth (path) > 1)
3321 /* An icon view subclass might add it's own model and populate
3322 * things at init() time instead of waiting for the constructor()
3325 if (icon_view->priv->cell_area)
3326 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3328 /* Here we can use a "grow-only" strategy for optimization
3329 * and only invalidate a single item and queue a relayout
3330 * instead of invalidating the whole thing.
3332 * For now GtkIconView still cant deal with huge models
3333 * so just invalidate the whole thing when the model
3336 gtk_icon_view_invalidate_sizes (icon_view);
3338 verify_items (icon_view);
3342 gtk_icon_view_row_inserted (GtkTreeModel *model,
3347 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3349 GtkIconViewItem *item;
3352 /* ignore changes in branches */
3353 if (gtk_tree_path_get_depth (path) > 1)
3356 index = gtk_tree_path_get_indices(path)[0];
3358 item = gtk_icon_view_item_new ();
3360 item->index = index;
3362 /* FIXME: We can be more efficient here,
3363 we can store a tail pointer and use that when
3364 appending (which is a rather common operation)
3366 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3369 list = g_list_nth (icon_view->priv->items, index + 1);
3370 for (; list; list = list->next)
3377 verify_items (icon_view);
3379 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3383 gtk_icon_view_row_deleted (GtkTreeModel *model,
3387 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3389 GtkIconViewItem *item;
3391 gboolean emit = FALSE;
3393 /* ignore changes in branches */
3394 if (gtk_tree_path_get_depth (path) > 1)
3397 index = gtk_tree_path_get_indices(path)[0];
3399 list = g_list_nth (icon_view->priv->items, index);
3402 if (icon_view->priv->cell_area)
3403 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3405 if (item == icon_view->priv->anchor_item)
3406 icon_view->priv->anchor_item = NULL;
3408 if (item == icon_view->priv->cursor_item)
3409 icon_view->priv->cursor_item = NULL;
3411 if (item == icon_view->priv->last_prelight)
3412 icon_view->priv->last_prelight = NULL;
3417 gtk_icon_view_item_free (item);
3419 for (next = list->next; next; next = next->next)
3426 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3428 verify_items (icon_view);
3430 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3433 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3437 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3438 GtkTreePath *parent,
3443 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3446 GList *items = NULL, *list;
3447 GtkIconViewItem **item_array;
3450 /* ignore changes in branches */
3454 if (icon_view->priv->cell_area)
3455 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3457 length = gtk_tree_model_iter_n_children (model, NULL);
3459 order = g_new (gint, length);
3460 for (i = 0; i < length; i++)
3461 order [new_order[i]] = i;
3463 item_array = g_new (GtkIconViewItem *, length);
3464 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3465 item_array[order[i]] = list->data;
3468 for (i = length - 1; i >= 0; i--)
3470 item_array[i]->index = i;
3471 items = g_list_prepend (items, item_array[i]);
3474 g_free (item_array);
3475 g_list_free (icon_view->priv->items);
3476 icon_view->priv->items = items;
3478 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3480 verify_items (icon_view);
3484 gtk_icon_view_build_items (GtkIconView *icon_view)
3488 GList *items = NULL;
3490 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3498 GtkIconViewItem *item = gtk_icon_view_item_new ();
3504 items = g_list_prepend (items, item);
3506 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3508 icon_view->priv->items = g_list_reverse (items);
3512 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3515 GtkMovementStep step,
3519 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3520 I_("move-cursor"), 2,
3524 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3529 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3532 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3537 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3544 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3545 GtkMovementStep step,
3548 GdkModifierType state;
3550 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3551 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3552 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3553 step == GTK_MOVEMENT_DISPLAY_LINES ||
3554 step == GTK_MOVEMENT_PAGES ||
3555 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3557 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3560 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3561 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3563 if (gtk_get_current_event_state (&state))
3565 GdkModifierType extend_mod_mask;
3566 GdkModifierType modify_mod_mask;
3569 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3570 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3572 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3573 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3575 if ((state & modify_mod_mask) == modify_mod_mask)
3576 icon_view->priv->modify_selection_pressed = TRUE;
3577 if ((state & extend_mod_mask) == extend_mod_mask)
3578 icon_view->priv->extend_selection_pressed = TRUE;
3580 /* else we assume not pressed */
3584 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3585 case GTK_MOVEMENT_VISUAL_POSITIONS:
3586 gtk_icon_view_move_cursor_left_right (icon_view, count);
3588 case GTK_MOVEMENT_DISPLAY_LINES:
3589 gtk_icon_view_move_cursor_up_down (icon_view, count);
3591 case GTK_MOVEMENT_PAGES:
3592 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3594 case GTK_MOVEMENT_BUFFER_ENDS:
3595 gtk_icon_view_move_cursor_start_end (icon_view, count);
3598 g_assert_not_reached ();
3601 icon_view->priv->modify_selection_pressed = FALSE;
3602 icon_view->priv->extend_selection_pressed = FALSE;
3604 icon_view->priv->draw_focus = TRUE;
3609 static GtkIconViewItem *
3610 find_item (GtkIconView *icon_view,
3611 GtkIconViewItem *current,
3617 GtkIconViewItem *item;
3619 /* FIXME: this could be more efficient
3621 row = current->row + row_ofs;
3622 col = current->col + col_ofs;
3624 for (items = icon_view->priv->items; items; items = items->next)
3627 if (item->row == row && item->col == col)
3634 static GtkIconViewItem *
3635 find_item_page_up_down (GtkIconView *icon_view,
3636 GtkIconViewItem *current,
3643 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3645 item = g_list_find (icon_view->priv->items, current);
3650 for (next = item->next; next; next = next->next)
3652 if (((GtkIconViewItem *)next->data)->col == col)
3655 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3665 for (next = item->prev; next; next = next->prev)
3667 if (((GtkIconViewItem *)next->data)->col == col)
3670 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3684 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3685 GtkIconViewItem *anchor,
3686 GtkIconViewItem *cursor)
3689 GtkIconViewItem *item;
3690 gint row1, row2, col1, col2;
3691 gboolean dirty = FALSE;
3693 if (anchor->row < cursor->row)
3704 if (anchor->col < cursor->col)
3715 for (items = icon_view->priv->items; items; items = items->next)
3719 if (row1 <= item->row && item->row <= row2 &&
3720 col1 <= item->col && item->col <= col2)
3722 if (!item->selected)
3725 item->selected = TRUE;
3726 gtk_icon_view_item_selected_changed (icon_view, item);
3728 gtk_icon_view_queue_draw_item (icon_view, item);
3736 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3739 GtkIconViewItem *item;
3740 GtkCellRenderer *cell = NULL;
3741 gboolean dirty = FALSE;
3743 GtkDirectionType direction;
3745 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3748 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3750 if (!icon_view->priv->cursor_item)
3755 list = icon_view->priv->items;
3757 list = g_list_last (icon_view->priv->items);
3763 /* Give focus to the first cell initially */
3764 _gtk_icon_view_set_cell_data (icon_view, item);
3765 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3774 item = icon_view->priv->cursor_item;
3775 step = count > 0 ? 1 : -1;
3777 /* Save the current focus cell in case we hit the edge */
3778 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3782 _gtk_icon_view_set_cell_data (icon_view, item);
3784 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3787 item = find_item (icon_view, item, step, 0);
3793 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3795 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3797 gtk_widget_child_focus (toplevel,
3798 direction == GTK_DIR_UP ?
3799 GTK_DIR_TAB_BACKWARD :
3800 GTK_DIR_TAB_FORWARD);
3804 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3808 if (icon_view->priv->modify_selection_pressed ||
3809 !icon_view->priv->extend_selection_pressed ||
3810 !icon_view->priv->anchor_item ||
3811 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3812 icon_view->priv->anchor_item = item;
3814 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3815 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3817 if (!icon_view->priv->modify_selection_pressed &&
3818 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3820 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3821 dirty = gtk_icon_view_select_all_between (icon_view,
3822 icon_view->priv->anchor_item,
3826 gtk_icon_view_scroll_to_item (icon_view, item);
3829 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3833 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3836 GtkIconViewItem *item;
3837 gboolean dirty = FALSE;
3839 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3842 if (!icon_view->priv->cursor_item)
3847 list = icon_view->priv->items;
3849 list = g_list_last (icon_view->priv->items);
3851 item = list ? list->data : NULL;
3854 item = find_item_page_up_down (icon_view,
3855 icon_view->priv->cursor_item,
3858 if (item == icon_view->priv->cursor_item)
3859 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3864 if (icon_view->priv->modify_selection_pressed ||
3865 !icon_view->priv->extend_selection_pressed ||
3866 !icon_view->priv->anchor_item ||
3867 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3868 icon_view->priv->anchor_item = item;
3870 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3872 if (!icon_view->priv->modify_selection_pressed &&
3873 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3875 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3876 dirty = gtk_icon_view_select_all_between (icon_view,
3877 icon_view->priv->anchor_item,
3881 gtk_icon_view_scroll_to_item (icon_view, item);
3884 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3888 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3891 GtkIconViewItem *item;
3892 GtkCellRenderer *cell = NULL;
3893 gboolean dirty = FALSE;
3895 GtkDirectionType direction;
3897 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3900 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3902 if (!icon_view->priv->cursor_item)
3907 list = icon_view->priv->items;
3909 list = g_list_last (icon_view->priv->items);
3915 /* Give focus to the first cell initially */
3916 _gtk_icon_view_set_cell_data (icon_view, item);
3917 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3926 item = icon_view->priv->cursor_item;
3927 step = count > 0 ? 1 : -1;
3929 /* Save the current focus cell in case we hit the edge */
3930 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3934 _gtk_icon_view_set_cell_data (icon_view, item);
3936 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3939 item = find_item (icon_view, item, 0, step);
3945 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3947 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3949 gtk_widget_child_focus (toplevel,
3950 direction == GTK_DIR_LEFT ?
3951 GTK_DIR_TAB_BACKWARD :
3952 GTK_DIR_TAB_FORWARD);
3956 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3960 if (icon_view->priv->modify_selection_pressed ||
3961 !icon_view->priv->extend_selection_pressed ||
3962 !icon_view->priv->anchor_item ||
3963 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3964 icon_view->priv->anchor_item = item;
3966 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3967 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3969 if (!icon_view->priv->modify_selection_pressed &&
3970 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3972 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3973 dirty = gtk_icon_view_select_all_between (icon_view,
3974 icon_view->priv->anchor_item,
3978 gtk_icon_view_scroll_to_item (icon_view, item);
3981 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3985 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3988 GtkIconViewItem *item;
3990 gboolean dirty = FALSE;
3992 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3996 list = icon_view->priv->items;
3998 list = g_list_last (icon_view->priv->items);
4000 item = list ? list->data : NULL;
4002 if (item == icon_view->priv->cursor_item)
4003 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4008 if (icon_view->priv->modify_selection_pressed ||
4009 !icon_view->priv->extend_selection_pressed ||
4010 !icon_view->priv->anchor_item ||
4011 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4012 icon_view->priv->anchor_item = item;
4014 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4016 if (!icon_view->priv->modify_selection_pressed &&
4017 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4019 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4020 dirty = gtk_icon_view_select_all_between (icon_view,
4021 icon_view->priv->anchor_item,
4025 gtk_icon_view_scroll_to_item (icon_view, item);
4028 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4032 * gtk_icon_view_scroll_to_path:
4033 * @icon_view: A #GtkIconView.
4034 * @path: The path of the item to move to.
4035 * @use_align: whether to use alignment arguments, or %FALSE.
4036 * @row_align: The vertical alignment of the item specified by @path.
4037 * @col_align: The horizontal alignment of the item specified by @path.
4039 * Moves the alignments of @icon_view to the position specified by @path.
4040 * @row_align determines where the row is placed, and @col_align determines
4041 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4042 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4045 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4046 * tree does the minimum amount of work to scroll the item onto the screen.
4047 * This means that the item will be scrolled to the edge closest to its current
4048 * position. If the item is currently visible on the screen, nothing is done.
4050 * This function only works if the model is set, and @path is a valid row on
4051 * the model. If the model changes before the @icon_view is realized, the
4052 * centered path will be modified to reflect this change.
4057 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4063 GtkIconViewItem *item = NULL;
4066 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4067 g_return_if_fail (path != NULL);
4068 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4069 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4071 widget = GTK_WIDGET (icon_view);
4073 if (gtk_tree_path_get_depth (path) > 0)
4074 item = g_list_nth_data (icon_view->priv->items,
4075 gtk_tree_path_get_indices(path)[0]);
4077 if (!item || item->cell_area.width < 0 ||
4078 !gtk_widget_get_realized (widget))
4080 if (icon_view->priv->scroll_to_path)
4081 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4083 icon_view->priv->scroll_to_path = NULL;
4086 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4088 icon_view->priv->scroll_to_use_align = use_align;
4089 icon_view->priv->scroll_to_row_align = row_align;
4090 icon_view->priv->scroll_to_col_align = col_align;
4097 GtkAllocation allocation;
4100 GdkRectangle item_area =
4102 item->cell_area.x - icon_view->priv->item_padding,
4103 item->cell_area.y - icon_view->priv->item_padding,
4104 item->cell_area.width + icon_view->priv->item_padding * 2,
4105 item->cell_area.height + icon_view->priv->item_padding * 2
4108 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4110 gtk_widget_get_allocation (widget, &allocation);
4112 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4114 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4115 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4117 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4119 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4120 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4122 gtk_adjustment_changed (icon_view->priv->hadjustment);
4123 gtk_adjustment_changed (icon_view->priv->vadjustment);
4126 gtk_icon_view_scroll_to_item (icon_view, item);
4131 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4132 GtkIconViewItem *item)
4134 GtkIconViewPrivate *priv = icon_view->priv;
4135 GtkWidget *widget = GTK_WIDGET (icon_view);
4136 GtkAdjustment *hadj, *vadj;
4137 GtkAllocation allocation;
4139 GdkRectangle item_area;
4141 item_area.x = item->cell_area.x - priv->item_padding;
4142 item_area.y = item->cell_area.y - priv->item_padding;
4143 item_area.width = item->cell_area.width + priv->item_padding * 2;
4144 item_area.height = item->cell_area.height + priv->item_padding * 2;
4146 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4147 gtk_widget_get_allocation (widget, &allocation);
4149 hadj = icon_view->priv->hadjustment;
4150 vadj = icon_view->priv->vadjustment;
4152 if (y + item_area.y < 0)
4153 gtk_adjustment_set_value (vadj,
4154 gtk_adjustment_get_value (vadj)
4156 else if (y + item_area.y + item_area.height > allocation.height)
4157 gtk_adjustment_set_value (vadj,
4158 gtk_adjustment_get_value (vadj)
4159 + y + item_area.y + item_area.height - allocation.height);
4161 if (x + item_area.x < 0)
4162 gtk_adjustment_set_value (hadj,
4163 gtk_adjustment_get_value (hadj)
4165 else if (x + item_area.x + item_area.width > allocation.width)
4166 gtk_adjustment_set_value (hadj,
4167 gtk_adjustment_get_value (hadj)
4168 + x + item_area.x + item_area.width - allocation.width);
4170 gtk_adjustment_changed (hadj);
4171 gtk_adjustment_changed (vadj);
4174 /* GtkCellLayout implementation */
4177 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4178 GtkCellArea *cell_area)
4180 GtkIconViewPrivate *priv = icon_view->priv;
4182 if (priv->cell_area)
4186 priv->cell_area = cell_area;
4188 priv->cell_area = gtk_cell_area_box_new ();
4190 g_object_ref_sink (priv->cell_area);
4192 if (GTK_IS_ORIENTABLE (priv->cell_area))
4193 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4195 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4197 priv->add_editable_id =
4198 g_signal_connect (priv->cell_area, "add-editable",
4199 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4200 priv->remove_editable_id =
4201 g_signal_connect (priv->cell_area, "remove-editable",
4202 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4204 update_text_cell (icon_view);
4205 update_pixbuf_cell (icon_view);
4208 static GtkCellArea *
4209 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4211 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4212 GtkIconViewPrivate *priv = icon_view->priv;
4214 if (G_UNLIKELY (!priv->cell_area))
4215 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4217 return icon_view->priv->cell_area;
4221 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4222 GtkIconViewItem *item)
4227 path = gtk_tree_path_new_from_indices (item->index, -1);
4228 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4230 gtk_tree_path_free (path);
4232 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4233 icon_view->priv->model,
4234 &iter, FALSE, FALSE);
4243 * gtk_icon_view_new:
4245 * Creates a new #GtkIconView widget
4247 * Return value: A newly created #GtkIconView widget
4252 gtk_icon_view_new (void)
4254 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4258 * gtk_icon_view_new_with_area:
4259 * @area: the #GtkCellArea to use to layout cells
4261 * Creates a new #GtkIconView widget using the
4262 * specified @area to layout cells inside the icons.
4264 * Return value: A newly created #GtkIconView widget
4269 gtk_icon_view_new_with_area (GtkCellArea *area)
4271 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4275 * gtk_icon_view_new_with_model:
4276 * @model: The model.
4278 * Creates a new #GtkIconView widget with the model @model.
4280 * Return value: A newly created #GtkIconView widget.
4285 gtk_icon_view_new_with_model (GtkTreeModel *model)
4287 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4291 * gtk_icon_view_convert_widget_to_bin_window_coords:
4292 * @icon_view: a #GtkIconView
4293 * @wx: X coordinate relative to the widget
4294 * @wy: Y coordinate relative to the widget
4295 * @bx: (out): return location for bin_window X coordinate
4296 * @by: (out): return location for bin_window Y coordinate
4298 * Converts widget coordinates to coordinates for the bin_window,
4299 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4304 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4312 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4314 if (icon_view->priv->bin_window)
4315 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4326 * gtk_icon_view_get_path_at_pos:
4327 * @icon_view: A #GtkIconView.
4328 * @x: The x position to be identified
4329 * @y: The y position to be identified
4331 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4332 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4333 * the cell at the specified position.
4334 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4335 * widget coordinates to bin_window coordinates.
4337 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4338 * if no icon exists at that position.
4343 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4347 GtkIconViewItem *item;
4350 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4352 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4357 path = gtk_tree_path_new_from_indices (item->index, -1);
4363 * gtk_icon_view_get_item_at_pos:
4364 * @icon_view: A #GtkIconView.
4365 * @x: The x position to be identified
4366 * @y: The y position to be identified
4367 * @path: (out) (allow-none): Return location for the path, or %NULL
4368 * @cell: (out) (allow-none): Return location for the renderer
4369 * responsible for the cell at (@x, @y), or %NULL
4371 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4372 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4373 * obtains the cell at the specified position. The returned path should
4374 * be freed with gtk_tree_path_free().
4375 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4376 * widget coordinates to bin_window coordinates.
4378 * Return value: %TRUE if an item exists at the specified position
4383 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4387 GtkCellRenderer **cell)
4389 GtkIconViewItem *item;
4390 GtkCellRenderer *renderer = NULL;
4392 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4394 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4399 *path = gtk_tree_path_new_from_indices (item->index, -1);
4407 return (item != NULL);
4411 * gtk_icon_view_set_tooltip_item:
4412 * @icon_view: a #GtkIconView
4413 * @tooltip: a #GtkTooltip
4414 * @path: a #GtkTreePath
4416 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4417 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4418 * See also gtk_tooltip_set_tip_area().
4423 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4424 GtkTooltip *tooltip,
4427 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4428 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4430 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4434 * gtk_icon_view_set_tooltip_cell:
4435 * @icon_view: a #GtkIconView
4436 * @tooltip: a #GtkTooltip
4437 * @path: a #GtkTreePath
4438 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4440 * Sets the tip area of @tooltip to the area which @cell occupies in
4441 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4443 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4448 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4449 GtkTooltip *tooltip,
4451 GtkCellRenderer *cell)
4454 GtkIconViewItem *item = NULL;
4457 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4458 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4459 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4461 if (gtk_tree_path_get_depth (path) > 0)
4462 item = g_list_nth_data (icon_view->priv->items,
4463 gtk_tree_path_get_indices(path)[0]);
4470 GtkCellAreaContext *context;
4472 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4473 _gtk_icon_view_set_cell_data (icon_view, item);
4474 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4475 GTK_WIDGET (icon_view),
4476 cell, &item->cell_area, &rect);
4480 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4481 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4482 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4483 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4486 if (icon_view->priv->bin_window)
4488 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4493 gtk_tooltip_set_tip_area (tooltip, &rect);
4498 * gtk_icon_view_get_tooltip_context:
4499 * @icon_view: an #GtkIconView
4500 * @x: (inout): the x coordinate (relative to widget coordinates)
4501 * @y: (inout): the y coordinate (relative to widget coordinates)
4502 * @keyboard_tip: whether this is a keyboard tooltip or not
4503 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4504 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4505 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4507 * This function is supposed to be used in a #GtkWidget::query-tooltip
4508 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4509 * which are received in the signal handler, should be passed to this
4510 * function without modification.
4512 * The return value indicates whether there is an icon view item at the given
4513 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4514 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4515 * @model, @path and @iter which have been provided will be set to point to
4516 * that row and the corresponding model. @x and @y will always be converted
4517 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4519 * Return value: whether or not the given tooltip context points to a item
4524 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4527 gboolean keyboard_tip,
4528 GtkTreeModel **model,
4532 GtkTreePath *tmppath = NULL;
4534 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4535 g_return_val_if_fail (x != NULL, FALSE);
4536 g_return_val_if_fail (y != NULL, FALSE);
4540 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4547 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4550 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4555 *model = gtk_icon_view_get_model (icon_view);
4558 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4564 gtk_tree_path_free (tmppath);
4570 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4573 gboolean keyboard_tip,
4574 GtkTooltip *tooltip,
4580 GtkTreeModel *model;
4581 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4583 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4586 &model, &path, &iter))
4589 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4593 gtk_tree_path_free (path);
4597 gtk_tooltip_set_markup (tooltip, str);
4598 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4600 gtk_tree_path_free (path);
4608 * gtk_icon_view_set_tooltip_column:
4609 * @icon_view: a #GtkIconView
4610 * @column: an integer, which is a valid column number for @icon_view's model
4612 * If you only plan to have simple (text-only) tooltips on full items, you
4613 * can use this function to have #GtkIconView handle these automatically
4614 * for you. @column should be set to the column in @icon_view's model
4615 * containing the tooltip texts, or -1 to disable this feature.
4617 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4618 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4620 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4621 * so &, <, etc have to be escaped in the text.
4626 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4629 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4631 if (column == icon_view->priv->tooltip_column)
4636 g_signal_handlers_disconnect_by_func (icon_view,
4637 gtk_icon_view_set_tooltip_query_cb,
4639 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4643 if (icon_view->priv->tooltip_column == -1)
4645 g_signal_connect (icon_view, "query-tooltip",
4646 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4647 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4651 icon_view->priv->tooltip_column = column;
4652 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4656 * gtk_icon_view_get_tooltip_column:
4657 * @icon_view: a #GtkIconView
4659 * Returns the column of @icon_view's model which is being used for
4660 * displaying tooltips on @icon_view's rows.
4662 * Return value: the index of the tooltip column that is currently being
4663 * used, or -1 if this is disabled.
4668 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4670 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4672 return icon_view->priv->tooltip_column;
4676 * gtk_icon_view_get_visible_range:
4677 * @icon_view: A #GtkIconView
4678 * @start_path: (out) (allow-none): Return location for start of region,
4680 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4682 * Sets @start_path and @end_path to be the first and last visible path.
4683 * Note that there may be invisible paths in between.
4685 * Both paths should be freed with gtk_tree_path_free() after use.
4687 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4692 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4693 GtkTreePath **start_path,
4694 GtkTreePath **end_path)
4696 gint start_index = -1;
4697 gint end_index = -1;
4700 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4702 if (icon_view->priv->hadjustment == NULL ||
4703 icon_view->priv->vadjustment == NULL)
4706 if (start_path == NULL && end_path == NULL)
4709 for (icons = icon_view->priv->items; icons; icons = icons->next)
4711 GtkIconViewItem *item = icons->data;
4712 GdkRectangle *item_area = &item->cell_area;
4714 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4715 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4717 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4718 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4720 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4721 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4723 if (start_index == -1)
4724 start_index = item->index;
4725 end_index = item->index;
4729 if (start_path && start_index != -1)
4730 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4731 if (end_path && end_index != -1)
4732 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4734 return start_index != -1;
4738 * gtk_icon_view_selected_foreach:
4739 * @icon_view: A #GtkIconView.
4740 * @func: (scope call): The function to call for each selected icon.
4741 * @data: User data to pass to the function.
4743 * Calls a function for each selected icon. Note that the model or
4744 * selection cannot be modified from within this function.
4749 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4750 GtkIconViewForeachFunc func,
4755 for (list = icon_view->priv->items; list; list = list->next)
4757 GtkIconViewItem *item = list->data;
4758 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4761 (* func) (icon_view, path, data);
4763 gtk_tree_path_free (path);
4768 * gtk_icon_view_set_selection_mode:
4769 * @icon_view: A #GtkIconView.
4770 * @mode: The selection mode
4772 * Sets the selection mode of the @icon_view.
4777 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4778 GtkSelectionMode mode)
4780 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4782 if (mode == icon_view->priv->selection_mode)
4785 if (mode == GTK_SELECTION_NONE ||
4786 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4787 gtk_icon_view_unselect_all (icon_view);
4789 icon_view->priv->selection_mode = mode;
4791 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4795 * gtk_icon_view_get_selection_mode:
4796 * @icon_view: A #GtkIconView.
4798 * Gets the selection mode of the @icon_view.
4800 * Return value: the current selection mode
4805 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4807 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4809 return icon_view->priv->selection_mode;
4813 * gtk_icon_view_set_model:
4814 * @icon_view: A #GtkIconView.
4815 * @model: (allow-none): The model.
4817 * Sets the model for a #GtkIconView.
4818 * If the @icon_view already has a model set, it will remove
4819 * it before setting the new model. If @model is %NULL, then
4820 * it will unset the old model.
4825 gtk_icon_view_set_model (GtkIconView *icon_view,
4826 GtkTreeModel *model)
4828 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4829 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4831 if (icon_view->priv->model == model)
4834 if (icon_view->priv->scroll_to_path)
4836 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4837 icon_view->priv->scroll_to_path = NULL;
4840 /* The area can be NULL while disposing */
4841 if (icon_view->priv->cell_area)
4842 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4848 if (icon_view->priv->pixbuf_column != -1)
4850 column_type = gtk_tree_model_get_column_type (model,
4851 icon_view->priv->pixbuf_column);
4853 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4856 if (icon_view->priv->text_column != -1)
4858 column_type = gtk_tree_model_get_column_type (model,
4859 icon_view->priv->text_column);
4861 g_return_if_fail (column_type == G_TYPE_STRING);
4864 if (icon_view->priv->markup_column != -1)
4866 column_type = gtk_tree_model_get_column_type (model,
4867 icon_view->priv->markup_column);
4869 g_return_if_fail (column_type == G_TYPE_STRING);
4874 if (icon_view->priv->model)
4876 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4877 gtk_icon_view_row_changed,
4879 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4880 gtk_icon_view_row_inserted,
4882 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4883 gtk_icon_view_row_deleted,
4885 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4886 gtk_icon_view_rows_reordered,
4889 g_object_unref (icon_view->priv->model);
4891 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4892 icon_view->priv->items = NULL;
4893 icon_view->priv->anchor_item = NULL;
4894 icon_view->priv->cursor_item = NULL;
4895 icon_view->priv->last_single_clicked = NULL;
4896 icon_view->priv->last_prelight = NULL;
4897 icon_view->priv->width = 0;
4898 icon_view->priv->height = 0;
4901 icon_view->priv->model = model;
4903 if (icon_view->priv->model)
4905 g_object_ref (icon_view->priv->model);
4906 g_signal_connect (icon_view->priv->model,
4908 G_CALLBACK (gtk_icon_view_row_changed),
4910 g_signal_connect (icon_view->priv->model,
4912 G_CALLBACK (gtk_icon_view_row_inserted),
4914 g_signal_connect (icon_view->priv->model,
4916 G_CALLBACK (gtk_icon_view_row_deleted),
4918 g_signal_connect (icon_view->priv->model,
4920 G_CALLBACK (gtk_icon_view_rows_reordered),
4923 gtk_icon_view_build_items (icon_view);
4926 g_object_notify (G_OBJECT (icon_view), "model");
4928 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4932 * gtk_icon_view_get_model:
4933 * @icon_view: a #GtkIconView
4935 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4938 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4939 * currently being used.
4944 gtk_icon_view_get_model (GtkIconView *icon_view)
4946 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4948 return icon_view->priv->model;
4952 update_text_cell (GtkIconView *icon_view)
4954 if (!icon_view->priv->cell_area)
4957 if (icon_view->priv->text_column == -1 &&
4958 icon_view->priv->markup_column == -1)
4960 if (icon_view->priv->text_cell != NULL)
4962 gtk_cell_area_remove (icon_view->priv->cell_area,
4963 icon_view->priv->text_cell);
4964 icon_view->priv->text_cell = NULL;
4969 if (icon_view->priv->text_cell == NULL)
4971 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4973 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4976 if (icon_view->priv->markup_column != -1)
4977 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4978 icon_view->priv->text_cell,
4979 "markup", icon_view->priv->markup_column,
4982 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4983 icon_view->priv->text_cell,
4984 "text", icon_view->priv->text_column,
4987 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4988 g_object_set (icon_view->priv->text_cell,
4989 "alignment", PANGO_ALIGN_CENTER,
4990 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4995 g_object_set (icon_view->priv->text_cell,
4996 "alignment", PANGO_ALIGN_LEFT,
4997 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5005 update_pixbuf_cell (GtkIconView *icon_view)
5007 if (!icon_view->priv->cell_area)
5010 if (icon_view->priv->pixbuf_column == -1)
5012 if (icon_view->priv->pixbuf_cell != NULL)
5014 gtk_cell_area_remove (icon_view->priv->cell_area,
5015 icon_view->priv->pixbuf_cell);
5017 icon_view->priv->pixbuf_cell = NULL;
5022 if (icon_view->priv->pixbuf_cell == NULL)
5024 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5026 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5029 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5030 icon_view->priv->pixbuf_cell,
5031 "pixbuf", icon_view->priv->pixbuf_column,
5034 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5035 g_object_set (icon_view->priv->pixbuf_cell,
5040 g_object_set (icon_view->priv->pixbuf_cell,
5048 * gtk_icon_view_set_text_column:
5049 * @icon_view: A #GtkIconView.
5050 * @column: A column in the currently used model, or -1 to display no text
5052 * Sets the column with text for @icon_view to be @column. The text
5053 * column must be of type #G_TYPE_STRING.
5058 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5061 if (column == icon_view->priv->text_column)
5065 icon_view->priv->text_column = -1;
5068 if (icon_view->priv->model != NULL)
5072 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5074 g_return_if_fail (column_type == G_TYPE_STRING);
5077 icon_view->priv->text_column = column;
5080 if (icon_view->priv->cell_area)
5081 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5083 update_text_cell (icon_view);
5085 gtk_icon_view_invalidate_sizes (icon_view);
5087 g_object_notify (G_OBJECT (icon_view), "text-column");
5091 * gtk_icon_view_get_text_column:
5092 * @icon_view: A #GtkIconView.
5094 * Returns the column with text for @icon_view.
5096 * Returns: the text column, or -1 if it's unset.
5101 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5103 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5105 return icon_view->priv->text_column;
5109 * gtk_icon_view_set_markup_column:
5110 * @icon_view: A #GtkIconView.
5111 * @column: A column in the currently used model, or -1 to display no text
5113 * Sets the column with markup information for @icon_view to be
5114 * @column. The markup column must be of type #G_TYPE_STRING.
5115 * If the markup column is set to something, it overrides
5116 * the text column set by gtk_icon_view_set_text_column().
5121 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5124 if (column == icon_view->priv->markup_column)
5128 icon_view->priv->markup_column = -1;
5131 if (icon_view->priv->model != NULL)
5135 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5137 g_return_if_fail (column_type == G_TYPE_STRING);
5140 icon_view->priv->markup_column = column;
5143 if (icon_view->priv->cell_area)
5144 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5146 update_text_cell (icon_view);
5148 gtk_icon_view_invalidate_sizes (icon_view);
5150 g_object_notify (G_OBJECT (icon_view), "markup-column");
5154 * gtk_icon_view_get_markup_column:
5155 * @icon_view: A #GtkIconView.
5157 * Returns the column with markup text for @icon_view.
5159 * Returns: the markup column, or -1 if it's unset.
5164 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5166 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5168 return icon_view->priv->markup_column;
5172 * gtk_icon_view_set_pixbuf_column:
5173 * @icon_view: A #GtkIconView.
5174 * @column: A column in the currently used model, or -1 to disable
5176 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5177 * column must be of type #GDK_TYPE_PIXBUF
5182 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5185 if (column == icon_view->priv->pixbuf_column)
5189 icon_view->priv->pixbuf_column = -1;
5192 if (icon_view->priv->model != NULL)
5196 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5198 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5201 icon_view->priv->pixbuf_column = column;
5204 if (icon_view->priv->cell_area)
5205 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5207 update_pixbuf_cell (icon_view);
5209 gtk_icon_view_invalidate_sizes (icon_view);
5211 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5216 * gtk_icon_view_get_pixbuf_column:
5217 * @icon_view: A #GtkIconView.
5219 * Returns the column with pixbufs for @icon_view.
5221 * Returns: the pixbuf column, or -1 if it's unset.
5226 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5228 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5230 return icon_view->priv->pixbuf_column;
5234 * gtk_icon_view_select_path:
5235 * @icon_view: A #GtkIconView.
5236 * @path: The #GtkTreePath to be selected.
5238 * Selects the row at @path.
5243 gtk_icon_view_select_path (GtkIconView *icon_view,
5246 GtkIconViewItem *item = NULL;
5248 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5249 g_return_if_fail (icon_view->priv->model != NULL);
5250 g_return_if_fail (path != NULL);
5252 if (gtk_tree_path_get_depth (path) > 0)
5253 item = g_list_nth_data (icon_view->priv->items,
5254 gtk_tree_path_get_indices(path)[0]);
5257 _gtk_icon_view_select_item (icon_view, item);
5261 * gtk_icon_view_unselect_path:
5262 * @icon_view: A #GtkIconView.
5263 * @path: The #GtkTreePath to be unselected.
5265 * Unselects the row at @path.
5270 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5273 GtkIconViewItem *item;
5275 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5276 g_return_if_fail (icon_view->priv->model != NULL);
5277 g_return_if_fail (path != NULL);
5279 item = g_list_nth_data (icon_view->priv->items,
5280 gtk_tree_path_get_indices(path)[0]);
5285 _gtk_icon_view_unselect_item (icon_view, item);
5289 * gtk_icon_view_get_selected_items:
5290 * @icon_view: A #GtkIconView.
5292 * Creates a list of paths of all selected items. Additionally, if you are
5293 * planning on modifying the model after calling this function, you may
5294 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5295 * To do this, you can use gtk_tree_row_reference_new().
5297 * To free the return value, use:
5299 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5302 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5307 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5310 GList *selected = NULL;
5312 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5314 for (list = icon_view->priv->items; list != NULL; list = list->next)
5316 GtkIconViewItem *item = list->data;
5320 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5322 selected = g_list_prepend (selected, path);
5330 * gtk_icon_view_select_all:
5331 * @icon_view: A #GtkIconView.
5333 * Selects all the icons. @icon_view must has its selection mode set
5334 * to #GTK_SELECTION_MULTIPLE.
5339 gtk_icon_view_select_all (GtkIconView *icon_view)
5342 gboolean dirty = FALSE;
5344 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5346 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5349 for (items = icon_view->priv->items; items; items = items->next)
5351 GtkIconViewItem *item = items->data;
5353 if (!item->selected)
5356 item->selected = TRUE;
5357 gtk_icon_view_queue_draw_item (icon_view, item);
5362 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5366 * gtk_icon_view_unselect_all:
5367 * @icon_view: A #GtkIconView.
5369 * Unselects all the icons.
5374 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5376 gboolean dirty = FALSE;
5378 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5380 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5383 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5386 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5390 * gtk_icon_view_path_is_selected:
5391 * @icon_view: A #GtkIconView.
5392 * @path: A #GtkTreePath to check selection on.
5394 * Returns %TRUE if the icon pointed to by @path is currently
5395 * selected. If @path does not point to a valid location, %FALSE is returned.
5397 * Return value: %TRUE if @path is selected.
5402 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5405 GtkIconViewItem *item;
5407 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5408 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5409 g_return_val_if_fail (path != NULL, FALSE);
5411 item = g_list_nth_data (icon_view->priv->items,
5412 gtk_tree_path_get_indices(path)[0]);
5417 return item->selected;
5421 * gtk_icon_view_get_item_row:
5422 * @icon_view: a #GtkIconView
5423 * @path: the #GtkTreePath of the item
5425 * Gets the row in which the item @path is currently
5426 * displayed. Row numbers start at 0.
5428 * Returns: The row in which the item is displayed
5433 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5436 GtkIconViewItem *item;
5438 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5439 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5440 g_return_val_if_fail (path != NULL, -1);
5442 item = g_list_nth_data (icon_view->priv->items,
5443 gtk_tree_path_get_indices(path)[0]);
5452 * gtk_icon_view_get_item_column:
5453 * @icon_view: a #GtkIconView
5454 * @path: the #GtkTreePath of the item
5456 * Gets the column in which the item @path is currently
5457 * displayed. Column numbers start at 0.
5459 * Returns: The column in which the item is displayed
5464 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5467 GtkIconViewItem *item;
5469 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5470 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5471 g_return_val_if_fail (path != NULL, -1);
5473 item = g_list_nth_data (icon_view->priv->items,
5474 gtk_tree_path_get_indices(path)[0]);
5483 * gtk_icon_view_item_activated:
5484 * @icon_view: A #GtkIconView
5485 * @path: The #GtkTreePath to be activated
5487 * Activates the item determined by @path.
5492 gtk_icon_view_item_activated (GtkIconView *icon_view,
5495 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5496 g_return_if_fail (path != NULL);
5498 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5502 * gtk_icon_view_set_item_orientation:
5503 * @icon_view: a #GtkIconView
5504 * @orientation: the relative position of texts and icons
5506 * Sets the ::item-orientation property which determines whether the labels
5507 * are drawn beside the icons instead of below.
5512 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5513 GtkOrientation orientation)
5515 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5517 if (icon_view->priv->item_orientation != orientation)
5519 icon_view->priv->item_orientation = orientation;
5521 if (icon_view->priv->cell_area)
5523 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5524 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5525 icon_view->priv->item_orientation);
5527 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5530 gtk_icon_view_invalidate_sizes (icon_view);
5532 update_text_cell (icon_view);
5533 update_pixbuf_cell (icon_view);
5535 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5540 * gtk_icon_view_get_item_orientation:
5541 * @icon_view: a #GtkIconView
5543 * Returns the value of the ::item-orientation property which determines
5544 * whether the labels are drawn beside the icons instead of below.
5546 * Return value: the relative position of texts and icons
5551 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5553 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5554 GTK_ORIENTATION_VERTICAL);
5556 return icon_view->priv->item_orientation;
5560 * gtk_icon_view_set_columns:
5561 * @icon_view: a #GtkIconView
5562 * @columns: the number of columns
5564 * Sets the ::columns property which determines in how
5565 * many columns the icons are arranged. If @columns is
5566 * -1, the number of columns will be chosen automatically
5567 * to fill the available area.
5572 gtk_icon_view_set_columns (GtkIconView *icon_view,
5575 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5577 if (icon_view->priv->columns != columns)
5579 icon_view->priv->columns = columns;
5581 if (icon_view->priv->cell_area)
5582 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5584 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5586 g_object_notify (G_OBJECT (icon_view), "columns");
5591 * gtk_icon_view_get_columns:
5592 * @icon_view: a #GtkIconView
5594 * Returns the value of the ::columns property.
5596 * Return value: the number of columns, or -1
5601 gtk_icon_view_get_columns (GtkIconView *icon_view)
5603 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5605 return icon_view->priv->columns;
5609 * gtk_icon_view_set_item_width:
5610 * @icon_view: a #GtkIconView
5611 * @item_width: the width for each item
5613 * Sets the ::item-width property which specifies the width
5614 * to use for each item. If it is set to -1, the icon view will
5615 * automatically determine a suitable item size.
5620 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5623 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5625 if (icon_view->priv->item_width != item_width)
5627 icon_view->priv->item_width = item_width;
5629 if (icon_view->priv->cell_area)
5630 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5632 gtk_icon_view_invalidate_sizes (icon_view);
5634 update_text_cell (icon_view);
5636 g_object_notify (G_OBJECT (icon_view), "item-width");
5641 * gtk_icon_view_get_item_width:
5642 * @icon_view: a #GtkIconView
5644 * Returns the value of the ::item-width property.
5646 * Return value: the width of a single item, or -1
5651 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5653 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5655 return icon_view->priv->item_width;
5660 * gtk_icon_view_set_spacing:
5661 * @icon_view: a #GtkIconView
5662 * @spacing: the spacing
5664 * Sets the ::spacing property which specifies the space
5665 * which is inserted between the cells (i.e. the icon and
5666 * the text) of an item.
5671 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5674 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5676 if (icon_view->priv->spacing != spacing)
5678 icon_view->priv->spacing = spacing;
5680 if (icon_view->priv->cell_area)
5681 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5683 gtk_icon_view_invalidate_sizes (icon_view);
5685 g_object_notify (G_OBJECT (icon_view), "spacing");
5690 * gtk_icon_view_get_spacing:
5691 * @icon_view: a #GtkIconView
5693 * Returns the value of the ::spacing property.
5695 * Return value: the space between cells
5700 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5702 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5704 return icon_view->priv->spacing;
5708 * gtk_icon_view_set_row_spacing:
5709 * @icon_view: a #GtkIconView
5710 * @row_spacing: the row spacing
5712 * Sets the ::row-spacing property which specifies the space
5713 * which is inserted between the rows of the icon view.
5718 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5721 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5723 if (icon_view->priv->row_spacing != row_spacing)
5725 icon_view->priv->row_spacing = row_spacing;
5727 if (icon_view->priv->cell_area)
5728 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5730 gtk_icon_view_invalidate_sizes (icon_view);
5732 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5737 * gtk_icon_view_get_row_spacing:
5738 * @icon_view: a #GtkIconView
5740 * Returns the value of the ::row-spacing property.
5742 * Return value: the space between rows
5747 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5749 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5751 return icon_view->priv->row_spacing;
5755 * gtk_icon_view_set_column_spacing:
5756 * @icon_view: a #GtkIconView
5757 * @column_spacing: the column spacing
5759 * Sets the ::column-spacing property which specifies the space
5760 * which is inserted between the columns of the icon view.
5765 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5766 gint column_spacing)
5768 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5770 if (icon_view->priv->column_spacing != column_spacing)
5772 icon_view->priv->column_spacing = column_spacing;
5774 if (icon_view->priv->cell_area)
5775 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5777 gtk_icon_view_invalidate_sizes (icon_view);
5779 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5784 * gtk_icon_view_get_column_spacing:
5785 * @icon_view: a #GtkIconView
5787 * Returns the value of the ::column-spacing property.
5789 * Return value: the space between columns
5794 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5796 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5798 return icon_view->priv->column_spacing;
5802 * gtk_icon_view_set_margin:
5803 * @icon_view: a #GtkIconView
5804 * @margin: the margin
5806 * Sets the ::margin property which specifies the space
5807 * which is inserted at the top, bottom, left and right
5813 gtk_icon_view_set_margin (GtkIconView *icon_view,
5816 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5818 if (icon_view->priv->margin != margin)
5820 icon_view->priv->margin = margin;
5822 if (icon_view->priv->cell_area)
5823 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5825 gtk_icon_view_invalidate_sizes (icon_view);
5827 g_object_notify (G_OBJECT (icon_view), "margin");
5832 * gtk_icon_view_get_margin:
5833 * @icon_view: a #GtkIconView
5835 * Returns the value of the ::margin property.
5837 * Return value: the space at the borders
5842 gtk_icon_view_get_margin (GtkIconView *icon_view)
5844 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5846 return icon_view->priv->margin;
5850 * gtk_icon_view_set_item_padding:
5851 * @icon_view: a #GtkIconView
5852 * @item_padding: the item padding
5854 * Sets the #GtkIconView:item-padding property which specifies the padding
5855 * around each of the icon view's items.
5860 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5863 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5865 if (icon_view->priv->item_padding != item_padding)
5867 icon_view->priv->item_padding = item_padding;
5869 if (icon_view->priv->cell_area)
5870 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5872 gtk_icon_view_invalidate_sizes (icon_view);
5874 g_object_notify (G_OBJECT (icon_view), "item-padding");
5879 * gtk_icon_view_get_item_padding:
5880 * @icon_view: a #GtkIconView
5882 * Returns the value of the ::item-padding property.
5884 * Return value: the padding around items
5889 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5891 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5893 return icon_view->priv->item_padding;
5896 /* Get/set whether drag_motion requested the drag data and
5897 * drag_data_received should thus not actually insert the data,
5898 * since the data doesn't result from a drop.
5901 set_status_pending (GdkDragContext *context,
5902 GdkDragAction suggested_action)
5904 g_object_set_data (G_OBJECT (context),
5905 I_("gtk-icon-view-status-pending"),
5906 GINT_TO_POINTER (suggested_action));
5909 static GdkDragAction
5910 get_status_pending (GdkDragContext *context)
5912 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5913 "gtk-icon-view-status-pending"));
5917 unset_reorderable (GtkIconView *icon_view)
5919 if (icon_view->priv->reorderable)
5921 icon_view->priv->reorderable = FALSE;
5922 g_object_notify (G_OBJECT (icon_view), "reorderable");
5927 set_source_row (GdkDragContext *context,
5928 GtkTreeModel *model,
5929 GtkTreePath *source_row)
5932 g_object_set_data_full (G_OBJECT (context),
5933 I_("gtk-icon-view-source-row"),
5934 gtk_tree_row_reference_new (model, source_row),
5935 (GDestroyNotify) gtk_tree_row_reference_free);
5937 g_object_set_data_full (G_OBJECT (context),
5938 I_("gtk-icon-view-source-row"),
5943 get_source_row (GdkDragContext *context)
5945 GtkTreeRowReference *ref;
5947 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5950 return gtk_tree_row_reference_get_path (ref);
5957 GtkTreeRowReference *dest_row;
5958 gboolean empty_view_drop;
5959 gboolean drop_append_mode;
5963 dest_row_free (gpointer data)
5965 DestRow *dr = (DestRow *)data;
5967 gtk_tree_row_reference_free (dr->dest_row);
5972 set_dest_row (GdkDragContext *context,
5973 GtkTreeModel *model,
5974 GtkTreePath *dest_row,
5975 gboolean empty_view_drop,
5976 gboolean drop_append_mode)
5982 g_object_set_data_full (G_OBJECT (context),
5983 I_("gtk-icon-view-dest-row"),
5988 dr = g_new0 (DestRow, 1);
5990 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5991 dr->empty_view_drop = empty_view_drop;
5992 dr->drop_append_mode = drop_append_mode;
5993 g_object_set_data_full (G_OBJECT (context),
5994 I_("gtk-icon-view-dest-row"),
5995 dr, (GDestroyNotify) dest_row_free);
5999 get_dest_row (GdkDragContext *context)
6003 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6007 GtkTreePath *path = NULL;
6010 path = gtk_tree_row_reference_get_path (dr->dest_row);
6011 else if (dr->empty_view_drop)
6012 path = gtk_tree_path_new_from_indices (0, -1);
6016 if (path && dr->drop_append_mode)
6017 gtk_tree_path_next (path);
6026 check_model_dnd (GtkTreeModel *model,
6027 GType required_iface,
6028 const gchar *signal)
6030 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6032 g_warning ("You must override the default '%s' handler "
6033 "on GtkIconView when using models that don't support "
6034 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6035 "is to connect to '%s' and call "
6036 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6037 "the default handler from running. Look at the source code "
6038 "for the default handler in gtkiconview.c to get an idea what "
6039 "your handler should do. (gtkiconview.c is in the GTK+ source "
6040 "code.) If you're using GTK+ from a language other than C, "
6041 "there may be a more natural way to override default handlers, e.g. via derivation.",
6042 signal, g_type_name (required_iface), signal);
6050 remove_scroll_timeout (GtkIconView *icon_view)
6052 if (icon_view->priv->scroll_timeout_id != 0)
6054 g_source_remove (icon_view->priv->scroll_timeout_id);
6056 icon_view->priv->scroll_timeout_id = 0;
6061 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6065 gint px, py, width, height;
6066 gint hoffset, voffset;
6068 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6070 gdk_window_get_device_position (window, device, &px, &py, NULL);
6071 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6073 /* see if we are near the edge. */
6074 voffset = py - 2 * SCROLL_EDGE_SIZE;
6076 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6078 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6080 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6083 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6084 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6087 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6088 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6092 GtkIconView *icon_view;
6097 drag_scroll_timeout (gpointer datap)
6099 DragScrollData *data = datap;
6101 gtk_icon_view_autoscroll (data->icon_view, data->device);
6107 drag_scroll_data_free (DragScrollData *data)
6109 g_slice_free (DragScrollData, data);
6113 set_destination (GtkIconView *icon_view,
6114 GdkDragContext *context,
6117 GdkDragAction *suggested_action,
6121 GtkTreePath *path = NULL;
6122 GtkIconViewDropPosition pos;
6123 GtkIconViewDropPosition old_pos;
6124 GtkTreePath *old_dest_path = NULL;
6125 gboolean can_drop = FALSE;
6127 widget = GTK_WIDGET (icon_view);
6129 *suggested_action = 0;
6132 if (!icon_view->priv->dest_set)
6134 /* someone unset us as a drag dest, note that if
6135 * we return FALSE drag_leave isn't called
6138 gtk_icon_view_set_drag_dest_item (icon_view,
6140 GTK_ICON_VIEW_DROP_LEFT);
6142 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6144 return FALSE; /* no longer a drop site */
6147 *target = gtk_drag_dest_find_target (widget, context,
6148 gtk_drag_dest_get_target_list (widget));
6149 if (*target == GDK_NONE)
6152 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6155 GtkTreeModel *model;
6157 /* the row got dropped on empty space, let's setup a special case
6161 gtk_tree_path_free (path);
6163 model = gtk_icon_view_get_model (icon_view);
6165 n_children = gtk_tree_model_iter_n_children (model, NULL);
6168 pos = GTK_ICON_VIEW_DROP_BELOW;
6169 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6173 pos = GTK_ICON_VIEW_DROP_ABOVE;
6174 path = gtk_tree_path_new_from_indices (0, -1);
6184 gtk_icon_view_get_drag_dest_item (icon_view,
6189 gtk_tree_path_free (old_dest_path);
6191 if (TRUE /* FIXME if the location droppable predicate */)
6199 GtkWidget *source_widget;
6201 *suggested_action = gdk_drag_context_get_suggested_action (context);
6202 source_widget = gtk_drag_get_source_widget (context);
6204 if (source_widget == widget)
6206 /* Default to MOVE, unless the user has
6207 * pressed ctrl or shift to affect available actions
6209 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6210 *suggested_action = GDK_ACTION_MOVE;
6213 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6218 /* can't drop here */
6219 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6221 GTK_ICON_VIEW_DROP_LEFT);
6225 gtk_tree_path_free (path);
6231 get_logical_destination (GtkIconView *icon_view,
6232 gboolean *drop_append_mode)
6234 /* adjust path to point to the row the drop goes in front of */
6235 GtkTreePath *path = NULL;
6236 GtkIconViewDropPosition pos;
6238 *drop_append_mode = FALSE;
6240 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6245 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6246 pos == GTK_ICON_VIEW_DROP_BELOW)
6249 GtkTreeModel *model = icon_view->priv->model;
6251 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6252 !gtk_tree_model_iter_next (model, &iter))
6253 *drop_append_mode = TRUE;
6256 *drop_append_mode = FALSE;
6257 gtk_tree_path_next (path);
6265 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6266 GdkEventMotion *event)
6268 GtkWidget *widget = GTK_WIDGET (icon_view);
6269 GdkDragContext *context;
6270 GtkTreePath *path = NULL;
6272 GtkTreeModel *model;
6273 gboolean retval = FALSE;
6275 if (!icon_view->priv->source_set)
6278 if (icon_view->priv->pressed_button < 0)
6281 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6282 icon_view->priv->press_start_x,
6283 icon_view->priv->press_start_y,
6284 event->x, event->y))
6287 model = gtk_icon_view_get_model (icon_view);
6292 button = icon_view->priv->pressed_button;
6293 icon_view->priv->pressed_button = -1;
6295 path = gtk_icon_view_get_path_at_pos (icon_view,
6296 icon_view->priv->press_start_x,
6297 icon_view->priv->press_start_y);
6302 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6303 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6307 /* FIXME Check whether we're a start button, if not return FALSE and
6311 /* Now we can begin the drag */
6315 context = gtk_drag_begin (widget,
6316 gtk_drag_source_get_target_list (widget),
6317 icon_view->priv->source_actions,
6321 set_source_row (context, model, path);
6325 gtk_tree_path_free (path);
6330 /* Source side drag signals */
6332 gtk_icon_view_drag_begin (GtkWidget *widget,
6333 GdkDragContext *context)
6335 GtkIconView *icon_view;
6336 GtkIconViewItem *item;
6337 cairo_surface_t *icon;
6341 icon_view = GTK_ICON_VIEW (widget);
6343 /* if the user uses a custom DnD impl, we don't set the icon here */
6344 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6347 item = _gtk_icon_view_get_item_at_coords (icon_view,
6348 icon_view->priv->press_start_x,
6349 icon_view->priv->press_start_y,
6353 g_return_if_fail (item != NULL);
6355 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6356 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6358 path = gtk_tree_path_new_from_indices (item->index, -1);
6359 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6360 gtk_tree_path_free (path);
6362 cairo_surface_set_device_offset (icon, -x, -y);
6364 gtk_drag_set_icon_surface (context, icon);
6366 cairo_surface_destroy (icon);
6370 gtk_icon_view_drag_end (GtkWidget *widget,
6371 GdkDragContext *context)
6377 gtk_icon_view_drag_data_get (GtkWidget *widget,
6378 GdkDragContext *context,
6379 GtkSelectionData *selection_data,
6383 GtkIconView *icon_view;
6384 GtkTreeModel *model;
6385 GtkTreePath *source_row;
6387 icon_view = GTK_ICON_VIEW (widget);
6388 model = gtk_icon_view_get_model (icon_view);
6393 if (!icon_view->priv->source_set)
6396 source_row = get_source_row (context);
6398 if (source_row == NULL)
6401 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6402 * any model; for DragSource models there are some other targets
6406 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6407 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6412 /* If drag_data_get does nothing, try providing row data. */
6413 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6414 gtk_tree_set_row_drag_data (selection_data,
6419 gtk_tree_path_free (source_row);
6423 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6424 GdkDragContext *context)
6426 GtkTreeModel *model;
6427 GtkIconView *icon_view;
6428 GtkTreePath *source_row;
6430 icon_view = GTK_ICON_VIEW (widget);
6431 model = gtk_icon_view_get_model (icon_view);
6433 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6436 if (!icon_view->priv->source_set)
6439 source_row = get_source_row (context);
6441 if (source_row == NULL)
6444 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6447 gtk_tree_path_free (source_row);
6449 set_source_row (context, NULL, NULL);
6452 /* Target side drag signals */
6454 gtk_icon_view_drag_leave (GtkWidget *widget,
6455 GdkDragContext *context,
6458 GtkIconView *icon_view;
6460 icon_view = GTK_ICON_VIEW (widget);
6462 /* unset any highlight row */
6463 gtk_icon_view_set_drag_dest_item (icon_view,
6465 GTK_ICON_VIEW_DROP_LEFT);
6467 remove_scroll_timeout (icon_view);
6471 gtk_icon_view_drag_motion (GtkWidget *widget,
6472 GdkDragContext *context,
6477 GtkTreePath *path = NULL;
6478 GtkIconViewDropPosition pos;
6479 GtkIconView *icon_view;
6480 GdkDragAction suggested_action = 0;
6484 icon_view = GTK_ICON_VIEW (widget);
6486 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6489 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6491 /* we only know this *after* set_desination_row */
6492 empty = icon_view->priv->empty_view_drop;
6494 if (path == NULL && !empty)
6496 /* Can't drop here. */
6497 gdk_drag_status (context, 0, time);
6501 if (icon_view->priv->scroll_timeout_id == 0)
6503 DragScrollData *data = g_slice_new (DragScrollData);
6504 data->icon_view = icon_view;
6505 data->device = gdk_drag_context_get_device (context);
6507 icon_view->priv->scroll_timeout_id =
6508 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6511 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6513 /* Request data so we can use the source row when
6514 * determining whether to accept the drop
6516 set_status_pending (context, suggested_action);
6517 gtk_drag_get_data (widget, context, target, time);
6521 set_status_pending (context, 0);
6522 gdk_drag_status (context, suggested_action, time);
6527 gtk_tree_path_free (path);
6533 gtk_icon_view_drag_drop (GtkWidget *widget,
6534 GdkDragContext *context,
6539 GtkIconView *icon_view;
6541 GdkDragAction suggested_action = 0;
6542 GdkAtom target = GDK_NONE;
6543 GtkTreeModel *model;
6544 gboolean drop_append_mode;
6546 icon_view = GTK_ICON_VIEW (widget);
6547 model = gtk_icon_view_get_model (icon_view);
6549 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6551 if (!icon_view->priv->dest_set)
6554 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6557 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6560 path = get_logical_destination (icon_view, &drop_append_mode);
6562 if (target != GDK_NONE && path != NULL)
6564 /* in case a motion had requested drag data, change things so we
6565 * treat drag data receives as a drop.
6567 set_status_pending (context, 0);
6568 set_dest_row (context, model, path,
6569 icon_view->priv->empty_view_drop, drop_append_mode);
6573 gtk_tree_path_free (path);
6575 /* Unset this thing */
6576 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6578 if (target != GDK_NONE)
6580 gtk_drag_get_data (widget, context, target, time);
6588 gtk_icon_view_drag_data_received (GtkWidget *widget,
6589 GdkDragContext *context,
6592 GtkSelectionData *selection_data,
6597 gboolean accepted = FALSE;
6598 GtkTreeModel *model;
6599 GtkIconView *icon_view;
6600 GtkTreePath *dest_row;
6601 GdkDragAction suggested_action;
6602 gboolean drop_append_mode;
6604 icon_view = GTK_ICON_VIEW (widget);
6605 model = gtk_icon_view_get_model (icon_view);
6607 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6610 if (!icon_view->priv->dest_set)
6613 suggested_action = get_status_pending (context);
6615 if (suggested_action)
6617 /* We are getting this data due to a request in drag_motion,
6618 * rather than due to a request in drag_drop, so we are just
6619 * supposed to call drag_status, not actually paste in the
6622 path = get_logical_destination (icon_view, &drop_append_mode);
6625 suggested_action = 0;
6627 if (suggested_action)
6629 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6632 suggested_action = 0;
6635 gdk_drag_status (context, suggested_action, time);
6638 gtk_tree_path_free (path);
6640 /* If you can't drop, remove user drop indicator until the next motion */
6641 if (suggested_action == 0)
6642 gtk_icon_view_set_drag_dest_item (icon_view,
6644 GTK_ICON_VIEW_DROP_LEFT);
6649 dest_row = get_dest_row (context);
6651 if (dest_row == NULL)
6654 if (gtk_selection_data_get_length (selection_data) >= 0)
6656 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6662 gtk_drag_finish (context,
6664 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6667 gtk_tree_path_free (dest_row);
6670 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6673 /* Drag-and-Drop support */
6675 * gtk_icon_view_enable_model_drag_source:
6676 * @icon_view: a #GtkIconTreeView
6677 * @start_button_mask: Mask of allowed buttons to start drag
6678 * @targets: (array length=n_targets): the table of targets that the drag will
6680 * @n_targets: the number of items in @targets
6681 * @actions: the bitmask of possible actions for a drag from this
6684 * Turns @icon_view into a drag source for automatic DND. Calling this
6685 * method sets #GtkIconView:reorderable to %FALSE.
6690 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6691 GdkModifierType start_button_mask,
6692 const GtkTargetEntry *targets,
6694 GdkDragAction actions)
6696 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6698 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6700 icon_view->priv->start_button_mask = start_button_mask;
6701 icon_view->priv->source_actions = actions;
6703 icon_view->priv->source_set = TRUE;
6705 unset_reorderable (icon_view);
6709 * gtk_icon_view_enable_model_drag_dest:
6710 * @icon_view: a #GtkIconView
6711 * @targets: (array length=n_targets): the table of targets that the drag will
6713 * @n_targets: the number of items in @targets
6714 * @actions: the bitmask of possible actions for a drag to this
6717 * Turns @icon_view into a drop destination for automatic DND. Calling this
6718 * method sets #GtkIconView:reorderable to %FALSE.
6723 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6724 const GtkTargetEntry *targets,
6726 GdkDragAction actions)
6728 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6730 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6732 icon_view->priv->dest_actions = actions;
6734 icon_view->priv->dest_set = TRUE;
6736 unset_reorderable (icon_view);
6740 * gtk_icon_view_unset_model_drag_source:
6741 * @icon_view: a #GtkIconView
6743 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6744 * method sets #GtkIconView:reorderable to %FALSE.
6749 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6751 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6753 if (icon_view->priv->source_set)
6755 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6756 icon_view->priv->source_set = FALSE;
6759 unset_reorderable (icon_view);
6763 * gtk_icon_view_unset_model_drag_dest:
6764 * @icon_view: a #GtkIconView
6766 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6767 * method sets #GtkIconView:reorderable to %FALSE.
6772 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6774 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6776 if (icon_view->priv->dest_set)
6778 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6779 icon_view->priv->dest_set = FALSE;
6782 unset_reorderable (icon_view);
6785 /* These are useful to implement your own custom stuff. */
6787 * gtk_icon_view_set_drag_dest_item:
6788 * @icon_view: a #GtkIconView
6789 * @path: (allow-none): The path of the item to highlight, or %NULL.
6790 * @pos: Specifies where to drop, relative to the item
6792 * Sets the item that is highlighted for feedback.
6797 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6799 GtkIconViewDropPosition pos)
6801 /* Note; this function is exported to allow a custom DND
6802 * implementation, so it can't touch TreeViewDragInfo
6805 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6807 if (icon_view->priv->dest_item)
6809 GtkTreePath *current_path;
6810 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6811 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6812 icon_view->priv->dest_item = NULL;
6814 gtk_icon_view_queue_draw_path (icon_view, current_path);
6815 gtk_tree_path_free (current_path);
6818 /* special case a drop on an empty model */
6819 icon_view->priv->empty_view_drop = FALSE;
6820 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6821 && gtk_tree_path_get_depth (path) == 1
6822 && gtk_tree_path_get_indices (path)[0] == 0)
6826 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6829 if (n_children == 0)
6830 icon_view->priv->empty_view_drop = TRUE;
6833 icon_view->priv->dest_pos = pos;
6837 icon_view->priv->dest_item =
6838 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6839 icon_view->priv->model, path);
6841 gtk_icon_view_queue_draw_path (icon_view, path);
6846 * gtk_icon_view_get_drag_dest_item:
6847 * @icon_view: a #GtkIconView
6848 * @path: (out) (allow-none): Return location for the path of
6849 * the highlighted item, or %NULL.
6850 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6852 * Gets information about the item that is highlighted for feedback.
6857 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6859 GtkIconViewDropPosition *pos)
6861 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6865 if (icon_view->priv->dest_item)
6866 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6872 *pos = icon_view->priv->dest_pos;
6876 * gtk_icon_view_get_dest_item_at_pos:
6877 * @icon_view: a #GtkIconView
6878 * @drag_x: the position to determine the destination item for
6879 * @drag_y: the position to determine the destination item for
6880 * @path: (out) (allow-none): Return location for the path of the item,
6882 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6884 * Determines the destination item for a given position.
6886 * Return value: whether there is an item at the given position.
6891 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6895 GtkIconViewDropPosition *pos)
6897 GtkIconViewItem *item;
6899 /* Note; this function is exported to allow a custom DND
6900 * implementation, so it can't touch TreeViewDragInfo
6903 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6904 g_return_val_if_fail (drag_x >= 0, FALSE);
6905 g_return_val_if_fail (drag_y >= 0, FALSE);
6906 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6912 item = _gtk_icon_view_get_item_at_coords (icon_view,
6913 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6914 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6921 *path = gtk_tree_path_new_from_indices (item->index, -1);
6925 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6926 *pos = GTK_ICON_VIEW_DROP_LEFT;
6927 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6928 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6929 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6930 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6931 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6932 *pos = GTK_ICON_VIEW_DROP_BELOW;
6934 *pos = GTK_ICON_VIEW_DROP_INTO;
6941 * gtk_icon_view_create_drag_icon:
6942 * @icon_view: a #GtkIconView
6943 * @path: a #GtkTreePath in @icon_view
6945 * Creates a #cairo_surface_t representation of the item at @path.
6946 * This image is used for a drag icon.
6948 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6953 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6957 GtkStyleContext *context;
6959 cairo_surface_t *surface;
6963 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6964 g_return_val_if_fail (path != NULL, NULL);
6966 widget = GTK_WIDGET (icon_view);
6967 context = gtk_widget_get_style_context (widget);
6969 if (!gtk_widget_get_realized (widget))
6972 index = gtk_tree_path_get_indices (path)[0];
6974 for (l = icon_view->priv->items; l; l = l->next)
6976 GtkIconViewItem *item = l->data;
6978 if (index == item->index)
6980 GdkRectangle rect = {
6981 item->cell_area.x - icon_view->priv->item_padding,
6982 item->cell_area.y - icon_view->priv->item_padding,
6983 item->cell_area.width + icon_view->priv->item_padding * 2,
6984 item->cell_area.height + icon_view->priv->item_padding * 2
6987 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6988 CAIRO_CONTENT_COLOR,
6992 cr = cairo_create (surface);
6993 cairo_set_line_width (cr, 1.);
6995 gtk_render_background (context, cr, 0, 0,
6996 rect.width + 2, rect.height + 2);
7000 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7003 gtk_icon_view_paint_item (icon_view, cr, item,
7004 icon_view->priv->item_padding + 1,
7005 icon_view->priv->item_padding + 1, FALSE);
7009 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7010 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7023 * gtk_icon_view_get_reorderable:
7024 * @icon_view: a #GtkIconView
7026 * Retrieves whether the user can reorder the list via drag-and-drop.
7027 * See gtk_icon_view_set_reorderable().
7029 * Return value: %TRUE if the list can be reordered.
7034 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7036 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7038 return icon_view->priv->reorderable;
7041 static const GtkTargetEntry item_targets[] = {
7042 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7047 * gtk_icon_view_set_reorderable:
7048 * @icon_view: A #GtkIconView.
7049 * @reorderable: %TRUE, if the list of items can be reordered.
7051 * This function is a convenience function to allow you to reorder models that
7052 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7053 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7054 * the user can reorder the model by dragging and dropping rows. The
7055 * developer can listen to these changes by connecting to the model's
7056 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7057 * the icon view as a drag source and destination. Therefore, drag and
7058 * drop can not be used in a reorderable view for any other purpose.
7060 * This function does not give you any degree of control over the order -- any
7061 * reordering is allowed. If more control is needed, you should probably
7062 * handle drag and drop manually.
7067 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7068 gboolean reorderable)
7070 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7072 reorderable = reorderable != FALSE;
7074 if (icon_view->priv->reorderable == reorderable)
7079 gtk_icon_view_enable_model_drag_source (icon_view,
7082 G_N_ELEMENTS (item_targets),
7084 gtk_icon_view_enable_model_drag_dest (icon_view,
7086 G_N_ELEMENTS (item_targets),
7091 gtk_icon_view_unset_model_drag_source (icon_view);
7092 gtk_icon_view_unset_model_drag_dest (icon_view);
7095 icon_view->priv->reorderable = reorderable;
7097 g_object_notify (G_OBJECT (icon_view), "reorderable");
7101 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7102 GtkBuilder *builder,
7104 const gchar *tagname,
7105 GMarkupParser *parser,
7108 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7109 tagname, parser, data))
7112 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7113 tagname, parser, data);
7117 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7118 GtkBuilder *builder,
7120 const gchar *tagname,
7123 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7124 child, tagname, data))
7125 parent_buildable_iface->custom_tag_end (buildable, builder,
7126 child, tagname, data);