2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gtkiconview.h"
27 #include "gtkcelllayout.h"
28 #include "gtkcellrenderer.h"
29 #include "gtkcellareabox.h"
30 #include "gtkcellareacontext.h"
31 #include "gtkcellrenderertext.h"
32 #include "gtkcellrendererpixbuf.h"
33 #include "gtkorientable.h"
34 #include "gtkmarshalers.h"
35 #include "gtkbindings.h"
39 #include "gtkaccessible.h"
40 #include "gtkwindow.h"
42 #include "gtkcombobox.h"
43 #include "gtktextbuffer.h"
44 #include "gtkscrollable.h"
45 #include "gtksizerequest.h"
46 #include "gtktreednd.h"
47 #include "gtktypebuiltins.h"
48 #include "gtkprivate.h"
53 * @short_description: A widget which displays a list of icons in a grid
55 * #GtkIconView provides an alternative view on a #GtkTreeModel.
56 * It displays the model as a grid of icons with labels. Like
57 * #GtkTreeView, it allows to select one or multiple items
58 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
59 * In addition to selection with the arrow keys, #GtkIconView supports
60 * rubberband selection, which is controlled by dragging the pointer.
62 * Note that if the tree model is backed by an actual tree store (as
63 * opposed to a flat list where the mapping to icons is obvious),
64 * #GtkIconView will only display the first level of the tree and
65 * ignore the tree's branches.
68 #define SCROLL_EDGE_SIZE 15
70 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
72 typedef struct _GtkIconViewItem GtkIconViewItem;
73 struct _GtkIconViewItem
75 /* First member is always the rectangle so it
76 * can be cast to a rectangle. */
77 GdkRectangle cell_area;
85 guint selected_before_rubberbanding : 1;
89 typedef struct _GtkIconViewChild GtkIconViewChild;
90 struct _GtkIconViewChild
96 struct _GtkIconViewPrivate
98 GtkCellArea *cell_area;
99 GtkCellAreaContext *cell_area_context;
101 gulong add_editable_id;
102 gulong remove_editable_id;
103 gulong context_changed_id;
105 GPtrArray *row_contexts;
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gint rubberband_x1, rubberband_y1;
125 gint rubberband_x2, rubberband_y2;
126 GdkDevice *rubberband_device;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *last_single_clicked;
137 GtkOrientation item_orientation;
151 GtkCellRenderer *pixbuf_cell;
152 GtkCellRenderer *text_cell;
157 GdkModifierType start_button_mask;
162 GdkDragAction source_actions;
163 GdkDragAction dest_actions;
165 GtkTreeRowReference *dest_item;
166 GtkIconViewDropPosition dest_pos;
169 GtkTreeRowReference *scroll_to_path;
170 gfloat scroll_to_row_align;
171 gfloat scroll_to_col_align;
172 guint scroll_to_use_align : 1;
174 guint source_set : 1;
176 guint reorderable : 1;
177 guint empty_view_drop :1;
179 guint ctrl_pressed : 1;
180 guint shift_pressed : 1;
182 guint draw_focus : 1;
184 /* GtkScrollablePolicy needs to be checked when
185 * driving the scrollable adjustment values */
186 guint hscroll_policy : 1;
187 guint vscroll_policy : 1;
189 guint doing_rubberband : 1;
203 ACTIVATE_CURSOR_ITEM,
215 PROP_ITEM_ORIENTATION,
228 /* For scrollable interface */
236 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
237 static void gtk_icon_view_dispose (GObject *object);
238 static GObject *gtk_icon_view_constructor (GType type,
239 guint n_construct_properties,
240 GObjectConstructParam *construct_properties);
241 static void gtk_icon_view_set_property (GObject *object,
245 static void gtk_icon_view_get_property (GObject *object,
249 /* GtkWidget vfuncs */
250 static void gtk_icon_view_destroy (GtkWidget *widget);
251 static void gtk_icon_view_realize (GtkWidget *widget);
252 static void gtk_icon_view_unrealize (GtkWidget *widget);
253 static void gtk_icon_view_style_updated (GtkWidget *widget);
254 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
255 GtkStateFlags previous_state);
256 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
259 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
262 static void gtk_icon_view_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static gboolean gtk_icon_view_draw (GtkWidget *widget,
266 static gboolean gtk_icon_view_motion (GtkWidget *widget,
267 GdkEventMotion *event);
268 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
274 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
276 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
279 /* GtkContainer vfuncs */
280 static void gtk_icon_view_remove (GtkContainer *container,
282 static void gtk_icon_view_forall (GtkContainer *container,
283 gboolean include_internals,
284 GtkCallback callback,
285 gpointer callback_data);
287 /* GtkIconView vfuncs */
288 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
289 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
291 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
292 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
294 /* Internal functions */
295 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
296 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
297 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
298 GtkAdjustment *adjustment);
299 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
300 GtkAdjustment *adjustment);
301 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
302 GtkOrientation orientation,
303 GtkAdjustment *adjustment);
304 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
305 GtkIconView *icon_view);
306 static void gtk_icon_view_layout (GtkIconView *icon_view);
307 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
309 GtkIconViewItem *item,
312 gboolean draw_focus);
313 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
315 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
317 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
318 GtkIconViewItem *item);
319 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
320 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
321 GtkIconViewItem *item,
322 GtkCellRenderer *cursor_cell);
323 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
327 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
328 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
329 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
330 GtkIconViewItem *item,
335 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
336 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
337 static void gtk_icon_view_update_rubberband (gpointer data);
338 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
339 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
340 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
343 GtkMovementStep step,
345 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
346 GtkMovementStep step,
348 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
350 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
352 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
354 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
356 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
357 GtkIconViewItem *item);
358 static void gtk_icon_view_select_item (GtkIconView *icon_view,
359 GtkIconViewItem *item);
360 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
363 GtkIconViewItem *anchor,
364 GtkIconViewItem *cursor);
365 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
368 gboolean only_in_cell,
369 GtkCellRenderer **cell_at_pos);
370 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
371 GtkIconViewItem *item);
373 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
374 GtkCellArea *cell_area);
376 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
378 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
379 GtkIconViewItem *item);
381 static void gtk_icon_view_add_editable (GtkCellArea *area,
382 GtkCellRenderer *renderer,
383 GtkCellEditable *editable,
384 GdkRectangle *cell_area,
386 GtkIconView *icon_view);
387 static void gtk_icon_view_remove_editable (GtkCellArea *area,
388 GtkCellRenderer *renderer,
389 GtkCellEditable *editable,
390 GtkIconView *icon_view);
391 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
393 GtkIconView *icon_view);
395 /* Source side drag signals */
396 static void gtk_icon_view_drag_begin (GtkWidget *widget,
397 GdkDragContext *context);
398 static void gtk_icon_view_drag_end (GtkWidget *widget,
399 GdkDragContext *context);
400 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
401 GdkDragContext *context,
402 GtkSelectionData *selection_data,
405 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
406 GdkDragContext *context);
408 /* Target side drag signals */
409 static void gtk_icon_view_drag_leave (GtkWidget *widget,
410 GdkDragContext *context,
412 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
413 GdkDragContext *context,
417 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
418 GdkDragContext *context,
422 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
423 GdkDragContext *context,
426 GtkSelectionData *selection_data,
429 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
430 GdkEventMotion *event);
432 static void remove_scroll_timeout (GtkIconView *icon_view);
435 static GtkBuildableIface *parent_buildable_iface;
436 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
437 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
440 const gchar *tagname,
441 GMarkupParser *parser,
443 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
446 const gchar *tagname,
449 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
451 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
452 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
453 gtk_icon_view_cell_layout_init)
454 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
455 gtk_icon_view_buildable_init)
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
459 gtk_icon_view_class_init (GtkIconViewClass *klass)
461 GObjectClass *gobject_class;
462 GtkWidgetClass *widget_class;
463 GtkContainerClass *container_class;
464 GtkBindingSet *binding_set;
466 binding_set = gtk_binding_set_by_class (klass);
468 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
470 gobject_class = (GObjectClass *) klass;
471 widget_class = (GtkWidgetClass *) klass;
472 container_class = (GtkContainerClass *) klass;
474 gobject_class->constructor = gtk_icon_view_constructor;
475 gobject_class->dispose = gtk_icon_view_dispose;
476 gobject_class->set_property = gtk_icon_view_set_property;
477 gobject_class->get_property = gtk_icon_view_get_property;
479 widget_class->destroy = gtk_icon_view_destroy;
480 widget_class->realize = gtk_icon_view_realize;
481 widget_class->unrealize = gtk_icon_view_unrealize;
482 widget_class->style_updated = gtk_icon_view_style_updated;
483 widget_class->get_accessible = gtk_icon_view_get_accessible;
484 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
485 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
486 widget_class->size_allocate = gtk_icon_view_size_allocate;
487 widget_class->draw = gtk_icon_view_draw;
488 widget_class->motion_notify_event = gtk_icon_view_motion;
489 widget_class->button_press_event = gtk_icon_view_button_press;
490 widget_class->button_release_event = gtk_icon_view_button_release;
491 widget_class->key_press_event = gtk_icon_view_key_press;
492 widget_class->key_release_event = gtk_icon_view_key_release;
493 widget_class->drag_begin = gtk_icon_view_drag_begin;
494 widget_class->drag_end = gtk_icon_view_drag_end;
495 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
496 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
497 widget_class->drag_leave = gtk_icon_view_drag_leave;
498 widget_class->drag_motion = gtk_icon_view_drag_motion;
499 widget_class->drag_drop = gtk_icon_view_drag_drop;
500 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
501 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
503 container_class->remove = gtk_icon_view_remove;
504 container_class->forall = gtk_icon_view_forall;
506 klass->select_all = gtk_icon_view_real_select_all;
507 klass->unselect_all = gtk_icon_view_real_unselect_all;
508 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
509 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
510 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
511 klass->move_cursor = gtk_icon_view_real_move_cursor;
515 * GtkIconView:selection-mode:
517 * The ::selection-mode property specifies the selection mode of
518 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
519 * is enabled, for the other modes, only keyboard selection is possible.
523 g_object_class_install_property (gobject_class,
525 g_param_spec_enum ("selection-mode",
526 P_("Selection mode"),
527 P_("The selection mode"),
528 GTK_TYPE_SELECTION_MODE,
529 GTK_SELECTION_SINGLE,
530 GTK_PARAM_READWRITE));
533 * GtkIconView:pixbuf-column:
535 * The ::pixbuf-column property contains the number of the model column
536 * containing the pixbufs which are displayed. The pixbuf column must be
537 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
538 * display of pixbufs.
542 g_object_class_install_property (gobject_class,
544 g_param_spec_int ("pixbuf-column",
546 P_("Model column used to retrieve the icon pixbuf from"),
548 GTK_PARAM_READWRITE));
551 * GtkIconView:text-column:
553 * The ::text-column property contains the number of the model column
554 * containing the texts which are displayed. The text column must be
555 * of type #G_TYPE_STRING. If this property and the :markup-column
556 * property are both set to -1, no texts are displayed.
560 g_object_class_install_property (gobject_class,
562 g_param_spec_int ("text-column",
564 P_("Model column used to retrieve the text from"),
566 GTK_PARAM_READWRITE));
570 * GtkIconView:markup-column:
572 * The ::markup-column property contains the number of the model column
573 * containing markup information to be displayed. The markup column must be
574 * of type #G_TYPE_STRING. If this property and the :text-column property
575 * are both set to column numbers, it overrides the text column.
576 * If both are set to -1, no texts are displayed.
580 g_object_class_install_property (gobject_class,
582 g_param_spec_int ("markup-column",
584 P_("Model column used to retrieve the text if using Pango markup"),
586 GTK_PARAM_READWRITE));
588 g_object_class_install_property (gobject_class,
590 g_param_spec_object ("model",
591 P_("Icon View Model"),
592 P_("The model for the icon view"),
594 GTK_PARAM_READWRITE));
597 * GtkIconView:columns:
599 * The columns property contains the number of the columns in which the
600 * items should be displayed. If it is -1, the number of columns will
601 * be chosen automatically to fill the available area.
605 g_object_class_install_property (gobject_class,
607 g_param_spec_int ("columns",
608 P_("Number of columns"),
609 P_("Number of columns to display"),
611 GTK_PARAM_READWRITE));
615 * GtkIconView:item-width:
617 * The item-width property specifies the width to use for each item.
618 * If it is set to -1, the icon view will automatically determine a
619 * suitable item size.
623 g_object_class_install_property (gobject_class,
625 g_param_spec_int ("item-width",
626 P_("Width for each item"),
627 P_("The width used for each item"),
629 GTK_PARAM_READWRITE));
632 * GtkIconView:spacing:
634 * The spacing property specifies the space which is inserted between
635 * the cells (i.e. the icon and the text) of an item.
639 g_object_class_install_property (gobject_class,
641 g_param_spec_int ("spacing",
643 P_("Space which is inserted between cells of an item"),
645 GTK_PARAM_READWRITE));
648 * GtkIconView:row-spacing:
650 * The row-spacing property specifies the space which is inserted between
651 * the rows of the icon view.
655 g_object_class_install_property (gobject_class,
657 g_param_spec_int ("row-spacing",
659 P_("Space which is inserted between grid rows"),
661 GTK_PARAM_READWRITE));
664 * GtkIconView:column-spacing:
666 * The column-spacing property specifies the space which is inserted between
667 * the columns of the icon view.
671 g_object_class_install_property (gobject_class,
673 g_param_spec_int ("column-spacing",
674 P_("Column Spacing"),
675 P_("Space which is inserted between grid columns"),
677 GTK_PARAM_READWRITE));
680 * GtkIconView:margin:
682 * The margin property specifies the space which is inserted
683 * at the edges of the icon view.
687 g_object_class_install_property (gobject_class,
689 g_param_spec_int ("margin",
691 P_("Space which is inserted at the edges of the icon view"),
693 GTK_PARAM_READWRITE));
696 * GtkIconView:item-orientation:
698 * The item-orientation property specifies how the cells (i.e. the icon and
699 * the text) of the item are positioned relative to each other.
703 g_object_class_install_property (gobject_class,
704 PROP_ITEM_ORIENTATION,
705 g_param_spec_enum ("item-orientation",
706 P_("Item Orientation"),
707 P_("How the text and icon of each item are positioned relative to each other"),
708 GTK_TYPE_ORIENTATION,
709 GTK_ORIENTATION_VERTICAL,
710 GTK_PARAM_READWRITE));
713 * GtkIconView:reorderable:
715 * The reorderable property specifies if the items can be reordered
720 g_object_class_install_property (gobject_class,
722 g_param_spec_boolean ("reorderable",
724 P_("View is reorderable"),
728 g_object_class_install_property (gobject_class,
730 g_param_spec_int ("tooltip-column",
731 P_("Tooltip Column"),
732 P_("The column in the model containing the tooltip texts for the items"),
736 GTK_PARAM_READWRITE));
739 * GtkIconView:item-padding:
741 * The item-padding property specifies the padding around each
742 * of the icon view's item.
746 g_object_class_install_property (gobject_class,
748 g_param_spec_int ("item-padding",
750 P_("Padding around icon view items"),
752 GTK_PARAM_READWRITE));
755 * GtkIconView:cell-area:
757 * The #GtkCellArea used to layout cell renderers for this view.
761 g_object_class_install_property (gobject_class,
763 g_param_spec_object ("cell-area",
765 P_("The GtkCellArea used to layout cells"),
767 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
769 /* Scrollable interface properties */
770 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
771 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
772 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
773 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
775 /* Style properties */
776 gtk_widget_class_install_style_property (widget_class,
777 g_param_spec_boxed ("selection-box-color",
778 P_("Selection Box Color"),
779 P_("Color of the selection box"),
781 GTK_PARAM_READABLE));
783 gtk_widget_class_install_style_property (widget_class,
784 g_param_spec_uchar ("selection-box-alpha",
785 P_("Selection Box Alpha"),
786 P_("Opacity of the selection box"),
789 GTK_PARAM_READABLE));
793 * GtkIconView::item-activated:
794 * @iconview: the object on which the signal is emitted
795 * @path: the #GtkTreePath for the activated item
797 * The ::item-activated signal is emitted when the method
798 * gtk_icon_view_item_activated() is called or the user double
799 * clicks an item. It is also emitted when a non-editable item
800 * is selected and one of the keys: Space, Return or Enter is
803 icon_view_signals[ITEM_ACTIVATED] =
804 g_signal_new (I_("item-activated"),
805 G_TYPE_FROM_CLASS (gobject_class),
807 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
809 g_cclosure_marshal_VOID__BOXED,
814 * GtkIconView::selection-changed:
815 * @iconview: the object on which the signal is emitted
817 * The ::selection-changed signal is emitted when the selection
818 * (i.e. the set of selected items) changes.
820 icon_view_signals[SELECTION_CHANGED] =
821 g_signal_new (I_("selection-changed"),
822 G_TYPE_FROM_CLASS (gobject_class),
824 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
826 g_cclosure_marshal_VOID__VOID,
830 * GtkIconView::select-all:
831 * @iconview: the object on which the signal is emitted
833 * A <link linkend="keybinding-signals">keybinding signal</link>
834 * which gets emitted when the user selects all items.
836 * Applications should not connect to it, but may emit it with
837 * g_signal_emit_by_name() if they need to control selection
840 * The default binding for this signal is Ctrl-a.
842 icon_view_signals[SELECT_ALL] =
843 g_signal_new (I_("select-all"),
844 G_TYPE_FROM_CLASS (gobject_class),
845 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
846 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
848 g_cclosure_marshal_VOID__VOID,
852 * GtkIconView::unselect-all:
853 * @iconview: the object on which the signal is emitted
855 * A <link linkend="keybinding-signals">keybinding signal</link>
856 * which gets emitted when the user unselects all items.
858 * Applications should not connect to it, but may emit it with
859 * g_signal_emit_by_name() if they need to control selection
862 * The default binding for this signal is Ctrl-Shift-a.
864 icon_view_signals[UNSELECT_ALL] =
865 g_signal_new (I_("unselect-all"),
866 G_TYPE_FROM_CLASS (gobject_class),
867 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
868 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
870 g_cclosure_marshal_VOID__VOID,
874 * GtkIconView::select-cursor-item:
875 * @iconview: the object on which the signal is emitted
877 * A <link linkend="keybinding-signals">keybinding signal</link>
878 * which gets emitted when the user selects the item that is currently
881 * Applications should not connect to it, but may emit it with
882 * g_signal_emit_by_name() if they need to control selection
885 * There is no default binding for this signal.
887 icon_view_signals[SELECT_CURSOR_ITEM] =
888 g_signal_new (I_("select-cursor-item"),
889 G_TYPE_FROM_CLASS (gobject_class),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
893 g_cclosure_marshal_VOID__VOID,
897 * GtkIconView::toggle-cursor-item:
898 * @iconview: the object on which the signal is emitted
900 * A <link linkend="keybinding-signals">keybinding signal</link>
901 * which gets emitted when the user toggles whether the currently
902 * focused item is selected or not. The exact effect of this
903 * depend on the selection mode.
905 * Applications should not connect to it, but may emit it with
906 * g_signal_emit_by_name() if they need to control selection
909 * There is no default binding for this signal is Ctrl-Space.
911 icon_view_signals[TOGGLE_CURSOR_ITEM] =
912 g_signal_new (I_("toggle-cursor-item"),
913 G_TYPE_FROM_CLASS (gobject_class),
914 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
915 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
917 g_cclosure_marshal_VOID__VOID,
921 * GtkIconView::activate-cursor-item:
922 * @iconview: the object on which the signal is emitted
924 * A <link linkend="keybinding-signals">keybinding signal</link>
925 * which gets emitted when the user activates the currently
928 * Applications should not connect to it, but may emit it with
929 * g_signal_emit_by_name() if they need to control activation
932 * The default bindings for this signal are Space, Return and Enter.
934 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
935 g_signal_new (I_("activate-cursor-item"),
936 G_TYPE_FROM_CLASS (gobject_class),
937 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
938 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
940 _gtk_marshal_BOOLEAN__VOID,
944 * GtkIconView::move-cursor:
945 * @iconview: the object which received the signal
946 * @step: the granularity of the move, as a #GtkMovementStep
947 * @count: the number of @step units to move
949 * The ::move-cursor signal is a
950 * <link linkend="keybinding-signals">keybinding signal</link>
951 * which gets emitted when the user initiates a cursor movement.
953 * Applications should not connect to it, but may emit it with
954 * g_signal_emit_by_name() if they need to control the cursor
957 * The default bindings for this signal include
959 * <listitem>Arrow keys which move by individual steps</listitem>
960 * <listitem>Home/End keys which move to the first/last item</listitem>
961 * <listitem>PageUp/PageDown which move by "pages"</listitem>
964 * All of these will extend the selection when combined with
965 * the Shift modifier.
967 icon_view_signals[MOVE_CURSOR] =
968 g_signal_new (I_("move-cursor"),
969 G_TYPE_FROM_CLASS (gobject_class),
970 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
971 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
973 _gtk_marshal_BOOLEAN__ENUM_INT,
975 GTK_TYPE_MOVEMENT_STEP,
979 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
981 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
983 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
984 "toggle-cursor-item", 0);
985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
986 "toggle-cursor-item", 0);
988 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
989 "activate-cursor-item", 0);
990 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
991 "activate-cursor-item", 0);
992 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
993 "activate-cursor-item", 0);
994 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
995 "activate-cursor-item", 0);
996 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
997 "activate-cursor-item", 0);
999 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1000 GTK_MOVEMENT_DISPLAY_LINES, -1);
1001 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1002 GTK_MOVEMENT_DISPLAY_LINES, -1);
1004 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1005 GTK_MOVEMENT_DISPLAY_LINES, 1);
1006 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1007 GTK_MOVEMENT_DISPLAY_LINES, 1);
1009 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1010 GTK_MOVEMENT_DISPLAY_LINES, -1);
1012 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1013 GTK_MOVEMENT_DISPLAY_LINES, 1);
1015 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1016 GTK_MOVEMENT_BUFFER_ENDS, -1);
1017 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1018 GTK_MOVEMENT_BUFFER_ENDS, -1);
1020 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1021 GTK_MOVEMENT_BUFFER_ENDS, 1);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1023 GTK_MOVEMENT_BUFFER_ENDS, 1);
1025 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1026 GTK_MOVEMENT_PAGES, -1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1028 GTK_MOVEMENT_PAGES, -1);
1030 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1031 GTK_MOVEMENT_PAGES, 1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1033 GTK_MOVEMENT_PAGES, 1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1036 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1038 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1041 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1043 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1047 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1049 parent_buildable_iface = g_type_interface_peek_parent (iface);
1050 iface->add_child = _gtk_cell_layout_buildable_add_child;
1051 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1052 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1056 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1058 iface->get_area = gtk_icon_view_cell_layout_get_area;
1062 gtk_icon_view_init (GtkIconView *icon_view)
1064 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1066 GtkIconViewPrivate);
1068 icon_view->priv->width = 0;
1069 icon_view->priv->height = 0;
1070 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1071 icon_view->priv->pressed_button = -1;
1072 icon_view->priv->press_start_x = -1;
1073 icon_view->priv->press_start_y = -1;
1074 icon_view->priv->text_column = -1;
1075 icon_view->priv->markup_column = -1;
1076 icon_view->priv->pixbuf_column = -1;
1077 icon_view->priv->text_cell = NULL;
1078 icon_view->priv->pixbuf_cell = NULL;
1079 icon_view->priv->tooltip_column = -1;
1081 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1083 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1085 icon_view->priv->columns = -1;
1086 icon_view->priv->item_width = -1;
1087 icon_view->priv->spacing = 0;
1088 icon_view->priv->row_spacing = 6;
1089 icon_view->priv->column_spacing = 6;
1090 icon_view->priv->margin = 6;
1091 icon_view->priv->item_padding = 6;
1093 icon_view->priv->draw_focus = TRUE;
1095 icon_view->priv->row_contexts =
1096 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1099 /* GObject methods */
1101 gtk_icon_view_constructor (GType type,
1102 guint n_construct_properties,
1103 GObjectConstructParam *construct_properties)
1105 GtkIconView *icon_view;
1108 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1109 (type, n_construct_properties, construct_properties);
1111 icon_view = (GtkIconView *) object;
1113 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1119 gtk_icon_view_dispose (GObject *object)
1121 GtkIconView *icon_view;
1122 GtkIconViewPrivate *priv;
1124 icon_view = GTK_ICON_VIEW (object);
1125 priv = icon_view->priv;
1127 if (priv->cell_area_context)
1129 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1130 priv->context_changed_id = 0;
1132 g_object_unref (priv->cell_area_context);
1133 priv->cell_area_context = NULL;
1136 if (priv->row_contexts)
1138 g_ptr_array_free (priv->row_contexts, TRUE);
1139 priv->row_contexts = NULL;
1142 if (priv->cell_area)
1144 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1146 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1147 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1148 priv->add_editable_id = 0;
1149 priv->remove_editable_id = 0;
1151 g_object_unref (priv->cell_area);
1152 priv->cell_area = NULL;
1155 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1159 gtk_icon_view_set_property (GObject *object,
1161 const GValue *value,
1164 GtkIconView *icon_view;
1167 icon_view = GTK_ICON_VIEW (object);
1171 case PROP_SELECTION_MODE:
1172 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1174 case PROP_PIXBUF_COLUMN:
1175 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1177 case PROP_TEXT_COLUMN:
1178 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1180 case PROP_MARKUP_COLUMN:
1181 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1184 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1186 case PROP_ITEM_ORIENTATION:
1187 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1190 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1192 case PROP_ITEM_WIDTH:
1193 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1196 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1198 case PROP_ROW_SPACING:
1199 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1201 case PROP_COLUMN_SPACING:
1202 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1205 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1207 case PROP_REORDERABLE:
1208 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1211 case PROP_TOOLTIP_COLUMN:
1212 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1215 case PROP_ITEM_PADDING:
1216 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1219 case PROP_CELL_AREA:
1220 /* Construct-only, can only be assigned once */
1221 area = g_value_get_object (value);
1224 if (icon_view->priv->cell_area != NULL)
1226 g_warning ("cell-area has already been set, ignoring construct property");
1227 g_object_ref_sink (area);
1228 g_object_unref (area);
1231 gtk_icon_view_ensure_cell_area (icon_view, area);
1235 case PROP_HADJUSTMENT:
1236 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1238 case PROP_VADJUSTMENT:
1239 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1241 case PROP_HSCROLL_POLICY:
1242 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1243 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1245 case PROP_VSCROLL_POLICY:
1246 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1247 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1251 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1257 gtk_icon_view_get_property (GObject *object,
1262 GtkIconView *icon_view;
1264 icon_view = GTK_ICON_VIEW (object);
1268 case PROP_SELECTION_MODE:
1269 g_value_set_enum (value, icon_view->priv->selection_mode);
1271 case PROP_PIXBUF_COLUMN:
1272 g_value_set_int (value, icon_view->priv->pixbuf_column);
1274 case PROP_TEXT_COLUMN:
1275 g_value_set_int (value, icon_view->priv->text_column);
1277 case PROP_MARKUP_COLUMN:
1278 g_value_set_int (value, icon_view->priv->markup_column);
1281 g_value_set_object (value, icon_view->priv->model);
1283 case PROP_ITEM_ORIENTATION:
1284 g_value_set_enum (value, icon_view->priv->item_orientation);
1287 g_value_set_int (value, icon_view->priv->columns);
1289 case PROP_ITEM_WIDTH:
1290 g_value_set_int (value, icon_view->priv->item_width);
1293 g_value_set_int (value, icon_view->priv->spacing);
1295 case PROP_ROW_SPACING:
1296 g_value_set_int (value, icon_view->priv->row_spacing);
1298 case PROP_COLUMN_SPACING:
1299 g_value_set_int (value, icon_view->priv->column_spacing);
1302 g_value_set_int (value, icon_view->priv->margin);
1304 case PROP_REORDERABLE:
1305 g_value_set_boolean (value, icon_view->priv->reorderable);
1307 case PROP_TOOLTIP_COLUMN:
1308 g_value_set_int (value, icon_view->priv->tooltip_column);
1311 case PROP_ITEM_PADDING:
1312 g_value_set_int (value, icon_view->priv->item_padding);
1315 case PROP_CELL_AREA:
1316 g_value_set_object (value, icon_view->priv->cell_area);
1319 case PROP_HADJUSTMENT:
1320 g_value_set_object (value, icon_view->priv->hadjustment);
1322 case PROP_VADJUSTMENT:
1323 g_value_set_object (value, icon_view->priv->vadjustment);
1325 case PROP_HSCROLL_POLICY:
1326 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1328 case PROP_VSCROLL_POLICY:
1329 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1338 /* GtkWidget methods */
1340 gtk_icon_view_destroy (GtkWidget *widget)
1342 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1344 gtk_icon_view_set_model (icon_view, NULL);
1346 if (icon_view->priv->layout_idle_id != 0)
1348 g_source_remove (icon_view->priv->layout_idle_id);
1349 icon_view->priv->layout_idle_id = 0;
1352 if (icon_view->priv->scroll_to_path != NULL)
1354 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1355 icon_view->priv->scroll_to_path = NULL;
1358 remove_scroll_timeout (icon_view);
1360 if (icon_view->priv->hadjustment != NULL)
1362 g_object_unref (icon_view->priv->hadjustment);
1363 icon_view->priv->hadjustment = NULL;
1366 if (icon_view->priv->vadjustment != NULL)
1368 g_object_unref (icon_view->priv->vadjustment);
1369 icon_view->priv->vadjustment = NULL;
1372 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1376 gtk_icon_view_realize (GtkWidget *widget)
1378 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1379 GtkAllocation allocation;
1381 GdkWindowAttr attributes;
1382 gint attributes_mask;
1383 GtkStyleContext *context;
1385 gtk_widget_set_realized (widget, TRUE);
1387 gtk_widget_get_allocation (widget, &allocation);
1389 /* Make the main, clipping window */
1390 attributes.window_type = GDK_WINDOW_CHILD;
1391 attributes.x = allocation.x;
1392 attributes.y = allocation.y;
1393 attributes.width = allocation.width;
1394 attributes.height = allocation.height;
1395 attributes.wclass = GDK_INPUT_OUTPUT;
1396 attributes.visual = gtk_widget_get_visual (widget);
1397 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1399 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1401 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1402 &attributes, attributes_mask);
1403 gtk_widget_set_window (widget, window);
1404 gdk_window_set_user_data (window, widget);
1406 gtk_widget_get_allocation (widget, &allocation);
1408 /* Make the window for the icon view */
1411 attributes.width = MAX (icon_view->priv->width, allocation.width);
1412 attributes.height = MAX (icon_view->priv->height, allocation.height);
1413 attributes.event_mask = (GDK_EXPOSURE_MASK |
1415 GDK_POINTER_MOTION_MASK |
1416 GDK_BUTTON_PRESS_MASK |
1417 GDK_BUTTON_RELEASE_MASK |
1418 GDK_KEY_PRESS_MASK |
1419 GDK_KEY_RELEASE_MASK) |
1420 gtk_widget_get_events (widget);
1422 icon_view->priv->bin_window = gdk_window_new (window,
1423 &attributes, attributes_mask);
1424 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1426 context = gtk_widget_get_style_context (widget);
1428 gtk_style_context_save (context);
1429 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1430 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1431 gtk_style_context_restore (context);
1433 gdk_window_show (icon_view->priv->bin_window);
1437 gtk_icon_view_unrealize (GtkWidget *widget)
1439 GtkIconView *icon_view;
1441 icon_view = GTK_ICON_VIEW (widget);
1443 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1444 gdk_window_destroy (icon_view->priv->bin_window);
1445 icon_view->priv->bin_window = NULL;
1447 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1451 _gtk_icon_view_update_background (GtkIconView *icon_view)
1453 GtkWidget *widget = GTK_WIDGET (icon_view);
1455 if (gtk_widget_get_realized (widget))
1457 GtkStyleContext *context;
1459 context = gtk_widget_get_style_context (widget);
1461 gtk_style_context_save (context);
1462 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1464 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1465 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1467 gtk_style_context_restore (context);
1472 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1473 GtkStateFlags previous_state)
1475 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1476 gtk_widget_queue_draw (widget);
1480 gtk_icon_view_style_updated (GtkWidget *widget)
1482 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1483 gtk_widget_queue_resize (widget);
1487 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1491 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1495 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1499 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1503 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1507 for (list = icon_view->priv->children; list; list = list->next)
1509 GtkIconViewChild *child = list->data;
1511 /* totally ignore our child's requisition */
1512 gtk_widget_size_allocate (child->widget, &child->area);
1517 gtk_icon_view_size_allocate (GtkWidget *widget,
1518 GtkAllocation *allocation)
1520 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1522 gtk_widget_set_allocation (widget, allocation);
1524 if (gtk_widget_get_realized (widget))
1526 gdk_window_move_resize (gtk_widget_get_window (widget),
1527 allocation->x, allocation->y,
1528 allocation->width, allocation->height);
1529 gdk_window_resize (icon_view->priv->bin_window,
1530 MAX (icon_view->priv->width, allocation->width),
1531 MAX (icon_view->priv->height, allocation->height));
1534 gtk_icon_view_layout (icon_view);
1536 gtk_icon_view_allocate_children (icon_view);
1538 /* Delay signal emission */
1539 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1540 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1542 gtk_icon_view_set_hadjustment_values (icon_view);
1543 gtk_icon_view_set_vadjustment_values (icon_view);
1545 if (gtk_widget_get_realized (widget) &&
1546 icon_view->priv->scroll_to_path)
1549 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1550 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1551 icon_view->priv->scroll_to_path = NULL;
1553 gtk_icon_view_scroll_to_path (icon_view, path,
1554 icon_view->priv->scroll_to_use_align,
1555 icon_view->priv->scroll_to_row_align,
1556 icon_view->priv->scroll_to_col_align);
1557 gtk_tree_path_free (path);
1560 /* Emit any pending signals now */
1561 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1562 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1566 gtk_icon_view_draw (GtkWidget *widget,
1569 GtkIconView *icon_view;
1573 GtkIconViewDropPosition dest_pos;
1574 GtkIconViewItem *dest_item = NULL;
1576 icon_view = GTK_ICON_VIEW (widget);
1578 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1583 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1585 cairo_set_line_width (cr, 1.);
1587 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1591 dest_index = gtk_tree_path_get_indices (path)[0];
1592 gtk_tree_path_free (path);
1597 for (icons = icon_view->priv->items; icons; icons = icons->next)
1599 GtkIconViewItem *item = icons->data;
1600 GdkRectangle paint_area;
1602 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1603 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1604 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1605 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1609 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1612 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1614 gtk_icon_view_paint_item (icon_view, cr, item,
1615 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1616 icon_view->priv->draw_focus);
1618 if (dest_index == item->index)
1626 dest_pos != GTK_ICON_VIEW_NO_DROP)
1628 GtkStyleContext *context;
1629 GtkStateFlags state;
1630 GdkRectangle rect = { 0 };
1632 context = gtk_widget_get_style_context (widget);
1633 state = gtk_widget_get_state_flags (widget);
1637 case GTK_ICON_VIEW_DROP_INTO:
1638 rect = dest_item->cell_area;
1640 case GTK_ICON_VIEW_DROP_ABOVE:
1641 rect.x = dest_item->cell_area.x;
1642 rect.y = dest_item->cell_area.y - 1;
1643 rect.width = dest_item->cell_area.width;
1646 case GTK_ICON_VIEW_DROP_LEFT:
1647 rect.x = dest_item->cell_area.x - 1;
1648 rect.y = dest_item->cell_area.y;
1650 rect.height = dest_item->cell_area.height;
1652 case GTK_ICON_VIEW_DROP_BELOW:
1653 rect.x = dest_item->cell_area.x;
1654 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1655 rect.width = dest_item->cell_area.width;
1658 case GTK_ICON_VIEW_DROP_RIGHT:
1659 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1660 rect.y = dest_item->cell_area.y;
1662 rect.height = dest_item->cell_area.height;
1663 case GTK_ICON_VIEW_NO_DROP: ;
1667 gtk_style_context_set_state (context, state);
1668 gtk_render_focus (context, cr,
1670 rect.width, rect.height);
1673 if (icon_view->priv->doing_rubberband)
1674 gtk_icon_view_paint_rubberband (icon_view, cr);
1678 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1684 rubberband_scroll_timeout (gpointer data)
1686 GtkIconView *icon_view = data;
1688 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1689 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1690 icon_view->priv->scroll_value_diff);
1692 gtk_icon_view_update_rubberband (icon_view);
1698 gtk_icon_view_motion (GtkWidget *widget,
1699 GdkEventMotion *event)
1701 GtkAllocation allocation;
1702 GtkIconView *icon_view;
1705 icon_view = GTK_ICON_VIEW (widget);
1707 gtk_icon_view_maybe_begin_drag (icon_view, event);
1709 if (icon_view->priv->doing_rubberband)
1711 gtk_icon_view_update_rubberband (widget);
1713 abs_y = event->y - icon_view->priv->height *
1714 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1715 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1716 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1718 gtk_widget_get_allocation (widget, &allocation);
1720 if (abs_y < 0 || abs_y > allocation.height)
1723 icon_view->priv->scroll_value_diff = abs_y;
1725 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1727 icon_view->priv->event_last_x = event->x;
1728 icon_view->priv->event_last_y = event->y;
1730 if (icon_view->priv->scroll_timeout_id == 0)
1731 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1735 remove_scroll_timeout (icon_view);
1742 gtk_icon_view_remove (GtkContainer *container,
1745 GtkIconView *icon_view;
1746 GtkIconViewChild *child = NULL;
1749 icon_view = GTK_ICON_VIEW (container);
1751 tmp_list = icon_view->priv->children;
1754 child = tmp_list->data;
1755 if (child->widget == widget)
1757 gtk_widget_unparent (widget);
1759 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1760 g_list_free_1 (tmp_list);
1765 tmp_list = tmp_list->next;
1770 gtk_icon_view_forall (GtkContainer *container,
1771 gboolean include_internals,
1772 GtkCallback callback,
1773 gpointer callback_data)
1775 GtkIconView *icon_view;
1776 GtkIconViewChild *child = NULL;
1779 icon_view = GTK_ICON_VIEW (container);
1781 tmp_list = icon_view->priv->children;
1784 child = tmp_list->data;
1785 tmp_list = tmp_list->next;
1787 (* callback) (child->widget, callback_data);
1792 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1793 GtkIconViewItem *item)
1796 AtkObject *item_obj;
1798 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1801 item_obj = atk_object_ref_accessible_child (obj, item->index);
1802 if (item_obj != NULL)
1804 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1805 g_object_unref (item_obj);
1811 gtk_icon_view_add_editable (GtkCellArea *area,
1812 GtkCellRenderer *renderer,
1813 GtkCellEditable *editable,
1814 GdkRectangle *cell_area,
1816 GtkIconView *icon_view)
1818 GtkIconViewChild *child;
1819 GtkWidget *widget = GTK_WIDGET (editable);
1821 child = g_new (GtkIconViewChild, 1);
1823 child->widget = widget;
1824 child->area.x = cell_area->x;
1825 child->area.y = cell_area->y;
1826 child->area.width = cell_area->width;
1827 child->area.height = cell_area->height;
1829 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1831 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1832 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1834 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1838 gtk_icon_view_remove_editable (GtkCellArea *area,
1839 GtkCellRenderer *renderer,
1840 GtkCellEditable *editable,
1841 GtkIconView *icon_view)
1845 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1846 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1848 gtk_container_remove (GTK_CONTAINER (icon_view),
1849 GTK_WIDGET (editable));
1851 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1852 gtk_icon_view_queue_draw_path (icon_view, path);
1853 gtk_tree_path_free (path);
1857 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1859 GtkIconView *icon_view)
1861 if (!strcmp (pspec->name, "minimum-width") ||
1862 !strcmp (pspec->name, "natural-width") ||
1863 !strcmp (pspec->name, "minimum-height") ||
1864 !strcmp (pspec->name, "natural-height"))
1865 gtk_icon_view_invalidate_sizes (icon_view);
1869 * gtk_icon_view_set_cursor:
1870 * @icon_view: A #GtkIconView
1871 * @path: A #GtkTreePath
1872 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1873 * @start_editing: %TRUE if the specified cell should start being edited.
1875 * Sets the current keyboard focus to be at @path, and selects it. This is
1876 * useful when you want to focus the user's attention on a particular item.
1877 * If @cell is not %NULL, then focus is given to the cell specified by
1878 * it. Additionally, if @start_editing is %TRUE, then editing should be
1879 * started in the specified cell.
1881 * This function is often followed by <literal>gtk_widget_grab_focus
1882 * (icon_view)</literal> in order to give keyboard focus to the widget.
1883 * Please note that editing can only happen when the widget is realized.
1888 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1890 GtkCellRenderer *cell,
1891 gboolean start_editing)
1893 GtkIconViewItem *item = NULL;
1895 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1896 g_return_if_fail (path != NULL);
1897 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1899 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1901 if (gtk_tree_path_get_depth (path) == 1)
1902 item = g_list_nth_data (icon_view->priv->items,
1903 gtk_tree_path_get_indices(path)[0]);
1908 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1909 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1913 GtkCellAreaContext *context;
1915 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1916 gtk_icon_view_set_cell_data (icon_view, item);
1917 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1918 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1919 0 /* XXX flags */, TRUE);
1924 * gtk_icon_view_get_cursor:
1925 * @icon_view: A #GtkIconView
1926 * @path: (out) (allow-none): Return location for the current cursor path,
1928 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1930 * Fills in @path and @cell with the current cursor path and cell.
1931 * If the cursor isn't currently set, then *@path will be %NULL.
1932 * If no cell currently has focus, then *@cell will be %NULL.
1934 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1936 * Return value: %TRUE if the cursor is set.
1941 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1943 GtkCellRenderer **cell)
1945 GtkIconViewItem *item;
1947 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1949 item = icon_view->priv->cursor_item;
1954 *path = gtk_tree_path_new_from_indices (item->index, -1);
1959 if (cell != NULL && item != NULL)
1960 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1962 return (item != NULL);
1966 gtk_icon_view_button_press (GtkWidget *widget,
1967 GdkEventButton *event)
1969 GtkIconView *icon_view;
1970 GtkIconViewItem *item;
1971 gboolean dirty = FALSE;
1972 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1974 icon_view = GTK_ICON_VIEW (widget);
1976 if (event->window != icon_view->priv->bin_window)
1979 if (!gtk_widget_has_focus (widget))
1980 gtk_widget_grab_focus (widget);
1982 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1984 item = gtk_icon_view_get_item_at_coords (icon_view,
1990 * We consider only the the cells' area as the item area if the
1991 * item is not selected, but if it *is* selected, the complete
1992 * selection rectangle is considered to be part of the item.
1994 if (item != NULL && (cell != NULL || item->selected))
1998 if (gtk_cell_renderer_is_activatable (cell))
2002 gtk_icon_view_scroll_to_item (icon_view, item);
2004 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2006 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2008 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2009 (event->state & GDK_SHIFT_MASK))
2011 gtk_icon_view_unselect_all_internal (icon_view);
2013 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2014 if (!icon_view->priv->anchor_item)
2015 icon_view->priv->anchor_item = item;
2017 gtk_icon_view_select_all_between (icon_view,
2018 icon_view->priv->anchor_item,
2024 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2025 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2026 (event->state & GDK_CONTROL_MASK))
2028 item->selected = !item->selected;
2029 gtk_icon_view_queue_draw_item (icon_view, item);
2034 gtk_icon_view_unselect_all_internal (icon_view);
2036 item->selected = TRUE;
2037 gtk_icon_view_queue_draw_item (icon_view, item);
2040 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2041 icon_view->priv->anchor_item = item;
2044 /* Save press to possibly begin a drag */
2045 if (icon_view->priv->pressed_button < 0)
2047 icon_view->priv->pressed_button = event->button;
2048 icon_view->priv->press_start_x = event->x;
2049 icon_view->priv->press_start_y = event->y;
2052 if (!icon_view->priv->last_single_clicked)
2053 icon_view->priv->last_single_clicked = item;
2055 /* cancel the current editing, if it exists */
2056 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2058 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2060 GtkCellAreaContext *context;
2062 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2064 gtk_icon_view_set_cell_data (icon_view, item);
2065 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2066 GTK_WIDGET (icon_view),
2067 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2072 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2073 !(event->state & GDK_CONTROL_MASK))
2075 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2078 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2079 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2082 /* don't draw keyboard focus around an clicked-on item */
2083 icon_view->priv->draw_focus = FALSE;
2086 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2088 item = gtk_icon_view_get_item_at_coords (icon_view,
2093 if (item && item == icon_view->priv->last_single_clicked)
2097 path = gtk_tree_path_new_from_indices (item->index, -1);
2098 gtk_icon_view_item_activated (icon_view, path);
2099 gtk_tree_path_free (path);
2102 icon_view->priv->last_single_clicked = NULL;
2103 icon_view->priv->pressed_button = -1;
2107 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2109 return event->button == 1;
2113 gtk_icon_view_button_release (GtkWidget *widget,
2114 GdkEventButton *event)
2116 GtkIconView *icon_view;
2118 icon_view = GTK_ICON_VIEW (widget);
2120 if (icon_view->priv->pressed_button == event->button)
2121 icon_view->priv->pressed_button = -1;
2123 gtk_icon_view_stop_rubberbanding (icon_view);
2125 remove_scroll_timeout (icon_view);
2131 gtk_icon_view_key_press (GtkWidget *widget,
2134 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2136 if (icon_view->priv->doing_rubberband)
2138 if (event->keyval == GDK_KEY_Escape)
2139 gtk_icon_view_stop_rubberbanding (icon_view);
2144 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2148 gtk_icon_view_key_release (GtkWidget *widget,
2151 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2153 if (icon_view->priv->doing_rubberband)
2156 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2160 gtk_icon_view_update_rubberband (gpointer data)
2162 GtkIconView *icon_view;
2164 GdkRectangle old_area;
2165 GdkRectangle new_area;
2166 GdkRectangle common;
2167 cairo_region_t *invalid_region;
2169 icon_view = GTK_ICON_VIEW (data);
2171 gdk_window_get_device_position (icon_view->priv->bin_window,
2172 icon_view->priv->rubberband_device,
2178 old_area.x = MIN (icon_view->priv->rubberband_x1,
2179 icon_view->priv->rubberband_x2);
2180 old_area.y = MIN (icon_view->priv->rubberband_y1,
2181 icon_view->priv->rubberband_y2);
2182 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2183 icon_view->priv->rubberband_x1) + 1;
2184 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2185 icon_view->priv->rubberband_y1) + 1;
2187 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2188 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2189 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2190 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2192 invalid_region = cairo_region_create_rectangle (&old_area);
2193 cairo_region_union_rectangle (invalid_region, &new_area);
2195 gdk_rectangle_intersect (&old_area, &new_area, &common);
2196 if (common.width > 2 && common.height > 2)
2198 cairo_region_t *common_region;
2200 /* make sure the border is invalidated */
2206 common_region = cairo_region_create_rectangle (&common);
2208 cairo_region_subtract (invalid_region, common_region);
2209 cairo_region_destroy (common_region);
2212 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2214 cairo_region_destroy (invalid_region);
2216 icon_view->priv->rubberband_x2 = x;
2217 icon_view->priv->rubberband_y2 = y;
2219 gtk_icon_view_update_rubberband_selection (icon_view);
2223 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2230 if (icon_view->priv->rubberband_device)
2233 for (items = icon_view->priv->items; items; items = items->next)
2235 GtkIconViewItem *item = items->data;
2237 item->selected_before_rubberbanding = item->selected;
2240 icon_view->priv->rubberband_x1 = x;
2241 icon_view->priv->rubberband_y1 = y;
2242 icon_view->priv->rubberband_x2 = x;
2243 icon_view->priv->rubberband_y2 = y;
2245 icon_view->priv->doing_rubberband = TRUE;
2246 icon_view->priv->rubberband_device = device;
2248 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2252 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2254 if (!icon_view->priv->doing_rubberband)
2257 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2258 icon_view->priv->rubberband_device);
2260 icon_view->priv->doing_rubberband = FALSE;
2261 icon_view->priv->rubberband_device = NULL;
2263 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2267 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2270 gint x, y, width, height;
2271 gboolean dirty = FALSE;
2273 x = MIN (icon_view->priv->rubberband_x1,
2274 icon_view->priv->rubberband_x2);
2275 y = MIN (icon_view->priv->rubberband_y1,
2276 icon_view->priv->rubberband_y2);
2277 width = ABS (icon_view->priv->rubberband_x1 -
2278 icon_view->priv->rubberband_x2);
2279 height = ABS (icon_view->priv->rubberband_y1 -
2280 icon_view->priv->rubberband_y2);
2282 for (items = icon_view->priv->items; items; items = items->next)
2284 GtkIconViewItem *item = items->data;
2288 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2289 x, y, width, height);
2291 selected = is_in ^ item->selected_before_rubberbanding;
2293 if (item->selected != selected)
2295 item->selected = selected;
2297 gtk_icon_view_queue_draw_item (icon_view, item);
2302 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2307 GdkRectangle hit_rect;
2312 hit_test (GtkCellRenderer *renderer,
2313 const GdkRectangle *cell_area,
2314 const GdkRectangle *cell_background,
2317 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2318 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2319 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2320 MAX (data->hit_rect.y, cell_area->y) > 0)
2323 return (data->hit != FALSE);
2327 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2328 GtkIconViewItem *item,
2334 HitTestData data = { { x, y, width, height }, FALSE };
2335 GtkCellAreaContext *context;
2336 GdkRectangle *item_area = (GdkRectangle *)item;
2338 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2339 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2342 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2344 gtk_icon_view_set_cell_data (icon_view, item);
2345 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2346 GTK_WIDGET (icon_view),
2347 item_area, item_area,
2348 (GtkCellAllocCallback)hit_test, &data);
2354 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2356 gboolean dirty = FALSE;
2359 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2362 for (items = icon_view->priv->items; items; items = items->next)
2364 GtkIconViewItem *item = items->data;
2368 item->selected = FALSE;
2370 gtk_icon_view_queue_draw_item (icon_view, item);
2371 gtk_icon_view_item_selected_changed (icon_view, item);
2379 /* GtkIconView signals */
2381 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2383 gtk_icon_view_select_all (icon_view);
2387 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2389 gtk_icon_view_unselect_all (icon_view);
2393 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2395 gtk_icon_view_unselect_all (icon_view);
2397 if (icon_view->priv->cursor_item != NULL)
2398 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2402 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2405 GtkCellAreaContext *context;
2407 if (!icon_view->priv->cursor_item)
2410 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2412 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2413 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2414 GTK_WIDGET (icon_view),
2415 (GdkRectangle *)icon_view->priv->cursor_item,
2419 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2420 gtk_icon_view_item_activated (icon_view, path);
2421 gtk_tree_path_free (path);
2427 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2429 if (!icon_view->priv->cursor_item)
2432 switch (icon_view->priv->selection_mode)
2434 case GTK_SELECTION_NONE:
2436 case GTK_SELECTION_BROWSE:
2437 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2439 case GTK_SELECTION_SINGLE:
2440 if (icon_view->priv->cursor_item->selected)
2441 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2443 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2445 case GTK_SELECTION_MULTIPLE:
2446 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2447 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2449 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2450 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2455 /* Internal functions */
2457 gtk_icon_view_process_updates (GtkIconView *icon_view)
2459 /* Prior to drawing, we check if a layout has been scheduled. If so,
2460 * do it now that all cell view items have valid sizes before we proceeed
2461 * (and resize the bin_window if required).
2463 if (icon_view->priv->layout_idle_id != 0)
2464 gtk_icon_view_layout (icon_view);
2466 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2470 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2472 GtkAllocation allocation;
2473 GtkAdjustment *adj = icon_view->priv->hadjustment;
2474 gdouble old_page_size;
2480 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2482 old_value = gtk_adjustment_get_value (adj);
2483 old_upper = gtk_adjustment_get_upper (adj);
2484 old_page_size = gtk_adjustment_get_page_size (adj);
2485 new_upper = MAX (allocation.width, icon_view->priv->width);
2487 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2489 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2490 /* Quick explanation:
2491 * In LTR locales, leftmost portion of visible rectangle should stay
2492 * fixed, which means left edge of scrollbar thumb should remain fixed
2493 * and thus adjustment's value should stay the same.
2495 * In RTL locales, we want to keep rightmost portion of visible
2496 * rectangle fixed. This means right edge of thumb should remain fixed.
2497 * In this case, upper - value - page_size should remain constant.
2499 new_value = (new_upper - allocation.width) -
2500 (old_upper - old_value - old_page_size);
2501 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2504 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2506 gtk_adjustment_configure (adj,
2510 allocation.width * 0.1,
2511 allocation.width * 0.9,
2516 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2518 GtkAllocation allocation;
2519 GtkAdjustment *adj = icon_view->priv->vadjustment;
2521 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2523 gtk_adjustment_configure (adj,
2524 gtk_adjustment_get_value (adj),
2526 MAX (allocation.height, icon_view->priv->height),
2527 allocation.height * 0.1,
2528 allocation.height * 0.9,
2533 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2534 GtkAdjustment *adjustment)
2536 GtkIconViewPrivate *priv = icon_view->priv;
2539 if (adjustment && priv->hadjustment == adjustment)
2542 if (priv->hadjustment != NULL)
2544 g_signal_handlers_disconnect_matched (priv->hadjustment,
2545 G_SIGNAL_MATCH_DATA,
2546 0, 0, NULL, NULL, icon_view);
2547 g_object_unref (priv->hadjustment);
2551 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2554 g_signal_connect (adjustment, "value-changed",
2555 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2556 priv->hadjustment = g_object_ref_sink (adjustment);
2557 gtk_icon_view_set_hadjustment_values (icon_view);
2559 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2560 gtk_icon_view_accessible_set_adjustment (atk_obj,
2561 GTK_ORIENTATION_HORIZONTAL,
2564 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2568 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2569 GtkAdjustment *adjustment)
2571 GtkIconViewPrivate *priv = icon_view->priv;
2574 if (adjustment && priv->vadjustment == adjustment)
2577 if (priv->vadjustment != NULL)
2579 g_signal_handlers_disconnect_matched (priv->vadjustment,
2580 G_SIGNAL_MATCH_DATA,
2581 0, 0, NULL, NULL, icon_view);
2582 g_object_unref (priv->vadjustment);
2586 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2589 g_signal_connect (adjustment, "value-changed",
2590 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2591 priv->vadjustment = g_object_ref_sink (adjustment);
2592 gtk_icon_view_set_vadjustment_values (icon_view);
2594 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2595 gtk_icon_view_accessible_set_adjustment (atk_obj,
2596 GTK_ORIENTATION_VERTICAL,
2599 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2603 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2604 GtkIconView *icon_view)
2606 GtkIconViewPrivate *priv = icon_view->priv;
2608 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2610 gdk_window_move (priv->bin_window,
2611 - gtk_adjustment_get_value (priv->hadjustment),
2612 - gtk_adjustment_get_value (priv->vadjustment));
2614 if (icon_view->priv->doing_rubberband)
2615 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2617 gtk_icon_view_process_updates (icon_view);
2622 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2627 gint *maximum_width)
2629 GtkAllocation allocation;
2630 GtkCellAreaContext *context;
2631 GtkIconViewPrivate *priv = icon_view->priv;
2632 GtkWidget *widget = GTK_WIDGET (icon_view);
2633 gint x, current_width;
2634 GList *items, *last_item;
2636 gint max_height = 0;
2639 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2647 current_width += 2 * priv->margin;
2649 gtk_widget_get_allocation (widget, &allocation);
2651 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2652 g_ptr_array_add (priv->row_contexts, context);
2654 /* In the first loop we iterate horizontally until we hit allocation width
2655 * and collect the aligned height-for-width */
2659 GtkIconViewItem *item = items->data;
2660 GdkRectangle *item_area = (GdkRectangle *)item;
2662 item_area->width = item_width;
2664 current_width += item_area->width + icon_view->priv->item_padding * 2;
2666 if (items != first_item)
2668 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2669 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2673 /* Get this item's particular width & height (all alignments are cached by now) */
2674 gtk_icon_view_set_cell_data (icon_view, item);
2675 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2680 current_width += icon_view->priv->column_spacing;
2682 item_area->y = *y + icon_view->priv->item_padding;
2683 item_area->x = x + icon_view->priv->item_padding;
2685 x = current_width - icon_view->priv->margin;
2687 if (current_width > *maximum_width)
2688 *maximum_width = current_width;
2694 items = items->next;
2699 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2700 gtk_cell_area_context_allocate (context, item_width, max_height);
2702 /* In the second loop the item height has been aligned and derived and
2703 * we just set the height and handle rtl layout */
2704 for (items = first_item; items != last_item; items = items->next)
2706 GtkIconViewItem *item = items->data;
2707 GdkRectangle *item_area = (GdkRectangle *)item;
2711 item_area->x = *maximum_width - item_area->width - item_area->x;
2712 item->col = col - 1 - item->col;
2715 /* All items in the same row get the same height */
2716 item_area->height = max_height;
2719 /* Adjust the new y coordinate. */
2720 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2726 adjust_wrap_width (GtkIconView *icon_view)
2728 if (icon_view->priv->text_cell)
2730 gint wrap_width = 50;
2732 /* Here we go with the same old guess, try the icon size and set double
2733 * the size of the first icon found in the list, naive but works much
2735 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2737 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2738 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2739 GTK_WIDGET (icon_view),
2742 wrap_width = MAX (wrap_width * 2, 50);
2745 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2746 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2751 gtk_icon_view_layout (GtkIconView *icon_view)
2753 GtkAllocation allocation;
2756 gint y = 0, maximum_width = 0;
2759 gboolean size_changed = FALSE;
2761 if (icon_view->priv->layout_idle_id != 0)
2763 g_source_remove (icon_view->priv->layout_idle_id);
2764 icon_view->priv->layout_idle_id = 0;
2767 if (icon_view->priv->model == NULL)
2770 widget = GTK_WIDGET (icon_view);
2772 item_width = icon_view->priv->item_width;
2774 /* Update the wrap width for the text cell before going and requesting sizes */
2775 adjust_wrap_width (icon_view);
2777 /* Update the context widths for any invalidated items */
2778 gtk_icon_view_cache_widths (icon_view);
2780 /* Fetch the new item width if needed */
2782 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2785 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2787 icons = icon_view->priv->items;
2788 y += icon_view->priv->margin;
2791 /* Clear the per row contexts */
2792 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2796 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2798 &y, &maximum_width);
2801 while (icons != NULL);
2803 if (maximum_width != icon_view->priv->width)
2805 icon_view->priv->width = maximum_width;
2806 size_changed = TRUE;
2809 y += icon_view->priv->margin;
2811 if (y != icon_view->priv->height)
2813 icon_view->priv->height = y;
2814 size_changed = TRUE;
2817 gtk_icon_view_set_hadjustment_values (icon_view);
2818 gtk_icon_view_set_vadjustment_values (icon_view);
2821 gtk_widget_queue_resize_no_redraw (widget);
2823 gtk_widget_get_allocation (widget, &allocation);
2824 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2825 gdk_window_resize (icon_view->priv->bin_window,
2826 MAX (icon_view->priv->width, allocation.width),
2827 MAX (icon_view->priv->height, allocation.height));
2829 if (icon_view->priv->scroll_to_path)
2833 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2834 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2835 icon_view->priv->scroll_to_path = NULL;
2837 gtk_icon_view_scroll_to_path (icon_view, path,
2838 icon_view->priv->scroll_to_use_align,
2839 icon_view->priv->scroll_to_row_align,
2840 icon_view->priv->scroll_to_col_align);
2841 gtk_tree_path_free (path);
2844 gtk_widget_queue_draw (widget);
2847 /* This ensures that all widths have been cached in the
2848 * context and we have proper alignments to go on.
2851 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2855 g_signal_handler_block (icon_view->priv->cell_area_context,
2856 icon_view->priv->context_changed_id);
2858 for (items = icon_view->priv->items; items; items = items->next)
2860 GtkIconViewItem *item = items->data;
2862 /* Only fetch the width of items with invalidated sizes */
2863 if (item->cell_area.width < 0)
2865 gtk_icon_view_set_cell_data (icon_view, item);
2866 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2867 icon_view->priv->cell_area_context,
2868 GTK_WIDGET (icon_view), NULL, NULL);
2872 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2873 icon_view->priv->context_changed_id);
2877 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2879 /* Clear all item sizes */
2880 g_list_foreach (icon_view->priv->items,
2881 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2883 /* Reset the context */
2884 g_signal_handler_block (icon_view->priv->cell_area_context,
2885 icon_view->priv->context_changed_id);
2886 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2887 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2888 icon_view->priv->context_changed_id);
2890 /* Re-layout the items */
2891 gtk_icon_view_queue_layout (icon_view);
2895 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2897 item->cell_area.width = -1;
2898 item->cell_area.height = -1;
2902 gtk_icon_view_paint_item (GtkIconView *icon_view,
2904 GtkIconViewItem *item,
2907 gboolean draw_focus)
2909 GdkRectangle cell_area;
2910 GtkStateFlags state = 0;
2911 GtkCellRendererState flags = 0;
2912 GtkStyleContext *style_context;
2913 GtkWidget *widget = GTK_WIDGET (icon_view);
2914 GtkIconViewPrivate *priv = icon_view->priv;
2915 GtkCellAreaContext *context;
2917 if (priv->model == NULL)
2920 gtk_icon_view_set_cell_data (icon_view, item);
2922 style_context = gtk_widget_get_style_context (widget);
2924 gtk_style_context_save (style_context);
2925 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2926 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2930 if (gtk_widget_has_focus (widget) &&
2931 item == icon_view->priv->cursor_item)
2933 state |= GTK_STATE_FLAG_FOCUSED;
2934 flags |= GTK_CELL_RENDERER_FOCUSED;
2937 state |= GTK_STATE_FLAG_SELECTED;
2938 flags |= GTK_CELL_RENDERER_SELECTED;
2940 gtk_style_context_set_state (style_context, state);
2941 gtk_render_background (style_context, cr,
2942 x - icon_view->priv->item_padding,
2943 y - icon_view->priv->item_padding,
2944 item->cell_area.width + icon_view->priv->item_padding * 2,
2945 item->cell_area.height + icon_view->priv->item_padding * 2);
2950 cell_area.width = item->cell_area.width;
2951 cell_area.height = item->cell_area.height;
2953 context = g_ptr_array_index (priv->row_contexts, item->row);
2954 gtk_cell_area_render (priv->cell_area, context,
2955 widget, cr, &cell_area, &cell_area, flags,
2958 gtk_style_context_restore (style_context);
2962 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2965 GtkStyleContext *context;
2970 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2971 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2972 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2973 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2975 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2977 gtk_style_context_save (context);
2978 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2980 gdk_cairo_rectangle (cr, &rect);
2983 gtk_render_background (context, cr,
2985 rect.width, rect.height);
2986 gtk_render_frame (context, cr,
2988 rect.width, rect.height);
2990 gtk_style_context_restore (context);
2995 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3001 index = gtk_tree_path_get_indices (path)[0];
3003 for (l = icon_view->priv->items; l; l = l->next)
3005 GtkIconViewItem *item = l->data;
3007 if (item->index == index)
3009 gtk_icon_view_queue_draw_item (icon_view, item);
3016 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3017 GtkIconViewItem *item)
3020 GdkRectangle *item_area = (GdkRectangle *)item;
3022 rect.x = item_area->x - icon_view->priv->item_padding;
3023 rect.y = item_area->y - icon_view->priv->item_padding;
3024 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3025 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3027 if (icon_view->priv->bin_window)
3028 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3032 layout_callback (gpointer user_data)
3034 GtkIconView *icon_view;
3036 icon_view = GTK_ICON_VIEW (user_data);
3038 icon_view->priv->layout_idle_id = 0;
3040 gtk_icon_view_layout (icon_view);
3046 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3048 if (icon_view->priv->layout_idle_id != 0)
3051 icon_view->priv->layout_idle_id =
3052 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3053 layout_callback, icon_view, NULL);
3057 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3058 GtkIconViewItem *item,
3059 GtkCellRenderer *cursor_cell)
3062 AtkObject *item_obj;
3063 AtkObject *cursor_item_obj;
3065 /* When hitting this path from keynav, the focus cell is
3066 * already set, we dont need to notify the atk object
3067 * but we still need to queue the draw here (in the case
3068 * that the focus cell changes but not the cursor item).
3070 gtk_icon_view_queue_draw_item (icon_view, item);
3072 if (icon_view->priv->cursor_item == item &&
3073 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3076 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3077 if (icon_view->priv->cursor_item != NULL)
3079 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3082 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3083 if (cursor_item_obj != NULL)
3084 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3087 icon_view->priv->cursor_item = item;
3090 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3093 /* Make sure there is a cell in focus initially */
3094 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3095 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3098 /* Notify that accessible focus object has changed */
3099 item_obj = atk_object_ref_accessible_child (obj, item->index);
3101 if (item_obj != NULL)
3103 atk_focus_tracker_notify (item_obj);
3104 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3105 g_object_unref (item_obj);
3110 static GtkIconViewItem *
3111 gtk_icon_view_item_new (void)
3113 GtkIconViewItem *item;
3115 item = g_slice_new0 (GtkIconViewItem);
3117 item->cell_area.width = -1;
3118 item->cell_area.height = -1;
3124 gtk_icon_view_item_free (GtkIconViewItem *item)
3126 g_return_if_fail (item != NULL);
3128 g_slice_free (GtkIconViewItem, item);
3131 static GtkIconViewItem *
3132 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3135 gboolean only_in_cell,
3136 GtkCellRenderer **cell_at_pos)
3141 *cell_at_pos = NULL;
3143 for (items = icon_view->priv->items; items; items = items->next)
3145 GtkIconViewItem *item = items->data;
3146 GdkRectangle *item_area = (GdkRectangle *)item;
3148 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3149 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3150 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3151 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3153 if (only_in_cell || cell_at_pos)
3155 GtkCellRenderer *cell = NULL;
3156 GtkCellAreaContext *context;
3158 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3159 gtk_icon_view_set_cell_data (icon_view, item);
3161 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3162 y >= item_area->y && y <= item_area->y + item_area->height)
3163 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3164 GTK_WIDGET (icon_view),
3169 *cell_at_pos = cell;
3172 return cell != NULL ? item : NULL;
3183 gtk_icon_view_select_item (GtkIconView *icon_view,
3184 GtkIconViewItem *item)
3186 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3187 g_return_if_fail (item != NULL);
3192 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3194 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3195 gtk_icon_view_unselect_all_internal (icon_view);
3197 item->selected = TRUE;
3199 gtk_icon_view_item_selected_changed (icon_view, item);
3200 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3202 gtk_icon_view_queue_draw_item (icon_view, item);
3207 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3208 GtkIconViewItem *item)
3210 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3211 g_return_if_fail (item != NULL);
3213 if (!item->selected)
3216 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3217 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3220 item->selected = FALSE;
3222 gtk_icon_view_item_selected_changed (icon_view, item);
3223 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3225 gtk_icon_view_queue_draw_item (icon_view, item);
3229 verify_items (GtkIconView *icon_view)
3234 for (items = icon_view->priv->items; items; items = items->next)
3236 GtkIconViewItem *item = items->data;
3238 if (item->index != i)
3239 g_error ("List item does not match its index: "
3240 "item index %d and list index %d\n", item->index, i);
3247 gtk_icon_view_row_changed (GtkTreeModel *model,
3252 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3254 /* ignore changes in branches */
3255 if (gtk_tree_path_get_depth (path) > 1)
3258 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3260 /* Here we can use a "grow-only" strategy for optimization
3261 * and only invalidate a single item and queue a relayout
3262 * instead of invalidating the whole thing.
3264 * For now GtkIconView still cant deal with huge models
3265 * so just invalidate the whole thing when the model
3268 gtk_icon_view_invalidate_sizes (icon_view);
3270 verify_items (icon_view);
3274 gtk_icon_view_row_inserted (GtkTreeModel *model,
3279 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3281 GtkIconViewItem *item;
3282 gboolean iters_persist;
3285 /* ignore changes in branches */
3286 if (gtk_tree_path_get_depth (path) > 1)
3289 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3291 index = gtk_tree_path_get_indices(path)[0];
3293 item = gtk_icon_view_item_new ();
3298 item->index = index;
3300 /* FIXME: We can be more efficient here,
3301 we can store a tail pointer and use that when
3302 appending (which is a rather common operation)
3304 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3307 list = g_list_nth (icon_view->priv->items, index + 1);
3308 for (; list; list = list->next)
3315 verify_items (icon_view);
3317 gtk_icon_view_queue_layout (icon_view);
3321 gtk_icon_view_row_deleted (GtkTreeModel *model,
3325 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3327 GtkIconViewItem *item;
3329 gboolean emit = FALSE;
3331 /* ignore changes in branches */
3332 if (gtk_tree_path_get_depth (path) > 1)
3335 index = gtk_tree_path_get_indices(path)[0];
3337 list = g_list_nth (icon_view->priv->items, index);
3340 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3342 if (item == icon_view->priv->anchor_item)
3343 icon_view->priv->anchor_item = NULL;
3345 if (item == icon_view->priv->cursor_item)
3346 icon_view->priv->cursor_item = NULL;
3351 gtk_icon_view_item_free (item);
3353 for (next = list->next; next; next = next->next)
3360 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3362 verify_items (icon_view);
3364 gtk_icon_view_queue_layout (icon_view);
3367 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3371 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3372 GtkTreePath *parent,
3377 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3380 GList *items = NULL, *list;
3381 GtkIconViewItem **item_array;
3384 /* ignore changes in branches */
3388 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3390 length = gtk_tree_model_iter_n_children (model, NULL);
3392 order = g_new (gint, length);
3393 for (i = 0; i < length; i++)
3394 order [new_order[i]] = i;
3396 item_array = g_new (GtkIconViewItem *, length);
3397 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3398 item_array[order[i]] = list->data;
3401 for (i = length - 1; i >= 0; i--)
3403 item_array[i]->index = i;
3404 items = g_list_prepend (items, item_array[i]);
3407 g_free (item_array);
3408 g_list_free (icon_view->priv->items);
3409 icon_view->priv->items = items;
3411 gtk_icon_view_queue_layout (icon_view);
3413 verify_items (icon_view);
3417 gtk_icon_view_build_items (GtkIconView *icon_view)
3421 gboolean iters_persist;
3422 GList *items = NULL;
3424 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3426 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3434 GtkIconViewItem *item = gtk_icon_view_item_new ();
3443 items = g_list_prepend (items, item);
3445 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3447 icon_view->priv->items = g_list_reverse (items);
3451 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3454 GtkMovementStep step,
3458 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3459 I_("move-cursor"), 2,
3463 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3468 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3471 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3476 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3483 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3484 GtkMovementStep step,
3487 GdkModifierType state;
3489 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3490 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3491 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3492 step == GTK_MOVEMENT_DISPLAY_LINES ||
3493 step == GTK_MOVEMENT_PAGES ||
3494 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3496 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3499 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3500 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3502 if (gtk_get_current_event_state (&state))
3504 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3505 icon_view->priv->ctrl_pressed = TRUE;
3506 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3507 icon_view->priv->shift_pressed = TRUE;
3509 /* else we assume not pressed */
3513 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3514 case GTK_MOVEMENT_VISUAL_POSITIONS:
3515 gtk_icon_view_move_cursor_left_right (icon_view, count);
3517 case GTK_MOVEMENT_DISPLAY_LINES:
3518 gtk_icon_view_move_cursor_up_down (icon_view, count);
3520 case GTK_MOVEMENT_PAGES:
3521 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3523 case GTK_MOVEMENT_BUFFER_ENDS:
3524 gtk_icon_view_move_cursor_start_end (icon_view, count);
3527 g_assert_not_reached ();
3530 icon_view->priv->ctrl_pressed = FALSE;
3531 icon_view->priv->shift_pressed = FALSE;
3533 icon_view->priv->draw_focus = TRUE;
3538 static GtkIconViewItem *
3539 find_item (GtkIconView *icon_view,
3540 GtkIconViewItem *current,
3546 GtkIconViewItem *item;
3548 /* FIXME: this could be more efficient
3550 row = current->row + row_ofs;
3551 col = current->col + col_ofs;
3553 for (items = icon_view->priv->items; items; items = items->next)
3556 if (item->row == row && item->col == col)
3563 static GtkIconViewItem *
3564 find_item_page_up_down (GtkIconView *icon_view,
3565 GtkIconViewItem *current,
3572 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3574 item = g_list_find (icon_view->priv->items, current);
3579 for (next = item->next; next; next = next->next)
3581 if (((GtkIconViewItem *)next->data)->col == col)
3584 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3594 for (next = item->prev; next; next = next->prev)
3596 if (((GtkIconViewItem *)next->data)->col == col)
3599 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3613 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3614 GtkIconViewItem *anchor,
3615 GtkIconViewItem *cursor)
3618 GtkIconViewItem *item;
3619 gint row1, row2, col1, col2;
3620 gboolean dirty = FALSE;
3622 if (anchor->row < cursor->row)
3633 if (anchor->col < cursor->col)
3644 for (items = icon_view->priv->items; items; items = items->next)
3648 if (row1 <= item->row && item->row <= row2 &&
3649 col1 <= item->col && item->col <= col2)
3651 if (!item->selected)
3654 item->selected = TRUE;
3655 gtk_icon_view_item_selected_changed (icon_view, item);
3657 gtk_icon_view_queue_draw_item (icon_view, item);
3665 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3668 GtkIconViewItem *item;
3669 GtkCellRenderer *cell;
3670 gboolean dirty = FALSE;
3672 GtkDirectionType direction;
3674 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3677 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3679 if (!icon_view->priv->cursor_item)
3684 list = icon_view->priv->items;
3686 list = g_list_last (icon_view->priv->items);
3688 item = list ? list->data : NULL;
3690 /* Give focus to the first cell initially */
3691 gtk_icon_view_set_cell_data (icon_view, item);
3692 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3696 item = icon_view->priv->cursor_item;
3697 step = count > 0 ? 1 : -1;
3699 /* Save the current focus cell in case we hit the edge */
3700 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3704 gtk_icon_view_set_cell_data (icon_view, item);
3706 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3709 item = find_item (icon_view, item, step, 0);
3715 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3717 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3719 gtk_widget_child_focus (toplevel,
3720 direction == GTK_DIR_UP ?
3721 GTK_DIR_TAB_BACKWARD :
3722 GTK_DIR_TAB_FORWARD);
3726 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3730 if (icon_view->priv->ctrl_pressed ||
3731 !icon_view->priv->shift_pressed ||
3732 !icon_view->priv->anchor_item ||
3733 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3734 icon_view->priv->anchor_item = item;
3736 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3737 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3739 if (!icon_view->priv->ctrl_pressed &&
3740 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3742 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3743 dirty = gtk_icon_view_select_all_between (icon_view,
3744 icon_view->priv->anchor_item,
3748 gtk_icon_view_scroll_to_item (icon_view, item);
3751 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3755 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3758 GtkIconViewItem *item;
3759 gboolean dirty = FALSE;
3761 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3764 if (!icon_view->priv->cursor_item)
3769 list = icon_view->priv->items;
3771 list = g_list_last (icon_view->priv->items);
3773 item = list ? list->data : NULL;
3776 item = find_item_page_up_down (icon_view,
3777 icon_view->priv->cursor_item,
3780 if (item == icon_view->priv->cursor_item)
3781 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3786 if (icon_view->priv->ctrl_pressed ||
3787 !icon_view->priv->shift_pressed ||
3788 !icon_view->priv->anchor_item ||
3789 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3790 icon_view->priv->anchor_item = item;
3792 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3794 if (!icon_view->priv->ctrl_pressed &&
3795 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3797 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3798 dirty = gtk_icon_view_select_all_between (icon_view,
3799 icon_view->priv->anchor_item,
3803 gtk_icon_view_scroll_to_item (icon_view, item);
3806 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3810 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3813 GtkIconViewItem *item;
3814 GtkCellRenderer *cell = NULL;
3815 gboolean dirty = FALSE;
3817 GtkDirectionType direction;
3819 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3822 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3824 if (!icon_view->priv->cursor_item)
3829 list = icon_view->priv->items;
3831 list = g_list_last (icon_view->priv->items);
3833 item = list ? list->data : NULL;
3835 /* Give focus to the first cell initially */
3836 gtk_icon_view_set_cell_data (icon_view, item);
3837 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3841 item = icon_view->priv->cursor_item;
3842 step = count > 0 ? 1 : -1;
3844 /* Save the current focus cell in case we hit the edge */
3845 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3849 gtk_icon_view_set_cell_data (icon_view, item);
3851 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3854 item = find_item (icon_view, item, 0, step);
3860 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3862 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3864 gtk_widget_child_focus (toplevel,
3865 direction == GTK_DIR_LEFT ?
3866 GTK_DIR_TAB_BACKWARD :
3867 GTK_DIR_TAB_FORWARD);
3871 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3875 if (icon_view->priv->ctrl_pressed ||
3876 !icon_view->priv->shift_pressed ||
3877 !icon_view->priv->anchor_item ||
3878 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3879 icon_view->priv->anchor_item = item;
3881 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3882 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3884 if (!icon_view->priv->ctrl_pressed &&
3885 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3887 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3888 dirty = gtk_icon_view_select_all_between (icon_view,
3889 icon_view->priv->anchor_item,
3893 gtk_icon_view_scroll_to_item (icon_view, item);
3896 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3900 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3903 GtkIconViewItem *item;
3905 gboolean dirty = FALSE;
3907 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3911 list = icon_view->priv->items;
3913 list = g_list_last (icon_view->priv->items);
3915 item = list ? list->data : NULL;
3917 if (item == icon_view->priv->cursor_item)
3918 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3923 if (icon_view->priv->ctrl_pressed ||
3924 !icon_view->priv->shift_pressed ||
3925 !icon_view->priv->anchor_item ||
3926 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3927 icon_view->priv->anchor_item = item;
3929 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3931 if (!icon_view->priv->ctrl_pressed &&
3932 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3934 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3935 dirty = gtk_icon_view_select_all_between (icon_view,
3936 icon_view->priv->anchor_item,
3940 gtk_icon_view_scroll_to_item (icon_view, item);
3943 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3947 * gtk_icon_view_scroll_to_path:
3948 * @icon_view: A #GtkIconView.
3949 * @path: The path of the item to move to.
3950 * @use_align: whether to use alignment arguments, or %FALSE.
3951 * @row_align: The vertical alignment of the item specified by @path.
3952 * @col_align: The horizontal alignment of the item specified by @path.
3954 * Moves the alignments of @icon_view to the position specified by @path.
3955 * @row_align determines where the row is placed, and @col_align determines
3956 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3957 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3960 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3961 * tree does the minimum amount of work to scroll the item onto the screen.
3962 * This means that the item will be scrolled to the edge closest to its current
3963 * position. If the item is currently visible on the screen, nothing is done.
3965 * This function only works if the model is set, and @path is a valid row on
3966 * the model. If the model changes before the @icon_view is realized, the
3967 * centered path will be modified to reflect this change.
3972 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3978 GtkIconViewItem *item = NULL;
3981 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3982 g_return_if_fail (path != NULL);
3983 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3984 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3986 widget = GTK_WIDGET (icon_view);
3988 if (gtk_tree_path_get_depth (path) > 0)
3989 item = g_list_nth_data (icon_view->priv->items,
3990 gtk_tree_path_get_indices(path)[0]);
3992 if (!item || item->cell_area.width < 0 ||
3993 !gtk_widget_get_realized (widget))
3995 if (icon_view->priv->scroll_to_path)
3996 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3998 icon_view->priv->scroll_to_path = NULL;
4001 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4003 icon_view->priv->scroll_to_use_align = use_align;
4004 icon_view->priv->scroll_to_row_align = row_align;
4005 icon_view->priv->scroll_to_col_align = col_align;
4012 GtkAllocation allocation;
4015 GdkRectangle item_area =
4017 item->cell_area.x - icon_view->priv->item_padding,
4018 item->cell_area.y - icon_view->priv->item_padding,
4019 item->cell_area.width + icon_view->priv->item_padding * 2,
4020 item->cell_area.height + icon_view->priv->item_padding * 2
4023 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4025 gtk_widget_get_allocation (widget, &allocation);
4027 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4029 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4030 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4032 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4034 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4035 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4037 gtk_adjustment_changed (icon_view->priv->hadjustment);
4038 gtk_adjustment_changed (icon_view->priv->vadjustment);
4041 gtk_icon_view_scroll_to_item (icon_view, item);
4046 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4047 GtkIconViewItem *item)
4049 GtkIconViewPrivate *priv = icon_view->priv;
4050 GtkWidget *widget = GTK_WIDGET (icon_view);
4051 GtkAdjustment *hadj, *vadj;
4052 GtkAllocation allocation;
4054 GdkRectangle item_area;
4056 item_area.x = item->cell_area.x - priv->item_padding;
4057 item_area.y = item->cell_area.y - priv->item_padding;
4058 item_area.width = item->cell_area.width + priv->item_padding * 2;
4059 item_area.height = item->cell_area.height + priv->item_padding * 2;
4061 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4062 gtk_widget_get_allocation (widget, &allocation);
4064 hadj = icon_view->priv->hadjustment;
4065 vadj = icon_view->priv->vadjustment;
4067 if (y + item_area.y < 0)
4068 gtk_adjustment_set_value (vadj,
4069 gtk_adjustment_get_value (vadj)
4071 else if (y + item_area.y + item_area.height > allocation.height)
4072 gtk_adjustment_set_value (vadj,
4073 gtk_adjustment_get_value (vadj)
4074 + y + item_area.y + item_area.height - allocation.height);
4076 if (x + item_area.x < 0)
4077 gtk_adjustment_set_value (hadj,
4078 gtk_adjustment_get_value (hadj)
4080 else if (x + item_area.x + item_area.width > allocation.width)
4081 gtk_adjustment_set_value (hadj,
4082 gtk_adjustment_get_value (hadj)
4083 + x + item_area.x + item_area.width - allocation.width);
4085 gtk_adjustment_changed (hadj);
4086 gtk_adjustment_changed (vadj);
4089 /* GtkCellLayout implementation */
4092 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4093 GtkCellArea *cell_area)
4095 GtkIconViewPrivate *priv = icon_view->priv;
4097 if (priv->cell_area)
4101 priv->cell_area = cell_area;
4103 priv->cell_area = gtk_cell_area_box_new ();
4105 g_object_ref_sink (priv->cell_area);
4107 if (GTK_IS_ORIENTABLE (priv->cell_area))
4108 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4110 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4112 priv->add_editable_id =
4113 g_signal_connect (priv->cell_area, "add-editable",
4114 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4115 priv->remove_editable_id =
4116 g_signal_connect (priv->cell_area, "remove-editable",
4117 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4118 priv->context_changed_id =
4119 g_signal_connect (priv->cell_area_context, "notify",
4120 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4123 static GtkCellArea *
4124 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4126 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4127 GtkIconViewPrivate *priv = icon_view->priv;
4129 if (G_UNLIKELY (!priv->cell_area))
4130 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4132 return icon_view->priv->cell_area;
4136 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4137 GtkIconViewItem *item)
4139 gboolean iters_persist;
4142 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4148 path = gtk_tree_path_new_from_indices (item->index, -1);
4149 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4151 gtk_tree_path_free (path);
4156 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4157 icon_view->priv->model,
4158 &iter, FALSE, FALSE);
4167 * gtk_icon_view_new:
4169 * Creates a new #GtkIconView widget
4171 * Return value: A newly created #GtkIconView widget
4176 gtk_icon_view_new (void)
4178 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4182 * gtk_icon_view_new_with_area:
4183 * @area: the #GtkCellArea to use to layout cells
4185 * Creates a new #GtkIconView widget using the
4186 * specified @area to layout cells inside the icons.
4188 * Return value: A newly created #GtkIconView widget
4193 gtk_icon_view_new_with_area (GtkCellArea *area)
4195 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4199 * gtk_icon_view_new_with_model:
4200 * @model: The model.
4202 * Creates a new #GtkIconView widget with the model @model.
4204 * Return value: A newly created #GtkIconView widget.
4209 gtk_icon_view_new_with_model (GtkTreeModel *model)
4211 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4215 * gtk_icon_view_convert_widget_to_bin_window_coords:
4216 * @icon_view: a #GtkIconView
4217 * @wx: X coordinate relative to the widget
4218 * @wy: Y coordinate relative to the widget
4219 * @bx: (out): return location for bin_window X coordinate
4220 * @by: (out): return location for bin_window Y coordinate
4222 * Converts widget coordinates to coordinates for the bin_window,
4223 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4228 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4236 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4238 if (icon_view->priv->bin_window)
4239 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4250 * gtk_icon_view_get_path_at_pos:
4251 * @icon_view: A #GtkIconView.
4252 * @x: The x position to be identified
4253 * @y: The y position to be identified
4255 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4256 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4257 * the cell at the specified position.
4258 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4259 * widget coordinates to bin_window coordinates.
4261 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4262 * if no icon exists at that position.
4267 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4271 GtkIconViewItem *item;
4274 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4276 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4281 path = gtk_tree_path_new_from_indices (item->index, -1);
4287 * gtk_icon_view_get_item_at_pos:
4288 * @icon_view: A #GtkIconView.
4289 * @x: The x position to be identified
4290 * @y: The y position to be identified
4291 * @path: (out) (allow-none): Return location for the path, or %NULL
4292 * @cell: (out) (allow-none): Return location for the renderer
4293 * responsible for the cell at (@x, @y), or %NULL
4295 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4296 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4297 * obtains the cell at the specified position. The returned path should
4298 * be freed with gtk_tree_path_free().
4299 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4300 * widget coordinates to bin_window coordinates.
4302 * Return value: %TRUE if an item exists at the specified position
4307 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4311 GtkCellRenderer **cell)
4313 GtkIconViewItem *item;
4314 GtkCellRenderer *renderer = NULL;
4316 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4318 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4323 *path = gtk_tree_path_new_from_indices (item->index, -1);
4331 return (item != NULL);
4335 * gtk_icon_view_set_tooltip_item:
4336 * @icon_view: a #GtkIconView
4337 * @tooltip: a #GtkTooltip
4338 * @path: a #GtkTreePath
4340 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4341 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4342 * See also gtk_tooltip_set_tip_area().
4347 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4348 GtkTooltip *tooltip,
4351 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4352 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4354 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4358 * gtk_icon_view_set_tooltip_cell:
4359 * @icon_view: a #GtkIconView
4360 * @tooltip: a #GtkTooltip
4361 * @path: a #GtkTreePath
4362 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4364 * Sets the tip area of @tooltip to the area which @cell occupies in
4365 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4367 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4372 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4373 GtkTooltip *tooltip,
4375 GtkCellRenderer *cell)
4378 GtkIconViewItem *item = NULL;
4381 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4382 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4383 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4385 if (gtk_tree_path_get_depth (path) > 0)
4386 item = g_list_nth_data (icon_view->priv->items,
4387 gtk_tree_path_get_indices(path)[0]);
4394 GtkCellAreaContext *context;
4396 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4397 gtk_icon_view_set_cell_data (icon_view, item);
4398 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4399 GTK_WIDGET (icon_view),
4400 cell, (GdkRectangle *)item, &rect);
4404 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4405 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4406 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4407 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4410 if (icon_view->priv->bin_window)
4412 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4417 gtk_tooltip_set_tip_area (tooltip, &rect);
4422 * gtk_icon_view_get_tooltip_context:
4423 * @icon_view: an #GtkIconView
4424 * @x: (inout): the x coordinate (relative to widget coordinates)
4425 * @y: (inout): the y coordinate (relative to widget coordinates)
4426 * @keyboard_tip: whether this is a keyboard tooltip or not
4427 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4428 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4429 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4431 * This function is supposed to be used in a #GtkWidget::query-tooltip
4432 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4433 * which are received in the signal handler, should be passed to this
4434 * function without modification.
4436 * The return value indicates whether there is an icon view item at the given
4437 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4438 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4439 * @model, @path and @iter which have been provided will be set to point to
4440 * that row and the corresponding model. @x and @y will always be converted
4441 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4443 * Return value: whether or not the given tooltip context points to a item
4448 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4451 gboolean keyboard_tip,
4452 GtkTreeModel **model,
4456 GtkTreePath *tmppath = NULL;
4458 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4459 g_return_val_if_fail (x != NULL, FALSE);
4460 g_return_val_if_fail (y != NULL, FALSE);
4464 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4471 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4474 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4479 *model = gtk_icon_view_get_model (icon_view);
4482 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4488 gtk_tree_path_free (tmppath);
4494 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4497 gboolean keyboard_tip,
4498 GtkTooltip *tooltip,
4504 GtkTreeModel *model;
4505 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4507 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4510 &model, &path, &iter))
4513 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4517 gtk_tree_path_free (path);
4521 gtk_tooltip_set_markup (tooltip, str);
4522 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4524 gtk_tree_path_free (path);
4532 * gtk_icon_view_set_tooltip_column:
4533 * @icon_view: a #GtkIconView
4534 * @column: an integer, which is a valid column number for @icon_view's model
4536 * If you only plan to have simple (text-only) tooltips on full items, you
4537 * can use this function to have #GtkIconView handle these automatically
4538 * for you. @column should be set to the column in @icon_view's model
4539 * containing the tooltip texts, or -1 to disable this feature.
4541 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4542 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4544 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4545 * so &, <, etc have to be escaped in the text.
4550 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4553 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4555 if (column == icon_view->priv->tooltip_column)
4560 g_signal_handlers_disconnect_by_func (icon_view,
4561 gtk_icon_view_set_tooltip_query_cb,
4563 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4567 if (icon_view->priv->tooltip_column == -1)
4569 g_signal_connect (icon_view, "query-tooltip",
4570 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4571 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4575 icon_view->priv->tooltip_column = column;
4576 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4580 * gtk_icon_view_get_tooltip_column:
4581 * @icon_view: a #GtkIconView
4583 * Returns the column of @icon_view's model which is being used for
4584 * displaying tooltips on @icon_view's rows.
4586 * Return value: the index of the tooltip column that is currently being
4587 * used, or -1 if this is disabled.
4592 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4594 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4596 return icon_view->priv->tooltip_column;
4600 * gtk_icon_view_get_visible_range:
4601 * @icon_view: A #GtkIconView
4602 * @start_path: (out) (allow-none): Return location for start of region,
4604 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4606 * Sets @start_path and @end_path to be the first and last visible path.
4607 * Note that there may be invisible paths in between.
4609 * Both paths should be freed with gtk_tree_path_free() after use.
4611 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4616 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4617 GtkTreePath **start_path,
4618 GtkTreePath **end_path)
4620 gint start_index = -1;
4621 gint end_index = -1;
4624 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4626 if (icon_view->priv->hadjustment == NULL ||
4627 icon_view->priv->vadjustment == NULL)
4630 if (start_path == NULL && end_path == NULL)
4633 for (icons = icon_view->priv->items; icons; icons = icons->next)
4635 GtkIconViewItem *item = icons->data;
4636 GdkRectangle *item_area = (GdkRectangle *)item;
4638 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4639 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4641 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4642 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4644 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4645 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4647 if (start_index == -1)
4648 start_index = item->index;
4649 end_index = item->index;
4653 if (start_path && start_index != -1)
4654 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4655 if (end_path && end_index != -1)
4656 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4658 return start_index != -1;
4662 * gtk_icon_view_selected_foreach:
4663 * @icon_view: A #GtkIconView.
4664 * @func: (scope call): The function to call for each selected icon.
4665 * @data: User data to pass to the function.
4667 * Calls a function for each selected icon. Note that the model or
4668 * selection cannot be modified from within this function.
4673 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4674 GtkIconViewForeachFunc func,
4679 for (list = icon_view->priv->items; list; list = list->next)
4681 GtkIconViewItem *item = list->data;
4682 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4685 (* func) (icon_view, path, data);
4687 gtk_tree_path_free (path);
4692 * gtk_icon_view_set_selection_mode:
4693 * @icon_view: A #GtkIconView.
4694 * @mode: The selection mode
4696 * Sets the selection mode of the @icon_view.
4701 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4702 GtkSelectionMode mode)
4704 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4706 if (mode == icon_view->priv->selection_mode)
4709 if (mode == GTK_SELECTION_NONE ||
4710 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4711 gtk_icon_view_unselect_all (icon_view);
4713 icon_view->priv->selection_mode = mode;
4715 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4719 * gtk_icon_view_get_selection_mode:
4720 * @icon_view: A #GtkIconView.
4722 * Gets the selection mode of the @icon_view.
4724 * Return value: the current selection mode
4729 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4731 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4733 return icon_view->priv->selection_mode;
4737 * gtk_icon_view_set_model:
4738 * @icon_view: A #GtkIconView.
4739 * @model: (allow-none): The model.
4741 * Sets the model for a #GtkIconView.
4742 * If the @icon_view already has a model set, it will remove
4743 * it before setting the new model. If @model is %NULL, then
4744 * it will unset the old model.
4749 gtk_icon_view_set_model (GtkIconView *icon_view,
4750 GtkTreeModel *model)
4752 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4753 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4755 if (icon_view->priv->model == model)
4758 if (icon_view->priv->scroll_to_path)
4760 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4761 icon_view->priv->scroll_to_path = NULL;
4764 /* The area can be NULL while disposing */
4765 if (icon_view->priv->cell_area)
4766 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4772 if (icon_view->priv->pixbuf_column != -1)
4774 column_type = gtk_tree_model_get_column_type (model,
4775 icon_view->priv->pixbuf_column);
4777 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4780 if (icon_view->priv->text_column != -1)
4782 column_type = gtk_tree_model_get_column_type (model,
4783 icon_view->priv->text_column);
4785 g_return_if_fail (column_type == G_TYPE_STRING);
4788 if (icon_view->priv->markup_column != -1)
4790 column_type = gtk_tree_model_get_column_type (model,
4791 icon_view->priv->markup_column);
4793 g_return_if_fail (column_type == G_TYPE_STRING);
4798 if (icon_view->priv->model)
4800 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4801 gtk_icon_view_row_changed,
4803 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4804 gtk_icon_view_row_inserted,
4806 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4807 gtk_icon_view_row_deleted,
4809 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4810 gtk_icon_view_rows_reordered,
4813 g_object_unref (icon_view->priv->model);
4815 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4816 g_list_free (icon_view->priv->items);
4817 icon_view->priv->items = NULL;
4818 icon_view->priv->anchor_item = NULL;
4819 icon_view->priv->cursor_item = NULL;
4820 icon_view->priv->last_single_clicked = NULL;
4821 icon_view->priv->width = 0;
4822 icon_view->priv->height = 0;
4825 icon_view->priv->model = model;
4827 if (icon_view->priv->model)
4829 g_object_ref (icon_view->priv->model);
4830 g_signal_connect (icon_view->priv->model,
4832 G_CALLBACK (gtk_icon_view_row_changed),
4834 g_signal_connect (icon_view->priv->model,
4836 G_CALLBACK (gtk_icon_view_row_inserted),
4838 g_signal_connect (icon_view->priv->model,
4840 G_CALLBACK (gtk_icon_view_row_deleted),
4842 g_signal_connect (icon_view->priv->model,
4844 G_CALLBACK (gtk_icon_view_rows_reordered),
4847 gtk_icon_view_build_items (icon_view);
4849 gtk_icon_view_queue_layout (icon_view);
4852 g_object_notify (G_OBJECT (icon_view), "model");
4854 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4855 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4859 * gtk_icon_view_get_model:
4860 * @icon_view: a #GtkIconView
4862 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4865 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4866 * currently being used.
4871 gtk_icon_view_get_model (GtkIconView *icon_view)
4873 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4875 return icon_view->priv->model;
4879 update_text_cell (GtkIconView *icon_view)
4881 if (icon_view->priv->text_column == -1 &&
4882 icon_view->priv->markup_column == -1)
4884 if (icon_view->priv->text_cell != NULL)
4886 gtk_cell_area_remove (icon_view->priv->cell_area,
4887 icon_view->priv->text_cell);
4888 icon_view->priv->text_cell = NULL;
4893 if (icon_view->priv->text_cell == NULL)
4895 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4897 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4900 if (icon_view->priv->markup_column != -1)
4901 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4902 icon_view->priv->text_cell,
4903 "markup", icon_view->priv->markup_column,
4906 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4907 icon_view->priv->text_cell,
4908 "text", icon_view->priv->text_column,
4911 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4912 g_object_set (icon_view->priv->text_cell,
4913 "alignment", PANGO_ALIGN_CENTER,
4914 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4919 g_object_set (icon_view->priv->text_cell,
4920 "alignment", PANGO_ALIGN_LEFT,
4921 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4929 update_pixbuf_cell (GtkIconView *icon_view)
4931 if (icon_view->priv->pixbuf_column == -1)
4933 if (icon_view->priv->pixbuf_cell != NULL)
4935 gtk_cell_area_remove (icon_view->priv->cell_area,
4936 icon_view->priv->pixbuf_cell);
4938 icon_view->priv->pixbuf_cell = NULL;
4943 if (icon_view->priv->pixbuf_cell == NULL)
4945 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4947 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4950 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4951 icon_view->priv->pixbuf_cell,
4952 "pixbuf", icon_view->priv->pixbuf_column,
4955 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4956 g_object_set (icon_view->priv->pixbuf_cell,
4961 g_object_set (icon_view->priv->pixbuf_cell,
4969 * gtk_icon_view_set_text_column:
4970 * @icon_view: A #GtkIconView.
4971 * @column: A column in the currently used model, or -1 to display no text
4973 * Sets the column with text for @icon_view to be @column. The text
4974 * column must be of type #G_TYPE_STRING.
4979 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4982 if (column == icon_view->priv->text_column)
4986 icon_view->priv->text_column = -1;
4989 if (icon_view->priv->model != NULL)
4993 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4995 g_return_if_fail (column_type == G_TYPE_STRING);
4998 icon_view->priv->text_column = column;
5002 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5004 update_text_cell (icon_view);
5006 gtk_icon_view_invalidate_sizes (icon_view);
5008 g_object_notify (G_OBJECT (icon_view), "text-column");
5012 * gtk_icon_view_get_text_column:
5013 * @icon_view: A #GtkIconView.
5015 * Returns the column with text for @icon_view.
5017 * Returns: the text column, or -1 if it's unset.
5022 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5024 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5026 return icon_view->priv->text_column;
5030 * gtk_icon_view_set_markup_column:
5031 * @icon_view: A #GtkIconView.
5032 * @column: A column in the currently used model, or -1 to display no text
5034 * Sets the column with markup information for @icon_view to be
5035 * @column. The markup column must be of type #G_TYPE_STRING.
5036 * If the markup column is set to something, it overrides
5037 * the text column set by gtk_icon_view_set_text_column().
5042 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5045 if (column == icon_view->priv->markup_column)
5049 icon_view->priv->markup_column = -1;
5052 if (icon_view->priv->model != NULL)
5056 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5058 g_return_if_fail (column_type == G_TYPE_STRING);
5061 icon_view->priv->markup_column = column;
5064 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5066 update_text_cell (icon_view);
5068 gtk_icon_view_invalidate_sizes (icon_view);
5070 g_object_notify (G_OBJECT (icon_view), "markup-column");
5074 * gtk_icon_view_get_markup_column:
5075 * @icon_view: A #GtkIconView.
5077 * Returns the column with markup text for @icon_view.
5079 * Returns: the markup column, or -1 if it's unset.
5084 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5086 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5088 return icon_view->priv->markup_column;
5092 * gtk_icon_view_set_pixbuf_column:
5093 * @icon_view: A #GtkIconView.
5094 * @column: A column in the currently used model, or -1 to disable
5096 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5097 * column must be of type #GDK_TYPE_PIXBUF
5102 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5105 if (column == icon_view->priv->pixbuf_column)
5109 icon_view->priv->pixbuf_column = -1;
5112 if (icon_view->priv->model != NULL)
5116 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5118 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5121 icon_view->priv->pixbuf_column = column;
5124 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5126 update_pixbuf_cell (icon_view);
5128 gtk_icon_view_invalidate_sizes (icon_view);
5130 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5135 * gtk_icon_view_get_pixbuf_column:
5136 * @icon_view: A #GtkIconView.
5138 * Returns the column with pixbufs for @icon_view.
5140 * Returns: the pixbuf column, or -1 if it's unset.
5145 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5147 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5149 return icon_view->priv->pixbuf_column;
5153 * gtk_icon_view_select_path:
5154 * @icon_view: A #GtkIconView.
5155 * @path: The #GtkTreePath to be selected.
5157 * Selects the row at @path.
5162 gtk_icon_view_select_path (GtkIconView *icon_view,
5165 GtkIconViewItem *item = NULL;
5167 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5168 g_return_if_fail (icon_view->priv->model != NULL);
5169 g_return_if_fail (path != NULL);
5171 if (gtk_tree_path_get_depth (path) > 0)
5172 item = g_list_nth_data (icon_view->priv->items,
5173 gtk_tree_path_get_indices(path)[0]);
5176 gtk_icon_view_select_item (icon_view, item);
5180 * gtk_icon_view_unselect_path:
5181 * @icon_view: A #GtkIconView.
5182 * @path: The #GtkTreePath to be unselected.
5184 * Unselects the row at @path.
5189 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5192 GtkIconViewItem *item;
5194 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5195 g_return_if_fail (icon_view->priv->model != NULL);
5196 g_return_if_fail (path != NULL);
5198 item = g_list_nth_data (icon_view->priv->items,
5199 gtk_tree_path_get_indices(path)[0]);
5204 gtk_icon_view_unselect_item (icon_view, item);
5208 * gtk_icon_view_get_selected_items:
5209 * @icon_view: A #GtkIconView.
5211 * Creates a list of paths of all selected items. Additionally, if you are
5212 * planning on modifying the model after calling this function, you may
5213 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5214 * To do this, you can use gtk_tree_row_reference_new().
5216 * To free the return value, use:
5218 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5219 * g_list_free (list);
5222 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5227 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5230 GList *selected = NULL;
5232 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5234 for (list = icon_view->priv->items; list != NULL; list = list->next)
5236 GtkIconViewItem *item = list->data;
5240 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5242 selected = g_list_prepend (selected, path);
5250 * gtk_icon_view_select_all:
5251 * @icon_view: A #GtkIconView.
5253 * Selects all the icons. @icon_view must has its selection mode set
5254 * to #GTK_SELECTION_MULTIPLE.
5259 gtk_icon_view_select_all (GtkIconView *icon_view)
5262 gboolean dirty = FALSE;
5264 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5266 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5269 for (items = icon_view->priv->items; items; items = items->next)
5271 GtkIconViewItem *item = items->data;
5273 if (!item->selected)
5276 item->selected = TRUE;
5277 gtk_icon_view_queue_draw_item (icon_view, item);
5282 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5286 * gtk_icon_view_unselect_all:
5287 * @icon_view: A #GtkIconView.
5289 * Unselects all the icons.
5294 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5296 gboolean dirty = FALSE;
5298 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5300 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5303 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5306 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5310 * gtk_icon_view_path_is_selected:
5311 * @icon_view: A #GtkIconView.
5312 * @path: A #GtkTreePath to check selection on.
5314 * Returns %TRUE if the icon pointed to by @path is currently
5315 * selected. If @path does not point to a valid location, %FALSE is returned.
5317 * Return value: %TRUE if @path is selected.
5322 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5325 GtkIconViewItem *item;
5327 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5328 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5329 g_return_val_if_fail (path != NULL, FALSE);
5331 item = g_list_nth_data (icon_view->priv->items,
5332 gtk_tree_path_get_indices(path)[0]);
5337 return item->selected;
5341 * gtk_icon_view_get_item_row:
5342 * @icon_view: a #GtkIconView
5343 * @path: the #GtkTreePath of the item
5345 * Gets the row in which the item @path is currently
5346 * displayed. Row numbers start at 0.
5348 * Returns: The row in which the item is displayed
5353 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5356 GtkIconViewItem *item;
5358 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5359 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5360 g_return_val_if_fail (path != NULL, -1);
5362 item = g_list_nth_data (icon_view->priv->items,
5363 gtk_tree_path_get_indices(path)[0]);
5372 * gtk_icon_view_get_item_column:
5373 * @icon_view: a #GtkIconView
5374 * @path: the #GtkTreePath of the item
5376 * Gets the column in which the item @path is currently
5377 * displayed. Column numbers start at 0.
5379 * Returns: The column in which the item is displayed
5384 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5387 GtkIconViewItem *item;
5389 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5390 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5391 g_return_val_if_fail (path != NULL, -1);
5393 item = g_list_nth_data (icon_view->priv->items,
5394 gtk_tree_path_get_indices(path)[0]);
5403 * gtk_icon_view_item_activated:
5404 * @icon_view: A #GtkIconView
5405 * @path: The #GtkTreePath to be activated
5407 * Activates the item determined by @path.
5412 gtk_icon_view_item_activated (GtkIconView *icon_view,
5415 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5416 g_return_if_fail (path != NULL);
5418 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5422 * gtk_icon_view_set_item_orientation:
5423 * @icon_view: a #GtkIconView
5424 * @orientation: the relative position of texts and icons
5426 * Sets the ::item-orientation property which determines whether the labels
5427 * are drawn beside the icons instead of below.
5432 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5433 GtkOrientation orientation)
5435 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5437 if (icon_view->priv->item_orientation != orientation)
5439 icon_view->priv->item_orientation = orientation;
5441 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5442 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5443 icon_view->priv->item_orientation);
5445 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5446 gtk_icon_view_invalidate_sizes (icon_view);
5448 update_text_cell (icon_view);
5449 update_pixbuf_cell (icon_view);
5451 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5456 * gtk_icon_view_get_item_orientation:
5457 * @icon_view: a #GtkIconView
5459 * Returns the value of the ::item-orientation property which determines
5460 * whether the labels are drawn beside the icons instead of below.
5462 * Return value: the relative position of texts and icons
5467 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5469 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5470 GTK_ORIENTATION_VERTICAL);
5472 return icon_view->priv->item_orientation;
5476 * gtk_icon_view_set_columns:
5477 * @icon_view: a #GtkIconView
5478 * @columns: the number of columns
5480 * Sets the ::columns property which determines in how
5481 * many columns the icons are arranged. If @columns is
5482 * -1, the number of columns will be chosen automatically
5483 * to fill the available area.
5488 gtk_icon_view_set_columns (GtkIconView *icon_view,
5491 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5493 if (icon_view->priv->columns != columns)
5495 icon_view->priv->columns = columns;
5497 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5498 gtk_icon_view_queue_layout (icon_view);
5500 g_object_notify (G_OBJECT (icon_view), "columns");
5505 * gtk_icon_view_get_columns:
5506 * @icon_view: a #GtkIconView
5508 * Returns the value of the ::columns property.
5510 * Return value: the number of columns, or -1
5515 gtk_icon_view_get_columns (GtkIconView *icon_view)
5517 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5519 return icon_view->priv->columns;
5523 * gtk_icon_view_set_item_width:
5524 * @icon_view: a #GtkIconView
5525 * @item_width: the width for each item
5527 * Sets the ::item-width property which specifies the width
5528 * to use for each item. If it is set to -1, the icon view will
5529 * automatically determine a suitable item size.
5534 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5537 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5539 if (icon_view->priv->item_width != item_width)
5541 icon_view->priv->item_width = item_width;
5543 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5544 gtk_icon_view_invalidate_sizes (icon_view);
5546 update_text_cell (icon_view);
5548 g_object_notify (G_OBJECT (icon_view), "item-width");
5553 * gtk_icon_view_get_item_width:
5554 * @icon_view: a #GtkIconView
5556 * Returns the value of the ::item-width property.
5558 * Return value: the width of a single item, or -1
5563 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5565 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5567 return icon_view->priv->item_width;
5572 * gtk_icon_view_set_spacing:
5573 * @icon_view: a #GtkIconView
5574 * @spacing: the spacing
5576 * Sets the ::spacing property which specifies the space
5577 * which is inserted between the cells (i.e. the icon and
5578 * the text) of an item.
5583 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5586 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5588 if (icon_view->priv->spacing != spacing)
5590 icon_view->priv->spacing = spacing;
5592 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5593 gtk_icon_view_invalidate_sizes (icon_view);
5595 g_object_notify (G_OBJECT (icon_view), "spacing");
5600 * gtk_icon_view_get_spacing:
5601 * @icon_view: a #GtkIconView
5603 * Returns the value of the ::spacing property.
5605 * Return value: the space between cells
5610 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5612 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5614 return icon_view->priv->spacing;
5618 * gtk_icon_view_set_row_spacing:
5619 * @icon_view: a #GtkIconView
5620 * @row_spacing: the row spacing
5622 * Sets the ::row-spacing property which specifies the space
5623 * which is inserted between the rows of the icon view.
5628 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5631 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5633 if (icon_view->priv->row_spacing != row_spacing)
5635 icon_view->priv->row_spacing = row_spacing;
5637 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5638 gtk_icon_view_invalidate_sizes (icon_view);
5640 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5645 * gtk_icon_view_get_row_spacing:
5646 * @icon_view: a #GtkIconView
5648 * Returns the value of the ::row-spacing property.
5650 * Return value: the space between rows
5655 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5657 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5659 return icon_view->priv->row_spacing;
5663 * gtk_icon_view_set_column_spacing:
5664 * @icon_view: a #GtkIconView
5665 * @column_spacing: the column spacing
5667 * Sets the ::column-spacing property which specifies the space
5668 * which is inserted between the columns of the icon view.
5673 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5674 gint column_spacing)
5676 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5678 if (icon_view->priv->column_spacing != column_spacing)
5680 icon_view->priv->column_spacing = column_spacing;
5682 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5683 gtk_icon_view_invalidate_sizes (icon_view);
5685 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5690 * gtk_icon_view_get_column_spacing:
5691 * @icon_view: a #GtkIconView
5693 * Returns the value of the ::column-spacing property.
5695 * Return value: the space between columns
5700 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5702 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5704 return icon_view->priv->column_spacing;
5708 * gtk_icon_view_set_margin:
5709 * @icon_view: a #GtkIconView
5710 * @margin: the margin
5712 * Sets the ::margin property which specifies the space
5713 * which is inserted at the top, bottom, left and right
5719 gtk_icon_view_set_margin (GtkIconView *icon_view,
5722 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5724 if (icon_view->priv->margin != margin)
5726 icon_view->priv->margin = margin;
5728 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5729 gtk_icon_view_invalidate_sizes (icon_view);
5731 g_object_notify (G_OBJECT (icon_view), "margin");
5736 * gtk_icon_view_get_margin:
5737 * @icon_view: a #GtkIconView
5739 * Returns the value of the ::margin property.
5741 * Return value: the space at the borders
5746 gtk_icon_view_get_margin (GtkIconView *icon_view)
5748 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5750 return icon_view->priv->margin;
5754 * gtk_icon_view_set_item_padding:
5755 * @icon_view: a #GtkIconView
5756 * @item_padding: the item padding
5758 * Sets the #GtkIconView:item-padding property which specifies the padding
5759 * around each of the icon view's items.
5764 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5767 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5769 if (icon_view->priv->item_padding != item_padding)
5771 icon_view->priv->item_padding = item_padding;
5773 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5774 gtk_icon_view_invalidate_sizes (icon_view);
5776 g_object_notify (G_OBJECT (icon_view), "item-padding");
5781 * gtk_icon_view_get_item_padding:
5782 * @icon_view: a #GtkIconView
5784 * Returns the value of the ::item-padding property.
5786 * Return value: the padding around items
5791 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5793 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5795 return icon_view->priv->item_padding;
5798 /* Get/set whether drag_motion requested the drag data and
5799 * drag_data_received should thus not actually insert the data,
5800 * since the data doesn't result from a drop.
5803 set_status_pending (GdkDragContext *context,
5804 GdkDragAction suggested_action)
5806 g_object_set_data (G_OBJECT (context),
5807 I_("gtk-icon-view-status-pending"),
5808 GINT_TO_POINTER (suggested_action));
5811 static GdkDragAction
5812 get_status_pending (GdkDragContext *context)
5814 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5815 "gtk-icon-view-status-pending"));
5819 unset_reorderable (GtkIconView *icon_view)
5821 if (icon_view->priv->reorderable)
5823 icon_view->priv->reorderable = FALSE;
5824 g_object_notify (G_OBJECT (icon_view), "reorderable");
5829 set_source_row (GdkDragContext *context,
5830 GtkTreeModel *model,
5831 GtkTreePath *source_row)
5834 g_object_set_data_full (G_OBJECT (context),
5835 I_("gtk-icon-view-source-row"),
5836 gtk_tree_row_reference_new (model, source_row),
5837 (GDestroyNotify) gtk_tree_row_reference_free);
5839 g_object_set_data_full (G_OBJECT (context),
5840 I_("gtk-icon-view-source-row"),
5845 get_source_row (GdkDragContext *context)
5847 GtkTreeRowReference *ref;
5849 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5852 return gtk_tree_row_reference_get_path (ref);
5859 GtkTreeRowReference *dest_row;
5860 gboolean empty_view_drop;
5861 gboolean drop_append_mode;
5865 dest_row_free (gpointer data)
5867 DestRow *dr = (DestRow *)data;
5869 gtk_tree_row_reference_free (dr->dest_row);
5874 set_dest_row (GdkDragContext *context,
5875 GtkTreeModel *model,
5876 GtkTreePath *dest_row,
5877 gboolean empty_view_drop,
5878 gboolean drop_append_mode)
5884 g_object_set_data_full (G_OBJECT (context),
5885 I_("gtk-icon-view-dest-row"),
5890 dr = g_new0 (DestRow, 1);
5892 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5893 dr->empty_view_drop = empty_view_drop;
5894 dr->drop_append_mode = drop_append_mode;
5895 g_object_set_data_full (G_OBJECT (context),
5896 I_("gtk-icon-view-dest-row"),
5897 dr, (GDestroyNotify) dest_row_free);
5901 get_dest_row (GdkDragContext *context)
5905 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5909 GtkTreePath *path = NULL;
5912 path = gtk_tree_row_reference_get_path (dr->dest_row);
5913 else if (dr->empty_view_drop)
5914 path = gtk_tree_path_new_from_indices (0, -1);
5918 if (path && dr->drop_append_mode)
5919 gtk_tree_path_next (path);
5928 check_model_dnd (GtkTreeModel *model,
5929 GType required_iface,
5930 const gchar *signal)
5932 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5934 g_warning ("You must override the default '%s' handler "
5935 "on GtkIconView when using models that don't support "
5936 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5937 "is to connect to '%s' and call "
5938 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5939 "the default handler from running. Look at the source code "
5940 "for the default handler in gtkiconview.c to get an idea what "
5941 "your handler should do. (gtkiconview.c is in the GTK+ source "
5942 "code.) If you're using GTK+ from a language other than C, "
5943 "there may be a more natural way to override default handlers, e.g. via derivation.",
5944 signal, g_type_name (required_iface), signal);
5952 remove_scroll_timeout (GtkIconView *icon_view)
5954 if (icon_view->priv->scroll_timeout_id != 0)
5956 g_source_remove (icon_view->priv->scroll_timeout_id);
5958 icon_view->priv->scroll_timeout_id = 0;
5963 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5966 gint px, py, x, y, width, height;
5967 gint hoffset, voffset;
5969 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
5971 gdk_window_get_pointer (window, &px, &py, NULL);
5972 gdk_window_get_geometry (window, &x, &y, &width, &height);
5974 /* see if we are near the edge. */
5975 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5977 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5979 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5981 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5984 gtk_adjustment_set_value (icon_view->priv->vadjustment,
5985 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
5988 gtk_adjustment_set_value (icon_view->priv->hadjustment,
5989 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
5994 drag_scroll_timeout (gpointer data)
5996 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5998 gtk_icon_view_autoscroll (icon_view);
6005 set_destination (GtkIconView *icon_view,
6006 GdkDragContext *context,
6009 GdkDragAction *suggested_action,
6013 GtkTreePath *path = NULL;
6014 GtkIconViewDropPosition pos;
6015 GtkIconViewDropPosition old_pos;
6016 GtkTreePath *old_dest_path = NULL;
6017 gboolean can_drop = FALSE;
6019 widget = GTK_WIDGET (icon_view);
6021 *suggested_action = 0;
6024 if (!icon_view->priv->dest_set)
6026 /* someone unset us as a drag dest, note that if
6027 * we return FALSE drag_leave isn't called
6030 gtk_icon_view_set_drag_dest_item (icon_view,
6032 GTK_ICON_VIEW_DROP_LEFT);
6034 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6036 return FALSE; /* no longer a drop site */
6039 *target = gtk_drag_dest_find_target (widget, context,
6040 gtk_drag_dest_get_target_list (widget));
6041 if (*target == GDK_NONE)
6044 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6047 GtkTreeModel *model;
6049 /* the row got dropped on empty space, let's setup a special case
6053 gtk_tree_path_free (path);
6055 model = gtk_icon_view_get_model (icon_view);
6057 n_children = gtk_tree_model_iter_n_children (model, NULL);
6060 pos = GTK_ICON_VIEW_DROP_BELOW;
6061 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6065 pos = GTK_ICON_VIEW_DROP_ABOVE;
6066 path = gtk_tree_path_new_from_indices (0, -1);
6076 gtk_icon_view_get_drag_dest_item (icon_view,
6081 gtk_tree_path_free (old_dest_path);
6083 if (TRUE /* FIXME if the location droppable predicate */)
6091 GtkWidget *source_widget;
6093 *suggested_action = gdk_drag_context_get_suggested_action (context);
6094 source_widget = gtk_drag_get_source_widget (context);
6096 if (source_widget == widget)
6098 /* Default to MOVE, unless the user has
6099 * pressed ctrl or shift to affect available actions
6101 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6102 *suggested_action = GDK_ACTION_MOVE;
6105 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6110 /* can't drop here */
6111 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6113 GTK_ICON_VIEW_DROP_LEFT);
6117 gtk_tree_path_free (path);
6123 get_logical_destination (GtkIconView *icon_view,
6124 gboolean *drop_append_mode)
6126 /* adjust path to point to the row the drop goes in front of */
6127 GtkTreePath *path = NULL;
6128 GtkIconViewDropPosition pos;
6130 *drop_append_mode = FALSE;
6132 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6137 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6138 pos == GTK_ICON_VIEW_DROP_BELOW)
6141 GtkTreeModel *model = icon_view->priv->model;
6143 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6144 !gtk_tree_model_iter_next (model, &iter))
6145 *drop_append_mode = TRUE;
6148 *drop_append_mode = FALSE;
6149 gtk_tree_path_next (path);
6157 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6158 GdkEventMotion *event)
6160 GtkWidget *widget = GTK_WIDGET (icon_view);
6161 GdkDragContext *context;
6162 GtkTreePath *path = NULL;
6164 GtkTreeModel *model;
6165 gboolean retval = FALSE;
6167 if (!icon_view->priv->source_set)
6170 if (icon_view->priv->pressed_button < 0)
6173 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6174 icon_view->priv->press_start_x,
6175 icon_view->priv->press_start_y,
6176 event->x, event->y))
6179 model = gtk_icon_view_get_model (icon_view);
6184 button = icon_view->priv->pressed_button;
6185 icon_view->priv->pressed_button = -1;
6187 path = gtk_icon_view_get_path_at_pos (icon_view,
6188 icon_view->priv->press_start_x,
6189 icon_view->priv->press_start_y);
6194 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6195 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6199 /* FIXME Check whether we're a start button, if not return FALSE and
6203 /* Now we can begin the drag */
6207 context = gtk_drag_begin (widget,
6208 gtk_drag_source_get_target_list (widget),
6209 icon_view->priv->source_actions,
6213 set_source_row (context, model, path);
6217 gtk_tree_path_free (path);
6222 /* Source side drag signals */
6224 gtk_icon_view_drag_begin (GtkWidget *widget,
6225 GdkDragContext *context)
6227 GtkIconView *icon_view;
6228 GtkIconViewItem *item;
6229 cairo_surface_t *icon;
6233 icon_view = GTK_ICON_VIEW (widget);
6235 /* if the user uses a custom DnD impl, we don't set the icon here */
6236 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6239 item = gtk_icon_view_get_item_at_coords (icon_view,
6240 icon_view->priv->press_start_x,
6241 icon_view->priv->press_start_y,
6245 g_return_if_fail (item != NULL);
6247 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6248 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6250 path = gtk_tree_path_new_from_indices (item->index, -1);
6251 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6252 gtk_tree_path_free (path);
6254 cairo_surface_set_device_offset (icon, -x, -y);
6256 gtk_drag_set_icon_surface (context, icon);
6258 cairo_surface_destroy (icon);
6262 gtk_icon_view_drag_end (GtkWidget *widget,
6263 GdkDragContext *context)
6269 gtk_icon_view_drag_data_get (GtkWidget *widget,
6270 GdkDragContext *context,
6271 GtkSelectionData *selection_data,
6275 GtkIconView *icon_view;
6276 GtkTreeModel *model;
6277 GtkTreePath *source_row;
6279 icon_view = GTK_ICON_VIEW (widget);
6280 model = gtk_icon_view_get_model (icon_view);
6285 if (!icon_view->priv->source_set)
6288 source_row = get_source_row (context);
6290 if (source_row == NULL)
6293 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6294 * any model; for DragSource models there are some other targets
6298 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6299 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6304 /* If drag_data_get does nothing, try providing row data. */
6305 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6306 gtk_tree_set_row_drag_data (selection_data,
6311 gtk_tree_path_free (source_row);
6315 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6316 GdkDragContext *context)
6318 GtkTreeModel *model;
6319 GtkIconView *icon_view;
6320 GtkTreePath *source_row;
6322 icon_view = GTK_ICON_VIEW (widget);
6323 model = gtk_icon_view_get_model (icon_view);
6325 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6328 if (!icon_view->priv->source_set)
6331 source_row = get_source_row (context);
6333 if (source_row == NULL)
6336 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6339 gtk_tree_path_free (source_row);
6341 set_source_row (context, NULL, NULL);
6344 /* Target side drag signals */
6346 gtk_icon_view_drag_leave (GtkWidget *widget,
6347 GdkDragContext *context,
6350 GtkIconView *icon_view;
6352 icon_view = GTK_ICON_VIEW (widget);
6354 /* unset any highlight row */
6355 gtk_icon_view_set_drag_dest_item (icon_view,
6357 GTK_ICON_VIEW_DROP_LEFT);
6359 remove_scroll_timeout (icon_view);
6363 gtk_icon_view_drag_motion (GtkWidget *widget,
6364 GdkDragContext *context,
6369 GtkTreePath *path = NULL;
6370 GtkIconViewDropPosition pos;
6371 GtkIconView *icon_view;
6372 GdkDragAction suggested_action = 0;
6376 icon_view = GTK_ICON_VIEW (widget);
6378 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6381 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6383 /* we only know this *after* set_desination_row */
6384 empty = icon_view->priv->empty_view_drop;
6386 if (path == NULL && !empty)
6388 /* Can't drop here. */
6389 gdk_drag_status (context, 0, time);
6393 if (icon_view->priv->scroll_timeout_id == 0)
6395 icon_view->priv->scroll_timeout_id =
6396 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6399 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6401 /* Request data so we can use the source row when
6402 * determining whether to accept the drop
6404 set_status_pending (context, suggested_action);
6405 gtk_drag_get_data (widget, context, target, time);
6409 set_status_pending (context, 0);
6410 gdk_drag_status (context, suggested_action, time);
6415 gtk_tree_path_free (path);
6421 gtk_icon_view_drag_drop (GtkWidget *widget,
6422 GdkDragContext *context,
6427 GtkIconView *icon_view;
6429 GdkDragAction suggested_action = 0;
6430 GdkAtom target = GDK_NONE;
6431 GtkTreeModel *model;
6432 gboolean drop_append_mode;
6434 icon_view = GTK_ICON_VIEW (widget);
6435 model = gtk_icon_view_get_model (icon_view);
6437 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6439 if (!icon_view->priv->dest_set)
6442 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6445 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6448 path = get_logical_destination (icon_view, &drop_append_mode);
6450 if (target != GDK_NONE && path != NULL)
6452 /* in case a motion had requested drag data, change things so we
6453 * treat drag data receives as a drop.
6455 set_status_pending (context, 0);
6456 set_dest_row (context, model, path,
6457 icon_view->priv->empty_view_drop, drop_append_mode);
6461 gtk_tree_path_free (path);
6463 /* Unset this thing */
6464 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6466 if (target != GDK_NONE)
6468 gtk_drag_get_data (widget, context, target, time);
6476 gtk_icon_view_drag_data_received (GtkWidget *widget,
6477 GdkDragContext *context,
6480 GtkSelectionData *selection_data,
6485 gboolean accepted = FALSE;
6486 GtkTreeModel *model;
6487 GtkIconView *icon_view;
6488 GtkTreePath *dest_row;
6489 GdkDragAction suggested_action;
6490 gboolean drop_append_mode;
6492 icon_view = GTK_ICON_VIEW (widget);
6493 model = gtk_icon_view_get_model (icon_view);
6495 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6498 if (!icon_view->priv->dest_set)
6501 suggested_action = get_status_pending (context);
6503 if (suggested_action)
6505 /* We are getting this data due to a request in drag_motion,
6506 * rather than due to a request in drag_drop, so we are just
6507 * supposed to call drag_status, not actually paste in the
6510 path = get_logical_destination (icon_view, &drop_append_mode);
6513 suggested_action = 0;
6515 if (suggested_action)
6517 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6520 suggested_action = 0;
6523 gdk_drag_status (context, suggested_action, time);
6526 gtk_tree_path_free (path);
6528 /* If you can't drop, remove user drop indicator until the next motion */
6529 if (suggested_action == 0)
6530 gtk_icon_view_set_drag_dest_item (icon_view,
6532 GTK_ICON_VIEW_DROP_LEFT);
6537 dest_row = get_dest_row (context);
6539 if (dest_row == NULL)
6542 if (gtk_selection_data_get_length (selection_data) >= 0)
6544 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6550 gtk_drag_finish (context,
6552 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6555 gtk_tree_path_free (dest_row);
6558 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6561 /* Drag-and-Drop support */
6563 * gtk_icon_view_enable_model_drag_source:
6564 * @icon_view: a #GtkIconTreeView
6565 * @start_button_mask: Mask of allowed buttons to start drag
6566 * @targets: (array length=n_targets): the table of targets that the drag will
6568 * @n_targets: the number of items in @targets
6569 * @actions: the bitmask of possible actions for a drag from this
6572 * Turns @icon_view into a drag source for automatic DND. Calling this
6573 * method sets #GtkIconView:reorderable to %FALSE.
6578 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6579 GdkModifierType start_button_mask,
6580 const GtkTargetEntry *targets,
6582 GdkDragAction actions)
6584 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6586 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6588 icon_view->priv->start_button_mask = start_button_mask;
6589 icon_view->priv->source_actions = actions;
6591 icon_view->priv->source_set = TRUE;
6593 unset_reorderable (icon_view);
6597 * gtk_icon_view_enable_model_drag_dest:
6598 * @icon_view: a #GtkIconView
6599 * @targets: (array length=n_targets): the table of targets that the drag will
6601 * @n_targets: the number of items in @targets
6602 * @actions: the bitmask of possible actions for a drag to this
6605 * Turns @icon_view into a drop destination for automatic DND. Calling this
6606 * method sets #GtkIconView:reorderable to %FALSE.
6611 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6612 const GtkTargetEntry *targets,
6614 GdkDragAction actions)
6616 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6618 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6620 icon_view->priv->dest_actions = actions;
6622 icon_view->priv->dest_set = TRUE;
6624 unset_reorderable (icon_view);
6628 * gtk_icon_view_unset_model_drag_source:
6629 * @icon_view: a #GtkIconView
6631 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6632 * method sets #GtkIconView:reorderable to %FALSE.
6637 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6639 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6641 if (icon_view->priv->source_set)
6643 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6644 icon_view->priv->source_set = FALSE;
6647 unset_reorderable (icon_view);
6651 * gtk_icon_view_unset_model_drag_dest:
6652 * @icon_view: a #GtkIconView
6654 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6655 * method sets #GtkIconView:reorderable to %FALSE.
6660 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6662 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6664 if (icon_view->priv->dest_set)
6666 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6667 icon_view->priv->dest_set = FALSE;
6670 unset_reorderable (icon_view);
6673 /* These are useful to implement your own custom stuff. */
6675 * gtk_icon_view_set_drag_dest_item:
6676 * @icon_view: a #GtkIconView
6677 * @path: (allow-none): The path of the item to highlight, or %NULL.
6678 * @pos: Specifies where to drop, relative to the item
6680 * Sets the item that is highlighted for feedback.
6685 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6687 GtkIconViewDropPosition pos)
6689 /* Note; this function is exported to allow a custom DND
6690 * implementation, so it can't touch TreeViewDragInfo
6693 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6695 if (icon_view->priv->dest_item)
6697 GtkTreePath *current_path;
6698 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6699 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6700 icon_view->priv->dest_item = NULL;
6702 gtk_icon_view_queue_draw_path (icon_view, current_path);
6703 gtk_tree_path_free (current_path);
6706 /* special case a drop on an empty model */
6707 icon_view->priv->empty_view_drop = FALSE;
6708 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6709 && gtk_tree_path_get_depth (path) == 1
6710 && gtk_tree_path_get_indices (path)[0] == 0)
6714 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6717 if (n_children == 0)
6718 icon_view->priv->empty_view_drop = TRUE;
6721 icon_view->priv->dest_pos = pos;
6725 icon_view->priv->dest_item =
6726 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6727 icon_view->priv->model, path);
6729 gtk_icon_view_queue_draw_path (icon_view, path);
6734 * gtk_icon_view_get_drag_dest_item:
6735 * @icon_view: a #GtkIconView
6736 * @path: (out) (allow-none): Return location for the path of
6737 * the highlighted item, or %NULL.
6738 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6740 * Gets information about the item that is highlighted for feedback.
6745 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6747 GtkIconViewDropPosition *pos)
6749 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6753 if (icon_view->priv->dest_item)
6754 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6760 *pos = icon_view->priv->dest_pos;
6764 * gtk_icon_view_get_dest_item_at_pos:
6765 * @icon_view: a #GtkIconView
6766 * @drag_x: the position to determine the destination item for
6767 * @drag_y: the position to determine the destination item for
6768 * @path: (out) (allow-none): Return location for the path of the item,
6770 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6772 * Determines the destination item for a given position.
6774 * Return value: whether there is an item at the given position.
6779 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6783 GtkIconViewDropPosition *pos)
6785 GtkIconViewItem *item;
6787 /* Note; this function is exported to allow a custom DND
6788 * implementation, so it can't touch TreeViewDragInfo
6791 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6792 g_return_val_if_fail (drag_x >= 0, FALSE);
6793 g_return_val_if_fail (drag_y >= 0, FALSE);
6794 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6800 item = gtk_icon_view_get_item_at_coords (icon_view,
6801 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6802 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6809 *path = gtk_tree_path_new_from_indices (item->index, -1);
6813 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6814 *pos = GTK_ICON_VIEW_DROP_LEFT;
6815 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6816 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6817 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6818 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6819 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6820 *pos = GTK_ICON_VIEW_DROP_BELOW;
6822 *pos = GTK_ICON_VIEW_DROP_INTO;
6829 * gtk_icon_view_create_drag_icon:
6830 * @icon_view: a #GtkIconView
6831 * @path: a #GtkTreePath in @icon_view
6833 * Creates a #cairo_surface_t representation of the item at @path.
6834 * This image is used for a drag icon.
6836 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6841 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6845 GtkStyleContext *context;
6847 cairo_surface_t *surface;
6851 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6852 g_return_val_if_fail (path != NULL, NULL);
6854 widget = GTK_WIDGET (icon_view);
6855 context = gtk_widget_get_style_context (widget);
6857 if (!gtk_widget_get_realized (widget))
6860 index = gtk_tree_path_get_indices (path)[0];
6862 for (l = icon_view->priv->items; l; l = l->next)
6864 GtkIconViewItem *item = l->data;
6866 if (index == item->index)
6868 GdkRectangle rect = {
6869 item->cell_area.x - icon_view->priv->item_padding,
6870 item->cell_area.y - icon_view->priv->item_padding,
6871 item->cell_area.width + icon_view->priv->item_padding * 2,
6872 item->cell_area.height + icon_view->priv->item_padding * 2
6875 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6876 CAIRO_CONTENT_COLOR,
6880 cr = cairo_create (surface);
6881 cairo_set_line_width (cr, 1.);
6883 gtk_render_background (context, cr, 0, 0,
6884 rect.width + 2, rect.height + 2);
6888 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6891 gtk_icon_view_paint_item (icon_view, cr, item,
6892 icon_view->priv->item_padding + 1,
6893 icon_view->priv->item_padding + 1, FALSE);
6897 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6898 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6911 * gtk_icon_view_get_reorderable:
6912 * @icon_view: a #GtkIconView
6914 * Retrieves whether the user can reorder the list via drag-and-drop.
6915 * See gtk_icon_view_set_reorderable().
6917 * Return value: %TRUE if the list can be reordered.
6922 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6924 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6926 return icon_view->priv->reorderable;
6929 static const GtkTargetEntry item_targets[] = {
6930 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6935 * gtk_icon_view_set_reorderable:
6936 * @icon_view: A #GtkIconView.
6937 * @reorderable: %TRUE, if the list of items can be reordered.
6939 * This function is a convenience function to allow you to reorder models that
6940 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6941 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6942 * the user can reorder the model by dragging and dropping rows. The
6943 * developer can listen to these changes by connecting to the model's
6944 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6945 * the icon view as a drag source and destination. Therefore, drag and
6946 * drop can not be used in a reorderable view for any other purpose.
6948 * This function does not give you any degree of control over the order -- any
6949 * reordering is allowed. If more control is needed, you should probably
6950 * handle drag and drop manually.
6955 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6956 gboolean reorderable)
6958 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6960 reorderable = reorderable != FALSE;
6962 if (icon_view->priv->reorderable == reorderable)
6967 gtk_icon_view_enable_model_drag_source (icon_view,
6970 G_N_ELEMENTS (item_targets),
6972 gtk_icon_view_enable_model_drag_dest (icon_view,
6974 G_N_ELEMENTS (item_targets),
6979 gtk_icon_view_unset_model_drag_source (icon_view);
6980 gtk_icon_view_unset_model_drag_dest (icon_view);
6983 icon_view->priv->reorderable = reorderable;
6985 g_object_notify (G_OBJECT (icon_view), "reorderable");
6989 /* Accessibility Support */
6991 static gpointer accessible_parent_class;
6992 static gpointer accessible_item_parent_class;
6993 static GQuark accessible_private_data_quark = 0;
6995 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6996 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6997 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6999 static GType gtk_icon_view_item_accessible_get_type (void);
7010 GtkIconViewItem *item;
7014 AtkStateSet *state_set;
7018 GtkTextBuffer *text_buffer;
7020 gchar *action_descriptions[LAST_ACTION];
7021 gchar *image_description;
7022 guint action_idle_handler;
7023 } GtkIconViewItemAccessible;
7025 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7031 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7036 typedef struct _GtkIconViewItemAccessibleClass
7038 AtkObjectClass parent_class;
7040 } GtkIconViewItemAccessibleClass;
7042 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7045 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7047 GtkIconViewItemAccessible *item;
7048 GtkIconView *icon_view;
7051 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7052 item->action_idle_handler = 0;
7054 if (item->widget != NULL)
7056 icon_view = GTK_ICON_VIEW (item->widget);
7057 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7058 gtk_icon_view_item_activated (icon_view, path);
7059 gtk_tree_path_free (path);
7066 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7069 GtkIconViewItemAccessible *item;
7071 if (i < 0 || i >= LAST_ACTION)
7074 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7076 if (!GTK_IS_ICON_VIEW (item->widget))
7079 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7084 case ACTION_ACTIVATE:
7085 if (!item->action_idle_handler)
7086 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7089 g_assert_not_reached ();
7097 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7102 static const gchar *
7103 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7106 GtkIconViewItemAccessible *item;
7108 if (i < 0 || i >= LAST_ACTION)
7111 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7113 if (item->action_descriptions[i])
7114 return item->action_descriptions[i];
7116 return gtk_icon_view_item_accessible_action_descriptions[i];
7119 static const gchar *
7120 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7123 if (i < 0 || i >= LAST_ACTION)
7126 return gtk_icon_view_item_accessible_action_names[i];
7130 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7132 const gchar *description)
7134 GtkIconViewItemAccessible *item;
7136 if (i < 0 || i >= LAST_ACTION)
7139 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7141 g_free (item->action_descriptions[i]);
7143 item->action_descriptions[i] = g_strdup (description);
7149 atk_action_item_interface_init (AtkActionIface *iface)
7151 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7152 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7153 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7154 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7155 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7158 static const gchar *
7159 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7161 GtkIconViewItemAccessible *item;
7163 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7165 return item->image_description;
7169 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7170 const gchar *description)
7172 GtkIconViewItemAccessible *item;
7174 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7176 g_free (item->image_description);
7177 item->image_description = g_strdup (description);
7184 gboolean pixbuf_found;
7188 get_pixbuf_foreach (GtkCellRenderer *renderer,
7189 const GdkRectangle *cell_area,
7190 const GdkRectangle *cell_background,
7191 GetPixbufBoxData *data)
7193 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7195 data->box = *cell_area;
7196 data->pixbuf_found = TRUE;
7198 return (data->pixbuf_found != FALSE);
7202 get_pixbuf_box (GtkIconView *icon_view,
7203 GtkIconViewItem *item,
7206 GetPixbufBoxData data = { { 0, }, FALSE };
7207 GtkCellAreaContext *context;
7209 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7211 gtk_icon_view_set_cell_data (icon_view, item);
7212 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7213 GTK_WIDGET (icon_view),
7214 (GdkRectangle *)item, (GdkRectangle *)item,
7215 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7217 return data.pixbuf_found;
7221 get_text_foreach (GtkCellRenderer *renderer,
7224 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7226 g_object_get (renderer, "text", text, NULL);
7234 get_text (GtkIconView *icon_view,
7235 GtkIconViewItem *item)
7239 gtk_icon_view_set_cell_data (icon_view, item);
7240 gtk_cell_area_foreach (icon_view->priv->cell_area,
7241 (GtkCellCallback)get_text_foreach, &text);
7247 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7251 GtkIconViewItemAccessible *item;
7254 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7256 if (!GTK_IS_ICON_VIEW (item->widget))
7259 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7262 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7265 *height = box.height;
7270 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7273 AtkCoordType coord_type)
7275 GtkIconViewItemAccessible *item;
7278 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7280 if (!GTK_IS_ICON_VIEW (item->widget))
7283 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7286 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7288 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7290 *x+= box.x - item->item->cell_area.x;
7291 *y+= box.y - item->item->cell_area.y;
7297 atk_image_item_interface_init (AtkImageIface *iface)
7299 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7300 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7301 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7302 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7306 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7310 GtkIconViewItemAccessible *item;
7311 GtkTextIter start, end;
7312 GtkTextBuffer *buffer;
7314 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7316 if (!GTK_IS_ICON_VIEW (item->widget))
7319 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7322 buffer = item->text_buffer;
7323 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7325 gtk_text_buffer_get_end_iter (buffer, &end);
7327 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7329 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7333 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7336 GtkIconViewItemAccessible *item;
7337 GtkTextIter start, end;
7338 GtkTextBuffer *buffer;
7342 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7344 if (!GTK_IS_ICON_VIEW (item->widget))
7347 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7350 buffer = item->text_buffer;
7351 if (offset >= gtk_text_buffer_get_char_count (buffer))
7354 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7356 gtk_text_iter_forward_char (&end);
7357 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7358 unichar = g_utf8_get_char (string);
7366 get_pango_text_offsets (PangoLayout *layout,
7367 GtkTextBuffer *buffer,
7369 AtkTextBoundary boundary_type,
7373 GtkTextIter *start_iter,
7374 GtkTextIter *end_iter)
7376 PangoLayoutIter *iter;
7377 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7378 gint index, start_index, end_index;
7380 gboolean found = FALSE;
7382 text = pango_layout_get_text (layout);
7383 index = g_utf8_offset_to_pointer (text, offset) - text;
7384 iter = pango_layout_get_iter (layout);
7387 line = pango_layout_iter_get_line_readonly (iter);
7388 start_index = line->start_index;
7389 end_index = start_index + line->length;
7391 if (index >= start_index && index <= end_index)
7394 * Found line for offset
7400 * We want the previous line
7404 switch (boundary_type)
7406 case ATK_TEXT_BOUNDARY_LINE_START:
7407 end_index = start_index;
7408 start_index = prev_line->start_index;
7410 case ATK_TEXT_BOUNDARY_LINE_END:
7412 start_index = prev_prev_line->start_index +
7413 prev_prev_line->length;
7414 end_index = prev_line->start_index + prev_line->length;
7417 g_assert_not_reached();
7421 start_index = end_index = 0;
7424 switch (boundary_type)
7426 case ATK_TEXT_BOUNDARY_LINE_START:
7427 if (pango_layout_iter_next_line (iter))
7428 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7430 case ATK_TEXT_BOUNDARY_LINE_END:
7432 start_index = prev_line->start_index +
7436 g_assert_not_reached();
7441 * We want the next line
7443 if (pango_layout_iter_next_line (iter))
7445 line = pango_layout_iter_get_line_readonly (iter);
7446 switch (boundary_type)
7448 case ATK_TEXT_BOUNDARY_LINE_START:
7449 start_index = line->start_index;
7450 if (pango_layout_iter_next_line (iter))
7451 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7453 end_index = start_index + line->length;
7455 case ATK_TEXT_BOUNDARY_LINE_END:
7456 start_index = end_index;
7457 end_index = line->start_index + line->length;
7460 g_assert_not_reached();
7464 start_index = end_index;
7470 prev_prev_line = prev_line;
7473 while (pango_layout_iter_next_line (iter));
7477 start_index = prev_line->start_index + prev_line->length;
7478 end_index = start_index;
7480 pango_layout_iter_free (iter);
7481 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7482 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7484 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7485 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7490 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7492 AtkTextBoundary boundary_type,
7496 GtkIconViewItemAccessible *item;
7497 GtkTextIter start, end;
7498 GtkTextBuffer *buffer;
7500 GtkIconView *icon_view;
7503 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7505 if (!GTK_IS_ICON_VIEW (item->widget))
7508 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7511 buffer = item->text_buffer;
7513 if (!gtk_text_buffer_get_char_count (buffer))
7517 return g_strdup ("");
7519 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7523 switch (boundary_type)
7525 case ATK_TEXT_BOUNDARY_CHAR:
7526 gtk_text_iter_backward_char(&start);
7528 case ATK_TEXT_BOUNDARY_WORD_START:
7529 if (!gtk_text_iter_starts_word (&start))
7530 gtk_text_iter_backward_word_start (&start);
7532 gtk_text_iter_backward_word_start(&start);
7534 case ATK_TEXT_BOUNDARY_WORD_END:
7535 if (gtk_text_iter_inside_word (&start) &&
7536 !gtk_text_iter_starts_word (&start))
7537 gtk_text_iter_backward_word_start (&start);
7538 while (!gtk_text_iter_ends_word (&start))
7540 if (!gtk_text_iter_backward_char (&start))
7544 gtk_text_iter_backward_word_start(&start);
7545 while (!gtk_text_iter_ends_word (&start))
7547 if (!gtk_text_iter_backward_char (&start))
7551 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7552 if (!gtk_text_iter_starts_sentence (&start))
7553 gtk_text_iter_backward_sentence_start (&start);
7555 gtk_text_iter_backward_sentence_start (&start);
7557 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7558 if (gtk_text_iter_inside_sentence (&start) &&
7559 !gtk_text_iter_starts_sentence (&start))
7560 gtk_text_iter_backward_sentence_start (&start);
7561 while (!gtk_text_iter_ends_sentence (&start))
7563 if (!gtk_text_iter_backward_char (&start))
7567 gtk_text_iter_backward_sentence_start (&start);
7568 while (!gtk_text_iter_ends_sentence (&start))
7570 if (!gtk_text_iter_backward_char (&start))
7574 case ATK_TEXT_BOUNDARY_LINE_START:
7575 case ATK_TEXT_BOUNDARY_LINE_END:
7577 icon_view = GTK_ICON_VIEW (item->widget);
7578 /* FIXME we probably have to use GailTextCell to salvage this */
7579 gtk_icon_view_update_item_text (icon_view, item->item);
7580 get_pango_text_offsets (icon_view->priv->layout,
7593 *start_offset = gtk_text_iter_get_offset (&start);
7594 *end_offset = gtk_text_iter_get_offset (&end);
7596 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7600 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7602 AtkTextBoundary boundary_type,
7606 GtkIconViewItemAccessible *item;
7607 GtkTextIter start, end;
7608 GtkTextBuffer *buffer;
7610 GtkIconView *icon_view;
7613 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7615 if (!GTK_IS_ICON_VIEW (item->widget))
7618 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7621 buffer = item->text_buffer;
7623 if (!gtk_text_buffer_get_char_count (buffer))
7627 return g_strdup ("");
7629 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7633 switch (boundary_type)
7635 case ATK_TEXT_BOUNDARY_CHAR:
7636 gtk_text_iter_forward_char (&end);
7638 case ATK_TEXT_BOUNDARY_WORD_START:
7639 if (!gtk_text_iter_starts_word (&start))
7640 gtk_text_iter_backward_word_start (&start);
7641 if (gtk_text_iter_inside_word (&end))
7642 gtk_text_iter_forward_word_end (&end);
7643 while (!gtk_text_iter_starts_word (&end))
7645 if (!gtk_text_iter_forward_char (&end))
7649 case ATK_TEXT_BOUNDARY_WORD_END:
7650 if (gtk_text_iter_inside_word (&start) &&
7651 !gtk_text_iter_starts_word (&start))
7652 gtk_text_iter_backward_word_start (&start);
7653 while (!gtk_text_iter_ends_word (&start))
7655 if (!gtk_text_iter_backward_char (&start))
7658 gtk_text_iter_forward_word_end (&end);
7660 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7661 if (!gtk_text_iter_starts_sentence (&start))
7662 gtk_text_iter_backward_sentence_start (&start);
7663 if (gtk_text_iter_inside_sentence (&end))
7664 gtk_text_iter_forward_sentence_end (&end);
7665 while (!gtk_text_iter_starts_sentence (&end))
7667 if (!gtk_text_iter_forward_char (&end))
7671 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7672 if (gtk_text_iter_inside_sentence (&start) &&
7673 !gtk_text_iter_starts_sentence (&start))
7674 gtk_text_iter_backward_sentence_start (&start);
7675 while (!gtk_text_iter_ends_sentence (&start))
7677 if (!gtk_text_iter_backward_char (&start))
7680 gtk_text_iter_forward_sentence_end (&end);
7682 case ATK_TEXT_BOUNDARY_LINE_START:
7683 case ATK_TEXT_BOUNDARY_LINE_END:
7685 icon_view = GTK_ICON_VIEW (item->widget);
7686 /* FIXME we probably have to use GailTextCell to salvage this */
7687 gtk_icon_view_update_item_text (icon_view, item->item);
7688 get_pango_text_offsets (icon_view->priv->layout,
7702 *start_offset = gtk_text_iter_get_offset (&start);
7703 *end_offset = gtk_text_iter_get_offset (&end);
7705 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7709 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7711 AtkTextBoundary boundary_type,
7715 GtkIconViewItemAccessible *item;
7716 GtkTextIter start, end;
7717 GtkTextBuffer *buffer;
7719 GtkIconView *icon_view;
7722 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7724 if (!GTK_IS_ICON_VIEW (item->widget))
7727 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7730 buffer = item->text_buffer;
7732 if (!gtk_text_buffer_get_char_count (buffer))
7736 return g_strdup ("");
7738 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7742 switch (boundary_type)
7744 case ATK_TEXT_BOUNDARY_CHAR:
7745 gtk_text_iter_forward_char(&start);
7746 gtk_text_iter_forward_chars(&end, 2);
7748 case ATK_TEXT_BOUNDARY_WORD_START:
7749 if (gtk_text_iter_inside_word (&end))
7750 gtk_text_iter_forward_word_end (&end);
7751 while (!gtk_text_iter_starts_word (&end))
7753 if (!gtk_text_iter_forward_char (&end))
7757 if (!gtk_text_iter_is_end (&end))
7759 gtk_text_iter_forward_word_end (&end);
7760 while (!gtk_text_iter_starts_word (&end))
7762 if (!gtk_text_iter_forward_char (&end))
7767 case ATK_TEXT_BOUNDARY_WORD_END:
7768 gtk_text_iter_forward_word_end (&end);
7770 if (!gtk_text_iter_is_end (&end))
7771 gtk_text_iter_forward_word_end (&end);
7773 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7774 if (gtk_text_iter_inside_sentence (&end))
7775 gtk_text_iter_forward_sentence_end (&end);
7776 while (!gtk_text_iter_starts_sentence (&end))
7778 if (!gtk_text_iter_forward_char (&end))
7782 if (!gtk_text_iter_is_end (&end))
7784 gtk_text_iter_forward_sentence_end (&end);
7785 while (!gtk_text_iter_starts_sentence (&end))
7787 if (!gtk_text_iter_forward_char (&end))
7792 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7793 gtk_text_iter_forward_sentence_end (&end);
7795 if (!gtk_text_iter_is_end (&end))
7796 gtk_text_iter_forward_sentence_end (&end);
7798 case ATK_TEXT_BOUNDARY_LINE_START:
7799 case ATK_TEXT_BOUNDARY_LINE_END:
7801 icon_view = GTK_ICON_VIEW (item->widget);
7802 /* FIXME we probably have to use GailTextCell to salvage this */
7803 gtk_icon_view_update_item_text (icon_view, item->item);
7804 get_pango_text_offsets (icon_view->priv->layout,
7816 *start_offset = gtk_text_iter_get_offset (&start);
7817 *end_offset = gtk_text_iter_get_offset (&end);
7819 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7823 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7825 GtkIconViewItemAccessible *item;
7827 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7829 if (!GTK_IS_ICON_VIEW (item->widget))
7832 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7835 return gtk_text_buffer_get_char_count (item->text_buffer);
7839 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7845 AtkCoordType coord_type)
7847 GtkIconViewItemAccessible *item;
7849 GtkIconView *icon_view;
7850 PangoRectangle char_rect;
7851 const gchar *item_text;
7855 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7857 if (!GTK_IS_ICON_VIEW (item->widget))
7860 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7864 icon_view = GTK_ICON_VIEW (item->widget);
7865 /* FIXME we probably have to use GailTextCell to salvage this */
7866 gtk_icon_view_update_item_text (icon_view, item->item);
7867 item_text = pango_layout_get_text (icon_view->priv->layout);
7868 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7869 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7871 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7872 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7873 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7874 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7875 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7876 *width = char_rect.width / PANGO_SCALE;
7877 *height = char_rect.height / PANGO_SCALE;
7882 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7885 AtkCoordType coord_type)
7887 GtkIconViewItemAccessible *item;
7890 GtkIconView *icon_view;
7891 const gchar *item_text;
7896 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7898 if (!GTK_IS_ICON_VIEW (item->widget))
7901 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7905 icon_view = GTK_ICON_VIEW (item->widget);
7906 /* FIXME we probably have to use GailTextCell to salvage this */
7907 gtk_icon_view_update_item_text (icon_view, item->item);
7908 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7909 x -= l_x + item->item->layout_x - item->item->x;
7910 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7911 y -= l_y + item->item->layout_y - item->item->y;
7912 item_text = pango_layout_get_text (icon_view->priv->layout);
7913 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7924 offset = g_utf8_strlen (item_text, -1);
7926 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7932 atk_text_item_interface_init (AtkTextIface *iface)
7934 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7935 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7936 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7937 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7938 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7939 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7940 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7941 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7945 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7950 AtkCoordType coord_type)
7952 GtkIconViewItemAccessible *item;
7953 AtkObject *parent_obj;
7956 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7958 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7959 if (!GTK_IS_WIDGET (item->widget))
7962 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7965 *width = item->item->cell_area.width;
7966 *height = item->item->cell_area.height;
7967 if (gtk_icon_view_item_accessible_is_showing (item))
7969 parent_obj = gtk_widget_get_accessible (item->widget);
7970 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7971 *x = l_x + item->item->cell_area.x;
7972 *y = l_y + item->item->cell_area.y;
7982 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7984 GtkIconViewItemAccessible *item;
7985 GtkWidget *toplevel;
7987 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7989 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7990 if (!GTK_IS_WIDGET (item->widget))
7993 gtk_widget_grab_focus (item->widget);
7994 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
7995 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7996 if (gtk_widget_is_toplevel (toplevel))
7997 gtk_window_present (GTK_WINDOW (toplevel));
8003 atk_component_item_interface_init (AtkComponentIface *iface)
8005 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8006 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8010 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8011 AtkStateType state_type,
8012 gboolean emit_signal)
8016 rc = atk_state_set_add_state (item->state_set, state_type);
8018 * The signal should only be generated if the value changed,
8019 * not when the item is set up. So states that are set
8020 * initially should pass FALSE as the emit_signal argument.
8025 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8026 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8027 if (state_type == ATK_STATE_VISIBLE)
8028 g_signal_emit_by_name (item, "visible-data-changed");
8035 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8036 AtkStateType state_type,
8037 gboolean emit_signal)
8039 if (atk_state_set_contains_state (item->state_set, state_type))
8043 rc = atk_state_set_remove_state (item->state_set, state_type);
8045 * The signal should only be generated if the value changed,
8046 * not when the item is set up. So states that are set
8047 * initially should pass FALSE as the emit_signal argument.
8052 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8053 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8054 if (state_type == ATK_STATE_VISIBLE)
8055 g_signal_emit_by_name (item, "visible-data-changed");
8065 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8067 GtkAllocation allocation;
8068 GtkIconView *icon_view;
8069 GdkRectangle visible_rect;
8070 gboolean is_showing;
8073 * An item is considered "SHOWING" if any part of the item is in the
8074 * visible rectangle.
8077 if (!GTK_IS_ICON_VIEW (item->widget))
8080 if (item->item == NULL)
8083 gtk_widget_get_allocation (item->widget, &allocation);
8085 icon_view = GTK_ICON_VIEW (item->widget);
8087 if (icon_view->priv->hadjustment)
8088 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8090 if (icon_view->priv->hadjustment)
8091 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8092 visible_rect.width = allocation.width;
8093 visible_rect.height = allocation.height;
8095 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8096 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8097 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8098 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8107 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8108 gboolean emit_signal)
8110 if (gtk_icon_view_item_accessible_is_showing (item))
8111 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8114 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8119 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8123 item->state_set = atk_state_set_new ();
8125 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8126 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8127 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8128 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8129 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8131 for (i = 0; i < LAST_ACTION; i++)
8132 item->action_descriptions[i] = NULL;
8134 item->image_description = NULL;
8136 item->action_idle_handler = 0;
8140 gtk_icon_view_item_accessible_finalize (GObject *object)
8142 GtkIconViewItemAccessible *item;
8145 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8147 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8150 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8152 if (item->state_set)
8153 g_object_unref (item->state_set);
8155 if (item->text_buffer)
8156 g_object_unref (item->text_buffer);
8158 for (i = 0; i < LAST_ACTION; i++)
8159 g_free (item->action_descriptions[i]);
8161 g_free (item->image_description);
8163 if (item->action_idle_handler)
8165 g_source_remove (item->action_idle_handler);
8166 item->action_idle_handler = 0;
8169 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8172 static G_CONST_RETURN gchar*
8173 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8179 GtkIconViewItemAccessible *item;
8180 GtkTextIter start_iter;
8181 GtkTextIter end_iter;
8183 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8185 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8186 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8188 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8193 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8195 GtkIconViewItemAccessible *item;
8197 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8198 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8201 return gtk_widget_get_accessible (item->widget);
8207 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8209 GtkIconViewItemAccessible *item;
8211 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8212 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8214 return item->item->index;
8217 static AtkStateSet *
8218 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8220 GtkIconViewItemAccessible *item;
8221 GtkIconView *icon_view;
8223 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8224 g_return_val_if_fail (item->state_set, NULL);
8229 icon_view = GTK_ICON_VIEW (item->widget);
8230 if (icon_view->priv->cursor_item == item->item)
8231 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8233 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8234 if (item->item->selected)
8235 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8237 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8239 return g_object_ref (item->state_set);
8243 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8245 GObjectClass *gobject_class;
8247 accessible_item_parent_class = g_type_class_peek_parent (klass);
8249 gobject_class = (GObjectClass *)klass;
8251 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8253 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8254 klass->get_name = gtk_icon_view_item_accessible_get_name;
8255 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8256 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8260 gtk_icon_view_item_accessible_get_type (void)
8262 static GType type = 0;
8266 const GTypeInfo tinfo =
8268 sizeof (GtkIconViewItemAccessibleClass),
8269 (GBaseInitFunc) NULL, /* base init */
8270 (GBaseFinalizeFunc) NULL, /* base finalize */
8271 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8272 (GClassFinalizeFunc) NULL, /* class finalize */
8273 NULL, /* class data */
8274 sizeof (GtkIconViewItemAccessible), /* instance size */
8275 0, /* nb preallocs */
8276 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8277 NULL /* value table */
8280 const GInterfaceInfo atk_component_info =
8282 (GInterfaceInitFunc) atk_component_item_interface_init,
8283 (GInterfaceFinalizeFunc) NULL,
8286 const GInterfaceInfo atk_action_info =
8288 (GInterfaceInitFunc) atk_action_item_interface_init,
8289 (GInterfaceFinalizeFunc) NULL,
8292 const GInterfaceInfo atk_image_info =
8294 (GInterfaceInitFunc) atk_image_item_interface_init,
8295 (GInterfaceFinalizeFunc) NULL,
8298 const GInterfaceInfo atk_text_info =
8300 (GInterfaceInitFunc) atk_text_item_interface_init,
8301 (GInterfaceFinalizeFunc) NULL,
8305 type = g_type_register_static (ATK_TYPE_OBJECT,
8306 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8307 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8308 &atk_component_info);
8309 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8311 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8313 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8320 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8321 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8322 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8324 static GType gtk_icon_view_accessible_get_type (void);
8329 } GtkIconViewAccessible;
8335 } GtkIconViewItemAccessibleInfo;
8341 GtkAdjustment *old_hadj;
8342 GtkAdjustment *old_vadj;
8344 GtkTreeModel *model;
8346 } GtkIconViewAccessiblePrivate;
8348 static GtkIconViewAccessiblePrivate *
8349 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8351 return g_object_get_qdata (G_OBJECT (accessible),
8352 accessible_private_data_quark);
8356 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8360 GtkIconViewItemAccessibleInfo *info;
8361 GtkIconViewItemAccessibleInfo *tmp_info;
8362 GtkIconViewAccessiblePrivate *priv;
8365 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8367 info->index = index;
8369 priv = gtk_icon_view_accessible_get_priv (accessible);
8370 items = priv->items;
8373 tmp_info = items->data;
8374 if (tmp_info->index > index)
8376 items = items->next;
8378 priv->items = g_list_insert_before (priv->items, items, info);
8379 priv->old_hadj = NULL;
8380 priv->old_vadj = NULL;
8384 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8386 GtkIconView *icon_view;
8389 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8393 icon_view = GTK_ICON_VIEW (widget);
8395 return g_list_length (icon_view->priv->items);
8399 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8402 GtkIconViewAccessiblePrivate *priv;
8403 GtkIconViewItemAccessibleInfo *info;
8406 priv = gtk_icon_view_accessible_get_priv (accessible);
8407 items = priv->items;
8412 if (info->index == index)
8414 items = items->next;
8420 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8423 GtkIconView *icon_view;
8427 GtkIconViewItemAccessible *a11y_item;
8429 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8433 icon_view = GTK_ICON_VIEW (widget);
8434 icons = g_list_nth (icon_view->priv->items, index);
8438 GtkIconViewItem *item = icons->data;
8440 g_return_val_if_fail (item->index == index, NULL);
8441 obj = gtk_icon_view_accessible_find_child (accessible, index);
8446 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8447 gtk_icon_view_item_accessible_info_new (accessible,
8450 obj->role = ATK_ROLE_ICON;
8451 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8452 a11y_item->item = item;
8453 a11y_item->widget = widget;
8454 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8456 text = get_text (icon_view, item);
8459 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8463 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8464 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8472 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8475 GtkIconViewAccessiblePrivate *priv;
8476 GtkIconViewItemAccessibleInfo *info;
8477 GtkIconViewItemAccessible *item;
8480 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8484 gboolean act_on_item;
8486 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8490 items = priv->items;
8492 act_on_item = (list == NULL);
8497 info = (GtkIconViewItemAccessibleInfo *)items->data;
8498 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8500 if (act_on_item == FALSE && list == items)
8504 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8506 items = items->next;
8512 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8513 GtkIconViewAccessible *view)
8515 gtk_icon_view_accessible_traverse_items (view, NULL);
8519 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8520 GtkOrientation orientation,
8521 GtkAdjustment *adjustment)
8523 GtkIconViewAccessiblePrivate *priv;
8524 GtkAdjustment **old_adj_ptr;
8526 priv = gtk_icon_view_accessible_get_priv (accessible);
8528 /* Adjustments are set for the first time in constructor and priv is not
8529 * initialized at that time, so skip this first setting. */
8533 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8535 if (priv->old_hadj == adjustment)
8538 old_adj_ptr = &priv->old_hadj;
8542 if (priv->old_vadj == adjustment)
8545 old_adj_ptr = &priv->old_vadj;
8548 /* Disconnect signal handlers */
8551 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8552 (gpointer *)&priv->old_hadj);
8553 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8554 gtk_icon_view_accessible_adjustment_changed,
8558 /* Connect signal */
8559 *old_adj_ptr = adjustment;
8560 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8561 g_signal_connect (adjustment, "value-changed",
8562 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8567 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8575 GtkIconView *icon_view;
8576 GtkIconViewItem *item;
8577 GtkIconViewItemAccessible *a11y_item;
8581 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8582 index = gtk_tree_path_get_indices(path)[0];
8583 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8584 gtk_icon_view_accessible_find_child (atk_obj, index));
8588 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8589 icon_view = GTK_ICON_VIEW (widget);
8590 item = a11y_item->item;
8592 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
8594 if (!name || strcmp (name, "") == 0)
8596 text = get_text (icon_view, item);
8599 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8605 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8611 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8616 GtkIconViewAccessiblePrivate *priv;
8617 GtkIconViewItemAccessibleInfo *info;
8618 GtkIconViewAccessible *view;
8619 GtkIconViewItemAccessible *item;
8625 index = gtk_tree_path_get_indices(path)[0];
8626 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8627 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8628 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8630 items = priv->items;
8635 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8636 if (info->index != item->item->index)
8638 if (info->index < index)
8639 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8641 if (tmp_list == NULL)
8644 info->index = item->item->index;
8647 items = items->next;
8649 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8650 g_signal_emit_by_name (atk_obj, "children-changed::add",
8656 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8660 GtkIconViewAccessiblePrivate *priv;
8661 GtkIconViewItemAccessibleInfo *info;
8662 GtkIconViewAccessible *view;
8663 GtkIconViewItemAccessible *item;
8666 GList *deleted_item;
8670 index = gtk_tree_path_get_indices(path)[0];
8671 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8672 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8673 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8675 items = priv->items;
8677 deleted_item = NULL;
8682 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8683 if (info->index == index)
8685 deleted_item = items;
8687 if (info->index != item->item->index)
8689 if (tmp_list == NULL)
8692 info->index = item->item->index;
8695 items = items->next;
8697 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8700 info = deleted_item->data;
8701 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8702 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8704 priv->items = g_list_remove_link (priv->items, deleted_item);
8712 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8713 GtkIconViewItemAccessibleInfo *i2)
8715 return i1->index - i2->index;
8719 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8725 GtkIconViewAccessiblePrivate *priv;
8726 GtkIconViewItemAccessibleInfo *info;
8727 GtkIconView *icon_view;
8728 GtkIconViewItemAccessible *item;
8734 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8735 icon_view = GTK_ICON_VIEW (user_data);
8736 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8738 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8740 order = g_new (gint, length);
8741 for (i = 0; i < length; i++)
8742 order [new_order[i]] = i;
8744 items = priv->items;
8748 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8749 info->index = order[info->index];
8750 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8751 items = items->next;
8754 priv->items = g_list_sort (priv->items,
8755 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8761 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8766 obj = G_OBJECT (model);
8767 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8768 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8769 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8770 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8774 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8778 obj = G_OBJECT (icon_view->priv->model);
8779 g_signal_connect_data (obj, "row-changed",
8780 (GCallback) gtk_icon_view_accessible_model_row_changed,
8781 icon_view, NULL, 0);
8782 g_signal_connect_data (obj, "row-inserted",
8783 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8784 icon_view, NULL, G_CONNECT_AFTER);
8785 g_signal_connect_data (obj, "row-deleted",
8786 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8787 icon_view, NULL, G_CONNECT_AFTER);
8788 g_signal_connect_data (obj, "rows-reordered",
8789 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8790 icon_view, NULL, G_CONNECT_AFTER);
8794 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8796 GtkIconViewItemAccessibleInfo *info;
8799 items = priv->items;
8802 info = (GtkIconViewItemAccessibleInfo *) items->data;
8803 g_object_unref (info->item);
8804 g_free (items->data);
8805 items = items->next;
8807 g_list_free (priv->items);
8812 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8815 GtkIconView *icon_view;
8818 GtkIconViewAccessiblePrivate *priv;
8820 if (strcmp (pspec->name, "model") == 0)
8822 widget = GTK_WIDGET (obj);
8823 atk_obj = gtk_widget_get_accessible (widget);
8824 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8827 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8828 (gpointer *)&priv->model);
8829 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8831 gtk_icon_view_accessible_clear_cache (priv);
8833 icon_view = GTK_ICON_VIEW (obj);
8834 priv->model = icon_view->priv->model;
8835 /* If there is no model the GtkIconView is probably being destroyed */
8838 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8839 gtk_icon_view_accessible_connect_model_signals (icon_view);
8847 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8850 GtkIconViewAccessiblePrivate *priv;
8851 GtkIconView *icon_view;
8853 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8854 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8856 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8857 g_object_set_qdata (G_OBJECT (accessible),
8858 accessible_private_data_quark,
8861 icon_view = GTK_ICON_VIEW (data);
8862 if (icon_view->priv->hadjustment)
8863 gtk_icon_view_accessible_set_adjustment (accessible,
8864 GTK_ORIENTATION_HORIZONTAL,
8865 icon_view->priv->hadjustment);
8866 if (icon_view->priv->vadjustment)
8867 gtk_icon_view_accessible_set_adjustment (accessible,
8868 GTK_ORIENTATION_VERTICAL,
8869 icon_view->priv->vadjustment);
8870 g_signal_connect (data,
8872 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8875 priv->model = icon_view->priv->model;
8878 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8879 gtk_icon_view_accessible_connect_model_signals (icon_view);
8882 accessible->role = ATK_ROLE_LAYERED_PANE;
8886 gtk_icon_view_accessible_finalize (GObject *object)
8888 GtkIconViewAccessiblePrivate *priv;
8890 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8891 gtk_icon_view_accessible_clear_cache (priv);
8895 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8899 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8900 GtkAccessible *accessible)
8903 GtkIconViewAccessiblePrivate *priv;
8905 atk_obj = ATK_OBJECT (accessible);
8906 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8909 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8910 (gpointer *)&priv->old_hadj);
8912 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8913 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8915 priv->old_hadj = NULL;
8919 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8920 (gpointer *)&priv->old_vadj);
8922 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8923 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8925 priv->old_vadj = NULL;
8930 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8934 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8937 g_signal_connect_after (widget,
8939 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8942 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8946 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8948 GObjectClass *gobject_class;
8949 GtkAccessibleClass *accessible_class;
8951 accessible_parent_class = g_type_class_peek_parent (klass);
8953 gobject_class = (GObjectClass *)klass;
8954 accessible_class = (GtkAccessibleClass *)klass;
8956 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8958 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8959 klass->ref_child = gtk_icon_view_accessible_ref_child;
8960 klass->initialize = gtk_icon_view_accessible_initialize;
8962 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8964 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8968 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8971 AtkCoordType coord_type)
8974 GtkIconView *icon_view;
8975 GtkIconViewItem *item;
8978 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8980 /* State is defunct */
8983 icon_view = GTK_ICON_VIEW (widget);
8984 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8985 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8987 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8993 atk_component_interface_init (AtkComponentIface *iface)
8995 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8999 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9003 GtkIconView *icon_view;
9004 GtkIconViewItem *item;
9006 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9010 icon_view = GTK_ICON_VIEW (widget);
9012 item = g_list_nth_data (icon_view->priv->items, i);
9017 gtk_icon_view_select_item (icon_view, item);
9023 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9026 GtkIconView *icon_view;
9028 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9032 icon_view = GTK_ICON_VIEW (widget);
9033 gtk_icon_view_unselect_all (icon_view);
9039 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9044 GtkIconView *icon_view;
9045 GtkIconViewItem *item;
9047 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9051 icon_view = GTK_ICON_VIEW (widget);
9053 l = icon_view->priv->items;
9060 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9071 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9074 GtkIconView *icon_view;
9075 GtkIconViewItem *item;
9079 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9083 icon_view = GTK_ICON_VIEW (widget);
9085 l = icon_view->priv->items;
9101 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9105 GtkIconView *icon_view;
9106 GtkIconViewItem *item;
9108 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9112 icon_view = GTK_ICON_VIEW (widget);
9114 item = g_list_nth_data (icon_view->priv->items, i);
9118 return item->selected;
9122 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9126 GtkIconView *icon_view;
9127 GtkIconViewItem *item;
9131 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9135 icon_view = GTK_ICON_VIEW (widget);
9136 l = icon_view->priv->items;
9145 gtk_icon_view_unselect_item (icon_view, item);
9157 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9160 GtkIconView *icon_view;
9162 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9166 icon_view = GTK_ICON_VIEW (widget);
9167 gtk_icon_view_select_all (icon_view);
9172 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9174 iface->add_selection = gtk_icon_view_accessible_add_selection;
9175 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9176 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9177 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9178 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9179 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9180 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9184 gtk_icon_view_accessible_get_type (void)
9186 static GType type = 0;
9193 (GBaseInitFunc) NULL, /* base init */
9194 (GBaseFinalizeFunc) NULL, /* base finalize */
9195 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9196 (GClassFinalizeFunc) NULL, /* class finalize */
9197 NULL, /* class data */
9198 0, /* instance size */
9199 0, /* nb preallocs */
9200 (GInstanceInitFunc) NULL, /* instance init */
9201 NULL /* value table */
9203 const GInterfaceInfo atk_component_info =
9205 (GInterfaceInitFunc) atk_component_interface_init,
9206 (GInterfaceFinalizeFunc) NULL,
9209 const GInterfaceInfo atk_selection_info =
9211 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9212 (GInterfaceFinalizeFunc) NULL,
9217 * Figure out the size of the class and instance
9218 * we are deriving from
9220 AtkObjectFactory *factory;
9223 GType derived_atk_type;
9225 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9226 factory = atk_registry_get_factory (atk_get_default_registry (),
9228 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9229 g_type_query (derived_atk_type, &query);
9230 tinfo.class_size = query.class_size;
9231 tinfo.instance_size = query.instance_size;
9233 type = g_type_register_static (derived_atk_type,
9234 I_("GtkIconViewAccessible"),
9236 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9237 &atk_component_info);
9238 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9239 &atk_selection_info);
9245 gtk_icon_view_accessible_new (GObject *obj)
9247 AtkObject *accessible;
9249 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9251 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9252 atk_object_initialize (accessible, obj);
9258 gtk_icon_view_accessible_factory_get_accessible_type (void)
9260 return gtk_icon_view_accessible_get_type ();
9264 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9266 return gtk_icon_view_accessible_new (obj);
9270 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9272 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9273 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9277 gtk_icon_view_accessible_factory_get_type (void)
9279 static GType type = 0;
9283 const GTypeInfo tinfo =
9285 sizeof (AtkObjectFactoryClass),
9286 NULL, /* base_init */
9287 NULL, /* base_finalize */
9288 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9289 NULL, /* class_finalize */
9290 NULL, /* class_data */
9291 sizeof (AtkObjectFactory),
9292 0, /* n_preallocs */
9296 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9297 I_("GtkIconViewAccessibleFactory"),
9305 gtk_icon_view_get_accessible (GtkWidget *widget)
9307 static gboolean first_time = TRUE;
9311 AtkObjectFactory *factory;
9312 AtkRegistry *registry;
9314 GType derived_atk_type;
9317 * Figure out whether accessibility is enabled by looking at the
9318 * type of the accessible object which would be created for
9319 * the parent type of GtkIconView.
9321 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9323 registry = atk_get_default_registry ();
9324 factory = atk_registry_get_factory (registry,
9326 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9327 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9328 atk_registry_set_factory_type (registry,
9330 gtk_icon_view_accessible_factory_get_type ());
9333 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9337 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9338 GtkBuilder *builder,
9340 const gchar *tagname,
9341 GMarkupParser *parser,
9344 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9345 tagname, parser, data))
9348 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9349 tagname, parser, data);
9353 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9354 GtkBuilder *builder,
9356 const gchar *tagname,
9359 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9360 child, tagname, data))
9361 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,