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;
87 guint selected_before_rubberbanding : 1;
91 typedef struct _GtkIconViewChild GtkIconViewChild;
92 struct _GtkIconViewChild
98 struct _GtkIconViewPrivate
100 GtkCellArea *cell_area;
101 GtkCellAreaContext *cell_area_context;
103 gulong add_editable_id;
104 gulong remove_editable_id;
105 gulong context_changed_id;
107 GPtrArray *row_contexts;
111 GtkSelectionMode selection_mode;
113 guint layout_idle_id;
115 GdkWindow *bin_window;
123 GtkAdjustment *hadjustment;
124 GtkAdjustment *vadjustment;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
128 GdkDevice *rubberband_device;
130 guint scroll_timeout_id;
131 gint scroll_value_diff;
132 gint event_last_x, event_last_y;
134 GtkIconViewItem *anchor_item;
135 GtkIconViewItem *cursor_item;
137 GtkIconViewItem *last_single_clicked;
138 GtkIconViewItem *last_prelight;
140 GtkOrientation item_orientation;
155 GtkCellRenderer *pixbuf_cell;
156 GtkCellRenderer *text_cell;
159 GdkModifierType start_button_mask;
164 GdkDragAction source_actions;
165 GdkDragAction dest_actions;
167 GtkTreeRowReference *dest_item;
168 GtkIconViewDropPosition dest_pos;
171 GtkTreeRowReference *scroll_to_path;
172 gfloat scroll_to_row_align;
173 gfloat scroll_to_col_align;
174 guint scroll_to_use_align : 1;
176 guint source_set : 1;
178 guint reorderable : 1;
179 guint empty_view_drop :1;
181 guint modify_selection_pressed : 1;
182 guint extend_selection_pressed : 1;
184 guint draw_focus : 1;
186 /* GtkScrollablePolicy needs to be checked when
187 * driving the scrollable adjustment values */
188 guint hscroll_policy : 1;
189 guint vscroll_policy : 1;
191 guint doing_rubberband : 1;
205 ACTIVATE_CURSOR_ITEM,
217 PROP_ITEM_ORIENTATION,
230 /* For scrollable interface */
238 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
239 static void gtk_icon_view_dispose (GObject *object);
240 static GObject *gtk_icon_view_constructor (GType type,
241 guint n_construct_properties,
242 GObjectConstructParam *construct_properties);
243 static void gtk_icon_view_set_property (GObject *object,
247 static void gtk_icon_view_get_property (GObject *object,
251 /* GtkWidget vfuncs */
252 static void gtk_icon_view_destroy (GtkWidget *widget);
253 static void gtk_icon_view_realize (GtkWidget *widget);
254 static void gtk_icon_view_unrealize (GtkWidget *widget);
255 static void gtk_icon_view_style_updated (GtkWidget *widget);
256 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
257 GtkStateFlags previous_state);
258 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
261 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
264 static void gtk_icon_view_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static gboolean gtk_icon_view_draw (GtkWidget *widget,
268 static gboolean gtk_icon_view_motion (GtkWidget *widget,
269 GdkEventMotion *event);
270 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
273 GdkEventButton *event);
274 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
276 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
280 /* GtkContainer vfuncs */
281 static void gtk_icon_view_remove (GtkContainer *container,
283 static void gtk_icon_view_forall (GtkContainer *container,
284 gboolean include_internals,
285 GtkCallback callback,
286 gpointer callback_data);
288 /* GtkIconView vfuncs */
289 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
291 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
292 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
293 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
295 /* Internal functions */
296 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
297 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
298 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
299 GtkAdjustment *adjustment);
300 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
301 GtkAdjustment *adjustment);
302 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
303 GtkOrientation orientation,
304 GtkAdjustment *adjustment);
305 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
306 GtkIconView *icon_view);
307 static void gtk_icon_view_layout (GtkIconView *icon_view);
308 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
310 GtkIconViewItem *item,
313 gboolean draw_focus);
314 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
316 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
318 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
319 GtkIconViewItem *item);
320 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
321 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
322 GtkIconViewItem *item,
323 GtkCellRenderer *cursor_cell);
324 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
328 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
329 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
330 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
331 GtkIconViewItem *item,
336 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
337 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
338 static void gtk_icon_view_update_rubberband (gpointer data);
339 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
340 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
341 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
344 GtkMovementStep step,
346 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
347 GtkMovementStep step,
349 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
351 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
353 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
355 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
357 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
358 GtkIconViewItem *item);
359 static void gtk_icon_view_select_item (GtkIconView *icon_view,
360 GtkIconViewItem *item);
361 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
362 GtkIconViewItem *item);
363 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
364 GtkIconViewItem *anchor,
365 GtkIconViewItem *cursor);
366 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
369 gboolean only_in_cell,
370 GtkCellRenderer **cell_at_pos);
371 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
372 GtkIconViewItem *item);
374 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
375 GtkCellArea *cell_area);
377 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
379 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
380 GtkIconViewItem *item);
382 static void gtk_icon_view_add_editable (GtkCellArea *area,
383 GtkCellRenderer *renderer,
384 GtkCellEditable *editable,
385 GdkRectangle *cell_area,
387 GtkIconView *icon_view);
388 static void gtk_icon_view_remove_editable (GtkCellArea *area,
389 GtkCellRenderer *renderer,
390 GtkCellEditable *editable,
391 GtkIconView *icon_view);
392 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
394 GtkIconView *icon_view);
395 static void update_text_cell (GtkIconView *icon_view);
396 static void update_pixbuf_cell (GtkIconView *icon_view);
398 /* Source side drag signals */
399 static void gtk_icon_view_drag_begin (GtkWidget *widget,
400 GdkDragContext *context);
401 static void gtk_icon_view_drag_end (GtkWidget *widget,
402 GdkDragContext *context);
403 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
404 GdkDragContext *context,
405 GtkSelectionData *selection_data,
408 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
409 GdkDragContext *context);
411 /* Target side drag signals */
412 static void gtk_icon_view_drag_leave (GtkWidget *widget,
413 GdkDragContext *context,
415 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
416 GdkDragContext *context,
420 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
421 GdkDragContext *context,
425 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
426 GdkDragContext *context,
429 GtkSelectionData *selection_data,
432 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
433 GdkEventMotion *event);
435 static void remove_scroll_timeout (GtkIconView *icon_view);
438 static GtkBuildableIface *parent_buildable_iface;
439 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
440 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
443 const gchar *tagname,
444 GMarkupParser *parser,
446 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
449 const gchar *tagname,
451 static GType _gtk_icon_view_accessible_get_type (void);
453 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
455 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
457 gtk_icon_view_cell_layout_init)
458 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
459 gtk_icon_view_buildable_init)
460 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
463 gtk_icon_view_class_init (GtkIconViewClass *klass)
465 GObjectClass *gobject_class;
466 GtkWidgetClass *widget_class;
467 GtkContainerClass *container_class;
468 GtkBindingSet *binding_set;
470 binding_set = gtk_binding_set_by_class (klass);
472 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
474 gobject_class = (GObjectClass *) klass;
475 widget_class = (GtkWidgetClass *) klass;
476 container_class = (GtkContainerClass *) klass;
478 gobject_class->constructor = gtk_icon_view_constructor;
479 gobject_class->dispose = gtk_icon_view_dispose;
480 gobject_class->set_property = gtk_icon_view_set_property;
481 gobject_class->get_property = gtk_icon_view_get_property;
483 widget_class->destroy = gtk_icon_view_destroy;
484 widget_class->realize = gtk_icon_view_realize;
485 widget_class->unrealize = gtk_icon_view_unrealize;
486 widget_class->style_updated = gtk_icon_view_style_updated;
487 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
488 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
489 widget_class->size_allocate = gtk_icon_view_size_allocate;
490 widget_class->draw = gtk_icon_view_draw;
491 widget_class->motion_notify_event = gtk_icon_view_motion;
492 widget_class->button_press_event = gtk_icon_view_button_press;
493 widget_class->button_release_event = gtk_icon_view_button_release;
494 widget_class->key_press_event = gtk_icon_view_key_press;
495 widget_class->key_release_event = gtk_icon_view_key_release;
496 widget_class->drag_begin = gtk_icon_view_drag_begin;
497 widget_class->drag_end = gtk_icon_view_drag_end;
498 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
499 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
500 widget_class->drag_leave = gtk_icon_view_drag_leave;
501 widget_class->drag_motion = gtk_icon_view_drag_motion;
502 widget_class->drag_drop = gtk_icon_view_drag_drop;
503 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
504 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
506 container_class->remove = gtk_icon_view_remove;
507 container_class->forall = gtk_icon_view_forall;
509 klass->select_all = gtk_icon_view_real_select_all;
510 klass->unselect_all = gtk_icon_view_real_unselect_all;
511 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
512 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
513 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
514 klass->move_cursor = gtk_icon_view_real_move_cursor;
518 * GtkIconView:selection-mode:
520 * The ::selection-mode property specifies the selection mode of
521 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
522 * is enabled, for the other modes, only keyboard selection is possible.
526 g_object_class_install_property (gobject_class,
528 g_param_spec_enum ("selection-mode",
529 P_("Selection mode"),
530 P_("The selection mode"),
531 GTK_TYPE_SELECTION_MODE,
532 GTK_SELECTION_SINGLE,
533 GTK_PARAM_READWRITE));
536 * GtkIconView:pixbuf-column:
538 * The ::pixbuf-column property contains the number of the model column
539 * containing the pixbufs which are displayed. The pixbuf column must be
540 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
541 * display of pixbufs.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_int ("pixbuf-column",
549 P_("Model column used to retrieve the icon pixbuf from"),
551 GTK_PARAM_READWRITE));
554 * GtkIconView:text-column:
556 * The ::text-column property contains the number of the model column
557 * containing the texts which are displayed. The text column must be
558 * of type #G_TYPE_STRING. If this property and the :markup-column
559 * property are both set to -1, no texts are displayed.
563 g_object_class_install_property (gobject_class,
565 g_param_spec_int ("text-column",
567 P_("Model column used to retrieve the text from"),
569 GTK_PARAM_READWRITE));
573 * GtkIconView:markup-column:
575 * The ::markup-column property contains the number of the model column
576 * containing markup information to be displayed. The markup column must be
577 * of type #G_TYPE_STRING. If this property and the :text-column property
578 * are both set to column numbers, it overrides the text column.
579 * If both are set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("markup-column",
587 P_("Model column used to retrieve the text if using Pango markup"),
589 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_object ("model",
594 P_("Icon View Model"),
595 P_("The model for the icon view"),
597 GTK_PARAM_READWRITE));
600 * GtkIconView:columns:
602 * The columns property contains the number of the columns in which the
603 * items should be displayed. If it is -1, the number of columns will
604 * be chosen automatically to fill the available area.
608 g_object_class_install_property (gobject_class,
610 g_param_spec_int ("columns",
611 P_("Number of columns"),
612 P_("Number of columns to display"),
614 GTK_PARAM_READWRITE));
618 * GtkIconView:item-width:
620 * The item-width property specifies the width to use for each item.
621 * If it is set to -1, the icon view will automatically determine a
622 * suitable item size.
626 g_object_class_install_property (gobject_class,
628 g_param_spec_int ("item-width",
629 P_("Width for each item"),
630 P_("The width used for each item"),
632 GTK_PARAM_READWRITE));
635 * GtkIconView:spacing:
637 * The spacing property specifies the space which is inserted between
638 * the cells (i.e. the icon and the text) of an item.
642 g_object_class_install_property (gobject_class,
644 g_param_spec_int ("spacing",
646 P_("Space which is inserted between cells of an item"),
648 GTK_PARAM_READWRITE));
651 * GtkIconView:row-spacing:
653 * The row-spacing property specifies the space which is inserted between
654 * the rows of the icon view.
658 g_object_class_install_property (gobject_class,
660 g_param_spec_int ("row-spacing",
662 P_("Space which is inserted between grid rows"),
664 GTK_PARAM_READWRITE));
667 * GtkIconView:column-spacing:
669 * The column-spacing property specifies the space which is inserted between
670 * the columns of the icon view.
674 g_object_class_install_property (gobject_class,
676 g_param_spec_int ("column-spacing",
677 P_("Column Spacing"),
678 P_("Space which is inserted between grid columns"),
680 GTK_PARAM_READWRITE));
683 * GtkIconView:margin:
685 * The margin property specifies the space which is inserted
686 * at the edges of the icon view.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_int ("margin",
694 P_("Space which is inserted at the edges of the icon view"),
696 GTK_PARAM_READWRITE));
699 * GtkIconView:item-orientation:
701 * The item-orientation property specifies how the cells (i.e. the icon and
702 * the text) of the item are positioned relative to each other.
706 g_object_class_install_property (gobject_class,
707 PROP_ITEM_ORIENTATION,
708 g_param_spec_enum ("item-orientation",
709 P_("Item Orientation"),
710 P_("How the text and icon of each item are positioned relative to each other"),
711 GTK_TYPE_ORIENTATION,
712 GTK_ORIENTATION_VERTICAL,
713 GTK_PARAM_READWRITE));
716 * GtkIconView:reorderable:
718 * The reorderable property specifies if the items can be reordered
723 g_object_class_install_property (gobject_class,
725 g_param_spec_boolean ("reorderable",
727 P_("View is reorderable"),
731 g_object_class_install_property (gobject_class,
733 g_param_spec_int ("tooltip-column",
734 P_("Tooltip Column"),
735 P_("The column in the model containing the tooltip texts for the items"),
739 GTK_PARAM_READWRITE));
742 * GtkIconView:item-padding:
744 * The item-padding property specifies the padding around each
745 * of the icon view's item.
749 g_object_class_install_property (gobject_class,
751 g_param_spec_int ("item-padding",
753 P_("Padding around icon view items"),
755 GTK_PARAM_READWRITE));
758 * GtkIconView:cell-area:
760 * The #GtkCellArea used to layout cell renderers for this view.
762 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
763 * a #GtkCellAreaBox will be used.
767 g_object_class_install_property (gobject_class,
769 g_param_spec_object ("cell-area",
771 P_("The GtkCellArea used to layout cells"),
773 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
775 /* Scrollable interface properties */
776 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
777 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
778 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
779 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
781 /* Style properties */
782 gtk_widget_class_install_style_property (widget_class,
783 g_param_spec_boxed ("selection-box-color",
784 P_("Selection Box Color"),
785 P_("Color of the selection box"),
787 GTK_PARAM_READABLE));
789 gtk_widget_class_install_style_property (widget_class,
790 g_param_spec_uchar ("selection-box-alpha",
791 P_("Selection Box Alpha"),
792 P_("Opacity of the selection box"),
795 GTK_PARAM_READABLE));
799 * GtkIconView::item-activated:
800 * @iconview: the object on which the signal is emitted
801 * @path: the #GtkTreePath for the activated item
803 * The ::item-activated signal is emitted when the method
804 * gtk_icon_view_item_activated() is called or the user double
805 * clicks an item. It is also emitted when a non-editable item
806 * is selected and one of the keys: Space, Return or Enter is
809 icon_view_signals[ITEM_ACTIVATED] =
810 g_signal_new (I_("item-activated"),
811 G_TYPE_FROM_CLASS (gobject_class),
813 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
815 g_cclosure_marshal_VOID__BOXED,
820 * GtkIconView::selection-changed:
821 * @iconview: the object on which the signal is emitted
823 * The ::selection-changed signal is emitted when the selection
824 * (i.e. the set of selected items) changes.
826 icon_view_signals[SELECTION_CHANGED] =
827 g_signal_new (I_("selection-changed"),
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
832 g_cclosure_marshal_VOID__VOID,
836 * GtkIconView::select-all:
837 * @iconview: the object on which the signal is emitted
839 * A <link linkend="keybinding-signals">keybinding signal</link>
840 * which gets emitted when the user selects all items.
842 * Applications should not connect to it, but may emit it with
843 * g_signal_emit_by_name() if they need to control selection
846 * The default binding for this signal is Ctrl-a.
848 icon_view_signals[SELECT_ALL] =
849 g_signal_new (I_("select-all"),
850 G_TYPE_FROM_CLASS (gobject_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
854 g_cclosure_marshal_VOID__VOID,
858 * GtkIconView::unselect-all:
859 * @iconview: the object on which the signal is emitted
861 * A <link linkend="keybinding-signals">keybinding signal</link>
862 * which gets emitted when the user unselects all items.
864 * Applications should not connect to it, but may emit it with
865 * g_signal_emit_by_name() if they need to control selection
868 * The default binding for this signal is Ctrl-Shift-a.
870 icon_view_signals[UNSELECT_ALL] =
871 g_signal_new (I_("unselect-all"),
872 G_TYPE_FROM_CLASS (gobject_class),
873 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
874 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
876 g_cclosure_marshal_VOID__VOID,
880 * GtkIconView::select-cursor-item:
881 * @iconview: the object on which the signal is emitted
883 * A <link linkend="keybinding-signals">keybinding signal</link>
884 * which gets emitted when the user selects the item that is currently
887 * Applications should not connect to it, but may emit it with
888 * g_signal_emit_by_name() if they need to control selection
891 * There is no default binding for this signal.
893 icon_view_signals[SELECT_CURSOR_ITEM] =
894 g_signal_new (I_("select-cursor-item"),
895 G_TYPE_FROM_CLASS (gobject_class),
896 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
897 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
899 g_cclosure_marshal_VOID__VOID,
903 * GtkIconView::toggle-cursor-item:
904 * @iconview: the object on which the signal is emitted
906 * A <link linkend="keybinding-signals">keybinding signal</link>
907 * which gets emitted when the user toggles whether the currently
908 * focused item is selected or not. The exact effect of this
909 * depend on the selection mode.
911 * Applications should not connect to it, but may emit it with
912 * g_signal_emit_by_name() if they need to control selection
915 * There is no default binding for this signal is Ctrl-Space.
917 icon_view_signals[TOGGLE_CURSOR_ITEM] =
918 g_signal_new (I_("toggle-cursor-item"),
919 G_TYPE_FROM_CLASS (gobject_class),
920 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
921 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
923 g_cclosure_marshal_VOID__VOID,
927 * GtkIconView::activate-cursor-item:
928 * @iconview: the object on which the signal is emitted
930 * A <link linkend="keybinding-signals">keybinding signal</link>
931 * which gets emitted when the user activates the currently
934 * Applications should not connect to it, but may emit it with
935 * g_signal_emit_by_name() if they need to control activation
938 * The default bindings for this signal are Space, Return and Enter.
940 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
941 g_signal_new (I_("activate-cursor-item"),
942 G_TYPE_FROM_CLASS (gobject_class),
943 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
944 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
946 _gtk_marshal_BOOLEAN__VOID,
950 * GtkIconView::move-cursor:
951 * @iconview: the object which received the signal
952 * @step: the granularity of the move, as a #GtkMovementStep
953 * @count: the number of @step units to move
955 * The ::move-cursor signal is a
956 * <link linkend="keybinding-signals">keybinding signal</link>
957 * which gets emitted when the user initiates a cursor movement.
959 * Applications should not connect to it, but may emit it with
960 * g_signal_emit_by_name() if they need to control the cursor
963 * The default bindings for this signal include
965 * <listitem>Arrow keys which move by individual steps</listitem>
966 * <listitem>Home/End keys which move to the first/last item</listitem>
967 * <listitem>PageUp/PageDown which move by "pages"</listitem>
970 * All of these will extend the selection when combined with
971 * the Shift modifier.
973 icon_view_signals[MOVE_CURSOR] =
974 g_signal_new (I_("move-cursor"),
975 G_TYPE_FROM_CLASS (gobject_class),
976 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
977 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
979 _gtk_marshal_BOOLEAN__ENUM_INT,
981 GTK_TYPE_MOVEMENT_STEP,
985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
990 "toggle-cursor-item", 0);
991 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
992 "toggle-cursor-item", 0);
994 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
995 "activate-cursor-item", 0);
996 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
997 "activate-cursor-item", 0);
998 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
999 "activate-cursor-item", 0);
1000 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1001 "activate-cursor-item", 0);
1002 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1003 "activate-cursor-item", 0);
1005 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1006 GTK_MOVEMENT_DISPLAY_LINES, -1);
1007 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1008 GTK_MOVEMENT_DISPLAY_LINES, -1);
1010 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1011 GTK_MOVEMENT_DISPLAY_LINES, 1);
1012 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1013 GTK_MOVEMENT_DISPLAY_LINES, 1);
1015 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1016 GTK_MOVEMENT_DISPLAY_LINES, -1);
1018 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1019 GTK_MOVEMENT_DISPLAY_LINES, 1);
1021 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1022 GTK_MOVEMENT_BUFFER_ENDS, -1);
1023 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1024 GTK_MOVEMENT_BUFFER_ENDS, -1);
1026 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1027 GTK_MOVEMENT_BUFFER_ENDS, 1);
1028 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1029 GTK_MOVEMENT_BUFFER_ENDS, 1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1032 GTK_MOVEMENT_PAGES, -1);
1033 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1034 GTK_MOVEMENT_PAGES, -1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1037 GTK_MOVEMENT_PAGES, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1039 GTK_MOVEMENT_PAGES, 1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1042 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1044 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1046 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1047 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1049 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1051 gtk_widget_class_set_accessible_type (widget_class, _gtk_icon_view_accessible_get_type ());
1055 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1057 parent_buildable_iface = g_type_interface_peek_parent (iface);
1058 iface->add_child = _gtk_cell_layout_buildable_add_child;
1059 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1060 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1064 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1066 iface->get_area = gtk_icon_view_cell_layout_get_area;
1070 gtk_icon_view_init (GtkIconView *icon_view)
1072 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1074 GtkIconViewPrivate);
1076 icon_view->priv->width = 0;
1077 icon_view->priv->height = 0;
1078 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1079 icon_view->priv->pressed_button = -1;
1080 icon_view->priv->press_start_x = -1;
1081 icon_view->priv->press_start_y = -1;
1082 icon_view->priv->text_column = -1;
1083 icon_view->priv->markup_column = -1;
1084 icon_view->priv->pixbuf_column = -1;
1085 icon_view->priv->text_cell = NULL;
1086 icon_view->priv->pixbuf_cell = NULL;
1087 icon_view->priv->tooltip_column = -1;
1089 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1091 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1093 icon_view->priv->columns = -1;
1094 icon_view->priv->item_width = -1;
1095 icon_view->priv->spacing = 0;
1096 icon_view->priv->row_spacing = 6;
1097 icon_view->priv->column_spacing = 6;
1098 icon_view->priv->margin = 6;
1099 icon_view->priv->item_padding = 6;
1101 icon_view->priv->draw_focus = TRUE;
1103 icon_view->priv->row_contexts =
1104 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1107 /* GObject methods */
1109 gtk_icon_view_constructor (GType type,
1110 guint n_construct_properties,
1111 GObjectConstructParam *construct_properties)
1113 GtkIconView *icon_view;
1116 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1117 (type, n_construct_properties, construct_properties);
1119 icon_view = (GtkIconView *) object;
1121 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1127 gtk_icon_view_dispose (GObject *object)
1129 GtkIconView *icon_view;
1130 GtkIconViewPrivate *priv;
1132 icon_view = GTK_ICON_VIEW (object);
1133 priv = icon_view->priv;
1135 if (priv->cell_area_context)
1137 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1138 priv->context_changed_id = 0;
1140 g_object_unref (priv->cell_area_context);
1141 priv->cell_area_context = NULL;
1144 if (priv->row_contexts)
1146 g_ptr_array_free (priv->row_contexts, TRUE);
1147 priv->row_contexts = NULL;
1150 if (priv->cell_area)
1152 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1154 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1155 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1156 priv->add_editable_id = 0;
1157 priv->remove_editable_id = 0;
1159 g_object_unref (priv->cell_area);
1160 priv->cell_area = NULL;
1163 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1167 gtk_icon_view_set_property (GObject *object,
1169 const GValue *value,
1172 GtkIconView *icon_view;
1175 icon_view = GTK_ICON_VIEW (object);
1179 case PROP_SELECTION_MODE:
1180 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1182 case PROP_PIXBUF_COLUMN:
1183 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1185 case PROP_TEXT_COLUMN:
1186 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1188 case PROP_MARKUP_COLUMN:
1189 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1192 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1194 case PROP_ITEM_ORIENTATION:
1195 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1198 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1200 case PROP_ITEM_WIDTH:
1201 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1204 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1206 case PROP_ROW_SPACING:
1207 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1209 case PROP_COLUMN_SPACING:
1210 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1213 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1215 case PROP_REORDERABLE:
1216 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1219 case PROP_TOOLTIP_COLUMN:
1220 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1223 case PROP_ITEM_PADDING:
1224 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1227 case PROP_CELL_AREA:
1228 /* Construct-only, can only be assigned once */
1229 area = g_value_get_object (value);
1232 if (icon_view->priv->cell_area != NULL)
1234 g_warning ("cell-area has already been set, ignoring construct property");
1235 g_object_ref_sink (area);
1236 g_object_unref (area);
1239 gtk_icon_view_ensure_cell_area (icon_view, area);
1243 case PROP_HADJUSTMENT:
1244 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1246 case PROP_VADJUSTMENT:
1247 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1249 case PROP_HSCROLL_POLICY:
1250 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1251 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1253 case PROP_VSCROLL_POLICY:
1254 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1255 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1265 gtk_icon_view_get_property (GObject *object,
1270 GtkIconView *icon_view;
1272 icon_view = GTK_ICON_VIEW (object);
1276 case PROP_SELECTION_MODE:
1277 g_value_set_enum (value, icon_view->priv->selection_mode);
1279 case PROP_PIXBUF_COLUMN:
1280 g_value_set_int (value, icon_view->priv->pixbuf_column);
1282 case PROP_TEXT_COLUMN:
1283 g_value_set_int (value, icon_view->priv->text_column);
1285 case PROP_MARKUP_COLUMN:
1286 g_value_set_int (value, icon_view->priv->markup_column);
1289 g_value_set_object (value, icon_view->priv->model);
1291 case PROP_ITEM_ORIENTATION:
1292 g_value_set_enum (value, icon_view->priv->item_orientation);
1295 g_value_set_int (value, icon_view->priv->columns);
1297 case PROP_ITEM_WIDTH:
1298 g_value_set_int (value, icon_view->priv->item_width);
1301 g_value_set_int (value, icon_view->priv->spacing);
1303 case PROP_ROW_SPACING:
1304 g_value_set_int (value, icon_view->priv->row_spacing);
1306 case PROP_COLUMN_SPACING:
1307 g_value_set_int (value, icon_view->priv->column_spacing);
1310 g_value_set_int (value, icon_view->priv->margin);
1312 case PROP_REORDERABLE:
1313 g_value_set_boolean (value, icon_view->priv->reorderable);
1315 case PROP_TOOLTIP_COLUMN:
1316 g_value_set_int (value, icon_view->priv->tooltip_column);
1319 case PROP_ITEM_PADDING:
1320 g_value_set_int (value, icon_view->priv->item_padding);
1323 case PROP_CELL_AREA:
1324 g_value_set_object (value, icon_view->priv->cell_area);
1327 case PROP_HADJUSTMENT:
1328 g_value_set_object (value, icon_view->priv->hadjustment);
1330 case PROP_VADJUSTMENT:
1331 g_value_set_object (value, icon_view->priv->vadjustment);
1333 case PROP_HSCROLL_POLICY:
1334 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1336 case PROP_VSCROLL_POLICY:
1337 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1346 /* GtkWidget methods */
1348 gtk_icon_view_destroy (GtkWidget *widget)
1350 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1352 gtk_icon_view_set_model (icon_view, NULL);
1354 if (icon_view->priv->layout_idle_id != 0)
1356 g_source_remove (icon_view->priv->layout_idle_id);
1357 icon_view->priv->layout_idle_id = 0;
1360 if (icon_view->priv->scroll_to_path != NULL)
1362 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1363 icon_view->priv->scroll_to_path = NULL;
1366 remove_scroll_timeout (icon_view);
1368 if (icon_view->priv->hadjustment != NULL)
1370 g_object_unref (icon_view->priv->hadjustment);
1371 icon_view->priv->hadjustment = NULL;
1374 if (icon_view->priv->vadjustment != NULL)
1376 g_object_unref (icon_view->priv->vadjustment);
1377 icon_view->priv->vadjustment = NULL;
1380 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1384 gtk_icon_view_realize (GtkWidget *widget)
1386 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1387 GtkAllocation allocation;
1389 GdkWindowAttr attributes;
1390 gint attributes_mask;
1391 GtkStyleContext *context;
1393 gtk_widget_set_realized (widget, TRUE);
1395 gtk_widget_get_allocation (widget, &allocation);
1397 /* Make the main, clipping window */
1398 attributes.window_type = GDK_WINDOW_CHILD;
1399 attributes.x = allocation.x;
1400 attributes.y = allocation.y;
1401 attributes.width = allocation.width;
1402 attributes.height = allocation.height;
1403 attributes.wclass = GDK_INPUT_OUTPUT;
1404 attributes.visual = gtk_widget_get_visual (widget);
1405 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1407 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1409 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1410 &attributes, attributes_mask);
1411 gtk_widget_set_window (widget, window);
1412 gdk_window_set_user_data (window, widget);
1414 gtk_widget_get_allocation (widget, &allocation);
1416 /* Make the window for the icon view */
1419 attributes.width = MAX (icon_view->priv->width, allocation.width);
1420 attributes.height = MAX (icon_view->priv->height, allocation.height);
1421 attributes.event_mask = (GDK_EXPOSURE_MASK |
1423 GDK_POINTER_MOTION_MASK |
1424 GDK_BUTTON_PRESS_MASK |
1425 GDK_BUTTON_RELEASE_MASK |
1426 GDK_KEY_PRESS_MASK |
1427 GDK_KEY_RELEASE_MASK) |
1428 gtk_widget_get_events (widget);
1430 icon_view->priv->bin_window = gdk_window_new (window,
1431 &attributes, attributes_mask);
1432 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1434 context = gtk_widget_get_style_context (widget);
1436 gtk_style_context_save (context);
1437 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1438 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1439 gtk_style_context_restore (context);
1441 gdk_window_show (icon_view->priv->bin_window);
1445 gtk_icon_view_unrealize (GtkWidget *widget)
1447 GtkIconView *icon_view;
1449 icon_view = GTK_ICON_VIEW (widget);
1451 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1452 gdk_window_destroy (icon_view->priv->bin_window);
1453 icon_view->priv->bin_window = NULL;
1455 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1459 _gtk_icon_view_update_background (GtkIconView *icon_view)
1461 GtkWidget *widget = GTK_WIDGET (icon_view);
1463 if (gtk_widget_get_realized (widget))
1465 GtkStyleContext *context;
1467 context = gtk_widget_get_style_context (widget);
1469 gtk_style_context_save (context);
1470 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1472 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1473 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1475 gtk_style_context_restore (context);
1480 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1481 GtkStateFlags previous_state)
1483 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1484 gtk_widget_queue_draw (widget);
1488 gtk_icon_view_style_updated (GtkWidget *widget)
1490 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1492 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1493 gtk_widget_queue_resize (widget);
1497 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1501 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1505 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1509 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1513 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1517 for (list = icon_view->priv->children; list; list = list->next)
1519 GtkIconViewChild *child = list->data;
1521 /* totally ignore our child's requisition */
1522 gtk_widget_size_allocate (child->widget, &child->area);
1527 gtk_icon_view_size_allocate (GtkWidget *widget,
1528 GtkAllocation *allocation)
1530 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1532 gtk_widget_set_allocation (widget, allocation);
1534 if (gtk_widget_get_realized (widget))
1536 gdk_window_move_resize (gtk_widget_get_window (widget),
1537 allocation->x, allocation->y,
1538 allocation->width, allocation->height);
1539 gdk_window_resize (icon_view->priv->bin_window,
1540 MAX (icon_view->priv->width, allocation->width),
1541 MAX (icon_view->priv->height, allocation->height));
1544 gtk_icon_view_layout (icon_view);
1546 gtk_icon_view_allocate_children (icon_view);
1548 /* Delay signal emission */
1549 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1550 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1552 gtk_icon_view_set_hadjustment_values (icon_view);
1553 gtk_icon_view_set_vadjustment_values (icon_view);
1555 if (gtk_widget_get_realized (widget) &&
1556 icon_view->priv->scroll_to_path)
1559 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1560 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1561 icon_view->priv->scroll_to_path = NULL;
1563 gtk_icon_view_scroll_to_path (icon_view, path,
1564 icon_view->priv->scroll_to_use_align,
1565 icon_view->priv->scroll_to_row_align,
1566 icon_view->priv->scroll_to_col_align);
1567 gtk_tree_path_free (path);
1570 /* Emit any pending signals now */
1571 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1572 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1576 gtk_icon_view_draw (GtkWidget *widget,
1579 GtkIconView *icon_view;
1583 GtkIconViewDropPosition dest_pos;
1584 GtkIconViewItem *dest_item = NULL;
1586 icon_view = GTK_ICON_VIEW (widget);
1588 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1593 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1595 cairo_set_line_width (cr, 1.);
1597 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1601 dest_index = gtk_tree_path_get_indices (path)[0];
1602 gtk_tree_path_free (path);
1607 for (icons = icon_view->priv->items; icons; icons = icons->next)
1609 GtkIconViewItem *item = icons->data;
1610 GdkRectangle paint_area;
1612 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1613 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1614 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1615 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1619 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1622 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1624 gtk_icon_view_paint_item (icon_view, cr, item,
1625 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1626 icon_view->priv->draw_focus);
1628 if (dest_index == item->index)
1636 dest_pos != GTK_ICON_VIEW_NO_DROP)
1638 GtkStyleContext *context;
1639 GtkStateFlags state;
1640 GdkRectangle rect = { 0 };
1642 context = gtk_widget_get_style_context (widget);
1643 state = gtk_widget_get_state_flags (widget);
1647 case GTK_ICON_VIEW_DROP_INTO:
1648 rect = dest_item->cell_area;
1650 case GTK_ICON_VIEW_DROP_ABOVE:
1651 rect.x = dest_item->cell_area.x;
1652 rect.y = dest_item->cell_area.y - 1;
1653 rect.width = dest_item->cell_area.width;
1656 case GTK_ICON_VIEW_DROP_LEFT:
1657 rect.x = dest_item->cell_area.x - 1;
1658 rect.y = dest_item->cell_area.y;
1660 rect.height = dest_item->cell_area.height;
1662 case GTK_ICON_VIEW_DROP_BELOW:
1663 rect.x = dest_item->cell_area.x;
1664 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1665 rect.width = dest_item->cell_area.width;
1668 case GTK_ICON_VIEW_DROP_RIGHT:
1669 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1670 rect.y = dest_item->cell_area.y;
1672 rect.height = dest_item->cell_area.height;
1673 case GTK_ICON_VIEW_NO_DROP: ;
1677 gtk_style_context_set_state (context, state);
1678 gtk_render_focus (context, cr,
1680 rect.width, rect.height);
1683 if (icon_view->priv->doing_rubberband)
1684 gtk_icon_view_paint_rubberband (icon_view, cr);
1688 return 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);
1747 GtkIconViewItem *item, *last_prelight_item;
1748 GtkCellRenderer *cell = NULL;
1750 last_prelight_item = icon_view->priv->last_prelight;
1751 item = gtk_icon_view_get_item_at_coords (icon_view,
1758 item->prelight = TRUE;
1759 gtk_icon_view_queue_draw_item (icon_view, item);
1762 if (last_prelight_item != NULL &&
1763 last_prelight_item != item)
1765 last_prelight_item->prelight = FALSE;
1766 gtk_icon_view_queue_draw_item (icon_view,
1767 icon_view->priv->last_prelight);
1770 icon_view->priv->last_prelight = item;
1777 gtk_icon_view_remove (GtkContainer *container,
1780 GtkIconView *icon_view;
1781 GtkIconViewChild *child = NULL;
1784 icon_view = GTK_ICON_VIEW (container);
1786 tmp_list = icon_view->priv->children;
1789 child = tmp_list->data;
1790 if (child->widget == widget)
1792 gtk_widget_unparent (widget);
1794 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1795 g_list_free_1 (tmp_list);
1800 tmp_list = tmp_list->next;
1805 gtk_icon_view_forall (GtkContainer *container,
1806 gboolean include_internals,
1807 GtkCallback callback,
1808 gpointer callback_data)
1810 GtkIconView *icon_view;
1811 GtkIconViewChild *child = NULL;
1814 icon_view = GTK_ICON_VIEW (container);
1816 tmp_list = icon_view->priv->children;
1819 child = tmp_list->data;
1820 tmp_list = tmp_list->next;
1822 (* callback) (child->widget, callback_data);
1827 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1828 GtkIconViewItem *item)
1831 AtkObject *item_obj;
1833 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1836 item_obj = atk_object_ref_accessible_child (obj, item->index);
1837 if (item_obj != NULL)
1839 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1840 g_object_unref (item_obj);
1846 gtk_icon_view_add_editable (GtkCellArea *area,
1847 GtkCellRenderer *renderer,
1848 GtkCellEditable *editable,
1849 GdkRectangle *cell_area,
1851 GtkIconView *icon_view)
1853 GtkIconViewChild *child;
1854 GtkWidget *widget = GTK_WIDGET (editable);
1856 child = g_new (GtkIconViewChild, 1);
1858 child->widget = widget;
1859 child->area.x = cell_area->x;
1860 child->area.y = cell_area->y;
1861 child->area.width = cell_area->width;
1862 child->area.height = cell_area->height;
1864 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1866 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1867 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1869 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1873 gtk_icon_view_remove_editable (GtkCellArea *area,
1874 GtkCellRenderer *renderer,
1875 GtkCellEditable *editable,
1876 GtkIconView *icon_view)
1880 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1881 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1883 gtk_container_remove (GTK_CONTAINER (icon_view),
1884 GTK_WIDGET (editable));
1886 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1887 gtk_icon_view_queue_draw_path (icon_view, path);
1888 gtk_tree_path_free (path);
1892 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1894 GtkIconView *icon_view)
1896 if (!strcmp (pspec->name, "minimum-width") ||
1897 !strcmp (pspec->name, "natural-width") ||
1898 !strcmp (pspec->name, "minimum-height") ||
1899 !strcmp (pspec->name, "natural-height"))
1900 gtk_icon_view_invalidate_sizes (icon_view);
1904 * gtk_icon_view_set_cursor:
1905 * @icon_view: A #GtkIconView
1906 * @path: A #GtkTreePath
1907 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1908 * @start_editing: %TRUE if the specified cell should start being edited.
1910 * Sets the current keyboard focus to be at @path, and selects it. This is
1911 * useful when you want to focus the user's attention on a particular item.
1912 * If @cell is not %NULL, then focus is given to the cell specified by
1913 * it. Additionally, if @start_editing is %TRUE, then editing should be
1914 * started in the specified cell.
1916 * This function is often followed by <literal>gtk_widget_grab_focus
1917 * (icon_view)</literal> in order to give keyboard focus to the widget.
1918 * Please note that editing can only happen when the widget is realized.
1923 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1925 GtkCellRenderer *cell,
1926 gboolean start_editing)
1928 GtkIconViewItem *item = NULL;
1930 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1931 g_return_if_fail (path != NULL);
1932 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1934 if (icon_view->priv->cell_area)
1935 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1937 if (gtk_tree_path_get_depth (path) == 1)
1938 item = g_list_nth_data (icon_view->priv->items,
1939 gtk_tree_path_get_indices(path)[0]);
1944 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1945 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1947 if (start_editing &&
1948 icon_view->priv->cell_area)
1950 GtkCellAreaContext *context;
1952 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1953 gtk_icon_view_set_cell_data (icon_view, item);
1954 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1955 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1956 0 /* XXX flags */, TRUE);
1961 * gtk_icon_view_get_cursor:
1962 * @icon_view: A #GtkIconView
1963 * @path: (out) (allow-none): Return location for the current cursor path,
1965 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1967 * Fills in @path and @cell with the current cursor path and cell.
1968 * If the cursor isn't currently set, then *@path will be %NULL.
1969 * If no cell currently has focus, then *@cell will be %NULL.
1971 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1973 * Return value: %TRUE if the cursor is set.
1978 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1980 GtkCellRenderer **cell)
1982 GtkIconViewItem *item;
1984 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1986 item = icon_view->priv->cursor_item;
1991 *path = gtk_tree_path_new_from_indices (item->index, -1);
1996 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1997 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1999 return (item != NULL);
2003 gtk_icon_view_button_press (GtkWidget *widget,
2004 GdkEventButton *event)
2006 GtkIconView *icon_view;
2007 GtkIconViewItem *item;
2008 gboolean dirty = FALSE;
2009 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
2011 icon_view = GTK_ICON_VIEW (widget);
2013 if (event->window != icon_view->priv->bin_window)
2016 if (!gtk_widget_has_focus (widget))
2017 gtk_widget_grab_focus (widget);
2019 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2021 GdkModifierType extend_mod_mask;
2022 GdkModifierType modify_mod_mask;
2025 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_EXTEND_SELECTION);
2028 gtk_widget_get_modifier_mask (widget, GDK_MODIFIER_INTENT_MODIFY_SELECTION);
2030 item = gtk_icon_view_get_item_at_coords (icon_view,
2036 * We consider only the the cells' area as the item area if the
2037 * item is not selected, but if it *is* selected, the complete
2038 * selection rectangle is considered to be part of the item.
2040 if (item != NULL && (cell != NULL || item->selected))
2044 if (gtk_cell_renderer_is_activatable (cell))
2048 gtk_icon_view_scroll_to_item (icon_view, item);
2050 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2052 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2054 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2055 (event->state & extend_mod_mask))
2057 gtk_icon_view_unselect_all_internal (icon_view);
2059 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2060 if (!icon_view->priv->anchor_item)
2061 icon_view->priv->anchor_item = item;
2063 gtk_icon_view_select_all_between (icon_view,
2064 icon_view->priv->anchor_item,
2070 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2071 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2072 (event->state & modify_mod_mask))
2074 item->selected = !item->selected;
2075 gtk_icon_view_queue_draw_item (icon_view, item);
2080 gtk_icon_view_unselect_all_internal (icon_view);
2082 item->selected = TRUE;
2083 gtk_icon_view_queue_draw_item (icon_view, item);
2086 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2087 icon_view->priv->anchor_item = item;
2090 /* Save press to possibly begin a drag */
2091 if (icon_view->priv->pressed_button < 0)
2093 icon_view->priv->pressed_button = event->button;
2094 icon_view->priv->press_start_x = event->x;
2095 icon_view->priv->press_start_y = event->y;
2098 if (!icon_view->priv->last_single_clicked)
2099 icon_view->priv->last_single_clicked = item;
2101 /* cancel the current editing, if it exists */
2102 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2104 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2106 GtkCellAreaContext *context;
2108 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2110 gtk_icon_view_set_cell_data (icon_view, item);
2111 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2112 GTK_WIDGET (icon_view),
2113 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2118 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2119 !(event->state & modify_mod_mask))
2121 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2124 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2125 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2128 /* don't draw keyboard focus around an clicked-on item */
2129 icon_view->priv->draw_focus = FALSE;
2132 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2134 item = gtk_icon_view_get_item_at_coords (icon_view,
2139 if (item && item == icon_view->priv->last_single_clicked)
2143 path = gtk_tree_path_new_from_indices (item->index, -1);
2144 gtk_icon_view_item_activated (icon_view, path);
2145 gtk_tree_path_free (path);
2148 icon_view->priv->last_single_clicked = NULL;
2149 icon_view->priv->pressed_button = -1;
2153 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2155 return event->button == 1;
2159 gtk_icon_view_button_release (GtkWidget *widget,
2160 GdkEventButton *event)
2162 GtkIconView *icon_view;
2164 icon_view = GTK_ICON_VIEW (widget);
2166 if (icon_view->priv->pressed_button == event->button)
2167 icon_view->priv->pressed_button = -1;
2169 gtk_icon_view_stop_rubberbanding (icon_view);
2171 remove_scroll_timeout (icon_view);
2177 gtk_icon_view_key_press (GtkWidget *widget,
2180 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2182 if (icon_view->priv->doing_rubberband)
2184 if (event->keyval == GDK_KEY_Escape)
2185 gtk_icon_view_stop_rubberbanding (icon_view);
2190 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2194 gtk_icon_view_key_release (GtkWidget *widget,
2197 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2199 if (icon_view->priv->doing_rubberband)
2202 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2206 gtk_icon_view_update_rubberband (gpointer data)
2208 GtkIconView *icon_view;
2210 GdkRectangle old_area;
2211 GdkRectangle new_area;
2212 GdkRectangle common;
2213 cairo_region_t *invalid_region;
2215 icon_view = GTK_ICON_VIEW (data);
2217 gdk_window_get_device_position (icon_view->priv->bin_window,
2218 icon_view->priv->rubberband_device,
2224 old_area.x = MIN (icon_view->priv->rubberband_x1,
2225 icon_view->priv->rubberband_x2);
2226 old_area.y = MIN (icon_view->priv->rubberband_y1,
2227 icon_view->priv->rubberband_y2);
2228 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2229 icon_view->priv->rubberband_x1) + 1;
2230 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2231 icon_view->priv->rubberband_y1) + 1;
2233 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2234 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2235 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2236 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2238 invalid_region = cairo_region_create_rectangle (&old_area);
2239 cairo_region_union_rectangle (invalid_region, &new_area);
2241 gdk_rectangle_intersect (&old_area, &new_area, &common);
2242 if (common.width > 2 && common.height > 2)
2244 cairo_region_t *common_region;
2246 /* make sure the border is invalidated */
2252 common_region = cairo_region_create_rectangle (&common);
2254 cairo_region_subtract (invalid_region, common_region);
2255 cairo_region_destroy (common_region);
2258 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2260 cairo_region_destroy (invalid_region);
2262 icon_view->priv->rubberband_x2 = x;
2263 icon_view->priv->rubberband_y2 = y;
2265 gtk_icon_view_update_rubberband_selection (icon_view);
2269 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2276 if (icon_view->priv->rubberband_device)
2279 for (items = icon_view->priv->items; items; items = items->next)
2281 GtkIconViewItem *item = items->data;
2283 item->selected_before_rubberbanding = item->selected;
2286 icon_view->priv->rubberband_x1 = x;
2287 icon_view->priv->rubberband_y1 = y;
2288 icon_view->priv->rubberband_x2 = x;
2289 icon_view->priv->rubberband_y2 = y;
2291 icon_view->priv->doing_rubberband = TRUE;
2292 icon_view->priv->rubberband_device = device;
2294 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2298 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2300 if (!icon_view->priv->doing_rubberband)
2303 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2304 icon_view->priv->rubberband_device);
2306 icon_view->priv->doing_rubberband = FALSE;
2307 icon_view->priv->rubberband_device = NULL;
2309 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2313 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2316 gint x, y, width, height;
2317 gboolean dirty = FALSE;
2319 x = MIN (icon_view->priv->rubberband_x1,
2320 icon_view->priv->rubberband_x2);
2321 y = MIN (icon_view->priv->rubberband_y1,
2322 icon_view->priv->rubberband_y2);
2323 width = ABS (icon_view->priv->rubberband_x1 -
2324 icon_view->priv->rubberband_x2);
2325 height = ABS (icon_view->priv->rubberband_y1 -
2326 icon_view->priv->rubberband_y2);
2328 for (items = icon_view->priv->items; items; items = items->next)
2330 GtkIconViewItem *item = items->data;
2334 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2335 x, y, width, height);
2337 selected = is_in ^ item->selected_before_rubberbanding;
2339 if (item->selected != selected)
2341 item->selected = selected;
2343 gtk_icon_view_queue_draw_item (icon_view, item);
2348 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2353 GdkRectangle hit_rect;
2358 hit_test (GtkCellRenderer *renderer,
2359 const GdkRectangle *cell_area,
2360 const GdkRectangle *cell_background,
2363 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2364 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2365 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2366 MAX (data->hit_rect.y, cell_area->y) > 0)
2369 return (data->hit != FALSE);
2373 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2374 GtkIconViewItem *item,
2380 HitTestData data = { { x, y, width, height }, FALSE };
2381 GtkCellAreaContext *context;
2382 GdkRectangle *item_area = (GdkRectangle *)item;
2384 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2385 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2388 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2390 gtk_icon_view_set_cell_data (icon_view, item);
2391 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2392 GTK_WIDGET (icon_view),
2393 item_area, item_area,
2394 (GtkCellAllocCallback)hit_test, &data);
2400 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2402 gboolean dirty = FALSE;
2405 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2408 for (items = icon_view->priv->items; items; items = items->next)
2410 GtkIconViewItem *item = items->data;
2414 item->selected = FALSE;
2416 gtk_icon_view_queue_draw_item (icon_view, item);
2417 gtk_icon_view_item_selected_changed (icon_view, item);
2425 /* GtkIconView signals */
2427 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2429 gtk_icon_view_select_all (icon_view);
2433 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2435 gtk_icon_view_unselect_all (icon_view);
2439 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2441 gtk_icon_view_unselect_all (icon_view);
2443 if (icon_view->priv->cursor_item != NULL)
2444 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2448 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2451 GtkCellAreaContext *context;
2453 if (!icon_view->priv->cursor_item)
2456 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2458 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2459 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2460 GTK_WIDGET (icon_view),
2461 (GdkRectangle *)icon_view->priv->cursor_item,
2465 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2466 gtk_icon_view_item_activated (icon_view, path);
2467 gtk_tree_path_free (path);
2473 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2475 if (!icon_view->priv->cursor_item)
2478 switch (icon_view->priv->selection_mode)
2480 case GTK_SELECTION_NONE:
2482 case GTK_SELECTION_BROWSE:
2483 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2485 case GTK_SELECTION_SINGLE:
2486 if (icon_view->priv->cursor_item->selected)
2487 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2489 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2491 case GTK_SELECTION_MULTIPLE:
2492 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2493 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2495 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2496 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2501 /* Internal functions */
2503 gtk_icon_view_process_updates (GtkIconView *icon_view)
2505 /* Prior to drawing, we check if a layout has been scheduled. If so,
2506 * do it now that all cell view items have valid sizes before we proceeed
2507 * (and resize the bin_window if required).
2509 if (icon_view->priv->layout_idle_id != 0)
2510 gtk_icon_view_layout (icon_view);
2512 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2516 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2518 GtkAllocation allocation;
2519 GtkAdjustment *adj = icon_view->priv->hadjustment;
2520 gdouble old_page_size;
2526 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2528 old_value = gtk_adjustment_get_value (adj);
2529 old_upper = gtk_adjustment_get_upper (adj);
2530 old_page_size = gtk_adjustment_get_page_size (adj);
2531 new_upper = MAX (allocation.width, icon_view->priv->width);
2533 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2535 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2536 /* Quick explanation:
2537 * In LTR locales, leftmost portion of visible rectangle should stay
2538 * fixed, which means left edge of scrollbar thumb should remain fixed
2539 * and thus adjustment's value should stay the same.
2541 * In RTL locales, we want to keep rightmost portion of visible
2542 * rectangle fixed. This means right edge of thumb should remain fixed.
2543 * In this case, upper - value - page_size should remain constant.
2545 new_value = (new_upper - allocation.width) -
2546 (old_upper - old_value - old_page_size);
2547 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2550 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2552 gtk_adjustment_configure (adj,
2556 allocation.width * 0.1,
2557 allocation.width * 0.9,
2562 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2564 GtkAllocation allocation;
2565 GtkAdjustment *adj = icon_view->priv->vadjustment;
2567 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2569 gtk_adjustment_configure (adj,
2570 gtk_adjustment_get_value (adj),
2572 MAX (allocation.height, icon_view->priv->height),
2573 allocation.height * 0.1,
2574 allocation.height * 0.9,
2579 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2580 GtkAdjustment *adjustment)
2582 GtkIconViewPrivate *priv = icon_view->priv;
2585 if (adjustment && priv->hadjustment == adjustment)
2588 if (priv->hadjustment != NULL)
2590 g_signal_handlers_disconnect_matched (priv->hadjustment,
2591 G_SIGNAL_MATCH_DATA,
2592 0, 0, NULL, NULL, icon_view);
2593 g_object_unref (priv->hadjustment);
2597 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2600 g_signal_connect (adjustment, "value-changed",
2601 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2602 priv->hadjustment = g_object_ref_sink (adjustment);
2603 gtk_icon_view_set_hadjustment_values (icon_view);
2605 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2606 gtk_icon_view_accessible_set_adjustment (atk_obj,
2607 GTK_ORIENTATION_HORIZONTAL,
2610 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2614 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2615 GtkAdjustment *adjustment)
2617 GtkIconViewPrivate *priv = icon_view->priv;
2620 if (adjustment && priv->vadjustment == adjustment)
2623 if (priv->vadjustment != NULL)
2625 g_signal_handlers_disconnect_matched (priv->vadjustment,
2626 G_SIGNAL_MATCH_DATA,
2627 0, 0, NULL, NULL, icon_view);
2628 g_object_unref (priv->vadjustment);
2632 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2635 g_signal_connect (adjustment, "value-changed",
2636 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2637 priv->vadjustment = g_object_ref_sink (adjustment);
2638 gtk_icon_view_set_vadjustment_values (icon_view);
2640 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2641 gtk_icon_view_accessible_set_adjustment (atk_obj,
2642 GTK_ORIENTATION_VERTICAL,
2645 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2649 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2650 GtkIconView *icon_view)
2652 GtkIconViewPrivate *priv = icon_view->priv;
2654 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2656 gdk_window_move (priv->bin_window,
2657 - gtk_adjustment_get_value (priv->hadjustment),
2658 - gtk_adjustment_get_value (priv->vadjustment));
2660 if (icon_view->priv->doing_rubberband)
2661 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2663 gtk_icon_view_process_updates (icon_view);
2668 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2673 gint *maximum_width)
2675 GtkAllocation allocation;
2676 GtkCellAreaContext *context;
2677 GtkIconViewPrivate *priv = icon_view->priv;
2678 GtkWidget *widget = GTK_WIDGET (icon_view);
2679 gint x, current_width;
2680 GList *items, *last_item;
2682 gint max_height = 0;
2685 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2693 current_width += 2 * priv->margin;
2695 gtk_widget_get_allocation (widget, &allocation);
2697 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2698 g_ptr_array_add (priv->row_contexts, context);
2700 /* In the first loop we iterate horizontally until we hit allocation width
2701 * and collect the aligned height-for-width */
2705 GtkIconViewItem *item = items->data;
2706 GdkRectangle *item_area = (GdkRectangle *)item;
2708 item_area->width = item_width;
2710 current_width += item_area->width + icon_view->priv->item_padding * 2;
2712 if (items != first_item)
2714 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2715 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2719 /* Get this item's particular width & height (all alignments are cached by now) */
2720 gtk_icon_view_set_cell_data (icon_view, item);
2721 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2726 current_width += icon_view->priv->column_spacing;
2728 item_area->y = *y + icon_view->priv->item_padding;
2729 item_area->x = x + icon_view->priv->item_padding;
2731 x = current_width - icon_view->priv->margin;
2733 if (current_width > *maximum_width)
2734 *maximum_width = current_width;
2740 items = items->next;
2745 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2746 gtk_cell_area_context_allocate (context, item_width, max_height);
2748 /* In the second loop the item height has been aligned and derived and
2749 * we just set the height and handle rtl layout */
2750 for (items = first_item; items != last_item; items = items->next)
2752 GtkIconViewItem *item = items->data;
2753 GdkRectangle *item_area = (GdkRectangle *)item;
2757 item_area->x = *maximum_width - item_area->width - item_area->x;
2758 item->col = col - 1 - item->col;
2761 /* All items in the same row get the same height */
2762 item_area->height = max_height;
2765 /* Adjust the new y coordinate. */
2766 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2772 adjust_wrap_width (GtkIconView *icon_view)
2774 if (icon_view->priv->text_cell)
2776 gint wrap_width = 50;
2778 /* Here we go with the same old guess, try the icon size and set double
2779 * the size of the first icon found in the list, naive but works much
2781 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2783 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2784 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2785 GTK_WIDGET (icon_view),
2788 wrap_width = MAX (wrap_width * 2, 50);
2791 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2792 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2797 gtk_icon_view_layout (GtkIconView *icon_view)
2799 GtkAllocation allocation;
2802 gint y = 0, maximum_width = 0;
2805 gboolean size_changed = FALSE;
2807 if (icon_view->priv->layout_idle_id != 0)
2809 g_source_remove (icon_view->priv->layout_idle_id);
2810 icon_view->priv->layout_idle_id = 0;
2813 if (icon_view->priv->model == NULL)
2816 widget = GTK_WIDGET (icon_view);
2818 item_width = icon_view->priv->item_width;
2820 /* Update the wrap width for the text cell before going and requesting sizes */
2821 adjust_wrap_width (icon_view);
2823 /* Update the context widths for any invalidated items */
2824 gtk_icon_view_cache_widths (icon_view);
2826 /* Fetch the new item width if needed */
2828 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2831 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2833 icons = icon_view->priv->items;
2834 y += icon_view->priv->margin;
2837 /* Clear the per row contexts */
2838 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2842 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2844 &y, &maximum_width);
2847 while (icons != NULL);
2849 if (maximum_width != icon_view->priv->width)
2851 icon_view->priv->width = maximum_width;
2852 size_changed = TRUE;
2855 y += icon_view->priv->margin;
2857 if (y != icon_view->priv->height)
2859 icon_view->priv->height = y;
2860 size_changed = TRUE;
2863 gtk_icon_view_set_hadjustment_values (icon_view);
2864 gtk_icon_view_set_vadjustment_values (icon_view);
2867 gtk_widget_queue_resize_no_redraw (widget);
2869 gtk_widget_get_allocation (widget, &allocation);
2870 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2871 gdk_window_resize (icon_view->priv->bin_window,
2872 MAX (icon_view->priv->width, allocation.width),
2873 MAX (icon_view->priv->height, allocation.height));
2875 if (icon_view->priv->scroll_to_path)
2879 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2880 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2881 icon_view->priv->scroll_to_path = NULL;
2883 gtk_icon_view_scroll_to_path (icon_view, path,
2884 icon_view->priv->scroll_to_use_align,
2885 icon_view->priv->scroll_to_row_align,
2886 icon_view->priv->scroll_to_col_align);
2887 gtk_tree_path_free (path);
2890 gtk_widget_queue_draw (widget);
2893 /* This ensures that all widths have been cached in the
2894 * context and we have proper alignments to go on.
2897 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2901 g_signal_handler_block (icon_view->priv->cell_area_context,
2902 icon_view->priv->context_changed_id);
2904 for (items = icon_view->priv->items; items; items = items->next)
2906 GtkIconViewItem *item = items->data;
2908 /* Only fetch the width of items with invalidated sizes */
2909 if (item->cell_area.width < 0)
2911 gtk_icon_view_set_cell_data (icon_view, item);
2912 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2913 icon_view->priv->cell_area_context,
2914 GTK_WIDGET (icon_view), NULL, NULL);
2918 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2919 icon_view->priv->context_changed_id);
2923 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2925 /* Clear all item sizes */
2926 g_list_foreach (icon_view->priv->items,
2927 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2929 /* Reset the context */
2930 if (icon_view->priv->cell_area_context)
2932 g_signal_handler_block (icon_view->priv->cell_area_context,
2933 icon_view->priv->context_changed_id);
2934 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2935 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2936 icon_view->priv->context_changed_id);
2939 /* Re-layout the items */
2940 gtk_icon_view_queue_layout (icon_view);
2944 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2946 item->cell_area.width = -1;
2947 item->cell_area.height = -1;
2951 gtk_icon_view_paint_item (GtkIconView *icon_view,
2953 GtkIconViewItem *item,
2956 gboolean draw_focus)
2958 GdkRectangle cell_area;
2959 GtkStateFlags state = 0;
2960 GtkCellRendererState flags = 0;
2961 GtkStyleContext *style_context;
2962 GtkWidget *widget = GTK_WIDGET (icon_view);
2963 GtkIconViewPrivate *priv = icon_view->priv;
2964 GtkCellAreaContext *context;
2966 if (priv->model == NULL)
2969 gtk_icon_view_set_cell_data (icon_view, item);
2971 style_context = gtk_widget_get_style_context (widget);
2973 gtk_style_context_save (style_context);
2974 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2975 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2979 if (gtk_widget_has_focus (widget) &&
2980 item == icon_view->priv->cursor_item)
2982 state |= GTK_STATE_FLAG_FOCUSED;
2983 flags |= GTK_CELL_RENDERER_FOCUSED;
2986 state |= GTK_STATE_FLAG_SELECTED;
2987 flags |= GTK_CELL_RENDERER_SELECTED;
2992 state |= GTK_STATE_FLAG_PRELIGHT;
2993 flags |= GTK_CELL_RENDERER_PRELIT;
2996 gtk_style_context_set_state (style_context, state);
3000 gtk_render_background (style_context, cr,
3001 x - icon_view->priv->item_padding,
3002 y - icon_view->priv->item_padding,
3003 item->cell_area.width + icon_view->priv->item_padding * 2,
3004 item->cell_area.height + icon_view->priv->item_padding * 2);
3005 gtk_render_frame (style_context, cr,
3006 x - icon_view->priv->item_padding,
3007 y - icon_view->priv->item_padding,
3008 item->cell_area.width + icon_view->priv->item_padding * 2,
3009 item->cell_area.height + icon_view->priv->item_padding * 2);
3014 cell_area.width = item->cell_area.width;
3015 cell_area.height = item->cell_area.height;
3017 context = g_ptr_array_index (priv->row_contexts, item->row);
3018 gtk_cell_area_render (priv->cell_area, context,
3019 widget, cr, &cell_area, &cell_area, flags,
3022 gtk_style_context_restore (style_context);
3026 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3029 GtkStyleContext *context;
3034 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3035 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3036 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3037 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3039 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3041 gtk_style_context_save (context);
3042 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3044 gdk_cairo_rectangle (cr, &rect);
3047 gtk_render_background (context, cr,
3049 rect.width, rect.height);
3050 gtk_render_frame (context, cr,
3052 rect.width, rect.height);
3054 gtk_style_context_restore (context);
3059 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3065 index = gtk_tree_path_get_indices (path)[0];
3067 for (l = icon_view->priv->items; l; l = l->next)
3069 GtkIconViewItem *item = l->data;
3071 if (item->index == index)
3073 gtk_icon_view_queue_draw_item (icon_view, item);
3080 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3081 GtkIconViewItem *item)
3084 GdkRectangle *item_area = (GdkRectangle *)item;
3086 rect.x = item_area->x - icon_view->priv->item_padding;
3087 rect.y = item_area->y - icon_view->priv->item_padding;
3088 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3089 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3091 if (icon_view->priv->bin_window)
3092 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3096 layout_callback (gpointer user_data)
3098 GtkIconView *icon_view;
3100 icon_view = GTK_ICON_VIEW (user_data);
3102 icon_view->priv->layout_idle_id = 0;
3104 gtk_icon_view_layout (icon_view);
3110 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3112 if (icon_view->priv->layout_idle_id != 0)
3115 icon_view->priv->layout_idle_id =
3116 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3117 layout_callback, icon_view, NULL);
3121 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3122 GtkIconViewItem *item,
3123 GtkCellRenderer *cursor_cell)
3126 AtkObject *item_obj;
3127 AtkObject *cursor_item_obj;
3129 /* When hitting this path from keynav, the focus cell is
3130 * already set, we dont need to notify the atk object
3131 * but we still need to queue the draw here (in the case
3132 * that the focus cell changes but not the cursor item).
3134 gtk_icon_view_queue_draw_item (icon_view, item);
3136 if (icon_view->priv->cursor_item == item &&
3137 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3140 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3141 if (icon_view->priv->cursor_item != NULL)
3143 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3146 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3147 if (cursor_item_obj != NULL)
3148 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3151 icon_view->priv->cursor_item = item;
3154 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3157 /* Make sure there is a cell in focus initially */
3158 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3159 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3162 /* Notify that accessible focus object has changed */
3163 item_obj = atk_object_ref_accessible_child (obj, item->index);
3165 if (item_obj != NULL)
3167 atk_focus_tracker_notify (item_obj);
3168 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3169 g_object_unref (item_obj);
3174 static GtkIconViewItem *
3175 gtk_icon_view_item_new (void)
3177 GtkIconViewItem *item;
3179 item = g_slice_new0 (GtkIconViewItem);
3181 item->cell_area.width = -1;
3182 item->cell_area.height = -1;
3188 gtk_icon_view_item_free (GtkIconViewItem *item)
3190 g_return_if_fail (item != NULL);
3192 g_slice_free (GtkIconViewItem, item);
3195 static GtkIconViewItem *
3196 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3199 gboolean only_in_cell,
3200 GtkCellRenderer **cell_at_pos)
3205 *cell_at_pos = NULL;
3207 for (items = icon_view->priv->items; items; items = items->next)
3209 GtkIconViewItem *item = items->data;
3210 GdkRectangle *item_area = (GdkRectangle *)item;
3212 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3213 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3214 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3215 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3217 if (only_in_cell || cell_at_pos)
3219 GtkCellRenderer *cell = NULL;
3220 GtkCellAreaContext *context;
3222 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3223 gtk_icon_view_set_cell_data (icon_view, item);
3225 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3226 y >= item_area->y && y <= item_area->y + item_area->height)
3227 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3228 GTK_WIDGET (icon_view),
3233 *cell_at_pos = cell;
3236 return cell != NULL ? item : NULL;
3247 gtk_icon_view_select_item (GtkIconView *icon_view,
3248 GtkIconViewItem *item)
3250 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3251 g_return_if_fail (item != NULL);
3256 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3258 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3259 gtk_icon_view_unselect_all_internal (icon_view);
3261 item->selected = TRUE;
3263 gtk_icon_view_item_selected_changed (icon_view, item);
3264 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3266 gtk_icon_view_queue_draw_item (icon_view, item);
3271 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3272 GtkIconViewItem *item)
3274 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3275 g_return_if_fail (item != NULL);
3277 if (!item->selected)
3280 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3281 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3284 item->selected = FALSE;
3286 gtk_icon_view_item_selected_changed (icon_view, item);
3287 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3289 gtk_icon_view_queue_draw_item (icon_view, item);
3293 verify_items (GtkIconView *icon_view)
3298 for (items = icon_view->priv->items; items; items = items->next)
3300 GtkIconViewItem *item = items->data;
3302 if (item->index != i)
3303 g_error ("List item does not match its index: "
3304 "item index %d and list index %d\n", item->index, i);
3311 gtk_icon_view_row_changed (GtkTreeModel *model,
3316 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3318 /* ignore changes in branches */
3319 if (gtk_tree_path_get_depth (path) > 1)
3322 /* An icon view subclass might add it's own model and populate
3323 * things at init() time instead of waiting for the constructor()
3326 if (icon_view->priv->cell_area)
3327 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3329 /* Here we can use a "grow-only" strategy for optimization
3330 * and only invalidate a single item and queue a relayout
3331 * instead of invalidating the whole thing.
3333 * For now GtkIconView still cant deal with huge models
3334 * so just invalidate the whole thing when the model
3337 gtk_icon_view_invalidate_sizes (icon_view);
3339 verify_items (icon_view);
3343 gtk_icon_view_row_inserted (GtkTreeModel *model,
3348 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3350 GtkIconViewItem *item;
3351 gboolean iters_persist;
3354 /* ignore changes in branches */
3355 if (gtk_tree_path_get_depth (path) > 1)
3358 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3360 index = gtk_tree_path_get_indices(path)[0];
3362 item = gtk_icon_view_item_new ();
3367 item->index = index;
3369 /* FIXME: We can be more efficient here,
3370 we can store a tail pointer and use that when
3371 appending (which is a rather common operation)
3373 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3376 list = g_list_nth (icon_view->priv->items, index + 1);
3377 for (; list; list = list->next)
3384 verify_items (icon_view);
3386 gtk_icon_view_queue_layout (icon_view);
3390 gtk_icon_view_row_deleted (GtkTreeModel *model,
3394 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3396 GtkIconViewItem *item;
3398 gboolean emit = FALSE;
3400 /* ignore changes in branches */
3401 if (gtk_tree_path_get_depth (path) > 1)
3404 index = gtk_tree_path_get_indices(path)[0];
3406 list = g_list_nth (icon_view->priv->items, index);
3409 if (icon_view->priv->cell_area)
3410 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3412 if (item == icon_view->priv->anchor_item)
3413 icon_view->priv->anchor_item = NULL;
3415 if (item == icon_view->priv->cursor_item)
3416 icon_view->priv->cursor_item = NULL;
3418 if (item == icon_view->priv->last_prelight)
3419 icon_view->priv->last_prelight = NULL;
3424 gtk_icon_view_item_free (item);
3426 for (next = list->next; next; next = next->next)
3433 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3435 verify_items (icon_view);
3437 gtk_icon_view_queue_layout (icon_view);
3440 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3444 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3445 GtkTreePath *parent,
3450 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3453 GList *items = NULL, *list;
3454 GtkIconViewItem **item_array;
3457 /* ignore changes in branches */
3461 if (icon_view->priv->cell_area)
3462 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3464 length = gtk_tree_model_iter_n_children (model, NULL);
3466 order = g_new (gint, length);
3467 for (i = 0; i < length; i++)
3468 order [new_order[i]] = i;
3470 item_array = g_new (GtkIconViewItem *, length);
3471 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3472 item_array[order[i]] = list->data;
3475 for (i = length - 1; i >= 0; i--)
3477 item_array[i]->index = i;
3478 items = g_list_prepend (items, item_array[i]);
3481 g_free (item_array);
3482 g_list_free (icon_view->priv->items);
3483 icon_view->priv->items = items;
3485 gtk_icon_view_queue_layout (icon_view);
3487 verify_items (icon_view);
3491 gtk_icon_view_build_items (GtkIconView *icon_view)
3495 gboolean iters_persist;
3496 GList *items = NULL;
3498 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3500 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3508 GtkIconViewItem *item = gtk_icon_view_item_new ();
3517 items = g_list_prepend (items, item);
3519 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3521 icon_view->priv->items = g_list_reverse (items);
3525 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3528 GtkMovementStep step,
3532 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3533 I_("move-cursor"), 2,
3537 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3542 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3545 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3550 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3557 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3558 GtkMovementStep step,
3561 GdkModifierType state;
3563 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3564 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3565 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3566 step == GTK_MOVEMENT_DISPLAY_LINES ||
3567 step == GTK_MOVEMENT_PAGES ||
3568 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3570 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3573 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3574 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3576 if (gtk_get_current_event_state (&state))
3578 GdkModifierType extend_mod_mask;
3579 GdkModifierType modify_mod_mask;
3582 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3583 GDK_MODIFIER_INTENT_EXTEND_SELECTION);
3585 gtk_widget_get_modifier_mask (GTK_WIDGET (icon_view),
3586 GDK_MODIFIER_INTENT_MODIFY_SELECTION);
3588 if ((state & modify_mod_mask) == modify_mod_mask)
3589 icon_view->priv->modify_selection_pressed = TRUE;
3590 if ((state & extend_mod_mask) == extend_mod_mask)
3591 icon_view->priv->extend_selection_pressed = TRUE;
3593 /* else we assume not pressed */
3597 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3598 case GTK_MOVEMENT_VISUAL_POSITIONS:
3599 gtk_icon_view_move_cursor_left_right (icon_view, count);
3601 case GTK_MOVEMENT_DISPLAY_LINES:
3602 gtk_icon_view_move_cursor_up_down (icon_view, count);
3604 case GTK_MOVEMENT_PAGES:
3605 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3607 case GTK_MOVEMENT_BUFFER_ENDS:
3608 gtk_icon_view_move_cursor_start_end (icon_view, count);
3611 g_assert_not_reached ();
3614 icon_view->priv->modify_selection_pressed = FALSE;
3615 icon_view->priv->extend_selection_pressed = FALSE;
3617 icon_view->priv->draw_focus = TRUE;
3622 static GtkIconViewItem *
3623 find_item (GtkIconView *icon_view,
3624 GtkIconViewItem *current,
3630 GtkIconViewItem *item;
3632 /* FIXME: this could be more efficient
3634 row = current->row + row_ofs;
3635 col = current->col + col_ofs;
3637 for (items = icon_view->priv->items; items; items = items->next)
3640 if (item->row == row && item->col == col)
3647 static GtkIconViewItem *
3648 find_item_page_up_down (GtkIconView *icon_view,
3649 GtkIconViewItem *current,
3656 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3658 item = g_list_find (icon_view->priv->items, current);
3663 for (next = item->next; next; next = next->next)
3665 if (((GtkIconViewItem *)next->data)->col == col)
3668 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3678 for (next = item->prev; next; next = next->prev)
3680 if (((GtkIconViewItem *)next->data)->col == col)
3683 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3697 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3698 GtkIconViewItem *anchor,
3699 GtkIconViewItem *cursor)
3702 GtkIconViewItem *item;
3703 gint row1, row2, col1, col2;
3704 gboolean dirty = FALSE;
3706 if (anchor->row < cursor->row)
3717 if (anchor->col < cursor->col)
3728 for (items = icon_view->priv->items; items; items = items->next)
3732 if (row1 <= item->row && item->row <= row2 &&
3733 col1 <= item->col && item->col <= col2)
3735 if (!item->selected)
3738 item->selected = TRUE;
3739 gtk_icon_view_item_selected_changed (icon_view, item);
3741 gtk_icon_view_queue_draw_item (icon_view, item);
3749 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3752 GtkIconViewItem *item;
3753 GtkCellRenderer *cell = NULL;
3754 gboolean dirty = FALSE;
3756 GtkDirectionType direction;
3758 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3761 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3763 if (!icon_view->priv->cursor_item)
3768 list = icon_view->priv->items;
3770 list = g_list_last (icon_view->priv->items);
3772 item = list ? list->data : NULL;
3774 /* Give focus to the first cell initially */
3775 gtk_icon_view_set_cell_data (icon_view, item);
3776 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3780 item = icon_view->priv->cursor_item;
3781 step = count > 0 ? 1 : -1;
3783 /* Save the current focus cell in case we hit the edge */
3784 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3788 gtk_icon_view_set_cell_data (icon_view, item);
3790 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3793 item = find_item (icon_view, item, step, 0);
3799 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3801 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3803 gtk_widget_child_focus (toplevel,
3804 direction == GTK_DIR_UP ?
3805 GTK_DIR_TAB_BACKWARD :
3806 GTK_DIR_TAB_FORWARD);
3810 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3814 if (icon_view->priv->modify_selection_pressed ||
3815 !icon_view->priv->extend_selection_pressed ||
3816 !icon_view->priv->anchor_item ||
3817 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3818 icon_view->priv->anchor_item = item;
3820 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3821 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3823 if (!icon_view->priv->modify_selection_pressed &&
3824 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3826 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3827 dirty = gtk_icon_view_select_all_between (icon_view,
3828 icon_view->priv->anchor_item,
3832 gtk_icon_view_scroll_to_item (icon_view, item);
3835 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3839 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3842 GtkIconViewItem *item;
3843 gboolean dirty = FALSE;
3845 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3848 if (!icon_view->priv->cursor_item)
3853 list = icon_view->priv->items;
3855 list = g_list_last (icon_view->priv->items);
3857 item = list ? list->data : NULL;
3860 item = find_item_page_up_down (icon_view,
3861 icon_view->priv->cursor_item,
3864 if (item == icon_view->priv->cursor_item)
3865 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3870 if (icon_view->priv->modify_selection_pressed ||
3871 !icon_view->priv->extend_selection_pressed ||
3872 !icon_view->priv->anchor_item ||
3873 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3874 icon_view->priv->anchor_item = item;
3876 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3878 if (!icon_view->priv->modify_selection_pressed &&
3879 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3881 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3882 dirty = gtk_icon_view_select_all_between (icon_view,
3883 icon_view->priv->anchor_item,
3887 gtk_icon_view_scroll_to_item (icon_view, item);
3890 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3894 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3897 GtkIconViewItem *item;
3898 GtkCellRenderer *cell = NULL;
3899 gboolean dirty = FALSE;
3901 GtkDirectionType direction;
3903 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3906 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3908 if (!icon_view->priv->cursor_item)
3913 list = icon_view->priv->items;
3915 list = g_list_last (icon_view->priv->items);
3917 item = list ? list->data : NULL;
3919 /* Give focus to the first cell initially */
3920 gtk_icon_view_set_cell_data (icon_view, item);
3921 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3925 item = icon_view->priv->cursor_item;
3926 step = count > 0 ? 1 : -1;
3928 /* Save the current focus cell in case we hit the edge */
3929 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3933 gtk_icon_view_set_cell_data (icon_view, item);
3935 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3938 item = find_item (icon_view, item, 0, step);
3944 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3946 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3948 gtk_widget_child_focus (toplevel,
3949 direction == GTK_DIR_LEFT ?
3950 GTK_DIR_TAB_BACKWARD :
3951 GTK_DIR_TAB_FORWARD);
3955 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3959 if (icon_view->priv->modify_selection_pressed ||
3960 !icon_view->priv->extend_selection_pressed ||
3961 !icon_view->priv->anchor_item ||
3962 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3963 icon_view->priv->anchor_item = item;
3965 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3966 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3968 if (!icon_view->priv->modify_selection_pressed &&
3969 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3971 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3972 dirty = gtk_icon_view_select_all_between (icon_view,
3973 icon_view->priv->anchor_item,
3977 gtk_icon_view_scroll_to_item (icon_view, item);
3980 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3984 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3987 GtkIconViewItem *item;
3989 gboolean dirty = FALSE;
3991 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3995 list = icon_view->priv->items;
3997 list = g_list_last (icon_view->priv->items);
3999 item = list ? list->data : NULL;
4001 if (item == icon_view->priv->cursor_item)
4002 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4007 if (icon_view->priv->modify_selection_pressed ||
4008 !icon_view->priv->extend_selection_pressed ||
4009 !icon_view->priv->anchor_item ||
4010 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4011 icon_view->priv->anchor_item = item;
4013 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
4015 if (!icon_view->priv->modify_selection_pressed &&
4016 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4018 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4019 dirty = gtk_icon_view_select_all_between (icon_view,
4020 icon_view->priv->anchor_item,
4024 gtk_icon_view_scroll_to_item (icon_view, item);
4027 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4031 * gtk_icon_view_scroll_to_path:
4032 * @icon_view: A #GtkIconView.
4033 * @path: The path of the item to move to.
4034 * @use_align: whether to use alignment arguments, or %FALSE.
4035 * @row_align: The vertical alignment of the item specified by @path.
4036 * @col_align: The horizontal alignment of the item specified by @path.
4038 * Moves the alignments of @icon_view to the position specified by @path.
4039 * @row_align determines where the row is placed, and @col_align determines
4040 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4041 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4044 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4045 * tree does the minimum amount of work to scroll the item onto the screen.
4046 * This means that the item will be scrolled to the edge closest to its current
4047 * position. If the item is currently visible on the screen, nothing is done.
4049 * This function only works if the model is set, and @path is a valid row on
4050 * the model. If the model changes before the @icon_view is realized, the
4051 * centered path will be modified to reflect this change.
4056 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4062 GtkIconViewItem *item = NULL;
4065 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4066 g_return_if_fail (path != NULL);
4067 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4068 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4070 widget = GTK_WIDGET (icon_view);
4072 if (gtk_tree_path_get_depth (path) > 0)
4073 item = g_list_nth_data (icon_view->priv->items,
4074 gtk_tree_path_get_indices(path)[0]);
4076 if (!item || item->cell_area.width < 0 ||
4077 !gtk_widget_get_realized (widget))
4079 if (icon_view->priv->scroll_to_path)
4080 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4082 icon_view->priv->scroll_to_path = NULL;
4085 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4087 icon_view->priv->scroll_to_use_align = use_align;
4088 icon_view->priv->scroll_to_row_align = row_align;
4089 icon_view->priv->scroll_to_col_align = col_align;
4096 GtkAllocation allocation;
4099 GdkRectangle item_area =
4101 item->cell_area.x - icon_view->priv->item_padding,
4102 item->cell_area.y - icon_view->priv->item_padding,
4103 item->cell_area.width + icon_view->priv->item_padding * 2,
4104 item->cell_area.height + icon_view->priv->item_padding * 2
4107 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4109 gtk_widget_get_allocation (widget, &allocation);
4111 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4113 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4114 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4116 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4118 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4119 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4121 gtk_adjustment_changed (icon_view->priv->hadjustment);
4122 gtk_adjustment_changed (icon_view->priv->vadjustment);
4125 gtk_icon_view_scroll_to_item (icon_view, item);
4130 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4131 GtkIconViewItem *item)
4133 GtkIconViewPrivate *priv = icon_view->priv;
4134 GtkWidget *widget = GTK_WIDGET (icon_view);
4135 GtkAdjustment *hadj, *vadj;
4136 GtkAllocation allocation;
4138 GdkRectangle item_area;
4140 item_area.x = item->cell_area.x - priv->item_padding;
4141 item_area.y = item->cell_area.y - priv->item_padding;
4142 item_area.width = item->cell_area.width + priv->item_padding * 2;
4143 item_area.height = item->cell_area.height + priv->item_padding * 2;
4145 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4146 gtk_widget_get_allocation (widget, &allocation);
4148 hadj = icon_view->priv->hadjustment;
4149 vadj = icon_view->priv->vadjustment;
4151 if (y + item_area.y < 0)
4152 gtk_adjustment_set_value (vadj,
4153 gtk_adjustment_get_value (vadj)
4155 else if (y + item_area.y + item_area.height > allocation.height)
4156 gtk_adjustment_set_value (vadj,
4157 gtk_adjustment_get_value (vadj)
4158 + y + item_area.y + item_area.height - allocation.height);
4160 if (x + item_area.x < 0)
4161 gtk_adjustment_set_value (hadj,
4162 gtk_adjustment_get_value (hadj)
4164 else if (x + item_area.x + item_area.width > allocation.width)
4165 gtk_adjustment_set_value (hadj,
4166 gtk_adjustment_get_value (hadj)
4167 + x + item_area.x + item_area.width - allocation.width);
4169 gtk_adjustment_changed (hadj);
4170 gtk_adjustment_changed (vadj);
4173 /* GtkCellLayout implementation */
4176 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4177 GtkCellArea *cell_area)
4179 GtkIconViewPrivate *priv = icon_view->priv;
4181 if (priv->cell_area)
4185 priv->cell_area = cell_area;
4187 priv->cell_area = gtk_cell_area_box_new ();
4189 g_object_ref_sink (priv->cell_area);
4191 if (GTK_IS_ORIENTABLE (priv->cell_area))
4192 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4194 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4196 priv->add_editable_id =
4197 g_signal_connect (priv->cell_area, "add-editable",
4198 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4199 priv->remove_editable_id =
4200 g_signal_connect (priv->cell_area, "remove-editable",
4201 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4202 priv->context_changed_id =
4203 g_signal_connect (priv->cell_area_context, "notify",
4204 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4206 update_text_cell (icon_view);
4207 update_pixbuf_cell (icon_view);
4210 static GtkCellArea *
4211 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4213 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4214 GtkIconViewPrivate *priv = icon_view->priv;
4216 if (G_UNLIKELY (!priv->cell_area))
4217 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4219 return icon_view->priv->cell_area;
4223 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4224 GtkIconViewItem *item)
4226 gboolean iters_persist;
4229 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4235 path = gtk_tree_path_new_from_indices (item->index, -1);
4236 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4238 gtk_tree_path_free (path);
4243 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4244 icon_view->priv->model,
4245 &iter, FALSE, FALSE);
4254 * gtk_icon_view_new:
4256 * Creates a new #GtkIconView widget
4258 * Return value: A newly created #GtkIconView widget
4263 gtk_icon_view_new (void)
4265 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4269 * gtk_icon_view_new_with_area:
4270 * @area: the #GtkCellArea to use to layout cells
4272 * Creates a new #GtkIconView widget using the
4273 * specified @area to layout cells inside the icons.
4275 * Return value: A newly created #GtkIconView widget
4280 gtk_icon_view_new_with_area (GtkCellArea *area)
4282 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4286 * gtk_icon_view_new_with_model:
4287 * @model: The model.
4289 * Creates a new #GtkIconView widget with the model @model.
4291 * Return value: A newly created #GtkIconView widget.
4296 gtk_icon_view_new_with_model (GtkTreeModel *model)
4298 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4302 * gtk_icon_view_convert_widget_to_bin_window_coords:
4303 * @icon_view: a #GtkIconView
4304 * @wx: X coordinate relative to the widget
4305 * @wy: Y coordinate relative to the widget
4306 * @bx: (out): return location for bin_window X coordinate
4307 * @by: (out): return location for bin_window Y coordinate
4309 * Converts widget coordinates to coordinates for the bin_window,
4310 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4315 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4323 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4325 if (icon_view->priv->bin_window)
4326 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4337 * gtk_icon_view_get_path_at_pos:
4338 * @icon_view: A #GtkIconView.
4339 * @x: The x position to be identified
4340 * @y: The y position to be identified
4342 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4343 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4344 * the cell at the specified position.
4345 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4346 * widget coordinates to bin_window coordinates.
4348 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4349 * if no icon exists at that position.
4354 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4358 GtkIconViewItem *item;
4361 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4363 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4368 path = gtk_tree_path_new_from_indices (item->index, -1);
4374 * gtk_icon_view_get_item_at_pos:
4375 * @icon_view: A #GtkIconView.
4376 * @x: The x position to be identified
4377 * @y: The y position to be identified
4378 * @path: (out) (allow-none): Return location for the path, or %NULL
4379 * @cell: (out) (allow-none): Return location for the renderer
4380 * responsible for the cell at (@x, @y), or %NULL
4382 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4383 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4384 * obtains the cell at the specified position. The returned path should
4385 * be freed with gtk_tree_path_free().
4386 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4387 * widget coordinates to bin_window coordinates.
4389 * Return value: %TRUE if an item exists at the specified position
4394 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4398 GtkCellRenderer **cell)
4400 GtkIconViewItem *item;
4401 GtkCellRenderer *renderer = NULL;
4403 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4405 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4410 *path = gtk_tree_path_new_from_indices (item->index, -1);
4418 return (item != NULL);
4422 * gtk_icon_view_set_tooltip_item:
4423 * @icon_view: a #GtkIconView
4424 * @tooltip: a #GtkTooltip
4425 * @path: a #GtkTreePath
4427 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4428 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4429 * See also gtk_tooltip_set_tip_area().
4434 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4435 GtkTooltip *tooltip,
4438 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4439 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4441 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4445 * gtk_icon_view_set_tooltip_cell:
4446 * @icon_view: a #GtkIconView
4447 * @tooltip: a #GtkTooltip
4448 * @path: a #GtkTreePath
4449 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4451 * Sets the tip area of @tooltip to the area which @cell occupies in
4452 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4454 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4459 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4460 GtkTooltip *tooltip,
4462 GtkCellRenderer *cell)
4465 GtkIconViewItem *item = NULL;
4468 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4469 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4470 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4472 if (gtk_tree_path_get_depth (path) > 0)
4473 item = g_list_nth_data (icon_view->priv->items,
4474 gtk_tree_path_get_indices(path)[0]);
4481 GtkCellAreaContext *context;
4483 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4484 gtk_icon_view_set_cell_data (icon_view, item);
4485 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4486 GTK_WIDGET (icon_view),
4487 cell, (GdkRectangle *)item, &rect);
4491 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4492 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4493 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4494 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4497 if (icon_view->priv->bin_window)
4499 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4504 gtk_tooltip_set_tip_area (tooltip, &rect);
4509 * gtk_icon_view_get_tooltip_context:
4510 * @icon_view: an #GtkIconView
4511 * @x: (inout): the x coordinate (relative to widget coordinates)
4512 * @y: (inout): the y coordinate (relative to widget coordinates)
4513 * @keyboard_tip: whether this is a keyboard tooltip or not
4514 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4515 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4516 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4518 * This function is supposed to be used in a #GtkWidget::query-tooltip
4519 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4520 * which are received in the signal handler, should be passed to this
4521 * function without modification.
4523 * The return value indicates whether there is an icon view item at the given
4524 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4525 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4526 * @model, @path and @iter which have been provided will be set to point to
4527 * that row and the corresponding model. @x and @y will always be converted
4528 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4530 * Return value: whether or not the given tooltip context points to a item
4535 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4538 gboolean keyboard_tip,
4539 GtkTreeModel **model,
4543 GtkTreePath *tmppath = NULL;
4545 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4546 g_return_val_if_fail (x != NULL, FALSE);
4547 g_return_val_if_fail (y != NULL, FALSE);
4551 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4558 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4561 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4566 *model = gtk_icon_view_get_model (icon_view);
4569 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4575 gtk_tree_path_free (tmppath);
4581 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4584 gboolean keyboard_tip,
4585 GtkTooltip *tooltip,
4591 GtkTreeModel *model;
4592 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4594 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4597 &model, &path, &iter))
4600 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4604 gtk_tree_path_free (path);
4608 gtk_tooltip_set_markup (tooltip, str);
4609 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4611 gtk_tree_path_free (path);
4619 * gtk_icon_view_set_tooltip_column:
4620 * @icon_view: a #GtkIconView
4621 * @column: an integer, which is a valid column number for @icon_view's model
4623 * If you only plan to have simple (text-only) tooltips on full items, you
4624 * can use this function to have #GtkIconView handle these automatically
4625 * for you. @column should be set to the column in @icon_view's model
4626 * containing the tooltip texts, or -1 to disable this feature.
4628 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4629 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4631 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4632 * so &, <, etc have to be escaped in the text.
4637 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4640 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4642 if (column == icon_view->priv->tooltip_column)
4647 g_signal_handlers_disconnect_by_func (icon_view,
4648 gtk_icon_view_set_tooltip_query_cb,
4650 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4654 if (icon_view->priv->tooltip_column == -1)
4656 g_signal_connect (icon_view, "query-tooltip",
4657 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4658 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4662 icon_view->priv->tooltip_column = column;
4663 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4667 * gtk_icon_view_get_tooltip_column:
4668 * @icon_view: a #GtkIconView
4670 * Returns the column of @icon_view's model which is being used for
4671 * displaying tooltips on @icon_view's rows.
4673 * Return value: the index of the tooltip column that is currently being
4674 * used, or -1 if this is disabled.
4679 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4681 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4683 return icon_view->priv->tooltip_column;
4687 * gtk_icon_view_get_visible_range:
4688 * @icon_view: A #GtkIconView
4689 * @start_path: (out) (allow-none): Return location for start of region,
4691 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4693 * Sets @start_path and @end_path to be the first and last visible path.
4694 * Note that there may be invisible paths in between.
4696 * Both paths should be freed with gtk_tree_path_free() after use.
4698 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4703 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4704 GtkTreePath **start_path,
4705 GtkTreePath **end_path)
4707 gint start_index = -1;
4708 gint end_index = -1;
4711 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4713 if (icon_view->priv->hadjustment == NULL ||
4714 icon_view->priv->vadjustment == NULL)
4717 if (start_path == NULL && end_path == NULL)
4720 for (icons = icon_view->priv->items; icons; icons = icons->next)
4722 GtkIconViewItem *item = icons->data;
4723 GdkRectangle *item_area = (GdkRectangle *)item;
4725 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4726 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4728 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4729 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4731 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4732 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4734 if (start_index == -1)
4735 start_index = item->index;
4736 end_index = item->index;
4740 if (start_path && start_index != -1)
4741 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4742 if (end_path && end_index != -1)
4743 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4745 return start_index != -1;
4749 * gtk_icon_view_selected_foreach:
4750 * @icon_view: A #GtkIconView.
4751 * @func: (scope call): The function to call for each selected icon.
4752 * @data: User data to pass to the function.
4754 * Calls a function for each selected icon. Note that the model or
4755 * selection cannot be modified from within this function.
4760 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4761 GtkIconViewForeachFunc func,
4766 for (list = icon_view->priv->items; list; list = list->next)
4768 GtkIconViewItem *item = list->data;
4769 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4772 (* func) (icon_view, path, data);
4774 gtk_tree_path_free (path);
4779 * gtk_icon_view_set_selection_mode:
4780 * @icon_view: A #GtkIconView.
4781 * @mode: The selection mode
4783 * Sets the selection mode of the @icon_view.
4788 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4789 GtkSelectionMode mode)
4791 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4793 if (mode == icon_view->priv->selection_mode)
4796 if (mode == GTK_SELECTION_NONE ||
4797 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4798 gtk_icon_view_unselect_all (icon_view);
4800 icon_view->priv->selection_mode = mode;
4802 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4806 * gtk_icon_view_get_selection_mode:
4807 * @icon_view: A #GtkIconView.
4809 * Gets the selection mode of the @icon_view.
4811 * Return value: the current selection mode
4816 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4818 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4820 return icon_view->priv->selection_mode;
4824 * gtk_icon_view_set_model:
4825 * @icon_view: A #GtkIconView.
4826 * @model: (allow-none): The model.
4828 * Sets the model for a #GtkIconView.
4829 * If the @icon_view already has a model set, it will remove
4830 * it before setting the new model. If @model is %NULL, then
4831 * it will unset the old model.
4836 gtk_icon_view_set_model (GtkIconView *icon_view,
4837 GtkTreeModel *model)
4839 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4840 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4842 if (icon_view->priv->model == model)
4845 if (icon_view->priv->scroll_to_path)
4847 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4848 icon_view->priv->scroll_to_path = NULL;
4851 /* The area can be NULL while disposing */
4852 if (icon_view->priv->cell_area)
4853 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4859 if (icon_view->priv->pixbuf_column != -1)
4861 column_type = gtk_tree_model_get_column_type (model,
4862 icon_view->priv->pixbuf_column);
4864 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4867 if (icon_view->priv->text_column != -1)
4869 column_type = gtk_tree_model_get_column_type (model,
4870 icon_view->priv->text_column);
4872 g_return_if_fail (column_type == G_TYPE_STRING);
4875 if (icon_view->priv->markup_column != -1)
4877 column_type = gtk_tree_model_get_column_type (model,
4878 icon_view->priv->markup_column);
4880 g_return_if_fail (column_type == G_TYPE_STRING);
4885 if (icon_view->priv->model)
4887 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4888 gtk_icon_view_row_changed,
4890 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4891 gtk_icon_view_row_inserted,
4893 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4894 gtk_icon_view_row_deleted,
4896 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4897 gtk_icon_view_rows_reordered,
4900 g_object_unref (icon_view->priv->model);
4902 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4903 g_list_free (icon_view->priv->items);
4904 icon_view->priv->items = NULL;
4905 icon_view->priv->anchor_item = NULL;
4906 icon_view->priv->cursor_item = NULL;
4907 icon_view->priv->last_single_clicked = NULL;
4908 icon_view->priv->last_prelight = NULL;
4909 icon_view->priv->width = 0;
4910 icon_view->priv->height = 0;
4913 icon_view->priv->model = model;
4915 if (icon_view->priv->model)
4917 g_object_ref (icon_view->priv->model);
4918 g_signal_connect (icon_view->priv->model,
4920 G_CALLBACK (gtk_icon_view_row_changed),
4922 g_signal_connect (icon_view->priv->model,
4924 G_CALLBACK (gtk_icon_view_row_inserted),
4926 g_signal_connect (icon_view->priv->model,
4928 G_CALLBACK (gtk_icon_view_row_deleted),
4930 g_signal_connect (icon_view->priv->model,
4932 G_CALLBACK (gtk_icon_view_rows_reordered),
4935 gtk_icon_view_build_items (icon_view);
4937 gtk_icon_view_layout (icon_view);
4940 g_object_notify (G_OBJECT (icon_view), "model");
4942 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4943 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4947 * gtk_icon_view_get_model:
4948 * @icon_view: a #GtkIconView
4950 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4953 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4954 * currently being used.
4959 gtk_icon_view_get_model (GtkIconView *icon_view)
4961 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4963 return icon_view->priv->model;
4967 update_text_cell (GtkIconView *icon_view)
4969 if (!icon_view->priv->cell_area)
4972 if (icon_view->priv->text_column == -1 &&
4973 icon_view->priv->markup_column == -1)
4975 if (icon_view->priv->text_cell != NULL)
4977 gtk_cell_area_remove (icon_view->priv->cell_area,
4978 icon_view->priv->text_cell);
4979 icon_view->priv->text_cell = NULL;
4984 if (icon_view->priv->text_cell == NULL)
4986 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4988 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4991 if (icon_view->priv->markup_column != -1)
4992 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4993 icon_view->priv->text_cell,
4994 "markup", icon_view->priv->markup_column,
4997 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4998 icon_view->priv->text_cell,
4999 "text", icon_view->priv->text_column,
5002 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5003 g_object_set (icon_view->priv->text_cell,
5004 "alignment", PANGO_ALIGN_CENTER,
5005 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5010 g_object_set (icon_view->priv->text_cell,
5011 "alignment", PANGO_ALIGN_LEFT,
5012 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5020 update_pixbuf_cell (GtkIconView *icon_view)
5022 if (!icon_view->priv->cell_area)
5025 if (icon_view->priv->pixbuf_column == -1)
5027 if (icon_view->priv->pixbuf_cell != NULL)
5029 gtk_cell_area_remove (icon_view->priv->cell_area,
5030 icon_view->priv->pixbuf_cell);
5032 icon_view->priv->pixbuf_cell = NULL;
5037 if (icon_view->priv->pixbuf_cell == NULL)
5039 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5041 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5044 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5045 icon_view->priv->pixbuf_cell,
5046 "pixbuf", icon_view->priv->pixbuf_column,
5049 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5050 g_object_set (icon_view->priv->pixbuf_cell,
5055 g_object_set (icon_view->priv->pixbuf_cell,
5063 * gtk_icon_view_set_text_column:
5064 * @icon_view: A #GtkIconView.
5065 * @column: A column in the currently used model, or -1 to display no text
5067 * Sets the column with text for @icon_view to be @column. The text
5068 * column must be of type #G_TYPE_STRING.
5073 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5076 if (column == icon_view->priv->text_column)
5080 icon_view->priv->text_column = -1;
5083 if (icon_view->priv->model != NULL)
5087 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5089 g_return_if_fail (column_type == G_TYPE_STRING);
5092 icon_view->priv->text_column = column;
5095 if (icon_view->priv->cell_area)
5096 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5098 update_text_cell (icon_view);
5100 gtk_icon_view_invalidate_sizes (icon_view);
5102 g_object_notify (G_OBJECT (icon_view), "text-column");
5106 * gtk_icon_view_get_text_column:
5107 * @icon_view: A #GtkIconView.
5109 * Returns the column with text for @icon_view.
5111 * Returns: the text column, or -1 if it's unset.
5116 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5118 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5120 return icon_view->priv->text_column;
5124 * gtk_icon_view_set_markup_column:
5125 * @icon_view: A #GtkIconView.
5126 * @column: A column in the currently used model, or -1 to display no text
5128 * Sets the column with markup information for @icon_view to be
5129 * @column. The markup column must be of type #G_TYPE_STRING.
5130 * If the markup column is set to something, it overrides
5131 * the text column set by gtk_icon_view_set_text_column().
5136 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5139 if (column == icon_view->priv->markup_column)
5143 icon_view->priv->markup_column = -1;
5146 if (icon_view->priv->model != NULL)
5150 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5152 g_return_if_fail (column_type == G_TYPE_STRING);
5155 icon_view->priv->markup_column = column;
5158 if (icon_view->priv->cell_area)
5159 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5161 update_text_cell (icon_view);
5163 gtk_icon_view_invalidate_sizes (icon_view);
5165 g_object_notify (G_OBJECT (icon_view), "markup-column");
5169 * gtk_icon_view_get_markup_column:
5170 * @icon_view: A #GtkIconView.
5172 * Returns the column with markup text for @icon_view.
5174 * Returns: the markup column, or -1 if it's unset.
5179 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5181 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5183 return icon_view->priv->markup_column;
5187 * gtk_icon_view_set_pixbuf_column:
5188 * @icon_view: A #GtkIconView.
5189 * @column: A column in the currently used model, or -1 to disable
5191 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5192 * column must be of type #GDK_TYPE_PIXBUF
5197 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5200 if (column == icon_view->priv->pixbuf_column)
5204 icon_view->priv->pixbuf_column = -1;
5207 if (icon_view->priv->model != NULL)
5211 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5213 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5216 icon_view->priv->pixbuf_column = column;
5219 if (icon_view->priv->cell_area)
5220 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5222 update_pixbuf_cell (icon_view);
5224 gtk_icon_view_invalidate_sizes (icon_view);
5226 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5231 * gtk_icon_view_get_pixbuf_column:
5232 * @icon_view: A #GtkIconView.
5234 * Returns the column with pixbufs for @icon_view.
5236 * Returns: the pixbuf column, or -1 if it's unset.
5241 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5243 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5245 return icon_view->priv->pixbuf_column;
5249 * gtk_icon_view_select_path:
5250 * @icon_view: A #GtkIconView.
5251 * @path: The #GtkTreePath to be selected.
5253 * Selects the row at @path.
5258 gtk_icon_view_select_path (GtkIconView *icon_view,
5261 GtkIconViewItem *item = NULL;
5263 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5264 g_return_if_fail (icon_view->priv->model != NULL);
5265 g_return_if_fail (path != NULL);
5267 if (gtk_tree_path_get_depth (path) > 0)
5268 item = g_list_nth_data (icon_view->priv->items,
5269 gtk_tree_path_get_indices(path)[0]);
5272 gtk_icon_view_select_item (icon_view, item);
5276 * gtk_icon_view_unselect_path:
5277 * @icon_view: A #GtkIconView.
5278 * @path: The #GtkTreePath to be unselected.
5280 * Unselects the row at @path.
5285 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5288 GtkIconViewItem *item;
5290 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5291 g_return_if_fail (icon_view->priv->model != NULL);
5292 g_return_if_fail (path != NULL);
5294 item = g_list_nth_data (icon_view->priv->items,
5295 gtk_tree_path_get_indices(path)[0]);
5300 gtk_icon_view_unselect_item (icon_view, item);
5304 * gtk_icon_view_get_selected_items:
5305 * @icon_view: A #GtkIconView.
5307 * Creates a list of paths of all selected items. Additionally, if you are
5308 * planning on modifying the model after calling this function, you may
5309 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5310 * To do this, you can use gtk_tree_row_reference_new().
5312 * To free the return value, use:
5314 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5315 * g_list_free (list);
5318 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5323 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5326 GList *selected = NULL;
5328 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5330 for (list = icon_view->priv->items; list != NULL; list = list->next)
5332 GtkIconViewItem *item = list->data;
5336 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5338 selected = g_list_prepend (selected, path);
5346 * gtk_icon_view_select_all:
5347 * @icon_view: A #GtkIconView.
5349 * Selects all the icons. @icon_view must has its selection mode set
5350 * to #GTK_SELECTION_MULTIPLE.
5355 gtk_icon_view_select_all (GtkIconView *icon_view)
5358 gboolean dirty = FALSE;
5360 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5362 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5365 for (items = icon_view->priv->items; items; items = items->next)
5367 GtkIconViewItem *item = items->data;
5369 if (!item->selected)
5372 item->selected = TRUE;
5373 gtk_icon_view_queue_draw_item (icon_view, item);
5378 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5382 * gtk_icon_view_unselect_all:
5383 * @icon_view: A #GtkIconView.
5385 * Unselects all the icons.
5390 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5392 gboolean dirty = FALSE;
5394 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5396 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5399 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5402 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5406 * gtk_icon_view_path_is_selected:
5407 * @icon_view: A #GtkIconView.
5408 * @path: A #GtkTreePath to check selection on.
5410 * Returns %TRUE if the icon pointed to by @path is currently
5411 * selected. If @path does not point to a valid location, %FALSE is returned.
5413 * Return value: %TRUE if @path is selected.
5418 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5421 GtkIconViewItem *item;
5423 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5424 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5425 g_return_val_if_fail (path != NULL, FALSE);
5427 item = g_list_nth_data (icon_view->priv->items,
5428 gtk_tree_path_get_indices(path)[0]);
5433 return item->selected;
5437 * gtk_icon_view_get_item_row:
5438 * @icon_view: a #GtkIconView
5439 * @path: the #GtkTreePath of the item
5441 * Gets the row in which the item @path is currently
5442 * displayed. Row numbers start at 0.
5444 * Returns: The row in which the item is displayed
5449 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5452 GtkIconViewItem *item;
5454 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5455 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5456 g_return_val_if_fail (path != NULL, -1);
5458 item = g_list_nth_data (icon_view->priv->items,
5459 gtk_tree_path_get_indices(path)[0]);
5468 * gtk_icon_view_get_item_column:
5469 * @icon_view: a #GtkIconView
5470 * @path: the #GtkTreePath of the item
5472 * Gets the column in which the item @path is currently
5473 * displayed. Column numbers start at 0.
5475 * Returns: The column in which the item is displayed
5480 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5483 GtkIconViewItem *item;
5485 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5486 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5487 g_return_val_if_fail (path != NULL, -1);
5489 item = g_list_nth_data (icon_view->priv->items,
5490 gtk_tree_path_get_indices(path)[0]);
5499 * gtk_icon_view_item_activated:
5500 * @icon_view: A #GtkIconView
5501 * @path: The #GtkTreePath to be activated
5503 * Activates the item determined by @path.
5508 gtk_icon_view_item_activated (GtkIconView *icon_view,
5511 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5512 g_return_if_fail (path != NULL);
5514 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5518 * gtk_icon_view_set_item_orientation:
5519 * @icon_view: a #GtkIconView
5520 * @orientation: the relative position of texts and icons
5522 * Sets the ::item-orientation property which determines whether the labels
5523 * are drawn beside the icons instead of below.
5528 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5529 GtkOrientation orientation)
5531 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5533 if (icon_view->priv->item_orientation != orientation)
5535 icon_view->priv->item_orientation = orientation;
5537 if (icon_view->priv->cell_area)
5539 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5540 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5541 icon_view->priv->item_orientation);
5543 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5546 gtk_icon_view_invalidate_sizes (icon_view);
5548 update_text_cell (icon_view);
5549 update_pixbuf_cell (icon_view);
5551 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5556 * gtk_icon_view_get_item_orientation:
5557 * @icon_view: a #GtkIconView
5559 * Returns the value of the ::item-orientation property which determines
5560 * whether the labels are drawn beside the icons instead of below.
5562 * Return value: the relative position of texts and icons
5567 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5569 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5570 GTK_ORIENTATION_VERTICAL);
5572 return icon_view->priv->item_orientation;
5576 * gtk_icon_view_set_columns:
5577 * @icon_view: a #GtkIconView
5578 * @columns: the number of columns
5580 * Sets the ::columns property which determines in how
5581 * many columns the icons are arranged. If @columns is
5582 * -1, the number of columns will be chosen automatically
5583 * to fill the available area.
5588 gtk_icon_view_set_columns (GtkIconView *icon_view,
5591 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5593 if (icon_view->priv->columns != columns)
5595 icon_view->priv->columns = columns;
5597 if (icon_view->priv->cell_area)
5598 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5600 gtk_icon_view_queue_layout (icon_view);
5602 g_object_notify (G_OBJECT (icon_view), "columns");
5607 * gtk_icon_view_get_columns:
5608 * @icon_view: a #GtkIconView
5610 * Returns the value of the ::columns property.
5612 * Return value: the number of columns, or -1
5617 gtk_icon_view_get_columns (GtkIconView *icon_view)
5619 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5621 return icon_view->priv->columns;
5625 * gtk_icon_view_set_item_width:
5626 * @icon_view: a #GtkIconView
5627 * @item_width: the width for each item
5629 * Sets the ::item-width property which specifies the width
5630 * to use for each item. If it is set to -1, the icon view will
5631 * automatically determine a suitable item size.
5636 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5639 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5641 if (icon_view->priv->item_width != item_width)
5643 icon_view->priv->item_width = item_width;
5645 if (icon_view->priv->cell_area)
5646 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5648 gtk_icon_view_invalidate_sizes (icon_view);
5650 update_text_cell (icon_view);
5652 g_object_notify (G_OBJECT (icon_view), "item-width");
5657 * gtk_icon_view_get_item_width:
5658 * @icon_view: a #GtkIconView
5660 * Returns the value of the ::item-width property.
5662 * Return value: the width of a single item, or -1
5667 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5669 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5671 return icon_view->priv->item_width;
5676 * gtk_icon_view_set_spacing:
5677 * @icon_view: a #GtkIconView
5678 * @spacing: the spacing
5680 * Sets the ::spacing property which specifies the space
5681 * which is inserted between the cells (i.e. the icon and
5682 * the text) of an item.
5687 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5690 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5692 if (icon_view->priv->spacing != spacing)
5694 icon_view->priv->spacing = spacing;
5696 if (icon_view->priv->cell_area)
5697 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5699 gtk_icon_view_invalidate_sizes (icon_view);
5701 g_object_notify (G_OBJECT (icon_view), "spacing");
5706 * gtk_icon_view_get_spacing:
5707 * @icon_view: a #GtkIconView
5709 * Returns the value of the ::spacing property.
5711 * Return value: the space between cells
5716 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5718 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5720 return icon_view->priv->spacing;
5724 * gtk_icon_view_set_row_spacing:
5725 * @icon_view: a #GtkIconView
5726 * @row_spacing: the row spacing
5728 * Sets the ::row-spacing property which specifies the space
5729 * which is inserted between the rows of the icon view.
5734 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5737 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5739 if (icon_view->priv->row_spacing != row_spacing)
5741 icon_view->priv->row_spacing = row_spacing;
5743 if (icon_view->priv->cell_area)
5744 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5746 gtk_icon_view_invalidate_sizes (icon_view);
5748 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5753 * gtk_icon_view_get_row_spacing:
5754 * @icon_view: a #GtkIconView
5756 * Returns the value of the ::row-spacing property.
5758 * Return value: the space between rows
5763 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5765 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5767 return icon_view->priv->row_spacing;
5771 * gtk_icon_view_set_column_spacing:
5772 * @icon_view: a #GtkIconView
5773 * @column_spacing: the column spacing
5775 * Sets the ::column-spacing property which specifies the space
5776 * which is inserted between the columns of the icon view.
5781 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5782 gint column_spacing)
5784 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5786 if (icon_view->priv->column_spacing != column_spacing)
5788 icon_view->priv->column_spacing = column_spacing;
5790 if (icon_view->priv->cell_area)
5791 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5793 gtk_icon_view_invalidate_sizes (icon_view);
5795 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5800 * gtk_icon_view_get_column_spacing:
5801 * @icon_view: a #GtkIconView
5803 * Returns the value of the ::column-spacing property.
5805 * Return value: the space between columns
5810 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5812 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5814 return icon_view->priv->column_spacing;
5818 * gtk_icon_view_set_margin:
5819 * @icon_view: a #GtkIconView
5820 * @margin: the margin
5822 * Sets the ::margin property which specifies the space
5823 * which is inserted at the top, bottom, left and right
5829 gtk_icon_view_set_margin (GtkIconView *icon_view,
5832 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5834 if (icon_view->priv->margin != margin)
5836 icon_view->priv->margin = margin;
5838 if (icon_view->priv->cell_area)
5839 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5841 gtk_icon_view_invalidate_sizes (icon_view);
5843 g_object_notify (G_OBJECT (icon_view), "margin");
5848 * gtk_icon_view_get_margin:
5849 * @icon_view: a #GtkIconView
5851 * Returns the value of the ::margin property.
5853 * Return value: the space at the borders
5858 gtk_icon_view_get_margin (GtkIconView *icon_view)
5860 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5862 return icon_view->priv->margin;
5866 * gtk_icon_view_set_item_padding:
5867 * @icon_view: a #GtkIconView
5868 * @item_padding: the item padding
5870 * Sets the #GtkIconView:item-padding property which specifies the padding
5871 * around each of the icon view's items.
5876 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5879 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5881 if (icon_view->priv->item_padding != item_padding)
5883 icon_view->priv->item_padding = item_padding;
5885 if (icon_view->priv->cell_area)
5886 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5888 gtk_icon_view_invalidate_sizes (icon_view);
5890 g_object_notify (G_OBJECT (icon_view), "item-padding");
5895 * gtk_icon_view_get_item_padding:
5896 * @icon_view: a #GtkIconView
5898 * Returns the value of the ::item-padding property.
5900 * Return value: the padding around items
5905 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5907 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5909 return icon_view->priv->item_padding;
5912 /* Get/set whether drag_motion requested the drag data and
5913 * drag_data_received should thus not actually insert the data,
5914 * since the data doesn't result from a drop.
5917 set_status_pending (GdkDragContext *context,
5918 GdkDragAction suggested_action)
5920 g_object_set_data (G_OBJECT (context),
5921 I_("gtk-icon-view-status-pending"),
5922 GINT_TO_POINTER (suggested_action));
5925 static GdkDragAction
5926 get_status_pending (GdkDragContext *context)
5928 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5929 "gtk-icon-view-status-pending"));
5933 unset_reorderable (GtkIconView *icon_view)
5935 if (icon_view->priv->reorderable)
5937 icon_view->priv->reorderable = FALSE;
5938 g_object_notify (G_OBJECT (icon_view), "reorderable");
5943 set_source_row (GdkDragContext *context,
5944 GtkTreeModel *model,
5945 GtkTreePath *source_row)
5948 g_object_set_data_full (G_OBJECT (context),
5949 I_("gtk-icon-view-source-row"),
5950 gtk_tree_row_reference_new (model, source_row),
5951 (GDestroyNotify) gtk_tree_row_reference_free);
5953 g_object_set_data_full (G_OBJECT (context),
5954 I_("gtk-icon-view-source-row"),
5959 get_source_row (GdkDragContext *context)
5961 GtkTreeRowReference *ref;
5963 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5966 return gtk_tree_row_reference_get_path (ref);
5973 GtkTreeRowReference *dest_row;
5974 gboolean empty_view_drop;
5975 gboolean drop_append_mode;
5979 dest_row_free (gpointer data)
5981 DestRow *dr = (DestRow *)data;
5983 gtk_tree_row_reference_free (dr->dest_row);
5988 set_dest_row (GdkDragContext *context,
5989 GtkTreeModel *model,
5990 GtkTreePath *dest_row,
5991 gboolean empty_view_drop,
5992 gboolean drop_append_mode)
5998 g_object_set_data_full (G_OBJECT (context),
5999 I_("gtk-icon-view-dest-row"),
6004 dr = g_new0 (DestRow, 1);
6006 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6007 dr->empty_view_drop = empty_view_drop;
6008 dr->drop_append_mode = drop_append_mode;
6009 g_object_set_data_full (G_OBJECT (context),
6010 I_("gtk-icon-view-dest-row"),
6011 dr, (GDestroyNotify) dest_row_free);
6015 get_dest_row (GdkDragContext *context)
6019 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6023 GtkTreePath *path = NULL;
6026 path = gtk_tree_row_reference_get_path (dr->dest_row);
6027 else if (dr->empty_view_drop)
6028 path = gtk_tree_path_new_from_indices (0, -1);
6032 if (path && dr->drop_append_mode)
6033 gtk_tree_path_next (path);
6042 check_model_dnd (GtkTreeModel *model,
6043 GType required_iface,
6044 const gchar *signal)
6046 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6048 g_warning ("You must override the default '%s' handler "
6049 "on GtkIconView when using models that don't support "
6050 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6051 "is to connect to '%s' and call "
6052 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6053 "the default handler from running. Look at the source code "
6054 "for the default handler in gtkiconview.c to get an idea what "
6055 "your handler should do. (gtkiconview.c is in the GTK+ source "
6056 "code.) If you're using GTK+ from a language other than C, "
6057 "there may be a more natural way to override default handlers, e.g. via derivation.",
6058 signal, g_type_name (required_iface), signal);
6066 remove_scroll_timeout (GtkIconView *icon_view)
6068 if (icon_view->priv->scroll_timeout_id != 0)
6070 g_source_remove (icon_view->priv->scroll_timeout_id);
6072 icon_view->priv->scroll_timeout_id = 0;
6077 gtk_icon_view_autoscroll (GtkIconView *icon_view,
6081 gint px, py, x, y, width, height;
6082 gint hoffset, voffset;
6084 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6086 gdk_window_get_device_position (window, device, &px, &py, NULL);
6087 gdk_window_get_geometry (window, &x, &y, &width, &height);
6089 /* see if we are near the edge. */
6090 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6092 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6094 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6096 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6099 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6100 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6103 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6104 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6108 GtkIconView *icon_view;
6113 drag_scroll_timeout (gpointer datap)
6115 DragScrollData *data = datap;
6117 gtk_icon_view_autoscroll (data->icon_view, data->device);
6124 set_destination (GtkIconView *icon_view,
6125 GdkDragContext *context,
6128 GdkDragAction *suggested_action,
6132 GtkTreePath *path = NULL;
6133 GtkIconViewDropPosition pos;
6134 GtkIconViewDropPosition old_pos;
6135 GtkTreePath *old_dest_path = NULL;
6136 gboolean can_drop = FALSE;
6138 widget = GTK_WIDGET (icon_view);
6140 *suggested_action = 0;
6143 if (!icon_view->priv->dest_set)
6145 /* someone unset us as a drag dest, note that if
6146 * we return FALSE drag_leave isn't called
6149 gtk_icon_view_set_drag_dest_item (icon_view,
6151 GTK_ICON_VIEW_DROP_LEFT);
6153 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6155 return FALSE; /* no longer a drop site */
6158 *target = gtk_drag_dest_find_target (widget, context,
6159 gtk_drag_dest_get_target_list (widget));
6160 if (*target == GDK_NONE)
6163 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6166 GtkTreeModel *model;
6168 /* the row got dropped on empty space, let's setup a special case
6172 gtk_tree_path_free (path);
6174 model = gtk_icon_view_get_model (icon_view);
6176 n_children = gtk_tree_model_iter_n_children (model, NULL);
6179 pos = GTK_ICON_VIEW_DROP_BELOW;
6180 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6184 pos = GTK_ICON_VIEW_DROP_ABOVE;
6185 path = gtk_tree_path_new_from_indices (0, -1);
6195 gtk_icon_view_get_drag_dest_item (icon_view,
6200 gtk_tree_path_free (old_dest_path);
6202 if (TRUE /* FIXME if the location droppable predicate */)
6210 GtkWidget *source_widget;
6212 *suggested_action = gdk_drag_context_get_suggested_action (context);
6213 source_widget = gtk_drag_get_source_widget (context);
6215 if (source_widget == widget)
6217 /* Default to MOVE, unless the user has
6218 * pressed ctrl or shift to affect available actions
6220 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6221 *suggested_action = GDK_ACTION_MOVE;
6224 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6229 /* can't drop here */
6230 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6232 GTK_ICON_VIEW_DROP_LEFT);
6236 gtk_tree_path_free (path);
6242 get_logical_destination (GtkIconView *icon_view,
6243 gboolean *drop_append_mode)
6245 /* adjust path to point to the row the drop goes in front of */
6246 GtkTreePath *path = NULL;
6247 GtkIconViewDropPosition pos;
6249 *drop_append_mode = FALSE;
6251 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6256 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6257 pos == GTK_ICON_VIEW_DROP_BELOW)
6260 GtkTreeModel *model = icon_view->priv->model;
6262 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6263 !gtk_tree_model_iter_next (model, &iter))
6264 *drop_append_mode = TRUE;
6267 *drop_append_mode = FALSE;
6268 gtk_tree_path_next (path);
6276 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6277 GdkEventMotion *event)
6279 GtkWidget *widget = GTK_WIDGET (icon_view);
6280 GdkDragContext *context;
6281 GtkTreePath *path = NULL;
6283 GtkTreeModel *model;
6284 gboolean retval = FALSE;
6286 if (!icon_view->priv->source_set)
6289 if (icon_view->priv->pressed_button < 0)
6292 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6293 icon_view->priv->press_start_x,
6294 icon_view->priv->press_start_y,
6295 event->x, event->y))
6298 model = gtk_icon_view_get_model (icon_view);
6303 button = icon_view->priv->pressed_button;
6304 icon_view->priv->pressed_button = -1;
6306 path = gtk_icon_view_get_path_at_pos (icon_view,
6307 icon_view->priv->press_start_x,
6308 icon_view->priv->press_start_y);
6313 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6314 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6318 /* FIXME Check whether we're a start button, if not return FALSE and
6322 /* Now we can begin the drag */
6326 context = gtk_drag_begin (widget,
6327 gtk_drag_source_get_target_list (widget),
6328 icon_view->priv->source_actions,
6332 set_source_row (context, model, path);
6336 gtk_tree_path_free (path);
6341 /* Source side drag signals */
6343 gtk_icon_view_drag_begin (GtkWidget *widget,
6344 GdkDragContext *context)
6346 GtkIconView *icon_view;
6347 GtkIconViewItem *item;
6348 cairo_surface_t *icon;
6352 icon_view = GTK_ICON_VIEW (widget);
6354 /* if the user uses a custom DnD impl, we don't set the icon here */
6355 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6358 item = gtk_icon_view_get_item_at_coords (icon_view,
6359 icon_view->priv->press_start_x,
6360 icon_view->priv->press_start_y,
6364 g_return_if_fail (item != NULL);
6366 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6367 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6369 path = gtk_tree_path_new_from_indices (item->index, -1);
6370 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6371 gtk_tree_path_free (path);
6373 cairo_surface_set_device_offset (icon, -x, -y);
6375 gtk_drag_set_icon_surface (context, icon);
6377 cairo_surface_destroy (icon);
6381 gtk_icon_view_drag_end (GtkWidget *widget,
6382 GdkDragContext *context)
6388 gtk_icon_view_drag_data_get (GtkWidget *widget,
6389 GdkDragContext *context,
6390 GtkSelectionData *selection_data,
6394 GtkIconView *icon_view;
6395 GtkTreeModel *model;
6396 GtkTreePath *source_row;
6398 icon_view = GTK_ICON_VIEW (widget);
6399 model = gtk_icon_view_get_model (icon_view);
6404 if (!icon_view->priv->source_set)
6407 source_row = get_source_row (context);
6409 if (source_row == NULL)
6412 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6413 * any model; for DragSource models there are some other targets
6417 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6418 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6423 /* If drag_data_get does nothing, try providing row data. */
6424 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6425 gtk_tree_set_row_drag_data (selection_data,
6430 gtk_tree_path_free (source_row);
6434 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6435 GdkDragContext *context)
6437 GtkTreeModel *model;
6438 GtkIconView *icon_view;
6439 GtkTreePath *source_row;
6441 icon_view = GTK_ICON_VIEW (widget);
6442 model = gtk_icon_view_get_model (icon_view);
6444 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6447 if (!icon_view->priv->source_set)
6450 source_row = get_source_row (context);
6452 if (source_row == NULL)
6455 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6458 gtk_tree_path_free (source_row);
6460 set_source_row (context, NULL, NULL);
6463 /* Target side drag signals */
6465 gtk_icon_view_drag_leave (GtkWidget *widget,
6466 GdkDragContext *context,
6469 GtkIconView *icon_view;
6471 icon_view = GTK_ICON_VIEW (widget);
6473 /* unset any highlight row */
6474 gtk_icon_view_set_drag_dest_item (icon_view,
6476 GTK_ICON_VIEW_DROP_LEFT);
6478 remove_scroll_timeout (icon_view);
6482 gtk_icon_view_drag_motion (GtkWidget *widget,
6483 GdkDragContext *context,
6488 GtkTreePath *path = NULL;
6489 GtkIconViewDropPosition pos;
6490 GtkIconView *icon_view;
6491 GdkDragAction suggested_action = 0;
6495 icon_view = GTK_ICON_VIEW (widget);
6497 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6500 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6502 /* we only know this *after* set_desination_row */
6503 empty = icon_view->priv->empty_view_drop;
6505 if (path == NULL && !empty)
6507 /* Can't drop here. */
6508 gdk_drag_status (context, 0, time);
6512 if (icon_view->priv->scroll_timeout_id == 0)
6514 DragScrollData *data = g_slice_new (DragScrollData);
6515 data->icon_view = icon_view;
6516 data->device = gdk_drag_context_get_device (context);
6518 icon_view->priv->scroll_timeout_id =
6519 gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT, 50, drag_scroll_timeout, data, g_free);
6522 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6524 /* Request data so we can use the source row when
6525 * determining whether to accept the drop
6527 set_status_pending (context, suggested_action);
6528 gtk_drag_get_data (widget, context, target, time);
6532 set_status_pending (context, 0);
6533 gdk_drag_status (context, suggested_action, time);
6538 gtk_tree_path_free (path);
6544 gtk_icon_view_drag_drop (GtkWidget *widget,
6545 GdkDragContext *context,
6550 GtkIconView *icon_view;
6552 GdkDragAction suggested_action = 0;
6553 GdkAtom target = GDK_NONE;
6554 GtkTreeModel *model;
6555 gboolean drop_append_mode;
6557 icon_view = GTK_ICON_VIEW (widget);
6558 model = gtk_icon_view_get_model (icon_view);
6560 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6562 if (!icon_view->priv->dest_set)
6565 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6568 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6571 path = get_logical_destination (icon_view, &drop_append_mode);
6573 if (target != GDK_NONE && path != NULL)
6575 /* in case a motion had requested drag data, change things so we
6576 * treat drag data receives as a drop.
6578 set_status_pending (context, 0);
6579 set_dest_row (context, model, path,
6580 icon_view->priv->empty_view_drop, drop_append_mode);
6584 gtk_tree_path_free (path);
6586 /* Unset this thing */
6587 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6589 if (target != GDK_NONE)
6591 gtk_drag_get_data (widget, context, target, time);
6599 gtk_icon_view_drag_data_received (GtkWidget *widget,
6600 GdkDragContext *context,
6603 GtkSelectionData *selection_data,
6608 gboolean accepted = FALSE;
6609 GtkTreeModel *model;
6610 GtkIconView *icon_view;
6611 GtkTreePath *dest_row;
6612 GdkDragAction suggested_action;
6613 gboolean drop_append_mode;
6615 icon_view = GTK_ICON_VIEW (widget);
6616 model = gtk_icon_view_get_model (icon_view);
6618 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6621 if (!icon_view->priv->dest_set)
6624 suggested_action = get_status_pending (context);
6626 if (suggested_action)
6628 /* We are getting this data due to a request in drag_motion,
6629 * rather than due to a request in drag_drop, so we are just
6630 * supposed to call drag_status, not actually paste in the
6633 path = get_logical_destination (icon_view, &drop_append_mode);
6636 suggested_action = 0;
6638 if (suggested_action)
6640 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6643 suggested_action = 0;
6646 gdk_drag_status (context, suggested_action, time);
6649 gtk_tree_path_free (path);
6651 /* If you can't drop, remove user drop indicator until the next motion */
6652 if (suggested_action == 0)
6653 gtk_icon_view_set_drag_dest_item (icon_view,
6655 GTK_ICON_VIEW_DROP_LEFT);
6660 dest_row = get_dest_row (context);
6662 if (dest_row == NULL)
6665 if (gtk_selection_data_get_length (selection_data) >= 0)
6667 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6673 gtk_drag_finish (context,
6675 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6678 gtk_tree_path_free (dest_row);
6681 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6684 /* Drag-and-Drop support */
6686 * gtk_icon_view_enable_model_drag_source:
6687 * @icon_view: a #GtkIconTreeView
6688 * @start_button_mask: Mask of allowed buttons to start drag
6689 * @targets: (array length=n_targets): the table of targets that the drag will
6691 * @n_targets: the number of items in @targets
6692 * @actions: the bitmask of possible actions for a drag from this
6695 * Turns @icon_view into a drag source for automatic DND. Calling this
6696 * method sets #GtkIconView:reorderable to %FALSE.
6701 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6702 GdkModifierType start_button_mask,
6703 const GtkTargetEntry *targets,
6705 GdkDragAction actions)
6707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6709 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6711 icon_view->priv->start_button_mask = start_button_mask;
6712 icon_view->priv->source_actions = actions;
6714 icon_view->priv->source_set = TRUE;
6716 unset_reorderable (icon_view);
6720 * gtk_icon_view_enable_model_drag_dest:
6721 * @icon_view: a #GtkIconView
6722 * @targets: (array length=n_targets): the table of targets that the drag will
6724 * @n_targets: the number of items in @targets
6725 * @actions: the bitmask of possible actions for a drag to this
6728 * Turns @icon_view into a drop destination for automatic DND. Calling this
6729 * method sets #GtkIconView:reorderable to %FALSE.
6734 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6735 const GtkTargetEntry *targets,
6737 GdkDragAction actions)
6739 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6741 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6743 icon_view->priv->dest_actions = actions;
6745 icon_view->priv->dest_set = TRUE;
6747 unset_reorderable (icon_view);
6751 * gtk_icon_view_unset_model_drag_source:
6752 * @icon_view: a #GtkIconView
6754 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6755 * method sets #GtkIconView:reorderable to %FALSE.
6760 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6762 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6764 if (icon_view->priv->source_set)
6766 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6767 icon_view->priv->source_set = FALSE;
6770 unset_reorderable (icon_view);
6774 * gtk_icon_view_unset_model_drag_dest:
6775 * @icon_view: a #GtkIconView
6777 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6778 * method sets #GtkIconView:reorderable to %FALSE.
6783 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6785 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6787 if (icon_view->priv->dest_set)
6789 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6790 icon_view->priv->dest_set = FALSE;
6793 unset_reorderable (icon_view);
6796 /* These are useful to implement your own custom stuff. */
6798 * gtk_icon_view_set_drag_dest_item:
6799 * @icon_view: a #GtkIconView
6800 * @path: (allow-none): The path of the item to highlight, or %NULL.
6801 * @pos: Specifies where to drop, relative to the item
6803 * Sets the item that is highlighted for feedback.
6808 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6810 GtkIconViewDropPosition pos)
6812 /* Note; this function is exported to allow a custom DND
6813 * implementation, so it can't touch TreeViewDragInfo
6816 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6818 if (icon_view->priv->dest_item)
6820 GtkTreePath *current_path;
6821 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6822 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6823 icon_view->priv->dest_item = NULL;
6825 gtk_icon_view_queue_draw_path (icon_view, current_path);
6826 gtk_tree_path_free (current_path);
6829 /* special case a drop on an empty model */
6830 icon_view->priv->empty_view_drop = FALSE;
6831 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6832 && gtk_tree_path_get_depth (path) == 1
6833 && gtk_tree_path_get_indices (path)[0] == 0)
6837 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6840 if (n_children == 0)
6841 icon_view->priv->empty_view_drop = TRUE;
6844 icon_view->priv->dest_pos = pos;
6848 icon_view->priv->dest_item =
6849 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6850 icon_view->priv->model, path);
6852 gtk_icon_view_queue_draw_path (icon_view, path);
6857 * gtk_icon_view_get_drag_dest_item:
6858 * @icon_view: a #GtkIconView
6859 * @path: (out) (allow-none): Return location for the path of
6860 * the highlighted item, or %NULL.
6861 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6863 * Gets information about the item that is highlighted for feedback.
6868 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6870 GtkIconViewDropPosition *pos)
6872 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6876 if (icon_view->priv->dest_item)
6877 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6883 *pos = icon_view->priv->dest_pos;
6887 * gtk_icon_view_get_dest_item_at_pos:
6888 * @icon_view: a #GtkIconView
6889 * @drag_x: the position to determine the destination item for
6890 * @drag_y: the position to determine the destination item for
6891 * @path: (out) (allow-none): Return location for the path of the item,
6893 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6895 * Determines the destination item for a given position.
6897 * Return value: whether there is an item at the given position.
6902 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6906 GtkIconViewDropPosition *pos)
6908 GtkIconViewItem *item;
6910 /* Note; this function is exported to allow a custom DND
6911 * implementation, so it can't touch TreeViewDragInfo
6914 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6915 g_return_val_if_fail (drag_x >= 0, FALSE);
6916 g_return_val_if_fail (drag_y >= 0, FALSE);
6917 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6923 item = gtk_icon_view_get_item_at_coords (icon_view,
6924 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6925 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6932 *path = gtk_tree_path_new_from_indices (item->index, -1);
6936 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6937 *pos = GTK_ICON_VIEW_DROP_LEFT;
6938 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6939 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6940 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6941 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6942 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6943 *pos = GTK_ICON_VIEW_DROP_BELOW;
6945 *pos = GTK_ICON_VIEW_DROP_INTO;
6952 * gtk_icon_view_create_drag_icon:
6953 * @icon_view: a #GtkIconView
6954 * @path: a #GtkTreePath in @icon_view
6956 * Creates a #cairo_surface_t representation of the item at @path.
6957 * This image is used for a drag icon.
6959 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6964 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6968 GtkStyleContext *context;
6970 cairo_surface_t *surface;
6974 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6975 g_return_val_if_fail (path != NULL, NULL);
6977 widget = GTK_WIDGET (icon_view);
6978 context = gtk_widget_get_style_context (widget);
6980 if (!gtk_widget_get_realized (widget))
6983 index = gtk_tree_path_get_indices (path)[0];
6985 for (l = icon_view->priv->items; l; l = l->next)
6987 GtkIconViewItem *item = l->data;
6989 if (index == item->index)
6991 GdkRectangle rect = {
6992 item->cell_area.x - icon_view->priv->item_padding,
6993 item->cell_area.y - icon_view->priv->item_padding,
6994 item->cell_area.width + icon_view->priv->item_padding * 2,
6995 item->cell_area.height + icon_view->priv->item_padding * 2
6998 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6999 CAIRO_CONTENT_COLOR,
7003 cr = cairo_create (surface);
7004 cairo_set_line_width (cr, 1.);
7006 gtk_render_background (context, cr, 0, 0,
7007 rect.width + 2, rect.height + 2);
7011 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
7014 gtk_icon_view_paint_item (icon_view, cr, item,
7015 icon_view->priv->item_padding + 1,
7016 icon_view->priv->item_padding + 1, FALSE);
7020 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7021 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7034 * gtk_icon_view_get_reorderable:
7035 * @icon_view: a #GtkIconView
7037 * Retrieves whether the user can reorder the list via drag-and-drop.
7038 * See gtk_icon_view_set_reorderable().
7040 * Return value: %TRUE if the list can be reordered.
7045 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7047 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7049 return icon_view->priv->reorderable;
7052 static const GtkTargetEntry item_targets[] = {
7053 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7058 * gtk_icon_view_set_reorderable:
7059 * @icon_view: A #GtkIconView.
7060 * @reorderable: %TRUE, if the list of items can be reordered.
7062 * This function is a convenience function to allow you to reorder models that
7063 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7064 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7065 * the user can reorder the model by dragging and dropping rows. The
7066 * developer can listen to these changes by connecting to the model's
7067 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7068 * the icon view as a drag source and destination. Therefore, drag and
7069 * drop can not be used in a reorderable view for any other purpose.
7071 * This function does not give you any degree of control over the order -- any
7072 * reordering is allowed. If more control is needed, you should probably
7073 * handle drag and drop manually.
7078 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7079 gboolean reorderable)
7081 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7083 reorderable = reorderable != FALSE;
7085 if (icon_view->priv->reorderable == reorderable)
7090 gtk_icon_view_enable_model_drag_source (icon_view,
7093 G_N_ELEMENTS (item_targets),
7095 gtk_icon_view_enable_model_drag_dest (icon_view,
7097 G_N_ELEMENTS (item_targets),
7102 gtk_icon_view_unset_model_drag_source (icon_view);
7103 gtk_icon_view_unset_model_drag_dest (icon_view);
7106 icon_view->priv->reorderable = reorderable;
7108 g_object_notify (G_OBJECT (icon_view), "reorderable");
7112 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7113 GtkBuilder *builder,
7115 const gchar *tagname,
7116 GMarkupParser *parser,
7119 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7120 tagname, parser, data))
7123 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7124 tagname, parser, data);
7128 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7129 GtkBuilder *builder,
7131 const gchar *tagname,
7134 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7135 child, tagname, data))
7136 parent_buildable_iface->custom_tag_end (buildable, builder,
7137 child, tagname, data);
7140 /* Accessibility Support */
7142 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (_gtk_icon_view_item_accessible_get_type ())
7143 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7144 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7150 GtkIconViewItem *item;
7152 AtkStateSet *state_set;
7154 gchar *action_description;
7155 gchar *image_description;
7156 guint action_idle_handler;
7157 } GtkIconViewItemAccessible;
7161 AtkObjectClass parent_class;
7163 } GtkIconViewItemAccessibleClass;
7165 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7167 static void atk_component_item_interface_init (AtkComponentIface *iface);
7168 static void atk_action_item_interface_init (AtkActionIface *iface);
7169 static void atk_text_item_interface_init (AtkTextIface *iface);
7170 static void atk_image_item_interface_init (AtkImageIface *iface);
7172 G_DEFINE_TYPE_WITH_CODE (GtkIconViewItemAccessible, _gtk_icon_view_item_accessible, ATK_TYPE_OBJECT,
7173 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_item_interface_init)
7174 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_item_interface_init)
7175 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_item_interface_init)
7176 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_item_interface_init))
7180 idle_do_action (gpointer data)
7182 GtkIconViewItemAccessible *item;
7183 GtkIconView *icon_view;
7186 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7187 item->action_idle_handler = 0;
7189 if (item->widget != NULL)
7191 icon_view = GTK_ICON_VIEW (item->widget);
7192 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7193 gtk_icon_view_item_activated (icon_view, path);
7194 gtk_tree_path_free (path);
7201 gtk_icon_view_item_accessible_do_action (AtkAction *action,
7204 GtkIconViewItemAccessible *item;
7209 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7211 if (!GTK_IS_ICON_VIEW (item->widget))
7214 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7217 if (!item->action_idle_handler)
7218 item->action_idle_handler = gdk_threads_add_idle (idle_do_action, item);
7224 gtk_icon_view_item_accessible_get_n_actions (AtkAction *action)
7229 static const gchar *
7230 gtk_icon_view_item_accessible_get_description (AtkAction *action,
7233 GtkIconViewItemAccessible *item;
7238 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7240 if (item->action_description)
7241 return item->action_description;
7243 return "Activate item";
7246 static const gchar *
7247 gtk_icon_view_item_accessible_get_name (AtkAction *action,
7257 gtk_icon_view_item_accessible_set_description (AtkAction *action,
7259 const gchar *description)
7261 GtkIconViewItemAccessible *item;
7266 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7268 g_free (item->action_description);
7269 item->action_description = g_strdup (description);
7275 atk_action_item_interface_init (AtkActionIface *iface)
7277 iface->do_action = gtk_icon_view_item_accessible_do_action;
7278 iface->set_description = gtk_icon_view_item_accessible_set_description;
7279 iface->get_name = gtk_icon_view_item_accessible_get_name;
7280 iface->get_n_actions = gtk_icon_view_item_accessible_get_n_actions;
7281 iface->get_description = gtk_icon_view_item_accessible_get_description;
7284 static const gchar *
7285 gtk_icon_view_item_accessible_get_image_description (AtkImage *image)
7287 GtkIconViewItemAccessible *item;
7289 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7291 return item->image_description;
7295 gtk_icon_view_item_accessible_set_image_description (AtkImage *image,
7296 const gchar *description)
7298 GtkIconViewItemAccessible *item;
7300 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7302 g_free (item->image_description);
7303 item->image_description = g_strdup (description);
7310 gboolean pixbuf_found;
7314 get_pixbuf_foreach (GtkCellRenderer *renderer,
7315 const GdkRectangle *cell_area,
7316 const GdkRectangle *cell_background,
7317 GetPixbufBoxData *data)
7319 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7321 data->box = *cell_area;
7322 data->pixbuf_found = TRUE;
7324 return (data->pixbuf_found != FALSE);
7328 get_pixbuf_box (GtkIconView *icon_view,
7329 GtkIconViewItem *item,
7332 GetPixbufBoxData data = { { 0, }, FALSE };
7333 GtkCellAreaContext *context;
7335 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7337 gtk_icon_view_set_cell_data (icon_view, item);
7338 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7339 GTK_WIDGET (icon_view),
7340 (GdkRectangle *)item, (GdkRectangle *)item,
7341 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7343 return data.pixbuf_found;
7347 get_text_foreach (GtkCellRenderer *renderer,
7350 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7352 g_object_get (renderer, "text", text, NULL);
7359 get_text (GtkIconView *icon_view,
7360 GtkIconViewItem *item)
7364 gtk_icon_view_set_cell_data (icon_view, item);
7365 gtk_cell_area_foreach (icon_view->priv->cell_area,
7366 (GtkCellCallback)get_text_foreach, &text);
7372 gtk_icon_view_item_accessible_get_image_size (AtkImage *image,
7376 GtkIconViewItemAccessible *item;
7379 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7381 if (!GTK_IS_ICON_VIEW (item->widget))
7384 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7390 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7393 *height = box.height;
7398 gtk_icon_view_item_accessible_get_image_position (AtkImage *image,
7401 AtkCoordType coord_type)
7403 GtkIconViewItemAccessible *item;
7406 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7408 if (!GTK_IS_ICON_VIEW (item->widget))
7411 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7414 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7416 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7418 *x+= box.x - item->item->cell_area.x;
7419 *y+= box.y - item->item->cell_area.y;
7425 atk_image_item_interface_init (AtkImageIface *iface)
7427 iface->get_image_description = gtk_icon_view_item_accessible_get_image_description;
7428 iface->set_image_description = gtk_icon_view_item_accessible_set_image_description;
7429 iface->get_image_size = gtk_icon_view_item_accessible_get_image_size;
7430 iface->get_image_position = gtk_icon_view_item_accessible_get_image_position;
7434 gtk_icon_view_item_accessible_get_text (AtkText *text,
7438 GtkIconViewItemAccessible *item;
7440 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7441 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7445 return g_utf8_substring (item->text, start_pos, end_pos > -1 ? end_pos : g_utf8_strlen (item->text, -1));
7447 return g_strdup ("");
7451 gtk_icon_view_item_accessible_get_character_at_offset (AtkText *text,
7454 GtkIconViewItemAccessible *item;
7458 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7459 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7462 string = item->text;
7467 if (offset >= g_utf8_strlen (string, -1))
7470 index = g_utf8_offset_to_pointer (string, offset);
7472 return g_utf8_get_char (index);
7475 static PangoLayout *
7476 create_pango_layout (GtkIconViewItemAccessible *item)
7478 PangoLayout *layout;
7480 layout = gtk_widget_create_pango_layout (item->widget, item->text);
7486 gtk_icon_view_item_accessible_get_text_before_offset (AtkText *atk_text,
7488 AtkTextBoundary boundary_type,
7492 GtkIconViewItemAccessible *item;
7493 PangoLayout *layout;
7496 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7497 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7500 layout = create_pango_layout (item);
7501 text = _gtk_pango_get_text_before (layout, boundary_type, offset, start_offset, end_offset);
7502 g_object_unref (layout);
7508 gtk_icon_view_item_accessible_get_text_at_offset (AtkText *atk_text,
7510 AtkTextBoundary boundary_type,
7514 GtkIconViewItemAccessible *item;
7515 PangoLayout *layout;
7518 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7519 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7522 layout = create_pango_layout (item);
7523 text = _gtk_pango_get_text_at (layout, boundary_type, offset, start_offset, end_offset);
7524 g_object_unref (layout);
7530 gtk_icon_view_item_accessible_get_text_after_offset (AtkText *atk_text,
7532 AtkTextBoundary boundary_type,
7536 GtkIconViewItemAccessible *item;
7537 PangoLayout *layout;
7540 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7541 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7544 layout = create_pango_layout (item);
7545 text = _gtk_pango_get_text_after (layout, boundary_type, offset, start_offset, end_offset);
7546 g_object_unref (layout);
7552 gtk_icon_view_item_accessible_get_character_count (AtkText *text)
7554 GtkIconViewItemAccessible *item;
7556 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7557 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7561 return g_utf8_strlen (item->text, -1);
7567 gtk_icon_view_item_accessible_get_character_extents (AtkText *text,
7573 AtkCoordType coord_type)
7575 GtkIconViewItemAccessible *item;
7577 GtkIconView *icon_view;
7578 PangoRectangle char_rect;
7579 const gchar *item_text;
7583 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7585 if (!GTK_IS_ICON_VIEW (item->widget))
7588 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7592 icon_view = GTK_ICON_VIEW (item->widget);
7593 /* FIXME we probably have to use GailTextCell to salvage this */
7594 gtk_icon_view_update_item_text (icon_view, item->item);
7595 item_text = pango_layout_get_text (icon_view->priv->layout);
7596 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7597 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7599 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7600 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7601 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7602 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7603 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7604 *width = char_rect.width / PANGO_SCALE;
7605 *height = char_rect.height / PANGO_SCALE;
7610 gtk_icon_view_item_accessible_get_offset_at_point (AtkText *text,
7613 AtkCoordType coord_type)
7615 GtkIconViewItemAccessible *item;
7618 GtkIconView *icon_view;
7619 const gchar *item_text;
7624 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7626 if (!GTK_IS_ICON_VIEW (item->widget))
7629 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7633 icon_view = GTK_ICON_VIEW (item->widget);
7634 /* FIXME we probably have to use GailTextCell to salvage this */
7635 gtk_icon_view_update_item_text (icon_view, item->item);
7636 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7637 x -= l_x + item->item->layout_x - item->item->x;
7638 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7639 y -= l_y + item->item->layout_y - item->item->y;
7640 item_text = pango_layout_get_text (icon_view->priv->layout);
7641 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7652 offset = g_utf8_strlen (item_text, -1);
7654 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7660 atk_text_item_interface_init (AtkTextIface *iface)
7662 iface->get_text = gtk_icon_view_item_accessible_get_text;
7663 iface->get_character_at_offset = gtk_icon_view_item_accessible_get_character_at_offset;
7664 iface->get_text_before_offset = gtk_icon_view_item_accessible_get_text_before_offset;
7665 iface->get_text_at_offset = gtk_icon_view_item_accessible_get_text_at_offset;
7666 iface->get_text_after_offset = gtk_icon_view_item_accessible_get_text_after_offset;
7667 iface->get_character_count = gtk_icon_view_item_accessible_get_character_count;
7668 iface->get_character_extents = gtk_icon_view_item_accessible_get_character_extents;
7669 iface->get_offset_at_point = gtk_icon_view_item_accessible_get_offset_at_point;
7673 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7678 AtkCoordType coord_type)
7680 GtkIconViewItemAccessible *item;
7681 AtkObject *parent_obj;
7684 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7686 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7687 if (!GTK_IS_WIDGET (item->widget))
7690 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7693 *width = item->item->cell_area.width;
7694 *height = item->item->cell_area.height;
7695 if (gtk_icon_view_item_accessible_is_showing (item))
7697 parent_obj = gtk_widget_get_accessible (item->widget);
7698 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7699 *x = l_x + item->item->cell_area.x;
7700 *y = l_y + item->item->cell_area.y;
7710 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7712 GtkIconViewItemAccessible *item;
7713 GtkWidget *toplevel;
7715 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7717 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7718 if (!GTK_IS_WIDGET (item->widget))
7721 gtk_widget_grab_focus (item->widget);
7722 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7723 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7724 if (gtk_widget_is_toplevel (toplevel))
7725 gtk_window_present (GTK_WINDOW (toplevel));
7731 atk_component_item_interface_init (AtkComponentIface *iface)
7733 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7734 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7738 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7739 AtkStateType state_type,
7740 gboolean emit_signal)
7744 rc = atk_state_set_add_state (item->state_set, state_type);
7746 /* The signal should only be generated if the value changed,
7747 * not when the item is set up. So states that are set
7748 * initially should pass FALSE as the emit_signal argument.
7752 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7753 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7754 if (state_type == ATK_STATE_VISIBLE)
7755 g_signal_emit_by_name (item, "visible-data-changed");
7762 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7763 AtkStateType state_type,
7764 gboolean emit_signal)
7766 if (atk_state_set_contains_state (item->state_set, state_type))
7770 rc = atk_state_set_remove_state (item->state_set, state_type);
7772 /* The signal should only be generated if the value changed,
7773 * not when the item is set up. So states that are set
7774 * initially should pass FALSE as the emit_signal argument.
7778 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7779 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7780 if (state_type == ATK_STATE_VISIBLE)
7781 g_signal_emit_by_name (item, "visible-data-changed");
7791 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7793 GtkAllocation allocation;
7794 GtkIconView *icon_view;
7795 GdkRectangle visible_rect;
7796 gboolean is_showing;
7798 /* An item is considered "SHOWING" if any part of the item
7799 * is in the visible rectangle.
7801 if (!GTK_IS_ICON_VIEW (item->widget))
7804 if (item->item == NULL)
7807 gtk_widget_get_allocation (item->widget, &allocation);
7809 icon_view = GTK_ICON_VIEW (item->widget);
7811 if (icon_view->priv->hadjustment)
7812 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
7814 if (icon_view->priv->hadjustment)
7815 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
7816 visible_rect.width = allocation.width;
7817 visible_rect.height = allocation.height;
7819 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
7820 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
7821 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
7822 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
7831 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7832 gboolean emit_signal)
7834 if (gtk_icon_view_item_accessible_is_showing (item))
7835 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7838 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7843 _gtk_icon_view_item_accessible_init (GtkIconViewItemAccessible *item)
7845 item->state_set = atk_state_set_new ();
7847 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7848 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7849 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7850 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7851 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7853 item->action_description = NULL;
7854 item->image_description = NULL;
7856 item->action_idle_handler = 0;
7860 gtk_icon_view_item_accessible_finalize (GObject *object)
7862 GtkIconViewItemAccessible *item;
7864 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7867 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7869 if (item->state_set)
7870 g_object_unref (item->state_set);
7873 g_free (item->text);
7874 g_free (item->action_description);
7875 g_free (item->image_description);
7877 if (item->action_idle_handler)
7879 g_source_remove (item->action_idle_handler);
7880 item->action_idle_handler = 0;
7883 G_OBJECT_CLASS (_gtk_icon_view_item_accessible_parent_class)->finalize (object);
7887 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7889 GtkIconViewItemAccessible *item;
7891 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7892 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7895 return gtk_widget_get_accessible (item->widget);
7901 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7903 GtkIconViewItemAccessible *item;
7905 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7906 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7908 return item->item->index;
7911 static AtkStateSet *
7912 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7914 GtkIconViewItemAccessible *item;
7915 GtkIconView *icon_view;
7917 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7918 g_return_val_if_fail (item->state_set, NULL);
7923 icon_view = GTK_ICON_VIEW (item->widget);
7924 if (icon_view->priv->cursor_item == item->item)
7925 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7927 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7928 if (item->item->selected)
7929 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
7931 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
7933 return g_object_ref (item->state_set);
7937 _gtk_icon_view_item_accessible_class_init (GtkIconViewItemAccessibleClass *klass)
7939 GObjectClass *gobject_class;
7940 AtkObjectClass *atk_class;
7942 gobject_class = (GObjectClass *)klass;
7943 atk_class = (AtkObjectClass *)klass;
7945 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7947 atk_class->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7948 atk_class->get_parent = gtk_icon_view_item_accessible_get_parent;
7949 atk_class->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7952 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (_gtk_icon_view_accessible_get_type ())
7953 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
7954 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
7958 GtkContainerAccessible parent;
7961 GtkAdjustment *old_hadj;
7962 GtkAdjustment *old_vadj;
7963 GtkTreeModel *model;
7964 } GtkIconViewAccessible;
7966 typedef GtkContainerAccessibleClass GtkIconViewAccessibleClass;
7968 static void atk_component_interface_init (AtkComponentIface *iface);
7969 static void atk_selection_interface_init (AtkSelectionIface *iface);
7971 G_DEFINE_TYPE_WITH_CODE (GtkIconViewAccessible, _gtk_icon_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
7972 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
7973 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
7979 } GtkIconViewItemAccessibleInfo;
7983 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
7987 GtkIconViewAccessible *view = (GtkIconViewAccessible *)accessible;
7988 GtkIconViewItemAccessibleInfo *info;
7989 GtkIconViewItemAccessibleInfo *tmp_info;
7992 info = g_new (GtkIconViewItemAccessibleInfo, 1);
7994 info->index = index;
7996 items = view->items;
7999 tmp_info = items->data;
8000 if (tmp_info->index > index)
8002 items = items->next;
8004 view->items = g_list_insert_before (view->items, items, info);
8005 view->old_hadj = NULL;
8006 view->old_vadj = NULL;
8010 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8012 GtkIconView *icon_view;
8015 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8019 icon_view = GTK_ICON_VIEW (widget);
8021 return g_list_length (icon_view->priv->items);
8025 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8028 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
8029 GtkIconViewItemAccessibleInfo *info;
8032 items = view->items;
8037 if (info->index == index)
8039 items = items->next;
8046 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8049 GtkIconView *icon_view;
8053 GtkIconViewItemAccessible *a11y_item;
8055 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8059 icon_view = GTK_ICON_VIEW (widget);
8060 icons = g_list_nth (icon_view->priv->items, index);
8064 GtkIconViewItem *item = icons->data;
8066 g_return_val_if_fail (item->index == index, NULL);
8067 obj = gtk_icon_view_accessible_find_child (accessible, index);
8070 obj = g_object_new (GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, NULL);
8071 gtk_icon_view_item_accessible_info_new (accessible, obj, index);
8072 obj->role = ATK_ROLE_ICON;
8073 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8074 a11y_item->item = item;
8075 a11y_item->widget = widget;
8077 g_free (a11y_item->text);
8078 a11y_item->text = get_text (icon_view, item);
8080 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8081 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8089 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8092 GtkIconViewItemAccessibleInfo *info;
8093 GtkIconViewItemAccessible *item;
8099 gboolean act_on_item;
8101 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8105 items = view->items;
8107 act_on_item = (list == NULL);
8112 info = (GtkIconViewItemAccessibleInfo *)items->data;
8113 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8115 if (act_on_item == FALSE && list == items)
8119 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8121 items = items->next;
8127 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8128 GtkIconViewAccessible *view)
8130 gtk_icon_view_accessible_traverse_items (view, NULL);
8134 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8135 GtkOrientation orientation,
8136 GtkAdjustment *adjustment)
8138 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
8139 GtkAdjustment **old_adj_ptr;
8141 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8143 if (view->old_hadj == adjustment)
8146 old_adj_ptr = &view->old_hadj;
8150 if (view->old_vadj == adjustment)
8153 old_adj_ptr = &view->old_vadj;
8156 /* Disconnect signal handlers */
8159 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8160 (gpointer *)old_adj_ptr);
8161 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8162 gtk_icon_view_accessible_adjustment_changed,
8166 /* Connect signal */
8167 *old_adj_ptr = adjustment;
8168 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8169 g_signal_connect (adjustment, "value-changed",
8170 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8175 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8183 GtkIconView *icon_view;
8184 GtkIconViewItem *item;
8185 GtkIconViewItemAccessible *a11y_item;
8188 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8189 index = gtk_tree_path_get_indices(path)[0];
8190 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8191 gtk_icon_view_accessible_find_child (atk_obj, index));
8195 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8196 icon_view = GTK_ICON_VIEW (widget);
8197 item = a11y_item->item;
8199 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8200 if (!name || strcmp (name, "") == 0)
8202 g_free (a11y_item->text);
8203 a11y_item->text = get_text (icon_view, item);
8207 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8213 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8218 GtkIconViewItemAccessibleInfo *info;
8219 GtkIconViewAccessible *view;
8220 GtkIconViewItemAccessible *item;
8226 index = gtk_tree_path_get_indices(path)[0];
8227 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8228 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8230 items = view->items;
8235 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8236 if (info->index != item->item->index)
8238 if (info->index < index)
8239 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8241 if (tmp_list == NULL)
8244 info->index = item->item->index;
8247 items = items->next;
8249 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8250 g_signal_emit_by_name (atk_obj, "children-changed::add",
8256 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8260 GtkIconViewItemAccessibleInfo *info;
8261 GtkIconViewAccessible *view;
8262 GtkIconViewItemAccessible *item;
8265 GList *deleted_item;
8269 index = gtk_tree_path_get_indices(path)[0];
8270 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8271 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8273 items = view->items;
8275 deleted_item = NULL;
8280 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8281 if (info->index == index)
8283 deleted_item = items;
8285 if (info->index != item->item->index)
8287 if (tmp_list == NULL)
8290 info->index = item->item->index;
8293 items = items->next;
8295 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8298 info = deleted_item->data;
8299 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8300 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8302 view->items = g_list_remove_link (view->items, deleted_item);
8310 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8311 GtkIconViewItemAccessibleInfo *i2)
8313 return i1->index - i2->index;
8317 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8323 GtkIconViewAccessible *view;
8324 GtkIconViewItemAccessibleInfo *info;
8325 GtkIconView *icon_view;
8326 GtkIconViewItemAccessible *item;
8332 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8333 icon_view = GTK_ICON_VIEW (user_data);
8334 view = (GtkIconViewAccessible*)atk_obj;
8336 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8338 order = g_new (gint, length);
8339 for (i = 0; i < length; i++)
8340 order [new_order[i]] = i;
8342 items = view->items;
8346 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8347 info->index = order[info->index];
8348 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8349 items = items->next;
8352 view->items = g_list_sort (view->items,
8353 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8359 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8364 obj = G_OBJECT (model);
8365 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8366 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8367 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8368 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8372 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8376 obj = G_OBJECT (icon_view->priv->model);
8377 g_signal_connect_data (obj, "row-changed",
8378 (GCallback) gtk_icon_view_accessible_model_row_changed,
8379 icon_view, NULL, 0);
8380 g_signal_connect_data (obj, "row-inserted",
8381 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8382 icon_view, NULL, G_CONNECT_AFTER);
8383 g_signal_connect_data (obj, "row-deleted",
8384 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8385 icon_view, NULL, G_CONNECT_AFTER);
8386 g_signal_connect_data (obj, "rows-reordered",
8387 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8388 icon_view, NULL, G_CONNECT_AFTER);
8392 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessible *view)
8394 GtkIconViewItemAccessibleInfo *info;
8397 items = view->items;
8400 info = (GtkIconViewItemAccessibleInfo *) items->data;
8401 g_object_unref (info->item);
8402 g_free (items->data);
8403 items = items->next;
8405 g_list_free (view->items);
8410 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8413 GtkIconView *icon_view;
8416 GtkIconViewAccessible *view;
8418 if (strcmp (pspec->name, "model") == 0)
8420 widget = GTK_WIDGET (obj);
8421 atk_obj = gtk_widget_get_accessible (widget);
8422 view = (GtkIconViewAccessible*)atk_obj;
8425 g_object_remove_weak_pointer (G_OBJECT (view->model),
8426 (gpointer *)&view->model);
8427 gtk_icon_view_accessible_disconnect_model_signals (view->model, widget);
8429 gtk_icon_view_accessible_clear_cache (view);
8431 icon_view = GTK_ICON_VIEW (obj);
8432 view->model = icon_view->priv->model;
8433 /* If there is no model the GtkIconView is probably being destroyed */
8436 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8437 gtk_icon_view_accessible_connect_model_signals (icon_view);
8445 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8448 GtkIconViewAccessible *view;
8449 GtkIconView *icon_view;
8451 if (ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize)
8452 ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize (accessible, data);
8454 icon_view = (GtkIconView*)data;
8455 view = (GtkIconViewAccessible*)accessible;
8457 if (icon_view->priv->hadjustment)
8458 gtk_icon_view_accessible_set_adjustment (accessible,
8459 GTK_ORIENTATION_HORIZONTAL,
8460 icon_view->priv->hadjustment);
8461 if (icon_view->priv->vadjustment)
8462 gtk_icon_view_accessible_set_adjustment (accessible,
8463 GTK_ORIENTATION_VERTICAL,
8464 icon_view->priv->vadjustment);
8465 g_signal_connect (data, "notify",
8466 G_CALLBACK (gtk_icon_view_accessible_notify_gtk), NULL);
8468 view->model = icon_view->priv->model;
8471 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8472 gtk_icon_view_accessible_connect_model_signals (icon_view);
8475 accessible->role = ATK_ROLE_LAYERED_PANE;
8479 gtk_icon_view_accessible_finalize (GObject *object)
8481 GtkIconViewAccessible *view = (GtkIconViewAccessible*)object;
8483 gtk_icon_view_accessible_clear_cache (view);
8485 G_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->finalize (object);
8489 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8490 GtkAccessible *accessible)
8493 GtkIconViewAccessible *view;
8495 atk_obj = ATK_OBJECT (accessible);
8496 view = (GtkIconViewAccessible*)atk_obj;
8499 g_object_remove_weak_pointer (G_OBJECT (view->old_hadj),
8500 (gpointer *)&view->old_hadj);
8502 g_signal_handlers_disconnect_by_func (view->old_hadj,
8503 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8505 view->old_hadj = NULL;
8509 g_object_remove_weak_pointer (G_OBJECT (view->old_vadj),
8510 (gpointer *)&view->old_vadj);
8512 g_signal_handlers_disconnect_by_func (view->old_vadj,
8513 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8515 view->old_vadj = NULL;
8520 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8524 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8527 g_signal_connect_after (widget, "destroy",
8528 G_CALLBACK (gtk_icon_view_accessible_destroyed), accessible);
8530 GTK_ACCESSIBLE_CLASS (_gtk_icon_view_accessible_parent_class)->connect_widget_destroyed (accessible);
8534 _gtk_icon_view_accessible_class_init (GtkIconViewAccessibleClass *klass)
8536 GObjectClass *gobject_class;
8537 GtkAccessibleClass *accessible_class;
8538 AtkObjectClass *atk_class;
8540 gobject_class = (GObjectClass *)klass;
8541 accessible_class = (GtkAccessibleClass *)klass;
8542 atk_class = (AtkObjectClass *)klass;
8544 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8546 atk_class->get_n_children = gtk_icon_view_accessible_get_n_children;
8547 atk_class->ref_child = gtk_icon_view_accessible_ref_child;
8548 atk_class->initialize = gtk_icon_view_accessible_initialize;
8550 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8554 _gtk_icon_view_accessible_init (GtkIconViewAccessible *accessible)
8559 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8562 AtkCoordType coord_type)
8565 GtkIconView *icon_view;
8566 GtkIconViewItem *item;
8569 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8573 icon_view = GTK_ICON_VIEW (widget);
8574 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8575 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8577 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8583 atk_component_interface_init (AtkComponentIface *iface)
8585 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8589 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8593 GtkIconView *icon_view;
8594 GtkIconViewItem *item;
8596 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8600 icon_view = GTK_ICON_VIEW (widget);
8602 item = g_list_nth_data (icon_view->priv->items, i);
8606 gtk_icon_view_select_item (icon_view, item);
8612 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8615 GtkIconView *icon_view;
8617 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8621 icon_view = GTK_ICON_VIEW (widget);
8622 gtk_icon_view_unselect_all (icon_view);
8628 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8633 GtkIconView *icon_view;
8634 GtkIconViewItem *item;
8636 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8640 icon_view = GTK_ICON_VIEW (widget);
8642 l = icon_view->priv->items;
8649 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8660 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8663 GtkIconView *icon_view;
8664 GtkIconViewItem *item;
8668 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8672 icon_view = GTK_ICON_VIEW (widget);
8674 l = icon_view->priv->items;
8690 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8694 GtkIconView *icon_view;
8695 GtkIconViewItem *item;
8697 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8701 icon_view = GTK_ICON_VIEW (widget);
8703 item = g_list_nth_data (icon_view->priv->items, i);
8707 return item->selected;
8711 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8715 GtkIconView *icon_view;
8716 GtkIconViewItem *item;
8720 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8724 icon_view = GTK_ICON_VIEW (widget);
8725 l = icon_view->priv->items;
8734 gtk_icon_view_unselect_item (icon_view, item);
8746 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8749 GtkIconView *icon_view;
8751 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8755 icon_view = GTK_ICON_VIEW (widget);
8756 gtk_icon_view_select_all (icon_view);
8761 atk_selection_interface_init (AtkSelectionIface *iface)
8763 iface->add_selection = gtk_icon_view_accessible_add_selection;
8764 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8765 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8766 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8767 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8768 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8769 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;