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;
976 /* GObject methods */
978 gtk_icon_view_constructor (GType type,
979 guint n_construct_properties,
980 GObjectConstructParam *construct_properties)
982 GtkIconView *icon_view;
985 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
986 (type, n_construct_properties, construct_properties);
988 icon_view = (GtkIconView *) object;
990 gtk_icon_view_ensure_cell_area (icon_view, NULL);
996 gtk_icon_view_dispose (GObject *object)
998 GtkIconView *icon_view;
999 GtkIconViewPrivate *priv;
1001 icon_view = GTK_ICON_VIEW (object);
1002 priv = icon_view->priv;
1004 if (priv->cell_area_context)
1006 g_object_unref (priv->cell_area_context);
1007 priv->cell_area_context = NULL;
1010 if (priv->cell_area)
1012 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1014 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1015 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1016 priv->add_editable_id = 0;
1017 priv->remove_editable_id = 0;
1019 g_object_unref (priv->cell_area);
1020 priv->cell_area = NULL;
1023 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1027 gtk_icon_view_set_property (GObject *object,
1029 const GValue *value,
1032 GtkIconView *icon_view;
1035 icon_view = GTK_ICON_VIEW (object);
1039 case PROP_SELECTION_MODE:
1040 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1042 case PROP_PIXBUF_COLUMN:
1043 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1045 case PROP_TEXT_COLUMN:
1046 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1048 case PROP_MARKUP_COLUMN:
1049 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1052 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1054 case PROP_ITEM_ORIENTATION:
1055 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1058 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1060 case PROP_ITEM_WIDTH:
1061 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1064 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1066 case PROP_ROW_SPACING:
1067 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1069 case PROP_COLUMN_SPACING:
1070 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1073 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1075 case PROP_REORDERABLE:
1076 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1079 case PROP_TOOLTIP_COLUMN:
1080 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1083 case PROP_ITEM_PADDING:
1084 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1087 case PROP_CELL_AREA:
1088 /* Construct-only, can only be assigned once */
1089 area = g_value_get_object (value);
1092 if (icon_view->priv->cell_area != NULL)
1094 g_warning ("cell-area has already been set, ignoring construct property");
1095 g_object_ref_sink (area);
1096 g_object_unref (area);
1099 gtk_icon_view_ensure_cell_area (icon_view, area);
1103 case PROP_HADJUSTMENT:
1104 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1106 case PROP_VADJUSTMENT:
1107 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1109 case PROP_HSCROLL_POLICY:
1110 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1111 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1113 case PROP_VSCROLL_POLICY:
1114 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1115 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1125 gtk_icon_view_get_property (GObject *object,
1130 GtkIconView *icon_view;
1132 icon_view = GTK_ICON_VIEW (object);
1136 case PROP_SELECTION_MODE:
1137 g_value_set_enum (value, icon_view->priv->selection_mode);
1139 case PROP_PIXBUF_COLUMN:
1140 g_value_set_int (value, icon_view->priv->pixbuf_column);
1142 case PROP_TEXT_COLUMN:
1143 g_value_set_int (value, icon_view->priv->text_column);
1145 case PROP_MARKUP_COLUMN:
1146 g_value_set_int (value, icon_view->priv->markup_column);
1149 g_value_set_object (value, icon_view->priv->model);
1151 case PROP_ITEM_ORIENTATION:
1152 g_value_set_enum (value, icon_view->priv->item_orientation);
1155 g_value_set_int (value, icon_view->priv->columns);
1157 case PROP_ITEM_WIDTH:
1158 g_value_set_int (value, icon_view->priv->item_width);
1161 g_value_set_int (value, icon_view->priv->spacing);
1163 case PROP_ROW_SPACING:
1164 g_value_set_int (value, icon_view->priv->row_spacing);
1166 case PROP_COLUMN_SPACING:
1167 g_value_set_int (value, icon_view->priv->column_spacing);
1170 g_value_set_int (value, icon_view->priv->margin);
1172 case PROP_REORDERABLE:
1173 g_value_set_boolean (value, icon_view->priv->reorderable);
1175 case PROP_TOOLTIP_COLUMN:
1176 g_value_set_int (value, icon_view->priv->tooltip_column);
1179 case PROP_ITEM_PADDING:
1180 g_value_set_int (value, icon_view->priv->item_padding);
1183 case PROP_CELL_AREA:
1184 g_value_set_object (value, icon_view->priv->cell_area);
1187 case PROP_HADJUSTMENT:
1188 g_value_set_object (value, icon_view->priv->hadjustment);
1190 case PROP_VADJUSTMENT:
1191 g_value_set_object (value, icon_view->priv->vadjustment);
1193 case PROP_HSCROLL_POLICY:
1194 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1196 case PROP_VSCROLL_POLICY:
1197 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1206 /* GtkWidget methods */
1208 gtk_icon_view_destroy (GtkWidget *widget)
1210 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1212 gtk_icon_view_set_model (icon_view, NULL);
1214 if (icon_view->priv->scroll_to_path != NULL)
1216 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1217 icon_view->priv->scroll_to_path = NULL;
1220 remove_scroll_timeout (icon_view);
1222 if (icon_view->priv->hadjustment != NULL)
1224 g_object_unref (icon_view->priv->hadjustment);
1225 icon_view->priv->hadjustment = NULL;
1228 if (icon_view->priv->vadjustment != NULL)
1230 g_object_unref (icon_view->priv->vadjustment);
1231 icon_view->priv->vadjustment = NULL;
1234 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1238 gtk_icon_view_realize (GtkWidget *widget)
1240 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1241 GtkAllocation allocation;
1243 GdkWindowAttr attributes;
1244 gint attributes_mask;
1245 GtkStyleContext *context;
1247 gtk_widget_set_realized (widget, TRUE);
1249 gtk_widget_get_allocation (widget, &allocation);
1251 /* Make the main, clipping window */
1252 attributes.window_type = GDK_WINDOW_CHILD;
1253 attributes.x = allocation.x;
1254 attributes.y = allocation.y;
1255 attributes.width = allocation.width;
1256 attributes.height = allocation.height;
1257 attributes.wclass = GDK_INPUT_OUTPUT;
1258 attributes.visual = gtk_widget_get_visual (widget);
1259 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1261 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1263 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1264 &attributes, attributes_mask);
1265 gtk_widget_set_window (widget, window);
1266 gdk_window_set_user_data (window, widget);
1268 gtk_widget_get_allocation (widget, &allocation);
1270 /* Make the window for the icon view */
1273 attributes.width = MAX (icon_view->priv->width, allocation.width);
1274 attributes.height = MAX (icon_view->priv->height, allocation.height);
1275 attributes.event_mask = (GDK_EXPOSURE_MASK |
1277 GDK_SMOOTH_SCROLL_MASK |
1278 GDK_POINTER_MOTION_MASK |
1279 GDK_BUTTON_PRESS_MASK |
1280 GDK_BUTTON_RELEASE_MASK |
1281 GDK_KEY_PRESS_MASK |
1282 GDK_KEY_RELEASE_MASK) |
1283 gtk_widget_get_events (widget);
1285 icon_view->priv->bin_window = gdk_window_new (window,
1286 &attributes, attributes_mask);
1287 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1289 context = gtk_widget_get_style_context (widget);
1291 gtk_style_context_save (context);
1292 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1293 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1294 gtk_style_context_set_background (context, window);
1295 gtk_style_context_restore (context);
1297 gdk_window_show (icon_view->priv->bin_window);
1301 gtk_icon_view_unrealize (GtkWidget *widget)
1303 GtkIconView *icon_view;
1305 icon_view = GTK_ICON_VIEW (widget);
1307 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1308 gdk_window_destroy (icon_view->priv->bin_window);
1309 icon_view->priv->bin_window = NULL;
1311 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1315 _gtk_icon_view_update_background (GtkIconView *icon_view)
1317 GtkWidget *widget = GTK_WIDGET (icon_view);
1319 if (gtk_widget_get_realized (widget))
1321 GtkStyleContext *context;
1323 context = gtk_widget_get_style_context (widget);
1325 gtk_style_context_save (context);
1326 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1328 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1329 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1331 gtk_style_context_restore (context);
1336 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1337 GtkStateFlags previous_state)
1339 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1340 gtk_widget_queue_draw (widget);
1344 gtk_icon_view_style_updated (GtkWidget *widget)
1346 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1348 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1349 gtk_widget_queue_resize (widget);
1353 gtk_icon_view_get_n_items (GtkIconView *icon_view)
1355 GtkIconViewPrivate *priv = icon_view->priv;
1357 if (priv->model == NULL)
1360 return gtk_tree_model_iter_n_children (priv->model, NULL);
1364 cell_area_get_preferred_size (GtkIconView *icon_view,
1365 GtkCellAreaContext *context,
1366 GtkOrientation orientation,
1371 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1374 gtk_cell_area_get_preferred_width_for_height (icon_view->priv->cell_area,
1376 GTK_WIDGET (icon_view),
1380 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
1382 GTK_WIDGET (icon_view),
1388 gtk_cell_area_get_preferred_height_for_width (icon_view->priv->cell_area,
1390 GTK_WIDGET (icon_view),
1394 gtk_cell_area_get_preferred_height (icon_view->priv->cell_area,
1396 GTK_WIDGET (icon_view),
1402 gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
1403 GtkOrientation orientation,
1408 GtkIconViewPrivate *priv = icon_view->priv;
1409 GtkCellAreaContext *context;
1412 context = gtk_cell_area_create_context (priv->cell_area);
1414 for_size -= 2 * priv->item_padding;
1418 /* This is necessary for the context to work properly */
1419 for (items = priv->items; items; items = items->next)
1421 GtkIconViewItem *item = items->data;
1423 _gtk_icon_view_set_cell_data (icon_view, item);
1424 cell_area_get_preferred_size (icon_view, context, 1 - orientation, -1, NULL, NULL);
1428 for (items = priv->items; items; items = items->next)
1430 GtkIconViewItem *item = items->data;
1432 _gtk_icon_view_set_cell_data (icon_view, item);
1433 cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
1436 cell_area_get_preferred_size (icon_view, context, orientation, for_size, minimum, natural);
1438 if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->item_width >= 0)
1441 *minimum = MAX (*minimum, priv->item_width);
1443 *natural = *minimum;
1447 *minimum += 2 * priv->item_padding;
1449 *natural += 2 * priv->item_padding;
1451 g_object_unref (context);
1455 gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
1456 GtkOrientation orientation,
1461 GtkIconViewPrivate *priv = icon_view->priv;
1462 int minimum, natural;
1464 if (priv->columns > 0)
1466 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1469 *min_items = priv->columns;
1471 *max_items = priv->columns;
1475 int n_items = gtk_icon_view_get_n_items (icon_view);
1478 *min_items = (n_items + priv->columns - 1) / priv->columns;
1480 *max_items = (n_items + priv->columns - 1) / priv->columns;
1486 size -= 2 * priv->margin;
1488 gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
1490 if (orientation == GTK_ORIENTATION_HORIZONTAL)
1492 size += priv->column_spacing;
1493 minimum += priv->column_spacing;
1494 natural += priv->column_spacing;
1498 size += priv->row_spacing;
1499 minimum += priv->row_spacing;
1500 natural += priv->row_spacing;
1505 if (size <= minimum)
1508 *max_items = size / minimum;
1513 if (size <= natural)
1516 *min_items = size / natural;
1520 static GtkSizeRequestMode
1521 gtk_icon_view_get_request_mode (GtkWidget *widget)
1523 return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
1527 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1531 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1532 GtkIconViewPrivate *priv = icon_view->priv;
1533 int item_min, item_nat;
1535 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_min, &item_nat);
1537 if (priv->columns > 0)
1539 *minimum = item_min * priv->columns + priv->column_spacing * (priv->columns - 1);
1540 *natural = item_nat * priv->columns + priv->column_spacing * (priv->columns - 1);
1544 int n_items = gtk_icon_view_get_n_items (icon_view);
1553 *minimum = item_min;
1554 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1558 *minimum += 2 * priv->margin;
1559 *natural += 2 * priv->margin;
1563 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1568 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1569 GtkIconViewPrivate *priv = icon_view->priv;
1570 int item_min, item_nat, rows, n_items;
1572 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, NULL);
1573 n_items = gtk_icon_view_get_n_items (icon_view);
1575 height = height + priv->row_spacing - 2 * priv->margin;
1577 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, height / rows - priv->row_spacing, &item_min, &item_nat);
1578 *minimum = item_min * ((n_items + rows - 1) / rows);
1579 *natural = item_nat * ((n_items + rows - 1) / rows);
1581 *minimum += 2 * priv->margin;
1582 *natural += 2 * priv->margin;
1586 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1590 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1591 GtkIconViewPrivate *priv = icon_view->priv;
1592 int item_min, item_nat, n_items;
1594 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1595 n_items = gtk_icon_view_get_n_items (icon_view);
1597 if (priv->columns > 0)
1599 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1601 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1602 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1613 *minimum = item_min;
1614 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1618 *minimum += 2 * priv->margin;
1619 *natural += 2 * priv->margin;
1623 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1628 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1629 GtkIconViewPrivate *priv = icon_view->priv;
1630 int item_min, item_nat, columns, n_items;
1632 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, &columns);
1633 n_items = gtk_icon_view_get_n_items (icon_view);
1635 width = width + priv->column_spacing - 2 * priv->margin;
1637 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, width / columns - priv->column_spacing, &item_min, &item_nat);
1638 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1639 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1641 *minimum += 2 * priv->margin;
1642 *natural += 2 * priv->margin;
1646 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1650 for (list = icon_view->priv->children; list; list = list->next)
1652 GtkIconViewChild *child = list->data;
1654 /* totally ignore our child's requisition */
1655 gtk_widget_size_allocate (child->widget, &child->area);
1660 gtk_icon_view_size_allocate (GtkWidget *widget,
1661 GtkAllocation *allocation)
1663 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1665 gtk_widget_set_allocation (widget, allocation);
1667 gtk_icon_view_layout (icon_view);
1669 if (gtk_widget_get_realized (widget))
1671 gdk_window_move_resize (gtk_widget_get_window (widget),
1672 allocation->x, allocation->y,
1673 allocation->width, allocation->height);
1674 gdk_window_resize (icon_view->priv->bin_window,
1675 MAX (icon_view->priv->width, allocation->width),
1676 MAX (icon_view->priv->height, allocation->height));
1679 gtk_icon_view_allocate_children (icon_view);
1681 /* Delay signal emission */
1682 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1683 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1685 gtk_icon_view_set_hadjustment_values (icon_view);
1686 gtk_icon_view_set_vadjustment_values (icon_view);
1688 if (gtk_widget_get_realized (widget) &&
1689 icon_view->priv->scroll_to_path)
1692 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1693 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1694 icon_view->priv->scroll_to_path = NULL;
1696 gtk_icon_view_scroll_to_path (icon_view, path,
1697 icon_view->priv->scroll_to_use_align,
1698 icon_view->priv->scroll_to_row_align,
1699 icon_view->priv->scroll_to_col_align);
1700 gtk_tree_path_free (path);
1703 /* Emit any pending signals now */
1704 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1705 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1709 gtk_icon_view_draw (GtkWidget *widget,
1712 GtkIconView *icon_view;
1716 GtkIconViewDropPosition dest_pos;
1717 GtkIconViewItem *dest_item = NULL;
1719 icon_view = GTK_ICON_VIEW (widget);
1721 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1726 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1728 cairo_set_line_width (cr, 1.);
1730 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1734 dest_index = gtk_tree_path_get_indices (path)[0];
1735 gtk_tree_path_free (path);
1740 for (icons = icon_view->priv->items; icons; icons = icons->next)
1742 GtkIconViewItem *item = icons->data;
1743 GdkRectangle paint_area;
1745 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1746 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1747 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1748 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1752 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1755 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1757 gtk_icon_view_paint_item (icon_view, cr, item,
1758 item->cell_area.x, item->cell_area.y,
1759 icon_view->priv->draw_focus);
1761 if (dest_index == item->index)
1769 dest_pos != GTK_ICON_VIEW_NO_DROP)
1771 GtkStyleContext *context;
1772 GdkRectangle rect = { 0 };
1774 context = gtk_widget_get_style_context (widget);
1778 case GTK_ICON_VIEW_DROP_INTO:
1779 rect = dest_item->cell_area;
1781 case GTK_ICON_VIEW_DROP_ABOVE:
1782 rect.x = dest_item->cell_area.x;
1783 rect.y = dest_item->cell_area.y - 1;
1784 rect.width = dest_item->cell_area.width;
1787 case GTK_ICON_VIEW_DROP_LEFT:
1788 rect.x = dest_item->cell_area.x - 1;
1789 rect.y = dest_item->cell_area.y;
1791 rect.height = dest_item->cell_area.height;
1793 case GTK_ICON_VIEW_DROP_BELOW:
1794 rect.x = dest_item->cell_area.x;
1795 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1796 rect.width = dest_item->cell_area.width;
1799 case GTK_ICON_VIEW_DROP_RIGHT:
1800 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1801 rect.y = dest_item->cell_area.y;
1803 rect.height = dest_item->cell_area.height;
1804 case GTK_ICON_VIEW_NO_DROP: ;
1808 gtk_render_focus (context, cr,
1810 rect.width, rect.height);
1813 if (icon_view->priv->doing_rubberband)
1814 gtk_icon_view_paint_rubberband (icon_view, cr);
1818 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1822 rubberband_scroll_timeout (gpointer data)
1824 GtkIconView *icon_view = data;
1826 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1827 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1828 icon_view->priv->scroll_value_diff);
1830 gtk_icon_view_update_rubberband (icon_view);
1836 gtk_icon_view_motion (GtkWidget *widget,
1837 GdkEventMotion *event)
1839 GtkAllocation allocation;
1840 GtkIconView *icon_view;
1843 icon_view = GTK_ICON_VIEW (widget);
1845 gtk_icon_view_maybe_begin_drag (icon_view, event);
1847 if (icon_view->priv->doing_rubberband)
1849 gtk_icon_view_update_rubberband (widget);
1851 abs_y = event->y - icon_view->priv->height *
1852 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1853 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1854 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1856 gtk_widget_get_allocation (widget, &allocation);
1858 if (abs_y < 0 || abs_y > allocation.height)
1861 icon_view->priv->scroll_value_diff = abs_y;
1863 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1865 icon_view->priv->event_last_x = event->x;
1866 icon_view->priv->event_last_y = event->y;
1868 if (icon_view->priv->scroll_timeout_id == 0)
1869 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1873 remove_scroll_timeout (icon_view);
1877 GtkIconViewItem *item, *last_prelight_item;
1878 GtkCellRenderer *cell = NULL;
1880 last_prelight_item = icon_view->priv->last_prelight;
1881 item = _gtk_icon_view_get_item_at_coords (icon_view,
1888 item->prelight = TRUE;
1889 gtk_icon_view_queue_draw_item (icon_view, item);
1892 if (last_prelight_item != NULL &&
1893 last_prelight_item != item)
1895 last_prelight_item->prelight = FALSE;
1896 gtk_icon_view_queue_draw_item (icon_view,
1897 icon_view->priv->last_prelight);
1900 icon_view->priv->last_prelight = item;
1907 gtk_icon_view_remove (GtkContainer *container,
1910 GtkIconView *icon_view;
1911 GtkIconViewChild *child = NULL;
1914 icon_view = GTK_ICON_VIEW (container);
1916 tmp_list = icon_view->priv->children;
1919 child = tmp_list->data;
1920 if (child->widget == widget)
1922 gtk_widget_unparent (widget);
1924 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1925 g_list_free_1 (tmp_list);
1930 tmp_list = tmp_list->next;
1935 gtk_icon_view_forall (GtkContainer *container,
1936 gboolean include_internals,
1937 GtkCallback callback,
1938 gpointer callback_data)
1940 GtkIconView *icon_view;
1941 GtkIconViewChild *child = NULL;
1944 icon_view = GTK_ICON_VIEW (container);
1946 tmp_list = icon_view->priv->children;
1949 child = tmp_list->data;
1950 tmp_list = tmp_list->next;
1952 (* callback) (child->widget, callback_data);
1957 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1958 GtkIconViewItem *item)
1961 AtkObject *item_obj;
1963 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1966 item_obj = atk_object_ref_accessible_child (obj, item->index);
1967 if (item_obj != NULL)
1969 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1970 g_object_unref (item_obj);
1976 gtk_icon_view_add_editable (GtkCellArea *area,
1977 GtkCellRenderer *renderer,
1978 GtkCellEditable *editable,
1979 GdkRectangle *cell_area,
1981 GtkIconView *icon_view)
1983 GtkIconViewChild *child;
1984 GtkWidget *widget = GTK_WIDGET (editable);
1986 child = g_new (GtkIconViewChild, 1);
1988 child->widget = widget;
1989 child->area.x = cell_area->x;
1990 child->area.y = cell_area->y;
1991 child->area.width = cell_area->width;
1992 child->area.height = cell_area->height;
1994 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1996 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1997 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1999 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
2003 gtk_icon_view_remove_editable (GtkCellArea *area,
2004 GtkCellRenderer *renderer,
2005 GtkCellEditable *editable,
2006 GtkIconView *icon_view)
2010 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
2011 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
2013 gtk_container_remove (GTK_CONTAINER (icon_view),
2014 GTK_WIDGET (editable));
2016 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2017 gtk_icon_view_queue_draw_path (icon_view, path);
2018 gtk_tree_path_free (path);
2022 * gtk_icon_view_set_cursor:
2023 * @icon_view: A #GtkIconView
2024 * @path: A #GtkTreePath
2025 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2026 * @start_editing: %TRUE if the specified cell should start being edited.
2028 * Sets the current keyboard focus to be at @path, and selects it. This is
2029 * useful when you want to focus the user's attention on a particular item.
2030 * If @cell is not %NULL, then focus is given to the cell specified by
2031 * it. Additionally, if @start_editing is %TRUE, then editing should be
2032 * started in the specified cell.
2034 * This function is often followed by <literal>gtk_widget_grab_focus
2035 * (icon_view)</literal> in order to give keyboard focus to the widget.
2036 * Please note that editing can only happen when the widget is realized.
2041 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2043 GtkCellRenderer *cell,
2044 gboolean start_editing)
2046 GtkIconViewItem *item = NULL;
2048 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2049 g_return_if_fail (path != NULL);
2050 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2052 if (icon_view->priv->cell_area)
2053 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2055 if (gtk_tree_path_get_depth (path) == 1)
2056 item = g_list_nth_data (icon_view->priv->items,
2057 gtk_tree_path_get_indices(path)[0]);
2062 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2063 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2065 if (start_editing &&
2066 icon_view->priv->cell_area)
2068 _gtk_icon_view_set_cell_data (icon_view, item);
2069 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2070 gtk_cell_area_activate (icon_view->priv->cell_area,
2071 icon_view->priv->cell_area_context,
2072 GTK_WIDGET (icon_view), &item->cell_area,
2073 0 /* XXX flags */, TRUE);
2078 * gtk_icon_view_get_cursor:
2079 * @icon_view: A #GtkIconView
2080 * @path: (out) (allow-none): Return location for the current cursor path,
2082 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2084 * Fills in @path and @cell with the current cursor path and cell.
2085 * If the cursor isn't currently set, then *@path will be %NULL.
2086 * If no cell currently has focus, then *@cell will be %NULL.
2088 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2090 * Return value: %TRUE if the cursor is set.
2095 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2097 GtkCellRenderer **cell)
2099 GtkIconViewItem *item;
2101 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2103 item = icon_view->priv->cursor_item;
2108 *path = gtk_tree_path_new_from_indices (item->index, -1);
2113 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2114 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2116 return (item != NULL);
2120 gtk_icon_view_button_press (GtkWidget *widget,
2121 GdkEventButton *event)
2123 GtkIconView *icon_view;
2124 GtkIconViewItem *item;
2125 gboolean dirty = FALSE;
2126 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2128 icon_view = GTK_ICON_VIEW (widget);
2130 if (event->window != icon_view->priv->bin_window)
2133 if (!gtk_widget_has_focus (widget))
2134 gtk_widget_grab_focus (widget);
2136 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2138 GdkModifierType extend_mod_mask;
2139 GdkModifierType modify_mod_mask;
2142 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2145 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2147 item = _gtk_icon_view_get_item_at_coords (icon_view,
2153 * We consider only the the cells' area as the item area if the
2154 * item is not selected, but if it *is* selected, the complete
2155 * selection rectangle is considered to be part of the item.
2157 if (item != NULL && (cell != NULL || item->selected))
2161 if (gtk_cell_renderer_is_activatable (cell))
2165 gtk_icon_view_scroll_to_item (icon_view, item);
2167 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2169 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2171 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2172 (event->state & extend_mod_mask))
2174 gtk_icon_view_unselect_all_internal (icon_view);
2176 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2177 if (!icon_view->priv->anchor_item)
2178 icon_view->priv->anchor_item = item;
2180 gtk_icon_view_select_all_between (icon_view,
2181 icon_view->priv->anchor_item,
2187 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2188 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2189 (event->state & modify_mod_mask))
2191 item->selected = !item->selected;
2192 gtk_icon_view_queue_draw_item (icon_view, item);
2197 gtk_icon_view_unselect_all_internal (icon_view);
2199 item->selected = TRUE;
2200 gtk_icon_view_queue_draw_item (icon_view, item);
2203 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2204 icon_view->priv->anchor_item = item;
2207 /* Save press to possibly begin a drag */
2208 if (icon_view->priv->pressed_button < 0)
2210 icon_view->priv->pressed_button = event->button;
2211 icon_view->priv->press_start_x = event->x;
2212 icon_view->priv->press_start_y = event->y;
2215 if (!icon_view->priv->last_single_clicked)
2216 icon_view->priv->last_single_clicked = item;
2218 /* cancel the current editing, if it exists */
2219 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2221 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2223 _gtk_icon_view_set_cell_data (icon_view, item);
2224 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2225 gtk_cell_area_activate (icon_view->priv->cell_area,
2226 icon_view->priv->cell_area_context,
2227 GTK_WIDGET (icon_view),
2228 &item->cell_area, 0/* XXX flags */, FALSE);
2233 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2234 !(event->state & modify_mod_mask))
2236 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2239 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2240 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2243 /* don't draw keyboard focus around an clicked-on item */
2244 icon_view->priv->draw_focus = FALSE;
2247 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
2249 item = _gtk_icon_view_get_item_at_coords (icon_view,
2254 if (item && item == icon_view->priv->last_single_clicked)
2258 path = gtk_tree_path_new_from_indices (item->index, -1);
2259 gtk_icon_view_item_activated (icon_view, path);
2260 gtk_tree_path_free (path);
2263 icon_view->priv->last_single_clicked = NULL;
2264 icon_view->priv->pressed_button = -1;
2268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2270 return event->button == GDK_BUTTON_PRIMARY;
2274 gtk_icon_view_button_release (GtkWidget *widget,
2275 GdkEventButton *event)
2277 GtkIconView *icon_view;
2279 icon_view = GTK_ICON_VIEW (widget);
2281 if (icon_view->priv->pressed_button == event->button)
2282 icon_view->priv->pressed_button = -1;
2284 gtk_icon_view_stop_rubberbanding (icon_view);
2286 remove_scroll_timeout (icon_view);
2292 gtk_icon_view_key_press (GtkWidget *widget,
2295 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2297 if (icon_view->priv->doing_rubberband)
2299 if (event->keyval == GDK_KEY_Escape)
2300 gtk_icon_view_stop_rubberbanding (icon_view);
2305 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2309 gtk_icon_view_key_release (GtkWidget *widget,
2312 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2314 if (icon_view->priv->doing_rubberband)
2317 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2321 gtk_icon_view_update_rubberband (gpointer data)
2323 GtkIconView *icon_view;
2325 GdkRectangle old_area;
2326 GdkRectangle new_area;
2327 GdkRectangle common;
2328 cairo_region_t *invalid_region;
2330 icon_view = GTK_ICON_VIEW (data);
2332 gdk_window_get_device_position (icon_view->priv->bin_window,
2333 icon_view->priv->rubberband_device,
2339 old_area.x = MIN (icon_view->priv->rubberband_x1,
2340 icon_view->priv->rubberband_x2);
2341 old_area.y = MIN (icon_view->priv->rubberband_y1,
2342 icon_view->priv->rubberband_y2);
2343 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2344 icon_view->priv->rubberband_x1) + 1;
2345 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2346 icon_view->priv->rubberband_y1) + 1;
2348 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2349 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2350 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2351 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2353 invalid_region = cairo_region_create_rectangle (&old_area);
2354 cairo_region_union_rectangle (invalid_region, &new_area);
2356 gdk_rectangle_intersect (&old_area, &new_area, &common);
2357 if (common.width > 2 && common.height > 2)
2359 cairo_region_t *common_region;
2361 /* make sure the border is invalidated */
2367 common_region = cairo_region_create_rectangle (&common);
2369 cairo_region_subtract (invalid_region, common_region);
2370 cairo_region_destroy (common_region);
2373 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2375 cairo_region_destroy (invalid_region);
2377 icon_view->priv->rubberband_x2 = x;
2378 icon_view->priv->rubberband_y2 = y;
2380 gtk_icon_view_update_rubberband_selection (icon_view);
2384 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2391 if (icon_view->priv->rubberband_device)
2394 for (items = icon_view->priv->items; items; items = items->next)
2396 GtkIconViewItem *item = items->data;
2398 item->selected_before_rubberbanding = item->selected;
2401 icon_view->priv->rubberband_x1 = x;
2402 icon_view->priv->rubberband_y1 = y;
2403 icon_view->priv->rubberband_x2 = x;
2404 icon_view->priv->rubberband_y2 = y;
2406 icon_view->priv->doing_rubberband = TRUE;
2407 icon_view->priv->rubberband_device = device;
2409 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2413 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2415 if (!icon_view->priv->doing_rubberband)
2418 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2419 icon_view->priv->rubberband_device);
2421 icon_view->priv->doing_rubberband = FALSE;
2422 icon_view->priv->rubberband_device = NULL;
2424 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2428 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2431 gint x, y, width, height;
2432 gboolean dirty = FALSE;
2434 x = MIN (icon_view->priv->rubberband_x1,
2435 icon_view->priv->rubberband_x2);
2436 y = MIN (icon_view->priv->rubberband_y1,
2437 icon_view->priv->rubberband_y2);
2438 width = ABS (icon_view->priv->rubberband_x1 -
2439 icon_view->priv->rubberband_x2);
2440 height = ABS (icon_view->priv->rubberband_y1 -
2441 icon_view->priv->rubberband_y2);
2443 for (items = icon_view->priv->items; items; items = items->next)
2445 GtkIconViewItem *item = items->data;
2449 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2450 x, y, width, height);
2452 selected = is_in ^ item->selected_before_rubberbanding;
2454 if (item->selected != selected)
2456 item->selected = selected;
2458 gtk_icon_view_queue_draw_item (icon_view, item);
2463 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2468 GdkRectangle hit_rect;
2473 hit_test (GtkCellRenderer *renderer,
2474 const GdkRectangle *cell_area,
2475 const GdkRectangle *cell_background,
2478 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2479 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2480 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2481 MAX (data->hit_rect.y, cell_area->y) > 0)
2484 return (data->hit != FALSE);
2488 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2489 GtkIconViewItem *item,
2495 HitTestData data = { { x, y, width, height }, FALSE };
2496 GdkRectangle *item_area = &item->cell_area;
2498 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2499 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2502 _gtk_icon_view_set_cell_data (icon_view, item);
2503 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2504 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area,
2505 icon_view->priv->cell_area_context,
2506 GTK_WIDGET (icon_view),
2507 item_area, item_area,
2508 (GtkCellAllocCallback)hit_test, &data);
2514 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2516 gboolean dirty = FALSE;
2519 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2522 for (items = icon_view->priv->items; items; items = items->next)
2524 GtkIconViewItem *item = items->data;
2528 item->selected = FALSE;
2530 gtk_icon_view_queue_draw_item (icon_view, item);
2531 gtk_icon_view_item_selected_changed (icon_view, item);
2539 /* GtkIconView signals */
2541 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2543 gtk_icon_view_select_all (icon_view);
2547 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2549 gtk_icon_view_unselect_all (icon_view);
2553 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2555 gtk_icon_view_unselect_all (icon_view);
2557 if (icon_view->priv->cursor_item != NULL)
2558 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2562 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2566 if (!icon_view->priv->cursor_item)
2569 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2570 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2571 icon_view->priv->cursor_item->cell_area.width,
2572 icon_view->priv->cursor_item->cell_area.height);
2573 gtk_cell_area_activate (icon_view->priv->cell_area,
2574 icon_view->priv->cell_area_context,
2575 GTK_WIDGET (icon_view),
2576 &icon_view->priv->cursor_item->cell_area,
2580 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2581 gtk_icon_view_item_activated (icon_view, path);
2582 gtk_tree_path_free (path);
2588 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2590 if (!icon_view->priv->cursor_item)
2593 switch (icon_view->priv->selection_mode)
2595 case GTK_SELECTION_NONE:
2597 case GTK_SELECTION_BROWSE:
2598 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2600 case GTK_SELECTION_SINGLE:
2601 if (icon_view->priv->cursor_item->selected)
2602 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2604 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2606 case GTK_SELECTION_MULTIPLE:
2607 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2608 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2610 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2611 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2617 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2619 GtkAllocation allocation;
2620 GtkAdjustment *adj = icon_view->priv->hadjustment;
2621 gdouble old_page_size;
2627 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2629 old_value = gtk_adjustment_get_value (adj);
2630 old_upper = gtk_adjustment_get_upper (adj);
2631 old_page_size = gtk_adjustment_get_page_size (adj);
2632 new_upper = MAX (allocation.width, icon_view->priv->width);
2634 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2636 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2637 /* Quick explanation:
2638 * In LTR locales, leftmost portion of visible rectangle should stay
2639 * fixed, which means left edge of scrollbar thumb should remain fixed
2640 * and thus adjustment's value should stay the same.
2642 * In RTL locales, we want to keep rightmost portion of visible
2643 * rectangle fixed. This means right edge of thumb should remain fixed.
2644 * In this case, upper - value - page_size should remain constant.
2646 new_value = (new_upper - allocation.width) -
2647 (old_upper - old_value - old_page_size);
2648 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2651 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2653 gtk_adjustment_configure (adj,
2657 allocation.width * 0.1,
2658 allocation.width * 0.9,
2663 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2665 GtkAllocation allocation;
2666 GtkAdjustment *adj = icon_view->priv->vadjustment;
2668 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2670 gtk_adjustment_configure (adj,
2671 gtk_adjustment_get_value (adj),
2673 MAX (allocation.height, icon_view->priv->height),
2674 allocation.height * 0.1,
2675 allocation.height * 0.9,
2680 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2681 GtkAdjustment *adjustment)
2683 GtkIconViewPrivate *priv = icon_view->priv;
2685 if (adjustment && priv->hadjustment == adjustment)
2688 if (priv->hadjustment != NULL)
2690 g_signal_handlers_disconnect_matched (priv->hadjustment,
2691 G_SIGNAL_MATCH_DATA,
2692 0, 0, NULL, NULL, icon_view);
2693 g_object_unref (priv->hadjustment);
2697 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2700 g_signal_connect (adjustment, "value-changed",
2701 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2702 priv->hadjustment = g_object_ref_sink (adjustment);
2703 gtk_icon_view_set_hadjustment_values (icon_view);
2705 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2709 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2710 GtkAdjustment *adjustment)
2712 GtkIconViewPrivate *priv = icon_view->priv;
2714 if (adjustment && priv->vadjustment == adjustment)
2717 if (priv->vadjustment != NULL)
2719 g_signal_handlers_disconnect_matched (priv->vadjustment,
2720 G_SIGNAL_MATCH_DATA,
2721 0, 0, NULL, NULL, icon_view);
2722 g_object_unref (priv->vadjustment);
2726 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2729 g_signal_connect (adjustment, "value-changed",
2730 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2731 priv->vadjustment = g_object_ref_sink (adjustment);
2732 gtk_icon_view_set_vadjustment_values (icon_view);
2734 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2738 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2739 GtkIconView *icon_view)
2741 GtkIconViewPrivate *priv = icon_view->priv;
2743 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2745 gdk_window_move (priv->bin_window,
2746 - gtk_adjustment_get_value (priv->hadjustment),
2747 - gtk_adjustment_get_value (priv->vadjustment));
2749 if (icon_view->priv->doing_rubberband)
2750 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2752 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2757 adjust_wrap_width (GtkIconView *icon_view)
2759 if (icon_view->priv->text_cell)
2761 gint wrap_width = 50;
2763 /* Here we go with the same old guess, try the icon size and set double
2764 * the size of the first icon found in the list, naive but works much
2766 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2768 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2769 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2770 GTK_WIDGET (icon_view),
2773 wrap_width = MAX (wrap_width * 2, 50);
2776 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2777 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2782 compare_sizes (gconstpointer p1,
2786 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2787 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2791 gtk_icon_view_layout (GtkIconView *icon_view)
2793 GtkIconViewPrivate *priv = icon_view->priv;
2794 GtkWidget *widget = GTK_WIDGET (icon_view);
2796 gint min_item_width, max_item_width; /* These include item_padding */
2797 gint item_width; /* this doesn't include item_padding */
2798 gint n_columns, n_rows, n_items;
2800 GtkRequestedSize *sizes;
2802 n_items = gtk_icon_view_get_n_items (icon_view);
2804 /* Update the wrap width for the text cell before going and requesting sizes */
2806 adjust_wrap_width (icon_view);
2808 gtk_icon_view_compute_n_items_for_size (icon_view,
2809 GTK_ORIENTATION_HORIZONTAL,
2810 gtk_widget_get_allocated_width (widget),
2813 n_rows = (n_items + n_columns - 1) / n_columns;
2815 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &min_item_width, &max_item_width);
2819 /* We might need vertical scrolling here */
2820 int min_width = min_item_width + 2 * priv->margin;
2821 priv->width = MAX (min_width, gtk_widget_get_allocated_width (widget));
2825 priv->width = gtk_widget_get_allocated_width (widget);
2828 item_width = (priv->width - 2 * priv->margin + priv->column_spacing) / n_columns;
2829 item_width -= priv->column_spacing;
2830 item_width = MIN (item_width, max_item_width);
2831 item_width -= 2 * priv->item_padding;
2833 gtk_cell_area_context_reset (priv->cell_area_context);
2834 gtk_cell_area_context_allocate (priv->cell_area_context, item_width, -1);
2835 /* because layouting is complicated. We designed an API
2836 * that is O(N²) and nonsensical.
2837 * And we're proud of it. */
2838 for (items = priv->items; items; items = items->next)
2840 _gtk_icon_view_set_cell_data (icon_view, items->data);
2841 gtk_cell_area_get_preferred_width (priv->cell_area,
2842 priv->cell_area_context,
2847 sizes = g_newa (GtkRequestedSize, n_rows);
2848 items = priv->items;
2849 priv->height = priv->margin;
2851 /* Collect the heights for all rows */
2852 for (row = 0; row < n_rows; row++)
2854 for (col = 0; col < n_columns && items; col++, items = items->next)
2856 GtkIconViewItem *item = items->data;
2858 _gtk_icon_view_set_cell_data (icon_view, item);
2859 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2860 priv->cell_area_context,
2866 sizes[row].data = GINT_TO_POINTER (row);
2867 gtk_cell_area_context_get_preferred_height_for_width (priv->cell_area_context,
2869 &sizes[row].minimum_size,
2870 &sizes[row].natural_size);
2871 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2874 priv->height -= priv->row_spacing;
2875 priv->height += priv->margin;
2876 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2878 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2882 /* Actually allocate the rows */
2883 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2885 items = priv->items;
2886 priv->height = priv->margin;
2888 for (row = 0; row < n_rows; row++)
2890 priv->height += priv->item_padding;
2892 for (col = 0; col < n_columns && items; col++, items = items->next)
2894 GtkIconViewItem *item = items->data;
2896 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2897 item->cell_area.width = item_width;
2898 item->cell_area.y = priv->height;
2899 item->cell_area.height = sizes[row].minimum_size;
2904 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
2907 priv->height -= priv->row_spacing;
2908 priv->height += priv->margin;
2909 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
2913 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2915 /* Clear all item sizes */
2916 g_list_foreach (icon_view->priv->items,
2917 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2919 /* Re-layout the items */
2920 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
2924 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2926 item->cell_area.width = -1;
2927 item->cell_area.height = -1;
2931 gtk_icon_view_paint_item (GtkIconView *icon_view,
2933 GtkIconViewItem *item,
2936 gboolean draw_focus)
2938 GdkRectangle cell_area;
2939 GtkStateFlags state = 0;
2940 GtkCellRendererState flags = 0;
2941 GtkStyleContext *style_context;
2942 GtkWidget *widget = GTK_WIDGET (icon_view);
2943 GtkIconViewPrivate *priv = icon_view->priv;
2945 if (priv->model == NULL)
2948 _gtk_icon_view_set_cell_data (icon_view, item);
2950 style_context = gtk_widget_get_style_context (widget);
2951 state = gtk_widget_get_state_flags (widget);
2953 gtk_style_context_save (style_context);
2954 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2955 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2957 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2961 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2962 item == icon_view->priv->cursor_item)
2964 flags |= GTK_CELL_RENDERER_FOCUSED;
2967 state |= GTK_STATE_FLAG_SELECTED;
2968 flags |= GTK_CELL_RENDERER_SELECTED;
2973 state |= GTK_STATE_FLAG_PRELIGHT;
2974 flags |= GTK_CELL_RENDERER_PRELIT;
2977 gtk_style_context_set_state (style_context, state);
2981 gtk_render_background (style_context, cr,
2982 x - icon_view->priv->item_padding,
2983 y - icon_view->priv->item_padding,
2984 item->cell_area.width + icon_view->priv->item_padding * 2,
2985 item->cell_area.height + icon_view->priv->item_padding * 2);
2986 gtk_render_frame (style_context, cr,
2987 x - icon_view->priv->item_padding,
2988 y - icon_view->priv->item_padding,
2989 item->cell_area.width + icon_view->priv->item_padding * 2,
2990 item->cell_area.height + icon_view->priv->item_padding * 2);
2995 cell_area.width = item->cell_area.width;
2996 cell_area.height = item->cell_area.height;
2998 gtk_cell_area_context_allocate (priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2999 gtk_cell_area_render (priv->cell_area, priv->cell_area_context,
3000 widget, cr, &cell_area, &cell_area, flags,
3003 gtk_style_context_restore (style_context);
3007 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3010 GtkStyleContext *context;
3015 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3016 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3017 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3018 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3020 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3022 gtk_style_context_save (context);
3023 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3025 gdk_cairo_rectangle (cr, &rect);
3028 gtk_render_background (context, cr,
3030 rect.width, rect.height);
3031 gtk_render_frame (context, cr,
3033 rect.width, rect.height);
3035 gtk_style_context_restore (context);
3040 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3046 index = gtk_tree_path_get_indices (path)[0];
3048 for (l = icon_view->priv->items; l; l = l->next)
3050 GtkIconViewItem *item = l->data;
3052 if (item->index == index)
3054 gtk_icon_view_queue_draw_item (icon_view, item);
3061 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3062 GtkIconViewItem *item)
3065 GdkRectangle *item_area = &item->cell_area;
3067 rect.x = item_area->x - icon_view->priv->item_padding;
3068 rect.y = item_area->y - icon_view->priv->item_padding;
3069 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3070 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3072 if (icon_view->priv->bin_window)
3073 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3077 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3078 GtkIconViewItem *item,
3079 GtkCellRenderer *cursor_cell)
3082 AtkObject *item_obj;
3083 AtkObject *cursor_item_obj;
3085 /* When hitting this path from keynav, the focus cell is
3086 * already set, we dont need to notify the atk object
3087 * but we still need to queue the draw here (in the case
3088 * that the focus cell changes but not the cursor item).
3090 gtk_icon_view_queue_draw_item (icon_view, item);
3092 if (icon_view->priv->cursor_item == item &&
3093 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3096 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3097 if (icon_view->priv->cursor_item != NULL)
3099 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3102 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3103 if (cursor_item_obj != NULL)
3104 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3107 icon_view->priv->cursor_item = item;
3110 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3113 /* Make sure there is a cell in focus initially */
3114 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3115 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3118 /* Notify that accessible focus object has changed */
3119 item_obj = atk_object_ref_accessible_child (obj, item->index);
3121 if (item_obj != NULL)
3123 atk_focus_tracker_notify (item_obj);
3124 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3125 g_object_unref (item_obj);
3130 static GtkIconViewItem *
3131 gtk_icon_view_item_new (void)
3133 GtkIconViewItem *item;
3135 item = g_slice_new0 (GtkIconViewItem);
3137 item->cell_area.width = -1;
3138 item->cell_area.height = -1;
3144 gtk_icon_view_item_free (GtkIconViewItem *item)
3146 g_return_if_fail (item != NULL);
3148 g_slice_free (GtkIconViewItem, item);
3152 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3155 gboolean only_in_cell,
3156 GtkCellRenderer **cell_at_pos)
3161 *cell_at_pos = NULL;
3163 for (items = icon_view->priv->items; items; items = items->next)
3165 GtkIconViewItem *item = items->data;
3166 GdkRectangle *item_area = &item->cell_area;
3168 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3169 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3170 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3171 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3173 if (only_in_cell || cell_at_pos)
3175 GtkCellRenderer *cell = NULL;
3177 _gtk_icon_view_set_cell_data (icon_view, item);
3179 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3180 y >= item_area->y && y <= item_area->y + item_area->height)
3182 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
3183 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area,
3184 icon_view->priv->cell_area_context,
3185 GTK_WIDGET (icon_view),
3191 *cell_at_pos = cell;
3194 return cell != NULL ? item : NULL;
3205 _gtk_icon_view_select_item (GtkIconView *icon_view,
3206 GtkIconViewItem *item)
3208 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3209 g_return_if_fail (item != NULL);
3214 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3216 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3217 gtk_icon_view_unselect_all_internal (icon_view);
3219 item->selected = TRUE;
3221 gtk_icon_view_item_selected_changed (icon_view, item);
3222 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3224 gtk_icon_view_queue_draw_item (icon_view, item);
3229 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3230 GtkIconViewItem *item)
3232 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3233 g_return_if_fail (item != NULL);
3235 if (!item->selected)
3238 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3239 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3242 item->selected = FALSE;
3244 gtk_icon_view_item_selected_changed (icon_view, item);
3245 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3247 gtk_icon_view_queue_draw_item (icon_view, item);
3251 verify_items (GtkIconView *icon_view)
3256 for (items = icon_view->priv->items; items; items = items->next)
3258 GtkIconViewItem *item = items->data;
3260 if (item->index != i)
3261 g_error ("List item does not match its index: "
3262 "item index %d and list index %d\n", item->index, i);
3269 gtk_icon_view_row_changed (GtkTreeModel *model,
3274 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3276 /* ignore changes in branches */
3277 if (gtk_tree_path_get_depth (path) > 1)
3280 /* An icon view subclass might add it's own model and populate
3281 * things at init() time instead of waiting for the constructor()
3284 if (icon_view->priv->cell_area)
3285 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3287 /* Here we can use a "grow-only" strategy for optimization
3288 * and only invalidate a single item and queue a relayout
3289 * instead of invalidating the whole thing.
3291 * For now GtkIconView still cant deal with huge models
3292 * so just invalidate the whole thing when the model
3295 gtk_icon_view_invalidate_sizes (icon_view);
3297 verify_items (icon_view);
3301 gtk_icon_view_row_inserted (GtkTreeModel *model,
3306 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3308 GtkIconViewItem *item;
3311 /* ignore changes in branches */
3312 if (gtk_tree_path_get_depth (path) > 1)
3315 index = gtk_tree_path_get_indices(path)[0];
3317 item = gtk_icon_view_item_new ();
3319 item->index = index;
3321 /* FIXME: We can be more efficient here,
3322 we can store a tail pointer and use that when
3323 appending (which is a rather common operation)
3325 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3328 list = g_list_nth (icon_view->priv->items, index + 1);
3329 for (; list; list = list->next)
3336 verify_items (icon_view);
3338 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3342 gtk_icon_view_row_deleted (GtkTreeModel *model,
3346 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3348 GtkIconViewItem *item;
3350 gboolean emit = FALSE;
3352 /* ignore changes in branches */
3353 if (gtk_tree_path_get_depth (path) > 1)
3356 index = gtk_tree_path_get_indices(path)[0];
3358 list = g_list_nth (icon_view->priv->items, index);
3361 if (icon_view->priv->cell_area)
3362 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3364 if (item == icon_view->priv->anchor_item)
3365 icon_view->priv->anchor_item = NULL;
3367 if (item == icon_view->priv->cursor_item)
3368 icon_view->priv->cursor_item = NULL;
3370 if (item == icon_view->priv->last_prelight)
3371 icon_view->priv->last_prelight = NULL;
3376 gtk_icon_view_item_free (item);
3378 for (next = list->next; next; next = next->next)
3385 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3387 verify_items (icon_view);
3389 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3392 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3396 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3397 GtkTreePath *parent,
3402 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3405 GList *items = NULL, *list;
3406 GtkIconViewItem **item_array;
3409 /* ignore changes in branches */
3413 if (icon_view->priv->cell_area)
3414 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3416 length = gtk_tree_model_iter_n_children (model, NULL);
3418 order = g_new (gint, length);
3419 for (i = 0; i < length; i++)
3420 order [new_order[i]] = i;
3422 item_array = g_new (GtkIconViewItem *, length);
3423 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3424 item_array[order[i]] = list->data;
3427 for (i = length - 1; i >= 0; i--)
3429 item_array[i]->index = i;
3430 items = g_list_prepend (items, item_array[i]);
3433 g_free (item_array);
3434 g_list_free (icon_view->priv->items);
3435 icon_view->priv->items = items;
3437 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3439 verify_items (icon_view);
3443 gtk_icon_view_build_items (GtkIconView *icon_view)
3447 GList *items = NULL;
3449 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3457 GtkIconViewItem *item = gtk_icon_view_item_new ();
3463 items = g_list_prepend (items, item);
3465 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3467 icon_view->priv->items = g_list_reverse (items);
3471 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3474 GtkMovementStep step,
3478 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3479 I_("move-cursor"), 2,
3483 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3488 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3491 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3496 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3503 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3504 GtkMovementStep step,
3507 GdkModifierType state;
3509 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3510 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3511 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3512 step == GTK_MOVEMENT_DISPLAY_LINES ||
3513 step == GTK_MOVEMENT_PAGES ||
3514 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3516 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3519 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3520 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3522 if (gtk_get_current_event_state (&state))
3524 GdkModifierType extend_mod_mask;
3525 GdkModifierType modify_mod_mask;
3528 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3529 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3531 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3532 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3534 if ((state & modify_mod_mask) == modify_mod_mask)
3535 icon_view->priv->modify_selection_pressed = TRUE;
3536 if ((state & extend_mod_mask) == extend_mod_mask)
3537 icon_view->priv->extend_selection_pressed = TRUE;
3539 /* else we assume not pressed */
3543 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3544 case GTK_MOVEMENT_VISUAL_POSITIONS:
3545 gtk_icon_view_move_cursor_left_right (icon_view, count);
3547 case GTK_MOVEMENT_DISPLAY_LINES:
3548 gtk_icon_view_move_cursor_up_down (icon_view, count);
3550 case GTK_MOVEMENT_PAGES:
3551 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3553 case GTK_MOVEMENT_BUFFER_ENDS:
3554 gtk_icon_view_move_cursor_start_end (icon_view, count);
3557 g_assert_not_reached ();
3560 icon_view->priv->modify_selection_pressed = FALSE;
3561 icon_view->priv->extend_selection_pressed = FALSE;
3563 icon_view->priv->draw_focus = TRUE;
3568 static GtkIconViewItem *
3569 find_item (GtkIconView *icon_view,
3570 GtkIconViewItem *current,
3576 GtkIconViewItem *item;
3578 /* FIXME: this could be more efficient
3580 row = current->row + row_ofs;
3581 col = current->col + col_ofs;
3583 for (items = icon_view->priv->items; items; items = items->next)
3586 if (item->row == row && item->col == col)
3593 static GtkIconViewItem *
3594 find_item_page_up_down (GtkIconView *icon_view,
3595 GtkIconViewItem *current,
3602 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3604 item = g_list_find (icon_view->priv->items, current);
3609 for (next = item->next; next; next = next->next)
3611 if (((GtkIconViewItem *)next->data)->col == col)
3614 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3624 for (next = item->prev; next; next = next->prev)
3626 if (((GtkIconViewItem *)next->data)->col == col)
3629 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3643 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3644 GtkIconViewItem *anchor,
3645 GtkIconViewItem *cursor)
3648 GtkIconViewItem *item;
3649 gint row1, row2, col1, col2;
3650 gboolean dirty = FALSE;
3652 if (anchor->row < cursor->row)
3663 if (anchor->col < cursor->col)
3674 for (items = icon_view->priv->items; items; items = items->next)
3678 if (row1 <= item->row && item->row <= row2 &&
3679 col1 <= item->col && item->col <= col2)
3681 if (!item->selected)
3684 item->selected = TRUE;
3685 gtk_icon_view_item_selected_changed (icon_view, item);
3687 gtk_icon_view_queue_draw_item (icon_view, item);
3695 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3698 GtkIconViewItem *item;
3699 GtkCellRenderer *cell = NULL;
3700 gboolean dirty = FALSE;
3702 GtkDirectionType direction;
3704 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3707 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3709 if (!icon_view->priv->cursor_item)
3714 list = icon_view->priv->items;
3716 list = g_list_last (icon_view->priv->items);
3722 /* Give focus to the first cell initially */
3723 _gtk_icon_view_set_cell_data (icon_view, item);
3724 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3733 item = icon_view->priv->cursor_item;
3734 step = count > 0 ? 1 : -1;
3736 /* Save the current focus cell in case we hit the edge */
3737 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3741 _gtk_icon_view_set_cell_data (icon_view, item);
3743 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3746 item = find_item (icon_view, item, step, 0);
3752 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3754 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3756 gtk_widget_child_focus (toplevel,
3757 direction == GTK_DIR_UP ?
3758 GTK_DIR_TAB_BACKWARD :
3759 GTK_DIR_TAB_FORWARD);
3763 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3767 if (icon_view->priv->modify_selection_pressed ||
3768 !icon_view->priv->extend_selection_pressed ||
3769 !icon_view->priv->anchor_item ||
3770 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3771 icon_view->priv->anchor_item = item;
3773 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3774 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3776 if (!icon_view->priv->modify_selection_pressed &&
3777 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3779 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3780 dirty = gtk_icon_view_select_all_between (icon_view,
3781 icon_view->priv->anchor_item,
3785 gtk_icon_view_scroll_to_item (icon_view, item);
3788 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3792 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3795 GtkIconViewItem *item;
3796 gboolean dirty = FALSE;
3798 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3801 if (!icon_view->priv->cursor_item)
3806 list = icon_view->priv->items;
3808 list = g_list_last (icon_view->priv->items);
3810 item = list ? list->data : NULL;
3813 item = find_item_page_up_down (icon_view,
3814 icon_view->priv->cursor_item,
3817 if (item == icon_view->priv->cursor_item)
3818 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3823 if (icon_view->priv->modify_selection_pressed ||
3824 !icon_view->priv->extend_selection_pressed ||
3825 !icon_view->priv->anchor_item ||
3826 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3827 icon_view->priv->anchor_item = item;
3829 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3831 if (!icon_view->priv->modify_selection_pressed &&
3832 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3834 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3835 dirty = gtk_icon_view_select_all_between (icon_view,
3836 icon_view->priv->anchor_item,
3840 gtk_icon_view_scroll_to_item (icon_view, item);
3843 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3847 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3850 GtkIconViewItem *item;
3851 GtkCellRenderer *cell = NULL;
3852 gboolean dirty = FALSE;
3854 GtkDirectionType direction;
3856 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3859 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3861 if (!icon_view->priv->cursor_item)
3866 list = icon_view->priv->items;
3868 list = g_list_last (icon_view->priv->items);
3874 /* Give focus to the first cell initially */
3875 _gtk_icon_view_set_cell_data (icon_view, item);
3876 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3885 item = icon_view->priv->cursor_item;
3886 step = count > 0 ? 1 : -1;
3888 /* Save the current focus cell in case we hit the edge */
3889 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3893 _gtk_icon_view_set_cell_data (icon_view, item);
3895 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3898 item = find_item (icon_view, item, 0, step);
3904 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3906 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3908 gtk_widget_child_focus (toplevel,
3909 direction == GTK_DIR_LEFT ?
3910 GTK_DIR_TAB_BACKWARD :
3911 GTK_DIR_TAB_FORWARD);
3915 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3919 if (icon_view->priv->modify_selection_pressed ||
3920 !icon_view->priv->extend_selection_pressed ||
3921 !icon_view->priv->anchor_item ||
3922 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3923 icon_view->priv->anchor_item = item;
3925 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3926 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3928 if (!icon_view->priv->modify_selection_pressed &&
3929 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3931 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3932 dirty = gtk_icon_view_select_all_between (icon_view,
3933 icon_view->priv->anchor_item,
3937 gtk_icon_view_scroll_to_item (icon_view, item);
3940 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3944 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3947 GtkIconViewItem *item;
3949 gboolean dirty = FALSE;
3951 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3955 list = icon_view->priv->items;
3957 list = g_list_last (icon_view->priv->items);
3959 item = list ? list->data : NULL;
3961 if (item == icon_view->priv->cursor_item)
3962 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3967 if (icon_view->priv->modify_selection_pressed ||
3968 !icon_view->priv->extend_selection_pressed ||
3969 !icon_view->priv->anchor_item ||
3970 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3971 icon_view->priv->anchor_item = item;
3973 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3975 if (!icon_view->priv->modify_selection_pressed &&
3976 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3978 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3979 dirty = gtk_icon_view_select_all_between (icon_view,
3980 icon_view->priv->anchor_item,
3984 gtk_icon_view_scroll_to_item (icon_view, item);
3987 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3991 * gtk_icon_view_scroll_to_path:
3992 * @icon_view: A #GtkIconView.
3993 * @path: The path of the item to move to.
3994 * @use_align: whether to use alignment arguments, or %FALSE.
3995 * @row_align: The vertical alignment of the item specified by @path.
3996 * @col_align: The horizontal alignment of the item specified by @path.
3998 * Moves the alignments of @icon_view to the position specified by @path.
3999 * @row_align determines where the row is placed, and @col_align determines
4000 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4001 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4004 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4005 * tree does the minimum amount of work to scroll the item onto the screen.
4006 * This means that the item will be scrolled to the edge closest to its current
4007 * position. If the item is currently visible on the screen, nothing is done.
4009 * This function only works if the model is set, and @path is a valid row on
4010 * the model. If the model changes before the @icon_view is realized, the
4011 * centered path will be modified to reflect this change.
4016 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4022 GtkIconViewItem *item = NULL;
4025 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4026 g_return_if_fail (path != NULL);
4027 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4028 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4030 widget = GTK_WIDGET (icon_view);
4032 if (gtk_tree_path_get_depth (path) > 0)
4033 item = g_list_nth_data (icon_view->priv->items,
4034 gtk_tree_path_get_indices(path)[0]);
4036 if (!item || item->cell_area.width < 0 ||
4037 !gtk_widget_get_realized (widget))
4039 if (icon_view->priv->scroll_to_path)
4040 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4042 icon_view->priv->scroll_to_path = NULL;
4045 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4047 icon_view->priv->scroll_to_use_align = use_align;
4048 icon_view->priv->scroll_to_row_align = row_align;
4049 icon_view->priv->scroll_to_col_align = col_align;
4056 GtkAllocation allocation;
4059 GdkRectangle item_area =
4061 item->cell_area.x - icon_view->priv->item_padding,
4062 item->cell_area.y - icon_view->priv->item_padding,
4063 item->cell_area.width + icon_view->priv->item_padding * 2,
4064 item->cell_area.height + icon_view->priv->item_padding * 2
4067 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4069 gtk_widget_get_allocation (widget, &allocation);
4071 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4073 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4074 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4076 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4078 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4079 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4081 gtk_adjustment_changed (icon_view->priv->hadjustment);
4082 gtk_adjustment_changed (icon_view->priv->vadjustment);
4085 gtk_icon_view_scroll_to_item (icon_view, item);
4090 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4091 GtkIconViewItem *item)
4093 GtkIconViewPrivate *priv = icon_view->priv;
4094 GtkWidget *widget = GTK_WIDGET (icon_view);
4095 GtkAdjustment *hadj, *vadj;
4096 GtkAllocation allocation;
4098 GdkRectangle item_area;
4100 item_area.x = item->cell_area.x - priv->item_padding;
4101 item_area.y = item->cell_area.y - priv->item_padding;
4102 item_area.width = item->cell_area.width + priv->item_padding * 2;
4103 item_area.height = item->cell_area.height + priv->item_padding * 2;
4105 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4106 gtk_widget_get_allocation (widget, &allocation);
4108 hadj = icon_view->priv->hadjustment;
4109 vadj = icon_view->priv->vadjustment;
4111 if (y + item_area.y < 0)
4112 gtk_adjustment_set_value (vadj,
4113 gtk_adjustment_get_value (vadj)
4115 else if (y + item_area.y + item_area.height > allocation.height)
4116 gtk_adjustment_set_value (vadj,
4117 gtk_adjustment_get_value (vadj)
4118 + y + item_area.y + item_area.height - allocation.height);
4120 if (x + item_area.x < 0)
4121 gtk_adjustment_set_value (hadj,
4122 gtk_adjustment_get_value (hadj)
4124 else if (x + item_area.x + item_area.width > allocation.width)
4125 gtk_adjustment_set_value (hadj,
4126 gtk_adjustment_get_value (hadj)
4127 + x + item_area.x + item_area.width - allocation.width);
4129 gtk_adjustment_changed (hadj);
4130 gtk_adjustment_changed (vadj);
4133 /* GtkCellLayout implementation */
4136 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4137 GtkCellArea *cell_area)
4139 GtkIconViewPrivate *priv = icon_view->priv;
4141 if (priv->cell_area)
4145 priv->cell_area = cell_area;
4147 priv->cell_area = gtk_cell_area_box_new ();
4149 g_object_ref_sink (priv->cell_area);
4151 if (GTK_IS_ORIENTABLE (priv->cell_area))
4152 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4154 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4156 priv->add_editable_id =
4157 g_signal_connect (priv->cell_area, "add-editable",
4158 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4159 priv->remove_editable_id =
4160 g_signal_connect (priv->cell_area, "remove-editable",
4161 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4163 update_text_cell (icon_view);
4164 update_pixbuf_cell (icon_view);
4167 static GtkCellArea *
4168 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4170 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4171 GtkIconViewPrivate *priv = icon_view->priv;
4173 if (G_UNLIKELY (!priv->cell_area))
4174 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4176 return icon_view->priv->cell_area;
4180 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4181 GtkIconViewItem *item)
4186 path = gtk_tree_path_new_from_indices (item->index, -1);
4187 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4189 gtk_tree_path_free (path);
4191 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4192 icon_view->priv->model,
4193 &iter, FALSE, FALSE);
4202 * gtk_icon_view_new:
4204 * Creates a new #GtkIconView widget
4206 * Return value: A newly created #GtkIconView widget
4211 gtk_icon_view_new (void)
4213 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4217 * gtk_icon_view_new_with_area:
4218 * @area: the #GtkCellArea to use to layout cells
4220 * Creates a new #GtkIconView widget using the
4221 * specified @area to layout cells inside the icons.
4223 * Return value: A newly created #GtkIconView widget
4228 gtk_icon_view_new_with_area (GtkCellArea *area)
4230 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4234 * gtk_icon_view_new_with_model:
4235 * @model: The model.
4237 * Creates a new #GtkIconView widget with the model @model.
4239 * Return value: A newly created #GtkIconView widget.
4244 gtk_icon_view_new_with_model (GtkTreeModel *model)
4246 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4250 * gtk_icon_view_convert_widget_to_bin_window_coords:
4251 * @icon_view: a #GtkIconView
4252 * @wx: X coordinate relative to the widget
4253 * @wy: Y coordinate relative to the widget
4254 * @bx: (out): return location for bin_window X coordinate
4255 * @by: (out): return location for bin_window Y coordinate
4257 * Converts widget coordinates to coordinates for the bin_window,
4258 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4263 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4271 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4273 if (icon_view->priv->bin_window)
4274 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4285 * gtk_icon_view_get_path_at_pos:
4286 * @icon_view: A #GtkIconView.
4287 * @x: The x position to be identified
4288 * @y: The y position to be identified
4290 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4291 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4292 * the cell at the specified position.
4293 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4294 * widget coordinates to bin_window coordinates.
4296 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4297 * if no icon exists at that position.
4302 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4306 GtkIconViewItem *item;
4309 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4311 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4316 path = gtk_tree_path_new_from_indices (item->index, -1);
4322 * gtk_icon_view_get_item_at_pos:
4323 * @icon_view: A #GtkIconView.
4324 * @x: The x position to be identified
4325 * @y: The y position to be identified
4326 * @path: (out) (allow-none): Return location for the path, or %NULL
4327 * @cell: (out) (allow-none): Return location for the renderer
4328 * responsible for the cell at (@x, @y), or %NULL
4330 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4331 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4332 * obtains the cell at the specified position. The returned path should
4333 * be freed with gtk_tree_path_free().
4334 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4335 * widget coordinates to bin_window coordinates.
4337 * Return value: %TRUE if an item exists at the specified position
4342 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4346 GtkCellRenderer **cell)
4348 GtkIconViewItem *item;
4349 GtkCellRenderer *renderer = NULL;
4351 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4353 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4358 *path = gtk_tree_path_new_from_indices (item->index, -1);
4366 return (item != NULL);
4370 * gtk_icon_view_set_tooltip_item:
4371 * @icon_view: a #GtkIconView
4372 * @tooltip: a #GtkTooltip
4373 * @path: a #GtkTreePath
4375 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4376 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4377 * See also gtk_tooltip_set_tip_area().
4382 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4383 GtkTooltip *tooltip,
4386 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4387 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4389 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4393 * gtk_icon_view_set_tooltip_cell:
4394 * @icon_view: a #GtkIconView
4395 * @tooltip: a #GtkTooltip
4396 * @path: a #GtkTreePath
4397 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4399 * Sets the tip area of @tooltip to the area which @cell occupies in
4400 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4402 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4407 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4408 GtkTooltip *tooltip,
4410 GtkCellRenderer *cell)
4413 GtkIconViewItem *item = NULL;
4416 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4417 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4418 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4420 if (gtk_tree_path_get_depth (path) > 0)
4421 item = g_list_nth_data (icon_view->priv->items,
4422 gtk_tree_path_get_indices(path)[0]);
4429 _gtk_icon_view_set_cell_data (icon_view, item);
4430 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
4431 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area,
4432 icon_view->priv->cell_area_context,
4433 GTK_WIDGET (icon_view),
4434 cell, &item->cell_area, &rect);
4438 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4439 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4440 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4441 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4444 if (icon_view->priv->bin_window)
4446 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4451 gtk_tooltip_set_tip_area (tooltip, &rect);
4456 * gtk_icon_view_get_tooltip_context:
4457 * @icon_view: an #GtkIconView
4458 * @x: (inout): the x coordinate (relative to widget coordinates)
4459 * @y: (inout): the y coordinate (relative to widget coordinates)
4460 * @keyboard_tip: whether this is a keyboard tooltip or not
4461 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4462 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4463 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4465 * This function is supposed to be used in a #GtkWidget::query-tooltip
4466 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4467 * which are received in the signal handler, should be passed to this
4468 * function without modification.
4470 * The return value indicates whether there is an icon view item at the given
4471 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4472 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4473 * @model, @path and @iter which have been provided will be set to point to
4474 * that row and the corresponding model. @x and @y will always be converted
4475 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4477 * Return value: whether or not the given tooltip context points to a item
4482 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4485 gboolean keyboard_tip,
4486 GtkTreeModel **model,
4490 GtkTreePath *tmppath = NULL;
4492 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4493 g_return_val_if_fail (x != NULL, FALSE);
4494 g_return_val_if_fail (y != NULL, FALSE);
4498 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4505 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4508 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4513 *model = gtk_icon_view_get_model (icon_view);
4516 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4522 gtk_tree_path_free (tmppath);
4528 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4531 gboolean keyboard_tip,
4532 GtkTooltip *tooltip,
4538 GtkTreeModel *model;
4539 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4541 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4544 &model, &path, &iter))
4547 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4551 gtk_tree_path_free (path);
4555 gtk_tooltip_set_markup (tooltip, str);
4556 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4558 gtk_tree_path_free (path);
4566 * gtk_icon_view_set_tooltip_column:
4567 * @icon_view: a #GtkIconView
4568 * @column: an integer, which is a valid column number for @icon_view's model
4570 * If you only plan to have simple (text-only) tooltips on full items, you
4571 * can use this function to have #GtkIconView handle these automatically
4572 * for you. @column should be set to the column in @icon_view's model
4573 * containing the tooltip texts, or -1 to disable this feature.
4575 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4576 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4578 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4579 * so &, <, etc have to be escaped in the text.
4584 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4587 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4589 if (column == icon_view->priv->tooltip_column)
4594 g_signal_handlers_disconnect_by_func (icon_view,
4595 gtk_icon_view_set_tooltip_query_cb,
4597 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4601 if (icon_view->priv->tooltip_column == -1)
4603 g_signal_connect (icon_view, "query-tooltip",
4604 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4605 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4609 icon_view->priv->tooltip_column = column;
4610 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4614 * gtk_icon_view_get_tooltip_column:
4615 * @icon_view: a #GtkIconView
4617 * Returns the column of @icon_view's model which is being used for
4618 * displaying tooltips on @icon_view's rows.
4620 * Return value: the index of the tooltip column that is currently being
4621 * used, or -1 if this is disabled.
4626 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4628 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4630 return icon_view->priv->tooltip_column;
4634 * gtk_icon_view_get_visible_range:
4635 * @icon_view: A #GtkIconView
4636 * @start_path: (out) (allow-none): Return location for start of region,
4638 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4640 * Sets @start_path and @end_path to be the first and last visible path.
4641 * Note that there may be invisible paths in between.
4643 * Both paths should be freed with gtk_tree_path_free() after use.
4645 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4650 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4651 GtkTreePath **start_path,
4652 GtkTreePath **end_path)
4654 gint start_index = -1;
4655 gint end_index = -1;
4658 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4660 if (icon_view->priv->hadjustment == NULL ||
4661 icon_view->priv->vadjustment == NULL)
4664 if (start_path == NULL && end_path == NULL)
4667 for (icons = icon_view->priv->items; icons; icons = icons->next)
4669 GtkIconViewItem *item = icons->data;
4670 GdkRectangle *item_area = &item->cell_area;
4672 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4673 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4675 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4676 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4678 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4679 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4681 if (start_index == -1)
4682 start_index = item->index;
4683 end_index = item->index;
4687 if (start_path && start_index != -1)
4688 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4689 if (end_path && end_index != -1)
4690 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4692 return start_index != -1;
4696 * gtk_icon_view_selected_foreach:
4697 * @icon_view: A #GtkIconView.
4698 * @func: (scope call): The function to call for each selected icon.
4699 * @data: User data to pass to the function.
4701 * Calls a function for each selected icon. Note that the model or
4702 * selection cannot be modified from within this function.
4707 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4708 GtkIconViewForeachFunc func,
4713 for (list = icon_view->priv->items; list; list = list->next)
4715 GtkIconViewItem *item = list->data;
4716 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4719 (* func) (icon_view, path, data);
4721 gtk_tree_path_free (path);
4726 * gtk_icon_view_set_selection_mode:
4727 * @icon_view: A #GtkIconView.
4728 * @mode: The selection mode
4730 * Sets the selection mode of the @icon_view.
4735 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4736 GtkSelectionMode mode)
4738 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4740 if (mode == icon_view->priv->selection_mode)
4743 if (mode == GTK_SELECTION_NONE ||
4744 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4745 gtk_icon_view_unselect_all (icon_view);
4747 icon_view->priv->selection_mode = mode;
4749 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4753 * gtk_icon_view_get_selection_mode:
4754 * @icon_view: A #GtkIconView.
4756 * Gets the selection mode of the @icon_view.
4758 * Return value: the current selection mode
4763 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4765 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4767 return icon_view->priv->selection_mode;
4771 * gtk_icon_view_set_model:
4772 * @icon_view: A #GtkIconView.
4773 * @model: (allow-none): The model.
4775 * Sets the model for a #GtkIconView.
4776 * If the @icon_view already has a model set, it will remove
4777 * it before setting the new model. If @model is %NULL, then
4778 * it will unset the old model.
4783 gtk_icon_view_set_model (GtkIconView *icon_view,
4784 GtkTreeModel *model)
4786 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4787 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4789 if (icon_view->priv->model == model)
4792 if (icon_view->priv->scroll_to_path)
4794 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4795 icon_view->priv->scroll_to_path = NULL;
4798 /* The area can be NULL while disposing */
4799 if (icon_view->priv->cell_area)
4800 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4806 if (icon_view->priv->pixbuf_column != -1)
4808 column_type = gtk_tree_model_get_column_type (model,
4809 icon_view->priv->pixbuf_column);
4811 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4814 if (icon_view->priv->text_column != -1)
4816 column_type = gtk_tree_model_get_column_type (model,
4817 icon_view->priv->text_column);
4819 g_return_if_fail (column_type == G_TYPE_STRING);
4822 if (icon_view->priv->markup_column != -1)
4824 column_type = gtk_tree_model_get_column_type (model,
4825 icon_view->priv->markup_column);
4827 g_return_if_fail (column_type == G_TYPE_STRING);
4832 if (icon_view->priv->model)
4834 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4835 gtk_icon_view_row_changed,
4837 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4838 gtk_icon_view_row_inserted,
4840 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4841 gtk_icon_view_row_deleted,
4843 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4844 gtk_icon_view_rows_reordered,
4847 g_object_unref (icon_view->priv->model);
4849 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4850 icon_view->priv->items = NULL;
4851 icon_view->priv->anchor_item = NULL;
4852 icon_view->priv->cursor_item = NULL;
4853 icon_view->priv->last_single_clicked = NULL;
4854 icon_view->priv->last_prelight = NULL;
4855 icon_view->priv->width = 0;
4856 icon_view->priv->height = 0;
4859 icon_view->priv->model = model;
4861 if (icon_view->priv->model)
4863 g_object_ref (icon_view->priv->model);
4864 g_signal_connect (icon_view->priv->model,
4866 G_CALLBACK (gtk_icon_view_row_changed),
4868 g_signal_connect (icon_view->priv->model,
4870 G_CALLBACK (gtk_icon_view_row_inserted),
4872 g_signal_connect (icon_view->priv->model,
4874 G_CALLBACK (gtk_icon_view_row_deleted),
4876 g_signal_connect (icon_view->priv->model,
4878 G_CALLBACK (gtk_icon_view_rows_reordered),
4881 gtk_icon_view_build_items (icon_view);
4884 g_object_notify (G_OBJECT (icon_view), "model");
4886 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4890 * gtk_icon_view_get_model:
4891 * @icon_view: a #GtkIconView
4893 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4896 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4897 * currently being used.
4902 gtk_icon_view_get_model (GtkIconView *icon_view)
4904 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4906 return icon_view->priv->model;
4910 update_text_cell (GtkIconView *icon_view)
4912 if (!icon_view->priv->cell_area)
4915 if (icon_view->priv->text_column == -1 &&
4916 icon_view->priv->markup_column == -1)
4918 if (icon_view->priv->text_cell != NULL)
4920 gtk_cell_area_remove (icon_view->priv->cell_area,
4921 icon_view->priv->text_cell);
4922 icon_view->priv->text_cell = NULL;
4927 if (icon_view->priv->text_cell == NULL)
4929 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4931 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4934 if (icon_view->priv->markup_column != -1)
4935 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4936 icon_view->priv->text_cell,
4937 "markup", icon_view->priv->markup_column,
4940 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4941 icon_view->priv->text_cell,
4942 "text", icon_view->priv->text_column,
4945 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4946 g_object_set (icon_view->priv->text_cell,
4947 "alignment", PANGO_ALIGN_CENTER,
4948 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4953 g_object_set (icon_view->priv->text_cell,
4954 "alignment", PANGO_ALIGN_LEFT,
4955 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4963 update_pixbuf_cell (GtkIconView *icon_view)
4965 if (!icon_view->priv->cell_area)
4968 if (icon_view->priv->pixbuf_column == -1)
4970 if (icon_view->priv->pixbuf_cell != NULL)
4972 gtk_cell_area_remove (icon_view->priv->cell_area,
4973 icon_view->priv->pixbuf_cell);
4975 icon_view->priv->pixbuf_cell = NULL;
4980 if (icon_view->priv->pixbuf_cell == NULL)
4982 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4984 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4987 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4988 icon_view->priv->pixbuf_cell,
4989 "pixbuf", icon_view->priv->pixbuf_column,
4992 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4993 g_object_set (icon_view->priv->pixbuf_cell,
4998 g_object_set (icon_view->priv->pixbuf_cell,
5006 * gtk_icon_view_set_text_column:
5007 * @icon_view: A #GtkIconView.
5008 * @column: A column in the currently used model, or -1 to display no text
5010 * Sets the column with text for @icon_view to be @column. The text
5011 * column must be of type #G_TYPE_STRING.
5016 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5019 if (column == icon_view->priv->text_column)
5023 icon_view->priv->text_column = -1;
5026 if (icon_view->priv->model != NULL)
5030 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5032 g_return_if_fail (column_type == G_TYPE_STRING);
5035 icon_view->priv->text_column = column;
5038 if (icon_view->priv->cell_area)
5039 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5041 update_text_cell (icon_view);
5043 gtk_icon_view_invalidate_sizes (icon_view);
5045 g_object_notify (G_OBJECT (icon_view), "text-column");
5049 * gtk_icon_view_get_text_column:
5050 * @icon_view: A #GtkIconView.
5052 * Returns the column with text for @icon_view.
5054 * Returns: the text column, or -1 if it's unset.
5059 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5061 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5063 return icon_view->priv->text_column;
5067 * gtk_icon_view_set_markup_column:
5068 * @icon_view: A #GtkIconView.
5069 * @column: A column in the currently used model, or -1 to display no text
5071 * Sets the column with markup information for @icon_view to be
5072 * @column. The markup column must be of type #G_TYPE_STRING.
5073 * If the markup column is set to something, it overrides
5074 * the text column set by gtk_icon_view_set_text_column().
5079 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5082 if (column == icon_view->priv->markup_column)
5086 icon_view->priv->markup_column = -1;
5089 if (icon_view->priv->model != NULL)
5093 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5095 g_return_if_fail (column_type == G_TYPE_STRING);
5098 icon_view->priv->markup_column = column;
5101 if (icon_view->priv->cell_area)
5102 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5104 update_text_cell (icon_view);
5106 gtk_icon_view_invalidate_sizes (icon_view);
5108 g_object_notify (G_OBJECT (icon_view), "markup-column");
5112 * gtk_icon_view_get_markup_column:
5113 * @icon_view: A #GtkIconView.
5115 * Returns the column with markup text for @icon_view.
5117 * Returns: the markup column, or -1 if it's unset.
5122 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5124 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5126 return icon_view->priv->markup_column;
5130 * gtk_icon_view_set_pixbuf_column:
5131 * @icon_view: A #GtkIconView.
5132 * @column: A column in the currently used model, or -1 to disable
5134 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5135 * column must be of type #GDK_TYPE_PIXBUF
5140 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5143 if (column == icon_view->priv->pixbuf_column)
5147 icon_view->priv->pixbuf_column = -1;
5150 if (icon_view->priv->model != NULL)
5154 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5156 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5159 icon_view->priv->pixbuf_column = column;
5162 if (icon_view->priv->cell_area)
5163 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5165 update_pixbuf_cell (icon_view);
5167 gtk_icon_view_invalidate_sizes (icon_view);
5169 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5174 * gtk_icon_view_get_pixbuf_column:
5175 * @icon_view: A #GtkIconView.
5177 * Returns the column with pixbufs for @icon_view.
5179 * Returns: the pixbuf column, or -1 if it's unset.
5184 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5186 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5188 return icon_view->priv->pixbuf_column;
5192 * gtk_icon_view_select_path:
5193 * @icon_view: A #GtkIconView.
5194 * @path: The #GtkTreePath to be selected.
5196 * Selects the row at @path.
5201 gtk_icon_view_select_path (GtkIconView *icon_view,
5204 GtkIconViewItem *item = NULL;
5206 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5207 g_return_if_fail (icon_view->priv->model != NULL);
5208 g_return_if_fail (path != NULL);
5210 if (gtk_tree_path_get_depth (path) > 0)
5211 item = g_list_nth_data (icon_view->priv->items,
5212 gtk_tree_path_get_indices(path)[0]);
5215 _gtk_icon_view_select_item (icon_view, item);
5219 * gtk_icon_view_unselect_path:
5220 * @icon_view: A #GtkIconView.
5221 * @path: The #GtkTreePath to be unselected.
5223 * Unselects the row at @path.
5228 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5231 GtkIconViewItem *item;
5233 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5234 g_return_if_fail (icon_view->priv->model != NULL);
5235 g_return_if_fail (path != NULL);
5237 item = g_list_nth_data (icon_view->priv->items,
5238 gtk_tree_path_get_indices(path)[0]);
5243 _gtk_icon_view_unselect_item (icon_view, item);
5247 * gtk_icon_view_get_selected_items:
5248 * @icon_view: A #GtkIconView.
5250 * Creates a list of paths of all selected items. Additionally, if you are
5251 * planning on modifying the model after calling this function, you may
5252 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5253 * To do this, you can use gtk_tree_row_reference_new().
5255 * To free the return value, use:
5257 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5260 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5265 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5268 GList *selected = NULL;
5270 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5272 for (list = icon_view->priv->items; list != NULL; list = list->next)
5274 GtkIconViewItem *item = list->data;
5278 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5280 selected = g_list_prepend (selected, path);
5288 * gtk_icon_view_select_all:
5289 * @icon_view: A #GtkIconView.
5291 * Selects all the icons. @icon_view must has its selection mode set
5292 * to #GTK_SELECTION_MULTIPLE.
5297 gtk_icon_view_select_all (GtkIconView *icon_view)
5300 gboolean dirty = FALSE;
5302 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5304 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5307 for (items = icon_view->priv->items; items; items = items->next)
5309 GtkIconViewItem *item = items->data;
5311 if (!item->selected)
5314 item->selected = TRUE;
5315 gtk_icon_view_queue_draw_item (icon_view, item);
5320 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5324 * gtk_icon_view_unselect_all:
5325 * @icon_view: A #GtkIconView.
5327 * Unselects all the icons.
5332 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5334 gboolean dirty = FALSE;
5336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5338 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5341 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5344 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5348 * gtk_icon_view_path_is_selected:
5349 * @icon_view: A #GtkIconView.
5350 * @path: A #GtkTreePath to check selection on.
5352 * Returns %TRUE if the icon pointed to by @path is currently
5353 * selected. If @path does not point to a valid location, %FALSE is returned.
5355 * Return value: %TRUE if @path is selected.
5360 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5363 GtkIconViewItem *item;
5365 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5366 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5367 g_return_val_if_fail (path != NULL, FALSE);
5369 item = g_list_nth_data (icon_view->priv->items,
5370 gtk_tree_path_get_indices(path)[0]);
5375 return item->selected;
5379 * gtk_icon_view_get_item_row:
5380 * @icon_view: a #GtkIconView
5381 * @path: the #GtkTreePath of the item
5383 * Gets the row in which the item @path is currently
5384 * displayed. Row numbers start at 0.
5386 * Returns: The row in which the item is displayed
5391 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5394 GtkIconViewItem *item;
5396 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5397 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5398 g_return_val_if_fail (path != NULL, -1);
5400 item = g_list_nth_data (icon_view->priv->items,
5401 gtk_tree_path_get_indices(path)[0]);
5410 * gtk_icon_view_get_item_column:
5411 * @icon_view: a #GtkIconView
5412 * @path: the #GtkTreePath of the item
5414 * Gets the column in which the item @path is currently
5415 * displayed. Column numbers start at 0.
5417 * Returns: The column in which the item is displayed
5422 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5425 GtkIconViewItem *item;
5427 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5428 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5429 g_return_val_if_fail (path != NULL, -1);
5431 item = g_list_nth_data (icon_view->priv->items,
5432 gtk_tree_path_get_indices(path)[0]);
5441 * gtk_icon_view_item_activated:
5442 * @icon_view: A #GtkIconView
5443 * @path: The #GtkTreePath to be activated
5445 * Activates the item determined by @path.
5450 gtk_icon_view_item_activated (GtkIconView *icon_view,
5453 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5454 g_return_if_fail (path != NULL);
5456 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5460 * gtk_icon_view_set_item_orientation:
5461 * @icon_view: a #GtkIconView
5462 * @orientation: the relative position of texts and icons
5464 * Sets the ::item-orientation property which determines whether the labels
5465 * are drawn beside the icons instead of below.
5470 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5471 GtkOrientation orientation)
5473 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5475 if (icon_view->priv->item_orientation != orientation)
5477 icon_view->priv->item_orientation = orientation;
5479 if (icon_view->priv->cell_area)
5481 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5482 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5483 icon_view->priv->item_orientation);
5485 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5488 gtk_icon_view_invalidate_sizes (icon_view);
5490 update_text_cell (icon_view);
5491 update_pixbuf_cell (icon_view);
5493 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5498 * gtk_icon_view_get_item_orientation:
5499 * @icon_view: a #GtkIconView
5501 * Returns the value of the ::item-orientation property which determines
5502 * whether the labels are drawn beside the icons instead of below.
5504 * Return value: the relative position of texts and icons
5509 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5511 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5512 GTK_ORIENTATION_VERTICAL);
5514 return icon_view->priv->item_orientation;
5518 * gtk_icon_view_set_columns:
5519 * @icon_view: a #GtkIconView
5520 * @columns: the number of columns
5522 * Sets the ::columns property which determines in how
5523 * many columns the icons are arranged. If @columns is
5524 * -1, the number of columns will be chosen automatically
5525 * to fill the available area.
5530 gtk_icon_view_set_columns (GtkIconView *icon_view,
5533 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5535 if (icon_view->priv->columns != columns)
5537 icon_view->priv->columns = columns;
5539 if (icon_view->priv->cell_area)
5540 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5542 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5544 g_object_notify (G_OBJECT (icon_view), "columns");
5549 * gtk_icon_view_get_columns:
5550 * @icon_view: a #GtkIconView
5552 * Returns the value of the ::columns property.
5554 * Return value: the number of columns, or -1
5559 gtk_icon_view_get_columns (GtkIconView *icon_view)
5561 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5563 return icon_view->priv->columns;
5567 * gtk_icon_view_set_item_width:
5568 * @icon_view: a #GtkIconView
5569 * @item_width: the width for each item
5571 * Sets the ::item-width property which specifies the width
5572 * to use for each item. If it is set to -1, the icon view will
5573 * automatically determine a suitable item size.
5578 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5581 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5583 if (icon_view->priv->item_width != item_width)
5585 icon_view->priv->item_width = item_width;
5587 if (icon_view->priv->cell_area)
5588 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5590 gtk_icon_view_invalidate_sizes (icon_view);
5592 update_text_cell (icon_view);
5594 g_object_notify (G_OBJECT (icon_view), "item-width");
5599 * gtk_icon_view_get_item_width:
5600 * @icon_view: a #GtkIconView
5602 * Returns the value of the ::item-width property.
5604 * Return value: the width of a single item, or -1
5609 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5611 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5613 return icon_view->priv->item_width;
5618 * gtk_icon_view_set_spacing:
5619 * @icon_view: a #GtkIconView
5620 * @spacing: the spacing
5622 * Sets the ::spacing property which specifies the space
5623 * which is inserted between the cells (i.e. the icon and
5624 * the text) of an item.
5629 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5632 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5634 if (icon_view->priv->spacing != spacing)
5636 icon_view->priv->spacing = spacing;
5638 if (icon_view->priv->cell_area)
5639 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5641 gtk_icon_view_invalidate_sizes (icon_view);
5643 g_object_notify (G_OBJECT (icon_view), "spacing");
5648 * gtk_icon_view_get_spacing:
5649 * @icon_view: a #GtkIconView
5651 * Returns the value of the ::spacing property.
5653 * Return value: the space between cells
5658 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5660 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5662 return icon_view->priv->spacing;
5666 * gtk_icon_view_set_row_spacing:
5667 * @icon_view: a #GtkIconView
5668 * @row_spacing: the row spacing
5670 * Sets the ::row-spacing property which specifies the space
5671 * which is inserted between the rows of the icon view.
5676 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5681 if (icon_view->priv->row_spacing != row_spacing)
5683 icon_view->priv->row_spacing = row_spacing;
5685 if (icon_view->priv->cell_area)
5686 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5688 gtk_icon_view_invalidate_sizes (icon_view);
5690 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5695 * gtk_icon_view_get_row_spacing:
5696 * @icon_view: a #GtkIconView
5698 * Returns the value of the ::row-spacing property.
5700 * Return value: the space between rows
5705 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5707 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5709 return icon_view->priv->row_spacing;
5713 * gtk_icon_view_set_column_spacing:
5714 * @icon_view: a #GtkIconView
5715 * @column_spacing: the column spacing
5717 * Sets the ::column-spacing property which specifies the space
5718 * which is inserted between the columns of the icon view.
5723 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5724 gint column_spacing)
5726 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5728 if (icon_view->priv->column_spacing != column_spacing)
5730 icon_view->priv->column_spacing = column_spacing;
5732 if (icon_view->priv->cell_area)
5733 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5735 gtk_icon_view_invalidate_sizes (icon_view);
5737 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5742 * gtk_icon_view_get_column_spacing:
5743 * @icon_view: a #GtkIconView
5745 * Returns the value of the ::column-spacing property.
5747 * Return value: the space between columns
5752 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5754 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5756 return icon_view->priv->column_spacing;
5760 * gtk_icon_view_set_margin:
5761 * @icon_view: a #GtkIconView
5762 * @margin: the margin
5764 * Sets the ::margin property which specifies the space
5765 * which is inserted at the top, bottom, left and right
5771 gtk_icon_view_set_margin (GtkIconView *icon_view,
5774 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5776 if (icon_view->priv->margin != margin)
5778 icon_view->priv->margin = margin;
5780 if (icon_view->priv->cell_area)
5781 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5783 gtk_icon_view_invalidate_sizes (icon_view);
5785 g_object_notify (G_OBJECT (icon_view), "margin");
5790 * gtk_icon_view_get_margin:
5791 * @icon_view: a #GtkIconView
5793 * Returns the value of the ::margin property.
5795 * Return value: the space at the borders
5800 gtk_icon_view_get_margin (GtkIconView *icon_view)
5802 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5804 return icon_view->priv->margin;
5808 * gtk_icon_view_set_item_padding:
5809 * @icon_view: a #GtkIconView
5810 * @item_padding: the item padding
5812 * Sets the #GtkIconView:item-padding property which specifies the padding
5813 * around each of the icon view's items.
5818 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5821 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5823 if (icon_view->priv->item_padding != item_padding)
5825 icon_view->priv->item_padding = item_padding;
5827 if (icon_view->priv->cell_area)
5828 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5830 gtk_icon_view_invalidate_sizes (icon_view);
5832 g_object_notify (G_OBJECT (icon_view), "item-padding");
5837 * gtk_icon_view_get_item_padding:
5838 * @icon_view: a #GtkIconView
5840 * Returns the value of the ::item-padding property.
5842 * Return value: the padding around items
5847 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5851 return icon_view->priv->item_padding;
5854 /* Get/set whether drag_motion requested the drag data and
5855 * drag_data_received should thus not actually insert the data,
5856 * since the data doesn't result from a drop.
5859 set_status_pending (GdkDragContext *context,
5860 GdkDragAction suggested_action)
5862 g_object_set_data (G_OBJECT (context),
5863 I_("gtk-icon-view-status-pending"),
5864 GINT_TO_POINTER (suggested_action));
5867 static GdkDragAction
5868 get_status_pending (GdkDragContext *context)
5870 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5871 "gtk-icon-view-status-pending"));
5875 unset_reorderable (GtkIconView *icon_view)
5877 if (icon_view->priv->reorderable)
5879 icon_view->priv->reorderable = FALSE;
5880 g_object_notify (G_OBJECT (icon_view), "reorderable");
5885 set_source_row (GdkDragContext *context,
5886 GtkTreeModel *model,
5887 GtkTreePath *source_row)
5890 g_object_set_data_full (G_OBJECT (context),
5891 I_("gtk-icon-view-source-row"),
5892 gtk_tree_row_reference_new (model, source_row),
5893 (GDestroyNotify) gtk_tree_row_reference_free);
5895 g_object_set_data_full (G_OBJECT (context),
5896 I_("gtk-icon-view-source-row"),
5901 get_source_row (GdkDragContext *context)
5903 GtkTreeRowReference *ref;
5905 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5908 return gtk_tree_row_reference_get_path (ref);
5915 GtkTreeRowReference *dest_row;
5916 gboolean empty_view_drop;
5917 gboolean drop_append_mode;
5921 dest_row_free (gpointer data)
5923 DestRow *dr = (DestRow *)data;
5925 gtk_tree_row_reference_free (dr->dest_row);
5930 set_dest_row (GdkDragContext *context,
5931 GtkTreeModel *model,
5932 GtkTreePath *dest_row,
5933 gboolean empty_view_drop,
5934 gboolean drop_append_mode)
5940 g_object_set_data_full (G_OBJECT (context),
5941 I_("gtk-icon-view-dest-row"),
5946 dr = g_new0 (DestRow, 1);
5948 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5949 dr->empty_view_drop = empty_view_drop;
5950 dr->drop_append_mode = drop_append_mode;
5951 g_object_set_data_full (G_OBJECT (context),
5952 I_("gtk-icon-view-dest-row"),
5953 dr, (GDestroyNotify) dest_row_free);
5957 get_dest_row (GdkDragContext *context)
5961 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5965 GtkTreePath *path = NULL;
5968 path = gtk_tree_row_reference_get_path (dr->dest_row);
5969 else if (dr->empty_view_drop)
5970 path = gtk_tree_path_new_from_indices (0, -1);
5974 if (path && dr->drop_append_mode)
5975 gtk_tree_path_next (path);
5984 check_model_dnd (GtkTreeModel *model,
5985 GType required_iface,
5986 const gchar *signal)
5988 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5990 g_warning ("You must override the default '%s' handler "
5991 "on GtkIconView when using models that don't support "
5992 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5993 "is to connect to '%s' and call "
5994 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5995 "the default handler from running. Look at the source code "
5996 "for the default handler in gtkiconview.c to get an idea what "
5997 "your handler should do. (gtkiconview.c is in the GTK+ source "
5998 "code.) If you're using GTK+ from a language other than C, "
5999 "there may be a more natural way to override default handlers, e.g. via derivation.",
6000 signal, g_type_name (required_iface), signal);
6008 remove_scroll_timeout (GtkIconView *icon_view)
6010 if (icon_view->priv->scroll_timeout_id != 0)
6012 g_source_remove (icon_view->priv->scroll_timeout_id);
6014 icon_view->priv->scroll_timeout_id = 0;
6019 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6023 gint px, py, width, height;
6024 gint hoffset, voffset;
6026 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6028 gdk_window_get_device_position (window, device, &px, &py, NULL);
6029 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6031 /* see if we are near the edge. */
6032 voffset = py - 2 * SCROLL_EDGE_SIZE;
6034 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6036 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6038 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6041 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6042 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6045 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6046 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6050 GtkIconView *icon_view;
6055 drag_scroll_timeout (gpointer datap)
6057 DragScrollData *data = datap;
6059 gtk_icon_view_autoscroll (data->icon_view, data->device);
6065 drag_scroll_data_free (DragScrollData *data)
6067 g_slice_free (DragScrollData, data);
6071 set_destination (GtkIconView *icon_view,
6072 GdkDragContext *context,
6075 GdkDragAction *suggested_action,
6079 GtkTreePath *path = NULL;
6080 GtkIconViewDropPosition pos;
6081 GtkIconViewDropPosition old_pos;
6082 GtkTreePath *old_dest_path = NULL;
6083 gboolean can_drop = FALSE;
6085 widget = GTK_WIDGET (icon_view);
6087 *suggested_action = 0;
6090 if (!icon_view->priv->dest_set)
6092 /* someone unset us as a drag dest, note that if
6093 * we return FALSE drag_leave isn't called
6096 gtk_icon_view_set_drag_dest_item (icon_view,
6098 GTK_ICON_VIEW_DROP_LEFT);
6100 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6102 return FALSE; /* no longer a drop site */
6105 *target = gtk_drag_dest_find_target (widget, context,
6106 gtk_drag_dest_get_target_list (widget));
6107 if (*target == GDK_NONE)
6110 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6113 GtkTreeModel *model;
6115 /* the row got dropped on empty space, let's setup a special case
6119 gtk_tree_path_free (path);
6121 model = gtk_icon_view_get_model (icon_view);
6123 n_children = gtk_tree_model_iter_n_children (model, NULL);
6126 pos = GTK_ICON_VIEW_DROP_BELOW;
6127 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6131 pos = GTK_ICON_VIEW_DROP_ABOVE;
6132 path = gtk_tree_path_new_from_indices (0, -1);
6142 gtk_icon_view_get_drag_dest_item (icon_view,
6147 gtk_tree_path_free (old_dest_path);
6149 if (TRUE /* FIXME if the location droppable predicate */)
6157 GtkWidget *source_widget;
6159 *suggested_action = gdk_drag_context_get_suggested_action (context);
6160 source_widget = gtk_drag_get_source_widget (context);
6162 if (source_widget == widget)
6164 /* Default to MOVE, unless the user has
6165 * pressed ctrl or shift to affect available actions
6167 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6168 *suggested_action = GDK_ACTION_MOVE;
6171 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6176 /* can't drop here */
6177 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6179 GTK_ICON_VIEW_DROP_LEFT);
6183 gtk_tree_path_free (path);
6189 get_logical_destination (GtkIconView *icon_view,
6190 gboolean *drop_append_mode)
6192 /* adjust path to point to the row the drop goes in front of */
6193 GtkTreePath *path = NULL;
6194 GtkIconViewDropPosition pos;
6196 *drop_append_mode = FALSE;
6198 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6203 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6204 pos == GTK_ICON_VIEW_DROP_BELOW)
6207 GtkTreeModel *model = icon_view->priv->model;
6209 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6210 !gtk_tree_model_iter_next (model, &iter))
6211 *drop_append_mode = TRUE;
6214 *drop_append_mode = FALSE;
6215 gtk_tree_path_next (path);
6223 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6224 GdkEventMotion *event)
6226 GtkWidget *widget = GTK_WIDGET (icon_view);
6227 GdkDragContext *context;
6228 GtkTreePath *path = NULL;
6230 GtkTreeModel *model;
6231 gboolean retval = FALSE;
6233 if (!icon_view->priv->source_set)
6236 if (icon_view->priv->pressed_button < 0)
6239 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6240 icon_view->priv->press_start_x,
6241 icon_view->priv->press_start_y,
6242 event->x, event->y))
6245 model = gtk_icon_view_get_model (icon_view);
6250 button = icon_view->priv->pressed_button;
6251 icon_view->priv->pressed_button = -1;
6253 path = gtk_icon_view_get_path_at_pos (icon_view,
6254 icon_view->priv->press_start_x,
6255 icon_view->priv->press_start_y);
6260 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6261 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6265 /* FIXME Check whether we're a start button, if not return FALSE and
6269 /* Now we can begin the drag */
6273 context = gtk_drag_begin (widget,
6274 gtk_drag_source_get_target_list (widget),
6275 icon_view->priv->source_actions,
6279 set_source_row (context, model, path);
6283 gtk_tree_path_free (path);
6288 /* Source side drag signals */
6290 gtk_icon_view_drag_begin (GtkWidget *widget,
6291 GdkDragContext *context)
6293 GtkIconView *icon_view;
6294 GtkIconViewItem *item;
6295 cairo_surface_t *icon;
6299 icon_view = GTK_ICON_VIEW (widget);
6301 /* if the user uses a custom DnD impl, we don't set the icon here */
6302 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6305 item = _gtk_icon_view_get_item_at_coords (icon_view,
6306 icon_view->priv->press_start_x,
6307 icon_view->priv->press_start_y,
6311 g_return_if_fail (item != NULL);
6313 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6314 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6316 path = gtk_tree_path_new_from_indices (item->index, -1);
6317 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6318 gtk_tree_path_free (path);
6320 cairo_surface_set_device_offset (icon, -x, -y);
6322 gtk_drag_set_icon_surface (context, icon);
6324 cairo_surface_destroy (icon);
6328 gtk_icon_view_drag_end (GtkWidget *widget,
6329 GdkDragContext *context)
6335 gtk_icon_view_drag_data_get (GtkWidget *widget,
6336 GdkDragContext *context,
6337 GtkSelectionData *selection_data,
6341 GtkIconView *icon_view;
6342 GtkTreeModel *model;
6343 GtkTreePath *source_row;
6345 icon_view = GTK_ICON_VIEW (widget);
6346 model = gtk_icon_view_get_model (icon_view);
6351 if (!icon_view->priv->source_set)
6354 source_row = get_source_row (context);
6356 if (source_row == NULL)
6359 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6360 * any model; for DragSource models there are some other targets
6364 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6365 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6370 /* If drag_data_get does nothing, try providing row data. */
6371 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6372 gtk_tree_set_row_drag_data (selection_data,
6377 gtk_tree_path_free (source_row);
6381 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6382 GdkDragContext *context)
6384 GtkTreeModel *model;
6385 GtkIconView *icon_view;
6386 GtkTreePath *source_row;
6388 icon_view = GTK_ICON_VIEW (widget);
6389 model = gtk_icon_view_get_model (icon_view);
6391 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6394 if (!icon_view->priv->source_set)
6397 source_row = get_source_row (context);
6399 if (source_row == NULL)
6402 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6405 gtk_tree_path_free (source_row);
6407 set_source_row (context, NULL, NULL);
6410 /* Target side drag signals */
6412 gtk_icon_view_drag_leave (GtkWidget *widget,
6413 GdkDragContext *context,
6416 GtkIconView *icon_view;
6418 icon_view = GTK_ICON_VIEW (widget);
6420 /* unset any highlight row */
6421 gtk_icon_view_set_drag_dest_item (icon_view,
6423 GTK_ICON_VIEW_DROP_LEFT);
6425 remove_scroll_timeout (icon_view);
6429 gtk_icon_view_drag_motion (GtkWidget *widget,
6430 GdkDragContext *context,
6435 GtkTreePath *path = NULL;
6436 GtkIconViewDropPosition pos;
6437 GtkIconView *icon_view;
6438 GdkDragAction suggested_action = 0;
6442 icon_view = GTK_ICON_VIEW (widget);
6444 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6447 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6449 /* we only know this *after* set_desination_row */
6450 empty = icon_view->priv->empty_view_drop;
6452 if (path == NULL && !empty)
6454 /* Can't drop here. */
6455 gdk_drag_status (context, 0, time);
6459 if (icon_view->priv->scroll_timeout_id == 0)
6461 DragScrollData *data = g_slice_new (DragScrollData);
6462 data->icon_view = icon_view;
6463 data->device = gdk_drag_context_get_device (context);
6465 icon_view->priv->scroll_timeout_id =
6466 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6469 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6471 /* Request data so we can use the source row when
6472 * determining whether to accept the drop
6474 set_status_pending (context, suggested_action);
6475 gtk_drag_get_data (widget, context, target, time);
6479 set_status_pending (context, 0);
6480 gdk_drag_status (context, suggested_action, time);
6485 gtk_tree_path_free (path);
6491 gtk_icon_view_drag_drop (GtkWidget *widget,
6492 GdkDragContext *context,
6497 GtkIconView *icon_view;
6499 GdkDragAction suggested_action = 0;
6500 GdkAtom target = GDK_NONE;
6501 GtkTreeModel *model;
6502 gboolean drop_append_mode;
6504 icon_view = GTK_ICON_VIEW (widget);
6505 model = gtk_icon_view_get_model (icon_view);
6507 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6509 if (!icon_view->priv->dest_set)
6512 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6515 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6518 path = get_logical_destination (icon_view, &drop_append_mode);
6520 if (target != GDK_NONE && path != NULL)
6522 /* in case a motion had requested drag data, change things so we
6523 * treat drag data receives as a drop.
6525 set_status_pending (context, 0);
6526 set_dest_row (context, model, path,
6527 icon_view->priv->empty_view_drop, drop_append_mode);
6531 gtk_tree_path_free (path);
6533 /* Unset this thing */
6534 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6536 if (target != GDK_NONE)
6538 gtk_drag_get_data (widget, context, target, time);
6546 gtk_icon_view_drag_data_received (GtkWidget *widget,
6547 GdkDragContext *context,
6550 GtkSelectionData *selection_data,
6555 gboolean accepted = FALSE;
6556 GtkTreeModel *model;
6557 GtkIconView *icon_view;
6558 GtkTreePath *dest_row;
6559 GdkDragAction suggested_action;
6560 gboolean drop_append_mode;
6562 icon_view = GTK_ICON_VIEW (widget);
6563 model = gtk_icon_view_get_model (icon_view);
6565 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6568 if (!icon_view->priv->dest_set)
6571 suggested_action = get_status_pending (context);
6573 if (suggested_action)
6575 /* We are getting this data due to a request in drag_motion,
6576 * rather than due to a request in drag_drop, so we are just
6577 * supposed to call drag_status, not actually paste in the
6580 path = get_logical_destination (icon_view, &drop_append_mode);
6583 suggested_action = 0;
6585 if (suggested_action)
6587 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6590 suggested_action = 0;
6593 gdk_drag_status (context, suggested_action, time);
6596 gtk_tree_path_free (path);
6598 /* If you can't drop, remove user drop indicator until the next motion */
6599 if (suggested_action == 0)
6600 gtk_icon_view_set_drag_dest_item (icon_view,
6602 GTK_ICON_VIEW_DROP_LEFT);
6607 dest_row = get_dest_row (context);
6609 if (dest_row == NULL)
6612 if (gtk_selection_data_get_length (selection_data) >= 0)
6614 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6620 gtk_drag_finish (context,
6622 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6625 gtk_tree_path_free (dest_row);
6628 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6631 /* Drag-and-Drop support */
6633 * gtk_icon_view_enable_model_drag_source:
6634 * @icon_view: a #GtkIconTreeView
6635 * @start_button_mask: Mask of allowed buttons to start drag
6636 * @targets: (array length=n_targets): the table of targets that the drag will
6638 * @n_targets: the number of items in @targets
6639 * @actions: the bitmask of possible actions for a drag from this
6642 * Turns @icon_view into a drag source for automatic DND. Calling this
6643 * method sets #GtkIconView:reorderable to %FALSE.
6648 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6649 GdkModifierType start_button_mask,
6650 const GtkTargetEntry *targets,
6652 GdkDragAction actions)
6654 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6656 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6658 icon_view->priv->start_button_mask = start_button_mask;
6659 icon_view->priv->source_actions = actions;
6661 icon_view->priv->source_set = TRUE;
6663 unset_reorderable (icon_view);
6667 * gtk_icon_view_enable_model_drag_dest:
6668 * @icon_view: a #GtkIconView
6669 * @targets: (array length=n_targets): the table of targets that the drag will
6671 * @n_targets: the number of items in @targets
6672 * @actions: the bitmask of possible actions for a drag to this
6675 * Turns @icon_view into a drop destination for automatic DND. Calling this
6676 * method sets #GtkIconView:reorderable to %FALSE.
6681 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6682 const GtkTargetEntry *targets,
6684 GdkDragAction actions)
6686 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6688 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6690 icon_view->priv->dest_actions = actions;
6692 icon_view->priv->dest_set = TRUE;
6694 unset_reorderable (icon_view);
6698 * gtk_icon_view_unset_model_drag_source:
6699 * @icon_view: a #GtkIconView
6701 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6702 * method sets #GtkIconView:reorderable to %FALSE.
6707 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6709 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6711 if (icon_view->priv->source_set)
6713 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6714 icon_view->priv->source_set = FALSE;
6717 unset_reorderable (icon_view);
6721 * gtk_icon_view_unset_model_drag_dest:
6722 * @icon_view: a #GtkIconView
6724 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6725 * method sets #GtkIconView:reorderable to %FALSE.
6730 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6732 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6734 if (icon_view->priv->dest_set)
6736 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6737 icon_view->priv->dest_set = FALSE;
6740 unset_reorderable (icon_view);
6743 /* These are useful to implement your own custom stuff. */
6745 * gtk_icon_view_set_drag_dest_item:
6746 * @icon_view: a #GtkIconView
6747 * @path: (allow-none): The path of the item to highlight, or %NULL.
6748 * @pos: Specifies where to drop, relative to the item
6750 * Sets the item that is highlighted for feedback.
6755 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6757 GtkIconViewDropPosition pos)
6759 /* Note; this function is exported to allow a custom DND
6760 * implementation, so it can't touch TreeViewDragInfo
6763 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6765 if (icon_view->priv->dest_item)
6767 GtkTreePath *current_path;
6768 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6769 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6770 icon_view->priv->dest_item = NULL;
6772 gtk_icon_view_queue_draw_path (icon_view, current_path);
6773 gtk_tree_path_free (current_path);
6776 /* special case a drop on an empty model */
6777 icon_view->priv->empty_view_drop = FALSE;
6778 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6779 && gtk_tree_path_get_depth (path) == 1
6780 && gtk_tree_path_get_indices (path)[0] == 0)
6784 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6787 if (n_children == 0)
6788 icon_view->priv->empty_view_drop = TRUE;
6791 icon_view->priv->dest_pos = pos;
6795 icon_view->priv->dest_item =
6796 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6797 icon_view->priv->model, path);
6799 gtk_icon_view_queue_draw_path (icon_view, path);
6804 * gtk_icon_view_get_drag_dest_item:
6805 * @icon_view: a #GtkIconView
6806 * @path: (out) (allow-none): Return location for the path of
6807 * the highlighted item, or %NULL.
6808 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6810 * Gets information about the item that is highlighted for feedback.
6815 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6817 GtkIconViewDropPosition *pos)
6819 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6823 if (icon_view->priv->dest_item)
6824 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6830 *pos = icon_view->priv->dest_pos;
6834 * gtk_icon_view_get_dest_item_at_pos:
6835 * @icon_view: a #GtkIconView
6836 * @drag_x: the position to determine the destination item for
6837 * @drag_y: the position to determine the destination item for
6838 * @path: (out) (allow-none): Return location for the path of the item,
6840 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6842 * Determines the destination item for a given position.
6844 * Return value: whether there is an item at the given position.
6849 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6853 GtkIconViewDropPosition *pos)
6855 GtkIconViewItem *item;
6857 /* Note; this function is exported to allow a custom DND
6858 * implementation, so it can't touch TreeViewDragInfo
6861 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6862 g_return_val_if_fail (drag_x >= 0, FALSE);
6863 g_return_val_if_fail (drag_y >= 0, FALSE);
6864 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6870 item = _gtk_icon_view_get_item_at_coords (icon_view,
6871 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6872 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6879 *path = gtk_tree_path_new_from_indices (item->index, -1);
6883 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6884 *pos = GTK_ICON_VIEW_DROP_LEFT;
6885 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6886 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6887 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6888 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6889 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6890 *pos = GTK_ICON_VIEW_DROP_BELOW;
6892 *pos = GTK_ICON_VIEW_DROP_INTO;
6899 * gtk_icon_view_create_drag_icon:
6900 * @icon_view: a #GtkIconView
6901 * @path: a #GtkTreePath in @icon_view
6903 * Creates a #cairo_surface_t representation of the item at @path.
6904 * This image is used for a drag icon.
6906 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6911 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6915 GtkStyleContext *context;
6917 cairo_surface_t *surface;
6921 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6922 g_return_val_if_fail (path != NULL, NULL);
6924 widget = GTK_WIDGET (icon_view);
6925 context = gtk_widget_get_style_context (widget);
6927 if (!gtk_widget_get_realized (widget))
6930 index = gtk_tree_path_get_indices (path)[0];
6932 for (l = icon_view->priv->items; l; l = l->next)
6934 GtkIconViewItem *item = l->data;
6936 if (index == item->index)
6938 GdkRectangle rect = {
6939 item->cell_area.x - icon_view->priv->item_padding,
6940 item->cell_area.y - icon_view->priv->item_padding,
6941 item->cell_area.width + icon_view->priv->item_padding * 2,
6942 item->cell_area.height + icon_view->priv->item_padding * 2
6945 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6946 CAIRO_CONTENT_COLOR,
6950 cr = cairo_create (surface);
6951 cairo_set_line_width (cr, 1.);
6953 gtk_render_background (context, cr, 0, 0,
6954 rect.width + 2, rect.height + 2);
6958 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6961 gtk_icon_view_paint_item (icon_view, cr, item,
6962 icon_view->priv->item_padding + 1,
6963 icon_view->priv->item_padding + 1, FALSE);
6967 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6968 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6981 * gtk_icon_view_get_reorderable:
6982 * @icon_view: a #GtkIconView
6984 * Retrieves whether the user can reorder the list via drag-and-drop.
6985 * See gtk_icon_view_set_reorderable().
6987 * Return value: %TRUE if the list can be reordered.
6992 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6994 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6996 return icon_view->priv->reorderable;
6999 static const GtkTargetEntry item_targets[] = {
7000 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7005 * gtk_icon_view_set_reorderable:
7006 * @icon_view: A #GtkIconView.
7007 * @reorderable: %TRUE, if the list of items can be reordered.
7009 * This function is a convenience function to allow you to reorder models that
7010 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7011 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7012 * the user can reorder the model by dragging and dropping rows. The
7013 * developer can listen to these changes by connecting to the model's
7014 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7015 * the icon view as a drag source and destination. Therefore, drag and
7016 * drop can not be used in a reorderable view for any other purpose.
7018 * This function does not give you any degree of control over the order -- any
7019 * reordering is allowed. If more control is needed, you should probably
7020 * handle drag and drop manually.
7025 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7026 gboolean reorderable)
7028 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7030 reorderable = reorderable != FALSE;
7032 if (icon_view->priv->reorderable == reorderable)
7037 gtk_icon_view_enable_model_drag_source (icon_view,
7040 G_N_ELEMENTS (item_targets),
7042 gtk_icon_view_enable_model_drag_dest (icon_view,
7044 G_N_ELEMENTS (item_targets),
7049 gtk_icon_view_unset_model_drag_source (icon_view);
7050 gtk_icon_view_unset_model_drag_dest (icon_view);
7053 icon_view->priv->reorderable = reorderable;
7055 g_object_notify (G_OBJECT (icon_view), "reorderable");
7059 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7060 GtkBuilder *builder,
7062 const gchar *tagname,
7063 GMarkupParser *parser,
7066 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7067 tagname, parser, data))
7070 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7071 tagname, parser, data);
7075 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7076 GtkBuilder *builder,
7078 const gchar *tagname,
7081 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7082 child, tagname, data))
7083 parent_buildable_iface->custom_tag_end (buildable, builder,
7084 child, tagname, data);