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 "gtktextbuffer.h"
44 #include "gtkscrollable.h"
45 #include "gtksizerequest.h"
46 #include "gtktreednd.h"
47 #include "gtktypebuiltins.h"
48 #include "gtkprivate.h"
53 * @short_description: A widget which displays a list of icons in a grid
55 * #GtkIconView provides an alternative view on a #GtkTreeModel.
56 * It displays the model as a grid of icons with labels. Like
57 * #GtkTreeView, it allows to select one or multiple items
58 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
59 * In addition to selection with the arrow keys, #GtkIconView supports
60 * rubberband selection, which is controlled by dragging the pointer.
62 * Note that if the tree model is backed by an actual tree store (as
63 * opposed to a flat list where the mapping to icons is obvious),
64 * #GtkIconView will only display the first level of the tree and
65 * ignore the tree's branches.
68 #define SCROLL_EDGE_SIZE 15
70 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
72 typedef struct _GtkIconViewItem GtkIconViewItem;
73 struct _GtkIconViewItem
81 gint x, y, width, height;
84 guint selected_before_rubberbanding : 1;
88 typedef struct _GtkIconViewChild GtkIconViewChild;
89 struct _GtkIconViewChild
95 struct _GtkIconViewPrivate
97 GtkCellArea *cell_area;
98 GtkCellAreaContext *cell_area_context;
100 gulong add_editable_id;
101 gulong remove_editable_id;
102 gulong focus_changed_id;
103 gulong context_changed_id;
107 GtkSelectionMode selection_mode;
109 GdkWindow *bin_window;
117 GtkAdjustment *hadjustment;
118 GtkAdjustment *vadjustment;
120 guint layout_idle_id;
122 gint rubberband_x1, rubberband_y1;
123 gint rubberband_x2, rubberband_y2;
124 GdkDevice *rubberband_device;
126 guint scroll_timeout_id;
127 gint scroll_value_diff;
128 gint event_last_x, event_last_y;
130 GtkIconViewItem *anchor_item;
131 GtkIconViewItem *cursor_item;
133 GtkIconViewItem *last_single_clicked;
135 GtkOrientation item_orientation;
139 gint effective_item_width;
150 GtkCellRenderer *pixbuf_cell;
151 GtkCellRenderer *text_cell;
156 GdkModifierType start_button_mask;
161 GdkDragAction source_actions;
162 GdkDragAction dest_actions;
164 GtkTreeRowReference *dest_item;
165 GtkIconViewDropPosition dest_pos;
168 GtkTreeRowReference *scroll_to_path;
169 gfloat scroll_to_row_align;
170 gfloat scroll_to_col_align;
171 guint scroll_to_use_align : 1;
173 guint source_set : 1;
175 guint reorderable : 1;
176 guint empty_view_drop :1;
178 guint ctrl_pressed : 1;
179 guint shift_pressed : 1;
181 guint draw_focus : 1;
183 /* GtkScrollablePolicy needs to be checked when
184 * driving the scrollable adjustment values */
185 guint hscroll_policy : 1;
186 guint vscroll_policy : 1;
188 guint doing_rubberband : 1;
202 ACTIVATE_CURSOR_ITEM,
214 PROP_ITEM_ORIENTATION,
227 /* For scrollable interface */
235 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
236 static void gtk_icon_view_dispose (GObject *object);
237 static GObject *gtk_icon_view_constructor (GType type,
238 guint n_construct_properties,
239 GObjectConstructParam *construct_properties);
240 static void gtk_icon_view_set_property (GObject *object,
244 static void gtk_icon_view_get_property (GObject *object,
248 /* GtkWidget vfuncs */
249 static void gtk_icon_view_destroy (GtkWidget *widget);
250 static void gtk_icon_view_realize (GtkWidget *widget);
251 static void gtk_icon_view_unrealize (GtkWidget *widget);
252 static void gtk_icon_view_style_set (GtkWidget *widget,
253 GtkStyle *previous_style);
254 static void gtk_icon_view_state_changed (GtkWidget *widget,
255 GtkStateType previous_state);
256 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
259 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
262 static void gtk_icon_view_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static gboolean gtk_icon_view_draw (GtkWidget *widget,
266 static gboolean gtk_icon_view_motion (GtkWidget *widget,
267 GdkEventMotion *event);
268 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
274 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
276 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
279 /* GtkContainer vfuncs */
280 static void gtk_icon_view_remove (GtkContainer *container,
282 static void gtk_icon_view_forall (GtkContainer *container,
283 gboolean include_internals,
284 GtkCallback callback,
285 gpointer callback_data);
287 /* GtkIconView vfuncs */
288 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
289 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
291 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
292 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
294 /* Internal functions */
295 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
296 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
297 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
298 GtkAdjustment *adjustment);
299 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
300 GtkAdjustment *adjustment);
301 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
302 GtkOrientation orientation,
303 GtkAdjustment *adjustment);
304 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
305 GtkIconView *icon_view);
306 static void gtk_icon_view_layout (GtkIconView *icon_view);
307 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
309 GtkIconViewItem *item,
312 gboolean draw_focus);
313 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
315 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
317 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
318 GtkIconViewItem *item);
319 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
320 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
321 GtkIconViewItem *item,
322 GtkCellRenderer *cursor_cell);
323 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
327 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
328 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
329 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
330 GtkIconViewItem *item,
335 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
336 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
337 static void gtk_icon_view_update_rubberband (gpointer data);
338 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
339 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
340 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
343 GtkMovementStep step,
345 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
346 GtkMovementStep step,
348 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
350 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
352 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
354 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
356 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
357 GtkIconViewItem *item);
358 static void gtk_icon_view_select_item (GtkIconView *icon_view,
359 GtkIconViewItem *item);
360 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
363 GtkIconViewItem *anchor,
364 GtkIconViewItem *cursor);
365 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
368 gboolean only_in_cell,
369 GtkCellRenderer **cell_at_pos);
370 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
371 GtkIconViewItem *item,
372 GdkRectangle *cell_area);
373 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
374 GtkIconViewItem *item);
376 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
378 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
379 GtkIconViewItem *item);
381 static void gtk_icon_view_add_editable (GtkCellArea *area,
382 GtkCellRenderer *renderer,
383 GtkCellEditable *editable,
384 GdkRectangle *cell_area,
386 GtkIconView *icon_view);
387 static void gtk_icon_view_remove_editable (GtkCellArea *area,
388 GtkCellRenderer *renderer,
389 GtkCellEditable *editable,
390 GtkIconView *icon_view);
391 static void gtk_icon_view_focus_changed (GtkCellArea *area,
392 GtkCellRenderer *renderer,
394 GtkIconView *icon_view);
396 /* Source side drag signals */
397 static void gtk_icon_view_drag_begin (GtkWidget *widget,
398 GdkDragContext *context);
399 static void gtk_icon_view_drag_end (GtkWidget *widget,
400 GdkDragContext *context);
401 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
402 GdkDragContext *context,
403 GtkSelectionData *selection_data,
406 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
407 GdkDragContext *context);
409 /* Target side drag signals */
410 static void gtk_icon_view_drag_leave (GtkWidget *widget,
411 GdkDragContext *context,
413 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
414 GdkDragContext *context,
418 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
419 GdkDragContext *context,
423 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
424 GdkDragContext *context,
427 GtkSelectionData *selection_data,
430 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
431 GdkEventMotion *event);
433 static void remove_scroll_timeout (GtkIconView *icon_view);
436 static GtkBuildableIface *parent_buildable_iface;
437 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
438 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
441 const gchar *tagname,
442 GMarkupParser *parser,
444 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
447 const gchar *tagname,
450 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
452 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
453 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
454 gtk_icon_view_cell_layout_init)
455 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
456 gtk_icon_view_buildable_init)
457 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
460 gtk_icon_view_class_init (GtkIconViewClass *klass)
462 GObjectClass *gobject_class;
463 GtkWidgetClass *widget_class;
464 GtkContainerClass *container_class;
465 GtkBindingSet *binding_set;
467 binding_set = gtk_binding_set_by_class (klass);
469 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
471 gobject_class = (GObjectClass *) klass;
472 widget_class = (GtkWidgetClass *) klass;
473 container_class = (GtkContainerClass *) klass;
475 gobject_class->constructor = gtk_icon_view_constructor;
476 gobject_class->dispose = gtk_icon_view_dispose;
477 gobject_class->set_property = gtk_icon_view_set_property;
478 gobject_class->get_property = gtk_icon_view_get_property;
480 widget_class->destroy = gtk_icon_view_destroy;
481 widget_class->realize = gtk_icon_view_realize;
482 widget_class->unrealize = gtk_icon_view_unrealize;
483 widget_class->style_set = gtk_icon_view_style_set;
484 widget_class->get_accessible = gtk_icon_view_get_accessible;
485 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
486 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
487 widget_class->size_allocate = gtk_icon_view_size_allocate;
488 widget_class->draw = gtk_icon_view_draw;
489 widget_class->motion_notify_event = gtk_icon_view_motion;
490 widget_class->button_press_event = gtk_icon_view_button_press;
491 widget_class->button_release_event = gtk_icon_view_button_release;
492 widget_class->key_press_event = gtk_icon_view_key_press;
493 widget_class->key_release_event = gtk_icon_view_key_release;
494 widget_class->drag_begin = gtk_icon_view_drag_begin;
495 widget_class->drag_end = gtk_icon_view_drag_end;
496 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
497 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
498 widget_class->drag_leave = gtk_icon_view_drag_leave;
499 widget_class->drag_motion = gtk_icon_view_drag_motion;
500 widget_class->drag_drop = gtk_icon_view_drag_drop;
501 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
502 widget_class->state_changed = gtk_icon_view_state_changed;
504 container_class->remove = gtk_icon_view_remove;
505 container_class->forall = gtk_icon_view_forall;
507 klass->select_all = gtk_icon_view_real_select_all;
508 klass->unselect_all = gtk_icon_view_real_unselect_all;
509 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
510 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
511 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
512 klass->move_cursor = gtk_icon_view_real_move_cursor;
516 * GtkIconView:selection-mode:
518 * The ::selection-mode property specifies the selection mode of
519 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
520 * is enabled, for the other modes, only keyboard selection is possible.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_enum ("selection-mode",
527 P_("Selection mode"),
528 P_("The selection mode"),
529 GTK_TYPE_SELECTION_MODE,
530 GTK_SELECTION_SINGLE,
531 GTK_PARAM_READWRITE));
534 * GtkIconView:pixbuf-column:
536 * The ::pixbuf-column property contains the number of the model column
537 * containing the pixbufs which are displayed. The pixbuf column must be
538 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
539 * display of pixbufs.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_int ("pixbuf-column",
547 P_("Model column used to retrieve the icon pixbuf from"),
549 GTK_PARAM_READWRITE));
552 * GtkIconView:text-column:
554 * The ::text-column property contains the number of the model column
555 * containing the texts which are displayed. The text column must be
556 * of type #G_TYPE_STRING. If this property and the :markup-column
557 * property are both set to -1, no texts are displayed.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_int ("text-column",
565 P_("Model column used to retrieve the text from"),
567 GTK_PARAM_READWRITE));
571 * GtkIconView:markup-column:
573 * The ::markup-column property contains the number of the model column
574 * containing markup information to be displayed. The markup column must be
575 * of type #G_TYPE_STRING. If this property and the :text-column property
576 * are both set to column numbers, it overrides the text column.
577 * If both are set to -1, no texts are displayed.
581 g_object_class_install_property (gobject_class,
583 g_param_spec_int ("markup-column",
585 P_("Model column used to retrieve the text if using Pango markup"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (gobject_class,
591 g_param_spec_object ("model",
592 P_("Icon View Model"),
593 P_("The model for the icon view"),
595 GTK_PARAM_READWRITE));
598 * GtkIconView:columns:
600 * The columns property contains the number of the columns in which the
601 * items should be displayed. If it is -1, the number of columns will
602 * be chosen automatically to fill the available area.
606 g_object_class_install_property (gobject_class,
608 g_param_spec_int ("columns",
609 P_("Number of columns"),
610 P_("Number of columns to display"),
612 GTK_PARAM_READWRITE));
616 * GtkIconView:item-width:
618 * The item-width property specifies the width to use for each item.
619 * If it is set to -1, the icon view will automatically determine a
620 * suitable item size.
624 g_object_class_install_property (gobject_class,
626 g_param_spec_int ("item-width",
627 P_("Width for each item"),
628 P_("The width used for each item"),
630 GTK_PARAM_READWRITE));
633 * GtkIconView:spacing:
635 * The spacing property specifies the space which is inserted between
636 * the cells (i.e. the icon and the text) of an item.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("spacing",
644 P_("Space which is inserted between cells of an item"),
646 GTK_PARAM_READWRITE));
649 * GtkIconView:row-spacing:
651 * The row-spacing property specifies the space which is inserted between
652 * the rows of the icon view.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("row-spacing",
660 P_("Space which is inserted between grid rows"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView:column-spacing:
667 * The column-spacing property specifies the space which is inserted between
668 * the columns of the icon view.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("column-spacing",
675 P_("Column Spacing"),
676 P_("Space which is inserted between grid columns"),
678 GTK_PARAM_READWRITE));
681 * GtkIconView:margin:
683 * The margin property specifies the space which is inserted
684 * at the edges of the icon view.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("margin",
692 P_("Space which is inserted at the edges of the icon view"),
694 GTK_PARAM_READWRITE));
697 * GtkIconView:item-orientation:
699 * The item-orientation property specifies how the cells (i.e. the icon and
700 * the text) of the item are positioned relative to each other.
704 g_object_class_install_property (gobject_class,
705 PROP_ITEM_ORIENTATION,
706 g_param_spec_enum ("item-orientation",
707 P_("Item Orientation"),
708 P_("How the text and icon of each item are positioned relative to each other"),
709 GTK_TYPE_ORIENTATION,
710 GTK_ORIENTATION_VERTICAL,
711 GTK_PARAM_READWRITE));
714 * GtkIconView:reorderable:
716 * The reorderable property specifies if the items can be reordered
721 g_object_class_install_property (gobject_class,
723 g_param_spec_boolean ("reorderable",
725 P_("View is reorderable"),
729 g_object_class_install_property (gobject_class,
731 g_param_spec_int ("tooltip-column",
732 P_("Tooltip Column"),
733 P_("The column in the model containing the tooltip texts for the items"),
737 GTK_PARAM_READWRITE));
740 * GtkIconView:item-padding:
742 * The item-padding property specifies the padding around each
743 * of the icon view's item.
747 g_object_class_install_property (gobject_class,
749 g_param_spec_int ("item-padding",
751 P_("Padding around icon view items"),
753 GTK_PARAM_READWRITE));
756 * GtkIconView:cell-area:
758 * The #GtkCellArea used to layout cell renderers for this view.
762 g_object_class_install_property (gobject_class,
764 g_param_spec_object ("cell-area",
766 P_("The GtkCellArea used to layout cells"),
768 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
770 /* Scrollable interface properties */
771 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
772 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
773 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
774 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
776 /* Style properties */
777 gtk_widget_class_install_style_property (widget_class,
778 g_param_spec_boxed ("selection-box-color",
779 P_("Selection Box Color"),
780 P_("Color of the selection box"),
782 GTK_PARAM_READABLE));
784 gtk_widget_class_install_style_property (widget_class,
785 g_param_spec_uchar ("selection-box-alpha",
786 P_("Selection Box Alpha"),
787 P_("Opacity of the selection box"),
790 GTK_PARAM_READABLE));
794 * GtkIconView::item-activated:
795 * @iconview: the object on which the signal is emitted
796 * @path: the #GtkTreePath for the activated item
798 * The ::item-activated signal is emitted when the method
799 * gtk_icon_view_item_activated() is called or the user double
800 * clicks an item. It is also emitted when a non-editable item
801 * is selected and one of the keys: Space, Return or Enter is
804 icon_view_signals[ITEM_ACTIVATED] =
805 g_signal_new (I_("item-activated"),
806 G_TYPE_FROM_CLASS (gobject_class),
808 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
810 g_cclosure_marshal_VOID__BOXED,
815 * GtkIconView::selection-changed:
816 * @iconview: the object on which the signal is emitted
818 * The ::selection-changed signal is emitted when the selection
819 * (i.e. the set of selected items) changes.
821 icon_view_signals[SELECTION_CHANGED] =
822 g_signal_new (I_("selection-changed"),
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
827 g_cclosure_marshal_VOID__VOID,
831 * GtkIconView::select-all:
832 * @iconview: the object on which the signal is emitted
834 * A <link linkend="keybinding-signals">keybinding signal</link>
835 * which gets emitted when the user selects all items.
837 * Applications should not connect to it, but may emit it with
838 * g_signal_emit_by_name() if they need to control selection
841 * The default binding for this signal is Ctrl-a.
843 icon_view_signals[SELECT_ALL] =
844 g_signal_new (I_("select-all"),
845 G_TYPE_FROM_CLASS (gobject_class),
846 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
847 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
849 g_cclosure_marshal_VOID__VOID,
853 * GtkIconView::unselect-all:
854 * @iconview: the object on which the signal is emitted
856 * A <link linkend="keybinding-signals">keybinding signal</link>
857 * which gets emitted when the user unselects all items.
859 * Applications should not connect to it, but may emit it with
860 * g_signal_emit_by_name() if they need to control selection
863 * The default binding for this signal is Ctrl-Shift-a.
865 icon_view_signals[UNSELECT_ALL] =
866 g_signal_new (I_("unselect-all"),
867 G_TYPE_FROM_CLASS (gobject_class),
868 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
869 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
871 g_cclosure_marshal_VOID__VOID,
875 * GtkIconView::select-cursor-item:
876 * @iconview: the object on which the signal is emitted
878 * A <link linkend="keybinding-signals">keybinding signal</link>
879 * which gets emitted when the user selects the item that is currently
882 * Applications should not connect to it, but may emit it with
883 * g_signal_emit_by_name() if they need to control selection
886 * There is no default binding for this signal.
888 icon_view_signals[SELECT_CURSOR_ITEM] =
889 g_signal_new (I_("select-cursor-item"),
890 G_TYPE_FROM_CLASS (gobject_class),
891 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
892 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
894 g_cclosure_marshal_VOID__VOID,
898 * GtkIconView::toggle-cursor-item:
899 * @iconview: the object on which the signal is emitted
901 * A <link linkend="keybinding-signals">keybinding signal</link>
902 * which gets emitted when the user toggles whether the currently
903 * focused item is selected or not. The exact effect of this
904 * depend on the selection mode.
906 * Applications should not connect to it, but may emit it with
907 * g_signal_emit_by_name() if they need to control selection
910 * There is no default binding for this signal is Ctrl-Space.
912 icon_view_signals[TOGGLE_CURSOR_ITEM] =
913 g_signal_new (I_("toggle-cursor-item"),
914 G_TYPE_FROM_CLASS (gobject_class),
915 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
916 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
918 g_cclosure_marshal_VOID__VOID,
922 * GtkIconView::activate-cursor-item:
923 * @iconview: the object on which the signal is emitted
925 * A <link linkend="keybinding-signals">keybinding signal</link>
926 * which gets emitted when the user activates the currently
929 * Applications should not connect to it, but may emit it with
930 * g_signal_emit_by_name() if they need to control activation
933 * The default bindings for this signal are Space, Return and Enter.
935 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
936 g_signal_new (I_("activate-cursor-item"),
937 G_TYPE_FROM_CLASS (gobject_class),
938 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
939 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
941 _gtk_marshal_BOOLEAN__VOID,
945 * GtkIconView::move-cursor:
946 * @iconview: the object which received the signal
947 * @step: the granularity of the move, as a #GtkMovementStep
948 * @count: the number of @step units to move
950 * The ::move-cursor signal is a
951 * <link linkend="keybinding-signals">keybinding signal</link>
952 * which gets emitted when the user initiates a cursor movement.
954 * Applications should not connect to it, but may emit it with
955 * g_signal_emit_by_name() if they need to control the cursor
958 * The default bindings for this signal include
960 * <listitem>Arrow keys which move by individual steps</listitem>
961 * <listitem>Home/End keys which move to the first/last item</listitem>
962 * <listitem>PageUp/PageDown which move by "pages"</listitem>
965 * All of these will extend the selection when combined with
966 * the Shift modifier.
968 icon_view_signals[MOVE_CURSOR] =
969 g_signal_new (I_("move-cursor"),
970 G_TYPE_FROM_CLASS (gobject_class),
971 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
972 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
974 _gtk_marshal_BOOLEAN__ENUM_INT,
976 GTK_TYPE_MOVEMENT_STEP,
980 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
982 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
984 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
985 "toggle-cursor-item", 0);
986 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
987 "toggle-cursor-item", 0);
989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
990 "activate-cursor-item", 0);
991 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
992 "activate-cursor-item", 0);
993 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
994 "activate-cursor-item", 0);
995 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
996 "activate-cursor-item", 0);
997 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
998 "activate-cursor-item", 0);
1000 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1001 GTK_MOVEMENT_DISPLAY_LINES, -1);
1002 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1003 GTK_MOVEMENT_DISPLAY_LINES, -1);
1005 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1006 GTK_MOVEMENT_DISPLAY_LINES, 1);
1007 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1008 GTK_MOVEMENT_DISPLAY_LINES, 1);
1010 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1011 GTK_MOVEMENT_DISPLAY_LINES, -1);
1013 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1014 GTK_MOVEMENT_DISPLAY_LINES, 1);
1016 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1017 GTK_MOVEMENT_BUFFER_ENDS, -1);
1018 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1019 GTK_MOVEMENT_BUFFER_ENDS, -1);
1021 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1022 GTK_MOVEMENT_BUFFER_ENDS, 1);
1023 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1024 GTK_MOVEMENT_BUFFER_ENDS, 1);
1026 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1027 GTK_MOVEMENT_PAGES, -1);
1028 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1029 GTK_MOVEMENT_PAGES, -1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1032 GTK_MOVEMENT_PAGES, 1);
1033 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1034 GTK_MOVEMENT_PAGES, 1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1037 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1039 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1042 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1044 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1048 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1050 parent_buildable_iface = g_type_interface_peek_parent (iface);
1051 iface->add_child = _gtk_cell_layout_buildable_add_child;
1052 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1053 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1057 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1059 iface->get_area = gtk_icon_view_cell_layout_get_area;
1063 gtk_icon_view_init (GtkIconView *icon_view)
1065 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1067 GtkIconViewPrivate);
1069 icon_view->priv->width = 0;
1070 icon_view->priv->height = 0;
1071 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1072 icon_view->priv->pressed_button = -1;
1073 icon_view->priv->press_start_x = -1;
1074 icon_view->priv->press_start_y = -1;
1075 icon_view->priv->text_column = -1;
1076 icon_view->priv->markup_column = -1;
1077 icon_view->priv->pixbuf_column = -1;
1078 icon_view->priv->text_cell = NULL;
1079 icon_view->priv->pixbuf_cell = NULL;
1080 icon_view->priv->tooltip_column = -1;
1082 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1084 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1086 icon_view->priv->columns = -1;
1087 icon_view->priv->item_width = -1;
1088 icon_view->priv->effective_item_width = -1;
1089 icon_view->priv->spacing = 0;
1090 icon_view->priv->row_spacing = 6;
1091 icon_view->priv->column_spacing = 6;
1092 icon_view->priv->margin = 6;
1093 icon_view->priv->item_padding = 6;
1095 icon_view->priv->draw_focus = TRUE;
1098 /* GObject methods */
1100 gtk_icon_view_constructor (GType type,
1101 guint n_construct_properties,
1102 GObjectConstructParam *construct_properties)
1104 GtkIconView *icon_view;
1105 GtkIconViewPrivate *priv;
1108 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1109 (type, n_construct_properties, construct_properties);
1111 icon_view = (GtkIconView *) object;
1112 priv = icon_view->priv;
1114 if (!priv->cell_area)
1116 priv->cell_area = gtk_cell_area_box_new ();
1117 g_object_ref_sink (priv->cell_area);
1120 if (GTK_IS_ORIENTABLE (priv->cell_area))
1121 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
1123 gtk_cell_area_set_style_detail (priv->cell_area, "icon_view");
1125 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
1127 priv->add_editable_id =
1128 g_signal_connect (priv->cell_area, "add-editable",
1129 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
1130 priv->remove_editable_id =
1131 g_signal_connect (priv->cell_area, "remove-editable",
1132 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
1133 priv->focus_changed_id =
1134 g_signal_connect (priv->cell_area, "focus-changed",
1135 G_CALLBACK (gtk_icon_view_focus_changed), icon_view);
1141 gtk_icon_view_dispose (GObject *object)
1143 GtkIconView *icon_view;
1144 GtkIconViewPrivate *priv;
1146 icon_view = GTK_ICON_VIEW (object);
1147 priv = icon_view->priv;
1149 if (priv->cell_area_context)
1151 g_object_unref (priv->cell_area_context);
1152 priv->cell_area_context = NULL;
1155 if (priv->cell_area)
1157 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1158 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1159 g_signal_handler_disconnect (priv->cell_area, priv->focus_changed_id);
1160 priv->add_editable_id = 0;
1161 priv->remove_editable_id = 0;
1162 priv->focus_changed_id = 0;
1164 g_object_unref (priv->cell_area);
1165 priv->cell_area = NULL;
1168 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1173 gtk_icon_view_set_property (GObject *object,
1175 const GValue *value,
1178 GtkIconView *icon_view;
1181 icon_view = GTK_ICON_VIEW (object);
1185 case PROP_SELECTION_MODE:
1186 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1188 case PROP_PIXBUF_COLUMN:
1189 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1191 case PROP_TEXT_COLUMN:
1192 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1194 case PROP_MARKUP_COLUMN:
1195 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1198 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1200 case PROP_ITEM_ORIENTATION:
1201 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1204 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1206 case PROP_ITEM_WIDTH:
1207 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1210 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1212 case PROP_ROW_SPACING:
1213 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1215 case PROP_COLUMN_SPACING:
1216 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1219 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1221 case PROP_REORDERABLE:
1222 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1225 case PROP_TOOLTIP_COLUMN:
1226 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1229 case PROP_ITEM_PADDING:
1230 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1233 case PROP_CELL_AREA:
1234 /* Construct-only, can only be assigned once */
1235 area = g_value_get_object (value);
1238 icon_view->priv->cell_area = g_object_ref_sink (area);
1241 case PROP_HADJUSTMENT:
1242 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1244 case PROP_VADJUSTMENT:
1245 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1247 case PROP_HSCROLL_POLICY:
1248 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1249 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1251 case PROP_VSCROLL_POLICY:
1252 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1253 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1263 gtk_icon_view_get_property (GObject *object,
1268 GtkIconView *icon_view;
1270 icon_view = GTK_ICON_VIEW (object);
1274 case PROP_SELECTION_MODE:
1275 g_value_set_enum (value, icon_view->priv->selection_mode);
1277 case PROP_PIXBUF_COLUMN:
1278 g_value_set_int (value, icon_view->priv->pixbuf_column);
1280 case PROP_TEXT_COLUMN:
1281 g_value_set_int (value, icon_view->priv->text_column);
1283 case PROP_MARKUP_COLUMN:
1284 g_value_set_int (value, icon_view->priv->markup_column);
1287 g_value_set_object (value, icon_view->priv->model);
1289 case PROP_ITEM_ORIENTATION:
1290 g_value_set_enum (value, icon_view->priv->item_orientation);
1293 g_value_set_int (value, icon_view->priv->columns);
1295 case PROP_ITEM_WIDTH:
1296 g_value_set_int (value, icon_view->priv->item_width);
1299 g_value_set_int (value, icon_view->priv->spacing);
1301 case PROP_ROW_SPACING:
1302 g_value_set_int (value, icon_view->priv->row_spacing);
1304 case PROP_COLUMN_SPACING:
1305 g_value_set_int (value, icon_view->priv->column_spacing);
1308 g_value_set_int (value, icon_view->priv->margin);
1310 case PROP_REORDERABLE:
1311 g_value_set_boolean (value, icon_view->priv->reorderable);
1313 case PROP_TOOLTIP_COLUMN:
1314 g_value_set_int (value, icon_view->priv->tooltip_column);
1317 case PROP_ITEM_PADDING:
1318 g_value_set_int (value, icon_view->priv->item_padding);
1321 case PROP_CELL_AREA:
1322 g_value_set_object (value, icon_view->priv->cell_area);
1325 case PROP_HADJUSTMENT:
1326 g_value_set_object (value, icon_view->priv->hadjustment);
1328 case PROP_VADJUSTMENT:
1329 g_value_set_object (value, icon_view->priv->vadjustment);
1331 case PROP_HSCROLL_POLICY:
1332 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1334 case PROP_VSCROLL_POLICY:
1335 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1339 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1344 /* GtkWidget methods */
1346 gtk_icon_view_destroy (GtkWidget *widget)
1348 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1350 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
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;
1392 gtk_widget_set_realized (widget, TRUE);
1394 gtk_widget_get_allocation (widget, &allocation);
1396 /* Make the main, clipping window */
1397 attributes.window_type = GDK_WINDOW_CHILD;
1398 attributes.x = allocation.x;
1399 attributes.y = allocation.y;
1400 attributes.width = allocation.width;
1401 attributes.height = allocation.height;
1402 attributes.wclass = GDK_INPUT_OUTPUT;
1403 attributes.visual = gtk_widget_get_visual (widget);
1404 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1406 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1408 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1409 &attributes, attributes_mask);
1410 gtk_widget_set_window (widget, window);
1411 gdk_window_set_user_data (window, widget);
1413 gtk_widget_get_allocation (widget, &allocation);
1415 /* Make the window for the icon view */
1418 attributes.width = MAX (icon_view->priv->width, allocation.width);
1419 attributes.height = MAX (icon_view->priv->height, allocation.height);
1420 attributes.event_mask = (GDK_EXPOSURE_MASK |
1422 GDK_POINTER_MOTION_MASK |
1423 GDK_BUTTON_PRESS_MASK |
1424 GDK_BUTTON_RELEASE_MASK |
1425 GDK_KEY_PRESS_MASK |
1426 GDK_KEY_RELEASE_MASK) |
1427 gtk_widget_get_events (widget);
1429 icon_view->priv->bin_window = gdk_window_new (window,
1430 &attributes, attributes_mask);
1431 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1433 gtk_widget_style_attach (widget);
1434 gdk_window_set_background (icon_view->priv->bin_window,
1435 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1437 gdk_window_show (icon_view->priv->bin_window);
1441 gtk_icon_view_unrealize (GtkWidget *widget)
1443 GtkIconView *icon_view;
1445 icon_view = GTK_ICON_VIEW (widget);
1447 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1448 gdk_window_destroy (icon_view->priv->bin_window);
1449 icon_view->priv->bin_window = NULL;
1451 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1455 gtk_icon_view_state_changed (GtkWidget *widget,
1456 GtkStateType previous_state)
1458 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1462 if (gtk_widget_get_realized (widget))
1464 style = gtk_widget_get_style (widget);
1465 state = gtk_widget_get_state (widget);
1467 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1468 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1471 gtk_widget_queue_draw (widget);
1475 gtk_icon_view_style_set (GtkWidget *widget,
1476 GtkStyle *previous_style)
1478 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1482 if (gtk_widget_get_realized (widget))
1484 style = gtk_widget_get_style (widget);
1485 state = gtk_widget_get_state (widget);
1487 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1488 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1491 gtk_widget_queue_resize (widget);
1495 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1499 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1503 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1507 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1511 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1515 for (list = icon_view->priv->children; list; list = list->next)
1517 GtkIconViewChild *child = list->data;
1519 /* totally ignore our child's requisition */
1520 gtk_widget_size_allocate (child->widget, &child->area);
1525 gtk_icon_view_size_allocate (GtkWidget *widget,
1526 GtkAllocation *allocation)
1528 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1530 gtk_widget_set_allocation (widget, allocation);
1532 if (gtk_widget_get_realized (widget))
1534 gdk_window_move_resize (gtk_widget_get_window (widget),
1535 allocation->x, allocation->y,
1536 allocation->width, allocation->height);
1537 gdk_window_resize (icon_view->priv->bin_window,
1538 MAX (icon_view->priv->width, allocation->width),
1539 MAX (icon_view->priv->height, allocation->height));
1542 gtk_icon_view_layout (icon_view);
1544 gtk_icon_view_allocate_children (icon_view);
1546 /* Delay signal emission */
1547 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1548 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1550 gtk_icon_view_set_hadjustment_values (icon_view);
1551 gtk_icon_view_set_vadjustment_values (icon_view);
1553 if (gtk_widget_get_realized (widget) &&
1554 icon_view->priv->scroll_to_path)
1557 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1558 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1559 icon_view->priv->scroll_to_path = NULL;
1561 gtk_icon_view_scroll_to_path (icon_view, path,
1562 icon_view->priv->scroll_to_use_align,
1563 icon_view->priv->scroll_to_row_align,
1564 icon_view->priv->scroll_to_col_align);
1565 gtk_tree_path_free (path);
1568 /* Emit any pending signals now */
1569 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1570 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1574 gtk_icon_view_draw (GtkWidget *widget,
1577 GtkIconView *icon_view;
1581 GtkIconViewDropPosition dest_pos;
1582 GtkIconViewItem *dest_item = NULL;
1584 icon_view = GTK_ICON_VIEW (widget);
1586 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1591 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1593 cairo_set_line_width (cr, 1.);
1595 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1599 dest_index = gtk_tree_path_get_indices (path)[0];
1600 gtk_tree_path_free (path);
1605 for (icons = icon_view->priv->items; icons; icons = icons->next)
1607 GtkIconViewItem *item = icons->data;
1611 cairo_rectangle (cr, item->x, item->y, item->width, item->height);
1614 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1616 gtk_icon_view_paint_item (icon_view, cr, item,
1618 icon_view->priv->draw_focus);
1620 if (dest_index == item->index)
1632 style = gtk_widget_get_style (widget);
1633 state = gtk_widget_get_state (widget);
1637 case GTK_ICON_VIEW_DROP_INTO:
1638 gtk_paint_focus (style,
1642 "iconview-drop-indicator",
1643 dest_item->x, dest_item->y,
1644 dest_item->width, dest_item->height);
1646 case GTK_ICON_VIEW_DROP_ABOVE:
1647 gtk_paint_focus (style,
1651 "iconview-drop-indicator",
1652 dest_item->x, dest_item->y - 1,
1653 dest_item->width, 2);
1655 case GTK_ICON_VIEW_DROP_LEFT:
1656 gtk_paint_focus (style,
1660 "iconview-drop-indicator",
1661 dest_item->x - 1, dest_item->y,
1662 2, dest_item->height);
1664 case GTK_ICON_VIEW_DROP_BELOW:
1665 gtk_paint_focus (style,
1669 "iconview-drop-indicator",
1670 dest_item->x, dest_item->y + dest_item->height - 1,
1671 dest_item->width, 2);
1673 case GTK_ICON_VIEW_DROP_RIGHT:
1674 gtk_paint_focus (style,
1678 "iconview-drop-indicator",
1679 dest_item->x + dest_item->width - 1, dest_item->y,
1680 2, dest_item->height);
1681 case GTK_ICON_VIEW_NO_DROP: ;
1686 if (icon_view->priv->doing_rubberband)
1687 gtk_icon_view_paint_rubberband (icon_view, cr);
1691 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1697 rubberband_scroll_timeout (gpointer data)
1699 GtkIconView *icon_view = data;
1701 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1702 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1703 icon_view->priv->scroll_value_diff);
1705 gtk_icon_view_update_rubberband (icon_view);
1711 gtk_icon_view_motion (GtkWidget *widget,
1712 GdkEventMotion *event)
1714 GtkAllocation allocation;
1715 GtkIconView *icon_view;
1718 icon_view = GTK_ICON_VIEW (widget);
1720 gtk_icon_view_maybe_begin_drag (icon_view, event);
1722 if (icon_view->priv->doing_rubberband)
1724 gtk_icon_view_update_rubberband (widget);
1726 abs_y = event->y - icon_view->priv->height *
1727 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1728 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1729 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1731 gtk_widget_get_allocation (widget, &allocation);
1733 if (abs_y < 0 || abs_y > allocation.height)
1736 icon_view->priv->scroll_value_diff = abs_y;
1738 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1740 icon_view->priv->event_last_x = event->x;
1741 icon_view->priv->event_last_y = event->y;
1743 if (icon_view->priv->scroll_timeout_id == 0)
1744 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1748 remove_scroll_timeout (icon_view);
1755 gtk_icon_view_remove (GtkContainer *container,
1758 GtkIconView *icon_view;
1759 GtkIconViewChild *child = NULL;
1762 icon_view = GTK_ICON_VIEW (container);
1764 tmp_list = icon_view->priv->children;
1767 child = tmp_list->data;
1768 if (child->widget == widget)
1770 gtk_widget_unparent (widget);
1772 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1773 g_list_free_1 (tmp_list);
1778 tmp_list = tmp_list->next;
1783 gtk_icon_view_forall (GtkContainer *container,
1784 gboolean include_internals,
1785 GtkCallback callback,
1786 gpointer callback_data)
1788 GtkIconView *icon_view;
1789 GtkIconViewChild *child = NULL;
1792 icon_view = GTK_ICON_VIEW (container);
1794 tmp_list = icon_view->priv->children;
1797 child = tmp_list->data;
1798 tmp_list = tmp_list->next;
1800 (* callback) (child->widget, callback_data);
1805 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1806 GtkIconViewItem *item)
1809 AtkObject *item_obj;
1811 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1814 item_obj = atk_object_ref_accessible_child (obj, item->index);
1815 if (item_obj != NULL)
1817 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1818 g_object_unref (item_obj);
1824 gtk_icon_view_add_editable (GtkCellArea *area,
1825 GtkCellRenderer *renderer,
1826 GtkCellEditable *editable,
1827 GdkRectangle *cell_area,
1829 GtkIconView *icon_view)
1831 GtkIconViewChild *child;
1832 GtkWidget *widget = GTK_WIDGET (editable);
1834 child = g_new (GtkIconViewChild, 1);
1836 child->widget = widget;
1837 child->area.x = cell_area->x;
1838 child->area.y = cell_area->y;
1839 child->area.width = cell_area->width;
1840 child->area.height = cell_area->height;
1842 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1844 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1845 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1847 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1851 gtk_icon_view_remove_editable (GtkCellArea *area,
1852 GtkCellRenderer *renderer,
1853 GtkCellEditable *editable,
1854 GtkIconView *icon_view)
1858 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1859 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1861 gtk_container_remove (GTK_CONTAINER (icon_view),
1862 GTK_WIDGET (editable));
1864 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1865 gtk_icon_view_queue_draw_path (icon_view, path);
1866 gtk_tree_path_free (path);
1870 gtk_icon_view_focus_changed (GtkCellArea *area,
1871 GtkCellRenderer *renderer,
1873 GtkIconView *icon_view)
1875 /* XXX Update cursor item for focus path here */
1879 * gtk_icon_view_set_cursor:
1880 * @icon_view: A #GtkIconView
1881 * @path: A #GtkTreePath
1882 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1883 * @start_editing: %TRUE if the specified cell should start being edited.
1885 * Sets the current keyboard focus to be at @path, and selects it. This is
1886 * useful when you want to focus the user's attention on a particular item.
1887 * If @cell is not %NULL, then focus is given to the cell specified by
1888 * it. Additionally, if @start_editing is %TRUE, then editing should be
1889 * started in the specified cell.
1891 * This function is often followed by <literal>gtk_widget_grab_focus
1892 * (icon_view)</literal> in order to give keyboard focus to the widget.
1893 * Please note that editing can only happen when the widget is realized.
1898 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1900 GtkCellRenderer *cell,
1901 gboolean start_editing)
1903 GtkIconViewItem *item = NULL;
1905 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1906 g_return_if_fail (path != NULL);
1907 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1909 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1911 if (gtk_tree_path_get_depth (path) == 1)
1912 item = g_list_nth_data (icon_view->priv->items,
1913 gtk_tree_path_get_indices(path)[0]);
1918 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1919 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1923 GdkRectangle cell_area;
1925 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
1926 icon_view->priv->effective_item_width,
1929 gtk_icon_view_set_cell_data (icon_view, item);
1930 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
1931 gtk_cell_area_activate (icon_view->priv->cell_area,
1932 icon_view->priv->cell_area_context,
1933 GTK_WIDGET (icon_view), &cell_area, 0 /* XXX flags */, TRUE);
1938 * gtk_icon_view_get_cursor:
1939 * @icon_view: A #GtkIconView
1940 * @path: (allow-none): Return location for the current cursor path, or %NULL
1941 * @cell: (allow-none): Return location the current focus cell, or %NULL
1943 * Fills in @path and @cell with the current cursor path and cell.
1944 * If the cursor isn't currently set, then *@path will be %NULL.
1945 * If no cell currently has focus, then *@cell will be %NULL.
1947 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1949 * Return value: %TRUE if the cursor is set.
1954 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1956 GtkCellRenderer **cell)
1958 GtkIconViewItem *item;
1960 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1962 item = icon_view->priv->cursor_item;
1967 *path = gtk_tree_path_new_from_indices (item->index, -1);
1972 if (cell != NULL && item != NULL)
1973 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1975 return (item != NULL);
1979 gtk_icon_view_button_press (GtkWidget *widget,
1980 GdkEventButton *event)
1982 GtkIconView *icon_view;
1983 GtkIconViewItem *item;
1984 gboolean dirty = FALSE;
1985 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1986 GdkRectangle cell_area;
1988 icon_view = GTK_ICON_VIEW (widget);
1990 if (event->window != icon_view->priv->bin_window)
1993 if (!gtk_widget_has_focus (widget))
1994 gtk_widget_grab_focus (widget);
1996 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1998 item = gtk_icon_view_get_item_at_coords (icon_view,
2004 * We consider only the the cells' area as the item area if the
2005 * item is not selected, but if it *is* selected, the complete
2006 * selection rectangle is considered to be part of the item.
2008 if (item != NULL && (cell != NULL || item->selected))
2012 if (gtk_cell_renderer_is_activatable (cell))
2016 gtk_icon_view_scroll_to_item (icon_view, item);
2018 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2020 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2022 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2023 (event->state & GDK_SHIFT_MASK))
2025 gtk_icon_view_unselect_all_internal (icon_view);
2027 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2028 if (!icon_view->priv->anchor_item)
2029 icon_view->priv->anchor_item = item;
2031 gtk_icon_view_select_all_between (icon_view,
2032 icon_view->priv->anchor_item,
2038 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2039 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2040 (event->state & GDK_CONTROL_MASK))
2042 item->selected = !item->selected;
2043 gtk_icon_view_queue_draw_item (icon_view, item);
2048 gtk_icon_view_unselect_all_internal (icon_view);
2050 item->selected = TRUE;
2051 gtk_icon_view_queue_draw_item (icon_view, item);
2054 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2055 icon_view->priv->anchor_item = item;
2058 /* Save press to possibly begin a drag */
2059 if (icon_view->priv->pressed_button < 0)
2061 icon_view->priv->pressed_button = event->button;
2062 icon_view->priv->press_start_x = event->x;
2063 icon_view->priv->press_start_y = event->y;
2066 if (!icon_view->priv->last_single_clicked)
2067 icon_view->priv->last_single_clicked = item;
2069 /* cancel the current editing, if it exists */
2070 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2072 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2075 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2076 icon_view->priv->effective_item_width,
2079 gtk_icon_view_set_cell_data (icon_view, item);
2080 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
2081 gtk_cell_area_activate (icon_view->priv->cell_area,
2082 icon_view->priv->cell_area_context,
2083 GTK_WIDGET (icon_view),
2084 &cell_area, 0/* XXX flags */, FALSE);
2089 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2090 !(event->state & GDK_CONTROL_MASK))
2092 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2095 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2096 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2099 /* don't draw keyboard focus around an clicked-on item */
2100 icon_view->priv->draw_focus = FALSE;
2103 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2105 item = gtk_icon_view_get_item_at_coords (icon_view,
2110 if (item && item == icon_view->priv->last_single_clicked)
2114 path = gtk_tree_path_new_from_indices (item->index, -1);
2115 gtk_icon_view_item_activated (icon_view, path);
2116 gtk_tree_path_free (path);
2119 icon_view->priv->last_single_clicked = NULL;
2120 icon_view->priv->pressed_button = -1;
2124 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2126 return event->button == 1;
2130 gtk_icon_view_button_release (GtkWidget *widget,
2131 GdkEventButton *event)
2133 GtkIconView *icon_view;
2135 icon_view = GTK_ICON_VIEW (widget);
2137 if (icon_view->priv->pressed_button == event->button)
2138 icon_view->priv->pressed_button = -1;
2140 gtk_icon_view_stop_rubberbanding (icon_view);
2142 remove_scroll_timeout (icon_view);
2148 gtk_icon_view_key_press (GtkWidget *widget,
2151 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2153 if (icon_view->priv->doing_rubberband)
2155 if (event->keyval == GDK_KEY_Escape)
2156 gtk_icon_view_stop_rubberbanding (icon_view);
2161 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2165 gtk_icon_view_key_release (GtkWidget *widget,
2168 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2170 if (icon_view->priv->doing_rubberband)
2173 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2177 gtk_icon_view_update_rubberband (gpointer data)
2179 GtkIconView *icon_view;
2181 GdkRectangle old_area;
2182 GdkRectangle new_area;
2183 GdkRectangle common;
2184 cairo_region_t *invalid_region;
2186 icon_view = GTK_ICON_VIEW (data);
2188 gdk_window_get_device_position (icon_view->priv->bin_window,
2189 icon_view->priv->rubberband_device,
2195 old_area.x = MIN (icon_view->priv->rubberband_x1,
2196 icon_view->priv->rubberband_x2);
2197 old_area.y = MIN (icon_view->priv->rubberband_y1,
2198 icon_view->priv->rubberband_y2);
2199 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2200 icon_view->priv->rubberband_x1) + 1;
2201 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2202 icon_view->priv->rubberband_y1) + 1;
2204 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2205 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2206 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2207 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2209 invalid_region = cairo_region_create_rectangle (&old_area);
2210 cairo_region_union_rectangle (invalid_region, &new_area);
2212 gdk_rectangle_intersect (&old_area, &new_area, &common);
2213 if (common.width > 2 && common.height > 2)
2215 cairo_region_t *common_region;
2217 /* make sure the border is invalidated */
2223 common_region = cairo_region_create_rectangle (&common);
2225 cairo_region_subtract (invalid_region, common_region);
2226 cairo_region_destroy (common_region);
2229 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2231 cairo_region_destroy (invalid_region);
2233 icon_view->priv->rubberband_x2 = x;
2234 icon_view->priv->rubberband_y2 = y;
2236 gtk_icon_view_update_rubberband_selection (icon_view);
2240 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2247 if (icon_view->priv->rubberband_device)
2250 for (items = icon_view->priv->items; items; items = items->next)
2252 GtkIconViewItem *item = items->data;
2254 item->selected_before_rubberbanding = item->selected;
2257 icon_view->priv->rubberband_x1 = x;
2258 icon_view->priv->rubberband_y1 = y;
2259 icon_view->priv->rubberband_x2 = x;
2260 icon_view->priv->rubberband_y2 = y;
2262 icon_view->priv->doing_rubberband = TRUE;
2263 icon_view->priv->rubberband_device = device;
2265 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2269 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2271 if (!icon_view->priv->doing_rubberband)
2274 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2275 icon_view->priv->rubberband_device);
2277 icon_view->priv->doing_rubberband = FALSE;
2278 icon_view->priv->rubberband_device = NULL;
2280 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2284 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2287 gint x, y, width, height;
2288 gboolean dirty = FALSE;
2290 x = MIN (icon_view->priv->rubberband_x1,
2291 icon_view->priv->rubberband_x2);
2292 y = MIN (icon_view->priv->rubberband_y1,
2293 icon_view->priv->rubberband_y2);
2294 width = ABS (icon_view->priv->rubberband_x1 -
2295 icon_view->priv->rubberband_x2);
2296 height = ABS (icon_view->priv->rubberband_y1 -
2297 icon_view->priv->rubberband_y2);
2299 for (items = icon_view->priv->items; items; items = items->next)
2301 GtkIconViewItem *item = items->data;
2305 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2306 x, y, width, height);
2308 selected = is_in ^ item->selected_before_rubberbanding;
2310 if (item->selected != selected)
2312 item->selected = selected;
2314 gtk_icon_view_queue_draw_item (icon_view, item);
2319 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2324 GdkRectangle hit_rect;
2329 hit_test (GtkCellRenderer *renderer,
2330 const GdkRectangle *cell_area,
2331 const GdkRectangle *cell_background,
2334 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2335 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2336 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2337 MAX (data->hit_rect.y, cell_area->y) > 0)
2340 return (data->hit != FALSE);
2344 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2345 GtkIconViewItem *item,
2351 GdkRectangle cell_area;
2352 HitTestData data = { { x, y, width, height }, FALSE };
2354 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2355 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2359 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2360 icon_view->priv->effective_item_width,
2363 gtk_icon_view_set_cell_data (icon_view, item);
2364 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
2365 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area,
2366 icon_view->priv->cell_area_context,
2367 GTK_WIDGET (icon_view),
2368 &cell_area, &cell_area,
2369 (GtkCellAllocCallback)hit_test, &data);
2375 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2377 gboolean dirty = FALSE;
2380 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2383 for (items = icon_view->priv->items; items; items = items->next)
2385 GtkIconViewItem *item = items->data;
2389 item->selected = FALSE;
2391 gtk_icon_view_queue_draw_item (icon_view, item);
2392 gtk_icon_view_item_selected_changed (icon_view, item);
2400 /* GtkIconView signals */
2402 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2404 gtk_icon_view_select_all (icon_view);
2408 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2410 gtk_icon_view_unselect_all (icon_view);
2414 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2416 gtk_icon_view_unselect_all (icon_view);
2418 if (icon_view->priv->cursor_item != NULL)
2419 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2423 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2426 GdkRectangle cell_area;
2429 if (!icon_view->priv->cursor_item)
2432 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2433 gtk_icon_view_get_cell_area (icon_view, icon_view->priv->cursor_item, &cell_area);
2434 activated = gtk_cell_area_activate (icon_view->priv->cell_area,
2435 icon_view->priv->cell_area_context,
2436 GTK_WIDGET (icon_view), &cell_area, 0 /* XXX flags */, FALSE);
2438 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2439 gtk_icon_view_item_activated (icon_view, path);
2440 gtk_tree_path_free (path);
2446 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2448 if (!icon_view->priv->cursor_item)
2451 switch (icon_view->priv->selection_mode)
2453 case GTK_SELECTION_NONE:
2455 case GTK_SELECTION_BROWSE:
2456 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2458 case GTK_SELECTION_SINGLE:
2459 if (icon_view->priv->cursor_item->selected)
2460 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2462 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2464 case GTK_SELECTION_MULTIPLE:
2465 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2466 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2468 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2469 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2474 /* Internal functions */
2476 gtk_icon_view_process_updates (GtkIconView *icon_view)
2478 /* Prior to drawing, we check if a layout has been scheduled. If so,
2479 * do it now that all cell view items have valid sizes before we proceeed
2480 * (and resize the bin_window if required).
2482 if (icon_view->priv->layout_idle_id != 0)
2483 gtk_icon_view_layout (icon_view);
2485 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2489 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2491 GtkAllocation allocation;
2492 GtkAdjustment *adj = icon_view->priv->hadjustment;
2493 gdouble old_page_size;
2499 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2501 old_value = gtk_adjustment_get_value (adj);
2502 old_upper = gtk_adjustment_get_upper (adj);
2503 old_page_size = gtk_adjustment_get_page_size (adj);
2504 new_upper = MAX (allocation.width, icon_view->priv->width);
2506 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2508 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2509 /* Quick explanation:
2510 * In LTR locales, leftmost portion of visible rectangle should stay
2511 * fixed, which means left edge of scrollbar thumb should remain fixed
2512 * and thus adjustment's value should stay the same.
2514 * In RTL locales, we want to keep rightmost portion of visible
2515 * rectangle fixed. This means right edge of thumb should remain fixed.
2516 * In this case, upper - value - page_size should remain constant.
2518 new_value = (new_upper - allocation.width) -
2519 (old_upper - old_value - old_page_size);
2520 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2523 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2525 gtk_adjustment_configure (adj,
2529 allocation.width * 0.1,
2530 allocation.width * 0.9,
2535 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2537 GtkAllocation allocation;
2538 GtkAdjustment *adj = icon_view->priv->vadjustment;
2540 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2542 gtk_adjustment_configure (adj,
2543 gtk_adjustment_get_value (adj),
2545 MAX (allocation.height, icon_view->priv->height),
2546 allocation.height * 0.1,
2547 allocation.height * 0.9,
2552 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2553 GtkAdjustment *adjustment)
2555 GtkIconViewPrivate *priv = icon_view->priv;
2558 if (adjustment && priv->hadjustment == adjustment)
2561 if (priv->hadjustment != NULL)
2563 g_signal_handlers_disconnect_matched (priv->hadjustment,
2564 G_SIGNAL_MATCH_DATA,
2565 0, 0, NULL, NULL, icon_view);
2566 g_object_unref (priv->hadjustment);
2570 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2573 g_signal_connect (adjustment, "value-changed",
2574 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2575 priv->hadjustment = g_object_ref_sink (adjustment);
2576 gtk_icon_view_set_hadjustment_values (icon_view);
2578 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2579 gtk_icon_view_accessible_set_adjustment (atk_obj,
2580 GTK_ORIENTATION_HORIZONTAL,
2583 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2587 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2588 GtkAdjustment *adjustment)
2590 GtkIconViewPrivate *priv = icon_view->priv;
2593 if (adjustment && priv->vadjustment == adjustment)
2596 if (priv->vadjustment != NULL)
2598 g_signal_handlers_disconnect_matched (priv->vadjustment,
2599 G_SIGNAL_MATCH_DATA,
2600 0, 0, NULL, NULL, icon_view);
2601 g_object_unref (priv->vadjustment);
2605 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2608 g_signal_connect (adjustment, "value-changed",
2609 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2610 priv->vadjustment = g_object_ref_sink (adjustment);
2611 gtk_icon_view_set_vadjustment_values (icon_view);
2613 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2614 gtk_icon_view_accessible_set_adjustment (atk_obj,
2615 GTK_ORIENTATION_VERTICAL,
2618 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2622 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2623 GtkIconView *icon_view)
2625 GtkIconViewPrivate *priv = icon_view->priv;
2627 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2629 gdk_window_move (priv->bin_window,
2630 - gtk_adjustment_get_value (priv->hadjustment),
2631 - gtk_adjustment_get_value (priv->vadjustment));
2633 if (icon_view->priv->doing_rubberband)
2634 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2636 gtk_icon_view_process_updates (icon_view);
2641 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2646 gint *maximum_width)
2648 GtkAllocation allocation;
2649 GtkIconViewPrivate *priv = icon_view->priv;
2650 GtkWidget *widget = GTK_WIDGET (icon_view);
2651 gint x, current_width;
2652 GList *items, *last_item;
2654 gint max_height = 0;
2657 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2665 current_width += 2 * priv->margin;
2667 gtk_widget_get_allocation (widget, &allocation);
2672 GtkIconViewItem *item = items->data;
2674 /* Get this item's particular width & height (all alignments are cached by now) */
2675 gtk_icon_view_set_cell_data (icon_view, item);
2676 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2677 priv->cell_area_context,
2679 &item->height, NULL);
2680 item->width = item_width;
2681 item->height += icon_view->priv->item_padding * 2;
2683 current_width += item->width;
2685 max_height = MAX (max_height, item->height);
2687 if (items != first_item)
2689 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2690 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2694 current_width += icon_view->priv->column_spacing;
2699 x = current_width - icon_view->priv->margin;
2701 if (current_width > *maximum_width)
2702 *maximum_width = current_width;
2708 items = items->next;
2713 /* Now go through the row again and align the icons */
2714 for (items = first_item; items != last_item; items = items->next)
2716 GtkIconViewItem *item = items->data;
2720 item->x = *maximum_width - item->width - item->x;
2721 item->col = col - 1 - item->col;
2724 /* All items in the same row get the same height */
2725 item->height = max_height;
2727 /* Adjust the new y coordinate. */
2728 if (item->y + item->height + icon_view->priv->row_spacing > *y)
2729 *y = item->y + item->height + icon_view->priv->row_spacing;
2736 gtk_icon_view_layout (GtkIconView *icon_view)
2738 GtkAllocation allocation;
2741 gint y = 0, maximum_width = 0;
2744 gboolean size_changed = FALSE;
2746 if (icon_view->priv->layout_idle_id != 0)
2748 g_source_remove (icon_view->priv->layout_idle_id);
2749 icon_view->priv->layout_idle_id = 0;
2752 if (icon_view->priv->model == NULL)
2755 widget = GTK_WIDGET (icon_view);
2757 item_width = icon_view->priv->item_width;
2759 /* Update the context widths for any invalidated
2761 gtk_icon_view_cache_widths (icon_view);
2763 /* Fetch the new item width if needed */
2766 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2768 item_width += icon_view->priv->item_padding * 2;
2771 icon_view->priv->effective_item_width = item_width;
2772 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2773 icon_view->priv->effective_item_width, -1);
2775 icons = icon_view->priv->items;
2776 y += icon_view->priv->margin;
2781 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2783 &y, &maximum_width);
2786 while (icons != NULL);
2788 if (maximum_width != icon_view->priv->width)
2790 icon_view->priv->width = maximum_width;
2791 size_changed = TRUE;
2794 y += icon_view->priv->margin;
2796 if (y != icon_view->priv->height)
2798 icon_view->priv->height = y;
2799 size_changed = TRUE;
2802 gtk_icon_view_set_hadjustment_values (icon_view);
2803 gtk_icon_view_set_vadjustment_values (icon_view);
2806 gtk_widget_queue_resize_no_redraw (widget);
2808 gtk_widget_get_allocation (widget, &allocation);
2809 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2810 gdk_window_resize (icon_view->priv->bin_window,
2811 MAX (icon_view->priv->width, allocation.width),
2812 MAX (icon_view->priv->height, allocation.height));
2814 if (icon_view->priv->scroll_to_path)
2818 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2819 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2820 icon_view->priv->scroll_to_path = NULL;
2822 gtk_icon_view_scroll_to_path (icon_view, path,
2823 icon_view->priv->scroll_to_use_align,
2824 icon_view->priv->scroll_to_row_align,
2825 icon_view->priv->scroll_to_col_align);
2826 gtk_tree_path_free (path);
2829 gtk_widget_queue_draw (widget);
2833 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2834 GtkIconViewItem *item,
2835 GdkRectangle *cell_area)
2837 cell_area->x = item->x + icon_view->priv->item_padding;
2838 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2839 cell_area->y = item->y + icon_view->priv->item_padding;
2840 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2843 /* This ensures that all widths have been cached in the
2844 * context and we have proper alignments to go on.
2847 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2851 for (items = icon_view->priv->items; items; items = items->next)
2853 GtkIconViewItem *item = items->data;
2855 /* Only fetch the width of items with invalidated sizes */
2856 if (item->width < 0)
2858 gtk_icon_view_set_cell_data (icon_view, item);
2859 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2860 icon_view->priv->cell_area_context,
2861 GTK_WIDGET (icon_view), NULL, NULL);
2867 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2869 g_list_foreach (icon_view->priv->items,
2870 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2874 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2881 gtk_icon_view_paint_item (GtkIconView *icon_view,
2883 GtkIconViewItem *item,
2886 gboolean draw_focus)
2888 GdkRectangle cell_area;
2890 GtkCellRendererState flags;
2891 GtkWidget *widget = GTK_WIDGET (icon_view);
2892 GtkIconViewPrivate *priv = icon_view->priv;
2895 if (priv->model == NULL)
2898 style = gtk_widget_get_style (widget);
2899 gtk_icon_view_set_cell_data (icon_view, item);
2903 flags = GTK_CELL_RENDERER_SELECTED;
2904 if (gtk_widget_has_focus (widget))
2905 state = GTK_STATE_SELECTED;
2907 state = GTK_STATE_ACTIVE;
2912 state = GTK_STATE_NORMAL;
2917 gtk_paint_flat_box (style,
2921 GTK_WIDGET (icon_view),
2924 item->width, item->height);
2929 cell_area.width = item->width;
2930 cell_area.height = item->height;
2932 if (gtk_widget_has_focus (widget) && item == icon_view->priv->cursor_item)
2933 flags |= GTK_CELL_RENDERER_FOCUSED;
2935 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
2936 icon_view->priv->effective_item_width,
2939 gtk_cell_area_render (priv->cell_area, priv->cell_area_context,
2940 widget, cr, &cell_area, &cell_area, flags,
2945 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2949 GdkColor *fill_color_gdk;
2950 guchar fill_color_alpha;
2954 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2955 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2956 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2957 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2959 gtk_widget_style_get (GTK_WIDGET (icon_view),
2960 "selection-box-color", &fill_color_gdk,
2961 "selection-box-alpha", &fill_color_alpha,
2964 if (!fill_color_gdk)
2965 fill_color_gdk = gdk_color_copy (>k_widget_get_style (GTK_WIDGET (icon_view))->base[GTK_STATE_SELECTED]);
2967 gdk_cairo_set_source_color (cr, fill_color_gdk);
2969 gdk_cairo_rectangle (cr, &rect);
2972 cairo_paint_with_alpha (cr, fill_color_alpha / 255.);
2974 cairo_rectangle (cr,
2975 rect.x + 0.5, rect.y + 0.5,
2976 rect.width - 1, rect.height - 1);
2979 gdk_color_free (fill_color_gdk);
2985 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2991 index = gtk_tree_path_get_indices (path)[0];
2993 for (l = icon_view->priv->items; l; l = l->next)
2995 GtkIconViewItem *item = l->data;
2997 if (item->index == index)
2999 gtk_icon_view_queue_draw_item (icon_view, item);
3006 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3007 GtkIconViewItem *item)
3013 rect.width = item->width;
3014 rect.height = item->height;
3016 if (icon_view->priv->bin_window)
3017 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3021 layout_callback (gpointer user_data)
3023 GtkIconView *icon_view;
3025 icon_view = GTK_ICON_VIEW (user_data);
3027 icon_view->priv->layout_idle_id = 0;
3029 gtk_icon_view_layout (icon_view);
3035 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3037 if (icon_view->priv->layout_idle_id != 0)
3040 icon_view->priv->layout_idle_id =
3041 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3042 layout_callback, icon_view, NULL);
3046 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3047 GtkIconViewItem *item,
3048 GtkCellRenderer *cursor_cell)
3051 AtkObject *item_obj;
3052 AtkObject *cursor_item_obj;
3054 if (icon_view->priv->cursor_item == item &&
3055 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3058 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3059 if (icon_view->priv->cursor_item != NULL)
3061 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3064 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3065 if (cursor_item_obj != NULL)
3066 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3069 icon_view->priv->cursor_item = item;
3071 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3073 gtk_icon_view_queue_draw_item (icon_view, item);
3075 /* Notify that accessible focus object has changed */
3076 item_obj = atk_object_ref_accessible_child (obj, item->index);
3078 if (item_obj != NULL)
3080 atk_focus_tracker_notify (item_obj);
3081 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3082 g_object_unref (item_obj);
3087 static GtkIconViewItem *
3088 gtk_icon_view_item_new (void)
3090 GtkIconViewItem *item;
3092 item = g_slice_new0 (GtkIconViewItem);
3101 gtk_icon_view_item_free (GtkIconViewItem *item)
3103 g_return_if_fail (item != NULL);
3105 g_slice_free (GtkIconViewItem, item);
3108 static GtkIconViewItem *
3109 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3112 gboolean only_in_cell,
3113 GtkCellRenderer **cell_at_pos)
3118 *cell_at_pos = NULL;
3120 for (items = icon_view->priv->items; items; items = items->next)
3122 GtkIconViewItem *item = items->data;
3124 if (x >= item->x - icon_view->priv->column_spacing/2 &&
3125 x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3126 y >= item->y - icon_view->priv->row_spacing/2 &&
3127 y <= item->y + item->height + icon_view->priv->row_spacing/2)
3129 if (only_in_cell || cell_at_pos)
3131 GdkRectangle cell_area;
3132 GtkCellRenderer *cell = NULL;
3134 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
3135 icon_view->priv->effective_item_width,
3138 gtk_icon_view_set_cell_data (icon_view, item);
3139 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
3141 if (x >= cell_area.x && x <= cell_area.x + cell_area.width &&
3142 y >= cell_area.y && y <= cell_area.y + cell_area.height)
3143 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area,
3144 icon_view->priv->cell_area_context,
3145 GTK_WIDGET (icon_view),
3150 *cell_at_pos = cell;
3153 return cell != NULL ? item : NULL;
3164 gtk_icon_view_select_item (GtkIconView *icon_view,
3165 GtkIconViewItem *item)
3167 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3168 g_return_if_fail (item != NULL);
3173 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3175 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3176 gtk_icon_view_unselect_all_internal (icon_view);
3178 item->selected = TRUE;
3180 gtk_icon_view_item_selected_changed (icon_view, item);
3181 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3183 gtk_icon_view_queue_draw_item (icon_view, item);
3188 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3189 GtkIconViewItem *item)
3191 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3192 g_return_if_fail (item != NULL);
3194 if (!item->selected)
3197 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3198 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3201 item->selected = FALSE;
3203 gtk_icon_view_item_selected_changed (icon_view, item);
3204 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3206 gtk_icon_view_queue_draw_item (icon_view, item);
3210 verify_items (GtkIconView *icon_view)
3215 for (items = icon_view->priv->items; items; items = items->next)
3217 GtkIconViewItem *item = items->data;
3219 if (item->index != i)
3220 g_error ("List item does not match its index: "
3221 "item index %d and list index %d\n", item->index, i);
3228 gtk_icon_view_row_changed (GtkTreeModel *model,
3233 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3234 GtkIconViewItem *item;
3237 /* ignore changes in branches */
3238 if (gtk_tree_path_get_depth (path) > 1)
3241 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3243 index = gtk_tree_path_get_indices(path)[0];
3244 item = g_list_nth_data (icon_view->priv->items, index);
3246 gtk_icon_view_item_invalidate_size (item);
3247 gtk_icon_view_queue_layout (icon_view);
3249 verify_items (icon_view);
3253 gtk_icon_view_row_inserted (GtkTreeModel *model,
3258 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3260 GtkIconViewItem *item;
3261 gboolean iters_persist;
3264 /* ignore changes in branches */
3265 if (gtk_tree_path_get_depth (path) > 1)
3268 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3270 index = gtk_tree_path_get_indices(path)[0];
3272 item = gtk_icon_view_item_new ();
3277 item->index = index;
3279 /* FIXME: We can be more efficient here,
3280 we can store a tail pointer and use that when
3281 appending (which is a rather common operation)
3283 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3286 list = g_list_nth (icon_view->priv->items, index + 1);
3287 for (; list; list = list->next)
3294 verify_items (icon_view);
3296 gtk_icon_view_queue_layout (icon_view);
3300 gtk_icon_view_row_deleted (GtkTreeModel *model,
3304 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3306 GtkIconViewItem *item;
3308 gboolean emit = FALSE;
3310 /* ignore changes in branches */
3311 if (gtk_tree_path_get_depth (path) > 1)
3314 index = gtk_tree_path_get_indices(path)[0];
3316 list = g_list_nth (icon_view->priv->items, index);
3319 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3321 if (item == icon_view->priv->anchor_item)
3322 icon_view->priv->anchor_item = NULL;
3324 if (item == icon_view->priv->cursor_item)
3325 icon_view->priv->cursor_item = NULL;
3330 gtk_icon_view_item_free (item);
3332 for (next = list->next; next; next = next->next)
3339 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3341 verify_items (icon_view);
3343 gtk_icon_view_queue_layout (icon_view);
3346 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3350 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3351 GtkTreePath *parent,
3356 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3359 GList *items = NULL, *list;
3360 GtkIconViewItem **item_array;
3363 /* ignore changes in branches */
3367 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3369 length = gtk_tree_model_iter_n_children (model, NULL);
3371 order = g_new (gint, length);
3372 for (i = 0; i < length; i++)
3373 order [new_order[i]] = i;
3375 item_array = g_new (GtkIconViewItem *, length);
3376 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3377 item_array[order[i]] = list->data;
3380 for (i = length - 1; i >= 0; i--)
3382 item_array[i]->index = i;
3383 items = g_list_prepend (items, item_array[i]);
3386 g_free (item_array);
3387 g_list_free (icon_view->priv->items);
3388 icon_view->priv->items = items;
3390 gtk_icon_view_queue_layout (icon_view);
3392 verify_items (icon_view);
3396 gtk_icon_view_build_items (GtkIconView *icon_view)
3400 gboolean iters_persist;
3401 GList *items = NULL;
3403 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3405 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3413 GtkIconViewItem *item = gtk_icon_view_item_new ();
3422 items = g_list_prepend (items, item);
3424 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3426 icon_view->priv->items = g_list_reverse (items);
3430 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3433 GtkMovementStep step,
3437 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3438 I_("move-cursor"), 2,
3442 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3447 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3450 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3455 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3462 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3463 GtkMovementStep step,
3466 GdkModifierType state;
3468 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3469 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3470 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3471 step == GTK_MOVEMENT_DISPLAY_LINES ||
3472 step == GTK_MOVEMENT_PAGES ||
3473 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3475 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3478 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3479 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3481 if (gtk_get_current_event_state (&state))
3483 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3484 icon_view->priv->ctrl_pressed = TRUE;
3485 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3486 icon_view->priv->shift_pressed = TRUE;
3488 /* else we assume not pressed */
3492 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3493 case GTK_MOVEMENT_VISUAL_POSITIONS:
3494 gtk_icon_view_move_cursor_left_right (icon_view, count);
3496 case GTK_MOVEMENT_DISPLAY_LINES:
3497 gtk_icon_view_move_cursor_up_down (icon_view, count);
3499 case GTK_MOVEMENT_PAGES:
3500 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3502 case GTK_MOVEMENT_BUFFER_ENDS:
3503 gtk_icon_view_move_cursor_start_end (icon_view, count);
3506 g_assert_not_reached ();
3509 icon_view->priv->ctrl_pressed = FALSE;
3510 icon_view->priv->shift_pressed = FALSE;
3512 icon_view->priv->draw_focus = TRUE;
3517 static GtkIconViewItem *
3518 find_item (GtkIconView *icon_view,
3519 GtkIconViewItem *current,
3525 GtkIconViewItem *item;
3527 /* FIXME: this could be more efficient
3529 row = current->row + row_ofs;
3530 col = current->col + col_ofs;
3532 for (items = icon_view->priv->items; items; items = items->next)
3535 if (item->row == row && item->col == col)
3542 static GtkIconViewItem *
3543 find_item_page_up_down (GtkIconView *icon_view,
3544 GtkIconViewItem *current,
3551 y = current->y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3553 item = g_list_find (icon_view->priv->items, current);
3558 for (next = item->next; next; next = next->next)
3560 if (((GtkIconViewItem *)next->data)->col == col)
3563 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3573 for (next = item->prev; next; next = next->prev)
3575 if (((GtkIconViewItem *)next->data)->col == col)
3578 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3592 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3593 GtkIconViewItem *anchor,
3594 GtkIconViewItem *cursor)
3597 GtkIconViewItem *item;
3598 gint row1, row2, col1, col2;
3599 gboolean dirty = FALSE;
3601 if (anchor->row < cursor->row)
3612 if (anchor->col < cursor->col)
3623 for (items = icon_view->priv->items; items; items = items->next)
3627 if (row1 <= item->row && item->row <= row2 &&
3628 col1 <= item->col && item->col <= col2)
3630 if (!item->selected)
3633 item->selected = TRUE;
3634 gtk_icon_view_item_selected_changed (icon_view, item);
3636 gtk_icon_view_queue_draw_item (icon_view, item);
3644 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3647 GtkIconViewItem *item;
3648 GtkCellRenderer *cell;
3649 gboolean dirty = FALSE;
3651 GtkDirectionType direction;
3653 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3656 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3658 if (!icon_view->priv->cursor_item)
3663 list = icon_view->priv->items;
3665 list = g_list_last (icon_view->priv->items);
3667 item = list ? list->data : NULL;
3669 /* Give focus to the first cell initially */
3670 gtk_icon_view_set_cell_data (icon_view, item);
3671 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3675 item = icon_view->priv->cursor_item;
3676 step = count > 0 ? 1 : -1;
3678 /* Save the current focus cell in case we hit the edge */
3679 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3683 gtk_icon_view_set_cell_data (icon_view, item);
3685 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3688 item = find_item (icon_view, item, step, 0);
3694 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3696 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3698 gtk_widget_child_focus (toplevel,
3699 direction == GTK_DIR_UP ?
3700 GTK_DIR_TAB_BACKWARD :
3701 GTK_DIR_TAB_FORWARD);
3704 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3708 if (icon_view->priv->ctrl_pressed ||
3709 !icon_view->priv->shift_pressed ||
3710 !icon_view->priv->anchor_item ||
3711 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3712 icon_view->priv->anchor_item = item;
3714 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3715 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3717 if (!icon_view->priv->ctrl_pressed &&
3718 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3720 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3721 dirty = gtk_icon_view_select_all_between (icon_view,
3722 icon_view->priv->anchor_item,
3726 gtk_icon_view_scroll_to_item (icon_view, item);
3729 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3733 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3736 GtkIconViewItem *item;
3737 gboolean dirty = FALSE;
3739 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3742 if (!icon_view->priv->cursor_item)
3747 list = icon_view->priv->items;
3749 list = g_list_last (icon_view->priv->items);
3751 item = list ? list->data : NULL;
3754 item = find_item_page_up_down (icon_view,
3755 icon_view->priv->cursor_item,
3758 if (item == icon_view->priv->cursor_item)
3759 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3764 if (icon_view->priv->ctrl_pressed ||
3765 !icon_view->priv->shift_pressed ||
3766 !icon_view->priv->anchor_item ||
3767 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3768 icon_view->priv->anchor_item = item;
3770 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3772 if (!icon_view->priv->ctrl_pressed &&
3773 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3775 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3776 dirty = gtk_icon_view_select_all_between (icon_view,
3777 icon_view->priv->anchor_item,
3781 gtk_icon_view_scroll_to_item (icon_view, item);
3784 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3788 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3791 GtkIconViewItem *item;
3792 GtkCellRenderer *cell = NULL;
3793 gboolean dirty = FALSE;
3795 GtkDirectionType direction;
3797 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3800 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3802 if (!icon_view->priv->cursor_item)
3807 list = icon_view->priv->items;
3809 list = g_list_last (icon_view->priv->items);
3811 item = list ? list->data : NULL;
3813 /* Give focus to the first cell initially */
3814 gtk_icon_view_set_cell_data (icon_view, item);
3815 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3819 item = icon_view->priv->cursor_item;
3820 step = count > 0 ? 1 : -1;
3822 /* Save the current focus cell in case we hit the edge */
3823 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3827 gtk_icon_view_set_cell_data (icon_view, item);
3829 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3832 item = find_item (icon_view, item, 0, step);
3838 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3840 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3842 gtk_widget_child_focus (toplevel,
3843 direction == GTK_DIR_LEFT ?
3844 GTK_DIR_TAB_BACKWARD :
3845 GTK_DIR_TAB_FORWARD);
3848 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3852 if (icon_view->priv->ctrl_pressed ||
3853 !icon_view->priv->shift_pressed ||
3854 !icon_view->priv->anchor_item ||
3855 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3856 icon_view->priv->anchor_item = item;
3858 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3859 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3861 if (!icon_view->priv->ctrl_pressed &&
3862 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3864 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3865 dirty = gtk_icon_view_select_all_between (icon_view,
3866 icon_view->priv->anchor_item,
3870 gtk_icon_view_scroll_to_item (icon_view, item);
3873 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3877 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3880 GtkIconViewItem *item;
3882 gboolean dirty = FALSE;
3884 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3888 list = icon_view->priv->items;
3890 list = g_list_last (icon_view->priv->items);
3892 item = list ? list->data : NULL;
3894 if (item == icon_view->priv->cursor_item)
3895 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3900 if (icon_view->priv->ctrl_pressed ||
3901 !icon_view->priv->shift_pressed ||
3902 !icon_view->priv->anchor_item ||
3903 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3904 icon_view->priv->anchor_item = item;
3906 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3908 if (!icon_view->priv->ctrl_pressed &&
3909 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3911 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3912 dirty = gtk_icon_view_select_all_between (icon_view,
3913 icon_view->priv->anchor_item,
3917 gtk_icon_view_scroll_to_item (icon_view, item);
3920 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3924 * gtk_icon_view_scroll_to_path:
3925 * @icon_view: A #GtkIconView.
3926 * @path: The path of the item to move to.
3927 * @use_align: whether to use alignment arguments, or %FALSE.
3928 * @row_align: The vertical alignment of the item specified by @path.
3929 * @col_align: The horizontal alignment of the item specified by @path.
3931 * Moves the alignments of @icon_view to the position specified by @path.
3932 * @row_align determines where the row is placed, and @col_align determines
3933 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3934 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3937 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3938 * tree does the minimum amount of work to scroll the item onto the screen.
3939 * This means that the item will be scrolled to the edge closest to its current
3940 * position. If the item is currently visible on the screen, nothing is done.
3942 * This function only works if the model is set, and @path is a valid row on
3943 * the model. If the model changes before the @icon_view is realized, the
3944 * centered path will be modified to reflect this change.
3949 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3955 GtkIconViewItem *item = NULL;
3958 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3959 g_return_if_fail (path != NULL);
3960 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3961 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3963 widget = GTK_WIDGET (icon_view);
3965 if (gtk_tree_path_get_depth (path) > 0)
3966 item = g_list_nth_data (icon_view->priv->items,
3967 gtk_tree_path_get_indices(path)[0]);
3969 if (!item || item->width < 0 ||
3970 !gtk_widget_get_realized (widget))
3972 if (icon_view->priv->scroll_to_path)
3973 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3975 icon_view->priv->scroll_to_path = NULL;
3978 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3980 icon_view->priv->scroll_to_use_align = use_align;
3981 icon_view->priv->scroll_to_row_align = row_align;
3982 icon_view->priv->scroll_to_col_align = col_align;
3989 GtkAllocation allocation;
3994 gtk_widget_style_get (widget,
3995 "focus-line-width", &focus_width,
3998 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4000 gtk_widget_get_allocation (widget, &allocation);
4002 offset = y + item->y - focus_width - row_align * (allocation.height - item->height);
4004 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4005 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4007 offset = x + item->x - focus_width - col_align * (allocation.width - item->width);
4009 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4010 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4012 gtk_adjustment_changed (icon_view->priv->hadjustment);
4013 gtk_adjustment_changed (icon_view->priv->vadjustment);
4016 gtk_icon_view_scroll_to_item (icon_view, item);
4021 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4022 GtkIconViewItem *item)
4024 GtkAllocation allocation;
4025 GtkWidget *widget = GTK_WIDGET (icon_view);
4026 gint x, y, width, height;
4029 gtk_widget_style_get (widget,
4030 "focus-line-width", &focus_width,
4033 width = gdk_window_get_width (icon_view->priv->bin_window);
4034 height = gdk_window_get_height (icon_view->priv->bin_window);
4035 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4037 gtk_widget_get_allocation (widget, &allocation);
4039 if (y + item->y - focus_width < 0)
4040 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4041 gtk_adjustment_get_value (icon_view->priv->vadjustment) + y + item->y - focus_width);
4042 else if (y + item->y + item->height + focus_width > allocation.height)
4043 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4044 gtk_adjustment_get_value (icon_view->priv->vadjustment) + y + item->y + item->height
4045 + focus_width - allocation.height);
4047 if (x + item->x - focus_width < 0)
4048 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4049 gtk_adjustment_get_value (icon_view->priv->hadjustment) + x + item->x - focus_width);
4050 else if (x + item->x + item->width + focus_width > allocation.width)
4051 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4052 gtk_adjustment_get_value (icon_view->priv->hadjustment) + x + item->x + item->width
4053 + focus_width - allocation.width);
4055 gtk_adjustment_changed (icon_view->priv->hadjustment);
4056 gtk_adjustment_changed (icon_view->priv->vadjustment);
4059 /* GtkCellLayout implementation */
4060 static GtkCellArea *
4061 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4063 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4065 return icon_view->priv->cell_area;
4069 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4070 GtkIconViewItem *item)
4072 gboolean iters_persist;
4075 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4081 path = gtk_tree_path_new_from_indices (item->index, -1);
4082 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4084 gtk_tree_path_free (path);
4089 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4090 icon_view->priv->model,
4091 &iter, FALSE, FALSE);
4100 * gtk_icon_view_new:
4102 * Creates a new #GtkIconView widget
4104 * Return value: A newly created #GtkIconView widget
4109 gtk_icon_view_new (void)
4111 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4115 * gtk_icon_view_new_with_model:
4116 * @model: The model.
4118 * Creates a new #GtkIconView widget with the model @model.
4120 * Return value: A newly created #GtkIconView widget.
4125 gtk_icon_view_new_with_model (GtkTreeModel *model)
4127 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4131 * gtk_icon_view_convert_widget_to_bin_window_coords:
4132 * @icon_view: a #GtkIconView
4133 * @wx: X coordinate relative to the widget
4134 * @wy: Y coordinate relative to the widget
4135 * @bx: return location for bin_window X coordinate
4136 * @by: return location for bin_window Y coordinate
4138 * Converts widget coordinates to coordinates for the bin_window,
4139 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4144 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4152 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4154 if (icon_view->priv->bin_window)
4155 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4166 * gtk_icon_view_get_path_at_pos:
4167 * @icon_view: A #GtkIconView.
4168 * @x: The x position to be identified
4169 * @y: The y position to be identified
4171 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4172 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4173 * the cell at the specified position.
4174 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4175 * widget coordinates to bin_window coordinates.
4177 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4178 * if no icon exists at that position.
4183 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4187 GtkIconViewItem *item;
4190 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4192 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4197 path = gtk_tree_path_new_from_indices (item->index, -1);
4203 * gtk_icon_view_get_item_at_pos:
4204 * @icon_view: A #GtkIconView.
4205 * @x: The x position to be identified
4206 * @y: The y position to be identified
4207 * @path: (allow-none): Return location for the path, or %NULL
4208 * @cell: Return location for the renderer responsible for the cell
4209 * at (@x, @y), or %NULL
4211 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4212 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4213 * obtains the cell at the specified position. The returned path should
4214 * be freed with gtk_tree_path_free().
4215 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4216 * widget coordinates to bin_window coordinates.
4218 * Return value: %TRUE if an item exists at the specified position
4223 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4227 GtkCellRenderer **cell)
4229 GtkIconViewItem *item;
4230 GtkCellRenderer *renderer = NULL;
4232 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4234 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4239 *path = gtk_tree_path_new_from_indices (item->index, -1);
4247 return (item != NULL);
4251 * gtk_icon_view_set_tooltip_item:
4252 * @icon_view: a #GtkIconView
4253 * @tooltip: a #GtkTooltip
4254 * @path: a #GtkTreePath
4256 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4257 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4258 * See also gtk_tooltip_set_tip_area().
4263 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4264 GtkTooltip *tooltip,
4267 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4268 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4270 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4274 * gtk_icon_view_set_tooltip_cell:
4275 * @icon_view: a #GtkIconView
4276 * @tooltip: a #GtkTooltip
4277 * @path: a #GtkTreePath
4278 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4280 * Sets the tip area of @tooltip to the area which @cell occupies in
4281 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4283 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4288 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4289 GtkTooltip *tooltip,
4291 GtkCellRenderer *cell)
4294 GtkIconViewItem *item = NULL;
4297 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4298 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4299 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4301 if (gtk_tree_path_get_depth (path) > 0)
4302 item = g_list_nth_data (icon_view->priv->items,
4303 gtk_tree_path_get_indices(path)[0]);
4310 GdkRectangle cell_area;
4312 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
4313 icon_view->priv->effective_item_width,
4315 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
4316 gtk_icon_view_set_cell_data (icon_view, item);
4317 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area,
4318 icon_view->priv->cell_area_context,
4319 GTK_WIDGET (icon_view),
4320 cell, &cell_area, &rect);
4326 rect.width = item->width;
4327 rect.height = item->height;
4330 if (icon_view->priv->bin_window)
4332 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4337 gtk_tooltip_set_tip_area (tooltip, &rect);
4342 * gtk_icon_view_get_tooltip_context:
4343 * @icon_view: an #GtkIconView
4344 * @x: the x coordinate (relative to widget coordinates)
4345 * @y: the y coordinate (relative to widget coordinates)
4346 * @keyboard_tip: whether this is a keyboard tooltip or not
4347 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4348 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4349 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4351 * This function is supposed to be used in a #GtkWidget::query-tooltip
4352 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4353 * which are received in the signal handler, should be passed to this
4354 * function without modification.
4356 * The return value indicates whether there is an icon view item at the given
4357 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4358 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4359 * @model, @path and @iter which have been provided will be set to point to
4360 * that row and the corresponding model. @x and @y will always be converted
4361 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4363 * Return value: whether or not the given tooltip context points to a item
4368 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4371 gboolean keyboard_tip,
4372 GtkTreeModel **model,
4376 GtkTreePath *tmppath = NULL;
4378 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4379 g_return_val_if_fail (x != NULL, FALSE);
4380 g_return_val_if_fail (y != NULL, FALSE);
4384 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4391 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4394 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4399 *model = gtk_icon_view_get_model (icon_view);
4402 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4408 gtk_tree_path_free (tmppath);
4414 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4417 gboolean keyboard_tip,
4418 GtkTooltip *tooltip,
4424 GtkTreeModel *model;
4425 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4427 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4430 &model, &path, &iter))
4433 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4437 gtk_tree_path_free (path);
4441 gtk_tooltip_set_markup (tooltip, str);
4442 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4444 gtk_tree_path_free (path);
4452 * gtk_icon_view_set_tooltip_column:
4453 * @icon_view: a #GtkIconView
4454 * @column: an integer, which is a valid column number for @icon_view's model
4456 * If you only plan to have simple (text-only) tooltips on full items, you
4457 * can use this function to have #GtkIconView handle these automatically
4458 * for you. @column should be set to the column in @icon_view's model
4459 * containing the tooltip texts, or -1 to disable this feature.
4461 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4462 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4464 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4465 * so &, <, etc have to be escaped in the text.
4470 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4473 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4475 if (column == icon_view->priv->tooltip_column)
4480 g_signal_handlers_disconnect_by_func (icon_view,
4481 gtk_icon_view_set_tooltip_query_cb,
4483 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4487 if (icon_view->priv->tooltip_column == -1)
4489 g_signal_connect (icon_view, "query-tooltip",
4490 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4491 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4495 icon_view->priv->tooltip_column = column;
4496 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4500 * gtk_icon_view_get_tooltip_column:
4501 * @icon_view: a #GtkIconView
4503 * Returns the column of @icon_view's model which is being used for
4504 * displaying tooltips on @icon_view's rows.
4506 * Return value: the index of the tooltip column that is currently being
4507 * used, or -1 if this is disabled.
4512 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4514 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4516 return icon_view->priv->tooltip_column;
4520 * gtk_icon_view_get_visible_range:
4521 * @icon_view: A #GtkIconView
4522 * @start_path: (allow-none): Return location for start of region, or %NULL
4523 * @end_path: (allow-none): Return location for end of region, or %NULL
4525 * Sets @start_path and @end_path to be the first and last visible path.
4526 * Note that there may be invisible paths in between.
4528 * Both paths should be freed with gtk_tree_path_free() after use.
4530 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4535 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4536 GtkTreePath **start_path,
4537 GtkTreePath **end_path)
4539 gint start_index = -1;
4540 gint end_index = -1;
4543 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4545 if (icon_view->priv->hadjustment == NULL ||
4546 icon_view->priv->vadjustment == NULL)
4549 if (start_path == NULL && end_path == NULL)
4552 for (icons = icon_view->priv->items; icons; icons = icons->next)
4554 GtkIconViewItem *item = icons->data;
4556 if ((item->x + item->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4557 (item->y + item->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4558 (item->x <= (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) + gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4559 (item->y <= (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) + gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4561 if (start_index == -1)
4562 start_index = item->index;
4563 end_index = item->index;
4567 if (start_path && start_index != -1)
4568 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4569 if (end_path && end_index != -1)
4570 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4572 return start_index != -1;
4576 * gtk_icon_view_selected_foreach:
4577 * @icon_view: A #GtkIconView.
4578 * @func: (scope call): The function to call for each selected icon.
4579 * @data: User data to pass to the function.
4581 * Calls a function for each selected icon. Note that the model or
4582 * selection cannot be modified from within this function.
4587 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4588 GtkIconViewForeachFunc func,
4593 for (list = icon_view->priv->items; list; list = list->next)
4595 GtkIconViewItem *item = list->data;
4596 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4599 (* func) (icon_view, path, data);
4601 gtk_tree_path_free (path);
4606 * gtk_icon_view_set_selection_mode:
4607 * @icon_view: A #GtkIconView.
4608 * @mode: The selection mode
4610 * Sets the selection mode of the @icon_view.
4615 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4616 GtkSelectionMode mode)
4618 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4620 if (mode == icon_view->priv->selection_mode)
4623 if (mode == GTK_SELECTION_NONE ||
4624 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4625 gtk_icon_view_unselect_all (icon_view);
4627 icon_view->priv->selection_mode = mode;
4629 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4633 * gtk_icon_view_get_selection_mode:
4634 * @icon_view: A #GtkIconView.
4636 * Gets the selection mode of the @icon_view.
4638 * Return value: the current selection mode
4643 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4645 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4647 return icon_view->priv->selection_mode;
4651 * gtk_icon_view_set_model:
4652 * @icon_view: A #GtkIconView.
4653 * @model: (allow-none): The model.
4655 * Sets the model for a #GtkIconView.
4656 * If the @icon_view already has a model set, it will remove
4657 * it before setting the new model. If @model is %NULL, then
4658 * it will unset the old model.
4663 gtk_icon_view_set_model (GtkIconView *icon_view,
4664 GtkTreeModel *model)
4666 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4667 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4669 if (icon_view->priv->model == model)
4672 if (icon_view->priv->scroll_to_path)
4674 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4675 icon_view->priv->scroll_to_path = NULL;
4678 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4684 if (icon_view->priv->pixbuf_column != -1)
4686 column_type = gtk_tree_model_get_column_type (model,
4687 icon_view->priv->pixbuf_column);
4689 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4692 if (icon_view->priv->text_column != -1)
4694 column_type = gtk_tree_model_get_column_type (model,
4695 icon_view->priv->text_column);
4697 g_return_if_fail (column_type == G_TYPE_STRING);
4700 if (icon_view->priv->markup_column != -1)
4702 column_type = gtk_tree_model_get_column_type (model,
4703 icon_view->priv->markup_column);
4705 g_return_if_fail (column_type == G_TYPE_STRING);
4710 if (icon_view->priv->model)
4712 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4713 gtk_icon_view_row_changed,
4715 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4716 gtk_icon_view_row_inserted,
4718 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4719 gtk_icon_view_row_deleted,
4721 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4722 gtk_icon_view_rows_reordered,
4725 g_object_unref (icon_view->priv->model);
4727 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4728 g_list_free (icon_view->priv->items);
4729 icon_view->priv->items = NULL;
4730 icon_view->priv->anchor_item = NULL;
4731 icon_view->priv->cursor_item = NULL;
4732 icon_view->priv->last_single_clicked = NULL;
4733 icon_view->priv->width = 0;
4734 icon_view->priv->height = 0;
4737 icon_view->priv->model = model;
4739 if (icon_view->priv->model)
4741 g_object_ref (icon_view->priv->model);
4742 g_signal_connect (icon_view->priv->model,
4744 G_CALLBACK (gtk_icon_view_row_changed),
4746 g_signal_connect (icon_view->priv->model,
4748 G_CALLBACK (gtk_icon_view_row_inserted),
4750 g_signal_connect (icon_view->priv->model,
4752 G_CALLBACK (gtk_icon_view_row_deleted),
4754 g_signal_connect (icon_view->priv->model,
4756 G_CALLBACK (gtk_icon_view_rows_reordered),
4759 gtk_icon_view_build_items (icon_view);
4761 gtk_icon_view_queue_layout (icon_view);
4764 g_object_notify (G_OBJECT (icon_view), "model");
4766 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4767 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4771 * gtk_icon_view_get_model:
4772 * @icon_view: a #GtkIconView
4774 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4777 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4778 * currently being used.
4783 gtk_icon_view_get_model (GtkIconView *icon_view)
4785 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4787 return icon_view->priv->model;
4791 update_text_cell (GtkIconView *icon_view)
4793 if (icon_view->priv->text_column == -1 &&
4794 icon_view->priv->markup_column == -1)
4796 if (icon_view->priv->text_cell != NULL)
4798 gtk_cell_area_remove (icon_view->priv->cell_area,
4799 icon_view->priv->text_cell);
4800 icon_view->priv->text_cell = NULL;
4805 if (icon_view->priv->text_cell == NULL)
4807 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4809 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4812 if (icon_view->priv->markup_column != -1)
4813 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4814 icon_view->priv->text_cell,
4815 "markup", icon_view->priv->markup_column,
4818 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4819 icon_view->priv->text_cell,
4820 "text", icon_view->priv->text_column,
4823 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4824 g_object_set (icon_view->priv->text_cell,
4825 "alignment", PANGO_ALIGN_CENTER,
4826 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4831 g_object_set (icon_view->priv->text_cell,
4832 "alignment", PANGO_ALIGN_LEFT,
4833 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4841 update_pixbuf_cell (GtkIconView *icon_view)
4843 if (icon_view->priv->pixbuf_column == -1)
4845 if (icon_view->priv->pixbuf_cell != NULL)
4847 gtk_cell_area_remove (icon_view->priv->cell_area,
4848 icon_view->priv->pixbuf_cell);
4850 icon_view->priv->pixbuf_cell = NULL;
4855 if (icon_view->priv->pixbuf_cell == NULL)
4857 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4859 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4862 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4863 icon_view->priv->pixbuf_cell,
4864 "pixbuf", icon_view->priv->pixbuf_column,
4867 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4868 g_object_set (icon_view->priv->pixbuf_cell,
4873 g_object_set (icon_view->priv->pixbuf_cell,
4881 * gtk_icon_view_set_text_column:
4882 * @icon_view: A #GtkIconView.
4883 * @column: A column in the currently used model, or -1 to display no text
4885 * Sets the column with text for @icon_view to be @column. The text
4886 * column must be of type #G_TYPE_STRING.
4891 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4894 if (column == icon_view->priv->text_column)
4898 icon_view->priv->text_column = -1;
4901 if (icon_view->priv->model != NULL)
4905 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4907 g_return_if_fail (column_type == G_TYPE_STRING);
4910 icon_view->priv->text_column = column;
4914 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4916 update_text_cell (icon_view);
4918 gtk_icon_view_invalidate_sizes (icon_view);
4919 gtk_icon_view_queue_layout (icon_view);
4921 g_object_notify (G_OBJECT (icon_view), "text-column");
4925 * gtk_icon_view_get_text_column:
4926 * @icon_view: A #GtkIconView.
4928 * Returns the column with text for @icon_view.
4930 * Returns: the text column, or -1 if it's unset.
4935 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4937 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4939 return icon_view->priv->text_column;
4943 * gtk_icon_view_set_markup_column:
4944 * @icon_view: A #GtkIconView.
4945 * @column: A column in the currently used model, or -1 to display no text
4947 * Sets the column with markup information for @icon_view to be
4948 * @column. The markup column must be of type #G_TYPE_STRING.
4949 * If the markup column is set to something, it overrides
4950 * the text column set by gtk_icon_view_set_text_column().
4955 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4958 if (column == icon_view->priv->markup_column)
4962 icon_view->priv->markup_column = -1;
4965 if (icon_view->priv->model != NULL)
4969 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4971 g_return_if_fail (column_type == G_TYPE_STRING);
4974 icon_view->priv->markup_column = column;
4977 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4979 update_text_cell (icon_view);
4981 gtk_icon_view_invalidate_sizes (icon_view);
4982 gtk_icon_view_queue_layout (icon_view);
4984 g_object_notify (G_OBJECT (icon_view), "markup-column");
4988 * gtk_icon_view_get_markup_column:
4989 * @icon_view: A #GtkIconView.
4991 * Returns the column with markup text for @icon_view.
4993 * Returns: the markup column, or -1 if it's unset.
4998 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5000 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5002 return icon_view->priv->markup_column;
5006 * gtk_icon_view_set_pixbuf_column:
5007 * @icon_view: A #GtkIconView.
5008 * @column: A column in the currently used model, or -1 to disable
5010 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5011 * column must be of type #GDK_TYPE_PIXBUF
5016 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5019 if (column == icon_view->priv->pixbuf_column)
5023 icon_view->priv->pixbuf_column = -1;
5026 if (icon_view->priv->model != NULL)
5030 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5032 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5035 icon_view->priv->pixbuf_column = column;
5038 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5040 update_pixbuf_cell (icon_view);
5042 gtk_icon_view_invalidate_sizes (icon_view);
5043 gtk_icon_view_queue_layout (icon_view);
5045 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5050 * gtk_icon_view_get_pixbuf_column:
5051 * @icon_view: A #GtkIconView.
5053 * Returns the column with pixbufs for @icon_view.
5055 * Returns: the pixbuf column, or -1 if it's unset.
5060 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5062 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5064 return icon_view->priv->pixbuf_column;
5068 * gtk_icon_view_select_path:
5069 * @icon_view: A #GtkIconView.
5070 * @path: The #GtkTreePath to be selected.
5072 * Selects the row at @path.
5077 gtk_icon_view_select_path (GtkIconView *icon_view,
5080 GtkIconViewItem *item = NULL;
5082 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5083 g_return_if_fail (icon_view->priv->model != NULL);
5084 g_return_if_fail (path != NULL);
5086 if (gtk_tree_path_get_depth (path) > 0)
5087 item = g_list_nth_data (icon_view->priv->items,
5088 gtk_tree_path_get_indices(path)[0]);
5091 gtk_icon_view_select_item (icon_view, item);
5095 * gtk_icon_view_unselect_path:
5096 * @icon_view: A #GtkIconView.
5097 * @path: The #GtkTreePath to be unselected.
5099 * Unselects the row at @path.
5104 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5107 GtkIconViewItem *item;
5109 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5110 g_return_if_fail (icon_view->priv->model != NULL);
5111 g_return_if_fail (path != NULL);
5113 item = g_list_nth_data (icon_view->priv->items,
5114 gtk_tree_path_get_indices(path)[0]);
5119 gtk_icon_view_unselect_item (icon_view, item);
5123 * gtk_icon_view_get_selected_items:
5124 * @icon_view: A #GtkIconView.
5126 * Creates a list of paths of all selected items. Additionally, if you are
5127 * planning on modifying the model after calling this function, you may
5128 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5129 * To do this, you can use gtk_tree_row_reference_new().
5131 * To free the return value, use:
5133 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5134 * g_list_free (list);
5137 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5142 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5145 GList *selected = NULL;
5147 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5149 for (list = icon_view->priv->items; list != NULL; list = list->next)
5151 GtkIconViewItem *item = list->data;
5155 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5157 selected = g_list_prepend (selected, path);
5165 * gtk_icon_view_select_all:
5166 * @icon_view: A #GtkIconView.
5168 * Selects all the icons. @icon_view must has its selection mode set
5169 * to #GTK_SELECTION_MULTIPLE.
5174 gtk_icon_view_select_all (GtkIconView *icon_view)
5177 gboolean dirty = FALSE;
5179 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5181 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5184 for (items = icon_view->priv->items; items; items = items->next)
5186 GtkIconViewItem *item = items->data;
5188 if (!item->selected)
5191 item->selected = TRUE;
5192 gtk_icon_view_queue_draw_item (icon_view, item);
5197 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5201 * gtk_icon_view_unselect_all:
5202 * @icon_view: A #GtkIconView.
5204 * Unselects all the icons.
5209 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5211 gboolean dirty = FALSE;
5213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5215 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5218 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5221 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5225 * gtk_icon_view_path_is_selected:
5226 * @icon_view: A #GtkIconView.
5227 * @path: A #GtkTreePath to check selection on.
5229 * Returns %TRUE if the icon pointed to by @path is currently
5230 * selected. If @path does not point to a valid location, %FALSE is returned.
5232 * Return value: %TRUE if @path is selected.
5237 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5240 GtkIconViewItem *item;
5242 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5243 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5244 g_return_val_if_fail (path != NULL, FALSE);
5246 item = g_list_nth_data (icon_view->priv->items,
5247 gtk_tree_path_get_indices(path)[0]);
5252 return item->selected;
5256 * gtk_icon_view_get_item_row:
5257 * @icon_view: a #GtkIconView
5258 * @path: the #GtkTreePath of the item
5260 * Gets the row in which the item @path is currently
5261 * displayed. Row numbers start at 0.
5263 * Returns: The row in which the item is displayed
5268 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5271 GtkIconViewItem *item;
5273 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5274 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5275 g_return_val_if_fail (path != NULL, -1);
5277 item = g_list_nth_data (icon_view->priv->items,
5278 gtk_tree_path_get_indices(path)[0]);
5287 * gtk_icon_view_get_item_column:
5288 * @icon_view: a #GtkIconView
5289 * @path: the #GtkTreePath of the item
5291 * Gets the column in which the item @path is currently
5292 * displayed. Column numbers start at 0.
5294 * Returns: The column in which the item is displayed
5299 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5302 GtkIconViewItem *item;
5304 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5305 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5306 g_return_val_if_fail (path != NULL, -1);
5308 item = g_list_nth_data (icon_view->priv->items,
5309 gtk_tree_path_get_indices(path)[0]);
5318 * gtk_icon_view_item_activated:
5319 * @icon_view: A #GtkIconView
5320 * @path: The #GtkTreePath to be activated
5322 * Activates the item determined by @path.
5327 gtk_icon_view_item_activated (GtkIconView *icon_view,
5330 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5331 g_return_if_fail (path != NULL);
5333 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5337 * gtk_icon_view_set_item_orientation:
5338 * @icon_view: a #GtkIconView
5339 * @orientation: the relative position of texts and icons
5341 * Sets the ::item-orientation property which determines whether the labels
5342 * are drawn beside the icons instead of below.
5347 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5348 GtkOrientation orientation)
5350 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5352 if (icon_view->priv->item_orientation != orientation)
5354 icon_view->priv->item_orientation = orientation;
5356 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5357 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5358 icon_view->priv->item_orientation);
5360 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5361 gtk_icon_view_invalidate_sizes (icon_view);
5362 gtk_icon_view_queue_layout (icon_view);
5364 update_text_cell (icon_view);
5365 update_pixbuf_cell (icon_view);
5367 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5372 * gtk_icon_view_get_item_orientation:
5373 * @icon_view: a #GtkIconView
5375 * Returns the value of the ::item-orientation property which determines
5376 * whether the labels are drawn beside the icons instead of below.
5378 * Return value: the relative position of texts and icons
5383 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5385 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5386 GTK_ORIENTATION_VERTICAL);
5388 return icon_view->priv->item_orientation;
5392 * gtk_icon_view_set_columns:
5393 * @icon_view: a #GtkIconView
5394 * @columns: the number of columns
5396 * Sets the ::columns property which determines in how
5397 * many columns the icons are arranged. If @columns is
5398 * -1, the number of columns will be chosen automatically
5399 * to fill the available area.
5404 gtk_icon_view_set_columns (GtkIconView *icon_view,
5407 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5409 if (icon_view->priv->columns != columns)
5411 icon_view->priv->columns = columns;
5413 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5414 gtk_icon_view_queue_layout (icon_view);
5416 g_object_notify (G_OBJECT (icon_view), "columns");
5421 * gtk_icon_view_get_columns:
5422 * @icon_view: a #GtkIconView
5424 * Returns the value of the ::columns property.
5426 * Return value: the number of columns, or -1
5431 gtk_icon_view_get_columns (GtkIconView *icon_view)
5433 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5435 return icon_view->priv->columns;
5439 * gtk_icon_view_set_item_width:
5440 * @icon_view: a #GtkIconView
5441 * @item_width: the width for each item
5443 * Sets the ::item-width property which specifies the width
5444 * to use for each item. If it is set to -1, the icon view will
5445 * automatically determine a suitable item size.
5450 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5453 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5455 if (icon_view->priv->item_width != item_width)
5457 icon_view->priv->item_width = item_width;
5459 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5460 gtk_icon_view_invalidate_sizes (icon_view);
5461 gtk_icon_view_queue_layout (icon_view);
5463 update_text_cell (icon_view);
5465 g_object_notify (G_OBJECT (icon_view), "item-width");
5470 * gtk_icon_view_get_item_width:
5471 * @icon_view: a #GtkIconView
5473 * Returns the value of the ::item-width property.
5475 * Return value: the width of a single item, or -1
5480 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5482 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5484 return icon_view->priv->item_width;
5489 * gtk_icon_view_set_spacing:
5490 * @icon_view: a #GtkIconView
5491 * @spacing: the spacing
5493 * Sets the ::spacing property which specifies the space
5494 * which is inserted between the cells (i.e. the icon and
5495 * the text) of an item.
5500 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5503 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5505 if (icon_view->priv->spacing != spacing)
5507 icon_view->priv->spacing = spacing;
5509 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5510 gtk_icon_view_invalidate_sizes (icon_view);
5511 gtk_icon_view_queue_layout (icon_view);
5513 g_object_notify (G_OBJECT (icon_view), "spacing");
5518 * gtk_icon_view_get_spacing:
5519 * @icon_view: a #GtkIconView
5521 * Returns the value of the ::spacing property.
5523 * Return value: the space between cells
5528 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5530 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5532 return icon_view->priv->spacing;
5536 * gtk_icon_view_set_row_spacing:
5537 * @icon_view: a #GtkIconView
5538 * @row_spacing: the row spacing
5540 * Sets the ::row-spacing property which specifies the space
5541 * which is inserted between the rows of the icon view.
5546 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5549 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5551 if (icon_view->priv->row_spacing != row_spacing)
5553 icon_view->priv->row_spacing = row_spacing;
5555 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5556 gtk_icon_view_invalidate_sizes (icon_view);
5557 gtk_icon_view_queue_layout (icon_view);
5559 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5564 * gtk_icon_view_get_row_spacing:
5565 * @icon_view: a #GtkIconView
5567 * Returns the value of the ::row-spacing property.
5569 * Return value: the space between rows
5574 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5576 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5578 return icon_view->priv->row_spacing;
5582 * gtk_icon_view_set_column_spacing:
5583 * @icon_view: a #GtkIconView
5584 * @column_spacing: the column spacing
5586 * Sets the ::column-spacing property which specifies the space
5587 * which is inserted between the columns of the icon view.
5592 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5593 gint column_spacing)
5595 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5597 if (icon_view->priv->column_spacing != column_spacing)
5599 icon_view->priv->column_spacing = column_spacing;
5601 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5602 gtk_icon_view_invalidate_sizes (icon_view);
5603 gtk_icon_view_queue_layout (icon_view);
5605 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5610 * gtk_icon_view_get_column_spacing:
5611 * @icon_view: a #GtkIconView
5613 * Returns the value of the ::column-spacing property.
5615 * Return value: the space between columns
5620 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5622 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5624 return icon_view->priv->column_spacing;
5628 * gtk_icon_view_set_margin:
5629 * @icon_view: a #GtkIconView
5630 * @margin: the margin
5632 * Sets the ::margin property which specifies the space
5633 * which is inserted at the top, bottom, left and right
5639 gtk_icon_view_set_margin (GtkIconView *icon_view,
5642 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5644 if (icon_view->priv->margin != margin)
5646 icon_view->priv->margin = margin;
5648 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5649 gtk_icon_view_invalidate_sizes (icon_view);
5650 gtk_icon_view_queue_layout (icon_view);
5652 g_object_notify (G_OBJECT (icon_view), "margin");
5657 * gtk_icon_view_get_margin:
5658 * @icon_view: a #GtkIconView
5660 * Returns the value of the ::margin property.
5662 * Return value: the space at the borders
5667 gtk_icon_view_get_margin (GtkIconView *icon_view)
5669 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5671 return icon_view->priv->margin;
5675 * gtk_icon_view_set_item_padding:
5676 * @icon_view: a #GtkIconView
5677 * @item_padding: the item padding
5679 * Sets the #GtkIconView:item-padding property which specifies the padding
5680 * around each of the icon view's items.
5685 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5688 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5690 if (icon_view->priv->item_padding != item_padding)
5692 icon_view->priv->item_padding = item_padding;
5694 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5695 gtk_icon_view_invalidate_sizes (icon_view);
5696 gtk_icon_view_queue_layout (icon_view);
5698 g_object_notify (G_OBJECT (icon_view), "item-padding");
5703 * gtk_icon_view_get_item_padding:
5704 * @icon_view: a #GtkIconView
5706 * Returns the value of the ::item-padding property.
5708 * Return value: the padding around items
5713 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5715 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5717 return icon_view->priv->item_padding;
5720 /* Get/set whether drag_motion requested the drag data and
5721 * drag_data_received should thus not actually insert the data,
5722 * since the data doesn't result from a drop.
5725 set_status_pending (GdkDragContext *context,
5726 GdkDragAction suggested_action)
5728 g_object_set_data (G_OBJECT (context),
5729 I_("gtk-icon-view-status-pending"),
5730 GINT_TO_POINTER (suggested_action));
5733 static GdkDragAction
5734 get_status_pending (GdkDragContext *context)
5736 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5737 "gtk-icon-view-status-pending"));
5741 unset_reorderable (GtkIconView *icon_view)
5743 if (icon_view->priv->reorderable)
5745 icon_view->priv->reorderable = FALSE;
5746 g_object_notify (G_OBJECT (icon_view), "reorderable");
5751 set_source_row (GdkDragContext *context,
5752 GtkTreeModel *model,
5753 GtkTreePath *source_row)
5756 g_object_set_data_full (G_OBJECT (context),
5757 I_("gtk-icon-view-source-row"),
5758 gtk_tree_row_reference_new (model, source_row),
5759 (GDestroyNotify) gtk_tree_row_reference_free);
5761 g_object_set_data_full (G_OBJECT (context),
5762 I_("gtk-icon-view-source-row"),
5767 get_source_row (GdkDragContext *context)
5769 GtkTreeRowReference *ref;
5771 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5774 return gtk_tree_row_reference_get_path (ref);
5781 GtkTreeRowReference *dest_row;
5782 gboolean empty_view_drop;
5783 gboolean drop_append_mode;
5787 dest_row_free (gpointer data)
5789 DestRow *dr = (DestRow *)data;
5791 gtk_tree_row_reference_free (dr->dest_row);
5796 set_dest_row (GdkDragContext *context,
5797 GtkTreeModel *model,
5798 GtkTreePath *dest_row,
5799 gboolean empty_view_drop,
5800 gboolean drop_append_mode)
5806 g_object_set_data_full (G_OBJECT (context),
5807 I_("gtk-icon-view-dest-row"),
5812 dr = g_new0 (DestRow, 1);
5814 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5815 dr->empty_view_drop = empty_view_drop;
5816 dr->drop_append_mode = drop_append_mode;
5817 g_object_set_data_full (G_OBJECT (context),
5818 I_("gtk-icon-view-dest-row"),
5819 dr, (GDestroyNotify) dest_row_free);
5823 get_dest_row (GdkDragContext *context)
5827 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5831 GtkTreePath *path = NULL;
5834 path = gtk_tree_row_reference_get_path (dr->dest_row);
5835 else if (dr->empty_view_drop)
5836 path = gtk_tree_path_new_from_indices (0, -1);
5840 if (path && dr->drop_append_mode)
5841 gtk_tree_path_next (path);
5850 check_model_dnd (GtkTreeModel *model,
5851 GType required_iface,
5852 const gchar *signal)
5854 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5856 g_warning ("You must override the default '%s' handler "
5857 "on GtkIconView when using models that don't support "
5858 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5859 "is to connect to '%s' and call "
5860 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5861 "the default handler from running. Look at the source code "
5862 "for the default handler in gtkiconview.c to get an idea what "
5863 "your handler should do. (gtkiconview.c is in the GTK+ source "
5864 "code.) If you're using GTK+ from a language other than C, "
5865 "there may be a more natural way to override default handlers, e.g. via derivation.",
5866 signal, g_type_name (required_iface), signal);
5874 remove_scroll_timeout (GtkIconView *icon_view)
5876 if (icon_view->priv->scroll_timeout_id != 0)
5878 g_source_remove (icon_view->priv->scroll_timeout_id);
5880 icon_view->priv->scroll_timeout_id = 0;
5885 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5888 gint px, py, x, y, width, height;
5889 gint hoffset, voffset;
5891 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5893 gdk_window_get_pointer (window, &px, &py, NULL);
5894 gdk_window_get_geometry (window, &x, &y, &width, &height);
5896 /* see if we are near the edge. */
5897 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5899 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5901 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5903 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5906 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5907 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5910 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5911 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5916 drag_scroll_timeout (gpointer data)
5918 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5920 gtk_icon_view_autoscroll (icon_view);
5927 set_destination (GtkIconView *icon_view,
5928 GdkDragContext *context,
5931 GdkDragAction *suggested_action,
5935 GtkTreePath *path = NULL;
5936 GtkIconViewDropPosition pos;
5937 GtkIconViewDropPosition old_pos;
5938 GtkTreePath *old_dest_path = NULL;
5939 gboolean can_drop = FALSE;
5941 widget = GTK_WIDGET (icon_view);
5943 *suggested_action = 0;
5946 if (!icon_view->priv->dest_set)
5948 /* someone unset us as a drag dest, note that if
5949 * we return FALSE drag_leave isn't called
5952 gtk_icon_view_set_drag_dest_item (icon_view,
5954 GTK_ICON_VIEW_DROP_LEFT);
5956 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5958 return FALSE; /* no longer a drop site */
5961 *target = gtk_drag_dest_find_target (widget, context,
5962 gtk_drag_dest_get_target_list (widget));
5963 if (*target == GDK_NONE)
5966 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5969 GtkTreeModel *model;
5971 /* the row got dropped on empty space, let's setup a special case
5975 gtk_tree_path_free (path);
5977 model = gtk_icon_view_get_model (icon_view);
5979 n_children = gtk_tree_model_iter_n_children (model, NULL);
5982 pos = GTK_ICON_VIEW_DROP_BELOW;
5983 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5987 pos = GTK_ICON_VIEW_DROP_ABOVE;
5988 path = gtk_tree_path_new_from_indices (0, -1);
5998 gtk_icon_view_get_drag_dest_item (icon_view,
6003 gtk_tree_path_free (old_dest_path);
6005 if (TRUE /* FIXME if the location droppable predicate */)
6013 GtkWidget *source_widget;
6015 *suggested_action = gdk_drag_context_get_suggested_action (context);
6016 source_widget = gtk_drag_get_source_widget (context);
6018 if (source_widget == widget)
6020 /* Default to MOVE, unless the user has
6021 * pressed ctrl or shift to affect available actions
6023 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6024 *suggested_action = GDK_ACTION_MOVE;
6027 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6032 /* can't drop here */
6033 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6035 GTK_ICON_VIEW_DROP_LEFT);
6039 gtk_tree_path_free (path);
6045 get_logical_destination (GtkIconView *icon_view,
6046 gboolean *drop_append_mode)
6048 /* adjust path to point to the row the drop goes in front of */
6049 GtkTreePath *path = NULL;
6050 GtkIconViewDropPosition pos;
6052 *drop_append_mode = FALSE;
6054 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6059 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6060 pos == GTK_ICON_VIEW_DROP_BELOW)
6063 GtkTreeModel *model = icon_view->priv->model;
6065 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6066 !gtk_tree_model_iter_next (model, &iter))
6067 *drop_append_mode = TRUE;
6070 *drop_append_mode = FALSE;
6071 gtk_tree_path_next (path);
6079 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6080 GdkEventMotion *event)
6082 GtkWidget *widget = GTK_WIDGET (icon_view);
6083 GdkDragContext *context;
6084 GtkTreePath *path = NULL;
6086 GtkTreeModel *model;
6087 gboolean retval = FALSE;
6089 if (!icon_view->priv->source_set)
6092 if (icon_view->priv->pressed_button < 0)
6095 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6096 icon_view->priv->press_start_x,
6097 icon_view->priv->press_start_y,
6098 event->x, event->y))
6101 model = gtk_icon_view_get_model (icon_view);
6106 button = icon_view->priv->pressed_button;
6107 icon_view->priv->pressed_button = -1;
6109 path = gtk_icon_view_get_path_at_pos (icon_view,
6110 icon_view->priv->press_start_x,
6111 icon_view->priv->press_start_y);
6116 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6117 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6121 /* FIXME Check whether we're a start button, if not return FALSE and
6125 /* Now we can begin the drag */
6129 context = gtk_drag_begin (widget,
6130 gtk_drag_source_get_target_list (widget),
6131 icon_view->priv->source_actions,
6135 set_source_row (context, model, path);
6139 gtk_tree_path_free (path);
6144 /* Source side drag signals */
6146 gtk_icon_view_drag_begin (GtkWidget *widget,
6147 GdkDragContext *context)
6149 GtkIconView *icon_view;
6150 GtkIconViewItem *item;
6151 cairo_surface_t *icon;
6155 icon_view = GTK_ICON_VIEW (widget);
6157 /* if the user uses a custom DnD impl, we don't set the icon here */
6158 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6161 item = gtk_icon_view_get_item_at_coords (icon_view,
6162 icon_view->priv->press_start_x,
6163 icon_view->priv->press_start_y,
6167 g_return_if_fail (item != NULL);
6169 x = icon_view->priv->press_start_x - item->x + 1;
6170 y = icon_view->priv->press_start_y - item->y + 1;
6172 path = gtk_tree_path_new_from_indices (item->index, -1);
6173 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6174 gtk_tree_path_free (path);
6176 cairo_surface_set_device_offset (icon, -x, -y);
6178 gtk_drag_set_icon_surface (context, icon);
6180 cairo_surface_destroy (icon);
6184 gtk_icon_view_drag_end (GtkWidget *widget,
6185 GdkDragContext *context)
6191 gtk_icon_view_drag_data_get (GtkWidget *widget,
6192 GdkDragContext *context,
6193 GtkSelectionData *selection_data,
6197 GtkIconView *icon_view;
6198 GtkTreeModel *model;
6199 GtkTreePath *source_row;
6201 icon_view = GTK_ICON_VIEW (widget);
6202 model = gtk_icon_view_get_model (icon_view);
6207 if (!icon_view->priv->source_set)
6210 source_row = get_source_row (context);
6212 if (source_row == NULL)
6215 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6216 * any model; for DragSource models there are some other targets
6220 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6221 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6226 /* If drag_data_get does nothing, try providing row data. */
6227 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6228 gtk_tree_set_row_drag_data (selection_data,
6233 gtk_tree_path_free (source_row);
6237 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6238 GdkDragContext *context)
6240 GtkTreeModel *model;
6241 GtkIconView *icon_view;
6242 GtkTreePath *source_row;
6244 icon_view = GTK_ICON_VIEW (widget);
6245 model = gtk_icon_view_get_model (icon_view);
6247 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6250 if (!icon_view->priv->source_set)
6253 source_row = get_source_row (context);
6255 if (source_row == NULL)
6258 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6261 gtk_tree_path_free (source_row);
6263 set_source_row (context, NULL, NULL);
6266 /* Target side drag signals */
6268 gtk_icon_view_drag_leave (GtkWidget *widget,
6269 GdkDragContext *context,
6272 GtkIconView *icon_view;
6274 icon_view = GTK_ICON_VIEW (widget);
6276 /* unset any highlight row */
6277 gtk_icon_view_set_drag_dest_item (icon_view,
6279 GTK_ICON_VIEW_DROP_LEFT);
6281 remove_scroll_timeout (icon_view);
6285 gtk_icon_view_drag_motion (GtkWidget *widget,
6286 GdkDragContext *context,
6291 GtkTreePath *path = NULL;
6292 GtkIconViewDropPosition pos;
6293 GtkIconView *icon_view;
6294 GdkDragAction suggested_action = 0;
6298 icon_view = GTK_ICON_VIEW (widget);
6300 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6303 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6305 /* we only know this *after* set_desination_row */
6306 empty = icon_view->priv->empty_view_drop;
6308 if (path == NULL && !empty)
6310 /* Can't drop here. */
6311 gdk_drag_status (context, 0, time);
6315 if (icon_view->priv->scroll_timeout_id == 0)
6317 icon_view->priv->scroll_timeout_id =
6318 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6321 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6323 /* Request data so we can use the source row when
6324 * determining whether to accept the drop
6326 set_status_pending (context, suggested_action);
6327 gtk_drag_get_data (widget, context, target, time);
6331 set_status_pending (context, 0);
6332 gdk_drag_status (context, suggested_action, time);
6337 gtk_tree_path_free (path);
6343 gtk_icon_view_drag_drop (GtkWidget *widget,
6344 GdkDragContext *context,
6349 GtkIconView *icon_view;
6351 GdkDragAction suggested_action = 0;
6352 GdkAtom target = GDK_NONE;
6353 GtkTreeModel *model;
6354 gboolean drop_append_mode;
6356 icon_view = GTK_ICON_VIEW (widget);
6357 model = gtk_icon_view_get_model (icon_view);
6359 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6361 if (!icon_view->priv->dest_set)
6364 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6367 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6370 path = get_logical_destination (icon_view, &drop_append_mode);
6372 if (target != GDK_NONE && path != NULL)
6374 /* in case a motion had requested drag data, change things so we
6375 * treat drag data receives as a drop.
6377 set_status_pending (context, 0);
6378 set_dest_row (context, model, path,
6379 icon_view->priv->empty_view_drop, drop_append_mode);
6383 gtk_tree_path_free (path);
6385 /* Unset this thing */
6386 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6388 if (target != GDK_NONE)
6390 gtk_drag_get_data (widget, context, target, time);
6398 gtk_icon_view_drag_data_received (GtkWidget *widget,
6399 GdkDragContext *context,
6402 GtkSelectionData *selection_data,
6407 gboolean accepted = FALSE;
6408 GtkTreeModel *model;
6409 GtkIconView *icon_view;
6410 GtkTreePath *dest_row;
6411 GdkDragAction suggested_action;
6412 gboolean drop_append_mode;
6414 icon_view = GTK_ICON_VIEW (widget);
6415 model = gtk_icon_view_get_model (icon_view);
6417 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6420 if (!icon_view->priv->dest_set)
6423 suggested_action = get_status_pending (context);
6425 if (suggested_action)
6427 /* We are getting this data due to a request in drag_motion,
6428 * rather than due to a request in drag_drop, so we are just
6429 * supposed to call drag_status, not actually paste in the
6432 path = get_logical_destination (icon_view, &drop_append_mode);
6435 suggested_action = 0;
6437 if (suggested_action)
6439 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6442 suggested_action = 0;
6445 gdk_drag_status (context, suggested_action, time);
6448 gtk_tree_path_free (path);
6450 /* If you can't drop, remove user drop indicator until the next motion */
6451 if (suggested_action == 0)
6452 gtk_icon_view_set_drag_dest_item (icon_view,
6454 GTK_ICON_VIEW_DROP_LEFT);
6459 dest_row = get_dest_row (context);
6461 if (dest_row == NULL)
6464 if (gtk_selection_data_get_length (selection_data) >= 0)
6466 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6472 gtk_drag_finish (context,
6474 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6477 gtk_tree_path_free (dest_row);
6480 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6483 /* Drag-and-Drop support */
6485 * gtk_icon_view_enable_model_drag_source:
6486 * @icon_view: a #GtkIconTreeView
6487 * @start_button_mask: Mask of allowed buttons to start drag
6488 * @targets: the table of targets that the drag will support
6489 * @n_targets: the number of items in @targets
6490 * @actions: the bitmask of possible actions for a drag from this
6493 * Turns @icon_view into a drag source for automatic DND. Calling this
6494 * method sets #GtkIconView:reorderable to %FALSE.
6499 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6500 GdkModifierType start_button_mask,
6501 const GtkTargetEntry *targets,
6503 GdkDragAction actions)
6505 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6507 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6509 icon_view->priv->start_button_mask = start_button_mask;
6510 icon_view->priv->source_actions = actions;
6512 icon_view->priv->source_set = TRUE;
6514 unset_reorderable (icon_view);
6518 * gtk_icon_view_enable_model_drag_dest:
6519 * @icon_view: a #GtkIconView
6520 * @targets: the table of targets that the drag will support
6521 * @n_targets: the number of items in @targets
6522 * @actions: the bitmask of possible actions for a drag to this
6525 * Turns @icon_view into a drop destination for automatic DND. Calling this
6526 * method sets #GtkIconView:reorderable to %FALSE.
6531 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6532 const GtkTargetEntry *targets,
6534 GdkDragAction actions)
6536 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6538 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6540 icon_view->priv->dest_actions = actions;
6542 icon_view->priv->dest_set = TRUE;
6544 unset_reorderable (icon_view);
6548 * gtk_icon_view_unset_model_drag_source:
6549 * @icon_view: a #GtkIconView
6551 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6552 * method sets #GtkIconView:reorderable to %FALSE.
6557 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6559 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6561 if (icon_view->priv->source_set)
6563 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6564 icon_view->priv->source_set = FALSE;
6567 unset_reorderable (icon_view);
6571 * gtk_icon_view_unset_model_drag_dest:
6572 * @icon_view: a #GtkIconView
6574 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6575 * method sets #GtkIconView:reorderable to %FALSE.
6580 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6582 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6584 if (icon_view->priv->dest_set)
6586 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6587 icon_view->priv->dest_set = FALSE;
6590 unset_reorderable (icon_view);
6593 /* These are useful to implement your own custom stuff. */
6595 * gtk_icon_view_set_drag_dest_item:
6596 * @icon_view: a #GtkIconView
6597 * @path: (allow-none): The path of the item to highlight, or %NULL.
6598 * @pos: Specifies where to drop, relative to the item
6600 * Sets the item that is highlighted for feedback.
6605 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6607 GtkIconViewDropPosition pos)
6609 /* Note; this function is exported to allow a custom DND
6610 * implementation, so it can't touch TreeViewDragInfo
6613 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6615 if (icon_view->priv->dest_item)
6617 GtkTreePath *current_path;
6618 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6619 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6620 icon_view->priv->dest_item = NULL;
6622 gtk_icon_view_queue_draw_path (icon_view, current_path);
6623 gtk_tree_path_free (current_path);
6626 /* special case a drop on an empty model */
6627 icon_view->priv->empty_view_drop = FALSE;
6628 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6629 && gtk_tree_path_get_depth (path) == 1
6630 && gtk_tree_path_get_indices (path)[0] == 0)
6634 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6637 if (n_children == 0)
6638 icon_view->priv->empty_view_drop = TRUE;
6641 icon_view->priv->dest_pos = pos;
6645 icon_view->priv->dest_item =
6646 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6647 icon_view->priv->model, path);
6649 gtk_icon_view_queue_draw_path (icon_view, path);
6654 * gtk_icon_view_get_drag_dest_item:
6655 * @icon_view: a #GtkIconView
6656 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
6657 * @pos: (allow-none): Return location for the drop position, or %NULL
6659 * Gets information about the item that is highlighted for feedback.
6664 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6666 GtkIconViewDropPosition *pos)
6668 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6672 if (icon_view->priv->dest_item)
6673 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6679 *pos = icon_view->priv->dest_pos;
6683 * gtk_icon_view_get_dest_item_at_pos:
6684 * @icon_view: a #GtkIconView
6685 * @drag_x: the position to determine the destination item for
6686 * @drag_y: the position to determine the destination item for
6687 * @path: (allow-none): Return location for the path of the item, or %NULL.
6688 * @pos: (allow-none): Return location for the drop position, or %NULL
6690 * Determines the destination item for a given position.
6692 * Return value: whether there is an item at the given position.
6697 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6701 GtkIconViewDropPosition *pos)
6703 GtkIconViewItem *item;
6705 /* Note; this function is exported to allow a custom DND
6706 * implementation, so it can't touch TreeViewDragInfo
6709 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6710 g_return_val_if_fail (drag_x >= 0, FALSE);
6711 g_return_val_if_fail (drag_y >= 0, FALSE);
6712 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6718 item = gtk_icon_view_get_item_at_coords (icon_view,
6719 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6720 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6727 *path = gtk_tree_path_new_from_indices (item->index, -1);
6731 if (drag_x < item->x + item->width / 4)
6732 *pos = GTK_ICON_VIEW_DROP_LEFT;
6733 else if (drag_x > item->x + item->width * 3 / 4)
6734 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6735 else if (drag_y < item->y + item->height / 4)
6736 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6737 else if (drag_y > item->y + item->height * 3 / 4)
6738 *pos = GTK_ICON_VIEW_DROP_BELOW;
6740 *pos = GTK_ICON_VIEW_DROP_INTO;
6747 * gtk_icon_view_create_drag_icon:
6748 * @icon_view: a #GtkIconView
6749 * @path: a #GtkTreePath in @icon_view
6751 * Creates a #cairo_surface_t representation of the item at @path.
6752 * This image is used for a drag icon.
6754 * Return value: (transfer full) a newly-allocated surface of the drag icon.
6759 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6764 cairo_surface_t *surface;
6768 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6769 g_return_val_if_fail (path != NULL, NULL);
6771 widget = GTK_WIDGET (icon_view);
6773 if (!gtk_widget_get_realized (widget))
6776 index = gtk_tree_path_get_indices (path)[0];
6778 for (l = icon_view->priv->items; l; l = l->next)
6780 GtkIconViewItem *item = l->data;
6782 if (index == item->index)
6784 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6785 CAIRO_CONTENT_COLOR,
6789 cr = cairo_create (surface);
6790 cairo_set_line_width (cr, 1.);
6792 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6793 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6798 cairo_rectangle (cr, 0, 0, item->width, item->height);
6801 gtk_icon_view_paint_item (icon_view, cr, item, 1, 1, FALSE);
6805 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6806 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6819 * gtk_icon_view_get_reorderable:
6820 * @icon_view: a #GtkIconView
6822 * Retrieves whether the user can reorder the list via drag-and-drop.
6823 * See gtk_icon_view_set_reorderable().
6825 * Return value: %TRUE if the list can be reordered.
6830 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6832 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6834 return icon_view->priv->reorderable;
6837 static const GtkTargetEntry item_targets[] = {
6838 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6843 * gtk_icon_view_set_reorderable:
6844 * @icon_view: A #GtkIconView.
6845 * @reorderable: %TRUE, if the list of items can be reordered.
6847 * This function is a convenience function to allow you to reorder models that
6848 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6849 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6850 * the user can reorder the model by dragging and dropping rows. The
6851 * developer can listen to these changes by connecting to the model's
6852 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6853 * the icon view as a drag source and destination. Therefore, drag and
6854 * drop can not be used in a reorderable view for any other purpose.
6856 * This function does not give you any degree of control over the order -- any
6857 * reordering is allowed. If more control is needed, you should probably
6858 * handle drag and drop manually.
6863 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6864 gboolean reorderable)
6866 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6868 reorderable = reorderable != FALSE;
6870 if (icon_view->priv->reorderable == reorderable)
6875 gtk_icon_view_enable_model_drag_source (icon_view,
6878 G_N_ELEMENTS (item_targets),
6880 gtk_icon_view_enable_model_drag_dest (icon_view,
6882 G_N_ELEMENTS (item_targets),
6887 gtk_icon_view_unset_model_drag_source (icon_view);
6888 gtk_icon_view_unset_model_drag_dest (icon_view);
6891 icon_view->priv->reorderable = reorderable;
6893 g_object_notify (G_OBJECT (icon_view), "reorderable");
6897 /* Accessibility Support */
6899 static gpointer accessible_parent_class;
6900 static gpointer accessible_item_parent_class;
6901 static GQuark accessible_private_data_quark = 0;
6903 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6904 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6905 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6907 static GType gtk_icon_view_item_accessible_get_type (void);
6918 GtkIconViewItem *item;
6922 AtkStateSet *state_set;
6926 GtkTextBuffer *text_buffer;
6928 gchar *action_descriptions[LAST_ACTION];
6929 gchar *image_description;
6930 guint action_idle_handler;
6931 } GtkIconViewItemAccessible;
6933 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6939 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6944 typedef struct _GtkIconViewItemAccessibleClass
6946 AtkObjectClass parent_class;
6948 } GtkIconViewItemAccessibleClass;
6950 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6953 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6955 GtkIconViewItemAccessible *item;
6956 GtkIconView *icon_view;
6959 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6960 item->action_idle_handler = 0;
6962 if (item->widget != NULL)
6964 icon_view = GTK_ICON_VIEW (item->widget);
6965 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6966 gtk_icon_view_item_activated (icon_view, path);
6967 gtk_tree_path_free (path);
6974 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6977 GtkIconViewItemAccessible *item;
6979 if (i < 0 || i >= LAST_ACTION)
6982 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6984 if (!GTK_IS_ICON_VIEW (item->widget))
6987 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6992 case ACTION_ACTIVATE:
6993 if (!item->action_idle_handler)
6994 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
6997 g_assert_not_reached ();
7005 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7010 static const gchar *
7011 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7014 GtkIconViewItemAccessible *item;
7016 if (i < 0 || i >= LAST_ACTION)
7019 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7021 if (item->action_descriptions[i])
7022 return item->action_descriptions[i];
7024 return gtk_icon_view_item_accessible_action_descriptions[i];
7027 static const gchar *
7028 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7031 if (i < 0 || i >= LAST_ACTION)
7034 return gtk_icon_view_item_accessible_action_names[i];
7038 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7040 const gchar *description)
7042 GtkIconViewItemAccessible *item;
7044 if (i < 0 || i >= LAST_ACTION)
7047 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7049 g_free (item->action_descriptions[i]);
7051 item->action_descriptions[i] = g_strdup (description);
7057 atk_action_item_interface_init (AtkActionIface *iface)
7059 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7060 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7061 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7062 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7063 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7066 static const gchar *
7067 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7069 GtkIconViewItemAccessible *item;
7071 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7073 return item->image_description;
7077 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7078 const gchar *description)
7080 GtkIconViewItemAccessible *item;
7082 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7084 g_free (item->image_description);
7085 item->image_description = g_strdup (description);
7092 gboolean pixbuf_found;
7096 get_pixbuf_foreach (GtkCellRenderer *renderer,
7097 const GdkRectangle *cell_area,
7098 const GdkRectangle *cell_background,
7099 GetPixbufBoxData *data)
7101 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7103 data->box = *cell_area;
7104 data->pixbuf_found = TRUE;
7106 return (data->pixbuf_found != FALSE);
7110 get_pixbuf_box (GtkIconView *icon_view,
7111 GtkIconViewItem *item,
7114 GetPixbufBoxData data = { { 0, }, FALSE };
7115 GdkRectangle cell_area;
7117 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context,
7118 icon_view->priv->effective_item_width,
7121 gtk_icon_view_set_cell_data (icon_view, item);
7122 gtk_icon_view_get_cell_area (icon_view, item, &cell_area);
7123 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area,
7124 icon_view->priv->cell_area_context,
7125 GTK_WIDGET (icon_view),
7126 &cell_area, &cell_area,
7127 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7129 return data.pixbuf_found;
7133 get_text_foreach (GtkCellRenderer *renderer,
7136 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7138 g_object_get (renderer, "text", text, NULL);
7146 get_text (GtkIconView *icon_view,
7147 GtkIconViewItem *item)
7151 gtk_icon_view_set_cell_data (icon_view, item);
7152 gtk_cell_area_foreach (icon_view->priv->cell_area,
7153 (GtkCellCallback)get_text_foreach, &text);
7159 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7163 GtkIconViewItemAccessible *item;
7166 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7168 if (!GTK_IS_ICON_VIEW (item->widget))
7171 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7174 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7177 *height = box.height;
7182 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7185 AtkCoordType coord_type)
7187 GtkIconViewItemAccessible *item;
7190 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7192 if (!GTK_IS_ICON_VIEW (item->widget))
7195 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7198 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7200 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7202 *x+= box.x - item->item->x;
7203 *y+= box.y - item->item->y;
7209 atk_image_item_interface_init (AtkImageIface *iface)
7211 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7212 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7213 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7214 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7218 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7222 GtkIconViewItemAccessible *item;
7223 GtkTextIter start, end;
7224 GtkTextBuffer *buffer;
7226 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7228 if (!GTK_IS_ICON_VIEW (item->widget))
7231 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7234 buffer = item->text_buffer;
7235 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7237 gtk_text_buffer_get_end_iter (buffer, &end);
7239 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7241 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7245 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7248 GtkIconViewItemAccessible *item;
7249 GtkTextIter start, end;
7250 GtkTextBuffer *buffer;
7254 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7256 if (!GTK_IS_ICON_VIEW (item->widget))
7259 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7262 buffer = item->text_buffer;
7263 if (offset >= gtk_text_buffer_get_char_count (buffer))
7266 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7268 gtk_text_iter_forward_char (&end);
7269 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7270 unichar = g_utf8_get_char (string);
7278 get_pango_text_offsets (PangoLayout *layout,
7279 GtkTextBuffer *buffer,
7281 AtkTextBoundary boundary_type,
7285 GtkTextIter *start_iter,
7286 GtkTextIter *end_iter)
7288 PangoLayoutIter *iter;
7289 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7290 gint index, start_index, end_index;
7292 gboolean found = FALSE;
7294 text = pango_layout_get_text (layout);
7295 index = g_utf8_offset_to_pointer (text, offset) - text;
7296 iter = pango_layout_get_iter (layout);
7299 line = pango_layout_iter_get_line_readonly (iter);
7300 start_index = line->start_index;
7301 end_index = start_index + line->length;
7303 if (index >= start_index && index <= end_index)
7306 * Found line for offset
7312 * We want the previous line
7316 switch (boundary_type)
7318 case ATK_TEXT_BOUNDARY_LINE_START:
7319 end_index = start_index;
7320 start_index = prev_line->start_index;
7322 case ATK_TEXT_BOUNDARY_LINE_END:
7324 start_index = prev_prev_line->start_index +
7325 prev_prev_line->length;
7326 end_index = prev_line->start_index + prev_line->length;
7329 g_assert_not_reached();
7333 start_index = end_index = 0;
7336 switch (boundary_type)
7338 case ATK_TEXT_BOUNDARY_LINE_START:
7339 if (pango_layout_iter_next_line (iter))
7340 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7342 case ATK_TEXT_BOUNDARY_LINE_END:
7344 start_index = prev_line->start_index +
7348 g_assert_not_reached();
7353 * We want the next line
7355 if (pango_layout_iter_next_line (iter))
7357 line = pango_layout_iter_get_line_readonly (iter);
7358 switch (boundary_type)
7360 case ATK_TEXT_BOUNDARY_LINE_START:
7361 start_index = line->start_index;
7362 if (pango_layout_iter_next_line (iter))
7363 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7365 end_index = start_index + line->length;
7367 case ATK_TEXT_BOUNDARY_LINE_END:
7368 start_index = end_index;
7369 end_index = line->start_index + line->length;
7372 g_assert_not_reached();
7376 start_index = end_index;
7382 prev_prev_line = prev_line;
7385 while (pango_layout_iter_next_line (iter));
7389 start_index = prev_line->start_index + prev_line->length;
7390 end_index = start_index;
7392 pango_layout_iter_free (iter);
7393 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7394 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7396 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7397 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7402 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7404 AtkTextBoundary boundary_type,
7408 GtkIconViewItemAccessible *item;
7409 GtkTextIter start, end;
7410 GtkTextBuffer *buffer;
7412 GtkIconView *icon_view;
7415 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7417 if (!GTK_IS_ICON_VIEW (item->widget))
7420 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7423 buffer = item->text_buffer;
7425 if (!gtk_text_buffer_get_char_count (buffer))
7429 return g_strdup ("");
7431 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7435 switch (boundary_type)
7437 case ATK_TEXT_BOUNDARY_CHAR:
7438 gtk_text_iter_backward_char(&start);
7440 case ATK_TEXT_BOUNDARY_WORD_START:
7441 if (!gtk_text_iter_starts_word (&start))
7442 gtk_text_iter_backward_word_start (&start);
7444 gtk_text_iter_backward_word_start(&start);
7446 case ATK_TEXT_BOUNDARY_WORD_END:
7447 if (gtk_text_iter_inside_word (&start) &&
7448 !gtk_text_iter_starts_word (&start))
7449 gtk_text_iter_backward_word_start (&start);
7450 while (!gtk_text_iter_ends_word (&start))
7452 if (!gtk_text_iter_backward_char (&start))
7456 gtk_text_iter_backward_word_start(&start);
7457 while (!gtk_text_iter_ends_word (&start))
7459 if (!gtk_text_iter_backward_char (&start))
7463 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7464 if (!gtk_text_iter_starts_sentence (&start))
7465 gtk_text_iter_backward_sentence_start (&start);
7467 gtk_text_iter_backward_sentence_start (&start);
7469 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7470 if (gtk_text_iter_inside_sentence (&start) &&
7471 !gtk_text_iter_starts_sentence (&start))
7472 gtk_text_iter_backward_sentence_start (&start);
7473 while (!gtk_text_iter_ends_sentence (&start))
7475 if (!gtk_text_iter_backward_char (&start))
7479 gtk_text_iter_backward_sentence_start (&start);
7480 while (!gtk_text_iter_ends_sentence (&start))
7482 if (!gtk_text_iter_backward_char (&start))
7486 case ATK_TEXT_BOUNDARY_LINE_START:
7487 case ATK_TEXT_BOUNDARY_LINE_END:
7489 icon_view = GTK_ICON_VIEW (item->widget);
7490 /* FIXME we probably have to use GailTextCell to salvage this */
7491 gtk_icon_view_update_item_text (icon_view, item->item);
7492 get_pango_text_offsets (icon_view->priv->layout,
7505 *start_offset = gtk_text_iter_get_offset (&start);
7506 *end_offset = gtk_text_iter_get_offset (&end);
7508 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7512 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7514 AtkTextBoundary boundary_type,
7518 GtkIconViewItemAccessible *item;
7519 GtkTextIter start, end;
7520 GtkTextBuffer *buffer;
7522 GtkIconView *icon_view;
7525 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7527 if (!GTK_IS_ICON_VIEW (item->widget))
7530 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7533 buffer = item->text_buffer;
7535 if (!gtk_text_buffer_get_char_count (buffer))
7539 return g_strdup ("");
7541 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7545 switch (boundary_type)
7547 case ATK_TEXT_BOUNDARY_CHAR:
7548 gtk_text_iter_forward_char (&end);
7550 case ATK_TEXT_BOUNDARY_WORD_START:
7551 if (!gtk_text_iter_starts_word (&start))
7552 gtk_text_iter_backward_word_start (&start);
7553 if (gtk_text_iter_inside_word (&end))
7554 gtk_text_iter_forward_word_end (&end);
7555 while (!gtk_text_iter_starts_word (&end))
7557 if (!gtk_text_iter_forward_char (&end))
7561 case ATK_TEXT_BOUNDARY_WORD_END:
7562 if (gtk_text_iter_inside_word (&start) &&
7563 !gtk_text_iter_starts_word (&start))
7564 gtk_text_iter_backward_word_start (&start);
7565 while (!gtk_text_iter_ends_word (&start))
7567 if (!gtk_text_iter_backward_char (&start))
7570 gtk_text_iter_forward_word_end (&end);
7572 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7573 if (!gtk_text_iter_starts_sentence (&start))
7574 gtk_text_iter_backward_sentence_start (&start);
7575 if (gtk_text_iter_inside_sentence (&end))
7576 gtk_text_iter_forward_sentence_end (&end);
7577 while (!gtk_text_iter_starts_sentence (&end))
7579 if (!gtk_text_iter_forward_char (&end))
7583 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7584 if (gtk_text_iter_inside_sentence (&start) &&
7585 !gtk_text_iter_starts_sentence (&start))
7586 gtk_text_iter_backward_sentence_start (&start);
7587 while (!gtk_text_iter_ends_sentence (&start))
7589 if (!gtk_text_iter_backward_char (&start))
7592 gtk_text_iter_forward_sentence_end (&end);
7594 case ATK_TEXT_BOUNDARY_LINE_START:
7595 case ATK_TEXT_BOUNDARY_LINE_END:
7597 icon_view = GTK_ICON_VIEW (item->widget);
7598 /* FIXME we probably have to use GailTextCell to salvage this */
7599 gtk_icon_view_update_item_text (icon_view, item->item);
7600 get_pango_text_offsets (icon_view->priv->layout,
7614 *start_offset = gtk_text_iter_get_offset (&start);
7615 *end_offset = gtk_text_iter_get_offset (&end);
7617 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7621 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7623 AtkTextBoundary boundary_type,
7627 GtkIconViewItemAccessible *item;
7628 GtkTextIter start, end;
7629 GtkTextBuffer *buffer;
7631 GtkIconView *icon_view;
7634 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7636 if (!GTK_IS_ICON_VIEW (item->widget))
7639 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7642 buffer = item->text_buffer;
7644 if (!gtk_text_buffer_get_char_count (buffer))
7648 return g_strdup ("");
7650 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7654 switch (boundary_type)
7656 case ATK_TEXT_BOUNDARY_CHAR:
7657 gtk_text_iter_forward_char(&start);
7658 gtk_text_iter_forward_chars(&end, 2);
7660 case ATK_TEXT_BOUNDARY_WORD_START:
7661 if (gtk_text_iter_inside_word (&end))
7662 gtk_text_iter_forward_word_end (&end);
7663 while (!gtk_text_iter_starts_word (&end))
7665 if (!gtk_text_iter_forward_char (&end))
7669 if (!gtk_text_iter_is_end (&end))
7671 gtk_text_iter_forward_word_end (&end);
7672 while (!gtk_text_iter_starts_word (&end))
7674 if (!gtk_text_iter_forward_char (&end))
7679 case ATK_TEXT_BOUNDARY_WORD_END:
7680 gtk_text_iter_forward_word_end (&end);
7682 if (!gtk_text_iter_is_end (&end))
7683 gtk_text_iter_forward_word_end (&end);
7685 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7686 if (gtk_text_iter_inside_sentence (&end))
7687 gtk_text_iter_forward_sentence_end (&end);
7688 while (!gtk_text_iter_starts_sentence (&end))
7690 if (!gtk_text_iter_forward_char (&end))
7694 if (!gtk_text_iter_is_end (&end))
7696 gtk_text_iter_forward_sentence_end (&end);
7697 while (!gtk_text_iter_starts_sentence (&end))
7699 if (!gtk_text_iter_forward_char (&end))
7704 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7705 gtk_text_iter_forward_sentence_end (&end);
7707 if (!gtk_text_iter_is_end (&end))
7708 gtk_text_iter_forward_sentence_end (&end);
7710 case ATK_TEXT_BOUNDARY_LINE_START:
7711 case ATK_TEXT_BOUNDARY_LINE_END:
7713 icon_view = GTK_ICON_VIEW (item->widget);
7714 /* FIXME we probably have to use GailTextCell to salvage this */
7715 gtk_icon_view_update_item_text (icon_view, item->item);
7716 get_pango_text_offsets (icon_view->priv->layout,
7728 *start_offset = gtk_text_iter_get_offset (&start);
7729 *end_offset = gtk_text_iter_get_offset (&end);
7731 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7735 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7737 GtkIconViewItemAccessible *item;
7739 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7741 if (!GTK_IS_ICON_VIEW (item->widget))
7744 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7747 return gtk_text_buffer_get_char_count (item->text_buffer);
7751 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7757 AtkCoordType coord_type)
7759 GtkIconViewItemAccessible *item;
7761 GtkIconView *icon_view;
7762 PangoRectangle char_rect;
7763 const gchar *item_text;
7767 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7769 if (!GTK_IS_ICON_VIEW (item->widget))
7772 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7776 icon_view = GTK_ICON_VIEW (item->widget);
7777 /* FIXME we probably have to use GailTextCell to salvage this */
7778 gtk_icon_view_update_item_text (icon_view, item->item);
7779 item_text = pango_layout_get_text (icon_view->priv->layout);
7780 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7781 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7783 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7784 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7785 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7786 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7787 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7788 *width = char_rect.width / PANGO_SCALE;
7789 *height = char_rect.height / PANGO_SCALE;
7794 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7797 AtkCoordType coord_type)
7799 GtkIconViewItemAccessible *item;
7802 GtkIconView *icon_view;
7803 const gchar *item_text;
7808 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7810 if (!GTK_IS_ICON_VIEW (item->widget))
7813 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7817 icon_view = GTK_ICON_VIEW (item->widget);
7818 /* FIXME we probably have to use GailTextCell to salvage this */
7819 gtk_icon_view_update_item_text (icon_view, item->item);
7820 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7821 x -= l_x + item->item->layout_x - item->item->x;
7822 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7823 y -= l_y + item->item->layout_y - item->item->y;
7824 item_text = pango_layout_get_text (icon_view->priv->layout);
7825 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7836 offset = g_utf8_strlen (item_text, -1);
7838 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7844 atk_text_item_interface_init (AtkTextIface *iface)
7846 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7847 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7848 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7849 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7850 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7851 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7852 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7853 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7857 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7862 AtkCoordType coord_type)
7864 GtkIconViewItemAccessible *item;
7865 AtkObject *parent_obj;
7868 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7870 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7871 if (!GTK_IS_WIDGET (item->widget))
7874 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7877 *width = item->item->width;
7878 *height = item->item->height;
7879 if (gtk_icon_view_item_accessible_is_showing (item))
7881 parent_obj = gtk_widget_get_accessible (item->widget);
7882 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7883 *x = l_x + item->item->x;
7884 *y = l_y + item->item->y;
7894 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7896 GtkIconViewItemAccessible *item;
7897 GtkWidget *toplevel;
7899 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7901 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7902 if (!GTK_IS_WIDGET (item->widget))
7905 gtk_widget_grab_focus (item->widget);
7906 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7907 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7908 if (gtk_widget_is_toplevel (toplevel))
7909 gtk_window_present (GTK_WINDOW (toplevel));
7915 atk_component_item_interface_init (AtkComponentIface *iface)
7917 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7918 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7922 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7923 AtkStateType state_type,
7924 gboolean emit_signal)
7928 rc = atk_state_set_add_state (item->state_set, state_type);
7930 * The signal should only be generated if the value changed,
7931 * not when the item is set up. So states that are set
7932 * initially should pass FALSE as the emit_signal argument.
7937 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7938 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7939 if (state_type == ATK_STATE_VISIBLE)
7940 g_signal_emit_by_name (item, "visible-data-changed");
7947 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7948 AtkStateType state_type,
7949 gboolean emit_signal)
7951 if (atk_state_set_contains_state (item->state_set, state_type))
7955 rc = atk_state_set_remove_state (item->state_set, state_type);
7957 * The signal should only be generated if the value changed,
7958 * not when the item is set up. So states that are set
7959 * initially should pass FALSE as the emit_signal argument.
7964 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7965 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7966 if (state_type == ATK_STATE_VISIBLE)
7967 g_signal_emit_by_name (item, "visible-data-changed");
7977 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7979 GtkAllocation allocation;
7980 GtkIconView *icon_view;
7981 GdkRectangle visible_rect;
7982 gboolean is_showing;
7985 * An item is considered "SHOWING" if any part of the item is in the
7986 * visible rectangle.
7989 if (!GTK_IS_ICON_VIEW (item->widget))
7992 if (item->item == NULL)
7995 gtk_widget_get_allocation (item->widget, &allocation);
7997 icon_view = GTK_ICON_VIEW (item->widget);
7999 if (icon_view->priv->hadjustment)
8000 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8002 if (icon_view->priv->hadjustment)
8003 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8004 visible_rect.width = allocation.width;
8005 visible_rect.height = allocation.height;
8007 if (((item->item->x + item->item->width) < visible_rect.x) ||
8008 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8009 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8010 (item->item->y > (visible_rect.y + visible_rect.height)))
8019 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8020 gboolean emit_signal)
8022 if (gtk_icon_view_item_accessible_is_showing (item))
8023 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8026 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8031 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8035 item->state_set = atk_state_set_new ();
8037 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8038 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8039 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8040 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8041 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8043 for (i = 0; i < LAST_ACTION; i++)
8044 item->action_descriptions[i] = NULL;
8046 item->image_description = NULL;
8048 item->action_idle_handler = 0;
8052 gtk_icon_view_item_accessible_finalize (GObject *object)
8054 GtkIconViewItemAccessible *item;
8057 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8059 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8062 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8064 if (item->state_set)
8065 g_object_unref (item->state_set);
8067 if (item->text_buffer)
8068 g_object_unref (item->text_buffer);
8070 for (i = 0; i < LAST_ACTION; i++)
8071 g_free (item->action_descriptions[i]);
8073 g_free (item->image_description);
8075 if (item->action_idle_handler)
8077 g_source_remove (item->action_idle_handler);
8078 item->action_idle_handler = 0;
8081 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8084 static G_CONST_RETURN gchar*
8085 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8091 GtkIconViewItemAccessible *item;
8092 GtkTextIter start_iter;
8093 GtkTextIter end_iter;
8095 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8097 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8098 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8100 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8105 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8107 GtkIconViewItemAccessible *item;
8109 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8110 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8113 return gtk_widget_get_accessible (item->widget);
8119 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8121 GtkIconViewItemAccessible *item;
8123 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8124 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8126 return item->item->index;
8129 static AtkStateSet *
8130 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8132 GtkIconViewItemAccessible *item;
8133 GtkIconView *icon_view;
8135 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8136 g_return_val_if_fail (item->state_set, NULL);
8141 icon_view = GTK_ICON_VIEW (item->widget);
8142 if (icon_view->priv->cursor_item == item->item)
8143 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8145 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8146 if (item->item->selected)
8147 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8149 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8151 return g_object_ref (item->state_set);
8155 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8157 GObjectClass *gobject_class;
8159 accessible_item_parent_class = g_type_class_peek_parent (klass);
8161 gobject_class = (GObjectClass *)klass;
8163 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8165 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8166 klass->get_name = gtk_icon_view_item_accessible_get_name;
8167 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8168 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8172 gtk_icon_view_item_accessible_get_type (void)
8174 static GType type = 0;
8178 const GTypeInfo tinfo =
8180 sizeof (GtkIconViewItemAccessibleClass),
8181 (GBaseInitFunc) NULL, /* base init */
8182 (GBaseFinalizeFunc) NULL, /* base finalize */
8183 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8184 (GClassFinalizeFunc) NULL, /* class finalize */
8185 NULL, /* class data */
8186 sizeof (GtkIconViewItemAccessible), /* instance size */
8187 0, /* nb preallocs */
8188 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8189 NULL /* value table */
8192 const GInterfaceInfo atk_component_info =
8194 (GInterfaceInitFunc) atk_component_item_interface_init,
8195 (GInterfaceFinalizeFunc) NULL,
8198 const GInterfaceInfo atk_action_info =
8200 (GInterfaceInitFunc) atk_action_item_interface_init,
8201 (GInterfaceFinalizeFunc) NULL,
8204 const GInterfaceInfo atk_image_info =
8206 (GInterfaceInitFunc) atk_image_item_interface_init,
8207 (GInterfaceFinalizeFunc) NULL,
8210 const GInterfaceInfo atk_text_info =
8212 (GInterfaceInitFunc) atk_text_item_interface_init,
8213 (GInterfaceFinalizeFunc) NULL,
8217 type = g_type_register_static (ATK_TYPE_OBJECT,
8218 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8219 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8220 &atk_component_info);
8221 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8223 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8225 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8232 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8233 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8234 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8236 static GType gtk_icon_view_accessible_get_type (void);
8241 } GtkIconViewAccessible;
8247 } GtkIconViewItemAccessibleInfo;
8253 GtkAdjustment *old_hadj;
8254 GtkAdjustment *old_vadj;
8256 GtkTreeModel *model;
8258 } GtkIconViewAccessiblePrivate;
8260 static GtkIconViewAccessiblePrivate *
8261 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8263 return g_object_get_qdata (G_OBJECT (accessible),
8264 accessible_private_data_quark);
8268 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8272 GtkIconViewItemAccessibleInfo *info;
8273 GtkIconViewItemAccessibleInfo *tmp_info;
8274 GtkIconViewAccessiblePrivate *priv;
8277 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8279 info->index = index;
8281 priv = gtk_icon_view_accessible_get_priv (accessible);
8282 items = priv->items;
8285 tmp_info = items->data;
8286 if (tmp_info->index > index)
8288 items = items->next;
8290 priv->items = g_list_insert_before (priv->items, items, info);
8291 priv->old_hadj = NULL;
8292 priv->old_vadj = NULL;
8296 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8298 GtkIconView *icon_view;
8301 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8305 icon_view = GTK_ICON_VIEW (widget);
8307 return g_list_length (icon_view->priv->items);
8311 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8314 GtkIconViewAccessiblePrivate *priv;
8315 GtkIconViewItemAccessibleInfo *info;
8318 priv = gtk_icon_view_accessible_get_priv (accessible);
8319 items = priv->items;
8324 if (info->index == index)
8326 items = items->next;
8332 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8335 GtkIconView *icon_view;
8339 GtkIconViewItemAccessible *a11y_item;
8341 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8345 icon_view = GTK_ICON_VIEW (widget);
8346 icons = g_list_nth (icon_view->priv->items, index);
8350 GtkIconViewItem *item = icons->data;
8352 g_return_val_if_fail (item->index == index, NULL);
8353 obj = gtk_icon_view_accessible_find_child (accessible, index);
8358 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8359 gtk_icon_view_item_accessible_info_new (accessible,
8362 obj->role = ATK_ROLE_ICON;
8363 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8364 a11y_item->item = item;
8365 a11y_item->widget = widget;
8366 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8368 text = get_text (icon_view, item);
8371 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8375 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8376 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8384 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8387 GtkIconViewAccessiblePrivate *priv;
8388 GtkIconViewItemAccessibleInfo *info;
8389 GtkIconViewItemAccessible *item;
8392 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8396 gboolean act_on_item;
8398 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8402 items = priv->items;
8404 act_on_item = (list == NULL);
8409 info = (GtkIconViewItemAccessibleInfo *)items->data;
8410 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8412 if (act_on_item == FALSE && list == items)
8416 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8418 items = items->next;
8424 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8425 GtkIconViewAccessible *view)
8427 gtk_icon_view_accessible_traverse_items (view, NULL);
8431 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8432 GtkOrientation orientation,
8433 GtkAdjustment *adjustment)
8435 GtkIconViewAccessiblePrivate *priv;
8436 GtkAdjustment **old_adj_ptr;
8438 priv = gtk_icon_view_accessible_get_priv (accessible);
8440 /* Adjustments are set for the first time in constructor and priv is not
8441 * initialized at that time, so skip this first setting. */
8445 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8447 if (priv->old_hadj == adjustment)
8450 old_adj_ptr = &priv->old_hadj;
8454 if (priv->old_vadj == adjustment)
8457 old_adj_ptr = &priv->old_vadj;
8460 /* Disconnect signal handlers */
8463 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8464 (gpointer *)&priv->old_hadj);
8465 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8466 gtk_icon_view_accessible_adjustment_changed,
8470 /* Connect signal */
8471 *old_adj_ptr = adjustment;
8472 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8473 g_signal_connect (adjustment, "value-changed",
8474 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8479 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8487 GtkIconView *icon_view;
8488 GtkIconViewItem *item;
8489 GtkIconViewAccessible *a11y_view;
8490 GtkIconViewItemAccessible *a11y_item;
8494 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8495 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8496 index = gtk_tree_path_get_indices(path)[0];
8497 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8498 gtk_icon_view_accessible_find_child (atk_obj, index));
8502 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8503 icon_view = GTK_ICON_VIEW (widget);
8504 item = a11y_item->item;
8506 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
8508 if (!name || strcmp (name, "") == 0)
8510 text = get_text (icon_view, item);
8513 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8519 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8525 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8530 GtkIconViewAccessiblePrivate *priv;
8531 GtkIconViewItemAccessibleInfo *info;
8532 GtkIconViewAccessible *view;
8533 GtkIconViewItemAccessible *item;
8539 index = gtk_tree_path_get_indices(path)[0];
8540 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8541 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8542 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8544 items = priv->items;
8549 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8550 if (info->index != item->item->index)
8552 if (info->index < index)
8553 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8555 if (tmp_list == NULL)
8558 info->index = item->item->index;
8561 items = items->next;
8563 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8564 g_signal_emit_by_name (atk_obj, "children-changed::add",
8570 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8574 GtkIconViewAccessiblePrivate *priv;
8575 GtkIconViewItemAccessibleInfo *info;
8576 GtkIconViewAccessible *view;
8577 GtkIconViewItemAccessible *item;
8580 GList *deleted_item;
8584 index = gtk_tree_path_get_indices(path)[0];
8585 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8586 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8587 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8589 items = priv->items;
8591 deleted_item = NULL;
8596 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8597 if (info->index == index)
8599 deleted_item = items;
8601 if (info->index != item->item->index)
8603 if (tmp_list == NULL)
8606 info->index = item->item->index;
8609 items = items->next;
8611 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8614 info = deleted_item->data;
8615 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8616 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8618 priv->items = g_list_remove_link (priv->items, deleted_item);
8626 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8627 GtkIconViewItemAccessibleInfo *i2)
8629 return i1->index - i2->index;
8633 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8639 GtkIconViewAccessiblePrivate *priv;
8640 GtkIconViewItemAccessibleInfo *info;
8641 GtkIconView *icon_view;
8642 GtkIconViewItemAccessible *item;
8648 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8649 icon_view = GTK_ICON_VIEW (user_data);
8650 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8652 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8654 order = g_new (gint, length);
8655 for (i = 0; i < length; i++)
8656 order [new_order[i]] = i;
8658 items = priv->items;
8662 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8663 info->index = order[info->index];
8664 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8665 items = items->next;
8668 priv->items = g_list_sort (priv->items,
8669 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8675 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8680 obj = G_OBJECT (model);
8681 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8682 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8683 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8684 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8688 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8692 obj = G_OBJECT (icon_view->priv->model);
8693 g_signal_connect_data (obj, "row-changed",
8694 (GCallback) gtk_icon_view_accessible_model_row_changed,
8695 icon_view, NULL, 0);
8696 g_signal_connect_data (obj, "row-inserted",
8697 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8698 icon_view, NULL, G_CONNECT_AFTER);
8699 g_signal_connect_data (obj, "row-deleted",
8700 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8701 icon_view, NULL, G_CONNECT_AFTER);
8702 g_signal_connect_data (obj, "rows-reordered",
8703 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8704 icon_view, NULL, G_CONNECT_AFTER);
8708 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8710 GtkIconViewItemAccessibleInfo *info;
8713 items = priv->items;
8716 info = (GtkIconViewItemAccessibleInfo *) items->data;
8717 g_object_unref (info->item);
8718 g_free (items->data);
8719 items = items->next;
8721 g_list_free (priv->items);
8726 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8729 GtkIconView *icon_view;
8732 GtkIconViewAccessiblePrivate *priv;
8734 if (strcmp (pspec->name, "model") == 0)
8736 widget = GTK_WIDGET (obj);
8737 atk_obj = gtk_widget_get_accessible (widget);
8738 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8741 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8742 (gpointer *)&priv->model);
8743 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8745 gtk_icon_view_accessible_clear_cache (priv);
8747 icon_view = GTK_ICON_VIEW (obj);
8748 priv->model = icon_view->priv->model;
8749 /* If there is no model the GtkIconView is probably being destroyed */
8752 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8753 gtk_icon_view_accessible_connect_model_signals (icon_view);
8761 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8764 GtkIconViewAccessiblePrivate *priv;
8765 GtkIconView *icon_view;
8767 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8768 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8770 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8771 g_object_set_qdata (G_OBJECT (accessible),
8772 accessible_private_data_quark,
8775 icon_view = GTK_ICON_VIEW (data);
8776 if (icon_view->priv->hadjustment)
8777 gtk_icon_view_accessible_set_adjustment (accessible,
8778 GTK_ORIENTATION_HORIZONTAL,
8779 icon_view->priv->hadjustment);
8780 if (icon_view->priv->vadjustment)
8781 gtk_icon_view_accessible_set_adjustment (accessible,
8782 GTK_ORIENTATION_VERTICAL,
8783 icon_view->priv->vadjustment);
8784 g_signal_connect (data,
8786 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8789 priv->model = icon_view->priv->model;
8792 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8793 gtk_icon_view_accessible_connect_model_signals (icon_view);
8796 accessible->role = ATK_ROLE_LAYERED_PANE;
8800 gtk_icon_view_accessible_finalize (GObject *object)
8802 GtkIconViewAccessiblePrivate *priv;
8804 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8805 gtk_icon_view_accessible_clear_cache (priv);
8809 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8813 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8814 GtkAccessible *accessible)
8817 GtkIconViewAccessiblePrivate *priv;
8819 atk_obj = ATK_OBJECT (accessible);
8820 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8823 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8824 (gpointer *)&priv->old_hadj);
8826 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8827 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8829 priv->old_hadj = NULL;
8833 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8834 (gpointer *)&priv->old_vadj);
8836 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8837 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8839 priv->old_vadj = NULL;
8844 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8848 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8851 g_signal_connect_after (widget,
8853 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8856 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8860 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8862 GObjectClass *gobject_class;
8863 GtkAccessibleClass *accessible_class;
8865 accessible_parent_class = g_type_class_peek_parent (klass);
8867 gobject_class = (GObjectClass *)klass;
8868 accessible_class = (GtkAccessibleClass *)klass;
8870 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8872 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8873 klass->ref_child = gtk_icon_view_accessible_ref_child;
8874 klass->initialize = gtk_icon_view_accessible_initialize;
8876 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8878 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8882 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8885 AtkCoordType coord_type)
8888 GtkIconView *icon_view;
8889 GtkIconViewItem *item;
8892 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8894 /* State is defunct */
8897 icon_view = GTK_ICON_VIEW (widget);
8898 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8899 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8901 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8907 atk_component_interface_init (AtkComponentIface *iface)
8909 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8913 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8917 GtkIconView *icon_view;
8918 GtkIconViewItem *item;
8920 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8924 icon_view = GTK_ICON_VIEW (widget);
8926 item = g_list_nth_data (icon_view->priv->items, i);
8931 gtk_icon_view_select_item (icon_view, item);
8937 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8940 GtkIconView *icon_view;
8942 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8946 icon_view = GTK_ICON_VIEW (widget);
8947 gtk_icon_view_unselect_all (icon_view);
8953 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8958 GtkIconView *icon_view;
8959 GtkIconViewItem *item;
8961 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8965 icon_view = GTK_ICON_VIEW (widget);
8967 l = icon_view->priv->items;
8974 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8985 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8988 GtkIconView *icon_view;
8989 GtkIconViewItem *item;
8993 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
8997 icon_view = GTK_ICON_VIEW (widget);
8999 l = icon_view->priv->items;
9015 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9019 GtkIconView *icon_view;
9020 GtkIconViewItem *item;
9022 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9026 icon_view = GTK_ICON_VIEW (widget);
9028 item = g_list_nth_data (icon_view->priv->items, i);
9032 return item->selected;
9036 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9040 GtkIconView *icon_view;
9041 GtkIconViewItem *item;
9045 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9049 icon_view = GTK_ICON_VIEW (widget);
9050 l = icon_view->priv->items;
9059 gtk_icon_view_unselect_item (icon_view, item);
9071 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9074 GtkIconView *icon_view;
9076 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9080 icon_view = GTK_ICON_VIEW (widget);
9081 gtk_icon_view_select_all (icon_view);
9086 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9088 iface->add_selection = gtk_icon_view_accessible_add_selection;
9089 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9090 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9091 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9092 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9093 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9094 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9098 gtk_icon_view_accessible_get_type (void)
9100 static GType type = 0;
9107 (GBaseInitFunc) NULL, /* base init */
9108 (GBaseFinalizeFunc) NULL, /* base finalize */
9109 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9110 (GClassFinalizeFunc) NULL, /* class finalize */
9111 NULL, /* class data */
9112 0, /* instance size */
9113 0, /* nb preallocs */
9114 (GInstanceInitFunc) NULL, /* instance init */
9115 NULL /* value table */
9117 const GInterfaceInfo atk_component_info =
9119 (GInterfaceInitFunc) atk_component_interface_init,
9120 (GInterfaceFinalizeFunc) NULL,
9123 const GInterfaceInfo atk_selection_info =
9125 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9126 (GInterfaceFinalizeFunc) NULL,
9131 * Figure out the size of the class and instance
9132 * we are deriving from
9134 AtkObjectFactory *factory;
9137 GType derived_atk_type;
9139 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9140 factory = atk_registry_get_factory (atk_get_default_registry (),
9142 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9143 g_type_query (derived_atk_type, &query);
9144 tinfo.class_size = query.class_size;
9145 tinfo.instance_size = query.instance_size;
9147 type = g_type_register_static (derived_atk_type,
9148 I_("GtkIconViewAccessible"),
9150 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9151 &atk_component_info);
9152 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9153 &atk_selection_info);
9159 gtk_icon_view_accessible_new (GObject *obj)
9161 AtkObject *accessible;
9163 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9165 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9166 atk_object_initialize (accessible, obj);
9172 gtk_icon_view_accessible_factory_get_accessible_type (void)
9174 return gtk_icon_view_accessible_get_type ();
9178 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9180 return gtk_icon_view_accessible_new (obj);
9184 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9186 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9187 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9191 gtk_icon_view_accessible_factory_get_type (void)
9193 static GType type = 0;
9197 const GTypeInfo tinfo =
9199 sizeof (AtkObjectFactoryClass),
9200 NULL, /* base_init */
9201 NULL, /* base_finalize */
9202 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9203 NULL, /* class_finalize */
9204 NULL, /* class_data */
9205 sizeof (AtkObjectFactory),
9206 0, /* n_preallocs */
9210 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9211 I_("GtkIconViewAccessibleFactory"),
9219 gtk_icon_view_get_accessible (GtkWidget *widget)
9221 static gboolean first_time = TRUE;
9225 AtkObjectFactory *factory;
9226 AtkRegistry *registry;
9228 GType derived_atk_type;
9231 * Figure out whether accessibility is enabled by looking at the
9232 * type of the accessible object which would be created for
9233 * the parent type of GtkIconView.
9235 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9237 registry = atk_get_default_registry ();
9238 factory = atk_registry_get_factory (registry,
9240 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9241 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9242 atk_registry_set_factory_type (registry,
9244 gtk_icon_view_accessible_factory_get_type ());
9247 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9251 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9252 GtkBuilder *builder,
9254 const gchar *tagname,
9255 GMarkupParser *parser,
9258 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9259 tagname, parser, data))
9262 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9263 tagname, parser, data);
9267 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9268 GtkBuilder *builder,
9270 const gchar *tagname,
9273 if (strcmp (tagname, "attributes") == 0)
9274 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9277 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,