2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gtkiconview.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrenderer.h"
29 #include "gtkcellareabox.h"
30 #include "gtkcellareacontext.h"
31 #include "gtkcellrenderertext.h"
32 #include "gtkcellrendererpixbuf.h"
33 #include "gtkorientable.h"
34 #include "gtkmarshalers.h"
35 #include "gtkbindings.h"
39 #include "gtkaccessible.h"
40 #include "gtkwindow.h"
42 #include "gtkcombobox.h"
43 #include "gtkscrollable.h"
44 #include "gtksizerequest.h"
45 #include "gtktreednd.h"
46 #include "gtktypebuiltins.h"
47 #include "gtkprivate.h"
49 #include "a11y/gtkcontaineraccessible.h"
54 * @short_description: A widget which displays a list of icons in a grid
56 * #GtkIconView provides an alternative view on a #GtkTreeModel.
57 * It displays the model as a grid of icons with labels. Like
58 * #GtkTreeView, it allows to select one or multiple items
59 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
60 * In addition to selection with the arrow keys, #GtkIconView supports
61 * rubberband selection, which is controlled by dragging the pointer.
63 * Note that if the tree model is backed by an actual tree store (as
64 * opposed to a flat list where the mapping to icons is obvious),
65 * #GtkIconView will only display the first level of the tree and
66 * ignore the tree's branches.
69 #define SCROLL_EDGE_SIZE 15
71 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
73 typedef struct _GtkIconViewItem GtkIconViewItem;
74 struct _GtkIconViewItem
76 /* First member is always the rectangle so it
77 * can be cast to a rectangle. */
78 GdkRectangle cell_area;
86 guint selected_before_rubberbanding : 1;
90 typedef struct _GtkIconViewChild GtkIconViewChild;
91 struct _GtkIconViewChild
97 struct _GtkIconViewPrivate
99 GtkCellArea *cell_area;
100 GtkCellAreaContext *cell_area_context;
102 gulong add_editable_id;
103 gulong remove_editable_id;
104 gulong context_changed_id;
106 GPtrArray *row_contexts;
110 GtkSelectionMode selection_mode;
112 guint layout_idle_id;
114 GdkWindow *bin_window;
122 GtkAdjustment *hadjustment;
123 GtkAdjustment *vadjustment;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
127 GdkDevice *rubberband_device;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
136 GtkIconViewItem *last_single_clicked;
138 GtkOrientation item_orientation;
153 GtkCellRenderer *pixbuf_cell;
154 GtkCellRenderer *text_cell;
157 GdkModifierType start_button_mask;
162 GdkDragAction source_actions;
163 GdkDragAction dest_actions;
165 GtkTreeRowReference *dest_item;
166 GtkIconViewDropPosition dest_pos;
169 GtkTreeRowReference *scroll_to_path;
170 gfloat scroll_to_row_align;
171 gfloat scroll_to_col_align;
172 guint scroll_to_use_align : 1;
174 guint source_set : 1;
176 guint reorderable : 1;
177 guint empty_view_drop :1;
179 guint ctrl_pressed : 1;
180 guint shift_pressed : 1;
182 guint draw_focus : 1;
184 /* GtkScrollablePolicy needs to be checked when
185 * driving the scrollable adjustment values */
186 guint hscroll_policy : 1;
187 guint vscroll_policy : 1;
189 guint doing_rubberband : 1;
203 ACTIVATE_CURSOR_ITEM,
215 PROP_ITEM_ORIENTATION,
228 /* For scrollable interface */
236 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
237 static void gtk_icon_view_dispose (GObject *object);
238 static GObject *gtk_icon_view_constructor (GType type,
239 guint n_construct_properties,
240 GObjectConstructParam *construct_properties);
241 static void gtk_icon_view_set_property (GObject *object,
245 static void gtk_icon_view_get_property (GObject *object,
249 /* GtkWidget vfuncs */
250 static void gtk_icon_view_destroy (GtkWidget *widget);
251 static void gtk_icon_view_realize (GtkWidget *widget);
252 static void gtk_icon_view_unrealize (GtkWidget *widget);
253 static void gtk_icon_view_style_updated (GtkWidget *widget);
254 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
255 GtkStateFlags previous_state);
256 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
259 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
262 static void gtk_icon_view_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static gboolean gtk_icon_view_draw (GtkWidget *widget,
266 static gboolean gtk_icon_view_motion (GtkWidget *widget,
267 GdkEventMotion *event);
268 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
274 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
278 /* GtkContainer vfuncs */
279 static void gtk_icon_view_remove (GtkContainer *container,
281 static void gtk_icon_view_forall (GtkContainer *container,
282 gboolean include_internals,
283 GtkCallback callback,
284 gpointer callback_data);
286 /* GtkIconView vfuncs */
287 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
288 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
289 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
290 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
291 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
293 /* Internal functions */
294 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
295 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
296 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
297 GtkAdjustment *adjustment);
298 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
299 GtkAdjustment *adjustment);
300 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
301 GtkOrientation orientation,
302 GtkAdjustment *adjustment);
303 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
304 GtkIconView *icon_view);
305 static void gtk_icon_view_layout (GtkIconView *icon_view);
306 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
308 GtkIconViewItem *item,
311 gboolean draw_focus);
312 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
314 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
316 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
317 GtkIconViewItem *item);
318 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
319 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
320 GtkIconViewItem *item,
321 GtkCellRenderer *cursor_cell);
322 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
326 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
327 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
328 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
329 GtkIconViewItem *item,
334 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
335 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
336 static void gtk_icon_view_update_rubberband (gpointer data);
337 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
338 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
339 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
342 GtkMovementStep step,
344 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
345 GtkMovementStep step,
347 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
349 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
351 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
353 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
355 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
356 GtkIconViewItem *item);
357 static void gtk_icon_view_select_item (GtkIconView *icon_view,
358 GtkIconViewItem *item);
359 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
360 GtkIconViewItem *item);
361 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
362 GtkIconViewItem *anchor,
363 GtkIconViewItem *cursor);
364 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
367 gboolean only_in_cell,
368 GtkCellRenderer **cell_at_pos);
369 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
370 GtkIconViewItem *item);
372 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
373 GtkCellArea *cell_area);
375 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
377 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
378 GtkIconViewItem *item);
380 static void gtk_icon_view_add_editable (GtkCellArea *area,
381 GtkCellRenderer *renderer,
382 GtkCellEditable *editable,
383 GdkRectangle *cell_area,
385 GtkIconView *icon_view);
386 static void gtk_icon_view_remove_editable (GtkCellArea *area,
387 GtkCellRenderer *renderer,
388 GtkCellEditable *editable,
389 GtkIconView *icon_view);
390 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
392 GtkIconView *icon_view);
393 static void update_text_cell (GtkIconView *icon_view);
394 static void update_pixbuf_cell (GtkIconView *icon_view);
396 /* Source side drag signals */
397 static void gtk_icon_view_drag_begin (GtkWidget *widget,
398 GdkDragContext *context);
399 static void gtk_icon_view_drag_end (GtkWidget *widget,
400 GdkDragContext *context);
401 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
402 GdkDragContext *context,
403 GtkSelectionData *selection_data,
406 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
407 GdkDragContext *context);
409 /* Target side drag signals */
410 static void gtk_icon_view_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
414 GdkDragContext *context,
418 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
419 GdkDragContext *context,
423 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
424 GdkDragContext *context,
427 GtkSelectionData *selection_data,
430 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
431 GdkEventMotion *event);
433 static void remove_scroll_timeout (GtkIconView *icon_view);
436 static GtkBuildableIface *parent_buildable_iface;
437 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
438 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
441 const gchar *tagname,
442 GMarkupParser *parser,
444 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
447 const gchar *tagname,
449 static GType _gtk_icon_view_accessible_get_type (void);
451 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
453 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
454 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
455 gtk_icon_view_cell_layout_init)
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
457 gtk_icon_view_buildable_init)
458 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
461 gtk_icon_view_class_init (GtkIconViewClass *klass)
463 GObjectClass *gobject_class;
464 GtkWidgetClass *widget_class;
465 GtkContainerClass *container_class;
466 GtkBindingSet *binding_set;
468 binding_set = gtk_binding_set_by_class (klass);
470 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
472 gobject_class = (GObjectClass *) klass;
473 widget_class = (GtkWidgetClass *) klass;
474 container_class = (GtkContainerClass *) klass;
476 gobject_class->constructor = gtk_icon_view_constructor;
477 gobject_class->dispose = gtk_icon_view_dispose;
478 gobject_class->set_property = gtk_icon_view_set_property;
479 gobject_class->get_property = gtk_icon_view_get_property;
481 widget_class->destroy = gtk_icon_view_destroy;
482 widget_class->realize = gtk_icon_view_realize;
483 widget_class->unrealize = gtk_icon_view_unrealize;
484 widget_class->style_updated = gtk_icon_view_style_updated;
485 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
486 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
487 widget_class->size_allocate = gtk_icon_view_size_allocate;
488 widget_class->draw = gtk_icon_view_draw;
489 widget_class->motion_notify_event = gtk_icon_view_motion;
490 widget_class->button_press_event = gtk_icon_view_button_press;
491 widget_class->button_release_event = gtk_icon_view_button_release;
492 widget_class->key_press_event = gtk_icon_view_key_press;
493 widget_class->key_release_event = gtk_icon_view_key_release;
494 widget_class->drag_begin = gtk_icon_view_drag_begin;
495 widget_class->drag_end = gtk_icon_view_drag_end;
496 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
497 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
498 widget_class->drag_leave = gtk_icon_view_drag_leave;
499 widget_class->drag_motion = gtk_icon_view_drag_motion;
500 widget_class->drag_drop = gtk_icon_view_drag_drop;
501 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
502 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
504 container_class->remove = gtk_icon_view_remove;
505 container_class->forall = gtk_icon_view_forall;
507 klass->select_all = gtk_icon_view_real_select_all;
508 klass->unselect_all = gtk_icon_view_real_unselect_all;
509 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
510 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
511 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
512 klass->move_cursor = gtk_icon_view_real_move_cursor;
516 * GtkIconView:selection-mode:
518 * The ::selection-mode property specifies the selection mode of
519 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
520 * is enabled, for the other modes, only keyboard selection is possible.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_enum ("selection-mode",
527 P_("Selection mode"),
528 P_("The selection mode"),
529 GTK_TYPE_SELECTION_MODE,
530 GTK_SELECTION_SINGLE,
531 GTK_PARAM_READWRITE));
534 * GtkIconView:pixbuf-column:
536 * The ::pixbuf-column property contains the number of the model column
537 * containing the pixbufs which are displayed. The pixbuf column must be
538 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
539 * display of pixbufs.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_int ("pixbuf-column",
547 P_("Model column used to retrieve the icon pixbuf from"),
549 GTK_PARAM_READWRITE));
552 * GtkIconView:text-column:
554 * The ::text-column property contains the number of the model column
555 * containing the texts which are displayed. The text column must be
556 * of type #G_TYPE_STRING. If this property and the :markup-column
557 * property are both set to -1, no texts are displayed.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_int ("text-column",
565 P_("Model column used to retrieve the text from"),
567 GTK_PARAM_READWRITE));
571 * GtkIconView:markup-column:
573 * The ::markup-column property contains the number of the model column
574 * containing markup information to be displayed. The markup column must be
575 * of type #G_TYPE_STRING. If this property and the :text-column property
576 * are both set to column numbers, it overrides the text column.
577 * If both are set to -1, no texts are displayed.
581 g_object_class_install_property (gobject_class,
583 g_param_spec_int ("markup-column",
585 P_("Model column used to retrieve the text if using Pango markup"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (gobject_class,
591 g_param_spec_object ("model",
592 P_("Icon View Model"),
593 P_("The model for the icon view"),
595 GTK_PARAM_READWRITE));
598 * GtkIconView:columns:
600 * The columns property contains the number of the columns in which the
601 * items should be displayed. If it is -1, the number of columns will
602 * be chosen automatically to fill the available area.
606 g_object_class_install_property (gobject_class,
608 g_param_spec_int ("columns",
609 P_("Number of columns"),
610 P_("Number of columns to display"),
612 GTK_PARAM_READWRITE));
616 * GtkIconView:item-width:
618 * The item-width property specifies the width to use for each item.
619 * If it is set to -1, the icon view will automatically determine a
620 * suitable item size.
624 g_object_class_install_property (gobject_class,
626 g_param_spec_int ("item-width",
627 P_("Width for each item"),
628 P_("The width used for each item"),
630 GTK_PARAM_READWRITE));
633 * GtkIconView:spacing:
635 * The spacing property specifies the space which is inserted between
636 * the cells (i.e. the icon and the text) of an item.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("spacing",
644 P_("Space which is inserted between cells of an item"),
646 GTK_PARAM_READWRITE));
649 * GtkIconView:row-spacing:
651 * The row-spacing property specifies the space which is inserted between
652 * the rows of the icon view.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("row-spacing",
660 P_("Space which is inserted between grid rows"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView:column-spacing:
667 * The column-spacing property specifies the space which is inserted between
668 * the columns of the icon view.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("column-spacing",
675 P_("Column Spacing"),
676 P_("Space which is inserted between grid columns"),
678 GTK_PARAM_READWRITE));
681 * GtkIconView:margin:
683 * The margin property specifies the space which is inserted
684 * at the edges of the icon view.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("margin",
692 P_("Space which is inserted at the edges of the icon view"),
694 GTK_PARAM_READWRITE));
697 * GtkIconView:item-orientation:
699 * The item-orientation property specifies how the cells (i.e. the icon and
700 * the text) of the item are positioned relative to each other.
704 g_object_class_install_property (gobject_class,
705 PROP_ITEM_ORIENTATION,
706 g_param_spec_enum ("item-orientation",
707 P_("Item Orientation"),
708 P_("How the text and icon of each item are positioned relative to each other"),
709 GTK_TYPE_ORIENTATION,
710 GTK_ORIENTATION_VERTICAL,
711 GTK_PARAM_READWRITE));
714 * GtkIconView:reorderable:
716 * The reorderable property specifies if the items can be reordered
721 g_object_class_install_property (gobject_class,
723 g_param_spec_boolean ("reorderable",
725 P_("View is reorderable"),
729 g_object_class_install_property (gobject_class,
731 g_param_spec_int ("tooltip-column",
732 P_("Tooltip Column"),
733 P_("The column in the model containing the tooltip texts for the items"),
737 GTK_PARAM_READWRITE));
740 * GtkIconView:item-padding:
742 * The item-padding property specifies the padding around each
743 * of the icon view's item.
747 g_object_class_install_property (gobject_class,
749 g_param_spec_int ("item-padding",
751 P_("Padding around icon view items"),
753 GTK_PARAM_READWRITE));
756 * GtkIconView:cell-area:
758 * The #GtkCellArea used to layout cell renderers for this view.
760 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
761 * a #GtkCellAreaBox will be used.
765 g_object_class_install_property (gobject_class,
767 g_param_spec_object ("cell-area",
769 P_("The GtkCellArea used to layout cells"),
771 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
773 /* Scrollable interface properties */
774 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
775 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
776 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
777 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
779 /* Style properties */
780 gtk_widget_class_install_style_property (widget_class,
781 g_param_spec_boxed ("selection-box-color",
782 P_("Selection Box Color"),
783 P_("Color of the selection box"),
785 GTK_PARAM_READABLE));
787 gtk_widget_class_install_style_property (widget_class,
788 g_param_spec_uchar ("selection-box-alpha",
789 P_("Selection Box Alpha"),
790 P_("Opacity of the selection box"),
793 GTK_PARAM_READABLE));
797 * GtkIconView::item-activated:
798 * @iconview: the object on which the signal is emitted
799 * @path: the #GtkTreePath for the activated item
801 * The ::item-activated signal is emitted when the method
802 * gtk_icon_view_item_activated() is called or the user double
803 * clicks an item. It is also emitted when a non-editable item
804 * is selected and one of the keys: Space, Return or Enter is
807 icon_view_signals[ITEM_ACTIVATED] =
808 g_signal_new (I_("item-activated"),
809 G_TYPE_FROM_CLASS (gobject_class),
811 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
813 g_cclosure_marshal_VOID__BOXED,
818 * GtkIconView::selection-changed:
819 * @iconview: the object on which the signal is emitted
821 * The ::selection-changed signal is emitted when the selection
822 * (i.e. the set of selected items) changes.
824 icon_view_signals[SELECTION_CHANGED] =
825 g_signal_new (I_("selection-changed"),
826 G_TYPE_FROM_CLASS (gobject_class),
828 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
830 g_cclosure_marshal_VOID__VOID,
834 * GtkIconView::select-all:
835 * @iconview: the object on which the signal is emitted
837 * A <link linkend="keybinding-signals">keybinding signal</link>
838 * which gets emitted when the user selects all items.
840 * Applications should not connect to it, but may emit it with
841 * g_signal_emit_by_name() if they need to control selection
844 * The default binding for this signal is Ctrl-a.
846 icon_view_signals[SELECT_ALL] =
847 g_signal_new (I_("select-all"),
848 G_TYPE_FROM_CLASS (gobject_class),
849 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
850 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
852 g_cclosure_marshal_VOID__VOID,
856 * GtkIconView::unselect-all:
857 * @iconview: the object on which the signal is emitted
859 * A <link linkend="keybinding-signals">keybinding signal</link>
860 * which gets emitted when the user unselects all items.
862 * Applications should not connect to it, but may emit it with
863 * g_signal_emit_by_name() if they need to control selection
866 * The default binding for this signal is Ctrl-Shift-a.
868 icon_view_signals[UNSELECT_ALL] =
869 g_signal_new (I_("unselect-all"),
870 G_TYPE_FROM_CLASS (gobject_class),
871 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
872 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
874 g_cclosure_marshal_VOID__VOID,
878 * GtkIconView::select-cursor-item:
879 * @iconview: the object on which the signal is emitted
881 * A <link linkend="keybinding-signals">keybinding signal</link>
882 * which gets emitted when the user selects the item that is currently
885 * Applications should not connect to it, but may emit it with
886 * g_signal_emit_by_name() if they need to control selection
889 * There is no default binding for this signal.
891 icon_view_signals[SELECT_CURSOR_ITEM] =
892 g_signal_new (I_("select-cursor-item"),
893 G_TYPE_FROM_CLASS (gobject_class),
894 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
895 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
897 g_cclosure_marshal_VOID__VOID,
901 * GtkIconView::toggle-cursor-item:
902 * @iconview: the object on which the signal is emitted
904 * A <link linkend="keybinding-signals">keybinding signal</link>
905 * which gets emitted when the user toggles whether the currently
906 * focused item is selected or not. The exact effect of this
907 * depend on the selection mode.
909 * Applications should not connect to it, but may emit it with
910 * g_signal_emit_by_name() if they need to control selection
913 * There is no default binding for this signal is Ctrl-Space.
915 icon_view_signals[TOGGLE_CURSOR_ITEM] =
916 g_signal_new (I_("toggle-cursor-item"),
917 G_TYPE_FROM_CLASS (gobject_class),
918 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
919 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
921 g_cclosure_marshal_VOID__VOID,
925 * GtkIconView::activate-cursor-item:
926 * @iconview: the object on which the signal is emitted
928 * A <link linkend="keybinding-signals">keybinding signal</link>
929 * which gets emitted when the user activates the currently
932 * Applications should not connect to it, but may emit it with
933 * g_signal_emit_by_name() if they need to control activation
936 * The default bindings for this signal are Space, Return and Enter.
938 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
939 g_signal_new (I_("activate-cursor-item"),
940 G_TYPE_FROM_CLASS (gobject_class),
941 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
942 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
944 _gtk_marshal_BOOLEAN__VOID,
948 * GtkIconView::move-cursor:
949 * @iconview: the object which received the signal
950 * @step: the granularity of the move, as a #GtkMovementStep
951 * @count: the number of @step units to move
953 * The ::move-cursor signal is a
954 * <link linkend="keybinding-signals">keybinding signal</link>
955 * which gets emitted when the user initiates a cursor movement.
957 * Applications should not connect to it, but may emit it with
958 * g_signal_emit_by_name() if they need to control the cursor
961 * The default bindings for this signal include
963 * <listitem>Arrow keys which move by individual steps</listitem>
964 * <listitem>Home/End keys which move to the first/last item</listitem>
965 * <listitem>PageUp/PageDown which move by "pages"</listitem>
968 * All of these will extend the selection when combined with
969 * the Shift modifier.
971 icon_view_signals[MOVE_CURSOR] =
972 g_signal_new (I_("move-cursor"),
973 G_TYPE_FROM_CLASS (gobject_class),
974 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
975 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
977 _gtk_marshal_BOOLEAN__ENUM_INT,
979 GTK_TYPE_MOVEMENT_STEP,
983 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
988 "toggle-cursor-item", 0);
989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
990 "toggle-cursor-item", 0);
992 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
993 "activate-cursor-item", 0);
994 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
995 "activate-cursor-item", 0);
996 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
997 "activate-cursor-item", 0);
998 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
999 "activate-cursor-item", 0);
1000 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1001 "activate-cursor-item", 0);
1003 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1004 GTK_MOVEMENT_DISPLAY_LINES, -1);
1005 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1006 GTK_MOVEMENT_DISPLAY_LINES, -1);
1008 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1009 GTK_MOVEMENT_DISPLAY_LINES, 1);
1010 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1011 GTK_MOVEMENT_DISPLAY_LINES, 1);
1013 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1014 GTK_MOVEMENT_DISPLAY_LINES, -1);
1016 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1017 GTK_MOVEMENT_DISPLAY_LINES, 1);
1019 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1020 GTK_MOVEMENT_BUFFER_ENDS, -1);
1021 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1022 GTK_MOVEMENT_BUFFER_ENDS, -1);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1025 GTK_MOVEMENT_BUFFER_ENDS, 1);
1026 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1027 GTK_MOVEMENT_BUFFER_ENDS, 1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1030 GTK_MOVEMENT_PAGES, -1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1032 GTK_MOVEMENT_PAGES, -1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1035 GTK_MOVEMENT_PAGES, 1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1037 GTK_MOVEMENT_PAGES, 1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1040 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1042 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1044 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1045 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1046 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1047 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1049 gtk_widget_class_set_accessible_type (widget_class, _gtk_icon_view_accessible_get_type ());
1053 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1055 parent_buildable_iface = g_type_interface_peek_parent (iface);
1056 iface->add_child = _gtk_cell_layout_buildable_add_child;
1057 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1058 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1062 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1064 iface->get_area = gtk_icon_view_cell_layout_get_area;
1068 gtk_icon_view_init (GtkIconView *icon_view)
1070 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1072 GtkIconViewPrivate);
1074 icon_view->priv->width = 0;
1075 icon_view->priv->height = 0;
1076 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1077 icon_view->priv->pressed_button = -1;
1078 icon_view->priv->press_start_x = -1;
1079 icon_view->priv->press_start_y = -1;
1080 icon_view->priv->text_column = -1;
1081 icon_view->priv->markup_column = -1;
1082 icon_view->priv->pixbuf_column = -1;
1083 icon_view->priv->text_cell = NULL;
1084 icon_view->priv->pixbuf_cell = NULL;
1085 icon_view->priv->tooltip_column = -1;
1087 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1089 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1091 icon_view->priv->columns = -1;
1092 icon_view->priv->item_width = -1;
1093 icon_view->priv->spacing = 0;
1094 icon_view->priv->row_spacing = 6;
1095 icon_view->priv->column_spacing = 6;
1096 icon_view->priv->margin = 6;
1097 icon_view->priv->item_padding = 6;
1099 icon_view->priv->draw_focus = TRUE;
1101 icon_view->priv->row_contexts =
1102 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1105 /* GObject methods */
1107 gtk_icon_view_constructor (GType type,
1108 guint n_construct_properties,
1109 GObjectConstructParam *construct_properties)
1111 GtkIconView *icon_view;
1114 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1115 (type, n_construct_properties, construct_properties);
1117 icon_view = (GtkIconView *) object;
1119 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1125 gtk_icon_view_dispose (GObject *object)
1127 GtkIconView *icon_view;
1128 GtkIconViewPrivate *priv;
1130 icon_view = GTK_ICON_VIEW (object);
1131 priv = icon_view->priv;
1133 if (priv->cell_area_context)
1135 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1136 priv->context_changed_id = 0;
1138 g_object_unref (priv->cell_area_context);
1139 priv->cell_area_context = NULL;
1142 if (priv->row_contexts)
1144 g_ptr_array_free (priv->row_contexts, TRUE);
1145 priv->row_contexts = NULL;
1148 if (priv->cell_area)
1150 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1152 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1153 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1154 priv->add_editable_id = 0;
1155 priv->remove_editable_id = 0;
1157 g_object_unref (priv->cell_area);
1158 priv->cell_area = NULL;
1161 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1165 gtk_icon_view_set_property (GObject *object,
1167 const GValue *value,
1170 GtkIconView *icon_view;
1173 icon_view = GTK_ICON_VIEW (object);
1177 case PROP_SELECTION_MODE:
1178 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1180 case PROP_PIXBUF_COLUMN:
1181 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1183 case PROP_TEXT_COLUMN:
1184 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1186 case PROP_MARKUP_COLUMN:
1187 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1190 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1192 case PROP_ITEM_ORIENTATION:
1193 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1196 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1198 case PROP_ITEM_WIDTH:
1199 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1202 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1204 case PROP_ROW_SPACING:
1205 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1207 case PROP_COLUMN_SPACING:
1208 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1211 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1213 case PROP_REORDERABLE:
1214 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1217 case PROP_TOOLTIP_COLUMN:
1218 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1221 case PROP_ITEM_PADDING:
1222 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1225 case PROP_CELL_AREA:
1226 /* Construct-only, can only be assigned once */
1227 area = g_value_get_object (value);
1230 if (icon_view->priv->cell_area != NULL)
1232 g_warning ("cell-area has already been set, ignoring construct property");
1233 g_object_ref_sink (area);
1234 g_object_unref (area);
1237 gtk_icon_view_ensure_cell_area (icon_view, area);
1241 case PROP_HADJUSTMENT:
1242 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1244 case PROP_VADJUSTMENT:
1245 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1247 case PROP_HSCROLL_POLICY:
1248 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1249 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1251 case PROP_VSCROLL_POLICY:
1252 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1253 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1263 gtk_icon_view_get_property (GObject *object,
1268 GtkIconView *icon_view;
1270 icon_view = GTK_ICON_VIEW (object);
1274 case PROP_SELECTION_MODE:
1275 g_value_set_enum (value, icon_view->priv->selection_mode);
1277 case PROP_PIXBUF_COLUMN:
1278 g_value_set_int (value, icon_view->priv->pixbuf_column);
1280 case PROP_TEXT_COLUMN:
1281 g_value_set_int (value, icon_view->priv->text_column);
1283 case PROP_MARKUP_COLUMN:
1284 g_value_set_int (value, icon_view->priv->markup_column);
1287 g_value_set_object (value, icon_view->priv->model);
1289 case PROP_ITEM_ORIENTATION:
1290 g_value_set_enum (value, icon_view->priv->item_orientation);
1293 g_value_set_int (value, icon_view->priv->columns);
1295 case PROP_ITEM_WIDTH:
1296 g_value_set_int (value, icon_view->priv->item_width);
1299 g_value_set_int (value, icon_view->priv->spacing);
1301 case PROP_ROW_SPACING:
1302 g_value_set_int (value, icon_view->priv->row_spacing);
1304 case PROP_COLUMN_SPACING:
1305 g_value_set_int (value, icon_view->priv->column_spacing);
1308 g_value_set_int (value, icon_view->priv->margin);
1310 case PROP_REORDERABLE:
1311 g_value_set_boolean (value, icon_view->priv->reorderable);
1313 case PROP_TOOLTIP_COLUMN:
1314 g_value_set_int (value, icon_view->priv->tooltip_column);
1317 case PROP_ITEM_PADDING:
1318 g_value_set_int (value, icon_view->priv->item_padding);
1321 case PROP_CELL_AREA:
1322 g_value_set_object (value, icon_view->priv->cell_area);
1325 case PROP_HADJUSTMENT:
1326 g_value_set_object (value, icon_view->priv->hadjustment);
1328 case PROP_VADJUSTMENT:
1329 g_value_set_object (value, icon_view->priv->vadjustment);
1331 case PROP_HSCROLL_POLICY:
1332 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1334 case PROP_VSCROLL_POLICY:
1335 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1339 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1344 /* GtkWidget methods */
1346 gtk_icon_view_destroy (GtkWidget *widget)
1348 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1350 gtk_icon_view_set_model (icon_view, NULL);
1352 if (icon_view->priv->layout_idle_id != 0)
1354 g_source_remove (icon_view->priv->layout_idle_id);
1355 icon_view->priv->layout_idle_id = 0;
1358 if (icon_view->priv->scroll_to_path != NULL)
1360 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1361 icon_view->priv->scroll_to_path = NULL;
1364 remove_scroll_timeout (icon_view);
1366 if (icon_view->priv->hadjustment != NULL)
1368 g_object_unref (icon_view->priv->hadjustment);
1369 icon_view->priv->hadjustment = NULL;
1372 if (icon_view->priv->vadjustment != NULL)
1374 g_object_unref (icon_view->priv->vadjustment);
1375 icon_view->priv->vadjustment = NULL;
1378 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1382 gtk_icon_view_realize (GtkWidget *widget)
1384 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1385 GtkAllocation allocation;
1387 GdkWindowAttr attributes;
1388 gint attributes_mask;
1389 GtkStyleContext *context;
1391 gtk_widget_set_realized (widget, TRUE);
1393 gtk_widget_get_allocation (widget, &allocation);
1395 /* Make the main, clipping window */
1396 attributes.window_type = GDK_WINDOW_CHILD;
1397 attributes.x = allocation.x;
1398 attributes.y = allocation.y;
1399 attributes.width = allocation.width;
1400 attributes.height = allocation.height;
1401 attributes.wclass = GDK_INPUT_OUTPUT;
1402 attributes.visual = gtk_widget_get_visual (widget);
1403 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1405 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1407 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1408 &attributes, attributes_mask);
1409 gtk_widget_set_window (widget, window);
1410 gdk_window_set_user_data (window, widget);
1412 gtk_widget_get_allocation (widget, &allocation);
1414 /* Make the window for the icon view */
1417 attributes.width = MAX (icon_view->priv->width, allocation.width);
1418 attributes.height = MAX (icon_view->priv->height, allocation.height);
1419 attributes.event_mask = (GDK_EXPOSURE_MASK |
1421 GDK_POINTER_MOTION_MASK |
1422 GDK_BUTTON_PRESS_MASK |
1423 GDK_BUTTON_RELEASE_MASK |
1424 GDK_KEY_PRESS_MASK |
1425 GDK_KEY_RELEASE_MASK) |
1426 gtk_widget_get_events (widget);
1428 icon_view->priv->bin_window = gdk_window_new (window,
1429 &attributes, attributes_mask);
1430 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1432 context = gtk_widget_get_style_context (widget);
1434 gtk_style_context_save (context);
1435 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1436 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1437 gtk_style_context_restore (context);
1439 gdk_window_show (icon_view->priv->bin_window);
1443 gtk_icon_view_unrealize (GtkWidget *widget)
1445 GtkIconView *icon_view;
1447 icon_view = GTK_ICON_VIEW (widget);
1449 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1450 gdk_window_destroy (icon_view->priv->bin_window);
1451 icon_view->priv->bin_window = NULL;
1453 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1457 _gtk_icon_view_update_background (GtkIconView *icon_view)
1459 GtkWidget *widget = GTK_WIDGET (icon_view);
1461 if (gtk_widget_get_realized (widget))
1463 GtkStyleContext *context;
1465 context = gtk_widget_get_style_context (widget);
1467 gtk_style_context_save (context);
1468 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1470 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1471 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1473 gtk_style_context_restore (context);
1478 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1479 GtkStateFlags previous_state)
1481 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1482 gtk_widget_queue_draw (widget);
1486 gtk_icon_view_style_updated (GtkWidget *widget)
1488 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1490 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1491 gtk_widget_queue_resize (widget);
1495 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1499 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1503 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1507 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1511 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1515 for (list = icon_view->priv->children; list; list = list->next)
1517 GtkIconViewChild *child = list->data;
1519 /* totally ignore our child's requisition */
1520 gtk_widget_size_allocate (child->widget, &child->area);
1525 gtk_icon_view_size_allocate (GtkWidget *widget,
1526 GtkAllocation *allocation)
1528 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1530 gtk_widget_set_allocation (widget, allocation);
1532 if (gtk_widget_get_realized (widget))
1534 gdk_window_move_resize (gtk_widget_get_window (widget),
1535 allocation->x, allocation->y,
1536 allocation->width, allocation->height);
1537 gdk_window_resize (icon_view->priv->bin_window,
1538 MAX (icon_view->priv->width, allocation->width),
1539 MAX (icon_view->priv->height, allocation->height));
1542 gtk_icon_view_layout (icon_view);
1544 gtk_icon_view_allocate_children (icon_view);
1546 /* Delay signal emission */
1547 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1548 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1550 gtk_icon_view_set_hadjustment_values (icon_view);
1551 gtk_icon_view_set_vadjustment_values (icon_view);
1553 if (gtk_widget_get_realized (widget) &&
1554 icon_view->priv->scroll_to_path)
1557 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1558 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1559 icon_view->priv->scroll_to_path = NULL;
1561 gtk_icon_view_scroll_to_path (icon_view, path,
1562 icon_view->priv->scroll_to_use_align,
1563 icon_view->priv->scroll_to_row_align,
1564 icon_view->priv->scroll_to_col_align);
1565 gtk_tree_path_free (path);
1568 /* Emit any pending signals now */
1569 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1570 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1574 gtk_icon_view_draw (GtkWidget *widget,
1577 GtkIconView *icon_view;
1581 GtkIconViewDropPosition dest_pos;
1582 GtkIconViewItem *dest_item = NULL;
1584 icon_view = GTK_ICON_VIEW (widget);
1586 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1591 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1593 cairo_set_line_width (cr, 1.);
1595 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1599 dest_index = gtk_tree_path_get_indices (path)[0];
1600 gtk_tree_path_free (path);
1605 for (icons = icon_view->priv->items; icons; icons = icons->next)
1607 GtkIconViewItem *item = icons->data;
1608 GdkRectangle paint_area;
1610 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1611 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1612 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1613 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1617 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1620 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1622 gtk_icon_view_paint_item (icon_view, cr, item,
1623 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1624 icon_view->priv->draw_focus);
1626 if (dest_index == item->index)
1634 dest_pos != GTK_ICON_VIEW_NO_DROP)
1636 GtkStyleContext *context;
1637 GtkStateFlags state;
1638 GdkRectangle rect = { 0 };
1640 context = gtk_widget_get_style_context (widget);
1641 state = gtk_widget_get_state_flags (widget);
1645 case GTK_ICON_VIEW_DROP_INTO:
1646 rect = dest_item->cell_area;
1648 case GTK_ICON_VIEW_DROP_ABOVE:
1649 rect.x = dest_item->cell_area.x;
1650 rect.y = dest_item->cell_area.y - 1;
1651 rect.width = dest_item->cell_area.width;
1654 case GTK_ICON_VIEW_DROP_LEFT:
1655 rect.x = dest_item->cell_area.x - 1;
1656 rect.y = dest_item->cell_area.y;
1658 rect.height = dest_item->cell_area.height;
1660 case GTK_ICON_VIEW_DROP_BELOW:
1661 rect.x = dest_item->cell_area.x;
1662 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1663 rect.width = dest_item->cell_area.width;
1666 case GTK_ICON_VIEW_DROP_RIGHT:
1667 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1668 rect.y = dest_item->cell_area.y;
1670 rect.height = dest_item->cell_area.height;
1671 case GTK_ICON_VIEW_NO_DROP: ;
1675 gtk_style_context_set_state (context, state);
1676 gtk_render_focus (context, cr,
1678 rect.width, rect.height);
1681 if (icon_view->priv->doing_rubberband)
1682 gtk_icon_view_paint_rubberband (icon_view, cr);
1686 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1692 rubberband_scroll_timeout (gpointer data)
1694 GtkIconView *icon_view = data;
1696 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1697 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1698 icon_view->priv->scroll_value_diff);
1700 gtk_icon_view_update_rubberband (icon_view);
1706 gtk_icon_view_motion (GtkWidget *widget,
1707 GdkEventMotion *event)
1709 GtkAllocation allocation;
1710 GtkIconView *icon_view;
1713 icon_view = GTK_ICON_VIEW (widget);
1715 gtk_icon_view_maybe_begin_drag (icon_view, event);
1717 if (icon_view->priv->doing_rubberband)
1719 gtk_icon_view_update_rubberband (widget);
1721 abs_y = event->y - icon_view->priv->height *
1722 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1723 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1724 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1726 gtk_widget_get_allocation (widget, &allocation);
1728 if (abs_y < 0 || abs_y > allocation.height)
1731 icon_view->priv->scroll_value_diff = abs_y;
1733 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1735 icon_view->priv->event_last_x = event->x;
1736 icon_view->priv->event_last_y = event->y;
1738 if (icon_view->priv->scroll_timeout_id == 0)
1739 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1743 remove_scroll_timeout (icon_view);
1750 gtk_icon_view_remove (GtkContainer *container,
1753 GtkIconView *icon_view;
1754 GtkIconViewChild *child = NULL;
1757 icon_view = GTK_ICON_VIEW (container);
1759 tmp_list = icon_view->priv->children;
1762 child = tmp_list->data;
1763 if (child->widget == widget)
1765 gtk_widget_unparent (widget);
1767 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1768 g_list_free_1 (tmp_list);
1773 tmp_list = tmp_list->next;
1778 gtk_icon_view_forall (GtkContainer *container,
1779 gboolean include_internals,
1780 GtkCallback callback,
1781 gpointer callback_data)
1783 GtkIconView *icon_view;
1784 GtkIconViewChild *child = NULL;
1787 icon_view = GTK_ICON_VIEW (container);
1789 tmp_list = icon_view->priv->children;
1792 child = tmp_list->data;
1793 tmp_list = tmp_list->next;
1795 (* callback) (child->widget, callback_data);
1800 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1801 GtkIconViewItem *item)
1804 AtkObject *item_obj;
1806 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1809 item_obj = atk_object_ref_accessible_child (obj, item->index);
1810 if (item_obj != NULL)
1812 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1813 g_object_unref (item_obj);
1819 gtk_icon_view_add_editable (GtkCellArea *area,
1820 GtkCellRenderer *renderer,
1821 GtkCellEditable *editable,
1822 GdkRectangle *cell_area,
1824 GtkIconView *icon_view)
1826 GtkIconViewChild *child;
1827 GtkWidget *widget = GTK_WIDGET (editable);
1829 child = g_new (GtkIconViewChild, 1);
1831 child->widget = widget;
1832 child->area.x = cell_area->x;
1833 child->area.y = cell_area->y;
1834 child->area.width = cell_area->width;
1835 child->area.height = cell_area->height;
1837 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1839 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1840 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1842 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1846 gtk_icon_view_remove_editable (GtkCellArea *area,
1847 GtkCellRenderer *renderer,
1848 GtkCellEditable *editable,
1849 GtkIconView *icon_view)
1853 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1854 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1856 gtk_container_remove (GTK_CONTAINER (icon_view),
1857 GTK_WIDGET (editable));
1859 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1860 gtk_icon_view_queue_draw_path (icon_view, path);
1861 gtk_tree_path_free (path);
1865 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1867 GtkIconView *icon_view)
1869 if (!strcmp (pspec->name, "minimum-width") ||
1870 !strcmp (pspec->name, "natural-width") ||
1871 !strcmp (pspec->name, "minimum-height") ||
1872 !strcmp (pspec->name, "natural-height"))
1873 gtk_icon_view_invalidate_sizes (icon_view);
1877 * gtk_icon_view_set_cursor:
1878 * @icon_view: A #GtkIconView
1879 * @path: A #GtkTreePath
1880 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1881 * @start_editing: %TRUE if the specified cell should start being edited.
1883 * Sets the current keyboard focus to be at @path, and selects it. This is
1884 * useful when you want to focus the user's attention on a particular item.
1885 * If @cell is not %NULL, then focus is given to the cell specified by
1886 * it. Additionally, if @start_editing is %TRUE, then editing should be
1887 * started in the specified cell.
1889 * This function is often followed by <literal>gtk_widget_grab_focus
1890 * (icon_view)</literal> in order to give keyboard focus to the widget.
1891 * Please note that editing can only happen when the widget is realized.
1896 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1898 GtkCellRenderer *cell,
1899 gboolean start_editing)
1901 GtkIconViewItem *item = NULL;
1903 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1904 g_return_if_fail (path != NULL);
1905 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1907 if (icon_view->priv->cell_area)
1908 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1910 if (gtk_tree_path_get_depth (path) == 1)
1911 item = g_list_nth_data (icon_view->priv->items,
1912 gtk_tree_path_get_indices(path)[0]);
1917 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1918 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1920 if (start_editing &&
1921 icon_view->priv->cell_area)
1923 GtkCellAreaContext *context;
1925 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1926 gtk_icon_view_set_cell_data (icon_view, item);
1927 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1928 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1929 0 /* XXX flags */, TRUE);
1934 * gtk_icon_view_get_cursor:
1935 * @icon_view: A #GtkIconView
1936 * @path: (out) (allow-none): Return location for the current cursor path,
1938 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1940 * Fills in @path and @cell with the current cursor path and cell.
1941 * If the cursor isn't currently set, then *@path will be %NULL.
1942 * If no cell currently has focus, then *@cell will be %NULL.
1944 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1946 * Return value: %TRUE if the cursor is set.
1951 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1953 GtkCellRenderer **cell)
1955 GtkIconViewItem *item;
1957 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1959 item = icon_view->priv->cursor_item;
1964 *path = gtk_tree_path_new_from_indices (item->index, -1);
1969 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1970 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1972 return (item != NULL);
1976 gtk_icon_view_button_press (GtkWidget *widget,
1977 GdkEventButton *event)
1979 GtkIconView *icon_view;
1980 GtkIconViewItem *item;
1981 gboolean dirty = FALSE;
1982 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1984 icon_view = GTK_ICON_VIEW (widget);
1986 if (event->window != icon_view->priv->bin_window)
1989 if (!gtk_widget_has_focus (widget))
1990 gtk_widget_grab_focus (widget);
1992 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1994 item = gtk_icon_view_get_item_at_coords (icon_view,
2000 * We consider only the the cells' area as the item area if the
2001 * item is not selected, but if it *is* selected, the complete
2002 * selection rectangle is considered to be part of the item.
2004 if (item != NULL && (cell != NULL || item->selected))
2008 if (gtk_cell_renderer_is_activatable (cell))
2012 gtk_icon_view_scroll_to_item (icon_view, item);
2014 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2016 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2018 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2019 (event->state & GDK_SHIFT_MASK))
2021 gtk_icon_view_unselect_all_internal (icon_view);
2023 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2024 if (!icon_view->priv->anchor_item)
2025 icon_view->priv->anchor_item = item;
2027 gtk_icon_view_select_all_between (icon_view,
2028 icon_view->priv->anchor_item,
2034 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2035 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2036 (event->state & GDK_CONTROL_MASK))
2038 item->selected = !item->selected;
2039 gtk_icon_view_queue_draw_item (icon_view, item);
2044 gtk_icon_view_unselect_all_internal (icon_view);
2046 item->selected = TRUE;
2047 gtk_icon_view_queue_draw_item (icon_view, item);
2050 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2051 icon_view->priv->anchor_item = item;
2054 /* Save press to possibly begin a drag */
2055 if (icon_view->priv->pressed_button < 0)
2057 icon_view->priv->pressed_button = event->button;
2058 icon_view->priv->press_start_x = event->x;
2059 icon_view->priv->press_start_y = event->y;
2062 if (!icon_view->priv->last_single_clicked)
2063 icon_view->priv->last_single_clicked = item;
2065 /* cancel the current editing, if it exists */
2066 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2068 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2070 GtkCellAreaContext *context;
2072 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2074 gtk_icon_view_set_cell_data (icon_view, item);
2075 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2076 GTK_WIDGET (icon_view),
2077 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2082 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2083 !(event->state & GDK_CONTROL_MASK))
2085 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2088 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2089 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2092 /* don't draw keyboard focus around an clicked-on item */
2093 icon_view->priv->draw_focus = FALSE;
2096 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2098 item = gtk_icon_view_get_item_at_coords (icon_view,
2103 if (item && item == icon_view->priv->last_single_clicked)
2107 path = gtk_tree_path_new_from_indices (item->index, -1);
2108 gtk_icon_view_item_activated (icon_view, path);
2109 gtk_tree_path_free (path);
2112 icon_view->priv->last_single_clicked = NULL;
2113 icon_view->priv->pressed_button = -1;
2117 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2119 return event->button == 1;
2123 gtk_icon_view_button_release (GtkWidget *widget,
2124 GdkEventButton *event)
2126 GtkIconView *icon_view;
2128 icon_view = GTK_ICON_VIEW (widget);
2130 if (icon_view->priv->pressed_button == event->button)
2131 icon_view->priv->pressed_button = -1;
2133 gtk_icon_view_stop_rubberbanding (icon_view);
2135 remove_scroll_timeout (icon_view);
2141 gtk_icon_view_key_press (GtkWidget *widget,
2144 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2146 if (icon_view->priv->doing_rubberband)
2148 if (event->keyval == GDK_KEY_Escape)
2149 gtk_icon_view_stop_rubberbanding (icon_view);
2154 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2158 gtk_icon_view_key_release (GtkWidget *widget,
2161 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2163 if (icon_view->priv->doing_rubberband)
2166 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2170 gtk_icon_view_update_rubberband (gpointer data)
2172 GtkIconView *icon_view;
2174 GdkRectangle old_area;
2175 GdkRectangle new_area;
2176 GdkRectangle common;
2177 cairo_region_t *invalid_region;
2179 icon_view = GTK_ICON_VIEW (data);
2181 gdk_window_get_device_position (icon_view->priv->bin_window,
2182 icon_view->priv->rubberband_device,
2188 old_area.x = MIN (icon_view->priv->rubberband_x1,
2189 icon_view->priv->rubberband_x2);
2190 old_area.y = MIN (icon_view->priv->rubberband_y1,
2191 icon_view->priv->rubberband_y2);
2192 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2193 icon_view->priv->rubberband_x1) + 1;
2194 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2195 icon_view->priv->rubberband_y1) + 1;
2197 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2198 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2199 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2200 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2202 invalid_region = cairo_region_create_rectangle (&old_area);
2203 cairo_region_union_rectangle (invalid_region, &new_area);
2205 gdk_rectangle_intersect (&old_area, &new_area, &common);
2206 if (common.width > 2 && common.height > 2)
2208 cairo_region_t *common_region;
2210 /* make sure the border is invalidated */
2216 common_region = cairo_region_create_rectangle (&common);
2218 cairo_region_subtract (invalid_region, common_region);
2219 cairo_region_destroy (common_region);
2222 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2224 cairo_region_destroy (invalid_region);
2226 icon_view->priv->rubberband_x2 = x;
2227 icon_view->priv->rubberband_y2 = y;
2229 gtk_icon_view_update_rubberband_selection (icon_view);
2233 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2240 if (icon_view->priv->rubberband_device)
2243 for (items = icon_view->priv->items; items; items = items->next)
2245 GtkIconViewItem *item = items->data;
2247 item->selected_before_rubberbanding = item->selected;
2250 icon_view->priv->rubberband_x1 = x;
2251 icon_view->priv->rubberband_y1 = y;
2252 icon_view->priv->rubberband_x2 = x;
2253 icon_view->priv->rubberband_y2 = y;
2255 icon_view->priv->doing_rubberband = TRUE;
2256 icon_view->priv->rubberband_device = device;
2258 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2262 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2264 if (!icon_view->priv->doing_rubberband)
2267 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2268 icon_view->priv->rubberband_device);
2270 icon_view->priv->doing_rubberband = FALSE;
2271 icon_view->priv->rubberband_device = NULL;
2273 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2277 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2280 gint x, y, width, height;
2281 gboolean dirty = FALSE;
2283 x = MIN (icon_view->priv->rubberband_x1,
2284 icon_view->priv->rubberband_x2);
2285 y = MIN (icon_view->priv->rubberband_y1,
2286 icon_view->priv->rubberband_y2);
2287 width = ABS (icon_view->priv->rubberband_x1 -
2288 icon_view->priv->rubberband_x2);
2289 height = ABS (icon_view->priv->rubberband_y1 -
2290 icon_view->priv->rubberband_y2);
2292 for (items = icon_view->priv->items; items; items = items->next)
2294 GtkIconViewItem *item = items->data;
2298 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2299 x, y, width, height);
2301 selected = is_in ^ item->selected_before_rubberbanding;
2303 if (item->selected != selected)
2305 item->selected = selected;
2307 gtk_icon_view_queue_draw_item (icon_view, item);
2312 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2317 GdkRectangle hit_rect;
2322 hit_test (GtkCellRenderer *renderer,
2323 const GdkRectangle *cell_area,
2324 const GdkRectangle *cell_background,
2327 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2328 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2329 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2330 MAX (data->hit_rect.y, cell_area->y) > 0)
2333 return (data->hit != FALSE);
2337 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2338 GtkIconViewItem *item,
2344 HitTestData data = { { x, y, width, height }, FALSE };
2345 GtkCellAreaContext *context;
2346 GdkRectangle *item_area = (GdkRectangle *)item;
2348 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2349 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2352 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2354 gtk_icon_view_set_cell_data (icon_view, item);
2355 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2356 GTK_WIDGET (icon_view),
2357 item_area, item_area,
2358 (GtkCellAllocCallback)hit_test, &data);
2364 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2366 gboolean dirty = FALSE;
2369 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2372 for (items = icon_view->priv->items; items; items = items->next)
2374 GtkIconViewItem *item = items->data;
2378 item->selected = FALSE;
2380 gtk_icon_view_queue_draw_item (icon_view, item);
2381 gtk_icon_view_item_selected_changed (icon_view, item);
2389 /* GtkIconView signals */
2391 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2393 gtk_icon_view_select_all (icon_view);
2397 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2399 gtk_icon_view_unselect_all (icon_view);
2403 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2405 gtk_icon_view_unselect_all (icon_view);
2407 if (icon_view->priv->cursor_item != NULL)
2408 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2412 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2415 GtkCellAreaContext *context;
2417 if (!icon_view->priv->cursor_item)
2420 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2422 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2423 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2424 GTK_WIDGET (icon_view),
2425 (GdkRectangle *)icon_view->priv->cursor_item,
2429 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2430 gtk_icon_view_item_activated (icon_view, path);
2431 gtk_tree_path_free (path);
2437 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2439 if (!icon_view->priv->cursor_item)
2442 switch (icon_view->priv->selection_mode)
2444 case GTK_SELECTION_NONE:
2446 case GTK_SELECTION_BROWSE:
2447 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2449 case GTK_SELECTION_SINGLE:
2450 if (icon_view->priv->cursor_item->selected)
2451 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2453 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2455 case GTK_SELECTION_MULTIPLE:
2456 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2457 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2459 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2460 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2465 /* Internal functions */
2467 gtk_icon_view_process_updates (GtkIconView *icon_view)
2469 /* Prior to drawing, we check if a layout has been scheduled. If so,
2470 * do it now that all cell view items have valid sizes before we proceeed
2471 * (and resize the bin_window if required).
2473 if (icon_view->priv->layout_idle_id != 0)
2474 gtk_icon_view_layout (icon_view);
2476 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2480 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2482 GtkAllocation allocation;
2483 GtkAdjustment *adj = icon_view->priv->hadjustment;
2484 gdouble old_page_size;
2490 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2492 old_value = gtk_adjustment_get_value (adj);
2493 old_upper = gtk_adjustment_get_upper (adj);
2494 old_page_size = gtk_adjustment_get_page_size (adj);
2495 new_upper = MAX (allocation.width, icon_view->priv->width);
2497 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2499 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2500 /* Quick explanation:
2501 * In LTR locales, leftmost portion of visible rectangle should stay
2502 * fixed, which means left edge of scrollbar thumb should remain fixed
2503 * and thus adjustment's value should stay the same.
2505 * In RTL locales, we want to keep rightmost portion of visible
2506 * rectangle fixed. This means right edge of thumb should remain fixed.
2507 * In this case, upper - value - page_size should remain constant.
2509 new_value = (new_upper - allocation.width) -
2510 (old_upper - old_value - old_page_size);
2511 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2514 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2516 gtk_adjustment_configure (adj,
2520 allocation.width * 0.1,
2521 allocation.width * 0.9,
2526 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2528 GtkAllocation allocation;
2529 GtkAdjustment *adj = icon_view->priv->vadjustment;
2531 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2533 gtk_adjustment_configure (adj,
2534 gtk_adjustment_get_value (adj),
2536 MAX (allocation.height, icon_view->priv->height),
2537 allocation.height * 0.1,
2538 allocation.height * 0.9,
2543 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2544 GtkAdjustment *adjustment)
2546 GtkIconViewPrivate *priv = icon_view->priv;
2549 if (adjustment && priv->hadjustment == adjustment)
2552 if (priv->hadjustment != NULL)
2554 g_signal_handlers_disconnect_matched (priv->hadjustment,
2555 G_SIGNAL_MATCH_DATA,
2556 0, 0, NULL, NULL, icon_view);
2557 g_object_unref (priv->hadjustment);
2561 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2564 g_signal_connect (adjustment, "value-changed",
2565 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2566 priv->hadjustment = g_object_ref_sink (adjustment);
2567 gtk_icon_view_set_hadjustment_values (icon_view);
2569 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2570 gtk_icon_view_accessible_set_adjustment (atk_obj,
2571 GTK_ORIENTATION_HORIZONTAL,
2574 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2578 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2579 GtkAdjustment *adjustment)
2581 GtkIconViewPrivate *priv = icon_view->priv;
2584 if (adjustment && priv->vadjustment == adjustment)
2587 if (priv->vadjustment != NULL)
2589 g_signal_handlers_disconnect_matched (priv->vadjustment,
2590 G_SIGNAL_MATCH_DATA,
2591 0, 0, NULL, NULL, icon_view);
2592 g_object_unref (priv->vadjustment);
2596 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2599 g_signal_connect (adjustment, "value-changed",
2600 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2601 priv->vadjustment = g_object_ref_sink (adjustment);
2602 gtk_icon_view_set_vadjustment_values (icon_view);
2604 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2605 gtk_icon_view_accessible_set_adjustment (atk_obj,
2606 GTK_ORIENTATION_VERTICAL,
2609 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2613 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2614 GtkIconView *icon_view)
2616 GtkIconViewPrivate *priv = icon_view->priv;
2618 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2620 gdk_window_move (priv->bin_window,
2621 - gtk_adjustment_get_value (priv->hadjustment),
2622 - gtk_adjustment_get_value (priv->vadjustment));
2624 if (icon_view->priv->doing_rubberband)
2625 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2627 gtk_icon_view_process_updates (icon_view);
2632 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2637 gint *maximum_width)
2639 GtkAllocation allocation;
2640 GtkCellAreaContext *context;
2641 GtkIconViewPrivate *priv = icon_view->priv;
2642 GtkWidget *widget = GTK_WIDGET (icon_view);
2643 gint x, current_width;
2644 GList *items, *last_item;
2646 gint max_height = 0;
2649 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2657 current_width += 2 * priv->margin;
2659 gtk_widget_get_allocation (widget, &allocation);
2661 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2662 g_ptr_array_add (priv->row_contexts, context);
2664 /* In the first loop we iterate horizontally until we hit allocation width
2665 * and collect the aligned height-for-width */
2669 GtkIconViewItem *item = items->data;
2670 GdkRectangle *item_area = (GdkRectangle *)item;
2672 item_area->width = item_width;
2674 current_width += item_area->width + icon_view->priv->item_padding * 2;
2676 if (items != first_item)
2678 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2679 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2683 /* Get this item's particular width & height (all alignments are cached by now) */
2684 gtk_icon_view_set_cell_data (icon_view, item);
2685 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2690 current_width += icon_view->priv->column_spacing;
2692 item_area->y = *y + icon_view->priv->item_padding;
2693 item_area->x = x + icon_view->priv->item_padding;
2695 x = current_width - icon_view->priv->margin;
2697 if (current_width > *maximum_width)
2698 *maximum_width = current_width;
2704 items = items->next;
2709 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2710 gtk_cell_area_context_allocate (context, item_width, max_height);
2712 /* In the second loop the item height has been aligned and derived and
2713 * we just set the height and handle rtl layout */
2714 for (items = first_item; items != last_item; items = items->next)
2716 GtkIconViewItem *item = items->data;
2717 GdkRectangle *item_area = (GdkRectangle *)item;
2721 item_area->x = *maximum_width - item_area->width - item_area->x;
2722 item->col = col - 1 - item->col;
2725 /* All items in the same row get the same height */
2726 item_area->height = max_height;
2729 /* Adjust the new y coordinate. */
2730 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2736 adjust_wrap_width (GtkIconView *icon_view)
2738 if (icon_view->priv->text_cell)
2740 gint wrap_width = 50;
2742 /* Here we go with the same old guess, try the icon size and set double
2743 * the size of the first icon found in the list, naive but works much
2745 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2747 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2748 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2749 GTK_WIDGET (icon_view),
2752 wrap_width = MAX (wrap_width * 2, 50);
2755 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2756 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2761 gtk_icon_view_layout (GtkIconView *icon_view)
2763 GtkAllocation allocation;
2766 gint y = 0, maximum_width = 0;
2769 gboolean size_changed = FALSE;
2771 if (icon_view->priv->layout_idle_id != 0)
2773 g_source_remove (icon_view->priv->layout_idle_id);
2774 icon_view->priv->layout_idle_id = 0;
2777 if (icon_view->priv->model == NULL)
2780 widget = GTK_WIDGET (icon_view);
2782 item_width = icon_view->priv->item_width;
2784 /* Update the wrap width for the text cell before going and requesting sizes */
2785 adjust_wrap_width (icon_view);
2787 /* Update the context widths for any invalidated items */
2788 gtk_icon_view_cache_widths (icon_view);
2790 /* Fetch the new item width if needed */
2792 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2795 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2797 icons = icon_view->priv->items;
2798 y += icon_view->priv->margin;
2801 /* Clear the per row contexts */
2802 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2806 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2808 &y, &maximum_width);
2811 while (icons != NULL);
2813 if (maximum_width != icon_view->priv->width)
2815 icon_view->priv->width = maximum_width;
2816 size_changed = TRUE;
2819 y += icon_view->priv->margin;
2821 if (y != icon_view->priv->height)
2823 icon_view->priv->height = y;
2824 size_changed = TRUE;
2827 gtk_icon_view_set_hadjustment_values (icon_view);
2828 gtk_icon_view_set_vadjustment_values (icon_view);
2831 gtk_widget_queue_resize_no_redraw (widget);
2833 gtk_widget_get_allocation (widget, &allocation);
2834 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2835 gdk_window_resize (icon_view->priv->bin_window,
2836 MAX (icon_view->priv->width, allocation.width),
2837 MAX (icon_view->priv->height, allocation.height));
2839 if (icon_view->priv->scroll_to_path)
2843 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2844 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2845 icon_view->priv->scroll_to_path = NULL;
2847 gtk_icon_view_scroll_to_path (icon_view, path,
2848 icon_view->priv->scroll_to_use_align,
2849 icon_view->priv->scroll_to_row_align,
2850 icon_view->priv->scroll_to_col_align);
2851 gtk_tree_path_free (path);
2854 gtk_widget_queue_draw (widget);
2857 /* This ensures that all widths have been cached in the
2858 * context and we have proper alignments to go on.
2861 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2865 g_signal_handler_block (icon_view->priv->cell_area_context,
2866 icon_view->priv->context_changed_id);
2868 for (items = icon_view->priv->items; items; items = items->next)
2870 GtkIconViewItem *item = items->data;
2872 /* Only fetch the width of items with invalidated sizes */
2873 if (item->cell_area.width < 0)
2875 gtk_icon_view_set_cell_data (icon_view, item);
2876 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2877 icon_view->priv->cell_area_context,
2878 GTK_WIDGET (icon_view), NULL, NULL);
2882 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2883 icon_view->priv->context_changed_id);
2887 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2889 /* Clear all item sizes */
2890 g_list_foreach (icon_view->priv->items,
2891 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2893 /* Reset the context */
2894 if (icon_view->priv->cell_area_context)
2896 g_signal_handler_block (icon_view->priv->cell_area_context,
2897 icon_view->priv->context_changed_id);
2898 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2899 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2900 icon_view->priv->context_changed_id);
2903 /* Re-layout the items */
2904 gtk_icon_view_queue_layout (icon_view);
2908 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2910 item->cell_area.width = -1;
2911 item->cell_area.height = -1;
2915 gtk_icon_view_paint_item (GtkIconView *icon_view,
2917 GtkIconViewItem *item,
2920 gboolean draw_focus)
2922 GdkRectangle cell_area;
2923 GtkStateFlags state = 0;
2924 GtkCellRendererState flags = 0;
2925 GtkStyleContext *style_context;
2926 GtkWidget *widget = GTK_WIDGET (icon_view);
2927 GtkIconViewPrivate *priv = icon_view->priv;
2928 GtkCellAreaContext *context;
2930 if (priv->model == NULL)
2933 gtk_icon_view_set_cell_data (icon_view, item);
2935 style_context = gtk_widget_get_style_context (widget);
2937 gtk_style_context_save (style_context);
2938 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2939 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2943 if (gtk_widget_has_focus (widget) &&
2944 item == icon_view->priv->cursor_item)
2946 state |= GTK_STATE_FLAG_FOCUSED;
2947 flags |= GTK_CELL_RENDERER_FOCUSED;
2950 state |= GTK_STATE_FLAG_SELECTED;
2951 flags |= GTK_CELL_RENDERER_SELECTED;
2953 gtk_style_context_set_state (style_context, state);
2955 gtk_render_background (style_context, cr,
2956 x - icon_view->priv->item_padding,
2957 y - icon_view->priv->item_padding,
2958 item->cell_area.width + icon_view->priv->item_padding * 2,
2959 item->cell_area.height + icon_view->priv->item_padding * 2);
2960 gtk_render_frame (style_context, cr,
2961 x - icon_view->priv->item_padding,
2962 y - icon_view->priv->item_padding,
2963 item->cell_area.width + icon_view->priv->item_padding * 2,
2964 item->cell_area.height + icon_view->priv->item_padding * 2);
2969 cell_area.width = item->cell_area.width;
2970 cell_area.height = item->cell_area.height;
2972 context = g_ptr_array_index (priv->row_contexts, item->row);
2973 gtk_cell_area_render (priv->cell_area, context,
2974 widget, cr, &cell_area, &cell_area, flags,
2977 gtk_style_context_restore (style_context);
2981 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2984 GtkStyleContext *context;
2989 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2990 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2991 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2992 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2994 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2996 gtk_style_context_save (context);
2997 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2999 gdk_cairo_rectangle (cr, &rect);
3002 gtk_render_background (context, cr,
3004 rect.width, rect.height);
3005 gtk_render_frame (context, cr,
3007 rect.width, rect.height);
3009 gtk_style_context_restore (context);
3014 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3020 index = gtk_tree_path_get_indices (path)[0];
3022 for (l = icon_view->priv->items; l; l = l->next)
3024 GtkIconViewItem *item = l->data;
3026 if (item->index == index)
3028 gtk_icon_view_queue_draw_item (icon_view, item);
3035 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3036 GtkIconViewItem *item)
3039 GdkRectangle *item_area = (GdkRectangle *)item;
3041 rect.x = item_area->x - icon_view->priv->item_padding;
3042 rect.y = item_area->y - icon_view->priv->item_padding;
3043 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3044 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3046 if (icon_view->priv->bin_window)
3047 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3051 layout_callback (gpointer user_data)
3053 GtkIconView *icon_view;
3055 icon_view = GTK_ICON_VIEW (user_data);
3057 icon_view->priv->layout_idle_id = 0;
3059 gtk_icon_view_layout (icon_view);
3065 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3067 if (icon_view->priv->layout_idle_id != 0)
3070 icon_view->priv->layout_idle_id =
3071 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3072 layout_callback, icon_view, NULL);
3076 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3077 GtkIconViewItem *item,
3078 GtkCellRenderer *cursor_cell)
3081 AtkObject *item_obj;
3082 AtkObject *cursor_item_obj;
3084 /* When hitting this path from keynav, the focus cell is
3085 * already set, we dont need to notify the atk object
3086 * but we still need to queue the draw here (in the case
3087 * that the focus cell changes but not the cursor item).
3089 gtk_icon_view_queue_draw_item (icon_view, item);
3091 if (icon_view->priv->cursor_item == item &&
3092 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3095 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3096 if (icon_view->priv->cursor_item != NULL)
3098 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3101 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3102 if (cursor_item_obj != NULL)
3103 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3106 icon_view->priv->cursor_item = item;
3109 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3112 /* Make sure there is a cell in focus initially */
3113 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3114 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3117 /* Notify that accessible focus object has changed */
3118 item_obj = atk_object_ref_accessible_child (obj, item->index);
3120 if (item_obj != NULL)
3122 atk_focus_tracker_notify (item_obj);
3123 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3124 g_object_unref (item_obj);
3129 static GtkIconViewItem *
3130 gtk_icon_view_item_new (void)
3132 GtkIconViewItem *item;
3134 item = g_slice_new0 (GtkIconViewItem);
3136 item->cell_area.width = -1;
3137 item->cell_area.height = -1;
3143 gtk_icon_view_item_free (GtkIconViewItem *item)
3145 g_return_if_fail (item != NULL);
3147 g_slice_free (GtkIconViewItem, item);
3150 static GtkIconViewItem *
3151 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3154 gboolean only_in_cell,
3155 GtkCellRenderer **cell_at_pos)
3160 *cell_at_pos = NULL;
3162 for (items = icon_view->priv->items; items; items = items->next)
3164 GtkIconViewItem *item = items->data;
3165 GdkRectangle *item_area = (GdkRectangle *)item;
3167 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3168 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3169 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3170 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3172 if (only_in_cell || cell_at_pos)
3174 GtkCellRenderer *cell = NULL;
3175 GtkCellAreaContext *context;
3177 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3178 gtk_icon_view_set_cell_data (icon_view, item);
3180 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3181 y >= item_area->y && y <= item_area->y + item_area->height)
3182 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3183 GTK_WIDGET (icon_view),
3188 *cell_at_pos = cell;
3191 return cell != NULL ? item : NULL;
3202 gtk_icon_view_select_item (GtkIconView *icon_view,
3203 GtkIconViewItem *item)
3205 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3206 g_return_if_fail (item != NULL);
3211 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3213 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3214 gtk_icon_view_unselect_all_internal (icon_view);
3216 item->selected = TRUE;
3218 gtk_icon_view_item_selected_changed (icon_view, item);
3219 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3221 gtk_icon_view_queue_draw_item (icon_view, item);
3226 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3227 GtkIconViewItem *item)
3229 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3230 g_return_if_fail (item != NULL);
3232 if (!item->selected)
3235 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3236 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3239 item->selected = FALSE;
3241 gtk_icon_view_item_selected_changed (icon_view, item);
3242 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3244 gtk_icon_view_queue_draw_item (icon_view, item);
3248 verify_items (GtkIconView *icon_view)
3253 for (items = icon_view->priv->items; items; items = items->next)
3255 GtkIconViewItem *item = items->data;
3257 if (item->index != i)
3258 g_error ("List item does not match its index: "
3259 "item index %d and list index %d\n", item->index, i);
3266 gtk_icon_view_row_changed (GtkTreeModel *model,
3271 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3273 /* ignore changes in branches */
3274 if (gtk_tree_path_get_depth (path) > 1)
3277 /* An icon view subclass might add it's own model and populate
3278 * things at init() time instead of waiting for the constructor()
3281 if (icon_view->priv->cell_area)
3282 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3284 /* Here we can use a "grow-only" strategy for optimization
3285 * and only invalidate a single item and queue a relayout
3286 * instead of invalidating the whole thing.
3288 * For now GtkIconView still cant deal with huge models
3289 * so just invalidate the whole thing when the model
3292 gtk_icon_view_invalidate_sizes (icon_view);
3294 verify_items (icon_view);
3298 gtk_icon_view_row_inserted (GtkTreeModel *model,
3303 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3305 GtkIconViewItem *item;
3306 gboolean iters_persist;
3309 /* ignore changes in branches */
3310 if (gtk_tree_path_get_depth (path) > 1)
3313 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3315 index = gtk_tree_path_get_indices(path)[0];
3317 item = gtk_icon_view_item_new ();
3322 item->index = index;
3324 /* FIXME: We can be more efficient here,
3325 we can store a tail pointer and use that when
3326 appending (which is a rather common operation)
3328 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3331 list = g_list_nth (icon_view->priv->items, index + 1);
3332 for (; list; list = list->next)
3339 verify_items (icon_view);
3341 gtk_icon_view_queue_layout (icon_view);
3345 gtk_icon_view_row_deleted (GtkTreeModel *model,
3349 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3351 GtkIconViewItem *item;
3353 gboolean emit = FALSE;
3355 /* ignore changes in branches */
3356 if (gtk_tree_path_get_depth (path) > 1)
3359 index = gtk_tree_path_get_indices(path)[0];
3361 list = g_list_nth (icon_view->priv->items, index);
3364 if (icon_view->priv->cell_area)
3365 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3367 if (item == icon_view->priv->anchor_item)
3368 icon_view->priv->anchor_item = NULL;
3370 if (item == icon_view->priv->cursor_item)
3371 icon_view->priv->cursor_item = NULL;
3376 gtk_icon_view_item_free (item);
3378 for (next = list->next; next; next = next->next)
3385 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3387 verify_items (icon_view);
3389 gtk_icon_view_queue_layout (icon_view);
3392 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3396 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3397 GtkTreePath *parent,
3402 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3405 GList *items = NULL, *list;
3406 GtkIconViewItem **item_array;
3409 /* ignore changes in branches */
3413 if (icon_view->priv->cell_area)
3414 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3416 length = gtk_tree_model_iter_n_children (model, NULL);
3418 order = g_new (gint, length);
3419 for (i = 0; i < length; i++)
3420 order [new_order[i]] = i;
3422 item_array = g_new (GtkIconViewItem *, length);
3423 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3424 item_array[order[i]] = list->data;
3427 for (i = length - 1; i >= 0; i--)
3429 item_array[i]->index = i;
3430 items = g_list_prepend (items, item_array[i]);
3433 g_free (item_array);
3434 g_list_free (icon_view->priv->items);
3435 icon_view->priv->items = items;
3437 gtk_icon_view_queue_layout (icon_view);
3439 verify_items (icon_view);
3443 gtk_icon_view_build_items (GtkIconView *icon_view)
3447 gboolean iters_persist;
3448 GList *items = NULL;
3450 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3452 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3460 GtkIconViewItem *item = gtk_icon_view_item_new ();
3469 items = g_list_prepend (items, item);
3471 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3473 icon_view->priv->items = g_list_reverse (items);
3477 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3480 GtkMovementStep step,
3484 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3485 I_("move-cursor"), 2,
3489 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3494 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3497 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3502 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3509 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3510 GtkMovementStep step,
3513 GdkModifierType state;
3515 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3516 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3517 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3518 step == GTK_MOVEMENT_DISPLAY_LINES ||
3519 step == GTK_MOVEMENT_PAGES ||
3520 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3522 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3525 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3526 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3528 if (gtk_get_current_event_state (&state))
3530 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3531 icon_view->priv->ctrl_pressed = TRUE;
3532 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3533 icon_view->priv->shift_pressed = TRUE;
3535 /* else we assume not pressed */
3539 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3540 case GTK_MOVEMENT_VISUAL_POSITIONS:
3541 gtk_icon_view_move_cursor_left_right (icon_view, count);
3543 case GTK_MOVEMENT_DISPLAY_LINES:
3544 gtk_icon_view_move_cursor_up_down (icon_view, count);
3546 case GTK_MOVEMENT_PAGES:
3547 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3549 case GTK_MOVEMENT_BUFFER_ENDS:
3550 gtk_icon_view_move_cursor_start_end (icon_view, count);
3553 g_assert_not_reached ();
3556 icon_view->priv->ctrl_pressed = FALSE;
3557 icon_view->priv->shift_pressed = FALSE;
3559 icon_view->priv->draw_focus = TRUE;
3564 static GtkIconViewItem *
3565 find_item (GtkIconView *icon_view,
3566 GtkIconViewItem *current,
3572 GtkIconViewItem *item;
3574 /* FIXME: this could be more efficient
3576 row = current->row + row_ofs;
3577 col = current->col + col_ofs;
3579 for (items = icon_view->priv->items; items; items = items->next)
3582 if (item->row == row && item->col == col)
3589 static GtkIconViewItem *
3590 find_item_page_up_down (GtkIconView *icon_view,
3591 GtkIconViewItem *current,
3598 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3600 item = g_list_find (icon_view->priv->items, current);
3605 for (next = item->next; next; next = next->next)
3607 if (((GtkIconViewItem *)next->data)->col == col)
3610 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3620 for (next = item->prev; next; next = next->prev)
3622 if (((GtkIconViewItem *)next->data)->col == col)
3625 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3639 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3640 GtkIconViewItem *anchor,
3641 GtkIconViewItem *cursor)
3644 GtkIconViewItem *item;
3645 gint row1, row2, col1, col2;
3646 gboolean dirty = FALSE;
3648 if (anchor->row < cursor->row)
3659 if (anchor->col < cursor->col)
3670 for (items = icon_view->priv->items; items; items = items->next)
3674 if (row1 <= item->row && item->row <= row2 &&
3675 col1 <= item->col && item->col <= col2)
3677 if (!item->selected)
3680 item->selected = TRUE;
3681 gtk_icon_view_item_selected_changed (icon_view, item);
3683 gtk_icon_view_queue_draw_item (icon_view, item);
3691 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3694 GtkIconViewItem *item;
3695 GtkCellRenderer *cell;
3696 gboolean dirty = FALSE;
3698 GtkDirectionType direction;
3700 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3703 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3705 if (!icon_view->priv->cursor_item)
3710 list = icon_view->priv->items;
3712 list = g_list_last (icon_view->priv->items);
3714 item = list ? list->data : NULL;
3716 /* Give focus to the first cell initially */
3717 gtk_icon_view_set_cell_data (icon_view, item);
3718 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3722 item = icon_view->priv->cursor_item;
3723 step = count > 0 ? 1 : -1;
3725 /* Save the current focus cell in case we hit the edge */
3726 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3730 gtk_icon_view_set_cell_data (icon_view, item);
3732 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3735 item = find_item (icon_view, item, step, 0);
3741 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3743 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3745 gtk_widget_child_focus (toplevel,
3746 direction == GTK_DIR_UP ?
3747 GTK_DIR_TAB_BACKWARD :
3748 GTK_DIR_TAB_FORWARD);
3752 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3756 if (icon_view->priv->ctrl_pressed ||
3757 !icon_view->priv->shift_pressed ||
3758 !icon_view->priv->anchor_item ||
3759 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3760 icon_view->priv->anchor_item = item;
3762 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3763 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3765 if (!icon_view->priv->ctrl_pressed &&
3766 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3768 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3769 dirty = gtk_icon_view_select_all_between (icon_view,
3770 icon_view->priv->anchor_item,
3774 gtk_icon_view_scroll_to_item (icon_view, item);
3777 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3781 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3784 GtkIconViewItem *item;
3785 gboolean dirty = FALSE;
3787 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3790 if (!icon_view->priv->cursor_item)
3795 list = icon_view->priv->items;
3797 list = g_list_last (icon_view->priv->items);
3799 item = list ? list->data : NULL;
3802 item = find_item_page_up_down (icon_view,
3803 icon_view->priv->cursor_item,
3806 if (item == icon_view->priv->cursor_item)
3807 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3812 if (icon_view->priv->ctrl_pressed ||
3813 !icon_view->priv->shift_pressed ||
3814 !icon_view->priv->anchor_item ||
3815 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3816 icon_view->priv->anchor_item = item;
3818 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3820 if (!icon_view->priv->ctrl_pressed &&
3821 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3823 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3824 dirty = gtk_icon_view_select_all_between (icon_view,
3825 icon_view->priv->anchor_item,
3829 gtk_icon_view_scroll_to_item (icon_view, item);
3832 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3836 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3839 GtkIconViewItem *item;
3840 GtkCellRenderer *cell = NULL;
3841 gboolean dirty = FALSE;
3843 GtkDirectionType direction;
3845 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3848 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3850 if (!icon_view->priv->cursor_item)
3855 list = icon_view->priv->items;
3857 list = g_list_last (icon_view->priv->items);
3859 item = list ? list->data : NULL;
3861 /* Give focus to the first cell initially */
3862 gtk_icon_view_set_cell_data (icon_view, item);
3863 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3867 item = icon_view->priv->cursor_item;
3868 step = count > 0 ? 1 : -1;
3870 /* Save the current focus cell in case we hit the edge */
3871 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3875 gtk_icon_view_set_cell_data (icon_view, item);
3877 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3880 item = find_item (icon_view, item, 0, step);
3886 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3888 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3890 gtk_widget_child_focus (toplevel,
3891 direction == GTK_DIR_LEFT ?
3892 GTK_DIR_TAB_BACKWARD :
3893 GTK_DIR_TAB_FORWARD);
3897 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3901 if (icon_view->priv->ctrl_pressed ||
3902 !icon_view->priv->shift_pressed ||
3903 !icon_view->priv->anchor_item ||
3904 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3905 icon_view->priv->anchor_item = item;
3907 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3908 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3910 if (!icon_view->priv->ctrl_pressed &&
3911 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3913 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3914 dirty = gtk_icon_view_select_all_between (icon_view,
3915 icon_view->priv->anchor_item,
3919 gtk_icon_view_scroll_to_item (icon_view, item);
3922 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3926 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3929 GtkIconViewItem *item;
3931 gboolean dirty = FALSE;
3933 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3937 list = icon_view->priv->items;
3939 list = g_list_last (icon_view->priv->items);
3941 item = list ? list->data : NULL;
3943 if (item == icon_view->priv->cursor_item)
3944 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3949 if (icon_view->priv->ctrl_pressed ||
3950 !icon_view->priv->shift_pressed ||
3951 !icon_view->priv->anchor_item ||
3952 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3953 icon_view->priv->anchor_item = item;
3955 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3957 if (!icon_view->priv->ctrl_pressed &&
3958 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3960 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3961 dirty = gtk_icon_view_select_all_between (icon_view,
3962 icon_view->priv->anchor_item,
3966 gtk_icon_view_scroll_to_item (icon_view, item);
3969 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3973 * gtk_icon_view_scroll_to_path:
3974 * @icon_view: A #GtkIconView.
3975 * @path: The path of the item to move to.
3976 * @use_align: whether to use alignment arguments, or %FALSE.
3977 * @row_align: The vertical alignment of the item specified by @path.
3978 * @col_align: The horizontal alignment of the item specified by @path.
3980 * Moves the alignments of @icon_view to the position specified by @path.
3981 * @row_align determines where the row is placed, and @col_align determines
3982 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3983 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3986 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3987 * tree does the minimum amount of work to scroll the item onto the screen.
3988 * This means that the item will be scrolled to the edge closest to its current
3989 * position. If the item is currently visible on the screen, nothing is done.
3991 * This function only works if the model is set, and @path is a valid row on
3992 * the model. If the model changes before the @icon_view is realized, the
3993 * centered path will be modified to reflect this change.
3998 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4004 GtkIconViewItem *item = NULL;
4007 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4008 g_return_if_fail (path != NULL);
4009 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4010 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4012 widget = GTK_WIDGET (icon_view);
4014 if (gtk_tree_path_get_depth (path) > 0)
4015 item = g_list_nth_data (icon_view->priv->items,
4016 gtk_tree_path_get_indices(path)[0]);
4018 if (!item || item->cell_area.width < 0 ||
4019 !gtk_widget_get_realized (widget))
4021 if (icon_view->priv->scroll_to_path)
4022 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4024 icon_view->priv->scroll_to_path = NULL;
4027 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4029 icon_view->priv->scroll_to_use_align = use_align;
4030 icon_view->priv->scroll_to_row_align = row_align;
4031 icon_view->priv->scroll_to_col_align = col_align;
4038 GtkAllocation allocation;
4041 GdkRectangle item_area =
4043 item->cell_area.x - icon_view->priv->item_padding,
4044 item->cell_area.y - icon_view->priv->item_padding,
4045 item->cell_area.width + icon_view->priv->item_padding * 2,
4046 item->cell_area.height + icon_view->priv->item_padding * 2
4049 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4051 gtk_widget_get_allocation (widget, &allocation);
4053 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4055 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4056 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4058 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4060 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4061 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4063 gtk_adjustment_changed (icon_view->priv->hadjustment);
4064 gtk_adjustment_changed (icon_view->priv->vadjustment);
4067 gtk_icon_view_scroll_to_item (icon_view, item);
4072 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4073 GtkIconViewItem *item)
4075 GtkIconViewPrivate *priv = icon_view->priv;
4076 GtkWidget *widget = GTK_WIDGET (icon_view);
4077 GtkAdjustment *hadj, *vadj;
4078 GtkAllocation allocation;
4080 GdkRectangle item_area;
4082 item_area.x = item->cell_area.x - priv->item_padding;
4083 item_area.y = item->cell_area.y - priv->item_padding;
4084 item_area.width = item->cell_area.width + priv->item_padding * 2;
4085 item_area.height = item->cell_area.height + priv->item_padding * 2;
4087 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4088 gtk_widget_get_allocation (widget, &allocation);
4090 hadj = icon_view->priv->hadjustment;
4091 vadj = icon_view->priv->vadjustment;
4093 if (y + item_area.y < 0)
4094 gtk_adjustment_set_value (vadj,
4095 gtk_adjustment_get_value (vadj)
4097 else if (y + item_area.y + item_area.height > allocation.height)
4098 gtk_adjustment_set_value (vadj,
4099 gtk_adjustment_get_value (vadj)
4100 + y + item_area.y + item_area.height - allocation.height);
4102 if (x + item_area.x < 0)
4103 gtk_adjustment_set_value (hadj,
4104 gtk_adjustment_get_value (hadj)
4106 else if (x + item_area.x + item_area.width > allocation.width)
4107 gtk_adjustment_set_value (hadj,
4108 gtk_adjustment_get_value (hadj)
4109 + x + item_area.x + item_area.width - allocation.width);
4111 gtk_adjustment_changed (hadj);
4112 gtk_adjustment_changed (vadj);
4115 /* GtkCellLayout implementation */
4118 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4119 GtkCellArea *cell_area)
4121 GtkIconViewPrivate *priv = icon_view->priv;
4123 if (priv->cell_area)
4127 priv->cell_area = cell_area;
4129 priv->cell_area = gtk_cell_area_box_new ();
4131 g_object_ref_sink (priv->cell_area);
4133 if (GTK_IS_ORIENTABLE (priv->cell_area))
4134 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4136 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4138 priv->add_editable_id =
4139 g_signal_connect (priv->cell_area, "add-editable",
4140 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4141 priv->remove_editable_id =
4142 g_signal_connect (priv->cell_area, "remove-editable",
4143 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4144 priv->context_changed_id =
4145 g_signal_connect (priv->cell_area_context, "notify",
4146 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4148 update_text_cell (icon_view);
4149 update_pixbuf_cell (icon_view);
4152 static GtkCellArea *
4153 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4155 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4156 GtkIconViewPrivate *priv = icon_view->priv;
4158 if (G_UNLIKELY (!priv->cell_area))
4159 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4161 return icon_view->priv->cell_area;
4165 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4166 GtkIconViewItem *item)
4168 gboolean iters_persist;
4171 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4177 path = gtk_tree_path_new_from_indices (item->index, -1);
4178 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4180 gtk_tree_path_free (path);
4185 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4186 icon_view->priv->model,
4187 &iter, FALSE, FALSE);
4196 * gtk_icon_view_new:
4198 * Creates a new #GtkIconView widget
4200 * Return value: A newly created #GtkIconView widget
4205 gtk_icon_view_new (void)
4207 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4211 * gtk_icon_view_new_with_area:
4212 * @area: the #GtkCellArea to use to layout cells
4214 * Creates a new #GtkIconView widget using the
4215 * specified @area to layout cells inside the icons.
4217 * Return value: A newly created #GtkIconView widget
4222 gtk_icon_view_new_with_area (GtkCellArea *area)
4224 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4228 * gtk_icon_view_new_with_model:
4229 * @model: The model.
4231 * Creates a new #GtkIconView widget with the model @model.
4233 * Return value: A newly created #GtkIconView widget.
4238 gtk_icon_view_new_with_model (GtkTreeModel *model)
4240 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4244 * gtk_icon_view_convert_widget_to_bin_window_coords:
4245 * @icon_view: a #GtkIconView
4246 * @wx: X coordinate relative to the widget
4247 * @wy: Y coordinate relative to the widget
4248 * @bx: (out): return location for bin_window X coordinate
4249 * @by: (out): return location for bin_window Y coordinate
4251 * Converts widget coordinates to coordinates for the bin_window,
4252 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4257 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4265 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4267 if (icon_view->priv->bin_window)
4268 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4279 * gtk_icon_view_get_path_at_pos:
4280 * @icon_view: A #GtkIconView.
4281 * @x: The x position to be identified
4282 * @y: The y position to be identified
4284 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4285 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4286 * the cell at the specified position.
4287 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4288 * widget coordinates to bin_window coordinates.
4290 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4291 * if no icon exists at that position.
4296 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4300 GtkIconViewItem *item;
4303 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4305 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4310 path = gtk_tree_path_new_from_indices (item->index, -1);
4316 * gtk_icon_view_get_item_at_pos:
4317 * @icon_view: A #GtkIconView.
4318 * @x: The x position to be identified
4319 * @y: The y position to be identified
4320 * @path: (out) (allow-none): Return location for the path, or %NULL
4321 * @cell: (out) (allow-none): Return location for the renderer
4322 * responsible for the cell at (@x, @y), or %NULL
4324 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4325 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4326 * obtains the cell at the specified position. The returned path should
4327 * be freed with gtk_tree_path_free().
4328 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4329 * widget coordinates to bin_window coordinates.
4331 * Return value: %TRUE if an item exists at the specified position
4336 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4340 GtkCellRenderer **cell)
4342 GtkIconViewItem *item;
4343 GtkCellRenderer *renderer = NULL;
4345 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4347 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4352 *path = gtk_tree_path_new_from_indices (item->index, -1);
4360 return (item != NULL);
4364 * gtk_icon_view_set_tooltip_item:
4365 * @icon_view: a #GtkIconView
4366 * @tooltip: a #GtkTooltip
4367 * @path: a #GtkTreePath
4369 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4370 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4371 * See also gtk_tooltip_set_tip_area().
4376 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4377 GtkTooltip *tooltip,
4380 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4381 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4383 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4387 * gtk_icon_view_set_tooltip_cell:
4388 * @icon_view: a #GtkIconView
4389 * @tooltip: a #GtkTooltip
4390 * @path: a #GtkTreePath
4391 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4393 * Sets the tip area of @tooltip to the area which @cell occupies in
4394 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4396 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4401 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4402 GtkTooltip *tooltip,
4404 GtkCellRenderer *cell)
4407 GtkIconViewItem *item = NULL;
4410 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4411 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4412 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4414 if (gtk_tree_path_get_depth (path) > 0)
4415 item = g_list_nth_data (icon_view->priv->items,
4416 gtk_tree_path_get_indices(path)[0]);
4423 GtkCellAreaContext *context;
4425 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4426 gtk_icon_view_set_cell_data (icon_view, item);
4427 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4428 GTK_WIDGET (icon_view),
4429 cell, (GdkRectangle *)item, &rect);
4433 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4434 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4435 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4436 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4439 if (icon_view->priv->bin_window)
4441 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4446 gtk_tooltip_set_tip_area (tooltip, &rect);
4451 * gtk_icon_view_get_tooltip_context:
4452 * @icon_view: an #GtkIconView
4453 * @x: (inout): the x coordinate (relative to widget coordinates)
4454 * @y: (inout): the y coordinate (relative to widget coordinates)
4455 * @keyboard_tip: whether this is a keyboard tooltip or not
4456 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4457 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4458 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4460 * This function is supposed to be used in a #GtkWidget::query-tooltip
4461 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4462 * which are received in the signal handler, should be passed to this
4463 * function without modification.
4465 * The return value indicates whether there is an icon view item at the given
4466 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4467 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4468 * @model, @path and @iter which have been provided will be set to point to
4469 * that row and the corresponding model. @x and @y will always be converted
4470 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4472 * Return value: whether or not the given tooltip context points to a item
4477 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4480 gboolean keyboard_tip,
4481 GtkTreeModel **model,
4485 GtkTreePath *tmppath = NULL;
4487 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4488 g_return_val_if_fail (x != NULL, FALSE);
4489 g_return_val_if_fail (y != NULL, FALSE);
4493 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4500 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4503 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4508 *model = gtk_icon_view_get_model (icon_view);
4511 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4517 gtk_tree_path_free (tmppath);
4523 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4526 gboolean keyboard_tip,
4527 GtkTooltip *tooltip,
4533 GtkTreeModel *model;
4534 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4536 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4539 &model, &path, &iter))
4542 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4546 gtk_tree_path_free (path);
4550 gtk_tooltip_set_markup (tooltip, str);
4551 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4553 gtk_tree_path_free (path);
4561 * gtk_icon_view_set_tooltip_column:
4562 * @icon_view: a #GtkIconView
4563 * @column: an integer, which is a valid column number for @icon_view's model
4565 * If you only plan to have simple (text-only) tooltips on full items, you
4566 * can use this function to have #GtkIconView handle these automatically
4567 * for you. @column should be set to the column in @icon_view's model
4568 * containing the tooltip texts, or -1 to disable this feature.
4570 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4571 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4573 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4574 * so &, <, etc have to be escaped in the text.
4579 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4582 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4584 if (column == icon_view->priv->tooltip_column)
4589 g_signal_handlers_disconnect_by_func (icon_view,
4590 gtk_icon_view_set_tooltip_query_cb,
4592 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4596 if (icon_view->priv->tooltip_column == -1)
4598 g_signal_connect (icon_view, "query-tooltip",
4599 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4600 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4604 icon_view->priv->tooltip_column = column;
4605 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4609 * gtk_icon_view_get_tooltip_column:
4610 * @icon_view: a #GtkIconView
4612 * Returns the column of @icon_view's model which is being used for
4613 * displaying tooltips on @icon_view's rows.
4615 * Return value: the index of the tooltip column that is currently being
4616 * used, or -1 if this is disabled.
4621 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4623 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4625 return icon_view->priv->tooltip_column;
4629 * gtk_icon_view_get_visible_range:
4630 * @icon_view: A #GtkIconView
4631 * @start_path: (out) (allow-none): Return location for start of region,
4633 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4635 * Sets @start_path and @end_path to be the first and last visible path.
4636 * Note that there may be invisible paths in between.
4638 * Both paths should be freed with gtk_tree_path_free() after use.
4640 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4645 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4646 GtkTreePath **start_path,
4647 GtkTreePath **end_path)
4649 gint start_index = -1;
4650 gint end_index = -1;
4653 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4655 if (icon_view->priv->hadjustment == NULL ||
4656 icon_view->priv->vadjustment == NULL)
4659 if (start_path == NULL && end_path == NULL)
4662 for (icons = icon_view->priv->items; icons; icons = icons->next)
4664 GtkIconViewItem *item = icons->data;
4665 GdkRectangle *item_area = (GdkRectangle *)item;
4667 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4668 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4670 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4671 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4673 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4674 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4676 if (start_index == -1)
4677 start_index = item->index;
4678 end_index = item->index;
4682 if (start_path && start_index != -1)
4683 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4684 if (end_path && end_index != -1)
4685 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4687 return start_index != -1;
4691 * gtk_icon_view_selected_foreach:
4692 * @icon_view: A #GtkIconView.
4693 * @func: (scope call): The function to call for each selected icon.
4694 * @data: User data to pass to the function.
4696 * Calls a function for each selected icon. Note that the model or
4697 * selection cannot be modified from within this function.
4702 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4703 GtkIconViewForeachFunc func,
4708 for (list = icon_view->priv->items; list; list = list->next)
4710 GtkIconViewItem *item = list->data;
4711 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4714 (* func) (icon_view, path, data);
4716 gtk_tree_path_free (path);
4721 * gtk_icon_view_set_selection_mode:
4722 * @icon_view: A #GtkIconView.
4723 * @mode: The selection mode
4725 * Sets the selection mode of the @icon_view.
4730 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4731 GtkSelectionMode mode)
4733 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4735 if (mode == icon_view->priv->selection_mode)
4738 if (mode == GTK_SELECTION_NONE ||
4739 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4740 gtk_icon_view_unselect_all (icon_view);
4742 icon_view->priv->selection_mode = mode;
4744 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4748 * gtk_icon_view_get_selection_mode:
4749 * @icon_view: A #GtkIconView.
4751 * Gets the selection mode of the @icon_view.
4753 * Return value: the current selection mode
4758 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4760 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4762 return icon_view->priv->selection_mode;
4766 * gtk_icon_view_set_model:
4767 * @icon_view: A #GtkIconView.
4768 * @model: (allow-none): The model.
4770 * Sets the model for a #GtkIconView.
4771 * If the @icon_view already has a model set, it will remove
4772 * it before setting the new model. If @model is %NULL, then
4773 * it will unset the old model.
4778 gtk_icon_view_set_model (GtkIconView *icon_view,
4779 GtkTreeModel *model)
4781 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4782 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4784 if (icon_view->priv->model == model)
4787 if (icon_view->priv->scroll_to_path)
4789 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4790 icon_view->priv->scroll_to_path = NULL;
4793 /* The area can be NULL while disposing */
4794 if (icon_view->priv->cell_area)
4795 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4801 if (icon_view->priv->pixbuf_column != -1)
4803 column_type = gtk_tree_model_get_column_type (model,
4804 icon_view->priv->pixbuf_column);
4806 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4809 if (icon_view->priv->text_column != -1)
4811 column_type = gtk_tree_model_get_column_type (model,
4812 icon_view->priv->text_column);
4814 g_return_if_fail (column_type == G_TYPE_STRING);
4817 if (icon_view->priv->markup_column != -1)
4819 column_type = gtk_tree_model_get_column_type (model,
4820 icon_view->priv->markup_column);
4822 g_return_if_fail (column_type == G_TYPE_STRING);
4827 if (icon_view->priv->model)
4829 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4830 gtk_icon_view_row_changed,
4832 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4833 gtk_icon_view_row_inserted,
4835 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4836 gtk_icon_view_row_deleted,
4838 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4839 gtk_icon_view_rows_reordered,
4842 g_object_unref (icon_view->priv->model);
4844 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4845 g_list_free (icon_view->priv->items);
4846 icon_view->priv->items = NULL;
4847 icon_view->priv->anchor_item = NULL;
4848 icon_view->priv->cursor_item = NULL;
4849 icon_view->priv->last_single_clicked = NULL;
4850 icon_view->priv->width = 0;
4851 icon_view->priv->height = 0;
4854 icon_view->priv->model = model;
4856 if (icon_view->priv->model)
4858 g_object_ref (icon_view->priv->model);
4859 g_signal_connect (icon_view->priv->model,
4861 G_CALLBACK (gtk_icon_view_row_changed),
4863 g_signal_connect (icon_view->priv->model,
4865 G_CALLBACK (gtk_icon_view_row_inserted),
4867 g_signal_connect (icon_view->priv->model,
4869 G_CALLBACK (gtk_icon_view_row_deleted),
4871 g_signal_connect (icon_view->priv->model,
4873 G_CALLBACK (gtk_icon_view_rows_reordered),
4876 gtk_icon_view_build_items (icon_view);
4878 gtk_icon_view_queue_layout (icon_view);
4881 g_object_notify (G_OBJECT (icon_view), "model");
4883 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4884 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4888 * gtk_icon_view_get_model:
4889 * @icon_view: a #GtkIconView
4891 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4894 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4895 * currently being used.
4900 gtk_icon_view_get_model (GtkIconView *icon_view)
4902 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4904 return icon_view->priv->model;
4908 update_text_cell (GtkIconView *icon_view)
4910 if (!icon_view->priv->cell_area)
4913 if (icon_view->priv->text_column == -1 &&
4914 icon_view->priv->markup_column == -1)
4916 if (icon_view->priv->text_cell != NULL)
4918 gtk_cell_area_remove (icon_view->priv->cell_area,
4919 icon_view->priv->text_cell);
4920 icon_view->priv->text_cell = NULL;
4925 if (icon_view->priv->text_cell == NULL)
4927 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4929 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4932 if (icon_view->priv->markup_column != -1)
4933 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4934 icon_view->priv->text_cell,
4935 "markup", icon_view->priv->markup_column,
4938 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4939 icon_view->priv->text_cell,
4940 "text", icon_view->priv->text_column,
4943 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4944 g_object_set (icon_view->priv->text_cell,
4945 "alignment", PANGO_ALIGN_CENTER,
4946 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4951 g_object_set (icon_view->priv->text_cell,
4952 "alignment", PANGO_ALIGN_LEFT,
4953 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4961 update_pixbuf_cell (GtkIconView *icon_view)
4963 if (!icon_view->priv->cell_area)
4966 if (icon_view->priv->pixbuf_column == -1)
4968 if (icon_view->priv->pixbuf_cell != NULL)
4970 gtk_cell_area_remove (icon_view->priv->cell_area,
4971 icon_view->priv->pixbuf_cell);
4973 icon_view->priv->pixbuf_cell = NULL;
4978 if (icon_view->priv->pixbuf_cell == NULL)
4980 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4982 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4985 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4986 icon_view->priv->pixbuf_cell,
4987 "pixbuf", icon_view->priv->pixbuf_column,
4990 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4991 g_object_set (icon_view->priv->pixbuf_cell,
4996 g_object_set (icon_view->priv->pixbuf_cell,
5004 * gtk_icon_view_set_text_column:
5005 * @icon_view: A #GtkIconView.
5006 * @column: A column in the currently used model, or -1 to display no text
5008 * Sets the column with text for @icon_view to be @column. The text
5009 * column must be of type #G_TYPE_STRING.
5014 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5017 if (column == icon_view->priv->text_column)
5021 icon_view->priv->text_column = -1;
5024 if (icon_view->priv->model != NULL)
5028 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5030 g_return_if_fail (column_type == G_TYPE_STRING);
5033 icon_view->priv->text_column = column;
5036 if (icon_view->priv->cell_area)
5037 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5039 update_text_cell (icon_view);
5041 gtk_icon_view_invalidate_sizes (icon_view);
5043 g_object_notify (G_OBJECT (icon_view), "text-column");
5047 * gtk_icon_view_get_text_column:
5048 * @icon_view: A #GtkIconView.
5050 * Returns the column with text for @icon_view.
5052 * Returns: the text column, or -1 if it's unset.
5057 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5059 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5061 return icon_view->priv->text_column;
5065 * gtk_icon_view_set_markup_column:
5066 * @icon_view: A #GtkIconView.
5067 * @column: A column in the currently used model, or -1 to display no text
5069 * Sets the column with markup information for @icon_view to be
5070 * @column. The markup column must be of type #G_TYPE_STRING.
5071 * If the markup column is set to something, it overrides
5072 * the text column set by gtk_icon_view_set_text_column().
5077 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5080 if (column == icon_view->priv->markup_column)
5084 icon_view->priv->markup_column = -1;
5087 if (icon_view->priv->model != NULL)
5091 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5093 g_return_if_fail (column_type == G_TYPE_STRING);
5096 icon_view->priv->markup_column = column;
5099 if (icon_view->priv->cell_area)
5100 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5102 update_text_cell (icon_view);
5104 gtk_icon_view_invalidate_sizes (icon_view);
5106 g_object_notify (G_OBJECT (icon_view), "markup-column");
5110 * gtk_icon_view_get_markup_column:
5111 * @icon_view: A #GtkIconView.
5113 * Returns the column with markup text for @icon_view.
5115 * Returns: the markup column, or -1 if it's unset.
5120 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5122 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5124 return icon_view->priv->markup_column;
5128 * gtk_icon_view_set_pixbuf_column:
5129 * @icon_view: A #GtkIconView.
5130 * @column: A column in the currently used model, or -1 to disable
5132 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5133 * column must be of type #GDK_TYPE_PIXBUF
5138 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5141 if (column == icon_view->priv->pixbuf_column)
5145 icon_view->priv->pixbuf_column = -1;
5148 if (icon_view->priv->model != NULL)
5152 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5154 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5157 icon_view->priv->pixbuf_column = column;
5160 if (icon_view->priv->cell_area)
5161 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5163 update_pixbuf_cell (icon_view);
5165 gtk_icon_view_invalidate_sizes (icon_view);
5167 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5172 * gtk_icon_view_get_pixbuf_column:
5173 * @icon_view: A #GtkIconView.
5175 * Returns the column with pixbufs for @icon_view.
5177 * Returns: the pixbuf column, or -1 if it's unset.
5182 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5184 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5186 return icon_view->priv->pixbuf_column;
5190 * gtk_icon_view_select_path:
5191 * @icon_view: A #GtkIconView.
5192 * @path: The #GtkTreePath to be selected.
5194 * Selects the row at @path.
5199 gtk_icon_view_select_path (GtkIconView *icon_view,
5202 GtkIconViewItem *item = NULL;
5204 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5205 g_return_if_fail (icon_view->priv->model != NULL);
5206 g_return_if_fail (path != NULL);
5208 if (gtk_tree_path_get_depth (path) > 0)
5209 item = g_list_nth_data (icon_view->priv->items,
5210 gtk_tree_path_get_indices(path)[0]);
5213 gtk_icon_view_select_item (icon_view, item);
5217 * gtk_icon_view_unselect_path:
5218 * @icon_view: A #GtkIconView.
5219 * @path: The #GtkTreePath to be unselected.
5221 * Unselects the row at @path.
5226 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5229 GtkIconViewItem *item;
5231 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5232 g_return_if_fail (icon_view->priv->model != NULL);
5233 g_return_if_fail (path != NULL);
5235 item = g_list_nth_data (icon_view->priv->items,
5236 gtk_tree_path_get_indices(path)[0]);
5241 gtk_icon_view_unselect_item (icon_view, item);
5245 * gtk_icon_view_get_selected_items:
5246 * @icon_view: A #GtkIconView.
5248 * Creates a list of paths of all selected items. Additionally, if you are
5249 * planning on modifying the model after calling this function, you may
5250 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5251 * To do this, you can use gtk_tree_row_reference_new().
5253 * To free the return value, use:
5255 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5256 * g_list_free (list);
5259 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5264 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5267 GList *selected = NULL;
5269 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5271 for (list = icon_view->priv->items; list != NULL; list = list->next)
5273 GtkIconViewItem *item = list->data;
5277 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5279 selected = g_list_prepend (selected, path);
5287 * gtk_icon_view_select_all:
5288 * @icon_view: A #GtkIconView.
5290 * Selects all the icons. @icon_view must has its selection mode set
5291 * to #GTK_SELECTION_MULTIPLE.
5296 gtk_icon_view_select_all (GtkIconView *icon_view)
5299 gboolean dirty = FALSE;
5301 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5303 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5306 for (items = icon_view->priv->items; items; items = items->next)
5308 GtkIconViewItem *item = items->data;
5310 if (!item->selected)
5313 item->selected = TRUE;
5314 gtk_icon_view_queue_draw_item (icon_view, item);
5319 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5323 * gtk_icon_view_unselect_all:
5324 * @icon_view: A #GtkIconView.
5326 * Unselects all the icons.
5331 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5333 gboolean dirty = FALSE;
5335 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5337 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5340 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5343 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5347 * gtk_icon_view_path_is_selected:
5348 * @icon_view: A #GtkIconView.
5349 * @path: A #GtkTreePath to check selection on.
5351 * Returns %TRUE if the icon pointed to by @path is currently
5352 * selected. If @path does not point to a valid location, %FALSE is returned.
5354 * Return value: %TRUE if @path is selected.
5359 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5362 GtkIconViewItem *item;
5364 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5365 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5366 g_return_val_if_fail (path != NULL, FALSE);
5368 item = g_list_nth_data (icon_view->priv->items,
5369 gtk_tree_path_get_indices(path)[0]);
5374 return item->selected;
5378 * gtk_icon_view_get_item_row:
5379 * @icon_view: a #GtkIconView
5380 * @path: the #GtkTreePath of the item
5382 * Gets the row in which the item @path is currently
5383 * displayed. Row numbers start at 0.
5385 * Returns: The row in which the item is displayed
5390 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5393 GtkIconViewItem *item;
5395 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5396 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5397 g_return_val_if_fail (path != NULL, -1);
5399 item = g_list_nth_data (icon_view->priv->items,
5400 gtk_tree_path_get_indices(path)[0]);
5409 * gtk_icon_view_get_item_column:
5410 * @icon_view: a #GtkIconView
5411 * @path: the #GtkTreePath of the item
5413 * Gets the column in which the item @path is currently
5414 * displayed. Column numbers start at 0.
5416 * Returns: The column in which the item is displayed
5421 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5424 GtkIconViewItem *item;
5426 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5427 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5428 g_return_val_if_fail (path != NULL, -1);
5430 item = g_list_nth_data (icon_view->priv->items,
5431 gtk_tree_path_get_indices(path)[0]);
5440 * gtk_icon_view_item_activated:
5441 * @icon_view: A #GtkIconView
5442 * @path: The #GtkTreePath to be activated
5444 * Activates the item determined by @path.
5449 gtk_icon_view_item_activated (GtkIconView *icon_view,
5452 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5453 g_return_if_fail (path != NULL);
5455 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5459 * gtk_icon_view_set_item_orientation:
5460 * @icon_view: a #GtkIconView
5461 * @orientation: the relative position of texts and icons
5463 * Sets the ::item-orientation property which determines whether the labels
5464 * are drawn beside the icons instead of below.
5469 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5470 GtkOrientation orientation)
5472 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5474 if (icon_view->priv->item_orientation != orientation)
5476 icon_view->priv->item_orientation = orientation;
5478 if (icon_view->priv->cell_area)
5480 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5481 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5482 icon_view->priv->item_orientation);
5484 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5487 gtk_icon_view_invalidate_sizes (icon_view);
5489 update_text_cell (icon_view);
5490 update_pixbuf_cell (icon_view);
5492 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5497 * gtk_icon_view_get_item_orientation:
5498 * @icon_view: a #GtkIconView
5500 * Returns the value of the ::item-orientation property which determines
5501 * whether the labels are drawn beside the icons instead of below.
5503 * Return value: the relative position of texts and icons
5508 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5510 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5511 GTK_ORIENTATION_VERTICAL);
5513 return icon_view->priv->item_orientation;
5517 * gtk_icon_view_set_columns:
5518 * @icon_view: a #GtkIconView
5519 * @columns: the number of columns
5521 * Sets the ::columns property which determines in how
5522 * many columns the icons are arranged. If @columns is
5523 * -1, the number of columns will be chosen automatically
5524 * to fill the available area.
5529 gtk_icon_view_set_columns (GtkIconView *icon_view,
5532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5534 if (icon_view->priv->columns != columns)
5536 icon_view->priv->columns = columns;
5538 if (icon_view->priv->cell_area)
5539 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5541 gtk_icon_view_queue_layout (icon_view);
5543 g_object_notify (G_OBJECT (icon_view), "columns");
5548 * gtk_icon_view_get_columns:
5549 * @icon_view: a #GtkIconView
5551 * Returns the value of the ::columns property.
5553 * Return value: the number of columns, or -1
5558 gtk_icon_view_get_columns (GtkIconView *icon_view)
5560 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5562 return icon_view->priv->columns;
5566 * gtk_icon_view_set_item_width:
5567 * @icon_view: a #GtkIconView
5568 * @item_width: the width for each item
5570 * Sets the ::item-width property which specifies the width
5571 * to use for each item. If it is set to -1, the icon view will
5572 * automatically determine a suitable item size.
5577 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5580 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5582 if (icon_view->priv->item_width != item_width)
5584 icon_view->priv->item_width = item_width;
5586 if (icon_view->priv->cell_area)
5587 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5589 gtk_icon_view_invalidate_sizes (icon_view);
5591 update_text_cell (icon_view);
5593 g_object_notify (G_OBJECT (icon_view), "item-width");
5598 * gtk_icon_view_get_item_width:
5599 * @icon_view: a #GtkIconView
5601 * Returns the value of the ::item-width property.
5603 * Return value: the width of a single item, or -1
5608 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5610 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5612 return icon_view->priv->item_width;
5617 * gtk_icon_view_set_spacing:
5618 * @icon_view: a #GtkIconView
5619 * @spacing: the spacing
5621 * Sets the ::spacing property which specifies the space
5622 * which is inserted between the cells (i.e. the icon and
5623 * the text) of an item.
5628 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5631 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5633 if (icon_view->priv->spacing != spacing)
5635 icon_view->priv->spacing = spacing;
5637 if (icon_view->priv->cell_area)
5638 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5640 gtk_icon_view_invalidate_sizes (icon_view);
5642 g_object_notify (G_OBJECT (icon_view), "spacing");
5647 * gtk_icon_view_get_spacing:
5648 * @icon_view: a #GtkIconView
5650 * Returns the value of the ::spacing property.
5652 * Return value: the space between cells
5657 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5659 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5661 return icon_view->priv->spacing;
5665 * gtk_icon_view_set_row_spacing:
5666 * @icon_view: a #GtkIconView
5667 * @row_spacing: the row spacing
5669 * Sets the ::row-spacing property which specifies the space
5670 * which is inserted between the rows of the icon view.
5675 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5678 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5680 if (icon_view->priv->row_spacing != row_spacing)
5682 icon_view->priv->row_spacing = row_spacing;
5684 if (icon_view->priv->cell_area)
5685 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5687 gtk_icon_view_invalidate_sizes (icon_view);
5689 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5694 * gtk_icon_view_get_row_spacing:
5695 * @icon_view: a #GtkIconView
5697 * Returns the value of the ::row-spacing property.
5699 * Return value: the space between rows
5704 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5706 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5708 return icon_view->priv->row_spacing;
5712 * gtk_icon_view_set_column_spacing:
5713 * @icon_view: a #GtkIconView
5714 * @column_spacing: the column spacing
5716 * Sets the ::column-spacing property which specifies the space
5717 * which is inserted between the columns of the icon view.
5722 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5723 gint column_spacing)
5725 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5727 if (icon_view->priv->column_spacing != column_spacing)
5729 icon_view->priv->column_spacing = column_spacing;
5731 if (icon_view->priv->cell_area)
5732 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5734 gtk_icon_view_invalidate_sizes (icon_view);
5736 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5741 * gtk_icon_view_get_column_spacing:
5742 * @icon_view: a #GtkIconView
5744 * Returns the value of the ::column-spacing property.
5746 * Return value: the space between columns
5751 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5753 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5755 return icon_view->priv->column_spacing;
5759 * gtk_icon_view_set_margin:
5760 * @icon_view: a #GtkIconView
5761 * @margin: the margin
5763 * Sets the ::margin property which specifies the space
5764 * which is inserted at the top, bottom, left and right
5770 gtk_icon_view_set_margin (GtkIconView *icon_view,
5773 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5775 if (icon_view->priv->margin != margin)
5777 icon_view->priv->margin = margin;
5779 if (icon_view->priv->cell_area)
5780 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5782 gtk_icon_view_invalidate_sizes (icon_view);
5784 g_object_notify (G_OBJECT (icon_view), "margin");
5789 * gtk_icon_view_get_margin:
5790 * @icon_view: a #GtkIconView
5792 * Returns the value of the ::margin property.
5794 * Return value: the space at the borders
5799 gtk_icon_view_get_margin (GtkIconView *icon_view)
5801 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5803 return icon_view->priv->margin;
5807 * gtk_icon_view_set_item_padding:
5808 * @icon_view: a #GtkIconView
5809 * @item_padding: the item padding
5811 * Sets the #GtkIconView:item-padding property which specifies the padding
5812 * around each of the icon view's items.
5817 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5820 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5822 if (icon_view->priv->item_padding != item_padding)
5824 icon_view->priv->item_padding = item_padding;
5826 if (icon_view->priv->cell_area)
5827 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5829 gtk_icon_view_invalidate_sizes (icon_view);
5831 g_object_notify (G_OBJECT (icon_view), "item-padding");
5836 * gtk_icon_view_get_item_padding:
5837 * @icon_view: a #GtkIconView
5839 * Returns the value of the ::item-padding property.
5841 * Return value: the padding around items
5846 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5848 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5850 return icon_view->priv->item_padding;
5853 /* Get/set whether drag_motion requested the drag data and
5854 * drag_data_received should thus not actually insert the data,
5855 * since the data doesn't result from a drop.
5858 set_status_pending (GdkDragContext *context,
5859 GdkDragAction suggested_action)
5861 g_object_set_data (G_OBJECT (context),
5862 I_("gtk-icon-view-status-pending"),
5863 GINT_TO_POINTER (suggested_action));
5866 static GdkDragAction
5867 get_status_pending (GdkDragContext *context)
5869 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5870 "gtk-icon-view-status-pending"));
5874 unset_reorderable (GtkIconView *icon_view)
5876 if (icon_view->priv->reorderable)
5878 icon_view->priv->reorderable = FALSE;
5879 g_object_notify (G_OBJECT (icon_view), "reorderable");
5884 set_source_row (GdkDragContext *context,
5885 GtkTreeModel *model,
5886 GtkTreePath *source_row)
5889 g_object_set_data_full (G_OBJECT (context),
5890 I_("gtk-icon-view-source-row"),
5891 gtk_tree_row_reference_new (model, source_row),
5892 (GDestroyNotify) gtk_tree_row_reference_free);
5894 g_object_set_data_full (G_OBJECT (context),
5895 I_("gtk-icon-view-source-row"),
5900 get_source_row (GdkDragContext *context)
5902 GtkTreeRowReference *ref;
5904 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5907 return gtk_tree_row_reference_get_path (ref);
5914 GtkTreeRowReference *dest_row;
5915 gboolean empty_view_drop;
5916 gboolean drop_append_mode;
5920 dest_row_free (gpointer data)
5922 DestRow *dr = (DestRow *)data;
5924 gtk_tree_row_reference_free (dr->dest_row);
5929 set_dest_row (GdkDragContext *context,
5930 GtkTreeModel *model,
5931 GtkTreePath *dest_row,
5932 gboolean empty_view_drop,
5933 gboolean drop_append_mode)
5939 g_object_set_data_full (G_OBJECT (context),
5940 I_("gtk-icon-view-dest-row"),
5945 dr = g_new0 (DestRow, 1);
5947 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5948 dr->empty_view_drop = empty_view_drop;
5949 dr->drop_append_mode = drop_append_mode;
5950 g_object_set_data_full (G_OBJECT (context),
5951 I_("gtk-icon-view-dest-row"),
5952 dr, (GDestroyNotify) dest_row_free);
5956 get_dest_row (GdkDragContext *context)
5960 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5964 GtkTreePath *path = NULL;
5967 path = gtk_tree_row_reference_get_path (dr->dest_row);
5968 else if (dr->empty_view_drop)
5969 path = gtk_tree_path_new_from_indices (0, -1);
5973 if (path && dr->drop_append_mode)
5974 gtk_tree_path_next (path);
5983 check_model_dnd (GtkTreeModel *model,
5984 GType required_iface,
5985 const gchar *signal)
5987 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5989 g_warning ("You must override the default '%s' handler "
5990 "on GtkIconView when using models that don't support "
5991 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5992 "is to connect to '%s' and call "
5993 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5994 "the default handler from running. Look at the source code "
5995 "for the default handler in gtkiconview.c to get an idea what "
5996 "your handler should do. (gtkiconview.c is in the GTK+ source "
5997 "code.) If you're using GTK+ from a language other than C, "
5998 "there may be a more natural way to override default handlers, e.g. via derivation.",
5999 signal, g_type_name (required_iface), signal);
6007 remove_scroll_timeout (GtkIconView *icon_view)
6009 if (icon_view->priv->scroll_timeout_id != 0)
6011 g_source_remove (icon_view->priv->scroll_timeout_id);
6013 icon_view->priv->scroll_timeout_id = 0;
6018 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6021 gint px, py, x, y, width, height;
6022 gint hoffset, voffset;
6024 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6026 gdk_window_get_pointer (window, &px, &py, NULL);
6027 gdk_window_get_geometry (window, &x, &y, &width, &height);
6029 /* see if we are near the edge. */
6030 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6032 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6034 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6036 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6039 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6040 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6043 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6044 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6049 drag_scroll_timeout (gpointer data)
6051 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6053 gtk_icon_view_autoscroll (icon_view);
6060 set_destination (GtkIconView *icon_view,
6061 GdkDragContext *context,
6064 GdkDragAction *suggested_action,
6068 GtkTreePath *path = NULL;
6069 GtkIconViewDropPosition pos;
6070 GtkIconViewDropPosition old_pos;
6071 GtkTreePath *old_dest_path = NULL;
6072 gboolean can_drop = FALSE;
6074 widget = GTK_WIDGET (icon_view);
6076 *suggested_action = 0;
6079 if (!icon_view->priv->dest_set)
6081 /* someone unset us as a drag dest, note that if
6082 * we return FALSE drag_leave isn't called
6085 gtk_icon_view_set_drag_dest_item (icon_view,
6087 GTK_ICON_VIEW_DROP_LEFT);
6089 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6091 return FALSE; /* no longer a drop site */
6094 *target = gtk_drag_dest_find_target (widget, context,
6095 gtk_drag_dest_get_target_list (widget));
6096 if (*target == GDK_NONE)
6099 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6102 GtkTreeModel *model;
6104 /* the row got dropped on empty space, let's setup a special case
6108 gtk_tree_path_free (path);
6110 model = gtk_icon_view_get_model (icon_view);
6112 n_children = gtk_tree_model_iter_n_children (model, NULL);
6115 pos = GTK_ICON_VIEW_DROP_BELOW;
6116 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6120 pos = GTK_ICON_VIEW_DROP_ABOVE;
6121 path = gtk_tree_path_new_from_indices (0, -1);
6131 gtk_icon_view_get_drag_dest_item (icon_view,
6136 gtk_tree_path_free (old_dest_path);
6138 if (TRUE /* FIXME if the location droppable predicate */)
6146 GtkWidget *source_widget;
6148 *suggested_action = gdk_drag_context_get_suggested_action (context);
6149 source_widget = gtk_drag_get_source_widget (context);
6151 if (source_widget == widget)
6153 /* Default to MOVE, unless the user has
6154 * pressed ctrl or shift to affect available actions
6156 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6157 *suggested_action = GDK_ACTION_MOVE;
6160 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6165 /* can't drop here */
6166 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6168 GTK_ICON_VIEW_DROP_LEFT);
6172 gtk_tree_path_free (path);
6178 get_logical_destination (GtkIconView *icon_view,
6179 gboolean *drop_append_mode)
6181 /* adjust path to point to the row the drop goes in front of */
6182 GtkTreePath *path = NULL;
6183 GtkIconViewDropPosition pos;
6185 *drop_append_mode = FALSE;
6187 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6192 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6193 pos == GTK_ICON_VIEW_DROP_BELOW)
6196 GtkTreeModel *model = icon_view->priv->model;
6198 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6199 !gtk_tree_model_iter_next (model, &iter))
6200 *drop_append_mode = TRUE;
6203 *drop_append_mode = FALSE;
6204 gtk_tree_path_next (path);
6212 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6213 GdkEventMotion *event)
6215 GtkWidget *widget = GTK_WIDGET (icon_view);
6216 GdkDragContext *context;
6217 GtkTreePath *path = NULL;
6219 GtkTreeModel *model;
6220 gboolean retval = FALSE;
6222 if (!icon_view->priv->source_set)
6225 if (icon_view->priv->pressed_button < 0)
6228 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6229 icon_view->priv->press_start_x,
6230 icon_view->priv->press_start_y,
6231 event->x, event->y))
6234 model = gtk_icon_view_get_model (icon_view);
6239 button = icon_view->priv->pressed_button;
6240 icon_view->priv->pressed_button = -1;
6242 path = gtk_icon_view_get_path_at_pos (icon_view,
6243 icon_view->priv->press_start_x,
6244 icon_view->priv->press_start_y);
6249 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6250 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6254 /* FIXME Check whether we're a start button, if not return FALSE and
6258 /* Now we can begin the drag */
6262 context = gtk_drag_begin (widget,
6263 gtk_drag_source_get_target_list (widget),
6264 icon_view->priv->source_actions,
6268 set_source_row (context, model, path);
6272 gtk_tree_path_free (path);
6277 /* Source side drag signals */
6279 gtk_icon_view_drag_begin (GtkWidget *widget,
6280 GdkDragContext *context)
6282 GtkIconView *icon_view;
6283 GtkIconViewItem *item;
6284 cairo_surface_t *icon;
6288 icon_view = GTK_ICON_VIEW (widget);
6290 /* if the user uses a custom DnD impl, we don't set the icon here */
6291 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6294 item = gtk_icon_view_get_item_at_coords (icon_view,
6295 icon_view->priv->press_start_x,
6296 icon_view->priv->press_start_y,
6300 g_return_if_fail (item != NULL);
6302 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6303 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6305 path = gtk_tree_path_new_from_indices (item->index, -1);
6306 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6307 gtk_tree_path_free (path);
6309 cairo_surface_set_device_offset (icon, -x, -y);
6311 gtk_drag_set_icon_surface (context, icon);
6313 cairo_surface_destroy (icon);
6317 gtk_icon_view_drag_end (GtkWidget *widget,
6318 GdkDragContext *context)
6324 gtk_icon_view_drag_data_get (GtkWidget *widget,
6325 GdkDragContext *context,
6326 GtkSelectionData *selection_data,
6330 GtkIconView *icon_view;
6331 GtkTreeModel *model;
6332 GtkTreePath *source_row;
6334 icon_view = GTK_ICON_VIEW (widget);
6335 model = gtk_icon_view_get_model (icon_view);
6340 if (!icon_view->priv->source_set)
6343 source_row = get_source_row (context);
6345 if (source_row == NULL)
6348 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6349 * any model; for DragSource models there are some other targets
6353 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6354 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6359 /* If drag_data_get does nothing, try providing row data. */
6360 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6361 gtk_tree_set_row_drag_data (selection_data,
6366 gtk_tree_path_free (source_row);
6370 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6371 GdkDragContext *context)
6373 GtkTreeModel *model;
6374 GtkIconView *icon_view;
6375 GtkTreePath *source_row;
6377 icon_view = GTK_ICON_VIEW (widget);
6378 model = gtk_icon_view_get_model (icon_view);
6380 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6383 if (!icon_view->priv->source_set)
6386 source_row = get_source_row (context);
6388 if (source_row == NULL)
6391 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6394 gtk_tree_path_free (source_row);
6396 set_source_row (context, NULL, NULL);
6399 /* Target side drag signals */
6401 gtk_icon_view_drag_leave (GtkWidget *widget,
6402 GdkDragContext *context,
6405 GtkIconView *icon_view;
6407 icon_view = GTK_ICON_VIEW (widget);
6409 /* unset any highlight row */
6410 gtk_icon_view_set_drag_dest_item (icon_view,
6412 GTK_ICON_VIEW_DROP_LEFT);
6414 remove_scroll_timeout (icon_view);
6418 gtk_icon_view_drag_motion (GtkWidget *widget,
6419 GdkDragContext *context,
6424 GtkTreePath *path = NULL;
6425 GtkIconViewDropPosition pos;
6426 GtkIconView *icon_view;
6427 GdkDragAction suggested_action = 0;
6431 icon_view = GTK_ICON_VIEW (widget);
6433 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6436 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6438 /* we only know this *after* set_desination_row */
6439 empty = icon_view->priv->empty_view_drop;
6441 if (path == NULL && !empty)
6443 /* Can't drop here. */
6444 gdk_drag_status (context, 0, time);
6448 if (icon_view->priv->scroll_timeout_id == 0)
6450 icon_view->priv->scroll_timeout_id =
6451 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6454 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6456 /* Request data so we can use the source row when
6457 * determining whether to accept the drop
6459 set_status_pending (context, suggested_action);
6460 gtk_drag_get_data (widget, context, target, time);
6464 set_status_pending (context, 0);
6465 gdk_drag_status (context, suggested_action, time);
6470 gtk_tree_path_free (path);
6476 gtk_icon_view_drag_drop (GtkWidget *widget,
6477 GdkDragContext *context,
6482 GtkIconView *icon_view;
6484 GdkDragAction suggested_action = 0;
6485 GdkAtom target = GDK_NONE;
6486 GtkTreeModel *model;
6487 gboolean drop_append_mode;
6489 icon_view = GTK_ICON_VIEW (widget);
6490 model = gtk_icon_view_get_model (icon_view);
6492 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6494 if (!icon_view->priv->dest_set)
6497 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6500 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6503 path = get_logical_destination (icon_view, &drop_append_mode);
6505 if (target != GDK_NONE && path != NULL)
6507 /* in case a motion had requested drag data, change things so we
6508 * treat drag data receives as a drop.
6510 set_status_pending (context, 0);
6511 set_dest_row (context, model, path,
6512 icon_view->priv->empty_view_drop, drop_append_mode);
6516 gtk_tree_path_free (path);
6518 /* Unset this thing */
6519 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6521 if (target != GDK_NONE)
6523 gtk_drag_get_data (widget, context, target, time);
6531 gtk_icon_view_drag_data_received (GtkWidget *widget,
6532 GdkDragContext *context,
6535 GtkSelectionData *selection_data,
6540 gboolean accepted = FALSE;
6541 GtkTreeModel *model;
6542 GtkIconView *icon_view;
6543 GtkTreePath *dest_row;
6544 GdkDragAction suggested_action;
6545 gboolean drop_append_mode;
6547 icon_view = GTK_ICON_VIEW (widget);
6548 model = gtk_icon_view_get_model (icon_view);
6550 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6553 if (!icon_view->priv->dest_set)
6556 suggested_action = get_status_pending (context);
6558 if (suggested_action)
6560 /* We are getting this data due to a request in drag_motion,
6561 * rather than due to a request in drag_drop, so we are just
6562 * supposed to call drag_status, not actually paste in the
6565 path = get_logical_destination (icon_view, &drop_append_mode);
6568 suggested_action = 0;
6570 if (suggested_action)
6572 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6575 suggested_action = 0;
6578 gdk_drag_status (context, suggested_action, time);
6581 gtk_tree_path_free (path);
6583 /* If you can't drop, remove user drop indicator until the next motion */
6584 if (suggested_action == 0)
6585 gtk_icon_view_set_drag_dest_item (icon_view,
6587 GTK_ICON_VIEW_DROP_LEFT);
6592 dest_row = get_dest_row (context);
6594 if (dest_row == NULL)
6597 if (gtk_selection_data_get_length (selection_data) >= 0)
6599 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6605 gtk_drag_finish (context,
6607 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6610 gtk_tree_path_free (dest_row);
6613 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6616 /* Drag-and-Drop support */
6618 * gtk_icon_view_enable_model_drag_source:
6619 * @icon_view: a #GtkIconTreeView
6620 * @start_button_mask: Mask of allowed buttons to start drag
6621 * @targets: (array length=n_targets): the table of targets that the drag will
6623 * @n_targets: the number of items in @targets
6624 * @actions: the bitmask of possible actions for a drag from this
6627 * Turns @icon_view into a drag source for automatic DND. Calling this
6628 * method sets #GtkIconView:reorderable to %FALSE.
6633 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6634 GdkModifierType start_button_mask,
6635 const GtkTargetEntry *targets,
6637 GdkDragAction actions)
6639 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6641 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6643 icon_view->priv->start_button_mask = start_button_mask;
6644 icon_view->priv->source_actions = actions;
6646 icon_view->priv->source_set = TRUE;
6648 unset_reorderable (icon_view);
6652 * gtk_icon_view_enable_model_drag_dest:
6653 * @icon_view: a #GtkIconView
6654 * @targets: (array length=n_targets): the table of targets that the drag will
6656 * @n_targets: the number of items in @targets
6657 * @actions: the bitmask of possible actions for a drag to this
6660 * Turns @icon_view into a drop destination for automatic DND. Calling this
6661 * method sets #GtkIconView:reorderable to %FALSE.
6666 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6667 const GtkTargetEntry *targets,
6669 GdkDragAction actions)
6671 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6673 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6675 icon_view->priv->dest_actions = actions;
6677 icon_view->priv->dest_set = TRUE;
6679 unset_reorderable (icon_view);
6683 * gtk_icon_view_unset_model_drag_source:
6684 * @icon_view: a #GtkIconView
6686 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6687 * method sets #GtkIconView:reorderable to %FALSE.
6692 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6694 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6696 if (icon_view->priv->source_set)
6698 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6699 icon_view->priv->source_set = FALSE;
6702 unset_reorderable (icon_view);
6706 * gtk_icon_view_unset_model_drag_dest:
6707 * @icon_view: a #GtkIconView
6709 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6710 * method sets #GtkIconView:reorderable to %FALSE.
6715 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6717 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6719 if (icon_view->priv->dest_set)
6721 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6722 icon_view->priv->dest_set = FALSE;
6725 unset_reorderable (icon_view);
6728 /* These are useful to implement your own custom stuff. */
6730 * gtk_icon_view_set_drag_dest_item:
6731 * @icon_view: a #GtkIconView
6732 * @path: (allow-none): The path of the item to highlight, or %NULL.
6733 * @pos: Specifies where to drop, relative to the item
6735 * Sets the item that is highlighted for feedback.
6740 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6742 GtkIconViewDropPosition pos)
6744 /* Note; this function is exported to allow a custom DND
6745 * implementation, so it can't touch TreeViewDragInfo
6748 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6750 if (icon_view->priv->dest_item)
6752 GtkTreePath *current_path;
6753 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6754 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6755 icon_view->priv->dest_item = NULL;
6757 gtk_icon_view_queue_draw_path (icon_view, current_path);
6758 gtk_tree_path_free (current_path);
6761 /* special case a drop on an empty model */
6762 icon_view->priv->empty_view_drop = FALSE;
6763 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6764 && gtk_tree_path_get_depth (path) == 1
6765 && gtk_tree_path_get_indices (path)[0] == 0)
6769 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6772 if (n_children == 0)
6773 icon_view->priv->empty_view_drop = TRUE;
6776 icon_view->priv->dest_pos = pos;
6780 icon_view->priv->dest_item =
6781 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6782 icon_view->priv->model, path);
6784 gtk_icon_view_queue_draw_path (icon_view, path);
6789 * gtk_icon_view_get_drag_dest_item:
6790 * @icon_view: a #GtkIconView
6791 * @path: (out) (allow-none): Return location for the path of
6792 * the highlighted item, or %NULL.
6793 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6795 * Gets information about the item that is highlighted for feedback.
6800 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6802 GtkIconViewDropPosition *pos)
6804 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6808 if (icon_view->priv->dest_item)
6809 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6815 *pos = icon_view->priv->dest_pos;
6819 * gtk_icon_view_get_dest_item_at_pos:
6820 * @icon_view: a #GtkIconView
6821 * @drag_x: the position to determine the destination item for
6822 * @drag_y: the position to determine the destination item for
6823 * @path: (out) (allow-none): Return location for the path of the item,
6825 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6827 * Determines the destination item for a given position.
6829 * Return value: whether there is an item at the given position.
6834 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6838 GtkIconViewDropPosition *pos)
6840 GtkIconViewItem *item;
6842 /* Note; this function is exported to allow a custom DND
6843 * implementation, so it can't touch TreeViewDragInfo
6846 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6847 g_return_val_if_fail (drag_x >= 0, FALSE);
6848 g_return_val_if_fail (drag_y >= 0, FALSE);
6849 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6855 item = gtk_icon_view_get_item_at_coords (icon_view,
6856 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6857 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6864 *path = gtk_tree_path_new_from_indices (item->index, -1);
6868 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6869 *pos = GTK_ICON_VIEW_DROP_LEFT;
6870 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6871 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6872 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6873 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6874 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6875 *pos = GTK_ICON_VIEW_DROP_BELOW;
6877 *pos = GTK_ICON_VIEW_DROP_INTO;
6884 * gtk_icon_view_create_drag_icon:
6885 * @icon_view: a #GtkIconView
6886 * @path: a #GtkTreePath in @icon_view
6888 * Creates a #cairo_surface_t representation of the item at @path.
6889 * This image is used for a drag icon.
6891 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6896 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6900 GtkStyleContext *context;
6902 cairo_surface_t *surface;
6906 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6907 g_return_val_if_fail (path != NULL, NULL);
6909 widget = GTK_WIDGET (icon_view);
6910 context = gtk_widget_get_style_context (widget);
6912 if (!gtk_widget_get_realized (widget))
6915 index = gtk_tree_path_get_indices (path)[0];
6917 for (l = icon_view->priv->items; l; l = l->next)
6919 GtkIconViewItem *item = l->data;
6921 if (index == item->index)
6923 GdkRectangle rect = {
6924 item->cell_area.x - icon_view->priv->item_padding,
6925 item->cell_area.y - icon_view->priv->item_padding,
6926 item->cell_area.width + icon_view->priv->item_padding * 2,
6927 item->cell_area.height + icon_view->priv->item_padding * 2
6930 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6931 CAIRO_CONTENT_COLOR,
6935 cr = cairo_create (surface);
6936 cairo_set_line_width (cr, 1.);
6938 gtk_render_background (context, cr, 0, 0,
6939 rect.width + 2, rect.height + 2);
6943 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6946 gtk_icon_view_paint_item (icon_view, cr, item,
6947 icon_view->priv->item_padding + 1,
6948 icon_view->priv->item_padding + 1, FALSE);
6952 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6953 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6966 * gtk_icon_view_get_reorderable:
6967 * @icon_view: a #GtkIconView
6969 * Retrieves whether the user can reorder the list via drag-and-drop.
6970 * See gtk_icon_view_set_reorderable().
6972 * Return value: %TRUE if the list can be reordered.
6977 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6979 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6981 return icon_view->priv->reorderable;
6984 static const GtkTargetEntry item_targets[] = {
6985 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6990 * gtk_icon_view_set_reorderable:
6991 * @icon_view: A #GtkIconView.
6992 * @reorderable: %TRUE, if the list of items can be reordered.
6994 * This function is a convenience function to allow you to reorder models that
6995 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6996 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6997 * the user can reorder the model by dragging and dropping rows. The
6998 * developer can listen to these changes by connecting to the model's
6999 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7000 * the icon view as a drag source and destination. Therefore, drag and
7001 * drop can not be used in a reorderable view for any other purpose.
7003 * This function does not give you any degree of control over the order -- any
7004 * reordering is allowed. If more control is needed, you should probably
7005 * handle drag and drop manually.
7010 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7011 gboolean reorderable)
7013 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7015 reorderable = reorderable != FALSE;
7017 if (icon_view->priv->reorderable == reorderable)
7022 gtk_icon_view_enable_model_drag_source (icon_view,
7025 G_N_ELEMENTS (item_targets),
7027 gtk_icon_view_enable_model_drag_dest (icon_view,
7029 G_N_ELEMENTS (item_targets),
7034 gtk_icon_view_unset_model_drag_source (icon_view);
7035 gtk_icon_view_unset_model_drag_dest (icon_view);
7038 icon_view->priv->reorderable = reorderable;
7040 g_object_notify (G_OBJECT (icon_view), "reorderable");
7044 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7045 GtkBuilder *builder,
7047 const gchar *tagname,
7048 GMarkupParser *parser,
7051 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7052 tagname, parser, data))
7055 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7056 tagname, parser, data);
7060 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7061 GtkBuilder *builder,
7063 const gchar *tagname,
7066 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7067 child, tagname, data))
7068 parent_buildable_iface->custom_tag_end (buildable, builder,
7069 child, tagname, data);
7072 /* Accessibility Support */
7074 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (_gtk_icon_view_item_accessible_get_type ())
7075 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7076 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7082 GtkIconViewItem *item;
7084 AtkStateSet *state_set;
7086 gchar *action_description;
7087 gchar *image_description;
7088 guint action_idle_handler;
7089 } GtkIconViewItemAccessible;
7093 AtkObjectClass parent_class;
7095 } GtkIconViewItemAccessibleClass;
7097 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7099 static void atk_component_item_interface_init (AtkComponentIface *iface);
7100 static void atk_action_item_interface_init (AtkActionIface *iface);
7101 static void atk_text_item_interface_init (AtkTextIface *iface);
7102 static void atk_image_item_interface_init (AtkImageIface *iface);
7104 G_DEFINE_TYPE_WITH_CODE (GtkIconViewItemAccessible, _gtk_icon_view_item_accessible, ATK_TYPE_OBJECT,
7105 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_item_interface_init)
7106 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_item_interface_init)
7107 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_item_interface_init)
7108 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_item_interface_init))
7112 idle_do_action (gpointer data)
7114 GtkIconViewItemAccessible *item;
7115 GtkIconView *icon_view;
7118 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7119 item->action_idle_handler = 0;
7121 if (item->widget != NULL)
7123 icon_view = GTK_ICON_VIEW (item->widget);
7124 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7125 gtk_icon_view_item_activated (icon_view, path);
7126 gtk_tree_path_free (path);
7133 gtk_icon_view_item_accessible_do_action (AtkAction *action,
7136 GtkIconViewItemAccessible *item;
7141 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7143 if (!GTK_IS_ICON_VIEW (item->widget))
7146 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7149 if (!item->action_idle_handler)
7150 item->action_idle_handler = gdk_threads_add_idle (idle_do_action, item);
7156 gtk_icon_view_item_accessible_get_n_actions (AtkAction *action)
7161 static const gchar *
7162 gtk_icon_view_item_accessible_get_description (AtkAction *action,
7165 GtkIconViewItemAccessible *item;
7170 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7172 if (item->action_description)
7173 return item->action_description;
7175 return "Activate item";
7178 static const gchar *
7179 gtk_icon_view_item_accessible_get_name (AtkAction *action,
7189 gtk_icon_view_item_accessible_set_description (AtkAction *action,
7191 const gchar *description)
7193 GtkIconViewItemAccessible *item;
7198 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7200 g_free (item->action_description);
7201 item->action_description = g_strdup (description);
7207 atk_action_item_interface_init (AtkActionIface *iface)
7209 iface->do_action = gtk_icon_view_item_accessible_do_action;
7210 iface->set_description = gtk_icon_view_item_accessible_set_description;
7211 iface->get_name = gtk_icon_view_item_accessible_get_name;
7212 iface->get_n_actions = gtk_icon_view_item_accessible_get_n_actions;
7213 iface->get_description = gtk_icon_view_item_accessible_get_description;
7216 static const gchar *
7217 gtk_icon_view_item_accessible_get_image_description (AtkImage *image)
7219 GtkIconViewItemAccessible *item;
7221 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7223 return item->image_description;
7227 gtk_icon_view_item_accessible_set_image_description (AtkImage *image,
7228 const gchar *description)
7230 GtkIconViewItemAccessible *item;
7232 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7234 g_free (item->image_description);
7235 item->image_description = g_strdup (description);
7242 gboolean pixbuf_found;
7246 get_pixbuf_foreach (GtkCellRenderer *renderer,
7247 const GdkRectangle *cell_area,
7248 const GdkRectangle *cell_background,
7249 GetPixbufBoxData *data)
7251 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7253 data->box = *cell_area;
7254 data->pixbuf_found = TRUE;
7256 return (data->pixbuf_found != FALSE);
7260 get_pixbuf_box (GtkIconView *icon_view,
7261 GtkIconViewItem *item,
7264 GetPixbufBoxData data = { { 0, }, FALSE };
7265 GtkCellAreaContext *context;
7267 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7269 gtk_icon_view_set_cell_data (icon_view, item);
7270 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7271 GTK_WIDGET (icon_view),
7272 (GdkRectangle *)item, (GdkRectangle *)item,
7273 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7275 return data.pixbuf_found;
7279 get_text_foreach (GtkCellRenderer *renderer,
7282 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7284 g_object_get (renderer, "text", text, NULL);
7291 get_text (GtkIconView *icon_view,
7292 GtkIconViewItem *item)
7296 gtk_icon_view_set_cell_data (icon_view, item);
7297 gtk_cell_area_foreach (icon_view->priv->cell_area,
7298 (GtkCellCallback)get_text_foreach, &text);
7304 gtk_icon_view_item_accessible_get_image_size (AtkImage *image,
7308 GtkIconViewItemAccessible *item;
7311 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7313 if (!GTK_IS_ICON_VIEW (item->widget))
7316 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7319 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7322 *height = box.height;
7327 gtk_icon_view_item_accessible_get_image_position (AtkImage *image,
7330 AtkCoordType coord_type)
7332 GtkIconViewItemAccessible *item;
7335 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7337 if (!GTK_IS_ICON_VIEW (item->widget))
7340 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7343 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7345 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7347 *x+= box.x - item->item->cell_area.x;
7348 *y+= box.y - item->item->cell_area.y;
7354 atk_image_item_interface_init (AtkImageIface *iface)
7356 iface->get_image_description = gtk_icon_view_item_accessible_get_image_description;
7357 iface->set_image_description = gtk_icon_view_item_accessible_set_image_description;
7358 iface->get_image_size = gtk_icon_view_item_accessible_get_image_size;
7359 iface->get_image_position = gtk_icon_view_item_accessible_get_image_position;
7363 gtk_icon_view_item_accessible_get_text (AtkText *text,
7367 GtkIconViewItemAccessible *item;
7369 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7370 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7374 return g_utf8_substring (item->text, start_pos, end_pos > -1 ? end_pos : g_utf8_strlen (item->text, -1));
7376 return g_strdup ("");
7380 gtk_icon_view_item_accessible_get_character_at_offset (AtkText *text,
7383 GtkIconViewItemAccessible *item;
7387 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7388 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7391 string = item->text;
7396 if (offset >= g_utf8_strlen (string, -1))
7399 index = g_utf8_offset_to_pointer (string, offset);
7401 return g_utf8_get_char (index);
7404 static PangoLayout *
7405 create_pango_layout (GtkIconViewItemAccessible *item)
7407 PangoLayout *layout;
7409 layout = gtk_widget_create_pango_layout (item->widget, item->text);
7415 gtk_icon_view_item_accessible_get_text_before_offset (AtkText *atk_text,
7417 AtkTextBoundary boundary_type,
7421 GtkIconViewItemAccessible *item;
7422 PangoLayout *layout;
7425 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7426 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7429 layout = create_pango_layout (item);
7430 text = _gtk_pango_get_text_before (layout, boundary_type, offset, start_offset, end_offset);
7431 g_object_unref (layout);
7437 gtk_icon_view_item_accessible_get_text_at_offset (AtkText *atk_text,
7439 AtkTextBoundary boundary_type,
7443 GtkIconViewItemAccessible *item;
7444 PangoLayout *layout;
7447 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7448 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7451 layout = create_pango_layout (item);
7452 text = _gtk_pango_get_text_at (layout, boundary_type, offset, start_offset, end_offset);
7453 g_object_unref (layout);
7459 gtk_icon_view_item_accessible_get_text_after_offset (AtkText *atk_text,
7461 AtkTextBoundary boundary_type,
7465 GtkIconViewItemAccessible *item;
7466 PangoLayout *layout;
7469 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7470 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7473 layout = create_pango_layout (item);
7474 text = _gtk_pango_get_text_after (layout, boundary_type, offset, start_offset, end_offset);
7475 g_object_unref (layout);
7481 gtk_icon_view_item_accessible_get_character_count (AtkText *text)
7483 GtkIconViewItemAccessible *item;
7485 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7486 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7490 return g_utf8_strlen (item->text, -1);
7496 gtk_icon_view_item_accessible_get_character_extents (AtkText *text,
7502 AtkCoordType coord_type)
7504 GtkIconViewItemAccessible *item;
7506 GtkIconView *icon_view;
7507 PangoRectangle char_rect;
7508 const gchar *item_text;
7512 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7514 if (!GTK_IS_ICON_VIEW (item->widget))
7517 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7521 icon_view = GTK_ICON_VIEW (item->widget);
7522 /* FIXME we probably have to use GailTextCell to salvage this */
7523 gtk_icon_view_update_item_text (icon_view, item->item);
7524 item_text = pango_layout_get_text (icon_view->priv->layout);
7525 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7526 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7528 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7529 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7530 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7531 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7532 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7533 *width = char_rect.width / PANGO_SCALE;
7534 *height = char_rect.height / PANGO_SCALE;
7539 gtk_icon_view_item_accessible_get_offset_at_point (AtkText *text,
7542 AtkCoordType coord_type)
7544 GtkIconViewItemAccessible *item;
7547 GtkIconView *icon_view;
7548 const gchar *item_text;
7553 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7555 if (!GTK_IS_ICON_VIEW (item->widget))
7558 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7562 icon_view = GTK_ICON_VIEW (item->widget);
7563 /* FIXME we probably have to use GailTextCell to salvage this */
7564 gtk_icon_view_update_item_text (icon_view, item->item);
7565 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7566 x -= l_x + item->item->layout_x - item->item->x;
7567 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7568 y -= l_y + item->item->layout_y - item->item->y;
7569 item_text = pango_layout_get_text (icon_view->priv->layout);
7570 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7581 offset = g_utf8_strlen (item_text, -1);
7583 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7589 atk_text_item_interface_init (AtkTextIface *iface)
7591 iface->get_text = gtk_icon_view_item_accessible_get_text;
7592 iface->get_character_at_offset = gtk_icon_view_item_accessible_get_character_at_offset;
7593 iface->get_text_before_offset = gtk_icon_view_item_accessible_get_text_before_offset;
7594 iface->get_text_at_offset = gtk_icon_view_item_accessible_get_text_at_offset;
7595 iface->get_text_after_offset = gtk_icon_view_item_accessible_get_text_after_offset;
7596 iface->get_character_count = gtk_icon_view_item_accessible_get_character_count;
7597 iface->get_character_extents = gtk_icon_view_item_accessible_get_character_extents;
7598 iface->get_offset_at_point = gtk_icon_view_item_accessible_get_offset_at_point;
7602 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7607 AtkCoordType coord_type)
7609 GtkIconViewItemAccessible *item;
7610 AtkObject *parent_obj;
7613 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7615 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7616 if (!GTK_IS_WIDGET (item->widget))
7619 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7622 *width = item->item->cell_area.width;
7623 *height = item->item->cell_area.height;
7624 if (gtk_icon_view_item_accessible_is_showing (item))
7626 parent_obj = gtk_widget_get_accessible (item->widget);
7627 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7628 *x = l_x + item->item->cell_area.x;
7629 *y = l_y + item->item->cell_area.y;
7639 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7641 GtkIconViewItemAccessible *item;
7642 GtkWidget *toplevel;
7644 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7646 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7647 if (!GTK_IS_WIDGET (item->widget))
7650 gtk_widget_grab_focus (item->widget);
7651 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7652 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7653 if (gtk_widget_is_toplevel (toplevel))
7654 gtk_window_present (GTK_WINDOW (toplevel));
7660 atk_component_item_interface_init (AtkComponentIface *iface)
7662 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7663 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7667 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7668 AtkStateType state_type,
7669 gboolean emit_signal)
7673 rc = atk_state_set_add_state (item->state_set, state_type);
7675 /* The signal should only be generated if the value changed,
7676 * not when the item is set up. So states that are set
7677 * initially should pass FALSE as the emit_signal argument.
7681 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7682 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7683 if (state_type == ATK_STATE_VISIBLE)
7684 g_signal_emit_by_name (item, "visible-data-changed");
7691 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7692 AtkStateType state_type,
7693 gboolean emit_signal)
7695 if (atk_state_set_contains_state (item->state_set, state_type))
7699 rc = atk_state_set_remove_state (item->state_set, state_type);
7701 /* The signal should only be generated if the value changed,
7702 * not when the item is set up. So states that are set
7703 * initially should pass FALSE as the emit_signal argument.
7707 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7708 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7709 if (state_type == ATK_STATE_VISIBLE)
7710 g_signal_emit_by_name (item, "visible-data-changed");
7720 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7722 GtkAllocation allocation;
7723 GtkIconView *icon_view;
7724 GdkRectangle visible_rect;
7725 gboolean is_showing;
7727 /* An item is considered "SHOWING" if any part of the item
7728 * is in the visible rectangle.
7730 if (!GTK_IS_ICON_VIEW (item->widget))
7733 if (item->item == NULL)
7736 gtk_widget_get_allocation (item->widget, &allocation);
7738 icon_view = GTK_ICON_VIEW (item->widget);
7740 if (icon_view->priv->hadjustment)
7741 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
7743 if (icon_view->priv->hadjustment)
7744 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
7745 visible_rect.width = allocation.width;
7746 visible_rect.height = allocation.height;
7748 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
7749 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
7750 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
7751 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
7760 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7761 gboolean emit_signal)
7763 if (gtk_icon_view_item_accessible_is_showing (item))
7764 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7767 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7772 _gtk_icon_view_item_accessible_init (GtkIconViewItemAccessible *item)
7774 item->state_set = atk_state_set_new ();
7776 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7777 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7778 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7779 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7780 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7782 item->action_description = NULL;
7783 item->image_description = NULL;
7785 item->action_idle_handler = 0;
7789 gtk_icon_view_item_accessible_finalize (GObject *object)
7791 GtkIconViewItemAccessible *item;
7793 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7796 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7798 if (item->state_set)
7799 g_object_unref (item->state_set);
7802 g_free (item->text);
7803 g_free (item->action_description);
7804 g_free (item->image_description);
7806 if (item->action_idle_handler)
7808 g_source_remove (item->action_idle_handler);
7809 item->action_idle_handler = 0;
7812 G_OBJECT_CLASS (_gtk_icon_view_item_accessible_parent_class)->finalize (object);
7816 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7818 GtkIconViewItemAccessible *item;
7820 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7821 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7824 return gtk_widget_get_accessible (item->widget);
7830 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7832 GtkIconViewItemAccessible *item;
7834 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7835 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7837 return item->item->index;
7840 static AtkStateSet *
7841 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7843 GtkIconViewItemAccessible *item;
7844 GtkIconView *icon_view;
7846 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7847 g_return_val_if_fail (item->state_set, NULL);
7852 icon_view = GTK_ICON_VIEW (item->widget);
7853 if (icon_view->priv->cursor_item == item->item)
7854 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7856 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7857 if (item->item->selected)
7858 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
7860 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
7862 return g_object_ref (item->state_set);
7866 _gtk_icon_view_item_accessible_class_init (GtkIconViewItemAccessibleClass *klass)
7868 GObjectClass *gobject_class;
7869 AtkObjectClass *atk_class;
7871 gobject_class = (GObjectClass *)klass;
7872 atk_class = (AtkObjectClass *)klass;
7874 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7876 atk_class->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7877 atk_class->get_parent = gtk_icon_view_item_accessible_get_parent;
7878 atk_class->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7881 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (_gtk_icon_view_accessible_get_type ())
7882 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
7883 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
7887 GtkContainerAccessible parent;
7890 GtkAdjustment *old_hadj;
7891 GtkAdjustment *old_vadj;
7892 GtkTreeModel *model;
7893 } GtkIconViewAccessible;
7895 typedef GtkContainerAccessibleClass GtkIconViewAccessibleClass;
7897 static void atk_component_interface_init (AtkComponentIface *iface);
7898 static void atk_selection_interface_init (AtkSelectionIface *iface);
7900 G_DEFINE_TYPE_WITH_CODE (GtkIconViewAccessible, _gtk_icon_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
7901 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
7902 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
7908 } GtkIconViewItemAccessibleInfo;
7912 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
7916 GtkIconViewAccessible *view = (GtkIconViewAccessible *)accessible;
7917 GtkIconViewItemAccessibleInfo *info;
7918 GtkIconViewItemAccessibleInfo *tmp_info;
7921 info = g_new (GtkIconViewItemAccessibleInfo, 1);
7923 info->index = index;
7925 items = view->items;
7928 tmp_info = items->data;
7929 if (tmp_info->index > index)
7931 items = items->next;
7933 view->items = g_list_insert_before (view->items, items, info);
7934 view->old_hadj = NULL;
7935 view->old_vadj = NULL;
7939 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
7941 GtkIconView *icon_view;
7944 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
7948 icon_view = GTK_ICON_VIEW (widget);
7950 return g_list_length (icon_view->priv->items);
7954 gtk_icon_view_accessible_find_child (AtkObject *accessible,
7957 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
7958 GtkIconViewItemAccessibleInfo *info;
7961 items = view->items;
7966 if (info->index == index)
7968 items = items->next;
7975 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
7978 GtkIconView *icon_view;
7982 GtkIconViewItemAccessible *a11y_item;
7984 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
7988 icon_view = GTK_ICON_VIEW (widget);
7989 icons = g_list_nth (icon_view->priv->items, index);
7993 GtkIconViewItem *item = icons->data;
7995 g_return_val_if_fail (item->index == index, NULL);
7996 obj = gtk_icon_view_accessible_find_child (accessible, index);
7999 obj = g_object_new (GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, NULL);
8000 gtk_icon_view_item_accessible_info_new (accessible, obj, index);
8001 obj->role = ATK_ROLE_ICON;
8002 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8003 a11y_item->item = item;
8004 a11y_item->widget = widget;
8006 g_free (a11y_item->text);
8007 a11y_item->text = get_text (icon_view, item);
8009 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8010 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8018 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8021 GtkIconViewItemAccessibleInfo *info;
8022 GtkIconViewItemAccessible *item;
8028 gboolean act_on_item;
8030 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8034 items = view->items;
8036 act_on_item = (list == NULL);
8041 info = (GtkIconViewItemAccessibleInfo *)items->data;
8042 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8044 if (act_on_item == FALSE && list == items)
8048 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8050 items = items->next;
8056 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8057 GtkIconViewAccessible *view)
8059 gtk_icon_view_accessible_traverse_items (view, NULL);
8063 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8064 GtkOrientation orientation,
8065 GtkAdjustment *adjustment)
8067 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
8068 GtkAdjustment **old_adj_ptr;
8070 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8072 if (view->old_hadj == adjustment)
8075 old_adj_ptr = &view->old_hadj;
8079 if (view->old_vadj == adjustment)
8082 old_adj_ptr = &view->old_vadj;
8085 /* Disconnect signal handlers */
8088 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8089 (gpointer *)&view->old_hadj);
8090 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8091 gtk_icon_view_accessible_adjustment_changed,
8095 /* Connect signal */
8096 *old_adj_ptr = adjustment;
8097 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8098 g_signal_connect (adjustment, "value-changed",
8099 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8104 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8112 GtkIconView *icon_view;
8113 GtkIconViewItem *item;
8114 GtkIconViewItemAccessible *a11y_item;
8117 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8118 index = gtk_tree_path_get_indices(path)[0];
8119 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8120 gtk_icon_view_accessible_find_child (atk_obj, index));
8124 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8125 icon_view = GTK_ICON_VIEW (widget);
8126 item = a11y_item->item;
8128 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8129 if (!name || strcmp (name, "") == 0)
8131 g_free (a11y_item->text);
8132 a11y_item->text = get_text (icon_view, item);
8136 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8142 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8147 GtkIconViewItemAccessibleInfo *info;
8148 GtkIconViewAccessible *view;
8149 GtkIconViewItemAccessible *item;
8155 index = gtk_tree_path_get_indices(path)[0];
8156 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8157 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8159 items = view->items;
8164 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8165 if (info->index != item->item->index)
8167 if (info->index < index)
8168 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8170 if (tmp_list == NULL)
8173 info->index = item->item->index;
8176 items = items->next;
8178 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8179 g_signal_emit_by_name (atk_obj, "children-changed::add",
8185 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8189 GtkIconViewItemAccessibleInfo *info;
8190 GtkIconViewAccessible *view;
8191 GtkIconViewItemAccessible *item;
8194 GList *deleted_item;
8198 index = gtk_tree_path_get_indices(path)[0];
8199 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8200 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8202 items = view->items;
8204 deleted_item = NULL;
8209 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8210 if (info->index == index)
8212 deleted_item = items;
8214 if (info->index != item->item->index)
8216 if (tmp_list == NULL)
8219 info->index = item->item->index;
8222 items = items->next;
8224 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8227 info = deleted_item->data;
8228 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8229 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8231 view->items = g_list_remove_link (view->items, deleted_item);
8239 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8240 GtkIconViewItemAccessibleInfo *i2)
8242 return i1->index - i2->index;
8246 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8252 GtkIconViewAccessible *view;
8253 GtkIconViewItemAccessibleInfo *info;
8254 GtkIconView *icon_view;
8255 GtkIconViewItemAccessible *item;
8261 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8262 icon_view = GTK_ICON_VIEW (user_data);
8263 view = (GtkIconViewAccessible*)atk_obj;
8265 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8267 order = g_new (gint, length);
8268 for (i = 0; i < length; i++)
8269 order [new_order[i]] = i;
8271 items = view->items;
8275 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8276 info->index = order[info->index];
8277 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8278 items = items->next;
8281 view->items = g_list_sort (view->items,
8282 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8288 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8293 obj = G_OBJECT (model);
8294 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8295 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8296 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8297 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8301 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8305 obj = G_OBJECT (icon_view->priv->model);
8306 g_signal_connect_data (obj, "row-changed",
8307 (GCallback) gtk_icon_view_accessible_model_row_changed,
8308 icon_view, NULL, 0);
8309 g_signal_connect_data (obj, "row-inserted",
8310 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8311 icon_view, NULL, G_CONNECT_AFTER);
8312 g_signal_connect_data (obj, "row-deleted",
8313 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8314 icon_view, NULL, G_CONNECT_AFTER);
8315 g_signal_connect_data (obj, "rows-reordered",
8316 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8317 icon_view, NULL, G_CONNECT_AFTER);
8321 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessible *view)
8323 GtkIconViewItemAccessibleInfo *info;
8326 items = view->items;
8329 info = (GtkIconViewItemAccessibleInfo *) items->data;
8330 g_object_unref (info->item);
8331 g_free (items->data);
8332 items = items->next;
8334 g_list_free (view->items);
8339 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8342 GtkIconView *icon_view;
8345 GtkIconViewAccessible *view;
8347 if (strcmp (pspec->name, "model") == 0)
8349 widget = GTK_WIDGET (obj);
8350 atk_obj = gtk_widget_get_accessible (widget);
8351 view = (GtkIconViewAccessible*)atk_obj;
8354 g_object_remove_weak_pointer (G_OBJECT (view->model),
8355 (gpointer *)&view->model);
8356 gtk_icon_view_accessible_disconnect_model_signals (view->model, widget);
8358 gtk_icon_view_accessible_clear_cache (view);
8360 icon_view = GTK_ICON_VIEW (obj);
8361 view->model = icon_view->priv->model;
8362 /* If there is no model the GtkIconView is probably being destroyed */
8365 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8366 gtk_icon_view_accessible_connect_model_signals (icon_view);
8374 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8377 GtkIconViewAccessible *view;
8378 GtkIconView *icon_view;
8380 if (ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize)
8381 ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize (accessible, data);
8383 icon_view = (GtkIconView*)data;
8384 view = (GtkIconViewAccessible*)accessible;
8386 if (icon_view->priv->hadjustment)
8387 gtk_icon_view_accessible_set_adjustment (accessible,
8388 GTK_ORIENTATION_HORIZONTAL,
8389 icon_view->priv->hadjustment);
8390 if (icon_view->priv->vadjustment)
8391 gtk_icon_view_accessible_set_adjustment (accessible,
8392 GTK_ORIENTATION_VERTICAL,
8393 icon_view->priv->vadjustment);
8394 g_signal_connect (data, "notify",
8395 G_CALLBACK (gtk_icon_view_accessible_notify_gtk), NULL);
8397 view->model = icon_view->priv->model;
8400 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8401 gtk_icon_view_accessible_connect_model_signals (icon_view);
8404 accessible->role = ATK_ROLE_LAYERED_PANE;
8408 gtk_icon_view_accessible_finalize (GObject *object)
8410 GtkIconViewAccessible *view = (GtkIconViewAccessible*)object;
8412 gtk_icon_view_accessible_clear_cache (view);
8414 G_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->finalize (object);
8418 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8419 GtkAccessible *accessible)
8422 GtkIconViewAccessible *view;
8424 atk_obj = ATK_OBJECT (accessible);
8425 view = (GtkIconViewAccessible*)atk_obj;
8428 g_object_remove_weak_pointer (G_OBJECT (view->old_hadj),
8429 (gpointer *)&view->old_hadj);
8431 g_signal_handlers_disconnect_by_func (view->old_hadj,
8432 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8434 view->old_hadj = NULL;
8438 g_object_remove_weak_pointer (G_OBJECT (view->old_vadj),
8439 (gpointer *)&view->old_vadj);
8441 g_signal_handlers_disconnect_by_func (view->old_vadj,
8442 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8444 view->old_vadj = NULL;
8449 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8453 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8456 g_signal_connect_after (widget, "destroy",
8457 G_CALLBACK (gtk_icon_view_accessible_destroyed), accessible);
8459 GTK_ACCESSIBLE_CLASS (_gtk_icon_view_accessible_parent_class)->connect_widget_destroyed (accessible);
8463 _gtk_icon_view_accessible_class_init (GtkIconViewAccessibleClass *klass)
8465 GObjectClass *gobject_class;
8466 GtkAccessibleClass *accessible_class;
8467 AtkObjectClass *atk_class;
8469 gobject_class = (GObjectClass *)klass;
8470 accessible_class = (GtkAccessibleClass *)klass;
8471 atk_class = (AtkObjectClass *)klass;
8473 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8475 atk_class->get_n_children = gtk_icon_view_accessible_get_n_children;
8476 atk_class->ref_child = gtk_icon_view_accessible_ref_child;
8477 atk_class->initialize = gtk_icon_view_accessible_initialize;
8479 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8483 _gtk_icon_view_accessible_init (GtkIconViewAccessible *accessible)
8488 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8491 AtkCoordType coord_type)
8494 GtkIconView *icon_view;
8495 GtkIconViewItem *item;
8498 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8502 icon_view = GTK_ICON_VIEW (widget);
8503 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8504 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8506 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8512 atk_component_interface_init (AtkComponentIface *iface)
8514 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8518 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8522 GtkIconView *icon_view;
8523 GtkIconViewItem *item;
8525 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8529 icon_view = GTK_ICON_VIEW (widget);
8531 item = g_list_nth_data (icon_view->priv->items, i);
8535 gtk_icon_view_select_item (icon_view, item);
8541 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8544 GtkIconView *icon_view;
8546 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8550 icon_view = GTK_ICON_VIEW (widget);
8551 gtk_icon_view_unselect_all (icon_view);
8557 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8562 GtkIconView *icon_view;
8563 GtkIconViewItem *item;
8565 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8569 icon_view = GTK_ICON_VIEW (widget);
8571 l = icon_view->priv->items;
8578 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8589 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8592 GtkIconView *icon_view;
8593 GtkIconViewItem *item;
8597 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8601 icon_view = GTK_ICON_VIEW (widget);
8603 l = icon_view->priv->items;
8619 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8623 GtkIconView *icon_view;
8624 GtkIconViewItem *item;
8626 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8630 icon_view = GTK_ICON_VIEW (widget);
8632 item = g_list_nth_data (icon_view->priv->items, i);
8636 return item->selected;
8640 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8644 GtkIconView *icon_view;
8645 GtkIconViewItem *item;
8649 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8653 icon_view = GTK_ICON_VIEW (widget);
8654 l = icon_view->priv->items;
8663 gtk_icon_view_unselect_item (icon_view, item);
8675 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8678 GtkIconView *icon_view;
8680 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8684 icon_view = GTK_ICON_VIEW (widget);
8685 gtk_icon_view_select_all (icon_view);
8690 atk_selection_interface_init (AtkSelectionIface *iface)
8692 iface->add_selection = gtk_icon_view_accessible_add_selection;
8693 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8694 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8695 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8696 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8697 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8698 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;