2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 #include "gtkaccessibleprivate.h"
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellareabox.h"
31 #include "gtkcellareacontext.h"
32 #include "gtkcellrenderertext.h"
33 #include "gtkcellrendererpixbuf.h"
34 #include "gtkorientable.h"
35 #include "gtkmarshalers.h"
36 #include "gtkbindings.h"
40 #include "gtkaccessible.h"
41 #include "gtkwindow.h"
43 #include "gtkcombobox.h"
44 #include "gtktextbuffer.h"
45 #include "gtkscrollable.h"
46 #include "gtksizerequest.h"
47 #include "gtktreednd.h"
48 #include "gtktypebuiltins.h"
49 #include "gtkprivate.h"
50 #include "a11y/gtkcontaineraccessible.h"
55 * @short_description: A widget which displays a list of icons in a grid
57 * #GtkIconView provides an alternative view on a #GtkTreeModel.
58 * It displays the model as a grid of icons with labels. Like
59 * #GtkTreeView, it allows to select one or multiple items
60 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
61 * In addition to selection with the arrow keys, #GtkIconView supports
62 * rubberband selection, which is controlled by dragging the pointer.
64 * Note that if the tree model is backed by an actual tree store (as
65 * opposed to a flat list where the mapping to icons is obvious),
66 * #GtkIconView will only display the first level of the tree and
67 * ignore the tree's branches.
70 #define SCROLL_EDGE_SIZE 15
72 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
74 typedef struct _GtkIconViewItem GtkIconViewItem;
75 struct _GtkIconViewItem
77 /* First member is always the rectangle so it
78 * can be cast to a rectangle. */
79 GdkRectangle cell_area;
87 guint selected_before_rubberbanding : 1;
91 typedef struct _GtkIconViewChild GtkIconViewChild;
92 struct _GtkIconViewChild
98 struct _GtkIconViewPrivate
100 GtkCellArea *cell_area;
101 GtkCellAreaContext *cell_area_context;
103 gulong add_editable_id;
104 gulong remove_editable_id;
105 gulong context_changed_id;
107 GPtrArray *row_contexts;
111 GtkSelectionMode selection_mode;
113 guint layout_idle_id;
115 GdkWindow *bin_window;
123 GtkAdjustment *hadjustment;
124 GtkAdjustment *vadjustment;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
128 GdkDevice *rubberband_device;
130 guint scroll_timeout_id;
131 gint scroll_value_diff;
132 gint event_last_x, event_last_y;
134 GtkIconViewItem *anchor_item;
135 GtkIconViewItem *cursor_item;
137 GtkIconViewItem *last_single_clicked;
139 GtkOrientation item_orientation;
154 GtkCellRenderer *pixbuf_cell;
155 GtkCellRenderer *text_cell;
158 GdkModifierType start_button_mask;
163 GdkDragAction source_actions;
164 GdkDragAction dest_actions;
166 GtkTreeRowReference *dest_item;
167 GtkIconViewDropPosition dest_pos;
170 GtkTreeRowReference *scroll_to_path;
171 gfloat scroll_to_row_align;
172 gfloat scroll_to_col_align;
173 guint scroll_to_use_align : 1;
175 guint source_set : 1;
177 guint reorderable : 1;
178 guint empty_view_drop :1;
180 guint ctrl_pressed : 1;
181 guint shift_pressed : 1;
183 guint draw_focus : 1;
185 /* GtkScrollablePolicy needs to be checked when
186 * driving the scrollable adjustment values */
187 guint hscroll_policy : 1;
188 guint vscroll_policy : 1;
190 guint doing_rubberband : 1;
204 ACTIVATE_CURSOR_ITEM,
216 PROP_ITEM_ORIENTATION,
229 /* For scrollable interface */
237 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
238 static void gtk_icon_view_dispose (GObject *object);
239 static GObject *gtk_icon_view_constructor (GType type,
240 guint n_construct_properties,
241 GObjectConstructParam *construct_properties);
242 static void gtk_icon_view_set_property (GObject *object,
246 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkWidget vfuncs */
251 static void gtk_icon_view_destroy (GtkWidget *widget);
252 static void gtk_icon_view_realize (GtkWidget *widget);
253 static void gtk_icon_view_unrealize (GtkWidget *widget);
254 static void gtk_icon_view_style_updated (GtkWidget *widget);
255 static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
256 GtkStateFlags previous_state);
257 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
260 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
263 static void gtk_icon_view_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static gboolean gtk_icon_view_draw (GtkWidget *widget,
267 static gboolean gtk_icon_view_motion (GtkWidget *widget,
268 GdkEventMotion *event);
269 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
270 GdkEventButton *event);
271 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
272 GdkEventButton *event);
273 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
275 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
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,
451 static GType gtk_icon_view_accessible_get_type (void);
453 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
455 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
457 gtk_icon_view_cell_layout_init)
458 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
459 gtk_icon_view_buildable_init)
460 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
463 gtk_icon_view_class_init (GtkIconViewClass *klass)
465 GObjectClass *gobject_class;
466 GtkWidgetClass *widget_class;
467 GtkContainerClass *container_class;
468 GtkBindingSet *binding_set;
470 binding_set = gtk_binding_set_by_class (klass);
472 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
474 gobject_class = (GObjectClass *) klass;
475 widget_class = (GtkWidgetClass *) klass;
476 container_class = (GtkContainerClass *) klass;
478 gobject_class->constructor = gtk_icon_view_constructor;
479 gobject_class->dispose = gtk_icon_view_dispose;
480 gobject_class->set_property = gtk_icon_view_set_property;
481 gobject_class->get_property = gtk_icon_view_get_property;
483 widget_class->destroy = gtk_icon_view_destroy;
484 widget_class->realize = gtk_icon_view_realize;
485 widget_class->unrealize = gtk_icon_view_unrealize;
486 widget_class->style_updated = gtk_icon_view_style_updated;
487 widget_class->get_accessible = gtk_icon_view_get_accessible;
488 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
489 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
490 widget_class->size_allocate = gtk_icon_view_size_allocate;
491 widget_class->draw = gtk_icon_view_draw;
492 widget_class->motion_notify_event = gtk_icon_view_motion;
493 widget_class->button_press_event = gtk_icon_view_button_press;
494 widget_class->button_release_event = gtk_icon_view_button_release;
495 widget_class->key_press_event = gtk_icon_view_key_press;
496 widget_class->key_release_event = gtk_icon_view_key_release;
497 widget_class->drag_begin = gtk_icon_view_drag_begin;
498 widget_class->drag_end = gtk_icon_view_drag_end;
499 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
500 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
501 widget_class->drag_leave = gtk_icon_view_drag_leave;
502 widget_class->drag_motion = gtk_icon_view_drag_motion;
503 widget_class->drag_drop = gtk_icon_view_drag_drop;
504 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
505 widget_class->state_flags_changed = gtk_icon_view_state_flags_changed;
507 container_class->remove = gtk_icon_view_remove;
508 container_class->forall = gtk_icon_view_forall;
510 klass->select_all = gtk_icon_view_real_select_all;
511 klass->unselect_all = gtk_icon_view_real_unselect_all;
512 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
513 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
514 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
515 klass->move_cursor = gtk_icon_view_real_move_cursor;
519 * GtkIconView:selection-mode:
521 * The ::selection-mode property specifies the selection mode of
522 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
523 * is enabled, for the other modes, only keyboard selection is possible.
527 g_object_class_install_property (gobject_class,
529 g_param_spec_enum ("selection-mode",
530 P_("Selection mode"),
531 P_("The selection mode"),
532 GTK_TYPE_SELECTION_MODE,
533 GTK_SELECTION_SINGLE,
534 GTK_PARAM_READWRITE));
537 * GtkIconView:pixbuf-column:
539 * The ::pixbuf-column property contains the number of the model column
540 * containing the pixbufs which are displayed. The pixbuf column must be
541 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
542 * display of pixbufs.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_int ("pixbuf-column",
550 P_("Model column used to retrieve the icon pixbuf from"),
552 GTK_PARAM_READWRITE));
555 * GtkIconView:text-column:
557 * The ::text-column property contains the number of the model column
558 * containing the texts which are displayed. The text column must be
559 * of type #G_TYPE_STRING. If this property and the :markup-column
560 * property are both set to -1, no texts are displayed.
564 g_object_class_install_property (gobject_class,
566 g_param_spec_int ("text-column",
568 P_("Model column used to retrieve the text from"),
570 GTK_PARAM_READWRITE));
574 * GtkIconView:markup-column:
576 * The ::markup-column property contains the number of the model column
577 * containing markup information to be displayed. The markup column must be
578 * of type #G_TYPE_STRING. If this property and the :text-column property
579 * are both set to column numbers, it overrides the text column.
580 * If both are set to -1, no texts are displayed.
584 g_object_class_install_property (gobject_class,
586 g_param_spec_int ("markup-column",
588 P_("Model column used to retrieve the text if using Pango markup"),
590 GTK_PARAM_READWRITE));
592 g_object_class_install_property (gobject_class,
594 g_param_spec_object ("model",
595 P_("Icon View Model"),
596 P_("The model for the icon view"),
598 GTK_PARAM_READWRITE));
601 * GtkIconView:columns:
603 * The columns property contains the number of the columns in which the
604 * items should be displayed. If it is -1, the number of columns will
605 * be chosen automatically to fill the available area.
609 g_object_class_install_property (gobject_class,
611 g_param_spec_int ("columns",
612 P_("Number of columns"),
613 P_("Number of columns to display"),
615 GTK_PARAM_READWRITE));
619 * GtkIconView:item-width:
621 * The item-width property specifies the width to use for each item.
622 * If it is set to -1, the icon view will automatically determine a
623 * suitable item size.
627 g_object_class_install_property (gobject_class,
629 g_param_spec_int ("item-width",
630 P_("Width for each item"),
631 P_("The width used for each item"),
633 GTK_PARAM_READWRITE));
636 * GtkIconView:spacing:
638 * The spacing property specifies the space which is inserted between
639 * the cells (i.e. the icon and the text) of an item.
643 g_object_class_install_property (gobject_class,
645 g_param_spec_int ("spacing",
647 P_("Space which is inserted between cells of an item"),
649 GTK_PARAM_READWRITE));
652 * GtkIconView:row-spacing:
654 * The row-spacing property specifies the space which is inserted between
655 * the rows of the icon view.
659 g_object_class_install_property (gobject_class,
661 g_param_spec_int ("row-spacing",
663 P_("Space which is inserted between grid rows"),
665 GTK_PARAM_READWRITE));
668 * GtkIconView:column-spacing:
670 * The column-spacing property specifies the space which is inserted between
671 * the columns of the icon view.
675 g_object_class_install_property (gobject_class,
677 g_param_spec_int ("column-spacing",
678 P_("Column Spacing"),
679 P_("Space which is inserted between grid columns"),
681 GTK_PARAM_READWRITE));
684 * GtkIconView:margin:
686 * The margin property specifies the space which is inserted
687 * at the edges of the icon view.
691 g_object_class_install_property (gobject_class,
693 g_param_spec_int ("margin",
695 P_("Space which is inserted at the edges of the icon view"),
697 GTK_PARAM_READWRITE));
700 * GtkIconView:item-orientation:
702 * The item-orientation property specifies how the cells (i.e. the icon and
703 * the text) of the item are positioned relative to each other.
707 g_object_class_install_property (gobject_class,
708 PROP_ITEM_ORIENTATION,
709 g_param_spec_enum ("item-orientation",
710 P_("Item Orientation"),
711 P_("How the text and icon of each item are positioned relative to each other"),
712 GTK_TYPE_ORIENTATION,
713 GTK_ORIENTATION_VERTICAL,
714 GTK_PARAM_READWRITE));
717 * GtkIconView:reorderable:
719 * The reorderable property specifies if the items can be reordered
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("reorderable",
728 P_("View is reorderable"),
732 g_object_class_install_property (gobject_class,
734 g_param_spec_int ("tooltip-column",
735 P_("Tooltip Column"),
736 P_("The column in the model containing the tooltip texts for the items"),
740 GTK_PARAM_READWRITE));
743 * GtkIconView:item-padding:
745 * The item-padding property specifies the padding around each
746 * of the icon view's item.
750 g_object_class_install_property (gobject_class,
752 g_param_spec_int ("item-padding",
754 P_("Padding around icon view items"),
756 GTK_PARAM_READWRITE));
759 * GtkIconView:cell-area:
761 * The #GtkCellArea used to layout cell renderers for this view.
763 * If no area is specified when creating the icon view with gtk_icon_view_new_with_area()
764 * a #GtkCellAreaBox will be used.
768 g_object_class_install_property (gobject_class,
770 g_param_spec_object ("cell-area",
772 P_("The GtkCellArea used to layout cells"),
774 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
776 /* Scrollable interface properties */
777 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
778 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
779 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
780 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
782 /* Style properties */
783 gtk_widget_class_install_style_property (widget_class,
784 g_param_spec_boxed ("selection-box-color",
785 P_("Selection Box Color"),
786 P_("Color of the selection box"),
788 GTK_PARAM_READABLE));
790 gtk_widget_class_install_style_property (widget_class,
791 g_param_spec_uchar ("selection-box-alpha",
792 P_("Selection Box Alpha"),
793 P_("Opacity of the selection box"),
796 GTK_PARAM_READABLE));
800 * GtkIconView::item-activated:
801 * @iconview: the object on which the signal is emitted
802 * @path: the #GtkTreePath for the activated item
804 * The ::item-activated signal is emitted when the method
805 * gtk_icon_view_item_activated() is called or the user double
806 * clicks an item. It is also emitted when a non-editable item
807 * is selected and one of the keys: Space, Return or Enter is
810 icon_view_signals[ITEM_ACTIVATED] =
811 g_signal_new (I_("item-activated"),
812 G_TYPE_FROM_CLASS (gobject_class),
814 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
816 g_cclosure_marshal_VOID__BOXED,
821 * GtkIconView::selection-changed:
822 * @iconview: the object on which the signal is emitted
824 * The ::selection-changed signal is emitted when the selection
825 * (i.e. the set of selected items) changes.
827 icon_view_signals[SELECTION_CHANGED] =
828 g_signal_new (I_("selection-changed"),
829 G_TYPE_FROM_CLASS (gobject_class),
831 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
833 g_cclosure_marshal_VOID__VOID,
837 * GtkIconView::select-all:
838 * @iconview: the object on which the signal is emitted
840 * A <link linkend="keybinding-signals">keybinding signal</link>
841 * which gets emitted when the user selects all items.
843 * Applications should not connect to it, but may emit it with
844 * g_signal_emit_by_name() if they need to control selection
847 * The default binding for this signal is Ctrl-a.
849 icon_view_signals[SELECT_ALL] =
850 g_signal_new (I_("select-all"),
851 G_TYPE_FROM_CLASS (gobject_class),
852 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
853 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
855 g_cclosure_marshal_VOID__VOID,
859 * GtkIconView::unselect-all:
860 * @iconview: the object on which the signal is emitted
862 * A <link linkend="keybinding-signals">keybinding signal</link>
863 * which gets emitted when the user unselects all items.
865 * Applications should not connect to it, but may emit it with
866 * g_signal_emit_by_name() if they need to control selection
869 * The default binding for this signal is Ctrl-Shift-a.
871 icon_view_signals[UNSELECT_ALL] =
872 g_signal_new (I_("unselect-all"),
873 G_TYPE_FROM_CLASS (gobject_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
877 g_cclosure_marshal_VOID__VOID,
881 * GtkIconView::select-cursor-item:
882 * @iconview: the object on which the signal is emitted
884 * A <link linkend="keybinding-signals">keybinding signal</link>
885 * which gets emitted when the user selects the item that is currently
888 * Applications should not connect to it, but may emit it with
889 * g_signal_emit_by_name() if they need to control selection
892 * There is no default binding for this signal.
894 icon_view_signals[SELECT_CURSOR_ITEM] =
895 g_signal_new (I_("select-cursor-item"),
896 G_TYPE_FROM_CLASS (gobject_class),
897 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
898 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
900 g_cclosure_marshal_VOID__VOID,
904 * GtkIconView::toggle-cursor-item:
905 * @iconview: the object on which the signal is emitted
907 * A <link linkend="keybinding-signals">keybinding signal</link>
908 * which gets emitted when the user toggles whether the currently
909 * focused item is selected or not. The exact effect of this
910 * depend on the selection mode.
912 * Applications should not connect to it, but may emit it with
913 * g_signal_emit_by_name() if they need to control selection
916 * There is no default binding for this signal is Ctrl-Space.
918 icon_view_signals[TOGGLE_CURSOR_ITEM] =
919 g_signal_new (I_("toggle-cursor-item"),
920 G_TYPE_FROM_CLASS (gobject_class),
921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
924 g_cclosure_marshal_VOID__VOID,
928 * GtkIconView::activate-cursor-item:
929 * @iconview: the object on which the signal is emitted
931 * A <link linkend="keybinding-signals">keybinding signal</link>
932 * which gets emitted when the user activates the currently
935 * Applications should not connect to it, but may emit it with
936 * g_signal_emit_by_name() if they need to control activation
939 * The default bindings for this signal are Space, Return and Enter.
941 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
942 g_signal_new (I_("activate-cursor-item"),
943 G_TYPE_FROM_CLASS (gobject_class),
944 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
945 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
947 _gtk_marshal_BOOLEAN__VOID,
951 * GtkIconView::move-cursor:
952 * @iconview: the object which received the signal
953 * @step: the granularity of the move, as a #GtkMovementStep
954 * @count: the number of @step units to move
956 * The ::move-cursor signal is a
957 * <link linkend="keybinding-signals">keybinding signal</link>
958 * which gets emitted when the user initiates a cursor movement.
960 * Applications should not connect to it, but may emit it with
961 * g_signal_emit_by_name() if they need to control the cursor
964 * The default bindings for this signal include
966 * <listitem>Arrow keys which move by individual steps</listitem>
967 * <listitem>Home/End keys which move to the first/last item</listitem>
968 * <listitem>PageUp/PageDown which move by "pages"</listitem>
971 * All of these will extend the selection when combined with
972 * the Shift modifier.
974 icon_view_signals[MOVE_CURSOR] =
975 g_signal_new (I_("move-cursor"),
976 G_TYPE_FROM_CLASS (gobject_class),
977 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
978 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
980 _gtk_marshal_BOOLEAN__ENUM_INT,
982 GTK_TYPE_MOVEMENT_STEP,
986 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
988 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
990 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
991 "toggle-cursor-item", 0);
992 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
993 "toggle-cursor-item", 0);
995 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
996 "activate-cursor-item", 0);
997 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
998 "activate-cursor-item", 0);
999 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1000 "activate-cursor-item", 0);
1001 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1002 "activate-cursor-item", 0);
1003 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1004 "activate-cursor-item", 0);
1006 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1007 GTK_MOVEMENT_DISPLAY_LINES, -1);
1008 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1009 GTK_MOVEMENT_DISPLAY_LINES, -1);
1011 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1012 GTK_MOVEMENT_DISPLAY_LINES, 1);
1013 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1014 GTK_MOVEMENT_DISPLAY_LINES, 1);
1016 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1017 GTK_MOVEMENT_DISPLAY_LINES, -1);
1019 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1020 GTK_MOVEMENT_DISPLAY_LINES, 1);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1023 GTK_MOVEMENT_BUFFER_ENDS, -1);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1025 GTK_MOVEMENT_BUFFER_ENDS, -1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1028 GTK_MOVEMENT_BUFFER_ENDS, 1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1030 GTK_MOVEMENT_BUFFER_ENDS, 1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1033 GTK_MOVEMENT_PAGES, -1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1035 GTK_MOVEMENT_PAGES, -1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1038 GTK_MOVEMENT_PAGES, 1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1040 GTK_MOVEMENT_PAGES, 1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1043 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1044 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1045 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1048 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1049 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1050 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1052 gtk_widget_class_set_accessible_type (widget_class, gtk_icon_view_accessible_get_type ());
1056 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1058 parent_buildable_iface = g_type_interface_peek_parent (iface);
1059 iface->add_child = _gtk_cell_layout_buildable_add_child;
1060 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1061 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1065 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1067 iface->get_area = gtk_icon_view_cell_layout_get_area;
1071 gtk_icon_view_init (GtkIconView *icon_view)
1073 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1075 GtkIconViewPrivate);
1077 icon_view->priv->width = 0;
1078 icon_view->priv->height = 0;
1079 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1080 icon_view->priv->pressed_button = -1;
1081 icon_view->priv->press_start_x = -1;
1082 icon_view->priv->press_start_y = -1;
1083 icon_view->priv->text_column = -1;
1084 icon_view->priv->markup_column = -1;
1085 icon_view->priv->pixbuf_column = -1;
1086 icon_view->priv->text_cell = NULL;
1087 icon_view->priv->pixbuf_cell = NULL;
1088 icon_view->priv->tooltip_column = -1;
1090 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1092 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1094 icon_view->priv->columns = -1;
1095 icon_view->priv->item_width = -1;
1096 icon_view->priv->spacing = 0;
1097 icon_view->priv->row_spacing = 6;
1098 icon_view->priv->column_spacing = 6;
1099 icon_view->priv->margin = 6;
1100 icon_view->priv->item_padding = 6;
1102 icon_view->priv->draw_focus = TRUE;
1104 icon_view->priv->row_contexts =
1105 g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
1108 /* GObject methods */
1110 gtk_icon_view_constructor (GType type,
1111 guint n_construct_properties,
1112 GObjectConstructParam *construct_properties)
1114 GtkIconView *icon_view;
1117 object = G_OBJECT_CLASS (gtk_icon_view_parent_class)->constructor
1118 (type, n_construct_properties, construct_properties);
1120 icon_view = (GtkIconView *) object;
1122 gtk_icon_view_ensure_cell_area (icon_view, NULL);
1128 gtk_icon_view_dispose (GObject *object)
1130 GtkIconView *icon_view;
1131 GtkIconViewPrivate *priv;
1133 icon_view = GTK_ICON_VIEW (object);
1134 priv = icon_view->priv;
1136 if (priv->cell_area_context)
1138 g_signal_handler_disconnect (priv->cell_area_context, priv->context_changed_id);
1139 priv->context_changed_id = 0;
1141 g_object_unref (priv->cell_area_context);
1142 priv->cell_area_context = NULL;
1145 if (priv->row_contexts)
1147 g_ptr_array_free (priv->row_contexts, TRUE);
1148 priv->row_contexts = NULL;
1151 if (priv->cell_area)
1153 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1155 g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
1156 g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
1157 priv->add_editable_id = 0;
1158 priv->remove_editable_id = 0;
1160 g_object_unref (priv->cell_area);
1161 priv->cell_area = NULL;
1164 G_OBJECT_CLASS (gtk_icon_view_parent_class)->dispose (object);
1168 gtk_icon_view_set_property (GObject *object,
1170 const GValue *value,
1173 GtkIconView *icon_view;
1176 icon_view = GTK_ICON_VIEW (object);
1180 case PROP_SELECTION_MODE:
1181 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1183 case PROP_PIXBUF_COLUMN:
1184 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1186 case PROP_TEXT_COLUMN:
1187 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1189 case PROP_MARKUP_COLUMN:
1190 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1193 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1195 case PROP_ITEM_ORIENTATION:
1196 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1199 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1201 case PROP_ITEM_WIDTH:
1202 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1205 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1207 case PROP_ROW_SPACING:
1208 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1210 case PROP_COLUMN_SPACING:
1211 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1214 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1216 case PROP_REORDERABLE:
1217 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1220 case PROP_TOOLTIP_COLUMN:
1221 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1224 case PROP_ITEM_PADDING:
1225 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1228 case PROP_CELL_AREA:
1229 /* Construct-only, can only be assigned once */
1230 area = g_value_get_object (value);
1233 if (icon_view->priv->cell_area != NULL)
1235 g_warning ("cell-area has already been set, ignoring construct property");
1236 g_object_ref_sink (area);
1237 g_object_unref (area);
1240 gtk_icon_view_ensure_cell_area (icon_view, area);
1244 case PROP_HADJUSTMENT:
1245 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1247 case PROP_VADJUSTMENT:
1248 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1250 case PROP_HSCROLL_POLICY:
1251 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1252 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1254 case PROP_VSCROLL_POLICY:
1255 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1256 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1266 gtk_icon_view_get_property (GObject *object,
1271 GtkIconView *icon_view;
1273 icon_view = GTK_ICON_VIEW (object);
1277 case PROP_SELECTION_MODE:
1278 g_value_set_enum (value, icon_view->priv->selection_mode);
1280 case PROP_PIXBUF_COLUMN:
1281 g_value_set_int (value, icon_view->priv->pixbuf_column);
1283 case PROP_TEXT_COLUMN:
1284 g_value_set_int (value, icon_view->priv->text_column);
1286 case PROP_MARKUP_COLUMN:
1287 g_value_set_int (value, icon_view->priv->markup_column);
1290 g_value_set_object (value, icon_view->priv->model);
1292 case PROP_ITEM_ORIENTATION:
1293 g_value_set_enum (value, icon_view->priv->item_orientation);
1296 g_value_set_int (value, icon_view->priv->columns);
1298 case PROP_ITEM_WIDTH:
1299 g_value_set_int (value, icon_view->priv->item_width);
1302 g_value_set_int (value, icon_view->priv->spacing);
1304 case PROP_ROW_SPACING:
1305 g_value_set_int (value, icon_view->priv->row_spacing);
1307 case PROP_COLUMN_SPACING:
1308 g_value_set_int (value, icon_view->priv->column_spacing);
1311 g_value_set_int (value, icon_view->priv->margin);
1313 case PROP_REORDERABLE:
1314 g_value_set_boolean (value, icon_view->priv->reorderable);
1316 case PROP_TOOLTIP_COLUMN:
1317 g_value_set_int (value, icon_view->priv->tooltip_column);
1320 case PROP_ITEM_PADDING:
1321 g_value_set_int (value, icon_view->priv->item_padding);
1324 case PROP_CELL_AREA:
1325 g_value_set_object (value, icon_view->priv->cell_area);
1328 case PROP_HADJUSTMENT:
1329 g_value_set_object (value, icon_view->priv->hadjustment);
1331 case PROP_VADJUSTMENT:
1332 g_value_set_object (value, icon_view->priv->vadjustment);
1334 case PROP_HSCROLL_POLICY:
1335 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1337 case PROP_VSCROLL_POLICY:
1338 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1342 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1347 /* GtkWidget methods */
1349 gtk_icon_view_destroy (GtkWidget *widget)
1351 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1353 gtk_icon_view_set_model (icon_view, NULL);
1355 if (icon_view->priv->layout_idle_id != 0)
1357 g_source_remove (icon_view->priv->layout_idle_id);
1358 icon_view->priv->layout_idle_id = 0;
1361 if (icon_view->priv->scroll_to_path != NULL)
1363 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1364 icon_view->priv->scroll_to_path = NULL;
1367 remove_scroll_timeout (icon_view);
1369 if (icon_view->priv->hadjustment != NULL)
1371 g_object_unref (icon_view->priv->hadjustment);
1372 icon_view->priv->hadjustment = NULL;
1375 if (icon_view->priv->vadjustment != NULL)
1377 g_object_unref (icon_view->priv->vadjustment);
1378 icon_view->priv->vadjustment = NULL;
1381 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1385 gtk_icon_view_realize (GtkWidget *widget)
1387 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1388 GtkAllocation allocation;
1390 GdkWindowAttr attributes;
1391 gint attributes_mask;
1392 GtkStyleContext *context;
1394 gtk_widget_set_realized (widget, TRUE);
1396 gtk_widget_get_allocation (widget, &allocation);
1398 /* Make the main, clipping window */
1399 attributes.window_type = GDK_WINDOW_CHILD;
1400 attributes.x = allocation.x;
1401 attributes.y = allocation.y;
1402 attributes.width = allocation.width;
1403 attributes.height = allocation.height;
1404 attributes.wclass = GDK_INPUT_OUTPUT;
1405 attributes.visual = gtk_widget_get_visual (widget);
1406 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1408 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1410 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1411 &attributes, attributes_mask);
1412 gtk_widget_set_window (widget, window);
1413 gdk_window_set_user_data (window, widget);
1415 gtk_widget_get_allocation (widget, &allocation);
1417 /* Make the window for the icon view */
1420 attributes.width = MAX (icon_view->priv->width, allocation.width);
1421 attributes.height = MAX (icon_view->priv->height, allocation.height);
1422 attributes.event_mask = (GDK_EXPOSURE_MASK |
1424 GDK_POINTER_MOTION_MASK |
1425 GDK_BUTTON_PRESS_MASK |
1426 GDK_BUTTON_RELEASE_MASK |
1427 GDK_KEY_PRESS_MASK |
1428 GDK_KEY_RELEASE_MASK) |
1429 gtk_widget_get_events (widget);
1431 icon_view->priv->bin_window = gdk_window_new (window,
1432 &attributes, attributes_mask);
1433 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1435 context = gtk_widget_get_style_context (widget);
1437 gtk_style_context_save (context);
1438 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1439 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1440 gtk_style_context_restore (context);
1442 gdk_window_show (icon_view->priv->bin_window);
1446 gtk_icon_view_unrealize (GtkWidget *widget)
1448 GtkIconView *icon_view;
1450 icon_view = GTK_ICON_VIEW (widget);
1452 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1453 gdk_window_destroy (icon_view->priv->bin_window);
1454 icon_view->priv->bin_window = NULL;
1456 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1460 _gtk_icon_view_update_background (GtkIconView *icon_view)
1462 GtkWidget *widget = GTK_WIDGET (icon_view);
1464 if (gtk_widget_get_realized (widget))
1466 GtkStyleContext *context;
1468 context = gtk_widget_get_style_context (widget);
1470 gtk_style_context_save (context);
1471 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
1473 gtk_style_context_set_background (context, gtk_widget_get_window (widget));
1474 gtk_style_context_set_background (context, icon_view->priv->bin_window);
1476 gtk_style_context_restore (context);
1481 gtk_icon_view_state_flags_changed (GtkWidget *widget,
1482 GtkStateFlags previous_state)
1484 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1485 gtk_widget_queue_draw (widget);
1489 gtk_icon_view_style_updated (GtkWidget *widget)
1491 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
1493 _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
1494 gtk_widget_queue_resize (widget);
1498 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1502 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1506 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1510 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1514 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1518 for (list = icon_view->priv->children; list; list = list->next)
1520 GtkIconViewChild *child = list->data;
1522 /* totally ignore our child's requisition */
1523 gtk_widget_size_allocate (child->widget, &child->area);
1528 gtk_icon_view_size_allocate (GtkWidget *widget,
1529 GtkAllocation *allocation)
1531 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1533 gtk_widget_set_allocation (widget, allocation);
1535 if (gtk_widget_get_realized (widget))
1537 gdk_window_move_resize (gtk_widget_get_window (widget),
1538 allocation->x, allocation->y,
1539 allocation->width, allocation->height);
1540 gdk_window_resize (icon_view->priv->bin_window,
1541 MAX (icon_view->priv->width, allocation->width),
1542 MAX (icon_view->priv->height, allocation->height));
1545 gtk_icon_view_layout (icon_view);
1547 gtk_icon_view_allocate_children (icon_view);
1549 /* Delay signal emission */
1550 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1551 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1553 gtk_icon_view_set_hadjustment_values (icon_view);
1554 gtk_icon_view_set_vadjustment_values (icon_view);
1556 if (gtk_widget_get_realized (widget) &&
1557 icon_view->priv->scroll_to_path)
1560 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1561 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1562 icon_view->priv->scroll_to_path = NULL;
1564 gtk_icon_view_scroll_to_path (icon_view, path,
1565 icon_view->priv->scroll_to_use_align,
1566 icon_view->priv->scroll_to_row_align,
1567 icon_view->priv->scroll_to_col_align);
1568 gtk_tree_path_free (path);
1571 /* Emit any pending signals now */
1572 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1573 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1577 gtk_icon_view_draw (GtkWidget *widget,
1580 GtkIconView *icon_view;
1584 GtkIconViewDropPosition dest_pos;
1585 GtkIconViewItem *dest_item = NULL;
1587 icon_view = GTK_ICON_VIEW (widget);
1589 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1594 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1596 cairo_set_line_width (cr, 1.);
1598 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1602 dest_index = gtk_tree_path_get_indices (path)[0];
1603 gtk_tree_path_free (path);
1608 for (icons = icon_view->priv->items; icons; icons = icons->next)
1610 GtkIconViewItem *item = icons->data;
1611 GdkRectangle paint_area;
1613 paint_area.x = ((GdkRectangle *)item)->x - icon_view->priv->item_padding;
1614 paint_area.y = ((GdkRectangle *)item)->y - icon_view->priv->item_padding;
1615 paint_area.width = ((GdkRectangle *)item)->width + icon_view->priv->item_padding * 2;
1616 paint_area.height = ((GdkRectangle *)item)->height + icon_view->priv->item_padding * 2;
1620 cairo_rectangle (cr, paint_area.x, paint_area.y, paint_area.width, paint_area.height);
1623 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1625 gtk_icon_view_paint_item (icon_view, cr, item,
1626 ((GdkRectangle *)item)->x, ((GdkRectangle *)item)->y,
1627 icon_view->priv->draw_focus);
1629 if (dest_index == item->index)
1637 dest_pos != GTK_ICON_VIEW_NO_DROP)
1639 GtkStyleContext *context;
1640 GtkStateFlags state;
1641 GdkRectangle rect = { 0 };
1643 context = gtk_widget_get_style_context (widget);
1644 state = gtk_widget_get_state_flags (widget);
1648 case GTK_ICON_VIEW_DROP_INTO:
1649 rect = dest_item->cell_area;
1651 case GTK_ICON_VIEW_DROP_ABOVE:
1652 rect.x = dest_item->cell_area.x;
1653 rect.y = dest_item->cell_area.y - 1;
1654 rect.width = dest_item->cell_area.width;
1657 case GTK_ICON_VIEW_DROP_LEFT:
1658 rect.x = dest_item->cell_area.x - 1;
1659 rect.y = dest_item->cell_area.y;
1661 rect.height = dest_item->cell_area.height;
1663 case GTK_ICON_VIEW_DROP_BELOW:
1664 rect.x = dest_item->cell_area.x;
1665 rect.y = dest_item->cell_area.y + dest_item->cell_area.height - 1;
1666 rect.width = dest_item->cell_area.width;
1669 case GTK_ICON_VIEW_DROP_RIGHT:
1670 rect.x = dest_item->cell_area.x + dest_item->cell_area.width - 1;
1671 rect.y = dest_item->cell_area.y;
1673 rect.height = dest_item->cell_area.height;
1674 case GTK_ICON_VIEW_NO_DROP: ;
1678 gtk_style_context_set_state (context, state);
1679 gtk_render_focus (context, cr,
1681 rect.width, rect.height);
1684 if (icon_view->priv->doing_rubberband)
1685 gtk_icon_view_paint_rubberband (icon_view, cr);
1689 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1695 rubberband_scroll_timeout (gpointer data)
1697 GtkIconView *icon_view = data;
1699 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1700 gtk_adjustment_get_value (icon_view->priv->vadjustment) +
1701 icon_view->priv->scroll_value_diff);
1703 gtk_icon_view_update_rubberband (icon_view);
1709 gtk_icon_view_motion (GtkWidget *widget,
1710 GdkEventMotion *event)
1712 GtkAllocation allocation;
1713 GtkIconView *icon_view;
1716 icon_view = GTK_ICON_VIEW (widget);
1718 gtk_icon_view_maybe_begin_drag (icon_view, event);
1720 if (icon_view->priv->doing_rubberband)
1722 gtk_icon_view_update_rubberband (widget);
1724 abs_y = event->y - icon_view->priv->height *
1725 (gtk_adjustment_get_value (icon_view->priv->vadjustment) /
1726 (gtk_adjustment_get_upper (icon_view->priv->vadjustment) -
1727 gtk_adjustment_get_lower (icon_view->priv->vadjustment)));
1729 gtk_widget_get_allocation (widget, &allocation);
1731 if (abs_y < 0 || abs_y > allocation.height)
1734 icon_view->priv->scroll_value_diff = abs_y;
1736 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1738 icon_view->priv->event_last_x = event->x;
1739 icon_view->priv->event_last_y = event->y;
1741 if (icon_view->priv->scroll_timeout_id == 0)
1742 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1746 remove_scroll_timeout (icon_view);
1753 gtk_icon_view_remove (GtkContainer *container,
1756 GtkIconView *icon_view;
1757 GtkIconViewChild *child = NULL;
1760 icon_view = GTK_ICON_VIEW (container);
1762 tmp_list = icon_view->priv->children;
1765 child = tmp_list->data;
1766 if (child->widget == widget)
1768 gtk_widget_unparent (widget);
1770 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1771 g_list_free_1 (tmp_list);
1776 tmp_list = tmp_list->next;
1781 gtk_icon_view_forall (GtkContainer *container,
1782 gboolean include_internals,
1783 GtkCallback callback,
1784 gpointer callback_data)
1786 GtkIconView *icon_view;
1787 GtkIconViewChild *child = NULL;
1790 icon_view = GTK_ICON_VIEW (container);
1792 tmp_list = icon_view->priv->children;
1795 child = tmp_list->data;
1796 tmp_list = tmp_list->next;
1798 (* callback) (child->widget, callback_data);
1803 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1804 GtkIconViewItem *item)
1807 AtkObject *item_obj;
1809 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1812 item_obj = atk_object_ref_accessible_child (obj, item->index);
1813 if (item_obj != NULL)
1815 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1816 g_object_unref (item_obj);
1822 gtk_icon_view_add_editable (GtkCellArea *area,
1823 GtkCellRenderer *renderer,
1824 GtkCellEditable *editable,
1825 GdkRectangle *cell_area,
1827 GtkIconView *icon_view)
1829 GtkIconViewChild *child;
1830 GtkWidget *widget = GTK_WIDGET (editable);
1832 child = g_new (GtkIconViewChild, 1);
1834 child->widget = widget;
1835 child->area.x = cell_area->x;
1836 child->area.y = cell_area->y;
1837 child->area.width = cell_area->width;
1838 child->area.height = cell_area->height;
1840 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1842 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1843 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1845 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1849 gtk_icon_view_remove_editable (GtkCellArea *area,
1850 GtkCellRenderer *renderer,
1851 GtkCellEditable *editable,
1852 GtkIconView *icon_view)
1856 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1857 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1859 gtk_container_remove (GTK_CONTAINER (icon_view),
1860 GTK_WIDGET (editable));
1862 path = gtk_tree_path_new_from_string (gtk_cell_area_get_current_path_string (area));
1863 gtk_icon_view_queue_draw_path (icon_view, path);
1864 gtk_tree_path_free (path);
1868 gtk_icon_view_context_changed (GtkCellAreaContext *context,
1870 GtkIconView *icon_view)
1872 if (!strcmp (pspec->name, "minimum-width") ||
1873 !strcmp (pspec->name, "natural-width") ||
1874 !strcmp (pspec->name, "minimum-height") ||
1875 !strcmp (pspec->name, "natural-height"))
1876 gtk_icon_view_invalidate_sizes (icon_view);
1880 * gtk_icon_view_set_cursor:
1881 * @icon_view: A #GtkIconView
1882 * @path: A #GtkTreePath
1883 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1884 * @start_editing: %TRUE if the specified cell should start being edited.
1886 * Sets the current keyboard focus to be at @path, and selects it. This is
1887 * useful when you want to focus the user's attention on a particular item.
1888 * If @cell is not %NULL, then focus is given to the cell specified by
1889 * it. Additionally, if @start_editing is %TRUE, then editing should be
1890 * started in the specified cell.
1892 * This function is often followed by <literal>gtk_widget_grab_focus
1893 * (icon_view)</literal> in order to give keyboard focus to the widget.
1894 * Please note that editing can only happen when the widget is realized.
1899 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1901 GtkCellRenderer *cell,
1902 gboolean start_editing)
1904 GtkIconViewItem *item = NULL;
1906 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1907 g_return_if_fail (path != NULL);
1908 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1910 if (icon_view->priv->cell_area)
1911 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
1913 if (gtk_tree_path_get_depth (path) == 1)
1914 item = g_list_nth_data (icon_view->priv->items,
1915 gtk_tree_path_get_indices(path)[0]);
1920 gtk_icon_view_set_cursor_item (icon_view, item, cell);
1921 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1923 if (start_editing &&
1924 icon_view->priv->cell_area)
1926 GtkCellAreaContext *context;
1928 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
1929 gtk_icon_view_set_cell_data (icon_view, item);
1930 gtk_cell_area_activate (icon_view->priv->cell_area, context,
1931 GTK_WIDGET (icon_view), (GdkRectangle *)item,
1932 0 /* XXX flags */, TRUE);
1937 * gtk_icon_view_get_cursor:
1938 * @icon_view: A #GtkIconView
1939 * @path: (out) (allow-none): Return location for the current cursor path,
1941 * @cell: (out) (allow-none): Return location the current focus cell, or %NULL
1943 * Fills in @path and @cell with the current cursor path and cell.
1944 * If the cursor isn't currently set, then *@path will be %NULL.
1945 * If no cell currently has focus, then *@cell will be %NULL.
1947 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1949 * Return value: %TRUE if the cursor is set.
1954 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1956 GtkCellRenderer **cell)
1958 GtkIconViewItem *item;
1960 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1962 item = icon_view->priv->cursor_item;
1967 *path = gtk_tree_path_new_from_indices (item->index, -1);
1972 if (cell != NULL && item != NULL && icon_view->priv->cell_area != NULL)
1973 *cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
1975 return (item != NULL);
1979 gtk_icon_view_button_press (GtkWidget *widget,
1980 GdkEventButton *event)
1982 GtkIconView *icon_view;
1983 GtkIconViewItem *item;
1984 gboolean dirty = FALSE;
1985 GtkCellRenderer *cell = NULL, *cursor_cell = NULL;
1987 icon_view = GTK_ICON_VIEW (widget);
1989 if (event->window != icon_view->priv->bin_window)
1992 if (!gtk_widget_has_focus (widget))
1993 gtk_widget_grab_focus (widget);
1995 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1997 item = gtk_icon_view_get_item_at_coords (icon_view,
2003 * We consider only the the cells' area as the item area if the
2004 * item is not selected, but if it *is* selected, the complete
2005 * selection rectangle is considered to be part of the item.
2007 if (item != NULL && (cell != NULL || item->selected))
2011 if (gtk_cell_renderer_is_activatable (cell))
2015 gtk_icon_view_scroll_to_item (icon_view, item);
2017 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2019 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2021 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2022 (event->state & GDK_SHIFT_MASK))
2024 gtk_icon_view_unselect_all_internal (icon_view);
2026 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2027 if (!icon_view->priv->anchor_item)
2028 icon_view->priv->anchor_item = item;
2030 gtk_icon_view_select_all_between (icon_view,
2031 icon_view->priv->anchor_item,
2037 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2038 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2039 (event->state & GDK_CONTROL_MASK))
2041 item->selected = !item->selected;
2042 gtk_icon_view_queue_draw_item (icon_view, item);
2047 gtk_icon_view_unselect_all_internal (icon_view);
2049 item->selected = TRUE;
2050 gtk_icon_view_queue_draw_item (icon_view, item);
2053 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2054 icon_view->priv->anchor_item = item;
2057 /* Save press to possibly begin a drag */
2058 if (icon_view->priv->pressed_button < 0)
2060 icon_view->priv->pressed_button = event->button;
2061 icon_view->priv->press_start_x = event->x;
2062 icon_view->priv->press_start_y = event->y;
2065 if (!icon_view->priv->last_single_clicked)
2066 icon_view->priv->last_single_clicked = item;
2068 /* cancel the current editing, if it exists */
2069 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
2071 if (cell != NULL && gtk_cell_renderer_is_activatable (cell))
2073 GtkCellAreaContext *context;
2075 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2077 gtk_icon_view_set_cell_data (icon_view, item);
2078 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2079 GTK_WIDGET (icon_view),
2080 (GdkRectangle *)item, 0/* XXX flags */, FALSE);
2085 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2086 !(event->state & GDK_CONTROL_MASK))
2088 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2091 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2092 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2095 /* don't draw keyboard focus around an clicked-on item */
2096 icon_view->priv->draw_focus = FALSE;
2099 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2101 item = gtk_icon_view_get_item_at_coords (icon_view,
2106 if (item && item == icon_view->priv->last_single_clicked)
2110 path = gtk_tree_path_new_from_indices (item->index, -1);
2111 gtk_icon_view_item_activated (icon_view, path);
2112 gtk_tree_path_free (path);
2115 icon_view->priv->last_single_clicked = NULL;
2116 icon_view->priv->pressed_button = -1;
2120 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2122 return event->button == 1;
2126 gtk_icon_view_button_release (GtkWidget *widget,
2127 GdkEventButton *event)
2129 GtkIconView *icon_view;
2131 icon_view = GTK_ICON_VIEW (widget);
2133 if (icon_view->priv->pressed_button == event->button)
2134 icon_view->priv->pressed_button = -1;
2136 gtk_icon_view_stop_rubberbanding (icon_view);
2138 remove_scroll_timeout (icon_view);
2144 gtk_icon_view_key_press (GtkWidget *widget,
2147 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2149 if (icon_view->priv->doing_rubberband)
2151 if (event->keyval == GDK_KEY_Escape)
2152 gtk_icon_view_stop_rubberbanding (icon_view);
2157 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2161 gtk_icon_view_key_release (GtkWidget *widget,
2164 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2166 if (icon_view->priv->doing_rubberband)
2169 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2173 gtk_icon_view_update_rubberband (gpointer data)
2175 GtkIconView *icon_view;
2177 GdkRectangle old_area;
2178 GdkRectangle new_area;
2179 GdkRectangle common;
2180 cairo_region_t *invalid_region;
2182 icon_view = GTK_ICON_VIEW (data);
2184 gdk_window_get_device_position (icon_view->priv->bin_window,
2185 icon_view->priv->rubberband_device,
2191 old_area.x = MIN (icon_view->priv->rubberband_x1,
2192 icon_view->priv->rubberband_x2);
2193 old_area.y = MIN (icon_view->priv->rubberband_y1,
2194 icon_view->priv->rubberband_y2);
2195 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2196 icon_view->priv->rubberband_x1) + 1;
2197 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2198 icon_view->priv->rubberband_y1) + 1;
2200 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2201 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2202 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2203 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2205 invalid_region = cairo_region_create_rectangle (&old_area);
2206 cairo_region_union_rectangle (invalid_region, &new_area);
2208 gdk_rectangle_intersect (&old_area, &new_area, &common);
2209 if (common.width > 2 && common.height > 2)
2211 cairo_region_t *common_region;
2213 /* make sure the border is invalidated */
2219 common_region = cairo_region_create_rectangle (&common);
2221 cairo_region_subtract (invalid_region, common_region);
2222 cairo_region_destroy (common_region);
2225 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2227 cairo_region_destroy (invalid_region);
2229 icon_view->priv->rubberband_x2 = x;
2230 icon_view->priv->rubberband_y2 = y;
2232 gtk_icon_view_update_rubberband_selection (icon_view);
2236 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2243 if (icon_view->priv->rubberband_device)
2246 for (items = icon_view->priv->items; items; items = items->next)
2248 GtkIconViewItem *item = items->data;
2250 item->selected_before_rubberbanding = item->selected;
2253 icon_view->priv->rubberband_x1 = x;
2254 icon_view->priv->rubberband_y1 = y;
2255 icon_view->priv->rubberband_x2 = x;
2256 icon_view->priv->rubberband_y2 = y;
2258 icon_view->priv->doing_rubberband = TRUE;
2259 icon_view->priv->rubberband_device = device;
2261 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2265 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2267 if (!icon_view->priv->doing_rubberband)
2270 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2271 icon_view->priv->rubberband_device);
2273 icon_view->priv->doing_rubberband = FALSE;
2274 icon_view->priv->rubberband_device = NULL;
2276 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2280 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2283 gint x, y, width, height;
2284 gboolean dirty = FALSE;
2286 x = MIN (icon_view->priv->rubberband_x1,
2287 icon_view->priv->rubberband_x2);
2288 y = MIN (icon_view->priv->rubberband_y1,
2289 icon_view->priv->rubberband_y2);
2290 width = ABS (icon_view->priv->rubberband_x1 -
2291 icon_view->priv->rubberband_x2);
2292 height = ABS (icon_view->priv->rubberband_y1 -
2293 icon_view->priv->rubberband_y2);
2295 for (items = icon_view->priv->items; items; items = items->next)
2297 GtkIconViewItem *item = items->data;
2301 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2302 x, y, width, height);
2304 selected = is_in ^ item->selected_before_rubberbanding;
2306 if (item->selected != selected)
2308 item->selected = selected;
2310 gtk_icon_view_queue_draw_item (icon_view, item);
2315 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2320 GdkRectangle hit_rect;
2325 hit_test (GtkCellRenderer *renderer,
2326 const GdkRectangle *cell_area,
2327 const GdkRectangle *cell_background,
2330 if (MIN (data->hit_rect.x + data->hit_rect.width, cell_area->x + cell_area->width) -
2331 MAX (data->hit_rect.x, cell_area->x) > 0 &&
2332 MIN (data->hit_rect.y + data->hit_rect.height, cell_area->y + cell_area->height) -
2333 MAX (data->hit_rect.y, cell_area->y) > 0)
2336 return (data->hit != FALSE);
2340 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2341 GtkIconViewItem *item,
2347 HitTestData data = { { x, y, width, height }, FALSE };
2348 GtkCellAreaContext *context;
2349 GdkRectangle *item_area = (GdkRectangle *)item;
2351 if (MIN (x + width, item_area->x + item_area->width) - MAX (x, item_area->x) <= 0 ||
2352 MIN (y + height, item_area->y + item_area->height) - MAX (y, item_area->y) <= 0)
2355 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
2357 gtk_icon_view_set_cell_data (icon_view, item);
2358 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
2359 GTK_WIDGET (icon_view),
2360 item_area, item_area,
2361 (GtkCellAllocCallback)hit_test, &data);
2367 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2369 gboolean dirty = FALSE;
2372 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2375 for (items = icon_view->priv->items; items; items = items->next)
2377 GtkIconViewItem *item = items->data;
2381 item->selected = FALSE;
2383 gtk_icon_view_queue_draw_item (icon_view, item);
2384 gtk_icon_view_item_selected_changed (icon_view, item);
2392 /* GtkIconView signals */
2394 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2396 gtk_icon_view_select_all (icon_view);
2400 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2402 gtk_icon_view_unselect_all (icon_view);
2406 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2408 gtk_icon_view_unselect_all (icon_view);
2410 if (icon_view->priv->cursor_item != NULL)
2411 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2415 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2418 GtkCellAreaContext *context;
2420 if (!icon_view->priv->cursor_item)
2423 context = g_ptr_array_index (icon_view->priv->row_contexts, icon_view->priv->cursor_item->row);
2425 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->cursor_item);
2426 gtk_cell_area_activate (icon_view->priv->cell_area, context,
2427 GTK_WIDGET (icon_view),
2428 (GdkRectangle *)icon_view->priv->cursor_item,
2432 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2433 gtk_icon_view_item_activated (icon_view, path);
2434 gtk_tree_path_free (path);
2440 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2442 if (!icon_view->priv->cursor_item)
2445 switch (icon_view->priv->selection_mode)
2447 case GTK_SELECTION_NONE:
2449 case GTK_SELECTION_BROWSE:
2450 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2452 case GTK_SELECTION_SINGLE:
2453 if (icon_view->priv->cursor_item->selected)
2454 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2456 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2458 case GTK_SELECTION_MULTIPLE:
2459 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2460 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2462 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2463 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2468 /* Internal functions */
2470 gtk_icon_view_process_updates (GtkIconView *icon_view)
2472 /* Prior to drawing, we check if a layout has been scheduled. If so,
2473 * do it now that all cell view items have valid sizes before we proceeed
2474 * (and resize the bin_window if required).
2476 if (icon_view->priv->layout_idle_id != 0)
2477 gtk_icon_view_layout (icon_view);
2479 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2483 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2485 GtkAllocation allocation;
2486 GtkAdjustment *adj = icon_view->priv->hadjustment;
2487 gdouble old_page_size;
2493 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2495 old_value = gtk_adjustment_get_value (adj);
2496 old_upper = gtk_adjustment_get_upper (adj);
2497 old_page_size = gtk_adjustment_get_page_size (adj);
2498 new_upper = MAX (allocation.width, icon_view->priv->width);
2500 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2502 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2503 /* Quick explanation:
2504 * In LTR locales, leftmost portion of visible rectangle should stay
2505 * fixed, which means left edge of scrollbar thumb should remain fixed
2506 * and thus adjustment's value should stay the same.
2508 * In RTL locales, we want to keep rightmost portion of visible
2509 * rectangle fixed. This means right edge of thumb should remain fixed.
2510 * In this case, upper - value - page_size should remain constant.
2512 new_value = (new_upper - allocation.width) -
2513 (old_upper - old_value - old_page_size);
2514 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2517 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2519 gtk_adjustment_configure (adj,
2523 allocation.width * 0.1,
2524 allocation.width * 0.9,
2529 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2531 GtkAllocation allocation;
2532 GtkAdjustment *adj = icon_view->priv->vadjustment;
2534 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2536 gtk_adjustment_configure (adj,
2537 gtk_adjustment_get_value (adj),
2539 MAX (allocation.height, icon_view->priv->height),
2540 allocation.height * 0.1,
2541 allocation.height * 0.9,
2546 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2547 GtkAdjustment *adjustment)
2549 GtkIconViewPrivate *priv = icon_view->priv;
2552 if (adjustment && priv->hadjustment == adjustment)
2555 if (priv->hadjustment != NULL)
2557 g_signal_handlers_disconnect_matched (priv->hadjustment,
2558 G_SIGNAL_MATCH_DATA,
2559 0, 0, NULL, NULL, icon_view);
2560 g_object_unref (priv->hadjustment);
2564 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2567 g_signal_connect (adjustment, "value-changed",
2568 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2569 priv->hadjustment = g_object_ref_sink (adjustment);
2570 gtk_icon_view_set_hadjustment_values (icon_view);
2572 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2573 gtk_icon_view_accessible_set_adjustment (atk_obj,
2574 GTK_ORIENTATION_HORIZONTAL,
2577 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2581 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2582 GtkAdjustment *adjustment)
2584 GtkIconViewPrivate *priv = icon_view->priv;
2587 if (adjustment && priv->vadjustment == adjustment)
2590 if (priv->vadjustment != NULL)
2592 g_signal_handlers_disconnect_matched (priv->vadjustment,
2593 G_SIGNAL_MATCH_DATA,
2594 0, 0, NULL, NULL, icon_view);
2595 g_object_unref (priv->vadjustment);
2599 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2602 g_signal_connect (adjustment, "value-changed",
2603 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2604 priv->vadjustment = g_object_ref_sink (adjustment);
2605 gtk_icon_view_set_vadjustment_values (icon_view);
2607 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2608 gtk_icon_view_accessible_set_adjustment (atk_obj,
2609 GTK_ORIENTATION_VERTICAL,
2612 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2616 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2617 GtkIconView *icon_view)
2619 GtkIconViewPrivate *priv = icon_view->priv;
2621 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2623 gdk_window_move (priv->bin_window,
2624 - gtk_adjustment_get_value (priv->hadjustment),
2625 - gtk_adjustment_get_value (priv->vadjustment));
2627 if (icon_view->priv->doing_rubberband)
2628 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2630 gtk_icon_view_process_updates (icon_view);
2635 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2640 gint *maximum_width)
2642 GtkAllocation allocation;
2643 GtkCellAreaContext *context;
2644 GtkIconViewPrivate *priv = icon_view->priv;
2645 GtkWidget *widget = GTK_WIDGET (icon_view);
2646 gint x, current_width;
2647 GList *items, *last_item;
2649 gint max_height = 0;
2652 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2660 current_width += 2 * priv->margin;
2662 gtk_widget_get_allocation (widget, &allocation);
2664 context = gtk_cell_area_copy_context (priv->cell_area, priv->cell_area_context);
2665 g_ptr_array_add (priv->row_contexts, context);
2667 /* In the first loop we iterate horizontally until we hit allocation width
2668 * and collect the aligned height-for-width */
2672 GtkIconViewItem *item = items->data;
2673 GdkRectangle *item_area = (GdkRectangle *)item;
2675 item_area->width = item_width;
2677 current_width += item_area->width + icon_view->priv->item_padding * 2;
2679 if (items != first_item)
2681 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2682 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2686 /* Get this item's particular width & height (all alignments are cached by now) */
2687 gtk_icon_view_set_cell_data (icon_view, item);
2688 gtk_cell_area_get_preferred_height_for_width (priv->cell_area,
2693 current_width += icon_view->priv->column_spacing;
2695 item_area->y = *y + icon_view->priv->item_padding;
2696 item_area->x = x + icon_view->priv->item_padding;
2698 x = current_width - icon_view->priv->margin;
2700 if (current_width > *maximum_width)
2701 *maximum_width = current_width;
2707 items = items->next;
2712 gtk_cell_area_context_get_preferred_height_for_width (context, item_width, &max_height, NULL);
2713 gtk_cell_area_context_allocate (context, item_width, max_height);
2715 /* In the second loop the item height has been aligned and derived and
2716 * we just set the height and handle rtl layout */
2717 for (items = first_item; items != last_item; items = items->next)
2719 GtkIconViewItem *item = items->data;
2720 GdkRectangle *item_area = (GdkRectangle *)item;
2724 item_area->x = *maximum_width - item_area->width - item_area->x;
2725 item->col = col - 1 - item->col;
2728 /* All items in the same row get the same height */
2729 item_area->height = max_height;
2732 /* Adjust the new y coordinate. */
2733 *y += max_height + icon_view->priv->row_spacing + icon_view->priv->item_padding * 2;
2739 adjust_wrap_width (GtkIconView *icon_view)
2741 if (icon_view->priv->text_cell)
2743 gint wrap_width = 50;
2745 /* Here we go with the same old guess, try the icon size and set double
2746 * the size of the first icon found in the list, naive but works much
2748 if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
2750 gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
2751 gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
2752 GTK_WIDGET (icon_view),
2755 wrap_width = MAX (wrap_width * 2, 50);
2758 g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
2759 g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
2764 gtk_icon_view_layout (GtkIconView *icon_view)
2766 GtkAllocation allocation;
2769 gint y = 0, maximum_width = 0;
2772 gboolean size_changed = FALSE;
2774 if (icon_view->priv->layout_idle_id != 0)
2776 g_source_remove (icon_view->priv->layout_idle_id);
2777 icon_view->priv->layout_idle_id = 0;
2780 if (icon_view->priv->model == NULL)
2783 widget = GTK_WIDGET (icon_view);
2785 item_width = icon_view->priv->item_width;
2787 /* Update the wrap width for the text cell before going and requesting sizes */
2788 adjust_wrap_width (icon_view);
2790 /* Update the context widths for any invalidated items */
2791 gtk_icon_view_cache_widths (icon_view);
2793 /* Fetch the new item width if needed */
2795 gtk_cell_area_context_get_preferred_width (icon_view->priv->cell_area_context,
2798 gtk_cell_area_context_allocate (icon_view->priv->cell_area_context, item_width, -1);
2800 icons = icon_view->priv->items;
2801 y += icon_view->priv->margin;
2804 /* Clear the per row contexts */
2805 g_ptr_array_set_size (icon_view->priv->row_contexts, 0);
2809 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2811 &y, &maximum_width);
2814 while (icons != NULL);
2816 if (maximum_width != icon_view->priv->width)
2818 icon_view->priv->width = maximum_width;
2819 size_changed = TRUE;
2822 y += icon_view->priv->margin;
2824 if (y != icon_view->priv->height)
2826 icon_view->priv->height = y;
2827 size_changed = TRUE;
2830 gtk_icon_view_set_hadjustment_values (icon_view);
2831 gtk_icon_view_set_vadjustment_values (icon_view);
2834 gtk_widget_queue_resize_no_redraw (widget);
2836 gtk_widget_get_allocation (widget, &allocation);
2837 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2838 gdk_window_resize (icon_view->priv->bin_window,
2839 MAX (icon_view->priv->width, allocation.width),
2840 MAX (icon_view->priv->height, allocation.height));
2842 if (icon_view->priv->scroll_to_path)
2846 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2847 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2848 icon_view->priv->scroll_to_path = NULL;
2850 gtk_icon_view_scroll_to_path (icon_view, path,
2851 icon_view->priv->scroll_to_use_align,
2852 icon_view->priv->scroll_to_row_align,
2853 icon_view->priv->scroll_to_col_align);
2854 gtk_tree_path_free (path);
2857 gtk_widget_queue_draw (widget);
2860 /* This ensures that all widths have been cached in the
2861 * context and we have proper alignments to go on.
2864 gtk_icon_view_cache_widths (GtkIconView *icon_view)
2868 g_signal_handler_block (icon_view->priv->cell_area_context,
2869 icon_view->priv->context_changed_id);
2871 for (items = icon_view->priv->items; items; items = items->next)
2873 GtkIconViewItem *item = items->data;
2875 /* Only fetch the width of items with invalidated sizes */
2876 if (item->cell_area.width < 0)
2878 gtk_icon_view_set_cell_data (icon_view, item);
2879 gtk_cell_area_get_preferred_width (icon_view->priv->cell_area,
2880 icon_view->priv->cell_area_context,
2881 GTK_WIDGET (icon_view), NULL, NULL);
2885 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2886 icon_view->priv->context_changed_id);
2890 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2892 /* Clear all item sizes */
2893 g_list_foreach (icon_view->priv->items,
2894 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2896 /* Reset the context */
2897 if (icon_view->priv->cell_area_context)
2899 g_signal_handler_block (icon_view->priv->cell_area_context,
2900 icon_view->priv->context_changed_id);
2901 gtk_cell_area_context_reset (icon_view->priv->cell_area_context);
2902 g_signal_handler_unblock (icon_view->priv->cell_area_context,
2903 icon_view->priv->context_changed_id);
2906 /* Re-layout the items */
2907 gtk_icon_view_queue_layout (icon_view);
2911 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2913 item->cell_area.width = -1;
2914 item->cell_area.height = -1;
2918 gtk_icon_view_paint_item (GtkIconView *icon_view,
2920 GtkIconViewItem *item,
2923 gboolean draw_focus)
2925 GdkRectangle cell_area;
2926 GtkStateFlags state = 0;
2927 GtkCellRendererState flags = 0;
2928 GtkStyleContext *style_context;
2929 GtkWidget *widget = GTK_WIDGET (icon_view);
2930 GtkIconViewPrivate *priv = icon_view->priv;
2931 GtkCellAreaContext *context;
2933 if (priv->model == NULL)
2936 gtk_icon_view_set_cell_data (icon_view, item);
2938 style_context = gtk_widget_get_style_context (widget);
2940 gtk_style_context_save (style_context);
2941 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
2942 gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
2946 if (gtk_widget_has_focus (widget) &&
2947 item == icon_view->priv->cursor_item)
2949 state |= GTK_STATE_FLAG_FOCUSED;
2950 flags |= GTK_CELL_RENDERER_FOCUSED;
2953 state |= GTK_STATE_FLAG_SELECTED;
2954 flags |= GTK_CELL_RENDERER_SELECTED;
2956 gtk_style_context_set_state (style_context, state);
2957 gtk_render_background (style_context, cr,
2958 x - icon_view->priv->item_padding,
2959 y - icon_view->priv->item_padding,
2960 item->cell_area.width + icon_view->priv->item_padding * 2,
2961 item->cell_area.height + icon_view->priv->item_padding * 2);
2966 cell_area.width = item->cell_area.width;
2967 cell_area.height = item->cell_area.height;
2969 context = g_ptr_array_index (priv->row_contexts, item->row);
2970 gtk_cell_area_render (priv->cell_area, context,
2971 widget, cr, &cell_area, &cell_area, flags,
2974 gtk_style_context_restore (style_context);
2978 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2981 GtkStyleContext *context;
2986 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2987 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2988 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2989 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2991 context = gtk_widget_get_style_context (GTK_WIDGET (icon_view));
2993 gtk_style_context_save (context);
2994 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
2996 gdk_cairo_rectangle (cr, &rect);
2999 gtk_render_background (context, cr,
3001 rect.width, rect.height);
3002 gtk_render_frame (context, cr,
3004 rect.width, rect.height);
3006 gtk_style_context_restore (context);
3011 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3017 index = gtk_tree_path_get_indices (path)[0];
3019 for (l = icon_view->priv->items; l; l = l->next)
3021 GtkIconViewItem *item = l->data;
3023 if (item->index == index)
3025 gtk_icon_view_queue_draw_item (icon_view, item);
3032 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3033 GtkIconViewItem *item)
3036 GdkRectangle *item_area = (GdkRectangle *)item;
3038 rect.x = item_area->x - icon_view->priv->item_padding;
3039 rect.y = item_area->y - icon_view->priv->item_padding;
3040 rect.width = item_area->width + icon_view->priv->item_padding * 2;
3041 rect.height = item_area->height + icon_view->priv->item_padding * 2;
3043 if (icon_view->priv->bin_window)
3044 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3048 layout_callback (gpointer user_data)
3050 GtkIconView *icon_view;
3052 icon_view = GTK_ICON_VIEW (user_data);
3054 icon_view->priv->layout_idle_id = 0;
3056 gtk_icon_view_layout (icon_view);
3062 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3064 if (icon_view->priv->layout_idle_id != 0)
3067 icon_view->priv->layout_idle_id =
3068 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3069 layout_callback, icon_view, NULL);
3073 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3074 GtkIconViewItem *item,
3075 GtkCellRenderer *cursor_cell)
3078 AtkObject *item_obj;
3079 AtkObject *cursor_item_obj;
3081 /* When hitting this path from keynav, the focus cell is
3082 * already set, we dont need to notify the atk object
3083 * but we still need to queue the draw here (in the case
3084 * that the focus cell changes but not the cursor item).
3086 gtk_icon_view_queue_draw_item (icon_view, item);
3088 if (icon_view->priv->cursor_item == item &&
3089 (cursor_cell == NULL || cursor_cell == gtk_cell_area_get_focus_cell (icon_view->priv->cell_area)))
3092 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3093 if (icon_view->priv->cursor_item != NULL)
3095 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3098 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3099 if (cursor_item_obj != NULL)
3100 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3103 icon_view->priv->cursor_item = item;
3106 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cursor_cell);
3109 /* Make sure there is a cell in focus initially */
3110 if (!gtk_cell_area_get_focus_cell (icon_view->priv->cell_area))
3111 gtk_cell_area_focus (icon_view->priv->cell_area, GTK_DIR_TAB_FORWARD);
3114 /* Notify that accessible focus object has changed */
3115 item_obj = atk_object_ref_accessible_child (obj, item->index);
3117 if (item_obj != NULL)
3119 atk_focus_tracker_notify (item_obj);
3120 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3121 g_object_unref (item_obj);
3126 static GtkIconViewItem *
3127 gtk_icon_view_item_new (void)
3129 GtkIconViewItem *item;
3131 item = g_slice_new0 (GtkIconViewItem);
3133 item->cell_area.width = -1;
3134 item->cell_area.height = -1;
3140 gtk_icon_view_item_free (GtkIconViewItem *item)
3142 g_return_if_fail (item != NULL);
3144 g_slice_free (GtkIconViewItem, item);
3147 static GtkIconViewItem *
3148 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3151 gboolean only_in_cell,
3152 GtkCellRenderer **cell_at_pos)
3157 *cell_at_pos = NULL;
3159 for (items = icon_view->priv->items; items; items = items->next)
3161 GtkIconViewItem *item = items->data;
3162 GdkRectangle *item_area = (GdkRectangle *)item;
3164 if (x >= item_area->x - icon_view->priv->column_spacing/2 &&
3165 x <= item_area->x + item_area->width + icon_view->priv->column_spacing/2 &&
3166 y >= item_area->y - icon_view->priv->row_spacing/2 &&
3167 y <= item_area->y + item_area->height + icon_view->priv->row_spacing/2)
3169 if (only_in_cell || cell_at_pos)
3171 GtkCellRenderer *cell = NULL;
3172 GtkCellAreaContext *context;
3174 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
3175 gtk_icon_view_set_cell_data (icon_view, item);
3177 if (x >= item_area->x && x <= item_area->x + item_area->width &&
3178 y >= item_area->y && y <= item_area->y + item_area->height)
3179 cell = gtk_cell_area_get_cell_at_position (icon_view->priv->cell_area, context,
3180 GTK_WIDGET (icon_view),
3185 *cell_at_pos = cell;
3188 return cell != NULL ? item : NULL;
3199 gtk_icon_view_select_item (GtkIconView *icon_view,
3200 GtkIconViewItem *item)
3202 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3203 g_return_if_fail (item != NULL);
3208 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3210 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3211 gtk_icon_view_unselect_all_internal (icon_view);
3213 item->selected = TRUE;
3215 gtk_icon_view_item_selected_changed (icon_view, item);
3216 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3218 gtk_icon_view_queue_draw_item (icon_view, item);
3223 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3224 GtkIconViewItem *item)
3226 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3227 g_return_if_fail (item != NULL);
3229 if (!item->selected)
3232 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3233 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3236 item->selected = FALSE;
3238 gtk_icon_view_item_selected_changed (icon_view, item);
3239 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3241 gtk_icon_view_queue_draw_item (icon_view, item);
3245 verify_items (GtkIconView *icon_view)
3250 for (items = icon_view->priv->items; items; items = items->next)
3252 GtkIconViewItem *item = items->data;
3254 if (item->index != i)
3255 g_error ("List item does not match its index: "
3256 "item index %d and list index %d\n", item->index, i);
3263 gtk_icon_view_row_changed (GtkTreeModel *model,
3268 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3270 /* ignore changes in branches */
3271 if (gtk_tree_path_get_depth (path) > 1)
3274 /* An icon view subclass might add it's own model and populate
3275 * things at init() time instead of waiting for the constructor()
3278 if (icon_view->priv->cell_area)
3279 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3281 /* Here we can use a "grow-only" strategy for optimization
3282 * and only invalidate a single item and queue a relayout
3283 * instead of invalidating the whole thing.
3285 * For now GtkIconView still cant deal with huge models
3286 * so just invalidate the whole thing when the model
3289 gtk_icon_view_invalidate_sizes (icon_view);
3291 verify_items (icon_view);
3295 gtk_icon_view_row_inserted (GtkTreeModel *model,
3300 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3302 GtkIconViewItem *item;
3303 gboolean iters_persist;
3306 /* ignore changes in branches */
3307 if (gtk_tree_path_get_depth (path) > 1)
3310 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3312 index = gtk_tree_path_get_indices(path)[0];
3314 item = gtk_icon_view_item_new ();
3319 item->index = index;
3321 /* FIXME: We can be more efficient here,
3322 we can store a tail pointer and use that when
3323 appending (which is a rather common operation)
3325 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3328 list = g_list_nth (icon_view->priv->items, index + 1);
3329 for (; list; list = list->next)
3336 verify_items (icon_view);
3338 gtk_icon_view_queue_layout (icon_view);
3342 gtk_icon_view_row_deleted (GtkTreeModel *model,
3346 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3348 GtkIconViewItem *item;
3350 gboolean emit = FALSE;
3352 /* ignore changes in branches */
3353 if (gtk_tree_path_get_depth (path) > 1)
3356 index = gtk_tree_path_get_indices(path)[0];
3358 list = g_list_nth (icon_view->priv->items, index);
3361 if (icon_view->priv->cell_area)
3362 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3364 if (item == icon_view->priv->anchor_item)
3365 icon_view->priv->anchor_item = NULL;
3367 if (item == icon_view->priv->cursor_item)
3368 icon_view->priv->cursor_item = NULL;
3373 gtk_icon_view_item_free (item);
3375 for (next = list->next; next; next = next->next)
3382 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3384 verify_items (icon_view);
3386 gtk_icon_view_queue_layout (icon_view);
3389 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3393 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3394 GtkTreePath *parent,
3399 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3402 GList *items = NULL, *list;
3403 GtkIconViewItem **item_array;
3406 /* ignore changes in branches */
3410 if (icon_view->priv->cell_area)
3411 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
3413 length = gtk_tree_model_iter_n_children (model, NULL);
3415 order = g_new (gint, length);
3416 for (i = 0; i < length; i++)
3417 order [new_order[i]] = i;
3419 item_array = g_new (GtkIconViewItem *, length);
3420 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3421 item_array[order[i]] = list->data;
3424 for (i = length - 1; i >= 0; i--)
3426 item_array[i]->index = i;
3427 items = g_list_prepend (items, item_array[i]);
3430 g_free (item_array);
3431 g_list_free (icon_view->priv->items);
3432 icon_view->priv->items = items;
3434 gtk_icon_view_queue_layout (icon_view);
3436 verify_items (icon_view);
3440 gtk_icon_view_build_items (GtkIconView *icon_view)
3444 gboolean iters_persist;
3445 GList *items = NULL;
3447 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3449 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3457 GtkIconViewItem *item = gtk_icon_view_item_new ();
3466 items = g_list_prepend (items, item);
3468 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3470 icon_view->priv->items = g_list_reverse (items);
3474 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3477 GtkMovementStep step,
3481 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3482 I_("move-cursor"), 2,
3486 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3491 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3494 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3499 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3506 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3507 GtkMovementStep step,
3510 GdkModifierType state;
3512 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3513 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3514 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3515 step == GTK_MOVEMENT_DISPLAY_LINES ||
3516 step == GTK_MOVEMENT_PAGES ||
3517 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3519 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3522 gtk_cell_area_stop_editing (icon_view->priv->cell_area, FALSE);
3523 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3525 if (gtk_get_current_event_state (&state))
3527 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3528 icon_view->priv->ctrl_pressed = TRUE;
3529 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3530 icon_view->priv->shift_pressed = TRUE;
3532 /* else we assume not pressed */
3536 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3537 case GTK_MOVEMENT_VISUAL_POSITIONS:
3538 gtk_icon_view_move_cursor_left_right (icon_view, count);
3540 case GTK_MOVEMENT_DISPLAY_LINES:
3541 gtk_icon_view_move_cursor_up_down (icon_view, count);
3543 case GTK_MOVEMENT_PAGES:
3544 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3546 case GTK_MOVEMENT_BUFFER_ENDS:
3547 gtk_icon_view_move_cursor_start_end (icon_view, count);
3550 g_assert_not_reached ();
3553 icon_view->priv->ctrl_pressed = FALSE;
3554 icon_view->priv->shift_pressed = FALSE;
3556 icon_view->priv->draw_focus = TRUE;
3561 static GtkIconViewItem *
3562 find_item (GtkIconView *icon_view,
3563 GtkIconViewItem *current,
3569 GtkIconViewItem *item;
3571 /* FIXME: this could be more efficient
3573 row = current->row + row_ofs;
3574 col = current->col + col_ofs;
3576 for (items = icon_view->priv->items; items; items = items->next)
3579 if (item->row == row && item->col == col)
3586 static GtkIconViewItem *
3587 find_item_page_up_down (GtkIconView *icon_view,
3588 GtkIconViewItem *current,
3595 y = current->cell_area.y + count * gtk_adjustment_get_page_size (icon_view->priv->vadjustment);
3597 item = g_list_find (icon_view->priv->items, current);
3602 for (next = item->next; next; next = next->next)
3604 if (((GtkIconViewItem *)next->data)->col == col)
3607 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y > y)
3617 for (next = item->prev; next; next = next->prev)
3619 if (((GtkIconViewItem *)next->data)->col == col)
3622 if (!next || ((GtkIconViewItem *)next->data)->cell_area.y < y)
3636 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3637 GtkIconViewItem *anchor,
3638 GtkIconViewItem *cursor)
3641 GtkIconViewItem *item;
3642 gint row1, row2, col1, col2;
3643 gboolean dirty = FALSE;
3645 if (anchor->row < cursor->row)
3656 if (anchor->col < cursor->col)
3667 for (items = icon_view->priv->items; items; items = items->next)
3671 if (row1 <= item->row && item->row <= row2 &&
3672 col1 <= item->col && item->col <= col2)
3674 if (!item->selected)
3677 item->selected = TRUE;
3678 gtk_icon_view_item_selected_changed (icon_view, item);
3680 gtk_icon_view_queue_draw_item (icon_view, item);
3688 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3691 GtkIconViewItem *item;
3692 GtkCellRenderer *cell;
3693 gboolean dirty = FALSE;
3695 GtkDirectionType direction;
3697 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3700 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
3702 if (!icon_view->priv->cursor_item)
3707 list = icon_view->priv->items;
3709 list = g_list_last (icon_view->priv->items);
3711 item = list ? list->data : NULL;
3713 /* Give focus to the first cell initially */
3714 gtk_icon_view_set_cell_data (icon_view, item);
3715 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3719 item = icon_view->priv->cursor_item;
3720 step = count > 0 ? 1 : -1;
3722 /* Save the current focus cell in case we hit the edge */
3723 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3727 gtk_icon_view_set_cell_data (icon_view, item);
3729 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3732 item = find_item (icon_view, item, step, 0);
3738 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3740 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3742 gtk_widget_child_focus (toplevel,
3743 direction == GTK_DIR_UP ?
3744 GTK_DIR_TAB_BACKWARD :
3745 GTK_DIR_TAB_FORWARD);
3749 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3753 if (icon_view->priv->ctrl_pressed ||
3754 !icon_view->priv->shift_pressed ||
3755 !icon_view->priv->anchor_item ||
3756 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3757 icon_view->priv->anchor_item = item;
3759 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3760 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3762 if (!icon_view->priv->ctrl_pressed &&
3763 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3765 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3766 dirty = gtk_icon_view_select_all_between (icon_view,
3767 icon_view->priv->anchor_item,
3771 gtk_icon_view_scroll_to_item (icon_view, item);
3774 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3778 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3781 GtkIconViewItem *item;
3782 gboolean dirty = FALSE;
3784 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3787 if (!icon_view->priv->cursor_item)
3792 list = icon_view->priv->items;
3794 list = g_list_last (icon_view->priv->items);
3796 item = list ? list->data : NULL;
3799 item = find_item_page_up_down (icon_view,
3800 icon_view->priv->cursor_item,
3803 if (item == icon_view->priv->cursor_item)
3804 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3809 if (icon_view->priv->ctrl_pressed ||
3810 !icon_view->priv->shift_pressed ||
3811 !icon_view->priv->anchor_item ||
3812 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3813 icon_view->priv->anchor_item = item;
3815 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3817 if (!icon_view->priv->ctrl_pressed &&
3818 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3820 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3821 dirty = gtk_icon_view_select_all_between (icon_view,
3822 icon_view->priv->anchor_item,
3826 gtk_icon_view_scroll_to_item (icon_view, item);
3829 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3833 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3836 GtkIconViewItem *item;
3837 GtkCellRenderer *cell = NULL;
3838 gboolean dirty = FALSE;
3840 GtkDirectionType direction;
3842 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3845 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
3847 if (!icon_view->priv->cursor_item)
3852 list = icon_view->priv->items;
3854 list = g_list_last (icon_view->priv->items);
3856 item = list ? list->data : NULL;
3858 /* Give focus to the first cell initially */
3859 gtk_icon_view_set_cell_data (icon_view, item);
3860 gtk_cell_area_focus (icon_view->priv->cell_area, direction);
3864 item = icon_view->priv->cursor_item;
3865 step = count > 0 ? 1 : -1;
3867 /* Save the current focus cell in case we hit the edge */
3868 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3872 gtk_icon_view_set_cell_data (icon_view, item);
3874 if (gtk_cell_area_focus (icon_view->priv->cell_area, direction))
3877 item = find_item (icon_view, item, 0, step);
3883 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
3885 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
3887 gtk_widget_child_focus (toplevel,
3888 direction == GTK_DIR_LEFT ?
3889 GTK_DIR_TAB_BACKWARD :
3890 GTK_DIR_TAB_FORWARD);
3894 gtk_cell_area_set_focus_cell (icon_view->priv->cell_area, cell);
3898 if (icon_view->priv->ctrl_pressed ||
3899 !icon_view->priv->shift_pressed ||
3900 !icon_view->priv->anchor_item ||
3901 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3902 icon_view->priv->anchor_item = item;
3904 cell = gtk_cell_area_get_focus_cell (icon_view->priv->cell_area);
3905 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3907 if (!icon_view->priv->ctrl_pressed &&
3908 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3910 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3911 dirty = gtk_icon_view_select_all_between (icon_view,
3912 icon_view->priv->anchor_item,
3916 gtk_icon_view_scroll_to_item (icon_view, item);
3919 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3923 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3926 GtkIconViewItem *item;
3928 gboolean dirty = FALSE;
3930 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3934 list = icon_view->priv->items;
3936 list = g_list_last (icon_view->priv->items);
3938 item = list ? list->data : NULL;
3940 if (item == icon_view->priv->cursor_item)
3941 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3946 if (icon_view->priv->ctrl_pressed ||
3947 !icon_view->priv->shift_pressed ||
3948 !icon_view->priv->anchor_item ||
3949 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3950 icon_view->priv->anchor_item = item;
3952 gtk_icon_view_set_cursor_item (icon_view, item, NULL);
3954 if (!icon_view->priv->ctrl_pressed &&
3955 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3957 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3958 dirty = gtk_icon_view_select_all_between (icon_view,
3959 icon_view->priv->anchor_item,
3963 gtk_icon_view_scroll_to_item (icon_view, item);
3966 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3970 * gtk_icon_view_scroll_to_path:
3971 * @icon_view: A #GtkIconView.
3972 * @path: The path of the item to move to.
3973 * @use_align: whether to use alignment arguments, or %FALSE.
3974 * @row_align: The vertical alignment of the item specified by @path.
3975 * @col_align: The horizontal alignment of the item specified by @path.
3977 * Moves the alignments of @icon_view to the position specified by @path.
3978 * @row_align determines where the row is placed, and @col_align determines
3979 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3980 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3983 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3984 * tree does the minimum amount of work to scroll the item onto the screen.
3985 * This means that the item will be scrolled to the edge closest to its current
3986 * position. If the item is currently visible on the screen, nothing is done.
3988 * This function only works if the model is set, and @path is a valid row on
3989 * the model. If the model changes before the @icon_view is realized, the
3990 * centered path will be modified to reflect this change.
3995 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4001 GtkIconViewItem *item = NULL;
4004 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4005 g_return_if_fail (path != NULL);
4006 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4007 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4009 widget = GTK_WIDGET (icon_view);
4011 if (gtk_tree_path_get_depth (path) > 0)
4012 item = g_list_nth_data (icon_view->priv->items,
4013 gtk_tree_path_get_indices(path)[0]);
4015 if (!item || item->cell_area.width < 0 ||
4016 !gtk_widget_get_realized (widget))
4018 if (icon_view->priv->scroll_to_path)
4019 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4021 icon_view->priv->scroll_to_path = NULL;
4024 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4026 icon_view->priv->scroll_to_use_align = use_align;
4027 icon_view->priv->scroll_to_row_align = row_align;
4028 icon_view->priv->scroll_to_col_align = col_align;
4035 GtkAllocation allocation;
4038 GdkRectangle item_area =
4040 item->cell_area.x - icon_view->priv->item_padding,
4041 item->cell_area.y - icon_view->priv->item_padding,
4042 item->cell_area.width + icon_view->priv->item_padding * 2,
4043 item->cell_area.height + icon_view->priv->item_padding * 2
4046 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4048 gtk_widget_get_allocation (widget, &allocation);
4050 offset = y + item_area.y - row_align * (allocation.height - item_area.height);
4052 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4053 gtk_adjustment_get_value (icon_view->priv->vadjustment) + offset);
4055 offset = x + item_area.x - col_align * (allocation.width - item_area.width);
4057 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4058 gtk_adjustment_get_value (icon_view->priv->hadjustment) + offset);
4060 gtk_adjustment_changed (icon_view->priv->hadjustment);
4061 gtk_adjustment_changed (icon_view->priv->vadjustment);
4064 gtk_icon_view_scroll_to_item (icon_view, item);
4069 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4070 GtkIconViewItem *item)
4072 GtkIconViewPrivate *priv = icon_view->priv;
4073 GtkWidget *widget = GTK_WIDGET (icon_view);
4074 GtkAdjustment *hadj, *vadj;
4075 GtkAllocation allocation;
4077 GdkRectangle item_area;
4079 item_area.x = item->cell_area.x - priv->item_padding;
4080 item_area.y = item->cell_area.y - priv->item_padding;
4081 item_area.width = item->cell_area.width + priv->item_padding * 2;
4082 item_area.height = item->cell_area.height + priv->item_padding * 2;
4084 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4085 gtk_widget_get_allocation (widget, &allocation);
4087 hadj = icon_view->priv->hadjustment;
4088 vadj = icon_view->priv->vadjustment;
4090 if (y + item_area.y < 0)
4091 gtk_adjustment_set_value (vadj,
4092 gtk_adjustment_get_value (vadj)
4094 else if (y + item_area.y + item_area.height > allocation.height)
4095 gtk_adjustment_set_value (vadj,
4096 gtk_adjustment_get_value (vadj)
4097 + y + item_area.y + item_area.height - allocation.height);
4099 if (x + item_area.x < 0)
4100 gtk_adjustment_set_value (hadj,
4101 gtk_adjustment_get_value (hadj)
4103 else if (x + item_area.x + item_area.width > allocation.width)
4104 gtk_adjustment_set_value (hadj,
4105 gtk_adjustment_get_value (hadj)
4106 + x + item_area.x + item_area.width - allocation.width);
4108 gtk_adjustment_changed (hadj);
4109 gtk_adjustment_changed (vadj);
4112 /* GtkCellLayout implementation */
4115 gtk_icon_view_ensure_cell_area (GtkIconView *icon_view,
4116 GtkCellArea *cell_area)
4118 GtkIconViewPrivate *priv = icon_view->priv;
4120 if (priv->cell_area)
4124 priv->cell_area = cell_area;
4126 priv->cell_area = gtk_cell_area_box_new ();
4128 g_object_ref_sink (priv->cell_area);
4130 if (GTK_IS_ORIENTABLE (priv->cell_area))
4131 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->cell_area), priv->item_orientation);
4133 priv->cell_area_context = gtk_cell_area_create_context (priv->cell_area);
4135 priv->add_editable_id =
4136 g_signal_connect (priv->cell_area, "add-editable",
4137 G_CALLBACK (gtk_icon_view_add_editable), icon_view);
4138 priv->remove_editable_id =
4139 g_signal_connect (priv->cell_area, "remove-editable",
4140 G_CALLBACK (gtk_icon_view_remove_editable), icon_view);
4141 priv->context_changed_id =
4142 g_signal_connect (priv->cell_area_context, "notify",
4143 G_CALLBACK (gtk_icon_view_context_changed), icon_view);
4145 update_text_cell (icon_view);
4146 update_pixbuf_cell (icon_view);
4149 static GtkCellArea *
4150 gtk_icon_view_cell_layout_get_area (GtkCellLayout *cell_layout)
4152 GtkIconView *icon_view = GTK_ICON_VIEW (cell_layout);
4153 GtkIconViewPrivate *priv = icon_view->priv;
4155 if (G_UNLIKELY (!priv->cell_area))
4156 gtk_icon_view_ensure_cell_area (icon_view, NULL);
4158 return icon_view->priv->cell_area;
4162 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4163 GtkIconViewItem *item)
4165 gboolean iters_persist;
4168 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4174 path = gtk_tree_path_new_from_indices (item->index, -1);
4175 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4177 gtk_tree_path_free (path);
4182 gtk_cell_area_apply_attributes (icon_view->priv->cell_area,
4183 icon_view->priv->model,
4184 &iter, FALSE, FALSE);
4193 * gtk_icon_view_new:
4195 * Creates a new #GtkIconView widget
4197 * Return value: A newly created #GtkIconView widget
4202 gtk_icon_view_new (void)
4204 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4208 * gtk_icon_view_new_with_area:
4209 * @area: the #GtkCellArea to use to layout cells
4211 * Creates a new #GtkIconView widget using the
4212 * specified @area to layout cells inside the icons.
4214 * Return value: A newly created #GtkIconView widget
4219 gtk_icon_view_new_with_area (GtkCellArea *area)
4221 return g_object_new (GTK_TYPE_ICON_VIEW, "cell-area", area, NULL);
4225 * gtk_icon_view_new_with_model:
4226 * @model: The model.
4228 * Creates a new #GtkIconView widget with the model @model.
4230 * Return value: A newly created #GtkIconView widget.
4235 gtk_icon_view_new_with_model (GtkTreeModel *model)
4237 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4241 * gtk_icon_view_convert_widget_to_bin_window_coords:
4242 * @icon_view: a #GtkIconView
4243 * @wx: X coordinate relative to the widget
4244 * @wy: Y coordinate relative to the widget
4245 * @bx: (out): return location for bin_window X coordinate
4246 * @by: (out): return location for bin_window Y coordinate
4248 * Converts widget coordinates to coordinates for the bin_window,
4249 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4254 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4262 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4264 if (icon_view->priv->bin_window)
4265 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4276 * gtk_icon_view_get_path_at_pos:
4277 * @icon_view: A #GtkIconView.
4278 * @x: The x position to be identified
4279 * @y: The y position to be identified
4281 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4282 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4283 * the cell at the specified position.
4284 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4285 * widget coordinates to bin_window coordinates.
4287 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4288 * if no icon exists at that position.
4293 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4297 GtkIconViewItem *item;
4300 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4302 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4307 path = gtk_tree_path_new_from_indices (item->index, -1);
4313 * gtk_icon_view_get_item_at_pos:
4314 * @icon_view: A #GtkIconView.
4315 * @x: The x position to be identified
4316 * @y: The y position to be identified
4317 * @path: (out) (allow-none): Return location for the path, or %NULL
4318 * @cell: (out) (allow-none): Return location for the renderer
4319 * responsible for the cell at (@x, @y), or %NULL
4321 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4322 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4323 * obtains the cell at the specified position. The returned path should
4324 * be freed with gtk_tree_path_free().
4325 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4326 * widget coordinates to bin_window coordinates.
4328 * Return value: %TRUE if an item exists at the specified position
4333 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4337 GtkCellRenderer **cell)
4339 GtkIconViewItem *item;
4340 GtkCellRenderer *renderer = NULL;
4342 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4344 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &renderer);
4349 *path = gtk_tree_path_new_from_indices (item->index, -1);
4357 return (item != NULL);
4361 * gtk_icon_view_set_tooltip_item:
4362 * @icon_view: a #GtkIconView
4363 * @tooltip: a #GtkTooltip
4364 * @path: a #GtkTreePath
4366 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4367 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4368 * See also gtk_tooltip_set_tip_area().
4373 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4374 GtkTooltip *tooltip,
4377 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4378 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4380 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4384 * gtk_icon_view_set_tooltip_cell:
4385 * @icon_view: a #GtkIconView
4386 * @tooltip: a #GtkTooltip
4387 * @path: a #GtkTreePath
4388 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4390 * Sets the tip area of @tooltip to the area which @cell occupies in
4391 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4393 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4398 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4399 GtkTooltip *tooltip,
4401 GtkCellRenderer *cell)
4404 GtkIconViewItem *item = NULL;
4407 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4408 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4409 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4411 if (gtk_tree_path_get_depth (path) > 0)
4412 item = g_list_nth_data (icon_view->priv->items,
4413 gtk_tree_path_get_indices(path)[0]);
4420 GtkCellAreaContext *context;
4422 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
4423 gtk_icon_view_set_cell_data (icon_view, item);
4424 gtk_cell_area_get_cell_allocation (icon_view->priv->cell_area, context,
4425 GTK_WIDGET (icon_view),
4426 cell, (GdkRectangle *)item, &rect);
4430 rect.x = item->cell_area.x - icon_view->priv->item_padding;
4431 rect.y = item->cell_area.y - icon_view->priv->item_padding;
4432 rect.width = item->cell_area.width + icon_view->priv->item_padding * 2;
4433 rect.height = item->cell_area.height + icon_view->priv->item_padding * 2;
4436 if (icon_view->priv->bin_window)
4438 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4443 gtk_tooltip_set_tip_area (tooltip, &rect);
4448 * gtk_icon_view_get_tooltip_context:
4449 * @icon_view: an #GtkIconView
4450 * @x: (inout): the x coordinate (relative to widget coordinates)
4451 * @y: (inout): the y coordinate (relative to widget coordinates)
4452 * @keyboard_tip: whether this is a keyboard tooltip or not
4453 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4454 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4455 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4457 * This function is supposed to be used in a #GtkWidget::query-tooltip
4458 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4459 * which are received in the signal handler, should be passed to this
4460 * function without modification.
4462 * The return value indicates whether there is an icon view item at the given
4463 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4464 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4465 * @model, @path and @iter which have been provided will be set to point to
4466 * that row and the corresponding model. @x and @y will always be converted
4467 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4469 * Return value: whether or not the given tooltip context points to a item
4474 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4477 gboolean keyboard_tip,
4478 GtkTreeModel **model,
4482 GtkTreePath *tmppath = NULL;
4484 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4485 g_return_val_if_fail (x != NULL, FALSE);
4486 g_return_val_if_fail (y != NULL, FALSE);
4490 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4497 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4500 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4505 *model = gtk_icon_view_get_model (icon_view);
4508 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4514 gtk_tree_path_free (tmppath);
4520 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4523 gboolean keyboard_tip,
4524 GtkTooltip *tooltip,
4530 GtkTreeModel *model;
4531 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4533 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4536 &model, &path, &iter))
4539 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4543 gtk_tree_path_free (path);
4547 gtk_tooltip_set_markup (tooltip, str);
4548 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4550 gtk_tree_path_free (path);
4558 * gtk_icon_view_set_tooltip_column:
4559 * @icon_view: a #GtkIconView
4560 * @column: an integer, which is a valid column number for @icon_view's model
4562 * If you only plan to have simple (text-only) tooltips on full items, you
4563 * can use this function to have #GtkIconView handle these automatically
4564 * for you. @column should be set to the column in @icon_view's model
4565 * containing the tooltip texts, or -1 to disable this feature.
4567 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4568 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4570 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
4571 * so &, <, etc have to be escaped in the text.
4576 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4579 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4581 if (column == icon_view->priv->tooltip_column)
4586 g_signal_handlers_disconnect_by_func (icon_view,
4587 gtk_icon_view_set_tooltip_query_cb,
4589 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4593 if (icon_view->priv->tooltip_column == -1)
4595 g_signal_connect (icon_view, "query-tooltip",
4596 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4597 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4601 icon_view->priv->tooltip_column = column;
4602 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4606 * gtk_icon_view_get_tooltip_column:
4607 * @icon_view: a #GtkIconView
4609 * Returns the column of @icon_view's model which is being used for
4610 * displaying tooltips on @icon_view's rows.
4612 * Return value: the index of the tooltip column that is currently being
4613 * used, or -1 if this is disabled.
4618 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4620 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4622 return icon_view->priv->tooltip_column;
4626 * gtk_icon_view_get_visible_range:
4627 * @icon_view: A #GtkIconView
4628 * @start_path: (out) (allow-none): Return location for start of region,
4630 * @end_path: (out) (allow-none): Return location for end of region, or %NULL
4632 * Sets @start_path and @end_path to be the first and last visible path.
4633 * Note that there may be invisible paths in between.
4635 * Both paths should be freed with gtk_tree_path_free() after use.
4637 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4642 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4643 GtkTreePath **start_path,
4644 GtkTreePath **end_path)
4646 gint start_index = -1;
4647 gint end_index = -1;
4650 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4652 if (icon_view->priv->hadjustment == NULL ||
4653 icon_view->priv->vadjustment == NULL)
4656 if (start_path == NULL && end_path == NULL)
4659 for (icons = icon_view->priv->items; icons; icons = icons->next)
4661 GtkIconViewItem *item = icons->data;
4662 GdkRectangle *item_area = (GdkRectangle *)item;
4664 if ((item_area->x + item_area->width >= (int)gtk_adjustment_get_value (icon_view->priv->hadjustment)) &&
4665 (item_area->y + item_area->height >= (int)gtk_adjustment_get_value (icon_view->priv->vadjustment)) &&
4667 (int) (gtk_adjustment_get_value (icon_view->priv->hadjustment) +
4668 gtk_adjustment_get_page_size (icon_view->priv->hadjustment))) &&
4670 (int) (gtk_adjustment_get_value (icon_view->priv->vadjustment) +
4671 gtk_adjustment_get_page_size (icon_view->priv->vadjustment))))
4673 if (start_index == -1)
4674 start_index = item->index;
4675 end_index = item->index;
4679 if (start_path && start_index != -1)
4680 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4681 if (end_path && end_index != -1)
4682 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4684 return start_index != -1;
4688 * gtk_icon_view_selected_foreach:
4689 * @icon_view: A #GtkIconView.
4690 * @func: (scope call): The function to call for each selected icon.
4691 * @data: User data to pass to the function.
4693 * Calls a function for each selected icon. Note that the model or
4694 * selection cannot be modified from within this function.
4699 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4700 GtkIconViewForeachFunc func,
4705 for (list = icon_view->priv->items; list; list = list->next)
4707 GtkIconViewItem *item = list->data;
4708 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4711 (* func) (icon_view, path, data);
4713 gtk_tree_path_free (path);
4718 * gtk_icon_view_set_selection_mode:
4719 * @icon_view: A #GtkIconView.
4720 * @mode: The selection mode
4722 * Sets the selection mode of the @icon_view.
4727 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4728 GtkSelectionMode mode)
4730 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4732 if (mode == icon_view->priv->selection_mode)
4735 if (mode == GTK_SELECTION_NONE ||
4736 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4737 gtk_icon_view_unselect_all (icon_view);
4739 icon_view->priv->selection_mode = mode;
4741 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4745 * gtk_icon_view_get_selection_mode:
4746 * @icon_view: A #GtkIconView.
4748 * Gets the selection mode of the @icon_view.
4750 * Return value: the current selection mode
4755 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4757 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4759 return icon_view->priv->selection_mode;
4763 * gtk_icon_view_set_model:
4764 * @icon_view: A #GtkIconView.
4765 * @model: (allow-none): The model.
4767 * Sets the model for a #GtkIconView.
4768 * If the @icon_view already has a model set, it will remove
4769 * it before setting the new model. If @model is %NULL, then
4770 * it will unset the old model.
4775 gtk_icon_view_set_model (GtkIconView *icon_view,
4776 GtkTreeModel *model)
4778 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4779 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4781 if (icon_view->priv->model == model)
4784 if (icon_view->priv->scroll_to_path)
4786 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4787 icon_view->priv->scroll_to_path = NULL;
4790 /* The area can be NULL while disposing */
4791 if (icon_view->priv->cell_area)
4792 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
4798 if (icon_view->priv->pixbuf_column != -1)
4800 column_type = gtk_tree_model_get_column_type (model,
4801 icon_view->priv->pixbuf_column);
4803 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4806 if (icon_view->priv->text_column != -1)
4808 column_type = gtk_tree_model_get_column_type (model,
4809 icon_view->priv->text_column);
4811 g_return_if_fail (column_type == G_TYPE_STRING);
4814 if (icon_view->priv->markup_column != -1)
4816 column_type = gtk_tree_model_get_column_type (model,
4817 icon_view->priv->markup_column);
4819 g_return_if_fail (column_type == G_TYPE_STRING);
4824 if (icon_view->priv->model)
4826 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4827 gtk_icon_view_row_changed,
4829 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4830 gtk_icon_view_row_inserted,
4832 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4833 gtk_icon_view_row_deleted,
4835 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4836 gtk_icon_view_rows_reordered,
4839 g_object_unref (icon_view->priv->model);
4841 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4842 g_list_free (icon_view->priv->items);
4843 icon_view->priv->items = NULL;
4844 icon_view->priv->anchor_item = NULL;
4845 icon_view->priv->cursor_item = NULL;
4846 icon_view->priv->last_single_clicked = NULL;
4847 icon_view->priv->width = 0;
4848 icon_view->priv->height = 0;
4851 icon_view->priv->model = model;
4853 if (icon_view->priv->model)
4855 g_object_ref (icon_view->priv->model);
4856 g_signal_connect (icon_view->priv->model,
4858 G_CALLBACK (gtk_icon_view_row_changed),
4860 g_signal_connect (icon_view->priv->model,
4862 G_CALLBACK (gtk_icon_view_row_inserted),
4864 g_signal_connect (icon_view->priv->model,
4866 G_CALLBACK (gtk_icon_view_row_deleted),
4868 g_signal_connect (icon_view->priv->model,
4870 G_CALLBACK (gtk_icon_view_rows_reordered),
4873 gtk_icon_view_build_items (icon_view);
4875 gtk_icon_view_queue_layout (icon_view);
4878 g_object_notify (G_OBJECT (icon_view), "model");
4880 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4881 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4885 * gtk_icon_view_get_model:
4886 * @icon_view: a #GtkIconView
4888 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4891 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
4892 * currently being used.
4897 gtk_icon_view_get_model (GtkIconView *icon_view)
4899 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4901 return icon_view->priv->model;
4905 update_text_cell (GtkIconView *icon_view)
4907 if (!icon_view->priv->cell_area)
4910 if (icon_view->priv->text_column == -1 &&
4911 icon_view->priv->markup_column == -1)
4913 if (icon_view->priv->text_cell != NULL)
4915 gtk_cell_area_remove (icon_view->priv->cell_area,
4916 icon_view->priv->text_cell);
4917 icon_view->priv->text_cell = NULL;
4922 if (icon_view->priv->text_cell == NULL)
4924 icon_view->priv->text_cell = gtk_cell_renderer_text_new ();
4926 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), icon_view->priv->text_cell, FALSE);
4929 if (icon_view->priv->markup_column != -1)
4930 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4931 icon_view->priv->text_cell,
4932 "markup", icon_view->priv->markup_column,
4935 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4936 icon_view->priv->text_cell,
4937 "text", icon_view->priv->text_column,
4940 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4941 g_object_set (icon_view->priv->text_cell,
4942 "alignment", PANGO_ALIGN_CENTER,
4943 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4948 g_object_set (icon_view->priv->text_cell,
4949 "alignment", PANGO_ALIGN_LEFT,
4950 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4958 update_pixbuf_cell (GtkIconView *icon_view)
4960 if (!icon_view->priv->cell_area)
4963 if (icon_view->priv->pixbuf_column == -1)
4965 if (icon_view->priv->pixbuf_cell != NULL)
4967 gtk_cell_area_remove (icon_view->priv->cell_area,
4968 icon_view->priv->pixbuf_cell);
4970 icon_view->priv->pixbuf_cell = NULL;
4975 if (icon_view->priv->pixbuf_cell == NULL)
4977 icon_view->priv->pixbuf_cell = gtk_cell_renderer_pixbuf_new ();
4979 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), icon_view->priv->pixbuf_cell, FALSE);
4982 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4983 icon_view->priv->pixbuf_cell,
4984 "pixbuf", icon_view->priv->pixbuf_column,
4987 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
4988 g_object_set (icon_view->priv->pixbuf_cell,
4993 g_object_set (icon_view->priv->pixbuf_cell,
5001 * gtk_icon_view_set_text_column:
5002 * @icon_view: A #GtkIconView.
5003 * @column: A column in the currently used model, or -1 to display no text
5005 * Sets the column with text for @icon_view to be @column. The text
5006 * column must be of type #G_TYPE_STRING.
5011 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5014 if (column == icon_view->priv->text_column)
5018 icon_view->priv->text_column = -1;
5021 if (icon_view->priv->model != NULL)
5025 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5027 g_return_if_fail (column_type == G_TYPE_STRING);
5030 icon_view->priv->text_column = column;
5033 if (icon_view->priv->cell_area)
5034 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5036 update_text_cell (icon_view);
5038 gtk_icon_view_invalidate_sizes (icon_view);
5040 g_object_notify (G_OBJECT (icon_view), "text-column");
5044 * gtk_icon_view_get_text_column:
5045 * @icon_view: A #GtkIconView.
5047 * Returns the column with text for @icon_view.
5049 * Returns: the text column, or -1 if it's unset.
5054 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5056 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5058 return icon_view->priv->text_column;
5062 * gtk_icon_view_set_markup_column:
5063 * @icon_view: A #GtkIconView.
5064 * @column: A column in the currently used model, or -1 to display no text
5066 * Sets the column with markup information for @icon_view to be
5067 * @column. The markup column must be of type #G_TYPE_STRING.
5068 * If the markup column is set to something, it overrides
5069 * the text column set by gtk_icon_view_set_text_column().
5074 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5077 if (column == icon_view->priv->markup_column)
5081 icon_view->priv->markup_column = -1;
5084 if (icon_view->priv->model != NULL)
5088 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5090 g_return_if_fail (column_type == G_TYPE_STRING);
5093 icon_view->priv->markup_column = column;
5096 if (icon_view->priv->cell_area)
5097 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5099 update_text_cell (icon_view);
5101 gtk_icon_view_invalidate_sizes (icon_view);
5103 g_object_notify (G_OBJECT (icon_view), "markup-column");
5107 * gtk_icon_view_get_markup_column:
5108 * @icon_view: A #GtkIconView.
5110 * Returns the column with markup text for @icon_view.
5112 * Returns: the markup column, or -1 if it's unset.
5117 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5119 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5121 return icon_view->priv->markup_column;
5125 * gtk_icon_view_set_pixbuf_column:
5126 * @icon_view: A #GtkIconView.
5127 * @column: A column in the currently used model, or -1 to disable
5129 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5130 * column must be of type #GDK_TYPE_PIXBUF
5135 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5138 if (column == icon_view->priv->pixbuf_column)
5142 icon_view->priv->pixbuf_column = -1;
5145 if (icon_view->priv->model != NULL)
5149 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5151 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5154 icon_view->priv->pixbuf_column = column;
5157 if (icon_view->priv->cell_area)
5158 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5160 update_pixbuf_cell (icon_view);
5162 gtk_icon_view_invalidate_sizes (icon_view);
5164 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5169 * gtk_icon_view_get_pixbuf_column:
5170 * @icon_view: A #GtkIconView.
5172 * Returns the column with pixbufs for @icon_view.
5174 * Returns: the pixbuf column, or -1 if it's unset.
5179 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5181 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5183 return icon_view->priv->pixbuf_column;
5187 * gtk_icon_view_select_path:
5188 * @icon_view: A #GtkIconView.
5189 * @path: The #GtkTreePath to be selected.
5191 * Selects the row at @path.
5196 gtk_icon_view_select_path (GtkIconView *icon_view,
5199 GtkIconViewItem *item = NULL;
5201 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5202 g_return_if_fail (icon_view->priv->model != NULL);
5203 g_return_if_fail (path != NULL);
5205 if (gtk_tree_path_get_depth (path) > 0)
5206 item = g_list_nth_data (icon_view->priv->items,
5207 gtk_tree_path_get_indices(path)[0]);
5210 gtk_icon_view_select_item (icon_view, item);
5214 * gtk_icon_view_unselect_path:
5215 * @icon_view: A #GtkIconView.
5216 * @path: The #GtkTreePath to be unselected.
5218 * Unselects the row at @path.
5223 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5226 GtkIconViewItem *item;
5228 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5229 g_return_if_fail (icon_view->priv->model != NULL);
5230 g_return_if_fail (path != NULL);
5232 item = g_list_nth_data (icon_view->priv->items,
5233 gtk_tree_path_get_indices(path)[0]);
5238 gtk_icon_view_unselect_item (icon_view, item);
5242 * gtk_icon_view_get_selected_items:
5243 * @icon_view: A #GtkIconView.
5245 * Creates a list of paths of all selected items. Additionally, if you are
5246 * planning on modifying the model after calling this function, you may
5247 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5248 * To do this, you can use gtk_tree_row_reference_new().
5250 * To free the return value, use:
5252 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5253 * g_list_free (list);
5256 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5261 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5264 GList *selected = NULL;
5266 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5268 for (list = icon_view->priv->items; list != NULL; list = list->next)
5270 GtkIconViewItem *item = list->data;
5274 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5276 selected = g_list_prepend (selected, path);
5284 * gtk_icon_view_select_all:
5285 * @icon_view: A #GtkIconView.
5287 * Selects all the icons. @icon_view must has its selection mode set
5288 * to #GTK_SELECTION_MULTIPLE.
5293 gtk_icon_view_select_all (GtkIconView *icon_view)
5296 gboolean dirty = FALSE;
5298 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5300 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5303 for (items = icon_view->priv->items; items; items = items->next)
5305 GtkIconViewItem *item = items->data;
5307 if (!item->selected)
5310 item->selected = TRUE;
5311 gtk_icon_view_queue_draw_item (icon_view, item);
5316 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5320 * gtk_icon_view_unselect_all:
5321 * @icon_view: A #GtkIconView.
5323 * Unselects all the icons.
5328 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5330 gboolean dirty = FALSE;
5332 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5334 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5337 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5340 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5344 * gtk_icon_view_path_is_selected:
5345 * @icon_view: A #GtkIconView.
5346 * @path: A #GtkTreePath to check selection on.
5348 * Returns %TRUE if the icon pointed to by @path is currently
5349 * selected. If @path does not point to a valid location, %FALSE is returned.
5351 * Return value: %TRUE if @path is selected.
5356 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5359 GtkIconViewItem *item;
5361 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5362 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5363 g_return_val_if_fail (path != NULL, FALSE);
5365 item = g_list_nth_data (icon_view->priv->items,
5366 gtk_tree_path_get_indices(path)[0]);
5371 return item->selected;
5375 * gtk_icon_view_get_item_row:
5376 * @icon_view: a #GtkIconView
5377 * @path: the #GtkTreePath of the item
5379 * Gets the row in which the item @path is currently
5380 * displayed. Row numbers start at 0.
5382 * Returns: The row in which the item is displayed
5387 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5390 GtkIconViewItem *item;
5392 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5393 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5394 g_return_val_if_fail (path != NULL, -1);
5396 item = g_list_nth_data (icon_view->priv->items,
5397 gtk_tree_path_get_indices(path)[0]);
5406 * gtk_icon_view_get_item_column:
5407 * @icon_view: a #GtkIconView
5408 * @path: the #GtkTreePath of the item
5410 * Gets the column in which the item @path is currently
5411 * displayed. Column numbers start at 0.
5413 * Returns: The column in which the item is displayed
5418 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5421 GtkIconViewItem *item;
5423 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5424 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5425 g_return_val_if_fail (path != NULL, -1);
5427 item = g_list_nth_data (icon_view->priv->items,
5428 gtk_tree_path_get_indices(path)[0]);
5437 * gtk_icon_view_item_activated:
5438 * @icon_view: A #GtkIconView
5439 * @path: The #GtkTreePath to be activated
5441 * Activates the item determined by @path.
5446 gtk_icon_view_item_activated (GtkIconView *icon_view,
5449 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5450 g_return_if_fail (path != NULL);
5452 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5456 * gtk_icon_view_set_item_orientation:
5457 * @icon_view: a #GtkIconView
5458 * @orientation: the relative position of texts and icons
5460 * Sets the ::item-orientation property which determines whether the labels
5461 * are drawn beside the icons instead of below.
5466 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
5467 GtkOrientation orientation)
5469 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5471 if (icon_view->priv->item_orientation != orientation)
5473 icon_view->priv->item_orientation = orientation;
5475 if (icon_view->priv->cell_area)
5477 if (GTK_IS_ORIENTABLE (icon_view->priv->cell_area))
5478 gtk_orientable_set_orientation (GTK_ORIENTABLE (icon_view->priv->cell_area),
5479 icon_view->priv->item_orientation);
5481 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5484 gtk_icon_view_invalidate_sizes (icon_view);
5486 update_text_cell (icon_view);
5487 update_pixbuf_cell (icon_view);
5489 g_object_notify (G_OBJECT (icon_view), "item-orientation");
5494 * gtk_icon_view_get_item_orientation:
5495 * @icon_view: a #GtkIconView
5497 * Returns the value of the ::item-orientation property which determines
5498 * whether the labels are drawn beside the icons instead of below.
5500 * Return value: the relative position of texts and icons
5505 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
5507 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5508 GTK_ORIENTATION_VERTICAL);
5510 return icon_view->priv->item_orientation;
5514 * gtk_icon_view_set_columns:
5515 * @icon_view: a #GtkIconView
5516 * @columns: the number of columns
5518 * Sets the ::columns property which determines in how
5519 * many columns the icons are arranged. If @columns is
5520 * -1, the number of columns will be chosen automatically
5521 * to fill the available area.
5526 gtk_icon_view_set_columns (GtkIconView *icon_view,
5529 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5531 if (icon_view->priv->columns != columns)
5533 icon_view->priv->columns = columns;
5535 if (icon_view->priv->cell_area)
5536 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5538 gtk_icon_view_queue_layout (icon_view);
5540 g_object_notify (G_OBJECT (icon_view), "columns");
5545 * gtk_icon_view_get_columns:
5546 * @icon_view: a #GtkIconView
5548 * Returns the value of the ::columns property.
5550 * Return value: the number of columns, or -1
5555 gtk_icon_view_get_columns (GtkIconView *icon_view)
5557 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5559 return icon_view->priv->columns;
5563 * gtk_icon_view_set_item_width:
5564 * @icon_view: a #GtkIconView
5565 * @item_width: the width for each item
5567 * Sets the ::item-width property which specifies the width
5568 * to use for each item. If it is set to -1, the icon view will
5569 * automatically determine a suitable item size.
5574 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5577 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5579 if (icon_view->priv->item_width != item_width)
5581 icon_view->priv->item_width = item_width;
5583 if (icon_view->priv->cell_area)
5584 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5586 gtk_icon_view_invalidate_sizes (icon_view);
5588 update_text_cell (icon_view);
5590 g_object_notify (G_OBJECT (icon_view), "item-width");
5595 * gtk_icon_view_get_item_width:
5596 * @icon_view: a #GtkIconView
5598 * Returns the value of the ::item-width property.
5600 * Return value: the width of a single item, or -1
5605 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5607 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5609 return icon_view->priv->item_width;
5614 * gtk_icon_view_set_spacing:
5615 * @icon_view: a #GtkIconView
5616 * @spacing: the spacing
5618 * Sets the ::spacing property which specifies the space
5619 * which is inserted between the cells (i.e. the icon and
5620 * the text) of an item.
5625 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5628 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5630 if (icon_view->priv->spacing != spacing)
5632 icon_view->priv->spacing = spacing;
5634 if (icon_view->priv->cell_area)
5635 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5637 gtk_icon_view_invalidate_sizes (icon_view);
5639 g_object_notify (G_OBJECT (icon_view), "spacing");
5644 * gtk_icon_view_get_spacing:
5645 * @icon_view: a #GtkIconView
5647 * Returns the value of the ::spacing property.
5649 * Return value: the space between cells
5654 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5656 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5658 return icon_view->priv->spacing;
5662 * gtk_icon_view_set_row_spacing:
5663 * @icon_view: a #GtkIconView
5664 * @row_spacing: the row spacing
5666 * Sets the ::row-spacing property which specifies the space
5667 * which is inserted between the rows of the icon view.
5672 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5675 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5677 if (icon_view->priv->row_spacing != row_spacing)
5679 icon_view->priv->row_spacing = row_spacing;
5681 if (icon_view->priv->cell_area)
5682 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5684 gtk_icon_view_invalidate_sizes (icon_view);
5686 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5691 * gtk_icon_view_get_row_spacing:
5692 * @icon_view: a #GtkIconView
5694 * Returns the value of the ::row-spacing property.
5696 * Return value: the space between rows
5701 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5703 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5705 return icon_view->priv->row_spacing;
5709 * gtk_icon_view_set_column_spacing:
5710 * @icon_view: a #GtkIconView
5711 * @column_spacing: the column spacing
5713 * Sets the ::column-spacing property which specifies the space
5714 * which is inserted between the columns of the icon view.
5719 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5720 gint column_spacing)
5722 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5724 if (icon_view->priv->column_spacing != column_spacing)
5726 icon_view->priv->column_spacing = column_spacing;
5728 if (icon_view->priv->cell_area)
5729 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5731 gtk_icon_view_invalidate_sizes (icon_view);
5733 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5738 * gtk_icon_view_get_column_spacing:
5739 * @icon_view: a #GtkIconView
5741 * Returns the value of the ::column-spacing property.
5743 * Return value: the space between columns
5748 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5750 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5752 return icon_view->priv->column_spacing;
5756 * gtk_icon_view_set_margin:
5757 * @icon_view: a #GtkIconView
5758 * @margin: the margin
5760 * Sets the ::margin property which specifies the space
5761 * which is inserted at the top, bottom, left and right
5767 gtk_icon_view_set_margin (GtkIconView *icon_view,
5770 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5772 if (icon_view->priv->margin != margin)
5774 icon_view->priv->margin = margin;
5776 if (icon_view->priv->cell_area)
5777 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5779 gtk_icon_view_invalidate_sizes (icon_view);
5781 g_object_notify (G_OBJECT (icon_view), "margin");
5786 * gtk_icon_view_get_margin:
5787 * @icon_view: a #GtkIconView
5789 * Returns the value of the ::margin property.
5791 * Return value: the space at the borders
5796 gtk_icon_view_get_margin (GtkIconView *icon_view)
5798 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5800 return icon_view->priv->margin;
5804 * gtk_icon_view_set_item_padding:
5805 * @icon_view: a #GtkIconView
5806 * @item_padding: the item padding
5808 * Sets the #GtkIconView:item-padding property which specifies the padding
5809 * around each of the icon view's items.
5814 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
5817 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5819 if (icon_view->priv->item_padding != item_padding)
5821 icon_view->priv->item_padding = item_padding;
5823 if (icon_view->priv->cell_area)
5824 gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
5826 gtk_icon_view_invalidate_sizes (icon_view);
5828 g_object_notify (G_OBJECT (icon_view), "item-padding");
5833 * gtk_icon_view_get_item_padding:
5834 * @icon_view: a #GtkIconView
5836 * Returns the value of the ::item-padding property.
5838 * Return value: the padding around items
5843 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
5845 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5847 return icon_view->priv->item_padding;
5850 /* Get/set whether drag_motion requested the drag data and
5851 * drag_data_received should thus not actually insert the data,
5852 * since the data doesn't result from a drop.
5855 set_status_pending (GdkDragContext *context,
5856 GdkDragAction suggested_action)
5858 g_object_set_data (G_OBJECT (context),
5859 I_("gtk-icon-view-status-pending"),
5860 GINT_TO_POINTER (suggested_action));
5863 static GdkDragAction
5864 get_status_pending (GdkDragContext *context)
5866 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5867 "gtk-icon-view-status-pending"));
5871 unset_reorderable (GtkIconView *icon_view)
5873 if (icon_view->priv->reorderable)
5875 icon_view->priv->reorderable = FALSE;
5876 g_object_notify (G_OBJECT (icon_view), "reorderable");
5881 set_source_row (GdkDragContext *context,
5882 GtkTreeModel *model,
5883 GtkTreePath *source_row)
5886 g_object_set_data_full (G_OBJECT (context),
5887 I_("gtk-icon-view-source-row"),
5888 gtk_tree_row_reference_new (model, source_row),
5889 (GDestroyNotify) gtk_tree_row_reference_free);
5891 g_object_set_data_full (G_OBJECT (context),
5892 I_("gtk-icon-view-source-row"),
5897 get_source_row (GdkDragContext *context)
5899 GtkTreeRowReference *ref;
5901 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5904 return gtk_tree_row_reference_get_path (ref);
5911 GtkTreeRowReference *dest_row;
5912 gboolean empty_view_drop;
5913 gboolean drop_append_mode;
5917 dest_row_free (gpointer data)
5919 DestRow *dr = (DestRow *)data;
5921 gtk_tree_row_reference_free (dr->dest_row);
5926 set_dest_row (GdkDragContext *context,
5927 GtkTreeModel *model,
5928 GtkTreePath *dest_row,
5929 gboolean empty_view_drop,
5930 gboolean drop_append_mode)
5936 g_object_set_data_full (G_OBJECT (context),
5937 I_("gtk-icon-view-dest-row"),
5942 dr = g_new0 (DestRow, 1);
5944 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5945 dr->empty_view_drop = empty_view_drop;
5946 dr->drop_append_mode = drop_append_mode;
5947 g_object_set_data_full (G_OBJECT (context),
5948 I_("gtk-icon-view-dest-row"),
5949 dr, (GDestroyNotify) dest_row_free);
5953 get_dest_row (GdkDragContext *context)
5957 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5961 GtkTreePath *path = NULL;
5964 path = gtk_tree_row_reference_get_path (dr->dest_row);
5965 else if (dr->empty_view_drop)
5966 path = gtk_tree_path_new_from_indices (0, -1);
5970 if (path && dr->drop_append_mode)
5971 gtk_tree_path_next (path);
5980 check_model_dnd (GtkTreeModel *model,
5981 GType required_iface,
5982 const gchar *signal)
5984 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5986 g_warning ("You must override the default '%s' handler "
5987 "on GtkIconView when using models that don't support "
5988 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5989 "is to connect to '%s' and call "
5990 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5991 "the default handler from running. Look at the source code "
5992 "for the default handler in gtkiconview.c to get an idea what "
5993 "your handler should do. (gtkiconview.c is in the GTK+ source "
5994 "code.) If you're using GTK+ from a language other than C, "
5995 "there may be a more natural way to override default handlers, e.g. via derivation.",
5996 signal, g_type_name (required_iface), signal);
6004 remove_scroll_timeout (GtkIconView *icon_view)
6006 if (icon_view->priv->scroll_timeout_id != 0)
6008 g_source_remove (icon_view->priv->scroll_timeout_id);
6010 icon_view->priv->scroll_timeout_id = 0;
6015 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6018 gint px, py, x, y, width, height;
6019 gint hoffset, voffset;
6021 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6023 gdk_window_get_pointer (window, &px, &py, NULL);
6024 gdk_window_get_geometry (window, &x, &y, &width, &height);
6026 /* see if we are near the edge. */
6027 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6029 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6031 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6033 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6036 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6037 gtk_adjustment_get_value (icon_view->priv->vadjustment) + voffset);
6040 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6041 gtk_adjustment_get_value (icon_view->priv->hadjustment) + hoffset);
6046 drag_scroll_timeout (gpointer data)
6048 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6050 gtk_icon_view_autoscroll (icon_view);
6057 set_destination (GtkIconView *icon_view,
6058 GdkDragContext *context,
6061 GdkDragAction *suggested_action,
6065 GtkTreePath *path = NULL;
6066 GtkIconViewDropPosition pos;
6067 GtkIconViewDropPosition old_pos;
6068 GtkTreePath *old_dest_path = NULL;
6069 gboolean can_drop = FALSE;
6071 widget = GTK_WIDGET (icon_view);
6073 *suggested_action = 0;
6076 if (!icon_view->priv->dest_set)
6078 /* someone unset us as a drag dest, note that if
6079 * we return FALSE drag_leave isn't called
6082 gtk_icon_view_set_drag_dest_item (icon_view,
6084 GTK_ICON_VIEW_DROP_LEFT);
6086 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6088 return FALSE; /* no longer a drop site */
6091 *target = gtk_drag_dest_find_target (widget, context,
6092 gtk_drag_dest_get_target_list (widget));
6093 if (*target == GDK_NONE)
6096 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6099 GtkTreeModel *model;
6101 /* the row got dropped on empty space, let's setup a special case
6105 gtk_tree_path_free (path);
6107 model = gtk_icon_view_get_model (icon_view);
6109 n_children = gtk_tree_model_iter_n_children (model, NULL);
6112 pos = GTK_ICON_VIEW_DROP_BELOW;
6113 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6117 pos = GTK_ICON_VIEW_DROP_ABOVE;
6118 path = gtk_tree_path_new_from_indices (0, -1);
6128 gtk_icon_view_get_drag_dest_item (icon_view,
6133 gtk_tree_path_free (old_dest_path);
6135 if (TRUE /* FIXME if the location droppable predicate */)
6143 GtkWidget *source_widget;
6145 *suggested_action = gdk_drag_context_get_suggested_action (context);
6146 source_widget = gtk_drag_get_source_widget (context);
6148 if (source_widget == widget)
6150 /* Default to MOVE, unless the user has
6151 * pressed ctrl or shift to affect available actions
6153 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6154 *suggested_action = GDK_ACTION_MOVE;
6157 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6162 /* can't drop here */
6163 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6165 GTK_ICON_VIEW_DROP_LEFT);
6169 gtk_tree_path_free (path);
6175 get_logical_destination (GtkIconView *icon_view,
6176 gboolean *drop_append_mode)
6178 /* adjust path to point to the row the drop goes in front of */
6179 GtkTreePath *path = NULL;
6180 GtkIconViewDropPosition pos;
6182 *drop_append_mode = FALSE;
6184 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6189 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6190 pos == GTK_ICON_VIEW_DROP_BELOW)
6193 GtkTreeModel *model = icon_view->priv->model;
6195 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6196 !gtk_tree_model_iter_next (model, &iter))
6197 *drop_append_mode = TRUE;
6200 *drop_append_mode = FALSE;
6201 gtk_tree_path_next (path);
6209 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6210 GdkEventMotion *event)
6212 GtkWidget *widget = GTK_WIDGET (icon_view);
6213 GdkDragContext *context;
6214 GtkTreePath *path = NULL;
6216 GtkTreeModel *model;
6217 gboolean retval = FALSE;
6219 if (!icon_view->priv->source_set)
6222 if (icon_view->priv->pressed_button < 0)
6225 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6226 icon_view->priv->press_start_x,
6227 icon_view->priv->press_start_y,
6228 event->x, event->y))
6231 model = gtk_icon_view_get_model (icon_view);
6236 button = icon_view->priv->pressed_button;
6237 icon_view->priv->pressed_button = -1;
6239 path = gtk_icon_view_get_path_at_pos (icon_view,
6240 icon_view->priv->press_start_x,
6241 icon_view->priv->press_start_y);
6246 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6247 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6251 /* FIXME Check whether we're a start button, if not return FALSE and
6255 /* Now we can begin the drag */
6259 context = gtk_drag_begin (widget,
6260 gtk_drag_source_get_target_list (widget),
6261 icon_view->priv->source_actions,
6265 set_source_row (context, model, path);
6269 gtk_tree_path_free (path);
6274 /* Source side drag signals */
6276 gtk_icon_view_drag_begin (GtkWidget *widget,
6277 GdkDragContext *context)
6279 GtkIconView *icon_view;
6280 GtkIconViewItem *item;
6281 cairo_surface_t *icon;
6285 icon_view = GTK_ICON_VIEW (widget);
6287 /* if the user uses a custom DnD impl, we don't set the icon here */
6288 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6291 item = gtk_icon_view_get_item_at_coords (icon_view,
6292 icon_view->priv->press_start_x,
6293 icon_view->priv->press_start_y,
6297 g_return_if_fail (item != NULL);
6299 x = icon_view->priv->press_start_x - item->cell_area.x + 1;
6300 y = icon_view->priv->press_start_y - item->cell_area.y + 1;
6302 path = gtk_tree_path_new_from_indices (item->index, -1);
6303 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6304 gtk_tree_path_free (path);
6306 cairo_surface_set_device_offset (icon, -x, -y);
6308 gtk_drag_set_icon_surface (context, icon);
6310 cairo_surface_destroy (icon);
6314 gtk_icon_view_drag_end (GtkWidget *widget,
6315 GdkDragContext *context)
6321 gtk_icon_view_drag_data_get (GtkWidget *widget,
6322 GdkDragContext *context,
6323 GtkSelectionData *selection_data,
6327 GtkIconView *icon_view;
6328 GtkTreeModel *model;
6329 GtkTreePath *source_row;
6331 icon_view = GTK_ICON_VIEW (widget);
6332 model = gtk_icon_view_get_model (icon_view);
6337 if (!icon_view->priv->source_set)
6340 source_row = get_source_row (context);
6342 if (source_row == NULL)
6345 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6346 * any model; for DragSource models there are some other targets
6350 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6351 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6356 /* If drag_data_get does nothing, try providing row data. */
6357 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6358 gtk_tree_set_row_drag_data (selection_data,
6363 gtk_tree_path_free (source_row);
6367 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6368 GdkDragContext *context)
6370 GtkTreeModel *model;
6371 GtkIconView *icon_view;
6372 GtkTreePath *source_row;
6374 icon_view = GTK_ICON_VIEW (widget);
6375 model = gtk_icon_view_get_model (icon_view);
6377 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6380 if (!icon_view->priv->source_set)
6383 source_row = get_source_row (context);
6385 if (source_row == NULL)
6388 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6391 gtk_tree_path_free (source_row);
6393 set_source_row (context, NULL, NULL);
6396 /* Target side drag signals */
6398 gtk_icon_view_drag_leave (GtkWidget *widget,
6399 GdkDragContext *context,
6402 GtkIconView *icon_view;
6404 icon_view = GTK_ICON_VIEW (widget);
6406 /* unset any highlight row */
6407 gtk_icon_view_set_drag_dest_item (icon_view,
6409 GTK_ICON_VIEW_DROP_LEFT);
6411 remove_scroll_timeout (icon_view);
6415 gtk_icon_view_drag_motion (GtkWidget *widget,
6416 GdkDragContext *context,
6421 GtkTreePath *path = NULL;
6422 GtkIconViewDropPosition pos;
6423 GtkIconView *icon_view;
6424 GdkDragAction suggested_action = 0;
6428 icon_view = GTK_ICON_VIEW (widget);
6430 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6433 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6435 /* we only know this *after* set_desination_row */
6436 empty = icon_view->priv->empty_view_drop;
6438 if (path == NULL && !empty)
6440 /* Can't drop here. */
6441 gdk_drag_status (context, 0, time);
6445 if (icon_view->priv->scroll_timeout_id == 0)
6447 icon_view->priv->scroll_timeout_id =
6448 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6451 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6453 /* Request data so we can use the source row when
6454 * determining whether to accept the drop
6456 set_status_pending (context, suggested_action);
6457 gtk_drag_get_data (widget, context, target, time);
6461 set_status_pending (context, 0);
6462 gdk_drag_status (context, suggested_action, time);
6467 gtk_tree_path_free (path);
6473 gtk_icon_view_drag_drop (GtkWidget *widget,
6474 GdkDragContext *context,
6479 GtkIconView *icon_view;
6481 GdkDragAction suggested_action = 0;
6482 GdkAtom target = GDK_NONE;
6483 GtkTreeModel *model;
6484 gboolean drop_append_mode;
6486 icon_view = GTK_ICON_VIEW (widget);
6487 model = gtk_icon_view_get_model (icon_view);
6489 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6491 if (!icon_view->priv->dest_set)
6494 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6497 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6500 path = get_logical_destination (icon_view, &drop_append_mode);
6502 if (target != GDK_NONE && path != NULL)
6504 /* in case a motion had requested drag data, change things so we
6505 * treat drag data receives as a drop.
6507 set_status_pending (context, 0);
6508 set_dest_row (context, model, path,
6509 icon_view->priv->empty_view_drop, drop_append_mode);
6513 gtk_tree_path_free (path);
6515 /* Unset this thing */
6516 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6518 if (target != GDK_NONE)
6520 gtk_drag_get_data (widget, context, target, time);
6528 gtk_icon_view_drag_data_received (GtkWidget *widget,
6529 GdkDragContext *context,
6532 GtkSelectionData *selection_data,
6537 gboolean accepted = FALSE;
6538 GtkTreeModel *model;
6539 GtkIconView *icon_view;
6540 GtkTreePath *dest_row;
6541 GdkDragAction suggested_action;
6542 gboolean drop_append_mode;
6544 icon_view = GTK_ICON_VIEW (widget);
6545 model = gtk_icon_view_get_model (icon_view);
6547 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6550 if (!icon_view->priv->dest_set)
6553 suggested_action = get_status_pending (context);
6555 if (suggested_action)
6557 /* We are getting this data due to a request in drag_motion,
6558 * rather than due to a request in drag_drop, so we are just
6559 * supposed to call drag_status, not actually paste in the
6562 path = get_logical_destination (icon_view, &drop_append_mode);
6565 suggested_action = 0;
6567 if (suggested_action)
6569 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6572 suggested_action = 0;
6575 gdk_drag_status (context, suggested_action, time);
6578 gtk_tree_path_free (path);
6580 /* If you can't drop, remove user drop indicator until the next motion */
6581 if (suggested_action == 0)
6582 gtk_icon_view_set_drag_dest_item (icon_view,
6584 GTK_ICON_VIEW_DROP_LEFT);
6589 dest_row = get_dest_row (context);
6591 if (dest_row == NULL)
6594 if (gtk_selection_data_get_length (selection_data) >= 0)
6596 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6602 gtk_drag_finish (context,
6604 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
6607 gtk_tree_path_free (dest_row);
6610 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6613 /* Drag-and-Drop support */
6615 * gtk_icon_view_enable_model_drag_source:
6616 * @icon_view: a #GtkIconTreeView
6617 * @start_button_mask: Mask of allowed buttons to start drag
6618 * @targets: (array length=n_targets): the table of targets that the drag will
6620 * @n_targets: the number of items in @targets
6621 * @actions: the bitmask of possible actions for a drag from this
6624 * Turns @icon_view into a drag source for automatic DND. Calling this
6625 * method sets #GtkIconView:reorderable to %FALSE.
6630 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6631 GdkModifierType start_button_mask,
6632 const GtkTargetEntry *targets,
6634 GdkDragAction actions)
6636 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6638 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6640 icon_view->priv->start_button_mask = start_button_mask;
6641 icon_view->priv->source_actions = actions;
6643 icon_view->priv->source_set = TRUE;
6645 unset_reorderable (icon_view);
6649 * gtk_icon_view_enable_model_drag_dest:
6650 * @icon_view: a #GtkIconView
6651 * @targets: (array length=n_targets): the table of targets that the drag will
6653 * @n_targets: the number of items in @targets
6654 * @actions: the bitmask of possible actions for a drag to this
6657 * Turns @icon_view into a drop destination for automatic DND. Calling this
6658 * method sets #GtkIconView:reorderable to %FALSE.
6663 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6664 const GtkTargetEntry *targets,
6666 GdkDragAction actions)
6668 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6670 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6672 icon_view->priv->dest_actions = actions;
6674 icon_view->priv->dest_set = TRUE;
6676 unset_reorderable (icon_view);
6680 * gtk_icon_view_unset_model_drag_source:
6681 * @icon_view: a #GtkIconView
6683 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
6684 * method sets #GtkIconView:reorderable to %FALSE.
6689 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6691 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6693 if (icon_view->priv->source_set)
6695 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6696 icon_view->priv->source_set = FALSE;
6699 unset_reorderable (icon_view);
6703 * gtk_icon_view_unset_model_drag_dest:
6704 * @icon_view: a #GtkIconView
6706 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
6707 * method sets #GtkIconView:reorderable to %FALSE.
6712 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6714 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6716 if (icon_view->priv->dest_set)
6718 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6719 icon_view->priv->dest_set = FALSE;
6722 unset_reorderable (icon_view);
6725 /* These are useful to implement your own custom stuff. */
6727 * gtk_icon_view_set_drag_dest_item:
6728 * @icon_view: a #GtkIconView
6729 * @path: (allow-none): The path of the item to highlight, or %NULL.
6730 * @pos: Specifies where to drop, relative to the item
6732 * Sets the item that is highlighted for feedback.
6737 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6739 GtkIconViewDropPosition pos)
6741 /* Note; this function is exported to allow a custom DND
6742 * implementation, so it can't touch TreeViewDragInfo
6745 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6747 if (icon_view->priv->dest_item)
6749 GtkTreePath *current_path;
6750 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6751 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6752 icon_view->priv->dest_item = NULL;
6754 gtk_icon_view_queue_draw_path (icon_view, current_path);
6755 gtk_tree_path_free (current_path);
6758 /* special case a drop on an empty model */
6759 icon_view->priv->empty_view_drop = FALSE;
6760 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
6761 && gtk_tree_path_get_depth (path) == 1
6762 && gtk_tree_path_get_indices (path)[0] == 0)
6766 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6769 if (n_children == 0)
6770 icon_view->priv->empty_view_drop = TRUE;
6773 icon_view->priv->dest_pos = pos;
6777 icon_view->priv->dest_item =
6778 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6779 icon_view->priv->model, path);
6781 gtk_icon_view_queue_draw_path (icon_view, path);
6786 * gtk_icon_view_get_drag_dest_item:
6787 * @icon_view: a #GtkIconView
6788 * @path: (out) (allow-none): Return location for the path of
6789 * the highlighted item, or %NULL.
6790 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6792 * Gets information about the item that is highlighted for feedback.
6797 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6799 GtkIconViewDropPosition *pos)
6801 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6805 if (icon_view->priv->dest_item)
6806 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6812 *pos = icon_view->priv->dest_pos;
6816 * gtk_icon_view_get_dest_item_at_pos:
6817 * @icon_view: a #GtkIconView
6818 * @drag_x: the position to determine the destination item for
6819 * @drag_y: the position to determine the destination item for
6820 * @path: (out) (allow-none): Return location for the path of the item,
6822 * @pos: (out) (allow-none): Return location for the drop position, or %NULL
6824 * Determines the destination item for a given position.
6826 * Return value: whether there is an item at the given position.
6831 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6835 GtkIconViewDropPosition *pos)
6837 GtkIconViewItem *item;
6839 /* Note; this function is exported to allow a custom DND
6840 * implementation, so it can't touch TreeViewDragInfo
6843 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6844 g_return_val_if_fail (drag_x >= 0, FALSE);
6845 g_return_val_if_fail (drag_y >= 0, FALSE);
6846 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6852 item = gtk_icon_view_get_item_at_coords (icon_view,
6853 drag_x + gtk_adjustment_get_value (icon_view->priv->hadjustment),
6854 drag_y + gtk_adjustment_get_value (icon_view->priv->vadjustment),
6861 *path = gtk_tree_path_new_from_indices (item->index, -1);
6865 if (drag_x < item->cell_area.x + item->cell_area.width / 4)
6866 *pos = GTK_ICON_VIEW_DROP_LEFT;
6867 else if (drag_x > item->cell_area.x + item->cell_area.width * 3 / 4)
6868 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6869 else if (drag_y < item->cell_area.y + item->cell_area.height / 4)
6870 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6871 else if (drag_y > item->cell_area.y + item->cell_area.height * 3 / 4)
6872 *pos = GTK_ICON_VIEW_DROP_BELOW;
6874 *pos = GTK_ICON_VIEW_DROP_INTO;
6881 * gtk_icon_view_create_drag_icon:
6882 * @icon_view: a #GtkIconView
6883 * @path: a #GtkTreePath in @icon_view
6885 * Creates a #cairo_surface_t representation of the item at @path.
6886 * This image is used for a drag icon.
6888 * Return value: (transfer full): a newly-allocated surface of the drag icon.
6893 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6897 GtkStyleContext *context;
6899 cairo_surface_t *surface;
6903 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6904 g_return_val_if_fail (path != NULL, NULL);
6906 widget = GTK_WIDGET (icon_view);
6907 context = gtk_widget_get_style_context (widget);
6909 if (!gtk_widget_get_realized (widget))
6912 index = gtk_tree_path_get_indices (path)[0];
6914 for (l = icon_view->priv->items; l; l = l->next)
6916 GtkIconViewItem *item = l->data;
6918 if (index == item->index)
6920 GdkRectangle rect = {
6921 item->cell_area.x - icon_view->priv->item_padding,
6922 item->cell_area.y - icon_view->priv->item_padding,
6923 item->cell_area.width + icon_view->priv->item_padding * 2,
6924 item->cell_area.height + icon_view->priv->item_padding * 2
6927 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
6928 CAIRO_CONTENT_COLOR,
6932 cr = cairo_create (surface);
6933 cairo_set_line_width (cr, 1.);
6935 gtk_render_background (context, cr, 0, 0,
6936 rect.width + 2, rect.height + 2);
6940 cairo_rectangle (cr, 1, 1, rect.width, rect.height);
6943 gtk_icon_view_paint_item (icon_view, cr, item,
6944 icon_view->priv->item_padding + 1,
6945 icon_view->priv->item_padding + 1, FALSE);
6949 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6950 cairo_rectangle (cr, 0.5, 0.5, rect.width + 1, rect.height + 1);
6963 * gtk_icon_view_get_reorderable:
6964 * @icon_view: a #GtkIconView
6966 * Retrieves whether the user can reorder the list via drag-and-drop.
6967 * See gtk_icon_view_set_reorderable().
6969 * Return value: %TRUE if the list can be reordered.
6974 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6976 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6978 return icon_view->priv->reorderable;
6981 static const GtkTargetEntry item_targets[] = {
6982 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6987 * gtk_icon_view_set_reorderable:
6988 * @icon_view: A #GtkIconView.
6989 * @reorderable: %TRUE, if the list of items can be reordered.
6991 * This function is a convenience function to allow you to reorder models that
6992 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6993 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6994 * the user can reorder the model by dragging and dropping rows. The
6995 * developer can listen to these changes by connecting to the model's
6996 * row_inserted and row_deleted signals. The reordering is implemented by setting up
6997 * the icon view as a drag source and destination. Therefore, drag and
6998 * drop can not be used in a reorderable view for any other purpose.
7000 * This function does not give you any degree of control over the order -- any
7001 * reordering is allowed. If more control is needed, you should probably
7002 * handle drag and drop manually.
7007 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7008 gboolean reorderable)
7010 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7012 reorderable = reorderable != FALSE;
7014 if (icon_view->priv->reorderable == reorderable)
7019 gtk_icon_view_enable_model_drag_source (icon_view,
7022 G_N_ELEMENTS (item_targets),
7024 gtk_icon_view_enable_model_drag_dest (icon_view,
7026 G_N_ELEMENTS (item_targets),
7031 gtk_icon_view_unset_model_drag_source (icon_view);
7032 gtk_icon_view_unset_model_drag_dest (icon_view);
7035 icon_view->priv->reorderable = reorderable;
7037 g_object_notify (G_OBJECT (icon_view), "reorderable");
7041 /* Accessibility Support */
7043 static gpointer accessible_parent_class;
7044 static gpointer accessible_item_parent_class;
7045 static GQuark accessible_private_data_quark = 0;
7047 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7048 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7049 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7051 static GType gtk_icon_view_item_accessible_get_type (void);
7062 GtkIconViewItem *item;
7066 AtkStateSet *state_set;
7070 GtkTextBuffer *text_buffer;
7072 gchar *action_descriptions[LAST_ACTION];
7073 gchar *image_description;
7074 guint action_idle_handler;
7075 } GtkIconViewItemAccessible;
7077 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7083 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7088 typedef struct _GtkIconViewItemAccessibleClass
7090 AtkObjectClass parent_class;
7092 } GtkIconViewItemAccessibleClass;
7094 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7097 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7099 GtkIconViewItemAccessible *item;
7100 GtkIconView *icon_view;
7103 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7104 item->action_idle_handler = 0;
7106 if (item->widget != NULL)
7108 icon_view = GTK_ICON_VIEW (item->widget);
7109 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7110 gtk_icon_view_item_activated (icon_view, path);
7111 gtk_tree_path_free (path);
7118 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7121 GtkIconViewItemAccessible *item;
7123 if (i < 0 || i >= LAST_ACTION)
7126 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7128 if (!GTK_IS_ICON_VIEW (item->widget))
7131 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7136 case ACTION_ACTIVATE:
7137 if (!item->action_idle_handler)
7138 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7141 g_assert_not_reached ();
7149 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7154 static const gchar *
7155 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7158 GtkIconViewItemAccessible *item;
7160 if (i < 0 || i >= LAST_ACTION)
7163 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7165 if (item->action_descriptions[i])
7166 return item->action_descriptions[i];
7168 return gtk_icon_view_item_accessible_action_descriptions[i];
7171 static const gchar *
7172 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7175 if (i < 0 || i >= LAST_ACTION)
7178 return gtk_icon_view_item_accessible_action_names[i];
7182 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7184 const gchar *description)
7186 GtkIconViewItemAccessible *item;
7188 if (i < 0 || i >= LAST_ACTION)
7191 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7193 g_free (item->action_descriptions[i]);
7195 item->action_descriptions[i] = g_strdup (description);
7201 atk_action_item_interface_init (AtkActionIface *iface)
7203 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7204 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7205 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7206 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7207 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7210 static const gchar *
7211 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7213 GtkIconViewItemAccessible *item;
7215 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7217 return item->image_description;
7221 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7222 const gchar *description)
7224 GtkIconViewItemAccessible *item;
7226 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7228 g_free (item->image_description);
7229 item->image_description = g_strdup (description);
7236 gboolean pixbuf_found;
7240 get_pixbuf_foreach (GtkCellRenderer *renderer,
7241 const GdkRectangle *cell_area,
7242 const GdkRectangle *cell_background,
7243 GetPixbufBoxData *data)
7245 if (GTK_IS_CELL_RENDERER_PIXBUF (renderer))
7247 data->box = *cell_area;
7248 data->pixbuf_found = TRUE;
7250 return (data->pixbuf_found != FALSE);
7254 get_pixbuf_box (GtkIconView *icon_view,
7255 GtkIconViewItem *item,
7258 GetPixbufBoxData data = { { 0, }, FALSE };
7259 GtkCellAreaContext *context;
7261 context = g_ptr_array_index (icon_view->priv->row_contexts, item->row);
7263 gtk_icon_view_set_cell_data (icon_view, item);
7264 gtk_cell_area_foreach_alloc (icon_view->priv->cell_area, context,
7265 GTK_WIDGET (icon_view),
7266 (GdkRectangle *)item, (GdkRectangle *)item,
7267 (GtkCellAllocCallback)get_pixbuf_foreach, &data);
7269 return data.pixbuf_found;
7273 get_text_foreach (GtkCellRenderer *renderer,
7276 if (GTK_IS_CELL_RENDERER_TEXT (renderer))
7278 g_object_get (renderer, "text", text, NULL);
7286 get_text (GtkIconView *icon_view,
7287 GtkIconViewItem *item)
7291 gtk_icon_view_set_cell_data (icon_view, item);
7292 gtk_cell_area_foreach (icon_view->priv->cell_area,
7293 (GtkCellCallback)get_text_foreach, &text);
7299 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7303 GtkIconViewItemAccessible *item;
7306 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7308 if (!GTK_IS_ICON_VIEW (item->widget))
7311 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7314 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7317 *height = box.height;
7322 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7325 AtkCoordType coord_type)
7327 GtkIconViewItemAccessible *item;
7330 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7332 if (!GTK_IS_ICON_VIEW (item->widget))
7335 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7338 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7340 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7342 *x+= box.x - item->item->cell_area.x;
7343 *y+= box.y - item->item->cell_area.y;
7349 atk_image_item_interface_init (AtkImageIface *iface)
7351 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7352 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7353 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7354 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7358 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7362 GtkIconViewItemAccessible *item;
7363 GtkTextIter start, end;
7364 GtkTextBuffer *buffer;
7366 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7368 if (!GTK_IS_ICON_VIEW (item->widget))
7371 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7374 buffer = item->text_buffer;
7375 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7377 gtk_text_buffer_get_end_iter (buffer, &end);
7379 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7381 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7385 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7388 GtkIconViewItemAccessible *item;
7389 GtkTextIter start, end;
7390 GtkTextBuffer *buffer;
7394 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7396 if (!GTK_IS_ICON_VIEW (item->widget))
7399 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7402 buffer = item->text_buffer;
7403 if (offset >= gtk_text_buffer_get_char_count (buffer))
7406 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7408 gtk_text_iter_forward_char (&end);
7409 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7410 unichar = g_utf8_get_char (string);
7418 get_pango_text_offsets (PangoLayout *layout,
7419 GtkTextBuffer *buffer,
7421 AtkTextBoundary boundary_type,
7425 GtkTextIter *start_iter,
7426 GtkTextIter *end_iter)
7428 PangoLayoutIter *iter;
7429 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7430 gint index, start_index, end_index;
7432 gboolean found = FALSE;
7434 text = pango_layout_get_text (layout);
7435 index = g_utf8_offset_to_pointer (text, offset) - text;
7436 iter = pango_layout_get_iter (layout);
7439 line = pango_layout_iter_get_line_readonly (iter);
7440 start_index = line->start_index;
7441 end_index = start_index + line->length;
7443 if (index >= start_index && index <= end_index)
7446 * Found line for offset
7452 * We want the previous line
7456 switch (boundary_type)
7458 case ATK_TEXT_BOUNDARY_LINE_START:
7459 end_index = start_index;
7460 start_index = prev_line->start_index;
7462 case ATK_TEXT_BOUNDARY_LINE_END:
7464 start_index = prev_prev_line->start_index +
7465 prev_prev_line->length;
7466 end_index = prev_line->start_index + prev_line->length;
7469 g_assert_not_reached();
7473 start_index = end_index = 0;
7476 switch (boundary_type)
7478 case ATK_TEXT_BOUNDARY_LINE_START:
7479 if (pango_layout_iter_next_line (iter))
7480 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7482 case ATK_TEXT_BOUNDARY_LINE_END:
7484 start_index = prev_line->start_index +
7488 g_assert_not_reached();
7493 * We want the next line
7495 if (pango_layout_iter_next_line (iter))
7497 line = pango_layout_iter_get_line_readonly (iter);
7498 switch (boundary_type)
7500 case ATK_TEXT_BOUNDARY_LINE_START:
7501 start_index = line->start_index;
7502 if (pango_layout_iter_next_line (iter))
7503 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7505 end_index = start_index + line->length;
7507 case ATK_TEXT_BOUNDARY_LINE_END:
7508 start_index = end_index;
7509 end_index = line->start_index + line->length;
7512 g_assert_not_reached();
7516 start_index = end_index;
7522 prev_prev_line = prev_line;
7525 while (pango_layout_iter_next_line (iter));
7529 start_index = prev_line->start_index + prev_line->length;
7530 end_index = start_index;
7532 pango_layout_iter_free (iter);
7533 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7534 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7536 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7537 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7542 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7544 AtkTextBoundary boundary_type,
7548 GtkIconViewItemAccessible *item;
7549 GtkTextIter start, end;
7550 GtkTextBuffer *buffer;
7552 GtkIconView *icon_view;
7555 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7557 if (!GTK_IS_ICON_VIEW (item->widget))
7560 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7563 buffer = item->text_buffer;
7565 if (!gtk_text_buffer_get_char_count (buffer))
7569 return g_strdup ("");
7571 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7575 switch (boundary_type)
7577 case ATK_TEXT_BOUNDARY_CHAR:
7578 gtk_text_iter_backward_char(&start);
7580 case ATK_TEXT_BOUNDARY_WORD_START:
7581 if (!gtk_text_iter_starts_word (&start))
7582 gtk_text_iter_backward_word_start (&start);
7584 gtk_text_iter_backward_word_start(&start);
7586 case ATK_TEXT_BOUNDARY_WORD_END:
7587 if (gtk_text_iter_inside_word (&start) &&
7588 !gtk_text_iter_starts_word (&start))
7589 gtk_text_iter_backward_word_start (&start);
7590 while (!gtk_text_iter_ends_word (&start))
7592 if (!gtk_text_iter_backward_char (&start))
7596 gtk_text_iter_backward_word_start(&start);
7597 while (!gtk_text_iter_ends_word (&start))
7599 if (!gtk_text_iter_backward_char (&start))
7603 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7604 if (!gtk_text_iter_starts_sentence (&start))
7605 gtk_text_iter_backward_sentence_start (&start);
7607 gtk_text_iter_backward_sentence_start (&start);
7609 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7610 if (gtk_text_iter_inside_sentence (&start) &&
7611 !gtk_text_iter_starts_sentence (&start))
7612 gtk_text_iter_backward_sentence_start (&start);
7613 while (!gtk_text_iter_ends_sentence (&start))
7615 if (!gtk_text_iter_backward_char (&start))
7619 gtk_text_iter_backward_sentence_start (&start);
7620 while (!gtk_text_iter_ends_sentence (&start))
7622 if (!gtk_text_iter_backward_char (&start))
7626 case ATK_TEXT_BOUNDARY_LINE_START:
7627 case ATK_TEXT_BOUNDARY_LINE_END:
7629 icon_view = GTK_ICON_VIEW (item->widget);
7630 /* FIXME we probably have to use GailTextCell to salvage this */
7631 gtk_icon_view_update_item_text (icon_view, item->item);
7632 get_pango_text_offsets (icon_view->priv->layout,
7645 *start_offset = gtk_text_iter_get_offset (&start);
7646 *end_offset = gtk_text_iter_get_offset (&end);
7648 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7652 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7654 AtkTextBoundary boundary_type,
7658 GtkIconViewItemAccessible *item;
7659 GtkTextIter start, end;
7660 GtkTextBuffer *buffer;
7662 GtkIconView *icon_view;
7665 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7667 if (!GTK_IS_ICON_VIEW (item->widget))
7670 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7673 buffer = item->text_buffer;
7675 if (!gtk_text_buffer_get_char_count (buffer))
7679 return g_strdup ("");
7681 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7685 switch (boundary_type)
7687 case ATK_TEXT_BOUNDARY_CHAR:
7688 gtk_text_iter_forward_char (&end);
7690 case ATK_TEXT_BOUNDARY_WORD_START:
7691 if (!gtk_text_iter_starts_word (&start))
7692 gtk_text_iter_backward_word_start (&start);
7693 if (gtk_text_iter_inside_word (&end))
7694 gtk_text_iter_forward_word_end (&end);
7695 while (!gtk_text_iter_starts_word (&end))
7697 if (!gtk_text_iter_forward_char (&end))
7701 case ATK_TEXT_BOUNDARY_WORD_END:
7702 if (gtk_text_iter_inside_word (&start) &&
7703 !gtk_text_iter_starts_word (&start))
7704 gtk_text_iter_backward_word_start (&start);
7705 while (!gtk_text_iter_ends_word (&start))
7707 if (!gtk_text_iter_backward_char (&start))
7710 gtk_text_iter_forward_word_end (&end);
7712 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7713 if (!gtk_text_iter_starts_sentence (&start))
7714 gtk_text_iter_backward_sentence_start (&start);
7715 if (gtk_text_iter_inside_sentence (&end))
7716 gtk_text_iter_forward_sentence_end (&end);
7717 while (!gtk_text_iter_starts_sentence (&end))
7719 if (!gtk_text_iter_forward_char (&end))
7723 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7724 if (gtk_text_iter_inside_sentence (&start) &&
7725 !gtk_text_iter_starts_sentence (&start))
7726 gtk_text_iter_backward_sentence_start (&start);
7727 while (!gtk_text_iter_ends_sentence (&start))
7729 if (!gtk_text_iter_backward_char (&start))
7732 gtk_text_iter_forward_sentence_end (&end);
7734 case ATK_TEXT_BOUNDARY_LINE_START:
7735 case ATK_TEXT_BOUNDARY_LINE_END:
7737 icon_view = GTK_ICON_VIEW (item->widget);
7738 /* FIXME we probably have to use GailTextCell to salvage this */
7739 gtk_icon_view_update_item_text (icon_view, item->item);
7740 get_pango_text_offsets (icon_view->priv->layout,
7754 *start_offset = gtk_text_iter_get_offset (&start);
7755 *end_offset = gtk_text_iter_get_offset (&end);
7757 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7761 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7763 AtkTextBoundary boundary_type,
7767 GtkIconViewItemAccessible *item;
7768 GtkTextIter start, end;
7769 GtkTextBuffer *buffer;
7771 GtkIconView *icon_view;
7774 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7776 if (!GTK_IS_ICON_VIEW (item->widget))
7779 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7782 buffer = item->text_buffer;
7784 if (!gtk_text_buffer_get_char_count (buffer))
7788 return g_strdup ("");
7790 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7794 switch (boundary_type)
7796 case ATK_TEXT_BOUNDARY_CHAR:
7797 gtk_text_iter_forward_char(&start);
7798 gtk_text_iter_forward_chars(&end, 2);
7800 case ATK_TEXT_BOUNDARY_WORD_START:
7801 if (gtk_text_iter_inside_word (&end))
7802 gtk_text_iter_forward_word_end (&end);
7803 while (!gtk_text_iter_starts_word (&end))
7805 if (!gtk_text_iter_forward_char (&end))
7809 if (!gtk_text_iter_is_end (&end))
7811 gtk_text_iter_forward_word_end (&end);
7812 while (!gtk_text_iter_starts_word (&end))
7814 if (!gtk_text_iter_forward_char (&end))
7819 case ATK_TEXT_BOUNDARY_WORD_END:
7820 gtk_text_iter_forward_word_end (&end);
7822 if (!gtk_text_iter_is_end (&end))
7823 gtk_text_iter_forward_word_end (&end);
7825 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7826 if (gtk_text_iter_inside_sentence (&end))
7827 gtk_text_iter_forward_sentence_end (&end);
7828 while (!gtk_text_iter_starts_sentence (&end))
7830 if (!gtk_text_iter_forward_char (&end))
7834 if (!gtk_text_iter_is_end (&end))
7836 gtk_text_iter_forward_sentence_end (&end);
7837 while (!gtk_text_iter_starts_sentence (&end))
7839 if (!gtk_text_iter_forward_char (&end))
7844 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7845 gtk_text_iter_forward_sentence_end (&end);
7847 if (!gtk_text_iter_is_end (&end))
7848 gtk_text_iter_forward_sentence_end (&end);
7850 case ATK_TEXT_BOUNDARY_LINE_START:
7851 case ATK_TEXT_BOUNDARY_LINE_END:
7853 icon_view = GTK_ICON_VIEW (item->widget);
7854 /* FIXME we probably have to use GailTextCell to salvage this */
7855 gtk_icon_view_update_item_text (icon_view, item->item);
7856 get_pango_text_offsets (icon_view->priv->layout,
7868 *start_offset = gtk_text_iter_get_offset (&start);
7869 *end_offset = gtk_text_iter_get_offset (&end);
7871 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7875 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7877 GtkIconViewItemAccessible *item;
7879 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7881 if (!GTK_IS_ICON_VIEW (item->widget))
7884 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7887 return gtk_text_buffer_get_char_count (item->text_buffer);
7891 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7897 AtkCoordType coord_type)
7899 GtkIconViewItemAccessible *item;
7901 GtkIconView *icon_view;
7902 PangoRectangle char_rect;
7903 const gchar *item_text;
7907 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7909 if (!GTK_IS_ICON_VIEW (item->widget))
7912 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7916 icon_view = GTK_ICON_VIEW (item->widget);
7917 /* FIXME we probably have to use GailTextCell to salvage this */
7918 gtk_icon_view_update_item_text (icon_view, item->item);
7919 item_text = pango_layout_get_text (icon_view->priv->layout);
7920 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7921 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7923 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7924 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7925 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7926 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7927 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7928 *width = char_rect.width / PANGO_SCALE;
7929 *height = char_rect.height / PANGO_SCALE;
7934 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7937 AtkCoordType coord_type)
7939 GtkIconViewItemAccessible *item;
7942 GtkIconView *icon_view;
7943 const gchar *item_text;
7948 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7950 if (!GTK_IS_ICON_VIEW (item->widget))
7953 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7957 icon_view = GTK_ICON_VIEW (item->widget);
7958 /* FIXME we probably have to use GailTextCell to salvage this */
7959 gtk_icon_view_update_item_text (icon_view, item->item);
7960 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7961 x -= l_x + item->item->layout_x - item->item->x;
7962 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7963 y -= l_y + item->item->layout_y - item->item->y;
7964 item_text = pango_layout_get_text (icon_view->priv->layout);
7965 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7976 offset = g_utf8_strlen (item_text, -1);
7978 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7984 atk_text_item_interface_init (AtkTextIface *iface)
7986 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7987 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7988 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7989 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7990 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7991 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7992 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7993 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7997 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8002 AtkCoordType coord_type)
8004 GtkIconViewItemAccessible *item;
8005 AtkObject *parent_obj;
8008 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8010 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8011 if (!GTK_IS_WIDGET (item->widget))
8014 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8017 *width = item->item->cell_area.width;
8018 *height = item->item->cell_area.height;
8019 if (gtk_icon_view_item_accessible_is_showing (item))
8021 parent_obj = gtk_widget_get_accessible (item->widget);
8022 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8023 *x = l_x + item->item->cell_area.x;
8024 *y = l_y + item->item->cell_area.y;
8034 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8036 GtkIconViewItemAccessible *item;
8037 GtkWidget *toplevel;
8039 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8041 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8042 if (!GTK_IS_WIDGET (item->widget))
8045 gtk_widget_grab_focus (item->widget);
8046 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, NULL);
8047 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8048 if (gtk_widget_is_toplevel (toplevel))
8049 gtk_window_present (GTK_WINDOW (toplevel));
8055 atk_component_item_interface_init (AtkComponentIface *iface)
8057 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8058 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8062 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8063 AtkStateType state_type,
8064 gboolean emit_signal)
8068 rc = atk_state_set_add_state (item->state_set, state_type);
8070 * The signal should only be generated if the value changed,
8071 * not when the item is set up. So states that are set
8072 * initially should pass FALSE as the emit_signal argument.
8077 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8078 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8079 if (state_type == ATK_STATE_VISIBLE)
8080 g_signal_emit_by_name (item, "visible-data-changed");
8087 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8088 AtkStateType state_type,
8089 gboolean emit_signal)
8091 if (atk_state_set_contains_state (item->state_set, state_type))
8095 rc = atk_state_set_remove_state (item->state_set, state_type);
8097 * The signal should only be generated if the value changed,
8098 * not when the item is set up. So states that are set
8099 * initially should pass FALSE as the emit_signal argument.
8104 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8105 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8106 if (state_type == ATK_STATE_VISIBLE)
8107 g_signal_emit_by_name (item, "visible-data-changed");
8117 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8119 GtkAllocation allocation;
8120 GtkIconView *icon_view;
8121 GdkRectangle visible_rect;
8122 gboolean is_showing;
8125 * An item is considered "SHOWING" if any part of the item is in the
8126 * visible rectangle.
8129 if (!GTK_IS_ICON_VIEW (item->widget))
8132 if (item->item == NULL)
8135 gtk_widget_get_allocation (item->widget, &allocation);
8137 icon_view = GTK_ICON_VIEW (item->widget);
8139 if (icon_view->priv->hadjustment)
8140 visible_rect.x += gtk_adjustment_get_value (icon_view->priv->hadjustment);
8142 if (icon_view->priv->hadjustment)
8143 visible_rect.y += gtk_adjustment_get_value (icon_view->priv->vadjustment);
8144 visible_rect.width = allocation.width;
8145 visible_rect.height = allocation.height;
8147 if (((item->item->cell_area.x + item->item->cell_area.width) < visible_rect.x) ||
8148 ((item->item->cell_area.y + item->item->cell_area.height) < (visible_rect.y)) ||
8149 (item->item->cell_area.x > (visible_rect.x + visible_rect.width)) ||
8150 (item->item->cell_area.y > (visible_rect.y + visible_rect.height)))
8159 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8160 gboolean emit_signal)
8162 if (gtk_icon_view_item_accessible_is_showing (item))
8163 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8166 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8171 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8175 item->state_set = atk_state_set_new ();
8177 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8178 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8179 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8180 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8181 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8183 for (i = 0; i < LAST_ACTION; i++)
8184 item->action_descriptions[i] = NULL;
8186 item->image_description = NULL;
8188 item->action_idle_handler = 0;
8192 gtk_icon_view_item_accessible_finalize (GObject *object)
8194 GtkIconViewItemAccessible *item;
8197 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8199 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8202 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8204 if (item->state_set)
8205 g_object_unref (item->state_set);
8207 if (item->text_buffer)
8208 g_object_unref (item->text_buffer);
8210 for (i = 0; i < LAST_ACTION; i++)
8211 g_free (item->action_descriptions[i]);
8213 g_free (item->image_description);
8215 if (item->action_idle_handler)
8217 g_source_remove (item->action_idle_handler);
8218 item->action_idle_handler = 0;
8221 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8225 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8227 GtkIconViewItemAccessible *item;
8229 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8230 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8233 return gtk_widget_get_accessible (item->widget);
8239 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8241 GtkIconViewItemAccessible *item;
8243 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8244 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8246 return item->item->index;
8249 static AtkStateSet *
8250 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8252 GtkIconViewItemAccessible *item;
8253 GtkIconView *icon_view;
8255 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8256 g_return_val_if_fail (item->state_set, NULL);
8261 icon_view = GTK_ICON_VIEW (item->widget);
8262 if (icon_view->priv->cursor_item == item->item)
8263 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8265 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8266 if (item->item->selected)
8267 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8269 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8271 return g_object_ref (item->state_set);
8275 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8277 GObjectClass *gobject_class;
8279 accessible_item_parent_class = g_type_class_peek_parent (klass);
8281 gobject_class = (GObjectClass *)klass;
8283 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8285 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8286 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8287 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8291 gtk_icon_view_item_accessible_get_type (void)
8293 static GType type = 0;
8297 const GTypeInfo tinfo =
8299 sizeof (GtkIconViewItemAccessibleClass),
8300 (GBaseInitFunc) NULL, /* base init */
8301 (GBaseFinalizeFunc) NULL, /* base finalize */
8302 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8303 (GClassFinalizeFunc) NULL, /* class finalize */
8304 NULL, /* class data */
8305 sizeof (GtkIconViewItemAccessible), /* instance size */
8306 0, /* nb preallocs */
8307 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8308 NULL /* value table */
8311 const GInterfaceInfo atk_component_info =
8313 (GInterfaceInitFunc) atk_component_item_interface_init,
8314 (GInterfaceFinalizeFunc) NULL,
8317 const GInterfaceInfo atk_action_info =
8319 (GInterfaceInitFunc) atk_action_item_interface_init,
8320 (GInterfaceFinalizeFunc) NULL,
8323 const GInterfaceInfo atk_image_info =
8325 (GInterfaceInitFunc) atk_image_item_interface_init,
8326 (GInterfaceFinalizeFunc) NULL,
8329 const GInterfaceInfo atk_text_info =
8331 (GInterfaceInitFunc) atk_text_item_interface_init,
8332 (GInterfaceFinalizeFunc) NULL,
8336 type = g_type_register_static (ATK_TYPE_OBJECT,
8337 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8338 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8339 &atk_component_info);
8340 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8342 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8344 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8351 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8352 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8353 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8355 static GType gtk_icon_view_accessible_get_type (void);
8360 } GtkIconViewAccessible;
8366 } GtkIconViewItemAccessibleInfo;
8372 GtkAdjustment *old_hadj;
8373 GtkAdjustment *old_vadj;
8375 GtkTreeModel *model;
8377 } GtkIconViewAccessiblePrivate;
8379 static GtkIconViewAccessiblePrivate *
8380 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8382 return g_object_get_qdata (G_OBJECT (accessible),
8383 accessible_private_data_quark);
8387 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8391 GtkIconViewItemAccessibleInfo *info;
8392 GtkIconViewItemAccessibleInfo *tmp_info;
8393 GtkIconViewAccessiblePrivate *priv;
8396 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8398 info->index = index;
8400 priv = gtk_icon_view_accessible_get_priv (accessible);
8401 items = priv->items;
8404 tmp_info = items->data;
8405 if (tmp_info->index > index)
8407 items = items->next;
8409 priv->items = g_list_insert_before (priv->items, items, info);
8410 priv->old_hadj = NULL;
8411 priv->old_vadj = NULL;
8415 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8417 GtkIconView *icon_view;
8420 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8424 icon_view = GTK_ICON_VIEW (widget);
8426 return g_list_length (icon_view->priv->items);
8430 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8433 GtkIconViewAccessiblePrivate *priv;
8434 GtkIconViewItemAccessibleInfo *info;
8437 priv = gtk_icon_view_accessible_get_priv (accessible);
8438 items = priv->items;
8443 if (info->index == index)
8445 items = items->next;
8451 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8454 GtkIconView *icon_view;
8458 GtkIconViewItemAccessible *a11y_item;
8460 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8464 icon_view = GTK_ICON_VIEW (widget);
8465 icons = g_list_nth (icon_view->priv->items, index);
8469 GtkIconViewItem *item = icons->data;
8471 g_return_val_if_fail (item->index == index, NULL);
8472 obj = gtk_icon_view_accessible_find_child (accessible, index);
8477 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8478 gtk_icon_view_item_accessible_info_new (accessible,
8481 obj->role = ATK_ROLE_ICON;
8482 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8483 a11y_item->item = item;
8484 a11y_item->widget = widget;
8485 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8487 text = get_text (icon_view, item);
8490 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8494 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8495 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8503 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8506 GtkIconViewAccessiblePrivate *priv;
8507 GtkIconViewItemAccessibleInfo *info;
8508 GtkIconViewItemAccessible *item;
8511 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8515 gboolean act_on_item;
8517 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
8521 items = priv->items;
8523 act_on_item = (list == NULL);
8528 info = (GtkIconViewItemAccessibleInfo *)items->data;
8529 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8531 if (act_on_item == FALSE && list == items)
8535 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8537 items = items->next;
8543 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8544 GtkIconViewAccessible *view)
8546 gtk_icon_view_accessible_traverse_items (view, NULL);
8550 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
8551 GtkOrientation orientation,
8552 GtkAdjustment *adjustment)
8554 GtkIconViewAccessiblePrivate *priv;
8555 GtkAdjustment **old_adj_ptr;
8557 priv = gtk_icon_view_accessible_get_priv (accessible);
8559 /* Adjustments are set for the first time in constructor and priv is not
8560 * initialized at that time, so skip this first setting. */
8564 if (orientation == GTK_ORIENTATION_HORIZONTAL)
8566 if (priv->old_hadj == adjustment)
8569 old_adj_ptr = &priv->old_hadj;
8573 if (priv->old_vadj == adjustment)
8576 old_adj_ptr = &priv->old_vadj;
8579 /* Disconnect signal handlers */
8582 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
8583 (gpointer *)&priv->old_hadj);
8584 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
8585 gtk_icon_view_accessible_adjustment_changed,
8589 /* Connect signal */
8590 *old_adj_ptr = adjustment;
8591 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
8592 g_signal_connect (adjustment, "value-changed",
8593 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8598 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8606 GtkIconView *icon_view;
8607 GtkIconViewItem *item;
8608 GtkIconViewItemAccessible *a11y_item;
8612 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8613 index = gtk_tree_path_get_indices(path)[0];
8614 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
8615 gtk_icon_view_accessible_find_child (atk_obj, index));
8619 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
8620 icon_view = GTK_ICON_VIEW (widget);
8621 item = a11y_item->item;
8623 name = atk_object_get_name (ATK_OBJECT (a11y_item));
8625 if (!name || strcmp (name, "") == 0)
8627 text = get_text (icon_view, item);
8630 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8636 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8642 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8647 GtkIconViewAccessiblePrivate *priv;
8648 GtkIconViewItemAccessibleInfo *info;
8649 GtkIconViewAccessible *view;
8650 GtkIconViewItemAccessible *item;
8656 index = gtk_tree_path_get_indices(path)[0];
8657 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8658 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8659 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8661 items = priv->items;
8666 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8667 if (info->index != item->item->index)
8669 if (info->index < index)
8670 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8672 if (tmp_list == NULL)
8675 info->index = item->item->index;
8678 items = items->next;
8680 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8681 g_signal_emit_by_name (atk_obj, "children-changed::add",
8687 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8691 GtkIconViewAccessiblePrivate *priv;
8692 GtkIconViewItemAccessibleInfo *info;
8693 GtkIconViewAccessible *view;
8694 GtkIconViewItemAccessible *item;
8697 GList *deleted_item;
8701 index = gtk_tree_path_get_indices(path)[0];
8702 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8703 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8704 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8706 items = priv->items;
8708 deleted_item = NULL;
8713 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8714 if (info->index == index)
8716 deleted_item = items;
8718 if (info->index != item->item->index)
8720 if (tmp_list == NULL)
8723 info->index = item->item->index;
8726 items = items->next;
8728 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8731 info = deleted_item->data;
8732 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8733 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8735 priv->items = g_list_remove_link (priv->items, deleted_item);
8743 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8744 GtkIconViewItemAccessibleInfo *i2)
8746 return i1->index - i2->index;
8750 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8756 GtkIconViewAccessiblePrivate *priv;
8757 GtkIconViewItemAccessibleInfo *info;
8758 GtkIconView *icon_view;
8759 GtkIconViewItemAccessible *item;
8765 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8766 icon_view = GTK_ICON_VIEW (user_data);
8767 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8769 length = gtk_tree_model_iter_n_children (tree_model, NULL);
8771 order = g_new (gint, length);
8772 for (i = 0; i < length; i++)
8773 order [new_order[i]] = i;
8775 items = priv->items;
8779 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8780 info->index = order[info->index];
8781 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8782 items = items->next;
8785 priv->items = g_list_sort (priv->items,
8786 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8792 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8797 obj = G_OBJECT (model);
8798 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8799 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8800 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8801 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8805 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8809 obj = G_OBJECT (icon_view->priv->model);
8810 g_signal_connect_data (obj, "row-changed",
8811 (GCallback) gtk_icon_view_accessible_model_row_changed,
8812 icon_view, NULL, 0);
8813 g_signal_connect_data (obj, "row-inserted",
8814 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8815 icon_view, NULL, G_CONNECT_AFTER);
8816 g_signal_connect_data (obj, "row-deleted",
8817 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8818 icon_view, NULL, G_CONNECT_AFTER);
8819 g_signal_connect_data (obj, "rows-reordered",
8820 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8821 icon_view, NULL, G_CONNECT_AFTER);
8825 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8827 GtkIconViewItemAccessibleInfo *info;
8830 items = priv->items;
8833 info = (GtkIconViewItemAccessibleInfo *) items->data;
8834 g_object_unref (info->item);
8835 g_free (items->data);
8836 items = items->next;
8838 g_list_free (priv->items);
8843 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8846 GtkIconView *icon_view;
8849 GtkIconViewAccessiblePrivate *priv;
8851 if (strcmp (pspec->name, "model") == 0)
8853 widget = GTK_WIDGET (obj);
8854 atk_obj = gtk_widget_get_accessible (widget);
8855 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8858 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8859 (gpointer *)&priv->model);
8860 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8862 gtk_icon_view_accessible_clear_cache (priv);
8864 icon_view = GTK_ICON_VIEW (obj);
8865 priv->model = icon_view->priv->model;
8866 /* If there is no model the GtkIconView is probably being destroyed */
8869 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8870 gtk_icon_view_accessible_connect_model_signals (icon_view);
8878 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8881 GtkIconViewAccessiblePrivate *priv;
8882 GtkIconView *icon_view;
8884 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8885 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8887 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8888 g_object_set_qdata (G_OBJECT (accessible),
8889 accessible_private_data_quark,
8892 icon_view = GTK_ICON_VIEW (data);
8893 if (icon_view->priv->hadjustment)
8894 gtk_icon_view_accessible_set_adjustment (accessible,
8895 GTK_ORIENTATION_HORIZONTAL,
8896 icon_view->priv->hadjustment);
8897 if (icon_view->priv->vadjustment)
8898 gtk_icon_view_accessible_set_adjustment (accessible,
8899 GTK_ORIENTATION_VERTICAL,
8900 icon_view->priv->vadjustment);
8901 g_signal_connect (data,
8903 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8906 priv->model = icon_view->priv->model;
8909 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8910 gtk_icon_view_accessible_connect_model_signals (icon_view);
8913 accessible->role = ATK_ROLE_LAYERED_PANE;
8917 gtk_icon_view_accessible_finalize (GObject *object)
8919 GtkIconViewAccessiblePrivate *priv;
8921 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8922 gtk_icon_view_accessible_clear_cache (priv);
8926 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8930 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8931 GtkAccessible *accessible)
8934 GtkIconViewAccessiblePrivate *priv;
8936 atk_obj = ATK_OBJECT (accessible);
8937 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8940 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8941 (gpointer *)&priv->old_hadj);
8943 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8944 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8946 priv->old_hadj = NULL;
8950 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8951 (gpointer *)&priv->old_vadj);
8953 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8954 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8956 priv->old_vadj = NULL;
8961 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8965 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8968 g_signal_connect_after (widget,
8970 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8973 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8977 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8979 GObjectClass *gobject_class;
8980 GtkAccessibleClass *accessible_class;
8982 accessible_parent_class = g_type_class_peek_parent (klass);
8984 gobject_class = (GObjectClass *)klass;
8985 accessible_class = (GtkAccessibleClass *)klass;
8987 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8989 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8990 klass->ref_child = gtk_icon_view_accessible_ref_child;
8991 klass->initialize = gtk_icon_view_accessible_initialize;
8993 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8995 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8999 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9002 AtkCoordType coord_type)
9005 GtkIconView *icon_view;
9006 GtkIconViewItem *item;
9009 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9011 /* State is defunct */
9014 icon_view = GTK_ICON_VIEW (widget);
9015 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9016 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9018 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9024 atk_component_interface_init (AtkComponentIface *iface)
9026 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9030 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9034 GtkIconView *icon_view;
9035 GtkIconViewItem *item;
9037 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9041 icon_view = GTK_ICON_VIEW (widget);
9043 item = g_list_nth_data (icon_view->priv->items, i);
9048 gtk_icon_view_select_item (icon_view, item);
9054 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9057 GtkIconView *icon_view;
9059 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9063 icon_view = GTK_ICON_VIEW (widget);
9064 gtk_icon_view_unselect_all (icon_view);
9070 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9075 GtkIconView *icon_view;
9076 GtkIconViewItem *item;
9078 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9082 icon_view = GTK_ICON_VIEW (widget);
9084 l = icon_view->priv->items;
9091 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9102 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9105 GtkIconView *icon_view;
9106 GtkIconViewItem *item;
9110 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9114 icon_view = GTK_ICON_VIEW (widget);
9116 l = icon_view->priv->items;
9132 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9136 GtkIconView *icon_view;
9137 GtkIconViewItem *item;
9139 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9143 icon_view = GTK_ICON_VIEW (widget);
9145 item = g_list_nth_data (icon_view->priv->items, i);
9149 return item->selected;
9153 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9157 GtkIconView *icon_view;
9158 GtkIconViewItem *item;
9162 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9166 icon_view = GTK_ICON_VIEW (widget);
9167 l = icon_view->priv->items;
9176 gtk_icon_view_unselect_item (icon_view, item);
9188 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9191 GtkIconView *icon_view;
9193 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9197 icon_view = GTK_ICON_VIEW (widget);
9198 gtk_icon_view_select_all (icon_view);
9203 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9205 iface->add_selection = gtk_icon_view_accessible_add_selection;
9206 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9207 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9208 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9209 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9210 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9211 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9215 gtk_icon_view_accessible_get_type (void)
9217 static GType type = 0;
9223 sizeof (GtkContainerAccessibleClass), /* class size */
9224 (GBaseInitFunc) NULL, /* base init */
9225 (GBaseFinalizeFunc) NULL, /* base finalize */
9226 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9227 (GClassFinalizeFunc) NULL, /* class finalize */
9228 NULL, /* class data */
9229 sizeof (GtkContainerAccessible), /* instance size */
9230 0, /* nb preallocs */
9231 (GInstanceInitFunc) NULL, /* instance init */
9232 NULL /* value table */
9234 const GInterfaceInfo atk_component_info =
9236 (GInterfaceInitFunc) atk_component_interface_init,
9237 (GInterfaceFinalizeFunc) NULL,
9240 const GInterfaceInfo atk_selection_info =
9242 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9243 (GInterfaceFinalizeFunc) NULL,
9247 type = g_type_register_static (GTK_TYPE_CONTAINER_ACCESSIBLE,
9248 I_("GtkIconViewAccessible"), &tinfo, 0);
9249 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9250 &atk_component_info);
9251 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9252 &atk_selection_info);
9258 gtk_icon_view_accessible_new (GObject *obj)
9260 AtkObject *accessible;
9262 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9264 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9265 atk_object_initialize (accessible, obj);
9271 gtk_icon_view_accessible_factory_get_accessible_type (void)
9273 return gtk_icon_view_accessible_get_type ();
9277 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9279 return gtk_icon_view_accessible_new (obj);
9283 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9285 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9286 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9290 gtk_icon_view_accessible_factory_get_type (void)
9292 static GType type = 0;
9296 const GTypeInfo tinfo =
9298 sizeof (AtkObjectFactoryClass),
9299 NULL, /* base_init */
9300 NULL, /* base_finalize */
9301 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9302 NULL, /* class_finalize */
9303 NULL, /* class_data */
9304 sizeof (AtkObjectFactory),
9305 0, /* n_preallocs */
9309 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9310 I_("GtkIconViewAccessibleFactory"),
9318 gtk_icon_view_get_accessible (GtkWidget *widget)
9320 static gboolean first_time = TRUE;
9324 _gtk_accessible_set_factory_type (GTK_TYPE_ICON_VIEW,
9325 gtk_icon_view_accessible_factory_get_type ());
9328 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9332 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9333 GtkBuilder *builder,
9335 const gchar *tagname,
9336 GMarkupParser *parser,
9339 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9340 tagname, parser, data))
9343 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9344 tagname, parser, data);
9348 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9349 GtkBuilder *builder,
9351 const gchar *tagname,
9354 if (!_gtk_cell_layout_buildable_custom_tag_end (buildable, builder,
9355 child, tagname, data))
9356 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,