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);
1546 *minimum = n_items ? item_min : 0;
1547 *natural = item_nat * n_items + priv->column_spacing * (n_items - 1);
1550 *minimum += 2 * priv->margin;
1551 *natural += 2 * priv->margin;
1555 gtk_icon_view_get_preferred_width_for_height (GtkWidget *widget,
1560 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1561 GtkIconViewPrivate *priv = icon_view->priv;
1562 int item_min, item_nat, rows, n_items;
1564 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_VERTICAL, height, &rows, NULL);
1565 n_items = gtk_icon_view_get_n_items (icon_view);
1567 height = height + priv->row_spacing - 2 * priv->margin;
1569 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, height / rows - priv->row_spacing, &item_min, &item_nat);
1570 *minimum = item_min * ((n_items + rows - 1) / rows);
1571 *natural = item_nat * ((n_items + rows - 1) / rows);
1573 *minimum += 2 * priv->margin;
1574 *natural += 2 * priv->margin;
1578 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1582 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1583 GtkIconViewPrivate *priv = icon_view->priv;
1584 int item_min, item_nat, n_items;
1586 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, -1, &item_min, &item_nat);
1587 n_items = gtk_icon_view_get_n_items (icon_view);
1589 if (priv->columns > 0)
1591 int n_rows = (n_items + priv->columns - 1) / priv->columns;
1593 *minimum = item_min * n_rows + priv->row_spacing * (n_rows - 1);
1594 *natural = item_nat * n_rows + priv->row_spacing * (n_rows - 1);
1598 *minimum = n_items ? item_min : 0;
1599 *natural = item_nat * n_items + priv->row_spacing * (n_items - 1);
1602 *minimum += 2 * priv->margin;
1603 *natural += 2 * priv->margin;
1607 gtk_icon_view_get_preferred_height_for_width (GtkWidget *widget,
1612 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1613 GtkIconViewPrivate *priv = icon_view->priv;
1614 int item_min, item_nat, columns, n_items;
1616 gtk_icon_view_compute_n_items_for_size (icon_view, GTK_ORIENTATION_HORIZONTAL, width, NULL, &columns);
1617 n_items = gtk_icon_view_get_n_items (icon_view);
1619 width = width + priv->column_spacing - 2 * priv->margin;
1621 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_VERTICAL, width / columns - priv->column_spacing, &item_min, &item_nat);
1622 *minimum = (item_min + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1623 *natural = (item_nat + priv->row_spacing) * ((n_items + columns - 1) / columns) - priv->row_spacing;
1625 *minimum += 2 * priv->margin;
1626 *natural += 2 * priv->margin;
1630 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1634 for (list = icon_view->priv->children; list; list = list->next)
1636 GtkIconViewChild *child = list->data;
1638 /* totally ignore our child's requisition */
1639 gtk_widget_size_allocate (child->widget, &child->area);
1644 gtk_icon_view_size_allocate (GtkWidget *widget,
1645 GtkAllocation *allocation)
1647 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1649 gtk_widget_set_allocation (widget, allocation);
1651 gtk_icon_view_layout (icon_view);
1653 if (gtk_widget_get_realized (widget))
1655 gdk_window_move_resize (gtk_widget_get_window (widget),
1656 allocation->x, allocation->y,
1657 allocation->width, allocation->height);
1658 gdk_window_resize (icon_view->priv->bin_window,
1659 MAX (icon_view->priv->width, allocation->width),
1660 MAX (icon_view->priv->height, allocation->height));
1663 gtk_icon_view_allocate_children (icon_view);
1665 /* Delay signal emission */
1666 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1667 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1669 gtk_icon_view_set_hadjustment_values (icon_view);
1670 gtk_icon_view_set_vadjustment_values (icon_view);
1672 if (gtk_widget_get_realized (widget) &&
1673 icon_view->priv->scroll_to_path)
1676 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1677 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1678 icon_view->priv->scroll_to_path = NULL;
1680 gtk_icon_view_scroll_to_path (icon_view, path,
1681 icon_view->priv->scroll_to_use_align,
1682 icon_view->priv->scroll_to_row_align,
1683 icon_view->priv->scroll_to_col_align);
1684 gtk_tree_path_free (path);
1687 /* Emit any pending signals now */
1688 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1689 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1693 gtk_icon_view_draw (GtkWidget *widget,
1696 GtkIconView *icon_view;
1700 GtkIconViewDropPosition dest_pos;
1701 GtkIconViewItem *dest_item = NULL;
1703 icon_view = GTK_ICON_VIEW (widget);
1705 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1710 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1712 cairo_set_line_width (cr, 1.);
1714 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1718 dest_index = gtk_tree_path_get_indices (path)[0];
1719 gtk_tree_path_free (path);
1724 for (icons = icon_view->priv->items; icons; icons = icons->next)
1726 GtkIconViewItem *item = icons->data;
1727 GdkRectangle paint_area;
1729 paint_area.x = item->cell_area.x - icon_view->priv->item_padding;
1730 paint_area.y = item->cell_area.y - icon_view->priv->item_padding;
1731 paint_area.width = item->cell_area.width + icon_view->priv->item_padding * 2;
1732 paint_area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
1736 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1739 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1741 gtk_icon_view_paint_item (icon_view, cr, item,
1742 item->cell_area.x, item->cell_area.y,
1743 icon_view->priv->draw_focus);
1745 if (dest_index == item->index)
1753 dest_pos != GTK_ICON_VIEW_NO_DROP)
1755 GtkStyleContext *context;
1756 GdkRectangle rect = { 0 };
1758 context = gtk_widget_get_style_context (widget);
1762 case GTK_ICON_VIEW_DROP_INTO:
1763 rect = dest_item->cell_area;
1765 case GTK_ICON_VIEW_DROP_ABOVE:
1766 rect.x = dest_item->cell_area.x;
1767 rect.y = dest_item->cell_area.y - 1;
1768 rect.width = dest_item->cell_area.width;
1771 case GTK_ICON_VIEW_DROP_LEFT:
1772 rect.x = dest_item->cell_area.x - 1;
1773 rect.y = dest_item->cell_area.y;
1775 rect.height = dest_item->cell_area.height;
1777 case GTK_ICON_VIEW_DROP_BELOW:
1778 rect.x = dest_item->cell_area.x;
1779 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1780 rect.width = dest_item->cell_area.width;
1783 case GTK_ICON_VIEW_DROP_RIGHT:
1784 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1785 rect.y = dest_item->cell_area.y;
1787 rect.height = dest_item->cell_area.height;
1788 case GTK_ICON_VIEW_NO_DROP: ;
1792 gtk_render_focus (context, cr,
1794 rect.width, rect.height);
1797 if (icon_view->priv->doing_rubberband)
1798 gtk_icon_view_paint_rubberband (icon_view, cr);
1802 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1806 rubberband_scroll_timeout (gpointer data)
1808 GtkIconView *icon_view = data;
1810 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1811 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1812 icon_view->priv->scroll_value_diff);
1814 gtk_icon_view_update_rubberband (icon_view);
1820 gtk_icon_view_motion (GtkWidget *widget,
1821 GdkEventMotion *event)
1823 GtkAllocation allocation;
1824 GtkIconView *icon_view;
1827 icon_view = GTK_ICON_VIEW (widget);
1829 gtk_icon_view_maybe_begin_drag (icon_view, event);
1831 if (icon_view->priv->doing_rubberband)
1833 gtk_icon_view_update_rubberband (widget);
1835 abs_y = event->y - icon_view->priv->height *
1836 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1837 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1838 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1840 gtk_widget_get_allocation (widget, &allocation);
1842 if (abs_y < 0 || abs_y > allocation.height)
1845 icon_view->priv->scroll_value_diff = abs_y;
1847 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1849 icon_view->priv->event_last_x = event->x;
1850 icon_view->priv->event_last_y = event->y;
1852 if (icon_view->priv->scroll_timeout_id == 0)
1853 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1857 remove_scroll_timeout (icon_view);
1861 GtkIconViewItem *item, *last_prelight_item;
1862 GtkCellRenderer *cell = NULL;
1864 last_prelight_item = icon_view->priv->last_prelight;
1865 item = _gtk_icon_view_get_item_at_coords (icon_view,
1872 item->prelight = TRUE;
1873 gtk_icon_view_queue_draw_item (icon_view, item);
1876 if (last_prelight_item != NULL &&
1877 last_prelight_item != item)
1879 last_prelight_item->prelight = FALSE;
1880 gtk_icon_view_queue_draw_item (icon_view,
1881 icon_view->priv->last_prelight);
1884 icon_view->priv->last_prelight = item;
1891 gtk_icon_view_remove (GtkContainer *container,
1894 GtkIconView *icon_view;
1895 GtkIconViewChild *child = NULL;
1898 icon_view = GTK_ICON_VIEW (container);
1900 tmp_list = icon_view->priv->children;
1903 child = tmp_list->data;
1904 if (child->widget == widget)
1906 gtk_widget_unparent (widget);
1908 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1909 g_list_free_1 (tmp_list);
1914 tmp_list = tmp_list->next;
1919 gtk_icon_view_forall (GtkContainer *container,
1920 gboolean include_internals,
1921 GtkCallback callback,
1922 gpointer callback_data)
1924 GtkIconView *icon_view;
1925 GtkIconViewChild *child = NULL;
1928 icon_view = GTK_ICON_VIEW (container);
1930 tmp_list = icon_view->priv->children;
1933 child = tmp_list->data;
1934 tmp_list = tmp_list->next;
1936 (* callback) (child->widget, callback_data);
1941 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1942 GtkIconViewItem *item)
1945 AtkObject *item_obj;
1947 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1950 item_obj = atk_object_ref_accessible_child (obj, item->index);
1951 if (item_obj != NULL)
1953 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1954 g_object_unref (item_obj);
1960 gtk_icon_view_add_editable (GtkCellArea *area,
1961 GtkCellRenderer *renderer,
1962 GtkCellEditable *editable,
1963 GdkRectangle *cell_area,
1965 GtkIconView *icon_view)
1967 GtkIconViewChild *child;
1968 GtkWidget *widget = GTK_WIDGET (editable);
1970 child = g_new (GtkIconViewChild, 1);
1972 child->widget = widget;
1973 child->area.x = cell_area->x;
1974 child->area.y = cell_area->y;
1975 child->area.width = cell_area->width;
1976 child->area.height = cell_area->height;
1978 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1980 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1981 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1983 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1987 gtk_icon_view_remove_editable (GtkCellArea *area,
1988 GtkCellRenderer *renderer,
1989 GtkCellEditable *editable,
1990 GtkIconView *icon_view)
1994 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1995 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1997 gtk_container_remove (GTK_CONTAINER (icon_view),
1998 GTK_WIDGET (editable));
2000 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
2001 gtk_icon_view_queue_draw_path (icon_view, path);
2002 gtk_tree_path_free (path);
2006 * gtk_icon_view_set_cursor:
2007 * @icon_view: A #GtkIconView
2008 * @path: A #GtkTreePath
2009 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2010 * @start_editing: %TRUE if the specified cell should start being edited.
2012 * Sets the current keyboard focus to be at @path, and selects it. This is
2013 * useful when you want to focus the user's attention on a particular item.
2014 * If @cell is not %NULL, then focus is given to the cell specified by
2015 * it. Additionally, if @start_editing is %TRUE, then editing should be
2016 * started in the specified cell.
2018 * This function is often followed by <literal>gtk_widget_grab_focus
2019 * (icon_view)</literal> in order to give keyboard focus to the widget.
2020 * Please note that editing can only happen when the widget is realized.
2025 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2027 GtkCellRenderer *cell,
2028 gboolean start_editing)
2030 GtkIconViewItem *item = NULL;
2032 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2033 g_return_if_fail (path != NULL);
2034 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2036 if (icon_view->priv->cell_area)
2037 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2039 if (gtk_tree_path_get_depth (path) == 1)
2040 item = g_list_nth_data (icon_view->priv->items,
2041 gtk_tree_path_get_indices(path)[0]);
2046 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
2047 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2049 if (start_editing &&
2050 icon_view->priv->cell_area)
2052 _gtk_icon_view_set_cell_data (icon_view, item);
2053 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2054 gtk_cell_area_activate (icon_view->priv->cell_area,
2055 icon_view->priv->cell_area_context,
2056 GTK_WIDGET (icon_view), &item->cell_area,
2057 0 /* XXX flags */, TRUE);
2062 * gtk_icon_view_get_cursor:
2063 * @icon_view: A #GtkIconView
2064 * @path: (out) (allow-none): Return location for the current cursor path,
2066 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
2068 * Fills in @path and @cell with the current cursor path and cell.
2069 * If the cursor isn't currently set, then *@path will be %NULL.
2070 * If no cell currently has focus, then *@cell will be %NULL.
2072 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2074 * Return value: %TRUE if the cursor is set.
2079 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2081 GtkCellRenderer **cell)
2083 GtkIconViewItem *item;
2085 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2087 item = icon_view->priv->cursor_item;
2092 *path = gtk_tree_path_new_from_indices (item->index, -1);
2097 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
2098 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
2100 return (item != NULL);
2104 gtk_icon_view_button_press (GtkWidget *widget,
2105 GdkEventButton *event)
2107 GtkIconView *icon_view;
2108 GtkIconViewItem *item;
2109 gboolean dirty = FALSE;
2110 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2112 icon_view = GTK_ICON_VIEW (widget);
2114 if (event->window != icon_view->priv->bin_window)
2117 if (!gtk_widget_has_focus (widget))
2118 gtk_widget_grab_focus (widget);
2120 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_BUTTON_PRESS)
2122 GdkModifierType extend_mod_mask;
2123 GdkModifierType modify_mod_mask;
2126 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2129 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2131 item = _gtk_icon_view_get_item_at_coords (icon_view,
2137 * We consider only the the cells' area as the item area if the
2138 * item is not selected, but if it *is* selected, the complete
2139 * selection rectangle is considered to be part of the item.
2141 if (item != NULL && (cell != NULL || item->selected))
2145 if (gtk_cell_renderer_is_activatable (cell))
2149 gtk_icon_view_scroll_to_item (icon_view, item);
2151 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2153 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2155 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2156 (event->state & extend_mod_mask))
2158 gtk_icon_view_unselect_all_internal (icon_view);
2160 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2161 if (!icon_view->priv->anchor_item)
2162 icon_view->priv->anchor_item = item;
2164 gtk_icon_view_select_all_between (icon_view,
2165 icon_view->priv->anchor_item,
2171 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2172 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2173 (event->state & modify_mod_mask))
2175 item->selected = !item->selected;
2176 gtk_icon_view_queue_draw_item (icon_view, item);
2181 gtk_icon_view_unselect_all_internal (icon_view);
2183 item->selected = TRUE;
2184 gtk_icon_view_queue_draw_item (icon_view, item);
2187 _gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2188 icon_view->priv->anchor_item = item;
2191 /* Save press to possibly begin a drag */
2192 if (icon_view->priv->pressed_button < 0)
2194 icon_view->priv->pressed_button = event->button;
2195 icon_view->priv->press_start_x = event->x;
2196 icon_view->priv->press_start_y = event->y;
2199 if (!icon_view->priv->last_single_clicked)
2200 icon_view->priv->last_single_clicked = item;
2202 /* cancel the current editing, if it exists */
2203 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2205 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2207 _gtk_icon_view_set_cell_data (icon_view, item);
2208 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2209 gtk_cell_area_activate (icon_view->priv->cell_area,
2210 icon_view->priv->cell_area_context,
2211 GTK_WIDGET (icon_view),
2212 &item->cell_area, 0/* XXX flags */, FALSE);
2217 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2218 !(event->state & modify_mod_mask))
2220 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2223 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2224 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2227 /* don't draw keyboard focus around an clicked-on item */
2228 icon_view->priv->draw_focus = FALSE;
2231 if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
2233 item = _gtk_icon_view_get_item_at_coords (icon_view,
2238 if (item && item == icon_view->priv->last_single_clicked)
2242 path = gtk_tree_path_new_from_indices (item->index, -1);
2243 gtk_icon_view_item_activated (icon_view, path);
2244 gtk_tree_path_free (path);
2247 icon_view->priv->last_single_clicked = NULL;
2248 icon_view->priv->pressed_button = -1;
2252 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2254 return event->button == GDK_BUTTON_PRIMARY;
2258 gtk_icon_view_button_release (GtkWidget *widget,
2259 GdkEventButton *event)
2261 GtkIconView *icon_view;
2263 icon_view = GTK_ICON_VIEW (widget);
2265 if (icon_view->priv->pressed_button == event->button)
2266 icon_view->priv->pressed_button = -1;
2268 gtk_icon_view_stop_rubberbanding (icon_view);
2270 remove_scroll_timeout (icon_view);
2276 gtk_icon_view_key_press (GtkWidget *widget,
2279 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2281 if (icon_view->priv->doing_rubberband)
2283 if (event->keyval == GDK_KEY_Escape)
2284 gtk_icon_view_stop_rubberbanding (icon_view);
2289 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2293 gtk_icon_view_key_release (GtkWidget *widget,
2296 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2298 if (icon_view->priv->doing_rubberband)
2301 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2305 gtk_icon_view_update_rubberband (gpointer data)
2307 GtkIconView *icon_view;
2309 GdkRectangle old_area;
2310 GdkRectangle new_area;
2311 GdkRectangle common;
2312 cairo_region_t *invalid_region;
2314 icon_view = GTK_ICON_VIEW (data);
2316 gdk_window_get_device_position (icon_view->priv->bin_window,
2317 icon_view->priv->rubberband_device,
2323 old_area.x = MIN (icon_view->priv->rubberband_x1,
2324 icon_view->priv->rubberband_x2);
2325 old_area.y = MIN (icon_view->priv->rubberband_y1,
2326 icon_view->priv->rubberband_y2);
2327 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2328 icon_view->priv->rubberband_x1) + 1;
2329 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2330 icon_view->priv->rubberband_y1) + 1;
2332 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2333 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2334 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2335 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2337 invalid_region = cairo_region_create_rectangle (&old_area);
2338 cairo_region_union_rectangle (invalid_region, &new_area);
2340 gdk_rectangle_intersect (&old_area, &new_area, &common);
2341 if (common.width > 2 && common.height > 2)
2343 cairo_region_t *common_region;
2345 /* make sure the border is invalidated */
2351 common_region = cairo_region_create_rectangle (&common);
2353 cairo_region_subtract (invalid_region, common_region);
2354 cairo_region_destroy (common_region);
2357 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2359 cairo_region_destroy (invalid_region);
2361 icon_view->priv->rubberband_x2 = x;
2362 icon_view->priv->rubberband_y2 = y;
2364 gtk_icon_view_update_rubberband_selection (icon_view);
2368 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2375 if (icon_view->priv->rubberband_device)
2378 for (items = icon_view->priv->items; items; items = items->next)
2380 GtkIconViewItem *item = items->data;
2382 item->selected_before_rubberbanding = item->selected;
2385 icon_view->priv->rubberband_x1 = x;
2386 icon_view->priv->rubberband_y1 = y;
2387 icon_view->priv->rubberband_x2 = x;
2388 icon_view->priv->rubberband_y2 = y;
2390 icon_view->priv->doing_rubberband = TRUE;
2391 icon_view->priv->rubberband_device = device;
2393 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2397 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2399 if (!icon_view->priv->doing_rubberband)
2402 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2403 icon_view->priv->rubberband_device);
2405 icon_view->priv->doing_rubberband = FALSE;
2406 icon_view->priv->rubberband_device = NULL;
2408 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2412 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2415 gint x, y, width, height;
2416 gboolean dirty = FALSE;
2418 x = MIN (icon_view->priv->rubberband_x1,
2419 icon_view->priv->rubberband_x2);
2420 y = MIN (icon_view->priv->rubberband_y1,
2421 icon_view->priv->rubberband_y2);
2422 width = ABS (icon_view->priv->rubberband_x1 -
2423 icon_view->priv->rubberband_x2);
2424 height = ABS (icon_view->priv->rubberband_y1 -
2425 icon_view->priv->rubberband_y2);
2427 for (items = icon_view->priv->items; items; items = items->next)
2429 GtkIconViewItem *item = items->data;
2433 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2434 x, y, width, height);
2436 selected = is_in ^ item->selected_before_rubberbanding;
2438 if (item->selected != selected)
2440 item->selected = selected;
2442 gtk_icon_view_queue_draw_item (icon_view, item);
2447 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2452 GdkRectangle hit_rect;
2457 hit_test (GtkCellRenderer *renderer,
2458 const GdkRectangle *cell_area,
2459 const GdkRectangle *cell_background,
2462 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2463 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2464 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2465 MAX (data->hit_rect.y, cell_area->y) > 0)
2468 return (data->hit != FALSE);
2472 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2473 GtkIconViewItem *item,
2479 HitTestData data = { { x, y, width, height }, FALSE };
2480 GdkRectangle *item_area = &item->cell_area;
2482 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2483 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2486 _gtk_icon_view_set_cell_data (icon_view, item);
2487 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2488 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area,
2489 icon_view->priv->cell_area_context,
2490 GTK_WIDGET (icon_view),
2491 item_area, item_area,
2492 (GtkCellAllocCallback)hit_test, &data);
2498 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2500 gboolean dirty = FALSE;
2503 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2506 for (items = icon_view->priv->items; items; items = items->next)
2508 GtkIconViewItem *item = items->data;
2512 item->selected = FALSE;
2514 gtk_icon_view_queue_draw_item (icon_view, item);
2515 gtk_icon_view_item_selected_changed (icon_view, item);
2523 /* GtkIconView signals */
2525 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2527 gtk_icon_view_select_all (icon_view);
2531 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2533 gtk_icon_view_unselect_all (icon_view);
2537 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2539 gtk_icon_view_unselect_all (icon_view);
2541 if (icon_view->priv->cursor_item != NULL)
2542 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2546 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2550 if (!icon_view->priv->cursor_item)
2553 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2554 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2555 icon_view->priv->cursor_item->cell_area.width,
2556 icon_view->priv->cursor_item->cell_area.height);
2557 gtk_cell_area_activate (icon_view->priv->cell_area,
2558 icon_view->priv->cell_area_context,
2559 GTK_WIDGET (icon_view),
2560 &icon_view->priv->cursor_item->cell_area,
2564 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2565 gtk_icon_view_item_activated (icon_view, path);
2566 gtk_tree_path_free (path);
2572 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2574 if (!icon_view->priv->cursor_item)
2577 switch (icon_view->priv->selection_mode)
2579 case GTK_SELECTION_NONE:
2581 case GTK_SELECTION_BROWSE:
2582 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2584 case GTK_SELECTION_SINGLE:
2585 if (icon_view->priv->cursor_item->selected)
2586 _gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2588 _gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2590 case GTK_SELECTION_MULTIPLE:
2591 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2592 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2594 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2595 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2601 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2603 GtkAllocation allocation;
2604 GtkAdjustment *adj = icon_view->priv->hadjustment;
2605 gdouble old_page_size;
2611 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2613 old_value = gtk_adjustment_get_value (adj);
2614 old_upper = gtk_adjustment_get_upper (adj);
2615 old_page_size = gtk_adjustment_get_page_size (adj);
2616 new_upper = MAX (allocation.width, icon_view->priv->width);
2618 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2620 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2621 /* Quick explanation:
2622 * In LTR locales, leftmost portion of visible rectangle should stay
2623 * fixed, which means left edge of scrollbar thumb should remain fixed
2624 * and thus adjustment's value should stay the same.
2626 * In RTL locales, we want to keep rightmost portion of visible
2627 * rectangle fixed. This means right edge of thumb should remain fixed.
2628 * In this case, upper - value - page_size should remain constant.
2630 new_value = (new_upper - allocation.width) -
2631 (old_upper - old_value - old_page_size);
2632 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2635 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2637 gtk_adjustment_configure (adj,
2641 allocation.width * 0.1,
2642 allocation.width * 0.9,
2647 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2649 GtkAllocation allocation;
2650 GtkAdjustment *adj = icon_view->priv->vadjustment;
2652 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2654 gtk_adjustment_configure (adj,
2655 gtk_adjustment_get_value (adj),
2657 MAX (allocation.height, icon_view->priv->height),
2658 allocation.height * 0.1,
2659 allocation.height * 0.9,
2664 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2665 GtkAdjustment *adjustment)
2667 GtkIconViewPrivate *priv = icon_view->priv;
2669 if (adjustment && priv->hadjustment == adjustment)
2672 if (priv->hadjustment != NULL)
2674 g_signal_handlers_disconnect_matched (priv->hadjustment,
2675 G_SIGNAL_MATCH_DATA,
2676 0, 0, NULL, NULL, icon_view);
2677 g_object_unref (priv->hadjustment);
2681 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2684 g_signal_connect (adjustment, "value-changed",
2685 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2686 priv->hadjustment = g_object_ref_sink (adjustment);
2687 gtk_icon_view_set_hadjustment_values (icon_view);
2689 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2693 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2694 GtkAdjustment *adjustment)
2696 GtkIconViewPrivate *priv = icon_view->priv;
2698 if (adjustment && priv->vadjustment == adjustment)
2701 if (priv->vadjustment != NULL)
2703 g_signal_handlers_disconnect_matched (priv->vadjustment,
2704 G_SIGNAL_MATCH_DATA,
2705 0, 0, NULL, NULL, icon_view);
2706 g_object_unref (priv->vadjustment);
2710 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2713 g_signal_connect (adjustment, "value-changed",
2714 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2715 priv->vadjustment = g_object_ref_sink (adjustment);
2716 gtk_icon_view_set_vadjustment_values (icon_view);
2718 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2722 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2723 GtkIconView *icon_view)
2725 GtkIconViewPrivate *priv = icon_view->priv;
2727 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2729 gdk_window_move (priv->bin_window,
2730 - gtk_adjustment_get_value (priv->hadjustment),
2731 - gtk_adjustment_get_value (priv->vadjustment));
2733 if (icon_view->priv->doing_rubberband)
2734 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2736 _gtk_icon_view_accessible_adjustment_changed (icon_view);
2741 adjust_wrap_width (GtkIconView *icon_view)
2743 if (icon_view->priv->text_cell)
2745 gint wrap_width = 50;
2747 /* Here we go with the same old guess, try the icon size and set double
2748 * the size of the first icon found in the list, naive but works much
2750 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2752 _gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2753 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2754 GTK_WIDGET (icon_view),
2757 wrap_width = MAX (wrap_width * 2, 50);
2760 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2761 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2766 compare_sizes (gconstpointer p1,
2770 return GPOINTER_TO_INT (((const GtkRequestedSize *) p1)->data)
2771 - GPOINTER_TO_INT (((const GtkRequestedSize *) p2)->data);
2775 gtk_icon_view_layout (GtkIconView *icon_view)
2777 GtkIconViewPrivate *priv = icon_view->priv;
2778 GtkWidget *widget = GTK_WIDGET (icon_view);
2781 gint n_columns, n_rows, n_items;
2783 GtkRequestedSize *sizes;
2785 n_items = gtk_icon_view_get_n_items (icon_view);
2787 /* Update the wrap width for the text cell before going and requesting sizes */
2789 adjust_wrap_width (icon_view);
2791 gtk_icon_view_compute_n_items_for_size (icon_view,
2792 GTK_ORIENTATION_HORIZONTAL,
2793 gtk_widget_get_allocated_width (widget),
2796 n_rows = (n_items + n_columns - 1) / n_columns;
2800 /* We might need vertical scrolling here */
2801 gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_width, NULL);
2802 item_width += 2 * priv->item_padding + 2 * priv->margin;
2803 priv->width = MAX (item_width, gtk_widget_get_allocated_width (widget));
2807 priv->width = gtk_widget_get_allocated_width (widget);
2810 item_width = (priv->width - 2 * priv->margin + priv->column_spacing) / n_columns;
2811 item_width -= priv->column_spacing;
2812 item_width -= 2 * priv->item_padding;
2814 gtk_cell_area_context_reset (priv->cell_area_context);
2815 gtk_cell_area_context_allocate (priv->cell_area_context, item_width, -1);
2816 /* because layouting is complicated. We designed an API
2817 * that is O(N²) and nonsensical.
2818 * And we're proud of it. */
2819 for (items = priv->items; items; items = items->next)
2821 _gtk_icon_view_set_cell_data (icon_view, items->data);
2822 gtk_cell_area_get_preferred_width (priv->cell_area,
2823 priv->cell_area_context,
2828 sizes = g_newa (GtkRequestedSize, n_rows);
2829 items = priv->items;
2830 priv->height = priv->margin;
2832 /* Collect the heights for all rows */
2833 for (row = 0; row < n_rows; row++)
2835 for (col = 0; col < n_columns && items; col++, items = items->next)
2837 GtkIconViewItem *item = items->data;
2839 _gtk_icon_view_set_cell_data (icon_view, item);
2840 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2841 priv->cell_area_context,
2847 sizes[row].data = GINT_TO_POINTER (row);
2848 gtk_cell_area_context_get_preferred_height_for_width (priv->cell_area_context,
2850 &sizes[row].minimum_size,
2851 &sizes[row].natural_size);
2852 priv->height += sizes[row].minimum_size + 2 * priv->item_padding + priv->row_spacing;
2855 priv->height -= priv->row_spacing;
2856 priv->height += priv->margin;
2857 priv->height = MIN (priv->height, gtk_widget_get_allocated_height (widget));
2859 gtk_distribute_natural_allocation (gtk_widget_get_allocated_height (widget) - priv->height,
2863 /* Actually allocate the rows */
2864 g_qsort_with_data (sizes, n_rows, sizeof (GtkRequestedSize), compare_sizes, NULL);
2866 items = priv->items;
2867 priv->height = priv->margin;
2869 for (row = 0; row < n_rows; row++)
2871 priv->height += priv->item_padding;
2873 for (col = 0; col < n_columns && items; col++, items = items->next)
2875 GtkIconViewItem *item = items->data;
2877 item->cell_area.x = priv->margin + (col * 2 + 1) * priv->item_padding + col * (priv->column_spacing + item_width);
2878 item->cell_area.width = item_width;
2879 item->cell_area.y = priv->height;
2880 item->cell_area.height = sizes[row].minimum_size;
2885 priv->height += sizes[row].minimum_size + priv->item_padding + priv->row_spacing;
2888 priv->height -= priv->row_spacing;
2889 priv->height += priv->margin;
2890 priv->height = MAX (priv->height, gtk_widget_get_allocated_height (widget));
2894 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2896 /* Clear all item sizes */
2897 g_list_foreach (icon_view->priv->items,
2898 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2900 /* Re-layout the items */
2901 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
2905 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2907 item->cell_area.width = -1;
2908 item->cell_area.height = -1;
2912 gtk_icon_view_paint_item (GtkIconView *icon_view,
2914 GtkIconViewItem *item,
2917 gboolean draw_focus)
2919 GdkRectangle cell_area;
2920 GtkStateFlags state = 0;
2921 GtkCellRendererState flags = 0;
2922 GtkStyleContext *style_context;
2923 GtkWidget *widget = GTK_WIDGET (icon_view);
2924 GtkIconViewPrivate *priv = icon_view->priv;
2926 if (priv->model == NULL)
2929 _gtk_icon_view_set_cell_data (icon_view, item);
2931 style_context = gtk_widget_get_style_context (widget);
2932 state = gtk_widget_get_state_flags (widget);
2934 gtk_style_context_save (style_context);
2935 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2936 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2938 state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
2942 if ((state & GTK_STATE_FLAG_FOCUSED) &&
2943 item == icon_view->priv->cursor_item)
2945 flags |= GTK_CELL_RENDERER_FOCUSED;
2948 state |= GTK_STATE_FLAG_SELECTED;
2949 flags |= GTK_CELL_RENDERER_SELECTED;
2954 state |= GTK_STATE_FLAG_PRELIGHT;
2955 flags |= GTK_CELL_RENDERER_PRELIT;
2958 gtk_style_context_set_state (style_context, state);
2962 gtk_render_background (style_context, cr,
2963 x - icon_view->priv->item_padding,
2964 y - icon_view->priv->item_padding,
2965 item->cell_area.width + icon_view->priv->item_padding * 2,
2966 item->cell_area.height + icon_view->priv->item_padding * 2);
2967 gtk_render_frame (style_context, cr,
2968 x - icon_view->priv->item_padding,
2969 y - icon_view->priv->item_padding,
2970 item->cell_area.width + icon_view->priv->item_padding * 2,
2971 item->cell_area.height + icon_view->priv->item_padding * 2);
2976 cell_area.width = item->cell_area.width;
2977 cell_area.height = item->cell_area.height;
2979 gtk_cell_area_context_allocate (priv->cell_area_context, item->cell_area.width, item->cell_area.height);
2980 gtk_cell_area_render (priv->cell_area, priv->cell_area_context,
2981 widget, cr, &cell_area, &cell_area, flags,
2984 gtk_style_context_restore (style_context);
2988 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2991 GtkStyleContext *context;
2996 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2997 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2998 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2999 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3001 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3003 gtk_style_context_save (context);
3004 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3006 gdk_cairo_rectangle (cr, &rect);
3009 gtk_render_background (context, cr,
3011 rect.width, rect.height);
3012 gtk_render_frame (context, cr,
3014 rect.width, rect.height);
3016 gtk_style_context_restore (context);
3021 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3027 index = gtk_tree_path_get_indices (path)[0];
3029 for (l = icon_view->priv->items; l; l = l->next)
3031 GtkIconViewItem *item = l->data;
3033 if (item->index == index)
3035 gtk_icon_view_queue_draw_item (icon_view, item);
3042 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3043 GtkIconViewItem *item)
3046 GdkRectangle *item_area = &item->cell_area;
3048 rect.x = item_area->x - icon_view->priv->item_padding;
3049 rect.y = item_area->y - icon_view->priv->item_padding;
3050 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3051 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3053 if (icon_view->priv->bin_window)
3054 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3058 _gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3059 GtkIconViewItem *item,
3060 GtkCellRenderer *cursor_cell)
3063 AtkObject *item_obj;
3064 AtkObject *cursor_item_obj;
3066 /* When hitting this path from keynav, the focus cell is
3067 * already set, we dont need to notify the atk object
3068 * but we still need to queue the draw here (in the case
3069 * that the focus cell changes but not the cursor item).
3071 gtk_icon_view_queue_draw_item (icon_view, item);
3073 if (icon_view->priv->cursor_item == item &&
3074 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3077 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3078 if (icon_view->priv->cursor_item != NULL)
3080 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3083 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3084 if (cursor_item_obj != NULL)
3085 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3088 icon_view->priv->cursor_item = item;
3091 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3094 /* Make sure there is a cell in focus initially */
3095 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3096 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3099 /* Notify that accessible focus object has changed */
3100 item_obj = atk_object_ref_accessible_child (obj, item->index);
3102 if (item_obj != NULL)
3104 atk_focus_tracker_notify (item_obj);
3105 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3106 g_object_unref (item_obj);
3111 static GtkIconViewItem *
3112 gtk_icon_view_item_new (void)
3114 GtkIconViewItem *item;
3116 item = g_slice_new0 (GtkIconViewItem);
3118 item->cell_area.width = -1;
3119 item->cell_area.height = -1;
3125 gtk_icon_view_item_free (GtkIconViewItem *item)
3127 g_return_if_fail (item != NULL);
3129 g_slice_free (GtkIconViewItem, item);
3133 _gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3136 gboolean only_in_cell,
3137 GtkCellRenderer **cell_at_pos)
3142 *cell_at_pos = NULL;
3144 for (items = icon_view->priv->items; items; items = items->next)
3146 GtkIconViewItem *item = items->data;
3147 GdkRectangle *item_area = &item->cell_area;
3149 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3150 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3151 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3152 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3154 if (only_in_cell || cell_at_pos)
3156 GtkCellRenderer *cell = NULL;
3158 _gtk_icon_view_set_cell_data (icon_view, item);
3160 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3161 y >= item_area->y && y <= item_area->y + item_area->height)
3163 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
3164 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area,
3165 icon_view->priv->cell_area_context,
3166 GTK_WIDGET (icon_view),
3172 *cell_at_pos = cell;
3175 return cell != NULL ? item : NULL;
3186 _gtk_icon_view_select_item (GtkIconView *icon_view,
3187 GtkIconViewItem *item)
3189 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3190 g_return_if_fail (item != NULL);
3195 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3197 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3198 gtk_icon_view_unselect_all_internal (icon_view);
3200 item->selected = TRUE;
3202 gtk_icon_view_item_selected_changed (icon_view, item);
3203 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3205 gtk_icon_view_queue_draw_item (icon_view, item);
3210 _gtk_icon_view_unselect_item (GtkIconView *icon_view,
3211 GtkIconViewItem *item)
3213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3214 g_return_if_fail (item != NULL);
3216 if (!item->selected)
3219 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3220 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3223 item->selected = FALSE;
3225 gtk_icon_view_item_selected_changed (icon_view, item);
3226 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3228 gtk_icon_view_queue_draw_item (icon_view, item);
3232 verify_items (GtkIconView *icon_view)
3237 for (items = icon_view->priv->items; items; items = items->next)
3239 GtkIconViewItem *item = items->data;
3241 if (item->index != i)
3242 g_error ("List item does not match its index: "
3243 "item index %d and list index %d\n", item->index, i);
3250 gtk_icon_view_row_changed (GtkTreeModel *model,
3255 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3257 /* ignore changes in branches */
3258 if (gtk_tree_path_get_depth (path) > 1)
3261 /* An icon view subclass might add it's own model and populate
3262 * things at init() time instead of waiting for the constructor()
3265 if (icon_view->priv->cell_area)
3266 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3268 /* Here we can use a "grow-only" strategy for optimization
3269 * and only invalidate a single item and queue a relayout
3270 * instead of invalidating the whole thing.
3272 * For now GtkIconView still cant deal with huge models
3273 * so just invalidate the whole thing when the model
3276 gtk_icon_view_invalidate_sizes (icon_view);
3278 verify_items (icon_view);
3282 gtk_icon_view_row_inserted (GtkTreeModel *model,
3287 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3289 GtkIconViewItem *item;
3292 /* ignore changes in branches */
3293 if (gtk_tree_path_get_depth (path) > 1)
3296 index = gtk_tree_path_get_indices(path)[0];
3298 item = gtk_icon_view_item_new ();
3300 item->index = index;
3302 /* FIXME: We can be more efficient here,
3303 we can store a tail pointer and use that when
3304 appending (which is a rather common operation)
3306 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3309 list = g_list_nth (icon_view->priv->items, index + 1);
3310 for (; list; list = list->next)
3317 verify_items (icon_view);
3319 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3323 gtk_icon_view_row_deleted (GtkTreeModel *model,
3327 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3329 GtkIconViewItem *item;
3331 gboolean emit = FALSE;
3333 /* ignore changes in branches */
3334 if (gtk_tree_path_get_depth (path) > 1)
3337 index = gtk_tree_path_get_indices(path)[0];
3339 list = g_list_nth (icon_view->priv->items, index);
3342 if (icon_view->priv->cell_area)
3343 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3345 if (item == icon_view->priv->anchor_item)
3346 icon_view->priv->anchor_item = NULL;
3348 if (item == icon_view->priv->cursor_item)
3349 icon_view->priv->cursor_item = NULL;
3351 if (item == icon_view->priv->last_prelight)
3352 icon_view->priv->last_prelight = NULL;
3357 gtk_icon_view_item_free (item);
3359 for (next = list->next; next; next = next->next)
3366 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3368 verify_items (icon_view);
3370 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3373 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3377 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3378 GtkTreePath *parent,
3383 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3386 GList *items = NULL, *list;
3387 GtkIconViewItem **item_array;
3390 /* ignore changes in branches */
3394 if (icon_view->priv->cell_area)
3395 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3397 length = gtk_tree_model_iter_n_children (model, NULL);
3399 order = g_new (gint, length);
3400 for (i = 0; i < length; i++)
3401 order [new_order[i]] = i;
3403 item_array = g_new (GtkIconViewItem *, length);
3404 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3405 item_array[order[i]] = list->data;
3408 for (i = length - 1; i >= 0; i--)
3410 item_array[i]->index = i;
3411 items = g_list_prepend (items, item_array[i]);
3414 g_free (item_array);
3415 g_list_free (icon_view->priv->items);
3416 icon_view->priv->items = items;
3418 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
3420 verify_items (icon_view);
3424 gtk_icon_view_build_items (GtkIconView *icon_view)
3428 GList *items = NULL;
3430 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3438 GtkIconViewItem *item = gtk_icon_view_item_new ();
3444 items = g_list_prepend (items, item);
3446 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3448 icon_view->priv->items = g_list_reverse (items);
3452 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3455 GtkMovementStep step,
3459 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3460 I_("move-cursor"), 2,
3464 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3469 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3472 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3477 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3484 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3485 GtkMovementStep step,
3488 GdkModifierType state;
3490 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3491 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3492 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3493 step == GTK_MOVEMENT_DISPLAY_LINES ||
3494 step == GTK_MOVEMENT_PAGES ||
3495 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3497 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3500 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3501 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3503 if (gtk_get_current_event_state (&state))
3505 GdkModifierType extend_mod_mask;
3506 GdkModifierType modify_mod_mask;
3509 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3510 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3512 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3513 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3515 if ((state & modify_mod_mask) == modify_mod_mask)
3516 icon_view->priv->modify_selection_pressed = TRUE;
3517 if ((state & extend_mod_mask) == extend_mod_mask)
3518 icon_view->priv->extend_selection_pressed = TRUE;
3520 /* else we assume not pressed */
3524 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3525 case GTK_MOVEMENT_VISUAL_POSITIONS:
3526 gtk_icon_view_move_cursor_left_right (icon_view, count);
3528 case GTK_MOVEMENT_DISPLAY_LINES:
3529 gtk_icon_view_move_cursor_up_down (icon_view, count);
3531 case GTK_MOVEMENT_PAGES:
3532 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3534 case GTK_MOVEMENT_BUFFER_ENDS:
3535 gtk_icon_view_move_cursor_start_end (icon_view, count);
3538 g_assert_not_reached ();
3541 icon_view->priv->modify_selection_pressed = FALSE;
3542 icon_view->priv->extend_selection_pressed = FALSE;
3544 icon_view->priv->draw_focus = TRUE;
3549 static GtkIconViewItem *
3550 find_item (GtkIconView *icon_view,
3551 GtkIconViewItem *current,
3557 GtkIconViewItem *item;
3559 /* FIXME: this could be more efficient
3561 row = current->row + row_ofs;
3562 col = current->col + col_ofs;
3564 for (items = icon_view->priv->items; items; items = items->next)
3567 if (item->row == row && item->col == col)
3574 static GtkIconViewItem *
3575 find_item_page_up_down (GtkIconView *icon_view,
3576 GtkIconViewItem *current,
3583 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3585 item = g_list_find (icon_view->priv->items, current);
3590 for (next = item->next; next; next = next->next)
3592 if (((GtkIconViewItem *)next->data)->col == col)
3595 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3605 for (next = item->prev; next; next = next->prev)
3607 if (((GtkIconViewItem *)next->data)->col == col)
3610 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3624 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3625 GtkIconViewItem *anchor,
3626 GtkIconViewItem *cursor)
3629 GtkIconViewItem *item;
3630 gint row1, row2, col1, col2;
3631 gboolean dirty = FALSE;
3633 if (anchor->row < cursor->row)
3644 if (anchor->col < cursor->col)
3655 for (items = icon_view->priv->items; items; items = items->next)
3659 if (row1 <= item->row && item->row <= row2 &&
3660 col1 <= item->col && item->col <= col2)
3662 if (!item->selected)
3665 item->selected = TRUE;
3666 gtk_icon_view_item_selected_changed (icon_view, item);
3668 gtk_icon_view_queue_draw_item (icon_view, item);
3676 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3679 GtkIconViewItem *item;
3680 GtkCellRenderer *cell = NULL;
3681 gboolean dirty = FALSE;
3683 GtkDirectionType direction;
3685 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3688 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3690 if (!icon_view->priv->cursor_item)
3695 list = icon_view->priv->items;
3697 list = g_list_last (icon_view->priv->items);
3703 /* Give focus to the first cell initially */
3704 _gtk_icon_view_set_cell_data (icon_view, item);
3705 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3714 item = icon_view->priv->cursor_item;
3715 step = count > 0 ? 1 : -1;
3717 /* Save the current focus cell in case we hit the edge */
3718 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3722 _gtk_icon_view_set_cell_data (icon_view, item);
3724 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3727 item = find_item (icon_view, item, step, 0);
3733 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3735 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3737 gtk_widget_child_focus (toplevel,
3738 direction == GTK_DIR_UP ?
3739 GTK_DIR_TAB_BACKWARD :
3740 GTK_DIR_TAB_FORWARD);
3744 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3748 if (icon_view->priv->modify_selection_pressed ||
3749 !icon_view->priv->extend_selection_pressed ||
3750 !icon_view->priv->anchor_item ||
3751 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3752 icon_view->priv->anchor_item = item;
3754 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3755 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3757 if (!icon_view->priv->modify_selection_pressed &&
3758 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3760 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3761 dirty = gtk_icon_view_select_all_between (icon_view,
3762 icon_view->priv->anchor_item,
3766 gtk_icon_view_scroll_to_item (icon_view, item);
3769 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3773 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3776 GtkIconViewItem *item;
3777 gboolean dirty = FALSE;
3779 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3782 if (!icon_view->priv->cursor_item)
3787 list = icon_view->priv->items;
3789 list = g_list_last (icon_view->priv->items);
3791 item = list ? list->data : NULL;
3794 item = find_item_page_up_down (icon_view,
3795 icon_view->priv->cursor_item,
3798 if (item == icon_view->priv->cursor_item)
3799 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3804 if (icon_view->priv->modify_selection_pressed ||
3805 !icon_view->priv->extend_selection_pressed ||
3806 !icon_view->priv->anchor_item ||
3807 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3808 icon_view->priv->anchor_item = item;
3810 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3812 if (!icon_view->priv->modify_selection_pressed &&
3813 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3815 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3816 dirty = gtk_icon_view_select_all_between (icon_view,
3817 icon_view->priv->anchor_item,
3821 gtk_icon_view_scroll_to_item (icon_view, item);
3824 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3828 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3831 GtkIconViewItem *item;
3832 GtkCellRenderer *cell = NULL;
3833 gboolean dirty = FALSE;
3835 GtkDirectionType direction;
3837 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3840 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3842 if (!icon_view->priv->cursor_item)
3847 list = icon_view->priv->items;
3849 list = g_list_last (icon_view->priv->items);
3855 /* Give focus to the first cell initially */
3856 _gtk_icon_view_set_cell_data (icon_view, item);
3857 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3866 item = icon_view->priv->cursor_item;
3867 step = count > 0 ? 1 : -1;
3869 /* Save the current focus cell in case we hit the edge */
3870 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3874 _gtk_icon_view_set_cell_data (icon_view, item);
3876 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3879 item = find_item (icon_view, item, 0, step);
3885 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3887 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3889 gtk_widget_child_focus (toplevel,
3890 direction == GTK_DIR_LEFT ?
3891 GTK_DIR_TAB_BACKWARD :
3892 GTK_DIR_TAB_FORWARD);
3896 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3900 if (icon_view->priv->modify_selection_pressed ||
3901 !icon_view->priv->extend_selection_pressed ||
3902 !icon_view->priv->anchor_item ||
3903 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3904 icon_view->priv->anchor_item = item;
3906 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3907 _gtk_icon_view_set_cursor_item (icon_view, item, cell);
3909 if (!icon_view->priv->modify_selection_pressed &&
3910 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3912 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3913 dirty = gtk_icon_view_select_all_between (icon_view,
3914 icon_view->priv->anchor_item,
3918 gtk_icon_view_scroll_to_item (icon_view, item);
3921 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3925 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3928 GtkIconViewItem *item;
3930 gboolean dirty = FALSE;
3932 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3936 list = icon_view->priv->items;
3938 list = g_list_last (icon_view->priv->items);
3940 item = list ? list->data : NULL;
3942 if (item == icon_view->priv->cursor_item)
3943 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3948 if (icon_view->priv->modify_selection_pressed ||
3949 !icon_view->priv->extend_selection_pressed ||
3950 !icon_view->priv->anchor_item ||
3951 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3952 icon_view->priv->anchor_item = item;
3954 _gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3956 if (!icon_view->priv->modify_selection_pressed &&
3957 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3959 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3960 dirty = gtk_icon_view_select_all_between (icon_view,
3961 icon_view->priv->anchor_item,
3965 gtk_icon_view_scroll_to_item (icon_view, item);
3968 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3972 * gtk_icon_view_scroll_to_path:
3973 * @icon_view: A #GtkIconView.
3974 * @path: The path of the item to move to.
3975 * @use_align: whether to use alignment arguments, or %FALSE.
3976 * @row_align: The vertical alignment of the item specified by @path.
3977 * @col_align: The horizontal alignment of the item specified by @path.
3979 * Moves the alignments of @icon_view to the position specified by @path.
3980 * @row_align determines where the row is placed, and @col_align determines
3981 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3982 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3985 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3986 * tree does the minimum amount of work to scroll the item onto the screen.
3987 * This means that the item will be scrolled to the edge closest to its current
3988 * position. If the item is currently visible on the screen, nothing is done.
3990 * This function only works if the model is set, and @path is a valid row on
3991 * the model. If the model changes before the @icon_view is realized, the
3992 * centered path will be modified to reflect this change.
3997 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4003 GtkIconViewItem *item = NULL;
4006 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4007 g_return_if_fail (path != NULL);
4008 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4009 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4011 widget = GTK_WIDGET (icon_view);
4013 if (gtk_tree_path_get_depth (path) > 0)
4014 item = g_list_nth_data (icon_view->priv->items,
4015 gtk_tree_path_get_indices(path)[0]);
4017 if (!item || item->cell_area.width < 0 ||
4018 !gtk_widget_get_realized (widget))
4020 if (icon_view->priv->scroll_to_path)
4021 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4023 icon_view->priv->scroll_to_path = NULL;
4026 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4028 icon_view->priv->scroll_to_use_align = use_align;
4029 icon_view->priv->scroll_to_row_align = row_align;
4030 icon_view->priv->scroll_to_col_align = col_align;
4037 GtkAllocation allocation;
4040 GdkRectangle item_area =
4042 item->cell_area.x - icon_view->priv->item_padding,
4043 item->cell_area.y - icon_view->priv->item_padding,
4044 item->cell_area.width + icon_view->priv->item_padding * 2,
4045 item->cell_area.height + icon_view->priv->item_padding * 2
4048 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4050 gtk_widget_get_allocation (widget, &allocation);
4052 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4054 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4055 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4057 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4059 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4060 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4062 gtk_adjustment_changed (icon_view->priv->hadjustment);
4063 gtk_adjustment_changed (icon_view->priv->vadjustment);
4066 gtk_icon_view_scroll_to_item (icon_view, item);
4071 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4072 GtkIconViewItem *item)
4074 GtkIconViewPrivate *priv = icon_view->priv;
4075 GtkWidget *widget = GTK_WIDGET (icon_view);
4076 GtkAdjustment *hadj, *vadj;
4077 GtkAllocation allocation;
4079 GdkRectangle item_area;
4081 item_area.x = item->cell_area.x - priv->item_padding;
4082 item_area.y = item->cell_area.y - priv->item_padding;
4083 item_area.width = item->cell_area.width + priv->item_padding * 2;
4084 item_area.height = item->cell_area.height + priv->item_padding * 2;
4086 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4087 gtk_widget_get_allocation (widget, &allocation);
4089 hadj = icon_view->priv->hadjustment;
4090 vadj = icon_view->priv->vadjustment;
4092 if (y + item_area.y < 0)
4093 gtk_adjustment_set_value (vadj,
4094 gtk_adjustment_get_value (vadj)
4096 else if (y + item_area.y + item_area.height > allocation.height)
4097 gtk_adjustment_set_value (vadj,
4098 gtk_adjustment_get_value (vadj)
4099 + y + item_area.y + item_area.height - allocation.height);
4101 if (x + item_area.x < 0)
4102 gtk_adjustment_set_value (hadj,
4103 gtk_adjustment_get_value (hadj)
4105 else if (x + item_area.x + item_area.width > allocation.width)
4106 gtk_adjustment_set_value (hadj,
4107 gtk_adjustment_get_value (hadj)
4108 + x + item_area.x + item_area.width - allocation.width);
4110 gtk_adjustment_changed (hadj);
4111 gtk_adjustment_changed (vadj);
4114 /* GtkCellLayout implementation */
4117 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4118 GtkCellArea *cell_area)
4120 GtkIconViewPrivate *priv = icon_view->priv;
4122 if (priv->cell_area)
4126 priv->cell_area = cell_area;
4128 priv->cell_area = gtk_cell_area_box_new ();
4130 g_object_ref_sink (priv->cell_area);
4132 if (GTK_IS_ORIENTABLE (priv->cell_area))
4133 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4135 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4137 priv->add_editable_id =
4138 g_signal_connect (priv->cell_area, "add-editable",
4139 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4140 priv->remove_editable_id =
4141 g_signal_connect (priv->cell_area, "remove-editable",
4142 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4144 update_text_cell (icon_view);
4145 update_pixbuf_cell (icon_view);
4148 static GtkCellArea *
4149 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4151 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4152 GtkIconViewPrivate *priv = icon_view->priv;
4154 if (G_UNLIKELY (!priv->cell_area))
4155 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4157 return icon_view->priv->cell_area;
4161 _gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4162 GtkIconViewItem *item)
4167 path = gtk_tree_path_new_from_indices (item->index, -1);
4168 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4170 gtk_tree_path_free (path);
4172 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4173 icon_view->priv->model,
4174 &iter, FALSE, FALSE);
4183 * gtk_icon_view_new:
4185 * Creates a new #GtkIconView widget
4187 * Return value: A newly created #GtkIconView widget
4192 gtk_icon_view_new (void)
4194 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4198 * gtk_icon_view_new_with_area:
4199 * @area: the #GtkCellArea to use to layout cells
4201 * Creates a new #GtkIconView widget using the
4202 * specified @area to layout cells inside the icons.
4204 * Return value: A newly created #GtkIconView widget
4209 gtk_icon_view_new_with_area (GtkCellArea *area)
4211 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4215 * gtk_icon_view_new_with_model:
4216 * @model: The model.
4218 * Creates a new #GtkIconView widget with the model @model.
4220 * Return value: A newly created #GtkIconView widget.
4225 gtk_icon_view_new_with_model (GtkTreeModel *model)
4227 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4231 * gtk_icon_view_convert_widget_to_bin_window_coords:
4232 * @icon_view: a #GtkIconView
4233 * @wx: X coordinate relative to the widget
4234 * @wy: Y coordinate relative to the widget
4235 * @bx: (out): return location for bin_window X coordinate
4236 * @by: (out): return location for bin_window Y coordinate
4238 * Converts widget coordinates to coordinates for the bin_window,
4239 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4244 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4252 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4254 if (icon_view->priv->bin_window)
4255 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4266 * gtk_icon_view_get_path_at_pos:
4267 * @icon_view: A #GtkIconView.
4268 * @x: The x position to be identified
4269 * @y: The y position to be identified
4271 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4272 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4273 * the cell at the specified position.
4274 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4275 * widget coordinates to bin_window coordinates.
4277 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4278 * if no icon exists at that position.
4283 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4287 GtkIconViewItem *item;
4290 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4292 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4297 path = gtk_tree_path_new_from_indices (item->index, -1);
4303 * gtk_icon_view_get_item_at_pos:
4304 * @icon_view: A #GtkIconView.
4305 * @x: The x position to be identified
4306 * @y: The y position to be identified
4307 * @path: (out) (allow-none): Return location for the path, or %NULL
4308 * @cell: (out) (allow-none): Return location for the renderer
4309 * responsible for the cell at (@x, @y), or %NULL
4311 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4312 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4313 * obtains the cell at the specified position. The returned path should
4314 * be freed with gtk_tree_path_free().
4315 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4316 * widget coordinates to bin_window coordinates.
4318 * Return value: %TRUE if an item exists at the specified position
4323 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4327 GtkCellRenderer **cell)
4329 GtkIconViewItem *item;
4330 GtkCellRenderer *renderer = NULL;
4332 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4334 item = _gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4339 *path = gtk_tree_path_new_from_indices (item->index, -1);
4347 return (item != NULL);
4351 * gtk_icon_view_set_tooltip_item:
4352 * @icon_view: a #GtkIconView
4353 * @tooltip: a #GtkTooltip
4354 * @path: a #GtkTreePath
4356 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4357 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4358 * See also gtk_tooltip_set_tip_area().
4363 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4364 GtkTooltip *tooltip,
4367 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4368 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4370 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4374 * gtk_icon_view_set_tooltip_cell:
4375 * @icon_view: a #GtkIconView
4376 * @tooltip: a #GtkTooltip
4377 * @path: a #GtkTreePath
4378 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4380 * Sets the tip area of @tooltip to the area which @cell occupies in
4381 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4383 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4388 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4389 GtkTooltip *tooltip,
4391 GtkCellRenderer *cell)
4394 GtkIconViewItem *item = NULL;
4397 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4398 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4399 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4401 if (gtk_tree_path_get_depth (path) > 0)
4402 item = g_list_nth_data (icon_view->priv->items,
4403 gtk_tree_path_get_indices(path)[0]);
4410 _gtk_icon_view_set_cell_data (icon_view, item);
4411 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item->cell_area.width, item->cell_area.height);
4412 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area,
4413 icon_view->priv->cell_area_context,
4414 GTK_WIDGET (icon_view),
4415 cell, &item->cell_area, &rect);
4419 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4420 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4421 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4422 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4425 if (icon_view->priv->bin_window)
4427 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4432 gtk_tooltip_set_tip_area (tooltip, &rect);
4437 * gtk_icon_view_get_tooltip_context:
4438 * @icon_view: an #GtkIconView
4439 * @x: (inout): the x coordinate (relative to widget coordinates)
4440 * @y: (inout): the y coordinate (relative to widget coordinates)
4441 * @keyboard_tip: whether this is a keyboard tooltip or not
4442 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4443 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4444 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4446 * This function is supposed to be used in a #GtkWidget::query-tooltip
4447 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4448 * which are received in the signal handler, should be passed to this
4449 * function without modification.
4451 * The return value indicates whether there is an icon view item at the given
4452 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4453 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4454 * @model, @path and @iter which have been provided will be set to point to
4455 * that row and the corresponding model. @x and @y will always be converted
4456 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4458 * Return value: whether or not the given tooltip context points to a item
4463 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4466 gboolean keyboard_tip,
4467 GtkTreeModel **model,
4471 GtkTreePath *tmppath = NULL;
4473 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4474 g_return_val_if_fail (x != NULL, FALSE);
4475 g_return_val_if_fail (y != NULL, FALSE);
4479 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4486 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4489 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4494 *model = gtk_icon_view_get_model (icon_view);
4497 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4503 gtk_tree_path_free (tmppath);
4509 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4512 gboolean keyboard_tip,
4513 GtkTooltip *tooltip,
4519 GtkTreeModel *model;
4520 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4522 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4525 &model, &path, &iter))
4528 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4532 gtk_tree_path_free (path);
4536 gtk_tooltip_set_markup (tooltip, str);
4537 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4539 gtk_tree_path_free (path);
4547 * gtk_icon_view_set_tooltip_column:
4548 * @icon_view: a #GtkIconView
4549 * @column: an integer, which is a valid column number for @icon_view's model
4551 * If you only plan to have simple (text-only) tooltips on full items, you
4552 * can use this function to have #GtkIconView handle these automatically
4553 * for you. @column should be set to the column in @icon_view's model
4554 * containing the tooltip texts, or -1 to disable this feature.
4556 * When enabled, #GtkWidget:has-tooltip will be set to %TRUE and
4557 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4559 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4560 * so &, <, etc have to be escaped in the text.
4565 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4568 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4570 if (column == icon_view->priv->tooltip_column)
4575 g_signal_handlers_disconnect_by_func (icon_view,
4576 gtk_icon_view_set_tooltip_query_cb,
4578 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4582 if (icon_view->priv->tooltip_column == -1)
4584 g_signal_connect (icon_view, "query-tooltip",
4585 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4586 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4590 icon_view->priv->tooltip_column = column;
4591 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4595 * gtk_icon_view_get_tooltip_column:
4596 * @icon_view: a #GtkIconView
4598 * Returns the column of @icon_view's model which is being used for
4599 * displaying tooltips on @icon_view's rows.
4601 * Return value: the index of the tooltip column that is currently being
4602 * used, or -1 if this is disabled.
4607 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4609 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4611 return icon_view->priv->tooltip_column;
4615 * gtk_icon_view_get_visible_range:
4616 * @icon_view: A #GtkIconView
4617 * @start_path: (out) (allow-none): Return location for start of region,
4619 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4621 * Sets @start_path and @end_path to be the first and last visible path.
4622 * Note that there may be invisible paths in between.
4624 * Both paths should be freed with gtk_tree_path_free() after use.
4626 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4631 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4632 GtkTreePath **start_path,
4633 GtkTreePath **end_path)
4635 gint start_index = -1;
4636 gint end_index = -1;
4639 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4641 if (icon_view->priv->hadjustment == NULL ||
4642 icon_view->priv->vadjustment == NULL)
4645 if (start_path == NULL && end_path == NULL)
4648 for (icons = icon_view->priv->items; icons; icons = icons->next)
4650 GtkIconViewItem *item = icons->data;
4651 GdkRectangle *item_area = &item->cell_area;
4653 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4654 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4656 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4657 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4659 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4660 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4662 if (start_index == -1)
4663 start_index = item->index;
4664 end_index = item->index;
4668 if (start_path && start_index != -1)
4669 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4670 if (end_path && end_index != -1)
4671 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4673 return start_index != -1;
4677 * gtk_icon_view_selected_foreach:
4678 * @icon_view: A #GtkIconView.
4679 * @func: (scope call): The function to call for each selected icon.
4680 * @data: User data to pass to the function.
4682 * Calls a function for each selected icon. Note that the model or
4683 * selection cannot be modified from within this function.
4688 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4689 GtkIconViewForeachFunc func,
4694 for (list = icon_view->priv->items; list; list = list->next)
4696 GtkIconViewItem *item = list->data;
4697 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4700 (* func) (icon_view, path, data);
4702 gtk_tree_path_free (path);
4707 * gtk_icon_view_set_selection_mode:
4708 * @icon_view: A #GtkIconView.
4709 * @mode: The selection mode
4711 * Sets the selection mode of the @icon_view.
4716 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4717 GtkSelectionMode mode)
4719 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4721 if (mode == icon_view->priv->selection_mode)
4724 if (mode == GTK_SELECTION_NONE ||
4725 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4726 gtk_icon_view_unselect_all (icon_view);
4728 icon_view->priv->selection_mode = mode;
4730 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4734 * gtk_icon_view_get_selection_mode:
4735 * @icon_view: A #GtkIconView.
4737 * Gets the selection mode of the @icon_view.
4739 * Return value: the current selection mode
4744 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4746 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4748 return icon_view->priv->selection_mode;
4752 * gtk_icon_view_set_model:
4753 * @icon_view: A #GtkIconView.
4754 * @model: (allow-none): The model.
4756 * Sets the model for a #GtkIconView.
4757 * If the @icon_view already has a model set, it will remove
4758 * it before setting the new model. If @model is %NULL, then
4759 * it will unset the old model.
4764 gtk_icon_view_set_model (GtkIconView *icon_view,
4765 GtkTreeModel *model)
4767 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4768 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4770 if (icon_view->priv->model == model)
4773 if (icon_view->priv->scroll_to_path)
4775 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4776 icon_view->priv->scroll_to_path = NULL;
4779 /* The area can be NULL while disposing */
4780 if (icon_view->priv->cell_area)
4781 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4787 if (icon_view->priv->pixbuf_column != -1)
4789 column_type = gtk_tree_model_get_column_type (model,
4790 icon_view->priv->pixbuf_column);
4792 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4795 if (icon_view->priv->text_column != -1)
4797 column_type = gtk_tree_model_get_column_type (model,
4798 icon_view->priv->text_column);
4800 g_return_if_fail (column_type == G_TYPE_STRING);
4803 if (icon_view->priv->markup_column != -1)
4805 column_type = gtk_tree_model_get_column_type (model,
4806 icon_view->priv->markup_column);
4808 g_return_if_fail (column_type == G_TYPE_STRING);
4813 if (icon_view->priv->model)
4815 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4816 gtk_icon_view_row_changed,
4818 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4819 gtk_icon_view_row_inserted,
4821 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4822 gtk_icon_view_row_deleted,
4824 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4825 gtk_icon_view_rows_reordered,
4828 g_object_unref (icon_view->priv->model);
4830 g_list_free_full (icon_view->priv->items, (GDestroyNotify) gtk_icon_view_item_free);
4831 icon_view->priv->items = NULL;
4832 icon_view->priv->anchor_item = NULL;
4833 icon_view->priv->cursor_item = NULL;
4834 icon_view->priv->last_single_clicked = NULL;
4835 icon_view->priv->last_prelight = NULL;
4836 icon_view->priv->width = 0;
4837 icon_view->priv->height = 0;
4840 icon_view->priv->model = model;
4842 if (icon_view->priv->model)
4844 g_object_ref (icon_view->priv->model);
4845 g_signal_connect (icon_view->priv->model,
4847 G_CALLBACK (gtk_icon_view_row_changed),
4849 g_signal_connect (icon_view->priv->model,
4851 G_CALLBACK (gtk_icon_view_row_inserted),
4853 g_signal_connect (icon_view->priv->model,
4855 G_CALLBACK (gtk_icon_view_row_deleted),
4857 g_signal_connect (icon_view->priv->model,
4859 G_CALLBACK (gtk_icon_view_rows_reordered),
4862 gtk_icon_view_build_items (icon_view);
4865 g_object_notify (G_OBJECT (icon_view), "model");
4867 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4871 * gtk_icon_view_get_model:
4872 * @icon_view: a #GtkIconView
4874 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4877 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4878 * currently being used.
4883 gtk_icon_view_get_model (GtkIconView *icon_view)
4885 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4887 return icon_view->priv->model;
4891 update_text_cell (GtkIconView *icon_view)
4893 if (!icon_view->priv->cell_area)
4896 if (icon_view->priv->text_column == -1 &&
4897 icon_view->priv->markup_column == -1)
4899 if (icon_view->priv->text_cell != NULL)
4901 gtk_cell_area_remove (icon_view->priv->cell_area,
4902 icon_view->priv->text_cell);
4903 icon_view->priv->text_cell = NULL;
4908 if (icon_view->priv->text_cell == NULL)
4910 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4912 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4915 if (icon_view->priv->markup_column != -1)
4916 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4917 icon_view->priv->text_cell,
4918 "markup", icon_view->priv->markup_column,
4921 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4922 icon_view->priv->text_cell,
4923 "text", icon_view->priv->text_column,
4926 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4927 g_object_set (icon_view->priv->text_cell,
4928 "alignment", PANGO_ALIGN_CENTER,
4929 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4934 g_object_set (icon_view->priv->text_cell,
4935 "alignment", PANGO_ALIGN_LEFT,
4936 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4944 update_pixbuf_cell (GtkIconView *icon_view)
4946 if (!icon_view->priv->cell_area)
4949 if (icon_view->priv->pixbuf_column == -1)
4951 if (icon_view->priv->pixbuf_cell != NULL)
4953 gtk_cell_area_remove (icon_view->priv->cell_area,
4954 icon_view->priv->pixbuf_cell);
4956 icon_view->priv->pixbuf_cell = NULL;
4961 if (icon_view->priv->pixbuf_cell == NULL)
4963 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4965 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4968 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4969 icon_view->priv->pixbuf_cell,
4970 "pixbuf", icon_view->priv->pixbuf_column,
4973 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4974 g_object_set (icon_view->priv->pixbuf_cell,
4979 g_object_set (icon_view->priv->pixbuf_cell,
4987 * gtk_icon_view_set_text_column:
4988 * @icon_view: A #GtkIconView.
4989 * @column: A column in the currently used model, or -1 to display no text
4991 * Sets the column with text for @icon_view to be @column. The text
4992 * column must be of type #G_TYPE_STRING.
4997 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5000 if (column == icon_view->priv->text_column)
5004 icon_view->priv->text_column = -1;
5007 if (icon_view->priv->model != NULL)
5011 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5013 g_return_if_fail (column_type == G_TYPE_STRING);
5016 icon_view->priv->text_column = column;
5019 if (icon_view->priv->cell_area)
5020 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5022 update_text_cell (icon_view);
5024 gtk_icon_view_invalidate_sizes (icon_view);
5026 g_object_notify (G_OBJECT (icon_view), "text-column");
5030 * gtk_icon_view_get_text_column:
5031 * @icon_view: A #GtkIconView.
5033 * Returns the column with text for @icon_view.
5035 * Returns: the text column, or -1 if it's unset.
5040 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5042 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5044 return icon_view->priv->text_column;
5048 * gtk_icon_view_set_markup_column:
5049 * @icon_view: A #GtkIconView.
5050 * @column: A column in the currently used model, or -1 to display no text
5052 * Sets the column with markup information for @icon_view to be
5053 * @column. The markup column must be of type #G_TYPE_STRING.
5054 * If the markup column is set to something, it overrides
5055 * the text column set by gtk_icon_view_set_text_column().
5060 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5063 if (column == icon_view->priv->markup_column)
5067 icon_view->priv->markup_column = -1;
5070 if (icon_view->priv->model != NULL)
5074 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5076 g_return_if_fail (column_type == G_TYPE_STRING);
5079 icon_view->priv->markup_column = column;
5082 if (icon_view->priv->cell_area)
5083 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5085 update_text_cell (icon_view);
5087 gtk_icon_view_invalidate_sizes (icon_view);
5089 g_object_notify (G_OBJECT (icon_view), "markup-column");
5093 * gtk_icon_view_get_markup_column:
5094 * @icon_view: A #GtkIconView.
5096 * Returns the column with markup text for @icon_view.
5098 * Returns: the markup column, or -1 if it's unset.
5103 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5105 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5107 return icon_view->priv->markup_column;
5111 * gtk_icon_view_set_pixbuf_column:
5112 * @icon_view: A #GtkIconView.
5113 * @column: A column in the currently used model, or -1 to disable
5115 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5116 * column must be of type #GDK_TYPE_PIXBUF
5121 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5124 if (column == icon_view->priv->pixbuf_column)
5128 icon_view->priv->pixbuf_column = -1;
5131 if (icon_view->priv->model != NULL)
5135 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5137 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5140 icon_view->priv->pixbuf_column = column;
5143 if (icon_view->priv->cell_area)
5144 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5146 update_pixbuf_cell (icon_view);
5148 gtk_icon_view_invalidate_sizes (icon_view);
5150 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5155 * gtk_icon_view_get_pixbuf_column:
5156 * @icon_view: A #GtkIconView.
5158 * Returns the column with pixbufs for @icon_view.
5160 * Returns: the pixbuf column, or -1 if it's unset.
5165 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5167 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5169 return icon_view->priv->pixbuf_column;
5173 * gtk_icon_view_select_path:
5174 * @icon_view: A #GtkIconView.
5175 * @path: The #GtkTreePath to be selected.
5177 * Selects the row at @path.
5182 gtk_icon_view_select_path (GtkIconView *icon_view,
5185 GtkIconViewItem *item = NULL;
5187 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5188 g_return_if_fail (icon_view->priv->model != NULL);
5189 g_return_if_fail (path != NULL);
5191 if (gtk_tree_path_get_depth (path) > 0)
5192 item = g_list_nth_data (icon_view->priv->items,
5193 gtk_tree_path_get_indices(path)[0]);
5196 _gtk_icon_view_select_item (icon_view, item);
5200 * gtk_icon_view_unselect_path:
5201 * @icon_view: A #GtkIconView.
5202 * @path: The #GtkTreePath to be unselected.
5204 * Unselects the row at @path.
5209 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5212 GtkIconViewItem *item;
5214 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5215 g_return_if_fail (icon_view->priv->model != NULL);
5216 g_return_if_fail (path != NULL);
5218 item = g_list_nth_data (icon_view->priv->items,
5219 gtk_tree_path_get_indices(path)[0]);
5224 _gtk_icon_view_unselect_item (icon_view, item);
5228 * gtk_icon_view_get_selected_items:
5229 * @icon_view: A #GtkIconView.
5231 * Creates a list of paths of all selected items. Additionally, if you are
5232 * planning on modifying the model after calling this function, you may
5233 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5234 * To do this, you can use gtk_tree_row_reference_new().
5236 * To free the return value, use:
5238 * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
5241 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5246 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5249 GList *selected = NULL;
5251 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5253 for (list = icon_view->priv->items; list != NULL; list = list->next)
5255 GtkIconViewItem *item = list->data;
5259 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5261 selected = g_list_prepend (selected, path);
5269 * gtk_icon_view_select_all:
5270 * @icon_view: A #GtkIconView.
5272 * Selects all the icons. @icon_view must has its selection mode set
5273 * to #GTK_SELECTION_MULTIPLE.
5278 gtk_icon_view_select_all (GtkIconView *icon_view)
5281 gboolean dirty = FALSE;
5283 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5285 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5288 for (items = icon_view->priv->items; items; items = items->next)
5290 GtkIconViewItem *item = items->data;
5292 if (!item->selected)
5295 item->selected = TRUE;
5296 gtk_icon_view_queue_draw_item (icon_view, item);
5301 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5305 * gtk_icon_view_unselect_all:
5306 * @icon_view: A #GtkIconView.
5308 * Unselects all the icons.
5313 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5315 gboolean dirty = FALSE;
5317 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5319 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5322 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5325 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5329 * gtk_icon_view_path_is_selected:
5330 * @icon_view: A #GtkIconView.
5331 * @path: A #GtkTreePath to check selection on.
5333 * Returns %TRUE if the icon pointed to by @path is currently
5334 * selected. If @path does not point to a valid location, %FALSE is returned.
5336 * Return value: %TRUE if @path is selected.
5341 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5344 GtkIconViewItem *item;
5346 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5347 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5348 g_return_val_if_fail (path != NULL, FALSE);
5350 item = g_list_nth_data (icon_view->priv->items,
5351 gtk_tree_path_get_indices(path)[0]);
5356 return item->selected;
5360 * gtk_icon_view_get_item_row:
5361 * @icon_view: a #GtkIconView
5362 * @path: the #GtkTreePath of the item
5364 * Gets the row in which the item @path is currently
5365 * displayed. Row numbers start at 0.
5367 * Returns: The row in which the item is displayed
5372 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5375 GtkIconViewItem *item;
5377 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5378 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5379 g_return_val_if_fail (path != NULL, -1);
5381 item = g_list_nth_data (icon_view->priv->items,
5382 gtk_tree_path_get_indices(path)[0]);
5391 * gtk_icon_view_get_item_column:
5392 * @icon_view: a #GtkIconView
5393 * @path: the #GtkTreePath of the item
5395 * Gets the column in which the item @path is currently
5396 * displayed. Column numbers start at 0.
5398 * Returns: The column in which the item is displayed
5403 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5406 GtkIconViewItem *item;
5408 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5409 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5410 g_return_val_if_fail (path != NULL, -1);
5412 item = g_list_nth_data (icon_view->priv->items,
5413 gtk_tree_path_get_indices(path)[0]);
5422 * gtk_icon_view_item_activated:
5423 * @icon_view: A #GtkIconView
5424 * @path: The #GtkTreePath to be activated
5426 * Activates the item determined by @path.
5431 gtk_icon_view_item_activated (GtkIconView *icon_view,
5434 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5435 g_return_if_fail (path != NULL);
5437 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5441 * gtk_icon_view_set_item_orientation:
5442 * @icon_view: a #GtkIconView
5443 * @orientation: the relative position of texts and icons
5445 * Sets the ::item-orientation property which determines whether the labels
5446 * are drawn beside the icons instead of below.
5451 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5452 GtkOrientation orientation)
5454 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5456 if (icon_view->priv->item_orientation != orientation)
5458 icon_view->priv->item_orientation = orientation;
5460 if (icon_view->priv->cell_area)
5462 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5463 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5464 icon_view->priv->item_orientation);
5466 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5469 gtk_icon_view_invalidate_sizes (icon_view);
5471 update_text_cell (icon_view);
5472 update_pixbuf_cell (icon_view);
5474 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5479 * gtk_icon_view_get_item_orientation:
5480 * @icon_view: a #GtkIconView
5482 * Returns the value of the ::item-orientation property which determines
5483 * whether the labels are drawn beside the icons instead of below.
5485 * Return value: the relative position of texts and icons
5490 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5492 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5493 GTK_ORIENTATION_VERTICAL);
5495 return icon_view->priv->item_orientation;
5499 * gtk_icon_view_set_columns:
5500 * @icon_view: a #GtkIconView
5501 * @columns: the number of columns
5503 * Sets the ::columns property which determines in how
5504 * many columns the icons are arranged. If @columns is
5505 * -1, the number of columns will be chosen automatically
5506 * to fill the available area.
5511 gtk_icon_view_set_columns (GtkIconView *icon_view,
5514 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5516 if (icon_view->priv->columns != columns)
5518 icon_view->priv->columns = columns;
5520 if (icon_view->priv->cell_area)
5521 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5523 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5525 g_object_notify (G_OBJECT (icon_view), "columns");
5530 * gtk_icon_view_get_columns:
5531 * @icon_view: a #GtkIconView
5533 * Returns the value of the ::columns property.
5535 * Return value: the number of columns, or -1
5540 gtk_icon_view_get_columns (GtkIconView *icon_view)
5542 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5544 return icon_view->priv->columns;
5548 * gtk_icon_view_set_item_width:
5549 * @icon_view: a #GtkIconView
5550 * @item_width: the width for each item
5552 * Sets the ::item-width property which specifies the width
5553 * to use for each item. If it is set to -1, the icon view will
5554 * automatically determine a suitable item size.
5559 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5562 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5564 if (icon_view->priv->item_width != item_width)
5566 icon_view->priv->item_width = item_width;
5568 if (icon_view->priv->cell_area)
5569 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5571 gtk_icon_view_invalidate_sizes (icon_view);
5573 update_text_cell (icon_view);
5575 g_object_notify (G_OBJECT (icon_view), "item-width");
5580 * gtk_icon_view_get_item_width:
5581 * @icon_view: a #GtkIconView
5583 * Returns the value of the ::item-width property.
5585 * Return value: the width of a single item, or -1
5590 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5592 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5594 return icon_view->priv->item_width;
5599 * gtk_icon_view_set_spacing:
5600 * @icon_view: a #GtkIconView
5601 * @spacing: the spacing
5603 * Sets the ::spacing property which specifies the space
5604 * which is inserted between the cells (i.e. the icon and
5605 * the text) of an item.
5610 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5613 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5615 if (icon_view->priv->spacing != spacing)
5617 icon_view->priv->spacing = spacing;
5619 if (icon_view->priv->cell_area)
5620 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5622 gtk_icon_view_invalidate_sizes (icon_view);
5624 g_object_notify (G_OBJECT (icon_view), "spacing");
5629 * gtk_icon_view_get_spacing:
5630 * @icon_view: a #GtkIconView
5632 * Returns the value of the ::spacing property.
5634 * Return value: the space between cells
5639 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5641 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5643 return icon_view->priv->spacing;
5647 * gtk_icon_view_set_row_spacing:
5648 * @icon_view: a #GtkIconView
5649 * @row_spacing: the row spacing
5651 * Sets the ::row-spacing property which specifies the space
5652 * which is inserted between the rows of the icon view.
5657 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5660 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5662 if (icon_view->priv->row_spacing != row_spacing)
5664 icon_view->priv->row_spacing = row_spacing;
5666 if (icon_view->priv->cell_area)
5667 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5669 gtk_icon_view_invalidate_sizes (icon_view);
5671 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5676 * gtk_icon_view_get_row_spacing:
5677 * @icon_view: a #GtkIconView
5679 * Returns the value of the ::row-spacing property.
5681 * Return value: the space between rows
5686 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5688 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5690 return icon_view->priv->row_spacing;
5694 * gtk_icon_view_set_column_spacing:
5695 * @icon_view: a #GtkIconView
5696 * @column_spacing: the column spacing
5698 * Sets the ::column-spacing property which specifies the space
5699 * which is inserted between the columns of the icon view.
5704 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5705 gint column_spacing)
5707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5709 if (icon_view->priv->column_spacing != column_spacing)
5711 icon_view->priv->column_spacing = column_spacing;
5713 if (icon_view->priv->cell_area)
5714 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5716 gtk_icon_view_invalidate_sizes (icon_view);
5718 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5723 * gtk_icon_view_get_column_spacing:
5724 * @icon_view: a #GtkIconView
5726 * Returns the value of the ::column-spacing property.
5728 * Return value: the space between columns
5733 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5735 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5737 return icon_view->priv->column_spacing;
5741 * gtk_icon_view_set_margin:
5742 * @icon_view: a #GtkIconView
5743 * @margin: the margin
5745 * Sets the ::margin property which specifies the space
5746 * which is inserted at the top, bottom, left and right
5752 gtk_icon_view_set_margin (GtkIconView *icon_view,
5755 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5757 if (icon_view->priv->margin != margin)
5759 icon_view->priv->margin = margin;
5761 if (icon_view->priv->cell_area)
5762 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5764 gtk_icon_view_invalidate_sizes (icon_view);
5766 g_object_notify (G_OBJECT (icon_view), "margin");
5771 * gtk_icon_view_get_margin:
5772 * @icon_view: a #GtkIconView
5774 * Returns the value of the ::margin property.
5776 * Return value: the space at the borders
5781 gtk_icon_view_get_margin (GtkIconView *icon_view)
5783 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5785 return icon_view->priv->margin;
5789 * gtk_icon_view_set_item_padding:
5790 * @icon_view: a #GtkIconView
5791 * @item_padding: the item padding
5793 * Sets the #GtkIconView:item-padding property which specifies the padding
5794 * around each of the icon view's items.
5799 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5802 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5804 if (icon_view->priv->item_padding != item_padding)
5806 icon_view->priv->item_padding = item_padding;
5808 if (icon_view->priv->cell_area)
5809 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5811 gtk_icon_view_invalidate_sizes (icon_view);
5813 g_object_notify (G_OBJECT (icon_view), "item-padding");
5818 * gtk_icon_view_get_item_padding:
5819 * @icon_view: a #GtkIconView
5821 * Returns the value of the ::item-padding property.
5823 * Return value: the padding around items
5828 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5830 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5832 return icon_view->priv->item_padding;
5835 /* Get/set whether drag_motion requested the drag data and
5836 * drag_data_received should thus not actually insert the data,
5837 * since the data doesn't result from a drop.
5840 set_status_pending (GdkDragContext *context,
5841 GdkDragAction suggested_action)
5843 g_object_set_data (G_OBJECT (context),
5844 I_("gtk-icon-view-status-pending"),
5845 GINT_TO_POINTER (suggested_action));
5848 static GdkDragAction
5849 get_status_pending (GdkDragContext *context)
5851 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5852 "gtk-icon-view-status-pending"));
5856 unset_reorderable (GtkIconView *icon_view)
5858 if (icon_view->priv->reorderable)
5860 icon_view->priv->reorderable = FALSE;
5861 g_object_notify (G_OBJECT (icon_view), "reorderable");
5866 set_source_row (GdkDragContext *context,
5867 GtkTreeModel *model,
5868 GtkTreePath *source_row)
5871 g_object_set_data_full (G_OBJECT (context),
5872 I_("gtk-icon-view-source-row"),
5873 gtk_tree_row_reference_new (model, source_row),
5874 (GDestroyNotify) gtk_tree_row_reference_free);
5876 g_object_set_data_full (G_OBJECT (context),
5877 I_("gtk-icon-view-source-row"),
5882 get_source_row (GdkDragContext *context)
5884 GtkTreeRowReference *ref;
5886 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5889 return gtk_tree_row_reference_get_path (ref);
5896 GtkTreeRowReference *dest_row;
5897 gboolean empty_view_drop;
5898 gboolean drop_append_mode;
5902 dest_row_free (gpointer data)
5904 DestRow *dr = (DestRow *)data;
5906 gtk_tree_row_reference_free (dr->dest_row);
5911 set_dest_row (GdkDragContext *context,
5912 GtkTreeModel *model,
5913 GtkTreePath *dest_row,
5914 gboolean empty_view_drop,
5915 gboolean drop_append_mode)
5921 g_object_set_data_full (G_OBJECT (context),
5922 I_("gtk-icon-view-dest-row"),
5927 dr = g_new0 (DestRow, 1);
5929 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5930 dr->empty_view_drop = empty_view_drop;
5931 dr->drop_append_mode = drop_append_mode;
5932 g_object_set_data_full (G_OBJECT (context),
5933 I_("gtk-icon-view-dest-row"),
5934 dr, (GDestroyNotify) dest_row_free);
5938 get_dest_row (GdkDragContext *context)
5942 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5946 GtkTreePath *path = NULL;
5949 path = gtk_tree_row_reference_get_path (dr->dest_row);
5950 else if (dr->empty_view_drop)
5951 path = gtk_tree_path_new_from_indices (0, -1);
5955 if (path && dr->drop_append_mode)
5956 gtk_tree_path_next (path);
5965 check_model_dnd (GtkTreeModel *model,
5966 GType required_iface,
5967 const gchar *signal)
5969 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5971 g_warning ("You must override the default '%s' handler "
5972 "on GtkIconView when using models that don't support "
5973 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5974 "is to connect to '%s' and call "
5975 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5976 "the default handler from running. Look at the source code "
5977 "for the default handler in gtkiconview.c to get an idea what "
5978 "your handler should do. (gtkiconview.c is in the GTK+ source "
5979 "code.) If you're using GTK+ from a language other than C, "
5980 "there may be a more natural way to override default handlers, e.g. via derivation.",
5981 signal, g_type_name (required_iface), signal);
5989 remove_scroll_timeout (GtkIconView *icon_view)
5991 if (icon_view->priv->scroll_timeout_id != 0)
5993 g_source_remove (icon_view->priv->scroll_timeout_id);
5995 icon_view->priv->scroll_timeout_id = 0;
6000 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6004 gint px, py, width, height;
6005 gint hoffset, voffset;
6007 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6009 gdk_window_get_device_position (window, device, &px, &py, NULL);
6010 gdk_window_get_geometry (window, NULL, NULL, &width, &height);
6012 /* see if we are near the edge. */
6013 voffset = py - 2 * SCROLL_EDGE_SIZE;
6015 voffset = MAX (py - (height - 2 * SCROLL_EDGE_SIZE), 0);
6017 hoffset = px - 2 * SCROLL_EDGE_SIZE;
6019 hoffset = MAX (px - (width - 2 * SCROLL_EDGE_SIZE), 0);
6022 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6023 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6026 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6027 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6031 GtkIconView *icon_view;
6036 drag_scroll_timeout (gpointer datap)
6038 DragScrollData *data = datap;
6040 gtk_icon_view_autoscroll (data->icon_view, data->device);
6046 drag_scroll_data_free (DragScrollData *data)
6048 g_slice_free (DragScrollData, data);
6052 set_destination (GtkIconView *icon_view,
6053 GdkDragContext *context,
6056 GdkDragAction *suggested_action,
6060 GtkTreePath *path = NULL;
6061 GtkIconViewDropPosition pos;
6062 GtkIconViewDropPosition old_pos;
6063 GtkTreePath *old_dest_path = NULL;
6064 gboolean can_drop = FALSE;
6066 widget = GTK_WIDGET (icon_view);
6068 *suggested_action = 0;
6071 if (!icon_view->priv->dest_set)
6073 /* someone unset us as a drag dest, note that if
6074 * we return FALSE drag_leave isn't called
6077 gtk_icon_view_set_drag_dest_item (icon_view,
6079 GTK_ICON_VIEW_DROP_LEFT);
6081 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6083 return FALSE; /* no longer a drop site */
6086 *target = gtk_drag_dest_find_target (widget, context,
6087 gtk_drag_dest_get_target_list (widget));
6088 if (*target == GDK_NONE)
6091 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6094 GtkTreeModel *model;
6096 /* the row got dropped on empty space, let's setup a special case
6100 gtk_tree_path_free (path);
6102 model = gtk_icon_view_get_model (icon_view);
6104 n_children = gtk_tree_model_iter_n_children (model, NULL);
6107 pos = GTK_ICON_VIEW_DROP_BELOW;
6108 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6112 pos = GTK_ICON_VIEW_DROP_ABOVE;
6113 path = gtk_tree_path_new_from_indices (0, -1);
6123 gtk_icon_view_get_drag_dest_item (icon_view,
6128 gtk_tree_path_free (old_dest_path);
6130 if (TRUE /* FIXME if the location droppable predicate */)
6138 GtkWidget *source_widget;
6140 *suggested_action = gdk_drag_context_get_suggested_action (context);
6141 source_widget = gtk_drag_get_source_widget (context);
6143 if (source_widget == widget)
6145 /* Default to MOVE, unless the user has
6146 * pressed ctrl or shift to affect available actions
6148 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6149 *suggested_action = GDK_ACTION_MOVE;
6152 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6157 /* can't drop here */
6158 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6160 GTK_ICON_VIEW_DROP_LEFT);
6164 gtk_tree_path_free (path);
6170 get_logical_destination (GtkIconView *icon_view,
6171 gboolean *drop_append_mode)
6173 /* adjust path to point to the row the drop goes in front of */
6174 GtkTreePath *path = NULL;
6175 GtkIconViewDropPosition pos;
6177 *drop_append_mode = FALSE;
6179 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6184 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6185 pos == GTK_ICON_VIEW_DROP_BELOW)
6188 GtkTreeModel *model = icon_view->priv->model;
6190 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6191 !gtk_tree_model_iter_next (model, &iter))
6192 *drop_append_mode = TRUE;
6195 *drop_append_mode = FALSE;
6196 gtk_tree_path_next (path);
6204 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6205 GdkEventMotion *event)
6207 GtkWidget *widget = GTK_WIDGET (icon_view);
6208 GdkDragContext *context;
6209 GtkTreePath *path = NULL;
6211 GtkTreeModel *model;
6212 gboolean retval = FALSE;
6214 if (!icon_view->priv->source_set)
6217 if (icon_view->priv->pressed_button < 0)
6220 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6221 icon_view->priv->press_start_x,
6222 icon_view->priv->press_start_y,
6223 event->x, event->y))
6226 model = gtk_icon_view_get_model (icon_view);
6231 button = icon_view->priv->pressed_button;
6232 icon_view->priv->pressed_button = -1;
6234 path = gtk_icon_view_get_path_at_pos (icon_view,
6235 icon_view->priv->press_start_x,
6236 icon_view->priv->press_start_y);
6241 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6242 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6246 /* FIXME Check whether we're a start button, if not return FALSE and
6250 /* Now we can begin the drag */
6254 context = gtk_drag_begin (widget,
6255 gtk_drag_source_get_target_list (widget),
6256 icon_view->priv->source_actions,
6260 set_source_row (context, model, path);
6264 gtk_tree_path_free (path);
6269 /* Source side drag signals */
6271 gtk_icon_view_drag_begin (GtkWidget *widget,
6272 GdkDragContext *context)
6274 GtkIconView *icon_view;
6275 GtkIconViewItem *item;
6276 cairo_surface_t *icon;
6280 icon_view = GTK_ICON_VIEW (widget);
6282 /* if the user uses a custom DnD impl, we don't set the icon here */
6283 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6286 item = _gtk_icon_view_get_item_at_coords (icon_view,
6287 icon_view->priv->press_start_x,
6288 icon_view->priv->press_start_y,
6292 g_return_if_fail (item != NULL);
6294 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6295 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6297 path = gtk_tree_path_new_from_indices (item->index, -1);
6298 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6299 gtk_tree_path_free (path);
6301 cairo_surface_set_device_offset (icon, -x, -y);
6303 gtk_drag_set_icon_surface (context, icon);
6305 cairo_surface_destroy (icon);
6309 gtk_icon_view_drag_end (GtkWidget *widget,
6310 GdkDragContext *context)
6316 gtk_icon_view_drag_data_get (GtkWidget *widget,
6317 GdkDragContext *context,
6318 GtkSelectionData *selection_data,
6322 GtkIconView *icon_view;
6323 GtkTreeModel *model;
6324 GtkTreePath *source_row;
6326 icon_view = GTK_ICON_VIEW (widget);
6327 model = gtk_icon_view_get_model (icon_view);
6332 if (!icon_view->priv->source_set)
6335 source_row = get_source_row (context);
6337 if (source_row == NULL)
6340 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6341 * any model; for DragSource models there are some other targets
6345 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6346 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6351 /* If drag_data_get does nothing, try providing row data. */
6352 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6353 gtk_tree_set_row_drag_data (selection_data,
6358 gtk_tree_path_free (source_row);
6362 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6363 GdkDragContext *context)
6365 GtkTreeModel *model;
6366 GtkIconView *icon_view;
6367 GtkTreePath *source_row;
6369 icon_view = GTK_ICON_VIEW (widget);
6370 model = gtk_icon_view_get_model (icon_view);
6372 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6375 if (!icon_view->priv->source_set)
6378 source_row = get_source_row (context);
6380 if (source_row == NULL)
6383 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6386 gtk_tree_path_free (source_row);
6388 set_source_row (context, NULL, NULL);
6391 /* Target side drag signals */
6393 gtk_icon_view_drag_leave (GtkWidget *widget,
6394 GdkDragContext *context,
6397 GtkIconView *icon_view;
6399 icon_view = GTK_ICON_VIEW (widget);
6401 /* unset any highlight row */
6402 gtk_icon_view_set_drag_dest_item (icon_view,
6404 GTK_ICON_VIEW_DROP_LEFT);
6406 remove_scroll_timeout (icon_view);
6410 gtk_icon_view_drag_motion (GtkWidget *widget,
6411 GdkDragContext *context,
6416 GtkTreePath *path = NULL;
6417 GtkIconViewDropPosition pos;
6418 GtkIconView *icon_view;
6419 GdkDragAction suggested_action = 0;
6423 icon_view = GTK_ICON_VIEW (widget);
6425 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6428 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6430 /* we only know this *after* set_desination_row */
6431 empty = icon_view->priv->empty_view_drop;
6433 if (path == NULL && !empty)
6435 /* Can't drop here. */
6436 gdk_drag_status (context, 0, time);
6440 if (icon_view->priv->scroll_timeout_id == 0)
6442 DragScrollData *data = g_slice_new (DragScrollData);
6443 data->icon_view = icon_view;
6444 data->device = gdk_drag_context_get_device (context);
6446 icon_view->priv->scroll_timeout_id =
6447 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, (GDestroyNotify) drag_scroll_data_free);
6450 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6452 /* Request data so we can use the source row when
6453 * determining whether to accept the drop
6455 set_status_pending (context, suggested_action);
6456 gtk_drag_get_data (widget, context, target, time);
6460 set_status_pending (context, 0);
6461 gdk_drag_status (context, suggested_action, time);
6466 gtk_tree_path_free (path);
6472 gtk_icon_view_drag_drop (GtkWidget *widget,
6473 GdkDragContext *context,
6478 GtkIconView *icon_view;
6480 GdkDragAction suggested_action = 0;
6481 GdkAtom target = GDK_NONE;
6482 GtkTreeModel *model;
6483 gboolean drop_append_mode;
6485 icon_view = GTK_ICON_VIEW (widget);
6486 model = gtk_icon_view_get_model (icon_view);
6488 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6490 if (!icon_view->priv->dest_set)
6493 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6496 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6499 path = get_logical_destination (icon_view, &drop_append_mode);
6501 if (target != GDK_NONE && path != NULL)
6503 /* in case a motion had requested drag data, change things so we
6504 * treat drag data receives as a drop.
6506 set_status_pending (context, 0);
6507 set_dest_row (context, model, path,
6508 icon_view->priv->empty_view_drop, drop_append_mode);
6512 gtk_tree_path_free (path);
6514 /* Unset this thing */
6515 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6517 if (target != GDK_NONE)
6519 gtk_drag_get_data (widget, context, target, time);
6527 gtk_icon_view_drag_data_received (GtkWidget *widget,
6528 GdkDragContext *context,
6531 GtkSelectionData *selection_data,
6536 gboolean accepted = FALSE;
6537 GtkTreeModel *model;
6538 GtkIconView *icon_view;
6539 GtkTreePath *dest_row;
6540 GdkDragAction suggested_action;
6541 gboolean drop_append_mode;
6543 icon_view = GTK_ICON_VIEW (widget);
6544 model = gtk_icon_view_get_model (icon_view);
6546 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6549 if (!icon_view->priv->dest_set)
6552 suggested_action = get_status_pending (context);
6554 if (suggested_action)
6556 /* We are getting this data due to a request in drag_motion,
6557 * rather than due to a request in drag_drop, so we are just
6558 * supposed to call drag_status, not actually paste in the
6561 path = get_logical_destination (icon_view, &drop_append_mode);
6564 suggested_action = 0;
6566 if (suggested_action)
6568 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6571 suggested_action = 0;
6574 gdk_drag_status (context, suggested_action, time);
6577 gtk_tree_path_free (path);
6579 /* If you can't drop, remove user drop indicator until the next motion */
6580 if (suggested_action == 0)
6581 gtk_icon_view_set_drag_dest_item (icon_view,
6583 GTK_ICON_VIEW_DROP_LEFT);
6588 dest_row = get_dest_row (context);
6590 if (dest_row == NULL)
6593 if (gtk_selection_data_get_length (selection_data) >= 0)
6595 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6601 gtk_drag_finish (context,
6603 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6606 gtk_tree_path_free (dest_row);
6609 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6612 /* Drag-and-Drop support */
6614 * gtk_icon_view_enable_model_drag_source:
6615 * @icon_view: a #GtkIconTreeView
6616 * @start_button_mask: Mask of allowed buttons to start drag
6617 * @targets: (array length=n_targets): the table of targets that the drag will
6619 * @n_targets: the number of items in @targets
6620 * @actions: the bitmask of possible actions for a drag from this
6623 * Turns @icon_view into a drag source for automatic DND. Calling this
6624 * method sets #GtkIconView:reorderable to %FALSE.
6629 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6630 GdkModifierType start_button_mask,
6631 const GtkTargetEntry *targets,
6633 GdkDragAction actions)
6635 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6637 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6639 icon_view->priv->start_button_mask = start_button_mask;
6640 icon_view->priv->source_actions = actions;
6642 icon_view->priv->source_set = TRUE;
6644 unset_reorderable (icon_view);
6648 * gtk_icon_view_enable_model_drag_dest:
6649 * @icon_view: a #GtkIconView
6650 * @targets: (array length=n_targets): the table of targets that the drag will
6652 * @n_targets: the number of items in @targets
6653 * @actions: the bitmask of possible actions for a drag to this
6656 * Turns @icon_view into a drop destination for automatic DND. Calling this
6657 * method sets #GtkIconView:reorderable to %FALSE.
6662 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6663 const GtkTargetEntry *targets,
6665 GdkDragAction actions)
6667 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6669 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6671 icon_view->priv->dest_actions = actions;
6673 icon_view->priv->dest_set = TRUE;
6675 unset_reorderable (icon_view);
6679 * gtk_icon_view_unset_model_drag_source:
6680 * @icon_view: a #GtkIconView
6682 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6683 * method sets #GtkIconView:reorderable to %FALSE.
6688 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6690 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6692 if (icon_view->priv->source_set)
6694 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6695 icon_view->priv->source_set = FALSE;
6698 unset_reorderable (icon_view);
6702 * gtk_icon_view_unset_model_drag_dest:
6703 * @icon_view: a #GtkIconView
6705 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6706 * method sets #GtkIconView:reorderable to %FALSE.
6711 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6713 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6715 if (icon_view->priv->dest_set)
6717 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6718 icon_view->priv->dest_set = FALSE;
6721 unset_reorderable (icon_view);
6724 /* These are useful to implement your own custom stuff. */
6726 * gtk_icon_view_set_drag_dest_item:
6727 * @icon_view: a #GtkIconView
6728 * @path: (allow-none): The path of the item to highlight, or %NULL.
6729 * @pos: Specifies where to drop, relative to the item
6731 * Sets the item that is highlighted for feedback.
6736 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6738 GtkIconViewDropPosition pos)
6740 /* Note; this function is exported to allow a custom DND
6741 * implementation, so it can't touch TreeViewDragInfo
6744 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6746 if (icon_view->priv->dest_item)
6748 GtkTreePath *current_path;
6749 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6750 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6751 icon_view->priv->dest_item = NULL;
6753 gtk_icon_view_queue_draw_path (icon_view, current_path);
6754 gtk_tree_path_free (current_path);
6757 /* special case a drop on an empty model */
6758 icon_view->priv->empty_view_drop = FALSE;
6759 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6760 && gtk_tree_path_get_depth (path) == 1
6761 && gtk_tree_path_get_indices (path)[0] == 0)
6765 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6768 if (n_children == 0)
6769 icon_view->priv->empty_view_drop = TRUE;
6772 icon_view->priv->dest_pos = pos;
6776 icon_view->priv->dest_item =
6777 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6778 icon_view->priv->model, path);
6780 gtk_icon_view_queue_draw_path (icon_view, path);
6785 * gtk_icon_view_get_drag_dest_item:
6786 * @icon_view: a #GtkIconView
6787 * @path: (out) (allow-none): Return location for the path of
6788 * the highlighted item, or %NULL.
6789 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6791 * Gets information about the item that is highlighted for feedback.
6796 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6798 GtkIconViewDropPosition *pos)
6800 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6804 if (icon_view->priv->dest_item)
6805 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6811 *pos = icon_view->priv->dest_pos;
6815 * gtk_icon_view_get_dest_item_at_pos:
6816 * @icon_view: a #GtkIconView
6817 * @drag_x: the position to determine the destination item for
6818 * @drag_y: the position to determine the destination item for
6819 * @path: (out) (allow-none): Return location for the path of the item,
6821 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6823 * Determines the destination item for a given position.
6825 * Return value: whether there is an item at the given position.
6830 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6834 GtkIconViewDropPosition *pos)
6836 GtkIconViewItem *item;
6838 /* Note; this function is exported to allow a custom DND
6839 * implementation, so it can't touch TreeViewDragInfo
6842 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6843 g_return_val_if_fail (drag_x >= 0, FALSE);
6844 g_return_val_if_fail (drag_y >= 0, FALSE);
6845 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6851 item = _gtk_icon_view_get_item_at_coords (icon_view,
6852 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6853 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6860 *path = gtk_tree_path_new_from_indices (item->index, -1);
6864 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6865 *pos = GTK_ICON_VIEW_DROP_LEFT;
6866 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6867 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6868 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6869 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6870 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6871 *pos = GTK_ICON_VIEW_DROP_BELOW;
6873 *pos = GTK_ICON_VIEW_DROP_INTO;
6880 * gtk_icon_view_create_drag_icon:
6881 * @icon_view: a #GtkIconView
6882 * @path: a #GtkTreePath in @icon_view
6884 * Creates a #cairo_surface_t representation of the item at @path.
6885 * This image is used for a drag icon.
6887 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6892 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6896 GtkStyleContext *context;
6898 cairo_surface_t *surface;
6902 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6903 g_return_val_if_fail (path != NULL, NULL);
6905 widget = GTK_WIDGET (icon_view);
6906 context = gtk_widget_get_style_context (widget);
6908 if (!gtk_widget_get_realized (widget))
6911 index = gtk_tree_path_get_indices (path)[0];
6913 for (l = icon_view->priv->items; l; l = l->next)
6915 GtkIconViewItem *item = l->data;
6917 if (index == item->index)
6919 GdkRectangle rect = {
6920 item->cell_area.x - icon_view->priv->item_padding,
6921 item->cell_area.y - icon_view->priv->item_padding,
6922 item->cell_area.width + icon_view->priv->item_padding * 2,
6923 item->cell_area.height + icon_view->priv->item_padding * 2
6926 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6927 CAIRO_CONTENT_COLOR,
6931 cr = cairo_create (surface);
6932 cairo_set_line_width (cr, 1.);
6934 gtk_render_background (context, cr, 0, 0,
6935 rect.width + 2, rect.height + 2);
6939 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6942 gtk_icon_view_paint_item (icon_view, cr, item,
6943 icon_view->priv->item_padding + 1,
6944 icon_view->priv->item_padding + 1, FALSE);
6948 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6949 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6962 * gtk_icon_view_get_reorderable:
6963 * @icon_view: a #GtkIconView
6965 * Retrieves whether the user can reorder the list via drag-and-drop.
6966 * See gtk_icon_view_set_reorderable().
6968 * Return value: %TRUE if the list can be reordered.
6973 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6975 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6977 return icon_view->priv->reorderable;
6980 static const GtkTargetEntry item_targets[] = {
6981 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6986 * gtk_icon_view_set_reorderable:
6987 * @icon_view: A #GtkIconView.
6988 * @reorderable: %TRUE, if the list of items can be reordered.
6990 * This function is a convenience function to allow you to reorder models that
6991 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6992 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6993 * the user can reorder the model by dragging and dropping rows. The
6994 * developer can listen to these changes by connecting to the model's
6995 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6996 * the icon view as a drag source and destination. Therefore, drag and
6997 * drop can not be used in a reorderable view for any other purpose.
6999 * This function does not give you any degree of control over the order -- any
7000 * reordering is allowed. If more control is needed, you should probably
7001 * handle drag and drop manually.
7006 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7007 gboolean reorderable)
7009 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7011 reorderable = reorderable != FALSE;
7013 if (icon_view->priv->reorderable == reorderable)
7018 gtk_icon_view_enable_model_drag_source (icon_view,
7021 G_N_ELEMENTS (item_targets),
7023 gtk_icon_view_enable_model_drag_dest (icon_view,
7025 G_N_ELEMENTS (item_targets),
7030 gtk_icon_view_unset_model_drag_source (icon_view);
7031 gtk_icon_view_unset_model_drag_dest (icon_view);
7034 icon_view->priv->reorderable = reorderable;
7036 g_object_notify (G_OBJECT (icon_view), "reorderable");
7040 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7041 GtkBuilder *builder,
7043 const gchar *tagname,
7044 GMarkupParser *parser,
7047 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7048 tagname, parser, data))
7051 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7052 tagname, parser, data);
7056 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7057 GtkBuilder *builder,
7059 const gchar *tagname,
7062 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7063 child, tagname, data))
7064 parent_buildable_iface->custom_tag_end (buildable, builder,
7065 child, tagname, data);