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 "gtkaccessibleprivate.h"
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellareabox.h"
31 #include "gtkcellareacontext.h"
32 #include "gtkcellrenderertext.h"
33 #include "gtkcellrendererpixbuf.h"
34 #include "gtkorientable.h"
35 #include "gtkmarshalers.h"
36 #include "gtkbindings.h"
40 #include "gtkaccessible.h"
41 #include "gtkwindow.h"
43 #include "gtkcombobox.h"
44 #include "gtktextbuffer.h"
45 #include "gtkscrollable.h"
46 #include "gtksizerequest.h"
47 #include "gtktreednd.h"
48 #include "gtktypebuiltins.h"
49 #include "gtkprivate.h"
54 * @short_description: A widget which displays a list of icons in a grid
56 * #GtkIconView provides an alternative view on a #GtkTreeModel.
57 * It displays the model as a grid of icons with labels. Like
58 * #GtkTreeView, it allows to select one or multiple items
59 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
60 * In addition to selection with the arrow keys, #GtkIconView supports
61 * rubberband selection, which is controlled by dragging the pointer.
63 * Note that if the tree model is backed by an actual tree store (as
64 * opposed to a flat list where the mapping to icons is obvious),
65 * #GtkIconView will only display the first level of the tree and
66 * ignore the tree's branches.
69 #define SCROLL_EDGE_SIZE 15
71 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
73 typedef struct _GtkIconViewItem GtkIconViewItem;
74 struct _GtkIconViewItem
76 /* First member is always the rectangle so it
77 * can be cast to a rectangle. */
78 GdkRectangle cell_area;
86 guint selected_before_rubberbanding : 1;
90 typedef struct _GtkIconViewChild GtkIconViewChild;
91 struct _GtkIconViewChild
97 struct _GtkIconViewPrivate
99 GtkCellArea *cell_area;
100 GtkCellAreaContext *cell_area_context;
102 gulong add_editable_id;
103 gulong remove_editable_id;
104 gulong context_changed_id;
106 GPtrArray *row_contexts;
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
127 GdkDevice *rubberband_device;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
136 GtkIconViewItem *last_single_clicked;
138 GtkOrientation item_orientation;
152 GtkCellRenderer *pixbuf_cell;
153 GtkCellRenderer *text_cell;
158 GdkModifierType start_button_mask;
163 GdkDragAction source_actions;
164 GdkDragAction dest_actions;
166 GtkTreeRowReference *dest_item;
167 GtkIconViewDropPosition dest_pos;
170 GtkTreeRowReference *scroll_to_path;
171 gfloat scroll_to_row_align;
172 gfloat scroll_to_col_align;
173 guint scroll_to_use_align : 1;
175 guint source_set : 1;
177 guint reorderable : 1;
178 guint empty_view_drop :1;
180 guint ctrl_pressed : 1;
181 guint shift_pressed : 1;
183 guint draw_focus : 1;
185 /* GtkScrollablePolicy needs to be checked when
186 * driving the scrollable adjustment values */
187 guint hscroll_policy : 1;
188 guint vscroll_policy : 1;
190 guint doing_rubberband : 1;
204 ACTIVATE_CURSOR_ITEM,
216 PROP_ITEM_ORIENTATION,
229 /* For scrollable interface */
237 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
238 static void gtk_icon_view_dispose (GObject *object);
239 static GObject *gtk_icon_view_constructor (GType type,
240 guint n_construct_properties,
241 GObjectConstructParam *construct_properties);
242 static void gtk_icon_view_set_property (GObject *object,
246 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkWidget vfuncs */
251 static void gtk_icon_view_destroy (GtkWidget *widget);
252 static void gtk_icon_view_realize (GtkWidget *widget);
253 static void gtk_icon_view_unrealize (GtkWidget *widget);
254 static void gtk_icon_view_style_updated (GtkWidget *widget);
255 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
256 GtkStateFlags previous_state);
257 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
260 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
263 static void gtk_icon_view_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static gboolean gtk_icon_view_draw (GtkWidget *widget,
267 static gboolean gtk_icon_view_motion (GtkWidget *widget,
268 GdkEventMotion *event);
269 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
270 GdkEventButton *event);
271 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
272 GdkEventButton *event);
273 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
275 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
277 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
280 /* GtkContainer vfuncs */
281 static void gtk_icon_view_remove (GtkContainer *container,
283 static void gtk_icon_view_forall (GtkContainer *container,
284 gboolean include_internals,
285 GtkCallback callback,
286 gpointer callback_data);
288 /* GtkIconView vfuncs */
289 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
291 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
292 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
293 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
295 /* Internal functions */
296 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
297 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
298 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
299 GtkAdjustment *adjustment);
300 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
301 GtkAdjustment *adjustment);
302 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
303 GtkOrientation orientation,
304 GtkAdjustment *adjustment);
305 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
306 GtkIconView *icon_view);
307 static void gtk_icon_view_layout (GtkIconView *icon_view);
308 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
310 GtkIconViewItem *item,
313 gboolean draw_focus);
314 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
316 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
318 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
319 GtkIconViewItem *item);
320 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
321 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
322 GtkIconViewItem *item,
323 GtkCellRenderer *cursor_cell);
324 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
328 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
329 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
330 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
331 GtkIconViewItem *item,
336 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
337 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
338 static void gtk_icon_view_update_rubberband (gpointer data);
339 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
340 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
341 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
344 GtkMovementStep step,
346 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
347 GtkMovementStep step,
349 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
351 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
353 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
355 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
357 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
358 GtkIconViewItem *item);
359 static void gtk_icon_view_select_item (GtkIconView *icon_view,
360 GtkIconViewItem *item);
361 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
362 GtkIconViewItem *item);
363 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
364 GtkIconViewItem *anchor,
365 GtkIconViewItem *cursor);
366 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
369 gboolean only_in_cell,
370 GtkCellRenderer **cell_at_pos);
371 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
372 GtkIconViewItem *item);
374 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
375 GtkCellArea *cell_area);
377 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
379 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
380 GtkIconViewItem *item);
382 static void gtk_icon_view_add_editable (GtkCellArea *area,
383 GtkCellRenderer *renderer,
384 GtkCellEditable *editable,
385 GdkRectangle *cell_area,
387 GtkIconView *icon_view);
388 static void gtk_icon_view_remove_editable (GtkCellArea *area,
389 GtkCellRenderer *renderer,
390 GtkCellEditable *editable,
391 GtkIconView *icon_view);
392 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
394 GtkIconView *icon_view);
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_updated = gtk_icon_view_style_updated;
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_flags_changed = gtk_icon_view_state_flags_changed;
504 container_class->remove = gtk_icon_view_remove;
505 container_class->forall = gtk_icon_view_forall;
507 klass->select_all = gtk_icon_view_real_select_all;
508 klass->unselect_all = gtk_icon_view_real_unselect_all;
509 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
510 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
511 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
512 klass->move_cursor = gtk_icon_view_real_move_cursor;
516 * GtkIconView:selection-mode:
518 * The ::selection-mode property specifies the selection mode of
519 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
520 * is enabled, for the other modes, only keyboard selection is possible.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_enum ("selection-mode",
527 P_("Selection mode"),
528 P_("The selection mode"),
529 GTK_TYPE_SELECTION_MODE,
530 GTK_SELECTION_SINGLE,
531 GTK_PARAM_READWRITE));
534 * GtkIconView:pixbuf-column:
536 * The ::pixbuf-column property contains the number of the model column
537 * containing the pixbufs which are displayed. The pixbuf column must be
538 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
539 * display of pixbufs.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_int ("pixbuf-column",
547 P_("Model column used to retrieve the icon pixbuf from"),
549 GTK_PARAM_READWRITE));
552 * GtkIconView:text-column:
554 * The ::text-column property contains the number of the model column
555 * containing the texts which are displayed. The text column must be
556 * of type #G_TYPE_STRING. If this property and the :markup-column
557 * property are both set to -1, no texts are displayed.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_int ("text-column",
565 P_("Model column used to retrieve the text from"),
567 GTK_PARAM_READWRITE));
571 * GtkIconView:markup-column:
573 * The ::markup-column property contains the number of the model column
574 * containing markup information to be displayed. The markup column must be
575 * of type #G_TYPE_STRING. If this property and the :text-column property
576 * are both set to column numbers, it overrides the text column.
577 * If both are set to -1, no texts are displayed.
581 g_object_class_install_property (gobject_class,
583 g_param_spec_int ("markup-column",
585 P_("Model column used to retrieve the text if using Pango markup"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (gobject_class,
591 g_param_spec_object ("model",
592 P_("Icon View Model"),
593 P_("The model for the icon view"),
595 GTK_PARAM_READWRITE));
598 * GtkIconView:columns:
600 * The columns property contains the number of the columns in which the
601 * items should be displayed. If it is -1, the number of columns will
602 * be chosen automatically to fill the available area.
606 g_object_class_install_property (gobject_class,
608 g_param_spec_int ("columns",
609 P_("Number of columns"),
610 P_("Number of columns to display"),
612 GTK_PARAM_READWRITE));
616 * GtkIconView:item-width:
618 * The item-width property specifies the width to use for each item.
619 * If it is set to -1, the icon view will automatically determine a
620 * suitable item size.
624 g_object_class_install_property (gobject_class,
626 g_param_spec_int ("item-width",
627 P_("Width for each item"),
628 P_("The width used for each item"),
630 GTK_PARAM_READWRITE));
633 * GtkIconView:spacing:
635 * The spacing property specifies the space which is inserted between
636 * the cells (i.e. the icon and the text) of an item.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("spacing",
644 P_("Space which is inserted between cells of an item"),
646 GTK_PARAM_READWRITE));
649 * GtkIconView:row-spacing:
651 * The row-spacing property specifies the space which is inserted between
652 * the rows of the icon view.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("row-spacing",
660 P_("Space which is inserted between grid rows"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView:column-spacing:
667 * The column-spacing property specifies the space which is inserted between
668 * the columns of the icon view.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("column-spacing",
675 P_("Column Spacing"),
676 P_("Space which is inserted between grid columns"),
678 GTK_PARAM_READWRITE));
681 * GtkIconView:margin:
683 * The margin property specifies the space which is inserted
684 * at the edges of the icon view.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("margin",
692 P_("Space which is inserted at the edges of the icon view"),
694 GTK_PARAM_READWRITE));
697 * GtkIconView:item-orientation:
699 * The item-orientation property specifies how the cells (i.e. the icon and
700 * the text) of the item are positioned relative to each other.
704 g_object_class_install_property (gobject_class,
705 PROP_ITEM_ORIENTATION,
706 g_param_spec_enum ("item-orientation",
707 P_("Item Orientation"),
708 P_("How the text and icon of each item are positioned relative to each other"),
709 GTK_TYPE_ORIENTATION,
710 GTK_ORIENTATION_VERTICAL,
711 GTK_PARAM_READWRITE));
714 * GtkIconView:reorderable:
716 * The reorderable property specifies if the items can be reordered
721 g_object_class_install_property (gobject_class,
723 g_param_spec_boolean ("reorderable",
725 P_("View is reorderable"),
729 g_object_class_install_property (gobject_class,
731 g_param_spec_int ("tooltip-column",
732 P_("Tooltip Column"),
733 P_("The column in the model containing the tooltip texts for the items"),
737 GTK_PARAM_READWRITE));
740 * GtkIconView:item-padding:
742 * The item-padding property specifies the padding around each
743 * of the icon view's item.
747 g_object_class_install_property (gobject_class,
749 g_param_spec_int ("item-padding",
751 P_("Padding around icon view items"),
753 GTK_PARAM_READWRITE));
756 * GtkIconView:cell-area:
758 * The #GtkCellArea used to layout cell renderers for this view.
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->spacing = 0;
1089 icon_view->priv->row_spacing = 6;
1090 icon_view->priv->column_spacing = 6;
1091 icon_view->priv->margin = 6;
1092 icon_view->priv->item_padding = 6;
1094 icon_view->priv->draw_focus = TRUE;
1096 icon_view->priv->row_contexts =
1097 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1100 /* GObject methods */
1102 gtk_icon_view_constructor (GType type,
1103 guint n_construct_properties,
1104 GObjectConstructParam *construct_properties)
1106 GtkIconView *icon_view;
1109 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1110 (type, n_construct_properties, construct_properties);
1112 icon_view = (GtkIconView *) object;
1114 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1120 gtk_icon_view_dispose (GObject *object)
1122 GtkIconView *icon_view;
1123 GtkIconViewPrivate *priv;
1125 icon_view = GTK_ICON_VIEW (object);
1126 priv = icon_view->priv;
1128 if (priv->cell_area_context)
1130 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1131 priv->context_changed_id = 0;
1133 g_object_unref (priv->cell_area_context);
1134 priv->cell_area_context = NULL;
1137 if (priv->row_contexts)
1139 g_ptr_array_free (priv->row_contexts, TRUE);
1140 priv->row_contexts = NULL;
1143 if (priv->cell_area)
1145 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1147 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1148 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1149 priv->add_editable_id = 0;
1150 priv->remove_editable_id = 0;
1152 g_object_unref (priv->cell_area);
1153 priv->cell_area = NULL;
1156 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1160 gtk_icon_view_set_property (GObject *object,
1162 const GValue *value,
1165 GtkIconView *icon_view;
1168 icon_view = GTK_ICON_VIEW (object);
1172 case PROP_SELECTION_MODE:
1173 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1175 case PROP_PIXBUF_COLUMN:
1176 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1178 case PROP_TEXT_COLUMN:
1179 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1181 case PROP_MARKUP_COLUMN:
1182 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1185 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1187 case PROP_ITEM_ORIENTATION:
1188 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1191 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1193 case PROP_ITEM_WIDTH:
1194 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1197 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1199 case PROP_ROW_SPACING:
1200 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1202 case PROP_COLUMN_SPACING:
1203 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1206 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1208 case PROP_REORDERABLE:
1209 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1212 case PROP_TOOLTIP_COLUMN:
1213 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1216 case PROP_ITEM_PADDING:
1217 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1220 case PROP_CELL_AREA:
1221 /* Construct-only, can only be assigned once */
1222 area = g_value_get_object (value);
1225 if (icon_view->priv->cell_area != NULL)
1227 g_warning ("cell-area has already been set, ignoring construct property");
1228 g_object_ref_sink (area);
1229 g_object_unref (area);
1232 gtk_icon_view_ensure_cell_area (icon_view, area);
1236 case PROP_HADJUSTMENT:
1237 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1239 case PROP_VADJUSTMENT:
1240 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1242 case PROP_HSCROLL_POLICY:
1243 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1244 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1246 case PROP_VSCROLL_POLICY:
1247 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1248 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1258 gtk_icon_view_get_property (GObject *object,
1263 GtkIconView *icon_view;
1265 icon_view = GTK_ICON_VIEW (object);
1269 case PROP_SELECTION_MODE:
1270 g_value_set_enum (value, icon_view->priv->selection_mode);
1272 case PROP_PIXBUF_COLUMN:
1273 g_value_set_int (value, icon_view->priv->pixbuf_column);
1275 case PROP_TEXT_COLUMN:
1276 g_value_set_int (value, icon_view->priv->text_column);
1278 case PROP_MARKUP_COLUMN:
1279 g_value_set_int (value, icon_view->priv->markup_column);
1282 g_value_set_object (value, icon_view->priv->model);
1284 case PROP_ITEM_ORIENTATION:
1285 g_value_set_enum (value, icon_view->priv->item_orientation);
1288 g_value_set_int (value, icon_view->priv->columns);
1290 case PROP_ITEM_WIDTH:
1291 g_value_set_int (value, icon_view->priv->item_width);
1294 g_value_set_int (value, icon_view->priv->spacing);
1296 case PROP_ROW_SPACING:
1297 g_value_set_int (value, icon_view->priv->row_spacing);
1299 case PROP_COLUMN_SPACING:
1300 g_value_set_int (value, icon_view->priv->column_spacing);
1303 g_value_set_int (value, icon_view->priv->margin);
1305 case PROP_REORDERABLE:
1306 g_value_set_boolean (value, icon_view->priv->reorderable);
1308 case PROP_TOOLTIP_COLUMN:
1309 g_value_set_int (value, icon_view->priv->tooltip_column);
1312 case PROP_ITEM_PADDING:
1313 g_value_set_int (value, icon_view->priv->item_padding);
1316 case PROP_CELL_AREA:
1317 g_value_set_object (value, icon_view->priv->cell_area);
1320 case PROP_HADJUSTMENT:
1321 g_value_set_object (value, icon_view->priv->hadjustment);
1323 case PROP_VADJUSTMENT:
1324 g_value_set_object (value, icon_view->priv->vadjustment);
1326 case PROP_HSCROLL_POLICY:
1327 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1329 case PROP_VSCROLL_POLICY:
1330 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1339 /* GtkWidget methods */
1341 gtk_icon_view_destroy (GtkWidget *widget)
1343 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1345 gtk_icon_view_set_model (icon_view, NULL);
1347 if (icon_view->priv->layout_idle_id != 0)
1349 g_source_remove (icon_view->priv->layout_idle_id);
1350 icon_view->priv->layout_idle_id = 0;
1353 if (icon_view->priv->scroll_to_path != NULL)
1355 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1356 icon_view->priv->scroll_to_path = NULL;
1359 remove_scroll_timeout (icon_view);
1361 if (icon_view->priv->hadjustment != NULL)
1363 g_object_unref (icon_view->priv->hadjustment);
1364 icon_view->priv->hadjustment = NULL;
1367 if (icon_view->priv->vadjustment != NULL)
1369 g_object_unref (icon_view->priv->vadjustment);
1370 icon_view->priv->vadjustment = NULL;
1373 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1377 gtk_icon_view_realize (GtkWidget *widget)
1379 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1380 GtkAllocation allocation;
1382 GdkWindowAttr attributes;
1383 gint attributes_mask;
1384 GtkStyleContext *context;
1386 gtk_widget_set_realized (widget, TRUE);
1388 gtk_widget_get_allocation (widget, &allocation);
1390 /* Make the main, clipping window */
1391 attributes.window_type = GDK_WINDOW_CHILD;
1392 attributes.x = allocation.x;
1393 attributes.y = allocation.y;
1394 attributes.width = allocation.width;
1395 attributes.height = allocation.height;
1396 attributes.wclass = GDK_INPUT_OUTPUT;
1397 attributes.visual = gtk_widget_get_visual (widget);
1398 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1400 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1402 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1403 &attributes, attributes_mask);
1404 gtk_widget_set_window (widget, window);
1405 gdk_window_set_user_data (window, widget);
1407 gtk_widget_get_allocation (widget, &allocation);
1409 /* Make the window for the icon view */
1412 attributes.width = MAX (icon_view->priv->width, allocation.width);
1413 attributes.height = MAX (icon_view->priv->height, allocation.height);
1414 attributes.event_mask = (GDK_EXPOSURE_MASK |
1416 GDK_POINTER_MOTION_MASK |
1417 GDK_BUTTON_PRESS_MASK |
1418 GDK_BUTTON_RELEASE_MASK |
1419 GDK_KEY_PRESS_MASK |
1420 GDK_KEY_RELEASE_MASK) |
1421 gtk_widget_get_events (widget);
1423 icon_view->priv->bin_window = gdk_window_new (window,
1424 &attributes, attributes_mask);
1425 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1427 context = gtk_widget_get_style_context (widget);
1429 gtk_style_context_save (context);
1430 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1431 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1432 gtk_style_context_restore (context);
1434 gdk_window_show (icon_view->priv->bin_window);
1438 gtk_icon_view_unrealize (GtkWidget *widget)
1440 GtkIconView *icon_view;
1442 icon_view = GTK_ICON_VIEW (widget);
1444 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1445 gdk_window_destroy (icon_view->priv->bin_window);
1446 icon_view->priv->bin_window = NULL;
1448 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1452 _gtk_icon_view_update_background (GtkIconView *icon_view)
1454 GtkWidget *widget = GTK_WIDGET (icon_view);
1456 if (gtk_widget_get_realized (widget))
1458 GtkStyleContext *context;
1460 context = gtk_widget_get_style_context (widget);
1462 gtk_style_context_save (context);
1463 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1465 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1466 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1468 gtk_style_context_restore (context);
1473 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1474 GtkStateFlags previous_state)
1476 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1477 gtk_widget_queue_draw (widget);
1481 gtk_icon_view_style_updated (GtkWidget *widget)
1483 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1485 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1486 gtk_widget_queue_resize (widget);
1490 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1494 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1498 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1502 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1506 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1510 for (list = icon_view->priv->children; list; list = list->next)
1512 GtkIconViewChild *child = list->data;
1514 /* totally ignore our child's requisition */
1515 gtk_widget_size_allocate (child->widget, &child->area);
1520 gtk_icon_view_size_allocate (GtkWidget *widget,
1521 GtkAllocation *allocation)
1523 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1525 gtk_widget_set_allocation (widget, allocation);
1527 if (gtk_widget_get_realized (widget))
1529 gdk_window_move_resize (gtk_widget_get_window (widget),
1530 allocation->x, allocation->y,
1531 allocation->width, allocation->height);
1532 gdk_window_resize (icon_view->priv->bin_window,
1533 MAX (icon_view->priv->width, allocation->width),
1534 MAX (icon_view->priv->height, allocation->height));
1537 gtk_icon_view_layout (icon_view);
1539 gtk_icon_view_allocate_children (icon_view);
1541 /* Delay signal emission */
1542 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1543 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1545 gtk_icon_view_set_hadjustment_values (icon_view);
1546 gtk_icon_view_set_vadjustment_values (icon_view);
1548 if (gtk_widget_get_realized (widget) &&
1549 icon_view->priv->scroll_to_path)
1552 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1553 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1554 icon_view->priv->scroll_to_path = NULL;
1556 gtk_icon_view_scroll_to_path (icon_view, path,
1557 icon_view->priv->scroll_to_use_align,
1558 icon_view->priv->scroll_to_row_align,
1559 icon_view->priv->scroll_to_col_align);
1560 gtk_tree_path_free (path);
1563 /* Emit any pending signals now */
1564 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1565 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1569 gtk_icon_view_draw (GtkWidget *widget,
1572 GtkIconView *icon_view;
1576 GtkIconViewDropPosition dest_pos;
1577 GtkIconViewItem *dest_item = NULL;
1579 icon_view = GTK_ICON_VIEW (widget);
1581 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1586 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1588 cairo_set_line_width (cr, 1.);
1590 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1594 dest_index = gtk_tree_path_get_indices (path)[0];
1595 gtk_tree_path_free (path);
1600 for (icons = icon_view->priv->items; icons; icons = icons->next)
1602 GtkIconViewItem *item = icons->data;
1603 GdkRectangle paint_area;
1605 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1606 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1607 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1608 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1612 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1615 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1617 gtk_icon_view_paint_item (icon_view, cr, item,
1618 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1619 icon_view->priv->draw_focus);
1621 if (dest_index == item->index)
1629 dest_pos != GTK_ICON_VIEW_NO_DROP)
1631 GtkStyleContext *context;
1632 GtkStateFlags state;
1633 GdkRectangle rect = { 0 };
1635 context = gtk_widget_get_style_context (widget);
1636 state = gtk_widget_get_state_flags (widget);
1640 case GTK_ICON_VIEW_DROP_INTO:
1641 rect = dest_item->cell_area;
1643 case GTK_ICON_VIEW_DROP_ABOVE:
1644 rect.x = dest_item->cell_area.x;
1645 rect.y = dest_item->cell_area.y - 1;
1646 rect.width = dest_item->cell_area.width;
1649 case GTK_ICON_VIEW_DROP_LEFT:
1650 rect.x = dest_item->cell_area.x - 1;
1651 rect.y = dest_item->cell_area.y;
1653 rect.height = dest_item->cell_area.height;
1655 case GTK_ICON_VIEW_DROP_BELOW:
1656 rect.x = dest_item->cell_area.x;
1657 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1658 rect.width = dest_item->cell_area.width;
1661 case GTK_ICON_VIEW_DROP_RIGHT:
1662 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1663 rect.y = dest_item->cell_area.y;
1665 rect.height = dest_item->cell_area.height;
1666 case GTK_ICON_VIEW_NO_DROP: ;
1670 gtk_style_context_set_state (context, state);
1671 gtk_render_focus (context, cr,
1673 rect.width, rect.height);
1676 if (icon_view->priv->doing_rubberband)
1677 gtk_icon_view_paint_rubberband (icon_view, cr);
1681 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1687 rubberband_scroll_timeout (gpointer data)
1689 GtkIconView *icon_view = data;
1691 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1692 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1693 icon_view->priv->scroll_value_diff);
1695 gtk_icon_view_update_rubberband (icon_view);
1701 gtk_icon_view_motion (GtkWidget *widget,
1702 GdkEventMotion *event)
1704 GtkAllocation allocation;
1705 GtkIconView *icon_view;
1708 icon_view = GTK_ICON_VIEW (widget);
1710 gtk_icon_view_maybe_begin_drag (icon_view, event);
1712 if (icon_view->priv->doing_rubberband)
1714 gtk_icon_view_update_rubberband (widget);
1716 abs_y = event->y - icon_view->priv->height *
1717 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1718 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1719 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1721 gtk_widget_get_allocation (widget, &allocation);
1723 if (abs_y < 0 || abs_y > allocation.height)
1726 icon_view->priv->scroll_value_diff = abs_y;
1728 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1730 icon_view->priv->event_last_x = event->x;
1731 icon_view->priv->event_last_y = event->y;
1733 if (icon_view->priv->scroll_timeout_id == 0)
1734 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1738 remove_scroll_timeout (icon_view);
1745 gtk_icon_view_remove (GtkContainer *container,
1748 GtkIconView *icon_view;
1749 GtkIconViewChild *child = NULL;
1752 icon_view = GTK_ICON_VIEW (container);
1754 tmp_list = icon_view->priv->children;
1757 child = tmp_list->data;
1758 if (child->widget == widget)
1760 gtk_widget_unparent (widget);
1762 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1763 g_list_free_1 (tmp_list);
1768 tmp_list = tmp_list->next;
1773 gtk_icon_view_forall (GtkContainer *container,
1774 gboolean include_internals,
1775 GtkCallback callback,
1776 gpointer callback_data)
1778 GtkIconView *icon_view;
1779 GtkIconViewChild *child = NULL;
1782 icon_view = GTK_ICON_VIEW (container);
1784 tmp_list = icon_view->priv->children;
1787 child = tmp_list->data;
1788 tmp_list = tmp_list->next;
1790 (* callback) (child->widget, callback_data);
1795 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1796 GtkIconViewItem *item)
1799 AtkObject *item_obj;
1801 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1804 item_obj = atk_object_ref_accessible_child (obj, item->index);
1805 if (item_obj != NULL)
1807 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1808 g_object_unref (item_obj);
1814 gtk_icon_view_add_editable (GtkCellArea *area,
1815 GtkCellRenderer *renderer,
1816 GtkCellEditable *editable,
1817 GdkRectangle *cell_area,
1819 GtkIconView *icon_view)
1821 GtkIconViewChild *child;
1822 GtkWidget *widget = GTK_WIDGET (editable);
1824 child = g_new (GtkIconViewChild, 1);
1826 child->widget = widget;
1827 child->area.x = cell_area->x;
1828 child->area.y = cell_area->y;
1829 child->area.width = cell_area->width;
1830 child->area.height = cell_area->height;
1832 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1834 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1835 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1837 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1841 gtk_icon_view_remove_editable (GtkCellArea *area,
1842 GtkCellRenderer *renderer,
1843 GtkCellEditable *editable,
1844 GtkIconView *icon_view)
1848 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1849 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1851 gtk_container_remove (GTK_CONTAINER (icon_view),
1852 GTK_WIDGET (editable));
1854 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1855 gtk_icon_view_queue_draw_path (icon_view, path);
1856 gtk_tree_path_free (path);
1860 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1862 GtkIconView *icon_view)
1864 if (!strcmp (pspec->name, "minimum-width") ||
1865 !strcmp (pspec->name, "natural-width") ||
1866 !strcmp (pspec->name, "minimum-height") ||
1867 !strcmp (pspec->name, "natural-height"))
1868 gtk_icon_view_invalidate_sizes (icon_view);
1872 * gtk_icon_view_set_cursor:
1873 * @icon_view: A #GtkIconView
1874 * @path: A #GtkTreePath
1875 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1876 * @start_editing: %TRUE if the specified cell should start being edited.
1878 * Sets the current keyboard focus to be at @path, and selects it. This is
1879 * useful when you want to focus the user's attention on a particular item.
1880 * If @cell is not %NULL, then focus is given to the cell specified by
1881 * it. Additionally, if @start_editing is %TRUE, then editing should be
1882 * started in the specified cell.
1884 * This function is often followed by <literal>gtk_widget_grab_focus
1885 * (icon_view)</literal> in order to give keyboard focus to the widget.
1886 * Please note that editing can only happen when the widget is realized.
1891 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1893 GtkCellRenderer *cell,
1894 gboolean start_editing)
1896 GtkIconViewItem *item = NULL;
1898 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1899 g_return_if_fail (path != NULL);
1900 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1902 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1904 if (gtk_tree_path_get_depth (path) == 1)
1905 item = g_list_nth_data (icon_view->priv->items,
1906 gtk_tree_path_get_indices(path)[0]);
1911 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1912 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1916 GtkCellAreaContext *context;
1918 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1919 gtk_icon_view_set_cell_data (icon_view, item);
1920 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1921 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1922 0 /* XXX flags */, TRUE);
1927 * gtk_icon_view_get_cursor:
1928 * @icon_view: A #GtkIconView
1929 * @path: (out) (allow-none): Return location for the current cursor path,
1931 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1933 * Fills in @path and @cell with the current cursor path and cell.
1934 * If the cursor isn't currently set, then *@path will be %NULL.
1935 * If no cell currently has focus, then *@cell will be %NULL.
1937 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1939 * Return value: %TRUE if the cursor is set.
1944 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1946 GtkCellRenderer **cell)
1948 GtkIconViewItem *item;
1950 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1952 item = icon_view->priv->cursor_item;
1957 *path = gtk_tree_path_new_from_indices (item->index, -1);
1962 if (cell != NULL && item != NULL)
1963 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1965 return (item != NULL);
1969 gtk_icon_view_button_press (GtkWidget *widget,
1970 GdkEventButton *event)
1972 GtkIconView *icon_view;
1973 GtkIconViewItem *item;
1974 gboolean dirty = FALSE;
1975 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1977 icon_view = GTK_ICON_VIEW (widget);
1979 if (event->window != icon_view->priv->bin_window)
1982 if (!gtk_widget_has_focus (widget))
1983 gtk_widget_grab_focus (widget);
1985 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1987 item = gtk_icon_view_get_item_at_coords (icon_view,
1993 * We consider only the the cells' area as the item area if the
1994 * item is not selected, but if it *is* selected, the complete
1995 * selection rectangle is considered to be part of the item.
1997 if (item != NULL && (cell != NULL || item->selected))
2001 if (gtk_cell_renderer_is_activatable (cell))
2005 gtk_icon_view_scroll_to_item (icon_view, item);
2007 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2009 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2011 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2012 (event->state & GDK_SHIFT_MASK))
2014 gtk_icon_view_unselect_all_internal (icon_view);
2016 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2017 if (!icon_view->priv->anchor_item)
2018 icon_view->priv->anchor_item = item;
2020 gtk_icon_view_select_all_between (icon_view,
2021 icon_view->priv->anchor_item,
2027 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2028 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2029 (event->state & GDK_CONTROL_MASK))
2031 item->selected = !item->selected;
2032 gtk_icon_view_queue_draw_item (icon_view, item);
2037 gtk_icon_view_unselect_all_internal (icon_view);
2039 item->selected = TRUE;
2040 gtk_icon_view_queue_draw_item (icon_view, item);
2043 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2044 icon_view->priv->anchor_item = item;
2047 /* Save press to possibly begin a drag */
2048 if (icon_view->priv->pressed_button < 0)
2050 icon_view->priv->pressed_button = event->button;
2051 icon_view->priv->press_start_x = event->x;
2052 icon_view->priv->press_start_y = event->y;
2055 if (!icon_view->priv->last_single_clicked)
2056 icon_view->priv->last_single_clicked = item;
2058 /* cancel the current editing, if it exists */
2059 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2061 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2063 GtkCellAreaContext *context;
2065 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2067 gtk_icon_view_set_cell_data (icon_view, item);
2068 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2069 GTK_WIDGET (icon_view),
2070 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2075 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2076 !(event->state & GDK_CONTROL_MASK))
2078 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2081 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2082 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2085 /* don't draw keyboard focus around an clicked-on item */
2086 icon_view->priv->draw_focus = FALSE;
2089 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2091 item = gtk_icon_view_get_item_at_coords (icon_view,
2096 if (item && item == icon_view->priv->last_single_clicked)
2100 path = gtk_tree_path_new_from_indices (item->index, -1);
2101 gtk_icon_view_item_activated (icon_view, path);
2102 gtk_tree_path_free (path);
2105 icon_view->priv->last_single_clicked = NULL;
2106 icon_view->priv->pressed_button = -1;
2110 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2112 return event->button == 1;
2116 gtk_icon_view_button_release (GtkWidget *widget,
2117 GdkEventButton *event)
2119 GtkIconView *icon_view;
2121 icon_view = GTK_ICON_VIEW (widget);
2123 if (icon_view->priv->pressed_button == event->button)
2124 icon_view->priv->pressed_button = -1;
2126 gtk_icon_view_stop_rubberbanding (icon_view);
2128 remove_scroll_timeout (icon_view);
2134 gtk_icon_view_key_press (GtkWidget *widget,
2137 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2139 if (icon_view->priv->doing_rubberband)
2141 if (event->keyval == GDK_KEY_Escape)
2142 gtk_icon_view_stop_rubberbanding (icon_view);
2147 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2151 gtk_icon_view_key_release (GtkWidget *widget,
2154 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2156 if (icon_view->priv->doing_rubberband)
2159 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2163 gtk_icon_view_update_rubberband (gpointer data)
2165 GtkIconView *icon_view;
2167 GdkRectangle old_area;
2168 GdkRectangle new_area;
2169 GdkRectangle common;
2170 cairo_region_t *invalid_region;
2172 icon_view = GTK_ICON_VIEW (data);
2174 gdk_window_get_device_position (icon_view->priv->bin_window,
2175 icon_view->priv->rubberband_device,
2181 old_area.x = MIN (icon_view->priv->rubberband_x1,
2182 icon_view->priv->rubberband_x2);
2183 old_area.y = MIN (icon_view->priv->rubberband_y1,
2184 icon_view->priv->rubberband_y2);
2185 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2186 icon_view->priv->rubberband_x1) + 1;
2187 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2188 icon_view->priv->rubberband_y1) + 1;
2190 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2191 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2192 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2193 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2195 invalid_region = cairo_region_create_rectangle (&old_area);
2196 cairo_region_union_rectangle (invalid_region, &new_area);
2198 gdk_rectangle_intersect (&old_area, &new_area, &common);
2199 if (common.width > 2 && common.height > 2)
2201 cairo_region_t *common_region;
2203 /* make sure the border is invalidated */
2209 common_region = cairo_region_create_rectangle (&common);
2211 cairo_region_subtract (invalid_region, common_region);
2212 cairo_region_destroy (common_region);
2215 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2217 cairo_region_destroy (invalid_region);
2219 icon_view->priv->rubberband_x2 = x;
2220 icon_view->priv->rubberband_y2 = y;
2222 gtk_icon_view_update_rubberband_selection (icon_view);
2226 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2233 if (icon_view->priv->rubberband_device)
2236 for (items = icon_view->priv->items; items; items = items->next)
2238 GtkIconViewItem *item = items->data;
2240 item->selected_before_rubberbanding = item->selected;
2243 icon_view->priv->rubberband_x1 = x;
2244 icon_view->priv->rubberband_y1 = y;
2245 icon_view->priv->rubberband_x2 = x;
2246 icon_view->priv->rubberband_y2 = y;
2248 icon_view->priv->doing_rubberband = TRUE;
2249 icon_view->priv->rubberband_device = device;
2251 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2255 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2257 if (!icon_view->priv->doing_rubberband)
2260 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2261 icon_view->priv->rubberband_device);
2263 icon_view->priv->doing_rubberband = FALSE;
2264 icon_view->priv->rubberband_device = NULL;
2266 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2270 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2273 gint x, y, width, height;
2274 gboolean dirty = FALSE;
2276 x = MIN (icon_view->priv->rubberband_x1,
2277 icon_view->priv->rubberband_x2);
2278 y = MIN (icon_view->priv->rubberband_y1,
2279 icon_view->priv->rubberband_y2);
2280 width = ABS (icon_view->priv->rubberband_x1 -
2281 icon_view->priv->rubberband_x2);
2282 height = ABS (icon_view->priv->rubberband_y1 -
2283 icon_view->priv->rubberband_y2);
2285 for (items = icon_view->priv->items; items; items = items->next)
2287 GtkIconViewItem *item = items->data;
2291 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2292 x, y, width, height);
2294 selected = is_in ^ item->selected_before_rubberbanding;
2296 if (item->selected != selected)
2298 item->selected = selected;
2300 gtk_icon_view_queue_draw_item (icon_view, item);
2305 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2310 GdkRectangle hit_rect;
2315 hit_test (GtkCellRenderer *renderer,
2316 const GdkRectangle *cell_area,
2317 const GdkRectangle *cell_background,
2320 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2321 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2322 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2323 MAX (data->hit_rect.y, cell_area->y) > 0)
2326 return (data->hit != FALSE);
2330 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2331 GtkIconViewItem *item,
2337 HitTestData data = { { x, y, width, height }, FALSE };
2338 GtkCellAreaContext *context;
2339 GdkRectangle *item_area = (GdkRectangle *)item;
2341 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2342 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2345 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2347 gtk_icon_view_set_cell_data (icon_view, item);
2348 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2349 GTK_WIDGET (icon_view),
2350 item_area, item_area,
2351 (GtkCellAllocCallback)hit_test, &data);
2357 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2359 gboolean dirty = FALSE;
2362 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2365 for (items = icon_view->priv->items; items; items = items->next)
2367 GtkIconViewItem *item = items->data;
2371 item->selected = FALSE;
2373 gtk_icon_view_queue_draw_item (icon_view, item);
2374 gtk_icon_view_item_selected_changed (icon_view, item);
2382 /* GtkIconView signals */
2384 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2386 gtk_icon_view_select_all (icon_view);
2390 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2392 gtk_icon_view_unselect_all (icon_view);
2396 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2398 gtk_icon_view_unselect_all (icon_view);
2400 if (icon_view->priv->cursor_item != NULL)
2401 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2405 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2408 GtkCellAreaContext *context;
2410 if (!icon_view->priv->cursor_item)
2413 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2415 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2416 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2417 GTK_WIDGET (icon_view),
2418 (GdkRectangle *)icon_view->priv->cursor_item,
2422 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2423 gtk_icon_view_item_activated (icon_view, path);
2424 gtk_tree_path_free (path);
2430 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2432 if (!icon_view->priv->cursor_item)
2435 switch (icon_view->priv->selection_mode)
2437 case GTK_SELECTION_NONE:
2439 case GTK_SELECTION_BROWSE:
2440 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2442 case GTK_SELECTION_SINGLE:
2443 if (icon_view->priv->cursor_item->selected)
2444 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2446 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2448 case GTK_SELECTION_MULTIPLE:
2449 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2450 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2452 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2453 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2458 /* Internal functions */
2460 gtk_icon_view_process_updates (GtkIconView *icon_view)
2462 /* Prior to drawing, we check if a layout has been scheduled. If so,
2463 * do it now that all cell view items have valid sizes before we proceeed
2464 * (and resize the bin_window if required).
2466 if (icon_view->priv->layout_idle_id != 0)
2467 gtk_icon_view_layout (icon_view);
2469 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2473 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2475 GtkAllocation allocation;
2476 GtkAdjustment *adj = icon_view->priv->hadjustment;
2477 gdouble old_page_size;
2483 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2485 old_value = gtk_adjustment_get_value (adj);
2486 old_upper = gtk_adjustment_get_upper (adj);
2487 old_page_size = gtk_adjustment_get_page_size (adj);
2488 new_upper = MAX (allocation.width, icon_view->priv->width);
2490 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2492 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2493 /* Quick explanation:
2494 * In LTR locales, leftmost portion of visible rectangle should stay
2495 * fixed, which means left edge of scrollbar thumb should remain fixed
2496 * and thus adjustment's value should stay the same.
2498 * In RTL locales, we want to keep rightmost portion of visible
2499 * rectangle fixed. This means right edge of thumb should remain fixed.
2500 * In this case, upper - value - page_size should remain constant.
2502 new_value = (new_upper - allocation.width) -
2503 (old_upper - old_value - old_page_size);
2504 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2507 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2509 gtk_adjustment_configure (adj,
2513 allocation.width * 0.1,
2514 allocation.width * 0.9,
2519 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2521 GtkAllocation allocation;
2522 GtkAdjustment *adj = icon_view->priv->vadjustment;
2524 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2526 gtk_adjustment_configure (adj,
2527 gtk_adjustment_get_value (adj),
2529 MAX (allocation.height, icon_view->priv->height),
2530 allocation.height * 0.1,
2531 allocation.height * 0.9,
2536 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2537 GtkAdjustment *adjustment)
2539 GtkIconViewPrivate *priv = icon_view->priv;
2542 if (adjustment && priv->hadjustment == adjustment)
2545 if (priv->hadjustment != NULL)
2547 g_signal_handlers_disconnect_matched (priv->hadjustment,
2548 G_SIGNAL_MATCH_DATA,
2549 0, 0, NULL, NULL, icon_view);
2550 g_object_unref (priv->hadjustment);
2554 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2557 g_signal_connect (adjustment, "value-changed",
2558 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2559 priv->hadjustment = g_object_ref_sink (adjustment);
2560 gtk_icon_view_set_hadjustment_values (icon_view);
2562 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2563 gtk_icon_view_accessible_set_adjustment (atk_obj,
2564 GTK_ORIENTATION_HORIZONTAL,
2567 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2571 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2572 GtkAdjustment *adjustment)
2574 GtkIconViewPrivate *priv = icon_view->priv;
2577 if (adjustment && priv->vadjustment == adjustment)
2580 if (priv->vadjustment != NULL)
2582 g_signal_handlers_disconnect_matched (priv->vadjustment,
2583 G_SIGNAL_MATCH_DATA,
2584 0, 0, NULL, NULL, icon_view);
2585 g_object_unref (priv->vadjustment);
2589 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2592 g_signal_connect (adjustment, "value-changed",
2593 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2594 priv->vadjustment = g_object_ref_sink (adjustment);
2595 gtk_icon_view_set_vadjustment_values (icon_view);
2597 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2598 gtk_icon_view_accessible_set_adjustment (atk_obj,
2599 GTK_ORIENTATION_VERTICAL,
2602 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2606 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2607 GtkIconView *icon_view)
2609 GtkIconViewPrivate *priv = icon_view->priv;
2611 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2613 gdk_window_move (priv->bin_window,
2614 - gtk_adjustment_get_value (priv->hadjustment),
2615 - gtk_adjustment_get_value (priv->vadjustment));
2617 if (icon_view->priv->doing_rubberband)
2618 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2620 gtk_icon_view_process_updates (icon_view);
2625 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2630 gint *maximum_width)
2632 GtkAllocation allocation;
2633 GtkCellAreaContext *context;
2634 GtkIconViewPrivate *priv = icon_view->priv;
2635 GtkWidget *widget = GTK_WIDGET (icon_view);
2636 gint x, current_width;
2637 GList *items, *last_item;
2639 gint max_height = 0;
2642 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2650 current_width += 2 * priv->margin;
2652 gtk_widget_get_allocation (widget, &allocation);
2654 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2655 g_ptr_array_add (priv->row_contexts, context);
2657 /* In the first loop we iterate horizontally until we hit allocation width
2658 * and collect the aligned height-for-width */
2662 GtkIconViewItem *item = items->data;
2663 GdkRectangle *item_area = (GdkRectangle *)item;
2665 item_area->width = item_width;
2667 current_width += item_area->width + icon_view->priv->item_padding * 2;
2669 if (items != first_item)
2671 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2672 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2676 /* Get this item's particular width & height (all alignments are cached by now) */
2677 gtk_icon_view_set_cell_data (icon_view, item);
2678 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2683 current_width += icon_view->priv->column_spacing;
2685 item_area->y = *y + icon_view->priv->item_padding;
2686 item_area->x = x + icon_view->priv->item_padding;
2688 x = current_width - icon_view->priv->margin;
2690 if (current_width > *maximum_width)
2691 *maximum_width = current_width;
2697 items = items->next;
2702 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2703 gtk_cell_area_context_allocate (context, item_width, max_height);
2705 /* In the second loop the item height has been aligned and derived and
2706 * we just set the height and handle rtl layout */
2707 for (items = first_item; items != last_item; items = items->next)
2709 GtkIconViewItem *item = items->data;
2710 GdkRectangle *item_area = (GdkRectangle *)item;
2714 item_area->x = *maximum_width - item_area->width - item_area->x;
2715 item->col = col - 1 - item->col;
2718 /* All items in the same row get the same height */
2719 item_area->height = max_height;
2722 /* Adjust the new y coordinate. */
2723 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2729 adjust_wrap_width (GtkIconView *icon_view)
2731 if (icon_view->priv->text_cell)
2733 gint wrap_width = 50;
2735 /* Here we go with the same old guess, try the icon size and set double
2736 * the size of the first icon found in the list, naive but works much
2738 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2740 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2741 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2742 GTK_WIDGET (icon_view),
2745 wrap_width = MAX (wrap_width * 2, 50);
2748 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2749 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2754 gtk_icon_view_layout (GtkIconView *icon_view)
2756 GtkAllocation allocation;
2759 gint y = 0, maximum_width = 0;
2762 gboolean size_changed = FALSE;
2764 if (icon_view->priv->layout_idle_id != 0)
2766 g_source_remove (icon_view->priv->layout_idle_id);
2767 icon_view->priv->layout_idle_id = 0;
2770 if (icon_view->priv->model == NULL)
2773 widget = GTK_WIDGET (icon_view);
2775 item_width = icon_view->priv->item_width;
2777 /* Update the wrap width for the text cell before going and requesting sizes */
2778 adjust_wrap_width (icon_view);
2780 /* Update the context widths for any invalidated items */
2781 gtk_icon_view_cache_widths (icon_view);
2783 /* Fetch the new item width if needed */
2785 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2788 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2790 icons = icon_view->priv->items;
2791 y += icon_view->priv->margin;
2794 /* Clear the per row contexts */
2795 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2799 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2801 &y, &maximum_width);
2804 while (icons != NULL);
2806 if (maximum_width != icon_view->priv->width)
2808 icon_view->priv->width = maximum_width;
2809 size_changed = TRUE;
2812 y += icon_view->priv->margin;
2814 if (y != icon_view->priv->height)
2816 icon_view->priv->height = y;
2817 size_changed = TRUE;
2820 gtk_icon_view_set_hadjustment_values (icon_view);
2821 gtk_icon_view_set_vadjustment_values (icon_view);
2824 gtk_widget_queue_resize_no_redraw (widget);
2826 gtk_widget_get_allocation (widget, &allocation);
2827 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2828 gdk_window_resize (icon_view->priv->bin_window,
2829 MAX (icon_view->priv->width, allocation.width),
2830 MAX (icon_view->priv->height, allocation.height));
2832 if (icon_view->priv->scroll_to_path)
2836 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2837 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2838 icon_view->priv->scroll_to_path = NULL;
2840 gtk_icon_view_scroll_to_path (icon_view, path,
2841 icon_view->priv->scroll_to_use_align,
2842 icon_view->priv->scroll_to_row_align,
2843 icon_view->priv->scroll_to_col_align);
2844 gtk_tree_path_free (path);
2847 gtk_widget_queue_draw (widget);
2850 /* This ensures that all widths have been cached in the
2851 * context and we have proper alignments to go on.
2854 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2858 g_signal_handler_block (icon_view->priv->cell_area_context,
2859 icon_view->priv->context_changed_id);
2861 for (items = icon_view->priv->items; items; items = items->next)
2863 GtkIconViewItem *item = items->data;
2865 /* Only fetch the width of items with invalidated sizes */
2866 if (item->cell_area.width < 0)
2868 gtk_icon_view_set_cell_data (icon_view, item);
2869 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2870 icon_view->priv->cell_area_context,
2871 GTK_WIDGET (icon_view), NULL, NULL);
2875 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2876 icon_view->priv->context_changed_id);
2880 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2882 /* Clear all item sizes */
2883 g_list_foreach (icon_view->priv->items,
2884 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2886 /* Reset the context */
2887 g_signal_handler_block (icon_view->priv->cell_area_context,
2888 icon_view->priv->context_changed_id);
2889 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2890 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2891 icon_view->priv->context_changed_id);
2893 /* Re-layout the items */
2894 gtk_icon_view_queue_layout (icon_view);
2898 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2900 item->cell_area.width = -1;
2901 item->cell_area.height = -1;
2905 gtk_icon_view_paint_item (GtkIconView *icon_view,
2907 GtkIconViewItem *item,
2910 gboolean draw_focus)
2912 GdkRectangle cell_area;
2913 GtkStateFlags state = 0;
2914 GtkCellRendererState flags = 0;
2915 GtkStyleContext *style_context;
2916 GtkWidget *widget = GTK_WIDGET (icon_view);
2917 GtkIconViewPrivate *priv = icon_view->priv;
2918 GtkCellAreaContext *context;
2920 if (priv->model == NULL)
2923 gtk_icon_view_set_cell_data (icon_view, item);
2925 style_context = gtk_widget_get_style_context (widget);
2927 gtk_style_context_save (style_context);
2928 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2929 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2933 if (gtk_widget_has_focus (widget) &&
2934 item == icon_view->priv->cursor_item)
2936 state |= GTK_STATE_FLAG_FOCUSED;
2937 flags |= GTK_CELL_RENDERER_FOCUSED;
2940 state |= GTK_STATE_FLAG_SELECTED;
2941 flags |= GTK_CELL_RENDERER_SELECTED;
2943 gtk_style_context_set_state (style_context, state);
2944 gtk_render_background (style_context, cr,
2945 x - icon_view->priv->item_padding,
2946 y - icon_view->priv->item_padding,
2947 item->cell_area.width + icon_view->priv->item_padding * 2,
2948 item->cell_area.height + icon_view->priv->item_padding * 2);
2953 cell_area.width = item->cell_area.width;
2954 cell_area.height = item->cell_area.height;
2956 context = g_ptr_array_index (priv->row_contexts, item->row);
2957 gtk_cell_area_render (priv->cell_area, context,
2958 widget, cr, &cell_area, &cell_area, flags,
2961 gtk_style_context_restore (style_context);
2965 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2968 GtkStyleContext *context;
2973 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2974 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2975 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2976 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2978 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2980 gtk_style_context_save (context);
2981 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2983 gdk_cairo_rectangle (cr, &rect);
2986 gtk_render_background (context, cr,
2988 rect.width, rect.height);
2989 gtk_render_frame (context, cr,
2991 rect.width, rect.height);
2993 gtk_style_context_restore (context);
2998 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3004 index = gtk_tree_path_get_indices (path)[0];
3006 for (l = icon_view->priv->items; l; l = l->next)
3008 GtkIconViewItem *item = l->data;
3010 if (item->index == index)
3012 gtk_icon_view_queue_draw_item (icon_view, item);
3019 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3020 GtkIconViewItem *item)
3023 GdkRectangle *item_area = (GdkRectangle *)item;
3025 rect.x = item_area->x - icon_view->priv->item_padding;
3026 rect.y = item_area->y - icon_view->priv->item_padding;
3027 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3028 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3030 if (icon_view->priv->bin_window)
3031 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3035 layout_callback (gpointer user_data)
3037 GtkIconView *icon_view;
3039 icon_view = GTK_ICON_VIEW (user_data);
3041 icon_view->priv->layout_idle_id = 0;
3043 gtk_icon_view_layout (icon_view);
3049 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3051 if (icon_view->priv->layout_idle_id != 0)
3054 icon_view->priv->layout_idle_id =
3055 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3056 layout_callback, icon_view, NULL);
3060 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3061 GtkIconViewItem *item,
3062 GtkCellRenderer *cursor_cell)
3065 AtkObject *item_obj;
3066 AtkObject *cursor_item_obj;
3068 /* When hitting this path from keynav, the focus cell is
3069 * already set, we dont need to notify the atk object
3070 * but we still need to queue the draw here (in the case
3071 * that the focus cell changes but not the cursor item).
3073 gtk_icon_view_queue_draw_item (icon_view, item);
3075 if (icon_view->priv->cursor_item == item &&
3076 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3079 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3080 if (icon_view->priv->cursor_item != NULL)
3082 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3085 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3086 if (cursor_item_obj != NULL)
3087 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3090 icon_view->priv->cursor_item = item;
3093 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3096 /* Make sure there is a cell in focus initially */
3097 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3098 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3101 /* Notify that accessible focus object has changed */
3102 item_obj = atk_object_ref_accessible_child (obj, item->index);
3104 if (item_obj != NULL)
3106 atk_focus_tracker_notify (item_obj);
3107 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3108 g_object_unref (item_obj);
3113 static GtkIconViewItem *
3114 gtk_icon_view_item_new (void)
3116 GtkIconViewItem *item;
3118 item = g_slice_new0 (GtkIconViewItem);
3120 item->cell_area.width = -1;
3121 item->cell_area.height = -1;
3127 gtk_icon_view_item_free (GtkIconViewItem *item)
3129 g_return_if_fail (item != NULL);
3131 g_slice_free (GtkIconViewItem, item);
3134 static GtkIconViewItem *
3135 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3138 gboolean only_in_cell,
3139 GtkCellRenderer **cell_at_pos)
3144 *cell_at_pos = NULL;
3146 for (items = icon_view->priv->items; items; items = items->next)
3148 GtkIconViewItem *item = items->data;
3149 GdkRectangle *item_area = (GdkRectangle *)item;
3151 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3152 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3153 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3154 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3156 if (only_in_cell || cell_at_pos)
3158 GtkCellRenderer *cell = NULL;
3159 GtkCellAreaContext *context;
3161 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3162 gtk_icon_view_set_cell_data (icon_view, item);
3164 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3165 y >= item_area->y && y <= item_area->y + item_area->height)
3166 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3167 GTK_WIDGET (icon_view),
3172 *cell_at_pos = cell;
3175 return cell != NULL ? item : NULL;
3186 gtk_icon_view_select_item (GtkIconView *icon_view,
3187 GtkIconViewItem *item)
3189 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3190 g_return_if_fail (item != NULL);
3195 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3197 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3198 gtk_icon_view_unselect_all_internal (icon_view);
3200 item->selected = TRUE;
3202 gtk_icon_view_item_selected_changed (icon_view, item);
3203 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3205 gtk_icon_view_queue_draw_item (icon_view, item);
3210 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3211 GtkIconViewItem *item)
3213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3214 g_return_if_fail (item != NULL);
3216 if (!item->selected)
3219 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3220 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3223 item->selected = FALSE;
3225 gtk_icon_view_item_selected_changed (icon_view, item);
3226 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3228 gtk_icon_view_queue_draw_item (icon_view, item);
3232 verify_items (GtkIconView *icon_view)
3237 for (items = icon_view->priv->items; items; items = items->next)
3239 GtkIconViewItem *item = items->data;
3241 if (item->index != i)
3242 g_error ("List item does not match its index: "
3243 "item index %d and list index %d\n", item->index, i);
3250 gtk_icon_view_row_changed (GtkTreeModel *model,
3255 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3257 /* ignore changes in branches */
3258 if (gtk_tree_path_get_depth (path) > 1)
3261 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3263 /* Here we can use a "grow-only" strategy for optimization
3264 * and only invalidate a single item and queue a relayout
3265 * instead of invalidating the whole thing.
3267 * For now GtkIconView still cant deal with huge models
3268 * so just invalidate the whole thing when the model
3271 gtk_icon_view_invalidate_sizes (icon_view);
3273 verify_items (icon_view);
3277 gtk_icon_view_row_inserted (GtkTreeModel *model,
3282 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3284 GtkIconViewItem *item;
3285 gboolean iters_persist;
3288 /* ignore changes in branches */
3289 if (gtk_tree_path_get_depth (path) > 1)
3292 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3294 index = gtk_tree_path_get_indices(path)[0];
3296 item = gtk_icon_view_item_new ();
3301 item->index = index;
3303 /* FIXME: We can be more efficient here,
3304 we can store a tail pointer and use that when
3305 appending (which is a rather common operation)
3307 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3310 list = g_list_nth (icon_view->priv->items, index + 1);
3311 for (; list; list = list->next)
3318 verify_items (icon_view);
3320 gtk_icon_view_queue_layout (icon_view);
3324 gtk_icon_view_row_deleted (GtkTreeModel *model,
3328 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3330 GtkIconViewItem *item;
3332 gboolean emit = FALSE;
3334 /* ignore changes in branches */
3335 if (gtk_tree_path_get_depth (path) > 1)
3338 index = gtk_tree_path_get_indices(path)[0];
3340 list = g_list_nth (icon_view->priv->items, index);
3343 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3345 if (item == icon_view->priv->anchor_item)
3346 icon_view->priv->anchor_item = NULL;
3348 if (item == icon_view->priv->cursor_item)
3349 icon_view->priv->cursor_item = NULL;
3354 gtk_icon_view_item_free (item);
3356 for (next = list->next; next; next = next->next)
3363 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3365 verify_items (icon_view);
3367 gtk_icon_view_queue_layout (icon_view);
3370 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3374 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3375 GtkTreePath *parent,
3380 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3383 GList *items = NULL, *list;
3384 GtkIconViewItem **item_array;
3387 /* ignore changes in branches */
3391 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3393 length = gtk_tree_model_iter_n_children (model, NULL);
3395 order = g_new (gint, length);
3396 for (i = 0; i < length; i++)
3397 order [new_order[i]] = i;
3399 item_array = g_new (GtkIconViewItem *, length);
3400 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3401 item_array[order[i]] = list->data;
3404 for (i = length - 1; i >= 0; i--)
3406 item_array[i]->index = i;
3407 items = g_list_prepend (items, item_array[i]);
3410 g_free (item_array);
3411 g_list_free (icon_view->priv->items);
3412 icon_view->priv->items = items;
3414 gtk_icon_view_queue_layout (icon_view);
3416 verify_items (icon_view);
3420 gtk_icon_view_build_items (GtkIconView *icon_view)
3424 gboolean iters_persist;
3425 GList *items = NULL;
3427 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3429 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3437 GtkIconViewItem *item = gtk_icon_view_item_new ();
3446 items = g_list_prepend (items, item);
3448 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3450 icon_view->priv->items = g_list_reverse (items);
3454 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3457 GtkMovementStep step,
3461 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3462 I_("move-cursor"), 2,
3466 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3471 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3474 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3479 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3486 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3487 GtkMovementStep step,
3490 GdkModifierType state;
3492 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3493 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3494 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3495 step == GTK_MOVEMENT_DISPLAY_LINES ||
3496 step == GTK_MOVEMENT_PAGES ||
3497 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3499 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3502 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3503 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3505 if (gtk_get_current_event_state (&state))
3507 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3508 icon_view->priv->ctrl_pressed = TRUE;
3509 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3510 icon_view->priv->shift_pressed = TRUE;
3512 /* else we assume not pressed */
3516 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3517 case GTK_MOVEMENT_VISUAL_POSITIONS:
3518 gtk_icon_view_move_cursor_left_right (icon_view, count);
3520 case GTK_MOVEMENT_DISPLAY_LINES:
3521 gtk_icon_view_move_cursor_up_down (icon_view, count);
3523 case GTK_MOVEMENT_PAGES:
3524 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3526 case GTK_MOVEMENT_BUFFER_ENDS:
3527 gtk_icon_view_move_cursor_start_end (icon_view, count);
3530 g_assert_not_reached ();
3533 icon_view->priv->ctrl_pressed = FALSE;
3534 icon_view->priv->shift_pressed = FALSE;
3536 icon_view->priv->draw_focus = TRUE;
3541 static GtkIconViewItem *
3542 find_item (GtkIconView *icon_view,
3543 GtkIconViewItem *current,
3549 GtkIconViewItem *item;
3551 /* FIXME: this could be more efficient
3553 row = current->row + row_ofs;
3554 col = current->col + col_ofs;
3556 for (items = icon_view->priv->items; items; items = items->next)
3559 if (item->row == row && item->col == col)
3566 static GtkIconViewItem *
3567 find_item_page_up_down (GtkIconView *icon_view,
3568 GtkIconViewItem *current,
3575 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3577 item = g_list_find (icon_view->priv->items, current);
3582 for (next = item->next; next; next = next->next)
3584 if (((GtkIconViewItem *)next->data)->col == col)
3587 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3597 for (next = item->prev; next; next = next->prev)
3599 if (((GtkIconViewItem *)next->data)->col == col)
3602 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3616 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3617 GtkIconViewItem *anchor,
3618 GtkIconViewItem *cursor)
3621 GtkIconViewItem *item;
3622 gint row1, row2, col1, col2;
3623 gboolean dirty = FALSE;
3625 if (anchor->row < cursor->row)
3636 if (anchor->col < cursor->col)
3647 for (items = icon_view->priv->items; items; items = items->next)
3651 if (row1 <= item->row && item->row <= row2 &&
3652 col1 <= item->col && item->col <= col2)
3654 if (!item->selected)
3657 item->selected = TRUE;
3658 gtk_icon_view_item_selected_changed (icon_view, item);
3660 gtk_icon_view_queue_draw_item (icon_view, item);
3668 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3671 GtkIconViewItem *item;
3672 GtkCellRenderer *cell;
3673 gboolean dirty = FALSE;
3675 GtkDirectionType direction;
3677 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3680 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3682 if (!icon_view->priv->cursor_item)
3687 list = icon_view->priv->items;
3689 list = g_list_last (icon_view->priv->items);
3691 item = list ? list->data : NULL;
3693 /* Give focus to the first cell initially */
3694 gtk_icon_view_set_cell_data (icon_view, item);
3695 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3699 item = icon_view->priv->cursor_item;
3700 step = count > 0 ? 1 : -1;
3702 /* Save the current focus cell in case we hit the edge */
3703 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3707 gtk_icon_view_set_cell_data (icon_view, item);
3709 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3712 item = find_item (icon_view, item, step, 0);
3718 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3720 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3722 gtk_widget_child_focus (toplevel,
3723 direction == GTK_DIR_UP ?
3724 GTK_DIR_TAB_BACKWARD :
3725 GTK_DIR_TAB_FORWARD);
3729 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3733 if (icon_view->priv->ctrl_pressed ||
3734 !icon_view->priv->shift_pressed ||
3735 !icon_view->priv->anchor_item ||
3736 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3737 icon_view->priv->anchor_item = item;
3739 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3740 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3742 if (!icon_view->priv->ctrl_pressed &&
3743 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3745 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3746 dirty = gtk_icon_view_select_all_between (icon_view,
3747 icon_view->priv->anchor_item,
3751 gtk_icon_view_scroll_to_item (icon_view, item);
3754 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3758 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3761 GtkIconViewItem *item;
3762 gboolean dirty = FALSE;
3764 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3767 if (!icon_view->priv->cursor_item)
3772 list = icon_view->priv->items;
3774 list = g_list_last (icon_view->priv->items);
3776 item = list ? list->data : NULL;
3779 item = find_item_page_up_down (icon_view,
3780 icon_view->priv->cursor_item,
3783 if (item == icon_view->priv->cursor_item)
3784 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3789 if (icon_view->priv->ctrl_pressed ||
3790 !icon_view->priv->shift_pressed ||
3791 !icon_view->priv->anchor_item ||
3792 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3793 icon_view->priv->anchor_item = item;
3795 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3797 if (!icon_view->priv->ctrl_pressed &&
3798 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3800 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3801 dirty = gtk_icon_view_select_all_between (icon_view,
3802 icon_view->priv->anchor_item,
3806 gtk_icon_view_scroll_to_item (icon_view, item);
3809 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3813 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3816 GtkIconViewItem *item;
3817 GtkCellRenderer *cell = NULL;
3818 gboolean dirty = FALSE;
3820 GtkDirectionType direction;
3822 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3825 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3827 if (!icon_view->priv->cursor_item)
3832 list = icon_view->priv->items;
3834 list = g_list_last (icon_view->priv->items);
3836 item = list ? list->data : NULL;
3838 /* Give focus to the first cell initially */
3839 gtk_icon_view_set_cell_data (icon_view, item);
3840 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3844 item = icon_view->priv->cursor_item;
3845 step = count > 0 ? 1 : -1;
3847 /* Save the current focus cell in case we hit the edge */
3848 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3852 gtk_icon_view_set_cell_data (icon_view, item);
3854 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3857 item = find_item (icon_view, item, 0, step);
3863 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3865 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3867 gtk_widget_child_focus (toplevel,
3868 direction == GTK_DIR_LEFT ?
3869 GTK_DIR_TAB_BACKWARD :
3870 GTK_DIR_TAB_FORWARD);
3874 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3878 if (icon_view->priv->ctrl_pressed ||
3879 !icon_view->priv->shift_pressed ||
3880 !icon_view->priv->anchor_item ||
3881 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3882 icon_view->priv->anchor_item = item;
3884 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3885 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3887 if (!icon_view->priv->ctrl_pressed &&
3888 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3890 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3891 dirty = gtk_icon_view_select_all_between (icon_view,
3892 icon_view->priv->anchor_item,
3896 gtk_icon_view_scroll_to_item (icon_view, item);
3899 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3903 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3906 GtkIconViewItem *item;
3908 gboolean dirty = FALSE;
3910 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3914 list = icon_view->priv->items;
3916 list = g_list_last (icon_view->priv->items);
3918 item = list ? list->data : NULL;
3920 if (item == icon_view->priv->cursor_item)
3921 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3926 if (icon_view->priv->ctrl_pressed ||
3927 !icon_view->priv->shift_pressed ||
3928 !icon_view->priv->anchor_item ||
3929 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3930 icon_view->priv->anchor_item = item;
3932 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3934 if (!icon_view->priv->ctrl_pressed &&
3935 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3937 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3938 dirty = gtk_icon_view_select_all_between (icon_view,
3939 icon_view->priv->anchor_item,
3943 gtk_icon_view_scroll_to_item (icon_view, item);
3946 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3950 * gtk_icon_view_scroll_to_path:
3951 * @icon_view: A #GtkIconView.
3952 * @path: The path of the item to move to.
3953 * @use_align: whether to use alignment arguments, or %FALSE.
3954 * @row_align: The vertical alignment of the item specified by @path.
3955 * @col_align: The horizontal alignment of the item specified by @path.
3957 * Moves the alignments of @icon_view to the position specified by @path.
3958 * @row_align determines where the row is placed, and @col_align determines
3959 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3960 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3963 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3964 * tree does the minimum amount of work to scroll the item onto the screen.
3965 * This means that the item will be scrolled to the edge closest to its current
3966 * position. If the item is currently visible on the screen, nothing is done.
3968 * This function only works if the model is set, and @path is a valid row on
3969 * the model. If the model changes before the @icon_view is realized, the
3970 * centered path will be modified to reflect this change.
3975 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3981 GtkIconViewItem *item = NULL;
3984 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3985 g_return_if_fail (path != NULL);
3986 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3987 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3989 widget = GTK_WIDGET (icon_view);
3991 if (gtk_tree_path_get_depth (path) > 0)
3992 item = g_list_nth_data (icon_view->priv->items,
3993 gtk_tree_path_get_indices(path)[0]);
3995 if (!item || item->cell_area.width < 0 ||
3996 !gtk_widget_get_realized (widget))
3998 if (icon_view->priv->scroll_to_path)
3999 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4001 icon_view->priv->scroll_to_path = NULL;
4004 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4006 icon_view->priv->scroll_to_use_align = use_align;
4007 icon_view->priv->scroll_to_row_align = row_align;
4008 icon_view->priv->scroll_to_col_align = col_align;
4015 GtkAllocation allocation;
4018 GdkRectangle item_area =
4020 item->cell_area.x - icon_view->priv->item_padding,
4021 item->cell_area.y - icon_view->priv->item_padding,
4022 item->cell_area.width + icon_view->priv->item_padding * 2,
4023 item->cell_area.height + icon_view->priv->item_padding * 2
4026 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4028 gtk_widget_get_allocation (widget, &allocation);
4030 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4032 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4033 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4035 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4037 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4038 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4040 gtk_adjustment_changed (icon_view->priv->hadjustment);
4041 gtk_adjustment_changed (icon_view->priv->vadjustment);
4044 gtk_icon_view_scroll_to_item (icon_view, item);
4049 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4050 GtkIconViewItem *item)
4052 GtkIconViewPrivate *priv = icon_view->priv;
4053 GtkWidget *widget = GTK_WIDGET (icon_view);
4054 GtkAdjustment *hadj, *vadj;
4055 GtkAllocation allocation;
4057 GdkRectangle item_area;
4059 item_area.x = item->cell_area.x - priv->item_padding;
4060 item_area.y = item->cell_area.y - priv->item_padding;
4061 item_area.width = item->cell_area.width + priv->item_padding * 2;
4062 item_area.height = item->cell_area.height + priv->item_padding * 2;
4064 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4065 gtk_widget_get_allocation (widget, &allocation);
4067 hadj = icon_view->priv->hadjustment;
4068 vadj = icon_view->priv->vadjustment;
4070 if (y + item_area.y < 0)
4071 gtk_adjustment_set_value (vadj,
4072 gtk_adjustment_get_value (vadj)
4074 else if (y + item_area.y + item_area.height > allocation.height)
4075 gtk_adjustment_set_value (vadj,
4076 gtk_adjustment_get_value (vadj)
4077 + y + item_area.y + item_area.height - allocation.height);
4079 if (x + item_area.x < 0)
4080 gtk_adjustment_set_value (hadj,
4081 gtk_adjustment_get_value (hadj)
4083 else if (x + item_area.x + item_area.width > allocation.width)
4084 gtk_adjustment_set_value (hadj,
4085 gtk_adjustment_get_value (hadj)
4086 + x + item_area.x + item_area.width - allocation.width);
4088 gtk_adjustment_changed (hadj);
4089 gtk_adjustment_changed (vadj);
4092 /* GtkCellLayout implementation */
4095 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4096 GtkCellArea *cell_area)
4098 GtkIconViewPrivate *priv = icon_view->priv;
4100 if (priv->cell_area)
4104 priv->cell_area = cell_area;
4106 priv->cell_area = gtk_cell_area_box_new ();
4108 g_object_ref_sink (priv->cell_area);
4110 if (GTK_IS_ORIENTABLE (priv->cell_area))
4111 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4113 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4115 priv->add_editable_id =
4116 g_signal_connect (priv->cell_area, "add-editable",
4117 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4118 priv->remove_editable_id =
4119 g_signal_connect (priv->cell_area, "remove-editable",
4120 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4121 priv->context_changed_id =
4122 g_signal_connect (priv->cell_area_context, "notify",
4123 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4126 static GtkCellArea *
4127 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4129 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4130 GtkIconViewPrivate *priv = icon_view->priv;
4132 if (G_UNLIKELY (!priv->cell_area))
4133 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4135 return icon_view->priv->cell_area;
4139 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4140 GtkIconViewItem *item)
4142 gboolean iters_persist;
4145 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4151 path = gtk_tree_path_new_from_indices (item->index, -1);
4152 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4154 gtk_tree_path_free (path);
4159 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4160 icon_view->priv->model,
4161 &iter, FALSE, FALSE);
4170 * gtk_icon_view_new:
4172 * Creates a new #GtkIconView widget
4174 * Return value: A newly created #GtkIconView widget
4179 gtk_icon_view_new (void)
4181 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4185 * gtk_icon_view_new_with_area:
4186 * @area: the #GtkCellArea to use to layout cells
4188 * Creates a new #GtkIconView widget using the
4189 * specified @area to layout cells inside the icons.
4191 * Return value: A newly created #GtkIconView widget
4196 gtk_icon_view_new_with_area (GtkCellArea *area)
4198 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4202 * gtk_icon_view_new_with_model:
4203 * @model: The model.
4205 * Creates a new #GtkIconView widget with the model @model.
4207 * Return value: A newly created #GtkIconView widget.
4212 gtk_icon_view_new_with_model (GtkTreeModel *model)
4214 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4218 * gtk_icon_view_convert_widget_to_bin_window_coords:
4219 * @icon_view: a #GtkIconView
4220 * @wx: X coordinate relative to the widget
4221 * @wy: Y coordinate relative to the widget
4222 * @bx: (out): return location for bin_window X coordinate
4223 * @by: (out): return location for bin_window Y coordinate
4225 * Converts widget coordinates to coordinates for the bin_window,
4226 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4231 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4239 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4241 if (icon_view->priv->bin_window)
4242 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4253 * gtk_icon_view_get_path_at_pos:
4254 * @icon_view: A #GtkIconView.
4255 * @x: The x position to be identified
4256 * @y: The y position to be identified
4258 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4259 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4260 * the cell at the specified position.
4261 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4262 * widget coordinates to bin_window coordinates.
4264 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4265 * if no icon exists at that position.
4270 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4274 GtkIconViewItem *item;
4277 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4279 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4284 path = gtk_tree_path_new_from_indices (item->index, -1);
4290 * gtk_icon_view_get_item_at_pos:
4291 * @icon_view: A #GtkIconView.
4292 * @x: The x position to be identified
4293 * @y: The y position to be identified
4294 * @path: (out) (allow-none): Return location for the path, or %NULL
4295 * @cell: (out) (allow-none): Return location for the renderer
4296 * responsible for the cell at (@x, @y), or %NULL
4298 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4299 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4300 * obtains the cell at the specified position. The returned path should
4301 * be freed with gtk_tree_path_free().
4302 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4303 * widget coordinates to bin_window coordinates.
4305 * Return value: %TRUE if an item exists at the specified position
4310 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4314 GtkCellRenderer **cell)
4316 GtkIconViewItem *item;
4317 GtkCellRenderer *renderer = NULL;
4319 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4321 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4326 *path = gtk_tree_path_new_from_indices (item->index, -1);
4334 return (item != NULL);
4338 * gtk_icon_view_set_tooltip_item:
4339 * @icon_view: a #GtkIconView
4340 * @tooltip: a #GtkTooltip
4341 * @path: a #GtkTreePath
4343 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4344 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4345 * See also gtk_tooltip_set_tip_area().
4350 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4351 GtkTooltip *tooltip,
4354 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4355 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4357 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4361 * gtk_icon_view_set_tooltip_cell:
4362 * @icon_view: a #GtkIconView
4363 * @tooltip: a #GtkTooltip
4364 * @path: a #GtkTreePath
4365 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4367 * Sets the tip area of @tooltip to the area which @cell occupies in
4368 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4370 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4375 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4376 GtkTooltip *tooltip,
4378 GtkCellRenderer *cell)
4381 GtkIconViewItem *item = NULL;
4384 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4385 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4386 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4388 if (gtk_tree_path_get_depth (path) > 0)
4389 item = g_list_nth_data (icon_view->priv->items,
4390 gtk_tree_path_get_indices(path)[0]);
4397 GtkCellAreaContext *context;
4399 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4400 gtk_icon_view_set_cell_data (icon_view, item);
4401 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4402 GTK_WIDGET (icon_view),
4403 cell, (GdkRectangle *)item, &rect);
4407 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4408 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4409 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4410 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4413 if (icon_view->priv->bin_window)
4415 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4420 gtk_tooltip_set_tip_area (tooltip, &rect);
4425 * gtk_icon_view_get_tooltip_context:
4426 * @icon_view: an #GtkIconView
4427 * @x: (inout): the x coordinate (relative to widget coordinates)
4428 * @y: (inout): the y coordinate (relative to widget coordinates)
4429 * @keyboard_tip: whether this is a keyboard tooltip or not
4430 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4431 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4432 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4434 * This function is supposed to be used in a #GtkWidget::query-tooltip
4435 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4436 * which are received in the signal handler, should be passed to this
4437 * function without modification.
4439 * The return value indicates whether there is an icon view item at the given
4440 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4441 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4442 * @model, @path and @iter which have been provided will be set to point to
4443 * that row and the corresponding model. @x and @y will always be converted
4444 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4446 * Return value: whether or not the given tooltip context points to a item
4451 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4454 gboolean keyboard_tip,
4455 GtkTreeModel **model,
4459 GtkTreePath *tmppath = NULL;
4461 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4462 g_return_val_if_fail (x != NULL, FALSE);
4463 g_return_val_if_fail (y != NULL, FALSE);
4467 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4474 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4477 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4482 *model = gtk_icon_view_get_model (icon_view);
4485 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4491 gtk_tree_path_free (tmppath);
4497 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4500 gboolean keyboard_tip,
4501 GtkTooltip *tooltip,
4507 GtkTreeModel *model;
4508 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4510 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4513 &model, &path, &iter))
4516 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4520 gtk_tree_path_free (path);
4524 gtk_tooltip_set_markup (tooltip, str);
4525 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4527 gtk_tree_path_free (path);
4535 * gtk_icon_view_set_tooltip_column:
4536 * @icon_view: a #GtkIconView
4537 * @column: an integer, which is a valid column number for @icon_view's model
4539 * If you only plan to have simple (text-only) tooltips on full items, you
4540 * can use this function to have #GtkIconView handle these automatically
4541 * for you. @column should be set to the column in @icon_view's model
4542 * containing the tooltip texts, or -1 to disable this feature.
4544 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4545 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4547 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4548 * so &, <, etc have to be escaped in the text.
4553 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4556 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4558 if (column == icon_view->priv->tooltip_column)
4563 g_signal_handlers_disconnect_by_func (icon_view,
4564 gtk_icon_view_set_tooltip_query_cb,
4566 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4570 if (icon_view->priv->tooltip_column == -1)
4572 g_signal_connect (icon_view, "query-tooltip",
4573 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4574 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4578 icon_view->priv->tooltip_column = column;
4579 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4583 * gtk_icon_view_get_tooltip_column:
4584 * @icon_view: a #GtkIconView
4586 * Returns the column of @icon_view's model which is being used for
4587 * displaying tooltips on @icon_view's rows.
4589 * Return value: the index of the tooltip column that is currently being
4590 * used, or -1 if this is disabled.
4595 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4597 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4599 return icon_view->priv->tooltip_column;
4603 * gtk_icon_view_get_visible_range:
4604 * @icon_view: A #GtkIconView
4605 * @start_path: (out) (allow-none): Return location for start of region,
4607 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4609 * Sets @start_path and @end_path to be the first and last visible path.
4610 * Note that there may be invisible paths in between.
4612 * Both paths should be freed with gtk_tree_path_free() after use.
4614 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4619 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4620 GtkTreePath **start_path,
4621 GtkTreePath **end_path)
4623 gint start_index = -1;
4624 gint end_index = -1;
4627 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4629 if (icon_view->priv->hadjustment == NULL ||
4630 icon_view->priv->vadjustment == NULL)
4633 if (start_path == NULL && end_path == NULL)
4636 for (icons = icon_view->priv->items; icons; icons = icons->next)
4638 GtkIconViewItem *item = icons->data;
4639 GdkRectangle *item_area = (GdkRectangle *)item;
4641 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4642 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4644 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4645 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4647 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4648 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4650 if (start_index == -1)
4651 start_index = item->index;
4652 end_index = item->index;
4656 if (start_path && start_index != -1)
4657 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4658 if (end_path && end_index != -1)
4659 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4661 return start_index != -1;
4665 * gtk_icon_view_selected_foreach:
4666 * @icon_view: A #GtkIconView.
4667 * @func: (scope call): The function to call for each selected icon.
4668 * @data: User data to pass to the function.
4670 * Calls a function for each selected icon. Note that the model or
4671 * selection cannot be modified from within this function.
4676 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4677 GtkIconViewForeachFunc func,
4682 for (list = icon_view->priv->items; list; list = list->next)
4684 GtkIconViewItem *item = list->data;
4685 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4688 (* func) (icon_view, path, data);
4690 gtk_tree_path_free (path);
4695 * gtk_icon_view_set_selection_mode:
4696 * @icon_view: A #GtkIconView.
4697 * @mode: The selection mode
4699 * Sets the selection mode of the @icon_view.
4704 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4705 GtkSelectionMode mode)
4707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4709 if (mode == icon_view->priv->selection_mode)
4712 if (mode == GTK_SELECTION_NONE ||
4713 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4714 gtk_icon_view_unselect_all (icon_view);
4716 icon_view->priv->selection_mode = mode;
4718 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4722 * gtk_icon_view_get_selection_mode:
4723 * @icon_view: A #GtkIconView.
4725 * Gets the selection mode of the @icon_view.
4727 * Return value: the current selection mode
4732 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4734 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4736 return icon_view->priv->selection_mode;
4740 * gtk_icon_view_set_model:
4741 * @icon_view: A #GtkIconView.
4742 * @model: (allow-none): The model.
4744 * Sets the model for a #GtkIconView.
4745 * If the @icon_view already has a model set, it will remove
4746 * it before setting the new model. If @model is %NULL, then
4747 * it will unset the old model.
4752 gtk_icon_view_set_model (GtkIconView *icon_view,
4753 GtkTreeModel *model)
4755 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4756 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4758 if (icon_view->priv->model == model)
4761 if (icon_view->priv->scroll_to_path)
4763 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4764 icon_view->priv->scroll_to_path = NULL;
4767 /* The area can be NULL while disposing */
4768 if (icon_view->priv->cell_area)
4769 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4775 if (icon_view->priv->pixbuf_column != -1)
4777 column_type = gtk_tree_model_get_column_type (model,
4778 icon_view->priv->pixbuf_column);
4780 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4783 if (icon_view->priv->text_column != -1)
4785 column_type = gtk_tree_model_get_column_type (model,
4786 icon_view->priv->text_column);
4788 g_return_if_fail (column_type == G_TYPE_STRING);
4791 if (icon_view->priv->markup_column != -1)
4793 column_type = gtk_tree_model_get_column_type (model,
4794 icon_view->priv->markup_column);
4796 g_return_if_fail (column_type == G_TYPE_STRING);
4801 if (icon_view->priv->model)
4803 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4804 gtk_icon_view_row_changed,
4806 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4807 gtk_icon_view_row_inserted,
4809 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4810 gtk_icon_view_row_deleted,
4812 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4813 gtk_icon_view_rows_reordered,
4816 g_object_unref (icon_view->priv->model);
4818 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4819 g_list_free (icon_view->priv->items);
4820 icon_view->priv->items = NULL;
4821 icon_view->priv->anchor_item = NULL;
4822 icon_view->priv->cursor_item = NULL;
4823 icon_view->priv->last_single_clicked = NULL;
4824 icon_view->priv->width = 0;
4825 icon_view->priv->height = 0;
4828 icon_view->priv->model = model;
4830 if (icon_view->priv->model)
4832 g_object_ref (icon_view->priv->model);
4833 g_signal_connect (icon_view->priv->model,
4835 G_CALLBACK (gtk_icon_view_row_changed),
4837 g_signal_connect (icon_view->priv->model,
4839 G_CALLBACK (gtk_icon_view_row_inserted),
4841 g_signal_connect (icon_view->priv->model,
4843 G_CALLBACK (gtk_icon_view_row_deleted),
4845 g_signal_connect (icon_view->priv->model,
4847 G_CALLBACK (gtk_icon_view_rows_reordered),
4850 gtk_icon_view_build_items (icon_view);
4852 gtk_icon_view_queue_layout (icon_view);
4855 g_object_notify (G_OBJECT (icon_view), "model");
4857 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4858 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4862 * gtk_icon_view_get_model:
4863 * @icon_view: a #GtkIconView
4865 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4868 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4869 * currently being used.
4874 gtk_icon_view_get_model (GtkIconView *icon_view)
4876 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4878 return icon_view->priv->model;
4882 update_text_cell (GtkIconView *icon_view)
4884 if (icon_view->priv->text_column == -1 &&
4885 icon_view->priv->markup_column == -1)
4887 if (icon_view->priv->text_cell != NULL)
4889 gtk_cell_area_remove (icon_view->priv->cell_area,
4890 icon_view->priv->text_cell);
4891 icon_view->priv->text_cell = NULL;
4896 if (icon_view->priv->text_cell == NULL)
4898 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4900 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4903 if (icon_view->priv->markup_column != -1)
4904 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4905 icon_view->priv->text_cell,
4906 "markup", icon_view->priv->markup_column,
4909 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4910 icon_view->priv->text_cell,
4911 "text", icon_view->priv->text_column,
4914 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4915 g_object_set (icon_view->priv->text_cell,
4916 "alignment", PANGO_ALIGN_CENTER,
4917 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4922 g_object_set (icon_view->priv->text_cell,
4923 "alignment", PANGO_ALIGN_LEFT,
4924 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4932 update_pixbuf_cell (GtkIconView *icon_view)
4934 if (icon_view->priv->pixbuf_column == -1)
4936 if (icon_view->priv->pixbuf_cell != NULL)
4938 gtk_cell_area_remove (icon_view->priv->cell_area,
4939 icon_view->priv->pixbuf_cell);
4941 icon_view->priv->pixbuf_cell = NULL;
4946 if (icon_view->priv->pixbuf_cell == NULL)
4948 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4950 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4953 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4954 icon_view->priv->pixbuf_cell,
4955 "pixbuf", icon_view->priv->pixbuf_column,
4958 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4959 g_object_set (icon_view->priv->pixbuf_cell,
4964 g_object_set (icon_view->priv->pixbuf_cell,
4972 * gtk_icon_view_set_text_column:
4973 * @icon_view: A #GtkIconView.
4974 * @column: A column in the currently used model, or -1 to display no text
4976 * Sets the column with text for @icon_view to be @column. The text
4977 * column must be of type #G_TYPE_STRING.
4982 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4985 if (column == icon_view->priv->text_column)
4989 icon_view->priv->text_column = -1;
4992 if (icon_view->priv->model != NULL)
4996 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4998 g_return_if_fail (column_type == G_TYPE_STRING);
5001 icon_view->priv->text_column = column;
5005 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5007 update_text_cell (icon_view);
5009 gtk_icon_view_invalidate_sizes (icon_view);
5011 g_object_notify (G_OBJECT (icon_view), "text-column");
5015 * gtk_icon_view_get_text_column:
5016 * @icon_view: A #GtkIconView.
5018 * Returns the column with text for @icon_view.
5020 * Returns: the text column, or -1 if it's unset.
5025 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5027 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5029 return icon_view->priv->text_column;
5033 * gtk_icon_view_set_markup_column:
5034 * @icon_view: A #GtkIconView.
5035 * @column: A column in the currently used model, or -1 to display no text
5037 * Sets the column with markup information for @icon_view to be
5038 * @column. The markup column must be of type #G_TYPE_STRING.
5039 * If the markup column is set to something, it overrides
5040 * the text column set by gtk_icon_view_set_text_column().
5045 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5048 if (column == icon_view->priv->markup_column)
5052 icon_view->priv->markup_column = -1;
5055 if (icon_view->priv->model != NULL)
5059 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5061 g_return_if_fail (column_type == G_TYPE_STRING);
5064 icon_view->priv->markup_column = column;
5067 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5069 update_text_cell (icon_view);
5071 gtk_icon_view_invalidate_sizes (icon_view);
5073 g_object_notify (G_OBJECT (icon_view), "markup-column");
5077 * gtk_icon_view_get_markup_column:
5078 * @icon_view: A #GtkIconView.
5080 * Returns the column with markup text for @icon_view.
5082 * Returns: the markup column, or -1 if it's unset.
5087 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5089 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5091 return icon_view->priv->markup_column;
5095 * gtk_icon_view_set_pixbuf_column:
5096 * @icon_view: A #GtkIconView.
5097 * @column: A column in the currently used model, or -1 to disable
5099 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5100 * column must be of type #GDK_TYPE_PIXBUF
5105 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5108 if (column == icon_view->priv->pixbuf_column)
5112 icon_view->priv->pixbuf_column = -1;
5115 if (icon_view->priv->model != NULL)
5119 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5121 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5124 icon_view->priv->pixbuf_column = column;
5127 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5129 update_pixbuf_cell (icon_view);
5131 gtk_icon_view_invalidate_sizes (icon_view);
5133 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5138 * gtk_icon_view_get_pixbuf_column:
5139 * @icon_view: A #GtkIconView.
5141 * Returns the column with pixbufs for @icon_view.
5143 * Returns: the pixbuf column, or -1 if it's unset.
5148 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5150 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5152 return icon_view->priv->pixbuf_column;
5156 * gtk_icon_view_select_path:
5157 * @icon_view: A #GtkIconView.
5158 * @path: The #GtkTreePath to be selected.
5160 * Selects the row at @path.
5165 gtk_icon_view_select_path (GtkIconView *icon_view,
5168 GtkIconViewItem *item = NULL;
5170 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5171 g_return_if_fail (icon_view->priv->model != NULL);
5172 g_return_if_fail (path != NULL);
5174 if (gtk_tree_path_get_depth (path) > 0)
5175 item = g_list_nth_data (icon_view->priv->items,
5176 gtk_tree_path_get_indices(path)[0]);
5179 gtk_icon_view_select_item (icon_view, item);
5183 * gtk_icon_view_unselect_path:
5184 * @icon_view: A #GtkIconView.
5185 * @path: The #GtkTreePath to be unselected.
5187 * Unselects the row at @path.
5192 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5195 GtkIconViewItem *item;
5197 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5198 g_return_if_fail (icon_view->priv->model != NULL);
5199 g_return_if_fail (path != NULL);
5201 item = g_list_nth_data (icon_view->priv->items,
5202 gtk_tree_path_get_indices(path)[0]);
5207 gtk_icon_view_unselect_item (icon_view, item);
5211 * gtk_icon_view_get_selected_items:
5212 * @icon_view: A #GtkIconView.
5214 * Creates a list of paths of all selected items. Additionally, if you are
5215 * planning on modifying the model after calling this function, you may
5216 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5217 * To do this, you can use gtk_tree_row_reference_new().
5219 * To free the return value, use:
5221 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5222 * g_list_free (list);
5225 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5230 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5233 GList *selected = NULL;
5235 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5237 for (list = icon_view->priv->items; list != NULL; list = list->next)
5239 GtkIconViewItem *item = list->data;
5243 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5245 selected = g_list_prepend (selected, path);
5253 * gtk_icon_view_select_all:
5254 * @icon_view: A #GtkIconView.
5256 * Selects all the icons. @icon_view must has its selection mode set
5257 * to #GTK_SELECTION_MULTIPLE.
5262 gtk_icon_view_select_all (GtkIconView *icon_view)
5265 gboolean dirty = FALSE;
5267 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5269 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5272 for (items = icon_view->priv->items; items; items = items->next)
5274 GtkIconViewItem *item = items->data;
5276 if (!item->selected)
5279 item->selected = TRUE;
5280 gtk_icon_view_queue_draw_item (icon_view, item);
5285 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5289 * gtk_icon_view_unselect_all:
5290 * @icon_view: A #GtkIconView.
5292 * Unselects all the icons.
5297 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5299 gboolean dirty = FALSE;
5301 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5303 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5306 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5309 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5313 * gtk_icon_view_path_is_selected:
5314 * @icon_view: A #GtkIconView.
5315 * @path: A #GtkTreePath to check selection on.
5317 * Returns %TRUE if the icon pointed to by @path is currently
5318 * selected. If @path does not point to a valid location, %FALSE is returned.
5320 * Return value: %TRUE if @path is selected.
5325 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5328 GtkIconViewItem *item;
5330 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5331 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5332 g_return_val_if_fail (path != NULL, FALSE);
5334 item = g_list_nth_data (icon_view->priv->items,
5335 gtk_tree_path_get_indices(path)[0]);
5340 return item->selected;
5344 * gtk_icon_view_get_item_row:
5345 * @icon_view: a #GtkIconView
5346 * @path: the #GtkTreePath of the item
5348 * Gets the row in which the item @path is currently
5349 * displayed. Row numbers start at 0.
5351 * Returns: The row in which the item is displayed
5356 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5359 GtkIconViewItem *item;
5361 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5362 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5363 g_return_val_if_fail (path != NULL, -1);
5365 item = g_list_nth_data (icon_view->priv->items,
5366 gtk_tree_path_get_indices(path)[0]);
5375 * gtk_icon_view_get_item_column:
5376 * @icon_view: a #GtkIconView
5377 * @path: the #GtkTreePath of the item
5379 * Gets the column in which the item @path is currently
5380 * displayed. Column numbers start at 0.
5382 * Returns: The column in which the item is displayed
5387 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5390 GtkIconViewItem *item;
5392 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5393 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5394 g_return_val_if_fail (path != NULL, -1);
5396 item = g_list_nth_data (icon_view->priv->items,
5397 gtk_tree_path_get_indices(path)[0]);
5406 * gtk_icon_view_item_activated:
5407 * @icon_view: A #GtkIconView
5408 * @path: The #GtkTreePath to be activated
5410 * Activates the item determined by @path.
5415 gtk_icon_view_item_activated (GtkIconView *icon_view,
5418 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5419 g_return_if_fail (path != NULL);
5421 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5425 * gtk_icon_view_set_item_orientation:
5426 * @icon_view: a #GtkIconView
5427 * @orientation: the relative position of texts and icons
5429 * Sets the ::item-orientation property which determines whether the labels
5430 * are drawn beside the icons instead of below.
5435 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5436 GtkOrientation orientation)
5438 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5440 if (icon_view->priv->item_orientation != orientation)
5442 icon_view->priv->item_orientation = orientation;
5444 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5445 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5446 icon_view->priv->item_orientation);
5448 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5449 gtk_icon_view_invalidate_sizes (icon_view);
5451 update_text_cell (icon_view);
5452 update_pixbuf_cell (icon_view);
5454 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5459 * gtk_icon_view_get_item_orientation:
5460 * @icon_view: a #GtkIconView
5462 * Returns the value of the ::item-orientation property which determines
5463 * whether the labels are drawn beside the icons instead of below.
5465 * Return value: the relative position of texts and icons
5470 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5472 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5473 GTK_ORIENTATION_VERTICAL);
5475 return icon_view->priv->item_orientation;
5479 * gtk_icon_view_set_columns:
5480 * @icon_view: a #GtkIconView
5481 * @columns: the number of columns
5483 * Sets the ::columns property which determines in how
5484 * many columns the icons are arranged. If @columns is
5485 * -1, the number of columns will be chosen automatically
5486 * to fill the available area.
5491 gtk_icon_view_set_columns (GtkIconView *icon_view,
5494 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5496 if (icon_view->priv->columns != columns)
5498 icon_view->priv->columns = columns;
5500 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5501 gtk_icon_view_queue_layout (icon_view);
5503 g_object_notify (G_OBJECT (icon_view), "columns");
5508 * gtk_icon_view_get_columns:
5509 * @icon_view: a #GtkIconView
5511 * Returns the value of the ::columns property.
5513 * Return value: the number of columns, or -1
5518 gtk_icon_view_get_columns (GtkIconView *icon_view)
5520 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5522 return icon_view->priv->columns;
5526 * gtk_icon_view_set_item_width:
5527 * @icon_view: a #GtkIconView
5528 * @item_width: the width for each item
5530 * Sets the ::item-width property which specifies the width
5531 * to use for each item. If it is set to -1, the icon view will
5532 * automatically determine a suitable item size.
5537 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5542 if (icon_view->priv->item_width != item_width)
5544 icon_view->priv->item_width = item_width;
5546 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5547 gtk_icon_view_invalidate_sizes (icon_view);
5549 update_text_cell (icon_view);
5551 g_object_notify (G_OBJECT (icon_view), "item-width");
5556 * gtk_icon_view_get_item_width:
5557 * @icon_view: a #GtkIconView
5559 * Returns the value of the ::item-width property.
5561 * Return value: the width of a single item, or -1
5566 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5568 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5570 return icon_view->priv->item_width;
5575 * gtk_icon_view_set_spacing:
5576 * @icon_view: a #GtkIconView
5577 * @spacing: the spacing
5579 * Sets the ::spacing property which specifies the space
5580 * which is inserted between the cells (i.e. the icon and
5581 * the text) of an item.
5586 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5589 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5591 if (icon_view->priv->spacing != spacing)
5593 icon_view->priv->spacing = spacing;
5595 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5596 gtk_icon_view_invalidate_sizes (icon_view);
5598 g_object_notify (G_OBJECT (icon_view), "spacing");
5603 * gtk_icon_view_get_spacing:
5604 * @icon_view: a #GtkIconView
5606 * Returns the value of the ::spacing property.
5608 * Return value: the space between cells
5613 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5615 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5617 return icon_view->priv->spacing;
5621 * gtk_icon_view_set_row_spacing:
5622 * @icon_view: a #GtkIconView
5623 * @row_spacing: the row spacing
5625 * Sets the ::row-spacing property which specifies the space
5626 * which is inserted between the rows of the icon view.
5631 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5634 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5636 if (icon_view->priv->row_spacing != row_spacing)
5638 icon_view->priv->row_spacing = row_spacing;
5640 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5641 gtk_icon_view_invalidate_sizes (icon_view);
5643 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5648 * gtk_icon_view_get_row_spacing:
5649 * @icon_view: a #GtkIconView
5651 * Returns the value of the ::row-spacing property.
5653 * Return value: the space between rows
5658 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5660 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5662 return icon_view->priv->row_spacing;
5666 * gtk_icon_view_set_column_spacing:
5667 * @icon_view: a #GtkIconView
5668 * @column_spacing: the column spacing
5670 * Sets the ::column-spacing property which specifies the space
5671 * which is inserted between the columns of the icon view.
5676 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5677 gint column_spacing)
5679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5681 if (icon_view->priv->column_spacing != column_spacing)
5683 icon_view->priv->column_spacing = column_spacing;
5685 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5686 gtk_icon_view_invalidate_sizes (icon_view);
5688 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5693 * gtk_icon_view_get_column_spacing:
5694 * @icon_view: a #GtkIconView
5696 * Returns the value of the ::column-spacing property.
5698 * Return value: the space between columns
5703 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5705 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5707 return icon_view->priv->column_spacing;
5711 * gtk_icon_view_set_margin:
5712 * @icon_view: a #GtkIconView
5713 * @margin: the margin
5715 * Sets the ::margin property which specifies the space
5716 * which is inserted at the top, bottom, left and right
5722 gtk_icon_view_set_margin (GtkIconView *icon_view,
5725 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5727 if (icon_view->priv->margin != margin)
5729 icon_view->priv->margin = margin;
5731 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5732 gtk_icon_view_invalidate_sizes (icon_view);
5734 g_object_notify (G_OBJECT (icon_view), "margin");
5739 * gtk_icon_view_get_margin:
5740 * @icon_view: a #GtkIconView
5742 * Returns the value of the ::margin property.
5744 * Return value: the space at the borders
5749 gtk_icon_view_get_margin (GtkIconView *icon_view)
5751 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5753 return icon_view->priv->margin;
5757 * gtk_icon_view_set_item_padding:
5758 * @icon_view: a #GtkIconView
5759 * @item_padding: the item padding
5761 * Sets the #GtkIconView:item-padding property which specifies the padding
5762 * around each of the icon view's items.
5767 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5770 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5772 if (icon_view->priv->item_padding != item_padding)
5774 icon_view->priv->item_padding = item_padding;
5776 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5777 gtk_icon_view_invalidate_sizes (icon_view);
5779 g_object_notify (G_OBJECT (icon_view), "item-padding");
5784 * gtk_icon_view_get_item_padding:
5785 * @icon_view: a #GtkIconView
5787 * Returns the value of the ::item-padding property.
5789 * Return value: the padding around items
5794 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5796 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5798 return icon_view->priv->item_padding;
5801 /* Get/set whether drag_motion requested the drag data and
5802 * drag_data_received should thus not actually insert the data,
5803 * since the data doesn't result from a drop.
5806 set_status_pending (GdkDragContext *context,
5807 GdkDragAction suggested_action)
5809 g_object_set_data (G_OBJECT (context),
5810 I_("gtk-icon-view-status-pending"),
5811 GINT_TO_POINTER (suggested_action));
5814 static GdkDragAction
5815 get_status_pending (GdkDragContext *context)
5817 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5818 "gtk-icon-view-status-pending"));
5822 unset_reorderable (GtkIconView *icon_view)
5824 if (icon_view->priv->reorderable)
5826 icon_view->priv->reorderable = FALSE;
5827 g_object_notify (G_OBJECT (icon_view), "reorderable");
5832 set_source_row (GdkDragContext *context,
5833 GtkTreeModel *model,
5834 GtkTreePath *source_row)
5837 g_object_set_data_full (G_OBJECT (context),
5838 I_("gtk-icon-view-source-row"),
5839 gtk_tree_row_reference_new (model, source_row),
5840 (GDestroyNotify) gtk_tree_row_reference_free);
5842 g_object_set_data_full (G_OBJECT (context),
5843 I_("gtk-icon-view-source-row"),
5848 get_source_row (GdkDragContext *context)
5850 GtkTreeRowReference *ref;
5852 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5855 return gtk_tree_row_reference_get_path (ref);
5862 GtkTreeRowReference *dest_row;
5863 gboolean empty_view_drop;
5864 gboolean drop_append_mode;
5868 dest_row_free (gpointer data)
5870 DestRow *dr = (DestRow *)data;
5872 gtk_tree_row_reference_free (dr->dest_row);
5877 set_dest_row (GdkDragContext *context,
5878 GtkTreeModel *model,
5879 GtkTreePath *dest_row,
5880 gboolean empty_view_drop,
5881 gboolean drop_append_mode)
5887 g_object_set_data_full (G_OBJECT (context),
5888 I_("gtk-icon-view-dest-row"),
5893 dr = g_new0 (DestRow, 1);
5895 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5896 dr->empty_view_drop = empty_view_drop;
5897 dr->drop_append_mode = drop_append_mode;
5898 g_object_set_data_full (G_OBJECT (context),
5899 I_("gtk-icon-view-dest-row"),
5900 dr, (GDestroyNotify) dest_row_free);
5904 get_dest_row (GdkDragContext *context)
5908 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5912 GtkTreePath *path = NULL;
5915 path = gtk_tree_row_reference_get_path (dr->dest_row);
5916 else if (dr->empty_view_drop)
5917 path = gtk_tree_path_new_from_indices (0, -1);
5921 if (path && dr->drop_append_mode)
5922 gtk_tree_path_next (path);
5931 check_model_dnd (GtkTreeModel *model,
5932 GType required_iface,
5933 const gchar *signal)
5935 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5937 g_warning ("You must override the default '%s' handler "
5938 "on GtkIconView when using models that don't support "
5939 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5940 "is to connect to '%s' and call "
5941 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5942 "the default handler from running. Look at the source code "
5943 "for the default handler in gtkiconview.c to get an idea what "
5944 "your handler should do. (gtkiconview.c is in the GTK+ source "
5945 "code.) If you're using GTK+ from a language other than C, "
5946 "there may be a more natural way to override default handlers, e.g. via derivation.",
5947 signal, g_type_name (required_iface), signal);
5955 remove_scroll_timeout (GtkIconView *icon_view)
5957 if (icon_view->priv->scroll_timeout_id != 0)
5959 g_source_remove (icon_view->priv->scroll_timeout_id);
5961 icon_view->priv->scroll_timeout_id = 0;
5966 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5969 gint px, py, x, y, width, height;
5970 gint hoffset, voffset;
5972 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5974 gdk_window_get_pointer (window, &px, &py, NULL);
5975 gdk_window_get_geometry (window, &x, &y, &width, &height);
5977 /* see if we are near the edge. */
5978 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5980 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5982 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5984 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5987 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5988 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5991 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5992 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5997 drag_scroll_timeout (gpointer data)
5999 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6001 gtk_icon_view_autoscroll (icon_view);
6008 set_destination (GtkIconView *icon_view,
6009 GdkDragContext *context,
6012 GdkDragAction *suggested_action,
6016 GtkTreePath *path = NULL;
6017 GtkIconViewDropPosition pos;
6018 GtkIconViewDropPosition old_pos;
6019 GtkTreePath *old_dest_path = NULL;
6020 gboolean can_drop = FALSE;
6022 widget = GTK_WIDGET (icon_view);
6024 *suggested_action = 0;
6027 if (!icon_view->priv->dest_set)
6029 /* someone unset us as a drag dest, note that if
6030 * we return FALSE drag_leave isn't called
6033 gtk_icon_view_set_drag_dest_item (icon_view,
6035 GTK_ICON_VIEW_DROP_LEFT);
6037 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6039 return FALSE; /* no longer a drop site */
6042 *target = gtk_drag_dest_find_target (widget, context,
6043 gtk_drag_dest_get_target_list (widget));
6044 if (*target == GDK_NONE)
6047 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6050 GtkTreeModel *model;
6052 /* the row got dropped on empty space, let's setup a special case
6056 gtk_tree_path_free (path);
6058 model = gtk_icon_view_get_model (icon_view);
6060 n_children = gtk_tree_model_iter_n_children (model, NULL);
6063 pos = GTK_ICON_VIEW_DROP_BELOW;
6064 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6068 pos = GTK_ICON_VIEW_DROP_ABOVE;
6069 path = gtk_tree_path_new_from_indices (0, -1);
6079 gtk_icon_view_get_drag_dest_item (icon_view,
6084 gtk_tree_path_free (old_dest_path);
6086 if (TRUE /* FIXME if the location droppable predicate */)
6094 GtkWidget *source_widget;
6096 *suggested_action = gdk_drag_context_get_suggested_action (context);
6097 source_widget = gtk_drag_get_source_widget (context);
6099 if (source_widget == widget)
6101 /* Default to MOVE, unless the user has
6102 * pressed ctrl or shift to affect available actions
6104 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6105 *suggested_action = GDK_ACTION_MOVE;
6108 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6113 /* can't drop here */
6114 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6116 GTK_ICON_VIEW_DROP_LEFT);
6120 gtk_tree_path_free (path);
6126 get_logical_destination (GtkIconView *icon_view,
6127 gboolean *drop_append_mode)
6129 /* adjust path to point to the row the drop goes in front of */
6130 GtkTreePath *path = NULL;
6131 GtkIconViewDropPosition pos;
6133 *drop_append_mode = FALSE;
6135 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6140 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6141 pos == GTK_ICON_VIEW_DROP_BELOW)
6144 GtkTreeModel *model = icon_view->priv->model;
6146 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6147 !gtk_tree_model_iter_next (model, &iter))
6148 *drop_append_mode = TRUE;
6151 *drop_append_mode = FALSE;
6152 gtk_tree_path_next (path);
6160 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6161 GdkEventMotion *event)
6163 GtkWidget *widget = GTK_WIDGET (icon_view);
6164 GdkDragContext *context;
6165 GtkTreePath *path = NULL;
6167 GtkTreeModel *model;
6168 gboolean retval = FALSE;
6170 if (!icon_view->priv->source_set)
6173 if (icon_view->priv->pressed_button < 0)
6176 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6177 icon_view->priv->press_start_x,
6178 icon_view->priv->press_start_y,
6179 event->x, event->y))
6182 model = gtk_icon_view_get_model (icon_view);
6187 button = icon_view->priv->pressed_button;
6188 icon_view->priv->pressed_button = -1;
6190 path = gtk_icon_view_get_path_at_pos (icon_view,
6191 icon_view->priv->press_start_x,
6192 icon_view->priv->press_start_y);
6197 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6198 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6202 /* FIXME Check whether we're a start button, if not return FALSE and
6206 /* Now we can begin the drag */
6210 context = gtk_drag_begin (widget,
6211 gtk_drag_source_get_target_list (widget),
6212 icon_view->priv->source_actions,
6216 set_source_row (context, model, path);
6220 gtk_tree_path_free (path);
6225 /* Source side drag signals */
6227 gtk_icon_view_drag_begin (GtkWidget *widget,
6228 GdkDragContext *context)
6230 GtkIconView *icon_view;
6231 GtkIconViewItem *item;
6232 cairo_surface_t *icon;
6236 icon_view = GTK_ICON_VIEW (widget);
6238 /* if the user uses a custom DnD impl, we don't set the icon here */
6239 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6242 item = gtk_icon_view_get_item_at_coords (icon_view,
6243 icon_view->priv->press_start_x,
6244 icon_view->priv->press_start_y,
6248 g_return_if_fail (item != NULL);
6250 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6251 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6253 path = gtk_tree_path_new_from_indices (item->index, -1);
6254 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6255 gtk_tree_path_free (path);
6257 cairo_surface_set_device_offset (icon, -x, -y);
6259 gtk_drag_set_icon_surface (context, icon);
6261 cairo_surface_destroy (icon);
6265 gtk_icon_view_drag_end (GtkWidget *widget,
6266 GdkDragContext *context)
6272 gtk_icon_view_drag_data_get (GtkWidget *widget,
6273 GdkDragContext *context,
6274 GtkSelectionData *selection_data,
6278 GtkIconView *icon_view;
6279 GtkTreeModel *model;
6280 GtkTreePath *source_row;
6282 icon_view = GTK_ICON_VIEW (widget);
6283 model = gtk_icon_view_get_model (icon_view);
6288 if (!icon_view->priv->source_set)
6291 source_row = get_source_row (context);
6293 if (source_row == NULL)
6296 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6297 * any model; for DragSource models there are some other targets
6301 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6302 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6307 /* If drag_data_get does nothing, try providing row data. */
6308 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6309 gtk_tree_set_row_drag_data (selection_data,
6314 gtk_tree_path_free (source_row);
6318 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6319 GdkDragContext *context)
6321 GtkTreeModel *model;
6322 GtkIconView *icon_view;
6323 GtkTreePath *source_row;
6325 icon_view = GTK_ICON_VIEW (widget);
6326 model = gtk_icon_view_get_model (icon_view);
6328 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6331 if (!icon_view->priv->source_set)
6334 source_row = get_source_row (context);
6336 if (source_row == NULL)
6339 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6342 gtk_tree_path_free (source_row);
6344 set_source_row (context, NULL, NULL);
6347 /* Target side drag signals */
6349 gtk_icon_view_drag_leave (GtkWidget *widget,
6350 GdkDragContext *context,
6353 GtkIconView *icon_view;
6355 icon_view = GTK_ICON_VIEW (widget);
6357 /* unset any highlight row */
6358 gtk_icon_view_set_drag_dest_item (icon_view,
6360 GTK_ICON_VIEW_DROP_LEFT);
6362 remove_scroll_timeout (icon_view);
6366 gtk_icon_view_drag_motion (GtkWidget *widget,
6367 GdkDragContext *context,
6372 GtkTreePath *path = NULL;
6373 GtkIconViewDropPosition pos;
6374 GtkIconView *icon_view;
6375 GdkDragAction suggested_action = 0;
6379 icon_view = GTK_ICON_VIEW (widget);
6381 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6384 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6386 /* we only know this *after* set_desination_row */
6387 empty = icon_view->priv->empty_view_drop;
6389 if (path == NULL && !empty)
6391 /* Can't drop here. */
6392 gdk_drag_status (context, 0, time);
6396 if (icon_view->priv->scroll_timeout_id == 0)
6398 icon_view->priv->scroll_timeout_id =
6399 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6402 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6404 /* Request data so we can use the source row when
6405 * determining whether to accept the drop
6407 set_status_pending (context, suggested_action);
6408 gtk_drag_get_data (widget, context, target, time);
6412 set_status_pending (context, 0);
6413 gdk_drag_status (context, suggested_action, time);
6418 gtk_tree_path_free (path);
6424 gtk_icon_view_drag_drop (GtkWidget *widget,
6425 GdkDragContext *context,
6430 GtkIconView *icon_view;
6432 GdkDragAction suggested_action = 0;
6433 GdkAtom target = GDK_NONE;
6434 GtkTreeModel *model;
6435 gboolean drop_append_mode;
6437 icon_view = GTK_ICON_VIEW (widget);
6438 model = gtk_icon_view_get_model (icon_view);
6440 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6442 if (!icon_view->priv->dest_set)
6445 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6448 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6451 path = get_logical_destination (icon_view, &drop_append_mode);
6453 if (target != GDK_NONE && path != NULL)
6455 /* in case a motion had requested drag data, change things so we
6456 * treat drag data receives as a drop.
6458 set_status_pending (context, 0);
6459 set_dest_row (context, model, path,
6460 icon_view->priv->empty_view_drop, drop_append_mode);
6464 gtk_tree_path_free (path);
6466 /* Unset this thing */
6467 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6469 if (target != GDK_NONE)
6471 gtk_drag_get_data (widget, context, target, time);
6479 gtk_icon_view_drag_data_received (GtkWidget *widget,
6480 GdkDragContext *context,
6483 GtkSelectionData *selection_data,
6488 gboolean accepted = FALSE;
6489 GtkTreeModel *model;
6490 GtkIconView *icon_view;
6491 GtkTreePath *dest_row;
6492 GdkDragAction suggested_action;
6493 gboolean drop_append_mode;
6495 icon_view = GTK_ICON_VIEW (widget);
6496 model = gtk_icon_view_get_model (icon_view);
6498 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6501 if (!icon_view->priv->dest_set)
6504 suggested_action = get_status_pending (context);
6506 if (suggested_action)
6508 /* We are getting this data due to a request in drag_motion,
6509 * rather than due to a request in drag_drop, so we are just
6510 * supposed to call drag_status, not actually paste in the
6513 path = get_logical_destination (icon_view, &drop_append_mode);
6516 suggested_action = 0;
6518 if (suggested_action)
6520 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6523 suggested_action = 0;
6526 gdk_drag_status (context, suggested_action, time);
6529 gtk_tree_path_free (path);
6531 /* If you can't drop, remove user drop indicator until the next motion */
6532 if (suggested_action == 0)
6533 gtk_icon_view_set_drag_dest_item (icon_view,
6535 GTK_ICON_VIEW_DROP_LEFT);
6540 dest_row = get_dest_row (context);
6542 if (dest_row == NULL)
6545 if (gtk_selection_data_get_length (selection_data) >= 0)
6547 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6553 gtk_drag_finish (context,
6555 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6558 gtk_tree_path_free (dest_row);
6561 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6564 /* Drag-and-Drop support */
6566 * gtk_icon_view_enable_model_drag_source:
6567 * @icon_view: a #GtkIconTreeView
6568 * @start_button_mask: Mask of allowed buttons to start drag
6569 * @targets: (array length=n_targets): the table of targets that the drag will
6571 * @n_targets: the number of items in @targets
6572 * @actions: the bitmask of possible actions for a drag from this
6575 * Turns @icon_view into a drag source for automatic DND. Calling this
6576 * method sets #GtkIconView:reorderable to %FALSE.
6581 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6582 GdkModifierType start_button_mask,
6583 const GtkTargetEntry *targets,
6585 GdkDragAction actions)
6587 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6589 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6591 icon_view->priv->start_button_mask = start_button_mask;
6592 icon_view->priv->source_actions = actions;
6594 icon_view->priv->source_set = TRUE;
6596 unset_reorderable (icon_view);
6600 * gtk_icon_view_enable_model_drag_dest:
6601 * @icon_view: a #GtkIconView
6602 * @targets: (array length=n_targets): the table of targets that the drag will
6604 * @n_targets: the number of items in @targets
6605 * @actions: the bitmask of possible actions for a drag to this
6608 * Turns @icon_view into a drop destination for automatic DND. Calling this
6609 * method sets #GtkIconView:reorderable to %FALSE.
6614 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6615 const GtkTargetEntry *targets,
6617 GdkDragAction actions)
6619 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6621 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6623 icon_view->priv->dest_actions = actions;
6625 icon_view->priv->dest_set = TRUE;
6627 unset_reorderable (icon_view);
6631 * gtk_icon_view_unset_model_drag_source:
6632 * @icon_view: a #GtkIconView
6634 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6635 * method sets #GtkIconView:reorderable to %FALSE.
6640 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6642 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6644 if (icon_view->priv->source_set)
6646 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6647 icon_view->priv->source_set = FALSE;
6650 unset_reorderable (icon_view);
6654 * gtk_icon_view_unset_model_drag_dest:
6655 * @icon_view: a #GtkIconView
6657 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6658 * method sets #GtkIconView:reorderable to %FALSE.
6663 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6665 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6667 if (icon_view->priv->dest_set)
6669 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6670 icon_view->priv->dest_set = FALSE;
6673 unset_reorderable (icon_view);
6676 /* These are useful to implement your own custom stuff. */
6678 * gtk_icon_view_set_drag_dest_item:
6679 * @icon_view: a #GtkIconView
6680 * @path: (allow-none): The path of the item to highlight, or %NULL.
6681 * @pos: Specifies where to drop, relative to the item
6683 * Sets the item that is highlighted for feedback.
6688 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6690 GtkIconViewDropPosition pos)
6692 /* Note; this function is exported to allow a custom DND
6693 * implementation, so it can't touch TreeViewDragInfo
6696 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6698 if (icon_view->priv->dest_item)
6700 GtkTreePath *current_path;
6701 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6702 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6703 icon_view->priv->dest_item = NULL;
6705 gtk_icon_view_queue_draw_path (icon_view, current_path);
6706 gtk_tree_path_free (current_path);
6709 /* special case a drop on an empty model */
6710 icon_view->priv->empty_view_drop = FALSE;
6711 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6712 && gtk_tree_path_get_depth (path) == 1
6713 && gtk_tree_path_get_indices (path)[0] == 0)
6717 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6720 if (n_children == 0)
6721 icon_view->priv->empty_view_drop = TRUE;
6724 icon_view->priv->dest_pos = pos;
6728 icon_view->priv->dest_item =
6729 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6730 icon_view->priv->model, path);
6732 gtk_icon_view_queue_draw_path (icon_view, path);
6737 * gtk_icon_view_get_drag_dest_item:
6738 * @icon_view: a #GtkIconView
6739 * @path: (out) (allow-none): Return location for the path of
6740 * the highlighted item, or %NULL.
6741 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6743 * Gets information about the item that is highlighted for feedback.
6748 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6750 GtkIconViewDropPosition *pos)
6752 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6756 if (icon_view->priv->dest_item)
6757 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6763 *pos = icon_view->priv->dest_pos;
6767 * gtk_icon_view_get_dest_item_at_pos:
6768 * @icon_view: a #GtkIconView
6769 * @drag_x: the position to determine the destination item for
6770 * @drag_y: the position to determine the destination item for
6771 * @path: (out) (allow-none): Return location for the path of the item,
6773 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6775 * Determines the destination item for a given position.
6777 * Return value: whether there is an item at the given position.
6782 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6786 GtkIconViewDropPosition *pos)
6788 GtkIconViewItem *item;
6790 /* Note; this function is exported to allow a custom DND
6791 * implementation, so it can't touch TreeViewDragInfo
6794 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6795 g_return_val_if_fail (drag_x >= 0, FALSE);
6796 g_return_val_if_fail (drag_y >= 0, FALSE);
6797 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6803 item = gtk_icon_view_get_item_at_coords (icon_view,
6804 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6805 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6812 *path = gtk_tree_path_new_from_indices (item->index, -1);
6816 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6817 *pos = GTK_ICON_VIEW_DROP_LEFT;
6818 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6819 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6820 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6821 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6822 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6823 *pos = GTK_ICON_VIEW_DROP_BELOW;
6825 *pos = GTK_ICON_VIEW_DROP_INTO;
6832 * gtk_icon_view_create_drag_icon:
6833 * @icon_view: a #GtkIconView
6834 * @path: a #GtkTreePath in @icon_view
6836 * Creates a #cairo_surface_t representation of the item at @path.
6837 * This image is used for a drag icon.
6839 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6844 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6848 GtkStyleContext *context;
6850 cairo_surface_t *surface;
6854 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6855 g_return_val_if_fail (path != NULL, NULL);
6857 widget = GTK_WIDGET (icon_view);
6858 context = gtk_widget_get_style_context (widget);
6860 if (!gtk_widget_get_realized (widget))
6863 index = gtk_tree_path_get_indices (path)[0];
6865 for (l = icon_view->priv->items; l; l = l->next)
6867 GtkIconViewItem *item = l->data;
6869 if (index == item->index)
6871 GdkRectangle rect = {
6872 item->cell_area.x - icon_view->priv->item_padding,
6873 item->cell_area.y - icon_view->priv->item_padding,
6874 item->cell_area.width + icon_view->priv->item_padding * 2,
6875 item->cell_area.height + icon_view->priv->item_padding * 2
6878 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6879 CAIRO_CONTENT_COLOR,
6883 cr = cairo_create (surface);
6884 cairo_set_line_width (cr, 1.);
6886 gtk_render_background (context, cr, 0, 0,
6887 rect.width + 2, rect.height + 2);
6891 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6894 gtk_icon_view_paint_item (icon_view, cr, item,
6895 icon_view->priv->item_padding + 1,
6896 icon_view->priv->item_padding + 1, FALSE);
6900 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6901 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6914 * gtk_icon_view_get_reorderable:
6915 * @icon_view: a #GtkIconView
6917 * Retrieves whether the user can reorder the list via drag-and-drop.
6918 * See gtk_icon_view_set_reorderable().
6920 * Return value: %TRUE if the list can be reordered.
6925 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6927 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6929 return icon_view->priv->reorderable;
6932 static const GtkTargetEntry item_targets[] = {
6933 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6938 * gtk_icon_view_set_reorderable:
6939 * @icon_view: A #GtkIconView.
6940 * @reorderable: %TRUE, if the list of items can be reordered.
6942 * This function is a convenience function to allow you to reorder models that
6943 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6944 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6945 * the user can reorder the model by dragging and dropping rows. The
6946 * developer can listen to these changes by connecting to the model's
6947 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6948 * the icon view as a drag source and destination. Therefore, drag and
6949 * drop can not be used in a reorderable view for any other purpose.
6951 * This function does not give you any degree of control over the order -- any
6952 * reordering is allowed. If more control is needed, you should probably
6953 * handle drag and drop manually.
6958 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6959 gboolean reorderable)
6961 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6963 reorderable = reorderable != FALSE;
6965 if (icon_view->priv->reorderable == reorderable)
6970 gtk_icon_view_enable_model_drag_source (icon_view,
6973 G_N_ELEMENTS (item_targets),
6975 gtk_icon_view_enable_model_drag_dest (icon_view,
6977 G_N_ELEMENTS (item_targets),
6982 gtk_icon_view_unset_model_drag_source (icon_view);
6983 gtk_icon_view_unset_model_drag_dest (icon_view);
6986 icon_view->priv->reorderable = reorderable;
6988 g_object_notify (G_OBJECT (icon_view), "reorderable");
6992 /* Accessibility Support */
6994 static gpointer accessible_parent_class;
6995 static gpointer accessible_item_parent_class;
6996 static GQuark accessible_private_data_quark = 0;
6998 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6999 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7000 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7002 static GType gtk_icon_view_item_accessible_get_type (void);
7013 GtkIconViewItem *item;
7017 AtkStateSet *state_set;
7021 GtkTextBuffer *text_buffer;
7023 gchar *action_descriptions[LAST_ACTION];
7024 gchar *image_description;
7025 guint action_idle_handler;
7026 } GtkIconViewItemAccessible;
7028 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7034 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7039 typedef struct _GtkIconViewItemAccessibleClass
7041 AtkObjectClass parent_class;
7043 } GtkIconViewItemAccessibleClass;
7045 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7048 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7050 GtkIconViewItemAccessible *item;
7051 GtkIconView *icon_view;
7054 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7055 item->action_idle_handler = 0;
7057 if (item->widget != NULL)
7059 icon_view = GTK_ICON_VIEW (item->widget);
7060 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7061 gtk_icon_view_item_activated (icon_view, path);
7062 gtk_tree_path_free (path);
7069 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7072 GtkIconViewItemAccessible *item;
7074 if (i < 0 || i >= LAST_ACTION)
7077 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7079 if (!GTK_IS_ICON_VIEW (item->widget))
7082 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7087 case ACTION_ACTIVATE:
7088 if (!item->action_idle_handler)
7089 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7092 g_assert_not_reached ();
7100 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7105 static const gchar *
7106 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7109 GtkIconViewItemAccessible *item;
7111 if (i < 0 || i >= LAST_ACTION)
7114 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7116 if (item->action_descriptions[i])
7117 return item->action_descriptions[i];
7119 return gtk_icon_view_item_accessible_action_descriptions[i];
7122 static const gchar *
7123 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7126 if (i < 0 || i >= LAST_ACTION)
7129 return gtk_icon_view_item_accessible_action_names[i];
7133 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7135 const gchar *description)
7137 GtkIconViewItemAccessible *item;
7139 if (i < 0 || i >= LAST_ACTION)
7142 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7144 g_free (item->action_descriptions[i]);
7146 item->action_descriptions[i] = g_strdup (description);
7152 atk_action_item_interface_init (AtkActionIface *iface)
7154 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7155 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7156 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7157 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7158 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7161 static const gchar *
7162 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7164 GtkIconViewItemAccessible *item;
7166 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7168 return item->image_description;
7172 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7173 const gchar *description)
7175 GtkIconViewItemAccessible *item;
7177 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7179 g_free (item->image_description);
7180 item->image_description = g_strdup (description);
7187 gboolean pixbuf_found;
7191 get_pixbuf_foreach (GtkCellRenderer *renderer,
7192 const GdkRectangle *cell_area,
7193 const GdkRectangle *cell_background,
7194 GetPixbufBoxData *data)
7196 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7198 data->box = *cell_area;
7199 data->pixbuf_found = TRUE;
7201 return (data->pixbuf_found != FALSE);
7205 get_pixbuf_box (GtkIconView *icon_view,
7206 GtkIconViewItem *item,
7209 GetPixbufBoxData data = { { 0, }, FALSE };
7210 GtkCellAreaContext *context;
7212 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7214 gtk_icon_view_set_cell_data (icon_view, item);
7215 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7216 GTK_WIDGET (icon_view),
7217 (GdkRectangle *)item, (GdkRectangle *)item,
7218 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7220 return data.pixbuf_found;
7224 get_text_foreach (GtkCellRenderer *renderer,
7227 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7229 g_object_get (renderer, "text", text, NULL);
7237 get_text (GtkIconView *icon_view,
7238 GtkIconViewItem *item)
7242 gtk_icon_view_set_cell_data (icon_view, item);
7243 gtk_cell_area_foreach (icon_view->priv->cell_area,
7244 (GtkCellCallback)get_text_foreach, &text);
7250 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7254 GtkIconViewItemAccessible *item;
7257 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7259 if (!GTK_IS_ICON_VIEW (item->widget))
7262 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7265 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7268 *height = box.height;
7273 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7276 AtkCoordType coord_type)
7278 GtkIconViewItemAccessible *item;
7281 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7283 if (!GTK_IS_ICON_VIEW (item->widget))
7286 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7289 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7291 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7293 *x+= box.x - item->item->cell_area.x;
7294 *y+= box.y - item->item->cell_area.y;
7300 atk_image_item_interface_init (AtkImageIface *iface)
7302 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7303 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7304 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7305 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7309 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7313 GtkIconViewItemAccessible *item;
7314 GtkTextIter start, end;
7315 GtkTextBuffer *buffer;
7317 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7319 if (!GTK_IS_ICON_VIEW (item->widget))
7322 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7325 buffer = item->text_buffer;
7326 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7328 gtk_text_buffer_get_end_iter (buffer, &end);
7330 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7332 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7336 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7339 GtkIconViewItemAccessible *item;
7340 GtkTextIter start, end;
7341 GtkTextBuffer *buffer;
7345 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7347 if (!GTK_IS_ICON_VIEW (item->widget))
7350 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7353 buffer = item->text_buffer;
7354 if (offset >= gtk_text_buffer_get_char_count (buffer))
7357 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7359 gtk_text_iter_forward_char (&end);
7360 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7361 unichar = g_utf8_get_char (string);
7369 get_pango_text_offsets (PangoLayout *layout,
7370 GtkTextBuffer *buffer,
7372 AtkTextBoundary boundary_type,
7376 GtkTextIter *start_iter,
7377 GtkTextIter *end_iter)
7379 PangoLayoutIter *iter;
7380 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7381 gint index, start_index, end_index;
7383 gboolean found = FALSE;
7385 text = pango_layout_get_text (layout);
7386 index = g_utf8_offset_to_pointer (text, offset) - text;
7387 iter = pango_layout_get_iter (layout);
7390 line = pango_layout_iter_get_line_readonly (iter);
7391 start_index = line->start_index;
7392 end_index = start_index + line->length;
7394 if (index >= start_index && index <= end_index)
7397 * Found line for offset
7403 * We want the previous line
7407 switch (boundary_type)
7409 case ATK_TEXT_BOUNDARY_LINE_START:
7410 end_index = start_index;
7411 start_index = prev_line->start_index;
7413 case ATK_TEXT_BOUNDARY_LINE_END:
7415 start_index = prev_prev_line->start_index +
7416 prev_prev_line->length;
7417 end_index = prev_line->start_index + prev_line->length;
7420 g_assert_not_reached();
7424 start_index = end_index = 0;
7427 switch (boundary_type)
7429 case ATK_TEXT_BOUNDARY_LINE_START:
7430 if (pango_layout_iter_next_line (iter))
7431 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7433 case ATK_TEXT_BOUNDARY_LINE_END:
7435 start_index = prev_line->start_index +
7439 g_assert_not_reached();
7444 * We want the next line
7446 if (pango_layout_iter_next_line (iter))
7448 line = pango_layout_iter_get_line_readonly (iter);
7449 switch (boundary_type)
7451 case ATK_TEXT_BOUNDARY_LINE_START:
7452 start_index = line->start_index;
7453 if (pango_layout_iter_next_line (iter))
7454 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7456 end_index = start_index + line->length;
7458 case ATK_TEXT_BOUNDARY_LINE_END:
7459 start_index = end_index;
7460 end_index = line->start_index + line->length;
7463 g_assert_not_reached();
7467 start_index = end_index;
7473 prev_prev_line = prev_line;
7476 while (pango_layout_iter_next_line (iter));
7480 start_index = prev_line->start_index + prev_line->length;
7481 end_index = start_index;
7483 pango_layout_iter_free (iter);
7484 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7485 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7487 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7488 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7493 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7495 AtkTextBoundary boundary_type,
7499 GtkIconViewItemAccessible *item;
7500 GtkTextIter start, end;
7501 GtkTextBuffer *buffer;
7503 GtkIconView *icon_view;
7506 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7508 if (!GTK_IS_ICON_VIEW (item->widget))
7511 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7514 buffer = item->text_buffer;
7516 if (!gtk_text_buffer_get_char_count (buffer))
7520 return g_strdup ("");
7522 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7526 switch (boundary_type)
7528 case ATK_TEXT_BOUNDARY_CHAR:
7529 gtk_text_iter_backward_char(&start);
7531 case ATK_TEXT_BOUNDARY_WORD_START:
7532 if (!gtk_text_iter_starts_word (&start))
7533 gtk_text_iter_backward_word_start (&start);
7535 gtk_text_iter_backward_word_start(&start);
7537 case ATK_TEXT_BOUNDARY_WORD_END:
7538 if (gtk_text_iter_inside_word (&start) &&
7539 !gtk_text_iter_starts_word (&start))
7540 gtk_text_iter_backward_word_start (&start);
7541 while (!gtk_text_iter_ends_word (&start))
7543 if (!gtk_text_iter_backward_char (&start))
7547 gtk_text_iter_backward_word_start(&start);
7548 while (!gtk_text_iter_ends_word (&start))
7550 if (!gtk_text_iter_backward_char (&start))
7554 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7555 if (!gtk_text_iter_starts_sentence (&start))
7556 gtk_text_iter_backward_sentence_start (&start);
7558 gtk_text_iter_backward_sentence_start (&start);
7560 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7561 if (gtk_text_iter_inside_sentence (&start) &&
7562 !gtk_text_iter_starts_sentence (&start))
7563 gtk_text_iter_backward_sentence_start (&start);
7564 while (!gtk_text_iter_ends_sentence (&start))
7566 if (!gtk_text_iter_backward_char (&start))
7570 gtk_text_iter_backward_sentence_start (&start);
7571 while (!gtk_text_iter_ends_sentence (&start))
7573 if (!gtk_text_iter_backward_char (&start))
7577 case ATK_TEXT_BOUNDARY_LINE_START:
7578 case ATK_TEXT_BOUNDARY_LINE_END:
7580 icon_view = GTK_ICON_VIEW (item->widget);
7581 /* FIXME we probably have to use GailTextCell to salvage this */
7582 gtk_icon_view_update_item_text (icon_view, item->item);
7583 get_pango_text_offsets (icon_view->priv->layout,
7596 *start_offset = gtk_text_iter_get_offset (&start);
7597 *end_offset = gtk_text_iter_get_offset (&end);
7599 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7603 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7605 AtkTextBoundary boundary_type,
7609 GtkIconViewItemAccessible *item;
7610 GtkTextIter start, end;
7611 GtkTextBuffer *buffer;
7613 GtkIconView *icon_view;
7616 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7618 if (!GTK_IS_ICON_VIEW (item->widget))
7621 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7624 buffer = item->text_buffer;
7626 if (!gtk_text_buffer_get_char_count (buffer))
7630 return g_strdup ("");
7632 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7636 switch (boundary_type)
7638 case ATK_TEXT_BOUNDARY_CHAR:
7639 gtk_text_iter_forward_char (&end);
7641 case ATK_TEXT_BOUNDARY_WORD_START:
7642 if (!gtk_text_iter_starts_word (&start))
7643 gtk_text_iter_backward_word_start (&start);
7644 if (gtk_text_iter_inside_word (&end))
7645 gtk_text_iter_forward_word_end (&end);
7646 while (!gtk_text_iter_starts_word (&end))
7648 if (!gtk_text_iter_forward_char (&end))
7652 case ATK_TEXT_BOUNDARY_WORD_END:
7653 if (gtk_text_iter_inside_word (&start) &&
7654 !gtk_text_iter_starts_word (&start))
7655 gtk_text_iter_backward_word_start (&start);
7656 while (!gtk_text_iter_ends_word (&start))
7658 if (!gtk_text_iter_backward_char (&start))
7661 gtk_text_iter_forward_word_end (&end);
7663 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7664 if (!gtk_text_iter_starts_sentence (&start))
7665 gtk_text_iter_backward_sentence_start (&start);
7666 if (gtk_text_iter_inside_sentence (&end))
7667 gtk_text_iter_forward_sentence_end (&end);
7668 while (!gtk_text_iter_starts_sentence (&end))
7670 if (!gtk_text_iter_forward_char (&end))
7674 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7675 if (gtk_text_iter_inside_sentence (&start) &&
7676 !gtk_text_iter_starts_sentence (&start))
7677 gtk_text_iter_backward_sentence_start (&start);
7678 while (!gtk_text_iter_ends_sentence (&start))
7680 if (!gtk_text_iter_backward_char (&start))
7683 gtk_text_iter_forward_sentence_end (&end);
7685 case ATK_TEXT_BOUNDARY_LINE_START:
7686 case ATK_TEXT_BOUNDARY_LINE_END:
7688 icon_view = GTK_ICON_VIEW (item->widget);
7689 /* FIXME we probably have to use GailTextCell to salvage this */
7690 gtk_icon_view_update_item_text (icon_view, item->item);
7691 get_pango_text_offsets (icon_view->priv->layout,
7705 *start_offset = gtk_text_iter_get_offset (&start);
7706 *end_offset = gtk_text_iter_get_offset (&end);
7708 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7712 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7714 AtkTextBoundary boundary_type,
7718 GtkIconViewItemAccessible *item;
7719 GtkTextIter start, end;
7720 GtkTextBuffer *buffer;
7722 GtkIconView *icon_view;
7725 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7727 if (!GTK_IS_ICON_VIEW (item->widget))
7730 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7733 buffer = item->text_buffer;
7735 if (!gtk_text_buffer_get_char_count (buffer))
7739 return g_strdup ("");
7741 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7745 switch (boundary_type)
7747 case ATK_TEXT_BOUNDARY_CHAR:
7748 gtk_text_iter_forward_char(&start);
7749 gtk_text_iter_forward_chars(&end, 2);
7751 case ATK_TEXT_BOUNDARY_WORD_START:
7752 if (gtk_text_iter_inside_word (&end))
7753 gtk_text_iter_forward_word_end (&end);
7754 while (!gtk_text_iter_starts_word (&end))
7756 if (!gtk_text_iter_forward_char (&end))
7760 if (!gtk_text_iter_is_end (&end))
7762 gtk_text_iter_forward_word_end (&end);
7763 while (!gtk_text_iter_starts_word (&end))
7765 if (!gtk_text_iter_forward_char (&end))
7770 case ATK_TEXT_BOUNDARY_WORD_END:
7771 gtk_text_iter_forward_word_end (&end);
7773 if (!gtk_text_iter_is_end (&end))
7774 gtk_text_iter_forward_word_end (&end);
7776 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7777 if (gtk_text_iter_inside_sentence (&end))
7778 gtk_text_iter_forward_sentence_end (&end);
7779 while (!gtk_text_iter_starts_sentence (&end))
7781 if (!gtk_text_iter_forward_char (&end))
7785 if (!gtk_text_iter_is_end (&end))
7787 gtk_text_iter_forward_sentence_end (&end);
7788 while (!gtk_text_iter_starts_sentence (&end))
7790 if (!gtk_text_iter_forward_char (&end))
7795 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7796 gtk_text_iter_forward_sentence_end (&end);
7798 if (!gtk_text_iter_is_end (&end))
7799 gtk_text_iter_forward_sentence_end (&end);
7801 case ATK_TEXT_BOUNDARY_LINE_START:
7802 case ATK_TEXT_BOUNDARY_LINE_END:
7804 icon_view = GTK_ICON_VIEW (item->widget);
7805 /* FIXME we probably have to use GailTextCell to salvage this */
7806 gtk_icon_view_update_item_text (icon_view, item->item);
7807 get_pango_text_offsets (icon_view->priv->layout,
7819 *start_offset = gtk_text_iter_get_offset (&start);
7820 *end_offset = gtk_text_iter_get_offset (&end);
7822 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7826 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7828 GtkIconViewItemAccessible *item;
7830 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7832 if (!GTK_IS_ICON_VIEW (item->widget))
7835 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7838 return gtk_text_buffer_get_char_count (item->text_buffer);
7842 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7848 AtkCoordType coord_type)
7850 GtkIconViewItemAccessible *item;
7852 GtkIconView *icon_view;
7853 PangoRectangle char_rect;
7854 const gchar *item_text;
7858 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7860 if (!GTK_IS_ICON_VIEW (item->widget))
7863 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7867 icon_view = GTK_ICON_VIEW (item->widget);
7868 /* FIXME we probably have to use GailTextCell to salvage this */
7869 gtk_icon_view_update_item_text (icon_view, item->item);
7870 item_text = pango_layout_get_text (icon_view->priv->layout);
7871 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7872 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7874 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7875 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7876 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7877 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7878 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7879 *width = char_rect.width / PANGO_SCALE;
7880 *height = char_rect.height / PANGO_SCALE;
7885 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7888 AtkCoordType coord_type)
7890 GtkIconViewItemAccessible *item;
7893 GtkIconView *icon_view;
7894 const gchar *item_text;
7899 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7901 if (!GTK_IS_ICON_VIEW (item->widget))
7904 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7908 icon_view = GTK_ICON_VIEW (item->widget);
7909 /* FIXME we probably have to use GailTextCell to salvage this */
7910 gtk_icon_view_update_item_text (icon_view, item->item);
7911 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7912 x -= l_x + item->item->layout_x - item->item->x;
7913 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7914 y -= l_y + item->item->layout_y - item->item->y;
7915 item_text = pango_layout_get_text (icon_view->priv->layout);
7916 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7927 offset = g_utf8_strlen (item_text, -1);
7929 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7935 atk_text_item_interface_init (AtkTextIface *iface)
7937 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7938 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7939 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7940 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7941 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7942 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7943 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7944 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7948 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7953 AtkCoordType coord_type)
7955 GtkIconViewItemAccessible *item;
7956 AtkObject *parent_obj;
7959 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7961 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7962 if (!GTK_IS_WIDGET (item->widget))
7965 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7968 *width = item->item->cell_area.width;
7969 *height = item->item->cell_area.height;
7970 if (gtk_icon_view_item_accessible_is_showing (item))
7972 parent_obj = gtk_widget_get_accessible (item->widget);
7973 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7974 *x = l_x + item->item->cell_area.x;
7975 *y = l_y + item->item->cell_area.y;
7985 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7987 GtkIconViewItemAccessible *item;
7988 GtkWidget *toplevel;
7990 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7992 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7993 if (!GTK_IS_WIDGET (item->widget))
7996 gtk_widget_grab_focus (item->widget);
7997 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7998 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7999 if (gtk_widget_is_toplevel (toplevel))
8000 gtk_window_present (GTK_WINDOW (toplevel));
8006 atk_component_item_interface_init (AtkComponentIface *iface)
8008 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8009 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8013 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8014 AtkStateType state_type,
8015 gboolean emit_signal)
8019 rc = atk_state_set_add_state (item->state_set, state_type);
8021 * The signal should only be generated if the value changed,
8022 * not when the item is set up. So states that are set
8023 * initially should pass FALSE as the emit_signal argument.
8028 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8029 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8030 if (state_type == ATK_STATE_VISIBLE)
8031 g_signal_emit_by_name (item, "visible-data-changed");
8038 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8039 AtkStateType state_type,
8040 gboolean emit_signal)
8042 if (atk_state_set_contains_state (item->state_set, state_type))
8046 rc = atk_state_set_remove_state (item->state_set, state_type);
8048 * The signal should only be generated if the value changed,
8049 * not when the item is set up. So states that are set
8050 * initially should pass FALSE as the emit_signal argument.
8055 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8056 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8057 if (state_type == ATK_STATE_VISIBLE)
8058 g_signal_emit_by_name (item, "visible-data-changed");
8068 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8070 GtkAllocation allocation;
8071 GtkIconView *icon_view;
8072 GdkRectangle visible_rect;
8073 gboolean is_showing;
8076 * An item is considered "SHOWING" if any part of the item is in the
8077 * visible rectangle.
8080 if (!GTK_IS_ICON_VIEW (item->widget))
8083 if (item->item == NULL)
8086 gtk_widget_get_allocation (item->widget, &allocation);
8088 icon_view = GTK_ICON_VIEW (item->widget);
8090 if (icon_view->priv->hadjustment)
8091 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8093 if (icon_view->priv->hadjustment)
8094 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8095 visible_rect.width = allocation.width;
8096 visible_rect.height = allocation.height;
8098 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8099 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8100 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8101 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8110 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8111 gboolean emit_signal)
8113 if (gtk_icon_view_item_accessible_is_showing (item))
8114 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8117 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8122 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8126 item->state_set = atk_state_set_new ();
8128 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8129 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8130 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8131 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8132 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8134 for (i = 0; i < LAST_ACTION; i++)
8135 item->action_descriptions[i] = NULL;
8137 item->image_description = NULL;
8139 item->action_idle_handler = 0;
8143 gtk_icon_view_item_accessible_finalize (GObject *object)
8145 GtkIconViewItemAccessible *item;
8148 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8150 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8153 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8155 if (item->state_set)
8156 g_object_unref (item->state_set);
8158 if (item->text_buffer)
8159 g_object_unref (item->text_buffer);
8161 for (i = 0; i < LAST_ACTION; i++)
8162 g_free (item->action_descriptions[i]);
8164 g_free (item->image_description);
8166 if (item->action_idle_handler)
8168 g_source_remove (item->action_idle_handler);
8169 item->action_idle_handler = 0;
8172 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8175 static G_CONST_RETURN gchar*
8176 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8182 GtkIconViewItemAccessible *item;
8183 GtkTextIter start_iter;
8184 GtkTextIter end_iter;
8186 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8188 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8189 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8191 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8196 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8198 GtkIconViewItemAccessible *item;
8200 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8201 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8204 return gtk_widget_get_accessible (item->widget);
8210 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8212 GtkIconViewItemAccessible *item;
8214 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8215 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8217 return item->item->index;
8220 static AtkStateSet *
8221 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8223 GtkIconViewItemAccessible *item;
8224 GtkIconView *icon_view;
8226 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8227 g_return_val_if_fail (item->state_set, NULL);
8232 icon_view = GTK_ICON_VIEW (item->widget);
8233 if (icon_view->priv->cursor_item == item->item)
8234 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8236 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8237 if (item->item->selected)
8238 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8240 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8242 return g_object_ref (item->state_set);
8246 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8248 GObjectClass *gobject_class;
8250 accessible_item_parent_class = g_type_class_peek_parent (klass);
8252 gobject_class = (GObjectClass *)klass;
8254 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8256 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8257 klass->get_name = gtk_icon_view_item_accessible_get_name;
8258 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8259 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8263 gtk_icon_view_item_accessible_get_type (void)
8265 static GType type = 0;
8269 const GTypeInfo tinfo =
8271 sizeof (GtkIconViewItemAccessibleClass),
8272 (GBaseInitFunc) NULL, /* base init */
8273 (GBaseFinalizeFunc) NULL, /* base finalize */
8274 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8275 (GClassFinalizeFunc) NULL, /* class finalize */
8276 NULL, /* class data */
8277 sizeof (GtkIconViewItemAccessible), /* instance size */
8278 0, /* nb preallocs */
8279 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8280 NULL /* value table */
8283 const GInterfaceInfo atk_component_info =
8285 (GInterfaceInitFunc) atk_component_item_interface_init,
8286 (GInterfaceFinalizeFunc) NULL,
8289 const GInterfaceInfo atk_action_info =
8291 (GInterfaceInitFunc) atk_action_item_interface_init,
8292 (GInterfaceFinalizeFunc) NULL,
8295 const GInterfaceInfo atk_image_info =
8297 (GInterfaceInitFunc) atk_image_item_interface_init,
8298 (GInterfaceFinalizeFunc) NULL,
8301 const GInterfaceInfo atk_text_info =
8303 (GInterfaceInitFunc) atk_text_item_interface_init,
8304 (GInterfaceFinalizeFunc) NULL,
8308 type = g_type_register_static (ATK_TYPE_OBJECT,
8309 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8310 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8311 &atk_component_info);
8312 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8314 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8316 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8323 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8324 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8325 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8327 static GType gtk_icon_view_accessible_get_type (void);
8332 } GtkIconViewAccessible;
8338 } GtkIconViewItemAccessibleInfo;
8344 GtkAdjustment *old_hadj;
8345 GtkAdjustment *old_vadj;
8347 GtkTreeModel *model;
8349 } GtkIconViewAccessiblePrivate;
8351 static GtkIconViewAccessiblePrivate *
8352 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8354 return g_object_get_qdata (G_OBJECT (accessible),
8355 accessible_private_data_quark);
8359 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8363 GtkIconViewItemAccessibleInfo *info;
8364 GtkIconViewItemAccessibleInfo *tmp_info;
8365 GtkIconViewAccessiblePrivate *priv;
8368 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8370 info->index = index;
8372 priv = gtk_icon_view_accessible_get_priv (accessible);
8373 items = priv->items;
8376 tmp_info = items->data;
8377 if (tmp_info->index > index)
8379 items = items->next;
8381 priv->items = g_list_insert_before (priv->items, items, info);
8382 priv->old_hadj = NULL;
8383 priv->old_vadj = NULL;
8387 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8389 GtkIconView *icon_view;
8392 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8396 icon_view = GTK_ICON_VIEW (widget);
8398 return g_list_length (icon_view->priv->items);
8402 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8405 GtkIconViewAccessiblePrivate *priv;
8406 GtkIconViewItemAccessibleInfo *info;
8409 priv = gtk_icon_view_accessible_get_priv (accessible);
8410 items = priv->items;
8415 if (info->index == index)
8417 items = items->next;
8423 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8426 GtkIconView *icon_view;
8430 GtkIconViewItemAccessible *a11y_item;
8432 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8436 icon_view = GTK_ICON_VIEW (widget);
8437 icons = g_list_nth (icon_view->priv->items, index);
8441 GtkIconViewItem *item = icons->data;
8443 g_return_val_if_fail (item->index == index, NULL);
8444 obj = gtk_icon_view_accessible_find_child (accessible, index);
8449 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8450 gtk_icon_view_item_accessible_info_new (accessible,
8453 obj->role = ATK_ROLE_ICON;
8454 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8455 a11y_item->item = item;
8456 a11y_item->widget = widget;
8457 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8459 text = get_text (icon_view, item);
8462 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8466 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8467 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8475 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8478 GtkIconViewAccessiblePrivate *priv;
8479 GtkIconViewItemAccessibleInfo *info;
8480 GtkIconViewItemAccessible *item;
8483 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8487 gboolean act_on_item;
8489 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8493 items = priv->items;
8495 act_on_item = (list == NULL);
8500 info = (GtkIconViewItemAccessibleInfo *)items->data;
8501 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8503 if (act_on_item == FALSE && list == items)
8507 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8509 items = items->next;
8515 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8516 GtkIconViewAccessible *view)
8518 gtk_icon_view_accessible_traverse_items (view, NULL);
8522 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8523 GtkOrientation orientation,
8524 GtkAdjustment *adjustment)
8526 GtkIconViewAccessiblePrivate *priv;
8527 GtkAdjustment **old_adj_ptr;
8529 priv = gtk_icon_view_accessible_get_priv (accessible);
8531 /* Adjustments are set for the first time in constructor and priv is not
8532 * initialized at that time, so skip this first setting. */
8536 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8538 if (priv->old_hadj == adjustment)
8541 old_adj_ptr = &priv->old_hadj;
8545 if (priv->old_vadj == adjustment)
8548 old_adj_ptr = &priv->old_vadj;
8551 /* Disconnect signal handlers */
8554 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8555 (gpointer *)&priv->old_hadj);
8556 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8557 gtk_icon_view_accessible_adjustment_changed,
8561 /* Connect signal */
8562 *old_adj_ptr = adjustment;
8563 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8564 g_signal_connect (adjustment, "value-changed",
8565 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8570 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8578 GtkIconView *icon_view;
8579 GtkIconViewItem *item;
8580 GtkIconViewItemAccessible *a11y_item;
8584 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8585 index = gtk_tree_path_get_indices(path)[0];
8586 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8587 gtk_icon_view_accessible_find_child (atk_obj, index));
8591 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8592 icon_view = GTK_ICON_VIEW (widget);
8593 item = a11y_item->item;
8595 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
8597 if (!name || strcmp (name, "") == 0)
8599 text = get_text (icon_view, item);
8602 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8608 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8614 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8619 GtkIconViewAccessiblePrivate *priv;
8620 GtkIconViewItemAccessibleInfo *info;
8621 GtkIconViewAccessible *view;
8622 GtkIconViewItemAccessible *item;
8628 index = gtk_tree_path_get_indices(path)[0];
8629 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8630 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8631 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8633 items = priv->items;
8638 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8639 if (info->index != item->item->index)
8641 if (info->index < index)
8642 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8644 if (tmp_list == NULL)
8647 info->index = item->item->index;
8650 items = items->next;
8652 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8653 g_signal_emit_by_name (atk_obj, "children-changed::add",
8659 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8663 GtkIconViewAccessiblePrivate *priv;
8664 GtkIconViewItemAccessibleInfo *info;
8665 GtkIconViewAccessible *view;
8666 GtkIconViewItemAccessible *item;
8669 GList *deleted_item;
8673 index = gtk_tree_path_get_indices(path)[0];
8674 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8675 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8676 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8678 items = priv->items;
8680 deleted_item = NULL;
8685 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8686 if (info->index == index)
8688 deleted_item = items;
8690 if (info->index != item->item->index)
8692 if (tmp_list == NULL)
8695 info->index = item->item->index;
8698 items = items->next;
8700 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8703 info = deleted_item->data;
8704 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8705 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8707 priv->items = g_list_remove_link (priv->items, deleted_item);
8715 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8716 GtkIconViewItemAccessibleInfo *i2)
8718 return i1->index - i2->index;
8722 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8728 GtkIconViewAccessiblePrivate *priv;
8729 GtkIconViewItemAccessibleInfo *info;
8730 GtkIconView *icon_view;
8731 GtkIconViewItemAccessible *item;
8737 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8738 icon_view = GTK_ICON_VIEW (user_data);
8739 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8741 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8743 order = g_new (gint, length);
8744 for (i = 0; i < length; i++)
8745 order [new_order[i]] = i;
8747 items = priv->items;
8751 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8752 info->index = order[info->index];
8753 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8754 items = items->next;
8757 priv->items = g_list_sort (priv->items,
8758 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8764 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8769 obj = G_OBJECT (model);
8770 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8771 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8772 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8773 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8777 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8781 obj = G_OBJECT (icon_view->priv->model);
8782 g_signal_connect_data (obj, "row-changed",
8783 (GCallback) gtk_icon_view_accessible_model_row_changed,
8784 icon_view, NULL, 0);
8785 g_signal_connect_data (obj, "row-inserted",
8786 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8787 icon_view, NULL, G_CONNECT_AFTER);
8788 g_signal_connect_data (obj, "row-deleted",
8789 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8790 icon_view, NULL, G_CONNECT_AFTER);
8791 g_signal_connect_data (obj, "rows-reordered",
8792 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8793 icon_view, NULL, G_CONNECT_AFTER);
8797 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8799 GtkIconViewItemAccessibleInfo *info;
8802 items = priv->items;
8805 info = (GtkIconViewItemAccessibleInfo *) items->data;
8806 g_object_unref (info->item);
8807 g_free (items->data);
8808 items = items->next;
8810 g_list_free (priv->items);
8815 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8818 GtkIconView *icon_view;
8821 GtkIconViewAccessiblePrivate *priv;
8823 if (strcmp (pspec->name, "model") == 0)
8825 widget = GTK_WIDGET (obj);
8826 atk_obj = gtk_widget_get_accessible (widget);
8827 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8830 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8831 (gpointer *)&priv->model);
8832 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8834 gtk_icon_view_accessible_clear_cache (priv);
8836 icon_view = GTK_ICON_VIEW (obj);
8837 priv->model = icon_view->priv->model;
8838 /* If there is no model the GtkIconView is probably being destroyed */
8841 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8842 gtk_icon_view_accessible_connect_model_signals (icon_view);
8850 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8853 GtkIconViewAccessiblePrivate *priv;
8854 GtkIconView *icon_view;
8856 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8857 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8859 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8860 g_object_set_qdata (G_OBJECT (accessible),
8861 accessible_private_data_quark,
8864 icon_view = GTK_ICON_VIEW (data);
8865 if (icon_view->priv->hadjustment)
8866 gtk_icon_view_accessible_set_adjustment (accessible,
8867 GTK_ORIENTATION_HORIZONTAL,
8868 icon_view->priv->hadjustment);
8869 if (icon_view->priv->vadjustment)
8870 gtk_icon_view_accessible_set_adjustment (accessible,
8871 GTK_ORIENTATION_VERTICAL,
8872 icon_view->priv->vadjustment);
8873 g_signal_connect (data,
8875 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8878 priv->model = icon_view->priv->model;
8881 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8882 gtk_icon_view_accessible_connect_model_signals (icon_view);
8885 accessible->role = ATK_ROLE_LAYERED_PANE;
8889 gtk_icon_view_accessible_finalize (GObject *object)
8891 GtkIconViewAccessiblePrivate *priv;
8893 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8894 gtk_icon_view_accessible_clear_cache (priv);
8898 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8902 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8903 GtkAccessible *accessible)
8906 GtkIconViewAccessiblePrivate *priv;
8908 atk_obj = ATK_OBJECT (accessible);
8909 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8912 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8913 (gpointer *)&priv->old_hadj);
8915 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8916 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8918 priv->old_hadj = NULL;
8922 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8923 (gpointer *)&priv->old_vadj);
8925 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8926 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8928 priv->old_vadj = NULL;
8933 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8937 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8940 g_signal_connect_after (widget,
8942 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8945 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8949 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8951 GObjectClass *gobject_class;
8952 GtkAccessibleClass *accessible_class;
8954 accessible_parent_class = g_type_class_peek_parent (klass);
8956 gobject_class = (GObjectClass *)klass;
8957 accessible_class = (GtkAccessibleClass *)klass;
8959 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8961 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8962 klass->ref_child = gtk_icon_view_accessible_ref_child;
8963 klass->initialize = gtk_icon_view_accessible_initialize;
8965 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8967 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8971 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8974 AtkCoordType coord_type)
8977 GtkIconView *icon_view;
8978 GtkIconViewItem *item;
8981 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8983 /* State is defunct */
8986 icon_view = GTK_ICON_VIEW (widget);
8987 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8988 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8990 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8996 atk_component_interface_init (AtkComponentIface *iface)
8998 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9002 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9006 GtkIconView *icon_view;
9007 GtkIconViewItem *item;
9009 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9013 icon_view = GTK_ICON_VIEW (widget);
9015 item = g_list_nth_data (icon_view->priv->items, i);
9020 gtk_icon_view_select_item (icon_view, item);
9026 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9029 GtkIconView *icon_view;
9031 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9035 icon_view = GTK_ICON_VIEW (widget);
9036 gtk_icon_view_unselect_all (icon_view);
9042 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9047 GtkIconView *icon_view;
9048 GtkIconViewItem *item;
9050 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9054 icon_view = GTK_ICON_VIEW (widget);
9056 l = icon_view->priv->items;
9063 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9074 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9077 GtkIconView *icon_view;
9078 GtkIconViewItem *item;
9082 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9086 icon_view = GTK_ICON_VIEW (widget);
9088 l = icon_view->priv->items;
9104 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9108 GtkIconView *icon_view;
9109 GtkIconViewItem *item;
9111 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9115 icon_view = GTK_ICON_VIEW (widget);
9117 item = g_list_nth_data (icon_view->priv->items, i);
9121 return item->selected;
9125 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9129 GtkIconView *icon_view;
9130 GtkIconViewItem *item;
9134 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9138 icon_view = GTK_ICON_VIEW (widget);
9139 l = icon_view->priv->items;
9148 gtk_icon_view_unselect_item (icon_view, item);
9160 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9163 GtkIconView *icon_view;
9165 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9169 icon_view = GTK_ICON_VIEW (widget);
9170 gtk_icon_view_select_all (icon_view);
9175 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9177 iface->add_selection = gtk_icon_view_accessible_add_selection;
9178 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9179 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9180 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9181 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9182 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9183 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9187 gtk_icon_view_accessible_get_type (void)
9189 static GType type = 0;
9196 (GBaseInitFunc) NULL, /* base init */
9197 (GBaseFinalizeFunc) NULL, /* base finalize */
9198 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9199 (GClassFinalizeFunc) NULL, /* class finalize */
9200 NULL, /* class data */
9201 0, /* instance size */
9202 0, /* nb preallocs */
9203 (GInstanceInitFunc) NULL, /* instance init */
9204 NULL /* value table */
9206 const GInterfaceInfo atk_component_info =
9208 (GInterfaceInitFunc) atk_component_interface_init,
9209 (GInterfaceFinalizeFunc) NULL,
9212 const GInterfaceInfo atk_selection_info =
9214 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9215 (GInterfaceFinalizeFunc) NULL,
9220 * Figure out the size of the class and instance
9221 * we are deriving from
9223 AtkObjectFactory *factory;
9226 GType derived_atk_type;
9228 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9229 factory = atk_registry_get_factory (atk_get_default_registry (),
9231 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9232 g_type_query (derived_atk_type, &query);
9233 tinfo.class_size = query.class_size;
9234 tinfo.instance_size = query.instance_size;
9236 type = g_type_register_static (derived_atk_type,
9237 I_("GtkIconViewAccessible"),
9239 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9240 &atk_component_info);
9241 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9242 &atk_selection_info);
9248 gtk_icon_view_accessible_new (GObject *obj)
9250 AtkObject *accessible;
9252 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9254 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9255 atk_object_initialize (accessible, obj);
9261 gtk_icon_view_accessible_factory_get_accessible_type (void)
9263 return gtk_icon_view_accessible_get_type ();
9267 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9269 return gtk_icon_view_accessible_new (obj);
9273 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9275 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9276 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9280 gtk_icon_view_accessible_factory_get_type (void)
9282 static GType type = 0;
9286 const GTypeInfo tinfo =
9288 sizeof (AtkObjectFactoryClass),
9289 NULL, /* base_init */
9290 NULL, /* base_finalize */
9291 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9292 NULL, /* class_finalize */
9293 NULL, /* class_data */
9294 sizeof (AtkObjectFactory),
9295 0, /* n_preallocs */
9299 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9300 I_("GtkIconViewAccessibleFactory"),
9308 gtk_icon_view_get_accessible (GtkWidget *widget)
9310 static gboolean first_time = TRUE;
9314 _gtk_accessible_set_factory_type (GTK_TYPE_ICON_VIEW,
9315 gtk_icon_view_accessible_factory_get_type ());
9318 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9322 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9323 GtkBuilder *builder,
9325 const gchar *tagname,
9326 GMarkupParser *parser,
9329 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9330 tagname, parser, data))
9333 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9334 tagname, parser, data);
9338 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9339 GtkBuilder *builder,
9341 const gchar *tagname,
9344 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9345 child, tagname, data))
9346 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,