2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gtkaccessibleprivate.h"
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellareabox.h"
31 #include "gtkcellareacontext.h"
32 #include "gtkcellrenderertext.h"
33 #include "gtkcellrendererpixbuf.h"
34 #include "gtkorientable.h"
35 #include "gtkmarshalers.h"
36 #include "gtkbindings.h"
40 #include "gtkaccessible.h"
41 #include "gtkwindow.h"
43 #include "gtkcombobox.h"
44 #include "gtktextbuffer.h"
45 #include "gtkscrollable.h"
46 #include "gtksizerequest.h"
47 #include "gtktreednd.h"
48 #include "gtktypebuiltins.h"
49 #include "gtkprivate.h"
50 #include "a11y/gtkcontaineraccessible.h"
55 * @short_description: A widget which displays a list of icons in a grid
57 * #GtkIconView provides an alternative view on a #GtkTreeModel.
58 * It displays the model as a grid of icons with labels. Like
59 * #GtkTreeView, it allows to select one or multiple items
60 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
61 * In addition to selection with the arrow keys, #GtkIconView supports
62 * rubberband selection, which is controlled by dragging the pointer.
64 * Note that if the tree model is backed by an actual tree store (as
65 * opposed to a flat list where the mapping to icons is obvious),
66 * #GtkIconView will only display the first level of the tree and
67 * ignore the tree's branches.
70 #define SCROLL_EDGE_SIZE 15
72 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
74 typedef struct _GtkIconViewItem GtkIconViewItem;
75 struct _GtkIconViewItem
77 /* First member is always the rectangle so it
78 * can be cast to a rectangle. */
79 GdkRectangle cell_area;
87 guint selected_before_rubberbanding : 1;
91 typedef struct _GtkIconViewChild GtkIconViewChild;
92 struct _GtkIconViewChild
98 struct _GtkIconViewPrivate
100 GtkCellArea *cell_area;
101 GtkCellAreaContext *cell_area_context;
103 gulong add_editable_id;
104 gulong remove_editable_id;
105 gulong context_changed_id;
107 GPtrArray *row_contexts;
111 GtkSelectionMode selection_mode;
113 guint layout_idle_id;
115 GdkWindow *bin_window;
123 GtkAdjustment *hadjustment;
124 GtkAdjustment *vadjustment;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
128 GdkDevice *rubberband_device;
130 guint scroll_timeout_id;
131 gint scroll_value_diff;
132 gint event_last_x, event_last_y;
134 GtkIconViewItem *anchor_item;
135 GtkIconViewItem *cursor_item;
137 GtkIconViewItem *last_single_clicked;
139 GtkOrientation item_orientation;
154 GtkCellRenderer *pixbuf_cell;
155 GtkCellRenderer *text_cell;
158 GdkModifierType start_button_mask;
163 GdkDragAction source_actions;
164 GdkDragAction dest_actions;
166 GtkTreeRowReference *dest_item;
167 GtkIconViewDropPosition dest_pos;
170 GtkTreeRowReference *scroll_to_path;
171 gfloat scroll_to_row_align;
172 gfloat scroll_to_col_align;
173 guint scroll_to_use_align : 1;
175 guint source_set : 1;
177 guint reorderable : 1;
178 guint empty_view_drop :1;
180 guint ctrl_pressed : 1;
181 guint shift_pressed : 1;
183 guint draw_focus : 1;
185 /* GtkScrollablePolicy needs to be checked when
186 * driving the scrollable adjustment values */
187 guint hscroll_policy : 1;
188 guint vscroll_policy : 1;
190 guint doing_rubberband : 1;
204 ACTIVATE_CURSOR_ITEM,
216 PROP_ITEM_ORIENTATION,
229 /* For scrollable interface */
237 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
238 static void gtk_icon_view_dispose (GObject *object);
239 static GObject *gtk_icon_view_constructor (GType type,
240 guint n_construct_properties,
241 GObjectConstructParam *construct_properties);
242 static void gtk_icon_view_set_property (GObject *object,
246 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkWidget vfuncs */
251 static void gtk_icon_view_destroy (GtkWidget *widget);
252 static void gtk_icon_view_realize (GtkWidget *widget);
253 static void gtk_icon_view_unrealize (GtkWidget *widget);
254 static void gtk_icon_view_style_updated (GtkWidget *widget);
255 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
256 GtkStateFlags previous_state);
257 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
260 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
263 static void gtk_icon_view_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static gboolean gtk_icon_view_draw (GtkWidget *widget,
267 static gboolean gtk_icon_view_motion (GtkWidget *widget,
268 GdkEventMotion *event);
269 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
270 GdkEventButton *event);
271 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
272 GdkEventButton *event);
273 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
275 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
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);
394 static void update_text_cell (GtkIconView *icon_view);
395 static void update_pixbuf_cell (GtkIconView *icon_view);
397 /* Source side drag signals */
398 static void gtk_icon_view_drag_begin (GtkWidget *widget,
399 GdkDragContext *context);
400 static void gtk_icon_view_drag_end (GtkWidget *widget,
401 GdkDragContext *context);
402 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
403 GdkDragContext *context,
404 GtkSelectionData *selection_data,
407 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
408 GdkDragContext *context);
410 /* Target side drag signals */
411 static void gtk_icon_view_drag_leave (GtkWidget *widget,
412 GdkDragContext *context,
414 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
415 GdkDragContext *context,
419 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
420 GdkDragContext *context,
424 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
425 GdkDragContext *context,
428 GtkSelectionData *selection_data,
431 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
432 GdkEventMotion *event);
434 static void remove_scroll_timeout (GtkIconView *icon_view);
437 static GtkBuildableIface *parent_buildable_iface;
438 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
439 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
442 const gchar *tagname,
443 GMarkupParser *parser,
445 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
448 const gchar *tagname,
450 static GType gtk_icon_view_accessible_get_type (void);
452 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
454 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
455 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
456 gtk_icon_view_cell_layout_init)
457 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
458 gtk_icon_view_buildable_init)
459 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
462 gtk_icon_view_class_init (GtkIconViewClass *klass)
464 GObjectClass *gobject_class;
465 GtkWidgetClass *widget_class;
466 GtkContainerClass *container_class;
467 GtkBindingSet *binding_set;
469 binding_set = gtk_binding_set_by_class (klass);
471 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
473 gobject_class = (GObjectClass *) klass;
474 widget_class = (GtkWidgetClass *) klass;
475 container_class = (GtkContainerClass *) klass;
477 gobject_class->constructor = gtk_icon_view_constructor;
478 gobject_class->dispose = gtk_icon_view_dispose;
479 gobject_class->set_property = gtk_icon_view_set_property;
480 gobject_class->get_property = gtk_icon_view_get_property;
482 widget_class->destroy = gtk_icon_view_destroy;
483 widget_class->realize = gtk_icon_view_realize;
484 widget_class->unrealize = gtk_icon_view_unrealize;
485 widget_class->style_updated = gtk_icon_view_style_updated;
486 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
487 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
488 widget_class->size_allocate = gtk_icon_view_size_allocate;
489 widget_class->draw = gtk_icon_view_draw;
490 widget_class->motion_notify_event = gtk_icon_view_motion;
491 widget_class->button_press_event = gtk_icon_view_button_press;
492 widget_class->button_release_event = gtk_icon_view_button_release;
493 widget_class->key_press_event = gtk_icon_view_key_press;
494 widget_class->key_release_event = gtk_icon_view_key_release;
495 widget_class->drag_begin = gtk_icon_view_drag_begin;
496 widget_class->drag_end = gtk_icon_view_drag_end;
497 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
498 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
499 widget_class->drag_leave = gtk_icon_view_drag_leave;
500 widget_class->drag_motion = gtk_icon_view_drag_motion;
501 widget_class->drag_drop = gtk_icon_view_drag_drop;
502 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
503 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
505 container_class->remove = gtk_icon_view_remove;
506 container_class->forall = gtk_icon_view_forall;
508 klass->select_all = gtk_icon_view_real_select_all;
509 klass->unselect_all = gtk_icon_view_real_unselect_all;
510 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
511 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
512 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
513 klass->move_cursor = gtk_icon_view_real_move_cursor;
517 * GtkIconView:selection-mode:
519 * The ::selection-mode property specifies the selection mode of
520 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
521 * is enabled, for the other modes, only keyboard selection is possible.
525 g_object_class_install_property (gobject_class,
527 g_param_spec_enum ("selection-mode",
528 P_("Selection mode"),
529 P_("The selection mode"),
530 GTK_TYPE_SELECTION_MODE,
531 GTK_SELECTION_SINGLE,
532 GTK_PARAM_READWRITE));
535 * GtkIconView:pixbuf-column:
537 * The ::pixbuf-column property contains the number of the model column
538 * containing the pixbufs which are displayed. The pixbuf column must be
539 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
540 * display of pixbufs.
544 g_object_class_install_property (gobject_class,
546 g_param_spec_int ("pixbuf-column",
548 P_("Model column used to retrieve the icon pixbuf from"),
550 GTK_PARAM_READWRITE));
553 * GtkIconView:text-column:
555 * The ::text-column property contains the number of the model column
556 * containing the texts which are displayed. The text column must be
557 * of type #G_TYPE_STRING. If this property and the :markup-column
558 * property are both set to -1, no texts are displayed.
562 g_object_class_install_property (gobject_class,
564 g_param_spec_int ("text-column",
566 P_("Model column used to retrieve the text from"),
568 GTK_PARAM_READWRITE));
572 * GtkIconView:markup-column:
574 * The ::markup-column property contains the number of the model column
575 * containing markup information to be displayed. The markup column must be
576 * of type #G_TYPE_STRING. If this property and the :text-column property
577 * are both set to column numbers, it overrides the text column.
578 * If both are set to -1, no texts are displayed.
582 g_object_class_install_property (gobject_class,
584 g_param_spec_int ("markup-column",
586 P_("Model column used to retrieve the text if using Pango markup"),
588 GTK_PARAM_READWRITE));
590 g_object_class_install_property (gobject_class,
592 g_param_spec_object ("model",
593 P_("Icon View Model"),
594 P_("The model for the icon view"),
596 GTK_PARAM_READWRITE));
599 * GtkIconView:columns:
601 * The columns property contains the number of the columns in which the
602 * items should be displayed. If it is -1, the number of columns will
603 * be chosen automatically to fill the available area.
607 g_object_class_install_property (gobject_class,
609 g_param_spec_int ("columns",
610 P_("Number of columns"),
611 P_("Number of columns to display"),
613 GTK_PARAM_READWRITE));
617 * GtkIconView:item-width:
619 * The item-width property specifies the width to use for each item.
620 * If it is set to -1, the icon view will automatically determine a
621 * suitable item size.
625 g_object_class_install_property (gobject_class,
627 g_param_spec_int ("item-width",
628 P_("Width for each item"),
629 P_("The width used for each item"),
631 GTK_PARAM_READWRITE));
634 * GtkIconView:spacing:
636 * The spacing property specifies the space which is inserted between
637 * the cells (i.e. the icon and the text) of an item.
641 g_object_class_install_property (gobject_class,
643 g_param_spec_int ("spacing",
645 P_("Space which is inserted between cells of an item"),
647 GTK_PARAM_READWRITE));
650 * GtkIconView:row-spacing:
652 * The row-spacing property specifies the space which is inserted between
653 * the rows of the icon view.
657 g_object_class_install_property (gobject_class,
659 g_param_spec_int ("row-spacing",
661 P_("Space which is inserted between grid rows"),
663 GTK_PARAM_READWRITE));
666 * GtkIconView:column-spacing:
668 * The column-spacing property specifies the space which is inserted between
669 * the columns of the icon view.
673 g_object_class_install_property (gobject_class,
675 g_param_spec_int ("column-spacing",
676 P_("Column Spacing"),
677 P_("Space which is inserted between grid columns"),
679 GTK_PARAM_READWRITE));
682 * GtkIconView:margin:
684 * The margin property specifies the space which is inserted
685 * at the edges of the icon view.
689 g_object_class_install_property (gobject_class,
691 g_param_spec_int ("margin",
693 P_("Space which is inserted at the edges of the icon view"),
695 GTK_PARAM_READWRITE));
698 * GtkIconView:item-orientation:
700 * The item-orientation property specifies how the cells (i.e. the icon and
701 * the text) of the item are positioned relative to each other.
705 g_object_class_install_property (gobject_class,
706 PROP_ITEM_ORIENTATION,
707 g_param_spec_enum ("item-orientation",
708 P_("Item Orientation"),
709 P_("How the text and icon of each item are positioned relative to each other"),
710 GTK_TYPE_ORIENTATION,
711 GTK_ORIENTATION_VERTICAL,
712 GTK_PARAM_READWRITE));
715 * GtkIconView:reorderable:
717 * The reorderable property specifies if the items can be reordered
722 g_object_class_install_property (gobject_class,
724 g_param_spec_boolean ("reorderable",
726 P_("View is reorderable"),
730 g_object_class_install_property (gobject_class,
732 g_param_spec_int ("tooltip-column",
733 P_("Tooltip Column"),
734 P_("The column in the model containing the tooltip texts for the items"),
738 GTK_PARAM_READWRITE));
741 * GtkIconView:item-padding:
743 * The item-padding property specifies the padding around each
744 * of the icon view's item.
748 g_object_class_install_property (gobject_class,
750 g_param_spec_int ("item-padding",
752 P_("Padding around icon view items"),
754 GTK_PARAM_READWRITE));
757 * GtkIconView:cell-area:
759 * The #GtkCellArea used to layout cell renderers for this view.
761 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
762 * a #GtkCellAreaBox will be used.
766 g_object_class_install_property (gobject_class,
768 g_param_spec_object ("cell-area",
770 P_("The GtkCellArea used to layout cells"),
772 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
774 /* Scrollable interface properties */
775 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
776 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
777 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
778 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
780 /* Style properties */
781 gtk_widget_class_install_style_property (widget_class,
782 g_param_spec_boxed ("selection-box-color",
783 P_("Selection Box Color"),
784 P_("Color of the selection box"),
786 GTK_PARAM_READABLE));
788 gtk_widget_class_install_style_property (widget_class,
789 g_param_spec_uchar ("selection-box-alpha",
790 P_("Selection Box Alpha"),
791 P_("Opacity of the selection box"),
794 GTK_PARAM_READABLE));
798 * GtkIconView::item-activated:
799 * @iconview: the object on which the signal is emitted
800 * @path: the #GtkTreePath for the activated item
802 * The ::item-activated signal is emitted when the method
803 * gtk_icon_view_item_activated() is called or the user double
804 * clicks an item. It is also emitted when a non-editable item
805 * is selected and one of the keys: Space, Return or Enter is
808 icon_view_signals[ITEM_ACTIVATED] =
809 g_signal_new (I_("item-activated"),
810 G_TYPE_FROM_CLASS (gobject_class),
812 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
814 g_cclosure_marshal_VOID__BOXED,
819 * GtkIconView::selection-changed:
820 * @iconview: the object on which the signal is emitted
822 * The ::selection-changed signal is emitted when the selection
823 * (i.e. the set of selected items) changes.
825 icon_view_signals[SELECTION_CHANGED] =
826 g_signal_new (I_("selection-changed"),
827 G_TYPE_FROM_CLASS (gobject_class),
829 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
831 g_cclosure_marshal_VOID__VOID,
835 * GtkIconView::select-all:
836 * @iconview: the object on which the signal is emitted
838 * A <link linkend="keybinding-signals">keybinding signal</link>
839 * which gets emitted when the user selects all items.
841 * Applications should not connect to it, but may emit it with
842 * g_signal_emit_by_name() if they need to control selection
845 * The default binding for this signal is Ctrl-a.
847 icon_view_signals[SELECT_ALL] =
848 g_signal_new (I_("select-all"),
849 G_TYPE_FROM_CLASS (gobject_class),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
853 g_cclosure_marshal_VOID__VOID,
857 * GtkIconView::unselect-all:
858 * @iconview: the object on which the signal is emitted
860 * A <link linkend="keybinding-signals">keybinding signal</link>
861 * which gets emitted when the user unselects all items.
863 * Applications should not connect to it, but may emit it with
864 * g_signal_emit_by_name() if they need to control selection
867 * The default binding for this signal is Ctrl-Shift-a.
869 icon_view_signals[UNSELECT_ALL] =
870 g_signal_new (I_("unselect-all"),
871 G_TYPE_FROM_CLASS (gobject_class),
872 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
873 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
875 g_cclosure_marshal_VOID__VOID,
879 * GtkIconView::select-cursor-item:
880 * @iconview: the object on which the signal is emitted
882 * A <link linkend="keybinding-signals">keybinding signal</link>
883 * which gets emitted when the user selects the item that is currently
886 * Applications should not connect to it, but may emit it with
887 * g_signal_emit_by_name() if they need to control selection
890 * There is no default binding for this signal.
892 icon_view_signals[SELECT_CURSOR_ITEM] =
893 g_signal_new (I_("select-cursor-item"),
894 G_TYPE_FROM_CLASS (gobject_class),
895 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
896 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
898 g_cclosure_marshal_VOID__VOID,
902 * GtkIconView::toggle-cursor-item:
903 * @iconview: the object on which the signal is emitted
905 * A <link linkend="keybinding-signals">keybinding signal</link>
906 * which gets emitted when the user toggles whether the currently
907 * focused item is selected or not. The exact effect of this
908 * depend on the selection mode.
910 * Applications should not connect to it, but may emit it with
911 * g_signal_emit_by_name() if they need to control selection
914 * There is no default binding for this signal is Ctrl-Space.
916 icon_view_signals[TOGGLE_CURSOR_ITEM] =
917 g_signal_new (I_("toggle-cursor-item"),
918 G_TYPE_FROM_CLASS (gobject_class),
919 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
920 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
922 g_cclosure_marshal_VOID__VOID,
926 * GtkIconView::activate-cursor-item:
927 * @iconview: the object on which the signal is emitted
929 * A <link linkend="keybinding-signals">keybinding signal</link>
930 * which gets emitted when the user activates the currently
933 * Applications should not connect to it, but may emit it with
934 * g_signal_emit_by_name() if they need to control activation
937 * The default bindings for this signal are Space, Return and Enter.
939 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
940 g_signal_new (I_("activate-cursor-item"),
941 G_TYPE_FROM_CLASS (gobject_class),
942 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
943 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
945 _gtk_marshal_BOOLEAN__VOID,
949 * GtkIconView::move-cursor:
950 * @iconview: the object which received the signal
951 * @step: the granularity of the move, as a #GtkMovementStep
952 * @count: the number of @step units to move
954 * The ::move-cursor signal is a
955 * <link linkend="keybinding-signals">keybinding signal</link>
956 * which gets emitted when the user initiates a cursor movement.
958 * Applications should not connect to it, but may emit it with
959 * g_signal_emit_by_name() if they need to control the cursor
962 * The default bindings for this signal include
964 * <listitem>Arrow keys which move by individual steps</listitem>
965 * <listitem>Home/End keys which move to the first/last item</listitem>
966 * <listitem>PageUp/PageDown which move by "pages"</listitem>
969 * All of these will extend the selection when combined with
970 * the Shift modifier.
972 icon_view_signals[MOVE_CURSOR] =
973 g_signal_new (I_("move-cursor"),
974 G_TYPE_FROM_CLASS (gobject_class),
975 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
976 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
978 _gtk_marshal_BOOLEAN__ENUM_INT,
980 GTK_TYPE_MOVEMENT_STEP,
984 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
986 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
988 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
989 "toggle-cursor-item", 0);
990 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
991 "toggle-cursor-item", 0);
993 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
994 "activate-cursor-item", 0);
995 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
996 "activate-cursor-item", 0);
997 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
998 "activate-cursor-item", 0);
999 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1000 "activate-cursor-item", 0);
1001 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1002 "activate-cursor-item", 0);
1004 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1005 GTK_MOVEMENT_DISPLAY_LINES, -1);
1006 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1007 GTK_MOVEMENT_DISPLAY_LINES, -1);
1009 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1010 GTK_MOVEMENT_DISPLAY_LINES, 1);
1011 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1012 GTK_MOVEMENT_DISPLAY_LINES, 1);
1014 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1015 GTK_MOVEMENT_DISPLAY_LINES, -1);
1017 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1018 GTK_MOVEMENT_DISPLAY_LINES, 1);
1020 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1021 GTK_MOVEMENT_BUFFER_ENDS, -1);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1023 GTK_MOVEMENT_BUFFER_ENDS, -1);
1025 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1026 GTK_MOVEMENT_BUFFER_ENDS, 1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1028 GTK_MOVEMENT_BUFFER_ENDS, 1);
1030 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1031 GTK_MOVEMENT_PAGES, -1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1033 GTK_MOVEMENT_PAGES, -1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1036 GTK_MOVEMENT_PAGES, 1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1038 GTK_MOVEMENT_PAGES, 1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1041 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1043 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1046 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1048 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1050 gtk_widget_class_set_accessible_type (widget_class, gtk_icon_view_accessible_get_type ());
1054 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1056 parent_buildable_iface = g_type_interface_peek_parent (iface);
1057 iface->add_child = _gtk_cell_layout_buildable_add_child;
1058 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1059 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1063 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1065 iface->get_area = gtk_icon_view_cell_layout_get_area;
1069 gtk_icon_view_init (GtkIconView *icon_view)
1071 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1073 GtkIconViewPrivate);
1075 icon_view->priv->width = 0;
1076 icon_view->priv->height = 0;
1077 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1078 icon_view->priv->pressed_button = -1;
1079 icon_view->priv->press_start_x = -1;
1080 icon_view->priv->press_start_y = -1;
1081 icon_view->priv->text_column = -1;
1082 icon_view->priv->markup_column = -1;
1083 icon_view->priv->pixbuf_column = -1;
1084 icon_view->priv->text_cell = NULL;
1085 icon_view->priv->pixbuf_cell = NULL;
1086 icon_view->priv->tooltip_column = -1;
1088 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1090 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1092 icon_view->priv->columns = -1;
1093 icon_view->priv->item_width = -1;
1094 icon_view->priv->spacing = 0;
1095 icon_view->priv->row_spacing = 6;
1096 icon_view->priv->column_spacing = 6;
1097 icon_view->priv->margin = 6;
1098 icon_view->priv->item_padding = 6;
1100 icon_view->priv->draw_focus = TRUE;
1102 icon_view->priv->row_contexts =
1103 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1106 /* GObject methods */
1108 gtk_icon_view_constructor (GType type,
1109 guint n_construct_properties,
1110 GObjectConstructParam *construct_properties)
1112 GtkIconView *icon_view;
1115 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1116 (type, n_construct_properties, construct_properties);
1118 icon_view = (GtkIconView *) object;
1120 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1126 gtk_icon_view_dispose (GObject *object)
1128 GtkIconView *icon_view;
1129 GtkIconViewPrivate *priv;
1131 icon_view = GTK_ICON_VIEW (object);
1132 priv = icon_view->priv;
1134 if (priv->cell_area_context)
1136 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1137 priv->context_changed_id = 0;
1139 g_object_unref (priv->cell_area_context);
1140 priv->cell_area_context = NULL;
1143 if (priv->row_contexts)
1145 g_ptr_array_free (priv->row_contexts, TRUE);
1146 priv->row_contexts = NULL;
1149 if (priv->cell_area)
1151 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1153 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1154 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1155 priv->add_editable_id = 0;
1156 priv->remove_editable_id = 0;
1158 g_object_unref (priv->cell_area);
1159 priv->cell_area = NULL;
1162 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1166 gtk_icon_view_set_property (GObject *object,
1168 const GValue *value,
1171 GtkIconView *icon_view;
1174 icon_view = GTK_ICON_VIEW (object);
1178 case PROP_SELECTION_MODE:
1179 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1181 case PROP_PIXBUF_COLUMN:
1182 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1184 case PROP_TEXT_COLUMN:
1185 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1187 case PROP_MARKUP_COLUMN:
1188 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1191 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1193 case PROP_ITEM_ORIENTATION:
1194 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1197 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1199 case PROP_ITEM_WIDTH:
1200 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1203 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1205 case PROP_ROW_SPACING:
1206 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1208 case PROP_COLUMN_SPACING:
1209 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1212 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1214 case PROP_REORDERABLE:
1215 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1218 case PROP_TOOLTIP_COLUMN:
1219 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1222 case PROP_ITEM_PADDING:
1223 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1226 case PROP_CELL_AREA:
1227 /* Construct-only, can only be assigned once */
1228 area = g_value_get_object (value);
1231 if (icon_view->priv->cell_area != NULL)
1233 g_warning ("cell-area has already been set, ignoring construct property");
1234 g_object_ref_sink (area);
1235 g_object_unref (area);
1238 gtk_icon_view_ensure_cell_area (icon_view, area);
1242 case PROP_HADJUSTMENT:
1243 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1245 case PROP_VADJUSTMENT:
1246 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1248 case PROP_HSCROLL_POLICY:
1249 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1250 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1252 case PROP_VSCROLL_POLICY:
1253 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1254 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1264 gtk_icon_view_get_property (GObject *object,
1269 GtkIconView *icon_view;
1271 icon_view = GTK_ICON_VIEW (object);
1275 case PROP_SELECTION_MODE:
1276 g_value_set_enum (value, icon_view->priv->selection_mode);
1278 case PROP_PIXBUF_COLUMN:
1279 g_value_set_int (value, icon_view->priv->pixbuf_column);
1281 case PROP_TEXT_COLUMN:
1282 g_value_set_int (value, icon_view->priv->text_column);
1284 case PROP_MARKUP_COLUMN:
1285 g_value_set_int (value, icon_view->priv->markup_column);
1288 g_value_set_object (value, icon_view->priv->model);
1290 case PROP_ITEM_ORIENTATION:
1291 g_value_set_enum (value, icon_view->priv->item_orientation);
1294 g_value_set_int (value, icon_view->priv->columns);
1296 case PROP_ITEM_WIDTH:
1297 g_value_set_int (value, icon_view->priv->item_width);
1300 g_value_set_int (value, icon_view->priv->spacing);
1302 case PROP_ROW_SPACING:
1303 g_value_set_int (value, icon_view->priv->row_spacing);
1305 case PROP_COLUMN_SPACING:
1306 g_value_set_int (value, icon_view->priv->column_spacing);
1309 g_value_set_int (value, icon_view->priv->margin);
1311 case PROP_REORDERABLE:
1312 g_value_set_boolean (value, icon_view->priv->reorderable);
1314 case PROP_TOOLTIP_COLUMN:
1315 g_value_set_int (value, icon_view->priv->tooltip_column);
1318 case PROP_ITEM_PADDING:
1319 g_value_set_int (value, icon_view->priv->item_padding);
1322 case PROP_CELL_AREA:
1323 g_value_set_object (value, icon_view->priv->cell_area);
1326 case PROP_HADJUSTMENT:
1327 g_value_set_object (value, icon_view->priv->hadjustment);
1329 case PROP_VADJUSTMENT:
1330 g_value_set_object (value, icon_view->priv->vadjustment);
1332 case PROP_HSCROLL_POLICY:
1333 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1335 case PROP_VSCROLL_POLICY:
1336 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1340 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1345 /* GtkWidget methods */
1347 gtk_icon_view_destroy (GtkWidget *widget)
1349 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1351 gtk_icon_view_set_model (icon_view, NULL);
1353 if (icon_view->priv->layout_idle_id != 0)
1355 g_source_remove (icon_view->priv->layout_idle_id);
1356 icon_view->priv->layout_idle_id = 0;
1359 if (icon_view->priv->scroll_to_path != NULL)
1361 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1362 icon_view->priv->scroll_to_path = NULL;
1365 remove_scroll_timeout (icon_view);
1367 if (icon_view->priv->hadjustment != NULL)
1369 g_object_unref (icon_view->priv->hadjustment);
1370 icon_view->priv->hadjustment = NULL;
1373 if (icon_view->priv->vadjustment != NULL)
1375 g_object_unref (icon_view->priv->vadjustment);
1376 icon_view->priv->vadjustment = NULL;
1379 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1383 gtk_icon_view_realize (GtkWidget *widget)
1385 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1386 GtkAllocation allocation;
1388 GdkWindowAttr attributes;
1389 gint attributes_mask;
1390 GtkStyleContext *context;
1392 gtk_widget_set_realized (widget, TRUE);
1394 gtk_widget_get_allocation (widget, &allocation);
1396 /* Make the main, clipping window */
1397 attributes.window_type = GDK_WINDOW_CHILD;
1398 attributes.x = allocation.x;
1399 attributes.y = allocation.y;
1400 attributes.width = allocation.width;
1401 attributes.height = allocation.height;
1402 attributes.wclass = GDK_INPUT_OUTPUT;
1403 attributes.visual = gtk_widget_get_visual (widget);
1404 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1406 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1408 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1409 &attributes, attributes_mask);
1410 gtk_widget_set_window (widget, window);
1411 gdk_window_set_user_data (window, widget);
1413 gtk_widget_get_allocation (widget, &allocation);
1415 /* Make the window for the icon view */
1418 attributes.width = MAX (icon_view->priv->width, allocation.width);
1419 attributes.height = MAX (icon_view->priv->height, allocation.height);
1420 attributes.event_mask = (GDK_EXPOSURE_MASK |
1422 GDK_POINTER_MOTION_MASK |
1423 GDK_BUTTON_PRESS_MASK |
1424 GDK_BUTTON_RELEASE_MASK |
1425 GDK_KEY_PRESS_MASK |
1426 GDK_KEY_RELEASE_MASK) |
1427 gtk_widget_get_events (widget);
1429 icon_view->priv->bin_window = gdk_window_new (window,
1430 &attributes, attributes_mask);
1431 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1433 context = gtk_widget_get_style_context (widget);
1435 gtk_style_context_save (context);
1436 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1437 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1438 gtk_style_context_restore (context);
1440 gdk_window_show (icon_view->priv->bin_window);
1444 gtk_icon_view_unrealize (GtkWidget *widget)
1446 GtkIconView *icon_view;
1448 icon_view = GTK_ICON_VIEW (widget);
1450 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1451 gdk_window_destroy (icon_view->priv->bin_window);
1452 icon_view->priv->bin_window = NULL;
1454 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1458 _gtk_icon_view_update_background (GtkIconView *icon_view)
1460 GtkWidget *widget = GTK_WIDGET (icon_view);
1462 if (gtk_widget_get_realized (widget))
1464 GtkStyleContext *context;
1466 context = gtk_widget_get_style_context (widget);
1468 gtk_style_context_save (context);
1469 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1471 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1472 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1474 gtk_style_context_restore (context);
1479 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1480 GtkStateFlags previous_state)
1482 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1483 gtk_widget_queue_draw (widget);
1487 gtk_icon_view_style_updated (GtkWidget *widget)
1489 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1491 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1492 gtk_widget_queue_resize (widget);
1496 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1500 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1504 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1508 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1512 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1516 for (list = icon_view->priv->children; list; list = list->next)
1518 GtkIconViewChild *child = list->data;
1520 /* totally ignore our child's requisition */
1521 gtk_widget_size_allocate (child->widget, &child->area);
1526 gtk_icon_view_size_allocate (GtkWidget *widget,
1527 GtkAllocation *allocation)
1529 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1531 gtk_widget_set_allocation (widget, allocation);
1533 if (gtk_widget_get_realized (widget))
1535 gdk_window_move_resize (gtk_widget_get_window (widget),
1536 allocation->x, allocation->y,
1537 allocation->width, allocation->height);
1538 gdk_window_resize (icon_view->priv->bin_window,
1539 MAX (icon_view->priv->width, allocation->width),
1540 MAX (icon_view->priv->height, allocation->height));
1543 gtk_icon_view_layout (icon_view);
1545 gtk_icon_view_allocate_children (icon_view);
1547 /* Delay signal emission */
1548 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1549 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1551 gtk_icon_view_set_hadjustment_values (icon_view);
1552 gtk_icon_view_set_vadjustment_values (icon_view);
1554 if (gtk_widget_get_realized (widget) &&
1555 icon_view->priv->scroll_to_path)
1558 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1559 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1560 icon_view->priv->scroll_to_path = NULL;
1562 gtk_icon_view_scroll_to_path (icon_view, path,
1563 icon_view->priv->scroll_to_use_align,
1564 icon_view->priv->scroll_to_row_align,
1565 icon_view->priv->scroll_to_col_align);
1566 gtk_tree_path_free (path);
1569 /* Emit any pending signals now */
1570 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1571 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1575 gtk_icon_view_draw (GtkWidget *widget,
1578 GtkIconView *icon_view;
1582 GtkIconViewDropPosition dest_pos;
1583 GtkIconViewItem *dest_item = NULL;
1585 icon_view = GTK_ICON_VIEW (widget);
1587 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1592 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1594 cairo_set_line_width (cr, 1.);
1596 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1600 dest_index = gtk_tree_path_get_indices (path)[0];
1601 gtk_tree_path_free (path);
1606 for (icons = icon_view->priv->items; icons; icons = icons->next)
1608 GtkIconViewItem *item = icons->data;
1609 GdkRectangle paint_area;
1611 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1612 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1613 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1614 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1618 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1621 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1623 gtk_icon_view_paint_item (icon_view, cr, item,
1624 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1625 icon_view->priv->draw_focus);
1627 if (dest_index == item->index)
1635 dest_pos != GTK_ICON_VIEW_NO_DROP)
1637 GtkStyleContext *context;
1638 GtkStateFlags state;
1639 GdkRectangle rect = { 0 };
1641 context = gtk_widget_get_style_context (widget);
1642 state = gtk_widget_get_state_flags (widget);
1646 case GTK_ICON_VIEW_DROP_INTO:
1647 rect = dest_item->cell_area;
1649 case GTK_ICON_VIEW_DROP_ABOVE:
1650 rect.x = dest_item->cell_area.x;
1651 rect.y = dest_item->cell_area.y - 1;
1652 rect.width = dest_item->cell_area.width;
1655 case GTK_ICON_VIEW_DROP_LEFT:
1656 rect.x = dest_item->cell_area.x - 1;
1657 rect.y = dest_item->cell_area.y;
1659 rect.height = dest_item->cell_area.height;
1661 case GTK_ICON_VIEW_DROP_BELOW:
1662 rect.x = dest_item->cell_area.x;
1663 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1664 rect.width = dest_item->cell_area.width;
1667 case GTK_ICON_VIEW_DROP_RIGHT:
1668 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1669 rect.y = dest_item->cell_area.y;
1671 rect.height = dest_item->cell_area.height;
1672 case GTK_ICON_VIEW_NO_DROP: ;
1676 gtk_style_context_set_state (context, state);
1677 gtk_render_focus (context, cr,
1679 rect.width, rect.height);
1682 if (icon_view->priv->doing_rubberband)
1683 gtk_icon_view_paint_rubberband (icon_view, cr);
1687 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1693 rubberband_scroll_timeout (gpointer data)
1695 GtkIconView *icon_view = data;
1697 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1698 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1699 icon_view->priv->scroll_value_diff);
1701 gtk_icon_view_update_rubberband (icon_view);
1707 gtk_icon_view_motion (GtkWidget *widget,
1708 GdkEventMotion *event)
1710 GtkAllocation allocation;
1711 GtkIconView *icon_view;
1714 icon_view = GTK_ICON_VIEW (widget);
1716 gtk_icon_view_maybe_begin_drag (icon_view, event);
1718 if (icon_view->priv->doing_rubberband)
1720 gtk_icon_view_update_rubberband (widget);
1722 abs_y = event->y - icon_view->priv->height *
1723 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1724 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1725 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1727 gtk_widget_get_allocation (widget, &allocation);
1729 if (abs_y < 0 || abs_y > allocation.height)
1732 icon_view->priv->scroll_value_diff = abs_y;
1734 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1736 icon_view->priv->event_last_x = event->x;
1737 icon_view->priv->event_last_y = event->y;
1739 if (icon_view->priv->scroll_timeout_id == 0)
1740 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1744 remove_scroll_timeout (icon_view);
1751 gtk_icon_view_remove (GtkContainer *container,
1754 GtkIconView *icon_view;
1755 GtkIconViewChild *child = NULL;
1758 icon_view = GTK_ICON_VIEW (container);
1760 tmp_list = icon_view->priv->children;
1763 child = tmp_list->data;
1764 if (child->widget == widget)
1766 gtk_widget_unparent (widget);
1768 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1769 g_list_free_1 (tmp_list);
1774 tmp_list = tmp_list->next;
1779 gtk_icon_view_forall (GtkContainer *container,
1780 gboolean include_internals,
1781 GtkCallback callback,
1782 gpointer callback_data)
1784 GtkIconView *icon_view;
1785 GtkIconViewChild *child = NULL;
1788 icon_view = GTK_ICON_VIEW (container);
1790 tmp_list = icon_view->priv->children;
1793 child = tmp_list->data;
1794 tmp_list = tmp_list->next;
1796 (* callback) (child->widget, callback_data);
1801 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1802 GtkIconViewItem *item)
1805 AtkObject *item_obj;
1807 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1810 item_obj = atk_object_ref_accessible_child (obj, item->index);
1811 if (item_obj != NULL)
1813 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1814 g_object_unref (item_obj);
1820 gtk_icon_view_add_editable (GtkCellArea *area,
1821 GtkCellRenderer *renderer,
1822 GtkCellEditable *editable,
1823 GdkRectangle *cell_area,
1825 GtkIconView *icon_view)
1827 GtkIconViewChild *child;
1828 GtkWidget *widget = GTK_WIDGET (editable);
1830 child = g_new (GtkIconViewChild, 1);
1832 child->widget = widget;
1833 child->area.x = cell_area->x;
1834 child->area.y = cell_area->y;
1835 child->area.width = cell_area->width;
1836 child->area.height = cell_area->height;
1838 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1840 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1841 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1843 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1847 gtk_icon_view_remove_editable (GtkCellArea *area,
1848 GtkCellRenderer *renderer,
1849 GtkCellEditable *editable,
1850 GtkIconView *icon_view)
1854 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1855 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1857 gtk_container_remove (GTK_CONTAINER (icon_view),
1858 GTK_WIDGET (editable));
1860 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1861 gtk_icon_view_queue_draw_path (icon_view, path);
1862 gtk_tree_path_free (path);
1866 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1868 GtkIconView *icon_view)
1870 if (!strcmp (pspec->name, "minimum-width") ||
1871 !strcmp (pspec->name, "natural-width") ||
1872 !strcmp (pspec->name, "minimum-height") ||
1873 !strcmp (pspec->name, "natural-height"))
1874 gtk_icon_view_invalidate_sizes (icon_view);
1878 * gtk_icon_view_set_cursor:
1879 * @icon_view: A #GtkIconView
1880 * @path: A #GtkTreePath
1881 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1882 * @start_editing: %TRUE if the specified cell should start being edited.
1884 * Sets the current keyboard focus to be at @path, and selects it. This is
1885 * useful when you want to focus the user's attention on a particular item.
1886 * If @cell is not %NULL, then focus is given to the cell specified by
1887 * it. Additionally, if @start_editing is %TRUE, then editing should be
1888 * started in the specified cell.
1890 * This function is often followed by <literal>gtk_widget_grab_focus
1891 * (icon_view)</literal> in order to give keyboard focus to the widget.
1892 * Please note that editing can only happen when the widget is realized.
1897 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1899 GtkCellRenderer *cell,
1900 gboolean start_editing)
1902 GtkIconViewItem *item = NULL;
1904 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1905 g_return_if_fail (path != NULL);
1906 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1908 if (icon_view->priv->cell_area)
1909 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1911 if (gtk_tree_path_get_depth (path) == 1)
1912 item = g_list_nth_data (icon_view->priv->items,
1913 gtk_tree_path_get_indices(path)[0]);
1918 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1919 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1921 if (start_editing &&
1922 icon_view->priv->cell_area)
1924 GtkCellAreaContext *context;
1926 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1927 gtk_icon_view_set_cell_data (icon_view, item);
1928 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1929 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1930 0 /* XXX flags */, TRUE);
1935 * gtk_icon_view_get_cursor:
1936 * @icon_view: A #GtkIconView
1937 * @path: (out) (allow-none): Return location for the current cursor path,
1939 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1941 * Fills in @path and @cell with the current cursor path and cell.
1942 * If the cursor isn't currently set, then *@path will be %NULL.
1943 * If no cell currently has focus, then *@cell will be %NULL.
1945 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1947 * Return value: %TRUE if the cursor is set.
1952 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1954 GtkCellRenderer **cell)
1956 GtkIconViewItem *item;
1958 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1960 item = icon_view->priv->cursor_item;
1965 *path = gtk_tree_path_new_from_indices (item->index, -1);
1970 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1971 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1973 return (item != NULL);
1977 gtk_icon_view_button_press (GtkWidget *widget,
1978 GdkEventButton *event)
1980 GtkIconView *icon_view;
1981 GtkIconViewItem *item;
1982 gboolean dirty = FALSE;
1983 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1985 icon_view = GTK_ICON_VIEW (widget);
1987 if (event->window != icon_view->priv->bin_window)
1990 if (!gtk_widget_has_focus (widget))
1991 gtk_widget_grab_focus (widget);
1993 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1995 item = gtk_icon_view_get_item_at_coords (icon_view,
2001 * We consider only the the cells' area as the item area if the
2002 * item is not selected, but if it *is* selected, the complete
2003 * selection rectangle is considered to be part of the item.
2005 if (item != NULL && (cell != NULL || item->selected))
2009 if (gtk_cell_renderer_is_activatable (cell))
2013 gtk_icon_view_scroll_to_item (icon_view, item);
2015 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2017 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2019 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2020 (event->state & GDK_SHIFT_MASK))
2022 gtk_icon_view_unselect_all_internal (icon_view);
2024 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2025 if (!icon_view->priv->anchor_item)
2026 icon_view->priv->anchor_item = item;
2028 gtk_icon_view_select_all_between (icon_view,
2029 icon_view->priv->anchor_item,
2035 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2036 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2037 (event->state & GDK_CONTROL_MASK))
2039 item->selected = !item->selected;
2040 gtk_icon_view_queue_draw_item (icon_view, item);
2045 gtk_icon_view_unselect_all_internal (icon_view);
2047 item->selected = TRUE;
2048 gtk_icon_view_queue_draw_item (icon_view, item);
2051 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2052 icon_view->priv->anchor_item = item;
2055 /* Save press to possibly begin a drag */
2056 if (icon_view->priv->pressed_button < 0)
2058 icon_view->priv->pressed_button = event->button;
2059 icon_view->priv->press_start_x = event->x;
2060 icon_view->priv->press_start_y = event->y;
2063 if (!icon_view->priv->last_single_clicked)
2064 icon_view->priv->last_single_clicked = item;
2066 /* cancel the current editing, if it exists */
2067 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2069 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2071 GtkCellAreaContext *context;
2073 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2075 gtk_icon_view_set_cell_data (icon_view, item);
2076 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2077 GTK_WIDGET (icon_view),
2078 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2083 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2084 !(event->state & GDK_CONTROL_MASK))
2086 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2089 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2090 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2093 /* don't draw keyboard focus around an clicked-on item */
2094 icon_view->priv->draw_focus = FALSE;
2097 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2099 item = gtk_icon_view_get_item_at_coords (icon_view,
2104 if (item && item == icon_view->priv->last_single_clicked)
2108 path = gtk_tree_path_new_from_indices (item->index, -1);
2109 gtk_icon_view_item_activated (icon_view, path);
2110 gtk_tree_path_free (path);
2113 icon_view->priv->last_single_clicked = NULL;
2114 icon_view->priv->pressed_button = -1;
2118 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2120 return event->button == 1;
2124 gtk_icon_view_button_release (GtkWidget *widget,
2125 GdkEventButton *event)
2127 GtkIconView *icon_view;
2129 icon_view = GTK_ICON_VIEW (widget);
2131 if (icon_view->priv->pressed_button == event->button)
2132 icon_view->priv->pressed_button = -1;
2134 gtk_icon_view_stop_rubberbanding (icon_view);
2136 remove_scroll_timeout (icon_view);
2142 gtk_icon_view_key_press (GtkWidget *widget,
2145 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2147 if (icon_view->priv->doing_rubberband)
2149 if (event->keyval == GDK_KEY_Escape)
2150 gtk_icon_view_stop_rubberbanding (icon_view);
2155 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2159 gtk_icon_view_key_release (GtkWidget *widget,
2162 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2164 if (icon_view->priv->doing_rubberband)
2167 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2171 gtk_icon_view_update_rubberband (gpointer data)
2173 GtkIconView *icon_view;
2175 GdkRectangle old_area;
2176 GdkRectangle new_area;
2177 GdkRectangle common;
2178 cairo_region_t *invalid_region;
2180 icon_view = GTK_ICON_VIEW (data);
2182 gdk_window_get_device_position (icon_view->priv->bin_window,
2183 icon_view->priv->rubberband_device,
2189 old_area.x = MIN (icon_view->priv->rubberband_x1,
2190 icon_view->priv->rubberband_x2);
2191 old_area.y = MIN (icon_view->priv->rubberband_y1,
2192 icon_view->priv->rubberband_y2);
2193 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2194 icon_view->priv->rubberband_x1) + 1;
2195 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2196 icon_view->priv->rubberband_y1) + 1;
2198 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2199 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2200 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2201 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2203 invalid_region = cairo_region_create_rectangle (&old_area);
2204 cairo_region_union_rectangle (invalid_region, &new_area);
2206 gdk_rectangle_intersect (&old_area, &new_area, &common);
2207 if (common.width > 2 && common.height > 2)
2209 cairo_region_t *common_region;
2211 /* make sure the border is invalidated */
2217 common_region = cairo_region_create_rectangle (&common);
2219 cairo_region_subtract (invalid_region, common_region);
2220 cairo_region_destroy (common_region);
2223 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2225 cairo_region_destroy (invalid_region);
2227 icon_view->priv->rubberband_x2 = x;
2228 icon_view->priv->rubberband_y2 = y;
2230 gtk_icon_view_update_rubberband_selection (icon_view);
2234 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2241 if (icon_view->priv->rubberband_device)
2244 for (items = icon_view->priv->items; items; items = items->next)
2246 GtkIconViewItem *item = items->data;
2248 item->selected_before_rubberbanding = item->selected;
2251 icon_view->priv->rubberband_x1 = x;
2252 icon_view->priv->rubberband_y1 = y;
2253 icon_view->priv->rubberband_x2 = x;
2254 icon_view->priv->rubberband_y2 = y;
2256 icon_view->priv->doing_rubberband = TRUE;
2257 icon_view->priv->rubberband_device = device;
2259 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2263 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2265 if (!icon_view->priv->doing_rubberband)
2268 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2269 icon_view->priv->rubberband_device);
2271 icon_view->priv->doing_rubberband = FALSE;
2272 icon_view->priv->rubberband_device = NULL;
2274 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2278 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2281 gint x, y, width, height;
2282 gboolean dirty = FALSE;
2284 x = MIN (icon_view->priv->rubberband_x1,
2285 icon_view->priv->rubberband_x2);
2286 y = MIN (icon_view->priv->rubberband_y1,
2287 icon_view->priv->rubberband_y2);
2288 width = ABS (icon_view->priv->rubberband_x1 -
2289 icon_view->priv->rubberband_x2);
2290 height = ABS (icon_view->priv->rubberband_y1 -
2291 icon_view->priv->rubberband_y2);
2293 for (items = icon_view->priv->items; items; items = items->next)
2295 GtkIconViewItem *item = items->data;
2299 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2300 x, y, width, height);
2302 selected = is_in ^ item->selected_before_rubberbanding;
2304 if (item->selected != selected)
2306 item->selected = selected;
2308 gtk_icon_view_queue_draw_item (icon_view, item);
2313 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2318 GdkRectangle hit_rect;
2323 hit_test (GtkCellRenderer *renderer,
2324 const GdkRectangle *cell_area,
2325 const GdkRectangle *cell_background,
2328 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2329 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2330 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2331 MAX (data->hit_rect.y, cell_area->y) > 0)
2334 return (data->hit != FALSE);
2338 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2339 GtkIconViewItem *item,
2345 HitTestData data = { { x, y, width, height }, FALSE };
2346 GtkCellAreaContext *context;
2347 GdkRectangle *item_area = (GdkRectangle *)item;
2349 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2350 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2353 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2355 gtk_icon_view_set_cell_data (icon_view, item);
2356 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2357 GTK_WIDGET (icon_view),
2358 item_area, item_area,
2359 (GtkCellAllocCallback)hit_test, &data);
2365 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2367 gboolean dirty = FALSE;
2370 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2373 for (items = icon_view->priv->items; items; items = items->next)
2375 GtkIconViewItem *item = items->data;
2379 item->selected = FALSE;
2381 gtk_icon_view_queue_draw_item (icon_view, item);
2382 gtk_icon_view_item_selected_changed (icon_view, item);
2390 /* GtkIconView signals */
2392 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2394 gtk_icon_view_select_all (icon_view);
2398 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2400 gtk_icon_view_unselect_all (icon_view);
2404 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2406 gtk_icon_view_unselect_all (icon_view);
2408 if (icon_view->priv->cursor_item != NULL)
2409 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2413 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2416 GtkCellAreaContext *context;
2418 if (!icon_view->priv->cursor_item)
2421 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2423 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2424 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2425 GTK_WIDGET (icon_view),
2426 (GdkRectangle *)icon_view->priv->cursor_item,
2430 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2431 gtk_icon_view_item_activated (icon_view, path);
2432 gtk_tree_path_free (path);
2438 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2440 if (!icon_view->priv->cursor_item)
2443 switch (icon_view->priv->selection_mode)
2445 case GTK_SELECTION_NONE:
2447 case GTK_SELECTION_BROWSE:
2448 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2450 case GTK_SELECTION_SINGLE:
2451 if (icon_view->priv->cursor_item->selected)
2452 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2454 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2456 case GTK_SELECTION_MULTIPLE:
2457 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2458 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2460 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2461 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2466 /* Internal functions */
2468 gtk_icon_view_process_updates (GtkIconView *icon_view)
2470 /* Prior to drawing, we check if a layout has been scheduled. If so,
2471 * do it now that all cell view items have valid sizes before we proceeed
2472 * (and resize the bin_window if required).
2474 if (icon_view->priv->layout_idle_id != 0)
2475 gtk_icon_view_layout (icon_view);
2477 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2481 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2483 GtkAllocation allocation;
2484 GtkAdjustment *adj = icon_view->priv->hadjustment;
2485 gdouble old_page_size;
2491 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2493 old_value = gtk_adjustment_get_value (adj);
2494 old_upper = gtk_adjustment_get_upper (adj);
2495 old_page_size = gtk_adjustment_get_page_size (adj);
2496 new_upper = MAX (allocation.width, icon_view->priv->width);
2498 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2500 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2501 /* Quick explanation:
2502 * In LTR locales, leftmost portion of visible rectangle should stay
2503 * fixed, which means left edge of scrollbar thumb should remain fixed
2504 * and thus adjustment's value should stay the same.
2506 * In RTL locales, we want to keep rightmost portion of visible
2507 * rectangle fixed. This means right edge of thumb should remain fixed.
2508 * In this case, upper - value - page_size should remain constant.
2510 new_value = (new_upper - allocation.width) -
2511 (old_upper - old_value - old_page_size);
2512 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2515 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2517 gtk_adjustment_configure (adj,
2521 allocation.width * 0.1,
2522 allocation.width * 0.9,
2527 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2529 GtkAllocation allocation;
2530 GtkAdjustment *adj = icon_view->priv->vadjustment;
2532 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2534 gtk_adjustment_configure (adj,
2535 gtk_adjustment_get_value (adj),
2537 MAX (allocation.height, icon_view->priv->height),
2538 allocation.height * 0.1,
2539 allocation.height * 0.9,
2544 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2545 GtkAdjustment *adjustment)
2547 GtkIconViewPrivate *priv = icon_view->priv;
2550 if (adjustment && priv->hadjustment == adjustment)
2553 if (priv->hadjustment != NULL)
2555 g_signal_handlers_disconnect_matched (priv->hadjustment,
2556 G_SIGNAL_MATCH_DATA,
2557 0, 0, NULL, NULL, icon_view);
2558 g_object_unref (priv->hadjustment);
2562 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2565 g_signal_connect (adjustment, "value-changed",
2566 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2567 priv->hadjustment = g_object_ref_sink (adjustment);
2568 gtk_icon_view_set_hadjustment_values (icon_view);
2570 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2571 gtk_icon_view_accessible_set_adjustment (atk_obj,
2572 GTK_ORIENTATION_HORIZONTAL,
2575 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2579 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2580 GtkAdjustment *adjustment)
2582 GtkIconViewPrivate *priv = icon_view->priv;
2585 if (adjustment && priv->vadjustment == adjustment)
2588 if (priv->vadjustment != NULL)
2590 g_signal_handlers_disconnect_matched (priv->vadjustment,
2591 G_SIGNAL_MATCH_DATA,
2592 0, 0, NULL, NULL, icon_view);
2593 g_object_unref (priv->vadjustment);
2597 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2600 g_signal_connect (adjustment, "value-changed",
2601 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2602 priv->vadjustment = g_object_ref_sink (adjustment);
2603 gtk_icon_view_set_vadjustment_values (icon_view);
2605 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2606 gtk_icon_view_accessible_set_adjustment (atk_obj,
2607 GTK_ORIENTATION_VERTICAL,
2610 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2614 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2615 GtkIconView *icon_view)
2617 GtkIconViewPrivate *priv = icon_view->priv;
2619 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2621 gdk_window_move (priv->bin_window,
2622 - gtk_adjustment_get_value (priv->hadjustment),
2623 - gtk_adjustment_get_value (priv->vadjustment));
2625 if (icon_view->priv->doing_rubberband)
2626 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2628 gtk_icon_view_process_updates (icon_view);
2633 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2638 gint *maximum_width)
2640 GtkAllocation allocation;
2641 GtkCellAreaContext *context;
2642 GtkIconViewPrivate *priv = icon_view->priv;
2643 GtkWidget *widget = GTK_WIDGET (icon_view);
2644 gint x, current_width;
2645 GList *items, *last_item;
2647 gint max_height = 0;
2650 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2658 current_width += 2 * priv->margin;
2660 gtk_widget_get_allocation (widget, &allocation);
2662 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2663 g_ptr_array_add (priv->row_contexts, context);
2665 /* In the first loop we iterate horizontally until we hit allocation width
2666 * and collect the aligned height-for-width */
2670 GtkIconViewItem *item = items->data;
2671 GdkRectangle *item_area = (GdkRectangle *)item;
2673 item_area->width = item_width;
2675 current_width += item_area->width + icon_view->priv->item_padding * 2;
2677 if (items != first_item)
2679 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2680 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2684 /* Get this item's particular width & height (all alignments are cached by now) */
2685 gtk_icon_view_set_cell_data (icon_view, item);
2686 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2691 current_width += icon_view->priv->column_spacing;
2693 item_area->y = *y + icon_view->priv->item_padding;
2694 item_area->x = x + icon_view->priv->item_padding;
2696 x = current_width - icon_view->priv->margin;
2698 if (current_width > *maximum_width)
2699 *maximum_width = current_width;
2705 items = items->next;
2710 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2711 gtk_cell_area_context_allocate (context, item_width, max_height);
2713 /* In the second loop the item height has been aligned and derived and
2714 * we just set the height and handle rtl layout */
2715 for (items = first_item; items != last_item; items = items->next)
2717 GtkIconViewItem *item = items->data;
2718 GdkRectangle *item_area = (GdkRectangle *)item;
2722 item_area->x = *maximum_width - item_area->width - item_area->x;
2723 item->col = col - 1 - item->col;
2726 /* All items in the same row get the same height */
2727 item_area->height = max_height;
2730 /* Adjust the new y coordinate. */
2731 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2737 adjust_wrap_width (GtkIconView *icon_view)
2739 if (icon_view->priv->text_cell)
2741 gint wrap_width = 50;
2743 /* Here we go with the same old guess, try the icon size and set double
2744 * the size of the first icon found in the list, naive but works much
2746 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2748 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2749 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2750 GTK_WIDGET (icon_view),
2753 wrap_width = MAX (wrap_width * 2, 50);
2756 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2757 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2762 gtk_icon_view_layout (GtkIconView *icon_view)
2764 GtkAllocation allocation;
2767 gint y = 0, maximum_width = 0;
2770 gboolean size_changed = FALSE;
2772 if (icon_view->priv->layout_idle_id != 0)
2774 g_source_remove (icon_view->priv->layout_idle_id);
2775 icon_view->priv->layout_idle_id = 0;
2778 if (icon_view->priv->model == NULL)
2781 widget = GTK_WIDGET (icon_view);
2783 item_width = icon_view->priv->item_width;
2785 /* Update the wrap width for the text cell before going and requesting sizes */
2786 adjust_wrap_width (icon_view);
2788 /* Update the context widths for any invalidated items */
2789 gtk_icon_view_cache_widths (icon_view);
2791 /* Fetch the new item width if needed */
2793 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2796 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2798 icons = icon_view->priv->items;
2799 y += icon_view->priv->margin;
2802 /* Clear the per row contexts */
2803 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2807 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2809 &y, &maximum_width);
2812 while (icons != NULL);
2814 if (maximum_width != icon_view->priv->width)
2816 icon_view->priv->width = maximum_width;
2817 size_changed = TRUE;
2820 y += icon_view->priv->margin;
2822 if (y != icon_view->priv->height)
2824 icon_view->priv->height = y;
2825 size_changed = TRUE;
2828 gtk_icon_view_set_hadjustment_values (icon_view);
2829 gtk_icon_view_set_vadjustment_values (icon_view);
2832 gtk_widget_queue_resize_no_redraw (widget);
2834 gtk_widget_get_allocation (widget, &allocation);
2835 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2836 gdk_window_resize (icon_view->priv->bin_window,
2837 MAX (icon_view->priv->width, allocation.width),
2838 MAX (icon_view->priv->height, allocation.height));
2840 if (icon_view->priv->scroll_to_path)
2844 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2845 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2846 icon_view->priv->scroll_to_path = NULL;
2848 gtk_icon_view_scroll_to_path (icon_view, path,
2849 icon_view->priv->scroll_to_use_align,
2850 icon_view->priv->scroll_to_row_align,
2851 icon_view->priv->scroll_to_col_align);
2852 gtk_tree_path_free (path);
2855 gtk_widget_queue_draw (widget);
2858 /* This ensures that all widths have been cached in the
2859 * context and we have proper alignments to go on.
2862 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2866 g_signal_handler_block (icon_view->priv->cell_area_context,
2867 icon_view->priv->context_changed_id);
2869 for (items = icon_view->priv->items; items; items = items->next)
2871 GtkIconViewItem *item = items->data;
2873 /* Only fetch the width of items with invalidated sizes */
2874 if (item->cell_area.width < 0)
2876 gtk_icon_view_set_cell_data (icon_view, item);
2877 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2878 icon_view->priv->cell_area_context,
2879 GTK_WIDGET (icon_view), NULL, NULL);
2883 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2884 icon_view->priv->context_changed_id);
2888 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2890 /* Clear all item sizes */
2891 g_list_foreach (icon_view->priv->items,
2892 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2894 /* Reset the context */
2895 if (icon_view->priv->cell_area_context)
2897 g_signal_handler_block (icon_view->priv->cell_area_context,
2898 icon_view->priv->context_changed_id);
2899 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2900 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2901 icon_view->priv->context_changed_id);
2904 /* Re-layout the items */
2905 gtk_icon_view_queue_layout (icon_view);
2909 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2911 item->cell_area.width = -1;
2912 item->cell_area.height = -1;
2916 gtk_icon_view_paint_item (GtkIconView *icon_view,
2918 GtkIconViewItem *item,
2921 gboolean draw_focus)
2923 GdkRectangle cell_area;
2924 GtkStateFlags state = 0;
2925 GtkCellRendererState flags = 0;
2926 GtkStyleContext *style_context;
2927 GtkWidget *widget = GTK_WIDGET (icon_view);
2928 GtkIconViewPrivate *priv = icon_view->priv;
2929 GtkCellAreaContext *context;
2931 if (priv->model == NULL)
2934 gtk_icon_view_set_cell_data (icon_view, item);
2936 style_context = gtk_widget_get_style_context (widget);
2938 gtk_style_context_save (style_context);
2939 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2940 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2944 if (gtk_widget_has_focus (widget) &&
2945 item == icon_view->priv->cursor_item)
2947 state |= GTK_STATE_FLAG_FOCUSED;
2948 flags |= GTK_CELL_RENDERER_FOCUSED;
2951 state |= GTK_STATE_FLAG_SELECTED;
2952 flags |= GTK_CELL_RENDERER_SELECTED;
2954 gtk_style_context_set_state (style_context, state);
2956 gtk_render_background (style_context, cr,
2957 x - icon_view->priv->item_padding,
2958 y - icon_view->priv->item_padding,
2959 item->cell_area.width + icon_view->priv->item_padding * 2,
2960 item->cell_area.height + icon_view->priv->item_padding * 2);
2961 gtk_render_frame (style_context, cr,
2962 x - icon_view->priv->item_padding,
2963 y - icon_view->priv->item_padding,
2964 item->cell_area.width + icon_view->priv->item_padding * 2,
2965 item->cell_area.height + icon_view->priv->item_padding * 2);
2970 cell_area.width = item->cell_area.width;
2971 cell_area.height = item->cell_area.height;
2973 context = g_ptr_array_index (priv->row_contexts, item->row);
2974 gtk_cell_area_render (priv->cell_area, context,
2975 widget, cr, &cell_area, &cell_area, flags,
2978 gtk_style_context_restore (style_context);
2982 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2985 GtkStyleContext *context;
2990 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2991 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2992 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2993 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2995 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2997 gtk_style_context_save (context);
2998 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
3000 gdk_cairo_rectangle (cr, &rect);
3003 gtk_render_background (context, cr,
3005 rect.width, rect.height);
3006 gtk_render_frame (context, cr,
3008 rect.width, rect.height);
3010 gtk_style_context_restore (context);
3015 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3021 index = gtk_tree_path_get_indices (path)[0];
3023 for (l = icon_view->priv->items; l; l = l->next)
3025 GtkIconViewItem *item = l->data;
3027 if (item->index == index)
3029 gtk_icon_view_queue_draw_item (icon_view, item);
3036 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3037 GtkIconViewItem *item)
3040 GdkRectangle *item_area = (GdkRectangle *)item;
3042 rect.x = item_area->x - icon_view->priv->item_padding;
3043 rect.y = item_area->y - icon_view->priv->item_padding;
3044 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3045 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3047 if (icon_view->priv->bin_window)
3048 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3052 layout_callback (gpointer user_data)
3054 GtkIconView *icon_view;
3056 icon_view = GTK_ICON_VIEW (user_data);
3058 icon_view->priv->layout_idle_id = 0;
3060 gtk_icon_view_layout (icon_view);
3066 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3068 if (icon_view->priv->layout_idle_id != 0)
3071 icon_view->priv->layout_idle_id =
3072 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3073 layout_callback, icon_view, NULL);
3077 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3078 GtkIconViewItem *item,
3079 GtkCellRenderer *cursor_cell)
3082 AtkObject *item_obj;
3083 AtkObject *cursor_item_obj;
3085 /* When hitting this path from keynav, the focus cell is
3086 * already set, we dont need to notify the atk object
3087 * but we still need to queue the draw here (in the case
3088 * that the focus cell changes but not the cursor item).
3090 gtk_icon_view_queue_draw_item (icon_view, item);
3092 if (icon_view->priv->cursor_item == item &&
3093 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3096 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3097 if (icon_view->priv->cursor_item != NULL)
3099 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3102 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3103 if (cursor_item_obj != NULL)
3104 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3107 icon_view->priv->cursor_item = item;
3110 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3113 /* Make sure there is a cell in focus initially */
3114 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3115 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3118 /* Notify that accessible focus object has changed */
3119 item_obj = atk_object_ref_accessible_child (obj, item->index);
3121 if (item_obj != NULL)
3123 atk_focus_tracker_notify (item_obj);
3124 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3125 g_object_unref (item_obj);
3130 static GtkIconViewItem *
3131 gtk_icon_view_item_new (void)
3133 GtkIconViewItem *item;
3135 item = g_slice_new0 (GtkIconViewItem);
3137 item->cell_area.width = -1;
3138 item->cell_area.height = -1;
3144 gtk_icon_view_item_free (GtkIconViewItem *item)
3146 g_return_if_fail (item != NULL);
3148 g_slice_free (GtkIconViewItem, item);
3151 static GtkIconViewItem *
3152 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3155 gboolean only_in_cell,
3156 GtkCellRenderer **cell_at_pos)
3161 *cell_at_pos = NULL;
3163 for (items = icon_view->priv->items; items; items = items->next)
3165 GtkIconViewItem *item = items->data;
3166 GdkRectangle *item_area = (GdkRectangle *)item;
3168 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3169 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3170 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3171 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3173 if (only_in_cell || cell_at_pos)
3175 GtkCellRenderer *cell = NULL;
3176 GtkCellAreaContext *context;
3178 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3179 gtk_icon_view_set_cell_data (icon_view, item);
3181 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3182 y >= item_area->y && y <= item_area->y + item_area->height)
3183 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3184 GTK_WIDGET (icon_view),
3189 *cell_at_pos = cell;
3192 return cell != NULL ? item : NULL;
3203 gtk_icon_view_select_item (GtkIconView *icon_view,
3204 GtkIconViewItem *item)
3206 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3207 g_return_if_fail (item != NULL);
3212 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3214 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3215 gtk_icon_view_unselect_all_internal (icon_view);
3217 item->selected = TRUE;
3219 gtk_icon_view_item_selected_changed (icon_view, item);
3220 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3222 gtk_icon_view_queue_draw_item (icon_view, item);
3227 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3228 GtkIconViewItem *item)
3230 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3231 g_return_if_fail (item != NULL);
3233 if (!item->selected)
3236 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3237 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3240 item->selected = FALSE;
3242 gtk_icon_view_item_selected_changed (icon_view, item);
3243 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3245 gtk_icon_view_queue_draw_item (icon_view, item);
3249 verify_items (GtkIconView *icon_view)
3254 for (items = icon_view->priv->items; items; items = items->next)
3256 GtkIconViewItem *item = items->data;
3258 if (item->index != i)
3259 g_error ("List item does not match its index: "
3260 "item index %d and list index %d\n", item->index, i);
3267 gtk_icon_view_row_changed (GtkTreeModel *model,
3272 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3274 /* ignore changes in branches */
3275 if (gtk_tree_path_get_depth (path) > 1)
3278 /* An icon view subclass might add it's own model and populate
3279 * things at init() time instead of waiting for the constructor()
3282 if (icon_view->priv->cell_area)
3283 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3285 /* Here we can use a "grow-only" strategy for optimization
3286 * and only invalidate a single item and queue a relayout
3287 * instead of invalidating the whole thing.
3289 * For now GtkIconView still cant deal with huge models
3290 * so just invalidate the whole thing when the model
3293 gtk_icon_view_invalidate_sizes (icon_view);
3295 verify_items (icon_view);
3299 gtk_icon_view_row_inserted (GtkTreeModel *model,
3304 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3306 GtkIconViewItem *item;
3307 gboolean iters_persist;
3310 /* ignore changes in branches */
3311 if (gtk_tree_path_get_depth (path) > 1)
3314 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3316 index = gtk_tree_path_get_indices(path)[0];
3318 item = gtk_icon_view_item_new ();
3323 item->index = index;
3325 /* FIXME: We can be more efficient here,
3326 we can store a tail pointer and use that when
3327 appending (which is a rather common operation)
3329 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3332 list = g_list_nth (icon_view->priv->items, index + 1);
3333 for (; list; list = list->next)
3340 verify_items (icon_view);
3342 gtk_icon_view_queue_layout (icon_view);
3346 gtk_icon_view_row_deleted (GtkTreeModel *model,
3350 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3352 GtkIconViewItem *item;
3354 gboolean emit = FALSE;
3356 /* ignore changes in branches */
3357 if (gtk_tree_path_get_depth (path) > 1)
3360 index = gtk_tree_path_get_indices(path)[0];
3362 list = g_list_nth (icon_view->priv->items, index);
3365 if (icon_view->priv->cell_area)
3366 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3368 if (item == icon_view->priv->anchor_item)
3369 icon_view->priv->anchor_item = NULL;
3371 if (item == icon_view->priv->cursor_item)
3372 icon_view->priv->cursor_item = NULL;
3377 gtk_icon_view_item_free (item);
3379 for (next = list->next; next; next = next->next)
3386 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3388 verify_items (icon_view);
3390 gtk_icon_view_queue_layout (icon_view);
3393 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3397 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3398 GtkTreePath *parent,
3403 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3406 GList *items = NULL, *list;
3407 GtkIconViewItem **item_array;
3410 /* ignore changes in branches */
3414 if (icon_view->priv->cell_area)
3415 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3417 length = gtk_tree_model_iter_n_children (model, NULL);
3419 order = g_new (gint, length);
3420 for (i = 0; i < length; i++)
3421 order [new_order[i]] = i;
3423 item_array = g_new (GtkIconViewItem *, length);
3424 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3425 item_array[order[i]] = list->data;
3428 for (i = length - 1; i >= 0; i--)
3430 item_array[i]->index = i;
3431 items = g_list_prepend (items, item_array[i]);
3434 g_free (item_array);
3435 g_list_free (icon_view->priv->items);
3436 icon_view->priv->items = items;
3438 gtk_icon_view_queue_layout (icon_view);
3440 verify_items (icon_view);
3444 gtk_icon_view_build_items (GtkIconView *icon_view)
3448 gboolean iters_persist;
3449 GList *items = NULL;
3451 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3453 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3461 GtkIconViewItem *item = gtk_icon_view_item_new ();
3470 items = g_list_prepend (items, item);
3472 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3474 icon_view->priv->items = g_list_reverse (items);
3478 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3481 GtkMovementStep step,
3485 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3486 I_("move-cursor"), 2,
3490 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3495 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3498 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3503 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3510 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3511 GtkMovementStep step,
3514 GdkModifierType state;
3516 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3517 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3518 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3519 step == GTK_MOVEMENT_DISPLAY_LINES ||
3520 step == GTK_MOVEMENT_PAGES ||
3521 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3523 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3526 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3527 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3529 if (gtk_get_current_event_state (&state))
3531 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3532 icon_view->priv->ctrl_pressed = TRUE;
3533 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3534 icon_view->priv->shift_pressed = TRUE;
3536 /* else we assume not pressed */
3540 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3541 case GTK_MOVEMENT_VISUAL_POSITIONS:
3542 gtk_icon_view_move_cursor_left_right (icon_view, count);
3544 case GTK_MOVEMENT_DISPLAY_LINES:
3545 gtk_icon_view_move_cursor_up_down (icon_view, count);
3547 case GTK_MOVEMENT_PAGES:
3548 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3550 case GTK_MOVEMENT_BUFFER_ENDS:
3551 gtk_icon_view_move_cursor_start_end (icon_view, count);
3554 g_assert_not_reached ();
3557 icon_view->priv->ctrl_pressed = FALSE;
3558 icon_view->priv->shift_pressed = FALSE;
3560 icon_view->priv->draw_focus = TRUE;
3565 static GtkIconViewItem *
3566 find_item (GtkIconView *icon_view,
3567 GtkIconViewItem *current,
3573 GtkIconViewItem *item;
3575 /* FIXME: this could be more efficient
3577 row = current->row + row_ofs;
3578 col = current->col + col_ofs;
3580 for (items = icon_view->priv->items; items; items = items->next)
3583 if (item->row == row && item->col == col)
3590 static GtkIconViewItem *
3591 find_item_page_up_down (GtkIconView *icon_view,
3592 GtkIconViewItem *current,
3599 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3601 item = g_list_find (icon_view->priv->items, current);
3606 for (next = item->next; next; next = next->next)
3608 if (((GtkIconViewItem *)next->data)->col == col)
3611 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3621 for (next = item->prev; next; next = next->prev)
3623 if (((GtkIconViewItem *)next->data)->col == col)
3626 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3640 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3641 GtkIconViewItem *anchor,
3642 GtkIconViewItem *cursor)
3645 GtkIconViewItem *item;
3646 gint row1, row2, col1, col2;
3647 gboolean dirty = FALSE;
3649 if (anchor->row < cursor->row)
3660 if (anchor->col < cursor->col)
3671 for (items = icon_view->priv->items; items; items = items->next)
3675 if (row1 <= item->row && item->row <= row2 &&
3676 col1 <= item->col && item->col <= col2)
3678 if (!item->selected)
3681 item->selected = TRUE;
3682 gtk_icon_view_item_selected_changed (icon_view, item);
3684 gtk_icon_view_queue_draw_item (icon_view, item);
3692 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3695 GtkIconViewItem *item;
3696 GtkCellRenderer *cell;
3697 gboolean dirty = FALSE;
3699 GtkDirectionType direction;
3701 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3704 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3706 if (!icon_view->priv->cursor_item)
3711 list = icon_view->priv->items;
3713 list = g_list_last (icon_view->priv->items);
3715 item = list ? list->data : NULL;
3717 /* Give focus to the first cell initially */
3718 gtk_icon_view_set_cell_data (icon_view, item);
3719 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3723 item = icon_view->priv->cursor_item;
3724 step = count > 0 ? 1 : -1;
3726 /* Save the current focus cell in case we hit the edge */
3727 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3731 gtk_icon_view_set_cell_data (icon_view, item);
3733 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3736 item = find_item (icon_view, item, step, 0);
3742 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3744 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3746 gtk_widget_child_focus (toplevel,
3747 direction == GTK_DIR_UP ?
3748 GTK_DIR_TAB_BACKWARD :
3749 GTK_DIR_TAB_FORWARD);
3753 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3757 if (icon_view->priv->ctrl_pressed ||
3758 !icon_view->priv->shift_pressed ||
3759 !icon_view->priv->anchor_item ||
3760 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3761 icon_view->priv->anchor_item = item;
3763 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3764 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3766 if (!icon_view->priv->ctrl_pressed &&
3767 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3769 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3770 dirty = gtk_icon_view_select_all_between (icon_view,
3771 icon_view->priv->anchor_item,
3775 gtk_icon_view_scroll_to_item (icon_view, item);
3778 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3782 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3785 GtkIconViewItem *item;
3786 gboolean dirty = FALSE;
3788 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3791 if (!icon_view->priv->cursor_item)
3796 list = icon_view->priv->items;
3798 list = g_list_last (icon_view->priv->items);
3800 item = list ? list->data : NULL;
3803 item = find_item_page_up_down (icon_view,
3804 icon_view->priv->cursor_item,
3807 if (item == icon_view->priv->cursor_item)
3808 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3813 if (icon_view->priv->ctrl_pressed ||
3814 !icon_view->priv->shift_pressed ||
3815 !icon_view->priv->anchor_item ||
3816 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3817 icon_view->priv->anchor_item = item;
3819 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3821 if (!icon_view->priv->ctrl_pressed &&
3822 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3824 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3825 dirty = gtk_icon_view_select_all_between (icon_view,
3826 icon_view->priv->anchor_item,
3830 gtk_icon_view_scroll_to_item (icon_view, item);
3833 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3837 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3840 GtkIconViewItem *item;
3841 GtkCellRenderer *cell = NULL;
3842 gboolean dirty = FALSE;
3844 GtkDirectionType direction;
3846 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3849 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3851 if (!icon_view->priv->cursor_item)
3856 list = icon_view->priv->items;
3858 list = g_list_last (icon_view->priv->items);
3860 item = list ? list->data : NULL;
3862 /* Give focus to the first cell initially */
3863 gtk_icon_view_set_cell_data (icon_view, item);
3864 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3868 item = icon_view->priv->cursor_item;
3869 step = count > 0 ? 1 : -1;
3871 /* Save the current focus cell in case we hit the edge */
3872 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3876 gtk_icon_view_set_cell_data (icon_view, item);
3878 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3881 item = find_item (icon_view, item, 0, step);
3887 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3889 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3891 gtk_widget_child_focus (toplevel,
3892 direction == GTK_DIR_LEFT ?
3893 GTK_DIR_TAB_BACKWARD :
3894 GTK_DIR_TAB_FORWARD);
3898 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3902 if (icon_view->priv->ctrl_pressed ||
3903 !icon_view->priv->shift_pressed ||
3904 !icon_view->priv->anchor_item ||
3905 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3906 icon_view->priv->anchor_item = item;
3908 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3909 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3911 if (!icon_view->priv->ctrl_pressed &&
3912 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3914 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3915 dirty = gtk_icon_view_select_all_between (icon_view,
3916 icon_view->priv->anchor_item,
3920 gtk_icon_view_scroll_to_item (icon_view, item);
3923 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3927 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3930 GtkIconViewItem *item;
3932 gboolean dirty = FALSE;
3934 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3938 list = icon_view->priv->items;
3940 list = g_list_last (icon_view->priv->items);
3942 item = list ? list->data : NULL;
3944 if (item == icon_view->priv->cursor_item)
3945 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3950 if (icon_view->priv->ctrl_pressed ||
3951 !icon_view->priv->shift_pressed ||
3952 !icon_view->priv->anchor_item ||
3953 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3954 icon_view->priv->anchor_item = item;
3956 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3958 if (!icon_view->priv->ctrl_pressed &&
3959 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3961 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3962 dirty = gtk_icon_view_select_all_between (icon_view,
3963 icon_view->priv->anchor_item,
3967 gtk_icon_view_scroll_to_item (icon_view, item);
3970 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3974 * gtk_icon_view_scroll_to_path:
3975 * @icon_view: A #GtkIconView.
3976 * @path: The path of the item to move to.
3977 * @use_align: whether to use alignment arguments, or %FALSE.
3978 * @row_align: The vertical alignment of the item specified by @path.
3979 * @col_align: The horizontal alignment of the item specified by @path.
3981 * Moves the alignments of @icon_view to the position specified by @path.
3982 * @row_align determines where the row is placed, and @col_align determines
3983 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3984 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3987 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3988 * tree does the minimum amount of work to scroll the item onto the screen.
3989 * This means that the item will be scrolled to the edge closest to its current
3990 * position. If the item is currently visible on the screen, nothing is done.
3992 * This function only works if the model is set, and @path is a valid row on
3993 * the model. If the model changes before the @icon_view is realized, the
3994 * centered path will be modified to reflect this change.
3999 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4005 GtkIconViewItem *item = NULL;
4008 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4009 g_return_if_fail (path != NULL);
4010 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4011 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4013 widget = GTK_WIDGET (icon_view);
4015 if (gtk_tree_path_get_depth (path) > 0)
4016 item = g_list_nth_data (icon_view->priv->items,
4017 gtk_tree_path_get_indices(path)[0]);
4019 if (!item || item->cell_area.width < 0 ||
4020 !gtk_widget_get_realized (widget))
4022 if (icon_view->priv->scroll_to_path)
4023 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4025 icon_view->priv->scroll_to_path = NULL;
4028 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4030 icon_view->priv->scroll_to_use_align = use_align;
4031 icon_view->priv->scroll_to_row_align = row_align;
4032 icon_view->priv->scroll_to_col_align = col_align;
4039 GtkAllocation allocation;
4042 GdkRectangle item_area =
4044 item->cell_area.x - icon_view->priv->item_padding,
4045 item->cell_area.y - icon_view->priv->item_padding,
4046 item->cell_area.width + icon_view->priv->item_padding * 2,
4047 item->cell_area.height + icon_view->priv->item_padding * 2
4050 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4052 gtk_widget_get_allocation (widget, &allocation);
4054 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4056 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4057 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4059 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4061 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4062 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4064 gtk_adjustment_changed (icon_view->priv->hadjustment);
4065 gtk_adjustment_changed (icon_view->priv->vadjustment);
4068 gtk_icon_view_scroll_to_item (icon_view, item);
4073 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4074 GtkIconViewItem *item)
4076 GtkIconViewPrivate *priv = icon_view->priv;
4077 GtkWidget *widget = GTK_WIDGET (icon_view);
4078 GtkAdjustment *hadj, *vadj;
4079 GtkAllocation allocation;
4081 GdkRectangle item_area;
4083 item_area.x = item->cell_area.x - priv->item_padding;
4084 item_area.y = item->cell_area.y - priv->item_padding;
4085 item_area.width = item->cell_area.width + priv->item_padding * 2;
4086 item_area.height = item->cell_area.height + priv->item_padding * 2;
4088 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4089 gtk_widget_get_allocation (widget, &allocation);
4091 hadj = icon_view->priv->hadjustment;
4092 vadj = icon_view->priv->vadjustment;
4094 if (y + item_area.y < 0)
4095 gtk_adjustment_set_value (vadj,
4096 gtk_adjustment_get_value (vadj)
4098 else if (y + item_area.y + item_area.height > allocation.height)
4099 gtk_adjustment_set_value (vadj,
4100 gtk_adjustment_get_value (vadj)
4101 + y + item_area.y + item_area.height - allocation.height);
4103 if (x + item_area.x < 0)
4104 gtk_adjustment_set_value (hadj,
4105 gtk_adjustment_get_value (hadj)
4107 else if (x + item_area.x + item_area.width > allocation.width)
4108 gtk_adjustment_set_value (hadj,
4109 gtk_adjustment_get_value (hadj)
4110 + x + item_area.x + item_area.width - allocation.width);
4112 gtk_adjustment_changed (hadj);
4113 gtk_adjustment_changed (vadj);
4116 /* GtkCellLayout implementation */
4119 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4120 GtkCellArea *cell_area)
4122 GtkIconViewPrivate *priv = icon_view->priv;
4124 if (priv->cell_area)
4128 priv->cell_area = cell_area;
4130 priv->cell_area = gtk_cell_area_box_new ();
4132 g_object_ref_sink (priv->cell_area);
4134 if (GTK_IS_ORIENTABLE (priv->cell_area))
4135 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4137 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4139 priv->add_editable_id =
4140 g_signal_connect (priv->cell_area, "add-editable",
4141 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4142 priv->remove_editable_id =
4143 g_signal_connect (priv->cell_area, "remove-editable",
4144 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4145 priv->context_changed_id =
4146 g_signal_connect (priv->cell_area_context, "notify",
4147 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4149 update_text_cell (icon_view);
4150 update_pixbuf_cell (icon_view);
4153 static GtkCellArea *
4154 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4156 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4157 GtkIconViewPrivate *priv = icon_view->priv;
4159 if (G_UNLIKELY (!priv->cell_area))
4160 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4162 return icon_view->priv->cell_area;
4166 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4167 GtkIconViewItem *item)
4169 gboolean iters_persist;
4172 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4178 path = gtk_tree_path_new_from_indices (item->index, -1);
4179 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4181 gtk_tree_path_free (path);
4186 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4187 icon_view->priv->model,
4188 &iter, FALSE, FALSE);
4197 * gtk_icon_view_new:
4199 * Creates a new #GtkIconView widget
4201 * Return value: A newly created #GtkIconView widget
4206 gtk_icon_view_new (void)
4208 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4212 * gtk_icon_view_new_with_area:
4213 * @area: the #GtkCellArea to use to layout cells
4215 * Creates a new #GtkIconView widget using the
4216 * specified @area to layout cells inside the icons.
4218 * Return value: A newly created #GtkIconView widget
4223 gtk_icon_view_new_with_area (GtkCellArea *area)
4225 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4229 * gtk_icon_view_new_with_model:
4230 * @model: The model.
4232 * Creates a new #GtkIconView widget with the model @model.
4234 * Return value: A newly created #GtkIconView widget.
4239 gtk_icon_view_new_with_model (GtkTreeModel *model)
4241 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4245 * gtk_icon_view_convert_widget_to_bin_window_coords:
4246 * @icon_view: a #GtkIconView
4247 * @wx: X coordinate relative to the widget
4248 * @wy: Y coordinate relative to the widget
4249 * @bx: (out): return location for bin_window X coordinate
4250 * @by: (out): return location for bin_window Y coordinate
4252 * Converts widget coordinates to coordinates for the bin_window,
4253 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4258 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4266 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4268 if (icon_view->priv->bin_window)
4269 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4280 * gtk_icon_view_get_path_at_pos:
4281 * @icon_view: A #GtkIconView.
4282 * @x: The x position to be identified
4283 * @y: The y position to be identified
4285 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4286 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4287 * the cell at the specified position.
4288 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4289 * widget coordinates to bin_window coordinates.
4291 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4292 * if no icon exists at that position.
4297 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4301 GtkIconViewItem *item;
4304 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4306 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4311 path = gtk_tree_path_new_from_indices (item->index, -1);
4317 * gtk_icon_view_get_item_at_pos:
4318 * @icon_view: A #GtkIconView.
4319 * @x: The x position to be identified
4320 * @y: The y position to be identified
4321 * @path: (out) (allow-none): Return location for the path, or %NULL
4322 * @cell: (out) (allow-none): Return location for the renderer
4323 * responsible for the cell at (@x, @y), or %NULL
4325 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4326 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4327 * obtains the cell at the specified position. The returned path should
4328 * be freed with gtk_tree_path_free().
4329 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4330 * widget coordinates to bin_window coordinates.
4332 * Return value: %TRUE if an item exists at the specified position
4337 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4341 GtkCellRenderer **cell)
4343 GtkIconViewItem *item;
4344 GtkCellRenderer *renderer = NULL;
4346 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4348 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4353 *path = gtk_tree_path_new_from_indices (item->index, -1);
4361 return (item != NULL);
4365 * gtk_icon_view_set_tooltip_item:
4366 * @icon_view: a #GtkIconView
4367 * @tooltip: a #GtkTooltip
4368 * @path: a #GtkTreePath
4370 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4371 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4372 * See also gtk_tooltip_set_tip_area().
4377 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4378 GtkTooltip *tooltip,
4381 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4382 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4384 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4388 * gtk_icon_view_set_tooltip_cell:
4389 * @icon_view: a #GtkIconView
4390 * @tooltip: a #GtkTooltip
4391 * @path: a #GtkTreePath
4392 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4394 * Sets the tip area of @tooltip to the area which @cell occupies in
4395 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4397 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4402 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4403 GtkTooltip *tooltip,
4405 GtkCellRenderer *cell)
4408 GtkIconViewItem *item = NULL;
4411 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4412 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4413 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4415 if (gtk_tree_path_get_depth (path) > 0)
4416 item = g_list_nth_data (icon_view->priv->items,
4417 gtk_tree_path_get_indices(path)[0]);
4424 GtkCellAreaContext *context;
4426 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4427 gtk_icon_view_set_cell_data (icon_view, item);
4428 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4429 GTK_WIDGET (icon_view),
4430 cell, (GdkRectangle *)item, &rect);
4434 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4435 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4436 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4437 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4440 if (icon_view->priv->bin_window)
4442 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4447 gtk_tooltip_set_tip_area (tooltip, &rect);
4452 * gtk_icon_view_get_tooltip_context:
4453 * @icon_view: an #GtkIconView
4454 * @x: (inout): the x coordinate (relative to widget coordinates)
4455 * @y: (inout): the y coordinate (relative to widget coordinates)
4456 * @keyboard_tip: whether this is a keyboard tooltip or not
4457 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4458 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4459 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4461 * This function is supposed to be used in a #GtkWidget::query-tooltip
4462 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4463 * which are received in the signal handler, should be passed to this
4464 * function without modification.
4466 * The return value indicates whether there is an icon view item at the given
4467 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4468 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4469 * @model, @path and @iter which have been provided will be set to point to
4470 * that row and the corresponding model. @x and @y will always be converted
4471 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4473 * Return value: whether or not the given tooltip context points to a item
4478 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4481 gboolean keyboard_tip,
4482 GtkTreeModel **model,
4486 GtkTreePath *tmppath = NULL;
4488 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4489 g_return_val_if_fail (x != NULL, FALSE);
4490 g_return_val_if_fail (y != NULL, FALSE);
4494 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4501 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4504 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4509 *model = gtk_icon_view_get_model (icon_view);
4512 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4518 gtk_tree_path_free (tmppath);
4524 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4527 gboolean keyboard_tip,
4528 GtkTooltip *tooltip,
4534 GtkTreeModel *model;
4535 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4537 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4540 &model, &path, &iter))
4543 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4547 gtk_tree_path_free (path);
4551 gtk_tooltip_set_markup (tooltip, str);
4552 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4554 gtk_tree_path_free (path);
4562 * gtk_icon_view_set_tooltip_column:
4563 * @icon_view: a #GtkIconView
4564 * @column: an integer, which is a valid column number for @icon_view's model
4566 * If you only plan to have simple (text-only) tooltips on full items, you
4567 * can use this function to have #GtkIconView handle these automatically
4568 * for you. @column should be set to the column in @icon_view's model
4569 * containing the tooltip texts, or -1 to disable this feature.
4571 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4572 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4574 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4575 * so &, <, etc have to be escaped in the text.
4580 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4583 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4585 if (column == icon_view->priv->tooltip_column)
4590 g_signal_handlers_disconnect_by_func (icon_view,
4591 gtk_icon_view_set_tooltip_query_cb,
4593 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4597 if (icon_view->priv->tooltip_column == -1)
4599 g_signal_connect (icon_view, "query-tooltip",
4600 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4601 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4605 icon_view->priv->tooltip_column = column;
4606 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4610 * gtk_icon_view_get_tooltip_column:
4611 * @icon_view: a #GtkIconView
4613 * Returns the column of @icon_view's model which is being used for
4614 * displaying tooltips on @icon_view's rows.
4616 * Return value: the index of the tooltip column that is currently being
4617 * used, or -1 if this is disabled.
4622 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4624 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4626 return icon_view->priv->tooltip_column;
4630 * gtk_icon_view_get_visible_range:
4631 * @icon_view: A #GtkIconView
4632 * @start_path: (out) (allow-none): Return location for start of region,
4634 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4636 * Sets @start_path and @end_path to be the first and last visible path.
4637 * Note that there may be invisible paths in between.
4639 * Both paths should be freed with gtk_tree_path_free() after use.
4641 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4646 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4647 GtkTreePath **start_path,
4648 GtkTreePath **end_path)
4650 gint start_index = -1;
4651 gint end_index = -1;
4654 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4656 if (icon_view->priv->hadjustment == NULL ||
4657 icon_view->priv->vadjustment == NULL)
4660 if (start_path == NULL && end_path == NULL)
4663 for (icons = icon_view->priv->items; icons; icons = icons->next)
4665 GtkIconViewItem *item = icons->data;
4666 GdkRectangle *item_area = (GdkRectangle *)item;
4668 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4669 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4671 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4672 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4674 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4675 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4677 if (start_index == -1)
4678 start_index = item->index;
4679 end_index = item->index;
4683 if (start_path && start_index != -1)
4684 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4685 if (end_path && end_index != -1)
4686 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4688 return start_index != -1;
4692 * gtk_icon_view_selected_foreach:
4693 * @icon_view: A #GtkIconView.
4694 * @func: (scope call): The function to call for each selected icon.
4695 * @data: User data to pass to the function.
4697 * Calls a function for each selected icon. Note that the model or
4698 * selection cannot be modified from within this function.
4703 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4704 GtkIconViewForeachFunc func,
4709 for (list = icon_view->priv->items; list; list = list->next)
4711 GtkIconViewItem *item = list->data;
4712 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4715 (* func) (icon_view, path, data);
4717 gtk_tree_path_free (path);
4722 * gtk_icon_view_set_selection_mode:
4723 * @icon_view: A #GtkIconView.
4724 * @mode: The selection mode
4726 * Sets the selection mode of the @icon_view.
4731 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4732 GtkSelectionMode mode)
4734 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4736 if (mode == icon_view->priv->selection_mode)
4739 if (mode == GTK_SELECTION_NONE ||
4740 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4741 gtk_icon_view_unselect_all (icon_view);
4743 icon_view->priv->selection_mode = mode;
4745 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4749 * gtk_icon_view_get_selection_mode:
4750 * @icon_view: A #GtkIconView.
4752 * Gets the selection mode of the @icon_view.
4754 * Return value: the current selection mode
4759 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4761 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4763 return icon_view->priv->selection_mode;
4767 * gtk_icon_view_set_model:
4768 * @icon_view: A #GtkIconView.
4769 * @model: (allow-none): The model.
4771 * Sets the model for a #GtkIconView.
4772 * If the @icon_view already has a model set, it will remove
4773 * it before setting the new model. If @model is %NULL, then
4774 * it will unset the old model.
4779 gtk_icon_view_set_model (GtkIconView *icon_view,
4780 GtkTreeModel *model)
4782 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4783 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4785 if (icon_view->priv->model == model)
4788 if (icon_view->priv->scroll_to_path)
4790 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4791 icon_view->priv->scroll_to_path = NULL;
4794 /* The area can be NULL while disposing */
4795 if (icon_view->priv->cell_area)
4796 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4802 if (icon_view->priv->pixbuf_column != -1)
4804 column_type = gtk_tree_model_get_column_type (model,
4805 icon_view->priv->pixbuf_column);
4807 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4810 if (icon_view->priv->text_column != -1)
4812 column_type = gtk_tree_model_get_column_type (model,
4813 icon_view->priv->text_column);
4815 g_return_if_fail (column_type == G_TYPE_STRING);
4818 if (icon_view->priv->markup_column != -1)
4820 column_type = gtk_tree_model_get_column_type (model,
4821 icon_view->priv->markup_column);
4823 g_return_if_fail (column_type == G_TYPE_STRING);
4828 if (icon_view->priv->model)
4830 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4831 gtk_icon_view_row_changed,
4833 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4834 gtk_icon_view_row_inserted,
4836 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4837 gtk_icon_view_row_deleted,
4839 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4840 gtk_icon_view_rows_reordered,
4843 g_object_unref (icon_view->priv->model);
4845 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4846 g_list_free (icon_view->priv->items);
4847 icon_view->priv->items = NULL;
4848 icon_view->priv->anchor_item = NULL;
4849 icon_view->priv->cursor_item = NULL;
4850 icon_view->priv->last_single_clicked = NULL;
4851 icon_view->priv->width = 0;
4852 icon_view->priv->height = 0;
4855 icon_view->priv->model = model;
4857 if (icon_view->priv->model)
4859 g_object_ref (icon_view->priv->model);
4860 g_signal_connect (icon_view->priv->model,
4862 G_CALLBACK (gtk_icon_view_row_changed),
4864 g_signal_connect (icon_view->priv->model,
4866 G_CALLBACK (gtk_icon_view_row_inserted),
4868 g_signal_connect (icon_view->priv->model,
4870 G_CALLBACK (gtk_icon_view_row_deleted),
4872 g_signal_connect (icon_view->priv->model,
4874 G_CALLBACK (gtk_icon_view_rows_reordered),
4877 gtk_icon_view_build_items (icon_view);
4879 gtk_icon_view_queue_layout (icon_view);
4882 g_object_notify (G_OBJECT (icon_view), "model");
4884 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4885 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4889 * gtk_icon_view_get_model:
4890 * @icon_view: a #GtkIconView
4892 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4895 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4896 * currently being used.
4901 gtk_icon_view_get_model (GtkIconView *icon_view)
4903 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4905 return icon_view->priv->model;
4909 update_text_cell (GtkIconView *icon_view)
4911 if (!icon_view->priv->cell_area)
4914 if (icon_view->priv->text_column == -1 &&
4915 icon_view->priv->markup_column == -1)
4917 if (icon_view->priv->text_cell != NULL)
4919 gtk_cell_area_remove (icon_view->priv->cell_area,
4920 icon_view->priv->text_cell);
4921 icon_view->priv->text_cell = NULL;
4926 if (icon_view->priv->text_cell == NULL)
4928 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4930 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4933 if (icon_view->priv->markup_column != -1)
4934 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4935 icon_view->priv->text_cell,
4936 "markup", icon_view->priv->markup_column,
4939 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4940 icon_view->priv->text_cell,
4941 "text", icon_view->priv->text_column,
4944 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4945 g_object_set (icon_view->priv->text_cell,
4946 "alignment", PANGO_ALIGN_CENTER,
4947 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4952 g_object_set (icon_view->priv->text_cell,
4953 "alignment", PANGO_ALIGN_LEFT,
4954 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4962 update_pixbuf_cell (GtkIconView *icon_view)
4964 if (!icon_view->priv->cell_area)
4967 if (icon_view->priv->pixbuf_column == -1)
4969 if (icon_view->priv->pixbuf_cell != NULL)
4971 gtk_cell_area_remove (icon_view->priv->cell_area,
4972 icon_view->priv->pixbuf_cell);
4974 icon_view->priv->pixbuf_cell = NULL;
4979 if (icon_view->priv->pixbuf_cell == NULL)
4981 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4983 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4986 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4987 icon_view->priv->pixbuf_cell,
4988 "pixbuf", icon_view->priv->pixbuf_column,
4991 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4992 g_object_set (icon_view->priv->pixbuf_cell,
4997 g_object_set (icon_view->priv->pixbuf_cell,
5005 * gtk_icon_view_set_text_column:
5006 * @icon_view: A #GtkIconView.
5007 * @column: A column in the currently used model, or -1 to display no text
5009 * Sets the column with text for @icon_view to be @column. The text
5010 * column must be of type #G_TYPE_STRING.
5015 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5018 if (column == icon_view->priv->text_column)
5022 icon_view->priv->text_column = -1;
5025 if (icon_view->priv->model != NULL)
5029 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5031 g_return_if_fail (column_type == G_TYPE_STRING);
5034 icon_view->priv->text_column = column;
5037 if (icon_view->priv->cell_area)
5038 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5040 update_text_cell (icon_view);
5042 gtk_icon_view_invalidate_sizes (icon_view);
5044 g_object_notify (G_OBJECT (icon_view), "text-column");
5048 * gtk_icon_view_get_text_column:
5049 * @icon_view: A #GtkIconView.
5051 * Returns the column with text for @icon_view.
5053 * Returns: the text column, or -1 if it's unset.
5058 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5060 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5062 return icon_view->priv->text_column;
5066 * gtk_icon_view_set_markup_column:
5067 * @icon_view: A #GtkIconView.
5068 * @column: A column in the currently used model, or -1 to display no text
5070 * Sets the column with markup information for @icon_view to be
5071 * @column. The markup column must be of type #G_TYPE_STRING.
5072 * If the markup column is set to something, it overrides
5073 * the text column set by gtk_icon_view_set_text_column().
5078 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5081 if (column == icon_view->priv->markup_column)
5085 icon_view->priv->markup_column = -1;
5088 if (icon_view->priv->model != NULL)
5092 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5094 g_return_if_fail (column_type == G_TYPE_STRING);
5097 icon_view->priv->markup_column = column;
5100 if (icon_view->priv->cell_area)
5101 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5103 update_text_cell (icon_view);
5105 gtk_icon_view_invalidate_sizes (icon_view);
5107 g_object_notify (G_OBJECT (icon_view), "markup-column");
5111 * gtk_icon_view_get_markup_column:
5112 * @icon_view: A #GtkIconView.
5114 * Returns the column with markup text for @icon_view.
5116 * Returns: the markup column, or -1 if it's unset.
5121 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5123 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5125 return icon_view->priv->markup_column;
5129 * gtk_icon_view_set_pixbuf_column:
5130 * @icon_view: A #GtkIconView.
5131 * @column: A column in the currently used model, or -1 to disable
5133 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5134 * column must be of type #GDK_TYPE_PIXBUF
5139 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5142 if (column == icon_view->priv->pixbuf_column)
5146 icon_view->priv->pixbuf_column = -1;
5149 if (icon_view->priv->model != NULL)
5153 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5155 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5158 icon_view->priv->pixbuf_column = column;
5161 if (icon_view->priv->cell_area)
5162 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5164 update_pixbuf_cell (icon_view);
5166 gtk_icon_view_invalidate_sizes (icon_view);
5168 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5173 * gtk_icon_view_get_pixbuf_column:
5174 * @icon_view: A #GtkIconView.
5176 * Returns the column with pixbufs for @icon_view.
5178 * Returns: the pixbuf column, or -1 if it's unset.
5183 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5185 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5187 return icon_view->priv->pixbuf_column;
5191 * gtk_icon_view_select_path:
5192 * @icon_view: A #GtkIconView.
5193 * @path: The #GtkTreePath to be selected.
5195 * Selects the row at @path.
5200 gtk_icon_view_select_path (GtkIconView *icon_view,
5203 GtkIconViewItem *item = NULL;
5205 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5206 g_return_if_fail (icon_view->priv->model != NULL);
5207 g_return_if_fail (path != NULL);
5209 if (gtk_tree_path_get_depth (path) > 0)
5210 item = g_list_nth_data (icon_view->priv->items,
5211 gtk_tree_path_get_indices(path)[0]);
5214 gtk_icon_view_select_item (icon_view, item);
5218 * gtk_icon_view_unselect_path:
5219 * @icon_view: A #GtkIconView.
5220 * @path: The #GtkTreePath to be unselected.
5222 * Unselects the row at @path.
5227 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5230 GtkIconViewItem *item;
5232 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5233 g_return_if_fail (icon_view->priv->model != NULL);
5234 g_return_if_fail (path != NULL);
5236 item = g_list_nth_data (icon_view->priv->items,
5237 gtk_tree_path_get_indices(path)[0]);
5242 gtk_icon_view_unselect_item (icon_view, item);
5246 * gtk_icon_view_get_selected_items:
5247 * @icon_view: A #GtkIconView.
5249 * Creates a list of paths of all selected items. Additionally, if you are
5250 * planning on modifying the model after calling this function, you may
5251 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5252 * To do this, you can use gtk_tree_row_reference_new().
5254 * To free the return value, use:
5256 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5257 * g_list_free (list);
5260 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5265 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5268 GList *selected = NULL;
5270 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5272 for (list = icon_view->priv->items; list != NULL; list = list->next)
5274 GtkIconViewItem *item = list->data;
5278 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5280 selected = g_list_prepend (selected, path);
5288 * gtk_icon_view_select_all:
5289 * @icon_view: A #GtkIconView.
5291 * Selects all the icons. @icon_view must has its selection mode set
5292 * to #GTK_SELECTION_MULTIPLE.
5297 gtk_icon_view_select_all (GtkIconView *icon_view)
5300 gboolean dirty = FALSE;
5302 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5304 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5307 for (items = icon_view->priv->items; items; items = items->next)
5309 GtkIconViewItem *item = items->data;
5311 if (!item->selected)
5314 item->selected = TRUE;
5315 gtk_icon_view_queue_draw_item (icon_view, item);
5320 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5324 * gtk_icon_view_unselect_all:
5325 * @icon_view: A #GtkIconView.
5327 * Unselects all the icons.
5332 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5334 gboolean dirty = FALSE;
5336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5338 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5341 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5344 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5348 * gtk_icon_view_path_is_selected:
5349 * @icon_view: A #GtkIconView.
5350 * @path: A #GtkTreePath to check selection on.
5352 * Returns %TRUE if the icon pointed to by @path is currently
5353 * selected. If @path does not point to a valid location, %FALSE is returned.
5355 * Return value: %TRUE if @path is selected.
5360 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5363 GtkIconViewItem *item;
5365 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5366 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5367 g_return_val_if_fail (path != NULL, FALSE);
5369 item = g_list_nth_data (icon_view->priv->items,
5370 gtk_tree_path_get_indices(path)[0]);
5375 return item->selected;
5379 * gtk_icon_view_get_item_row:
5380 * @icon_view: a #GtkIconView
5381 * @path: the #GtkTreePath of the item
5383 * Gets the row in which the item @path is currently
5384 * displayed. Row numbers start at 0.
5386 * Returns: The row in which the item is displayed
5391 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5394 GtkIconViewItem *item;
5396 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5397 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5398 g_return_val_if_fail (path != NULL, -1);
5400 item = g_list_nth_data (icon_view->priv->items,
5401 gtk_tree_path_get_indices(path)[0]);
5410 * gtk_icon_view_get_item_column:
5411 * @icon_view: a #GtkIconView
5412 * @path: the #GtkTreePath of the item
5414 * Gets the column in which the item @path is currently
5415 * displayed. Column numbers start at 0.
5417 * Returns: The column in which the item is displayed
5422 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5425 GtkIconViewItem *item;
5427 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5428 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5429 g_return_val_if_fail (path != NULL, -1);
5431 item = g_list_nth_data (icon_view->priv->items,
5432 gtk_tree_path_get_indices(path)[0]);
5441 * gtk_icon_view_item_activated:
5442 * @icon_view: A #GtkIconView
5443 * @path: The #GtkTreePath to be activated
5445 * Activates the item determined by @path.
5450 gtk_icon_view_item_activated (GtkIconView *icon_view,
5453 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5454 g_return_if_fail (path != NULL);
5456 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5460 * gtk_icon_view_set_item_orientation:
5461 * @icon_view: a #GtkIconView
5462 * @orientation: the relative position of texts and icons
5464 * Sets the ::item-orientation property which determines whether the labels
5465 * are drawn beside the icons instead of below.
5470 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5471 GtkOrientation orientation)
5473 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5475 if (icon_view->priv->item_orientation != orientation)
5477 icon_view->priv->item_orientation = orientation;
5479 if (icon_view->priv->cell_area)
5481 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5482 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5483 icon_view->priv->item_orientation);
5485 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5488 gtk_icon_view_invalidate_sizes (icon_view);
5490 update_text_cell (icon_view);
5491 update_pixbuf_cell (icon_view);
5493 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5498 * gtk_icon_view_get_item_orientation:
5499 * @icon_view: a #GtkIconView
5501 * Returns the value of the ::item-orientation property which determines
5502 * whether the labels are drawn beside the icons instead of below.
5504 * Return value: the relative position of texts and icons
5509 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5511 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5512 GTK_ORIENTATION_VERTICAL);
5514 return icon_view->priv->item_orientation;
5518 * gtk_icon_view_set_columns:
5519 * @icon_view: a #GtkIconView
5520 * @columns: the number of columns
5522 * Sets the ::columns property which determines in how
5523 * many columns the icons are arranged. If @columns is
5524 * -1, the number of columns will be chosen automatically
5525 * to fill the available area.
5530 gtk_icon_view_set_columns (GtkIconView *icon_view,
5533 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5535 if (icon_view->priv->columns != columns)
5537 icon_view->priv->columns = columns;
5539 if (icon_view->priv->cell_area)
5540 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5542 gtk_icon_view_queue_layout (icon_view);
5544 g_object_notify (G_OBJECT (icon_view), "columns");
5549 * gtk_icon_view_get_columns:
5550 * @icon_view: a #GtkIconView
5552 * Returns the value of the ::columns property.
5554 * Return value: the number of columns, or -1
5559 gtk_icon_view_get_columns (GtkIconView *icon_view)
5561 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5563 return icon_view->priv->columns;
5567 * gtk_icon_view_set_item_width:
5568 * @icon_view: a #GtkIconView
5569 * @item_width: the width for each item
5571 * Sets the ::item-width property which specifies the width
5572 * to use for each item. If it is set to -1, the icon view will
5573 * automatically determine a suitable item size.
5578 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5581 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5583 if (icon_view->priv->item_width != item_width)
5585 icon_view->priv->item_width = item_width;
5587 if (icon_view->priv->cell_area)
5588 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5590 gtk_icon_view_invalidate_sizes (icon_view);
5592 update_text_cell (icon_view);
5594 g_object_notify (G_OBJECT (icon_view), "item-width");
5599 * gtk_icon_view_get_item_width:
5600 * @icon_view: a #GtkIconView
5602 * Returns the value of the ::item-width property.
5604 * Return value: the width of a single item, or -1
5609 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5611 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5613 return icon_view->priv->item_width;
5618 * gtk_icon_view_set_spacing:
5619 * @icon_view: a #GtkIconView
5620 * @spacing: the spacing
5622 * Sets the ::spacing property which specifies the space
5623 * which is inserted between the cells (i.e. the icon and
5624 * the text) of an item.
5629 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5632 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5634 if (icon_view->priv->spacing != spacing)
5636 icon_view->priv->spacing = spacing;
5638 if (icon_view->priv->cell_area)
5639 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5641 gtk_icon_view_invalidate_sizes (icon_view);
5643 g_object_notify (G_OBJECT (icon_view), "spacing");
5648 * gtk_icon_view_get_spacing:
5649 * @icon_view: a #GtkIconView
5651 * Returns the value of the ::spacing property.
5653 * Return value: the space between cells
5658 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5660 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5662 return icon_view->priv->spacing;
5666 * gtk_icon_view_set_row_spacing:
5667 * @icon_view: a #GtkIconView
5668 * @row_spacing: the row spacing
5670 * Sets the ::row-spacing property which specifies the space
5671 * which is inserted between the rows of the icon view.
5676 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5681 if (icon_view->priv->row_spacing != row_spacing)
5683 icon_view->priv->row_spacing = row_spacing;
5685 if (icon_view->priv->cell_area)
5686 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5688 gtk_icon_view_invalidate_sizes (icon_view);
5690 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5695 * gtk_icon_view_get_row_spacing:
5696 * @icon_view: a #GtkIconView
5698 * Returns the value of the ::row-spacing property.
5700 * Return value: the space between rows
5705 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5707 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5709 return icon_view->priv->row_spacing;
5713 * gtk_icon_view_set_column_spacing:
5714 * @icon_view: a #GtkIconView
5715 * @column_spacing: the column spacing
5717 * Sets the ::column-spacing property which specifies the space
5718 * which is inserted between the columns of the icon view.
5723 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5724 gint column_spacing)
5726 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5728 if (icon_view->priv->column_spacing != column_spacing)
5730 icon_view->priv->column_spacing = column_spacing;
5732 if (icon_view->priv->cell_area)
5733 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5735 gtk_icon_view_invalidate_sizes (icon_view);
5737 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5742 * gtk_icon_view_get_column_spacing:
5743 * @icon_view: a #GtkIconView
5745 * Returns the value of the ::column-spacing property.
5747 * Return value: the space between columns
5752 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5754 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5756 return icon_view->priv->column_spacing;
5760 * gtk_icon_view_set_margin:
5761 * @icon_view: a #GtkIconView
5762 * @margin: the margin
5764 * Sets the ::margin property which specifies the space
5765 * which is inserted at the top, bottom, left and right
5771 gtk_icon_view_set_margin (GtkIconView *icon_view,
5774 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5776 if (icon_view->priv->margin != margin)
5778 icon_view->priv->margin = margin;
5780 if (icon_view->priv->cell_area)
5781 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5783 gtk_icon_view_invalidate_sizes (icon_view);
5785 g_object_notify (G_OBJECT (icon_view), "margin");
5790 * gtk_icon_view_get_margin:
5791 * @icon_view: a #GtkIconView
5793 * Returns the value of the ::margin property.
5795 * Return value: the space at the borders
5800 gtk_icon_view_get_margin (GtkIconView *icon_view)
5802 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5804 return icon_view->priv->margin;
5808 * gtk_icon_view_set_item_padding:
5809 * @icon_view: a #GtkIconView
5810 * @item_padding: the item padding
5812 * Sets the #GtkIconView:item-padding property which specifies the padding
5813 * around each of the icon view's items.
5818 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5821 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5823 if (icon_view->priv->item_padding != item_padding)
5825 icon_view->priv->item_padding = item_padding;
5827 if (icon_view->priv->cell_area)
5828 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5830 gtk_icon_view_invalidate_sizes (icon_view);
5832 g_object_notify (G_OBJECT (icon_view), "item-padding");
5837 * gtk_icon_view_get_item_padding:
5838 * @icon_view: a #GtkIconView
5840 * Returns the value of the ::item-padding property.
5842 * Return value: the padding around items
5847 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5851 return icon_view->priv->item_padding;
5854 /* Get/set whether drag_motion requested the drag data and
5855 * drag_data_received should thus not actually insert the data,
5856 * since the data doesn't result from a drop.
5859 set_status_pending (GdkDragContext *context,
5860 GdkDragAction suggested_action)
5862 g_object_set_data (G_OBJECT (context),
5863 I_("gtk-icon-view-status-pending"),
5864 GINT_TO_POINTER (suggested_action));
5867 static GdkDragAction
5868 get_status_pending (GdkDragContext *context)
5870 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5871 "gtk-icon-view-status-pending"));
5875 unset_reorderable (GtkIconView *icon_view)
5877 if (icon_view->priv->reorderable)
5879 icon_view->priv->reorderable = FALSE;
5880 g_object_notify (G_OBJECT (icon_view), "reorderable");
5885 set_source_row (GdkDragContext *context,
5886 GtkTreeModel *model,
5887 GtkTreePath *source_row)
5890 g_object_set_data_full (G_OBJECT (context),
5891 I_("gtk-icon-view-source-row"),
5892 gtk_tree_row_reference_new (model, source_row),
5893 (GDestroyNotify) gtk_tree_row_reference_free);
5895 g_object_set_data_full (G_OBJECT (context),
5896 I_("gtk-icon-view-source-row"),
5901 get_source_row (GdkDragContext *context)
5903 GtkTreeRowReference *ref;
5905 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5908 return gtk_tree_row_reference_get_path (ref);
5915 GtkTreeRowReference *dest_row;
5916 gboolean empty_view_drop;
5917 gboolean drop_append_mode;
5921 dest_row_free (gpointer data)
5923 DestRow *dr = (DestRow *)data;
5925 gtk_tree_row_reference_free (dr->dest_row);
5930 set_dest_row (GdkDragContext *context,
5931 GtkTreeModel *model,
5932 GtkTreePath *dest_row,
5933 gboolean empty_view_drop,
5934 gboolean drop_append_mode)
5940 g_object_set_data_full (G_OBJECT (context),
5941 I_("gtk-icon-view-dest-row"),
5946 dr = g_new0 (DestRow, 1);
5948 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5949 dr->empty_view_drop = empty_view_drop;
5950 dr->drop_append_mode = drop_append_mode;
5951 g_object_set_data_full (G_OBJECT (context),
5952 I_("gtk-icon-view-dest-row"),
5953 dr, (GDestroyNotify) dest_row_free);
5957 get_dest_row (GdkDragContext *context)
5961 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5965 GtkTreePath *path = NULL;
5968 path = gtk_tree_row_reference_get_path (dr->dest_row);
5969 else if (dr->empty_view_drop)
5970 path = gtk_tree_path_new_from_indices (0, -1);
5974 if (path && dr->drop_append_mode)
5975 gtk_tree_path_next (path);
5984 check_model_dnd (GtkTreeModel *model,
5985 GType required_iface,
5986 const gchar *signal)
5988 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5990 g_warning ("You must override the default '%s' handler "
5991 "on GtkIconView when using models that don't support "
5992 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5993 "is to connect to '%s' and call "
5994 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5995 "the default handler from running. Look at the source code "
5996 "for the default handler in gtkiconview.c to get an idea what "
5997 "your handler should do. (gtkiconview.c is in the GTK+ source "
5998 "code.) If you're using GTK+ from a language other than C, "
5999 "there may be a more natural way to override default handlers, e.g. via derivation.",
6000 signal, g_type_name (required_iface), signal);
6008 remove_scroll_timeout (GtkIconView *icon_view)
6010 if (icon_view->priv->scroll_timeout_id != 0)
6012 g_source_remove (icon_view->priv->scroll_timeout_id);
6014 icon_view->priv->scroll_timeout_id = 0;
6019 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6022 gint px, py, x, y, width, height;
6023 gint hoffset, voffset;
6025 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6027 gdk_window_get_pointer (window, &px, &py, NULL);
6028 gdk_window_get_geometry (window, &x, &y, &width, &height);
6030 /* see if we are near the edge. */
6031 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6033 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6035 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6037 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6040 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6041 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6044 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6045 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6050 drag_scroll_timeout (gpointer data)
6052 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6054 gtk_icon_view_autoscroll (icon_view);
6061 set_destination (GtkIconView *icon_view,
6062 GdkDragContext *context,
6065 GdkDragAction *suggested_action,
6069 GtkTreePath *path = NULL;
6070 GtkIconViewDropPosition pos;
6071 GtkIconViewDropPosition old_pos;
6072 GtkTreePath *old_dest_path = NULL;
6073 gboolean can_drop = FALSE;
6075 widget = GTK_WIDGET (icon_view);
6077 *suggested_action = 0;
6080 if (!icon_view->priv->dest_set)
6082 /* someone unset us as a drag dest, note that if
6083 * we return FALSE drag_leave isn't called
6086 gtk_icon_view_set_drag_dest_item (icon_view,
6088 GTK_ICON_VIEW_DROP_LEFT);
6090 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6092 return FALSE; /* no longer a drop site */
6095 *target = gtk_drag_dest_find_target (widget, context,
6096 gtk_drag_dest_get_target_list (widget));
6097 if (*target == GDK_NONE)
6100 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6103 GtkTreeModel *model;
6105 /* the row got dropped on empty space, let's setup a special case
6109 gtk_tree_path_free (path);
6111 model = gtk_icon_view_get_model (icon_view);
6113 n_children = gtk_tree_model_iter_n_children (model, NULL);
6116 pos = GTK_ICON_VIEW_DROP_BELOW;
6117 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6121 pos = GTK_ICON_VIEW_DROP_ABOVE;
6122 path = gtk_tree_path_new_from_indices (0, -1);
6132 gtk_icon_view_get_drag_dest_item (icon_view,
6137 gtk_tree_path_free (old_dest_path);
6139 if (TRUE /* FIXME if the location droppable predicate */)
6147 GtkWidget *source_widget;
6149 *suggested_action = gdk_drag_context_get_suggested_action (context);
6150 source_widget = gtk_drag_get_source_widget (context);
6152 if (source_widget == widget)
6154 /* Default to MOVE, unless the user has
6155 * pressed ctrl or shift to affect available actions
6157 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6158 *suggested_action = GDK_ACTION_MOVE;
6161 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6166 /* can't drop here */
6167 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6169 GTK_ICON_VIEW_DROP_LEFT);
6173 gtk_tree_path_free (path);
6179 get_logical_destination (GtkIconView *icon_view,
6180 gboolean *drop_append_mode)
6182 /* adjust path to point to the row the drop goes in front of */
6183 GtkTreePath *path = NULL;
6184 GtkIconViewDropPosition pos;
6186 *drop_append_mode = FALSE;
6188 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6193 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6194 pos == GTK_ICON_VIEW_DROP_BELOW)
6197 GtkTreeModel *model = icon_view->priv->model;
6199 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6200 !gtk_tree_model_iter_next (model, &iter))
6201 *drop_append_mode = TRUE;
6204 *drop_append_mode = FALSE;
6205 gtk_tree_path_next (path);
6213 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6214 GdkEventMotion *event)
6216 GtkWidget *widget = GTK_WIDGET (icon_view);
6217 GdkDragContext *context;
6218 GtkTreePath *path = NULL;
6220 GtkTreeModel *model;
6221 gboolean retval = FALSE;
6223 if (!icon_view->priv->source_set)
6226 if (icon_view->priv->pressed_button < 0)
6229 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6230 icon_view->priv->press_start_x,
6231 icon_view->priv->press_start_y,
6232 event->x, event->y))
6235 model = gtk_icon_view_get_model (icon_view);
6240 button = icon_view->priv->pressed_button;
6241 icon_view->priv->pressed_button = -1;
6243 path = gtk_icon_view_get_path_at_pos (icon_view,
6244 icon_view->priv->press_start_x,
6245 icon_view->priv->press_start_y);
6250 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6251 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6255 /* FIXME Check whether we're a start button, if not return FALSE and
6259 /* Now we can begin the drag */
6263 context = gtk_drag_begin (widget,
6264 gtk_drag_source_get_target_list (widget),
6265 icon_view->priv->source_actions,
6269 set_source_row (context, model, path);
6273 gtk_tree_path_free (path);
6278 /* Source side drag signals */
6280 gtk_icon_view_drag_begin (GtkWidget *widget,
6281 GdkDragContext *context)
6283 GtkIconView *icon_view;
6284 GtkIconViewItem *item;
6285 cairo_surface_t *icon;
6289 icon_view = GTK_ICON_VIEW (widget);
6291 /* if the user uses a custom DnD impl, we don't set the icon here */
6292 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6295 item = gtk_icon_view_get_item_at_coords (icon_view,
6296 icon_view->priv->press_start_x,
6297 icon_view->priv->press_start_y,
6301 g_return_if_fail (item != NULL);
6303 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6304 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6306 path = gtk_tree_path_new_from_indices (item->index, -1);
6307 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6308 gtk_tree_path_free (path);
6310 cairo_surface_set_device_offset (icon, -x, -y);
6312 gtk_drag_set_icon_surface (context, icon);
6314 cairo_surface_destroy (icon);
6318 gtk_icon_view_drag_end (GtkWidget *widget,
6319 GdkDragContext *context)
6325 gtk_icon_view_drag_data_get (GtkWidget *widget,
6326 GdkDragContext *context,
6327 GtkSelectionData *selection_data,
6331 GtkIconView *icon_view;
6332 GtkTreeModel *model;
6333 GtkTreePath *source_row;
6335 icon_view = GTK_ICON_VIEW (widget);
6336 model = gtk_icon_view_get_model (icon_view);
6341 if (!icon_view->priv->source_set)
6344 source_row = get_source_row (context);
6346 if (source_row == NULL)
6349 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6350 * any model; for DragSource models there are some other targets
6354 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6355 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6360 /* If drag_data_get does nothing, try providing row data. */
6361 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6362 gtk_tree_set_row_drag_data (selection_data,
6367 gtk_tree_path_free (source_row);
6371 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6372 GdkDragContext *context)
6374 GtkTreeModel *model;
6375 GtkIconView *icon_view;
6376 GtkTreePath *source_row;
6378 icon_view = GTK_ICON_VIEW (widget);
6379 model = gtk_icon_view_get_model (icon_view);
6381 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6384 if (!icon_view->priv->source_set)
6387 source_row = get_source_row (context);
6389 if (source_row == NULL)
6392 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6395 gtk_tree_path_free (source_row);
6397 set_source_row (context, NULL, NULL);
6400 /* Target side drag signals */
6402 gtk_icon_view_drag_leave (GtkWidget *widget,
6403 GdkDragContext *context,
6406 GtkIconView *icon_view;
6408 icon_view = GTK_ICON_VIEW (widget);
6410 /* unset any highlight row */
6411 gtk_icon_view_set_drag_dest_item (icon_view,
6413 GTK_ICON_VIEW_DROP_LEFT);
6415 remove_scroll_timeout (icon_view);
6419 gtk_icon_view_drag_motion (GtkWidget *widget,
6420 GdkDragContext *context,
6425 GtkTreePath *path = NULL;
6426 GtkIconViewDropPosition pos;
6427 GtkIconView *icon_view;
6428 GdkDragAction suggested_action = 0;
6432 icon_view = GTK_ICON_VIEW (widget);
6434 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6437 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6439 /* we only know this *after* set_desination_row */
6440 empty = icon_view->priv->empty_view_drop;
6442 if (path == NULL && !empty)
6444 /* Can't drop here. */
6445 gdk_drag_status (context, 0, time);
6449 if (icon_view->priv->scroll_timeout_id == 0)
6451 icon_view->priv->scroll_timeout_id =
6452 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6455 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6457 /* Request data so we can use the source row when
6458 * determining whether to accept the drop
6460 set_status_pending (context, suggested_action);
6461 gtk_drag_get_data (widget, context, target, time);
6465 set_status_pending (context, 0);
6466 gdk_drag_status (context, suggested_action, time);
6471 gtk_tree_path_free (path);
6477 gtk_icon_view_drag_drop (GtkWidget *widget,
6478 GdkDragContext *context,
6483 GtkIconView *icon_view;
6485 GdkDragAction suggested_action = 0;
6486 GdkAtom target = GDK_NONE;
6487 GtkTreeModel *model;
6488 gboolean drop_append_mode;
6490 icon_view = GTK_ICON_VIEW (widget);
6491 model = gtk_icon_view_get_model (icon_view);
6493 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6495 if (!icon_view->priv->dest_set)
6498 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6501 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6504 path = get_logical_destination (icon_view, &drop_append_mode);
6506 if (target != GDK_NONE && path != NULL)
6508 /* in case a motion had requested drag data, change things so we
6509 * treat drag data receives as a drop.
6511 set_status_pending (context, 0);
6512 set_dest_row (context, model, path,
6513 icon_view->priv->empty_view_drop, drop_append_mode);
6517 gtk_tree_path_free (path);
6519 /* Unset this thing */
6520 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6522 if (target != GDK_NONE)
6524 gtk_drag_get_data (widget, context, target, time);
6532 gtk_icon_view_drag_data_received (GtkWidget *widget,
6533 GdkDragContext *context,
6536 GtkSelectionData *selection_data,
6541 gboolean accepted = FALSE;
6542 GtkTreeModel *model;
6543 GtkIconView *icon_view;
6544 GtkTreePath *dest_row;
6545 GdkDragAction suggested_action;
6546 gboolean drop_append_mode;
6548 icon_view = GTK_ICON_VIEW (widget);
6549 model = gtk_icon_view_get_model (icon_view);
6551 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6554 if (!icon_view->priv->dest_set)
6557 suggested_action = get_status_pending (context);
6559 if (suggested_action)
6561 /* We are getting this data due to a request in drag_motion,
6562 * rather than due to a request in drag_drop, so we are just
6563 * supposed to call drag_status, not actually paste in the
6566 path = get_logical_destination (icon_view, &drop_append_mode);
6569 suggested_action = 0;
6571 if (suggested_action)
6573 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6576 suggested_action = 0;
6579 gdk_drag_status (context, suggested_action, time);
6582 gtk_tree_path_free (path);
6584 /* If you can't drop, remove user drop indicator until the next motion */
6585 if (suggested_action == 0)
6586 gtk_icon_view_set_drag_dest_item (icon_view,
6588 GTK_ICON_VIEW_DROP_LEFT);
6593 dest_row = get_dest_row (context);
6595 if (dest_row == NULL)
6598 if (gtk_selection_data_get_length (selection_data) >= 0)
6600 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6606 gtk_drag_finish (context,
6608 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6611 gtk_tree_path_free (dest_row);
6614 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6617 /* Drag-and-Drop support */
6619 * gtk_icon_view_enable_model_drag_source:
6620 * @icon_view: a #GtkIconTreeView
6621 * @start_button_mask: Mask of allowed buttons to start drag
6622 * @targets: (array length=n_targets): the table of targets that the drag will
6624 * @n_targets: the number of items in @targets
6625 * @actions: the bitmask of possible actions for a drag from this
6628 * Turns @icon_view into a drag source for automatic DND. Calling this
6629 * method sets #GtkIconView:reorderable to %FALSE.
6634 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6635 GdkModifierType start_button_mask,
6636 const GtkTargetEntry *targets,
6638 GdkDragAction actions)
6640 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6642 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6644 icon_view->priv->start_button_mask = start_button_mask;
6645 icon_view->priv->source_actions = actions;
6647 icon_view->priv->source_set = TRUE;
6649 unset_reorderable (icon_view);
6653 * gtk_icon_view_enable_model_drag_dest:
6654 * @icon_view: a #GtkIconView
6655 * @targets: (array length=n_targets): the table of targets that the drag will
6657 * @n_targets: the number of items in @targets
6658 * @actions: the bitmask of possible actions for a drag to this
6661 * Turns @icon_view into a drop destination for automatic DND. Calling this
6662 * method sets #GtkIconView:reorderable to %FALSE.
6667 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6668 const GtkTargetEntry *targets,
6670 GdkDragAction actions)
6672 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6674 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6676 icon_view->priv->dest_actions = actions;
6678 icon_view->priv->dest_set = TRUE;
6680 unset_reorderable (icon_view);
6684 * gtk_icon_view_unset_model_drag_source:
6685 * @icon_view: a #GtkIconView
6687 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6688 * method sets #GtkIconView:reorderable to %FALSE.
6693 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6695 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6697 if (icon_view->priv->source_set)
6699 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6700 icon_view->priv->source_set = FALSE;
6703 unset_reorderable (icon_view);
6707 * gtk_icon_view_unset_model_drag_dest:
6708 * @icon_view: a #GtkIconView
6710 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6711 * method sets #GtkIconView:reorderable to %FALSE.
6716 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6718 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6720 if (icon_view->priv->dest_set)
6722 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6723 icon_view->priv->dest_set = FALSE;
6726 unset_reorderable (icon_view);
6729 /* These are useful to implement your own custom stuff. */
6731 * gtk_icon_view_set_drag_dest_item:
6732 * @icon_view: a #GtkIconView
6733 * @path: (allow-none): The path of the item to highlight, or %NULL.
6734 * @pos: Specifies where to drop, relative to the item
6736 * Sets the item that is highlighted for feedback.
6741 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6743 GtkIconViewDropPosition pos)
6745 /* Note; this function is exported to allow a custom DND
6746 * implementation, so it can't touch TreeViewDragInfo
6749 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6751 if (icon_view->priv->dest_item)
6753 GtkTreePath *current_path;
6754 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6755 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6756 icon_view->priv->dest_item = NULL;
6758 gtk_icon_view_queue_draw_path (icon_view, current_path);
6759 gtk_tree_path_free (current_path);
6762 /* special case a drop on an empty model */
6763 icon_view->priv->empty_view_drop = FALSE;
6764 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6765 && gtk_tree_path_get_depth (path) == 1
6766 && gtk_tree_path_get_indices (path)[0] == 0)
6770 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6773 if (n_children == 0)
6774 icon_view->priv->empty_view_drop = TRUE;
6777 icon_view->priv->dest_pos = pos;
6781 icon_view->priv->dest_item =
6782 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6783 icon_view->priv->model, path);
6785 gtk_icon_view_queue_draw_path (icon_view, path);
6790 * gtk_icon_view_get_drag_dest_item:
6791 * @icon_view: a #GtkIconView
6792 * @path: (out) (allow-none): Return location for the path of
6793 * the highlighted item, or %NULL.
6794 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6796 * Gets information about the item that is highlighted for feedback.
6801 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6803 GtkIconViewDropPosition *pos)
6805 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6809 if (icon_view->priv->dest_item)
6810 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6816 *pos = icon_view->priv->dest_pos;
6820 * gtk_icon_view_get_dest_item_at_pos:
6821 * @icon_view: a #GtkIconView
6822 * @drag_x: the position to determine the destination item for
6823 * @drag_y: the position to determine the destination item for
6824 * @path: (out) (allow-none): Return location for the path of the item,
6826 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6828 * Determines the destination item for a given position.
6830 * Return value: whether there is an item at the given position.
6835 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6839 GtkIconViewDropPosition *pos)
6841 GtkIconViewItem *item;
6843 /* Note; this function is exported to allow a custom DND
6844 * implementation, so it can't touch TreeViewDragInfo
6847 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6848 g_return_val_if_fail (drag_x >= 0, FALSE);
6849 g_return_val_if_fail (drag_y >= 0, FALSE);
6850 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6856 item = gtk_icon_view_get_item_at_coords (icon_view,
6857 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6858 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6865 *path = gtk_tree_path_new_from_indices (item->index, -1);
6869 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6870 *pos = GTK_ICON_VIEW_DROP_LEFT;
6871 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6872 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6873 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6874 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6875 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6876 *pos = GTK_ICON_VIEW_DROP_BELOW;
6878 *pos = GTK_ICON_VIEW_DROP_INTO;
6885 * gtk_icon_view_create_drag_icon:
6886 * @icon_view: a #GtkIconView
6887 * @path: a #GtkTreePath in @icon_view
6889 * Creates a #cairo_surface_t representation of the item at @path.
6890 * This image is used for a drag icon.
6892 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6897 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6901 GtkStyleContext *context;
6903 cairo_surface_t *surface;
6907 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6908 g_return_val_if_fail (path != NULL, NULL);
6910 widget = GTK_WIDGET (icon_view);
6911 context = gtk_widget_get_style_context (widget);
6913 if (!gtk_widget_get_realized (widget))
6916 index = gtk_tree_path_get_indices (path)[0];
6918 for (l = icon_view->priv->items; l; l = l->next)
6920 GtkIconViewItem *item = l->data;
6922 if (index == item->index)
6924 GdkRectangle rect = {
6925 item->cell_area.x - icon_view->priv->item_padding,
6926 item->cell_area.y - icon_view->priv->item_padding,
6927 item->cell_area.width + icon_view->priv->item_padding * 2,
6928 item->cell_area.height + icon_view->priv->item_padding * 2
6931 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6932 CAIRO_CONTENT_COLOR,
6936 cr = cairo_create (surface);
6937 cairo_set_line_width (cr, 1.);
6939 gtk_render_background (context, cr, 0, 0,
6940 rect.width + 2, rect.height + 2);
6944 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6947 gtk_icon_view_paint_item (icon_view, cr, item,
6948 icon_view->priv->item_padding + 1,
6949 icon_view->priv->item_padding + 1, FALSE);
6953 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6954 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6967 * gtk_icon_view_get_reorderable:
6968 * @icon_view: a #GtkIconView
6970 * Retrieves whether the user can reorder the list via drag-and-drop.
6971 * See gtk_icon_view_set_reorderable().
6973 * Return value: %TRUE if the list can be reordered.
6978 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6980 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6982 return icon_view->priv->reorderable;
6985 static const GtkTargetEntry item_targets[] = {
6986 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6991 * gtk_icon_view_set_reorderable:
6992 * @icon_view: A #GtkIconView.
6993 * @reorderable: %TRUE, if the list of items can be reordered.
6995 * This function is a convenience function to allow you to reorder models that
6996 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6997 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6998 * the user can reorder the model by dragging and dropping rows. The
6999 * developer can listen to these changes by connecting to the model's
7000 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7001 * the icon view as a drag source and destination. Therefore, drag and
7002 * drop can not be used in a reorderable view for any other purpose.
7004 * This function does not give you any degree of control over the order -- any
7005 * reordering is allowed. If more control is needed, you should probably
7006 * handle drag and drop manually.
7011 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7012 gboolean reorderable)
7014 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7016 reorderable = reorderable != FALSE;
7018 if (icon_view->priv->reorderable == reorderable)
7023 gtk_icon_view_enable_model_drag_source (icon_view,
7026 G_N_ELEMENTS (item_targets),
7028 gtk_icon_view_enable_model_drag_dest (icon_view,
7030 G_N_ELEMENTS (item_targets),
7035 gtk_icon_view_unset_model_drag_source (icon_view);
7036 gtk_icon_view_unset_model_drag_dest (icon_view);
7039 icon_view->priv->reorderable = reorderable;
7041 g_object_notify (G_OBJECT (icon_view), "reorderable");
7045 /* Accessibility Support */
7047 static gpointer accessible_parent_class;
7048 static gpointer accessible_item_parent_class;
7049 static GQuark accessible_private_data_quark = 0;
7051 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7052 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7053 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7055 static GType gtk_icon_view_item_accessible_get_type (void);
7066 GtkIconViewItem *item;
7070 AtkStateSet *state_set;
7074 GtkTextBuffer *text_buffer;
7076 gchar *action_descriptions[LAST_ACTION];
7077 gchar *image_description;
7078 guint action_idle_handler;
7079 } GtkIconViewItemAccessible;
7081 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7087 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7092 typedef struct _GtkIconViewItemAccessibleClass
7094 AtkObjectClass parent_class;
7096 } GtkIconViewItemAccessibleClass;
7098 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7101 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7103 GtkIconViewItemAccessible *item;
7104 GtkIconView *icon_view;
7107 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7108 item->action_idle_handler = 0;
7110 if (item->widget != NULL)
7112 icon_view = GTK_ICON_VIEW (item->widget);
7113 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7114 gtk_icon_view_item_activated (icon_view, path);
7115 gtk_tree_path_free (path);
7122 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7125 GtkIconViewItemAccessible *item;
7127 if (i < 0 || i >= LAST_ACTION)
7130 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7132 if (!GTK_IS_ICON_VIEW (item->widget))
7135 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7140 case ACTION_ACTIVATE:
7141 if (!item->action_idle_handler)
7142 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7145 g_assert_not_reached ();
7153 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7158 static const gchar *
7159 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7162 GtkIconViewItemAccessible *item;
7164 if (i < 0 || i >= LAST_ACTION)
7167 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7169 if (item->action_descriptions[i])
7170 return item->action_descriptions[i];
7172 return gtk_icon_view_item_accessible_action_descriptions[i];
7175 static const gchar *
7176 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7179 if (i < 0 || i >= LAST_ACTION)
7182 return gtk_icon_view_item_accessible_action_names[i];
7186 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7188 const gchar *description)
7190 GtkIconViewItemAccessible *item;
7192 if (i < 0 || i >= LAST_ACTION)
7195 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7197 g_free (item->action_descriptions[i]);
7199 item->action_descriptions[i] = g_strdup (description);
7205 atk_action_item_interface_init (AtkActionIface *iface)
7207 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7208 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7209 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7210 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7211 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7214 static const gchar *
7215 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7217 GtkIconViewItemAccessible *item;
7219 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7221 return item->image_description;
7225 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7226 const gchar *description)
7228 GtkIconViewItemAccessible *item;
7230 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7232 g_free (item->image_description);
7233 item->image_description = g_strdup (description);
7240 gboolean pixbuf_found;
7244 get_pixbuf_foreach (GtkCellRenderer *renderer,
7245 const GdkRectangle *cell_area,
7246 const GdkRectangle *cell_background,
7247 GetPixbufBoxData *data)
7249 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7251 data->box = *cell_area;
7252 data->pixbuf_found = TRUE;
7254 return (data->pixbuf_found != FALSE);
7258 get_pixbuf_box (GtkIconView *icon_view,
7259 GtkIconViewItem *item,
7262 GetPixbufBoxData data = { { 0, }, FALSE };
7263 GtkCellAreaContext *context;
7265 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7267 gtk_icon_view_set_cell_data (icon_view, item);
7268 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7269 GTK_WIDGET (icon_view),
7270 (GdkRectangle *)item, (GdkRectangle *)item,
7271 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7273 return data.pixbuf_found;
7277 get_text_foreach (GtkCellRenderer *renderer,
7280 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7282 g_object_get (renderer, "text", text, NULL);
7290 get_text (GtkIconView *icon_view,
7291 GtkIconViewItem *item)
7295 gtk_icon_view_set_cell_data (icon_view, item);
7296 gtk_cell_area_foreach (icon_view->priv->cell_area,
7297 (GtkCellCallback)get_text_foreach, &text);
7303 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7307 GtkIconViewItemAccessible *item;
7310 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7312 if (!GTK_IS_ICON_VIEW (item->widget))
7315 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7318 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7321 *height = box.height;
7326 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7329 AtkCoordType coord_type)
7331 GtkIconViewItemAccessible *item;
7334 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7336 if (!GTK_IS_ICON_VIEW (item->widget))
7339 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7342 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7344 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7346 *x+= box.x - item->item->cell_area.x;
7347 *y+= box.y - item->item->cell_area.y;
7353 atk_image_item_interface_init (AtkImageIface *iface)
7355 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7356 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7357 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7358 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7362 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7366 GtkIconViewItemAccessible *item;
7367 GtkTextIter start, end;
7368 GtkTextBuffer *buffer;
7370 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7372 if (!GTK_IS_ICON_VIEW (item->widget))
7375 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7378 buffer = item->text_buffer;
7379 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7381 gtk_text_buffer_get_end_iter (buffer, &end);
7383 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7385 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7389 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7392 GtkIconViewItemAccessible *item;
7393 GtkTextIter start, end;
7394 GtkTextBuffer *buffer;
7398 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7400 if (!GTK_IS_ICON_VIEW (item->widget))
7403 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7406 buffer = item->text_buffer;
7407 if (offset >= gtk_text_buffer_get_char_count (buffer))
7410 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7412 gtk_text_iter_forward_char (&end);
7413 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7414 unichar = g_utf8_get_char (string);
7422 get_pango_text_offsets (PangoLayout *layout,
7423 GtkTextBuffer *buffer,
7425 AtkTextBoundary boundary_type,
7429 GtkTextIter *start_iter,
7430 GtkTextIter *end_iter)
7432 PangoLayoutIter *iter;
7433 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7434 gint index, start_index, end_index;
7436 gboolean found = FALSE;
7438 text = pango_layout_get_text (layout);
7439 index = g_utf8_offset_to_pointer (text, offset) - text;
7440 iter = pango_layout_get_iter (layout);
7443 line = pango_layout_iter_get_line_readonly (iter);
7444 start_index = line->start_index;
7445 end_index = start_index + line->length;
7447 if (index >= start_index && index <= end_index)
7450 * Found line for offset
7456 * We want the previous line
7460 switch (boundary_type)
7462 case ATK_TEXT_BOUNDARY_LINE_START:
7463 end_index = start_index;
7464 start_index = prev_line->start_index;
7466 case ATK_TEXT_BOUNDARY_LINE_END:
7468 start_index = prev_prev_line->start_index +
7469 prev_prev_line->length;
7470 end_index = prev_line->start_index + prev_line->length;
7473 g_assert_not_reached();
7477 start_index = end_index = 0;
7480 switch (boundary_type)
7482 case ATK_TEXT_BOUNDARY_LINE_START:
7483 if (pango_layout_iter_next_line (iter))
7484 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7486 case ATK_TEXT_BOUNDARY_LINE_END:
7488 start_index = prev_line->start_index +
7492 g_assert_not_reached();
7497 * We want the next line
7499 if (pango_layout_iter_next_line (iter))
7501 line = pango_layout_iter_get_line_readonly (iter);
7502 switch (boundary_type)
7504 case ATK_TEXT_BOUNDARY_LINE_START:
7505 start_index = line->start_index;
7506 if (pango_layout_iter_next_line (iter))
7507 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7509 end_index = start_index + line->length;
7511 case ATK_TEXT_BOUNDARY_LINE_END:
7512 start_index = end_index;
7513 end_index = line->start_index + line->length;
7516 g_assert_not_reached();
7520 start_index = end_index;
7526 prev_prev_line = prev_line;
7529 while (pango_layout_iter_next_line (iter));
7533 start_index = prev_line->start_index + prev_line->length;
7534 end_index = start_index;
7536 pango_layout_iter_free (iter);
7537 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7538 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7540 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7541 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7546 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7548 AtkTextBoundary boundary_type,
7552 GtkIconViewItemAccessible *item;
7553 GtkTextIter start, end;
7554 GtkTextBuffer *buffer;
7556 GtkIconView *icon_view;
7559 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7561 if (!GTK_IS_ICON_VIEW (item->widget))
7564 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7567 buffer = item->text_buffer;
7569 if (!gtk_text_buffer_get_char_count (buffer))
7573 return g_strdup ("");
7575 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7579 switch (boundary_type)
7581 case ATK_TEXT_BOUNDARY_CHAR:
7582 gtk_text_iter_backward_char(&start);
7584 case ATK_TEXT_BOUNDARY_WORD_START:
7585 if (!gtk_text_iter_starts_word (&start))
7586 gtk_text_iter_backward_word_start (&start);
7588 gtk_text_iter_backward_word_start(&start);
7590 case ATK_TEXT_BOUNDARY_WORD_END:
7591 if (gtk_text_iter_inside_word (&start) &&
7592 !gtk_text_iter_starts_word (&start))
7593 gtk_text_iter_backward_word_start (&start);
7594 while (!gtk_text_iter_ends_word (&start))
7596 if (!gtk_text_iter_backward_char (&start))
7600 gtk_text_iter_backward_word_start(&start);
7601 while (!gtk_text_iter_ends_word (&start))
7603 if (!gtk_text_iter_backward_char (&start))
7607 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7608 if (!gtk_text_iter_starts_sentence (&start))
7609 gtk_text_iter_backward_sentence_start (&start);
7611 gtk_text_iter_backward_sentence_start (&start);
7613 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7614 if (gtk_text_iter_inside_sentence (&start) &&
7615 !gtk_text_iter_starts_sentence (&start))
7616 gtk_text_iter_backward_sentence_start (&start);
7617 while (!gtk_text_iter_ends_sentence (&start))
7619 if (!gtk_text_iter_backward_char (&start))
7623 gtk_text_iter_backward_sentence_start (&start);
7624 while (!gtk_text_iter_ends_sentence (&start))
7626 if (!gtk_text_iter_backward_char (&start))
7630 case ATK_TEXT_BOUNDARY_LINE_START:
7631 case ATK_TEXT_BOUNDARY_LINE_END:
7633 icon_view = GTK_ICON_VIEW (item->widget);
7634 /* FIXME we probably have to use GailTextCell to salvage this */
7635 gtk_icon_view_update_item_text (icon_view, item->item);
7636 get_pango_text_offsets (icon_view->priv->layout,
7649 *start_offset = gtk_text_iter_get_offset (&start);
7650 *end_offset = gtk_text_iter_get_offset (&end);
7652 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7656 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7658 AtkTextBoundary boundary_type,
7662 GtkIconViewItemAccessible *item;
7663 GtkTextIter start, end;
7664 GtkTextBuffer *buffer;
7666 GtkIconView *icon_view;
7669 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7671 if (!GTK_IS_ICON_VIEW (item->widget))
7674 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7677 buffer = item->text_buffer;
7679 if (!gtk_text_buffer_get_char_count (buffer))
7683 return g_strdup ("");
7685 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7689 switch (boundary_type)
7691 case ATK_TEXT_BOUNDARY_CHAR:
7692 gtk_text_iter_forward_char (&end);
7694 case ATK_TEXT_BOUNDARY_WORD_START:
7695 if (!gtk_text_iter_starts_word (&start))
7696 gtk_text_iter_backward_word_start (&start);
7697 if (gtk_text_iter_inside_word (&end))
7698 gtk_text_iter_forward_word_end (&end);
7699 while (!gtk_text_iter_starts_word (&end))
7701 if (!gtk_text_iter_forward_char (&end))
7705 case ATK_TEXT_BOUNDARY_WORD_END:
7706 if (gtk_text_iter_inside_word (&start) &&
7707 !gtk_text_iter_starts_word (&start))
7708 gtk_text_iter_backward_word_start (&start);
7709 while (!gtk_text_iter_ends_word (&start))
7711 if (!gtk_text_iter_backward_char (&start))
7714 gtk_text_iter_forward_word_end (&end);
7716 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7717 if (!gtk_text_iter_starts_sentence (&start))
7718 gtk_text_iter_backward_sentence_start (&start);
7719 if (gtk_text_iter_inside_sentence (&end))
7720 gtk_text_iter_forward_sentence_end (&end);
7721 while (!gtk_text_iter_starts_sentence (&end))
7723 if (!gtk_text_iter_forward_char (&end))
7727 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7728 if (gtk_text_iter_inside_sentence (&start) &&
7729 !gtk_text_iter_starts_sentence (&start))
7730 gtk_text_iter_backward_sentence_start (&start);
7731 while (!gtk_text_iter_ends_sentence (&start))
7733 if (!gtk_text_iter_backward_char (&start))
7736 gtk_text_iter_forward_sentence_end (&end);
7738 case ATK_TEXT_BOUNDARY_LINE_START:
7739 case ATK_TEXT_BOUNDARY_LINE_END:
7741 icon_view = GTK_ICON_VIEW (item->widget);
7742 /* FIXME we probably have to use GailTextCell to salvage this */
7743 gtk_icon_view_update_item_text (icon_view, item->item);
7744 get_pango_text_offsets (icon_view->priv->layout,
7758 *start_offset = gtk_text_iter_get_offset (&start);
7759 *end_offset = gtk_text_iter_get_offset (&end);
7761 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7765 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7767 AtkTextBoundary boundary_type,
7771 GtkIconViewItemAccessible *item;
7772 GtkTextIter start, end;
7773 GtkTextBuffer *buffer;
7775 GtkIconView *icon_view;
7778 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7780 if (!GTK_IS_ICON_VIEW (item->widget))
7783 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7786 buffer = item->text_buffer;
7788 if (!gtk_text_buffer_get_char_count (buffer))
7792 return g_strdup ("");
7794 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7798 switch (boundary_type)
7800 case ATK_TEXT_BOUNDARY_CHAR:
7801 gtk_text_iter_forward_char(&start);
7802 gtk_text_iter_forward_chars(&end, 2);
7804 case ATK_TEXT_BOUNDARY_WORD_START:
7805 if (gtk_text_iter_inside_word (&end))
7806 gtk_text_iter_forward_word_end (&end);
7807 while (!gtk_text_iter_starts_word (&end))
7809 if (!gtk_text_iter_forward_char (&end))
7813 if (!gtk_text_iter_is_end (&end))
7815 gtk_text_iter_forward_word_end (&end);
7816 while (!gtk_text_iter_starts_word (&end))
7818 if (!gtk_text_iter_forward_char (&end))
7823 case ATK_TEXT_BOUNDARY_WORD_END:
7824 gtk_text_iter_forward_word_end (&end);
7826 if (!gtk_text_iter_is_end (&end))
7827 gtk_text_iter_forward_word_end (&end);
7829 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7830 if (gtk_text_iter_inside_sentence (&end))
7831 gtk_text_iter_forward_sentence_end (&end);
7832 while (!gtk_text_iter_starts_sentence (&end))
7834 if (!gtk_text_iter_forward_char (&end))
7838 if (!gtk_text_iter_is_end (&end))
7840 gtk_text_iter_forward_sentence_end (&end);
7841 while (!gtk_text_iter_starts_sentence (&end))
7843 if (!gtk_text_iter_forward_char (&end))
7848 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7849 gtk_text_iter_forward_sentence_end (&end);
7851 if (!gtk_text_iter_is_end (&end))
7852 gtk_text_iter_forward_sentence_end (&end);
7854 case ATK_TEXT_BOUNDARY_LINE_START:
7855 case ATK_TEXT_BOUNDARY_LINE_END:
7857 icon_view = GTK_ICON_VIEW (item->widget);
7858 /* FIXME we probably have to use GailTextCell to salvage this */
7859 gtk_icon_view_update_item_text (icon_view, item->item);
7860 get_pango_text_offsets (icon_view->priv->layout,
7872 *start_offset = gtk_text_iter_get_offset (&start);
7873 *end_offset = gtk_text_iter_get_offset (&end);
7875 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7879 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7881 GtkIconViewItemAccessible *item;
7883 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7885 if (!GTK_IS_ICON_VIEW (item->widget))
7888 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7891 return gtk_text_buffer_get_char_count (item->text_buffer);
7895 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7901 AtkCoordType coord_type)
7903 GtkIconViewItemAccessible *item;
7905 GtkIconView *icon_view;
7906 PangoRectangle char_rect;
7907 const gchar *item_text;
7911 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7913 if (!GTK_IS_ICON_VIEW (item->widget))
7916 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7920 icon_view = GTK_ICON_VIEW (item->widget);
7921 /* FIXME we probably have to use GailTextCell to salvage this */
7922 gtk_icon_view_update_item_text (icon_view, item->item);
7923 item_text = pango_layout_get_text (icon_view->priv->layout);
7924 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7925 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7927 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7928 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7929 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7930 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7931 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7932 *width = char_rect.width / PANGO_SCALE;
7933 *height = char_rect.height / PANGO_SCALE;
7938 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7941 AtkCoordType coord_type)
7943 GtkIconViewItemAccessible *item;
7946 GtkIconView *icon_view;
7947 const gchar *item_text;
7952 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7954 if (!GTK_IS_ICON_VIEW (item->widget))
7957 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7961 icon_view = GTK_ICON_VIEW (item->widget);
7962 /* FIXME we probably have to use GailTextCell to salvage this */
7963 gtk_icon_view_update_item_text (icon_view, item->item);
7964 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7965 x -= l_x + item->item->layout_x - item->item->x;
7966 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7967 y -= l_y + item->item->layout_y - item->item->y;
7968 item_text = pango_layout_get_text (icon_view->priv->layout);
7969 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7980 offset = g_utf8_strlen (item_text, -1);
7982 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7988 atk_text_item_interface_init (AtkTextIface *iface)
7990 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7991 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7992 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7993 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7994 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7995 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7996 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7997 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8001 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8006 AtkCoordType coord_type)
8008 GtkIconViewItemAccessible *item;
8009 AtkObject *parent_obj;
8012 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8014 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8015 if (!GTK_IS_WIDGET (item->widget))
8018 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8021 *width = item->item->cell_area.width;
8022 *height = item->item->cell_area.height;
8023 if (gtk_icon_view_item_accessible_is_showing (item))
8025 parent_obj = gtk_widget_get_accessible (item->widget);
8026 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8027 *x = l_x + item->item->cell_area.x;
8028 *y = l_y + item->item->cell_area.y;
8038 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8040 GtkIconViewItemAccessible *item;
8041 GtkWidget *toplevel;
8043 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8045 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8046 if (!GTK_IS_WIDGET (item->widget))
8049 gtk_widget_grab_focus (item->widget);
8050 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
8051 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8052 if (gtk_widget_is_toplevel (toplevel))
8053 gtk_window_present (GTK_WINDOW (toplevel));
8059 atk_component_item_interface_init (AtkComponentIface *iface)
8061 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8062 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8066 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8067 AtkStateType state_type,
8068 gboolean emit_signal)
8072 rc = atk_state_set_add_state (item->state_set, state_type);
8074 * The signal should only be generated if the value changed,
8075 * not when the item is set up. So states that are set
8076 * initially should pass FALSE as the emit_signal argument.
8081 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8082 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8083 if (state_type == ATK_STATE_VISIBLE)
8084 g_signal_emit_by_name (item, "visible-data-changed");
8091 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8092 AtkStateType state_type,
8093 gboolean emit_signal)
8095 if (atk_state_set_contains_state (item->state_set, state_type))
8099 rc = atk_state_set_remove_state (item->state_set, state_type);
8101 * The signal should only be generated if the value changed,
8102 * not when the item is set up. So states that are set
8103 * initially should pass FALSE as the emit_signal argument.
8108 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8109 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8110 if (state_type == ATK_STATE_VISIBLE)
8111 g_signal_emit_by_name (item, "visible-data-changed");
8121 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8123 GtkAllocation allocation;
8124 GtkIconView *icon_view;
8125 GdkRectangle visible_rect;
8126 gboolean is_showing;
8129 * An item is considered "SHOWING" if any part of the item is in the
8130 * visible rectangle.
8133 if (!GTK_IS_ICON_VIEW (item->widget))
8136 if (item->item == NULL)
8139 gtk_widget_get_allocation (item->widget, &allocation);
8141 icon_view = GTK_ICON_VIEW (item->widget);
8143 if (icon_view->priv->hadjustment)
8144 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8146 if (icon_view->priv->hadjustment)
8147 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8148 visible_rect.width = allocation.width;
8149 visible_rect.height = allocation.height;
8151 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8152 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8153 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8154 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8163 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8164 gboolean emit_signal)
8166 if (gtk_icon_view_item_accessible_is_showing (item))
8167 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8170 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8175 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8179 item->state_set = atk_state_set_new ();
8181 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8182 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8183 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8184 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8185 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8187 for (i = 0; i < LAST_ACTION; i++)
8188 item->action_descriptions[i] = NULL;
8190 item->image_description = NULL;
8192 item->action_idle_handler = 0;
8196 gtk_icon_view_item_accessible_finalize (GObject *object)
8198 GtkIconViewItemAccessible *item;
8201 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8203 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8206 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8208 if (item->state_set)
8209 g_object_unref (item->state_set);
8211 if (item->text_buffer)
8212 g_object_unref (item->text_buffer);
8214 for (i = 0; i < LAST_ACTION; i++)
8215 g_free (item->action_descriptions[i]);
8217 g_free (item->image_description);
8219 if (item->action_idle_handler)
8221 g_source_remove (item->action_idle_handler);
8222 item->action_idle_handler = 0;
8225 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8229 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8231 GtkIconViewItemAccessible *item;
8233 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8234 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8237 return gtk_widget_get_accessible (item->widget);
8243 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8245 GtkIconViewItemAccessible *item;
8247 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8248 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8250 return item->item->index;
8253 static AtkStateSet *
8254 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8256 GtkIconViewItemAccessible *item;
8257 GtkIconView *icon_view;
8259 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8260 g_return_val_if_fail (item->state_set, NULL);
8265 icon_view = GTK_ICON_VIEW (item->widget);
8266 if (icon_view->priv->cursor_item == item->item)
8267 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8269 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8270 if (item->item->selected)
8271 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8273 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8275 return g_object_ref (item->state_set);
8279 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8281 GObjectClass *gobject_class;
8283 accessible_item_parent_class = g_type_class_peek_parent (klass);
8285 gobject_class = (GObjectClass *)klass;
8287 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8289 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8290 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8291 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8295 gtk_icon_view_item_accessible_get_type (void)
8297 static GType type = 0;
8301 const GTypeInfo tinfo =
8303 sizeof (GtkIconViewItemAccessibleClass),
8304 (GBaseInitFunc) NULL, /* base init */
8305 (GBaseFinalizeFunc) NULL, /* base finalize */
8306 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8307 (GClassFinalizeFunc) NULL, /* class finalize */
8308 NULL, /* class data */
8309 sizeof (GtkIconViewItemAccessible), /* instance size */
8310 0, /* nb preallocs */
8311 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8312 NULL /* value table */
8315 const GInterfaceInfo atk_component_info =
8317 (GInterfaceInitFunc) atk_component_item_interface_init,
8318 (GInterfaceFinalizeFunc) NULL,
8321 const GInterfaceInfo atk_action_info =
8323 (GInterfaceInitFunc) atk_action_item_interface_init,
8324 (GInterfaceFinalizeFunc) NULL,
8327 const GInterfaceInfo atk_image_info =
8329 (GInterfaceInitFunc) atk_image_item_interface_init,
8330 (GInterfaceFinalizeFunc) NULL,
8333 const GInterfaceInfo atk_text_info =
8335 (GInterfaceInitFunc) atk_text_item_interface_init,
8336 (GInterfaceFinalizeFunc) NULL,
8340 type = g_type_register_static (ATK_TYPE_OBJECT,
8341 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8342 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8343 &atk_component_info);
8344 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8346 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8348 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8355 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8356 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8357 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8359 static GType gtk_icon_view_accessible_get_type (void);
8364 } GtkIconViewAccessible;
8370 } GtkIconViewItemAccessibleInfo;
8376 GtkAdjustment *old_hadj;
8377 GtkAdjustment *old_vadj;
8379 GtkTreeModel *model;
8381 } GtkIconViewAccessiblePrivate;
8383 static GtkIconViewAccessiblePrivate *
8384 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8386 return g_object_get_qdata (G_OBJECT (accessible),
8387 accessible_private_data_quark);
8391 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8395 GtkIconViewItemAccessibleInfo *info;
8396 GtkIconViewItemAccessibleInfo *tmp_info;
8397 GtkIconViewAccessiblePrivate *priv;
8400 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8402 info->index = index;
8404 priv = gtk_icon_view_accessible_get_priv (accessible);
8405 items = priv->items;
8408 tmp_info = items->data;
8409 if (tmp_info->index > index)
8411 items = items->next;
8413 priv->items = g_list_insert_before (priv->items, items, info);
8414 priv->old_hadj = NULL;
8415 priv->old_vadj = NULL;
8419 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8421 GtkIconView *icon_view;
8424 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8428 icon_view = GTK_ICON_VIEW (widget);
8430 return g_list_length (icon_view->priv->items);
8434 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8437 GtkIconViewAccessiblePrivate *priv;
8438 GtkIconViewItemAccessibleInfo *info;
8441 priv = gtk_icon_view_accessible_get_priv (accessible);
8442 items = priv->items;
8447 if (info->index == index)
8449 items = items->next;
8455 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8458 GtkIconView *icon_view;
8462 GtkIconViewItemAccessible *a11y_item;
8464 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8468 icon_view = GTK_ICON_VIEW (widget);
8469 icons = g_list_nth (icon_view->priv->items, index);
8473 GtkIconViewItem *item = icons->data;
8475 g_return_val_if_fail (item->index == index, NULL);
8476 obj = gtk_icon_view_accessible_find_child (accessible, index);
8481 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8482 gtk_icon_view_item_accessible_info_new (accessible,
8485 obj->role = ATK_ROLE_ICON;
8486 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8487 a11y_item->item = item;
8488 a11y_item->widget = widget;
8489 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8491 text = get_text (icon_view, item);
8494 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8498 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8499 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8507 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8510 GtkIconViewAccessiblePrivate *priv;
8511 GtkIconViewItemAccessibleInfo *info;
8512 GtkIconViewItemAccessible *item;
8515 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8519 gboolean act_on_item;
8521 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8525 items = priv->items;
8527 act_on_item = (list == NULL);
8532 info = (GtkIconViewItemAccessibleInfo *)items->data;
8533 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8535 if (act_on_item == FALSE && list == items)
8539 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8541 items = items->next;
8547 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8548 GtkIconViewAccessible *view)
8550 gtk_icon_view_accessible_traverse_items (view, NULL);
8554 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8555 GtkOrientation orientation,
8556 GtkAdjustment *adjustment)
8558 GtkIconViewAccessiblePrivate *priv;
8559 GtkAdjustment **old_adj_ptr;
8561 priv = gtk_icon_view_accessible_get_priv (accessible);
8563 /* Adjustments are set for the first time in constructor and priv is not
8564 * initialized at that time, so skip this first setting. */
8568 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8570 if (priv->old_hadj == adjustment)
8573 old_adj_ptr = &priv->old_hadj;
8577 if (priv->old_vadj == adjustment)
8580 old_adj_ptr = &priv->old_vadj;
8583 /* Disconnect signal handlers */
8586 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8587 (gpointer *)&priv->old_hadj);
8588 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8589 gtk_icon_view_accessible_adjustment_changed,
8593 /* Connect signal */
8594 *old_adj_ptr = adjustment;
8595 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8596 g_signal_connect (adjustment, "value-changed",
8597 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8602 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8610 GtkIconView *icon_view;
8611 GtkIconViewItem *item;
8612 GtkIconViewItemAccessible *a11y_item;
8616 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8617 index = gtk_tree_path_get_indices(path)[0];
8618 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8619 gtk_icon_view_accessible_find_child (atk_obj, index));
8623 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8624 icon_view = GTK_ICON_VIEW (widget);
8625 item = a11y_item->item;
8627 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8629 if (!name || strcmp (name, "") == 0)
8631 text = get_text (icon_view, item);
8634 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8640 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8646 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8651 GtkIconViewAccessiblePrivate *priv;
8652 GtkIconViewItemAccessibleInfo *info;
8653 GtkIconViewAccessible *view;
8654 GtkIconViewItemAccessible *item;
8660 index = gtk_tree_path_get_indices(path)[0];
8661 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8662 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8663 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8665 items = priv->items;
8670 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8671 if (info->index != item->item->index)
8673 if (info->index < index)
8674 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8676 if (tmp_list == NULL)
8679 info->index = item->item->index;
8682 items = items->next;
8684 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8685 g_signal_emit_by_name (atk_obj, "children-changed::add",
8691 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8695 GtkIconViewAccessiblePrivate *priv;
8696 GtkIconViewItemAccessibleInfo *info;
8697 GtkIconViewAccessible *view;
8698 GtkIconViewItemAccessible *item;
8701 GList *deleted_item;
8705 index = gtk_tree_path_get_indices(path)[0];
8706 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8707 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8708 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8710 items = priv->items;
8712 deleted_item = NULL;
8717 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8718 if (info->index == index)
8720 deleted_item = items;
8722 if (info->index != item->item->index)
8724 if (tmp_list == NULL)
8727 info->index = item->item->index;
8730 items = items->next;
8732 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8735 info = deleted_item->data;
8736 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8737 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8739 priv->items = g_list_remove_link (priv->items, deleted_item);
8747 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8748 GtkIconViewItemAccessibleInfo *i2)
8750 return i1->index - i2->index;
8754 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8760 GtkIconViewAccessiblePrivate *priv;
8761 GtkIconViewItemAccessibleInfo *info;
8762 GtkIconView *icon_view;
8763 GtkIconViewItemAccessible *item;
8769 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8770 icon_view = GTK_ICON_VIEW (user_data);
8771 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8773 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8775 order = g_new (gint, length);
8776 for (i = 0; i < length; i++)
8777 order [new_order[i]] = i;
8779 items = priv->items;
8783 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8784 info->index = order[info->index];
8785 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8786 items = items->next;
8789 priv->items = g_list_sort (priv->items,
8790 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8796 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8801 obj = G_OBJECT (model);
8802 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8803 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8804 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8805 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8809 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8813 obj = G_OBJECT (icon_view->priv->model);
8814 g_signal_connect_data (obj, "row-changed",
8815 (GCallback) gtk_icon_view_accessible_model_row_changed,
8816 icon_view, NULL, 0);
8817 g_signal_connect_data (obj, "row-inserted",
8818 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8819 icon_view, NULL, G_CONNECT_AFTER);
8820 g_signal_connect_data (obj, "row-deleted",
8821 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8822 icon_view, NULL, G_CONNECT_AFTER);
8823 g_signal_connect_data (obj, "rows-reordered",
8824 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8825 icon_view, NULL, G_CONNECT_AFTER);
8829 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8831 GtkIconViewItemAccessibleInfo *info;
8834 items = priv->items;
8837 info = (GtkIconViewItemAccessibleInfo *) items->data;
8838 g_object_unref (info->item);
8839 g_free (items->data);
8840 items = items->next;
8842 g_list_free (priv->items);
8847 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8850 GtkIconView *icon_view;
8853 GtkIconViewAccessiblePrivate *priv;
8855 if (strcmp (pspec->name, "model") == 0)
8857 widget = GTK_WIDGET (obj);
8858 atk_obj = gtk_widget_get_accessible (widget);
8859 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8862 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8863 (gpointer *)&priv->model);
8864 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8866 gtk_icon_view_accessible_clear_cache (priv);
8868 icon_view = GTK_ICON_VIEW (obj);
8869 priv->model = icon_view->priv->model;
8870 /* If there is no model the GtkIconView is probably being destroyed */
8873 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8874 gtk_icon_view_accessible_connect_model_signals (icon_view);
8882 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8885 GtkIconViewAccessiblePrivate *priv;
8886 GtkIconView *icon_view;
8888 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8889 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8891 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8892 g_object_set_qdata (G_OBJECT (accessible),
8893 accessible_private_data_quark,
8896 icon_view = GTK_ICON_VIEW (data);
8897 if (icon_view->priv->hadjustment)
8898 gtk_icon_view_accessible_set_adjustment (accessible,
8899 GTK_ORIENTATION_HORIZONTAL,
8900 icon_view->priv->hadjustment);
8901 if (icon_view->priv->vadjustment)
8902 gtk_icon_view_accessible_set_adjustment (accessible,
8903 GTK_ORIENTATION_VERTICAL,
8904 icon_view->priv->vadjustment);
8905 g_signal_connect (data,
8907 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8910 priv->model = icon_view->priv->model;
8913 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8914 gtk_icon_view_accessible_connect_model_signals (icon_view);
8917 accessible->role = ATK_ROLE_LAYERED_PANE;
8921 gtk_icon_view_accessible_finalize (GObject *object)
8923 GtkIconViewAccessiblePrivate *priv;
8925 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8926 gtk_icon_view_accessible_clear_cache (priv);
8930 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8934 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8935 GtkAccessible *accessible)
8938 GtkIconViewAccessiblePrivate *priv;
8940 atk_obj = ATK_OBJECT (accessible);
8941 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8944 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8945 (gpointer *)&priv->old_hadj);
8947 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8948 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8950 priv->old_hadj = NULL;
8954 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8955 (gpointer *)&priv->old_vadj);
8957 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8958 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8960 priv->old_vadj = NULL;
8965 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8969 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8972 g_signal_connect_after (widget,
8974 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8977 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8981 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8983 GObjectClass *gobject_class;
8984 GtkAccessibleClass *accessible_class;
8986 accessible_parent_class = g_type_class_peek_parent (klass);
8988 gobject_class = (GObjectClass *)klass;
8989 accessible_class = (GtkAccessibleClass *)klass;
8991 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8993 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8994 klass->ref_child = gtk_icon_view_accessible_ref_child;
8995 klass->initialize = gtk_icon_view_accessible_initialize;
8997 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8999 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9003 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9006 AtkCoordType coord_type)
9009 GtkIconView *icon_view;
9010 GtkIconViewItem *item;
9013 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9015 /* State is defunct */
9018 icon_view = GTK_ICON_VIEW (widget);
9019 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9020 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9022 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9028 atk_component_interface_init (AtkComponentIface *iface)
9030 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9034 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9038 GtkIconView *icon_view;
9039 GtkIconViewItem *item;
9041 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9045 icon_view = GTK_ICON_VIEW (widget);
9047 item = g_list_nth_data (icon_view->priv->items, i);
9052 gtk_icon_view_select_item (icon_view, item);
9058 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9061 GtkIconView *icon_view;
9063 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9067 icon_view = GTK_ICON_VIEW (widget);
9068 gtk_icon_view_unselect_all (icon_view);
9074 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9079 GtkIconView *icon_view;
9080 GtkIconViewItem *item;
9082 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9086 icon_view = GTK_ICON_VIEW (widget);
9088 l = icon_view->priv->items;
9095 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9106 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9109 GtkIconView *icon_view;
9110 GtkIconViewItem *item;
9114 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9118 icon_view = GTK_ICON_VIEW (widget);
9120 l = icon_view->priv->items;
9136 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9140 GtkIconView *icon_view;
9141 GtkIconViewItem *item;
9143 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9147 icon_view = GTK_ICON_VIEW (widget);
9149 item = g_list_nth_data (icon_view->priv->items, i);
9153 return item->selected;
9157 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9161 GtkIconView *icon_view;
9162 GtkIconViewItem *item;
9166 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9170 icon_view = GTK_ICON_VIEW (widget);
9171 l = icon_view->priv->items;
9180 gtk_icon_view_unselect_item (icon_view, item);
9192 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9195 GtkIconView *icon_view;
9197 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9201 icon_view = GTK_ICON_VIEW (widget);
9202 gtk_icon_view_select_all (icon_view);
9207 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9209 iface->add_selection = gtk_icon_view_accessible_add_selection;
9210 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9211 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9212 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9213 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9214 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9215 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9219 gtk_icon_view_accessible_get_type (void)
9221 static GType type = 0;
9227 sizeof (GtkContainerAccessibleClass), /* class size */
9228 (GBaseInitFunc) NULL, /* base init */
9229 (GBaseFinalizeFunc) NULL, /* base finalize */
9230 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9231 (GClassFinalizeFunc) NULL, /* class finalize */
9232 NULL, /* class data */
9233 sizeof (GtkContainerAccessible), /* instance size */
9234 0, /* nb preallocs */
9235 (GInstanceInitFunc) NULL, /* instance init */
9236 NULL /* value table */
9238 const GInterfaceInfo atk_component_info =
9240 (GInterfaceInitFunc) atk_component_interface_init,
9241 (GInterfaceFinalizeFunc) NULL,
9244 const GInterfaceInfo atk_selection_info =
9246 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9247 (GInterfaceFinalizeFunc) NULL,
9251 type = g_type_register_static (GTK_TYPE_CONTAINER_ACCESSIBLE,
9252 I_("GtkIconViewAccessible"), &tinfo, 0);
9253 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9254 &atk_component_info);
9255 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9256 &atk_selection_info);
9262 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9263 GtkBuilder *builder,
9265 const gchar *tagname,
9266 GMarkupParser *parser,
9269 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9270 tagname, parser, data))
9273 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9274 tagname, parser, data);
9278 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9279 GtkBuilder *builder,
9281 const gchar *tagname,
9284 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9285 child, tagname, data))
9286 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,