2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gtkaccessibleprivate.h"
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellareabox.h"
31 #include "gtkcellareacontext.h"
32 #include "gtkcellrenderertext.h"
33 #include "gtkcellrendererpixbuf.h"
34 #include "gtkorientable.h"
35 #include "gtkmarshalers.h"
36 #include "gtkbindings.h"
40 #include "gtkaccessible.h"
41 #include "gtkwindow.h"
43 #include "gtkcombobox.h"
44 #include "gtktextbuffer.h"
45 #include "gtkscrollable.h"
46 #include "gtksizerequest.h"
47 #include "gtktreednd.h"
48 #include "gtktypebuiltins.h"
49 #include "gtkprivate.h"
54 * @short_description: A widget which displays a list of icons in a grid
56 * #GtkIconView provides an alternative view on a #GtkTreeModel.
57 * It displays the model as a grid of icons with labels. Like
58 * #GtkTreeView, it allows to select one or multiple items
59 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
60 * In addition to selection with the arrow keys, #GtkIconView supports
61 * rubberband selection, which is controlled by dragging the pointer.
63 * Note that if the tree model is backed by an actual tree store (as
64 * opposed to a flat list where the mapping to icons is obvious),
65 * #GtkIconView will only display the first level of the tree and
66 * ignore the tree's branches.
69 #define SCROLL_EDGE_SIZE 15
71 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
73 typedef struct _GtkIconViewItem GtkIconViewItem;
74 struct _GtkIconViewItem
76 /* First member is always the rectangle so it
77 * can be cast to a rectangle. */
78 GdkRectangle cell_area;
86 guint selected_before_rubberbanding : 1;
90 typedef struct _GtkIconViewChild GtkIconViewChild;
91 struct _GtkIconViewChild
97 struct _GtkIconViewPrivate
99 GtkCellArea *cell_area;
100 GtkCellAreaContext *cell_area_context;
102 gulong add_editable_id;
103 gulong remove_editable_id;
104 gulong context_changed_id;
106 GPtrArray *row_contexts;
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
127 GdkDevice *rubberband_device;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
136 GtkIconViewItem *last_single_clicked;
138 GtkOrientation item_orientation;
152 GtkCellRenderer *pixbuf_cell;
153 GtkCellRenderer *text_cell;
158 GdkModifierType start_button_mask;
163 GdkDragAction source_actions;
164 GdkDragAction dest_actions;
166 GtkTreeRowReference *dest_item;
167 GtkIconViewDropPosition dest_pos;
170 GtkTreeRowReference *scroll_to_path;
171 gfloat scroll_to_row_align;
172 gfloat scroll_to_col_align;
173 guint scroll_to_use_align : 1;
175 guint source_set : 1;
177 guint reorderable : 1;
178 guint empty_view_drop :1;
180 guint ctrl_pressed : 1;
181 guint shift_pressed : 1;
183 guint draw_focus : 1;
185 /* GtkScrollablePolicy needs to be checked when
186 * driving the scrollable adjustment values */
187 guint hscroll_policy : 1;
188 guint vscroll_policy : 1;
190 guint doing_rubberband : 1;
204 ACTIVATE_CURSOR_ITEM,
216 PROP_ITEM_ORIENTATION,
229 /* For scrollable interface */
237 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
238 static void gtk_icon_view_dispose (GObject *object);
239 static GObject *gtk_icon_view_constructor (GType type,
240 guint n_construct_properties,
241 GObjectConstructParam *construct_properties);
242 static void gtk_icon_view_set_property (GObject *object,
246 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkWidget vfuncs */
251 static void gtk_icon_view_destroy (GtkWidget *widget);
252 static void gtk_icon_view_realize (GtkWidget *widget);
253 static void gtk_icon_view_unrealize (GtkWidget *widget);
254 static void gtk_icon_view_style_updated (GtkWidget *widget);
255 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
256 GtkStateFlags previous_state);
257 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
260 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
263 static void gtk_icon_view_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static gboolean gtk_icon_view_draw (GtkWidget *widget,
267 static gboolean gtk_icon_view_motion (GtkWidget *widget,
268 GdkEventMotion *event);
269 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
270 GdkEventButton *event);
271 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
272 GdkEventButton *event);
273 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
275 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
277 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
280 /* GtkContainer vfuncs */
281 static void gtk_icon_view_remove (GtkContainer *container,
283 static void gtk_icon_view_forall (GtkContainer *container,
284 gboolean include_internals,
285 GtkCallback callback,
286 gpointer callback_data);
288 /* GtkIconView vfuncs */
289 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
291 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
292 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
293 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
295 /* Internal functions */
296 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
297 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
298 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
299 GtkAdjustment *adjustment);
300 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
301 GtkAdjustment *adjustment);
302 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
303 GtkOrientation orientation,
304 GtkAdjustment *adjustment);
305 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
306 GtkIconView *icon_view);
307 static void gtk_icon_view_layout (GtkIconView *icon_view);
308 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
310 GtkIconViewItem *item,
313 gboolean draw_focus);
314 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
316 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
318 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
319 GtkIconViewItem *item);
320 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
321 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
322 GtkIconViewItem *item,
323 GtkCellRenderer *cursor_cell);
324 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
328 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
329 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
330 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
331 GtkIconViewItem *item,
336 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
337 static void gtk_icon_view_cache_widths (GtkIconView *icon_view);
338 static void gtk_icon_view_update_rubberband (gpointer data);
339 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
340 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
341 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
344 GtkMovementStep step,
346 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
347 GtkMovementStep step,
349 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
351 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
353 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
355 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
357 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
358 GtkIconViewItem *item);
359 static void gtk_icon_view_select_item (GtkIconView *icon_view,
360 GtkIconViewItem *item);
361 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
362 GtkIconViewItem *item);
363 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
364 GtkIconViewItem *anchor,
365 GtkIconViewItem *cursor);
366 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
369 gboolean only_in_cell,
370 GtkCellRenderer **cell_at_pos);
371 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
372 GtkIconViewItem *item);
374 static void gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
375 GtkCellArea *cell_area);
377 static GtkCellArea *gtk_icon_view_cell_layout_get_area (GtkCellLayout *layout);
379 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
380 GtkIconViewItem *item);
382 static void gtk_icon_view_add_editable (GtkCellArea *area,
383 GtkCellRenderer *renderer,
384 GtkCellEditable *editable,
385 GdkRectangle *cell_area,
387 GtkIconView *icon_view);
388 static void gtk_icon_view_remove_editable (GtkCellArea *area,
389 GtkCellRenderer *renderer,
390 GtkCellEditable *editable,
391 GtkIconView *icon_view);
392 static void gtk_icon_view_context_changed (GtkCellAreaContext *context,
394 GtkIconView *icon_view);
395 static void update_text_cell (GtkIconView *icon_view);
396 static void update_pixbuf_cell (GtkIconView *icon_view);
398 /* Source side drag signals */
399 static void gtk_icon_view_drag_begin (GtkWidget *widget,
400 GdkDragContext *context);
401 static void gtk_icon_view_drag_end (GtkWidget *widget,
402 GdkDragContext *context);
403 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
404 GdkDragContext *context,
405 GtkSelectionData *selection_data,
408 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
409 GdkDragContext *context);
411 /* Target side drag signals */
412 static void gtk_icon_view_drag_leave (GtkWidget *widget,
413 GdkDragContext *context,
415 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
416 GdkDragContext *context,
420 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
421 GdkDragContext *context,
425 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
426 GdkDragContext *context,
429 GtkSelectionData *selection_data,
432 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
433 GdkEventMotion *event);
435 static void remove_scroll_timeout (GtkIconView *icon_view);
438 static GtkBuildableIface *parent_buildable_iface;
439 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
440 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
443 const gchar *tagname,
444 GMarkupParser *parser,
446 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
449 const gchar *tagname,
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_accessible = gtk_icon_view_get_accessible;
487 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
488 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
489 widget_class->size_allocate = gtk_icon_view_size_allocate;
490 widget_class->draw = gtk_icon_view_draw;
491 widget_class->motion_notify_event = gtk_icon_view_motion;
492 widget_class->button_press_event = gtk_icon_view_button_press;
493 widget_class->button_release_event = gtk_icon_view_button_release;
494 widget_class->key_press_event = gtk_icon_view_key_press;
495 widget_class->key_release_event = gtk_icon_view_key_release;
496 widget_class->drag_begin = gtk_icon_view_drag_begin;
497 widget_class->drag_end = gtk_icon_view_drag_end;
498 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
499 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
500 widget_class->drag_leave = gtk_icon_view_drag_leave;
501 widget_class->drag_motion = gtk_icon_view_drag_motion;
502 widget_class->drag_drop = gtk_icon_view_drag_drop;
503 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
504 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
506 container_class->remove = gtk_icon_view_remove;
507 container_class->forall = gtk_icon_view_forall;
509 klass->select_all = gtk_icon_view_real_select_all;
510 klass->unselect_all = gtk_icon_view_real_unselect_all;
511 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
512 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
513 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
514 klass->move_cursor = gtk_icon_view_real_move_cursor;
518 * GtkIconView:selection-mode:
520 * The ::selection-mode property specifies the selection mode of
521 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
522 * is enabled, for the other modes, only keyboard selection is possible.
526 g_object_class_install_property (gobject_class,
528 g_param_spec_enum ("selection-mode",
529 P_("Selection mode"),
530 P_("The selection mode"),
531 GTK_TYPE_SELECTION_MODE,
532 GTK_SELECTION_SINGLE,
533 GTK_PARAM_READWRITE));
536 * GtkIconView:pixbuf-column:
538 * The ::pixbuf-column property contains the number of the model column
539 * containing the pixbufs which are displayed. The pixbuf column must be
540 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
541 * display of pixbufs.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_int ("pixbuf-column",
549 P_("Model column used to retrieve the icon pixbuf from"),
551 GTK_PARAM_READWRITE));
554 * GtkIconView:text-column:
556 * The ::text-column property contains the number of the model column
557 * containing the texts which are displayed. The text column must be
558 * of type #G_TYPE_STRING. If this property and the :markup-column
559 * property are both set to -1, no texts are displayed.
563 g_object_class_install_property (gobject_class,
565 g_param_spec_int ("text-column",
567 P_("Model column used to retrieve the text from"),
569 GTK_PARAM_READWRITE));
573 * GtkIconView:markup-column:
575 * The ::markup-column property contains the number of the model column
576 * containing markup information to be displayed. The markup column must be
577 * of type #G_TYPE_STRING. If this property and the :text-column property
578 * are both set to column numbers, it overrides the text column.
579 * If both are set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("markup-column",
587 P_("Model column used to retrieve the text if using Pango markup"),
589 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_object ("model",
594 P_("Icon View Model"),
595 P_("The model for the icon view"),
597 GTK_PARAM_READWRITE));
600 * GtkIconView:columns:
602 * The columns property contains the number of the columns in which the
603 * items should be displayed. If it is -1, the number of columns will
604 * be chosen automatically to fill the available area.
608 g_object_class_install_property (gobject_class,
610 g_param_spec_int ("columns",
611 P_("Number of columns"),
612 P_("Number of columns to display"),
614 GTK_PARAM_READWRITE));
618 * GtkIconView:item-width:
620 * The item-width property specifies the width to use for each item.
621 * If it is set to -1, the icon view will automatically determine a
622 * suitable item size.
626 g_object_class_install_property (gobject_class,
628 g_param_spec_int ("item-width",
629 P_("Width for each item"),
630 P_("The width used for each item"),
632 GTK_PARAM_READWRITE));
635 * GtkIconView:spacing:
637 * The spacing property specifies the space which is inserted between
638 * the cells (i.e. the icon and the text) of an item.
642 g_object_class_install_property (gobject_class,
644 g_param_spec_int ("spacing",
646 P_("Space which is inserted between cells of an item"),
648 GTK_PARAM_READWRITE));
651 * GtkIconView:row-spacing:
653 * The row-spacing property specifies the space which is inserted between
654 * the rows of the icon view.
658 g_object_class_install_property (gobject_class,
660 g_param_spec_int ("row-spacing",
662 P_("Space which is inserted between grid rows"),
664 GTK_PARAM_READWRITE));
667 * GtkIconView:column-spacing:
669 * The column-spacing property specifies the space which is inserted between
670 * the columns of the icon view.
674 g_object_class_install_property (gobject_class,
676 g_param_spec_int ("column-spacing",
677 P_("Column Spacing"),
678 P_("Space which is inserted between grid columns"),
680 GTK_PARAM_READWRITE));
683 * GtkIconView:margin:
685 * The margin property specifies the space which is inserted
686 * at the edges of the icon view.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_int ("margin",
694 P_("Space which is inserted at the edges of the icon view"),
696 GTK_PARAM_READWRITE));
699 * GtkIconView:item-orientation:
701 * The item-orientation property specifies how the cells (i.e. the icon and
702 * the text) of the item are positioned relative to each other.
706 g_object_class_install_property (gobject_class,
707 PROP_ITEM_ORIENTATION,
708 g_param_spec_enum ("item-orientation",
709 P_("Item Orientation"),
710 P_("How the text and icon of each item are positioned relative to each other"),
711 GTK_TYPE_ORIENTATION,
712 GTK_ORIENTATION_VERTICAL,
713 GTK_PARAM_READWRITE));
716 * GtkIconView:reorderable:
718 * The reorderable property specifies if the items can be reordered
723 g_object_class_install_property (gobject_class,
725 g_param_spec_boolean ("reorderable",
727 P_("View is reorderable"),
731 g_object_class_install_property (gobject_class,
733 g_param_spec_int ("tooltip-column",
734 P_("Tooltip Column"),
735 P_("The column in the model containing the tooltip texts for the items"),
739 GTK_PARAM_READWRITE));
742 * GtkIconView:item-padding:
744 * The item-padding property specifies the padding around each
745 * of the icon view's item.
749 g_object_class_install_property (gobject_class,
751 g_param_spec_int ("item-padding",
753 P_("Padding around icon view items"),
755 GTK_PARAM_READWRITE));
758 * GtkIconView:cell-area:
760 * The #GtkCellArea used to layout cell renderers for this view.
762 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
763 * a #GtkCellAreaBox will be used.
767 g_object_class_install_property (gobject_class,
769 g_param_spec_object ("cell-area",
771 P_("The GtkCellArea used to layout cells"),
773 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
775 /* Scrollable interface properties */
776 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
777 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
778 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
779 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
781 /* Style properties */
782 gtk_widget_class_install_style_property (widget_class,
783 g_param_spec_boxed ("selection-box-color",
784 P_("Selection Box Color"),
785 P_("Color of the selection box"),
787 GTK_PARAM_READABLE));
789 gtk_widget_class_install_style_property (widget_class,
790 g_param_spec_uchar ("selection-box-alpha",
791 P_("Selection Box Alpha"),
792 P_("Opacity of the selection box"),
795 GTK_PARAM_READABLE));
799 * GtkIconView::item-activated:
800 * @iconview: the object on which the signal is emitted
801 * @path: the #GtkTreePath for the activated item
803 * The ::item-activated signal is emitted when the method
804 * gtk_icon_view_item_activated() is called or the user double
805 * clicks an item. It is also emitted when a non-editable item
806 * is selected and one of the keys: Space, Return or Enter is
809 icon_view_signals[ITEM_ACTIVATED] =
810 g_signal_new (I_("item-activated"),
811 G_TYPE_FROM_CLASS (gobject_class),
813 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
815 g_cclosure_marshal_VOID__BOXED,
820 * GtkIconView::selection-changed:
821 * @iconview: the object on which the signal is emitted
823 * The ::selection-changed signal is emitted when the selection
824 * (i.e. the set of selected items) changes.
826 icon_view_signals[SELECTION_CHANGED] =
827 g_signal_new (I_("selection-changed"),
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
832 g_cclosure_marshal_VOID__VOID,
836 * GtkIconView::select-all:
837 * @iconview: the object on which the signal is emitted
839 * A <link linkend="keybinding-signals">keybinding signal</link>
840 * which gets emitted when the user selects all items.
842 * Applications should not connect to it, but may emit it with
843 * g_signal_emit_by_name() if they need to control selection
846 * The default binding for this signal is Ctrl-a.
848 icon_view_signals[SELECT_ALL] =
849 g_signal_new (I_("select-all"),
850 G_TYPE_FROM_CLASS (gobject_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
854 g_cclosure_marshal_VOID__VOID,
858 * GtkIconView::unselect-all:
859 * @iconview: the object on which the signal is emitted
861 * A <link linkend="keybinding-signals">keybinding signal</link>
862 * which gets emitted when the user unselects all items.
864 * Applications should not connect to it, but may emit it with
865 * g_signal_emit_by_name() if they need to control selection
868 * The default binding for this signal is Ctrl-Shift-a.
870 icon_view_signals[UNSELECT_ALL] =
871 g_signal_new (I_("unselect-all"),
872 G_TYPE_FROM_CLASS (gobject_class),
873 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
874 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
876 g_cclosure_marshal_VOID__VOID,
880 * GtkIconView::select-cursor-item:
881 * @iconview: the object on which the signal is emitted
883 * A <link linkend="keybinding-signals">keybinding signal</link>
884 * which gets emitted when the user selects the item that is currently
887 * Applications should not connect to it, but may emit it with
888 * g_signal_emit_by_name() if they need to control selection
891 * There is no default binding for this signal.
893 icon_view_signals[SELECT_CURSOR_ITEM] =
894 g_signal_new (I_("select-cursor-item"),
895 G_TYPE_FROM_CLASS (gobject_class),
896 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
897 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
899 g_cclosure_marshal_VOID__VOID,
903 * GtkIconView::toggle-cursor-item:
904 * @iconview: the object on which the signal is emitted
906 * A <link linkend="keybinding-signals">keybinding signal</link>
907 * which gets emitted when the user toggles whether the currently
908 * focused item is selected or not. The exact effect of this
909 * depend on the selection mode.
911 * Applications should not connect to it, but may emit it with
912 * g_signal_emit_by_name() if they need to control selection
915 * There is no default binding for this signal is Ctrl-Space.
917 icon_view_signals[TOGGLE_CURSOR_ITEM] =
918 g_signal_new (I_("toggle-cursor-item"),
919 G_TYPE_FROM_CLASS (gobject_class),
920 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
921 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
923 g_cclosure_marshal_VOID__VOID,
927 * GtkIconView::activate-cursor-item:
928 * @iconview: the object on which the signal is emitted
930 * A <link linkend="keybinding-signals">keybinding signal</link>
931 * which gets emitted when the user activates the currently
934 * Applications should not connect to it, but may emit it with
935 * g_signal_emit_by_name() if they need to control activation
938 * The default bindings for this signal are Space, Return and Enter.
940 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
941 g_signal_new (I_("activate-cursor-item"),
942 G_TYPE_FROM_CLASS (gobject_class),
943 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
944 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
946 _gtk_marshal_BOOLEAN__VOID,
950 * GtkIconView::move-cursor:
951 * @iconview: the object which received the signal
952 * @step: the granularity of the move, as a #GtkMovementStep
953 * @count: the number of @step units to move
955 * The ::move-cursor signal is a
956 * <link linkend="keybinding-signals">keybinding signal</link>
957 * which gets emitted when the user initiates a cursor movement.
959 * Applications should not connect to it, but may emit it with
960 * g_signal_emit_by_name() if they need to control the cursor
963 * The default bindings for this signal include
965 * <listitem>Arrow keys which move by individual steps</listitem>
966 * <listitem>Home/End keys which move to the first/last item</listitem>
967 * <listitem>PageUp/PageDown which move by "pages"</listitem>
970 * All of these will extend the selection when combined with
971 * the Shift modifier.
973 icon_view_signals[MOVE_CURSOR] =
974 g_signal_new (I_("move-cursor"),
975 G_TYPE_FROM_CLASS (gobject_class),
976 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
977 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
979 _gtk_marshal_BOOLEAN__ENUM_INT,
981 GTK_TYPE_MOVEMENT_STEP,
985 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
989 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
990 "toggle-cursor-item", 0);
991 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
992 "toggle-cursor-item", 0);
994 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
995 "activate-cursor-item", 0);
996 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
997 "activate-cursor-item", 0);
998 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
999 "activate-cursor-item", 0);
1000 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1001 "activate-cursor-item", 0);
1002 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1003 "activate-cursor-item", 0);
1005 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1006 GTK_MOVEMENT_DISPLAY_LINES, -1);
1007 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1008 GTK_MOVEMENT_DISPLAY_LINES, -1);
1010 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1011 GTK_MOVEMENT_DISPLAY_LINES, 1);
1012 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1013 GTK_MOVEMENT_DISPLAY_LINES, 1);
1015 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1016 GTK_MOVEMENT_DISPLAY_LINES, -1);
1018 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1019 GTK_MOVEMENT_DISPLAY_LINES, 1);
1021 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1022 GTK_MOVEMENT_BUFFER_ENDS, -1);
1023 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1024 GTK_MOVEMENT_BUFFER_ENDS, -1);
1026 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1027 GTK_MOVEMENT_BUFFER_ENDS, 1);
1028 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1029 GTK_MOVEMENT_BUFFER_ENDS, 1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1032 GTK_MOVEMENT_PAGES, -1);
1033 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1034 GTK_MOVEMENT_PAGES, -1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1037 GTK_MOVEMENT_PAGES, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1039 GTK_MOVEMENT_PAGES, 1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1042 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1044 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1046 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1047 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1049 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1053 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1055 parent_buildable_iface = g_type_interface_peek_parent (iface);
1056 iface->add_child = _gtk_cell_layout_buildable_add_child;
1057 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1058 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1062 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1064 iface->get_area = gtk_icon_view_cell_layout_get_area;
1068 gtk_icon_view_init (GtkIconView *icon_view)
1070 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1072 GtkIconViewPrivate);
1074 icon_view->priv->width = 0;
1075 icon_view->priv->height = 0;
1076 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1077 icon_view->priv->pressed_button = -1;
1078 icon_view->priv->press_start_x = -1;
1079 icon_view->priv->press_start_y = -1;
1080 icon_view->priv->text_column = -1;
1081 icon_view->priv->markup_column = -1;
1082 icon_view->priv->pixbuf_column = -1;
1083 icon_view->priv->text_cell = NULL;
1084 icon_view->priv->pixbuf_cell = NULL;
1085 icon_view->priv->tooltip_column = -1;
1087 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1089 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1091 icon_view->priv->columns = -1;
1092 icon_view->priv->item_width = -1;
1093 icon_view->priv->spacing = 0;
1094 icon_view->priv->row_spacing = 6;
1095 icon_view->priv->column_spacing = 6;
1096 icon_view->priv->margin = 6;
1097 icon_view->priv->item_padding = 6;
1099 icon_view->priv->draw_focus = TRUE;
1101 icon_view->priv->row_contexts =
1102 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1105 /* GObject methods */
1107 gtk_icon_view_constructor (GType type,
1108 guint n_construct_properties,
1109 GObjectConstructParam *construct_properties)
1111 GtkIconView *icon_view;
1114 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1115 (type, n_construct_properties, construct_properties);
1117 icon_view = (GtkIconView *) object;
1119 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1125 gtk_icon_view_dispose (GObject *object)
1127 GtkIconView *icon_view;
1128 GtkIconViewPrivate *priv;
1130 icon_view = GTK_ICON_VIEW (object);
1131 priv = icon_view->priv;
1133 if (priv->cell_area_context)
1135 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1136 priv->context_changed_id = 0;
1138 g_object_unref (priv->cell_area_context);
1139 priv->cell_area_context = NULL;
1142 if (priv->row_contexts)
1144 g_ptr_array_free (priv->row_contexts, TRUE);
1145 priv->row_contexts = NULL;
1148 if (priv->cell_area)
1150 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1152 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1153 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1154 priv->add_editable_id = 0;
1155 priv->remove_editable_id = 0;
1157 g_object_unref (priv->cell_area);
1158 priv->cell_area = NULL;
1161 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1165 gtk_icon_view_set_property (GObject *object,
1167 const GValue *value,
1170 GtkIconView *icon_view;
1173 icon_view = GTK_ICON_VIEW (object);
1177 case PROP_SELECTION_MODE:
1178 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1180 case PROP_PIXBUF_COLUMN:
1181 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1183 case PROP_TEXT_COLUMN:
1184 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1186 case PROP_MARKUP_COLUMN:
1187 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1190 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1192 case PROP_ITEM_ORIENTATION:
1193 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1196 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1198 case PROP_ITEM_WIDTH:
1199 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1202 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1204 case PROP_ROW_SPACING:
1205 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1207 case PROP_COLUMN_SPACING:
1208 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1211 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1213 case PROP_REORDERABLE:
1214 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1217 case PROP_TOOLTIP_COLUMN:
1218 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1221 case PROP_ITEM_PADDING:
1222 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1225 case PROP_CELL_AREA:
1226 /* Construct-only, can only be assigned once */
1227 area = g_value_get_object (value);
1230 if (icon_view->priv->cell_area != NULL)
1232 g_warning ("cell-area has already been set, ignoring construct property");
1233 g_object_ref_sink (area);
1234 g_object_unref (area);
1237 gtk_icon_view_ensure_cell_area (icon_view, area);
1241 case PROP_HADJUSTMENT:
1242 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1244 case PROP_VADJUSTMENT:
1245 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1247 case PROP_HSCROLL_POLICY:
1248 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1249 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1251 case PROP_VSCROLL_POLICY:
1252 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1253 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1263 gtk_icon_view_get_property (GObject *object,
1268 GtkIconView *icon_view;
1270 icon_view = GTK_ICON_VIEW (object);
1274 case PROP_SELECTION_MODE:
1275 g_value_set_enum (value, icon_view->priv->selection_mode);
1277 case PROP_PIXBUF_COLUMN:
1278 g_value_set_int (value, icon_view->priv->pixbuf_column);
1280 case PROP_TEXT_COLUMN:
1281 g_value_set_int (value, icon_view->priv->text_column);
1283 case PROP_MARKUP_COLUMN:
1284 g_value_set_int (value, icon_view->priv->markup_column);
1287 g_value_set_object (value, icon_view->priv->model);
1289 case PROP_ITEM_ORIENTATION:
1290 g_value_set_enum (value, icon_view->priv->item_orientation);
1293 g_value_set_int (value, icon_view->priv->columns);
1295 case PROP_ITEM_WIDTH:
1296 g_value_set_int (value, icon_view->priv->item_width);
1299 g_value_set_int (value, icon_view->priv->spacing);
1301 case PROP_ROW_SPACING:
1302 g_value_set_int (value, icon_view->priv->row_spacing);
1304 case PROP_COLUMN_SPACING:
1305 g_value_set_int (value, icon_view->priv->column_spacing);
1308 g_value_set_int (value, icon_view->priv->margin);
1310 case PROP_REORDERABLE:
1311 g_value_set_boolean (value, icon_view->priv->reorderable);
1313 case PROP_TOOLTIP_COLUMN:
1314 g_value_set_int (value, icon_view->priv->tooltip_column);
1317 case PROP_ITEM_PADDING:
1318 g_value_set_int (value, icon_view->priv->item_padding);
1321 case PROP_CELL_AREA:
1322 g_value_set_object (value, icon_view->priv->cell_area);
1325 case PROP_HADJUSTMENT:
1326 g_value_set_object (value, icon_view->priv->hadjustment);
1328 case PROP_VADJUSTMENT:
1329 g_value_set_object (value, icon_view->priv->vadjustment);
1331 case PROP_HSCROLL_POLICY:
1332 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1334 case PROP_VSCROLL_POLICY:
1335 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1339 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1344 /* GtkWidget methods */
1346 gtk_icon_view_destroy (GtkWidget *widget)
1348 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1350 gtk_icon_view_set_model (icon_view, NULL);
1352 if (icon_view->priv->layout_idle_id != 0)
1354 g_source_remove (icon_view->priv->layout_idle_id);
1355 icon_view->priv->layout_idle_id = 0;
1358 if (icon_view->priv->scroll_to_path != NULL)
1360 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1361 icon_view->priv->scroll_to_path = NULL;
1364 remove_scroll_timeout (icon_view);
1366 if (icon_view->priv->hadjustment != NULL)
1368 g_object_unref (icon_view->priv->hadjustment);
1369 icon_view->priv->hadjustment = NULL;
1372 if (icon_view->priv->vadjustment != NULL)
1374 g_object_unref (icon_view->priv->vadjustment);
1375 icon_view->priv->vadjustment = NULL;
1378 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1382 gtk_icon_view_realize (GtkWidget *widget)
1384 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1385 GtkAllocation allocation;
1387 GdkWindowAttr attributes;
1388 gint attributes_mask;
1389 GtkStyleContext *context;
1391 gtk_widget_set_realized (widget, TRUE);
1393 gtk_widget_get_allocation (widget, &allocation);
1395 /* Make the main, clipping window */
1396 attributes.window_type = GDK_WINDOW_CHILD;
1397 attributes.x = allocation.x;
1398 attributes.y = allocation.y;
1399 attributes.width = allocation.width;
1400 attributes.height = allocation.height;
1401 attributes.wclass = GDK_INPUT_OUTPUT;
1402 attributes.visual = gtk_widget_get_visual (widget);
1403 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1405 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1407 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1408 &attributes, attributes_mask);
1409 gtk_widget_set_window (widget, window);
1410 gdk_window_set_user_data (window, widget);
1412 gtk_widget_get_allocation (widget, &allocation);
1414 /* Make the window for the icon view */
1417 attributes.width = MAX (icon_view->priv->width, allocation.width);
1418 attributes.height = MAX (icon_view->priv->height, allocation.height);
1419 attributes.event_mask = (GDK_EXPOSURE_MASK |
1421 GDK_POINTER_MOTION_MASK |
1422 GDK_BUTTON_PRESS_MASK |
1423 GDK_BUTTON_RELEASE_MASK |
1424 GDK_KEY_PRESS_MASK |
1425 GDK_KEY_RELEASE_MASK) |
1426 gtk_widget_get_events (widget);
1428 icon_view->priv->bin_window = gdk_window_new (window,
1429 &attributes, attributes_mask);
1430 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1432 context = gtk_widget_get_style_context (widget);
1434 gtk_style_context_save (context);
1435 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1436 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1437 gtk_style_context_restore (context);
1439 gdk_window_show (icon_view->priv->bin_window);
1443 gtk_icon_view_unrealize (GtkWidget *widget)
1445 GtkIconView *icon_view;
1447 icon_view = GTK_ICON_VIEW (widget);
1449 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1450 gdk_window_destroy (icon_view->priv->bin_window);
1451 icon_view->priv->bin_window = NULL;
1453 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1457 _gtk_icon_view_update_background (GtkIconView *icon_view)
1459 GtkWidget *widget = GTK_WIDGET (icon_view);
1461 if (gtk_widget_get_realized (widget))
1463 GtkStyleContext *context;
1465 context = gtk_widget_get_style_context (widget);
1467 gtk_style_context_save (context);
1468 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1470 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1471 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1473 gtk_style_context_restore (context);
1478 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1479 GtkStateFlags previous_state)
1481 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1482 gtk_widget_queue_draw (widget);
1486 gtk_icon_view_style_updated (GtkWidget *widget)
1488 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1490 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1491 gtk_widget_queue_resize (widget);
1495 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1499 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1503 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1507 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1511 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1515 for (list = icon_view->priv->children; list; list = list->next)
1517 GtkIconViewChild *child = list->data;
1519 /* totally ignore our child's requisition */
1520 gtk_widget_size_allocate (child->widget, &child->area);
1525 gtk_icon_view_size_allocate (GtkWidget *widget,
1526 GtkAllocation *allocation)
1528 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1530 gtk_widget_set_allocation (widget, allocation);
1532 if (gtk_widget_get_realized (widget))
1534 gdk_window_move_resize (gtk_widget_get_window (widget),
1535 allocation->x, allocation->y,
1536 allocation->width, allocation->height);
1537 gdk_window_resize (icon_view->priv->bin_window,
1538 MAX (icon_view->priv->width, allocation->width),
1539 MAX (icon_view->priv->height, allocation->height));
1542 gtk_icon_view_layout (icon_view);
1544 gtk_icon_view_allocate_children (icon_view);
1546 /* Delay signal emission */
1547 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1548 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1550 gtk_icon_view_set_hadjustment_values (icon_view);
1551 gtk_icon_view_set_vadjustment_values (icon_view);
1553 if (gtk_widget_get_realized (widget) &&
1554 icon_view->priv->scroll_to_path)
1557 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1558 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1559 icon_view->priv->scroll_to_path = NULL;
1561 gtk_icon_view_scroll_to_path (icon_view, path,
1562 icon_view->priv->scroll_to_use_align,
1563 icon_view->priv->scroll_to_row_align,
1564 icon_view->priv->scroll_to_col_align);
1565 gtk_tree_path_free (path);
1568 /* Emit any pending signals now */
1569 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1570 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1574 gtk_icon_view_draw (GtkWidget *widget,
1577 GtkIconView *icon_view;
1581 GtkIconViewDropPosition dest_pos;
1582 GtkIconViewItem *dest_item = NULL;
1584 icon_view = GTK_ICON_VIEW (widget);
1586 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1591 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1593 cairo_set_line_width (cr, 1.);
1595 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1599 dest_index = gtk_tree_path_get_indices (path)[0];
1600 gtk_tree_path_free (path);
1605 for (icons = icon_view->priv->items; icons; icons = icons->next)
1607 GtkIconViewItem *item = icons->data;
1608 GdkRectangle paint_area;
1610 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1611 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1612 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1613 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1617 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1620 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1622 gtk_icon_view_paint_item (icon_view, cr, item,
1623 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1624 icon_view->priv->draw_focus);
1626 if (dest_index == item->index)
1634 dest_pos != GTK_ICON_VIEW_NO_DROP)
1636 GtkStyleContext *context;
1637 GtkStateFlags state;
1638 GdkRectangle rect = { 0 };
1640 context = gtk_widget_get_style_context (widget);
1641 state = gtk_widget_get_state_flags (widget);
1645 case GTK_ICON_VIEW_DROP_INTO:
1646 rect = dest_item->cell_area;
1648 case GTK_ICON_VIEW_DROP_ABOVE:
1649 rect.x = dest_item->cell_area.x;
1650 rect.y = dest_item->cell_area.y - 1;
1651 rect.width = dest_item->cell_area.width;
1654 case GTK_ICON_VIEW_DROP_LEFT:
1655 rect.x = dest_item->cell_area.x - 1;
1656 rect.y = dest_item->cell_area.y;
1658 rect.height = dest_item->cell_area.height;
1660 case GTK_ICON_VIEW_DROP_BELOW:
1661 rect.x = dest_item->cell_area.x;
1662 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1663 rect.width = dest_item->cell_area.width;
1666 case GTK_ICON_VIEW_DROP_RIGHT:
1667 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1668 rect.y = dest_item->cell_area.y;
1670 rect.height = dest_item->cell_area.height;
1671 case GTK_ICON_VIEW_NO_DROP: ;
1675 gtk_style_context_set_state (context, state);
1676 gtk_render_focus (context, cr,
1678 rect.width, rect.height);
1681 if (icon_view->priv->doing_rubberband)
1682 gtk_icon_view_paint_rubberband (icon_view, cr);
1686 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1692 rubberband_scroll_timeout (gpointer data)
1694 GtkIconView *icon_view = data;
1696 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1697 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1698 icon_view->priv->scroll_value_diff);
1700 gtk_icon_view_update_rubberband (icon_view);
1706 gtk_icon_view_motion (GtkWidget *widget,
1707 GdkEventMotion *event)
1709 GtkAllocation allocation;
1710 GtkIconView *icon_view;
1713 icon_view = GTK_ICON_VIEW (widget);
1715 gtk_icon_view_maybe_begin_drag (icon_view, event);
1717 if (icon_view->priv->doing_rubberband)
1719 gtk_icon_view_update_rubberband (widget);
1721 abs_y = event->y - icon_view->priv->height *
1722 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1723 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1724 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1726 gtk_widget_get_allocation (widget, &allocation);
1728 if (abs_y < 0 || abs_y > allocation.height)
1731 icon_view->priv->scroll_value_diff = abs_y;
1733 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1735 icon_view->priv->event_last_x = event->x;
1736 icon_view->priv->event_last_y = event->y;
1738 if (icon_view->priv->scroll_timeout_id == 0)
1739 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1743 remove_scroll_timeout (icon_view);
1750 gtk_icon_view_remove (GtkContainer *container,
1753 GtkIconView *icon_view;
1754 GtkIconViewChild *child = NULL;
1757 icon_view = GTK_ICON_VIEW (container);
1759 tmp_list = icon_view->priv->children;
1762 child = tmp_list->data;
1763 if (child->widget == widget)
1765 gtk_widget_unparent (widget);
1767 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1768 g_list_free_1 (tmp_list);
1773 tmp_list = tmp_list->next;
1778 gtk_icon_view_forall (GtkContainer *container,
1779 gboolean include_internals,
1780 GtkCallback callback,
1781 gpointer callback_data)
1783 GtkIconView *icon_view;
1784 GtkIconViewChild *child = NULL;
1787 icon_view = GTK_ICON_VIEW (container);
1789 tmp_list = icon_view->priv->children;
1792 child = tmp_list->data;
1793 tmp_list = tmp_list->next;
1795 (* callback) (child->widget, callback_data);
1800 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1801 GtkIconViewItem *item)
1804 AtkObject *item_obj;
1806 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1809 item_obj = atk_object_ref_accessible_child (obj, item->index);
1810 if (item_obj != NULL)
1812 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1813 g_object_unref (item_obj);
1819 gtk_icon_view_add_editable (GtkCellArea *area,
1820 GtkCellRenderer *renderer,
1821 GtkCellEditable *editable,
1822 GdkRectangle *cell_area,
1824 GtkIconView *icon_view)
1826 GtkIconViewChild *child;
1827 GtkWidget *widget = GTK_WIDGET (editable);
1829 child = g_new (GtkIconViewChild, 1);
1831 child->widget = widget;
1832 child->area.x = cell_area->x;
1833 child->area.y = cell_area->y;
1834 child->area.width = cell_area->width;
1835 child->area.height = cell_area->height;
1837 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1839 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1840 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1842 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1846 gtk_icon_view_remove_editable (GtkCellArea *area,
1847 GtkCellRenderer *renderer,
1848 GtkCellEditable *editable,
1849 GtkIconView *icon_view)
1853 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1854 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1856 gtk_container_remove (GTK_CONTAINER (icon_view),
1857 GTK_WIDGET (editable));
1859 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1860 gtk_icon_view_queue_draw_path (icon_view, path);
1861 gtk_tree_path_free (path);
1865 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1867 GtkIconView *icon_view)
1869 if (!strcmp (pspec->name, "minimum-width") ||
1870 !strcmp (pspec->name, "natural-width") ||
1871 !strcmp (pspec->name, "minimum-height") ||
1872 !strcmp (pspec->name, "natural-height"))
1873 gtk_icon_view_invalidate_sizes (icon_view);
1877 * gtk_icon_view_set_cursor:
1878 * @icon_view: A #GtkIconView
1879 * @path: A #GtkTreePath
1880 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1881 * @start_editing: %TRUE if the specified cell should start being edited.
1883 * Sets the current keyboard focus to be at @path, and selects it. This is
1884 * useful when you want to focus the user's attention on a particular item.
1885 * If @cell is not %NULL, then focus is given to the cell specified by
1886 * it. Additionally, if @start_editing is %TRUE, then editing should be
1887 * started in the specified cell.
1889 * This function is often followed by <literal>gtk_widget_grab_focus
1890 * (icon_view)</literal> in order to give keyboard focus to the widget.
1891 * Please note that editing can only happen when the widget is realized.
1896 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1898 GtkCellRenderer *cell,
1899 gboolean start_editing)
1901 GtkIconViewItem *item = NULL;
1903 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1904 g_return_if_fail (path != NULL);
1905 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1907 if (icon_view->priv->cell_area)
1908 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1910 if (gtk_tree_path_get_depth (path) == 1)
1911 item = g_list_nth_data (icon_view->priv->items,
1912 gtk_tree_path_get_indices(path)[0]);
1917 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1918 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1920 if (start_editing &&
1921 icon_view->priv->cell_area)
1923 GtkCellAreaContext *context;
1925 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1926 gtk_icon_view_set_cell_data (icon_view, item);
1927 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1928 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1929 0 /* XXX flags */, TRUE);
1934 * gtk_icon_view_get_cursor:
1935 * @icon_view: A #GtkIconView
1936 * @path: (out) (allow-none): Return location for the current cursor path,
1938 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1940 * Fills in @path and @cell with the current cursor path and cell.
1941 * If the cursor isn't currently set, then *@path will be %NULL.
1942 * If no cell currently has focus, then *@cell will be %NULL.
1944 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1946 * Return value: %TRUE if the cursor is set.
1951 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1953 GtkCellRenderer **cell)
1955 GtkIconViewItem *item;
1957 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1959 item = icon_view->priv->cursor_item;
1964 *path = gtk_tree_path_new_from_indices (item->index, -1);
1969 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1970 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1972 return (item != NULL);
1976 gtk_icon_view_button_press (GtkWidget *widget,
1977 GdkEventButton *event)
1979 GtkIconView *icon_view;
1980 GtkIconViewItem *item;
1981 gboolean dirty = FALSE;
1982 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1984 icon_view = GTK_ICON_VIEW (widget);
1986 if (event->window != icon_view->priv->bin_window)
1989 if (!gtk_widget_has_focus (widget))
1990 gtk_widget_grab_focus (widget);
1992 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1994 item = gtk_icon_view_get_item_at_coords (icon_view,
2000 * We consider only the the cells' area as the item area if the
2001 * item is not selected, but if it *is* selected, the complete
2002 * selection rectangle is considered to be part of the item.
2004 if (item != NULL && (cell != NULL || item->selected))
2008 if (gtk_cell_renderer_is_activatable (cell))
2012 gtk_icon_view_scroll_to_item (icon_view, item);
2014 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2016 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2018 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2019 (event->state & GDK_SHIFT_MASK))
2021 gtk_icon_view_unselect_all_internal (icon_view);
2023 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2024 if (!icon_view->priv->anchor_item)
2025 icon_view->priv->anchor_item = item;
2027 gtk_icon_view_select_all_between (icon_view,
2028 icon_view->priv->anchor_item,
2034 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2035 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2036 (event->state & GDK_CONTROL_MASK))
2038 item->selected = !item->selected;
2039 gtk_icon_view_queue_draw_item (icon_view, item);
2044 gtk_icon_view_unselect_all_internal (icon_view);
2046 item->selected = TRUE;
2047 gtk_icon_view_queue_draw_item (icon_view, item);
2050 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2051 icon_view->priv->anchor_item = item;
2054 /* Save press to possibly begin a drag */
2055 if (icon_view->priv->pressed_button < 0)
2057 icon_view->priv->pressed_button = event->button;
2058 icon_view->priv->press_start_x = event->x;
2059 icon_view->priv->press_start_y = event->y;
2062 if (!icon_view->priv->last_single_clicked)
2063 icon_view->priv->last_single_clicked = item;
2065 /* cancel the current editing, if it exists */
2066 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2068 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2070 GtkCellAreaContext *context;
2072 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2074 gtk_icon_view_set_cell_data (icon_view, item);
2075 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2076 GTK_WIDGET (icon_view),
2077 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2082 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2083 !(event->state & GDK_CONTROL_MASK))
2085 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2088 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2089 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2092 /* don't draw keyboard focus around an clicked-on item */
2093 icon_view->priv->draw_focus = FALSE;
2096 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2098 item = gtk_icon_view_get_item_at_coords (icon_view,
2103 if (item && item == icon_view->priv->last_single_clicked)
2107 path = gtk_tree_path_new_from_indices (item->index, -1);
2108 gtk_icon_view_item_activated (icon_view, path);
2109 gtk_tree_path_free (path);
2112 icon_view->priv->last_single_clicked = NULL;
2113 icon_view->priv->pressed_button = -1;
2117 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2119 return event->button == 1;
2123 gtk_icon_view_button_release (GtkWidget *widget,
2124 GdkEventButton *event)
2126 GtkIconView *icon_view;
2128 icon_view = GTK_ICON_VIEW (widget);
2130 if (icon_view->priv->pressed_button == event->button)
2131 icon_view->priv->pressed_button = -1;
2133 gtk_icon_view_stop_rubberbanding (icon_view);
2135 remove_scroll_timeout (icon_view);
2141 gtk_icon_view_key_press (GtkWidget *widget,
2144 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2146 if (icon_view->priv->doing_rubberband)
2148 if (event->keyval == GDK_KEY_Escape)
2149 gtk_icon_view_stop_rubberbanding (icon_view);
2154 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2158 gtk_icon_view_key_release (GtkWidget *widget,
2161 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2163 if (icon_view->priv->doing_rubberband)
2166 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2170 gtk_icon_view_update_rubberband (gpointer data)
2172 GtkIconView *icon_view;
2174 GdkRectangle old_area;
2175 GdkRectangle new_area;
2176 GdkRectangle common;
2177 cairo_region_t *invalid_region;
2179 icon_view = GTK_ICON_VIEW (data);
2181 gdk_window_get_device_position (icon_view->priv->bin_window,
2182 icon_view->priv->rubberband_device,
2188 old_area.x = MIN (icon_view->priv->rubberband_x1,
2189 icon_view->priv->rubberband_x2);
2190 old_area.y = MIN (icon_view->priv->rubberband_y1,
2191 icon_view->priv->rubberband_y2);
2192 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2193 icon_view->priv->rubberband_x1) + 1;
2194 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2195 icon_view->priv->rubberband_y1) + 1;
2197 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2198 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2199 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2200 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2202 invalid_region = cairo_region_create_rectangle (&old_area);
2203 cairo_region_union_rectangle (invalid_region, &new_area);
2205 gdk_rectangle_intersect (&old_area, &new_area, &common);
2206 if (common.width > 2 && common.height > 2)
2208 cairo_region_t *common_region;
2210 /* make sure the border is invalidated */
2216 common_region = cairo_region_create_rectangle (&common);
2218 cairo_region_subtract (invalid_region, common_region);
2219 cairo_region_destroy (common_region);
2222 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2224 cairo_region_destroy (invalid_region);
2226 icon_view->priv->rubberband_x2 = x;
2227 icon_view->priv->rubberband_y2 = y;
2229 gtk_icon_view_update_rubberband_selection (icon_view);
2233 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2240 if (icon_view->priv->rubberband_device)
2243 for (items = icon_view->priv->items; items; items = items->next)
2245 GtkIconViewItem *item = items->data;
2247 item->selected_before_rubberbanding = item->selected;
2250 icon_view->priv->rubberband_x1 = x;
2251 icon_view->priv->rubberband_y1 = y;
2252 icon_view->priv->rubberband_x2 = x;
2253 icon_view->priv->rubberband_y2 = y;
2255 icon_view->priv->doing_rubberband = TRUE;
2256 icon_view->priv->rubberband_device = device;
2258 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2262 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2264 if (!icon_view->priv->doing_rubberband)
2267 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2268 icon_view->priv->rubberband_device);
2270 icon_view->priv->doing_rubberband = FALSE;
2271 icon_view->priv->rubberband_device = NULL;
2273 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2277 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2280 gint x, y, width, height;
2281 gboolean dirty = FALSE;
2283 x = MIN (icon_view->priv->rubberband_x1,
2284 icon_view->priv->rubberband_x2);
2285 y = MIN (icon_view->priv->rubberband_y1,
2286 icon_view->priv->rubberband_y2);
2287 width = ABS (icon_view->priv->rubberband_x1 -
2288 icon_view->priv->rubberband_x2);
2289 height = ABS (icon_view->priv->rubberband_y1 -
2290 icon_view->priv->rubberband_y2);
2292 for (items = icon_view->priv->items; items; items = items->next)
2294 GtkIconViewItem *item = items->data;
2298 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2299 x, y, width, height);
2301 selected = is_in ^ item->selected_before_rubberbanding;
2303 if (item->selected != selected)
2305 item->selected = selected;
2307 gtk_icon_view_queue_draw_item (icon_view, item);
2312 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2317 GdkRectangle hit_rect;
2322 hit_test (GtkCellRenderer *renderer,
2323 const GdkRectangle *cell_area,
2324 const GdkRectangle *cell_background,
2327 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2328 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2329 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2330 MAX (data->hit_rect.y, cell_area->y) > 0)
2333 return (data->hit != FALSE);
2337 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2338 GtkIconViewItem *item,
2344 HitTestData data = { { x, y, width, height }, FALSE };
2345 GtkCellAreaContext *context;
2346 GdkRectangle *item_area = (GdkRectangle *)item;
2348 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2349 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2352 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2354 gtk_icon_view_set_cell_data (icon_view, item);
2355 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2356 GTK_WIDGET (icon_view),
2357 item_area, item_area,
2358 (GtkCellAllocCallback)hit_test, &data);
2364 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2366 gboolean dirty = FALSE;
2369 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2372 for (items = icon_view->priv->items; items; items = items->next)
2374 GtkIconViewItem *item = items->data;
2378 item->selected = FALSE;
2380 gtk_icon_view_queue_draw_item (icon_view, item);
2381 gtk_icon_view_item_selected_changed (icon_view, item);
2389 /* GtkIconView signals */
2391 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2393 gtk_icon_view_select_all (icon_view);
2397 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2399 gtk_icon_view_unselect_all (icon_view);
2403 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2405 gtk_icon_view_unselect_all (icon_view);
2407 if (icon_view->priv->cursor_item != NULL)
2408 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2412 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2415 GtkCellAreaContext *context;
2417 if (!icon_view->priv->cursor_item)
2420 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2422 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2423 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2424 GTK_WIDGET (icon_view),
2425 (GdkRectangle *)icon_view->priv->cursor_item,
2429 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2430 gtk_icon_view_item_activated (icon_view, path);
2431 gtk_tree_path_free (path);
2437 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2439 if (!icon_view->priv->cursor_item)
2442 switch (icon_view->priv->selection_mode)
2444 case GTK_SELECTION_NONE:
2446 case GTK_SELECTION_BROWSE:
2447 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2449 case GTK_SELECTION_SINGLE:
2450 if (icon_view->priv->cursor_item->selected)
2451 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2453 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2455 case GTK_SELECTION_MULTIPLE:
2456 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2457 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2459 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2460 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2465 /* Internal functions */
2467 gtk_icon_view_process_updates (GtkIconView *icon_view)
2469 /* Prior to drawing, we check if a layout has been scheduled. If so,
2470 * do it now that all cell view items have valid sizes before we proceeed
2471 * (and resize the bin_window if required).
2473 if (icon_view->priv->layout_idle_id != 0)
2474 gtk_icon_view_layout (icon_view);
2476 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2480 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2482 GtkAllocation allocation;
2483 GtkAdjustment *adj = icon_view->priv->hadjustment;
2484 gdouble old_page_size;
2490 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2492 old_value = gtk_adjustment_get_value (adj);
2493 old_upper = gtk_adjustment_get_upper (adj);
2494 old_page_size = gtk_adjustment_get_page_size (adj);
2495 new_upper = MAX (allocation.width, icon_view->priv->width);
2497 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2499 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2500 /* Quick explanation:
2501 * In LTR locales, leftmost portion of visible rectangle should stay
2502 * fixed, which means left edge of scrollbar thumb should remain fixed
2503 * and thus adjustment's value should stay the same.
2505 * In RTL locales, we want to keep rightmost portion of visible
2506 * rectangle fixed. This means right edge of thumb should remain fixed.
2507 * In this case, upper - value - page_size should remain constant.
2509 new_value = (new_upper - allocation.width) -
2510 (old_upper - old_value - old_page_size);
2511 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2514 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2516 gtk_adjustment_configure (adj,
2520 allocation.width * 0.1,
2521 allocation.width * 0.9,
2526 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2528 GtkAllocation allocation;
2529 GtkAdjustment *adj = icon_view->priv->vadjustment;
2531 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2533 gtk_adjustment_configure (adj,
2534 gtk_adjustment_get_value (adj),
2536 MAX (allocation.height, icon_view->priv->height),
2537 allocation.height * 0.1,
2538 allocation.height * 0.9,
2543 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2544 GtkAdjustment *adjustment)
2546 GtkIconViewPrivate *priv = icon_view->priv;
2549 if (adjustment && priv->hadjustment == adjustment)
2552 if (priv->hadjustment != NULL)
2554 g_signal_handlers_disconnect_matched (priv->hadjustment,
2555 G_SIGNAL_MATCH_DATA,
2556 0, 0, NULL, NULL, icon_view);
2557 g_object_unref (priv->hadjustment);
2561 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2564 g_signal_connect (adjustment, "value-changed",
2565 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2566 priv->hadjustment = g_object_ref_sink (adjustment);
2567 gtk_icon_view_set_hadjustment_values (icon_view);
2569 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2570 gtk_icon_view_accessible_set_adjustment (atk_obj,
2571 GTK_ORIENTATION_HORIZONTAL,
2574 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2578 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2579 GtkAdjustment *adjustment)
2581 GtkIconViewPrivate *priv = icon_view->priv;
2584 if (adjustment && priv->vadjustment == adjustment)
2587 if (priv->vadjustment != NULL)
2589 g_signal_handlers_disconnect_matched (priv->vadjustment,
2590 G_SIGNAL_MATCH_DATA,
2591 0, 0, NULL, NULL, icon_view);
2592 g_object_unref (priv->vadjustment);
2596 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2599 g_signal_connect (adjustment, "value-changed",
2600 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2601 priv->vadjustment = g_object_ref_sink (adjustment);
2602 gtk_icon_view_set_vadjustment_values (icon_view);
2604 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2605 gtk_icon_view_accessible_set_adjustment (atk_obj,
2606 GTK_ORIENTATION_VERTICAL,
2609 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2613 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2614 GtkIconView *icon_view)
2616 GtkIconViewPrivate *priv = icon_view->priv;
2618 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2620 gdk_window_move (priv->bin_window,
2621 - gtk_adjustment_get_value (priv->hadjustment),
2622 - gtk_adjustment_get_value (priv->vadjustment));
2624 if (icon_view->priv->doing_rubberband)
2625 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2627 gtk_icon_view_process_updates (icon_view);
2632 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2637 gint *maximum_width)
2639 GtkAllocation allocation;
2640 GtkCellAreaContext *context;
2641 GtkIconViewPrivate *priv = icon_view->priv;
2642 GtkWidget *widget = GTK_WIDGET (icon_view);
2643 gint x, current_width;
2644 GList *items, *last_item;
2646 gint max_height = 0;
2649 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2657 current_width += 2 * priv->margin;
2659 gtk_widget_get_allocation (widget, &allocation);
2661 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2662 g_ptr_array_add (priv->row_contexts, context);
2664 /* In the first loop we iterate horizontally until we hit allocation width
2665 * and collect the aligned height-for-width */
2669 GtkIconViewItem *item = items->data;
2670 GdkRectangle *item_area = (GdkRectangle *)item;
2672 item_area->width = item_width;
2674 current_width += item_area->width + icon_view->priv->item_padding * 2;
2676 if (items != first_item)
2678 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2679 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2683 /* Get this item's particular width & height (all alignments are cached by now) */
2684 gtk_icon_view_set_cell_data (icon_view, item);
2685 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2690 current_width += icon_view->priv->column_spacing;
2692 item_area->y = *y + icon_view->priv->item_padding;
2693 item_area->x = x + icon_view->priv->item_padding;
2695 x = current_width - icon_view->priv->margin;
2697 if (current_width > *maximum_width)
2698 *maximum_width = current_width;
2704 items = items->next;
2709 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2710 gtk_cell_area_context_allocate (context, item_width, max_height);
2712 /* In the second loop the item height has been aligned and derived and
2713 * we just set the height and handle rtl layout */
2714 for (items = first_item; items != last_item; items = items->next)
2716 GtkIconViewItem *item = items->data;
2717 GdkRectangle *item_area = (GdkRectangle *)item;
2721 item_area->x = *maximum_width - item_area->width - item_area->x;
2722 item->col = col - 1 - item->col;
2725 /* All items in the same row get the same height */
2726 item_area->height = max_height;
2729 /* Adjust the new y coordinate. */
2730 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2736 adjust_wrap_width (GtkIconView *icon_view)
2738 if (icon_view->priv->text_cell)
2740 gint wrap_width = 50;
2742 /* Here we go with the same old guess, try the icon size and set double
2743 * the size of the first icon found in the list, naive but works much
2745 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2747 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2748 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2749 GTK_WIDGET (icon_view),
2752 wrap_width = MAX (wrap_width * 2, 50);
2755 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2756 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2761 gtk_icon_view_layout (GtkIconView *icon_view)
2763 GtkAllocation allocation;
2766 gint y = 0, maximum_width = 0;
2769 gboolean size_changed = FALSE;
2771 if (icon_view->priv->layout_idle_id != 0)
2773 g_source_remove (icon_view->priv->layout_idle_id);
2774 icon_view->priv->layout_idle_id = 0;
2777 if (icon_view->priv->model == NULL)
2780 widget = GTK_WIDGET (icon_view);
2782 item_width = icon_view->priv->item_width;
2784 /* Update the wrap width for the text cell before going and requesting sizes */
2785 adjust_wrap_width (icon_view);
2787 /* Update the context widths for any invalidated items */
2788 gtk_icon_view_cache_widths (icon_view);
2790 /* Fetch the new item width if needed */
2792 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2795 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2797 icons = icon_view->priv->items;
2798 y += icon_view->priv->margin;
2801 /* Clear the per row contexts */
2802 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2806 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2808 &y, &maximum_width);
2811 while (icons != NULL);
2813 if (maximum_width != icon_view->priv->width)
2815 icon_view->priv->width = maximum_width;
2816 size_changed = TRUE;
2819 y += icon_view->priv->margin;
2821 if (y != icon_view->priv->height)
2823 icon_view->priv->height = y;
2824 size_changed = TRUE;
2827 gtk_icon_view_set_hadjustment_values (icon_view);
2828 gtk_icon_view_set_vadjustment_values (icon_view);
2831 gtk_widget_queue_resize_no_redraw (widget);
2833 gtk_widget_get_allocation (widget, &allocation);
2834 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2835 gdk_window_resize (icon_view->priv->bin_window,
2836 MAX (icon_view->priv->width, allocation.width),
2837 MAX (icon_view->priv->height, allocation.height));
2839 if (icon_view->priv->scroll_to_path)
2843 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2844 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2845 icon_view->priv->scroll_to_path = NULL;
2847 gtk_icon_view_scroll_to_path (icon_view, path,
2848 icon_view->priv->scroll_to_use_align,
2849 icon_view->priv->scroll_to_row_align,
2850 icon_view->priv->scroll_to_col_align);
2851 gtk_tree_path_free (path);
2854 gtk_widget_queue_draw (widget);
2857 /* This ensures that all widths have been cached in the
2858 * context and we have proper alignments to go on.
2861 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2865 g_signal_handler_block (icon_view->priv->cell_area_context,
2866 icon_view->priv->context_changed_id);
2868 for (items = icon_view->priv->items; items; items = items->next)
2870 GtkIconViewItem *item = items->data;
2872 /* Only fetch the width of items with invalidated sizes */
2873 if (item->cell_area.width < 0)
2875 gtk_icon_view_set_cell_data (icon_view, item);
2876 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2877 icon_view->priv->cell_area_context,
2878 GTK_WIDGET (icon_view), NULL, NULL);
2882 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2883 icon_view->priv->context_changed_id);
2887 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2889 /* Clear all item sizes */
2890 g_list_foreach (icon_view->priv->items,
2891 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2893 /* Reset the context */
2894 if (icon_view->priv->cell_area_context)
2896 g_signal_handler_block (icon_view->priv->cell_area_context,
2897 icon_view->priv->context_changed_id);
2898 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2899 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2900 icon_view->priv->context_changed_id);
2903 /* Re-layout the items */
2904 gtk_icon_view_queue_layout (icon_view);
2908 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2910 item->cell_area.width = -1;
2911 item->cell_area.height = -1;
2915 gtk_icon_view_paint_item (GtkIconView *icon_view,
2917 GtkIconViewItem *item,
2920 gboolean draw_focus)
2922 GdkRectangle cell_area;
2923 GtkStateFlags state = 0;
2924 GtkCellRendererState flags = 0;
2925 GtkStyleContext *style_context;
2926 GtkWidget *widget = GTK_WIDGET (icon_view);
2927 GtkIconViewPrivate *priv = icon_view->priv;
2928 GtkCellAreaContext *context;
2930 if (priv->model == NULL)
2933 gtk_icon_view_set_cell_data (icon_view, item);
2935 style_context = gtk_widget_get_style_context (widget);
2937 gtk_style_context_save (style_context);
2938 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2939 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2943 if (gtk_widget_has_focus (widget) &&
2944 item == icon_view->priv->cursor_item)
2946 state |= GTK_STATE_FLAG_FOCUSED;
2947 flags |= GTK_CELL_RENDERER_FOCUSED;
2950 state |= GTK_STATE_FLAG_SELECTED;
2951 flags |= GTK_CELL_RENDERER_SELECTED;
2953 gtk_style_context_set_state (style_context, state);
2954 gtk_render_background (style_context, cr,
2955 x - icon_view->priv->item_padding,
2956 y - icon_view->priv->item_padding,
2957 item->cell_area.width + icon_view->priv->item_padding * 2,
2958 item->cell_area.height + icon_view->priv->item_padding * 2);
2963 cell_area.width = item->cell_area.width;
2964 cell_area.height = item->cell_area.height;
2966 context = g_ptr_array_index (priv->row_contexts, item->row);
2967 gtk_cell_area_render (priv->cell_area, context,
2968 widget, cr, &cell_area, &cell_area, flags,
2971 gtk_style_context_restore (style_context);
2975 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2978 GtkStyleContext *context;
2983 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2984 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2985 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2986 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2988 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2990 gtk_style_context_save (context);
2991 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2993 gdk_cairo_rectangle (cr, &rect);
2996 gtk_render_background (context, cr,
2998 rect.width, rect.height);
2999 gtk_render_frame (context, cr,
3001 rect.width, rect.height);
3003 gtk_style_context_restore (context);
3008 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3014 index = gtk_tree_path_get_indices (path)[0];
3016 for (l = icon_view->priv->items; l; l = l->next)
3018 GtkIconViewItem *item = l->data;
3020 if (item->index == index)
3022 gtk_icon_view_queue_draw_item (icon_view, item);
3029 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3030 GtkIconViewItem *item)
3033 GdkRectangle *item_area = (GdkRectangle *)item;
3035 rect.x = item_area->x - icon_view->priv->item_padding;
3036 rect.y = item_area->y - icon_view->priv->item_padding;
3037 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3038 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3040 if (icon_view->priv->bin_window)
3041 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3045 layout_callback (gpointer user_data)
3047 GtkIconView *icon_view;
3049 icon_view = GTK_ICON_VIEW (user_data);
3051 icon_view->priv->layout_idle_id = 0;
3053 gtk_icon_view_layout (icon_view);
3059 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3061 if (icon_view->priv->layout_idle_id != 0)
3064 icon_view->priv->layout_idle_id =
3065 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3066 layout_callback, icon_view, NULL);
3070 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3071 GtkIconViewItem *item,
3072 GtkCellRenderer *cursor_cell)
3075 AtkObject *item_obj;
3076 AtkObject *cursor_item_obj;
3078 /* When hitting this path from keynav, the focus cell is
3079 * already set, we dont need to notify the atk object
3080 * but we still need to queue the draw here (in the case
3081 * that the focus cell changes but not the cursor item).
3083 gtk_icon_view_queue_draw_item (icon_view, item);
3085 if (icon_view->priv->cursor_item == item &&
3086 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3089 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3090 if (icon_view->priv->cursor_item != NULL)
3092 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3095 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3096 if (cursor_item_obj != NULL)
3097 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3100 icon_view->priv->cursor_item = item;
3103 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3106 /* Make sure there is a cell in focus initially */
3107 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3108 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3111 /* Notify that accessible focus object has changed */
3112 item_obj = atk_object_ref_accessible_child (obj, item->index);
3114 if (item_obj != NULL)
3116 atk_focus_tracker_notify (item_obj);
3117 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3118 g_object_unref (item_obj);
3123 static GtkIconViewItem *
3124 gtk_icon_view_item_new (void)
3126 GtkIconViewItem *item;
3128 item = g_slice_new0 (GtkIconViewItem);
3130 item->cell_area.width = -1;
3131 item->cell_area.height = -1;
3137 gtk_icon_view_item_free (GtkIconViewItem *item)
3139 g_return_if_fail (item != NULL);
3141 g_slice_free (GtkIconViewItem, item);
3144 static GtkIconViewItem *
3145 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3148 gboolean only_in_cell,
3149 GtkCellRenderer **cell_at_pos)
3154 *cell_at_pos = NULL;
3156 for (items = icon_view->priv->items; items; items = items->next)
3158 GtkIconViewItem *item = items->data;
3159 GdkRectangle *item_area = (GdkRectangle *)item;
3161 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3162 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3163 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3164 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3166 if (only_in_cell || cell_at_pos)
3168 GtkCellRenderer *cell = NULL;
3169 GtkCellAreaContext *context;
3171 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3172 gtk_icon_view_set_cell_data (icon_view, item);
3174 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3175 y >= item_area->y && y <= item_area->y + item_area->height)
3176 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3177 GTK_WIDGET (icon_view),
3182 *cell_at_pos = cell;
3185 return cell != NULL ? item : NULL;
3196 gtk_icon_view_select_item (GtkIconView *icon_view,
3197 GtkIconViewItem *item)
3199 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3200 g_return_if_fail (item != NULL);
3205 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3207 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3208 gtk_icon_view_unselect_all_internal (icon_view);
3210 item->selected = TRUE;
3212 gtk_icon_view_item_selected_changed (icon_view, item);
3213 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3215 gtk_icon_view_queue_draw_item (icon_view, item);
3220 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3221 GtkIconViewItem *item)
3223 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3224 g_return_if_fail (item != NULL);
3226 if (!item->selected)
3229 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3230 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3233 item->selected = FALSE;
3235 gtk_icon_view_item_selected_changed (icon_view, item);
3236 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3238 gtk_icon_view_queue_draw_item (icon_view, item);
3242 verify_items (GtkIconView *icon_view)
3247 for (items = icon_view->priv->items; items; items = items->next)
3249 GtkIconViewItem *item = items->data;
3251 if (item->index != i)
3252 g_error ("List item does not match its index: "
3253 "item index %d and list index %d\n", item->index, i);
3260 gtk_icon_view_row_changed (GtkTreeModel *model,
3265 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3267 /* ignore changes in branches */
3268 if (gtk_tree_path_get_depth (path) > 1)
3271 /* An icon view subclass might add it's own model and populate
3272 * things at init() time instead of waiting for the constructor()
3275 if (icon_view->priv->cell_area)
3276 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3278 /* Here we can use a "grow-only" strategy for optimization
3279 * and only invalidate a single item and queue a relayout
3280 * instead of invalidating the whole thing.
3282 * For now GtkIconView still cant deal with huge models
3283 * so just invalidate the whole thing when the model
3286 gtk_icon_view_invalidate_sizes (icon_view);
3288 verify_items (icon_view);
3292 gtk_icon_view_row_inserted (GtkTreeModel *model,
3297 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3299 GtkIconViewItem *item;
3300 gboolean iters_persist;
3303 /* ignore changes in branches */
3304 if (gtk_tree_path_get_depth (path) > 1)
3307 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3309 index = gtk_tree_path_get_indices(path)[0];
3311 item = gtk_icon_view_item_new ();
3316 item->index = index;
3318 /* FIXME: We can be more efficient here,
3319 we can store a tail pointer and use that when
3320 appending (which is a rather common operation)
3322 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3325 list = g_list_nth (icon_view->priv->items, index + 1);
3326 for (; list; list = list->next)
3333 verify_items (icon_view);
3335 gtk_icon_view_queue_layout (icon_view);
3339 gtk_icon_view_row_deleted (GtkTreeModel *model,
3343 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3345 GtkIconViewItem *item;
3347 gboolean emit = FALSE;
3349 /* ignore changes in branches */
3350 if (gtk_tree_path_get_depth (path) > 1)
3353 index = gtk_tree_path_get_indices(path)[0];
3355 list = g_list_nth (icon_view->priv->items, index);
3358 if (icon_view->priv->cell_area)
3359 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3361 if (item == icon_view->priv->anchor_item)
3362 icon_view->priv->anchor_item = NULL;
3364 if (item == icon_view->priv->cursor_item)
3365 icon_view->priv->cursor_item = NULL;
3370 gtk_icon_view_item_free (item);
3372 for (next = list->next; next; next = next->next)
3379 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3381 verify_items (icon_view);
3383 gtk_icon_view_queue_layout (icon_view);
3386 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3390 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3391 GtkTreePath *parent,
3396 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3399 GList *items = NULL, *list;
3400 GtkIconViewItem **item_array;
3403 /* ignore changes in branches */
3407 if (icon_view->priv->cell_area)
3408 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3410 length = gtk_tree_model_iter_n_children (model, NULL);
3412 order = g_new (gint, length);
3413 for (i = 0; i < length; i++)
3414 order [new_order[i]] = i;
3416 item_array = g_new (GtkIconViewItem *, length);
3417 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3418 item_array[order[i]] = list->data;
3421 for (i = length - 1; i >= 0; i--)
3423 item_array[i]->index = i;
3424 items = g_list_prepend (items, item_array[i]);
3427 g_free (item_array);
3428 g_list_free (icon_view->priv->items);
3429 icon_view->priv->items = items;
3431 gtk_icon_view_queue_layout (icon_view);
3433 verify_items (icon_view);
3437 gtk_icon_view_build_items (GtkIconView *icon_view)
3441 gboolean iters_persist;
3442 GList *items = NULL;
3444 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3446 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3454 GtkIconViewItem *item = gtk_icon_view_item_new ();
3463 items = g_list_prepend (items, item);
3465 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3467 icon_view->priv->items = g_list_reverse (items);
3471 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3474 GtkMovementStep step,
3478 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3479 I_("move-cursor"), 2,
3483 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3488 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3491 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3496 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3503 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3504 GtkMovementStep step,
3507 GdkModifierType state;
3509 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3510 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3511 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3512 step == GTK_MOVEMENT_DISPLAY_LINES ||
3513 step == GTK_MOVEMENT_PAGES ||
3514 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3516 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3519 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3520 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3522 if (gtk_get_current_event_state (&state))
3524 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3525 icon_view->priv->ctrl_pressed = TRUE;
3526 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3527 icon_view->priv->shift_pressed = TRUE;
3529 /* else we assume not pressed */
3533 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3534 case GTK_MOVEMENT_VISUAL_POSITIONS:
3535 gtk_icon_view_move_cursor_left_right (icon_view, count);
3537 case GTK_MOVEMENT_DISPLAY_LINES:
3538 gtk_icon_view_move_cursor_up_down (icon_view, count);
3540 case GTK_MOVEMENT_PAGES:
3541 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3543 case GTK_MOVEMENT_BUFFER_ENDS:
3544 gtk_icon_view_move_cursor_start_end (icon_view, count);
3547 g_assert_not_reached ();
3550 icon_view->priv->ctrl_pressed = FALSE;
3551 icon_view->priv->shift_pressed = FALSE;
3553 icon_view->priv->draw_focus = TRUE;
3558 static GtkIconViewItem *
3559 find_item (GtkIconView *icon_view,
3560 GtkIconViewItem *current,
3566 GtkIconViewItem *item;
3568 /* FIXME: this could be more efficient
3570 row = current->row + row_ofs;
3571 col = current->col + col_ofs;
3573 for (items = icon_view->priv->items; items; items = items->next)
3576 if (item->row == row && item->col == col)
3583 static GtkIconViewItem *
3584 find_item_page_up_down (GtkIconView *icon_view,
3585 GtkIconViewItem *current,
3592 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3594 item = g_list_find (icon_view->priv->items, current);
3599 for (next = item->next; next; next = next->next)
3601 if (((GtkIconViewItem *)next->data)->col == col)
3604 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3614 for (next = item->prev; next; next = next->prev)
3616 if (((GtkIconViewItem *)next->data)->col == col)
3619 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3633 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3634 GtkIconViewItem *anchor,
3635 GtkIconViewItem *cursor)
3638 GtkIconViewItem *item;
3639 gint row1, row2, col1, col2;
3640 gboolean dirty = FALSE;
3642 if (anchor->row < cursor->row)
3653 if (anchor->col < cursor->col)
3664 for (items = icon_view->priv->items; items; items = items->next)
3668 if (row1 <= item->row && item->row <= row2 &&
3669 col1 <= item->col && item->col <= col2)
3671 if (!item->selected)
3674 item->selected = TRUE;
3675 gtk_icon_view_item_selected_changed (icon_view, item);
3677 gtk_icon_view_queue_draw_item (icon_view, item);
3685 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3688 GtkIconViewItem *item;
3689 GtkCellRenderer *cell;
3690 gboolean dirty = FALSE;
3692 GtkDirectionType direction;
3694 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3697 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3699 if (!icon_view->priv->cursor_item)
3704 list = icon_view->priv->items;
3706 list = g_list_last (icon_view->priv->items);
3708 item = list ? list->data : NULL;
3710 /* Give focus to the first cell initially */
3711 gtk_icon_view_set_cell_data (icon_view, item);
3712 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3716 item = icon_view->priv->cursor_item;
3717 step = count > 0 ? 1 : -1;
3719 /* Save the current focus cell in case we hit the edge */
3720 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3724 gtk_icon_view_set_cell_data (icon_view, item);
3726 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3729 item = find_item (icon_view, item, step, 0);
3735 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3737 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3739 gtk_widget_child_focus (toplevel,
3740 direction == GTK_DIR_UP ?
3741 GTK_DIR_TAB_BACKWARD :
3742 GTK_DIR_TAB_FORWARD);
3746 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3750 if (icon_view->priv->ctrl_pressed ||
3751 !icon_view->priv->shift_pressed ||
3752 !icon_view->priv->anchor_item ||
3753 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3754 icon_view->priv->anchor_item = item;
3756 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3757 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3759 if (!icon_view->priv->ctrl_pressed &&
3760 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3762 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3763 dirty = gtk_icon_view_select_all_between (icon_view,
3764 icon_view->priv->anchor_item,
3768 gtk_icon_view_scroll_to_item (icon_view, item);
3771 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3775 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3778 GtkIconViewItem *item;
3779 gboolean dirty = FALSE;
3781 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3784 if (!icon_view->priv->cursor_item)
3789 list = icon_view->priv->items;
3791 list = g_list_last (icon_view->priv->items);
3793 item = list ? list->data : NULL;
3796 item = find_item_page_up_down (icon_view,
3797 icon_view->priv->cursor_item,
3800 if (item == icon_view->priv->cursor_item)
3801 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3806 if (icon_view->priv->ctrl_pressed ||
3807 !icon_view->priv->shift_pressed ||
3808 !icon_view->priv->anchor_item ||
3809 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3810 icon_view->priv->anchor_item = item;
3812 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3814 if (!icon_view->priv->ctrl_pressed &&
3815 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3817 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3818 dirty = gtk_icon_view_select_all_between (icon_view,
3819 icon_view->priv->anchor_item,
3823 gtk_icon_view_scroll_to_item (icon_view, item);
3826 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3830 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3833 GtkIconViewItem *item;
3834 GtkCellRenderer *cell = NULL;
3835 gboolean dirty = FALSE;
3837 GtkDirectionType direction;
3839 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3842 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3844 if (!icon_view->priv->cursor_item)
3849 list = icon_view->priv->items;
3851 list = g_list_last (icon_view->priv->items);
3853 item = list ? list->data : NULL;
3855 /* Give focus to the first cell initially */
3856 gtk_icon_view_set_cell_data (icon_view, item);
3857 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3861 item = icon_view->priv->cursor_item;
3862 step = count > 0 ? 1 : -1;
3864 /* Save the current focus cell in case we hit the edge */
3865 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3869 gtk_icon_view_set_cell_data (icon_view, item);
3871 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3874 item = find_item (icon_view, item, 0, step);
3880 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3882 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3884 gtk_widget_child_focus (toplevel,
3885 direction == GTK_DIR_LEFT ?
3886 GTK_DIR_TAB_BACKWARD :
3887 GTK_DIR_TAB_FORWARD);
3891 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3895 if (icon_view->priv->ctrl_pressed ||
3896 !icon_view->priv->shift_pressed ||
3897 !icon_view->priv->anchor_item ||
3898 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3899 icon_view->priv->anchor_item = item;
3901 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3902 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3904 if (!icon_view->priv->ctrl_pressed &&
3905 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3907 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3908 dirty = gtk_icon_view_select_all_between (icon_view,
3909 icon_view->priv->anchor_item,
3913 gtk_icon_view_scroll_to_item (icon_view, item);
3916 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3920 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3923 GtkIconViewItem *item;
3925 gboolean dirty = FALSE;
3927 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3931 list = icon_view->priv->items;
3933 list = g_list_last (icon_view->priv->items);
3935 item = list ? list->data : NULL;
3937 if (item == icon_view->priv->cursor_item)
3938 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3943 if (icon_view->priv->ctrl_pressed ||
3944 !icon_view->priv->shift_pressed ||
3945 !icon_view->priv->anchor_item ||
3946 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3947 icon_view->priv->anchor_item = item;
3949 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3951 if (!icon_view->priv->ctrl_pressed &&
3952 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3954 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3955 dirty = gtk_icon_view_select_all_between (icon_view,
3956 icon_view->priv->anchor_item,
3960 gtk_icon_view_scroll_to_item (icon_view, item);
3963 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3967 * gtk_icon_view_scroll_to_path:
3968 * @icon_view: A #GtkIconView.
3969 * @path: The path of the item to move to.
3970 * @use_align: whether to use alignment arguments, or %FALSE.
3971 * @row_align: The vertical alignment of the item specified by @path.
3972 * @col_align: The horizontal alignment of the item specified by @path.
3974 * Moves the alignments of @icon_view to the position specified by @path.
3975 * @row_align determines where the row is placed, and @col_align determines
3976 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3977 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3980 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3981 * tree does the minimum amount of work to scroll the item onto the screen.
3982 * This means that the item will be scrolled to the edge closest to its current
3983 * position. If the item is currently visible on the screen, nothing is done.
3985 * This function only works if the model is set, and @path is a valid row on
3986 * the model. If the model changes before the @icon_view is realized, the
3987 * centered path will be modified to reflect this change.
3992 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3998 GtkIconViewItem *item = NULL;
4001 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4002 g_return_if_fail (path != NULL);
4003 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4004 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4006 widget = GTK_WIDGET (icon_view);
4008 if (gtk_tree_path_get_depth (path) > 0)
4009 item = g_list_nth_data (icon_view->priv->items,
4010 gtk_tree_path_get_indices(path)[0]);
4012 if (!item || item->cell_area.width < 0 ||
4013 !gtk_widget_get_realized (widget))
4015 if (icon_view->priv->scroll_to_path)
4016 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4018 icon_view->priv->scroll_to_path = NULL;
4021 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4023 icon_view->priv->scroll_to_use_align = use_align;
4024 icon_view->priv->scroll_to_row_align = row_align;
4025 icon_view->priv->scroll_to_col_align = col_align;
4032 GtkAllocation allocation;
4035 GdkRectangle item_area =
4037 item->cell_area.x - icon_view->priv->item_padding,
4038 item->cell_area.y - icon_view->priv->item_padding,
4039 item->cell_area.width + icon_view->priv->item_padding * 2,
4040 item->cell_area.height + icon_view->priv->item_padding * 2
4043 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4045 gtk_widget_get_allocation (widget, &allocation);
4047 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4049 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4050 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4052 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4054 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4055 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4057 gtk_adjustment_changed (icon_view->priv->hadjustment);
4058 gtk_adjustment_changed (icon_view->priv->vadjustment);
4061 gtk_icon_view_scroll_to_item (icon_view, item);
4066 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4067 GtkIconViewItem *item)
4069 GtkIconViewPrivate *priv = icon_view->priv;
4070 GtkWidget *widget = GTK_WIDGET (icon_view);
4071 GtkAdjustment *hadj, *vadj;
4072 GtkAllocation allocation;
4074 GdkRectangle item_area;
4076 item_area.x = item->cell_area.x - priv->item_padding;
4077 item_area.y = item->cell_area.y - priv->item_padding;
4078 item_area.width = item->cell_area.width + priv->item_padding * 2;
4079 item_area.height = item->cell_area.height + priv->item_padding * 2;
4081 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4082 gtk_widget_get_allocation (widget, &allocation);
4084 hadj = icon_view->priv->hadjustment;
4085 vadj = icon_view->priv->vadjustment;
4087 if (y + item_area.y < 0)
4088 gtk_adjustment_set_value (vadj,
4089 gtk_adjustment_get_value (vadj)
4091 else if (y + item_area.y + item_area.height > allocation.height)
4092 gtk_adjustment_set_value (vadj,
4093 gtk_adjustment_get_value (vadj)
4094 + y + item_area.y + item_area.height - allocation.height);
4096 if (x + item_area.x < 0)
4097 gtk_adjustment_set_value (hadj,
4098 gtk_adjustment_get_value (hadj)
4100 else if (x + item_area.x + item_area.width > allocation.width)
4101 gtk_adjustment_set_value (hadj,
4102 gtk_adjustment_get_value (hadj)
4103 + x + item_area.x + item_area.width - allocation.width);
4105 gtk_adjustment_changed (hadj);
4106 gtk_adjustment_changed (vadj);
4109 /* GtkCellLayout implementation */
4112 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4113 GtkCellArea *cell_area)
4115 GtkIconViewPrivate *priv = icon_view->priv;
4117 if (priv->cell_area)
4121 priv->cell_area = cell_area;
4123 priv->cell_area = gtk_cell_area_box_new ();
4125 g_object_ref_sink (priv->cell_area);
4127 if (GTK_IS_ORIENTABLE (priv->cell_area))
4128 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4130 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4132 priv->add_editable_id =
4133 g_signal_connect (priv->cell_area, "add-editable",
4134 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4135 priv->remove_editable_id =
4136 g_signal_connect (priv->cell_area, "remove-editable",
4137 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4138 priv->context_changed_id =
4139 g_signal_connect (priv->cell_area_context, "notify",
4140 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4142 update_text_cell (icon_view);
4143 update_pixbuf_cell (icon_view);
4146 static GtkCellArea *
4147 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4149 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4150 GtkIconViewPrivate *priv = icon_view->priv;
4152 if (G_UNLIKELY (!priv->cell_area))
4153 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4155 return icon_view->priv->cell_area;
4159 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4160 GtkIconViewItem *item)
4162 gboolean iters_persist;
4165 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4171 path = gtk_tree_path_new_from_indices (item->index, -1);
4172 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4174 gtk_tree_path_free (path);
4179 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4180 icon_view->priv->model,
4181 &iter, FALSE, FALSE);
4190 * gtk_icon_view_new:
4192 * Creates a new #GtkIconView widget
4194 * Return value: A newly created #GtkIconView widget
4199 gtk_icon_view_new (void)
4201 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4205 * gtk_icon_view_new_with_area:
4206 * @area: the #GtkCellArea to use to layout cells
4208 * Creates a new #GtkIconView widget using the
4209 * specified @area to layout cells inside the icons.
4211 * Return value: A newly created #GtkIconView widget
4216 gtk_icon_view_new_with_area (GtkCellArea *area)
4218 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4222 * gtk_icon_view_new_with_model:
4223 * @model: The model.
4225 * Creates a new #GtkIconView widget with the model @model.
4227 * Return value: A newly created #GtkIconView widget.
4232 gtk_icon_view_new_with_model (GtkTreeModel *model)
4234 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4238 * gtk_icon_view_convert_widget_to_bin_window_coords:
4239 * @icon_view: a #GtkIconView
4240 * @wx: X coordinate relative to the widget
4241 * @wy: Y coordinate relative to the widget
4242 * @bx: (out): return location for bin_window X coordinate
4243 * @by: (out): return location for bin_window Y coordinate
4245 * Converts widget coordinates to coordinates for the bin_window,
4246 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4251 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4259 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4261 if (icon_view->priv->bin_window)
4262 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4273 * gtk_icon_view_get_path_at_pos:
4274 * @icon_view: A #GtkIconView.
4275 * @x: The x position to be identified
4276 * @y: The y position to be identified
4278 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4279 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4280 * the cell at the specified position.
4281 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4282 * widget coordinates to bin_window coordinates.
4284 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4285 * if no icon exists at that position.
4290 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4294 GtkIconViewItem *item;
4297 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4299 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4304 path = gtk_tree_path_new_from_indices (item->index, -1);
4310 * gtk_icon_view_get_item_at_pos:
4311 * @icon_view: A #GtkIconView.
4312 * @x: The x position to be identified
4313 * @y: The y position to be identified
4314 * @path: (out) (allow-none): Return location for the path, or %NULL
4315 * @cell: (out) (allow-none): Return location for the renderer
4316 * responsible for the cell at (@x, @y), or %NULL
4318 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4319 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4320 * obtains the cell at the specified position. The returned path should
4321 * be freed with gtk_tree_path_free().
4322 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4323 * widget coordinates to bin_window coordinates.
4325 * Return value: %TRUE if an item exists at the specified position
4330 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4334 GtkCellRenderer **cell)
4336 GtkIconViewItem *item;
4337 GtkCellRenderer *renderer = NULL;
4339 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4341 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4346 *path = gtk_tree_path_new_from_indices (item->index, -1);
4354 return (item != NULL);
4358 * gtk_icon_view_set_tooltip_item:
4359 * @icon_view: a #GtkIconView
4360 * @tooltip: a #GtkTooltip
4361 * @path: a #GtkTreePath
4363 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4364 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4365 * See also gtk_tooltip_set_tip_area().
4370 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4371 GtkTooltip *tooltip,
4374 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4375 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4377 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4381 * gtk_icon_view_set_tooltip_cell:
4382 * @icon_view: a #GtkIconView
4383 * @tooltip: a #GtkTooltip
4384 * @path: a #GtkTreePath
4385 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4387 * Sets the tip area of @tooltip to the area which @cell occupies in
4388 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4390 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4395 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4396 GtkTooltip *tooltip,
4398 GtkCellRenderer *cell)
4401 GtkIconViewItem *item = NULL;
4404 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4405 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4406 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4408 if (gtk_tree_path_get_depth (path) > 0)
4409 item = g_list_nth_data (icon_view->priv->items,
4410 gtk_tree_path_get_indices(path)[0]);
4417 GtkCellAreaContext *context;
4419 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4420 gtk_icon_view_set_cell_data (icon_view, item);
4421 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4422 GTK_WIDGET (icon_view),
4423 cell, (GdkRectangle *)item, &rect);
4427 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4428 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4429 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4430 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4433 if (icon_view->priv->bin_window)
4435 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4440 gtk_tooltip_set_tip_area (tooltip, &rect);
4445 * gtk_icon_view_get_tooltip_context:
4446 * @icon_view: an #GtkIconView
4447 * @x: (inout): the x coordinate (relative to widget coordinates)
4448 * @y: (inout): the y coordinate (relative to widget coordinates)
4449 * @keyboard_tip: whether this is a keyboard tooltip or not
4450 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4451 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4452 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4454 * This function is supposed to be used in a #GtkWidget::query-tooltip
4455 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4456 * which are received in the signal handler, should be passed to this
4457 * function without modification.
4459 * The return value indicates whether there is an icon view item at the given
4460 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4461 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4462 * @model, @path and @iter which have been provided will be set to point to
4463 * that row and the corresponding model. @x and @y will always be converted
4464 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4466 * Return value: whether or not the given tooltip context points to a item
4471 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4474 gboolean keyboard_tip,
4475 GtkTreeModel **model,
4479 GtkTreePath *tmppath = NULL;
4481 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4482 g_return_val_if_fail (x != NULL, FALSE);
4483 g_return_val_if_fail (y != NULL, FALSE);
4487 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4494 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4497 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4502 *model = gtk_icon_view_get_model (icon_view);
4505 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4511 gtk_tree_path_free (tmppath);
4517 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4520 gboolean keyboard_tip,
4521 GtkTooltip *tooltip,
4527 GtkTreeModel *model;
4528 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4530 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4533 &model, &path, &iter))
4536 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4540 gtk_tree_path_free (path);
4544 gtk_tooltip_set_markup (tooltip, str);
4545 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4547 gtk_tree_path_free (path);
4555 * gtk_icon_view_set_tooltip_column:
4556 * @icon_view: a #GtkIconView
4557 * @column: an integer, which is a valid column number for @icon_view's model
4559 * If you only plan to have simple (text-only) tooltips on full items, you
4560 * can use this function to have #GtkIconView handle these automatically
4561 * for you. @column should be set to the column in @icon_view's model
4562 * containing the tooltip texts, or -1 to disable this feature.
4564 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4565 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4567 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4568 * so &, <, etc have to be escaped in the text.
4573 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4576 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4578 if (column == icon_view->priv->tooltip_column)
4583 g_signal_handlers_disconnect_by_func (icon_view,
4584 gtk_icon_view_set_tooltip_query_cb,
4586 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4590 if (icon_view->priv->tooltip_column == -1)
4592 g_signal_connect (icon_view, "query-tooltip",
4593 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4594 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4598 icon_view->priv->tooltip_column = column;
4599 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4603 * gtk_icon_view_get_tooltip_column:
4604 * @icon_view: a #GtkIconView
4606 * Returns the column of @icon_view's model which is being used for
4607 * displaying tooltips on @icon_view's rows.
4609 * Return value: the index of the tooltip column that is currently being
4610 * used, or -1 if this is disabled.
4615 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4617 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4619 return icon_view->priv->tooltip_column;
4623 * gtk_icon_view_get_visible_range:
4624 * @icon_view: A #GtkIconView
4625 * @start_path: (out) (allow-none): Return location for start of region,
4627 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4629 * Sets @start_path and @end_path to be the first and last visible path.
4630 * Note that there may be invisible paths in between.
4632 * Both paths should be freed with gtk_tree_path_free() after use.
4634 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4639 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4640 GtkTreePath **start_path,
4641 GtkTreePath **end_path)
4643 gint start_index = -1;
4644 gint end_index = -1;
4647 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4649 if (icon_view->priv->hadjustment == NULL ||
4650 icon_view->priv->vadjustment == NULL)
4653 if (start_path == NULL && end_path == NULL)
4656 for (icons = icon_view->priv->items; icons; icons = icons->next)
4658 GtkIconViewItem *item = icons->data;
4659 GdkRectangle *item_area = (GdkRectangle *)item;
4661 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4662 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4664 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4665 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4667 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4668 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4670 if (start_index == -1)
4671 start_index = item->index;
4672 end_index = item->index;
4676 if (start_path && start_index != -1)
4677 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4678 if (end_path && end_index != -1)
4679 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4681 return start_index != -1;
4685 * gtk_icon_view_selected_foreach:
4686 * @icon_view: A #GtkIconView.
4687 * @func: (scope call): The function to call for each selected icon.
4688 * @data: User data to pass to the function.
4690 * Calls a function for each selected icon. Note that the model or
4691 * selection cannot be modified from within this function.
4696 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4697 GtkIconViewForeachFunc func,
4702 for (list = icon_view->priv->items; list; list = list->next)
4704 GtkIconViewItem *item = list->data;
4705 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4708 (* func) (icon_view, path, data);
4710 gtk_tree_path_free (path);
4715 * gtk_icon_view_set_selection_mode:
4716 * @icon_view: A #GtkIconView.
4717 * @mode: The selection mode
4719 * Sets the selection mode of the @icon_view.
4724 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4725 GtkSelectionMode mode)
4727 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4729 if (mode == icon_view->priv->selection_mode)
4732 if (mode == GTK_SELECTION_NONE ||
4733 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4734 gtk_icon_view_unselect_all (icon_view);
4736 icon_view->priv->selection_mode = mode;
4738 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4742 * gtk_icon_view_get_selection_mode:
4743 * @icon_view: A #GtkIconView.
4745 * Gets the selection mode of the @icon_view.
4747 * Return value: the current selection mode
4752 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4754 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4756 return icon_view->priv->selection_mode;
4760 * gtk_icon_view_set_model:
4761 * @icon_view: A #GtkIconView.
4762 * @model: (allow-none): The model.
4764 * Sets the model for a #GtkIconView.
4765 * If the @icon_view already has a model set, it will remove
4766 * it before setting the new model. If @model is %NULL, then
4767 * it will unset the old model.
4772 gtk_icon_view_set_model (GtkIconView *icon_view,
4773 GtkTreeModel *model)
4775 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4776 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4778 if (icon_view->priv->model == model)
4781 if (icon_view->priv->scroll_to_path)
4783 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4784 icon_view->priv->scroll_to_path = NULL;
4787 /* The area can be NULL while disposing */
4788 if (icon_view->priv->cell_area)
4789 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4795 if (icon_view->priv->pixbuf_column != -1)
4797 column_type = gtk_tree_model_get_column_type (model,
4798 icon_view->priv->pixbuf_column);
4800 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4803 if (icon_view->priv->text_column != -1)
4805 column_type = gtk_tree_model_get_column_type (model,
4806 icon_view->priv->text_column);
4808 g_return_if_fail (column_type == G_TYPE_STRING);
4811 if (icon_view->priv->markup_column != -1)
4813 column_type = gtk_tree_model_get_column_type (model,
4814 icon_view->priv->markup_column);
4816 g_return_if_fail (column_type == G_TYPE_STRING);
4821 if (icon_view->priv->model)
4823 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4824 gtk_icon_view_row_changed,
4826 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4827 gtk_icon_view_row_inserted,
4829 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4830 gtk_icon_view_row_deleted,
4832 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4833 gtk_icon_view_rows_reordered,
4836 g_object_unref (icon_view->priv->model);
4838 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4839 g_list_free (icon_view->priv->items);
4840 icon_view->priv->items = NULL;
4841 icon_view->priv->anchor_item = NULL;
4842 icon_view->priv->cursor_item = NULL;
4843 icon_view->priv->last_single_clicked = NULL;
4844 icon_view->priv->width = 0;
4845 icon_view->priv->height = 0;
4848 icon_view->priv->model = model;
4850 if (icon_view->priv->model)
4852 g_object_ref (icon_view->priv->model);
4853 g_signal_connect (icon_view->priv->model,
4855 G_CALLBACK (gtk_icon_view_row_changed),
4857 g_signal_connect (icon_view->priv->model,
4859 G_CALLBACK (gtk_icon_view_row_inserted),
4861 g_signal_connect (icon_view->priv->model,
4863 G_CALLBACK (gtk_icon_view_row_deleted),
4865 g_signal_connect (icon_view->priv->model,
4867 G_CALLBACK (gtk_icon_view_rows_reordered),
4870 gtk_icon_view_build_items (icon_view);
4872 gtk_icon_view_queue_layout (icon_view);
4875 g_object_notify (G_OBJECT (icon_view), "model");
4877 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4878 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4882 * gtk_icon_view_get_model:
4883 * @icon_view: a #GtkIconView
4885 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4888 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4889 * currently being used.
4894 gtk_icon_view_get_model (GtkIconView *icon_view)
4896 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4898 return icon_view->priv->model;
4902 update_text_cell (GtkIconView *icon_view)
4904 if (!icon_view->priv->cell_area)
4907 if (icon_view->priv->text_column == -1 &&
4908 icon_view->priv->markup_column == -1)
4910 if (icon_view->priv->text_cell != NULL)
4912 gtk_cell_area_remove (icon_view->priv->cell_area,
4913 icon_view->priv->text_cell);
4914 icon_view->priv->text_cell = NULL;
4919 if (icon_view->priv->text_cell == NULL)
4921 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4923 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4926 if (icon_view->priv->markup_column != -1)
4927 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4928 icon_view->priv->text_cell,
4929 "markup", icon_view->priv->markup_column,
4932 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4933 icon_view->priv->text_cell,
4934 "text", icon_view->priv->text_column,
4937 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4938 g_object_set (icon_view->priv->text_cell,
4939 "alignment", PANGO_ALIGN_CENTER,
4940 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4945 g_object_set (icon_view->priv->text_cell,
4946 "alignment", PANGO_ALIGN_LEFT,
4947 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4955 update_pixbuf_cell (GtkIconView *icon_view)
4957 if (!icon_view->priv->cell_area)
4960 if (icon_view->priv->pixbuf_column == -1)
4962 if (icon_view->priv->pixbuf_cell != NULL)
4964 gtk_cell_area_remove (icon_view->priv->cell_area,
4965 icon_view->priv->pixbuf_cell);
4967 icon_view->priv->pixbuf_cell = NULL;
4972 if (icon_view->priv->pixbuf_cell == NULL)
4974 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4976 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4979 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4980 icon_view->priv->pixbuf_cell,
4981 "pixbuf", icon_view->priv->pixbuf_column,
4984 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4985 g_object_set (icon_view->priv->pixbuf_cell,
4990 g_object_set (icon_view->priv->pixbuf_cell,
4998 * gtk_icon_view_set_text_column:
4999 * @icon_view: A #GtkIconView.
5000 * @column: A column in the currently used model, or -1 to display no text
5002 * Sets the column with text for @icon_view to be @column. The text
5003 * column must be of type #G_TYPE_STRING.
5008 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5011 if (column == icon_view->priv->text_column)
5015 icon_view->priv->text_column = -1;
5018 if (icon_view->priv->model != NULL)
5022 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5024 g_return_if_fail (column_type == G_TYPE_STRING);
5027 icon_view->priv->text_column = column;
5030 if (icon_view->priv->cell_area)
5031 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5033 update_text_cell (icon_view);
5035 gtk_icon_view_invalidate_sizes (icon_view);
5037 g_object_notify (G_OBJECT (icon_view), "text-column");
5041 * gtk_icon_view_get_text_column:
5042 * @icon_view: A #GtkIconView.
5044 * Returns the column with text for @icon_view.
5046 * Returns: the text column, or -1 if it's unset.
5051 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5053 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5055 return icon_view->priv->text_column;
5059 * gtk_icon_view_set_markup_column:
5060 * @icon_view: A #GtkIconView.
5061 * @column: A column in the currently used model, or -1 to display no text
5063 * Sets the column with markup information for @icon_view to be
5064 * @column. The markup column must be of type #G_TYPE_STRING.
5065 * If the markup column is set to something, it overrides
5066 * the text column set by gtk_icon_view_set_text_column().
5071 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5074 if (column == icon_view->priv->markup_column)
5078 icon_view->priv->markup_column = -1;
5081 if (icon_view->priv->model != NULL)
5085 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5087 g_return_if_fail (column_type == G_TYPE_STRING);
5090 icon_view->priv->markup_column = column;
5093 if (icon_view->priv->cell_area)
5094 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5096 update_text_cell (icon_view);
5098 gtk_icon_view_invalidate_sizes (icon_view);
5100 g_object_notify (G_OBJECT (icon_view), "markup-column");
5104 * gtk_icon_view_get_markup_column:
5105 * @icon_view: A #GtkIconView.
5107 * Returns the column with markup text for @icon_view.
5109 * Returns: the markup column, or -1 if it's unset.
5114 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5116 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5118 return icon_view->priv->markup_column;
5122 * gtk_icon_view_set_pixbuf_column:
5123 * @icon_view: A #GtkIconView.
5124 * @column: A column in the currently used model, or -1 to disable
5126 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5127 * column must be of type #GDK_TYPE_PIXBUF
5132 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5135 if (column == icon_view->priv->pixbuf_column)
5139 icon_view->priv->pixbuf_column = -1;
5142 if (icon_view->priv->model != NULL)
5146 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5148 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5151 icon_view->priv->pixbuf_column = column;
5154 if (icon_view->priv->cell_area)
5155 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5157 update_pixbuf_cell (icon_view);
5159 gtk_icon_view_invalidate_sizes (icon_view);
5161 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5166 * gtk_icon_view_get_pixbuf_column:
5167 * @icon_view: A #GtkIconView.
5169 * Returns the column with pixbufs for @icon_view.
5171 * Returns: the pixbuf column, or -1 if it's unset.
5176 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5178 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5180 return icon_view->priv->pixbuf_column;
5184 * gtk_icon_view_select_path:
5185 * @icon_view: A #GtkIconView.
5186 * @path: The #GtkTreePath to be selected.
5188 * Selects the row at @path.
5193 gtk_icon_view_select_path (GtkIconView *icon_view,
5196 GtkIconViewItem *item = NULL;
5198 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5199 g_return_if_fail (icon_view->priv->model != NULL);
5200 g_return_if_fail (path != NULL);
5202 if (gtk_tree_path_get_depth (path) > 0)
5203 item = g_list_nth_data (icon_view->priv->items,
5204 gtk_tree_path_get_indices(path)[0]);
5207 gtk_icon_view_select_item (icon_view, item);
5211 * gtk_icon_view_unselect_path:
5212 * @icon_view: A #GtkIconView.
5213 * @path: The #GtkTreePath to be unselected.
5215 * Unselects the row at @path.
5220 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5223 GtkIconViewItem *item;
5225 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5226 g_return_if_fail (icon_view->priv->model != NULL);
5227 g_return_if_fail (path != NULL);
5229 item = g_list_nth_data (icon_view->priv->items,
5230 gtk_tree_path_get_indices(path)[0]);
5235 gtk_icon_view_unselect_item (icon_view, item);
5239 * gtk_icon_view_get_selected_items:
5240 * @icon_view: A #GtkIconView.
5242 * Creates a list of paths of all selected items. Additionally, if you are
5243 * planning on modifying the model after calling this function, you may
5244 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5245 * To do this, you can use gtk_tree_row_reference_new().
5247 * To free the return value, use:
5249 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5250 * g_list_free (list);
5253 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5258 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5261 GList *selected = NULL;
5263 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5265 for (list = icon_view->priv->items; list != NULL; list = list->next)
5267 GtkIconViewItem *item = list->data;
5271 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5273 selected = g_list_prepend (selected, path);
5281 * gtk_icon_view_select_all:
5282 * @icon_view: A #GtkIconView.
5284 * Selects all the icons. @icon_view must has its selection mode set
5285 * to #GTK_SELECTION_MULTIPLE.
5290 gtk_icon_view_select_all (GtkIconView *icon_view)
5293 gboolean dirty = FALSE;
5295 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5297 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5300 for (items = icon_view->priv->items; items; items = items->next)
5302 GtkIconViewItem *item = items->data;
5304 if (!item->selected)
5307 item->selected = TRUE;
5308 gtk_icon_view_queue_draw_item (icon_view, item);
5313 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5317 * gtk_icon_view_unselect_all:
5318 * @icon_view: A #GtkIconView.
5320 * Unselects all the icons.
5325 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5327 gboolean dirty = FALSE;
5329 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5331 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5334 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5337 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5341 * gtk_icon_view_path_is_selected:
5342 * @icon_view: A #GtkIconView.
5343 * @path: A #GtkTreePath to check selection on.
5345 * Returns %TRUE if the icon pointed to by @path is currently
5346 * selected. If @path does not point to a valid location, %FALSE is returned.
5348 * Return value: %TRUE if @path is selected.
5353 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5356 GtkIconViewItem *item;
5358 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5359 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5360 g_return_val_if_fail (path != NULL, FALSE);
5362 item = g_list_nth_data (icon_view->priv->items,
5363 gtk_tree_path_get_indices(path)[0]);
5368 return item->selected;
5372 * gtk_icon_view_get_item_row:
5373 * @icon_view: a #GtkIconView
5374 * @path: the #GtkTreePath of the item
5376 * Gets the row in which the item @path is currently
5377 * displayed. Row numbers start at 0.
5379 * Returns: The row in which the item is displayed
5384 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5387 GtkIconViewItem *item;
5389 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5390 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5391 g_return_val_if_fail (path != NULL, -1);
5393 item = g_list_nth_data (icon_view->priv->items,
5394 gtk_tree_path_get_indices(path)[0]);
5403 * gtk_icon_view_get_item_column:
5404 * @icon_view: a #GtkIconView
5405 * @path: the #GtkTreePath of the item
5407 * Gets the column in which the item @path is currently
5408 * displayed. Column numbers start at 0.
5410 * Returns: The column in which the item is displayed
5415 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5418 GtkIconViewItem *item;
5420 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5421 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5422 g_return_val_if_fail (path != NULL, -1);
5424 item = g_list_nth_data (icon_view->priv->items,
5425 gtk_tree_path_get_indices(path)[0]);
5434 * gtk_icon_view_item_activated:
5435 * @icon_view: A #GtkIconView
5436 * @path: The #GtkTreePath to be activated
5438 * Activates the item determined by @path.
5443 gtk_icon_view_item_activated (GtkIconView *icon_view,
5446 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5447 g_return_if_fail (path != NULL);
5449 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5453 * gtk_icon_view_set_item_orientation:
5454 * @icon_view: a #GtkIconView
5455 * @orientation: the relative position of texts and icons
5457 * Sets the ::item-orientation property which determines whether the labels
5458 * are drawn beside the icons instead of below.
5463 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5464 GtkOrientation orientation)
5466 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5468 if (icon_view->priv->item_orientation != orientation)
5470 icon_view->priv->item_orientation = orientation;
5472 if (icon_view->priv->cell_area)
5474 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5475 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5476 icon_view->priv->item_orientation);
5478 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5481 gtk_icon_view_invalidate_sizes (icon_view);
5483 update_text_cell (icon_view);
5484 update_pixbuf_cell (icon_view);
5486 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5491 * gtk_icon_view_get_item_orientation:
5492 * @icon_view: a #GtkIconView
5494 * Returns the value of the ::item-orientation property which determines
5495 * whether the labels are drawn beside the icons instead of below.
5497 * Return value: the relative position of texts and icons
5502 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5504 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5505 GTK_ORIENTATION_VERTICAL);
5507 return icon_view->priv->item_orientation;
5511 * gtk_icon_view_set_columns:
5512 * @icon_view: a #GtkIconView
5513 * @columns: the number of columns
5515 * Sets the ::columns property which determines in how
5516 * many columns the icons are arranged. If @columns is
5517 * -1, the number of columns will be chosen automatically
5518 * to fill the available area.
5523 gtk_icon_view_set_columns (GtkIconView *icon_view,
5526 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5528 if (icon_view->priv->columns != columns)
5530 icon_view->priv->columns = columns;
5532 if (icon_view->priv->cell_area)
5533 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5535 gtk_icon_view_queue_layout (icon_view);
5537 g_object_notify (G_OBJECT (icon_view), "columns");
5542 * gtk_icon_view_get_columns:
5543 * @icon_view: a #GtkIconView
5545 * Returns the value of the ::columns property.
5547 * Return value: the number of columns, or -1
5552 gtk_icon_view_get_columns (GtkIconView *icon_view)
5554 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5556 return icon_view->priv->columns;
5560 * gtk_icon_view_set_item_width:
5561 * @icon_view: a #GtkIconView
5562 * @item_width: the width for each item
5564 * Sets the ::item-width property which specifies the width
5565 * to use for each item. If it is set to -1, the icon view will
5566 * automatically determine a suitable item size.
5571 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5574 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5576 if (icon_view->priv->item_width != item_width)
5578 icon_view->priv->item_width = item_width;
5580 if (icon_view->priv->cell_area)
5581 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5583 gtk_icon_view_invalidate_sizes (icon_view);
5585 update_text_cell (icon_view);
5587 g_object_notify (G_OBJECT (icon_view), "item-width");
5592 * gtk_icon_view_get_item_width:
5593 * @icon_view: a #GtkIconView
5595 * Returns the value of the ::item-width property.
5597 * Return value: the width of a single item, or -1
5602 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5604 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5606 return icon_view->priv->item_width;
5611 * gtk_icon_view_set_spacing:
5612 * @icon_view: a #GtkIconView
5613 * @spacing: the spacing
5615 * Sets the ::spacing property which specifies the space
5616 * which is inserted between the cells (i.e. the icon and
5617 * the text) of an item.
5622 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5625 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5627 if (icon_view->priv->spacing != spacing)
5629 icon_view->priv->spacing = spacing;
5631 if (icon_view->priv->cell_area)
5632 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5634 gtk_icon_view_invalidate_sizes (icon_view);
5636 g_object_notify (G_OBJECT (icon_view), "spacing");
5641 * gtk_icon_view_get_spacing:
5642 * @icon_view: a #GtkIconView
5644 * Returns the value of the ::spacing property.
5646 * Return value: the space between cells
5651 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5653 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5655 return icon_view->priv->spacing;
5659 * gtk_icon_view_set_row_spacing:
5660 * @icon_view: a #GtkIconView
5661 * @row_spacing: the row spacing
5663 * Sets the ::row-spacing property which specifies the space
5664 * which is inserted between the rows of the icon view.
5669 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5672 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5674 if (icon_view->priv->row_spacing != row_spacing)
5676 icon_view->priv->row_spacing = row_spacing;
5678 if (icon_view->priv->cell_area)
5679 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5681 gtk_icon_view_invalidate_sizes (icon_view);
5683 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5688 * gtk_icon_view_get_row_spacing:
5689 * @icon_view: a #GtkIconView
5691 * Returns the value of the ::row-spacing property.
5693 * Return value: the space between rows
5698 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5700 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5702 return icon_view->priv->row_spacing;
5706 * gtk_icon_view_set_column_spacing:
5707 * @icon_view: a #GtkIconView
5708 * @column_spacing: the column spacing
5710 * Sets the ::column-spacing property which specifies the space
5711 * which is inserted between the columns of the icon view.
5716 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5717 gint column_spacing)
5719 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5721 if (icon_view->priv->column_spacing != column_spacing)
5723 icon_view->priv->column_spacing = column_spacing;
5725 if (icon_view->priv->cell_area)
5726 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5728 gtk_icon_view_invalidate_sizes (icon_view);
5730 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5735 * gtk_icon_view_get_column_spacing:
5736 * @icon_view: a #GtkIconView
5738 * Returns the value of the ::column-spacing property.
5740 * Return value: the space between columns
5745 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5747 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5749 return icon_view->priv->column_spacing;
5753 * gtk_icon_view_set_margin:
5754 * @icon_view: a #GtkIconView
5755 * @margin: the margin
5757 * Sets the ::margin property which specifies the space
5758 * which is inserted at the top, bottom, left and right
5764 gtk_icon_view_set_margin (GtkIconView *icon_view,
5767 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5769 if (icon_view->priv->margin != margin)
5771 icon_view->priv->margin = margin;
5773 if (icon_view->priv->cell_area)
5774 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5776 gtk_icon_view_invalidate_sizes (icon_view);
5778 g_object_notify (G_OBJECT (icon_view), "margin");
5783 * gtk_icon_view_get_margin:
5784 * @icon_view: a #GtkIconView
5786 * Returns the value of the ::margin property.
5788 * Return value: the space at the borders
5793 gtk_icon_view_get_margin (GtkIconView *icon_view)
5795 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5797 return icon_view->priv->margin;
5801 * gtk_icon_view_set_item_padding:
5802 * @icon_view: a #GtkIconView
5803 * @item_padding: the item padding
5805 * Sets the #GtkIconView:item-padding property which specifies the padding
5806 * around each of the icon view's items.
5811 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5814 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5816 if (icon_view->priv->item_padding != item_padding)
5818 icon_view->priv->item_padding = item_padding;
5820 if (icon_view->priv->cell_area)
5821 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5823 gtk_icon_view_invalidate_sizes (icon_view);
5825 g_object_notify (G_OBJECT (icon_view), "item-padding");
5830 * gtk_icon_view_get_item_padding:
5831 * @icon_view: a #GtkIconView
5833 * Returns the value of the ::item-padding property.
5835 * Return value: the padding around items
5840 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5842 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5844 return icon_view->priv->item_padding;
5847 /* Get/set whether drag_motion requested the drag data and
5848 * drag_data_received should thus not actually insert the data,
5849 * since the data doesn't result from a drop.
5852 set_status_pending (GdkDragContext *context,
5853 GdkDragAction suggested_action)
5855 g_object_set_data (G_OBJECT (context),
5856 I_("gtk-icon-view-status-pending"),
5857 GINT_TO_POINTER (suggested_action));
5860 static GdkDragAction
5861 get_status_pending (GdkDragContext *context)
5863 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5864 "gtk-icon-view-status-pending"));
5868 unset_reorderable (GtkIconView *icon_view)
5870 if (icon_view->priv->reorderable)
5872 icon_view->priv->reorderable = FALSE;
5873 g_object_notify (G_OBJECT (icon_view), "reorderable");
5878 set_source_row (GdkDragContext *context,
5879 GtkTreeModel *model,
5880 GtkTreePath *source_row)
5883 g_object_set_data_full (G_OBJECT (context),
5884 I_("gtk-icon-view-source-row"),
5885 gtk_tree_row_reference_new (model, source_row),
5886 (GDestroyNotify) gtk_tree_row_reference_free);
5888 g_object_set_data_full (G_OBJECT (context),
5889 I_("gtk-icon-view-source-row"),
5894 get_source_row (GdkDragContext *context)
5896 GtkTreeRowReference *ref;
5898 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5901 return gtk_tree_row_reference_get_path (ref);
5908 GtkTreeRowReference *dest_row;
5909 gboolean empty_view_drop;
5910 gboolean drop_append_mode;
5914 dest_row_free (gpointer data)
5916 DestRow *dr = (DestRow *)data;
5918 gtk_tree_row_reference_free (dr->dest_row);
5923 set_dest_row (GdkDragContext *context,
5924 GtkTreeModel *model,
5925 GtkTreePath *dest_row,
5926 gboolean empty_view_drop,
5927 gboolean drop_append_mode)
5933 g_object_set_data_full (G_OBJECT (context),
5934 I_("gtk-icon-view-dest-row"),
5939 dr = g_new0 (DestRow, 1);
5941 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5942 dr->empty_view_drop = empty_view_drop;
5943 dr->drop_append_mode = drop_append_mode;
5944 g_object_set_data_full (G_OBJECT (context),
5945 I_("gtk-icon-view-dest-row"),
5946 dr, (GDestroyNotify) dest_row_free);
5950 get_dest_row (GdkDragContext *context)
5954 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5958 GtkTreePath *path = NULL;
5961 path = gtk_tree_row_reference_get_path (dr->dest_row);
5962 else if (dr->empty_view_drop)
5963 path = gtk_tree_path_new_from_indices (0, -1);
5967 if (path && dr->drop_append_mode)
5968 gtk_tree_path_next (path);
5977 check_model_dnd (GtkTreeModel *model,
5978 GType required_iface,
5979 const gchar *signal)
5981 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5983 g_warning ("You must override the default '%s' handler "
5984 "on GtkIconView when using models that don't support "
5985 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5986 "is to connect to '%s' and call "
5987 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5988 "the default handler from running. Look at the source code "
5989 "for the default handler in gtkiconview.c to get an idea what "
5990 "your handler should do. (gtkiconview.c is in the GTK+ source "
5991 "code.) If you're using GTK+ from a language other than C, "
5992 "there may be a more natural way to override default handlers, e.g. via derivation.",
5993 signal, g_type_name (required_iface), signal);
6001 remove_scroll_timeout (GtkIconView *icon_view)
6003 if (icon_view->priv->scroll_timeout_id != 0)
6005 g_source_remove (icon_view->priv->scroll_timeout_id);
6007 icon_view->priv->scroll_timeout_id = 0;
6012 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6015 gint px, py, x, y, width, height;
6016 gint hoffset, voffset;
6018 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6020 gdk_window_get_pointer (window, &px, &py, NULL);
6021 gdk_window_get_geometry (window, &x, &y, &width, &height);
6023 /* see if we are near the edge. */
6024 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6026 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6028 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6030 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6033 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6034 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6037 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6038 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6043 drag_scroll_timeout (gpointer data)
6045 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6047 gtk_icon_view_autoscroll (icon_view);
6054 set_destination (GtkIconView *icon_view,
6055 GdkDragContext *context,
6058 GdkDragAction *suggested_action,
6062 GtkTreePath *path = NULL;
6063 GtkIconViewDropPosition pos;
6064 GtkIconViewDropPosition old_pos;
6065 GtkTreePath *old_dest_path = NULL;
6066 gboolean can_drop = FALSE;
6068 widget = GTK_WIDGET (icon_view);
6070 *suggested_action = 0;
6073 if (!icon_view->priv->dest_set)
6075 /* someone unset us as a drag dest, note that if
6076 * we return FALSE drag_leave isn't called
6079 gtk_icon_view_set_drag_dest_item (icon_view,
6081 GTK_ICON_VIEW_DROP_LEFT);
6083 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6085 return FALSE; /* no longer a drop site */
6088 *target = gtk_drag_dest_find_target (widget, context,
6089 gtk_drag_dest_get_target_list (widget));
6090 if (*target == GDK_NONE)
6093 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6096 GtkTreeModel *model;
6098 /* the row got dropped on empty space, let's setup a special case
6102 gtk_tree_path_free (path);
6104 model = gtk_icon_view_get_model (icon_view);
6106 n_children = gtk_tree_model_iter_n_children (model, NULL);
6109 pos = GTK_ICON_VIEW_DROP_BELOW;
6110 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6114 pos = GTK_ICON_VIEW_DROP_ABOVE;
6115 path = gtk_tree_path_new_from_indices (0, -1);
6125 gtk_icon_view_get_drag_dest_item (icon_view,
6130 gtk_tree_path_free (old_dest_path);
6132 if (TRUE /* FIXME if the location droppable predicate */)
6140 GtkWidget *source_widget;
6142 *suggested_action = gdk_drag_context_get_suggested_action (context);
6143 source_widget = gtk_drag_get_source_widget (context);
6145 if (source_widget == widget)
6147 /* Default to MOVE, unless the user has
6148 * pressed ctrl or shift to affect available actions
6150 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6151 *suggested_action = GDK_ACTION_MOVE;
6154 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6159 /* can't drop here */
6160 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6162 GTK_ICON_VIEW_DROP_LEFT);
6166 gtk_tree_path_free (path);
6172 get_logical_destination (GtkIconView *icon_view,
6173 gboolean *drop_append_mode)
6175 /* adjust path to point to the row the drop goes in front of */
6176 GtkTreePath *path = NULL;
6177 GtkIconViewDropPosition pos;
6179 *drop_append_mode = FALSE;
6181 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6186 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6187 pos == GTK_ICON_VIEW_DROP_BELOW)
6190 GtkTreeModel *model = icon_view->priv->model;
6192 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6193 !gtk_tree_model_iter_next (model, &iter))
6194 *drop_append_mode = TRUE;
6197 *drop_append_mode = FALSE;
6198 gtk_tree_path_next (path);
6206 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6207 GdkEventMotion *event)
6209 GtkWidget *widget = GTK_WIDGET (icon_view);
6210 GdkDragContext *context;
6211 GtkTreePath *path = NULL;
6213 GtkTreeModel *model;
6214 gboolean retval = FALSE;
6216 if (!icon_view->priv->source_set)
6219 if (icon_view->priv->pressed_button < 0)
6222 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6223 icon_view->priv->press_start_x,
6224 icon_view->priv->press_start_y,
6225 event->x, event->y))
6228 model = gtk_icon_view_get_model (icon_view);
6233 button = icon_view->priv->pressed_button;
6234 icon_view->priv->pressed_button = -1;
6236 path = gtk_icon_view_get_path_at_pos (icon_view,
6237 icon_view->priv->press_start_x,
6238 icon_view->priv->press_start_y);
6243 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6244 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6248 /* FIXME Check whether we're a start button, if not return FALSE and
6252 /* Now we can begin the drag */
6256 context = gtk_drag_begin (widget,
6257 gtk_drag_source_get_target_list (widget),
6258 icon_view->priv->source_actions,
6262 set_source_row (context, model, path);
6266 gtk_tree_path_free (path);
6271 /* Source side drag signals */
6273 gtk_icon_view_drag_begin (GtkWidget *widget,
6274 GdkDragContext *context)
6276 GtkIconView *icon_view;
6277 GtkIconViewItem *item;
6278 cairo_surface_t *icon;
6282 icon_view = GTK_ICON_VIEW (widget);
6284 /* if the user uses a custom DnD impl, we don't set the icon here */
6285 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6288 item = gtk_icon_view_get_item_at_coords (icon_view,
6289 icon_view->priv->press_start_x,
6290 icon_view->priv->press_start_y,
6294 g_return_if_fail (item != NULL);
6296 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6297 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6299 path = gtk_tree_path_new_from_indices (item->index, -1);
6300 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6301 gtk_tree_path_free (path);
6303 cairo_surface_set_device_offset (icon, -x, -y);
6305 gtk_drag_set_icon_surface (context, icon);
6307 cairo_surface_destroy (icon);
6311 gtk_icon_view_drag_end (GtkWidget *widget,
6312 GdkDragContext *context)
6318 gtk_icon_view_drag_data_get (GtkWidget *widget,
6319 GdkDragContext *context,
6320 GtkSelectionData *selection_data,
6324 GtkIconView *icon_view;
6325 GtkTreeModel *model;
6326 GtkTreePath *source_row;
6328 icon_view = GTK_ICON_VIEW (widget);
6329 model = gtk_icon_view_get_model (icon_view);
6334 if (!icon_view->priv->source_set)
6337 source_row = get_source_row (context);
6339 if (source_row == NULL)
6342 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6343 * any model; for DragSource models there are some other targets
6347 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6348 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6353 /* If drag_data_get does nothing, try providing row data. */
6354 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6355 gtk_tree_set_row_drag_data (selection_data,
6360 gtk_tree_path_free (source_row);
6364 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6365 GdkDragContext *context)
6367 GtkTreeModel *model;
6368 GtkIconView *icon_view;
6369 GtkTreePath *source_row;
6371 icon_view = GTK_ICON_VIEW (widget);
6372 model = gtk_icon_view_get_model (icon_view);
6374 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6377 if (!icon_view->priv->source_set)
6380 source_row = get_source_row (context);
6382 if (source_row == NULL)
6385 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6388 gtk_tree_path_free (source_row);
6390 set_source_row (context, NULL, NULL);
6393 /* Target side drag signals */
6395 gtk_icon_view_drag_leave (GtkWidget *widget,
6396 GdkDragContext *context,
6399 GtkIconView *icon_view;
6401 icon_view = GTK_ICON_VIEW (widget);
6403 /* unset any highlight row */
6404 gtk_icon_view_set_drag_dest_item (icon_view,
6406 GTK_ICON_VIEW_DROP_LEFT);
6408 remove_scroll_timeout (icon_view);
6412 gtk_icon_view_drag_motion (GtkWidget *widget,
6413 GdkDragContext *context,
6418 GtkTreePath *path = NULL;
6419 GtkIconViewDropPosition pos;
6420 GtkIconView *icon_view;
6421 GdkDragAction suggested_action = 0;
6425 icon_view = GTK_ICON_VIEW (widget);
6427 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6430 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6432 /* we only know this *after* set_desination_row */
6433 empty = icon_view->priv->empty_view_drop;
6435 if (path == NULL && !empty)
6437 /* Can't drop here. */
6438 gdk_drag_status (context, 0, time);
6442 if (icon_view->priv->scroll_timeout_id == 0)
6444 icon_view->priv->scroll_timeout_id =
6445 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6448 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6450 /* Request data so we can use the source row when
6451 * determining whether to accept the drop
6453 set_status_pending (context, suggested_action);
6454 gtk_drag_get_data (widget, context, target, time);
6458 set_status_pending (context, 0);
6459 gdk_drag_status (context, suggested_action, time);
6464 gtk_tree_path_free (path);
6470 gtk_icon_view_drag_drop (GtkWidget *widget,
6471 GdkDragContext *context,
6476 GtkIconView *icon_view;
6478 GdkDragAction suggested_action = 0;
6479 GdkAtom target = GDK_NONE;
6480 GtkTreeModel *model;
6481 gboolean drop_append_mode;
6483 icon_view = GTK_ICON_VIEW (widget);
6484 model = gtk_icon_view_get_model (icon_view);
6486 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6488 if (!icon_view->priv->dest_set)
6491 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6494 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6497 path = get_logical_destination (icon_view, &drop_append_mode);
6499 if (target != GDK_NONE && path != NULL)
6501 /* in case a motion had requested drag data, change things so we
6502 * treat drag data receives as a drop.
6504 set_status_pending (context, 0);
6505 set_dest_row (context, model, path,
6506 icon_view->priv->empty_view_drop, drop_append_mode);
6510 gtk_tree_path_free (path);
6512 /* Unset this thing */
6513 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6515 if (target != GDK_NONE)
6517 gtk_drag_get_data (widget, context, target, time);
6525 gtk_icon_view_drag_data_received (GtkWidget *widget,
6526 GdkDragContext *context,
6529 GtkSelectionData *selection_data,
6534 gboolean accepted = FALSE;
6535 GtkTreeModel *model;
6536 GtkIconView *icon_view;
6537 GtkTreePath *dest_row;
6538 GdkDragAction suggested_action;
6539 gboolean drop_append_mode;
6541 icon_view = GTK_ICON_VIEW (widget);
6542 model = gtk_icon_view_get_model (icon_view);
6544 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6547 if (!icon_view->priv->dest_set)
6550 suggested_action = get_status_pending (context);
6552 if (suggested_action)
6554 /* We are getting this data due to a request in drag_motion,
6555 * rather than due to a request in drag_drop, so we are just
6556 * supposed to call drag_status, not actually paste in the
6559 path = get_logical_destination (icon_view, &drop_append_mode);
6562 suggested_action = 0;
6564 if (suggested_action)
6566 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6569 suggested_action = 0;
6572 gdk_drag_status (context, suggested_action, time);
6575 gtk_tree_path_free (path);
6577 /* If you can't drop, remove user drop indicator until the next motion */
6578 if (suggested_action == 0)
6579 gtk_icon_view_set_drag_dest_item (icon_view,
6581 GTK_ICON_VIEW_DROP_LEFT);
6586 dest_row = get_dest_row (context);
6588 if (dest_row == NULL)
6591 if (gtk_selection_data_get_length (selection_data) >= 0)
6593 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6599 gtk_drag_finish (context,
6601 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6604 gtk_tree_path_free (dest_row);
6607 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6610 /* Drag-and-Drop support */
6612 * gtk_icon_view_enable_model_drag_source:
6613 * @icon_view: a #GtkIconTreeView
6614 * @start_button_mask: Mask of allowed buttons to start drag
6615 * @targets: (array length=n_targets): the table of targets that the drag will
6617 * @n_targets: the number of items in @targets
6618 * @actions: the bitmask of possible actions for a drag from this
6621 * Turns @icon_view into a drag source for automatic DND. Calling this
6622 * method sets #GtkIconView:reorderable to %FALSE.
6627 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6628 GdkModifierType start_button_mask,
6629 const GtkTargetEntry *targets,
6631 GdkDragAction actions)
6633 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6635 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6637 icon_view->priv->start_button_mask = start_button_mask;
6638 icon_view->priv->source_actions = actions;
6640 icon_view->priv->source_set = TRUE;
6642 unset_reorderable (icon_view);
6646 * gtk_icon_view_enable_model_drag_dest:
6647 * @icon_view: a #GtkIconView
6648 * @targets: (array length=n_targets): the table of targets that the drag will
6650 * @n_targets: the number of items in @targets
6651 * @actions: the bitmask of possible actions for a drag to this
6654 * Turns @icon_view into a drop destination for automatic DND. Calling this
6655 * method sets #GtkIconView:reorderable to %FALSE.
6660 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6661 const GtkTargetEntry *targets,
6663 GdkDragAction actions)
6665 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6667 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6669 icon_view->priv->dest_actions = actions;
6671 icon_view->priv->dest_set = TRUE;
6673 unset_reorderable (icon_view);
6677 * gtk_icon_view_unset_model_drag_source:
6678 * @icon_view: a #GtkIconView
6680 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6681 * method sets #GtkIconView:reorderable to %FALSE.
6686 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6688 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6690 if (icon_view->priv->source_set)
6692 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6693 icon_view->priv->source_set = FALSE;
6696 unset_reorderable (icon_view);
6700 * gtk_icon_view_unset_model_drag_dest:
6701 * @icon_view: a #GtkIconView
6703 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6704 * method sets #GtkIconView:reorderable to %FALSE.
6709 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6711 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6713 if (icon_view->priv->dest_set)
6715 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6716 icon_view->priv->dest_set = FALSE;
6719 unset_reorderable (icon_view);
6722 /* These are useful to implement your own custom stuff. */
6724 * gtk_icon_view_set_drag_dest_item:
6725 * @icon_view: a #GtkIconView
6726 * @path: (allow-none): The path of the item to highlight, or %NULL.
6727 * @pos: Specifies where to drop, relative to the item
6729 * Sets the item that is highlighted for feedback.
6734 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6736 GtkIconViewDropPosition pos)
6738 /* Note; this function is exported to allow a custom DND
6739 * implementation, so it can't touch TreeViewDragInfo
6742 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6744 if (icon_view->priv->dest_item)
6746 GtkTreePath *current_path;
6747 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6748 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6749 icon_view->priv->dest_item = NULL;
6751 gtk_icon_view_queue_draw_path (icon_view, current_path);
6752 gtk_tree_path_free (current_path);
6755 /* special case a drop on an empty model */
6756 icon_view->priv->empty_view_drop = FALSE;
6757 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6758 && gtk_tree_path_get_depth (path) == 1
6759 && gtk_tree_path_get_indices (path)[0] == 0)
6763 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6766 if (n_children == 0)
6767 icon_view->priv->empty_view_drop = TRUE;
6770 icon_view->priv->dest_pos = pos;
6774 icon_view->priv->dest_item =
6775 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6776 icon_view->priv->model, path);
6778 gtk_icon_view_queue_draw_path (icon_view, path);
6783 * gtk_icon_view_get_drag_dest_item:
6784 * @icon_view: a #GtkIconView
6785 * @path: (out) (allow-none): Return location for the path of
6786 * the highlighted item, or %NULL.
6787 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6789 * Gets information about the item that is highlighted for feedback.
6794 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6796 GtkIconViewDropPosition *pos)
6798 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6802 if (icon_view->priv->dest_item)
6803 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6809 *pos = icon_view->priv->dest_pos;
6813 * gtk_icon_view_get_dest_item_at_pos:
6814 * @icon_view: a #GtkIconView
6815 * @drag_x: the position to determine the destination item for
6816 * @drag_y: the position to determine the destination item for
6817 * @path: (out) (allow-none): Return location for the path of the item,
6819 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6821 * Determines the destination item for a given position.
6823 * Return value: whether there is an item at the given position.
6828 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6832 GtkIconViewDropPosition *pos)
6834 GtkIconViewItem *item;
6836 /* Note; this function is exported to allow a custom DND
6837 * implementation, so it can't touch TreeViewDragInfo
6840 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6841 g_return_val_if_fail (drag_x >= 0, FALSE);
6842 g_return_val_if_fail (drag_y >= 0, FALSE);
6843 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6849 item = gtk_icon_view_get_item_at_coords (icon_view,
6850 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6851 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6858 *path = gtk_tree_path_new_from_indices (item->index, -1);
6862 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6863 *pos = GTK_ICON_VIEW_DROP_LEFT;
6864 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6865 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6866 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6867 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6868 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6869 *pos = GTK_ICON_VIEW_DROP_BELOW;
6871 *pos = GTK_ICON_VIEW_DROP_INTO;
6878 * gtk_icon_view_create_drag_icon:
6879 * @icon_view: a #GtkIconView
6880 * @path: a #GtkTreePath in @icon_view
6882 * Creates a #cairo_surface_t representation of the item at @path.
6883 * This image is used for a drag icon.
6885 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6890 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6894 GtkStyleContext *context;
6896 cairo_surface_t *surface;
6900 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6901 g_return_val_if_fail (path != NULL, NULL);
6903 widget = GTK_WIDGET (icon_view);
6904 context = gtk_widget_get_style_context (widget);
6906 if (!gtk_widget_get_realized (widget))
6909 index = gtk_tree_path_get_indices (path)[0];
6911 for (l = icon_view->priv->items; l; l = l->next)
6913 GtkIconViewItem *item = l->data;
6915 if (index == item->index)
6917 GdkRectangle rect = {
6918 item->cell_area.x - icon_view->priv->item_padding,
6919 item->cell_area.y - icon_view->priv->item_padding,
6920 item->cell_area.width + icon_view->priv->item_padding * 2,
6921 item->cell_area.height + icon_view->priv->item_padding * 2
6924 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6925 CAIRO_CONTENT_COLOR,
6929 cr = cairo_create (surface);
6930 cairo_set_line_width (cr, 1.);
6932 gtk_render_background (context, cr, 0, 0,
6933 rect.width + 2, rect.height + 2);
6937 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6940 gtk_icon_view_paint_item (icon_view, cr, item,
6941 icon_view->priv->item_padding + 1,
6942 icon_view->priv->item_padding + 1, FALSE);
6946 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6947 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6960 * gtk_icon_view_get_reorderable:
6961 * @icon_view: a #GtkIconView
6963 * Retrieves whether the user can reorder the list via drag-and-drop.
6964 * See gtk_icon_view_set_reorderable().
6966 * Return value: %TRUE if the list can be reordered.
6971 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6973 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6975 return icon_view->priv->reorderable;
6978 static const GtkTargetEntry item_targets[] = {
6979 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6984 * gtk_icon_view_set_reorderable:
6985 * @icon_view: A #GtkIconView.
6986 * @reorderable: %TRUE, if the list of items can be reordered.
6988 * This function is a convenience function to allow you to reorder models that
6989 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6990 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6991 * the user can reorder the model by dragging and dropping rows. The
6992 * developer can listen to these changes by connecting to the model's
6993 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6994 * the icon view as a drag source and destination. Therefore, drag and
6995 * drop can not be used in a reorderable view for any other purpose.
6997 * This function does not give you any degree of control over the order -- any
6998 * reordering is allowed. If more control is needed, you should probably
6999 * handle drag and drop manually.
7004 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7005 gboolean reorderable)
7007 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7009 reorderable = reorderable != FALSE;
7011 if (icon_view->priv->reorderable == reorderable)
7016 gtk_icon_view_enable_model_drag_source (icon_view,
7019 G_N_ELEMENTS (item_targets),
7021 gtk_icon_view_enable_model_drag_dest (icon_view,
7023 G_N_ELEMENTS (item_targets),
7028 gtk_icon_view_unset_model_drag_source (icon_view);
7029 gtk_icon_view_unset_model_drag_dest (icon_view);
7032 icon_view->priv->reorderable = reorderable;
7034 g_object_notify (G_OBJECT (icon_view), "reorderable");
7038 /* Accessibility Support */
7040 static gpointer accessible_parent_class;
7041 static gpointer accessible_item_parent_class;
7042 static GQuark accessible_private_data_quark = 0;
7044 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7045 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7046 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7048 static GType gtk_icon_view_item_accessible_get_type (void);
7059 GtkIconViewItem *item;
7063 AtkStateSet *state_set;
7067 GtkTextBuffer *text_buffer;
7069 gchar *action_descriptions[LAST_ACTION];
7070 gchar *image_description;
7071 guint action_idle_handler;
7072 } GtkIconViewItemAccessible;
7074 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7080 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7085 typedef struct _GtkIconViewItemAccessibleClass
7087 AtkObjectClass parent_class;
7089 } GtkIconViewItemAccessibleClass;
7091 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7094 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7096 GtkIconViewItemAccessible *item;
7097 GtkIconView *icon_view;
7100 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7101 item->action_idle_handler = 0;
7103 if (item->widget != NULL)
7105 icon_view = GTK_ICON_VIEW (item->widget);
7106 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7107 gtk_icon_view_item_activated (icon_view, path);
7108 gtk_tree_path_free (path);
7115 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7118 GtkIconViewItemAccessible *item;
7120 if (i < 0 || i >= LAST_ACTION)
7123 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7125 if (!GTK_IS_ICON_VIEW (item->widget))
7128 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7133 case ACTION_ACTIVATE:
7134 if (!item->action_idle_handler)
7135 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7138 g_assert_not_reached ();
7146 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7151 static const gchar *
7152 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7155 GtkIconViewItemAccessible *item;
7157 if (i < 0 || i >= LAST_ACTION)
7160 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7162 if (item->action_descriptions[i])
7163 return item->action_descriptions[i];
7165 return gtk_icon_view_item_accessible_action_descriptions[i];
7168 static const gchar *
7169 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7172 if (i < 0 || i >= LAST_ACTION)
7175 return gtk_icon_view_item_accessible_action_names[i];
7179 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7181 const gchar *description)
7183 GtkIconViewItemAccessible *item;
7185 if (i < 0 || i >= LAST_ACTION)
7188 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7190 g_free (item->action_descriptions[i]);
7192 item->action_descriptions[i] = g_strdup (description);
7198 atk_action_item_interface_init (AtkActionIface *iface)
7200 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7201 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7202 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7203 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7204 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7207 static const gchar *
7208 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7210 GtkIconViewItemAccessible *item;
7212 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7214 return item->image_description;
7218 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7219 const gchar *description)
7221 GtkIconViewItemAccessible *item;
7223 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7225 g_free (item->image_description);
7226 item->image_description = g_strdup (description);
7233 gboolean pixbuf_found;
7237 get_pixbuf_foreach (GtkCellRenderer *renderer,
7238 const GdkRectangle *cell_area,
7239 const GdkRectangle *cell_background,
7240 GetPixbufBoxData *data)
7242 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7244 data->box = *cell_area;
7245 data->pixbuf_found = TRUE;
7247 return (data->pixbuf_found != FALSE);
7251 get_pixbuf_box (GtkIconView *icon_view,
7252 GtkIconViewItem *item,
7255 GetPixbufBoxData data = { { 0, }, FALSE };
7256 GtkCellAreaContext *context;
7258 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7260 gtk_icon_view_set_cell_data (icon_view, item);
7261 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7262 GTK_WIDGET (icon_view),
7263 (GdkRectangle *)item, (GdkRectangle *)item,
7264 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7266 return data.pixbuf_found;
7270 get_text_foreach (GtkCellRenderer *renderer,
7273 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7275 g_object_get (renderer, "text", text, NULL);
7283 get_text (GtkIconView *icon_view,
7284 GtkIconViewItem *item)
7288 gtk_icon_view_set_cell_data (icon_view, item);
7289 gtk_cell_area_foreach (icon_view->priv->cell_area,
7290 (GtkCellCallback)get_text_foreach, &text);
7296 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7300 GtkIconViewItemAccessible *item;
7303 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7305 if (!GTK_IS_ICON_VIEW (item->widget))
7308 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7311 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7314 *height = box.height;
7319 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7322 AtkCoordType coord_type)
7324 GtkIconViewItemAccessible *item;
7327 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7329 if (!GTK_IS_ICON_VIEW (item->widget))
7332 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7335 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7337 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7339 *x+= box.x - item->item->cell_area.x;
7340 *y+= box.y - item->item->cell_area.y;
7346 atk_image_item_interface_init (AtkImageIface *iface)
7348 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7349 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7350 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7351 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7355 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7359 GtkIconViewItemAccessible *item;
7360 GtkTextIter start, end;
7361 GtkTextBuffer *buffer;
7363 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7365 if (!GTK_IS_ICON_VIEW (item->widget))
7368 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7371 buffer = item->text_buffer;
7372 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7374 gtk_text_buffer_get_end_iter (buffer, &end);
7376 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7378 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7382 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7385 GtkIconViewItemAccessible *item;
7386 GtkTextIter start, end;
7387 GtkTextBuffer *buffer;
7391 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7393 if (!GTK_IS_ICON_VIEW (item->widget))
7396 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7399 buffer = item->text_buffer;
7400 if (offset >= gtk_text_buffer_get_char_count (buffer))
7403 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7405 gtk_text_iter_forward_char (&end);
7406 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7407 unichar = g_utf8_get_char (string);
7415 get_pango_text_offsets (PangoLayout *layout,
7416 GtkTextBuffer *buffer,
7418 AtkTextBoundary boundary_type,
7422 GtkTextIter *start_iter,
7423 GtkTextIter *end_iter)
7425 PangoLayoutIter *iter;
7426 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7427 gint index, start_index, end_index;
7429 gboolean found = FALSE;
7431 text = pango_layout_get_text (layout);
7432 index = g_utf8_offset_to_pointer (text, offset) - text;
7433 iter = pango_layout_get_iter (layout);
7436 line = pango_layout_iter_get_line_readonly (iter);
7437 start_index = line->start_index;
7438 end_index = start_index + line->length;
7440 if (index >= start_index && index <= end_index)
7443 * Found line for offset
7449 * We want the previous line
7453 switch (boundary_type)
7455 case ATK_TEXT_BOUNDARY_LINE_START:
7456 end_index = start_index;
7457 start_index = prev_line->start_index;
7459 case ATK_TEXT_BOUNDARY_LINE_END:
7461 start_index = prev_prev_line->start_index +
7462 prev_prev_line->length;
7463 end_index = prev_line->start_index + prev_line->length;
7466 g_assert_not_reached();
7470 start_index = end_index = 0;
7473 switch (boundary_type)
7475 case ATK_TEXT_BOUNDARY_LINE_START:
7476 if (pango_layout_iter_next_line (iter))
7477 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7479 case ATK_TEXT_BOUNDARY_LINE_END:
7481 start_index = prev_line->start_index +
7485 g_assert_not_reached();
7490 * We want the next line
7492 if (pango_layout_iter_next_line (iter))
7494 line = pango_layout_iter_get_line_readonly (iter);
7495 switch (boundary_type)
7497 case ATK_TEXT_BOUNDARY_LINE_START:
7498 start_index = line->start_index;
7499 if (pango_layout_iter_next_line (iter))
7500 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7502 end_index = start_index + line->length;
7504 case ATK_TEXT_BOUNDARY_LINE_END:
7505 start_index = end_index;
7506 end_index = line->start_index + line->length;
7509 g_assert_not_reached();
7513 start_index = end_index;
7519 prev_prev_line = prev_line;
7522 while (pango_layout_iter_next_line (iter));
7526 start_index = prev_line->start_index + prev_line->length;
7527 end_index = start_index;
7529 pango_layout_iter_free (iter);
7530 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7531 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7533 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7534 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7539 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7541 AtkTextBoundary boundary_type,
7545 GtkIconViewItemAccessible *item;
7546 GtkTextIter start, end;
7547 GtkTextBuffer *buffer;
7549 GtkIconView *icon_view;
7552 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7554 if (!GTK_IS_ICON_VIEW (item->widget))
7557 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7560 buffer = item->text_buffer;
7562 if (!gtk_text_buffer_get_char_count (buffer))
7566 return g_strdup ("");
7568 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7572 switch (boundary_type)
7574 case ATK_TEXT_BOUNDARY_CHAR:
7575 gtk_text_iter_backward_char(&start);
7577 case ATK_TEXT_BOUNDARY_WORD_START:
7578 if (!gtk_text_iter_starts_word (&start))
7579 gtk_text_iter_backward_word_start (&start);
7581 gtk_text_iter_backward_word_start(&start);
7583 case ATK_TEXT_BOUNDARY_WORD_END:
7584 if (gtk_text_iter_inside_word (&start) &&
7585 !gtk_text_iter_starts_word (&start))
7586 gtk_text_iter_backward_word_start (&start);
7587 while (!gtk_text_iter_ends_word (&start))
7589 if (!gtk_text_iter_backward_char (&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 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7601 if (!gtk_text_iter_starts_sentence (&start))
7602 gtk_text_iter_backward_sentence_start (&start);
7604 gtk_text_iter_backward_sentence_start (&start);
7606 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7607 if (gtk_text_iter_inside_sentence (&start) &&
7608 !gtk_text_iter_starts_sentence (&start))
7609 gtk_text_iter_backward_sentence_start (&start);
7610 while (!gtk_text_iter_ends_sentence (&start))
7612 if (!gtk_text_iter_backward_char (&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 case ATK_TEXT_BOUNDARY_LINE_START:
7624 case ATK_TEXT_BOUNDARY_LINE_END:
7626 icon_view = GTK_ICON_VIEW (item->widget);
7627 /* FIXME we probably have to use GailTextCell to salvage this */
7628 gtk_icon_view_update_item_text (icon_view, item->item);
7629 get_pango_text_offsets (icon_view->priv->layout,
7642 *start_offset = gtk_text_iter_get_offset (&start);
7643 *end_offset = gtk_text_iter_get_offset (&end);
7645 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7649 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7651 AtkTextBoundary boundary_type,
7655 GtkIconViewItemAccessible *item;
7656 GtkTextIter start, end;
7657 GtkTextBuffer *buffer;
7659 GtkIconView *icon_view;
7662 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7664 if (!GTK_IS_ICON_VIEW (item->widget))
7667 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7670 buffer = item->text_buffer;
7672 if (!gtk_text_buffer_get_char_count (buffer))
7676 return g_strdup ("");
7678 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7682 switch (boundary_type)
7684 case ATK_TEXT_BOUNDARY_CHAR:
7685 gtk_text_iter_forward_char (&end);
7687 case ATK_TEXT_BOUNDARY_WORD_START:
7688 if (!gtk_text_iter_starts_word (&start))
7689 gtk_text_iter_backward_word_start (&start);
7690 if (gtk_text_iter_inside_word (&end))
7691 gtk_text_iter_forward_word_end (&end);
7692 while (!gtk_text_iter_starts_word (&end))
7694 if (!gtk_text_iter_forward_char (&end))
7698 case ATK_TEXT_BOUNDARY_WORD_END:
7699 if (gtk_text_iter_inside_word (&start) &&
7700 !gtk_text_iter_starts_word (&start))
7701 gtk_text_iter_backward_word_start (&start);
7702 while (!gtk_text_iter_ends_word (&start))
7704 if (!gtk_text_iter_backward_char (&start))
7707 gtk_text_iter_forward_word_end (&end);
7709 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7710 if (!gtk_text_iter_starts_sentence (&start))
7711 gtk_text_iter_backward_sentence_start (&start);
7712 if (gtk_text_iter_inside_sentence (&end))
7713 gtk_text_iter_forward_sentence_end (&end);
7714 while (!gtk_text_iter_starts_sentence (&end))
7716 if (!gtk_text_iter_forward_char (&end))
7720 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7721 if (gtk_text_iter_inside_sentence (&start) &&
7722 !gtk_text_iter_starts_sentence (&start))
7723 gtk_text_iter_backward_sentence_start (&start);
7724 while (!gtk_text_iter_ends_sentence (&start))
7726 if (!gtk_text_iter_backward_char (&start))
7729 gtk_text_iter_forward_sentence_end (&end);
7731 case ATK_TEXT_BOUNDARY_LINE_START:
7732 case ATK_TEXT_BOUNDARY_LINE_END:
7734 icon_view = GTK_ICON_VIEW (item->widget);
7735 /* FIXME we probably have to use GailTextCell to salvage this */
7736 gtk_icon_view_update_item_text (icon_view, item->item);
7737 get_pango_text_offsets (icon_view->priv->layout,
7751 *start_offset = gtk_text_iter_get_offset (&start);
7752 *end_offset = gtk_text_iter_get_offset (&end);
7754 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7758 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7760 AtkTextBoundary boundary_type,
7764 GtkIconViewItemAccessible *item;
7765 GtkTextIter start, end;
7766 GtkTextBuffer *buffer;
7768 GtkIconView *icon_view;
7771 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7773 if (!GTK_IS_ICON_VIEW (item->widget))
7776 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7779 buffer = item->text_buffer;
7781 if (!gtk_text_buffer_get_char_count (buffer))
7785 return g_strdup ("");
7787 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7791 switch (boundary_type)
7793 case ATK_TEXT_BOUNDARY_CHAR:
7794 gtk_text_iter_forward_char(&start);
7795 gtk_text_iter_forward_chars(&end, 2);
7797 case ATK_TEXT_BOUNDARY_WORD_START:
7798 if (gtk_text_iter_inside_word (&end))
7799 gtk_text_iter_forward_word_end (&end);
7800 while (!gtk_text_iter_starts_word (&end))
7802 if (!gtk_text_iter_forward_char (&end))
7806 if (!gtk_text_iter_is_end (&end))
7808 gtk_text_iter_forward_word_end (&end);
7809 while (!gtk_text_iter_starts_word (&end))
7811 if (!gtk_text_iter_forward_char (&end))
7816 case ATK_TEXT_BOUNDARY_WORD_END:
7817 gtk_text_iter_forward_word_end (&end);
7819 if (!gtk_text_iter_is_end (&end))
7820 gtk_text_iter_forward_word_end (&end);
7822 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7823 if (gtk_text_iter_inside_sentence (&end))
7824 gtk_text_iter_forward_sentence_end (&end);
7825 while (!gtk_text_iter_starts_sentence (&end))
7827 if (!gtk_text_iter_forward_char (&end))
7831 if (!gtk_text_iter_is_end (&end))
7833 gtk_text_iter_forward_sentence_end (&end);
7834 while (!gtk_text_iter_starts_sentence (&end))
7836 if (!gtk_text_iter_forward_char (&end))
7841 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7842 gtk_text_iter_forward_sentence_end (&end);
7844 if (!gtk_text_iter_is_end (&end))
7845 gtk_text_iter_forward_sentence_end (&end);
7847 case ATK_TEXT_BOUNDARY_LINE_START:
7848 case ATK_TEXT_BOUNDARY_LINE_END:
7850 icon_view = GTK_ICON_VIEW (item->widget);
7851 /* FIXME we probably have to use GailTextCell to salvage this */
7852 gtk_icon_view_update_item_text (icon_view, item->item);
7853 get_pango_text_offsets (icon_view->priv->layout,
7865 *start_offset = gtk_text_iter_get_offset (&start);
7866 *end_offset = gtk_text_iter_get_offset (&end);
7868 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7872 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7874 GtkIconViewItemAccessible *item;
7876 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7878 if (!GTK_IS_ICON_VIEW (item->widget))
7881 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7884 return gtk_text_buffer_get_char_count (item->text_buffer);
7888 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7894 AtkCoordType coord_type)
7896 GtkIconViewItemAccessible *item;
7898 GtkIconView *icon_view;
7899 PangoRectangle char_rect;
7900 const gchar *item_text;
7904 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7906 if (!GTK_IS_ICON_VIEW (item->widget))
7909 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7913 icon_view = GTK_ICON_VIEW (item->widget);
7914 /* FIXME we probably have to use GailTextCell to salvage this */
7915 gtk_icon_view_update_item_text (icon_view, item->item);
7916 item_text = pango_layout_get_text (icon_view->priv->layout);
7917 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7918 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7920 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7921 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7922 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7923 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7924 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7925 *width = char_rect.width / PANGO_SCALE;
7926 *height = char_rect.height / PANGO_SCALE;
7931 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7934 AtkCoordType coord_type)
7936 GtkIconViewItemAccessible *item;
7939 GtkIconView *icon_view;
7940 const gchar *item_text;
7945 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7947 if (!GTK_IS_ICON_VIEW (item->widget))
7950 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7954 icon_view = GTK_ICON_VIEW (item->widget);
7955 /* FIXME we probably have to use GailTextCell to salvage this */
7956 gtk_icon_view_update_item_text (icon_view, item->item);
7957 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7958 x -= l_x + item->item->layout_x - item->item->x;
7959 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7960 y -= l_y + item->item->layout_y - item->item->y;
7961 item_text = pango_layout_get_text (icon_view->priv->layout);
7962 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7973 offset = g_utf8_strlen (item_text, -1);
7975 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7981 atk_text_item_interface_init (AtkTextIface *iface)
7983 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7984 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7985 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7986 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7987 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7988 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7989 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7990 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7994 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7999 AtkCoordType coord_type)
8001 GtkIconViewItemAccessible *item;
8002 AtkObject *parent_obj;
8005 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8007 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8008 if (!GTK_IS_WIDGET (item->widget))
8011 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8014 *width = item->item->cell_area.width;
8015 *height = item->item->cell_area.height;
8016 if (gtk_icon_view_item_accessible_is_showing (item))
8018 parent_obj = gtk_widget_get_accessible (item->widget);
8019 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8020 *x = l_x + item->item->cell_area.x;
8021 *y = l_y + item->item->cell_area.y;
8031 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8033 GtkIconViewItemAccessible *item;
8034 GtkWidget *toplevel;
8036 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8038 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8039 if (!GTK_IS_WIDGET (item->widget))
8042 gtk_widget_grab_focus (item->widget);
8043 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
8044 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8045 if (gtk_widget_is_toplevel (toplevel))
8046 gtk_window_present (GTK_WINDOW (toplevel));
8052 atk_component_item_interface_init (AtkComponentIface *iface)
8054 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8055 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8059 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8060 AtkStateType state_type,
8061 gboolean emit_signal)
8065 rc = atk_state_set_add_state (item->state_set, state_type);
8067 * The signal should only be generated if the value changed,
8068 * not when the item is set up. So states that are set
8069 * initially should pass FALSE as the emit_signal argument.
8074 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8075 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8076 if (state_type == ATK_STATE_VISIBLE)
8077 g_signal_emit_by_name (item, "visible-data-changed");
8084 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8085 AtkStateType state_type,
8086 gboolean emit_signal)
8088 if (atk_state_set_contains_state (item->state_set, state_type))
8092 rc = atk_state_set_remove_state (item->state_set, state_type);
8094 * The signal should only be generated if the value changed,
8095 * not when the item is set up. So states that are set
8096 * initially should pass FALSE as the emit_signal argument.
8101 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8102 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8103 if (state_type == ATK_STATE_VISIBLE)
8104 g_signal_emit_by_name (item, "visible-data-changed");
8114 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8116 GtkAllocation allocation;
8117 GtkIconView *icon_view;
8118 GdkRectangle visible_rect;
8119 gboolean is_showing;
8122 * An item is considered "SHOWING" if any part of the item is in the
8123 * visible rectangle.
8126 if (!GTK_IS_ICON_VIEW (item->widget))
8129 if (item->item == NULL)
8132 gtk_widget_get_allocation (item->widget, &allocation);
8134 icon_view = GTK_ICON_VIEW (item->widget);
8136 if (icon_view->priv->hadjustment)
8137 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8139 if (icon_view->priv->hadjustment)
8140 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8141 visible_rect.width = allocation.width;
8142 visible_rect.height = allocation.height;
8144 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8145 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8146 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8147 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8156 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8157 gboolean emit_signal)
8159 if (gtk_icon_view_item_accessible_is_showing (item))
8160 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8163 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8168 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8172 item->state_set = atk_state_set_new ();
8174 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8175 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8176 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8177 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8178 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8180 for (i = 0; i < LAST_ACTION; i++)
8181 item->action_descriptions[i] = NULL;
8183 item->image_description = NULL;
8185 item->action_idle_handler = 0;
8189 gtk_icon_view_item_accessible_finalize (GObject *object)
8191 GtkIconViewItemAccessible *item;
8194 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8196 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8199 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8201 if (item->state_set)
8202 g_object_unref (item->state_set);
8204 if (item->text_buffer)
8205 g_object_unref (item->text_buffer);
8207 for (i = 0; i < LAST_ACTION; i++)
8208 g_free (item->action_descriptions[i]);
8210 g_free (item->image_description);
8212 if (item->action_idle_handler)
8214 g_source_remove (item->action_idle_handler);
8215 item->action_idle_handler = 0;
8218 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8222 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8224 GtkIconViewItemAccessible *item;
8226 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8227 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8230 return gtk_widget_get_accessible (item->widget);
8236 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8238 GtkIconViewItemAccessible *item;
8240 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8241 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8243 return item->item->index;
8246 static AtkStateSet *
8247 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8249 GtkIconViewItemAccessible *item;
8250 GtkIconView *icon_view;
8252 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8253 g_return_val_if_fail (item->state_set, NULL);
8258 icon_view = GTK_ICON_VIEW (item->widget);
8259 if (icon_view->priv->cursor_item == item->item)
8260 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8262 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8263 if (item->item->selected)
8264 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8266 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8268 return g_object_ref (item->state_set);
8272 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8274 GObjectClass *gobject_class;
8276 accessible_item_parent_class = g_type_class_peek_parent (klass);
8278 gobject_class = (GObjectClass *)klass;
8280 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8282 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8283 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8284 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8288 gtk_icon_view_item_accessible_get_type (void)
8290 static GType type = 0;
8294 const GTypeInfo tinfo =
8296 sizeof (GtkIconViewItemAccessibleClass),
8297 (GBaseInitFunc) NULL, /* base init */
8298 (GBaseFinalizeFunc) NULL, /* base finalize */
8299 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8300 (GClassFinalizeFunc) NULL, /* class finalize */
8301 NULL, /* class data */
8302 sizeof (GtkIconViewItemAccessible), /* instance size */
8303 0, /* nb preallocs */
8304 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8305 NULL /* value table */
8308 const GInterfaceInfo atk_component_info =
8310 (GInterfaceInitFunc) atk_component_item_interface_init,
8311 (GInterfaceFinalizeFunc) NULL,
8314 const GInterfaceInfo atk_action_info =
8316 (GInterfaceInitFunc) atk_action_item_interface_init,
8317 (GInterfaceFinalizeFunc) NULL,
8320 const GInterfaceInfo atk_image_info =
8322 (GInterfaceInitFunc) atk_image_item_interface_init,
8323 (GInterfaceFinalizeFunc) NULL,
8326 const GInterfaceInfo atk_text_info =
8328 (GInterfaceInitFunc) atk_text_item_interface_init,
8329 (GInterfaceFinalizeFunc) NULL,
8333 type = g_type_register_static (ATK_TYPE_OBJECT,
8334 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8335 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8336 &atk_component_info);
8337 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8339 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8341 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8348 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8349 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8350 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8352 static GType gtk_icon_view_accessible_get_type (void);
8357 } GtkIconViewAccessible;
8363 } GtkIconViewItemAccessibleInfo;
8369 GtkAdjustment *old_hadj;
8370 GtkAdjustment *old_vadj;
8372 GtkTreeModel *model;
8374 } GtkIconViewAccessiblePrivate;
8376 static GtkIconViewAccessiblePrivate *
8377 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8379 return g_object_get_qdata (G_OBJECT (accessible),
8380 accessible_private_data_quark);
8384 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8388 GtkIconViewItemAccessibleInfo *info;
8389 GtkIconViewItemAccessibleInfo *tmp_info;
8390 GtkIconViewAccessiblePrivate *priv;
8393 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8395 info->index = index;
8397 priv = gtk_icon_view_accessible_get_priv (accessible);
8398 items = priv->items;
8401 tmp_info = items->data;
8402 if (tmp_info->index > index)
8404 items = items->next;
8406 priv->items = g_list_insert_before (priv->items, items, info);
8407 priv->old_hadj = NULL;
8408 priv->old_vadj = NULL;
8412 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8414 GtkIconView *icon_view;
8417 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8421 icon_view = GTK_ICON_VIEW (widget);
8423 return g_list_length (icon_view->priv->items);
8427 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8430 GtkIconViewAccessiblePrivate *priv;
8431 GtkIconViewItemAccessibleInfo *info;
8434 priv = gtk_icon_view_accessible_get_priv (accessible);
8435 items = priv->items;
8440 if (info->index == index)
8442 items = items->next;
8448 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8451 GtkIconView *icon_view;
8455 GtkIconViewItemAccessible *a11y_item;
8457 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8461 icon_view = GTK_ICON_VIEW (widget);
8462 icons = g_list_nth (icon_view->priv->items, index);
8466 GtkIconViewItem *item = icons->data;
8468 g_return_val_if_fail (item->index == index, NULL);
8469 obj = gtk_icon_view_accessible_find_child (accessible, index);
8474 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8475 gtk_icon_view_item_accessible_info_new (accessible,
8478 obj->role = ATK_ROLE_ICON;
8479 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8480 a11y_item->item = item;
8481 a11y_item->widget = widget;
8482 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8484 text = get_text (icon_view, item);
8487 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8491 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8492 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8500 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8503 GtkIconViewAccessiblePrivate *priv;
8504 GtkIconViewItemAccessibleInfo *info;
8505 GtkIconViewItemAccessible *item;
8508 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8512 gboolean act_on_item;
8514 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8518 items = priv->items;
8520 act_on_item = (list == NULL);
8525 info = (GtkIconViewItemAccessibleInfo *)items->data;
8526 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8528 if (act_on_item == FALSE && list == items)
8532 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8534 items = items->next;
8540 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8541 GtkIconViewAccessible *view)
8543 gtk_icon_view_accessible_traverse_items (view, NULL);
8547 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8548 GtkOrientation orientation,
8549 GtkAdjustment *adjustment)
8551 GtkIconViewAccessiblePrivate *priv;
8552 GtkAdjustment **old_adj_ptr;
8554 priv = gtk_icon_view_accessible_get_priv (accessible);
8556 /* Adjustments are set for the first time in constructor and priv is not
8557 * initialized at that time, so skip this first setting. */
8561 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8563 if (priv->old_hadj == adjustment)
8566 old_adj_ptr = &priv->old_hadj;
8570 if (priv->old_vadj == adjustment)
8573 old_adj_ptr = &priv->old_vadj;
8576 /* Disconnect signal handlers */
8579 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8580 (gpointer *)&priv->old_hadj);
8581 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8582 gtk_icon_view_accessible_adjustment_changed,
8586 /* Connect signal */
8587 *old_adj_ptr = adjustment;
8588 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8589 g_signal_connect (adjustment, "value-changed",
8590 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8595 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8603 GtkIconView *icon_view;
8604 GtkIconViewItem *item;
8605 GtkIconViewItemAccessible *a11y_item;
8609 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8610 index = gtk_tree_path_get_indices(path)[0];
8611 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8612 gtk_icon_view_accessible_find_child (atk_obj, index));
8616 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8617 icon_view = GTK_ICON_VIEW (widget);
8618 item = a11y_item->item;
8620 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8622 if (!name || strcmp (name, "") == 0)
8624 text = get_text (icon_view, item);
8627 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8633 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8639 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8644 GtkIconViewAccessiblePrivate *priv;
8645 GtkIconViewItemAccessibleInfo *info;
8646 GtkIconViewAccessible *view;
8647 GtkIconViewItemAccessible *item;
8653 index = gtk_tree_path_get_indices(path)[0];
8654 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8655 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8656 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8658 items = priv->items;
8663 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8664 if (info->index != item->item->index)
8666 if (info->index < index)
8667 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8669 if (tmp_list == NULL)
8672 info->index = item->item->index;
8675 items = items->next;
8677 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8678 g_signal_emit_by_name (atk_obj, "children-changed::add",
8684 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8688 GtkIconViewAccessiblePrivate *priv;
8689 GtkIconViewItemAccessibleInfo *info;
8690 GtkIconViewAccessible *view;
8691 GtkIconViewItemAccessible *item;
8694 GList *deleted_item;
8698 index = gtk_tree_path_get_indices(path)[0];
8699 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8700 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8701 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8703 items = priv->items;
8705 deleted_item = NULL;
8710 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8711 if (info->index == index)
8713 deleted_item = items;
8715 if (info->index != item->item->index)
8717 if (tmp_list == NULL)
8720 info->index = item->item->index;
8723 items = items->next;
8725 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8728 info = deleted_item->data;
8729 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8730 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8732 priv->items = g_list_remove_link (priv->items, deleted_item);
8740 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8741 GtkIconViewItemAccessibleInfo *i2)
8743 return i1->index - i2->index;
8747 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8753 GtkIconViewAccessiblePrivate *priv;
8754 GtkIconViewItemAccessibleInfo *info;
8755 GtkIconView *icon_view;
8756 GtkIconViewItemAccessible *item;
8762 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8763 icon_view = GTK_ICON_VIEW (user_data);
8764 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8766 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8768 order = g_new (gint, length);
8769 for (i = 0; i < length; i++)
8770 order [new_order[i]] = i;
8772 items = priv->items;
8776 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8777 info->index = order[info->index];
8778 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8779 items = items->next;
8782 priv->items = g_list_sort (priv->items,
8783 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8789 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8794 obj = G_OBJECT (model);
8795 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8796 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8797 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8798 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8802 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8806 obj = G_OBJECT (icon_view->priv->model);
8807 g_signal_connect_data (obj, "row-changed",
8808 (GCallback) gtk_icon_view_accessible_model_row_changed,
8809 icon_view, NULL, 0);
8810 g_signal_connect_data (obj, "row-inserted",
8811 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8812 icon_view, NULL, G_CONNECT_AFTER);
8813 g_signal_connect_data (obj, "row-deleted",
8814 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8815 icon_view, NULL, G_CONNECT_AFTER);
8816 g_signal_connect_data (obj, "rows-reordered",
8817 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8818 icon_view, NULL, G_CONNECT_AFTER);
8822 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8824 GtkIconViewItemAccessibleInfo *info;
8827 items = priv->items;
8830 info = (GtkIconViewItemAccessibleInfo *) items->data;
8831 g_object_unref (info->item);
8832 g_free (items->data);
8833 items = items->next;
8835 g_list_free (priv->items);
8840 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8843 GtkIconView *icon_view;
8846 GtkIconViewAccessiblePrivate *priv;
8848 if (strcmp (pspec->name, "model") == 0)
8850 widget = GTK_WIDGET (obj);
8851 atk_obj = gtk_widget_get_accessible (widget);
8852 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8855 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8856 (gpointer *)&priv->model);
8857 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8859 gtk_icon_view_accessible_clear_cache (priv);
8861 icon_view = GTK_ICON_VIEW (obj);
8862 priv->model = icon_view->priv->model;
8863 /* If there is no model the GtkIconView is probably being destroyed */
8866 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8867 gtk_icon_view_accessible_connect_model_signals (icon_view);
8875 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8878 GtkIconViewAccessiblePrivate *priv;
8879 GtkIconView *icon_view;
8881 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8882 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8884 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8885 g_object_set_qdata (G_OBJECT (accessible),
8886 accessible_private_data_quark,
8889 icon_view = GTK_ICON_VIEW (data);
8890 if (icon_view->priv->hadjustment)
8891 gtk_icon_view_accessible_set_adjustment (accessible,
8892 GTK_ORIENTATION_HORIZONTAL,
8893 icon_view->priv->hadjustment);
8894 if (icon_view->priv->vadjustment)
8895 gtk_icon_view_accessible_set_adjustment (accessible,
8896 GTK_ORIENTATION_VERTICAL,
8897 icon_view->priv->vadjustment);
8898 g_signal_connect (data,
8900 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8903 priv->model = icon_view->priv->model;
8906 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8907 gtk_icon_view_accessible_connect_model_signals (icon_view);
8910 accessible->role = ATK_ROLE_LAYERED_PANE;
8914 gtk_icon_view_accessible_finalize (GObject *object)
8916 GtkIconViewAccessiblePrivate *priv;
8918 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8919 gtk_icon_view_accessible_clear_cache (priv);
8923 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8927 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8928 GtkAccessible *accessible)
8931 GtkIconViewAccessiblePrivate *priv;
8933 atk_obj = ATK_OBJECT (accessible);
8934 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8937 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8938 (gpointer *)&priv->old_hadj);
8940 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8941 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8943 priv->old_hadj = NULL;
8947 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8948 (gpointer *)&priv->old_vadj);
8950 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8951 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8953 priv->old_vadj = NULL;
8958 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8962 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8965 g_signal_connect_after (widget,
8967 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8970 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8974 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8976 GObjectClass *gobject_class;
8977 GtkAccessibleClass *accessible_class;
8979 accessible_parent_class = g_type_class_peek_parent (klass);
8981 gobject_class = (GObjectClass *)klass;
8982 accessible_class = (GtkAccessibleClass *)klass;
8984 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8986 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8987 klass->ref_child = gtk_icon_view_accessible_ref_child;
8988 klass->initialize = gtk_icon_view_accessible_initialize;
8990 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8992 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8996 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8999 AtkCoordType coord_type)
9002 GtkIconView *icon_view;
9003 GtkIconViewItem *item;
9006 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9008 /* State is defunct */
9011 icon_view = GTK_ICON_VIEW (widget);
9012 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9013 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9015 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9021 atk_component_interface_init (AtkComponentIface *iface)
9023 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9027 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9031 GtkIconView *icon_view;
9032 GtkIconViewItem *item;
9034 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9038 icon_view = GTK_ICON_VIEW (widget);
9040 item = g_list_nth_data (icon_view->priv->items, i);
9045 gtk_icon_view_select_item (icon_view, item);
9051 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9054 GtkIconView *icon_view;
9056 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9060 icon_view = GTK_ICON_VIEW (widget);
9061 gtk_icon_view_unselect_all (icon_view);
9067 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9072 GtkIconView *icon_view;
9073 GtkIconViewItem *item;
9075 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9079 icon_view = GTK_ICON_VIEW (widget);
9081 l = icon_view->priv->items;
9088 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9099 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9102 GtkIconView *icon_view;
9103 GtkIconViewItem *item;
9107 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9111 icon_view = GTK_ICON_VIEW (widget);
9113 l = icon_view->priv->items;
9129 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9133 GtkIconView *icon_view;
9134 GtkIconViewItem *item;
9136 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9140 icon_view = GTK_ICON_VIEW (widget);
9142 item = g_list_nth_data (icon_view->priv->items, i);
9146 return item->selected;
9150 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9154 GtkIconView *icon_view;
9155 GtkIconViewItem *item;
9159 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9163 icon_view = GTK_ICON_VIEW (widget);
9164 l = icon_view->priv->items;
9173 gtk_icon_view_unselect_item (icon_view, item);
9185 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9188 GtkIconView *icon_view;
9190 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9194 icon_view = GTK_ICON_VIEW (widget);
9195 gtk_icon_view_select_all (icon_view);
9200 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9202 iface->add_selection = gtk_icon_view_accessible_add_selection;
9203 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9204 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9205 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9206 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9207 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9208 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9212 gtk_icon_view_accessible_get_type (void)
9214 static GType type = 0;
9221 (GBaseInitFunc) NULL, /* base init */
9222 (GBaseFinalizeFunc) NULL, /* base finalize */
9223 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9224 (GClassFinalizeFunc) NULL, /* class finalize */
9225 NULL, /* class data */
9226 0, /* instance size */
9227 0, /* nb preallocs */
9228 (GInstanceInitFunc) NULL, /* instance init */
9229 NULL /* value table */
9231 const GInterfaceInfo atk_component_info =
9233 (GInterfaceInitFunc) atk_component_interface_init,
9234 (GInterfaceFinalizeFunc) NULL,
9237 const GInterfaceInfo atk_selection_info =
9239 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9240 (GInterfaceFinalizeFunc) NULL,
9245 * Figure out the size of the class and instance
9246 * we are deriving from
9248 AtkObjectFactory *factory;
9251 GType derived_atk_type;
9253 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9254 factory = atk_registry_get_factory (atk_get_default_registry (),
9256 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9257 g_type_query (derived_atk_type, &query);
9258 tinfo.class_size = query.class_size;
9259 tinfo.instance_size = query.instance_size;
9261 type = g_type_register_static (derived_atk_type,
9262 I_("GtkIconViewAccessible"),
9264 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9265 &atk_component_info);
9266 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9267 &atk_selection_info);
9273 gtk_icon_view_accessible_new (GObject *obj)
9275 AtkObject *accessible;
9277 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9279 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9280 atk_object_initialize (accessible, obj);
9286 gtk_icon_view_accessible_factory_get_accessible_type (void)
9288 return gtk_icon_view_accessible_get_type ();
9292 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9294 return gtk_icon_view_accessible_new (obj);
9298 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9300 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9301 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9305 gtk_icon_view_accessible_factory_get_type (void)
9307 static GType type = 0;
9311 const GTypeInfo tinfo =
9313 sizeof (AtkObjectFactoryClass),
9314 NULL, /* base_init */
9315 NULL, /* base_finalize */
9316 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9317 NULL, /* class_finalize */
9318 NULL, /* class_data */
9319 sizeof (AtkObjectFactory),
9320 0, /* n_preallocs */
9324 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9325 I_("GtkIconViewAccessibleFactory"),
9333 gtk_icon_view_get_accessible (GtkWidget *widget)
9335 static gboolean first_time = TRUE;
9339 _gtk_accessible_set_factory_type (GTK_TYPE_ICON_VIEW,
9340 gtk_icon_view_accessible_factory_get_type ());
9343 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9347 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9348 GtkBuilder *builder,
9350 const gchar *tagname,
9351 GMarkupParser *parser,
9354 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9355 tagname, parser, data))
9358 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9359 tagname, parser, data);
9363 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9364 GtkBuilder *builder,
9366 const gchar *tagname,
9369 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9370 child, tagname, data))
9371 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,