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.
764 g_object_class_install_property (gobject_class,
766 g_param_spec_object ("cell-area",
768 P_("The GtkCellArea used to layout cells"),
770 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
772 /* Scrollable interface properties */
773 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
774 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
775 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
776 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
778 /* Style properties */
779 gtk_widget_class_install_style_property (widget_class,
780 g_param_spec_boxed ("selection-box-color",
781 P_("Selection Box Color"),
782 P_("Color of the selection box"),
784 GTK_PARAM_READABLE));
786 gtk_widget_class_install_style_property (widget_class,
787 g_param_spec_uchar ("selection-box-alpha",
788 P_("Selection Box Alpha"),
789 P_("Opacity of the selection box"),
792 GTK_PARAM_READABLE));
796 * GtkIconView::item-activated:
797 * @iconview: the object on which the signal is emitted
798 * @path: the #GtkTreePath for the activated item
800 * The ::item-activated signal is emitted when the method
801 * gtk_icon_view_item_activated() is called or the user double
802 * clicks an item. It is also emitted when a non-editable item
803 * is selected and one of the keys: Space, Return or Enter is
806 icon_view_signals[ITEM_ACTIVATED] =
807 g_signal_new (I_("item-activated"),
808 G_TYPE_FROM_CLASS (gobject_class),
810 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
812 g_cclosure_marshal_VOID__BOXED,
817 * GtkIconView::selection-changed:
818 * @iconview: the object on which the signal is emitted
820 * The ::selection-changed signal is emitted when the selection
821 * (i.e. the set of selected items) changes.
823 icon_view_signals[SELECTION_CHANGED] =
824 g_signal_new (I_("selection-changed"),
825 G_TYPE_FROM_CLASS (gobject_class),
827 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
829 g_cclosure_marshal_VOID__VOID,
833 * GtkIconView::select-all:
834 * @iconview: the object on which the signal is emitted
836 * A <link linkend="keybinding-signals">keybinding signal</link>
837 * which gets emitted when the user selects all items.
839 * Applications should not connect to it, but may emit it with
840 * g_signal_emit_by_name() if they need to control selection
843 * The default binding for this signal is Ctrl-a.
845 icon_view_signals[SELECT_ALL] =
846 g_signal_new (I_("select-all"),
847 G_TYPE_FROM_CLASS (gobject_class),
848 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
849 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
851 g_cclosure_marshal_VOID__VOID,
855 * GtkIconView::unselect-all:
856 * @iconview: the object on which the signal is emitted
858 * A <link linkend="keybinding-signals">keybinding signal</link>
859 * which gets emitted when the user unselects all items.
861 * Applications should not connect to it, but may emit it with
862 * g_signal_emit_by_name() if they need to control selection
865 * The default binding for this signal is Ctrl-Shift-a.
867 icon_view_signals[UNSELECT_ALL] =
868 g_signal_new (I_("unselect-all"),
869 G_TYPE_FROM_CLASS (gobject_class),
870 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
871 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
873 g_cclosure_marshal_VOID__VOID,
877 * GtkIconView::select-cursor-item:
878 * @iconview: the object on which the signal is emitted
880 * A <link linkend="keybinding-signals">keybinding signal</link>
881 * which gets emitted when the user selects the item that is currently
884 * Applications should not connect to it, but may emit it with
885 * g_signal_emit_by_name() if they need to control selection
888 * There is no default binding for this signal.
890 icon_view_signals[SELECT_CURSOR_ITEM] =
891 g_signal_new (I_("select-cursor-item"),
892 G_TYPE_FROM_CLASS (gobject_class),
893 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
894 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
896 g_cclosure_marshal_VOID__VOID,
900 * GtkIconView::toggle-cursor-item:
901 * @iconview: the object on which the signal is emitted
903 * A <link linkend="keybinding-signals">keybinding signal</link>
904 * which gets emitted when the user toggles whether the currently
905 * focused item is selected or not. The exact effect of this
906 * depend on the selection mode.
908 * Applications should not connect to it, but may emit it with
909 * g_signal_emit_by_name() if they need to control selection
912 * There is no default binding for this signal is Ctrl-Space.
914 icon_view_signals[TOGGLE_CURSOR_ITEM] =
915 g_signal_new (I_("toggle-cursor-item"),
916 G_TYPE_FROM_CLASS (gobject_class),
917 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
918 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
920 g_cclosure_marshal_VOID__VOID,
924 * GtkIconView::activate-cursor-item:
925 * @iconview: the object on which the signal is emitted
927 * A <link linkend="keybinding-signals">keybinding signal</link>
928 * which gets emitted when the user activates the currently
931 * Applications should not connect to it, but may emit it with
932 * g_signal_emit_by_name() if they need to control activation
935 * The default bindings for this signal are Space, Return and Enter.
937 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
938 g_signal_new (I_("activate-cursor-item"),
939 G_TYPE_FROM_CLASS (gobject_class),
940 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
941 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
943 _gtk_marshal_BOOLEAN__VOID,
947 * GtkIconView::move-cursor:
948 * @iconview: the object which received the signal
949 * @step: the granularity of the move, as a #GtkMovementStep
950 * @count: the number of @step units to move
952 * The ::move-cursor signal is a
953 * <link linkend="keybinding-signals">keybinding signal</link>
954 * which gets emitted when the user initiates a cursor movement.
956 * Applications should not connect to it, but may emit it with
957 * g_signal_emit_by_name() if they need to control the cursor
960 * The default bindings for this signal include
962 * <listitem>Arrow keys which move by individual steps</listitem>
963 * <listitem>Home/End keys which move to the first/last item</listitem>
964 * <listitem>PageUp/PageDown which move by "pages"</listitem>
967 * All of these will extend the selection when combined with
968 * the Shift modifier.
970 icon_view_signals[MOVE_CURSOR] =
971 g_signal_new (I_("move-cursor"),
972 G_TYPE_FROM_CLASS (gobject_class),
973 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
974 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
976 _gtk_marshal_BOOLEAN__ENUM_INT,
978 GTK_TYPE_MOVEMENT_STEP,
982 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
984 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
986 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
987 "toggle-cursor-item", 0);
988 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
989 "toggle-cursor-item", 0);
991 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
992 "activate-cursor-item", 0);
993 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
994 "activate-cursor-item", 0);
995 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
996 "activate-cursor-item", 0);
997 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
998 "activate-cursor-item", 0);
999 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1000 "activate-cursor-item", 0);
1002 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1003 GTK_MOVEMENT_DISPLAY_LINES, -1);
1004 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1005 GTK_MOVEMENT_DISPLAY_LINES, -1);
1007 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1008 GTK_MOVEMENT_DISPLAY_LINES, 1);
1009 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1010 GTK_MOVEMENT_DISPLAY_LINES, 1);
1012 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1013 GTK_MOVEMENT_DISPLAY_LINES, -1);
1015 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1016 GTK_MOVEMENT_DISPLAY_LINES, 1);
1018 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1019 GTK_MOVEMENT_BUFFER_ENDS, -1);
1020 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1021 GTK_MOVEMENT_BUFFER_ENDS, -1);
1023 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1024 GTK_MOVEMENT_BUFFER_ENDS, 1);
1025 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1026 GTK_MOVEMENT_BUFFER_ENDS, 1);
1028 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1029 GTK_MOVEMENT_PAGES, -1);
1030 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1031 GTK_MOVEMENT_PAGES, -1);
1033 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1034 GTK_MOVEMENT_PAGES, 1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1036 GTK_MOVEMENT_PAGES, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1039 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1041 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1044 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1046 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1050 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1052 parent_buildable_iface = g_type_interface_peek_parent (iface);
1053 iface->add_child = _gtk_cell_layout_buildable_add_child;
1054 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1055 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1059 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1061 iface->get_area = gtk_icon_view_cell_layout_get_area;
1065 gtk_icon_view_init (GtkIconView *icon_view)
1067 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1069 GtkIconViewPrivate);
1071 icon_view->priv->width = 0;
1072 icon_view->priv->height = 0;
1073 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1074 icon_view->priv->pressed_button = -1;
1075 icon_view->priv->press_start_x = -1;
1076 icon_view->priv->press_start_y = -1;
1077 icon_view->priv->text_column = -1;
1078 icon_view->priv->markup_column = -1;
1079 icon_view->priv->pixbuf_column = -1;
1080 icon_view->priv->text_cell = NULL;
1081 icon_view->priv->pixbuf_cell = NULL;
1082 icon_view->priv->tooltip_column = -1;
1084 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1086 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1088 icon_view->priv->columns = -1;
1089 icon_view->priv->item_width = -1;
1090 icon_view->priv->spacing = 0;
1091 icon_view->priv->row_spacing = 6;
1092 icon_view->priv->column_spacing = 6;
1093 icon_view->priv->margin = 6;
1094 icon_view->priv->item_padding = 6;
1096 icon_view->priv->draw_focus = TRUE;
1098 icon_view->priv->row_contexts =
1099 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1102 /* GObject methods */
1104 gtk_icon_view_constructor (GType type,
1105 guint n_construct_properties,
1106 GObjectConstructParam *construct_properties)
1108 GtkIconView *icon_view;
1111 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1112 (type, n_construct_properties, construct_properties);
1114 icon_view = (GtkIconView *) object;
1116 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1122 gtk_icon_view_dispose (GObject *object)
1124 GtkIconView *icon_view;
1125 GtkIconViewPrivate *priv;
1127 icon_view = GTK_ICON_VIEW (object);
1128 priv = icon_view->priv;
1130 if (priv->cell_area_context)
1132 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1133 priv->context_changed_id = 0;
1135 g_object_unref (priv->cell_area_context);
1136 priv->cell_area_context = NULL;
1139 if (priv->row_contexts)
1141 g_ptr_array_free (priv->row_contexts, TRUE);
1142 priv->row_contexts = NULL;
1145 if (priv->cell_area)
1147 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1149 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1150 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1151 priv->add_editable_id = 0;
1152 priv->remove_editable_id = 0;
1154 g_object_unref (priv->cell_area);
1155 priv->cell_area = NULL;
1158 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1162 gtk_icon_view_set_property (GObject *object,
1164 const GValue *value,
1167 GtkIconView *icon_view;
1170 icon_view = GTK_ICON_VIEW (object);
1174 case PROP_SELECTION_MODE:
1175 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1177 case PROP_PIXBUF_COLUMN:
1178 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1180 case PROP_TEXT_COLUMN:
1181 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1183 case PROP_MARKUP_COLUMN:
1184 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1187 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1189 case PROP_ITEM_ORIENTATION:
1190 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1193 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1195 case PROP_ITEM_WIDTH:
1196 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1199 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1201 case PROP_ROW_SPACING:
1202 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1204 case PROP_COLUMN_SPACING:
1205 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1208 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1210 case PROP_REORDERABLE:
1211 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1214 case PROP_TOOLTIP_COLUMN:
1215 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1218 case PROP_ITEM_PADDING:
1219 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1222 case PROP_CELL_AREA:
1223 /* Construct-only, can only be assigned once */
1224 area = g_value_get_object (value);
1227 if (icon_view->priv->cell_area != NULL)
1229 g_warning ("cell-area has already been set, ignoring construct property");
1230 g_object_ref_sink (area);
1231 g_object_unref (area);
1234 gtk_icon_view_ensure_cell_area (icon_view, area);
1238 case PROP_HADJUSTMENT:
1239 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1241 case PROP_VADJUSTMENT:
1242 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1244 case PROP_HSCROLL_POLICY:
1245 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1246 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1248 case PROP_VSCROLL_POLICY:
1249 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1250 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1260 gtk_icon_view_get_property (GObject *object,
1265 GtkIconView *icon_view;
1267 icon_view = GTK_ICON_VIEW (object);
1271 case PROP_SELECTION_MODE:
1272 g_value_set_enum (value, icon_view->priv->selection_mode);
1274 case PROP_PIXBUF_COLUMN:
1275 g_value_set_int (value, icon_view->priv->pixbuf_column);
1277 case PROP_TEXT_COLUMN:
1278 g_value_set_int (value, icon_view->priv->text_column);
1280 case PROP_MARKUP_COLUMN:
1281 g_value_set_int (value, icon_view->priv->markup_column);
1284 g_value_set_object (value, icon_view->priv->model);
1286 case PROP_ITEM_ORIENTATION:
1287 g_value_set_enum (value, icon_view->priv->item_orientation);
1290 g_value_set_int (value, icon_view->priv->columns);
1292 case PROP_ITEM_WIDTH:
1293 g_value_set_int (value, icon_view->priv->item_width);
1296 g_value_set_int (value, icon_view->priv->spacing);
1298 case PROP_ROW_SPACING:
1299 g_value_set_int (value, icon_view->priv->row_spacing);
1301 case PROP_COLUMN_SPACING:
1302 g_value_set_int (value, icon_view->priv->column_spacing);
1305 g_value_set_int (value, icon_view->priv->margin);
1307 case PROP_REORDERABLE:
1308 g_value_set_boolean (value, icon_view->priv->reorderable);
1310 case PROP_TOOLTIP_COLUMN:
1311 g_value_set_int (value, icon_view->priv->tooltip_column);
1314 case PROP_ITEM_PADDING:
1315 g_value_set_int (value, icon_view->priv->item_padding);
1318 case PROP_CELL_AREA:
1319 g_value_set_object (value, icon_view->priv->cell_area);
1322 case PROP_HADJUSTMENT:
1323 g_value_set_object (value, icon_view->priv->hadjustment);
1325 case PROP_VADJUSTMENT:
1326 g_value_set_object (value, icon_view->priv->vadjustment);
1328 case PROP_HSCROLL_POLICY:
1329 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1331 case PROP_VSCROLL_POLICY:
1332 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1341 /* GtkWidget methods */
1343 gtk_icon_view_destroy (GtkWidget *widget)
1345 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1347 gtk_icon_view_set_model (icon_view, NULL);
1349 if (icon_view->priv->layout_idle_id != 0)
1351 g_source_remove (icon_view->priv->layout_idle_id);
1352 icon_view->priv->layout_idle_id = 0;
1355 if (icon_view->priv->scroll_to_path != NULL)
1357 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1358 icon_view->priv->scroll_to_path = NULL;
1361 remove_scroll_timeout (icon_view);
1363 if (icon_view->priv->hadjustment != NULL)
1365 g_object_unref (icon_view->priv->hadjustment);
1366 icon_view->priv->hadjustment = NULL;
1369 if (icon_view->priv->vadjustment != NULL)
1371 g_object_unref (icon_view->priv->vadjustment);
1372 icon_view->priv->vadjustment = NULL;
1375 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1379 gtk_icon_view_realize (GtkWidget *widget)
1381 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1382 GtkAllocation allocation;
1384 GdkWindowAttr attributes;
1385 gint attributes_mask;
1386 GtkStyleContext *context;
1388 gtk_widget_set_realized (widget, TRUE);
1390 gtk_widget_get_allocation (widget, &allocation);
1392 /* Make the main, clipping window */
1393 attributes.window_type = GDK_WINDOW_CHILD;
1394 attributes.x = allocation.x;
1395 attributes.y = allocation.y;
1396 attributes.width = allocation.width;
1397 attributes.height = allocation.height;
1398 attributes.wclass = GDK_INPUT_OUTPUT;
1399 attributes.visual = gtk_widget_get_visual (widget);
1400 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1402 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1404 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1405 &attributes, attributes_mask);
1406 gtk_widget_set_window (widget, window);
1407 gdk_window_set_user_data (window, widget);
1409 gtk_widget_get_allocation (widget, &allocation);
1411 /* Make the window for the icon view */
1414 attributes.width = MAX (icon_view->priv->width, allocation.width);
1415 attributes.height = MAX (icon_view->priv->height, allocation.height);
1416 attributes.event_mask = (GDK_EXPOSURE_MASK |
1418 GDK_POINTER_MOTION_MASK |
1419 GDK_BUTTON_PRESS_MASK |
1420 GDK_BUTTON_RELEASE_MASK |
1421 GDK_KEY_PRESS_MASK |
1422 GDK_KEY_RELEASE_MASK) |
1423 gtk_widget_get_events (widget);
1425 icon_view->priv->bin_window = gdk_window_new (window,
1426 &attributes, attributes_mask);
1427 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1429 context = gtk_widget_get_style_context (widget);
1431 gtk_style_context_save (context);
1432 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1433 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1434 gtk_style_context_restore (context);
1436 gdk_window_show (icon_view->priv->bin_window);
1440 gtk_icon_view_unrealize (GtkWidget *widget)
1442 GtkIconView *icon_view;
1444 icon_view = GTK_ICON_VIEW (widget);
1446 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1447 gdk_window_destroy (icon_view->priv->bin_window);
1448 icon_view->priv->bin_window = NULL;
1450 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1454 _gtk_icon_view_update_background (GtkIconView *icon_view)
1456 GtkWidget *widget = GTK_WIDGET (icon_view);
1458 if (gtk_widget_get_realized (widget))
1460 GtkStyleContext *context;
1462 context = gtk_widget_get_style_context (widget);
1464 gtk_style_context_save (context);
1465 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1467 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1468 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1470 gtk_style_context_restore (context);
1475 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1476 GtkStateFlags previous_state)
1478 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1479 gtk_widget_queue_draw (widget);
1483 gtk_icon_view_style_updated (GtkWidget *widget)
1485 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1487 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1488 gtk_widget_queue_resize (widget);
1492 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1496 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1500 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1504 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1508 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1512 for (list = icon_view->priv->children; list; list = list->next)
1514 GtkIconViewChild *child = list->data;
1516 /* totally ignore our child's requisition */
1517 gtk_widget_size_allocate (child->widget, &child->area);
1522 gtk_icon_view_size_allocate (GtkWidget *widget,
1523 GtkAllocation *allocation)
1525 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1527 gtk_widget_set_allocation (widget, allocation);
1529 if (gtk_widget_get_realized (widget))
1531 gdk_window_move_resize (gtk_widget_get_window (widget),
1532 allocation->x, allocation->y,
1533 allocation->width, allocation->height);
1534 gdk_window_resize (icon_view->priv->bin_window,
1535 MAX (icon_view->priv->width, allocation->width),
1536 MAX (icon_view->priv->height, allocation->height));
1539 gtk_icon_view_layout (icon_view);
1541 gtk_icon_view_allocate_children (icon_view);
1543 /* Delay signal emission */
1544 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1545 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1547 gtk_icon_view_set_hadjustment_values (icon_view);
1548 gtk_icon_view_set_vadjustment_values (icon_view);
1550 if (gtk_widget_get_realized (widget) &&
1551 icon_view->priv->scroll_to_path)
1554 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1555 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1556 icon_view->priv->scroll_to_path = NULL;
1558 gtk_icon_view_scroll_to_path (icon_view, path,
1559 icon_view->priv->scroll_to_use_align,
1560 icon_view->priv->scroll_to_row_align,
1561 icon_view->priv->scroll_to_col_align);
1562 gtk_tree_path_free (path);
1565 /* Emit any pending signals now */
1566 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1567 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1571 gtk_icon_view_draw (GtkWidget *widget,
1574 GtkIconView *icon_view;
1578 GtkIconViewDropPosition dest_pos;
1579 GtkIconViewItem *dest_item = NULL;
1581 icon_view = GTK_ICON_VIEW (widget);
1583 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1588 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1590 cairo_set_line_width (cr, 1.);
1592 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1596 dest_index = gtk_tree_path_get_indices (path)[0];
1597 gtk_tree_path_free (path);
1602 for (icons = icon_view->priv->items; icons; icons = icons->next)
1604 GtkIconViewItem *item = icons->data;
1605 GdkRectangle paint_area;
1607 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1608 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1609 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1610 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1614 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1617 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1619 gtk_icon_view_paint_item (icon_view, cr, item,
1620 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1621 icon_view->priv->draw_focus);
1623 if (dest_index == item->index)
1631 dest_pos != GTK_ICON_VIEW_NO_DROP)
1633 GtkStyleContext *context;
1634 GtkStateFlags state;
1635 GdkRectangle rect = { 0 };
1637 context = gtk_widget_get_style_context (widget);
1638 state = gtk_widget_get_state_flags (widget);
1642 case GTK_ICON_VIEW_DROP_INTO:
1643 rect = dest_item->cell_area;
1645 case GTK_ICON_VIEW_DROP_ABOVE:
1646 rect.x = dest_item->cell_area.x;
1647 rect.y = dest_item->cell_area.y - 1;
1648 rect.width = dest_item->cell_area.width;
1651 case GTK_ICON_VIEW_DROP_LEFT:
1652 rect.x = dest_item->cell_area.x - 1;
1653 rect.y = dest_item->cell_area.y;
1655 rect.height = dest_item->cell_area.height;
1657 case GTK_ICON_VIEW_DROP_BELOW:
1658 rect.x = dest_item->cell_area.x;
1659 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1660 rect.width = dest_item->cell_area.width;
1663 case GTK_ICON_VIEW_DROP_RIGHT:
1664 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1665 rect.y = dest_item->cell_area.y;
1667 rect.height = dest_item->cell_area.height;
1668 case GTK_ICON_VIEW_NO_DROP: ;
1672 gtk_style_context_set_state (context, state);
1673 gtk_render_focus (context, cr,
1675 rect.width, rect.height);
1678 if (icon_view->priv->doing_rubberband)
1679 gtk_icon_view_paint_rubberband (icon_view, cr);
1683 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1689 rubberband_scroll_timeout (gpointer data)
1691 GtkIconView *icon_view = data;
1693 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1694 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1695 icon_view->priv->scroll_value_diff);
1697 gtk_icon_view_update_rubberband (icon_view);
1703 gtk_icon_view_motion (GtkWidget *widget,
1704 GdkEventMotion *event)
1706 GtkAllocation allocation;
1707 GtkIconView *icon_view;
1710 icon_view = GTK_ICON_VIEW (widget);
1712 gtk_icon_view_maybe_begin_drag (icon_view, event);
1714 if (icon_view->priv->doing_rubberband)
1716 gtk_icon_view_update_rubberband (widget);
1718 abs_y = event->y - icon_view->priv->height *
1719 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1720 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1721 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1723 gtk_widget_get_allocation (widget, &allocation);
1725 if (abs_y < 0 || abs_y > allocation.height)
1728 icon_view->priv->scroll_value_diff = abs_y;
1730 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1732 icon_view->priv->event_last_x = event->x;
1733 icon_view->priv->event_last_y = event->y;
1735 if (icon_view->priv->scroll_timeout_id == 0)
1736 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1740 remove_scroll_timeout (icon_view);
1747 gtk_icon_view_remove (GtkContainer *container,
1750 GtkIconView *icon_view;
1751 GtkIconViewChild *child = NULL;
1754 icon_view = GTK_ICON_VIEW (container);
1756 tmp_list = icon_view->priv->children;
1759 child = tmp_list->data;
1760 if (child->widget == widget)
1762 gtk_widget_unparent (widget);
1764 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1765 g_list_free_1 (tmp_list);
1770 tmp_list = tmp_list->next;
1775 gtk_icon_view_forall (GtkContainer *container,
1776 gboolean include_internals,
1777 GtkCallback callback,
1778 gpointer callback_data)
1780 GtkIconView *icon_view;
1781 GtkIconViewChild *child = NULL;
1784 icon_view = GTK_ICON_VIEW (container);
1786 tmp_list = icon_view->priv->children;
1789 child = tmp_list->data;
1790 tmp_list = tmp_list->next;
1792 (* callback) (child->widget, callback_data);
1797 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1798 GtkIconViewItem *item)
1801 AtkObject *item_obj;
1803 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1806 item_obj = atk_object_ref_accessible_child (obj, item->index);
1807 if (item_obj != NULL)
1809 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1810 g_object_unref (item_obj);
1816 gtk_icon_view_add_editable (GtkCellArea *area,
1817 GtkCellRenderer *renderer,
1818 GtkCellEditable *editable,
1819 GdkRectangle *cell_area,
1821 GtkIconView *icon_view)
1823 GtkIconViewChild *child;
1824 GtkWidget *widget = GTK_WIDGET (editable);
1826 child = g_new (GtkIconViewChild, 1);
1828 child->widget = widget;
1829 child->area.x = cell_area->x;
1830 child->area.y = cell_area->y;
1831 child->area.width = cell_area->width;
1832 child->area.height = cell_area->height;
1834 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1836 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1837 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1839 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1843 gtk_icon_view_remove_editable (GtkCellArea *area,
1844 GtkCellRenderer *renderer,
1845 GtkCellEditable *editable,
1846 GtkIconView *icon_view)
1850 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1851 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1853 gtk_container_remove (GTK_CONTAINER (icon_view),
1854 GTK_WIDGET (editable));
1856 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1857 gtk_icon_view_queue_draw_path (icon_view, path);
1858 gtk_tree_path_free (path);
1862 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1864 GtkIconView *icon_view)
1866 if (!strcmp (pspec->name, "minimum-width") ||
1867 !strcmp (pspec->name, "natural-width") ||
1868 !strcmp (pspec->name, "minimum-height") ||
1869 !strcmp (pspec->name, "natural-height"))
1870 gtk_icon_view_invalidate_sizes (icon_view);
1874 * gtk_icon_view_set_cursor:
1875 * @icon_view: A #GtkIconView
1876 * @path: A #GtkTreePath
1877 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1878 * @start_editing: %TRUE if the specified cell should start being edited.
1880 * Sets the current keyboard focus to be at @path, and selects it. This is
1881 * useful when you want to focus the user's attention on a particular item.
1882 * If @cell is not %NULL, then focus is given to the cell specified by
1883 * it. Additionally, if @start_editing is %TRUE, then editing should be
1884 * started in the specified cell.
1886 * This function is often followed by <literal>gtk_widget_grab_focus
1887 * (icon_view)</literal> in order to give keyboard focus to the widget.
1888 * Please note that editing can only happen when the widget is realized.
1893 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1895 GtkCellRenderer *cell,
1896 gboolean start_editing)
1898 GtkIconViewItem *item = NULL;
1900 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1901 g_return_if_fail (path != NULL);
1902 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1904 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1906 if (gtk_tree_path_get_depth (path) == 1)
1907 item = g_list_nth_data (icon_view->priv->items,
1908 gtk_tree_path_get_indices(path)[0]);
1913 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1914 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1918 GtkCellAreaContext *context;
1920 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1921 gtk_icon_view_set_cell_data (icon_view, item);
1922 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1923 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1924 0 /* XXX flags */, TRUE);
1929 * gtk_icon_view_get_cursor:
1930 * @icon_view: A #GtkIconView
1931 * @path: (out) (allow-none): Return location for the current cursor path,
1933 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1935 * Fills in @path and @cell with the current cursor path and cell.
1936 * If the cursor isn't currently set, then *@path will be %NULL.
1937 * If no cell currently has focus, then *@cell will be %NULL.
1939 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1941 * Return value: %TRUE if the cursor is set.
1946 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1948 GtkCellRenderer **cell)
1950 GtkIconViewItem *item;
1952 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1954 item = icon_view->priv->cursor_item;
1959 *path = gtk_tree_path_new_from_indices (item->index, -1);
1964 if (cell != NULL && item != NULL)
1965 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1967 return (item != NULL);
1971 gtk_icon_view_button_press (GtkWidget *widget,
1972 GdkEventButton *event)
1974 GtkIconView *icon_view;
1975 GtkIconViewItem *item;
1976 gboolean dirty = FALSE;
1977 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1979 icon_view = GTK_ICON_VIEW (widget);
1981 if (event->window != icon_view->priv->bin_window)
1984 if (!gtk_widget_has_focus (widget))
1985 gtk_widget_grab_focus (widget);
1987 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1989 item = gtk_icon_view_get_item_at_coords (icon_view,
1995 * We consider only the the cells' area as the item area if the
1996 * item is not selected, but if it *is* selected, the complete
1997 * selection rectangle is considered to be part of the item.
1999 if (item != NULL && (cell != NULL || item->selected))
2003 if (gtk_cell_renderer_is_activatable (cell))
2007 gtk_icon_view_scroll_to_item (icon_view, item);
2009 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2011 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2013 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2014 (event->state & GDK_SHIFT_MASK))
2016 gtk_icon_view_unselect_all_internal (icon_view);
2018 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2019 if (!icon_view->priv->anchor_item)
2020 icon_view->priv->anchor_item = item;
2022 gtk_icon_view_select_all_between (icon_view,
2023 icon_view->priv->anchor_item,
2029 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2030 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2031 (event->state & GDK_CONTROL_MASK))
2033 item->selected = !item->selected;
2034 gtk_icon_view_queue_draw_item (icon_view, item);
2039 gtk_icon_view_unselect_all_internal (icon_view);
2041 item->selected = TRUE;
2042 gtk_icon_view_queue_draw_item (icon_view, item);
2045 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2046 icon_view->priv->anchor_item = item;
2049 /* Save press to possibly begin a drag */
2050 if (icon_view->priv->pressed_button < 0)
2052 icon_view->priv->pressed_button = event->button;
2053 icon_view->priv->press_start_x = event->x;
2054 icon_view->priv->press_start_y = event->y;
2057 if (!icon_view->priv->last_single_clicked)
2058 icon_view->priv->last_single_clicked = item;
2060 /* cancel the current editing, if it exists */
2061 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2063 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2065 GtkCellAreaContext *context;
2067 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2069 gtk_icon_view_set_cell_data (icon_view, item);
2070 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2071 GTK_WIDGET (icon_view),
2072 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2077 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2078 !(event->state & GDK_CONTROL_MASK))
2080 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2083 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2084 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2087 /* don't draw keyboard focus around an clicked-on item */
2088 icon_view->priv->draw_focus = FALSE;
2091 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2093 item = gtk_icon_view_get_item_at_coords (icon_view,
2098 if (item && item == icon_view->priv->last_single_clicked)
2102 path = gtk_tree_path_new_from_indices (item->index, -1);
2103 gtk_icon_view_item_activated (icon_view, path);
2104 gtk_tree_path_free (path);
2107 icon_view->priv->last_single_clicked = NULL;
2108 icon_view->priv->pressed_button = -1;
2112 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2114 return event->button == 1;
2118 gtk_icon_view_button_release (GtkWidget *widget,
2119 GdkEventButton *event)
2121 GtkIconView *icon_view;
2123 icon_view = GTK_ICON_VIEW (widget);
2125 if (icon_view->priv->pressed_button == event->button)
2126 icon_view->priv->pressed_button = -1;
2128 gtk_icon_view_stop_rubberbanding (icon_view);
2130 remove_scroll_timeout (icon_view);
2136 gtk_icon_view_key_press (GtkWidget *widget,
2139 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2141 if (icon_view->priv->doing_rubberband)
2143 if (event->keyval == GDK_KEY_Escape)
2144 gtk_icon_view_stop_rubberbanding (icon_view);
2149 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2153 gtk_icon_view_key_release (GtkWidget *widget,
2156 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2158 if (icon_view->priv->doing_rubberband)
2161 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2165 gtk_icon_view_update_rubberband (gpointer data)
2167 GtkIconView *icon_view;
2169 GdkRectangle old_area;
2170 GdkRectangle new_area;
2171 GdkRectangle common;
2172 cairo_region_t *invalid_region;
2174 icon_view = GTK_ICON_VIEW (data);
2176 gdk_window_get_device_position (icon_view->priv->bin_window,
2177 icon_view->priv->rubberband_device,
2183 old_area.x = MIN (icon_view->priv->rubberband_x1,
2184 icon_view->priv->rubberband_x2);
2185 old_area.y = MIN (icon_view->priv->rubberband_y1,
2186 icon_view->priv->rubberband_y2);
2187 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2188 icon_view->priv->rubberband_x1) + 1;
2189 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2190 icon_view->priv->rubberband_y1) + 1;
2192 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2193 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2194 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2195 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2197 invalid_region = cairo_region_create_rectangle (&old_area);
2198 cairo_region_union_rectangle (invalid_region, &new_area);
2200 gdk_rectangle_intersect (&old_area, &new_area, &common);
2201 if (common.width > 2 && common.height > 2)
2203 cairo_region_t *common_region;
2205 /* make sure the border is invalidated */
2211 common_region = cairo_region_create_rectangle (&common);
2213 cairo_region_subtract (invalid_region, common_region);
2214 cairo_region_destroy (common_region);
2217 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2219 cairo_region_destroy (invalid_region);
2221 icon_view->priv->rubberband_x2 = x;
2222 icon_view->priv->rubberband_y2 = y;
2224 gtk_icon_view_update_rubberband_selection (icon_view);
2228 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2235 if (icon_view->priv->rubberband_device)
2238 for (items = icon_view->priv->items; items; items = items->next)
2240 GtkIconViewItem *item = items->data;
2242 item->selected_before_rubberbanding = item->selected;
2245 icon_view->priv->rubberband_x1 = x;
2246 icon_view->priv->rubberband_y1 = y;
2247 icon_view->priv->rubberband_x2 = x;
2248 icon_view->priv->rubberband_y2 = y;
2250 icon_view->priv->doing_rubberband = TRUE;
2251 icon_view->priv->rubberband_device = device;
2253 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2257 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2259 if (!icon_view->priv->doing_rubberband)
2262 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2263 icon_view->priv->rubberband_device);
2265 icon_view->priv->doing_rubberband = FALSE;
2266 icon_view->priv->rubberband_device = NULL;
2268 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2272 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2275 gint x, y, width, height;
2276 gboolean dirty = FALSE;
2278 x = MIN (icon_view->priv->rubberband_x1,
2279 icon_view->priv->rubberband_x2);
2280 y = MIN (icon_view->priv->rubberband_y1,
2281 icon_view->priv->rubberband_y2);
2282 width = ABS (icon_view->priv->rubberband_x1 -
2283 icon_view->priv->rubberband_x2);
2284 height = ABS (icon_view->priv->rubberband_y1 -
2285 icon_view->priv->rubberband_y2);
2287 for (items = icon_view->priv->items; items; items = items->next)
2289 GtkIconViewItem *item = items->data;
2293 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2294 x, y, width, height);
2296 selected = is_in ^ item->selected_before_rubberbanding;
2298 if (item->selected != selected)
2300 item->selected = selected;
2302 gtk_icon_view_queue_draw_item (icon_view, item);
2307 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2312 GdkRectangle hit_rect;
2317 hit_test (GtkCellRenderer *renderer,
2318 const GdkRectangle *cell_area,
2319 const GdkRectangle *cell_background,
2322 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2323 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2324 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2325 MAX (data->hit_rect.y, cell_area->y) > 0)
2328 return (data->hit != FALSE);
2332 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2333 GtkIconViewItem *item,
2339 HitTestData data = { { x, y, width, height }, FALSE };
2340 GtkCellAreaContext *context;
2341 GdkRectangle *item_area = (GdkRectangle *)item;
2343 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2344 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2347 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2349 gtk_icon_view_set_cell_data (icon_view, item);
2350 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2351 GTK_WIDGET (icon_view),
2352 item_area, item_area,
2353 (GtkCellAllocCallback)hit_test, &data);
2359 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2361 gboolean dirty = FALSE;
2364 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2367 for (items = icon_view->priv->items; items; items = items->next)
2369 GtkIconViewItem *item = items->data;
2373 item->selected = FALSE;
2375 gtk_icon_view_queue_draw_item (icon_view, item);
2376 gtk_icon_view_item_selected_changed (icon_view, item);
2384 /* GtkIconView signals */
2386 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2388 gtk_icon_view_select_all (icon_view);
2392 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2394 gtk_icon_view_unselect_all (icon_view);
2398 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2400 gtk_icon_view_unselect_all (icon_view);
2402 if (icon_view->priv->cursor_item != NULL)
2403 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2407 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2410 GtkCellAreaContext *context;
2412 if (!icon_view->priv->cursor_item)
2415 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2417 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2418 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2419 GTK_WIDGET (icon_view),
2420 (GdkRectangle *)icon_view->priv->cursor_item,
2424 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2425 gtk_icon_view_item_activated (icon_view, path);
2426 gtk_tree_path_free (path);
2432 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2434 if (!icon_view->priv->cursor_item)
2437 switch (icon_view->priv->selection_mode)
2439 case GTK_SELECTION_NONE:
2441 case GTK_SELECTION_BROWSE:
2442 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2444 case GTK_SELECTION_SINGLE:
2445 if (icon_view->priv->cursor_item->selected)
2446 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2448 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2450 case GTK_SELECTION_MULTIPLE:
2451 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2452 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2454 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2455 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2460 /* Internal functions */
2462 gtk_icon_view_process_updates (GtkIconView *icon_view)
2464 /* Prior to drawing, we check if a layout has been scheduled. If so,
2465 * do it now that all cell view items have valid sizes before we proceeed
2466 * (and resize the bin_window if required).
2468 if (icon_view->priv->layout_idle_id != 0)
2469 gtk_icon_view_layout (icon_view);
2471 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2475 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2477 GtkAllocation allocation;
2478 GtkAdjustment *adj = icon_view->priv->hadjustment;
2479 gdouble old_page_size;
2485 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2487 old_value = gtk_adjustment_get_value (adj);
2488 old_upper = gtk_adjustment_get_upper (adj);
2489 old_page_size = gtk_adjustment_get_page_size (adj);
2490 new_upper = MAX (allocation.width, icon_view->priv->width);
2492 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2494 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2495 /* Quick explanation:
2496 * In LTR locales, leftmost portion of visible rectangle should stay
2497 * fixed, which means left edge of scrollbar thumb should remain fixed
2498 * and thus adjustment's value should stay the same.
2500 * In RTL locales, we want to keep rightmost portion of visible
2501 * rectangle fixed. This means right edge of thumb should remain fixed.
2502 * In this case, upper - value - page_size should remain constant.
2504 new_value = (new_upper - allocation.width) -
2505 (old_upper - old_value - old_page_size);
2506 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2509 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2511 gtk_adjustment_configure (adj,
2515 allocation.width * 0.1,
2516 allocation.width * 0.9,
2521 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2523 GtkAllocation allocation;
2524 GtkAdjustment *adj = icon_view->priv->vadjustment;
2526 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2528 gtk_adjustment_configure (adj,
2529 gtk_adjustment_get_value (adj),
2531 MAX (allocation.height, icon_view->priv->height),
2532 allocation.height * 0.1,
2533 allocation.height * 0.9,
2538 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2539 GtkAdjustment *adjustment)
2541 GtkIconViewPrivate *priv = icon_view->priv;
2544 if (adjustment && priv->hadjustment == adjustment)
2547 if (priv->hadjustment != NULL)
2549 g_signal_handlers_disconnect_matched (priv->hadjustment,
2550 G_SIGNAL_MATCH_DATA,
2551 0, 0, NULL, NULL, icon_view);
2552 g_object_unref (priv->hadjustment);
2556 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2559 g_signal_connect (adjustment, "value-changed",
2560 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2561 priv->hadjustment = g_object_ref_sink (adjustment);
2562 gtk_icon_view_set_hadjustment_values (icon_view);
2564 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2565 gtk_icon_view_accessible_set_adjustment (atk_obj,
2566 GTK_ORIENTATION_HORIZONTAL,
2569 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2573 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2574 GtkAdjustment *adjustment)
2576 GtkIconViewPrivate *priv = icon_view->priv;
2579 if (adjustment && priv->vadjustment == adjustment)
2582 if (priv->vadjustment != NULL)
2584 g_signal_handlers_disconnect_matched (priv->vadjustment,
2585 G_SIGNAL_MATCH_DATA,
2586 0, 0, NULL, NULL, icon_view);
2587 g_object_unref (priv->vadjustment);
2591 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2594 g_signal_connect (adjustment, "value-changed",
2595 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2596 priv->vadjustment = g_object_ref_sink (adjustment);
2597 gtk_icon_view_set_vadjustment_values (icon_view);
2599 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2600 gtk_icon_view_accessible_set_adjustment (atk_obj,
2601 GTK_ORIENTATION_VERTICAL,
2604 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2608 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2609 GtkIconView *icon_view)
2611 GtkIconViewPrivate *priv = icon_view->priv;
2613 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2615 gdk_window_move (priv->bin_window,
2616 - gtk_adjustment_get_value (priv->hadjustment),
2617 - gtk_adjustment_get_value (priv->vadjustment));
2619 if (icon_view->priv->doing_rubberband)
2620 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2622 gtk_icon_view_process_updates (icon_view);
2627 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2632 gint *maximum_width)
2634 GtkAllocation allocation;
2635 GtkCellAreaContext *context;
2636 GtkIconViewPrivate *priv = icon_view->priv;
2637 GtkWidget *widget = GTK_WIDGET (icon_view);
2638 gint x, current_width;
2639 GList *items, *last_item;
2641 gint max_height = 0;
2644 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2652 current_width += 2 * priv->margin;
2654 gtk_widget_get_allocation (widget, &allocation);
2656 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2657 g_ptr_array_add (priv->row_contexts, context);
2659 /* In the first loop we iterate horizontally until we hit allocation width
2660 * and collect the aligned height-for-width */
2664 GtkIconViewItem *item = items->data;
2665 GdkRectangle *item_area = (GdkRectangle *)item;
2667 item_area->width = item_width;
2669 current_width += item_area->width + icon_view->priv->item_padding * 2;
2671 if (items != first_item)
2673 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2674 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2678 /* Get this item's particular width & height (all alignments are cached by now) */
2679 gtk_icon_view_set_cell_data (icon_view, item);
2680 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2685 current_width += icon_view->priv->column_spacing;
2687 item_area->y = *y + icon_view->priv->item_padding;
2688 item_area->x = x + icon_view->priv->item_padding;
2690 x = current_width - icon_view->priv->margin;
2692 if (current_width > *maximum_width)
2693 *maximum_width = current_width;
2699 items = items->next;
2704 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2705 gtk_cell_area_context_allocate (context, item_width, max_height);
2707 /* In the second loop the item height has been aligned and derived and
2708 * we just set the height and handle rtl layout */
2709 for (items = first_item; items != last_item; items = items->next)
2711 GtkIconViewItem *item = items->data;
2712 GdkRectangle *item_area = (GdkRectangle *)item;
2716 item_area->x = *maximum_width - item_area->width - item_area->x;
2717 item->col = col - 1 - item->col;
2720 /* All items in the same row get the same height */
2721 item_area->height = max_height;
2724 /* Adjust the new y coordinate. */
2725 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2731 adjust_wrap_width (GtkIconView *icon_view)
2733 if (icon_view->priv->text_cell)
2735 gint wrap_width = 50;
2737 /* Here we go with the same old guess, try the icon size and set double
2738 * the size of the first icon found in the list, naive but works much
2740 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2742 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2743 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2744 GTK_WIDGET (icon_view),
2747 wrap_width = MAX (wrap_width * 2, 50);
2750 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2751 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2756 gtk_icon_view_layout (GtkIconView *icon_view)
2758 GtkAllocation allocation;
2761 gint y = 0, maximum_width = 0;
2764 gboolean size_changed = FALSE;
2766 if (icon_view->priv->layout_idle_id != 0)
2768 g_source_remove (icon_view->priv->layout_idle_id);
2769 icon_view->priv->layout_idle_id = 0;
2772 if (icon_view->priv->model == NULL)
2775 widget = GTK_WIDGET (icon_view);
2777 item_width = icon_view->priv->item_width;
2779 /* Update the wrap width for the text cell before going and requesting sizes */
2780 adjust_wrap_width (icon_view);
2782 /* Update the context widths for any invalidated items */
2783 gtk_icon_view_cache_widths (icon_view);
2785 /* Fetch the new item width if needed */
2787 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2790 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2792 icons = icon_view->priv->items;
2793 y += icon_view->priv->margin;
2796 /* Clear the per row contexts */
2797 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2801 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2803 &y, &maximum_width);
2806 while (icons != NULL);
2808 if (maximum_width != icon_view->priv->width)
2810 icon_view->priv->width = maximum_width;
2811 size_changed = TRUE;
2814 y += icon_view->priv->margin;
2816 if (y != icon_view->priv->height)
2818 icon_view->priv->height = y;
2819 size_changed = TRUE;
2822 gtk_icon_view_set_hadjustment_values (icon_view);
2823 gtk_icon_view_set_vadjustment_values (icon_view);
2826 gtk_widget_queue_resize_no_redraw (widget);
2828 gtk_widget_get_allocation (widget, &allocation);
2829 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2830 gdk_window_resize (icon_view->priv->bin_window,
2831 MAX (icon_view->priv->width, allocation.width),
2832 MAX (icon_view->priv->height, allocation.height));
2834 if (icon_view->priv->scroll_to_path)
2838 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2839 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2840 icon_view->priv->scroll_to_path = NULL;
2842 gtk_icon_view_scroll_to_path (icon_view, path,
2843 icon_view->priv->scroll_to_use_align,
2844 icon_view->priv->scroll_to_row_align,
2845 icon_view->priv->scroll_to_col_align);
2846 gtk_tree_path_free (path);
2849 gtk_widget_queue_draw (widget);
2852 /* This ensures that all widths have been cached in the
2853 * context and we have proper alignments to go on.
2856 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2860 g_signal_handler_block (icon_view->priv->cell_area_context,
2861 icon_view->priv->context_changed_id);
2863 for (items = icon_view->priv->items; items; items = items->next)
2865 GtkIconViewItem *item = items->data;
2867 /* Only fetch the width of items with invalidated sizes */
2868 if (item->cell_area.width < 0)
2870 gtk_icon_view_set_cell_data (icon_view, item);
2871 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2872 icon_view->priv->cell_area_context,
2873 GTK_WIDGET (icon_view), NULL, NULL);
2877 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2878 icon_view->priv->context_changed_id);
2882 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2884 /* Clear all item sizes */
2885 g_list_foreach (icon_view->priv->items,
2886 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2888 /* Reset the context */
2889 if (icon_view->priv->cell_area_context)
2891 g_signal_handler_block (icon_view->priv->cell_area_context,
2892 icon_view->priv->context_changed_id);
2893 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2894 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2895 icon_view->priv->context_changed_id);
2898 /* Re-layout the items */
2899 gtk_icon_view_queue_layout (icon_view);
2903 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2905 item->cell_area.width = -1;
2906 item->cell_area.height = -1;
2910 gtk_icon_view_paint_item (GtkIconView *icon_view,
2912 GtkIconViewItem *item,
2915 gboolean draw_focus)
2917 GdkRectangle cell_area;
2918 GtkStateFlags state = 0;
2919 GtkCellRendererState flags = 0;
2920 GtkStyleContext *style_context;
2921 GtkWidget *widget = GTK_WIDGET (icon_view);
2922 GtkIconViewPrivate *priv = icon_view->priv;
2923 GtkCellAreaContext *context;
2925 if (priv->model == NULL)
2928 gtk_icon_view_set_cell_data (icon_view, item);
2930 style_context = gtk_widget_get_style_context (widget);
2932 gtk_style_context_save (style_context);
2933 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2934 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2938 if (gtk_widget_has_focus (widget) &&
2939 item == icon_view->priv->cursor_item)
2941 state |= GTK_STATE_FLAG_FOCUSED;
2942 flags |= GTK_CELL_RENDERER_FOCUSED;
2945 state |= GTK_STATE_FLAG_SELECTED;
2946 flags |= GTK_CELL_RENDERER_SELECTED;
2948 gtk_style_context_set_state (style_context, state);
2949 gtk_render_background (style_context, cr,
2950 x - icon_view->priv->item_padding,
2951 y - icon_view->priv->item_padding,
2952 item->cell_area.width + icon_view->priv->item_padding * 2,
2953 item->cell_area.height + icon_view->priv->item_padding * 2);
2958 cell_area.width = item->cell_area.width;
2959 cell_area.height = item->cell_area.height;
2961 context = g_ptr_array_index (priv->row_contexts, item->row);
2962 gtk_cell_area_render (priv->cell_area, context,
2963 widget, cr, &cell_area, &cell_area, flags,
2966 gtk_style_context_restore (style_context);
2970 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2973 GtkStyleContext *context;
2978 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2979 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2980 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2981 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2983 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2985 gtk_style_context_save (context);
2986 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2988 gdk_cairo_rectangle (cr, &rect);
2991 gtk_render_background (context, cr,
2993 rect.width, rect.height);
2994 gtk_render_frame (context, cr,
2996 rect.width, rect.height);
2998 gtk_style_context_restore (context);
3003 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3009 index = gtk_tree_path_get_indices (path)[0];
3011 for (l = icon_view->priv->items; l; l = l->next)
3013 GtkIconViewItem *item = l->data;
3015 if (item->index == index)
3017 gtk_icon_view_queue_draw_item (icon_view, item);
3024 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3025 GtkIconViewItem *item)
3028 GdkRectangle *item_area = (GdkRectangle *)item;
3030 rect.x = item_area->x - icon_view->priv->item_padding;
3031 rect.y = item_area->y - icon_view->priv->item_padding;
3032 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3033 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3035 if (icon_view->priv->bin_window)
3036 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3040 layout_callback (gpointer user_data)
3042 GtkIconView *icon_view;
3044 icon_view = GTK_ICON_VIEW (user_data);
3046 icon_view->priv->layout_idle_id = 0;
3048 gtk_icon_view_layout (icon_view);
3054 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3056 if (icon_view->priv->layout_idle_id != 0)
3059 icon_view->priv->layout_idle_id =
3060 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3061 layout_callback, icon_view, NULL);
3065 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3066 GtkIconViewItem *item,
3067 GtkCellRenderer *cursor_cell)
3070 AtkObject *item_obj;
3071 AtkObject *cursor_item_obj;
3073 /* When hitting this path from keynav, the focus cell is
3074 * already set, we dont need to notify the atk object
3075 * but we still need to queue the draw here (in the case
3076 * that the focus cell changes but not the cursor item).
3078 gtk_icon_view_queue_draw_item (icon_view, item);
3080 if (icon_view->priv->cursor_item == item &&
3081 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3084 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3085 if (icon_view->priv->cursor_item != NULL)
3087 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3090 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3091 if (cursor_item_obj != NULL)
3092 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3095 icon_view->priv->cursor_item = item;
3098 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3101 /* Make sure there is a cell in focus initially */
3102 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3103 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3106 /* Notify that accessible focus object has changed */
3107 item_obj = atk_object_ref_accessible_child (obj, item->index);
3109 if (item_obj != NULL)
3111 atk_focus_tracker_notify (item_obj);
3112 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3113 g_object_unref (item_obj);
3118 static GtkIconViewItem *
3119 gtk_icon_view_item_new (void)
3121 GtkIconViewItem *item;
3123 item = g_slice_new0 (GtkIconViewItem);
3125 item->cell_area.width = -1;
3126 item->cell_area.height = -1;
3132 gtk_icon_view_item_free (GtkIconViewItem *item)
3134 g_return_if_fail (item != NULL);
3136 g_slice_free (GtkIconViewItem, item);
3139 static GtkIconViewItem *
3140 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3143 gboolean only_in_cell,
3144 GtkCellRenderer **cell_at_pos)
3149 *cell_at_pos = NULL;
3151 for (items = icon_view->priv->items; items; items = items->next)
3153 GtkIconViewItem *item = items->data;
3154 GdkRectangle *item_area = (GdkRectangle *)item;
3156 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3157 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3158 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3159 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3161 if (only_in_cell || cell_at_pos)
3163 GtkCellRenderer *cell = NULL;
3164 GtkCellAreaContext *context;
3166 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3167 gtk_icon_view_set_cell_data (icon_view, item);
3169 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3170 y >= item_area->y && y <= item_area->y + item_area->height)
3171 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3172 GTK_WIDGET (icon_view),
3177 *cell_at_pos = cell;
3180 return cell != NULL ? item : NULL;
3191 gtk_icon_view_select_item (GtkIconView *icon_view,
3192 GtkIconViewItem *item)
3194 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3195 g_return_if_fail (item != NULL);
3200 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3202 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3203 gtk_icon_view_unselect_all_internal (icon_view);
3205 item->selected = TRUE;
3207 gtk_icon_view_item_selected_changed (icon_view, item);
3208 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3210 gtk_icon_view_queue_draw_item (icon_view, item);
3215 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3216 GtkIconViewItem *item)
3218 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3219 g_return_if_fail (item != NULL);
3221 if (!item->selected)
3224 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3225 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3228 item->selected = FALSE;
3230 gtk_icon_view_item_selected_changed (icon_view, item);
3231 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3233 gtk_icon_view_queue_draw_item (icon_view, item);
3237 verify_items (GtkIconView *icon_view)
3242 for (items = icon_view->priv->items; items; items = items->next)
3244 GtkIconViewItem *item = items->data;
3246 if (item->index != i)
3247 g_error ("List item does not match its index: "
3248 "item index %d and list index %d\n", item->index, i);
3255 gtk_icon_view_row_changed (GtkTreeModel *model,
3260 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3262 /* ignore changes in branches */
3263 if (gtk_tree_path_get_depth (path) > 1)
3266 /* An icon view subclass might add it's own model and populate
3267 * things at init() time instead of waiting for the constructor()
3270 if (icon_view->priv->cell_area)
3271 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3273 /* Here we can use a "grow-only" strategy for optimization
3274 * and only invalidate a single item and queue a relayout
3275 * instead of invalidating the whole thing.
3277 * For now GtkIconView still cant deal with huge models
3278 * so just invalidate the whole thing when the model
3281 gtk_icon_view_invalidate_sizes (icon_view);
3283 verify_items (icon_view);
3287 gtk_icon_view_row_inserted (GtkTreeModel *model,
3292 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3294 GtkIconViewItem *item;
3295 gboolean iters_persist;
3298 /* ignore changes in branches */
3299 if (gtk_tree_path_get_depth (path) > 1)
3302 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3304 index = gtk_tree_path_get_indices(path)[0];
3306 item = gtk_icon_view_item_new ();
3311 item->index = index;
3313 /* FIXME: We can be more efficient here,
3314 we can store a tail pointer and use that when
3315 appending (which is a rather common operation)
3317 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3320 list = g_list_nth (icon_view->priv->items, index + 1);
3321 for (; list; list = list->next)
3328 verify_items (icon_view);
3330 gtk_icon_view_queue_layout (icon_view);
3334 gtk_icon_view_row_deleted (GtkTreeModel *model,
3338 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3340 GtkIconViewItem *item;
3342 gboolean emit = FALSE;
3344 /* ignore changes in branches */
3345 if (gtk_tree_path_get_depth (path) > 1)
3348 index = gtk_tree_path_get_indices(path)[0];
3350 list = g_list_nth (icon_view->priv->items, index);
3353 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3355 if (item == icon_view->priv->anchor_item)
3356 icon_view->priv->anchor_item = NULL;
3358 if (item == icon_view->priv->cursor_item)
3359 icon_view->priv->cursor_item = NULL;
3364 gtk_icon_view_item_free (item);
3366 for (next = list->next; next; next = next->next)
3373 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3375 verify_items (icon_view);
3377 gtk_icon_view_queue_layout (icon_view);
3380 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3384 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3385 GtkTreePath *parent,
3390 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3393 GList *items = NULL, *list;
3394 GtkIconViewItem **item_array;
3397 /* ignore changes in branches */
3401 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3403 length = gtk_tree_model_iter_n_children (model, NULL);
3405 order = g_new (gint, length);
3406 for (i = 0; i < length; i++)
3407 order [new_order[i]] = i;
3409 item_array = g_new (GtkIconViewItem *, length);
3410 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3411 item_array[order[i]] = list->data;
3414 for (i = length - 1; i >= 0; i--)
3416 item_array[i]->index = i;
3417 items = g_list_prepend (items, item_array[i]);
3420 g_free (item_array);
3421 g_list_free (icon_view->priv->items);
3422 icon_view->priv->items = items;
3424 gtk_icon_view_queue_layout (icon_view);
3426 verify_items (icon_view);
3430 gtk_icon_view_build_items (GtkIconView *icon_view)
3434 gboolean iters_persist;
3435 GList *items = NULL;
3437 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3439 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3447 GtkIconViewItem *item = gtk_icon_view_item_new ();
3456 items = g_list_prepend (items, item);
3458 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3460 icon_view->priv->items = g_list_reverse (items);
3464 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3467 GtkMovementStep step,
3471 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3472 I_("move-cursor"), 2,
3476 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3481 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3484 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3489 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3496 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3497 GtkMovementStep step,
3500 GdkModifierType state;
3502 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3503 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3504 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3505 step == GTK_MOVEMENT_DISPLAY_LINES ||
3506 step == GTK_MOVEMENT_PAGES ||
3507 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3509 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3512 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3513 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3515 if (gtk_get_current_event_state (&state))
3517 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3518 icon_view->priv->ctrl_pressed = TRUE;
3519 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3520 icon_view->priv->shift_pressed = TRUE;
3522 /* else we assume not pressed */
3526 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3527 case GTK_MOVEMENT_VISUAL_POSITIONS:
3528 gtk_icon_view_move_cursor_left_right (icon_view, count);
3530 case GTK_MOVEMENT_DISPLAY_LINES:
3531 gtk_icon_view_move_cursor_up_down (icon_view, count);
3533 case GTK_MOVEMENT_PAGES:
3534 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3536 case GTK_MOVEMENT_BUFFER_ENDS:
3537 gtk_icon_view_move_cursor_start_end (icon_view, count);
3540 g_assert_not_reached ();
3543 icon_view->priv->ctrl_pressed = FALSE;
3544 icon_view->priv->shift_pressed = FALSE;
3546 icon_view->priv->draw_focus = TRUE;
3551 static GtkIconViewItem *
3552 find_item (GtkIconView *icon_view,
3553 GtkIconViewItem *current,
3559 GtkIconViewItem *item;
3561 /* FIXME: this could be more efficient
3563 row = current->row + row_ofs;
3564 col = current->col + col_ofs;
3566 for (items = icon_view->priv->items; items; items = items->next)
3569 if (item->row == row && item->col == col)
3576 static GtkIconViewItem *
3577 find_item_page_up_down (GtkIconView *icon_view,
3578 GtkIconViewItem *current,
3585 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3587 item = g_list_find (icon_view->priv->items, current);
3592 for (next = item->next; next; next = next->next)
3594 if (((GtkIconViewItem *)next->data)->col == col)
3597 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3607 for (next = item->prev; next; next = next->prev)
3609 if (((GtkIconViewItem *)next->data)->col == col)
3612 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3626 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3627 GtkIconViewItem *anchor,
3628 GtkIconViewItem *cursor)
3631 GtkIconViewItem *item;
3632 gint row1, row2, col1, col2;
3633 gboolean dirty = FALSE;
3635 if (anchor->row < cursor->row)
3646 if (anchor->col < cursor->col)
3657 for (items = icon_view->priv->items; items; items = items->next)
3661 if (row1 <= item->row && item->row <= row2 &&
3662 col1 <= item->col && item->col <= col2)
3664 if (!item->selected)
3667 item->selected = TRUE;
3668 gtk_icon_view_item_selected_changed (icon_view, item);
3670 gtk_icon_view_queue_draw_item (icon_view, item);
3678 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3681 GtkIconViewItem *item;
3682 GtkCellRenderer *cell;
3683 gboolean dirty = FALSE;
3685 GtkDirectionType direction;
3687 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3690 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3692 if (!icon_view->priv->cursor_item)
3697 list = icon_view->priv->items;
3699 list = g_list_last (icon_view->priv->items);
3701 item = list ? list->data : NULL;
3703 /* Give focus to the first cell initially */
3704 gtk_icon_view_set_cell_data (icon_view, item);
3705 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3709 item = icon_view->priv->cursor_item;
3710 step = count > 0 ? 1 : -1;
3712 /* Save the current focus cell in case we hit the edge */
3713 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3717 gtk_icon_view_set_cell_data (icon_view, item);
3719 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3722 item = find_item (icon_view, item, step, 0);
3728 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3730 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3732 gtk_widget_child_focus (toplevel,
3733 direction == GTK_DIR_UP ?
3734 GTK_DIR_TAB_BACKWARD :
3735 GTK_DIR_TAB_FORWARD);
3739 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3743 if (icon_view->priv->ctrl_pressed ||
3744 !icon_view->priv->shift_pressed ||
3745 !icon_view->priv->anchor_item ||
3746 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3747 icon_view->priv->anchor_item = item;
3749 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3750 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3752 if (!icon_view->priv->ctrl_pressed &&
3753 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3755 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3756 dirty = gtk_icon_view_select_all_between (icon_view,
3757 icon_view->priv->anchor_item,
3761 gtk_icon_view_scroll_to_item (icon_view, item);
3764 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3768 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3771 GtkIconViewItem *item;
3772 gboolean dirty = FALSE;
3774 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3777 if (!icon_view->priv->cursor_item)
3782 list = icon_view->priv->items;
3784 list = g_list_last (icon_view->priv->items);
3786 item = list ? list->data : NULL;
3789 item = find_item_page_up_down (icon_view,
3790 icon_view->priv->cursor_item,
3793 if (item == icon_view->priv->cursor_item)
3794 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3799 if (icon_view->priv->ctrl_pressed ||
3800 !icon_view->priv->shift_pressed ||
3801 !icon_view->priv->anchor_item ||
3802 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3803 icon_view->priv->anchor_item = item;
3805 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3807 if (!icon_view->priv->ctrl_pressed &&
3808 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3810 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3811 dirty = gtk_icon_view_select_all_between (icon_view,
3812 icon_view->priv->anchor_item,
3816 gtk_icon_view_scroll_to_item (icon_view, item);
3819 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3823 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3826 GtkIconViewItem *item;
3827 GtkCellRenderer *cell = NULL;
3828 gboolean dirty = FALSE;
3830 GtkDirectionType direction;
3832 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3835 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3837 if (!icon_view->priv->cursor_item)
3842 list = icon_view->priv->items;
3844 list = g_list_last (icon_view->priv->items);
3846 item = list ? list->data : NULL;
3848 /* Give focus to the first cell initially */
3849 gtk_icon_view_set_cell_data (icon_view, item);
3850 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3854 item = icon_view->priv->cursor_item;
3855 step = count > 0 ? 1 : -1;
3857 /* Save the current focus cell in case we hit the edge */
3858 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3862 gtk_icon_view_set_cell_data (icon_view, item);
3864 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3867 item = find_item (icon_view, item, 0, step);
3873 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3875 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3877 gtk_widget_child_focus (toplevel,
3878 direction == GTK_DIR_LEFT ?
3879 GTK_DIR_TAB_BACKWARD :
3880 GTK_DIR_TAB_FORWARD);
3884 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3888 if (icon_view->priv->ctrl_pressed ||
3889 !icon_view->priv->shift_pressed ||
3890 !icon_view->priv->anchor_item ||
3891 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3892 icon_view->priv->anchor_item = item;
3894 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3895 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3897 if (!icon_view->priv->ctrl_pressed &&
3898 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3900 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3901 dirty = gtk_icon_view_select_all_between (icon_view,
3902 icon_view->priv->anchor_item,
3906 gtk_icon_view_scroll_to_item (icon_view, item);
3909 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3913 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3916 GtkIconViewItem *item;
3918 gboolean dirty = FALSE;
3920 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3924 list = icon_view->priv->items;
3926 list = g_list_last (icon_view->priv->items);
3928 item = list ? list->data : NULL;
3930 if (item == icon_view->priv->cursor_item)
3931 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3936 if (icon_view->priv->ctrl_pressed ||
3937 !icon_view->priv->shift_pressed ||
3938 !icon_view->priv->anchor_item ||
3939 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3940 icon_view->priv->anchor_item = item;
3942 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3944 if (!icon_view->priv->ctrl_pressed &&
3945 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3947 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3948 dirty = gtk_icon_view_select_all_between (icon_view,
3949 icon_view->priv->anchor_item,
3953 gtk_icon_view_scroll_to_item (icon_view, item);
3956 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3960 * gtk_icon_view_scroll_to_path:
3961 * @icon_view: A #GtkIconView.
3962 * @path: The path of the item to move to.
3963 * @use_align: whether to use alignment arguments, or %FALSE.
3964 * @row_align: The vertical alignment of the item specified by @path.
3965 * @col_align: The horizontal alignment of the item specified by @path.
3967 * Moves the alignments of @icon_view to the position specified by @path.
3968 * @row_align determines where the row is placed, and @col_align determines
3969 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3970 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3973 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3974 * tree does the minimum amount of work to scroll the item onto the screen.
3975 * This means that the item will be scrolled to the edge closest to its current
3976 * position. If the item is currently visible on the screen, nothing is done.
3978 * This function only works if the model is set, and @path is a valid row on
3979 * the model. If the model changes before the @icon_view is realized, the
3980 * centered path will be modified to reflect this change.
3985 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3991 GtkIconViewItem *item = NULL;
3994 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3995 g_return_if_fail (path != NULL);
3996 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3997 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3999 widget = GTK_WIDGET (icon_view);
4001 if (gtk_tree_path_get_depth (path) > 0)
4002 item = g_list_nth_data (icon_view->priv->items,
4003 gtk_tree_path_get_indices(path)[0]);
4005 if (!item || item->cell_area.width < 0 ||
4006 !gtk_widget_get_realized (widget))
4008 if (icon_view->priv->scroll_to_path)
4009 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4011 icon_view->priv->scroll_to_path = NULL;
4014 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4016 icon_view->priv->scroll_to_use_align = use_align;
4017 icon_view->priv->scroll_to_row_align = row_align;
4018 icon_view->priv->scroll_to_col_align = col_align;
4025 GtkAllocation allocation;
4028 GdkRectangle item_area =
4030 item->cell_area.x - icon_view->priv->item_padding,
4031 item->cell_area.y - icon_view->priv->item_padding,
4032 item->cell_area.width + icon_view->priv->item_padding * 2,
4033 item->cell_area.height + icon_view->priv->item_padding * 2
4036 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4038 gtk_widget_get_allocation (widget, &allocation);
4040 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4042 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4043 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4045 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4047 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4048 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4050 gtk_adjustment_changed (icon_view->priv->hadjustment);
4051 gtk_adjustment_changed (icon_view->priv->vadjustment);
4054 gtk_icon_view_scroll_to_item (icon_view, item);
4059 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4060 GtkIconViewItem *item)
4062 GtkIconViewPrivate *priv = icon_view->priv;
4063 GtkWidget *widget = GTK_WIDGET (icon_view);
4064 GtkAdjustment *hadj, *vadj;
4065 GtkAllocation allocation;
4067 GdkRectangle item_area;
4069 item_area.x = item->cell_area.x - priv->item_padding;
4070 item_area.y = item->cell_area.y - priv->item_padding;
4071 item_area.width = item->cell_area.width + priv->item_padding * 2;
4072 item_area.height = item->cell_area.height + priv->item_padding * 2;
4074 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4075 gtk_widget_get_allocation (widget, &allocation);
4077 hadj = icon_view->priv->hadjustment;
4078 vadj = icon_view->priv->vadjustment;
4080 if (y + item_area.y < 0)
4081 gtk_adjustment_set_value (vadj,
4082 gtk_adjustment_get_value (vadj)
4084 else if (y + item_area.y + item_area.height > allocation.height)
4085 gtk_adjustment_set_value (vadj,
4086 gtk_adjustment_get_value (vadj)
4087 + y + item_area.y + item_area.height - allocation.height);
4089 if (x + item_area.x < 0)
4090 gtk_adjustment_set_value (hadj,
4091 gtk_adjustment_get_value (hadj)
4093 else if (x + item_area.x + item_area.width > allocation.width)
4094 gtk_adjustment_set_value (hadj,
4095 gtk_adjustment_get_value (hadj)
4096 + x + item_area.x + item_area.width - allocation.width);
4098 gtk_adjustment_changed (hadj);
4099 gtk_adjustment_changed (vadj);
4102 /* GtkCellLayout implementation */
4105 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4106 GtkCellArea *cell_area)
4108 GtkIconViewPrivate *priv = icon_view->priv;
4110 if (priv->cell_area)
4114 priv->cell_area = cell_area;
4116 priv->cell_area = gtk_cell_area_box_new ();
4118 g_object_ref_sink (priv->cell_area);
4120 if (GTK_IS_ORIENTABLE (priv->cell_area))
4121 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4123 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4125 priv->add_editable_id =
4126 g_signal_connect (priv->cell_area, "add-editable",
4127 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4128 priv->remove_editable_id =
4129 g_signal_connect (priv->cell_area, "remove-editable",
4130 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4131 priv->context_changed_id =
4132 g_signal_connect (priv->cell_area_context, "notify",
4133 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4135 update_text_cell (icon_view);
4136 update_pixbuf_cell (icon_view);
4139 static GtkCellArea *
4140 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4142 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4143 GtkIconViewPrivate *priv = icon_view->priv;
4145 if (G_UNLIKELY (!priv->cell_area))
4146 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4148 return icon_view->priv->cell_area;
4152 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4153 GtkIconViewItem *item)
4155 gboolean iters_persist;
4158 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4164 path = gtk_tree_path_new_from_indices (item->index, -1);
4165 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4167 gtk_tree_path_free (path);
4172 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4173 icon_view->priv->model,
4174 &iter, FALSE, FALSE);
4183 * gtk_icon_view_new:
4185 * Creates a new #GtkIconView widget
4187 * Return value: A newly created #GtkIconView widget
4192 gtk_icon_view_new (void)
4194 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4198 * gtk_icon_view_new_with_area:
4199 * @area: the #GtkCellArea to use to layout cells
4201 * Creates a new #GtkIconView widget using the
4202 * specified @area to layout cells inside the icons.
4204 * Return value: A newly created #GtkIconView widget
4209 gtk_icon_view_new_with_area (GtkCellArea *area)
4211 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4215 * gtk_icon_view_new_with_model:
4216 * @model: The model.
4218 * Creates a new #GtkIconView widget with the model @model.
4220 * Return value: A newly created #GtkIconView widget.
4225 gtk_icon_view_new_with_model (GtkTreeModel *model)
4227 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4231 * gtk_icon_view_convert_widget_to_bin_window_coords:
4232 * @icon_view: a #GtkIconView
4233 * @wx: X coordinate relative to the widget
4234 * @wy: Y coordinate relative to the widget
4235 * @bx: (out): return location for bin_window X coordinate
4236 * @by: (out): return location for bin_window Y coordinate
4238 * Converts widget coordinates to coordinates for the bin_window,
4239 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4244 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4252 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4254 if (icon_view->priv->bin_window)
4255 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4266 * gtk_icon_view_get_path_at_pos:
4267 * @icon_view: A #GtkIconView.
4268 * @x: The x position to be identified
4269 * @y: The y position to be identified
4271 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4272 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4273 * the cell at the specified position.
4274 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4275 * widget coordinates to bin_window coordinates.
4277 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4278 * if no icon exists at that position.
4283 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4287 GtkIconViewItem *item;
4290 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4292 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4297 path = gtk_tree_path_new_from_indices (item->index, -1);
4303 * gtk_icon_view_get_item_at_pos:
4304 * @icon_view: A #GtkIconView.
4305 * @x: The x position to be identified
4306 * @y: The y position to be identified
4307 * @path: (out) (allow-none): Return location for the path, or %NULL
4308 * @cell: (out) (allow-none): Return location for the renderer
4309 * responsible for the cell at (@x, @y), or %NULL
4311 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4312 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4313 * obtains the cell at the specified position. The returned path should
4314 * be freed with gtk_tree_path_free().
4315 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4316 * widget coordinates to bin_window coordinates.
4318 * Return value: %TRUE if an item exists at the specified position
4323 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4327 GtkCellRenderer **cell)
4329 GtkIconViewItem *item;
4330 GtkCellRenderer *renderer = NULL;
4332 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4334 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4339 *path = gtk_tree_path_new_from_indices (item->index, -1);
4347 return (item != NULL);
4351 * gtk_icon_view_set_tooltip_item:
4352 * @icon_view: a #GtkIconView
4353 * @tooltip: a #GtkTooltip
4354 * @path: a #GtkTreePath
4356 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4357 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4358 * See also gtk_tooltip_set_tip_area().
4363 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4364 GtkTooltip *tooltip,
4367 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4368 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4370 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4374 * gtk_icon_view_set_tooltip_cell:
4375 * @icon_view: a #GtkIconView
4376 * @tooltip: a #GtkTooltip
4377 * @path: a #GtkTreePath
4378 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4380 * Sets the tip area of @tooltip to the area which @cell occupies in
4381 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4383 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4388 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4389 GtkTooltip *tooltip,
4391 GtkCellRenderer *cell)
4394 GtkIconViewItem *item = NULL;
4397 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4398 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4399 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4401 if (gtk_tree_path_get_depth (path) > 0)
4402 item = g_list_nth_data (icon_view->priv->items,
4403 gtk_tree_path_get_indices(path)[0]);
4410 GtkCellAreaContext *context;
4412 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4413 gtk_icon_view_set_cell_data (icon_view, item);
4414 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4415 GTK_WIDGET (icon_view),
4416 cell, (GdkRectangle *)item, &rect);
4420 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4421 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4422 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4423 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4426 if (icon_view->priv->bin_window)
4428 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4433 gtk_tooltip_set_tip_area (tooltip, &rect);
4438 * gtk_icon_view_get_tooltip_context:
4439 * @icon_view: an #GtkIconView
4440 * @x: (inout): the x coordinate (relative to widget coordinates)
4441 * @y: (inout): the y coordinate (relative to widget coordinates)
4442 * @keyboard_tip: whether this is a keyboard tooltip or not
4443 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4444 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4445 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4447 * This function is supposed to be used in a #GtkWidget::query-tooltip
4448 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4449 * which are received in the signal handler, should be passed to this
4450 * function without modification.
4452 * The return value indicates whether there is an icon view item at the given
4453 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4454 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4455 * @model, @path and @iter which have been provided will be set to point to
4456 * that row and the corresponding model. @x and @y will always be converted
4457 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4459 * Return value: whether or not the given tooltip context points to a item
4464 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4467 gboolean keyboard_tip,
4468 GtkTreeModel **model,
4472 GtkTreePath *tmppath = NULL;
4474 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4475 g_return_val_if_fail (x != NULL, FALSE);
4476 g_return_val_if_fail (y != NULL, FALSE);
4480 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4487 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4490 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4495 *model = gtk_icon_view_get_model (icon_view);
4498 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4504 gtk_tree_path_free (tmppath);
4510 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4513 gboolean keyboard_tip,
4514 GtkTooltip *tooltip,
4520 GtkTreeModel *model;
4521 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4523 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4526 &model, &path, &iter))
4529 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4533 gtk_tree_path_free (path);
4537 gtk_tooltip_set_markup (tooltip, str);
4538 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4540 gtk_tree_path_free (path);
4548 * gtk_icon_view_set_tooltip_column:
4549 * @icon_view: a #GtkIconView
4550 * @column: an integer, which is a valid column number for @icon_view's model
4552 * If you only plan to have simple (text-only) tooltips on full items, you
4553 * can use this function to have #GtkIconView handle these automatically
4554 * for you. @column should be set to the column in @icon_view's model
4555 * containing the tooltip texts, or -1 to disable this feature.
4557 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4558 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4560 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4561 * so &, <, etc have to be escaped in the text.
4566 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4569 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4571 if (column == icon_view->priv->tooltip_column)
4576 g_signal_handlers_disconnect_by_func (icon_view,
4577 gtk_icon_view_set_tooltip_query_cb,
4579 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4583 if (icon_view->priv->tooltip_column == -1)
4585 g_signal_connect (icon_view, "query-tooltip",
4586 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4587 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4591 icon_view->priv->tooltip_column = column;
4592 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4596 * gtk_icon_view_get_tooltip_column:
4597 * @icon_view: a #GtkIconView
4599 * Returns the column of @icon_view's model which is being used for
4600 * displaying tooltips on @icon_view's rows.
4602 * Return value: the index of the tooltip column that is currently being
4603 * used, or -1 if this is disabled.
4608 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4610 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4612 return icon_view->priv->tooltip_column;
4616 * gtk_icon_view_get_visible_range:
4617 * @icon_view: A #GtkIconView
4618 * @start_path: (out) (allow-none): Return location for start of region,
4620 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4622 * Sets @start_path and @end_path to be the first and last visible path.
4623 * Note that there may be invisible paths in between.
4625 * Both paths should be freed with gtk_tree_path_free() after use.
4627 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4632 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4633 GtkTreePath **start_path,
4634 GtkTreePath **end_path)
4636 gint start_index = -1;
4637 gint end_index = -1;
4640 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4642 if (icon_view->priv->hadjustment == NULL ||
4643 icon_view->priv->vadjustment == NULL)
4646 if (start_path == NULL && end_path == NULL)
4649 for (icons = icon_view->priv->items; icons; icons = icons->next)
4651 GtkIconViewItem *item = icons->data;
4652 GdkRectangle *item_area = (GdkRectangle *)item;
4654 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4655 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4657 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4658 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4660 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4661 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4663 if (start_index == -1)
4664 start_index = item->index;
4665 end_index = item->index;
4669 if (start_path && start_index != -1)
4670 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4671 if (end_path && end_index != -1)
4672 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4674 return start_index != -1;
4678 * gtk_icon_view_selected_foreach:
4679 * @icon_view: A #GtkIconView.
4680 * @func: (scope call): The function to call for each selected icon.
4681 * @data: User data to pass to the function.
4683 * Calls a function for each selected icon. Note that the model or
4684 * selection cannot be modified from within this function.
4689 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4690 GtkIconViewForeachFunc func,
4695 for (list = icon_view->priv->items; list; list = list->next)
4697 GtkIconViewItem *item = list->data;
4698 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4701 (* func) (icon_view, path, data);
4703 gtk_tree_path_free (path);
4708 * gtk_icon_view_set_selection_mode:
4709 * @icon_view: A #GtkIconView.
4710 * @mode: The selection mode
4712 * Sets the selection mode of the @icon_view.
4717 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4718 GtkSelectionMode mode)
4720 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4722 if (mode == icon_view->priv->selection_mode)
4725 if (mode == GTK_SELECTION_NONE ||
4726 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4727 gtk_icon_view_unselect_all (icon_view);
4729 icon_view->priv->selection_mode = mode;
4731 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4735 * gtk_icon_view_get_selection_mode:
4736 * @icon_view: A #GtkIconView.
4738 * Gets the selection mode of the @icon_view.
4740 * Return value: the current selection mode
4745 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4747 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4749 return icon_view->priv->selection_mode;
4753 * gtk_icon_view_set_model:
4754 * @icon_view: A #GtkIconView.
4755 * @model: (allow-none): The model.
4757 * Sets the model for a #GtkIconView.
4758 * If the @icon_view already has a model set, it will remove
4759 * it before setting the new model. If @model is %NULL, then
4760 * it will unset the old model.
4765 gtk_icon_view_set_model (GtkIconView *icon_view,
4766 GtkTreeModel *model)
4768 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4769 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4771 if (icon_view->priv->model == model)
4774 if (icon_view->priv->scroll_to_path)
4776 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4777 icon_view->priv->scroll_to_path = NULL;
4780 /* The area can be NULL while disposing */
4781 if (icon_view->priv->cell_area)
4782 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4788 if (icon_view->priv->pixbuf_column != -1)
4790 column_type = gtk_tree_model_get_column_type (model,
4791 icon_view->priv->pixbuf_column);
4793 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4796 if (icon_view->priv->text_column != -1)
4798 column_type = gtk_tree_model_get_column_type (model,
4799 icon_view->priv->text_column);
4801 g_return_if_fail (column_type == G_TYPE_STRING);
4804 if (icon_view->priv->markup_column != -1)
4806 column_type = gtk_tree_model_get_column_type (model,
4807 icon_view->priv->markup_column);
4809 g_return_if_fail (column_type == G_TYPE_STRING);
4814 if (icon_view->priv->model)
4816 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4817 gtk_icon_view_row_changed,
4819 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4820 gtk_icon_view_row_inserted,
4822 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4823 gtk_icon_view_row_deleted,
4825 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4826 gtk_icon_view_rows_reordered,
4829 g_object_unref (icon_view->priv->model);
4831 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4832 g_list_free (icon_view->priv->items);
4833 icon_view->priv->items = NULL;
4834 icon_view->priv->anchor_item = NULL;
4835 icon_view->priv->cursor_item = NULL;
4836 icon_view->priv->last_single_clicked = NULL;
4837 icon_view->priv->width = 0;
4838 icon_view->priv->height = 0;
4841 icon_view->priv->model = model;
4843 if (icon_view->priv->model)
4845 g_object_ref (icon_view->priv->model);
4846 g_signal_connect (icon_view->priv->model,
4848 G_CALLBACK (gtk_icon_view_row_changed),
4850 g_signal_connect (icon_view->priv->model,
4852 G_CALLBACK (gtk_icon_view_row_inserted),
4854 g_signal_connect (icon_view->priv->model,
4856 G_CALLBACK (gtk_icon_view_row_deleted),
4858 g_signal_connect (icon_view->priv->model,
4860 G_CALLBACK (gtk_icon_view_rows_reordered),
4863 gtk_icon_view_build_items (icon_view);
4865 gtk_icon_view_queue_layout (icon_view);
4868 g_object_notify (G_OBJECT (icon_view), "model");
4870 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4871 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4875 * gtk_icon_view_get_model:
4876 * @icon_view: a #GtkIconView
4878 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4881 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4882 * currently being used.
4887 gtk_icon_view_get_model (GtkIconView *icon_view)
4889 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4891 return icon_view->priv->model;
4895 update_text_cell (GtkIconView *icon_view)
4897 if (!icon_view->priv->cell_area)
4900 if (icon_view->priv->text_column == -1 &&
4901 icon_view->priv->markup_column == -1)
4903 if (icon_view->priv->text_cell != NULL)
4905 gtk_cell_area_remove (icon_view->priv->cell_area,
4906 icon_view->priv->text_cell);
4907 icon_view->priv->text_cell = NULL;
4912 if (icon_view->priv->text_cell == NULL)
4914 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4916 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4919 if (icon_view->priv->markup_column != -1)
4920 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4921 icon_view->priv->text_cell,
4922 "markup", icon_view->priv->markup_column,
4925 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4926 icon_view->priv->text_cell,
4927 "text", icon_view->priv->text_column,
4930 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4931 g_object_set (icon_view->priv->text_cell,
4932 "alignment", PANGO_ALIGN_CENTER,
4933 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4938 g_object_set (icon_view->priv->text_cell,
4939 "alignment", PANGO_ALIGN_LEFT,
4940 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4948 update_pixbuf_cell (GtkIconView *icon_view)
4950 if (!icon_view->priv->cell_area)
4953 if (icon_view->priv->pixbuf_column == -1)
4955 if (icon_view->priv->pixbuf_cell != NULL)
4957 gtk_cell_area_remove (icon_view->priv->cell_area,
4958 icon_view->priv->pixbuf_cell);
4960 icon_view->priv->pixbuf_cell = NULL;
4965 if (icon_view->priv->pixbuf_cell == NULL)
4967 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4969 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4972 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4973 icon_view->priv->pixbuf_cell,
4974 "pixbuf", icon_view->priv->pixbuf_column,
4977 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4978 g_object_set (icon_view->priv->pixbuf_cell,
4983 g_object_set (icon_view->priv->pixbuf_cell,
4991 * gtk_icon_view_set_text_column:
4992 * @icon_view: A #GtkIconView.
4993 * @column: A column in the currently used model, or -1 to display no text
4995 * Sets the column with text for @icon_view to be @column. The text
4996 * column must be of type #G_TYPE_STRING.
5001 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5004 if (column == icon_view->priv->text_column)
5008 icon_view->priv->text_column = -1;
5011 if (icon_view->priv->model != NULL)
5015 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5017 g_return_if_fail (column_type == G_TYPE_STRING);
5020 icon_view->priv->text_column = column;
5023 if (icon_view->priv->cell_area)
5024 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5026 update_text_cell (icon_view);
5028 gtk_icon_view_invalidate_sizes (icon_view);
5030 g_object_notify (G_OBJECT (icon_view), "text-column");
5034 * gtk_icon_view_get_text_column:
5035 * @icon_view: A #GtkIconView.
5037 * Returns the column with text for @icon_view.
5039 * Returns: the text column, or -1 if it's unset.
5044 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5046 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5048 return icon_view->priv->text_column;
5052 * gtk_icon_view_set_markup_column:
5053 * @icon_view: A #GtkIconView.
5054 * @column: A column in the currently used model, or -1 to display no text
5056 * Sets the column with markup information for @icon_view to be
5057 * @column. The markup column must be of type #G_TYPE_STRING.
5058 * If the markup column is set to something, it overrides
5059 * the text column set by gtk_icon_view_set_text_column().
5064 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5067 if (column == icon_view->priv->markup_column)
5071 icon_view->priv->markup_column = -1;
5074 if (icon_view->priv->model != NULL)
5078 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5080 g_return_if_fail (column_type == G_TYPE_STRING);
5083 icon_view->priv->markup_column = column;
5086 if (icon_view->priv->cell_area)
5087 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5089 update_text_cell (icon_view);
5091 gtk_icon_view_invalidate_sizes (icon_view);
5093 g_object_notify (G_OBJECT (icon_view), "markup-column");
5097 * gtk_icon_view_get_markup_column:
5098 * @icon_view: A #GtkIconView.
5100 * Returns the column with markup text for @icon_view.
5102 * Returns: the markup column, or -1 if it's unset.
5107 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5109 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5111 return icon_view->priv->markup_column;
5115 * gtk_icon_view_set_pixbuf_column:
5116 * @icon_view: A #GtkIconView.
5117 * @column: A column in the currently used model, or -1 to disable
5119 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5120 * column must be of type #GDK_TYPE_PIXBUF
5125 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5128 if (column == icon_view->priv->pixbuf_column)
5132 icon_view->priv->pixbuf_column = -1;
5135 if (icon_view->priv->model != NULL)
5139 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5141 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5144 icon_view->priv->pixbuf_column = column;
5147 if (icon_view->priv->cell_area)
5148 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5150 update_pixbuf_cell (icon_view);
5152 gtk_icon_view_invalidate_sizes (icon_view);
5154 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5159 * gtk_icon_view_get_pixbuf_column:
5160 * @icon_view: A #GtkIconView.
5162 * Returns the column with pixbufs for @icon_view.
5164 * Returns: the pixbuf column, or -1 if it's unset.
5169 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5171 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5173 return icon_view->priv->pixbuf_column;
5177 * gtk_icon_view_select_path:
5178 * @icon_view: A #GtkIconView.
5179 * @path: The #GtkTreePath to be selected.
5181 * Selects the row at @path.
5186 gtk_icon_view_select_path (GtkIconView *icon_view,
5189 GtkIconViewItem *item = NULL;
5191 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5192 g_return_if_fail (icon_view->priv->model != NULL);
5193 g_return_if_fail (path != NULL);
5195 if (gtk_tree_path_get_depth (path) > 0)
5196 item = g_list_nth_data (icon_view->priv->items,
5197 gtk_tree_path_get_indices(path)[0]);
5200 gtk_icon_view_select_item (icon_view, item);
5204 * gtk_icon_view_unselect_path:
5205 * @icon_view: A #GtkIconView.
5206 * @path: The #GtkTreePath to be unselected.
5208 * Unselects the row at @path.
5213 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5216 GtkIconViewItem *item;
5218 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5219 g_return_if_fail (icon_view->priv->model != NULL);
5220 g_return_if_fail (path != NULL);
5222 item = g_list_nth_data (icon_view->priv->items,
5223 gtk_tree_path_get_indices(path)[0]);
5228 gtk_icon_view_unselect_item (icon_view, item);
5232 * gtk_icon_view_get_selected_items:
5233 * @icon_view: A #GtkIconView.
5235 * Creates a list of paths of all selected items. Additionally, if you are
5236 * planning on modifying the model after calling this function, you may
5237 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5238 * To do this, you can use gtk_tree_row_reference_new().
5240 * To free the return value, use:
5242 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5243 * g_list_free (list);
5246 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5251 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5254 GList *selected = NULL;
5256 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5258 for (list = icon_view->priv->items; list != NULL; list = list->next)
5260 GtkIconViewItem *item = list->data;
5264 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5266 selected = g_list_prepend (selected, path);
5274 * gtk_icon_view_select_all:
5275 * @icon_view: A #GtkIconView.
5277 * Selects all the icons. @icon_view must has its selection mode set
5278 * to #GTK_SELECTION_MULTIPLE.
5283 gtk_icon_view_select_all (GtkIconView *icon_view)
5286 gboolean dirty = FALSE;
5288 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5290 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5293 for (items = icon_view->priv->items; items; items = items->next)
5295 GtkIconViewItem *item = items->data;
5297 if (!item->selected)
5300 item->selected = TRUE;
5301 gtk_icon_view_queue_draw_item (icon_view, item);
5306 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5310 * gtk_icon_view_unselect_all:
5311 * @icon_view: A #GtkIconView.
5313 * Unselects all the icons.
5318 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5320 gboolean dirty = FALSE;
5322 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5324 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5327 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5330 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5334 * gtk_icon_view_path_is_selected:
5335 * @icon_view: A #GtkIconView.
5336 * @path: A #GtkTreePath to check selection on.
5338 * Returns %TRUE if the icon pointed to by @path is currently
5339 * selected. If @path does not point to a valid location, %FALSE is returned.
5341 * Return value: %TRUE if @path is selected.
5346 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5349 GtkIconViewItem *item;
5351 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5352 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5353 g_return_val_if_fail (path != NULL, FALSE);
5355 item = g_list_nth_data (icon_view->priv->items,
5356 gtk_tree_path_get_indices(path)[0]);
5361 return item->selected;
5365 * gtk_icon_view_get_item_row:
5366 * @icon_view: a #GtkIconView
5367 * @path: the #GtkTreePath of the item
5369 * Gets the row in which the item @path is currently
5370 * displayed. Row numbers start at 0.
5372 * Returns: The row in which the item is displayed
5377 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5380 GtkIconViewItem *item;
5382 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5383 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5384 g_return_val_if_fail (path != NULL, -1);
5386 item = g_list_nth_data (icon_view->priv->items,
5387 gtk_tree_path_get_indices(path)[0]);
5396 * gtk_icon_view_get_item_column:
5397 * @icon_view: a #GtkIconView
5398 * @path: the #GtkTreePath of the item
5400 * Gets the column in which the item @path is currently
5401 * displayed. Column numbers start at 0.
5403 * Returns: The column in which the item is displayed
5408 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5411 GtkIconViewItem *item;
5413 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5414 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5415 g_return_val_if_fail (path != NULL, -1);
5417 item = g_list_nth_data (icon_view->priv->items,
5418 gtk_tree_path_get_indices(path)[0]);
5427 * gtk_icon_view_item_activated:
5428 * @icon_view: A #GtkIconView
5429 * @path: The #GtkTreePath to be activated
5431 * Activates the item determined by @path.
5436 gtk_icon_view_item_activated (GtkIconView *icon_view,
5439 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5440 g_return_if_fail (path != NULL);
5442 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5446 * gtk_icon_view_set_item_orientation:
5447 * @icon_view: a #GtkIconView
5448 * @orientation: the relative position of texts and icons
5450 * Sets the ::item-orientation property which determines whether the labels
5451 * are drawn beside the icons instead of below.
5456 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5457 GtkOrientation orientation)
5459 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5461 if (icon_view->priv->item_orientation != orientation)
5463 icon_view->priv->item_orientation = orientation;
5465 if (icon_view->priv->cell_area)
5467 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5468 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5469 icon_view->priv->item_orientation);
5471 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5474 gtk_icon_view_invalidate_sizes (icon_view);
5476 update_text_cell (icon_view);
5477 update_pixbuf_cell (icon_view);
5479 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5484 * gtk_icon_view_get_item_orientation:
5485 * @icon_view: a #GtkIconView
5487 * Returns the value of the ::item-orientation property which determines
5488 * whether the labels are drawn beside the icons instead of below.
5490 * Return value: the relative position of texts and icons
5495 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5497 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5498 GTK_ORIENTATION_VERTICAL);
5500 return icon_view->priv->item_orientation;
5504 * gtk_icon_view_set_columns:
5505 * @icon_view: a #GtkIconView
5506 * @columns: the number of columns
5508 * Sets the ::columns property which determines in how
5509 * many columns the icons are arranged. If @columns is
5510 * -1, the number of columns will be chosen automatically
5511 * to fill the available area.
5516 gtk_icon_view_set_columns (GtkIconView *icon_view,
5519 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5521 if (icon_view->priv->columns != columns)
5523 icon_view->priv->columns = columns;
5525 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5526 gtk_icon_view_queue_layout (icon_view);
5528 g_object_notify (G_OBJECT (icon_view), "columns");
5533 * gtk_icon_view_get_columns:
5534 * @icon_view: a #GtkIconView
5536 * Returns the value of the ::columns property.
5538 * Return value: the number of columns, or -1
5543 gtk_icon_view_get_columns (GtkIconView *icon_view)
5545 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5547 return icon_view->priv->columns;
5551 * gtk_icon_view_set_item_width:
5552 * @icon_view: a #GtkIconView
5553 * @item_width: the width for each item
5555 * Sets the ::item-width property which specifies the width
5556 * to use for each item. If it is set to -1, the icon view will
5557 * automatically determine a suitable item size.
5562 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5565 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5567 if (icon_view->priv->item_width != item_width)
5569 icon_view->priv->item_width = item_width;
5571 if (icon_view->priv->cell_area)
5572 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5574 gtk_icon_view_invalidate_sizes (icon_view);
5576 update_text_cell (icon_view);
5578 g_object_notify (G_OBJECT (icon_view), "item-width");
5583 * gtk_icon_view_get_item_width:
5584 * @icon_view: a #GtkIconView
5586 * Returns the value of the ::item-width property.
5588 * Return value: the width of a single item, or -1
5593 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5595 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5597 return icon_view->priv->item_width;
5602 * gtk_icon_view_set_spacing:
5603 * @icon_view: a #GtkIconView
5604 * @spacing: the spacing
5606 * Sets the ::spacing property which specifies the space
5607 * which is inserted between the cells (i.e. the icon and
5608 * the text) of an item.
5613 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5616 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5618 if (icon_view->priv->spacing != spacing)
5620 icon_view->priv->spacing = spacing;
5622 if (icon_view->priv->cell_area)
5623 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5625 gtk_icon_view_invalidate_sizes (icon_view);
5627 g_object_notify (G_OBJECT (icon_view), "spacing");
5632 * gtk_icon_view_get_spacing:
5633 * @icon_view: a #GtkIconView
5635 * Returns the value of the ::spacing property.
5637 * Return value: the space between cells
5642 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5644 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5646 return icon_view->priv->spacing;
5650 * gtk_icon_view_set_row_spacing:
5651 * @icon_view: a #GtkIconView
5652 * @row_spacing: the row spacing
5654 * Sets the ::row-spacing property which specifies the space
5655 * which is inserted between the rows of the icon view.
5660 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5663 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5665 if (icon_view->priv->row_spacing != row_spacing)
5667 icon_view->priv->row_spacing = row_spacing;
5669 if (icon_view->priv->cell_area)
5670 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5672 gtk_icon_view_invalidate_sizes (icon_view);
5674 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5679 * gtk_icon_view_get_row_spacing:
5680 * @icon_view: a #GtkIconView
5682 * Returns the value of the ::row-spacing property.
5684 * Return value: the space between rows
5689 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5691 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5693 return icon_view->priv->row_spacing;
5697 * gtk_icon_view_set_column_spacing:
5698 * @icon_view: a #GtkIconView
5699 * @column_spacing: the column spacing
5701 * Sets the ::column-spacing property which specifies the space
5702 * which is inserted between the columns of the icon view.
5707 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5708 gint column_spacing)
5710 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5712 if (icon_view->priv->column_spacing != column_spacing)
5714 icon_view->priv->column_spacing = column_spacing;
5716 if (icon_view->priv->cell_area)
5717 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5719 gtk_icon_view_invalidate_sizes (icon_view);
5721 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5726 * gtk_icon_view_get_column_spacing:
5727 * @icon_view: a #GtkIconView
5729 * Returns the value of the ::column-spacing property.
5731 * Return value: the space between columns
5736 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5738 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5740 return icon_view->priv->column_spacing;
5744 * gtk_icon_view_set_margin:
5745 * @icon_view: a #GtkIconView
5746 * @margin: the margin
5748 * Sets the ::margin property which specifies the space
5749 * which is inserted at the top, bottom, left and right
5755 gtk_icon_view_set_margin (GtkIconView *icon_view,
5758 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5760 if (icon_view->priv->margin != margin)
5762 icon_view->priv->margin = margin;
5764 if (icon_view->priv->cell_area)
5765 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5767 gtk_icon_view_invalidate_sizes (icon_view);
5769 g_object_notify (G_OBJECT (icon_view), "margin");
5774 * gtk_icon_view_get_margin:
5775 * @icon_view: a #GtkIconView
5777 * Returns the value of the ::margin property.
5779 * Return value: the space at the borders
5784 gtk_icon_view_get_margin (GtkIconView *icon_view)
5786 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5788 return icon_view->priv->margin;
5792 * gtk_icon_view_set_item_padding:
5793 * @icon_view: a #GtkIconView
5794 * @item_padding: the item padding
5796 * Sets the #GtkIconView:item-padding property which specifies the padding
5797 * around each of the icon view's items.
5802 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5805 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5807 if (icon_view->priv->item_padding != item_padding)
5809 icon_view->priv->item_padding = item_padding;
5811 if (icon_view->priv->cell_area)
5812 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5814 gtk_icon_view_invalidate_sizes (icon_view);
5816 g_object_notify (G_OBJECT (icon_view), "item-padding");
5821 * gtk_icon_view_get_item_padding:
5822 * @icon_view: a #GtkIconView
5824 * Returns the value of the ::item-padding property.
5826 * Return value: the padding around items
5831 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5833 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5835 return icon_view->priv->item_padding;
5838 /* Get/set whether drag_motion requested the drag data and
5839 * drag_data_received should thus not actually insert the data,
5840 * since the data doesn't result from a drop.
5843 set_status_pending (GdkDragContext *context,
5844 GdkDragAction suggested_action)
5846 g_object_set_data (G_OBJECT (context),
5847 I_("gtk-icon-view-status-pending"),
5848 GINT_TO_POINTER (suggested_action));
5851 static GdkDragAction
5852 get_status_pending (GdkDragContext *context)
5854 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5855 "gtk-icon-view-status-pending"));
5859 unset_reorderable (GtkIconView *icon_view)
5861 if (icon_view->priv->reorderable)
5863 icon_view->priv->reorderable = FALSE;
5864 g_object_notify (G_OBJECT (icon_view), "reorderable");
5869 set_source_row (GdkDragContext *context,
5870 GtkTreeModel *model,
5871 GtkTreePath *source_row)
5874 g_object_set_data_full (G_OBJECT (context),
5875 I_("gtk-icon-view-source-row"),
5876 gtk_tree_row_reference_new (model, source_row),
5877 (GDestroyNotify) gtk_tree_row_reference_free);
5879 g_object_set_data_full (G_OBJECT (context),
5880 I_("gtk-icon-view-source-row"),
5885 get_source_row (GdkDragContext *context)
5887 GtkTreeRowReference *ref;
5889 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5892 return gtk_tree_row_reference_get_path (ref);
5899 GtkTreeRowReference *dest_row;
5900 gboolean empty_view_drop;
5901 gboolean drop_append_mode;
5905 dest_row_free (gpointer data)
5907 DestRow *dr = (DestRow *)data;
5909 gtk_tree_row_reference_free (dr->dest_row);
5914 set_dest_row (GdkDragContext *context,
5915 GtkTreeModel *model,
5916 GtkTreePath *dest_row,
5917 gboolean empty_view_drop,
5918 gboolean drop_append_mode)
5924 g_object_set_data_full (G_OBJECT (context),
5925 I_("gtk-icon-view-dest-row"),
5930 dr = g_new0 (DestRow, 1);
5932 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5933 dr->empty_view_drop = empty_view_drop;
5934 dr->drop_append_mode = drop_append_mode;
5935 g_object_set_data_full (G_OBJECT (context),
5936 I_("gtk-icon-view-dest-row"),
5937 dr, (GDestroyNotify) dest_row_free);
5941 get_dest_row (GdkDragContext *context)
5945 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5949 GtkTreePath *path = NULL;
5952 path = gtk_tree_row_reference_get_path (dr->dest_row);
5953 else if (dr->empty_view_drop)
5954 path = gtk_tree_path_new_from_indices (0, -1);
5958 if (path && dr->drop_append_mode)
5959 gtk_tree_path_next (path);
5968 check_model_dnd (GtkTreeModel *model,
5969 GType required_iface,
5970 const gchar *signal)
5972 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5974 g_warning ("You must override the default '%s' handler "
5975 "on GtkIconView when using models that don't support "
5976 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5977 "is to connect to '%s' and call "
5978 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5979 "the default handler from running. Look at the source code "
5980 "for the default handler in gtkiconview.c to get an idea what "
5981 "your handler should do. (gtkiconview.c is in the GTK+ source "
5982 "code.) If you're using GTK+ from a language other than C, "
5983 "there may be a more natural way to override default handlers, e.g. via derivation.",
5984 signal, g_type_name (required_iface), signal);
5992 remove_scroll_timeout (GtkIconView *icon_view)
5994 if (icon_view->priv->scroll_timeout_id != 0)
5996 g_source_remove (icon_view->priv->scroll_timeout_id);
5998 icon_view->priv->scroll_timeout_id = 0;
6003 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6006 gint px, py, x, y, width, height;
6007 gint hoffset, voffset;
6009 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6011 gdk_window_get_pointer (window, &px, &py, NULL);
6012 gdk_window_get_geometry (window, &x, &y, &width, &height);
6014 /* see if we are near the edge. */
6015 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6017 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6019 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6021 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6024 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6025 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6028 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6029 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6034 drag_scroll_timeout (gpointer data)
6036 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6038 gtk_icon_view_autoscroll (icon_view);
6045 set_destination (GtkIconView *icon_view,
6046 GdkDragContext *context,
6049 GdkDragAction *suggested_action,
6053 GtkTreePath *path = NULL;
6054 GtkIconViewDropPosition pos;
6055 GtkIconViewDropPosition old_pos;
6056 GtkTreePath *old_dest_path = NULL;
6057 gboolean can_drop = FALSE;
6059 widget = GTK_WIDGET (icon_view);
6061 *suggested_action = 0;
6064 if (!icon_view->priv->dest_set)
6066 /* someone unset us as a drag dest, note that if
6067 * we return FALSE drag_leave isn't called
6070 gtk_icon_view_set_drag_dest_item (icon_view,
6072 GTK_ICON_VIEW_DROP_LEFT);
6074 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6076 return FALSE; /* no longer a drop site */
6079 *target = gtk_drag_dest_find_target (widget, context,
6080 gtk_drag_dest_get_target_list (widget));
6081 if (*target == GDK_NONE)
6084 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6087 GtkTreeModel *model;
6089 /* the row got dropped on empty space, let's setup a special case
6093 gtk_tree_path_free (path);
6095 model = gtk_icon_view_get_model (icon_view);
6097 n_children = gtk_tree_model_iter_n_children (model, NULL);
6100 pos = GTK_ICON_VIEW_DROP_BELOW;
6101 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6105 pos = GTK_ICON_VIEW_DROP_ABOVE;
6106 path = gtk_tree_path_new_from_indices (0, -1);
6116 gtk_icon_view_get_drag_dest_item (icon_view,
6121 gtk_tree_path_free (old_dest_path);
6123 if (TRUE /* FIXME if the location droppable predicate */)
6131 GtkWidget *source_widget;
6133 *suggested_action = gdk_drag_context_get_suggested_action (context);
6134 source_widget = gtk_drag_get_source_widget (context);
6136 if (source_widget == widget)
6138 /* Default to MOVE, unless the user has
6139 * pressed ctrl or shift to affect available actions
6141 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6142 *suggested_action = GDK_ACTION_MOVE;
6145 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6150 /* can't drop here */
6151 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6153 GTK_ICON_VIEW_DROP_LEFT);
6157 gtk_tree_path_free (path);
6163 get_logical_destination (GtkIconView *icon_view,
6164 gboolean *drop_append_mode)
6166 /* adjust path to point to the row the drop goes in front of */
6167 GtkTreePath *path = NULL;
6168 GtkIconViewDropPosition pos;
6170 *drop_append_mode = FALSE;
6172 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6177 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6178 pos == GTK_ICON_VIEW_DROP_BELOW)
6181 GtkTreeModel *model = icon_view->priv->model;
6183 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6184 !gtk_tree_model_iter_next (model, &iter))
6185 *drop_append_mode = TRUE;
6188 *drop_append_mode = FALSE;
6189 gtk_tree_path_next (path);
6197 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6198 GdkEventMotion *event)
6200 GtkWidget *widget = GTK_WIDGET (icon_view);
6201 GdkDragContext *context;
6202 GtkTreePath *path = NULL;
6204 GtkTreeModel *model;
6205 gboolean retval = FALSE;
6207 if (!icon_view->priv->source_set)
6210 if (icon_view->priv->pressed_button < 0)
6213 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6214 icon_view->priv->press_start_x,
6215 icon_view->priv->press_start_y,
6216 event->x, event->y))
6219 model = gtk_icon_view_get_model (icon_view);
6224 button = icon_view->priv->pressed_button;
6225 icon_view->priv->pressed_button = -1;
6227 path = gtk_icon_view_get_path_at_pos (icon_view,
6228 icon_view->priv->press_start_x,
6229 icon_view->priv->press_start_y);
6234 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6235 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6239 /* FIXME Check whether we're a start button, if not return FALSE and
6243 /* Now we can begin the drag */
6247 context = gtk_drag_begin (widget,
6248 gtk_drag_source_get_target_list (widget),
6249 icon_view->priv->source_actions,
6253 set_source_row (context, model, path);
6257 gtk_tree_path_free (path);
6262 /* Source side drag signals */
6264 gtk_icon_view_drag_begin (GtkWidget *widget,
6265 GdkDragContext *context)
6267 GtkIconView *icon_view;
6268 GtkIconViewItem *item;
6269 cairo_surface_t *icon;
6273 icon_view = GTK_ICON_VIEW (widget);
6275 /* if the user uses a custom DnD impl, we don't set the icon here */
6276 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6279 item = gtk_icon_view_get_item_at_coords (icon_view,
6280 icon_view->priv->press_start_x,
6281 icon_view->priv->press_start_y,
6285 g_return_if_fail (item != NULL);
6287 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6288 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6290 path = gtk_tree_path_new_from_indices (item->index, -1);
6291 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6292 gtk_tree_path_free (path);
6294 cairo_surface_set_device_offset (icon, -x, -y);
6296 gtk_drag_set_icon_surface (context, icon);
6298 cairo_surface_destroy (icon);
6302 gtk_icon_view_drag_end (GtkWidget *widget,
6303 GdkDragContext *context)
6309 gtk_icon_view_drag_data_get (GtkWidget *widget,
6310 GdkDragContext *context,
6311 GtkSelectionData *selection_data,
6315 GtkIconView *icon_view;
6316 GtkTreeModel *model;
6317 GtkTreePath *source_row;
6319 icon_view = GTK_ICON_VIEW (widget);
6320 model = gtk_icon_view_get_model (icon_view);
6325 if (!icon_view->priv->source_set)
6328 source_row = get_source_row (context);
6330 if (source_row == NULL)
6333 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6334 * any model; for DragSource models there are some other targets
6338 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6339 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6344 /* If drag_data_get does nothing, try providing row data. */
6345 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6346 gtk_tree_set_row_drag_data (selection_data,
6351 gtk_tree_path_free (source_row);
6355 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6356 GdkDragContext *context)
6358 GtkTreeModel *model;
6359 GtkIconView *icon_view;
6360 GtkTreePath *source_row;
6362 icon_view = GTK_ICON_VIEW (widget);
6363 model = gtk_icon_view_get_model (icon_view);
6365 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6368 if (!icon_view->priv->source_set)
6371 source_row = get_source_row (context);
6373 if (source_row == NULL)
6376 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6379 gtk_tree_path_free (source_row);
6381 set_source_row (context, NULL, NULL);
6384 /* Target side drag signals */
6386 gtk_icon_view_drag_leave (GtkWidget *widget,
6387 GdkDragContext *context,
6390 GtkIconView *icon_view;
6392 icon_view = GTK_ICON_VIEW (widget);
6394 /* unset any highlight row */
6395 gtk_icon_view_set_drag_dest_item (icon_view,
6397 GTK_ICON_VIEW_DROP_LEFT);
6399 remove_scroll_timeout (icon_view);
6403 gtk_icon_view_drag_motion (GtkWidget *widget,
6404 GdkDragContext *context,
6409 GtkTreePath *path = NULL;
6410 GtkIconViewDropPosition pos;
6411 GtkIconView *icon_view;
6412 GdkDragAction suggested_action = 0;
6416 icon_view = GTK_ICON_VIEW (widget);
6418 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6421 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6423 /* we only know this *after* set_desination_row */
6424 empty = icon_view->priv->empty_view_drop;
6426 if (path == NULL && !empty)
6428 /* Can't drop here. */
6429 gdk_drag_status (context, 0, time);
6433 if (icon_view->priv->scroll_timeout_id == 0)
6435 icon_view->priv->scroll_timeout_id =
6436 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6439 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6441 /* Request data so we can use the source row when
6442 * determining whether to accept the drop
6444 set_status_pending (context, suggested_action);
6445 gtk_drag_get_data (widget, context, target, time);
6449 set_status_pending (context, 0);
6450 gdk_drag_status (context, suggested_action, time);
6455 gtk_tree_path_free (path);
6461 gtk_icon_view_drag_drop (GtkWidget *widget,
6462 GdkDragContext *context,
6467 GtkIconView *icon_view;
6469 GdkDragAction suggested_action = 0;
6470 GdkAtom target = GDK_NONE;
6471 GtkTreeModel *model;
6472 gboolean drop_append_mode;
6474 icon_view = GTK_ICON_VIEW (widget);
6475 model = gtk_icon_view_get_model (icon_view);
6477 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6479 if (!icon_view->priv->dest_set)
6482 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6485 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6488 path = get_logical_destination (icon_view, &drop_append_mode);
6490 if (target != GDK_NONE && path != NULL)
6492 /* in case a motion had requested drag data, change things so we
6493 * treat drag data receives as a drop.
6495 set_status_pending (context, 0);
6496 set_dest_row (context, model, path,
6497 icon_view->priv->empty_view_drop, drop_append_mode);
6501 gtk_tree_path_free (path);
6503 /* Unset this thing */
6504 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6506 if (target != GDK_NONE)
6508 gtk_drag_get_data (widget, context, target, time);
6516 gtk_icon_view_drag_data_received (GtkWidget *widget,
6517 GdkDragContext *context,
6520 GtkSelectionData *selection_data,
6525 gboolean accepted = FALSE;
6526 GtkTreeModel *model;
6527 GtkIconView *icon_view;
6528 GtkTreePath *dest_row;
6529 GdkDragAction suggested_action;
6530 gboolean drop_append_mode;
6532 icon_view = GTK_ICON_VIEW (widget);
6533 model = gtk_icon_view_get_model (icon_view);
6535 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6538 if (!icon_view->priv->dest_set)
6541 suggested_action = get_status_pending (context);
6543 if (suggested_action)
6545 /* We are getting this data due to a request in drag_motion,
6546 * rather than due to a request in drag_drop, so we are just
6547 * supposed to call drag_status, not actually paste in the
6550 path = get_logical_destination (icon_view, &drop_append_mode);
6553 suggested_action = 0;
6555 if (suggested_action)
6557 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6560 suggested_action = 0;
6563 gdk_drag_status (context, suggested_action, time);
6566 gtk_tree_path_free (path);
6568 /* If you can't drop, remove user drop indicator until the next motion */
6569 if (suggested_action == 0)
6570 gtk_icon_view_set_drag_dest_item (icon_view,
6572 GTK_ICON_VIEW_DROP_LEFT);
6577 dest_row = get_dest_row (context);
6579 if (dest_row == NULL)
6582 if (gtk_selection_data_get_length (selection_data) >= 0)
6584 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6590 gtk_drag_finish (context,
6592 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6595 gtk_tree_path_free (dest_row);
6598 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6601 /* Drag-and-Drop support */
6603 * gtk_icon_view_enable_model_drag_source:
6604 * @icon_view: a #GtkIconTreeView
6605 * @start_button_mask: Mask of allowed buttons to start drag
6606 * @targets: (array length=n_targets): the table of targets that the drag will
6608 * @n_targets: the number of items in @targets
6609 * @actions: the bitmask of possible actions for a drag from this
6612 * Turns @icon_view into a drag source for automatic DND. Calling this
6613 * method sets #GtkIconView:reorderable to %FALSE.
6618 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6619 GdkModifierType start_button_mask,
6620 const GtkTargetEntry *targets,
6622 GdkDragAction actions)
6624 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6626 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6628 icon_view->priv->start_button_mask = start_button_mask;
6629 icon_view->priv->source_actions = actions;
6631 icon_view->priv->source_set = TRUE;
6633 unset_reorderable (icon_view);
6637 * gtk_icon_view_enable_model_drag_dest:
6638 * @icon_view: a #GtkIconView
6639 * @targets: (array length=n_targets): the table of targets that the drag will
6641 * @n_targets: the number of items in @targets
6642 * @actions: the bitmask of possible actions for a drag to this
6645 * Turns @icon_view into a drop destination for automatic DND. Calling this
6646 * method sets #GtkIconView:reorderable to %FALSE.
6651 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6652 const GtkTargetEntry *targets,
6654 GdkDragAction actions)
6656 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6658 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6660 icon_view->priv->dest_actions = actions;
6662 icon_view->priv->dest_set = TRUE;
6664 unset_reorderable (icon_view);
6668 * gtk_icon_view_unset_model_drag_source:
6669 * @icon_view: a #GtkIconView
6671 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6672 * method sets #GtkIconView:reorderable to %FALSE.
6677 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6681 if (icon_view->priv->source_set)
6683 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6684 icon_view->priv->source_set = FALSE;
6687 unset_reorderable (icon_view);
6691 * gtk_icon_view_unset_model_drag_dest:
6692 * @icon_view: a #GtkIconView
6694 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6695 * method sets #GtkIconView:reorderable to %FALSE.
6700 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6702 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6704 if (icon_view->priv->dest_set)
6706 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6707 icon_view->priv->dest_set = FALSE;
6710 unset_reorderable (icon_view);
6713 /* These are useful to implement your own custom stuff. */
6715 * gtk_icon_view_set_drag_dest_item:
6716 * @icon_view: a #GtkIconView
6717 * @path: (allow-none): The path of the item to highlight, or %NULL.
6718 * @pos: Specifies where to drop, relative to the item
6720 * Sets the item that is highlighted for feedback.
6725 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6727 GtkIconViewDropPosition pos)
6729 /* Note; this function is exported to allow a custom DND
6730 * implementation, so it can't touch TreeViewDragInfo
6733 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6735 if (icon_view->priv->dest_item)
6737 GtkTreePath *current_path;
6738 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6739 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6740 icon_view->priv->dest_item = NULL;
6742 gtk_icon_view_queue_draw_path (icon_view, current_path);
6743 gtk_tree_path_free (current_path);
6746 /* special case a drop on an empty model */
6747 icon_view->priv->empty_view_drop = FALSE;
6748 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6749 && gtk_tree_path_get_depth (path) == 1
6750 && gtk_tree_path_get_indices (path)[0] == 0)
6754 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6757 if (n_children == 0)
6758 icon_view->priv->empty_view_drop = TRUE;
6761 icon_view->priv->dest_pos = pos;
6765 icon_view->priv->dest_item =
6766 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6767 icon_view->priv->model, path);
6769 gtk_icon_view_queue_draw_path (icon_view, path);
6774 * gtk_icon_view_get_drag_dest_item:
6775 * @icon_view: a #GtkIconView
6776 * @path: (out) (allow-none): Return location for the path of
6777 * the highlighted item, or %NULL.
6778 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6780 * Gets information about the item that is highlighted for feedback.
6785 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6787 GtkIconViewDropPosition *pos)
6789 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6793 if (icon_view->priv->dest_item)
6794 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6800 *pos = icon_view->priv->dest_pos;
6804 * gtk_icon_view_get_dest_item_at_pos:
6805 * @icon_view: a #GtkIconView
6806 * @drag_x: the position to determine the destination item for
6807 * @drag_y: the position to determine the destination item for
6808 * @path: (out) (allow-none): Return location for the path of the item,
6810 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6812 * Determines the destination item for a given position.
6814 * Return value: whether there is an item at the given position.
6819 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6823 GtkIconViewDropPosition *pos)
6825 GtkIconViewItem *item;
6827 /* Note; this function is exported to allow a custom DND
6828 * implementation, so it can't touch TreeViewDragInfo
6831 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6832 g_return_val_if_fail (drag_x >= 0, FALSE);
6833 g_return_val_if_fail (drag_y >= 0, FALSE);
6834 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6840 item = gtk_icon_view_get_item_at_coords (icon_view,
6841 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6842 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6849 *path = gtk_tree_path_new_from_indices (item->index, -1);
6853 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6854 *pos = GTK_ICON_VIEW_DROP_LEFT;
6855 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6856 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6857 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6858 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6859 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6860 *pos = GTK_ICON_VIEW_DROP_BELOW;
6862 *pos = GTK_ICON_VIEW_DROP_INTO;
6869 * gtk_icon_view_create_drag_icon:
6870 * @icon_view: a #GtkIconView
6871 * @path: a #GtkTreePath in @icon_view
6873 * Creates a #cairo_surface_t representation of the item at @path.
6874 * This image is used for a drag icon.
6876 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6881 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6885 GtkStyleContext *context;
6887 cairo_surface_t *surface;
6891 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6892 g_return_val_if_fail (path != NULL, NULL);
6894 widget = GTK_WIDGET (icon_view);
6895 context = gtk_widget_get_style_context (widget);
6897 if (!gtk_widget_get_realized (widget))
6900 index = gtk_tree_path_get_indices (path)[0];
6902 for (l = icon_view->priv->items; l; l = l->next)
6904 GtkIconViewItem *item = l->data;
6906 if (index == item->index)
6908 GdkRectangle rect = {
6909 item->cell_area.x - icon_view->priv->item_padding,
6910 item->cell_area.y - icon_view->priv->item_padding,
6911 item->cell_area.width + icon_view->priv->item_padding * 2,
6912 item->cell_area.height + icon_view->priv->item_padding * 2
6915 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6916 CAIRO_CONTENT_COLOR,
6920 cr = cairo_create (surface);
6921 cairo_set_line_width (cr, 1.);
6923 gtk_render_background (context, cr, 0, 0,
6924 rect.width + 2, rect.height + 2);
6928 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6931 gtk_icon_view_paint_item (icon_view, cr, item,
6932 icon_view->priv->item_padding + 1,
6933 icon_view->priv->item_padding + 1, FALSE);
6937 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6938 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6951 * gtk_icon_view_get_reorderable:
6952 * @icon_view: a #GtkIconView
6954 * Retrieves whether the user can reorder the list via drag-and-drop.
6955 * See gtk_icon_view_set_reorderable().
6957 * Return value: %TRUE if the list can be reordered.
6962 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6964 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6966 return icon_view->priv->reorderable;
6969 static const GtkTargetEntry item_targets[] = {
6970 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6975 * gtk_icon_view_set_reorderable:
6976 * @icon_view: A #GtkIconView.
6977 * @reorderable: %TRUE, if the list of items can be reordered.
6979 * This function is a convenience function to allow you to reorder models that
6980 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6981 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6982 * the user can reorder the model by dragging and dropping rows. The
6983 * developer can listen to these changes by connecting to the model's
6984 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6985 * the icon view as a drag source and destination. Therefore, drag and
6986 * drop can not be used in a reorderable view for any other purpose.
6988 * This function does not give you any degree of control over the order -- any
6989 * reordering is allowed. If more control is needed, you should probably
6990 * handle drag and drop manually.
6995 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6996 gboolean reorderable)
6998 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7000 reorderable = reorderable != FALSE;
7002 if (icon_view->priv->reorderable == reorderable)
7007 gtk_icon_view_enable_model_drag_source (icon_view,
7010 G_N_ELEMENTS (item_targets),
7012 gtk_icon_view_enable_model_drag_dest (icon_view,
7014 G_N_ELEMENTS (item_targets),
7019 gtk_icon_view_unset_model_drag_source (icon_view);
7020 gtk_icon_view_unset_model_drag_dest (icon_view);
7023 icon_view->priv->reorderable = reorderable;
7025 g_object_notify (G_OBJECT (icon_view), "reorderable");
7029 /* Accessibility Support */
7031 static gpointer accessible_parent_class;
7032 static gpointer accessible_item_parent_class;
7033 static GQuark accessible_private_data_quark = 0;
7035 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7036 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7037 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7039 static GType gtk_icon_view_item_accessible_get_type (void);
7050 GtkIconViewItem *item;
7054 AtkStateSet *state_set;
7058 GtkTextBuffer *text_buffer;
7060 gchar *action_descriptions[LAST_ACTION];
7061 gchar *image_description;
7062 guint action_idle_handler;
7063 } GtkIconViewItemAccessible;
7065 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7071 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7076 typedef struct _GtkIconViewItemAccessibleClass
7078 AtkObjectClass parent_class;
7080 } GtkIconViewItemAccessibleClass;
7082 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7085 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7087 GtkIconViewItemAccessible *item;
7088 GtkIconView *icon_view;
7091 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7092 item->action_idle_handler = 0;
7094 if (item->widget != NULL)
7096 icon_view = GTK_ICON_VIEW (item->widget);
7097 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7098 gtk_icon_view_item_activated (icon_view, path);
7099 gtk_tree_path_free (path);
7106 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7109 GtkIconViewItemAccessible *item;
7111 if (i < 0 || i >= LAST_ACTION)
7114 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7116 if (!GTK_IS_ICON_VIEW (item->widget))
7119 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7124 case ACTION_ACTIVATE:
7125 if (!item->action_idle_handler)
7126 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7129 g_assert_not_reached ();
7137 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7142 static const gchar *
7143 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7146 GtkIconViewItemAccessible *item;
7148 if (i < 0 || i >= LAST_ACTION)
7151 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7153 if (item->action_descriptions[i])
7154 return item->action_descriptions[i];
7156 return gtk_icon_view_item_accessible_action_descriptions[i];
7159 static const gchar *
7160 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7163 if (i < 0 || i >= LAST_ACTION)
7166 return gtk_icon_view_item_accessible_action_names[i];
7170 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7172 const gchar *description)
7174 GtkIconViewItemAccessible *item;
7176 if (i < 0 || i >= LAST_ACTION)
7179 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7181 g_free (item->action_descriptions[i]);
7183 item->action_descriptions[i] = g_strdup (description);
7189 atk_action_item_interface_init (AtkActionIface *iface)
7191 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7192 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7193 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7194 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7195 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7198 static const gchar *
7199 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7201 GtkIconViewItemAccessible *item;
7203 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7205 return item->image_description;
7209 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7210 const gchar *description)
7212 GtkIconViewItemAccessible *item;
7214 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7216 g_free (item->image_description);
7217 item->image_description = g_strdup (description);
7224 gboolean pixbuf_found;
7228 get_pixbuf_foreach (GtkCellRenderer *renderer,
7229 const GdkRectangle *cell_area,
7230 const GdkRectangle *cell_background,
7231 GetPixbufBoxData *data)
7233 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7235 data->box = *cell_area;
7236 data->pixbuf_found = TRUE;
7238 return (data->pixbuf_found != FALSE);
7242 get_pixbuf_box (GtkIconView *icon_view,
7243 GtkIconViewItem *item,
7246 GetPixbufBoxData data = { { 0, }, FALSE };
7247 GtkCellAreaContext *context;
7249 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7251 gtk_icon_view_set_cell_data (icon_view, item);
7252 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7253 GTK_WIDGET (icon_view),
7254 (GdkRectangle *)item, (GdkRectangle *)item,
7255 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7257 return data.pixbuf_found;
7261 get_text_foreach (GtkCellRenderer *renderer,
7264 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7266 g_object_get (renderer, "text", text, NULL);
7274 get_text (GtkIconView *icon_view,
7275 GtkIconViewItem *item)
7279 gtk_icon_view_set_cell_data (icon_view, item);
7280 gtk_cell_area_foreach (icon_view->priv->cell_area,
7281 (GtkCellCallback)get_text_foreach, &text);
7287 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7291 GtkIconViewItemAccessible *item;
7294 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7296 if (!GTK_IS_ICON_VIEW (item->widget))
7299 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7302 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7305 *height = box.height;
7310 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7313 AtkCoordType coord_type)
7315 GtkIconViewItemAccessible *item;
7318 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7320 if (!GTK_IS_ICON_VIEW (item->widget))
7323 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7326 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7328 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7330 *x+= box.x - item->item->cell_area.x;
7331 *y+= box.y - item->item->cell_area.y;
7337 atk_image_item_interface_init (AtkImageIface *iface)
7339 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7340 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7341 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7342 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7346 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7350 GtkIconViewItemAccessible *item;
7351 GtkTextIter start, end;
7352 GtkTextBuffer *buffer;
7354 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7356 if (!GTK_IS_ICON_VIEW (item->widget))
7359 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7362 buffer = item->text_buffer;
7363 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7365 gtk_text_buffer_get_end_iter (buffer, &end);
7367 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7369 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7373 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7376 GtkIconViewItemAccessible *item;
7377 GtkTextIter start, end;
7378 GtkTextBuffer *buffer;
7382 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7384 if (!GTK_IS_ICON_VIEW (item->widget))
7387 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7390 buffer = item->text_buffer;
7391 if (offset >= gtk_text_buffer_get_char_count (buffer))
7394 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7396 gtk_text_iter_forward_char (&end);
7397 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7398 unichar = g_utf8_get_char (string);
7406 get_pango_text_offsets (PangoLayout *layout,
7407 GtkTextBuffer *buffer,
7409 AtkTextBoundary boundary_type,
7413 GtkTextIter *start_iter,
7414 GtkTextIter *end_iter)
7416 PangoLayoutIter *iter;
7417 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7418 gint index, start_index, end_index;
7420 gboolean found = FALSE;
7422 text = pango_layout_get_text (layout);
7423 index = g_utf8_offset_to_pointer (text, offset) - text;
7424 iter = pango_layout_get_iter (layout);
7427 line = pango_layout_iter_get_line_readonly (iter);
7428 start_index = line->start_index;
7429 end_index = start_index + line->length;
7431 if (index >= start_index && index <= end_index)
7434 * Found line for offset
7440 * We want the previous line
7444 switch (boundary_type)
7446 case ATK_TEXT_BOUNDARY_LINE_START:
7447 end_index = start_index;
7448 start_index = prev_line->start_index;
7450 case ATK_TEXT_BOUNDARY_LINE_END:
7452 start_index = prev_prev_line->start_index +
7453 prev_prev_line->length;
7454 end_index = prev_line->start_index + prev_line->length;
7457 g_assert_not_reached();
7461 start_index = end_index = 0;
7464 switch (boundary_type)
7466 case ATK_TEXT_BOUNDARY_LINE_START:
7467 if (pango_layout_iter_next_line (iter))
7468 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7470 case ATK_TEXT_BOUNDARY_LINE_END:
7472 start_index = prev_line->start_index +
7476 g_assert_not_reached();
7481 * We want the next line
7483 if (pango_layout_iter_next_line (iter))
7485 line = pango_layout_iter_get_line_readonly (iter);
7486 switch (boundary_type)
7488 case ATK_TEXT_BOUNDARY_LINE_START:
7489 start_index = line->start_index;
7490 if (pango_layout_iter_next_line (iter))
7491 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7493 end_index = start_index + line->length;
7495 case ATK_TEXT_BOUNDARY_LINE_END:
7496 start_index = end_index;
7497 end_index = line->start_index + line->length;
7500 g_assert_not_reached();
7504 start_index = end_index;
7510 prev_prev_line = prev_line;
7513 while (pango_layout_iter_next_line (iter));
7517 start_index = prev_line->start_index + prev_line->length;
7518 end_index = start_index;
7520 pango_layout_iter_free (iter);
7521 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7522 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7524 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7525 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7530 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7532 AtkTextBoundary boundary_type,
7536 GtkIconViewItemAccessible *item;
7537 GtkTextIter start, end;
7538 GtkTextBuffer *buffer;
7540 GtkIconView *icon_view;
7543 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7545 if (!GTK_IS_ICON_VIEW (item->widget))
7548 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7551 buffer = item->text_buffer;
7553 if (!gtk_text_buffer_get_char_count (buffer))
7557 return g_strdup ("");
7559 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7563 switch (boundary_type)
7565 case ATK_TEXT_BOUNDARY_CHAR:
7566 gtk_text_iter_backward_char(&start);
7568 case ATK_TEXT_BOUNDARY_WORD_START:
7569 if (!gtk_text_iter_starts_word (&start))
7570 gtk_text_iter_backward_word_start (&start);
7572 gtk_text_iter_backward_word_start(&start);
7574 case ATK_TEXT_BOUNDARY_WORD_END:
7575 if (gtk_text_iter_inside_word (&start) &&
7576 !gtk_text_iter_starts_word (&start))
7577 gtk_text_iter_backward_word_start (&start);
7578 while (!gtk_text_iter_ends_word (&start))
7580 if (!gtk_text_iter_backward_char (&start))
7584 gtk_text_iter_backward_word_start(&start);
7585 while (!gtk_text_iter_ends_word (&start))
7587 if (!gtk_text_iter_backward_char (&start))
7591 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7592 if (!gtk_text_iter_starts_sentence (&start))
7593 gtk_text_iter_backward_sentence_start (&start);
7595 gtk_text_iter_backward_sentence_start (&start);
7597 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7598 if (gtk_text_iter_inside_sentence (&start) &&
7599 !gtk_text_iter_starts_sentence (&start))
7600 gtk_text_iter_backward_sentence_start (&start);
7601 while (!gtk_text_iter_ends_sentence (&start))
7603 if (!gtk_text_iter_backward_char (&start))
7607 gtk_text_iter_backward_sentence_start (&start);
7608 while (!gtk_text_iter_ends_sentence (&start))
7610 if (!gtk_text_iter_backward_char (&start))
7614 case ATK_TEXT_BOUNDARY_LINE_START:
7615 case ATK_TEXT_BOUNDARY_LINE_END:
7617 icon_view = GTK_ICON_VIEW (item->widget);
7618 /* FIXME we probably have to use GailTextCell to salvage this */
7619 gtk_icon_view_update_item_text (icon_view, item->item);
7620 get_pango_text_offsets (icon_view->priv->layout,
7633 *start_offset = gtk_text_iter_get_offset (&start);
7634 *end_offset = gtk_text_iter_get_offset (&end);
7636 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7640 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7642 AtkTextBoundary boundary_type,
7646 GtkIconViewItemAccessible *item;
7647 GtkTextIter start, end;
7648 GtkTextBuffer *buffer;
7650 GtkIconView *icon_view;
7653 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7655 if (!GTK_IS_ICON_VIEW (item->widget))
7658 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7661 buffer = item->text_buffer;
7663 if (!gtk_text_buffer_get_char_count (buffer))
7667 return g_strdup ("");
7669 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7673 switch (boundary_type)
7675 case ATK_TEXT_BOUNDARY_CHAR:
7676 gtk_text_iter_forward_char (&end);
7678 case ATK_TEXT_BOUNDARY_WORD_START:
7679 if (!gtk_text_iter_starts_word (&start))
7680 gtk_text_iter_backward_word_start (&start);
7681 if (gtk_text_iter_inside_word (&end))
7682 gtk_text_iter_forward_word_end (&end);
7683 while (!gtk_text_iter_starts_word (&end))
7685 if (!gtk_text_iter_forward_char (&end))
7689 case ATK_TEXT_BOUNDARY_WORD_END:
7690 if (gtk_text_iter_inside_word (&start) &&
7691 !gtk_text_iter_starts_word (&start))
7692 gtk_text_iter_backward_word_start (&start);
7693 while (!gtk_text_iter_ends_word (&start))
7695 if (!gtk_text_iter_backward_char (&start))
7698 gtk_text_iter_forward_word_end (&end);
7700 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7701 if (!gtk_text_iter_starts_sentence (&start))
7702 gtk_text_iter_backward_sentence_start (&start);
7703 if (gtk_text_iter_inside_sentence (&end))
7704 gtk_text_iter_forward_sentence_end (&end);
7705 while (!gtk_text_iter_starts_sentence (&end))
7707 if (!gtk_text_iter_forward_char (&end))
7711 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7712 if (gtk_text_iter_inside_sentence (&start) &&
7713 !gtk_text_iter_starts_sentence (&start))
7714 gtk_text_iter_backward_sentence_start (&start);
7715 while (!gtk_text_iter_ends_sentence (&start))
7717 if (!gtk_text_iter_backward_char (&start))
7720 gtk_text_iter_forward_sentence_end (&end);
7722 case ATK_TEXT_BOUNDARY_LINE_START:
7723 case ATK_TEXT_BOUNDARY_LINE_END:
7725 icon_view = GTK_ICON_VIEW (item->widget);
7726 /* FIXME we probably have to use GailTextCell to salvage this */
7727 gtk_icon_view_update_item_text (icon_view, item->item);
7728 get_pango_text_offsets (icon_view->priv->layout,
7742 *start_offset = gtk_text_iter_get_offset (&start);
7743 *end_offset = gtk_text_iter_get_offset (&end);
7745 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7749 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7751 AtkTextBoundary boundary_type,
7755 GtkIconViewItemAccessible *item;
7756 GtkTextIter start, end;
7757 GtkTextBuffer *buffer;
7759 GtkIconView *icon_view;
7762 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7764 if (!GTK_IS_ICON_VIEW (item->widget))
7767 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7770 buffer = item->text_buffer;
7772 if (!gtk_text_buffer_get_char_count (buffer))
7776 return g_strdup ("");
7778 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7782 switch (boundary_type)
7784 case ATK_TEXT_BOUNDARY_CHAR:
7785 gtk_text_iter_forward_char(&start);
7786 gtk_text_iter_forward_chars(&end, 2);
7788 case ATK_TEXT_BOUNDARY_WORD_START:
7789 if (gtk_text_iter_inside_word (&end))
7790 gtk_text_iter_forward_word_end (&end);
7791 while (!gtk_text_iter_starts_word (&end))
7793 if (!gtk_text_iter_forward_char (&end))
7797 if (!gtk_text_iter_is_end (&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))
7807 case ATK_TEXT_BOUNDARY_WORD_END:
7808 gtk_text_iter_forward_word_end (&end);
7810 if (!gtk_text_iter_is_end (&end))
7811 gtk_text_iter_forward_word_end (&end);
7813 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7814 if (gtk_text_iter_inside_sentence (&end))
7815 gtk_text_iter_forward_sentence_end (&end);
7816 while (!gtk_text_iter_starts_sentence (&end))
7818 if (!gtk_text_iter_forward_char (&end))
7822 if (!gtk_text_iter_is_end (&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))
7832 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7833 gtk_text_iter_forward_sentence_end (&end);
7835 if (!gtk_text_iter_is_end (&end))
7836 gtk_text_iter_forward_sentence_end (&end);
7838 case ATK_TEXT_BOUNDARY_LINE_START:
7839 case ATK_TEXT_BOUNDARY_LINE_END:
7841 icon_view = GTK_ICON_VIEW (item->widget);
7842 /* FIXME we probably have to use GailTextCell to salvage this */
7843 gtk_icon_view_update_item_text (icon_view, item->item);
7844 get_pango_text_offsets (icon_view->priv->layout,
7856 *start_offset = gtk_text_iter_get_offset (&start);
7857 *end_offset = gtk_text_iter_get_offset (&end);
7859 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7863 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7865 GtkIconViewItemAccessible *item;
7867 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7869 if (!GTK_IS_ICON_VIEW (item->widget))
7872 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7875 return gtk_text_buffer_get_char_count (item->text_buffer);
7879 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7885 AtkCoordType coord_type)
7887 GtkIconViewItemAccessible *item;
7889 GtkIconView *icon_view;
7890 PangoRectangle char_rect;
7891 const gchar *item_text;
7895 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7897 if (!GTK_IS_ICON_VIEW (item->widget))
7900 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7904 icon_view = GTK_ICON_VIEW (item->widget);
7905 /* FIXME we probably have to use GailTextCell to salvage this */
7906 gtk_icon_view_update_item_text (icon_view, item->item);
7907 item_text = pango_layout_get_text (icon_view->priv->layout);
7908 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7909 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7911 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7912 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7913 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7914 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7915 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7916 *width = char_rect.width / PANGO_SCALE;
7917 *height = char_rect.height / PANGO_SCALE;
7922 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7925 AtkCoordType coord_type)
7927 GtkIconViewItemAccessible *item;
7930 GtkIconView *icon_view;
7931 const gchar *item_text;
7936 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7938 if (!GTK_IS_ICON_VIEW (item->widget))
7941 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7945 icon_view = GTK_ICON_VIEW (item->widget);
7946 /* FIXME we probably have to use GailTextCell to salvage this */
7947 gtk_icon_view_update_item_text (icon_view, item->item);
7948 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7949 x -= l_x + item->item->layout_x - item->item->x;
7950 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7951 y -= l_y + item->item->layout_y - item->item->y;
7952 item_text = pango_layout_get_text (icon_view->priv->layout);
7953 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7964 offset = g_utf8_strlen (item_text, -1);
7966 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7972 atk_text_item_interface_init (AtkTextIface *iface)
7974 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7975 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7976 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7977 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7978 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7979 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7980 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7981 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7985 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7990 AtkCoordType coord_type)
7992 GtkIconViewItemAccessible *item;
7993 AtkObject *parent_obj;
7996 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7998 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7999 if (!GTK_IS_WIDGET (item->widget))
8002 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8005 *width = item->item->cell_area.width;
8006 *height = item->item->cell_area.height;
8007 if (gtk_icon_view_item_accessible_is_showing (item))
8009 parent_obj = gtk_widget_get_accessible (item->widget);
8010 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8011 *x = l_x + item->item->cell_area.x;
8012 *y = l_y + item->item->cell_area.y;
8022 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8024 GtkIconViewItemAccessible *item;
8025 GtkWidget *toplevel;
8027 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8029 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8030 if (!GTK_IS_WIDGET (item->widget))
8033 gtk_widget_grab_focus (item->widget);
8034 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
8035 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8036 if (gtk_widget_is_toplevel (toplevel))
8037 gtk_window_present (GTK_WINDOW (toplevel));
8043 atk_component_item_interface_init (AtkComponentIface *iface)
8045 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8046 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8050 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8051 AtkStateType state_type,
8052 gboolean emit_signal)
8056 rc = atk_state_set_add_state (item->state_set, state_type);
8058 * The signal should only be generated if the value changed,
8059 * not when the item is set up. So states that are set
8060 * initially should pass FALSE as the emit_signal argument.
8065 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8066 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8067 if (state_type == ATK_STATE_VISIBLE)
8068 g_signal_emit_by_name (item, "visible-data-changed");
8075 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8076 AtkStateType state_type,
8077 gboolean emit_signal)
8079 if (atk_state_set_contains_state (item->state_set, state_type))
8083 rc = atk_state_set_remove_state (item->state_set, state_type);
8085 * The signal should only be generated if the value changed,
8086 * not when the item is set up. So states that are set
8087 * initially should pass FALSE as the emit_signal argument.
8092 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8093 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8094 if (state_type == ATK_STATE_VISIBLE)
8095 g_signal_emit_by_name (item, "visible-data-changed");
8105 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8107 GtkAllocation allocation;
8108 GtkIconView *icon_view;
8109 GdkRectangle visible_rect;
8110 gboolean is_showing;
8113 * An item is considered "SHOWING" if any part of the item is in the
8114 * visible rectangle.
8117 if (!GTK_IS_ICON_VIEW (item->widget))
8120 if (item->item == NULL)
8123 gtk_widget_get_allocation (item->widget, &allocation);
8125 icon_view = GTK_ICON_VIEW (item->widget);
8127 if (icon_view->priv->hadjustment)
8128 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8130 if (icon_view->priv->hadjustment)
8131 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8132 visible_rect.width = allocation.width;
8133 visible_rect.height = allocation.height;
8135 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8136 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8137 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8138 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8147 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8148 gboolean emit_signal)
8150 if (gtk_icon_view_item_accessible_is_showing (item))
8151 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8154 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8159 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8163 item->state_set = atk_state_set_new ();
8165 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8166 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8167 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8168 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8169 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8171 for (i = 0; i < LAST_ACTION; i++)
8172 item->action_descriptions[i] = NULL;
8174 item->image_description = NULL;
8176 item->action_idle_handler = 0;
8180 gtk_icon_view_item_accessible_finalize (GObject *object)
8182 GtkIconViewItemAccessible *item;
8185 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8187 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8190 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8192 if (item->state_set)
8193 g_object_unref (item->state_set);
8195 if (item->text_buffer)
8196 g_object_unref (item->text_buffer);
8198 for (i = 0; i < LAST_ACTION; i++)
8199 g_free (item->action_descriptions[i]);
8201 g_free (item->image_description);
8203 if (item->action_idle_handler)
8205 g_source_remove (item->action_idle_handler);
8206 item->action_idle_handler = 0;
8209 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8213 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8215 GtkIconViewItemAccessible *item;
8217 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8218 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8221 return gtk_widget_get_accessible (item->widget);
8227 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8229 GtkIconViewItemAccessible *item;
8231 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8232 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8234 return item->item->index;
8237 static AtkStateSet *
8238 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8240 GtkIconViewItemAccessible *item;
8241 GtkIconView *icon_view;
8243 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8244 g_return_val_if_fail (item->state_set, NULL);
8249 icon_view = GTK_ICON_VIEW (item->widget);
8250 if (icon_view->priv->cursor_item == item->item)
8251 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8253 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8254 if (item->item->selected)
8255 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8257 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8259 return g_object_ref (item->state_set);
8263 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8265 GObjectClass *gobject_class;
8267 accessible_item_parent_class = g_type_class_peek_parent (klass);
8269 gobject_class = (GObjectClass *)klass;
8271 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8273 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8274 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8275 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8279 gtk_icon_view_item_accessible_get_type (void)
8281 static GType type = 0;
8285 const GTypeInfo tinfo =
8287 sizeof (GtkIconViewItemAccessibleClass),
8288 (GBaseInitFunc) NULL, /* base init */
8289 (GBaseFinalizeFunc) NULL, /* base finalize */
8290 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8291 (GClassFinalizeFunc) NULL, /* class finalize */
8292 NULL, /* class data */
8293 sizeof (GtkIconViewItemAccessible), /* instance size */
8294 0, /* nb preallocs */
8295 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8296 NULL /* value table */
8299 const GInterfaceInfo atk_component_info =
8301 (GInterfaceInitFunc) atk_component_item_interface_init,
8302 (GInterfaceFinalizeFunc) NULL,
8305 const GInterfaceInfo atk_action_info =
8307 (GInterfaceInitFunc) atk_action_item_interface_init,
8308 (GInterfaceFinalizeFunc) NULL,
8311 const GInterfaceInfo atk_image_info =
8313 (GInterfaceInitFunc) atk_image_item_interface_init,
8314 (GInterfaceFinalizeFunc) NULL,
8317 const GInterfaceInfo atk_text_info =
8319 (GInterfaceInitFunc) atk_text_item_interface_init,
8320 (GInterfaceFinalizeFunc) NULL,
8324 type = g_type_register_static (ATK_TYPE_OBJECT,
8325 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8326 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8327 &atk_component_info);
8328 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8330 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8332 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8339 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8340 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8341 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8343 static GType gtk_icon_view_accessible_get_type (void);
8348 } GtkIconViewAccessible;
8354 } GtkIconViewItemAccessibleInfo;
8360 GtkAdjustment *old_hadj;
8361 GtkAdjustment *old_vadj;
8363 GtkTreeModel *model;
8365 } GtkIconViewAccessiblePrivate;
8367 static GtkIconViewAccessiblePrivate *
8368 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8370 return g_object_get_qdata (G_OBJECT (accessible),
8371 accessible_private_data_quark);
8375 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8379 GtkIconViewItemAccessibleInfo *info;
8380 GtkIconViewItemAccessibleInfo *tmp_info;
8381 GtkIconViewAccessiblePrivate *priv;
8384 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8386 info->index = index;
8388 priv = gtk_icon_view_accessible_get_priv (accessible);
8389 items = priv->items;
8392 tmp_info = items->data;
8393 if (tmp_info->index > index)
8395 items = items->next;
8397 priv->items = g_list_insert_before (priv->items, items, info);
8398 priv->old_hadj = NULL;
8399 priv->old_vadj = NULL;
8403 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8405 GtkIconView *icon_view;
8408 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8412 icon_view = GTK_ICON_VIEW (widget);
8414 return g_list_length (icon_view->priv->items);
8418 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8421 GtkIconViewAccessiblePrivate *priv;
8422 GtkIconViewItemAccessibleInfo *info;
8425 priv = gtk_icon_view_accessible_get_priv (accessible);
8426 items = priv->items;
8431 if (info->index == index)
8433 items = items->next;
8439 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8442 GtkIconView *icon_view;
8446 GtkIconViewItemAccessible *a11y_item;
8448 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8452 icon_view = GTK_ICON_VIEW (widget);
8453 icons = g_list_nth (icon_view->priv->items, index);
8457 GtkIconViewItem *item = icons->data;
8459 g_return_val_if_fail (item->index == index, NULL);
8460 obj = gtk_icon_view_accessible_find_child (accessible, index);
8465 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8466 gtk_icon_view_item_accessible_info_new (accessible,
8469 obj->role = ATK_ROLE_ICON;
8470 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8471 a11y_item->item = item;
8472 a11y_item->widget = widget;
8473 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8475 text = get_text (icon_view, item);
8478 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8482 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8483 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8491 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8494 GtkIconViewAccessiblePrivate *priv;
8495 GtkIconViewItemAccessibleInfo *info;
8496 GtkIconViewItemAccessible *item;
8499 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8503 gboolean act_on_item;
8505 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8509 items = priv->items;
8511 act_on_item = (list == NULL);
8516 info = (GtkIconViewItemAccessibleInfo *)items->data;
8517 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8519 if (act_on_item == FALSE && list == items)
8523 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8525 items = items->next;
8531 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8532 GtkIconViewAccessible *view)
8534 gtk_icon_view_accessible_traverse_items (view, NULL);
8538 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8539 GtkOrientation orientation,
8540 GtkAdjustment *adjustment)
8542 GtkIconViewAccessiblePrivate *priv;
8543 GtkAdjustment **old_adj_ptr;
8545 priv = gtk_icon_view_accessible_get_priv (accessible);
8547 /* Adjustments are set for the first time in constructor and priv is not
8548 * initialized at that time, so skip this first setting. */
8552 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8554 if (priv->old_hadj == adjustment)
8557 old_adj_ptr = &priv->old_hadj;
8561 if (priv->old_vadj == adjustment)
8564 old_adj_ptr = &priv->old_vadj;
8567 /* Disconnect signal handlers */
8570 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8571 (gpointer *)&priv->old_hadj);
8572 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8573 gtk_icon_view_accessible_adjustment_changed,
8577 /* Connect signal */
8578 *old_adj_ptr = adjustment;
8579 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8580 g_signal_connect (adjustment, "value-changed",
8581 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8586 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8594 GtkIconView *icon_view;
8595 GtkIconViewItem *item;
8596 GtkIconViewItemAccessible *a11y_item;
8600 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8601 index = gtk_tree_path_get_indices(path)[0];
8602 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8603 gtk_icon_view_accessible_find_child (atk_obj, index));
8607 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8608 icon_view = GTK_ICON_VIEW (widget);
8609 item = a11y_item->item;
8611 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8613 if (!name || strcmp (name, "") == 0)
8615 text = get_text (icon_view, item);
8618 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8624 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8630 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8635 GtkIconViewAccessiblePrivate *priv;
8636 GtkIconViewItemAccessibleInfo *info;
8637 GtkIconViewAccessible *view;
8638 GtkIconViewItemAccessible *item;
8644 index = gtk_tree_path_get_indices(path)[0];
8645 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8646 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8647 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8649 items = priv->items;
8654 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8655 if (info->index != item->item->index)
8657 if (info->index < index)
8658 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8660 if (tmp_list == NULL)
8663 info->index = item->item->index;
8666 items = items->next;
8668 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8669 g_signal_emit_by_name (atk_obj, "children-changed::add",
8675 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8679 GtkIconViewAccessiblePrivate *priv;
8680 GtkIconViewItemAccessibleInfo *info;
8681 GtkIconViewAccessible *view;
8682 GtkIconViewItemAccessible *item;
8685 GList *deleted_item;
8689 index = gtk_tree_path_get_indices(path)[0];
8690 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8691 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8692 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8694 items = priv->items;
8696 deleted_item = NULL;
8701 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8702 if (info->index == index)
8704 deleted_item = items;
8706 if (info->index != item->item->index)
8708 if (tmp_list == NULL)
8711 info->index = item->item->index;
8714 items = items->next;
8716 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8719 info = deleted_item->data;
8720 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8721 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8723 priv->items = g_list_remove_link (priv->items, deleted_item);
8731 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8732 GtkIconViewItemAccessibleInfo *i2)
8734 return i1->index - i2->index;
8738 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8744 GtkIconViewAccessiblePrivate *priv;
8745 GtkIconViewItemAccessibleInfo *info;
8746 GtkIconView *icon_view;
8747 GtkIconViewItemAccessible *item;
8753 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8754 icon_view = GTK_ICON_VIEW (user_data);
8755 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8757 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8759 order = g_new (gint, length);
8760 for (i = 0; i < length; i++)
8761 order [new_order[i]] = i;
8763 items = priv->items;
8767 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8768 info->index = order[info->index];
8769 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8770 items = items->next;
8773 priv->items = g_list_sort (priv->items,
8774 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8780 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8785 obj = G_OBJECT (model);
8786 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8787 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8788 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8789 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8793 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8797 obj = G_OBJECT (icon_view->priv->model);
8798 g_signal_connect_data (obj, "row-changed",
8799 (GCallback) gtk_icon_view_accessible_model_row_changed,
8800 icon_view, NULL, 0);
8801 g_signal_connect_data (obj, "row-inserted",
8802 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8803 icon_view, NULL, G_CONNECT_AFTER);
8804 g_signal_connect_data (obj, "row-deleted",
8805 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8806 icon_view, NULL, G_CONNECT_AFTER);
8807 g_signal_connect_data (obj, "rows-reordered",
8808 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8809 icon_view, NULL, G_CONNECT_AFTER);
8813 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8815 GtkIconViewItemAccessibleInfo *info;
8818 items = priv->items;
8821 info = (GtkIconViewItemAccessibleInfo *) items->data;
8822 g_object_unref (info->item);
8823 g_free (items->data);
8824 items = items->next;
8826 g_list_free (priv->items);
8831 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8834 GtkIconView *icon_view;
8837 GtkIconViewAccessiblePrivate *priv;
8839 if (strcmp (pspec->name, "model") == 0)
8841 widget = GTK_WIDGET (obj);
8842 atk_obj = gtk_widget_get_accessible (widget);
8843 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8846 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8847 (gpointer *)&priv->model);
8848 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8850 gtk_icon_view_accessible_clear_cache (priv);
8852 icon_view = GTK_ICON_VIEW (obj);
8853 priv->model = icon_view->priv->model;
8854 /* If there is no model the GtkIconView is probably being destroyed */
8857 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8858 gtk_icon_view_accessible_connect_model_signals (icon_view);
8866 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8869 GtkIconViewAccessiblePrivate *priv;
8870 GtkIconView *icon_view;
8872 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8873 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8875 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8876 g_object_set_qdata (G_OBJECT (accessible),
8877 accessible_private_data_quark,
8880 icon_view = GTK_ICON_VIEW (data);
8881 if (icon_view->priv->hadjustment)
8882 gtk_icon_view_accessible_set_adjustment (accessible,
8883 GTK_ORIENTATION_HORIZONTAL,
8884 icon_view->priv->hadjustment);
8885 if (icon_view->priv->vadjustment)
8886 gtk_icon_view_accessible_set_adjustment (accessible,
8887 GTK_ORIENTATION_VERTICAL,
8888 icon_view->priv->vadjustment);
8889 g_signal_connect (data,
8891 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8894 priv->model = icon_view->priv->model;
8897 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8898 gtk_icon_view_accessible_connect_model_signals (icon_view);
8901 accessible->role = ATK_ROLE_LAYERED_PANE;
8905 gtk_icon_view_accessible_finalize (GObject *object)
8907 GtkIconViewAccessiblePrivate *priv;
8909 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8910 gtk_icon_view_accessible_clear_cache (priv);
8914 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8918 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8919 GtkAccessible *accessible)
8922 GtkIconViewAccessiblePrivate *priv;
8924 atk_obj = ATK_OBJECT (accessible);
8925 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8928 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8929 (gpointer *)&priv->old_hadj);
8931 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8932 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8934 priv->old_hadj = NULL;
8938 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8939 (gpointer *)&priv->old_vadj);
8941 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8942 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8944 priv->old_vadj = NULL;
8949 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8953 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8956 g_signal_connect_after (widget,
8958 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8961 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8965 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8967 GObjectClass *gobject_class;
8968 GtkAccessibleClass *accessible_class;
8970 accessible_parent_class = g_type_class_peek_parent (klass);
8972 gobject_class = (GObjectClass *)klass;
8973 accessible_class = (GtkAccessibleClass *)klass;
8975 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8977 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8978 klass->ref_child = gtk_icon_view_accessible_ref_child;
8979 klass->initialize = gtk_icon_view_accessible_initialize;
8981 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8983 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8987 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8990 AtkCoordType coord_type)
8993 GtkIconView *icon_view;
8994 GtkIconViewItem *item;
8997 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
8999 /* State is defunct */
9002 icon_view = GTK_ICON_VIEW (widget);
9003 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9004 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9006 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9012 atk_component_interface_init (AtkComponentIface *iface)
9014 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9018 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9022 GtkIconView *icon_view;
9023 GtkIconViewItem *item;
9025 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9029 icon_view = GTK_ICON_VIEW (widget);
9031 item = g_list_nth_data (icon_view->priv->items, i);
9036 gtk_icon_view_select_item (icon_view, item);
9042 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9045 GtkIconView *icon_view;
9047 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9051 icon_view = GTK_ICON_VIEW (widget);
9052 gtk_icon_view_unselect_all (icon_view);
9058 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9063 GtkIconView *icon_view;
9064 GtkIconViewItem *item;
9066 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9070 icon_view = GTK_ICON_VIEW (widget);
9072 l = icon_view->priv->items;
9079 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9090 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9093 GtkIconView *icon_view;
9094 GtkIconViewItem *item;
9098 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9102 icon_view = GTK_ICON_VIEW (widget);
9104 l = icon_view->priv->items;
9120 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9124 GtkIconView *icon_view;
9125 GtkIconViewItem *item;
9127 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9131 icon_view = GTK_ICON_VIEW (widget);
9133 item = g_list_nth_data (icon_view->priv->items, i);
9137 return item->selected;
9141 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9145 GtkIconView *icon_view;
9146 GtkIconViewItem *item;
9150 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9154 icon_view = GTK_ICON_VIEW (widget);
9155 l = icon_view->priv->items;
9164 gtk_icon_view_unselect_item (icon_view, item);
9176 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9179 GtkIconView *icon_view;
9181 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9185 icon_view = GTK_ICON_VIEW (widget);
9186 gtk_icon_view_select_all (icon_view);
9191 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9193 iface->add_selection = gtk_icon_view_accessible_add_selection;
9194 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9195 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9196 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9197 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9198 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9199 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9203 gtk_icon_view_accessible_get_type (void)
9205 static GType type = 0;
9212 (GBaseInitFunc) NULL, /* base init */
9213 (GBaseFinalizeFunc) NULL, /* base finalize */
9214 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9215 (GClassFinalizeFunc) NULL, /* class finalize */
9216 NULL, /* class data */
9217 0, /* instance size */
9218 0, /* nb preallocs */
9219 (GInstanceInitFunc) NULL, /* instance init */
9220 NULL /* value table */
9222 const GInterfaceInfo atk_component_info =
9224 (GInterfaceInitFunc) atk_component_interface_init,
9225 (GInterfaceFinalizeFunc) NULL,
9228 const GInterfaceInfo atk_selection_info =
9230 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9231 (GInterfaceFinalizeFunc) NULL,
9236 * Figure out the size of the class and instance
9237 * we are deriving from
9239 AtkObjectFactory *factory;
9242 GType derived_atk_type;
9244 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9245 factory = atk_registry_get_factory (atk_get_default_registry (),
9247 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9248 g_type_query (derived_atk_type, &query);
9249 tinfo.class_size = query.class_size;
9250 tinfo.instance_size = query.instance_size;
9252 type = g_type_register_static (derived_atk_type,
9253 I_("GtkIconViewAccessible"),
9255 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9256 &atk_component_info);
9257 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9258 &atk_selection_info);
9264 gtk_icon_view_accessible_new (GObject *obj)
9266 AtkObject *accessible;
9268 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9270 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9271 atk_object_initialize (accessible, obj);
9277 gtk_icon_view_accessible_factory_get_accessible_type (void)
9279 return gtk_icon_view_accessible_get_type ();
9283 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9285 return gtk_icon_view_accessible_new (obj);
9289 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9291 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9292 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9296 gtk_icon_view_accessible_factory_get_type (void)
9298 static GType type = 0;
9302 const GTypeInfo tinfo =
9304 sizeof (AtkObjectFactoryClass),
9305 NULL, /* base_init */
9306 NULL, /* base_finalize */
9307 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9308 NULL, /* class_finalize */
9309 NULL, /* class_data */
9310 sizeof (AtkObjectFactory),
9311 0, /* n_preallocs */
9315 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9316 I_("GtkIconViewAccessibleFactory"),
9324 gtk_icon_view_get_accessible (GtkWidget *widget)
9326 static gboolean first_time = TRUE;
9330 _gtk_accessible_set_factory_type (GTK_TYPE_ICON_VIEW,
9331 gtk_icon_view_accessible_factory_get_type ());
9334 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9338 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9339 GtkBuilder *builder,
9341 const gchar *tagname,
9342 GMarkupParser *parser,
9345 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9346 tagname, parser, data))
9349 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9350 tagname, parser, data);
9354 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9355 GtkBuilder *builder,
9357 const gchar *tagname,
9360 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9361 child, tagname, data))
9362 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,