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 ctrl_pressed : 1;
182 guint shift_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 item = gtk_icon_view_get_item_at_coords (icon_view,
2027 * We consider only the the cells' area as the item area if the
2028 * item is not selected, but if it *is* selected, the complete
2029 * selection rectangle is considered to be part of the item.
2031 if (item != NULL && (cell != NULL || item->selected))
2035 if (gtk_cell_renderer_is_activatable (cell))
2039 gtk_icon_view_scroll_to_item (icon_view, item);
2041 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2043 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2045 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2046 (event->state & GDK_SHIFT_MASK))
2048 gtk_icon_view_unselect_all_internal (icon_view);
2050 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2051 if (!icon_view->priv->anchor_item)
2052 icon_view->priv->anchor_item = item;
2054 gtk_icon_view_select_all_between (icon_view,
2055 icon_view->priv->anchor_item,
2061 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2062 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2063 (event->state & GDK_CONTROL_MASK))
2065 item->selected = !item->selected;
2066 gtk_icon_view_queue_draw_item (icon_view, item);
2071 gtk_icon_view_unselect_all_internal (icon_view);
2073 item->selected = TRUE;
2074 gtk_icon_view_queue_draw_item (icon_view, item);
2077 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2078 icon_view->priv->anchor_item = item;
2081 /* Save press to possibly begin a drag */
2082 if (icon_view->priv->pressed_button < 0)
2084 icon_view->priv->pressed_button = event->button;
2085 icon_view->priv->press_start_x = event->x;
2086 icon_view->priv->press_start_y = event->y;
2089 if (!icon_view->priv->last_single_clicked)
2090 icon_view->priv->last_single_clicked = item;
2092 /* cancel the current editing, if it exists */
2093 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2095 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2097 GtkCellAreaContext *context;
2099 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2101 gtk_icon_view_set_cell_data (icon_view, item);
2102 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2103 GTK_WIDGET (icon_view),
2104 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2109 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2110 !(event->state & GDK_CONTROL_MASK))
2112 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2115 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2116 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2119 /* don't draw keyboard focus around an clicked-on item */
2120 icon_view->priv->draw_focus = FALSE;
2123 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2125 item = gtk_icon_view_get_item_at_coords (icon_view,
2130 if (item && item == icon_view->priv->last_single_clicked)
2134 path = gtk_tree_path_new_from_indices (item->index, -1);
2135 gtk_icon_view_item_activated (icon_view, path);
2136 gtk_tree_path_free (path);
2139 icon_view->priv->last_single_clicked = NULL;
2140 icon_view->priv->pressed_button = -1;
2144 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2146 return event->button == 1;
2150 gtk_icon_view_button_release (GtkWidget *widget,
2151 GdkEventButton *event)
2153 GtkIconView *icon_view;
2155 icon_view = GTK_ICON_VIEW (widget);
2157 if (icon_view->priv->pressed_button == event->button)
2158 icon_view->priv->pressed_button = -1;
2160 gtk_icon_view_stop_rubberbanding (icon_view);
2162 remove_scroll_timeout (icon_view);
2168 gtk_icon_view_key_press (GtkWidget *widget,
2171 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2173 if (icon_view->priv->doing_rubberband)
2175 if (event->keyval == GDK_KEY_Escape)
2176 gtk_icon_view_stop_rubberbanding (icon_view);
2181 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2185 gtk_icon_view_key_release (GtkWidget *widget,
2188 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2190 if (icon_view->priv->doing_rubberband)
2193 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2197 gtk_icon_view_update_rubberband (gpointer data)
2199 GtkIconView *icon_view;
2201 GdkRectangle old_area;
2202 GdkRectangle new_area;
2203 GdkRectangle common;
2204 cairo_region_t *invalid_region;
2206 icon_view = GTK_ICON_VIEW (data);
2208 gdk_window_get_device_position (icon_view->priv->bin_window,
2209 icon_view->priv->rubberband_device,
2215 old_area.x = MIN (icon_view->priv->rubberband_x1,
2216 icon_view->priv->rubberband_x2);
2217 old_area.y = MIN (icon_view->priv->rubberband_y1,
2218 icon_view->priv->rubberband_y2);
2219 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2220 icon_view->priv->rubberband_x1) + 1;
2221 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2222 icon_view->priv->rubberband_y1) + 1;
2224 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2225 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2226 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2227 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2229 invalid_region = cairo_region_create_rectangle (&old_area);
2230 cairo_region_union_rectangle (invalid_region, &new_area);
2232 gdk_rectangle_intersect (&old_area, &new_area, &common);
2233 if (common.width > 2 && common.height > 2)
2235 cairo_region_t *common_region;
2237 /* make sure the border is invalidated */
2243 common_region = cairo_region_create_rectangle (&common);
2245 cairo_region_subtract (invalid_region, common_region);
2246 cairo_region_destroy (common_region);
2249 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2251 cairo_region_destroy (invalid_region);
2253 icon_view->priv->rubberband_x2 = x;
2254 icon_view->priv->rubberband_y2 = y;
2256 gtk_icon_view_update_rubberband_selection (icon_view);
2260 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2267 if (icon_view->priv->rubberband_device)
2270 for (items = icon_view->priv->items; items; items = items->next)
2272 GtkIconViewItem *item = items->data;
2274 item->selected_before_rubberbanding = item->selected;
2277 icon_view->priv->rubberband_x1 = x;
2278 icon_view->priv->rubberband_y1 = y;
2279 icon_view->priv->rubberband_x2 = x;
2280 icon_view->priv->rubberband_y2 = y;
2282 icon_view->priv->doing_rubberband = TRUE;
2283 icon_view->priv->rubberband_device = device;
2285 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2289 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2291 if (!icon_view->priv->doing_rubberband)
2294 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2295 icon_view->priv->rubberband_device);
2297 icon_view->priv->doing_rubberband = FALSE;
2298 icon_view->priv->rubberband_device = NULL;
2300 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2304 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2307 gint x, y, width, height;
2308 gboolean dirty = FALSE;
2310 x = MIN (icon_view->priv->rubberband_x1,
2311 icon_view->priv->rubberband_x2);
2312 y = MIN (icon_view->priv->rubberband_y1,
2313 icon_view->priv->rubberband_y2);
2314 width = ABS (icon_view->priv->rubberband_x1 -
2315 icon_view->priv->rubberband_x2);
2316 height = ABS (icon_view->priv->rubberband_y1 -
2317 icon_view->priv->rubberband_y2);
2319 for (items = icon_view->priv->items; items; items = items->next)
2321 GtkIconViewItem *item = items->data;
2325 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2326 x, y, width, height);
2328 selected = is_in ^ item->selected_before_rubberbanding;
2330 if (item->selected != selected)
2332 item->selected = selected;
2334 gtk_icon_view_queue_draw_item (icon_view, item);
2339 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2344 GdkRectangle hit_rect;
2349 hit_test (GtkCellRenderer *renderer,
2350 const GdkRectangle *cell_area,
2351 const GdkRectangle *cell_background,
2354 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2355 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2356 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2357 MAX (data->hit_rect.y, cell_area->y) > 0)
2360 return (data->hit != FALSE);
2364 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2365 GtkIconViewItem *item,
2371 HitTestData data = { { x, y, width, height }, FALSE };
2372 GtkCellAreaContext *context;
2373 GdkRectangle *item_area = (GdkRectangle *)item;
2375 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2376 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2379 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2381 gtk_icon_view_set_cell_data (icon_view, item);
2382 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2383 GTK_WIDGET (icon_view),
2384 item_area, item_area,
2385 (GtkCellAllocCallback)hit_test, &data);
2391 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2393 gboolean dirty = FALSE;
2396 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2399 for (items = icon_view->priv->items; items; items = items->next)
2401 GtkIconViewItem *item = items->data;
2405 item->selected = FALSE;
2407 gtk_icon_view_queue_draw_item (icon_view, item);
2408 gtk_icon_view_item_selected_changed (icon_view, item);
2416 /* GtkIconView signals */
2418 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2420 gtk_icon_view_select_all (icon_view);
2424 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2426 gtk_icon_view_unselect_all (icon_view);
2430 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2432 gtk_icon_view_unselect_all (icon_view);
2434 if (icon_view->priv->cursor_item != NULL)
2435 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2439 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2442 GtkCellAreaContext *context;
2444 if (!icon_view->priv->cursor_item)
2447 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2449 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2450 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2451 GTK_WIDGET (icon_view),
2452 (GdkRectangle *)icon_view->priv->cursor_item,
2456 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2457 gtk_icon_view_item_activated (icon_view, path);
2458 gtk_tree_path_free (path);
2464 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2466 if (!icon_view->priv->cursor_item)
2469 switch (icon_view->priv->selection_mode)
2471 case GTK_SELECTION_NONE:
2473 case GTK_SELECTION_BROWSE:
2474 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2476 case GTK_SELECTION_SINGLE:
2477 if (icon_view->priv->cursor_item->selected)
2478 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2480 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2482 case GTK_SELECTION_MULTIPLE:
2483 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2484 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2486 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2487 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2492 /* Internal functions */
2494 gtk_icon_view_process_updates (GtkIconView *icon_view)
2496 /* Prior to drawing, we check if a layout has been scheduled. If so,
2497 * do it now that all cell view items have valid sizes before we proceeed
2498 * (and resize the bin_window if required).
2500 if (icon_view->priv->layout_idle_id != 0)
2501 gtk_icon_view_layout (icon_view);
2503 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2507 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2509 GtkAllocation allocation;
2510 GtkAdjustment *adj = icon_view->priv->hadjustment;
2511 gdouble old_page_size;
2517 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2519 old_value = gtk_adjustment_get_value (adj);
2520 old_upper = gtk_adjustment_get_upper (adj);
2521 old_page_size = gtk_adjustment_get_page_size (adj);
2522 new_upper = MAX (allocation.width, icon_view->priv->width);
2524 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2526 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2527 /* Quick explanation:
2528 * In LTR locales, leftmost portion of visible rectangle should stay
2529 * fixed, which means left edge of scrollbar thumb should remain fixed
2530 * and thus adjustment's value should stay the same.
2532 * In RTL locales, we want to keep rightmost portion of visible
2533 * rectangle fixed. This means right edge of thumb should remain fixed.
2534 * In this case, upper - value - page_size should remain constant.
2536 new_value = (new_upper - allocation.width) -
2537 (old_upper - old_value - old_page_size);
2538 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2541 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2543 gtk_adjustment_configure (adj,
2547 allocation.width * 0.1,
2548 allocation.width * 0.9,
2553 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2555 GtkAllocation allocation;
2556 GtkAdjustment *adj = icon_view->priv->vadjustment;
2558 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2560 gtk_adjustment_configure (adj,
2561 gtk_adjustment_get_value (adj),
2563 MAX (allocation.height, icon_view->priv->height),
2564 allocation.height * 0.1,
2565 allocation.height * 0.9,
2570 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2571 GtkAdjustment *adjustment)
2573 GtkIconViewPrivate *priv = icon_view->priv;
2576 if (adjustment && priv->hadjustment == adjustment)
2579 if (priv->hadjustment != NULL)
2581 g_signal_handlers_disconnect_matched (priv->hadjustment,
2582 G_SIGNAL_MATCH_DATA,
2583 0, 0, NULL, NULL, icon_view);
2584 g_object_unref (priv->hadjustment);
2588 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2591 g_signal_connect (adjustment, "value-changed",
2592 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2593 priv->hadjustment = g_object_ref_sink (adjustment);
2594 gtk_icon_view_set_hadjustment_values (icon_view);
2596 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2597 gtk_icon_view_accessible_set_adjustment (atk_obj,
2598 GTK_ORIENTATION_HORIZONTAL,
2601 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2605 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2606 GtkAdjustment *adjustment)
2608 GtkIconViewPrivate *priv = icon_view->priv;
2611 if (adjustment && priv->vadjustment == adjustment)
2614 if (priv->vadjustment != NULL)
2616 g_signal_handlers_disconnect_matched (priv->vadjustment,
2617 G_SIGNAL_MATCH_DATA,
2618 0, 0, NULL, NULL, icon_view);
2619 g_object_unref (priv->vadjustment);
2623 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2626 g_signal_connect (adjustment, "value-changed",
2627 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2628 priv->vadjustment = g_object_ref_sink (adjustment);
2629 gtk_icon_view_set_vadjustment_values (icon_view);
2631 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2632 gtk_icon_view_accessible_set_adjustment (atk_obj,
2633 GTK_ORIENTATION_VERTICAL,
2636 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2640 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2641 GtkIconView *icon_view)
2643 GtkIconViewPrivate *priv = icon_view->priv;
2645 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2647 gdk_window_move (priv->bin_window,
2648 - gtk_adjustment_get_value (priv->hadjustment),
2649 - gtk_adjustment_get_value (priv->vadjustment));
2651 if (icon_view->priv->doing_rubberband)
2652 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2654 gtk_icon_view_process_updates (icon_view);
2659 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2664 gint *maximum_width)
2666 GtkAllocation allocation;
2667 GtkCellAreaContext *context;
2668 GtkIconViewPrivate *priv = icon_view->priv;
2669 GtkWidget *widget = GTK_WIDGET (icon_view);
2670 gint x, current_width;
2671 GList *items, *last_item;
2673 gint max_height = 0;
2676 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2684 current_width += 2 * priv->margin;
2686 gtk_widget_get_allocation (widget, &allocation);
2688 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2689 g_ptr_array_add (priv->row_contexts, context);
2691 /* In the first loop we iterate horizontally until we hit allocation width
2692 * and collect the aligned height-for-width */
2696 GtkIconViewItem *item = items->data;
2697 GdkRectangle *item_area = (GdkRectangle *)item;
2699 item_area->width = item_width;
2701 current_width += item_area->width + icon_view->priv->item_padding * 2;
2703 if (items != first_item)
2705 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2706 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2710 /* Get this item's particular width & height (all alignments are cached by now) */
2711 gtk_icon_view_set_cell_data (icon_view, item);
2712 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2717 current_width += icon_view->priv->column_spacing;
2719 item_area->y = *y + icon_view->priv->item_padding;
2720 item_area->x = x + icon_view->priv->item_padding;
2722 x = current_width - icon_view->priv->margin;
2724 if (current_width > *maximum_width)
2725 *maximum_width = current_width;
2731 items = items->next;
2736 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2737 gtk_cell_area_context_allocate (context, item_width, max_height);
2739 /* In the second loop the item height has been aligned and derived and
2740 * we just set the height and handle rtl layout */
2741 for (items = first_item; items != last_item; items = items->next)
2743 GtkIconViewItem *item = items->data;
2744 GdkRectangle *item_area = (GdkRectangle *)item;
2748 item_area->x = *maximum_width - item_area->width - item_area->x;
2749 item->col = col - 1 - item->col;
2752 /* All items in the same row get the same height */
2753 item_area->height = max_height;
2756 /* Adjust the new y coordinate. */
2757 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2763 adjust_wrap_width (GtkIconView *icon_view)
2765 if (icon_view->priv->text_cell)
2767 gint wrap_width = 50;
2769 /* Here we go with the same old guess, try the icon size and set double
2770 * the size of the first icon found in the list, naive but works much
2772 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2774 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2775 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2776 GTK_WIDGET (icon_view),
2779 wrap_width = MAX (wrap_width * 2, 50);
2782 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2783 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2788 gtk_icon_view_layout (GtkIconView *icon_view)
2790 GtkAllocation allocation;
2793 gint y = 0, maximum_width = 0;
2796 gboolean size_changed = FALSE;
2798 if (icon_view->priv->layout_idle_id != 0)
2800 g_source_remove (icon_view->priv->layout_idle_id);
2801 icon_view->priv->layout_idle_id = 0;
2804 if (icon_view->priv->model == NULL)
2807 widget = GTK_WIDGET (icon_view);
2809 item_width = icon_view->priv->item_width;
2811 /* Update the wrap width for the text cell before going and requesting sizes */
2812 adjust_wrap_width (icon_view);
2814 /* Update the context widths for any invalidated items */
2815 gtk_icon_view_cache_widths (icon_view);
2817 /* Fetch the new item width if needed */
2819 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2822 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2824 icons = icon_view->priv->items;
2825 y += icon_view->priv->margin;
2828 /* Clear the per row contexts */
2829 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2833 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2835 &y, &maximum_width);
2838 while (icons != NULL);
2840 if (maximum_width != icon_view->priv->width)
2842 icon_view->priv->width = maximum_width;
2843 size_changed = TRUE;
2846 y += icon_view->priv->margin;
2848 if (y != icon_view->priv->height)
2850 icon_view->priv->height = y;
2851 size_changed = TRUE;
2854 gtk_icon_view_set_hadjustment_values (icon_view);
2855 gtk_icon_view_set_vadjustment_values (icon_view);
2858 gtk_widget_queue_resize_no_redraw (widget);
2860 gtk_widget_get_allocation (widget, &allocation);
2861 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2862 gdk_window_resize (icon_view->priv->bin_window,
2863 MAX (icon_view->priv->width, allocation.width),
2864 MAX (icon_view->priv->height, allocation.height));
2866 if (icon_view->priv->scroll_to_path)
2870 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2871 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2872 icon_view->priv->scroll_to_path = NULL;
2874 gtk_icon_view_scroll_to_path (icon_view, path,
2875 icon_view->priv->scroll_to_use_align,
2876 icon_view->priv->scroll_to_row_align,
2877 icon_view->priv->scroll_to_col_align);
2878 gtk_tree_path_free (path);
2881 gtk_widget_queue_draw (widget);
2884 /* This ensures that all widths have been cached in the
2885 * context and we have proper alignments to go on.
2888 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2892 g_signal_handler_block (icon_view->priv->cell_area_context,
2893 icon_view->priv->context_changed_id);
2895 for (items = icon_view->priv->items; items; items = items->next)
2897 GtkIconViewItem *item = items->data;
2899 /* Only fetch the width of items with invalidated sizes */
2900 if (item->cell_area.width < 0)
2902 gtk_icon_view_set_cell_data (icon_view, item);
2903 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2904 icon_view->priv->cell_area_context,
2905 GTK_WIDGET (icon_view), NULL, NULL);
2909 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2910 icon_view->priv->context_changed_id);
2914 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2916 /* Clear all item sizes */
2917 g_list_foreach (icon_view->priv->items,
2918 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2920 /* Reset the context */
2921 if (icon_view->priv->cell_area_context)
2923 g_signal_handler_block (icon_view->priv->cell_area_context,
2924 icon_view->priv->context_changed_id);
2925 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2926 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2927 icon_view->priv->context_changed_id);
2930 /* Re-layout the items */
2931 gtk_icon_view_queue_layout (icon_view);
2935 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2937 item->cell_area.width = -1;
2938 item->cell_area.height = -1;
2942 gtk_icon_view_paint_item (GtkIconView *icon_view,
2944 GtkIconViewItem *item,
2947 gboolean draw_focus)
2949 GdkRectangle cell_area;
2950 GtkStateFlags state = 0;
2951 GtkCellRendererState flags = 0;
2952 GtkStyleContext *style_context;
2953 GtkWidget *widget = GTK_WIDGET (icon_view);
2954 GtkIconViewPrivate *priv = icon_view->priv;
2955 GtkCellAreaContext *context;
2957 if (priv->model == NULL)
2960 gtk_icon_view_set_cell_data (icon_view, item);
2962 style_context = gtk_widget_get_style_context (widget);
2964 gtk_style_context_save (style_context);
2965 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2966 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2970 if (gtk_widget_has_focus (widget) &&
2971 item == icon_view->priv->cursor_item)
2973 state |= GTK_STATE_FLAG_FOCUSED;
2974 flags |= GTK_CELL_RENDERER_FOCUSED;
2977 state |= GTK_STATE_FLAG_SELECTED;
2978 flags |= GTK_CELL_RENDERER_SELECTED;
2983 state |= GTK_STATE_FLAG_PRELIGHT;
2984 flags |= GTK_CELL_RENDERER_PRELIT;
2987 gtk_style_context_set_state (style_context, state);
2991 gtk_render_background (style_context, cr,
2992 x - icon_view->priv->item_padding,
2993 y - icon_view->priv->item_padding,
2994 item->cell_area.width + icon_view->priv->item_padding * 2,
2995 item->cell_area.height + icon_view->priv->item_padding * 2);
2996 gtk_render_frame (style_context, cr,
2997 x - icon_view->priv->item_padding,
2998 y - icon_view->priv->item_padding,
2999 item->cell_area.width + icon_view->priv->item_padding * 2,
3000 item->cell_area.height + icon_view->priv->item_padding * 2);
3005 cell_area.width = item->cell_area.width;
3006 cell_area.height = item->cell_area.height;
3008 context = g_ptr_array_index (priv->row_contexts, item->row);
3009 gtk_cell_area_render (priv->cell_area, context,
3010 widget, cr, &cell_area, &cell_area, flags,
3013 gtk_style_context_restore (style_context);
3017 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3020 GtkStyleContext *context;
3025 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3026 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3027 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3028 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3030 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
3032 gtk_style_context_save (context);
3033 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3035 gdk_cairo_rectangle (cr, &rect);
3038 gtk_render_background (context, cr,
3040 rect.width, rect.height);
3041 gtk_render_frame (context, cr,
3043 rect.width, rect.height);
3045 gtk_style_context_restore (context);
3050 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3056 index = gtk_tree_path_get_indices (path)[0];
3058 for (l = icon_view->priv->items; l; l = l->next)
3060 GtkIconViewItem *item = l->data;
3062 if (item->index == index)
3064 gtk_icon_view_queue_draw_item (icon_view, item);
3071 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3072 GtkIconViewItem *item)
3075 GdkRectangle *item_area = (GdkRectangle *)item;
3077 rect.x = item_area->x - icon_view->priv->item_padding;
3078 rect.y = item_area->y - icon_view->priv->item_padding;
3079 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3080 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3082 if (icon_view->priv->bin_window)
3083 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3087 layout_callback (gpointer user_data)
3089 GtkIconView *icon_view;
3091 icon_view = GTK_ICON_VIEW (user_data);
3093 icon_view->priv->layout_idle_id = 0;
3095 gtk_icon_view_layout (icon_view);
3101 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3103 if (icon_view->priv->layout_idle_id != 0)
3106 icon_view->priv->layout_idle_id =
3107 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3108 layout_callback, icon_view, NULL);
3112 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3113 GtkIconViewItem *item,
3114 GtkCellRenderer *cursor_cell)
3117 AtkObject *item_obj;
3118 AtkObject *cursor_item_obj;
3120 /* When hitting this path from keynav, the focus cell is
3121 * already set, we dont need to notify the atk object
3122 * but we still need to queue the draw here (in the case
3123 * that the focus cell changes but not the cursor item).
3125 gtk_icon_view_queue_draw_item (icon_view, item);
3127 if (icon_view->priv->cursor_item == item &&
3128 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3131 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3132 if (icon_view->priv->cursor_item != NULL)
3134 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3137 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3138 if (cursor_item_obj != NULL)
3139 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3142 icon_view->priv->cursor_item = item;
3145 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3148 /* Make sure there is a cell in focus initially */
3149 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3150 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3153 /* Notify that accessible focus object has changed */
3154 item_obj = atk_object_ref_accessible_child (obj, item->index);
3156 if (item_obj != NULL)
3158 atk_focus_tracker_notify (item_obj);
3159 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3160 g_object_unref (item_obj);
3165 static GtkIconViewItem *
3166 gtk_icon_view_item_new (void)
3168 GtkIconViewItem *item;
3170 item = g_slice_new0 (GtkIconViewItem);
3172 item->cell_area.width = -1;
3173 item->cell_area.height = -1;
3179 gtk_icon_view_item_free (GtkIconViewItem *item)
3181 g_return_if_fail (item != NULL);
3183 g_slice_free (GtkIconViewItem, item);
3186 static GtkIconViewItem *
3187 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3190 gboolean only_in_cell,
3191 GtkCellRenderer **cell_at_pos)
3196 *cell_at_pos = NULL;
3198 for (items = icon_view->priv->items; items; items = items->next)
3200 GtkIconViewItem *item = items->data;
3201 GdkRectangle *item_area = (GdkRectangle *)item;
3203 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3204 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3205 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3206 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3208 if (only_in_cell || cell_at_pos)
3210 GtkCellRenderer *cell = NULL;
3211 GtkCellAreaContext *context;
3213 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3214 gtk_icon_view_set_cell_data (icon_view, item);
3216 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3217 y >= item_area->y && y <= item_area->y + item_area->height)
3218 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3219 GTK_WIDGET (icon_view),
3224 *cell_at_pos = cell;
3227 return cell != NULL ? item : NULL;
3238 gtk_icon_view_select_item (GtkIconView *icon_view,
3239 GtkIconViewItem *item)
3241 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3242 g_return_if_fail (item != NULL);
3247 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3249 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3250 gtk_icon_view_unselect_all_internal (icon_view);
3252 item->selected = TRUE;
3254 gtk_icon_view_item_selected_changed (icon_view, item);
3255 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3257 gtk_icon_view_queue_draw_item (icon_view, item);
3262 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3263 GtkIconViewItem *item)
3265 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3266 g_return_if_fail (item != NULL);
3268 if (!item->selected)
3271 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3272 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3275 item->selected = FALSE;
3277 gtk_icon_view_item_selected_changed (icon_view, item);
3278 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3280 gtk_icon_view_queue_draw_item (icon_view, item);
3284 verify_items (GtkIconView *icon_view)
3289 for (items = icon_view->priv->items; items; items = items->next)
3291 GtkIconViewItem *item = items->data;
3293 if (item->index != i)
3294 g_error ("List item does not match its index: "
3295 "item index %d and list index %d\n", item->index, i);
3302 gtk_icon_view_row_changed (GtkTreeModel *model,
3307 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3309 /* ignore changes in branches */
3310 if (gtk_tree_path_get_depth (path) > 1)
3313 /* An icon view subclass might add it's own model and populate
3314 * things at init() time instead of waiting for the constructor()
3317 if (icon_view->priv->cell_area)
3318 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3320 /* Here we can use a "grow-only" strategy for optimization
3321 * and only invalidate a single item and queue a relayout
3322 * instead of invalidating the whole thing.
3324 * For now GtkIconView still cant deal with huge models
3325 * so just invalidate the whole thing when the model
3328 gtk_icon_view_invalidate_sizes (icon_view);
3330 verify_items (icon_view);
3334 gtk_icon_view_row_inserted (GtkTreeModel *model,
3339 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3341 GtkIconViewItem *item;
3342 gboolean iters_persist;
3345 /* ignore changes in branches */
3346 if (gtk_tree_path_get_depth (path) > 1)
3349 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3351 index = gtk_tree_path_get_indices(path)[0];
3353 item = gtk_icon_view_item_new ();
3358 item->index = index;
3360 /* FIXME: We can be more efficient here,
3361 we can store a tail pointer and use that when
3362 appending (which is a rather common operation)
3364 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3367 list = g_list_nth (icon_view->priv->items, index + 1);
3368 for (; list; list = list->next)
3375 verify_items (icon_view);
3377 gtk_icon_view_queue_layout (icon_view);
3381 gtk_icon_view_row_deleted (GtkTreeModel *model,
3385 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3387 GtkIconViewItem *item;
3389 gboolean emit = FALSE;
3391 /* ignore changes in branches */
3392 if (gtk_tree_path_get_depth (path) > 1)
3395 index = gtk_tree_path_get_indices(path)[0];
3397 list = g_list_nth (icon_view->priv->items, index);
3400 if (icon_view->priv->cell_area)
3401 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3403 if (item == icon_view->priv->anchor_item)
3404 icon_view->priv->anchor_item = NULL;
3406 if (item == icon_view->priv->cursor_item)
3407 icon_view->priv->cursor_item = NULL;
3409 if (item == icon_view->priv->last_prelight)
3410 icon_view->priv->last_prelight = NULL;
3415 gtk_icon_view_item_free (item);
3417 for (next = list->next; next; next = next->next)
3424 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3426 verify_items (icon_view);
3428 gtk_icon_view_queue_layout (icon_view);
3431 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3435 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3436 GtkTreePath *parent,
3441 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3444 GList *items = NULL, *list;
3445 GtkIconViewItem **item_array;
3448 /* ignore changes in branches */
3452 if (icon_view->priv->cell_area)
3453 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3455 length = gtk_tree_model_iter_n_children (model, NULL);
3457 order = g_new (gint, length);
3458 for (i = 0; i < length; i++)
3459 order [new_order[i]] = i;
3461 item_array = g_new (GtkIconViewItem *, length);
3462 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3463 item_array[order[i]] = list->data;
3466 for (i = length - 1; i >= 0; i--)
3468 item_array[i]->index = i;
3469 items = g_list_prepend (items, item_array[i]);
3472 g_free (item_array);
3473 g_list_free (icon_view->priv->items);
3474 icon_view->priv->items = items;
3476 gtk_icon_view_queue_layout (icon_view);
3478 verify_items (icon_view);
3482 gtk_icon_view_build_items (GtkIconView *icon_view)
3486 gboolean iters_persist;
3487 GList *items = NULL;
3489 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3491 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3499 GtkIconViewItem *item = gtk_icon_view_item_new ();
3508 items = g_list_prepend (items, item);
3510 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3512 icon_view->priv->items = g_list_reverse (items);
3516 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3519 GtkMovementStep step,
3523 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3524 I_("move-cursor"), 2,
3528 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3533 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3536 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3541 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3548 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3549 GtkMovementStep step,
3552 GdkModifierType state;
3554 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3555 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3556 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3557 step == GTK_MOVEMENT_DISPLAY_LINES ||
3558 step == GTK_MOVEMENT_PAGES ||
3559 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3561 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3564 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3565 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3567 if (gtk_get_current_event_state (&state))
3569 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3570 icon_view->priv->ctrl_pressed = TRUE;
3571 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3572 icon_view->priv->shift_pressed = TRUE;
3574 /* else we assume not pressed */
3578 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3579 case GTK_MOVEMENT_VISUAL_POSITIONS:
3580 gtk_icon_view_move_cursor_left_right (icon_view, count);
3582 case GTK_MOVEMENT_DISPLAY_LINES:
3583 gtk_icon_view_move_cursor_up_down (icon_view, count);
3585 case GTK_MOVEMENT_PAGES:
3586 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3588 case GTK_MOVEMENT_BUFFER_ENDS:
3589 gtk_icon_view_move_cursor_start_end (icon_view, count);
3592 g_assert_not_reached ();
3595 icon_view->priv->ctrl_pressed = FALSE;
3596 icon_view->priv->shift_pressed = FALSE;
3598 icon_view->priv->draw_focus = TRUE;
3603 static GtkIconViewItem *
3604 find_item (GtkIconView *icon_view,
3605 GtkIconViewItem *current,
3611 GtkIconViewItem *item;
3613 /* FIXME: this could be more efficient
3615 row = current->row + row_ofs;
3616 col = current->col + col_ofs;
3618 for (items = icon_view->priv->items; items; items = items->next)
3621 if (item->row == row && item->col == col)
3628 static GtkIconViewItem *
3629 find_item_page_up_down (GtkIconView *icon_view,
3630 GtkIconViewItem *current,
3637 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3639 item = g_list_find (icon_view->priv->items, current);
3644 for (next = item->next; next; next = next->next)
3646 if (((GtkIconViewItem *)next->data)->col == col)
3649 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3659 for (next = item->prev; next; next = next->prev)
3661 if (((GtkIconViewItem *)next->data)->col == col)
3664 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3678 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3679 GtkIconViewItem *anchor,
3680 GtkIconViewItem *cursor)
3683 GtkIconViewItem *item;
3684 gint row1, row2, col1, col2;
3685 gboolean dirty = FALSE;
3687 if (anchor->row < cursor->row)
3698 if (anchor->col < cursor->col)
3709 for (items = icon_view->priv->items; items; items = items->next)
3713 if (row1 <= item->row && item->row <= row2 &&
3714 col1 <= item->col && item->col <= col2)
3716 if (!item->selected)
3719 item->selected = TRUE;
3720 gtk_icon_view_item_selected_changed (icon_view, item);
3722 gtk_icon_view_queue_draw_item (icon_view, item);
3730 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3733 GtkIconViewItem *item;
3734 GtkCellRenderer *cell = NULL;
3735 gboolean dirty = FALSE;
3737 GtkDirectionType direction;
3739 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3742 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3744 if (!icon_view->priv->cursor_item)
3749 list = icon_view->priv->items;
3751 list = g_list_last (icon_view->priv->items);
3753 item = list ? list->data : NULL;
3755 /* Give focus to the first cell initially */
3756 gtk_icon_view_set_cell_data (icon_view, item);
3757 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3761 item = icon_view->priv->cursor_item;
3762 step = count > 0 ? 1 : -1;
3764 /* Save the current focus cell in case we hit the edge */
3765 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3769 gtk_icon_view_set_cell_data (icon_view, item);
3771 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3774 item = find_item (icon_view, item, step, 0);
3780 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3782 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3784 gtk_widget_child_focus (toplevel,
3785 direction == GTK_DIR_UP ?
3786 GTK_DIR_TAB_BACKWARD :
3787 GTK_DIR_TAB_FORWARD);
3791 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3795 if (icon_view->priv->ctrl_pressed ||
3796 !icon_view->priv->shift_pressed ||
3797 !icon_view->priv->anchor_item ||
3798 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3799 icon_view->priv->anchor_item = item;
3801 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3802 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3804 if (!icon_view->priv->ctrl_pressed &&
3805 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3807 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3808 dirty = gtk_icon_view_select_all_between (icon_view,
3809 icon_view->priv->anchor_item,
3813 gtk_icon_view_scroll_to_item (icon_view, item);
3816 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3820 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3823 GtkIconViewItem *item;
3824 gboolean dirty = FALSE;
3826 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3829 if (!icon_view->priv->cursor_item)
3834 list = icon_view->priv->items;
3836 list = g_list_last (icon_view->priv->items);
3838 item = list ? list->data : NULL;
3841 item = find_item_page_up_down (icon_view,
3842 icon_view->priv->cursor_item,
3845 if (item == icon_view->priv->cursor_item)
3846 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3851 if (icon_view->priv->ctrl_pressed ||
3852 !icon_view->priv->shift_pressed ||
3853 !icon_view->priv->anchor_item ||
3854 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3855 icon_view->priv->anchor_item = item;
3857 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3859 if (!icon_view->priv->ctrl_pressed &&
3860 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3862 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3863 dirty = gtk_icon_view_select_all_between (icon_view,
3864 icon_view->priv->anchor_item,
3868 gtk_icon_view_scroll_to_item (icon_view, item);
3871 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3875 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3878 GtkIconViewItem *item;
3879 GtkCellRenderer *cell = NULL;
3880 gboolean dirty = FALSE;
3882 GtkDirectionType direction;
3884 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3887 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3889 if (!icon_view->priv->cursor_item)
3894 list = icon_view->priv->items;
3896 list = g_list_last (icon_view->priv->items);
3898 item = list ? list->data : NULL;
3900 /* Give focus to the first cell initially */
3901 gtk_icon_view_set_cell_data (icon_view, item);
3902 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3906 item = icon_view->priv->cursor_item;
3907 step = count > 0 ? 1 : -1;
3909 /* Save the current focus cell in case we hit the edge */
3910 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3914 gtk_icon_view_set_cell_data (icon_view, item);
3916 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3919 item = find_item (icon_view, item, 0, step);
3925 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3927 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3929 gtk_widget_child_focus (toplevel,
3930 direction == GTK_DIR_LEFT ?
3931 GTK_DIR_TAB_BACKWARD :
3932 GTK_DIR_TAB_FORWARD);
3936 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3940 if (icon_view->priv->ctrl_pressed ||
3941 !icon_view->priv->shift_pressed ||
3942 !icon_view->priv->anchor_item ||
3943 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3944 icon_view->priv->anchor_item = item;
3946 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3947 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3949 if (!icon_view->priv->ctrl_pressed &&
3950 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3952 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3953 dirty = gtk_icon_view_select_all_between (icon_view,
3954 icon_view->priv->anchor_item,
3958 gtk_icon_view_scroll_to_item (icon_view, item);
3961 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3965 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3968 GtkIconViewItem *item;
3970 gboolean dirty = FALSE;
3972 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3976 list = icon_view->priv->items;
3978 list = g_list_last (icon_view->priv->items);
3980 item = list ? list->data : NULL;
3982 if (item == icon_view->priv->cursor_item)
3983 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3988 if (icon_view->priv->ctrl_pressed ||
3989 !icon_view->priv->shift_pressed ||
3990 !icon_view->priv->anchor_item ||
3991 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3992 icon_view->priv->anchor_item = item;
3994 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3996 if (!icon_view->priv->ctrl_pressed &&
3997 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3999 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4000 dirty = gtk_icon_view_select_all_between (icon_view,
4001 icon_view->priv->anchor_item,
4005 gtk_icon_view_scroll_to_item (icon_view, item);
4008 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4012 * gtk_icon_view_scroll_to_path:
4013 * @icon_view: A #GtkIconView.
4014 * @path: The path of the item to move to.
4015 * @use_align: whether to use alignment arguments, or %FALSE.
4016 * @row_align: The vertical alignment of the item specified by @path.
4017 * @col_align: The horizontal alignment of the item specified by @path.
4019 * Moves the alignments of @icon_view to the position specified by @path.
4020 * @row_align determines where the row is placed, and @col_align determines
4021 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4022 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4025 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4026 * tree does the minimum amount of work to scroll the item onto the screen.
4027 * This means that the item will be scrolled to the edge closest to its current
4028 * position. If the item is currently visible on the screen, nothing is done.
4030 * This function only works if the model is set, and @path is a valid row on
4031 * the model. If the model changes before the @icon_view is realized, the
4032 * centered path will be modified to reflect this change.
4037 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4043 GtkIconViewItem *item = NULL;
4046 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4047 g_return_if_fail (path != NULL);
4048 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4049 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4051 widget = GTK_WIDGET (icon_view);
4053 if (gtk_tree_path_get_depth (path) > 0)
4054 item = g_list_nth_data (icon_view->priv->items,
4055 gtk_tree_path_get_indices(path)[0]);
4057 if (!item || item->cell_area.width < 0 ||
4058 !gtk_widget_get_realized (widget))
4060 if (icon_view->priv->scroll_to_path)
4061 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4063 icon_view->priv->scroll_to_path = NULL;
4066 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4068 icon_view->priv->scroll_to_use_align = use_align;
4069 icon_view->priv->scroll_to_row_align = row_align;
4070 icon_view->priv->scroll_to_col_align = col_align;
4077 GtkAllocation allocation;
4080 GdkRectangle item_area =
4082 item->cell_area.x - icon_view->priv->item_padding,
4083 item->cell_area.y - icon_view->priv->item_padding,
4084 item->cell_area.width + icon_view->priv->item_padding * 2,
4085 item->cell_area.height + icon_view->priv->item_padding * 2
4088 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4090 gtk_widget_get_allocation (widget, &allocation);
4092 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4094 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4095 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4097 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4099 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4100 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4102 gtk_adjustment_changed (icon_view->priv->hadjustment);
4103 gtk_adjustment_changed (icon_view->priv->vadjustment);
4106 gtk_icon_view_scroll_to_item (icon_view, item);
4111 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4112 GtkIconViewItem *item)
4114 GtkIconViewPrivate *priv = icon_view->priv;
4115 GtkWidget *widget = GTK_WIDGET (icon_view);
4116 GtkAdjustment *hadj, *vadj;
4117 GtkAllocation allocation;
4119 GdkRectangle item_area;
4121 item_area.x = item->cell_area.x - priv->item_padding;
4122 item_area.y = item->cell_area.y - priv->item_padding;
4123 item_area.width = item->cell_area.width + priv->item_padding * 2;
4124 item_area.height = item->cell_area.height + priv->item_padding * 2;
4126 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4127 gtk_widget_get_allocation (widget, &allocation);
4129 hadj = icon_view->priv->hadjustment;
4130 vadj = icon_view->priv->vadjustment;
4132 if (y + item_area.y < 0)
4133 gtk_adjustment_set_value (vadj,
4134 gtk_adjustment_get_value (vadj)
4136 else if (y + item_area.y + item_area.height > allocation.height)
4137 gtk_adjustment_set_value (vadj,
4138 gtk_adjustment_get_value (vadj)
4139 + y + item_area.y + item_area.height - allocation.height);
4141 if (x + item_area.x < 0)
4142 gtk_adjustment_set_value (hadj,
4143 gtk_adjustment_get_value (hadj)
4145 else if (x + item_area.x + item_area.width > allocation.width)
4146 gtk_adjustment_set_value (hadj,
4147 gtk_adjustment_get_value (hadj)
4148 + x + item_area.x + item_area.width - allocation.width);
4150 gtk_adjustment_changed (hadj);
4151 gtk_adjustment_changed (vadj);
4154 /* GtkCellLayout implementation */
4157 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4158 GtkCellArea *cell_area)
4160 GtkIconViewPrivate *priv = icon_view->priv;
4162 if (priv->cell_area)
4166 priv->cell_area = cell_area;
4168 priv->cell_area = gtk_cell_area_box_new ();
4170 g_object_ref_sink (priv->cell_area);
4172 if (GTK_IS_ORIENTABLE (priv->cell_area))
4173 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4175 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4177 priv->add_editable_id =
4178 g_signal_connect (priv->cell_area, "add-editable",
4179 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4180 priv->remove_editable_id =
4181 g_signal_connect (priv->cell_area, "remove-editable",
4182 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4183 priv->context_changed_id =
4184 g_signal_connect (priv->cell_area_context, "notify",
4185 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4187 update_text_cell (icon_view);
4188 update_pixbuf_cell (icon_view);
4191 static GtkCellArea *
4192 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4194 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4195 GtkIconViewPrivate *priv = icon_view->priv;
4197 if (G_UNLIKELY (!priv->cell_area))
4198 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4200 return icon_view->priv->cell_area;
4204 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4205 GtkIconViewItem *item)
4207 gboolean iters_persist;
4210 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4216 path = gtk_tree_path_new_from_indices (item->index, -1);
4217 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4219 gtk_tree_path_free (path);
4224 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4225 icon_view->priv->model,
4226 &iter, FALSE, FALSE);
4235 * gtk_icon_view_new:
4237 * Creates a new #GtkIconView widget
4239 * Return value: A newly created #GtkIconView widget
4244 gtk_icon_view_new (void)
4246 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4250 * gtk_icon_view_new_with_area:
4251 * @area: the #GtkCellArea to use to layout cells
4253 * Creates a new #GtkIconView widget using the
4254 * specified @area to layout cells inside the icons.
4256 * Return value: A newly created #GtkIconView widget
4261 gtk_icon_view_new_with_area (GtkCellArea *area)
4263 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4267 * gtk_icon_view_new_with_model:
4268 * @model: The model.
4270 * Creates a new #GtkIconView widget with the model @model.
4272 * Return value: A newly created #GtkIconView widget.
4277 gtk_icon_view_new_with_model (GtkTreeModel *model)
4279 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4283 * gtk_icon_view_convert_widget_to_bin_window_coords:
4284 * @icon_view: a #GtkIconView
4285 * @wx: X coordinate relative to the widget
4286 * @wy: Y coordinate relative to the widget
4287 * @bx: (out): return location for bin_window X coordinate
4288 * @by: (out): return location for bin_window Y coordinate
4290 * Converts widget coordinates to coordinates for the bin_window,
4291 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4296 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4304 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4306 if (icon_view->priv->bin_window)
4307 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4318 * gtk_icon_view_get_path_at_pos:
4319 * @icon_view: A #GtkIconView.
4320 * @x: The x position to be identified
4321 * @y: The y position to be identified
4323 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4324 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4325 * the cell at the specified position.
4326 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4327 * widget coordinates to bin_window coordinates.
4329 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4330 * if no icon exists at that position.
4335 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4339 GtkIconViewItem *item;
4342 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4344 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4349 path = gtk_tree_path_new_from_indices (item->index, -1);
4355 * gtk_icon_view_get_item_at_pos:
4356 * @icon_view: A #GtkIconView.
4357 * @x: The x position to be identified
4358 * @y: The y position to be identified
4359 * @path: (out) (allow-none): Return location for the path, or %NULL
4360 * @cell: (out) (allow-none): Return location for the renderer
4361 * responsible for the cell at (@x, @y), or %NULL
4363 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4364 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4365 * obtains the cell at the specified position. The returned path should
4366 * be freed with gtk_tree_path_free().
4367 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4368 * widget coordinates to bin_window coordinates.
4370 * Return value: %TRUE if an item exists at the specified position
4375 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4379 GtkCellRenderer **cell)
4381 GtkIconViewItem *item;
4382 GtkCellRenderer *renderer = NULL;
4384 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4386 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4391 *path = gtk_tree_path_new_from_indices (item->index, -1);
4399 return (item != NULL);
4403 * gtk_icon_view_set_tooltip_item:
4404 * @icon_view: a #GtkIconView
4405 * @tooltip: a #GtkTooltip
4406 * @path: a #GtkTreePath
4408 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4409 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4410 * See also gtk_tooltip_set_tip_area().
4415 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4416 GtkTooltip *tooltip,
4419 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4420 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4422 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4426 * gtk_icon_view_set_tooltip_cell:
4427 * @icon_view: a #GtkIconView
4428 * @tooltip: a #GtkTooltip
4429 * @path: a #GtkTreePath
4430 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4432 * Sets the tip area of @tooltip to the area which @cell occupies in
4433 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4435 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4440 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4441 GtkTooltip *tooltip,
4443 GtkCellRenderer *cell)
4446 GtkIconViewItem *item = NULL;
4449 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4450 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4451 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4453 if (gtk_tree_path_get_depth (path) > 0)
4454 item = g_list_nth_data (icon_view->priv->items,
4455 gtk_tree_path_get_indices(path)[0]);
4462 GtkCellAreaContext *context;
4464 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4465 gtk_icon_view_set_cell_data (icon_view, item);
4466 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4467 GTK_WIDGET (icon_view),
4468 cell, (GdkRectangle *)item, &rect);
4472 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4473 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4474 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4475 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4478 if (icon_view->priv->bin_window)
4480 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4485 gtk_tooltip_set_tip_area (tooltip, &rect);
4490 * gtk_icon_view_get_tooltip_context:
4491 * @icon_view: an #GtkIconView
4492 * @x: (inout): the x coordinate (relative to widget coordinates)
4493 * @y: (inout): the y coordinate (relative to widget coordinates)
4494 * @keyboard_tip: whether this is a keyboard tooltip or not
4495 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4496 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4497 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4499 * This function is supposed to be used in a #GtkWidget::query-tooltip
4500 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4501 * which are received in the signal handler, should be passed to this
4502 * function without modification.
4504 * The return value indicates whether there is an icon view item at the given
4505 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4506 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4507 * @model, @path and @iter which have been provided will be set to point to
4508 * that row and the corresponding model. @x and @y will always be converted
4509 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4511 * Return value: whether or not the given tooltip context points to a item
4516 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4519 gboolean keyboard_tip,
4520 GtkTreeModel **model,
4524 GtkTreePath *tmppath = NULL;
4526 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4527 g_return_val_if_fail (x != NULL, FALSE);
4528 g_return_val_if_fail (y != NULL, FALSE);
4532 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4539 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4542 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4547 *model = gtk_icon_view_get_model (icon_view);
4550 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4556 gtk_tree_path_free (tmppath);
4562 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4565 gboolean keyboard_tip,
4566 GtkTooltip *tooltip,
4572 GtkTreeModel *model;
4573 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4575 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4578 &model, &path, &iter))
4581 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4585 gtk_tree_path_free (path);
4589 gtk_tooltip_set_markup (tooltip, str);
4590 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4592 gtk_tree_path_free (path);
4600 * gtk_icon_view_set_tooltip_column:
4601 * @icon_view: a #GtkIconView
4602 * @column: an integer, which is a valid column number for @icon_view's model
4604 * If you only plan to have simple (text-only) tooltips on full items, you
4605 * can use this function to have #GtkIconView handle these automatically
4606 * for you. @column should be set to the column in @icon_view's model
4607 * containing the tooltip texts, or -1 to disable this feature.
4609 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4610 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4612 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4613 * so &, <, etc have to be escaped in the text.
4618 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4621 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4623 if (column == icon_view->priv->tooltip_column)
4628 g_signal_handlers_disconnect_by_func (icon_view,
4629 gtk_icon_view_set_tooltip_query_cb,
4631 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4635 if (icon_view->priv->tooltip_column == -1)
4637 g_signal_connect (icon_view, "query-tooltip",
4638 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4639 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4643 icon_view->priv->tooltip_column = column;
4644 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4648 * gtk_icon_view_get_tooltip_column:
4649 * @icon_view: a #GtkIconView
4651 * Returns the column of @icon_view's model which is being used for
4652 * displaying tooltips on @icon_view's rows.
4654 * Return value: the index of the tooltip column that is currently being
4655 * used, or -1 if this is disabled.
4660 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4662 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4664 return icon_view->priv->tooltip_column;
4668 * gtk_icon_view_get_visible_range:
4669 * @icon_view: A #GtkIconView
4670 * @start_path: (out) (allow-none): Return location for start of region,
4672 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4674 * Sets @start_path and @end_path to be the first and last visible path.
4675 * Note that there may be invisible paths in between.
4677 * Both paths should be freed with gtk_tree_path_free() after use.
4679 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4684 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4685 GtkTreePath **start_path,
4686 GtkTreePath **end_path)
4688 gint start_index = -1;
4689 gint end_index = -1;
4692 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4694 if (icon_view->priv->hadjustment == NULL ||
4695 icon_view->priv->vadjustment == NULL)
4698 if (start_path == NULL && end_path == NULL)
4701 for (icons = icon_view->priv->items; icons; icons = icons->next)
4703 GtkIconViewItem *item = icons->data;
4704 GdkRectangle *item_area = (GdkRectangle *)item;
4706 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4707 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4709 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4710 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4712 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4713 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4715 if (start_index == -1)
4716 start_index = item->index;
4717 end_index = item->index;
4721 if (start_path && start_index != -1)
4722 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4723 if (end_path && end_index != -1)
4724 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4726 return start_index != -1;
4730 * gtk_icon_view_selected_foreach:
4731 * @icon_view: A #GtkIconView.
4732 * @func: (scope call): The function to call for each selected icon.
4733 * @data: User data to pass to the function.
4735 * Calls a function for each selected icon. Note that the model or
4736 * selection cannot be modified from within this function.
4741 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4742 GtkIconViewForeachFunc func,
4747 for (list = icon_view->priv->items; list; list = list->next)
4749 GtkIconViewItem *item = list->data;
4750 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4753 (* func) (icon_view, path, data);
4755 gtk_tree_path_free (path);
4760 * gtk_icon_view_set_selection_mode:
4761 * @icon_view: A #GtkIconView.
4762 * @mode: The selection mode
4764 * Sets the selection mode of the @icon_view.
4769 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4770 GtkSelectionMode mode)
4772 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4774 if (mode == icon_view->priv->selection_mode)
4777 if (mode == GTK_SELECTION_NONE ||
4778 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4779 gtk_icon_view_unselect_all (icon_view);
4781 icon_view->priv->selection_mode = mode;
4783 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4787 * gtk_icon_view_get_selection_mode:
4788 * @icon_view: A #GtkIconView.
4790 * Gets the selection mode of the @icon_view.
4792 * Return value: the current selection mode
4797 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4799 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4801 return icon_view->priv->selection_mode;
4805 * gtk_icon_view_set_model:
4806 * @icon_view: A #GtkIconView.
4807 * @model: (allow-none): The model.
4809 * Sets the model for a #GtkIconView.
4810 * If the @icon_view already has a model set, it will remove
4811 * it before setting the new model. If @model is %NULL, then
4812 * it will unset the old model.
4817 gtk_icon_view_set_model (GtkIconView *icon_view,
4818 GtkTreeModel *model)
4820 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4821 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4823 if (icon_view->priv->model == model)
4826 if (icon_view->priv->scroll_to_path)
4828 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4829 icon_view->priv->scroll_to_path = NULL;
4832 /* The area can be NULL while disposing */
4833 if (icon_view->priv->cell_area)
4834 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4840 if (icon_view->priv->pixbuf_column != -1)
4842 column_type = gtk_tree_model_get_column_type (model,
4843 icon_view->priv->pixbuf_column);
4845 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4848 if (icon_view->priv->text_column != -1)
4850 column_type = gtk_tree_model_get_column_type (model,
4851 icon_view->priv->text_column);
4853 g_return_if_fail (column_type == G_TYPE_STRING);
4856 if (icon_view->priv->markup_column != -1)
4858 column_type = gtk_tree_model_get_column_type (model,
4859 icon_view->priv->markup_column);
4861 g_return_if_fail (column_type == G_TYPE_STRING);
4866 if (icon_view->priv->model)
4868 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4869 gtk_icon_view_row_changed,
4871 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4872 gtk_icon_view_row_inserted,
4874 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4875 gtk_icon_view_row_deleted,
4877 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4878 gtk_icon_view_rows_reordered,
4881 g_object_unref (icon_view->priv->model);
4883 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4884 g_list_free (icon_view->priv->items);
4885 icon_view->priv->items = NULL;
4886 icon_view->priv->anchor_item = NULL;
4887 icon_view->priv->cursor_item = NULL;
4888 icon_view->priv->last_single_clicked = NULL;
4889 icon_view->priv->last_prelight = NULL;
4890 icon_view->priv->width = 0;
4891 icon_view->priv->height = 0;
4894 icon_view->priv->model = model;
4896 if (icon_view->priv->model)
4898 g_object_ref (icon_view->priv->model);
4899 g_signal_connect (icon_view->priv->model,
4901 G_CALLBACK (gtk_icon_view_row_changed),
4903 g_signal_connect (icon_view->priv->model,
4905 G_CALLBACK (gtk_icon_view_row_inserted),
4907 g_signal_connect (icon_view->priv->model,
4909 G_CALLBACK (gtk_icon_view_row_deleted),
4911 g_signal_connect (icon_view->priv->model,
4913 G_CALLBACK (gtk_icon_view_rows_reordered),
4916 gtk_icon_view_build_items (icon_view);
4918 gtk_icon_view_queue_layout (icon_view);
4921 g_object_notify (G_OBJECT (icon_view), "model");
4923 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4924 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4928 * gtk_icon_view_get_model:
4929 * @icon_view: a #GtkIconView
4931 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4934 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4935 * currently being used.
4940 gtk_icon_view_get_model (GtkIconView *icon_view)
4942 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4944 return icon_view->priv->model;
4948 update_text_cell (GtkIconView *icon_view)
4950 if (!icon_view->priv->cell_area)
4953 if (icon_view->priv->text_column == -1 &&
4954 icon_view->priv->markup_column == -1)
4956 if (icon_view->priv->text_cell != NULL)
4958 gtk_cell_area_remove (icon_view->priv->cell_area,
4959 icon_view->priv->text_cell);
4960 icon_view->priv->text_cell = NULL;
4965 if (icon_view->priv->text_cell == NULL)
4967 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4969 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4972 if (icon_view->priv->markup_column != -1)
4973 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4974 icon_view->priv->text_cell,
4975 "markup", icon_view->priv->markup_column,
4978 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4979 icon_view->priv->text_cell,
4980 "text", icon_view->priv->text_column,
4983 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4984 g_object_set (icon_view->priv->text_cell,
4985 "alignment", PANGO_ALIGN_CENTER,
4986 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4991 g_object_set (icon_view->priv->text_cell,
4992 "alignment", PANGO_ALIGN_LEFT,
4993 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5001 update_pixbuf_cell (GtkIconView *icon_view)
5003 if (!icon_view->priv->cell_area)
5006 if (icon_view->priv->pixbuf_column == -1)
5008 if (icon_view->priv->pixbuf_cell != NULL)
5010 gtk_cell_area_remove (icon_view->priv->cell_area,
5011 icon_view->priv->pixbuf_cell);
5013 icon_view->priv->pixbuf_cell = NULL;
5018 if (icon_view->priv->pixbuf_cell == NULL)
5020 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
5022 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
5025 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5026 icon_view->priv->pixbuf_cell,
5027 "pixbuf", icon_view->priv->pixbuf_column,
5030 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5031 g_object_set (icon_view->priv->pixbuf_cell,
5036 g_object_set (icon_view->priv->pixbuf_cell,
5044 * gtk_icon_view_set_text_column:
5045 * @icon_view: A #GtkIconView.
5046 * @column: A column in the currently used model, or -1 to display no text
5048 * Sets the column with text for @icon_view to be @column. The text
5049 * column must be of type #G_TYPE_STRING.
5054 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5057 if (column == icon_view->priv->text_column)
5061 icon_view->priv->text_column = -1;
5064 if (icon_view->priv->model != NULL)
5068 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5070 g_return_if_fail (column_type == G_TYPE_STRING);
5073 icon_view->priv->text_column = column;
5076 if (icon_view->priv->cell_area)
5077 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5079 update_text_cell (icon_view);
5081 gtk_icon_view_invalidate_sizes (icon_view);
5083 g_object_notify (G_OBJECT (icon_view), "text-column");
5087 * gtk_icon_view_get_text_column:
5088 * @icon_view: A #GtkIconView.
5090 * Returns the column with text for @icon_view.
5092 * Returns: the text column, or -1 if it's unset.
5097 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5099 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5101 return icon_view->priv->text_column;
5105 * gtk_icon_view_set_markup_column:
5106 * @icon_view: A #GtkIconView.
5107 * @column: A column in the currently used model, or -1 to display no text
5109 * Sets the column with markup information for @icon_view to be
5110 * @column. The markup column must be of type #G_TYPE_STRING.
5111 * If the markup column is set to something, it overrides
5112 * the text column set by gtk_icon_view_set_text_column().
5117 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5120 if (column == icon_view->priv->markup_column)
5124 icon_view->priv->markup_column = -1;
5127 if (icon_view->priv->model != NULL)
5131 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5133 g_return_if_fail (column_type == G_TYPE_STRING);
5136 icon_view->priv->markup_column = column;
5139 if (icon_view->priv->cell_area)
5140 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5142 update_text_cell (icon_view);
5144 gtk_icon_view_invalidate_sizes (icon_view);
5146 g_object_notify (G_OBJECT (icon_view), "markup-column");
5150 * gtk_icon_view_get_markup_column:
5151 * @icon_view: A #GtkIconView.
5153 * Returns the column with markup text for @icon_view.
5155 * Returns: the markup column, or -1 if it's unset.
5160 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5162 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5164 return icon_view->priv->markup_column;
5168 * gtk_icon_view_set_pixbuf_column:
5169 * @icon_view: A #GtkIconView.
5170 * @column: A column in the currently used model, or -1 to disable
5172 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5173 * column must be of type #GDK_TYPE_PIXBUF
5178 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5181 if (column == icon_view->priv->pixbuf_column)
5185 icon_view->priv->pixbuf_column = -1;
5188 if (icon_view->priv->model != NULL)
5192 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5194 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5197 icon_view->priv->pixbuf_column = column;
5200 if (icon_view->priv->cell_area)
5201 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5203 update_pixbuf_cell (icon_view);
5205 gtk_icon_view_invalidate_sizes (icon_view);
5207 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5212 * gtk_icon_view_get_pixbuf_column:
5213 * @icon_view: A #GtkIconView.
5215 * Returns the column with pixbufs for @icon_view.
5217 * Returns: the pixbuf column, or -1 if it's unset.
5222 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5224 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5226 return icon_view->priv->pixbuf_column;
5230 * gtk_icon_view_select_path:
5231 * @icon_view: A #GtkIconView.
5232 * @path: The #GtkTreePath to be selected.
5234 * Selects the row at @path.
5239 gtk_icon_view_select_path (GtkIconView *icon_view,
5242 GtkIconViewItem *item = NULL;
5244 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5245 g_return_if_fail (icon_view->priv->model != NULL);
5246 g_return_if_fail (path != NULL);
5248 if (gtk_tree_path_get_depth (path) > 0)
5249 item = g_list_nth_data (icon_view->priv->items,
5250 gtk_tree_path_get_indices(path)[0]);
5253 gtk_icon_view_select_item (icon_view, item);
5257 * gtk_icon_view_unselect_path:
5258 * @icon_view: A #GtkIconView.
5259 * @path: The #GtkTreePath to be unselected.
5261 * Unselects the row at @path.
5266 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5269 GtkIconViewItem *item;
5271 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5272 g_return_if_fail (icon_view->priv->model != NULL);
5273 g_return_if_fail (path != NULL);
5275 item = g_list_nth_data (icon_view->priv->items,
5276 gtk_tree_path_get_indices(path)[0]);
5281 gtk_icon_view_unselect_item (icon_view, item);
5285 * gtk_icon_view_get_selected_items:
5286 * @icon_view: A #GtkIconView.
5288 * Creates a list of paths of all selected items. Additionally, if you are
5289 * planning on modifying the model after calling this function, you may
5290 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5291 * To do this, you can use gtk_tree_row_reference_new().
5293 * To free the return value, use:
5295 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5296 * g_list_free (list);
5299 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5304 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5307 GList *selected = NULL;
5309 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5311 for (list = icon_view->priv->items; list != NULL; list = list->next)
5313 GtkIconViewItem *item = list->data;
5317 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5319 selected = g_list_prepend (selected, path);
5327 * gtk_icon_view_select_all:
5328 * @icon_view: A #GtkIconView.
5330 * Selects all the icons. @icon_view must has its selection mode set
5331 * to #GTK_SELECTION_MULTIPLE.
5336 gtk_icon_view_select_all (GtkIconView *icon_view)
5339 gboolean dirty = FALSE;
5341 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5343 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5346 for (items = icon_view->priv->items; items; items = items->next)
5348 GtkIconViewItem *item = items->data;
5350 if (!item->selected)
5353 item->selected = TRUE;
5354 gtk_icon_view_queue_draw_item (icon_view, item);
5359 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5363 * gtk_icon_view_unselect_all:
5364 * @icon_view: A #GtkIconView.
5366 * Unselects all the icons.
5371 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5373 gboolean dirty = FALSE;
5375 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5377 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5380 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5383 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5387 * gtk_icon_view_path_is_selected:
5388 * @icon_view: A #GtkIconView.
5389 * @path: A #GtkTreePath to check selection on.
5391 * Returns %TRUE if the icon pointed to by @path is currently
5392 * selected. If @path does not point to a valid location, %FALSE is returned.
5394 * Return value: %TRUE if @path is selected.
5399 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5402 GtkIconViewItem *item;
5404 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5405 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5406 g_return_val_if_fail (path != NULL, FALSE);
5408 item = g_list_nth_data (icon_view->priv->items,
5409 gtk_tree_path_get_indices(path)[0]);
5414 return item->selected;
5418 * gtk_icon_view_get_item_row:
5419 * @icon_view: a #GtkIconView
5420 * @path: the #GtkTreePath of the item
5422 * Gets the row in which the item @path is currently
5423 * displayed. Row numbers start at 0.
5425 * Returns: The row in which the item is displayed
5430 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5433 GtkIconViewItem *item;
5435 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5436 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5437 g_return_val_if_fail (path != NULL, -1);
5439 item = g_list_nth_data (icon_view->priv->items,
5440 gtk_tree_path_get_indices(path)[0]);
5449 * gtk_icon_view_get_item_column:
5450 * @icon_view: a #GtkIconView
5451 * @path: the #GtkTreePath of the item
5453 * Gets the column in which the item @path is currently
5454 * displayed. Column numbers start at 0.
5456 * Returns: The column in which the item is displayed
5461 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5464 GtkIconViewItem *item;
5466 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5467 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5468 g_return_val_if_fail (path != NULL, -1);
5470 item = g_list_nth_data (icon_view->priv->items,
5471 gtk_tree_path_get_indices(path)[0]);
5480 * gtk_icon_view_item_activated:
5481 * @icon_view: A #GtkIconView
5482 * @path: The #GtkTreePath to be activated
5484 * Activates the item determined by @path.
5489 gtk_icon_view_item_activated (GtkIconView *icon_view,
5492 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5493 g_return_if_fail (path != NULL);
5495 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5499 * gtk_icon_view_set_item_orientation:
5500 * @icon_view: a #GtkIconView
5501 * @orientation: the relative position of texts and icons
5503 * Sets the ::item-orientation property which determines whether the labels
5504 * are drawn beside the icons instead of below.
5509 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5510 GtkOrientation orientation)
5512 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5514 if (icon_view->priv->item_orientation != orientation)
5516 icon_view->priv->item_orientation = orientation;
5518 if (icon_view->priv->cell_area)
5520 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5521 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5522 icon_view->priv->item_orientation);
5524 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5527 gtk_icon_view_invalidate_sizes (icon_view);
5529 update_text_cell (icon_view);
5530 update_pixbuf_cell (icon_view);
5532 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5537 * gtk_icon_view_get_item_orientation:
5538 * @icon_view: a #GtkIconView
5540 * Returns the value of the ::item-orientation property which determines
5541 * whether the labels are drawn beside the icons instead of below.
5543 * Return value: the relative position of texts and icons
5548 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5550 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5551 GTK_ORIENTATION_VERTICAL);
5553 return icon_view->priv->item_orientation;
5557 * gtk_icon_view_set_columns:
5558 * @icon_view: a #GtkIconView
5559 * @columns: the number of columns
5561 * Sets the ::columns property which determines in how
5562 * many columns the icons are arranged. If @columns is
5563 * -1, the number of columns will be chosen automatically
5564 * to fill the available area.
5569 gtk_icon_view_set_columns (GtkIconView *icon_view,
5572 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5574 if (icon_view->priv->columns != columns)
5576 icon_view->priv->columns = columns;
5578 if (icon_view->priv->cell_area)
5579 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5581 gtk_icon_view_queue_layout (icon_view);
5583 g_object_notify (G_OBJECT (icon_view), "columns");
5588 * gtk_icon_view_get_columns:
5589 * @icon_view: a #GtkIconView
5591 * Returns the value of the ::columns property.
5593 * Return value: the number of columns, or -1
5598 gtk_icon_view_get_columns (GtkIconView *icon_view)
5600 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5602 return icon_view->priv->columns;
5606 * gtk_icon_view_set_item_width:
5607 * @icon_view: a #GtkIconView
5608 * @item_width: the width for each item
5610 * Sets the ::item-width property which specifies the width
5611 * to use for each item. If it is set to -1, the icon view will
5612 * automatically determine a suitable item size.
5617 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5620 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5622 if (icon_view->priv->item_width != item_width)
5624 icon_view->priv->item_width = item_width;
5626 if (icon_view->priv->cell_area)
5627 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5629 gtk_icon_view_invalidate_sizes (icon_view);
5631 update_text_cell (icon_view);
5633 g_object_notify (G_OBJECT (icon_view), "item-width");
5638 * gtk_icon_view_get_item_width:
5639 * @icon_view: a #GtkIconView
5641 * Returns the value of the ::item-width property.
5643 * Return value: the width of a single item, or -1
5648 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5650 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5652 return icon_view->priv->item_width;
5657 * gtk_icon_view_set_spacing:
5658 * @icon_view: a #GtkIconView
5659 * @spacing: the spacing
5661 * Sets the ::spacing property which specifies the space
5662 * which is inserted between the cells (i.e. the icon and
5663 * the text) of an item.
5668 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5671 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5673 if (icon_view->priv->spacing != spacing)
5675 icon_view->priv->spacing = spacing;
5677 if (icon_view->priv->cell_area)
5678 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5680 gtk_icon_view_invalidate_sizes (icon_view);
5682 g_object_notify (G_OBJECT (icon_view), "spacing");
5687 * gtk_icon_view_get_spacing:
5688 * @icon_view: a #GtkIconView
5690 * Returns the value of the ::spacing property.
5692 * Return value: the space between cells
5697 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5699 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5701 return icon_view->priv->spacing;
5705 * gtk_icon_view_set_row_spacing:
5706 * @icon_view: a #GtkIconView
5707 * @row_spacing: the row spacing
5709 * Sets the ::row-spacing property which specifies the space
5710 * which is inserted between the rows of the icon view.
5715 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5718 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5720 if (icon_view->priv->row_spacing != row_spacing)
5722 icon_view->priv->row_spacing = row_spacing;
5724 if (icon_view->priv->cell_area)
5725 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5727 gtk_icon_view_invalidate_sizes (icon_view);
5729 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5734 * gtk_icon_view_get_row_spacing:
5735 * @icon_view: a #GtkIconView
5737 * Returns the value of the ::row-spacing property.
5739 * Return value: the space between rows
5744 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5746 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5748 return icon_view->priv->row_spacing;
5752 * gtk_icon_view_set_column_spacing:
5753 * @icon_view: a #GtkIconView
5754 * @column_spacing: the column spacing
5756 * Sets the ::column-spacing property which specifies the space
5757 * which is inserted between the columns of the icon view.
5762 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5763 gint column_spacing)
5765 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5767 if (icon_view->priv->column_spacing != column_spacing)
5769 icon_view->priv->column_spacing = column_spacing;
5771 if (icon_view->priv->cell_area)
5772 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5774 gtk_icon_view_invalidate_sizes (icon_view);
5776 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5781 * gtk_icon_view_get_column_spacing:
5782 * @icon_view: a #GtkIconView
5784 * Returns the value of the ::column-spacing property.
5786 * Return value: the space between columns
5791 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5793 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5795 return icon_view->priv->column_spacing;
5799 * gtk_icon_view_set_margin:
5800 * @icon_view: a #GtkIconView
5801 * @margin: the margin
5803 * Sets the ::margin property which specifies the space
5804 * which is inserted at the top, bottom, left and right
5810 gtk_icon_view_set_margin (GtkIconView *icon_view,
5813 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5815 if (icon_view->priv->margin != margin)
5817 icon_view->priv->margin = margin;
5819 if (icon_view->priv->cell_area)
5820 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5822 gtk_icon_view_invalidate_sizes (icon_view);
5824 g_object_notify (G_OBJECT (icon_view), "margin");
5829 * gtk_icon_view_get_margin:
5830 * @icon_view: a #GtkIconView
5832 * Returns the value of the ::margin property.
5834 * Return value: the space at the borders
5839 gtk_icon_view_get_margin (GtkIconView *icon_view)
5841 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5843 return icon_view->priv->margin;
5847 * gtk_icon_view_set_item_padding:
5848 * @icon_view: a #GtkIconView
5849 * @item_padding: the item padding
5851 * Sets the #GtkIconView:item-padding property which specifies the padding
5852 * around each of the icon view's items.
5857 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5860 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5862 if (icon_view->priv->item_padding != item_padding)
5864 icon_view->priv->item_padding = item_padding;
5866 if (icon_view->priv->cell_area)
5867 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5869 gtk_icon_view_invalidate_sizes (icon_view);
5871 g_object_notify (G_OBJECT (icon_view), "item-padding");
5876 * gtk_icon_view_get_item_padding:
5877 * @icon_view: a #GtkIconView
5879 * Returns the value of the ::item-padding property.
5881 * Return value: the padding around items
5886 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5888 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5890 return icon_view->priv->item_padding;
5893 /* Get/set whether drag_motion requested the drag data and
5894 * drag_data_received should thus not actually insert the data,
5895 * since the data doesn't result from a drop.
5898 set_status_pending (GdkDragContext *context,
5899 GdkDragAction suggested_action)
5901 g_object_set_data (G_OBJECT (context),
5902 I_("gtk-icon-view-status-pending"),
5903 GINT_TO_POINTER (suggested_action));
5906 static GdkDragAction
5907 get_status_pending (GdkDragContext *context)
5909 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5910 "gtk-icon-view-status-pending"));
5914 unset_reorderable (GtkIconView *icon_view)
5916 if (icon_view->priv->reorderable)
5918 icon_view->priv->reorderable = FALSE;
5919 g_object_notify (G_OBJECT (icon_view), "reorderable");
5924 set_source_row (GdkDragContext *context,
5925 GtkTreeModel *model,
5926 GtkTreePath *source_row)
5929 g_object_set_data_full (G_OBJECT (context),
5930 I_("gtk-icon-view-source-row"),
5931 gtk_tree_row_reference_new (model, source_row),
5932 (GDestroyNotify) gtk_tree_row_reference_free);
5934 g_object_set_data_full (G_OBJECT (context),
5935 I_("gtk-icon-view-source-row"),
5940 get_source_row (GdkDragContext *context)
5942 GtkTreeRowReference *ref;
5944 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5947 return gtk_tree_row_reference_get_path (ref);
5954 GtkTreeRowReference *dest_row;
5955 gboolean empty_view_drop;
5956 gboolean drop_append_mode;
5960 dest_row_free (gpointer data)
5962 DestRow *dr = (DestRow *)data;
5964 gtk_tree_row_reference_free (dr->dest_row);
5969 set_dest_row (GdkDragContext *context,
5970 GtkTreeModel *model,
5971 GtkTreePath *dest_row,
5972 gboolean empty_view_drop,
5973 gboolean drop_append_mode)
5979 g_object_set_data_full (G_OBJECT (context),
5980 I_("gtk-icon-view-dest-row"),
5985 dr = g_new0 (DestRow, 1);
5987 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5988 dr->empty_view_drop = empty_view_drop;
5989 dr->drop_append_mode = drop_append_mode;
5990 g_object_set_data_full (G_OBJECT (context),
5991 I_("gtk-icon-view-dest-row"),
5992 dr, (GDestroyNotify) dest_row_free);
5996 get_dest_row (GdkDragContext *context)
6000 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6004 GtkTreePath *path = NULL;
6007 path = gtk_tree_row_reference_get_path (dr->dest_row);
6008 else if (dr->empty_view_drop)
6009 path = gtk_tree_path_new_from_indices (0, -1);
6013 if (path && dr->drop_append_mode)
6014 gtk_tree_path_next (path);
6023 check_model_dnd (GtkTreeModel *model,
6024 GType required_iface,
6025 const gchar *signal)
6027 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6029 g_warning ("You must override the default '%s' handler "
6030 "on GtkIconView when using models that don't support "
6031 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6032 "is to connect to '%s' and call "
6033 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6034 "the default handler from running. Look at the source code "
6035 "for the default handler in gtkiconview.c to get an idea what "
6036 "your handler should do. (gtkiconview.c is in the GTK+ source "
6037 "code.) If you're using GTK+ from a language other than C, "
6038 "there may be a more natural way to override default handlers, e.g. via derivation.",
6039 signal, g_type_name (required_iface), signal);
6047 remove_scroll_timeout (GtkIconView *icon_view)
6049 if (icon_view->priv->scroll_timeout_id != 0)
6051 g_source_remove (icon_view->priv->scroll_timeout_id);
6053 icon_view->priv->scroll_timeout_id = 0;
6058 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6061 gint px, py, x, y, width, height;
6062 gint hoffset, voffset;
6064 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6066 gdk_window_get_pointer (window, &px, &py, NULL);
6067 gdk_window_get_geometry (window, &x, &y, &width, &height);
6069 /* see if we are near the edge. */
6070 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6072 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6074 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6076 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6079 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6080 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6083 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6084 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6089 drag_scroll_timeout (gpointer data)
6091 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6093 gtk_icon_view_autoscroll (icon_view);
6100 set_destination (GtkIconView *icon_view,
6101 GdkDragContext *context,
6104 GdkDragAction *suggested_action,
6108 GtkTreePath *path = NULL;
6109 GtkIconViewDropPosition pos;
6110 GtkIconViewDropPosition old_pos;
6111 GtkTreePath *old_dest_path = NULL;
6112 gboolean can_drop = FALSE;
6114 widget = GTK_WIDGET (icon_view);
6116 *suggested_action = 0;
6119 if (!icon_view->priv->dest_set)
6121 /* someone unset us as a drag dest, note that if
6122 * we return FALSE drag_leave isn't called
6125 gtk_icon_view_set_drag_dest_item (icon_view,
6127 GTK_ICON_VIEW_DROP_LEFT);
6129 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6131 return FALSE; /* no longer a drop site */
6134 *target = gtk_drag_dest_find_target (widget, context,
6135 gtk_drag_dest_get_target_list (widget));
6136 if (*target == GDK_NONE)
6139 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6142 GtkTreeModel *model;
6144 /* the row got dropped on empty space, let's setup a special case
6148 gtk_tree_path_free (path);
6150 model = gtk_icon_view_get_model (icon_view);
6152 n_children = gtk_tree_model_iter_n_children (model, NULL);
6155 pos = GTK_ICON_VIEW_DROP_BELOW;
6156 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6160 pos = GTK_ICON_VIEW_DROP_ABOVE;
6161 path = gtk_tree_path_new_from_indices (0, -1);
6171 gtk_icon_view_get_drag_dest_item (icon_view,
6176 gtk_tree_path_free (old_dest_path);
6178 if (TRUE /* FIXME if the location droppable predicate */)
6186 GtkWidget *source_widget;
6188 *suggested_action = gdk_drag_context_get_suggested_action (context);
6189 source_widget = gtk_drag_get_source_widget (context);
6191 if (source_widget == widget)
6193 /* Default to MOVE, unless the user has
6194 * pressed ctrl or shift to affect available actions
6196 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6197 *suggested_action = GDK_ACTION_MOVE;
6200 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6205 /* can't drop here */
6206 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6208 GTK_ICON_VIEW_DROP_LEFT);
6212 gtk_tree_path_free (path);
6218 get_logical_destination (GtkIconView *icon_view,
6219 gboolean *drop_append_mode)
6221 /* adjust path to point to the row the drop goes in front of */
6222 GtkTreePath *path = NULL;
6223 GtkIconViewDropPosition pos;
6225 *drop_append_mode = FALSE;
6227 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6232 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6233 pos == GTK_ICON_VIEW_DROP_BELOW)
6236 GtkTreeModel *model = icon_view->priv->model;
6238 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6239 !gtk_tree_model_iter_next (model, &iter))
6240 *drop_append_mode = TRUE;
6243 *drop_append_mode = FALSE;
6244 gtk_tree_path_next (path);
6252 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6253 GdkEventMotion *event)
6255 GtkWidget *widget = GTK_WIDGET (icon_view);
6256 GdkDragContext *context;
6257 GtkTreePath *path = NULL;
6259 GtkTreeModel *model;
6260 gboolean retval = FALSE;
6262 if (!icon_view->priv->source_set)
6265 if (icon_view->priv->pressed_button < 0)
6268 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6269 icon_view->priv->press_start_x,
6270 icon_view->priv->press_start_y,
6271 event->x, event->y))
6274 model = gtk_icon_view_get_model (icon_view);
6279 button = icon_view->priv->pressed_button;
6280 icon_view->priv->pressed_button = -1;
6282 path = gtk_icon_view_get_path_at_pos (icon_view,
6283 icon_view->priv->press_start_x,
6284 icon_view->priv->press_start_y);
6289 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6290 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6294 /* FIXME Check whether we're a start button, if not return FALSE and
6298 /* Now we can begin the drag */
6302 context = gtk_drag_begin (widget,
6303 gtk_drag_source_get_target_list (widget),
6304 icon_view->priv->source_actions,
6308 set_source_row (context, model, path);
6312 gtk_tree_path_free (path);
6317 /* Source side drag signals */
6319 gtk_icon_view_drag_begin (GtkWidget *widget,
6320 GdkDragContext *context)
6322 GtkIconView *icon_view;
6323 GtkIconViewItem *item;
6324 cairo_surface_t *icon;
6328 icon_view = GTK_ICON_VIEW (widget);
6330 /* if the user uses a custom DnD impl, we don't set the icon here */
6331 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6334 item = gtk_icon_view_get_item_at_coords (icon_view,
6335 icon_view->priv->press_start_x,
6336 icon_view->priv->press_start_y,
6340 g_return_if_fail (item != NULL);
6342 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6343 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6345 path = gtk_tree_path_new_from_indices (item->index, -1);
6346 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6347 gtk_tree_path_free (path);
6349 cairo_surface_set_device_offset (icon, -x, -y);
6351 gtk_drag_set_icon_surface (context, icon);
6353 cairo_surface_destroy (icon);
6357 gtk_icon_view_drag_end (GtkWidget *widget,
6358 GdkDragContext *context)
6364 gtk_icon_view_drag_data_get (GtkWidget *widget,
6365 GdkDragContext *context,
6366 GtkSelectionData *selection_data,
6370 GtkIconView *icon_view;
6371 GtkTreeModel *model;
6372 GtkTreePath *source_row;
6374 icon_view = GTK_ICON_VIEW (widget);
6375 model = gtk_icon_view_get_model (icon_view);
6380 if (!icon_view->priv->source_set)
6383 source_row = get_source_row (context);
6385 if (source_row == NULL)
6388 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6389 * any model; for DragSource models there are some other targets
6393 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6394 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6399 /* If drag_data_get does nothing, try providing row data. */
6400 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6401 gtk_tree_set_row_drag_data (selection_data,
6406 gtk_tree_path_free (source_row);
6410 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6411 GdkDragContext *context)
6413 GtkTreeModel *model;
6414 GtkIconView *icon_view;
6415 GtkTreePath *source_row;
6417 icon_view = GTK_ICON_VIEW (widget);
6418 model = gtk_icon_view_get_model (icon_view);
6420 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6423 if (!icon_view->priv->source_set)
6426 source_row = get_source_row (context);
6428 if (source_row == NULL)
6431 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6434 gtk_tree_path_free (source_row);
6436 set_source_row (context, NULL, NULL);
6439 /* Target side drag signals */
6441 gtk_icon_view_drag_leave (GtkWidget *widget,
6442 GdkDragContext *context,
6445 GtkIconView *icon_view;
6447 icon_view = GTK_ICON_VIEW (widget);
6449 /* unset any highlight row */
6450 gtk_icon_view_set_drag_dest_item (icon_view,
6452 GTK_ICON_VIEW_DROP_LEFT);
6454 remove_scroll_timeout (icon_view);
6458 gtk_icon_view_drag_motion (GtkWidget *widget,
6459 GdkDragContext *context,
6464 GtkTreePath *path = NULL;
6465 GtkIconViewDropPosition pos;
6466 GtkIconView *icon_view;
6467 GdkDragAction suggested_action = 0;
6471 icon_view = GTK_ICON_VIEW (widget);
6473 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6476 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6478 /* we only know this *after* set_desination_row */
6479 empty = icon_view->priv->empty_view_drop;
6481 if (path == NULL && !empty)
6483 /* Can't drop here. */
6484 gdk_drag_status (context, 0, time);
6488 if (icon_view->priv->scroll_timeout_id == 0)
6490 icon_view->priv->scroll_timeout_id =
6491 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6494 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6496 /* Request data so we can use the source row when
6497 * determining whether to accept the drop
6499 set_status_pending (context, suggested_action);
6500 gtk_drag_get_data (widget, context, target, time);
6504 set_status_pending (context, 0);
6505 gdk_drag_status (context, suggested_action, time);
6510 gtk_tree_path_free (path);
6516 gtk_icon_view_drag_drop (GtkWidget *widget,
6517 GdkDragContext *context,
6522 GtkIconView *icon_view;
6524 GdkDragAction suggested_action = 0;
6525 GdkAtom target = GDK_NONE;
6526 GtkTreeModel *model;
6527 gboolean drop_append_mode;
6529 icon_view = GTK_ICON_VIEW (widget);
6530 model = gtk_icon_view_get_model (icon_view);
6532 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6534 if (!icon_view->priv->dest_set)
6537 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6540 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6543 path = get_logical_destination (icon_view, &drop_append_mode);
6545 if (target != GDK_NONE && path != NULL)
6547 /* in case a motion had requested drag data, change things so we
6548 * treat drag data receives as a drop.
6550 set_status_pending (context, 0);
6551 set_dest_row (context, model, path,
6552 icon_view->priv->empty_view_drop, drop_append_mode);
6556 gtk_tree_path_free (path);
6558 /* Unset this thing */
6559 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6561 if (target != GDK_NONE)
6563 gtk_drag_get_data (widget, context, target, time);
6571 gtk_icon_view_drag_data_received (GtkWidget *widget,
6572 GdkDragContext *context,
6575 GtkSelectionData *selection_data,
6580 gboolean accepted = FALSE;
6581 GtkTreeModel *model;
6582 GtkIconView *icon_view;
6583 GtkTreePath *dest_row;
6584 GdkDragAction suggested_action;
6585 gboolean drop_append_mode;
6587 icon_view = GTK_ICON_VIEW (widget);
6588 model = gtk_icon_view_get_model (icon_view);
6590 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6593 if (!icon_view->priv->dest_set)
6596 suggested_action = get_status_pending (context);
6598 if (suggested_action)
6600 /* We are getting this data due to a request in drag_motion,
6601 * rather than due to a request in drag_drop, so we are just
6602 * supposed to call drag_status, not actually paste in the
6605 path = get_logical_destination (icon_view, &drop_append_mode);
6608 suggested_action = 0;
6610 if (suggested_action)
6612 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6615 suggested_action = 0;
6618 gdk_drag_status (context, suggested_action, time);
6621 gtk_tree_path_free (path);
6623 /* If you can't drop, remove user drop indicator until the next motion */
6624 if (suggested_action == 0)
6625 gtk_icon_view_set_drag_dest_item (icon_view,
6627 GTK_ICON_VIEW_DROP_LEFT);
6632 dest_row = get_dest_row (context);
6634 if (dest_row == NULL)
6637 if (gtk_selection_data_get_length (selection_data) >= 0)
6639 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6645 gtk_drag_finish (context,
6647 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6650 gtk_tree_path_free (dest_row);
6653 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6656 /* Drag-and-Drop support */
6658 * gtk_icon_view_enable_model_drag_source:
6659 * @icon_view: a #GtkIconTreeView
6660 * @start_button_mask: Mask of allowed buttons to start drag
6661 * @targets: (array length=n_targets): the table of targets that the drag will
6663 * @n_targets: the number of items in @targets
6664 * @actions: the bitmask of possible actions for a drag from this
6667 * Turns @icon_view into a drag source for automatic DND. Calling this
6668 * method sets #GtkIconView:reorderable to %FALSE.
6673 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6674 GdkModifierType start_button_mask,
6675 const GtkTargetEntry *targets,
6677 GdkDragAction actions)
6679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6681 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6683 icon_view->priv->start_button_mask = start_button_mask;
6684 icon_view->priv->source_actions = actions;
6686 icon_view->priv->source_set = TRUE;
6688 unset_reorderable (icon_view);
6692 * gtk_icon_view_enable_model_drag_dest:
6693 * @icon_view: a #GtkIconView
6694 * @targets: (array length=n_targets): the table of targets that the drag will
6696 * @n_targets: the number of items in @targets
6697 * @actions: the bitmask of possible actions for a drag to this
6700 * Turns @icon_view into a drop destination for automatic DND. Calling this
6701 * method sets #GtkIconView:reorderable to %FALSE.
6706 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6707 const GtkTargetEntry *targets,
6709 GdkDragAction actions)
6711 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6713 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6715 icon_view->priv->dest_actions = actions;
6717 icon_view->priv->dest_set = TRUE;
6719 unset_reorderable (icon_view);
6723 * gtk_icon_view_unset_model_drag_source:
6724 * @icon_view: a #GtkIconView
6726 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6727 * method sets #GtkIconView:reorderable to %FALSE.
6732 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6734 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6736 if (icon_view->priv->source_set)
6738 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6739 icon_view->priv->source_set = FALSE;
6742 unset_reorderable (icon_view);
6746 * gtk_icon_view_unset_model_drag_dest:
6747 * @icon_view: a #GtkIconView
6749 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6750 * method sets #GtkIconView:reorderable to %FALSE.
6755 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6757 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6759 if (icon_view->priv->dest_set)
6761 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6762 icon_view->priv->dest_set = FALSE;
6765 unset_reorderable (icon_view);
6768 /* These are useful to implement your own custom stuff. */
6770 * gtk_icon_view_set_drag_dest_item:
6771 * @icon_view: a #GtkIconView
6772 * @path: (allow-none): The path of the item to highlight, or %NULL.
6773 * @pos: Specifies where to drop, relative to the item
6775 * Sets the item that is highlighted for feedback.
6780 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6782 GtkIconViewDropPosition pos)
6784 /* Note; this function is exported to allow a custom DND
6785 * implementation, so it can't touch TreeViewDragInfo
6788 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6790 if (icon_view->priv->dest_item)
6792 GtkTreePath *current_path;
6793 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6794 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6795 icon_view->priv->dest_item = NULL;
6797 gtk_icon_view_queue_draw_path (icon_view, current_path);
6798 gtk_tree_path_free (current_path);
6801 /* special case a drop on an empty model */
6802 icon_view->priv->empty_view_drop = FALSE;
6803 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6804 && gtk_tree_path_get_depth (path) == 1
6805 && gtk_tree_path_get_indices (path)[0] == 0)
6809 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6812 if (n_children == 0)
6813 icon_view->priv->empty_view_drop = TRUE;
6816 icon_view->priv->dest_pos = pos;
6820 icon_view->priv->dest_item =
6821 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6822 icon_view->priv->model, path);
6824 gtk_icon_view_queue_draw_path (icon_view, path);
6829 * gtk_icon_view_get_drag_dest_item:
6830 * @icon_view: a #GtkIconView
6831 * @path: (out) (allow-none): Return location for the path of
6832 * the highlighted item, or %NULL.
6833 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6835 * Gets information about the item that is highlighted for feedback.
6840 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6842 GtkIconViewDropPosition *pos)
6844 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6848 if (icon_view->priv->dest_item)
6849 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6855 *pos = icon_view->priv->dest_pos;
6859 * gtk_icon_view_get_dest_item_at_pos:
6860 * @icon_view: a #GtkIconView
6861 * @drag_x: the position to determine the destination item for
6862 * @drag_y: the position to determine the destination item for
6863 * @path: (out) (allow-none): Return location for the path of the item,
6865 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6867 * Determines the destination item for a given position.
6869 * Return value: whether there is an item at the given position.
6874 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6878 GtkIconViewDropPosition *pos)
6880 GtkIconViewItem *item;
6882 /* Note; this function is exported to allow a custom DND
6883 * implementation, so it can't touch TreeViewDragInfo
6886 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6887 g_return_val_if_fail (drag_x >= 0, FALSE);
6888 g_return_val_if_fail (drag_y >= 0, FALSE);
6889 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6895 item = gtk_icon_view_get_item_at_coords (icon_view,
6896 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6897 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6904 *path = gtk_tree_path_new_from_indices (item->index, -1);
6908 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6909 *pos = GTK_ICON_VIEW_DROP_LEFT;
6910 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6911 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6912 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6913 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6914 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6915 *pos = GTK_ICON_VIEW_DROP_BELOW;
6917 *pos = GTK_ICON_VIEW_DROP_INTO;
6924 * gtk_icon_view_create_drag_icon:
6925 * @icon_view: a #GtkIconView
6926 * @path: a #GtkTreePath in @icon_view
6928 * Creates a #cairo_surface_t representation of the item at @path.
6929 * This image is used for a drag icon.
6931 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6936 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6940 GtkStyleContext *context;
6942 cairo_surface_t *surface;
6946 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6947 g_return_val_if_fail (path != NULL, NULL);
6949 widget = GTK_WIDGET (icon_view);
6950 context = gtk_widget_get_style_context (widget);
6952 if (!gtk_widget_get_realized (widget))
6955 index = gtk_tree_path_get_indices (path)[0];
6957 for (l = icon_view->priv->items; l; l = l->next)
6959 GtkIconViewItem *item = l->data;
6961 if (index == item->index)
6963 GdkRectangle rect = {
6964 item->cell_area.x - icon_view->priv->item_padding,
6965 item->cell_area.y - icon_view->priv->item_padding,
6966 item->cell_area.width + icon_view->priv->item_padding * 2,
6967 item->cell_area.height + icon_view->priv->item_padding * 2
6970 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6971 CAIRO_CONTENT_COLOR,
6975 cr = cairo_create (surface);
6976 cairo_set_line_width (cr, 1.);
6978 gtk_render_background (context, cr, 0, 0,
6979 rect.width + 2, rect.height + 2);
6983 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6986 gtk_icon_view_paint_item (icon_view, cr, item,
6987 icon_view->priv->item_padding + 1,
6988 icon_view->priv->item_padding + 1, FALSE);
6992 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6993 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
7006 * gtk_icon_view_get_reorderable:
7007 * @icon_view: a #GtkIconView
7009 * Retrieves whether the user can reorder the list via drag-and-drop.
7010 * See gtk_icon_view_set_reorderable().
7012 * Return value: %TRUE if the list can be reordered.
7017 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7019 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7021 return icon_view->priv->reorderable;
7024 static const GtkTargetEntry item_targets[] = {
7025 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7030 * gtk_icon_view_set_reorderable:
7031 * @icon_view: A #GtkIconView.
7032 * @reorderable: %TRUE, if the list of items can be reordered.
7034 * This function is a convenience function to allow you to reorder models that
7035 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7036 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7037 * the user can reorder the model by dragging and dropping rows. The
7038 * developer can listen to these changes by connecting to the model's
7039 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7040 * the icon view as a drag source and destination. Therefore, drag and
7041 * drop can not be used in a reorderable view for any other purpose.
7043 * This function does not give you any degree of control over the order -- any
7044 * reordering is allowed. If more control is needed, you should probably
7045 * handle drag and drop manually.
7050 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7051 gboolean reorderable)
7053 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7055 reorderable = reorderable != FALSE;
7057 if (icon_view->priv->reorderable == reorderable)
7062 gtk_icon_view_enable_model_drag_source (icon_view,
7065 G_N_ELEMENTS (item_targets),
7067 gtk_icon_view_enable_model_drag_dest (icon_view,
7069 G_N_ELEMENTS (item_targets),
7074 gtk_icon_view_unset_model_drag_source (icon_view);
7075 gtk_icon_view_unset_model_drag_dest (icon_view);
7078 icon_view->priv->reorderable = reorderable;
7080 g_object_notify (G_OBJECT (icon_view), "reorderable");
7084 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
7085 GtkBuilder *builder,
7087 const gchar *tagname,
7088 GMarkupParser *parser,
7091 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
7092 tagname, parser, data))
7095 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
7096 tagname, parser, data);
7100 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
7101 GtkBuilder *builder,
7103 const gchar *tagname,
7106 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
7107 child, tagname, data))
7108 parent_buildable_iface->custom_tag_end (buildable, builder,
7109 child, tagname, data);
7112 /* Accessibility Support */
7114 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (_gtk_icon_view_item_accessible_get_type ())
7115 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7116 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7122 GtkIconViewItem *item;
7124 AtkStateSet *state_set;
7126 gchar *action_description;
7127 gchar *image_description;
7128 guint action_idle_handler;
7129 } GtkIconViewItemAccessible;
7133 AtkObjectClass parent_class;
7135 } GtkIconViewItemAccessibleClass;
7137 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7139 static void atk_component_item_interface_init (AtkComponentIface *iface);
7140 static void atk_action_item_interface_init (AtkActionIface *iface);
7141 static void atk_text_item_interface_init (AtkTextIface *iface);
7142 static void atk_image_item_interface_init (AtkImageIface *iface);
7144 G_DEFINE_TYPE_WITH_CODE (GtkIconViewItemAccessible, _gtk_icon_view_item_accessible, ATK_TYPE_OBJECT,
7145 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_item_interface_init)
7146 G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_item_interface_init)
7147 G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT, atk_text_item_interface_init)
7148 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE, atk_image_item_interface_init))
7152 idle_do_action (gpointer data)
7154 GtkIconViewItemAccessible *item;
7155 GtkIconView *icon_view;
7158 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7159 item->action_idle_handler = 0;
7161 if (item->widget != NULL)
7163 icon_view = GTK_ICON_VIEW (item->widget);
7164 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7165 gtk_icon_view_item_activated (icon_view, path);
7166 gtk_tree_path_free (path);
7173 gtk_icon_view_item_accessible_do_action (AtkAction *action,
7176 GtkIconViewItemAccessible *item;
7181 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7183 if (!GTK_IS_ICON_VIEW (item->widget))
7186 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7189 if (!item->action_idle_handler)
7190 item->action_idle_handler = gdk_threads_add_idle (idle_do_action, item);
7196 gtk_icon_view_item_accessible_get_n_actions (AtkAction *action)
7201 static const gchar *
7202 gtk_icon_view_item_accessible_get_description (AtkAction *action,
7205 GtkIconViewItemAccessible *item;
7210 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7212 if (item->action_description)
7213 return item->action_description;
7215 return "Activate item";
7218 static const gchar *
7219 gtk_icon_view_item_accessible_get_name (AtkAction *action,
7229 gtk_icon_view_item_accessible_set_description (AtkAction *action,
7231 const gchar *description)
7233 GtkIconViewItemAccessible *item;
7238 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7240 g_free (item->action_description);
7241 item->action_description = g_strdup (description);
7247 atk_action_item_interface_init (AtkActionIface *iface)
7249 iface->do_action = gtk_icon_view_item_accessible_do_action;
7250 iface->set_description = gtk_icon_view_item_accessible_set_description;
7251 iface->get_name = gtk_icon_view_item_accessible_get_name;
7252 iface->get_n_actions = gtk_icon_view_item_accessible_get_n_actions;
7253 iface->get_description = gtk_icon_view_item_accessible_get_description;
7256 static const gchar *
7257 gtk_icon_view_item_accessible_get_image_description (AtkImage *image)
7259 GtkIconViewItemAccessible *item;
7261 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7263 return item->image_description;
7267 gtk_icon_view_item_accessible_set_image_description (AtkImage *image,
7268 const gchar *description)
7270 GtkIconViewItemAccessible *item;
7272 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7274 g_free (item->image_description);
7275 item->image_description = g_strdup (description);
7282 gboolean pixbuf_found;
7286 get_pixbuf_foreach (GtkCellRenderer *renderer,
7287 const GdkRectangle *cell_area,
7288 const GdkRectangle *cell_background,
7289 GetPixbufBoxData *data)
7291 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7293 data->box = *cell_area;
7294 data->pixbuf_found = TRUE;
7296 return (data->pixbuf_found != FALSE);
7300 get_pixbuf_box (GtkIconView *icon_view,
7301 GtkIconViewItem *item,
7304 GetPixbufBoxData data = { { 0, }, FALSE };
7305 GtkCellAreaContext *context;
7307 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7309 gtk_icon_view_set_cell_data (icon_view, item);
7310 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7311 GTK_WIDGET (icon_view),
7312 (GdkRectangle *)item, (GdkRectangle *)item,
7313 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7315 return data.pixbuf_found;
7319 get_text_foreach (GtkCellRenderer *renderer,
7322 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7324 g_object_get (renderer, "text", text, NULL);
7331 get_text (GtkIconView *icon_view,
7332 GtkIconViewItem *item)
7336 gtk_icon_view_set_cell_data (icon_view, item);
7337 gtk_cell_area_foreach (icon_view->priv->cell_area,
7338 (GtkCellCallback)get_text_foreach, &text);
7344 gtk_icon_view_item_accessible_get_image_size (AtkImage *image,
7348 GtkIconViewItemAccessible *item;
7351 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7353 if (!GTK_IS_ICON_VIEW (item->widget))
7356 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7362 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7365 *height = box.height;
7370 gtk_icon_view_item_accessible_get_image_position (AtkImage *image,
7373 AtkCoordType coord_type)
7375 GtkIconViewItemAccessible *item;
7378 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7380 if (!GTK_IS_ICON_VIEW (item->widget))
7383 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7386 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7388 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7390 *x+= box.x - item->item->cell_area.x;
7391 *y+= box.y - item->item->cell_area.y;
7397 atk_image_item_interface_init (AtkImageIface *iface)
7399 iface->get_image_description = gtk_icon_view_item_accessible_get_image_description;
7400 iface->set_image_description = gtk_icon_view_item_accessible_set_image_description;
7401 iface->get_image_size = gtk_icon_view_item_accessible_get_image_size;
7402 iface->get_image_position = gtk_icon_view_item_accessible_get_image_position;
7406 gtk_icon_view_item_accessible_get_text (AtkText *text,
7410 GtkIconViewItemAccessible *item;
7412 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7413 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7417 return g_utf8_substring (item->text, start_pos, end_pos > -1 ? end_pos : g_utf8_strlen (item->text, -1));
7419 return g_strdup ("");
7423 gtk_icon_view_item_accessible_get_character_at_offset (AtkText *text,
7426 GtkIconViewItemAccessible *item;
7430 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7431 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7434 string = item->text;
7439 if (offset >= g_utf8_strlen (string, -1))
7442 index = g_utf8_offset_to_pointer (string, offset);
7444 return g_utf8_get_char (index);
7447 static PangoLayout *
7448 create_pango_layout (GtkIconViewItemAccessible *item)
7450 PangoLayout *layout;
7452 layout = gtk_widget_create_pango_layout (item->widget, item->text);
7458 gtk_icon_view_item_accessible_get_text_before_offset (AtkText *atk_text,
7460 AtkTextBoundary boundary_type,
7464 GtkIconViewItemAccessible *item;
7465 PangoLayout *layout;
7468 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7469 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7472 layout = create_pango_layout (item);
7473 text = _gtk_pango_get_text_before (layout, boundary_type, offset, start_offset, end_offset);
7474 g_object_unref (layout);
7480 gtk_icon_view_item_accessible_get_text_at_offset (AtkText *atk_text,
7482 AtkTextBoundary boundary_type,
7486 GtkIconViewItemAccessible *item;
7487 PangoLayout *layout;
7490 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7491 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7494 layout = create_pango_layout (item);
7495 text = _gtk_pango_get_text_at (layout, boundary_type, offset, start_offset, end_offset);
7496 g_object_unref (layout);
7502 gtk_icon_view_item_accessible_get_text_after_offset (AtkText *atk_text,
7504 AtkTextBoundary boundary_type,
7508 GtkIconViewItemAccessible *item;
7509 PangoLayout *layout;
7512 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (atk_text);
7513 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7516 layout = create_pango_layout (item);
7517 text = _gtk_pango_get_text_after (layout, boundary_type, offset, start_offset, end_offset);
7518 g_object_unref (layout);
7524 gtk_icon_view_item_accessible_get_character_count (AtkText *text)
7526 GtkIconViewItemAccessible *item;
7528 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7529 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7533 return g_utf8_strlen (item->text, -1);
7539 gtk_icon_view_item_accessible_get_character_extents (AtkText *text,
7545 AtkCoordType coord_type)
7547 GtkIconViewItemAccessible *item;
7549 GtkIconView *icon_view;
7550 PangoRectangle char_rect;
7551 const gchar *item_text;
7555 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7557 if (!GTK_IS_ICON_VIEW (item->widget))
7560 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7564 icon_view = GTK_ICON_VIEW (item->widget);
7565 /* FIXME we probably have to use GailTextCell to salvage this */
7566 gtk_icon_view_update_item_text (icon_view, item->item);
7567 item_text = pango_layout_get_text (icon_view->priv->layout);
7568 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7569 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7571 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7572 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7573 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7574 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7575 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7576 *width = char_rect.width / PANGO_SCALE;
7577 *height = char_rect.height / PANGO_SCALE;
7582 gtk_icon_view_item_accessible_get_offset_at_point (AtkText *text,
7585 AtkCoordType coord_type)
7587 GtkIconViewItemAccessible *item;
7590 GtkIconView *icon_view;
7591 const gchar *item_text;
7596 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7598 if (!GTK_IS_ICON_VIEW (item->widget))
7601 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7605 icon_view = GTK_ICON_VIEW (item->widget);
7606 /* FIXME we probably have to use GailTextCell to salvage this */
7607 gtk_icon_view_update_item_text (icon_view, item->item);
7608 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7609 x -= l_x + item->item->layout_x - item->item->x;
7610 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7611 y -= l_y + item->item->layout_y - item->item->y;
7612 item_text = pango_layout_get_text (icon_view->priv->layout);
7613 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7624 offset = g_utf8_strlen (item_text, -1);
7626 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7632 atk_text_item_interface_init (AtkTextIface *iface)
7634 iface->get_text = gtk_icon_view_item_accessible_get_text;
7635 iface->get_character_at_offset = gtk_icon_view_item_accessible_get_character_at_offset;
7636 iface->get_text_before_offset = gtk_icon_view_item_accessible_get_text_before_offset;
7637 iface->get_text_at_offset = gtk_icon_view_item_accessible_get_text_at_offset;
7638 iface->get_text_after_offset = gtk_icon_view_item_accessible_get_text_after_offset;
7639 iface->get_character_count = gtk_icon_view_item_accessible_get_character_count;
7640 iface->get_character_extents = gtk_icon_view_item_accessible_get_character_extents;
7641 iface->get_offset_at_point = gtk_icon_view_item_accessible_get_offset_at_point;
7645 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7650 AtkCoordType coord_type)
7652 GtkIconViewItemAccessible *item;
7653 AtkObject *parent_obj;
7656 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7658 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7659 if (!GTK_IS_WIDGET (item->widget))
7662 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7665 *width = item->item->cell_area.width;
7666 *height = item->item->cell_area.height;
7667 if (gtk_icon_view_item_accessible_is_showing (item))
7669 parent_obj = gtk_widget_get_accessible (item->widget);
7670 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7671 *x = l_x + item->item->cell_area.x;
7672 *y = l_y + item->item->cell_area.y;
7682 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7684 GtkIconViewItemAccessible *item;
7685 GtkWidget *toplevel;
7687 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7689 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7690 if (!GTK_IS_WIDGET (item->widget))
7693 gtk_widget_grab_focus (item->widget);
7694 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7695 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7696 if (gtk_widget_is_toplevel (toplevel))
7697 gtk_window_present (GTK_WINDOW (toplevel));
7703 atk_component_item_interface_init (AtkComponentIface *iface)
7705 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7706 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7710 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7711 AtkStateType state_type,
7712 gboolean emit_signal)
7716 rc = atk_state_set_add_state (item->state_set, state_type);
7718 /* The signal should only be generated if the value changed,
7719 * not when the item is set up. So states that are set
7720 * initially should pass FALSE as the emit_signal argument.
7724 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7725 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7726 if (state_type == ATK_STATE_VISIBLE)
7727 g_signal_emit_by_name (item, "visible-data-changed");
7734 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7735 AtkStateType state_type,
7736 gboolean emit_signal)
7738 if (atk_state_set_contains_state (item->state_set, state_type))
7742 rc = atk_state_set_remove_state (item->state_set, state_type);
7744 /* The signal should only be generated if the value changed,
7745 * not when the item is set up. So states that are set
7746 * initially should pass FALSE as the emit_signal argument.
7750 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7751 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7752 if (state_type == ATK_STATE_VISIBLE)
7753 g_signal_emit_by_name (item, "visible-data-changed");
7763 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7765 GtkAllocation allocation;
7766 GtkIconView *icon_view;
7767 GdkRectangle visible_rect;
7768 gboolean is_showing;
7770 /* An item is considered "SHOWING" if any part of the item
7771 * is in the visible rectangle.
7773 if (!GTK_IS_ICON_VIEW (item->widget))
7776 if (item->item == NULL)
7779 gtk_widget_get_allocation (item->widget, &allocation);
7781 icon_view = GTK_ICON_VIEW (item->widget);
7783 if (icon_view->priv->hadjustment)
7784 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
7786 if (icon_view->priv->hadjustment)
7787 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
7788 visible_rect.width = allocation.width;
7789 visible_rect.height = allocation.height;
7791 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
7792 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
7793 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
7794 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
7803 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7804 gboolean emit_signal)
7806 if (gtk_icon_view_item_accessible_is_showing (item))
7807 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7810 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7815 _gtk_icon_view_item_accessible_init (GtkIconViewItemAccessible *item)
7817 item->state_set = atk_state_set_new ();
7819 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7820 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7821 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7822 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7823 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7825 item->action_description = NULL;
7826 item->image_description = NULL;
7828 item->action_idle_handler = 0;
7832 gtk_icon_view_item_accessible_finalize (GObject *object)
7834 GtkIconViewItemAccessible *item;
7836 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7839 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7841 if (item->state_set)
7842 g_object_unref (item->state_set);
7845 g_free (item->text);
7846 g_free (item->action_description);
7847 g_free (item->image_description);
7849 if (item->action_idle_handler)
7851 g_source_remove (item->action_idle_handler);
7852 item->action_idle_handler = 0;
7855 G_OBJECT_CLASS (_gtk_icon_view_item_accessible_parent_class)->finalize (object);
7859 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7861 GtkIconViewItemAccessible *item;
7863 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7864 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7867 return gtk_widget_get_accessible (item->widget);
7873 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7875 GtkIconViewItemAccessible *item;
7877 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7878 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7880 return item->item->index;
7883 static AtkStateSet *
7884 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7886 GtkIconViewItemAccessible *item;
7887 GtkIconView *icon_view;
7889 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7890 g_return_val_if_fail (item->state_set, NULL);
7895 icon_view = GTK_ICON_VIEW (item->widget);
7896 if (icon_view->priv->cursor_item == item->item)
7897 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7899 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7900 if (item->item->selected)
7901 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
7903 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
7905 return g_object_ref (item->state_set);
7909 _gtk_icon_view_item_accessible_class_init (GtkIconViewItemAccessibleClass *klass)
7911 GObjectClass *gobject_class;
7912 AtkObjectClass *atk_class;
7914 gobject_class = (GObjectClass *)klass;
7915 atk_class = (AtkObjectClass *)klass;
7917 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7919 atk_class->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7920 atk_class->get_parent = gtk_icon_view_item_accessible_get_parent;
7921 atk_class->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7924 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (_gtk_icon_view_accessible_get_type ())
7925 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
7926 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
7930 GtkContainerAccessible parent;
7933 GtkAdjustment *old_hadj;
7934 GtkAdjustment *old_vadj;
7935 GtkTreeModel *model;
7936 } GtkIconViewAccessible;
7938 typedef GtkContainerAccessibleClass GtkIconViewAccessibleClass;
7940 static void atk_component_interface_init (AtkComponentIface *iface);
7941 static void atk_selection_interface_init (AtkSelectionIface *iface);
7943 G_DEFINE_TYPE_WITH_CODE (GtkIconViewAccessible, _gtk_icon_view_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE,
7944 G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init)
7945 G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, atk_selection_interface_init))
7951 } GtkIconViewItemAccessibleInfo;
7955 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
7959 GtkIconViewAccessible *view = (GtkIconViewAccessible *)accessible;
7960 GtkIconViewItemAccessibleInfo *info;
7961 GtkIconViewItemAccessibleInfo *tmp_info;
7964 info = g_new (GtkIconViewItemAccessibleInfo, 1);
7966 info->index = index;
7968 items = view->items;
7971 tmp_info = items->data;
7972 if (tmp_info->index > index)
7974 items = items->next;
7976 view->items = g_list_insert_before (view->items, items, info);
7977 view->old_hadj = NULL;
7978 view->old_vadj = NULL;
7982 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
7984 GtkIconView *icon_view;
7987 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
7991 icon_view = GTK_ICON_VIEW (widget);
7993 return g_list_length (icon_view->priv->items);
7997 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8000 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
8001 GtkIconViewItemAccessibleInfo *info;
8004 items = view->items;
8009 if (info->index == index)
8011 items = items->next;
8018 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8021 GtkIconView *icon_view;
8025 GtkIconViewItemAccessible *a11y_item;
8027 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8031 icon_view = GTK_ICON_VIEW (widget);
8032 icons = g_list_nth (icon_view->priv->items, index);
8036 GtkIconViewItem *item = icons->data;
8038 g_return_val_if_fail (item->index == index, NULL);
8039 obj = gtk_icon_view_accessible_find_child (accessible, index);
8042 obj = g_object_new (GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, NULL);
8043 gtk_icon_view_item_accessible_info_new (accessible, obj, index);
8044 obj->role = ATK_ROLE_ICON;
8045 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8046 a11y_item->item = item;
8047 a11y_item->widget = widget;
8049 g_free (a11y_item->text);
8050 a11y_item->text = get_text (icon_view, item);
8052 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8053 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8061 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8064 GtkIconViewItemAccessibleInfo *info;
8065 GtkIconViewItemAccessible *item;
8071 gboolean act_on_item;
8073 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8077 items = view->items;
8079 act_on_item = (list == NULL);
8084 info = (GtkIconViewItemAccessibleInfo *)items->data;
8085 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8087 if (act_on_item == FALSE && list == items)
8091 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8093 items = items->next;
8099 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8100 GtkIconViewAccessible *view)
8102 gtk_icon_view_accessible_traverse_items (view, NULL);
8106 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8107 GtkOrientation orientation,
8108 GtkAdjustment *adjustment)
8110 GtkIconViewAccessible *view = (GtkIconViewAccessible*)accessible;
8111 GtkAdjustment **old_adj_ptr;
8113 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8115 if (view->old_hadj == adjustment)
8118 old_adj_ptr = &view->old_hadj;
8122 if (view->old_vadj == adjustment)
8125 old_adj_ptr = &view->old_vadj;
8128 /* Disconnect signal handlers */
8131 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8132 (gpointer *)old_adj_ptr);
8133 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8134 gtk_icon_view_accessible_adjustment_changed,
8138 /* Connect signal */
8139 *old_adj_ptr = adjustment;
8140 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8141 g_signal_connect (adjustment, "value-changed",
8142 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8147 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8155 GtkIconView *icon_view;
8156 GtkIconViewItem *item;
8157 GtkIconViewItemAccessible *a11y_item;
8160 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8161 index = gtk_tree_path_get_indices(path)[0];
8162 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8163 gtk_icon_view_accessible_find_child (atk_obj, index));
8167 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8168 icon_view = GTK_ICON_VIEW (widget);
8169 item = a11y_item->item;
8171 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8172 if (!name || strcmp (name, "") == 0)
8174 g_free (a11y_item->text);
8175 a11y_item->text = get_text (icon_view, item);
8179 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8185 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8190 GtkIconViewItemAccessibleInfo *info;
8191 GtkIconViewAccessible *view;
8192 GtkIconViewItemAccessible *item;
8198 index = gtk_tree_path_get_indices(path)[0];
8199 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8200 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8202 items = view->items;
8207 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8208 if (info->index != item->item->index)
8210 if (info->index < index)
8211 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8213 if (tmp_list == NULL)
8216 info->index = item->item->index;
8219 items = items->next;
8221 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8222 g_signal_emit_by_name (atk_obj, "children-changed::add",
8228 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8232 GtkIconViewItemAccessibleInfo *info;
8233 GtkIconViewAccessible *view;
8234 GtkIconViewItemAccessible *item;
8237 GList *deleted_item;
8241 index = gtk_tree_path_get_indices(path)[0];
8242 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8243 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8245 items = view->items;
8247 deleted_item = NULL;
8252 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8253 if (info->index == index)
8255 deleted_item = items;
8257 if (info->index != item->item->index)
8259 if (tmp_list == NULL)
8262 info->index = item->item->index;
8265 items = items->next;
8267 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8270 info = deleted_item->data;
8271 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8272 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8274 view->items = g_list_remove_link (view->items, deleted_item);
8282 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8283 GtkIconViewItemAccessibleInfo *i2)
8285 return i1->index - i2->index;
8289 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8295 GtkIconViewAccessible *view;
8296 GtkIconViewItemAccessibleInfo *info;
8297 GtkIconView *icon_view;
8298 GtkIconViewItemAccessible *item;
8304 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8305 icon_view = GTK_ICON_VIEW (user_data);
8306 view = (GtkIconViewAccessible*)atk_obj;
8308 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8310 order = g_new (gint, length);
8311 for (i = 0; i < length; i++)
8312 order [new_order[i]] = i;
8314 items = view->items;
8318 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8319 info->index = order[info->index];
8320 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8321 items = items->next;
8324 view->items = g_list_sort (view->items,
8325 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8331 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8336 obj = G_OBJECT (model);
8337 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8338 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8339 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8340 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8344 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8348 obj = G_OBJECT (icon_view->priv->model);
8349 g_signal_connect_data (obj, "row-changed",
8350 (GCallback) gtk_icon_view_accessible_model_row_changed,
8351 icon_view, NULL, 0);
8352 g_signal_connect_data (obj, "row-inserted",
8353 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8354 icon_view, NULL, G_CONNECT_AFTER);
8355 g_signal_connect_data (obj, "row-deleted",
8356 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8357 icon_view, NULL, G_CONNECT_AFTER);
8358 g_signal_connect_data (obj, "rows-reordered",
8359 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8360 icon_view, NULL, G_CONNECT_AFTER);
8364 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessible *view)
8366 GtkIconViewItemAccessibleInfo *info;
8369 items = view->items;
8372 info = (GtkIconViewItemAccessibleInfo *) items->data;
8373 g_object_unref (info->item);
8374 g_free (items->data);
8375 items = items->next;
8377 g_list_free (view->items);
8382 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8385 GtkIconView *icon_view;
8388 GtkIconViewAccessible *view;
8390 if (strcmp (pspec->name, "model") == 0)
8392 widget = GTK_WIDGET (obj);
8393 atk_obj = gtk_widget_get_accessible (widget);
8394 view = (GtkIconViewAccessible*)atk_obj;
8397 g_object_remove_weak_pointer (G_OBJECT (view->model),
8398 (gpointer *)&view->model);
8399 gtk_icon_view_accessible_disconnect_model_signals (view->model, widget);
8401 gtk_icon_view_accessible_clear_cache (view);
8403 icon_view = GTK_ICON_VIEW (obj);
8404 view->model = icon_view->priv->model;
8405 /* If there is no model the GtkIconView is probably being destroyed */
8408 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8409 gtk_icon_view_accessible_connect_model_signals (icon_view);
8417 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8420 GtkIconViewAccessible *view;
8421 GtkIconView *icon_view;
8423 if (ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize)
8424 ATK_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->initialize (accessible, data);
8426 icon_view = (GtkIconView*)data;
8427 view = (GtkIconViewAccessible*)accessible;
8429 if (icon_view->priv->hadjustment)
8430 gtk_icon_view_accessible_set_adjustment (accessible,
8431 GTK_ORIENTATION_HORIZONTAL,
8432 icon_view->priv->hadjustment);
8433 if (icon_view->priv->vadjustment)
8434 gtk_icon_view_accessible_set_adjustment (accessible,
8435 GTK_ORIENTATION_VERTICAL,
8436 icon_view->priv->vadjustment);
8437 g_signal_connect (data, "notify",
8438 G_CALLBACK (gtk_icon_view_accessible_notify_gtk), NULL);
8440 view->model = icon_view->priv->model;
8443 g_object_add_weak_pointer (G_OBJECT (view->model), (gpointer *)&view->model);
8444 gtk_icon_view_accessible_connect_model_signals (icon_view);
8447 accessible->role = ATK_ROLE_LAYERED_PANE;
8451 gtk_icon_view_accessible_finalize (GObject *object)
8453 GtkIconViewAccessible *view = (GtkIconViewAccessible*)object;
8455 gtk_icon_view_accessible_clear_cache (view);
8457 G_OBJECT_CLASS (_gtk_icon_view_accessible_parent_class)->finalize (object);
8461 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8462 GtkAccessible *accessible)
8465 GtkIconViewAccessible *view;
8467 atk_obj = ATK_OBJECT (accessible);
8468 view = (GtkIconViewAccessible*)atk_obj;
8471 g_object_remove_weak_pointer (G_OBJECT (view->old_hadj),
8472 (gpointer *)&view->old_hadj);
8474 g_signal_handlers_disconnect_by_func (view->old_hadj,
8475 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8477 view->old_hadj = NULL;
8481 g_object_remove_weak_pointer (G_OBJECT (view->old_vadj),
8482 (gpointer *)&view->old_vadj);
8484 g_signal_handlers_disconnect_by_func (view->old_vadj,
8485 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8487 view->old_vadj = NULL;
8492 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8496 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8499 g_signal_connect_after (widget, "destroy",
8500 G_CALLBACK (gtk_icon_view_accessible_destroyed), accessible);
8502 GTK_ACCESSIBLE_CLASS (_gtk_icon_view_accessible_parent_class)->connect_widget_destroyed (accessible);
8506 _gtk_icon_view_accessible_class_init (GtkIconViewAccessibleClass *klass)
8508 GObjectClass *gobject_class;
8509 GtkAccessibleClass *accessible_class;
8510 AtkObjectClass *atk_class;
8512 gobject_class = (GObjectClass *)klass;
8513 accessible_class = (GtkAccessibleClass *)klass;
8514 atk_class = (AtkObjectClass *)klass;
8516 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8518 atk_class->get_n_children = gtk_icon_view_accessible_get_n_children;
8519 atk_class->ref_child = gtk_icon_view_accessible_ref_child;
8520 atk_class->initialize = gtk_icon_view_accessible_initialize;
8522 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8526 _gtk_icon_view_accessible_init (GtkIconViewAccessible *accessible)
8531 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8534 AtkCoordType coord_type)
8537 GtkIconView *icon_view;
8538 GtkIconViewItem *item;
8541 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8545 icon_view = GTK_ICON_VIEW (widget);
8546 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8547 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8549 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8555 atk_component_interface_init (AtkComponentIface *iface)
8557 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8561 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8565 GtkIconView *icon_view;
8566 GtkIconViewItem *item;
8568 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8572 icon_view = GTK_ICON_VIEW (widget);
8574 item = g_list_nth_data (icon_view->priv->items, i);
8578 gtk_icon_view_select_item (icon_view, item);
8584 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8587 GtkIconView *icon_view;
8589 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8593 icon_view = GTK_ICON_VIEW (widget);
8594 gtk_icon_view_unselect_all (icon_view);
8600 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8605 GtkIconView *icon_view;
8606 GtkIconViewItem *item;
8608 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8612 icon_view = GTK_ICON_VIEW (widget);
8614 l = icon_view->priv->items;
8621 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8632 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8635 GtkIconView *icon_view;
8636 GtkIconViewItem *item;
8640 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8644 icon_view = GTK_ICON_VIEW (widget);
8646 l = icon_view->priv->items;
8662 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8666 GtkIconView *icon_view;
8667 GtkIconViewItem *item;
8669 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8673 icon_view = GTK_ICON_VIEW (widget);
8675 item = g_list_nth_data (icon_view->priv->items, i);
8679 return item->selected;
8683 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8687 GtkIconView *icon_view;
8688 GtkIconViewItem *item;
8692 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8696 icon_view = GTK_ICON_VIEW (widget);
8697 l = icon_view->priv->items;
8706 gtk_icon_view_unselect_item (icon_view, item);
8718 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8721 GtkIconView *icon_view;
8723 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8727 icon_view = GTK_ICON_VIEW (widget);
8728 gtk_icon_view_select_all (icon_view);
8733 atk_selection_interface_init (AtkSelectionIface *iface)
8735 iface->add_selection = gtk_icon_view_accessible_add_selection;
8736 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8737 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8738 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8739 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8740 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8741 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;