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.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtktextbuffer.h"
42 #include "gtktreednd.h"
43 #include "gtkprivate.h"
46 #undef DEBUG_ICON_VIEW
48 #define SCROLL_EDGE_SIZE 15
50 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
52 typedef struct _GtkIconViewItem GtkIconViewItem;
53 struct _GtkIconViewItem
61 gint x, y, width, height;
64 * box[i] is the actual area occupied by cell i,
65 * before, after are used to calculate the cell
66 * area relative to the box.
67 * See gtk_icon_view_get_cell_area().
75 guint selected_before_rubberbanding : 1;
79 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
80 struct _GtkIconViewCellInfo
82 GtkCellRenderer *cell;
92 GtkCellLayoutDataFunc func;
94 GDestroyNotify destroy;
97 typedef struct _GtkIconViewChild GtkIconViewChild;
98 struct _GtkIconViewChild
101 GtkIconViewItem *item;
105 struct _GtkIconViewPrivate
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gboolean doing_rubberband;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
134 GtkIconViewItem *edited_item;
135 GtkCellEditable *editable;
137 GtkIconViewItem *last_single_clicked;
144 GtkOrientation orientation;
164 GdkModifierType start_button_mask;
169 GdkDragAction source_actions;
170 GdkDragAction dest_actions;
172 GtkTreeRowReference *dest_item;
173 GtkIconViewDropPosition dest_pos;
176 GtkTreeRowReference *scroll_to_path;
177 gfloat scroll_to_row_align;
178 gfloat scroll_to_col_align;
179 guint scroll_to_use_align : 1;
181 guint source_set : 1;
183 guint reorderable : 1;
184 guint empty_view_drop :1;
186 guint ctrl_pressed : 1;
187 guint shift_pressed : 1;
189 guint draw_focus : 1;
202 ACTIVATE_CURSOR_ITEM,
228 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
229 static void gtk_icon_view_finalize (GObject *object);
230 static void gtk_icon_view_set_property (GObject *object,
234 static void gtk_icon_view_get_property (GObject *object,
239 /* GtkObject vfuncs */
240 static void gtk_icon_view_destroy (GtkObject *object);
242 /* GtkWidget vfuncs */
243 static void gtk_icon_view_realize (GtkWidget *widget);
244 static void gtk_icon_view_unrealize (GtkWidget *widget);
245 static void gtk_icon_view_style_set (GtkWidget *widget,
246 GtkStyle *previous_style);
247 static void gtk_icon_view_state_changed (GtkWidget *widget,
248 GtkStateType previous_state);
249 static void gtk_icon_view_size_request (GtkWidget *widget,
250 GtkRequisition *requisition);
251 static void gtk_icon_view_size_allocate (GtkWidget *widget,
252 GtkAllocation *allocation);
253 static gboolean gtk_icon_view_expose (GtkWidget *widget,
254 GdkEventExpose *expose);
255 static gboolean gtk_icon_view_motion (GtkWidget *widget,
256 GdkEventMotion *event);
257 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
258 GdkEventButton *event);
259 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
260 GdkEventButton *event);
261 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
263 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
265 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
268 /* GtkContainer vfuncs */
269 static void gtk_icon_view_remove (GtkContainer *container,
271 static void gtk_icon_view_forall (GtkContainer *container,
272 gboolean include_internals,
273 GtkCallback callback,
274 gpointer callback_data);
276 /* GtkIconView vfuncs */
277 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
279 GtkAdjustment *vadj);
280 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
282 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
283 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
284 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
286 /* Internal functions */
287 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
288 GtkIconView *icon_view);
289 static void gtk_icon_view_layout (GtkIconView *icon_view);
290 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
293 GtkIconViewItem *item,
295 GdkDrawable *drawable,
298 gboolean draw_focus);
299 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
302 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
304 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
305 GtkIconViewItem *item);
306 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
307 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
308 GtkIconViewItem *item,
310 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
313 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
314 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
315 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
316 GtkIconViewItem *item,
321 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
322 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
323 GtkIconViewItem *item);
324 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
325 GtkIconViewItem *item,
327 static void gtk_icon_view_update_rubberband (gpointer data);
328 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
329 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
330 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
333 GtkMovementStep step,
335 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
336 GtkMovementStep step,
338 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
340 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
342 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
344 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
346 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
347 GtkIconViewItem *item);
348 static void gtk_icon_view_select_item (GtkIconView *icon_view,
349 GtkIconViewItem *item);
350 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
351 GtkIconViewItem *item);
352 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
353 GtkIconViewItem *anchor,
354 GtkIconViewItem *cursor);
355 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
358 gboolean only_in_cell,
359 GtkIconViewCellInfo **cell_at_pos);
360 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
361 GtkIconViewItem *item,
362 GtkIconViewCellInfo *cell_info,
363 GdkRectangle *cell_area);
364 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
365 GtkIconViewItem *item,
366 GtkIconViewCellInfo *info,
368 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
369 GtkCellRenderer *renderer);
370 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
371 GtkIconViewItem *item);
372 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
378 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
379 GtkCellRenderer *renderer,
380 const gchar *attribute,
382 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
383 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
384 GtkCellRenderer *renderer);
385 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
386 GtkCellRenderer *cell,
387 GtkCellLayoutDataFunc func,
389 GDestroyNotify destroy);
390 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
391 GtkCellRenderer *cell,
393 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
395 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
396 GtkIconViewItem *item,
397 GtkIconViewCellInfo *cell_info,
399 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
400 GtkIconViewItem *item);
401 static void gtk_icon_view_put (GtkIconView *icon_view,
403 GtkIconViewItem *item,
405 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
406 GtkIconView *icon_view);
407 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
408 GtkIconViewItem *item,
409 GtkIconViewCellInfo *cell_info,
411 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
412 gboolean cancel_editing);
414 /* Source side drag signals */
415 static void gtk_icon_view_drag_begin (GtkWidget *widget,
416 GdkDragContext *context);
417 static void gtk_icon_view_drag_end (GtkWidget *widget,
418 GdkDragContext *context);
419 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
420 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
425 GdkDragContext *context);
427 /* Target side drag signals */
428 static void gtk_icon_view_drag_leave (GtkWidget *widget,
429 GdkDragContext *context,
431 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
432 GdkDragContext *context,
436 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
437 GdkDragContext *context,
441 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
442 GdkDragContext *context,
445 GtkSelectionData *selection_data,
448 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
449 GdkEventMotion *event);
451 static void remove_scroll_timeout (GtkIconView *icon_view);
453 static void adjust_wrap_width (GtkIconView *icon_view,
454 GtkIconViewItem *item);
457 static GtkBuildableIface *parent_buildable_iface;
458 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
459 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
462 const gchar *tagname,
463 GMarkupParser *parser,
465 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
468 const gchar *tagname,
471 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
473 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
474 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
475 gtk_icon_view_cell_layout_init)
476 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
477 gtk_icon_view_buildable_init))
480 gtk_icon_view_class_init (GtkIconViewClass *klass)
482 GObjectClass *gobject_class;
483 GtkObjectClass *object_class;
484 GtkWidgetClass *widget_class;
485 GtkContainerClass *container_class;
486 GtkBindingSet *binding_set;
488 binding_set = gtk_binding_set_by_class (klass);
490 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
492 gobject_class = (GObjectClass *) klass;
493 object_class = (GtkObjectClass *) klass;
494 widget_class = (GtkWidgetClass *) klass;
495 container_class = (GtkContainerClass *) klass;
497 gobject_class->finalize = gtk_icon_view_finalize;
498 gobject_class->set_property = gtk_icon_view_set_property;
499 gobject_class->get_property = gtk_icon_view_get_property;
501 object_class->destroy = gtk_icon_view_destroy;
503 widget_class->realize = gtk_icon_view_realize;
504 widget_class->unrealize = gtk_icon_view_unrealize;
505 widget_class->style_set = gtk_icon_view_style_set;
506 widget_class->get_accessible = gtk_icon_view_get_accessible;
507 widget_class->size_request = gtk_icon_view_size_request;
508 widget_class->size_allocate = gtk_icon_view_size_allocate;
509 widget_class->expose_event = gtk_icon_view_expose;
510 widget_class->motion_notify_event = gtk_icon_view_motion;
511 widget_class->button_press_event = gtk_icon_view_button_press;
512 widget_class->button_release_event = gtk_icon_view_button_release;
513 widget_class->key_press_event = gtk_icon_view_key_press;
514 widget_class->key_release_event = gtk_icon_view_key_release;
515 widget_class->drag_begin = gtk_icon_view_drag_begin;
516 widget_class->drag_end = gtk_icon_view_drag_end;
517 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
518 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
519 widget_class->drag_leave = gtk_icon_view_drag_leave;
520 widget_class->drag_motion = gtk_icon_view_drag_motion;
521 widget_class->drag_drop = gtk_icon_view_drag_drop;
522 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
523 widget_class->state_changed = gtk_icon_view_state_changed;
525 container_class->remove = gtk_icon_view_remove;
526 container_class->forall = gtk_icon_view_forall;
528 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
529 klass->select_all = gtk_icon_view_real_select_all;
530 klass->unselect_all = gtk_icon_view_real_unselect_all;
531 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
532 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
533 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
534 klass->move_cursor = gtk_icon_view_real_move_cursor;
538 * GtkIconView:selection-mode:
540 * The ::selection-mode property specifies the selection mode of
541 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
542 * is enabled, for the other modes, only keyboard selection is possible.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_enum ("selection-mode",
549 P_("Selection mode"),
550 P_("The selection mode"),
551 GTK_TYPE_SELECTION_MODE,
552 GTK_SELECTION_SINGLE,
553 GTK_PARAM_READWRITE));
556 * GtkIconView:pixbuf-column:
558 * The ::pixbuf-column property contains the number of the model column
559 * containing the pixbufs which are displayed. The pixbuf column must be
560 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
561 * display of pixbufs.
565 g_object_class_install_property (gobject_class,
567 g_param_spec_int ("pixbuf-column",
569 P_("Model column used to retrieve the icon pixbuf from"),
571 GTK_PARAM_READWRITE));
574 * GtkIconView:text-column:
576 * The ::text-column property contains the number of the model column
577 * containing the texts which are displayed. The text column must be
578 * of type #G_TYPE_STRING. If this property and the :markup-column
579 * property are both set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("text-column",
587 P_("Model column used to retrieve the text from"),
589 GTK_PARAM_READWRITE));
593 * GtkIconView:markup-column:
595 * The ::markup-column property contains the number of the model column
596 * containing markup information to be displayed. The markup column must be
597 * of type #G_TYPE_STRING. If this property and the :text-column property
598 * are both set to column numbers, it overrides the text column.
599 * If both are set to -1, no texts are displayed.
603 g_object_class_install_property (gobject_class,
605 g_param_spec_int ("markup-column",
607 P_("Model column used to retrieve the text if using Pango markup"),
609 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_object ("model",
614 P_("Icon View Model"),
615 P_("The model for the icon view"),
617 GTK_PARAM_READWRITE));
620 * GtkIconView:columns:
622 * The columns property contains the number of the columns in which the
623 * items should be displayed. If it is -1, the number of columns will
624 * be chosen automatically to fill the available area.
628 g_object_class_install_property (gobject_class,
630 g_param_spec_int ("columns",
631 P_("Number of columns"),
632 P_("Number of columns to display"),
634 GTK_PARAM_READWRITE));
638 * GtkIconView:item-width:
640 * The item-width property specifies the width to use for each item.
641 * If it is set to -1, the icon view will automatically determine a
642 * suitable item size.
646 g_object_class_install_property (gobject_class,
648 g_param_spec_int ("item-width",
649 P_("Width for each item"),
650 P_("The width used for each item"),
652 GTK_PARAM_READWRITE));
655 * GtkIconView:spacing:
657 * The spacing property specifies the space which is inserted between
658 * the cells (i.e. the icon and the text) of an item.
662 g_object_class_install_property (gobject_class,
664 g_param_spec_int ("spacing",
666 P_("Space which is inserted between cells of an item"),
668 GTK_PARAM_READWRITE));
671 * GtkIconView:row-spacing:
673 * The row-spacing property specifies the space which is inserted between
674 * the rows of the icon view.
678 g_object_class_install_property (gobject_class,
680 g_param_spec_int ("row-spacing",
682 P_("Space which is inserted between grid rows"),
684 GTK_PARAM_READWRITE));
687 * GtkIconView:column-spacing:
689 * The column-spacing property specifies the space which is inserted between
690 * the columns of the icon view.
694 g_object_class_install_property (gobject_class,
696 g_param_spec_int ("column-spacing",
697 P_("Column Spacing"),
698 P_("Space which is inserted between grid columns"),
700 GTK_PARAM_READWRITE));
703 * GtkIconView:margin:
705 * The margin property specifies the space which is inserted
706 * at the edges of the icon view.
710 g_object_class_install_property (gobject_class,
712 g_param_spec_int ("margin",
714 P_("Space which is inserted at the edges of the icon view"),
716 GTK_PARAM_READWRITE));
719 * GtkIconView:orientation:
721 * The orientation property specifies how the cells (i.e. the icon and
722 * the text) of the item are positioned relative to each other.
726 g_object_class_install_property (gobject_class,
728 g_param_spec_enum ("orientation",
730 P_("How the text and icon of each item are positioned relative to each other"),
731 GTK_TYPE_ORIENTATION,
732 GTK_ORIENTATION_VERTICAL,
733 GTK_PARAM_READWRITE));
736 * GtkIconView:reorderable:
738 * The reorderable property specifies if the items can be reordered
743 g_object_class_install_property (gobject_class,
745 g_param_spec_boolean ("reorderable",
747 P_("View is reorderable"),
751 g_object_class_install_property (gobject_class,
753 g_param_spec_int ("tooltip-column",
754 P_("Tooltip Column"),
755 P_("The column in the model containing the tooltip texts for the items"),
759 GTK_PARAM_READWRITE));
762 * GtkIconView:item-padding:
764 * The item-padding property specifies the padding around each
765 * of the icon view's item.
769 g_object_class_install_property (gobject_class,
771 g_param_spec_int ("item-padding",
773 P_("Padding around icon view items"),
775 GTK_PARAM_READWRITE));
779 /* Style properties */
780 gtk_widget_class_install_style_property (widget_class,
781 g_param_spec_boxed ("selection-box-color",
782 P_("Selection Box Color"),
783 P_("Color of the selection box"),
785 GTK_PARAM_READABLE));
787 gtk_widget_class_install_style_property (widget_class,
788 g_param_spec_uchar ("selection-box-alpha",
789 P_("Selection Box Alpha"),
790 P_("Opacity of the selection box"),
793 GTK_PARAM_READABLE));
797 * GtkIconView::set-scroll-adjustments
798 * @horizontal: the horizontal #GtkAdjustment
799 * @vertical: the vertical #GtkAdjustment
801 * Set the scroll adjustments for the icon view. Usually scrolled containers
802 * like #GtkScrolledWindow will emit this signal to connect two instances
803 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
805 widget_class->set_scroll_adjustments_signal =
806 g_signal_new (I_("set-scroll-adjustments"),
807 G_TYPE_FROM_CLASS (gobject_class),
809 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
811 _gtk_marshal_VOID__OBJECT_OBJECT,
813 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
816 * GtkIconView::item-activated:
817 * @iconview: the object on which the signal is emitted
818 * @path: the #GtkTreePath for the activated item
820 * The ::item-activated signal is emitted when the method
821 * gtk_icon_view_item_activated() is called or the user double
822 * clicks an item. It is also emitted when a non-editable item
823 * is selected and one of the keys: Space, Return or Enter is
826 icon_view_signals[ITEM_ACTIVATED] =
827 g_signal_new (I_("item-activated"),
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
832 g_cclosure_marshal_VOID__BOXED,
837 * GtkIconView::selection-changed:
838 * @iconview: the object on which the signal is emitted
840 * The ::selection-changed signal is emitted when the selection
841 * (i.e. the set of selected items) changes.
843 icon_view_signals[SELECTION_CHANGED] =
844 g_signal_new (I_("selection-changed"),
845 G_TYPE_FROM_CLASS (gobject_class),
847 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
849 g_cclosure_marshal_VOID__VOID,
853 * GtkIconView::select-all:
854 * @iconview: the object on which the signal is emitted
856 * A <link linkend="keybinding-signals">keybinding signal</link>
857 * which gets emitted when the user selects all items.
859 * Applications should not connect to it, but may emit it with
860 * g_signal_emit_by_name() if they need to control selection
863 * The default binding for this signal is Ctrl-a.
865 icon_view_signals[SELECT_ALL] =
866 g_signal_new (I_("select-all"),
867 G_TYPE_FROM_CLASS (gobject_class),
868 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
869 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
871 g_cclosure_marshal_VOID__VOID,
875 * GtkIconView::unselect-all:
876 * @iconview: the object on which the signal is emitted
878 * A <link linkend="keybinding-signals">keybinding signal</link>
879 * which gets emitted when the user unselects all items.
881 * Applications should not connect to it, but may emit it with
882 * g_signal_emit_by_name() if they need to control selection
885 * The default binding for this signal is Ctrl-Shift-a.
887 icon_view_signals[UNSELECT_ALL] =
888 g_signal_new (I_("unselect-all"),
889 G_TYPE_FROM_CLASS (gobject_class),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
893 g_cclosure_marshal_VOID__VOID,
897 * GtkIconView::select-cursor-item:
898 * @iconview: the object on which the signal is emitted
900 * A <link linkend="keybinding-signals">keybinding signal</link>
901 * which gets emitted when the user selects the item that is currently
904 * Applications should not connect to it, but may emit it with
905 * g_signal_emit_by_name() if they need to control selection
908 * There is no default binding for this signal.
910 icon_view_signals[SELECT_CURSOR_ITEM] =
911 g_signal_new (I_("select-cursor-item"),
912 G_TYPE_FROM_CLASS (gobject_class),
913 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
914 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
916 g_cclosure_marshal_VOID__VOID,
920 * GtkIconView::toggle-cursor-item:
921 * @iconview: the object on which the signal is emitted
923 * A <link linkend="keybinding-signals">keybinding signal</link>
924 * which gets emitted when the user toggles whether the currently
925 * focused item is selected or not. The exact effect of this
926 * depend on the selection mode.
928 * Applications should not connect to it, but may emit it with
929 * g_signal_emit_by_name() if they need to control selection
932 * There is no default binding for this signal is Ctrl-Space.
934 icon_view_signals[TOGGLE_CURSOR_ITEM] =
935 g_signal_new (I_("toggle-cursor-item"),
936 G_TYPE_FROM_CLASS (gobject_class),
937 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
938 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
940 g_cclosure_marshal_VOID__VOID,
944 * GtkIconView::activate-cursor-item:
945 * @iconview: the object on which the signal is emitted
947 * A <link linkend="keybinding-signals">keybinding signal</link>
948 * which gets emitted when the user activates the currently
951 * Applications should not connect to it, but may emit it with
952 * g_signal_emit_by_name() if they need to control activation
955 * The default bindings for this signal are Space, Return and Enter.
957 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
958 g_signal_new (I_("activate-cursor-item"),
959 G_TYPE_FROM_CLASS (gobject_class),
960 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
961 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
963 _gtk_marshal_BOOLEAN__VOID,
967 * GtkIconView::move-cursor:
968 * @iconview: the object which received the signal
969 * @step: the granularity of the move, as a #GtkMovementStep
970 * @count: the number of @step units to move
972 * The ::move-cursor signal is a
973 * <link linkend="keybinding-signals">keybinding signal</link>
974 * which gets emitted when the user initiates a cursor movement.
976 * Applications should not connect to it, but may emit it with
977 * g_signal_emit_by_name() if they need to control the cursor
980 * The default bindings for this signal include
982 * <listitem>Arrow keys which move by individual steps</listitem>
983 * <listitem>Home/End keys which move to the first/last item</listitem>
984 * <listitem>PageUp/PageDown which move by "pages"</listitem>
987 * All of these will extend the selection when combined with
988 * the Shift modifier.
990 icon_view_signals[MOVE_CURSOR] =
991 g_signal_new (I_("move-cursor"),
992 G_TYPE_FROM_CLASS (gobject_class),
993 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
994 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
996 _gtk_marshal_BOOLEAN__ENUM_INT,
998 GTK_TYPE_MOVEMENT_STEP,
1002 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1004 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1006 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1007 "toggle-cursor-item", 0);
1008 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1009 "toggle-cursor-item", 0);
1011 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1012 "activate-cursor-item", 0);
1013 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1014 "activate-cursor-item", 0);
1015 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1016 "activate-cursor-item", 0);
1017 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1018 "activate-cursor-item", 0);
1019 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1020 "activate-cursor-item", 0);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1023 GTK_MOVEMENT_DISPLAY_LINES, -1);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1025 GTK_MOVEMENT_DISPLAY_LINES, -1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1028 GTK_MOVEMENT_DISPLAY_LINES, 1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1030 GTK_MOVEMENT_DISPLAY_LINES, 1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1033 GTK_MOVEMENT_DISPLAY_LINES, -1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1036 GTK_MOVEMENT_DISPLAY_LINES, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1039 GTK_MOVEMENT_BUFFER_ENDS, -1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1041 GTK_MOVEMENT_BUFFER_ENDS, -1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1044 GTK_MOVEMENT_BUFFER_ENDS, 1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1046 GTK_MOVEMENT_BUFFER_ENDS, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1049 GTK_MOVEMENT_PAGES, -1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1051 GTK_MOVEMENT_PAGES, -1);
1053 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1054 GTK_MOVEMENT_PAGES, 1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1056 GTK_MOVEMENT_PAGES, 1);
1058 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1059 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1061 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1063 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1064 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1066 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1070 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1072 parent_buildable_iface = g_type_interface_peek_parent (iface);
1073 iface->add_child = _gtk_cell_layout_buildable_add_child;
1074 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1075 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1079 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1081 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1082 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1083 iface->clear = gtk_icon_view_cell_layout_clear;
1084 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1085 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1086 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1087 iface->reorder = gtk_icon_view_cell_layout_reorder;
1088 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1092 gtk_icon_view_init (GtkIconView *icon_view)
1094 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1096 icon_view->priv->width = 0;
1097 icon_view->priv->height = 0;
1098 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1099 icon_view->priv->pressed_button = -1;
1100 icon_view->priv->press_start_x = -1;
1101 icon_view->priv->press_start_y = -1;
1102 icon_view->priv->text_column = -1;
1103 icon_view->priv->markup_column = -1;
1104 icon_view->priv->pixbuf_column = -1;
1105 icon_view->priv->text_cell = -1;
1106 icon_view->priv->pixbuf_cell = -1;
1107 icon_view->priv->tooltip_column = -1;
1109 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
1111 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1113 icon_view->priv->cell_list = NULL;
1114 icon_view->priv->n_cells = 0;
1115 icon_view->priv->cursor_cell = -1;
1117 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1119 icon_view->priv->columns = -1;
1120 icon_view->priv->item_width = -1;
1121 icon_view->priv->spacing = 0;
1122 icon_view->priv->row_spacing = 6;
1123 icon_view->priv->column_spacing = 6;
1124 icon_view->priv->margin = 6;
1125 icon_view->priv->item_padding = 6;
1127 icon_view->priv->draw_focus = TRUE;
1131 gtk_icon_view_destroy (GtkObject *object)
1133 GtkIconView *icon_view;
1135 icon_view = GTK_ICON_VIEW (object);
1137 gtk_icon_view_stop_editing (icon_view, TRUE);
1139 gtk_icon_view_set_model (icon_view, NULL);
1141 if (icon_view->priv->layout_idle_id != 0)
1143 g_source_remove (icon_view->priv->layout_idle_id);
1144 icon_view->priv->layout_idle_id = 0;
1147 if (icon_view->priv->scroll_to_path != NULL)
1149 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1150 icon_view->priv->scroll_to_path = NULL;
1153 remove_scroll_timeout (icon_view);
1155 if (icon_view->priv->hadjustment != NULL)
1157 g_object_unref (icon_view->priv->hadjustment);
1158 icon_view->priv->hadjustment = NULL;
1161 if (icon_view->priv->vadjustment != NULL)
1163 g_object_unref (icon_view->priv->vadjustment);
1164 icon_view->priv->vadjustment = NULL;
1167 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1170 /* GObject methods */
1172 gtk_icon_view_finalize (GObject *object)
1174 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1176 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1181 gtk_icon_view_set_property (GObject *object,
1183 const GValue *value,
1186 GtkIconView *icon_view;
1188 icon_view = GTK_ICON_VIEW (object);
1192 case PROP_SELECTION_MODE:
1193 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1195 case PROP_PIXBUF_COLUMN:
1196 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1198 case PROP_TEXT_COLUMN:
1199 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1201 case PROP_MARKUP_COLUMN:
1202 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1205 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1207 case PROP_ORIENTATION:
1208 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1211 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1213 case PROP_ITEM_WIDTH:
1214 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1217 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1219 case PROP_ROW_SPACING:
1220 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1222 case PROP_COLUMN_SPACING:
1223 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1226 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1228 case PROP_REORDERABLE:
1229 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1232 case PROP_TOOLTIP_COLUMN:
1233 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1236 case PROP_ITEM_PADDING:
1237 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1247 gtk_icon_view_get_property (GObject *object,
1252 GtkIconView *icon_view;
1254 icon_view = GTK_ICON_VIEW (object);
1258 case PROP_SELECTION_MODE:
1259 g_value_set_enum (value, icon_view->priv->selection_mode);
1261 case PROP_PIXBUF_COLUMN:
1262 g_value_set_int (value, icon_view->priv->pixbuf_column);
1264 case PROP_TEXT_COLUMN:
1265 g_value_set_int (value, icon_view->priv->text_column);
1267 case PROP_MARKUP_COLUMN:
1268 g_value_set_int (value, icon_view->priv->markup_column);
1271 g_value_set_object (value, icon_view->priv->model);
1273 case PROP_ORIENTATION:
1274 g_value_set_enum (value, icon_view->priv->orientation);
1277 g_value_set_int (value, icon_view->priv->columns);
1279 case PROP_ITEM_WIDTH:
1280 g_value_set_int (value, icon_view->priv->item_width);
1283 g_value_set_int (value, icon_view->priv->spacing);
1285 case PROP_ROW_SPACING:
1286 g_value_set_int (value, icon_view->priv->row_spacing);
1288 case PROP_COLUMN_SPACING:
1289 g_value_set_int (value, icon_view->priv->column_spacing);
1292 g_value_set_int (value, icon_view->priv->margin);
1294 case PROP_REORDERABLE:
1295 g_value_set_boolean (value, icon_view->priv->reorderable);
1297 case PROP_TOOLTIP_COLUMN:
1298 g_value_set_int (value, icon_view->priv->tooltip_column);
1301 case PROP_ITEM_PADDING:
1302 g_value_set_int (value, icon_view->priv->item_padding);
1306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1311 /* GtkWidget signals */
1313 gtk_icon_view_realize (GtkWidget *widget)
1315 GtkIconView *icon_view;
1316 GdkWindowAttr attributes;
1317 gint attributes_mask;
1319 icon_view = GTK_ICON_VIEW (widget);
1321 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1323 /* Make the main, clipping window */
1324 attributes.window_type = GDK_WINDOW_CHILD;
1325 attributes.x = widget->allocation.x;
1326 attributes.y = widget->allocation.y;
1327 attributes.width = widget->allocation.width;
1328 attributes.height = widget->allocation.height;
1329 attributes.wclass = GDK_INPUT_OUTPUT;
1330 attributes.visual = gtk_widget_get_visual (widget);
1331 attributes.colormap = gtk_widget_get_colormap (widget);
1332 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1334 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1336 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1337 &attributes, attributes_mask);
1338 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1339 gdk_window_set_user_data (widget->window, widget);
1341 /* Make the window for the icon view */
1344 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1345 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1346 attributes.event_mask = (GDK_EXPOSURE_MASK |
1348 GDK_POINTER_MOTION_MASK |
1349 GDK_BUTTON_PRESS_MASK |
1350 GDK_BUTTON_RELEASE_MASK |
1351 GDK_KEY_PRESS_MASK |
1352 GDK_KEY_RELEASE_MASK) |
1353 gtk_widget_get_events (widget);
1355 icon_view->priv->bin_window = gdk_window_new (widget->window,
1356 &attributes, attributes_mask);
1357 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1359 widget->style = gtk_style_attach (widget->style, widget->window);
1360 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1362 gdk_window_show (icon_view->priv->bin_window);
1366 gtk_icon_view_unrealize (GtkWidget *widget)
1368 GtkIconView *icon_view;
1370 icon_view = GTK_ICON_VIEW (widget);
1372 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1373 gdk_window_destroy (icon_view->priv->bin_window);
1374 icon_view->priv->bin_window = NULL;
1376 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1380 gtk_icon_view_state_changed (GtkWidget *widget,
1381 GtkStateType previous_state)
1383 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1385 if (GTK_WIDGET_REALIZED (widget))
1387 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1388 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1391 gtk_widget_queue_draw (widget);
1395 gtk_icon_view_style_set (GtkWidget *widget,
1396 GtkStyle *previous_style)
1398 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1400 if (GTK_WIDGET_REALIZED (widget))
1402 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1403 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1406 gtk_widget_queue_resize (widget);
1410 gtk_icon_view_size_request (GtkWidget *widget,
1411 GtkRequisition *requisition)
1413 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1416 requisition->width = icon_view->priv->width;
1417 requisition->height = icon_view->priv->height;
1419 tmp_list = icon_view->priv->children;
1423 GtkIconViewChild *child = tmp_list->data;
1424 GtkRequisition child_requisition;
1426 tmp_list = tmp_list->next;
1428 if (GTK_WIDGET_VISIBLE (child->widget))
1429 gtk_widget_size_request (child->widget, &child_requisition);
1434 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1438 for (list = icon_view->priv->children; list; list = list->next)
1440 GtkIconViewChild *child = list->data;
1441 GtkAllocation allocation;
1443 /* totally ignore our child's requisition */
1444 if (child->cell < 0)
1446 allocation.x = child->item->x + icon_view->priv->item_padding;
1447 allocation.y = child->item->y + icon_view->priv->item_padding;
1448 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1449 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1453 GdkRectangle *box = &child->item->box[child->cell];
1455 allocation.x = box->x;
1456 allocation.y = box->y;
1457 allocation.width = box->width;
1458 allocation.height = box->height;
1461 gtk_widget_size_allocate (child->widget, &allocation);
1466 gtk_icon_view_size_allocate (GtkWidget *widget,
1467 GtkAllocation *allocation)
1469 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1471 GtkAdjustment *hadjustment, *vadjustment;
1473 widget->allocation = *allocation;
1475 if (GTK_WIDGET_REALIZED (widget))
1477 gdk_window_move_resize (widget->window,
1478 allocation->x, allocation->y,
1479 allocation->width, allocation->height);
1480 gdk_window_resize (icon_view->priv->bin_window,
1481 MAX (icon_view->priv->width, allocation->width),
1482 MAX (icon_view->priv->height, allocation->height));
1485 gtk_icon_view_layout (icon_view);
1487 gtk_icon_view_allocate_children (icon_view);
1489 hadjustment = icon_view->priv->hadjustment;
1490 vadjustment = icon_view->priv->vadjustment;
1492 hadjustment->page_size = allocation->width;
1493 hadjustment->page_increment = allocation->width * 0.9;
1494 hadjustment->step_increment = allocation->width * 0.1;
1495 hadjustment->lower = 0;
1496 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1498 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1499 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1501 vadjustment->page_size = allocation->height;
1502 vadjustment->page_increment = allocation->height * 0.9;
1503 vadjustment->step_increment = allocation->height * 0.1;
1504 vadjustment->lower = 0;
1505 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1507 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1508 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1510 if (GTK_WIDGET_REALIZED (widget) &&
1511 icon_view->priv->scroll_to_path)
1514 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1515 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1516 icon_view->priv->scroll_to_path = NULL;
1518 gtk_icon_view_scroll_to_path (icon_view, path,
1519 icon_view->priv->scroll_to_use_align,
1520 icon_view->priv->scroll_to_row_align,
1521 icon_view->priv->scroll_to_col_align);
1522 gtk_tree_path_free (path);
1526 gtk_adjustment_changed (hadjustment);
1527 gtk_adjustment_changed (vadjustment);
1532 gtk_icon_view_expose (GtkWidget *widget,
1533 GdkEventExpose *expose)
1535 GtkIconView *icon_view;
1540 GtkIconViewDropPosition dest_pos;
1541 GtkIconViewItem *dest_item = NULL;
1543 icon_view = GTK_ICON_VIEW (widget);
1545 if (expose->window != icon_view->priv->bin_window)
1548 /* If a layout has been scheduled, do it now so that all
1549 * cell view items have valid sizes before we proceed. */
1550 if (icon_view->priv->layout_idle_id != 0)
1551 gtk_icon_view_layout (icon_view);
1553 cr = gdk_cairo_create (icon_view->priv->bin_window);
1554 cairo_set_line_width (cr, 1.);
1556 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1560 dest_index = gtk_tree_path_get_indices (path)[0];
1561 gtk_tree_path_free (path);
1566 for (icons = icon_view->priv->items; icons; icons = icons->next)
1568 GtkIconViewItem *item = icons->data;
1573 area.width = item->width;
1574 area.height = item->height;
1576 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1579 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1580 icon_view->priv->bin_window,
1582 icon_view->priv->draw_focus);
1584 if (dest_index == item->index)
1592 case GTK_ICON_VIEW_DROP_INTO:
1593 gtk_paint_focus (widget->style,
1594 icon_view->priv->bin_window,
1595 GTK_WIDGET_STATE (widget),
1598 "iconview-drop-indicator",
1599 dest_item->x, dest_item->y,
1600 dest_item->width, dest_item->height);
1602 case GTK_ICON_VIEW_DROP_ABOVE:
1603 gtk_paint_focus (widget->style,
1604 icon_view->priv->bin_window,
1605 GTK_WIDGET_STATE (widget),
1608 "iconview-drop-indicator",
1609 dest_item->x, dest_item->y - 1,
1610 dest_item->width, 2);
1612 case GTK_ICON_VIEW_DROP_LEFT:
1613 gtk_paint_focus (widget->style,
1614 icon_view->priv->bin_window,
1615 GTK_WIDGET_STATE (widget),
1618 "iconview-drop-indicator",
1619 dest_item->x - 1, dest_item->y,
1620 2, dest_item->height);
1622 case GTK_ICON_VIEW_DROP_BELOW:
1623 gtk_paint_focus (widget->style,
1624 icon_view->priv->bin_window,
1625 GTK_WIDGET_STATE (widget),
1628 "iconview-drop-indicator",
1629 dest_item->x, dest_item->y + dest_item->height - 1,
1630 dest_item->width, 2);
1632 case GTK_ICON_VIEW_DROP_RIGHT:
1633 gtk_paint_focus (widget->style,
1634 icon_view->priv->bin_window,
1635 GTK_WIDGET_STATE (widget),
1638 "iconview-drop-indicator",
1639 dest_item->x + dest_item->width - 1, dest_item->y,
1640 2, dest_item->height);
1641 case GTK_ICON_VIEW_NO_DROP: ;
1646 if (icon_view->priv->doing_rubberband)
1648 GdkRectangle *rectangles;
1651 gdk_region_get_rectangles (expose->region,
1655 while (n_rectangles--)
1656 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1658 g_free (rectangles);
1663 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1669 rubberband_scroll_timeout (gpointer data)
1671 GtkIconView *icon_view;
1676 value = MIN (icon_view->priv->vadjustment->value +
1677 icon_view->priv->scroll_value_diff,
1678 icon_view->priv->vadjustment->upper -
1679 icon_view->priv->vadjustment->page_size);
1681 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1683 gtk_icon_view_update_rubberband (icon_view);
1689 gtk_icon_view_motion (GtkWidget *widget,
1690 GdkEventMotion *event)
1692 GtkIconView *icon_view;
1695 icon_view = GTK_ICON_VIEW (widget);
1697 gtk_icon_view_maybe_begin_drag (icon_view, event);
1699 if (icon_view->priv->doing_rubberband)
1701 gtk_icon_view_update_rubberband (widget);
1703 abs_y = event->y - icon_view->priv->height *
1704 (icon_view->priv->vadjustment->value /
1705 (icon_view->priv->vadjustment->upper -
1706 icon_view->priv->vadjustment->lower));
1708 if (abs_y < 0 || abs_y > widget->allocation.height)
1711 icon_view->priv->scroll_value_diff = abs_y;
1713 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1715 icon_view->priv->event_last_x = event->x;
1716 icon_view->priv->event_last_y = event->y;
1718 if (icon_view->priv->scroll_timeout_id == 0)
1719 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1723 remove_scroll_timeout (icon_view);
1730 gtk_icon_view_remove (GtkContainer *container,
1733 GtkIconView *icon_view;
1734 GtkIconViewChild *child = NULL;
1737 icon_view = GTK_ICON_VIEW (container);
1739 tmp_list = icon_view->priv->children;
1742 child = tmp_list->data;
1743 if (child->widget == widget)
1745 gtk_widget_unparent (widget);
1747 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1748 g_list_free_1 (tmp_list);
1753 tmp_list = tmp_list->next;
1758 gtk_icon_view_forall (GtkContainer *container,
1759 gboolean include_internals,
1760 GtkCallback callback,
1761 gpointer callback_data)
1763 GtkIconView *icon_view;
1764 GtkIconViewChild *child = NULL;
1767 icon_view = GTK_ICON_VIEW (container);
1769 tmp_list = icon_view->priv->children;
1772 child = tmp_list->data;
1773 tmp_list = tmp_list->next;
1775 (* callback) (child->widget, callback_data);
1780 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1781 GtkIconViewItem *item,
1782 GtkIconViewCellInfo *info,
1787 GdkRectangle cell_area;
1788 gboolean visible, mode;
1790 gtk_icon_view_set_cell_data (icon_view, item);
1792 g_object_get (info->cell,
1793 "visible", &visible,
1797 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1799 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1801 path = gtk_tree_path_new_from_indices (item->index, -1);
1802 path_string = gtk_tree_path_to_string (path);
1803 gtk_tree_path_free (path);
1805 gtk_cell_renderer_activate (info->cell,
1807 GTK_WIDGET (icon_view),
1813 g_free (path_string);
1818 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1819 GtkIconViewItem *item)
1822 AtkObject *item_obj;
1824 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1827 item_obj = atk_object_ref_accessible_child (obj, item->index);
1828 if (item_obj != NULL)
1830 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1831 g_object_unref (item_obj);
1837 gtk_icon_view_put (GtkIconView *icon_view,
1839 GtkIconViewItem *item,
1842 GtkIconViewChild *child;
1844 child = g_new (GtkIconViewChild, 1);
1846 child->widget = widget;
1850 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1852 if (GTK_WIDGET_REALIZED (icon_view))
1853 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1855 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1859 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1860 GtkIconView *icon_view)
1863 GtkIconViewItem *item;
1865 if (icon_view->priv->edited_item == NULL)
1868 item = icon_view->priv->edited_item;
1869 icon_view->priv->edited_item = NULL;
1870 icon_view->priv->editable = NULL;
1871 for (l = icon_view->priv->cell_list; l; l = l->next)
1873 GtkIconViewCellInfo *info = l->data;
1875 info->editing = FALSE;
1878 if (GTK_WIDGET_HAS_FOCUS (editable))
1879 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1881 g_signal_handlers_disconnect_by_func (editable,
1882 gtk_icon_view_remove_widget,
1885 gtk_container_remove (GTK_CONTAINER (icon_view),
1886 GTK_WIDGET (editable));
1888 gtk_icon_view_queue_draw_item (icon_view, item);
1893 gtk_icon_view_start_editing (GtkIconView *icon_view,
1894 GtkIconViewItem *item,
1895 GtkIconViewCellInfo *info,
1900 GdkRectangle cell_area;
1901 gboolean visible, mode;
1902 GtkCellEditable *editable;
1904 gtk_icon_view_set_cell_data (icon_view, item);
1906 g_object_get (info->cell,
1907 "visible", &visible,
1910 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1912 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1914 path = gtk_tree_path_new_from_indices (item->index, -1);
1915 path_string = gtk_tree_path_to_string (path);
1916 gtk_tree_path_free (path);
1918 editable = gtk_cell_renderer_start_editing (info->cell,
1920 GTK_WIDGET (icon_view),
1925 g_free (path_string);
1927 /* the rest corresponds to tree_view_real_start_editing... */
1928 icon_view->priv->edited_item = item;
1929 icon_view->priv->editable = editable;
1930 info->editing = TRUE;
1932 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1934 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1936 gtk_widget_grab_focus (GTK_WIDGET (editable));
1937 g_signal_connect (editable, "remove-widget",
1938 G_CALLBACK (gtk_icon_view_remove_widget),
1945 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1946 gboolean cancel_editing)
1948 GtkCellRenderer *cell = NULL;
1949 GtkIconViewItem *item;
1952 if (icon_view->priv->edited_item == NULL)
1956 * This is very evil. We need to do this, because
1957 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1958 * later on. If gtk_icon_view_row_changed notices
1959 * icon_view->priv->edited_item != NULL, it'll call
1960 * gtk_icon_view_stop_editing again. Bad things will happen then.
1962 * Please read that again if you intend to modify anything here.
1965 item = icon_view->priv->edited_item;
1966 icon_view->priv->edited_item = NULL;
1968 for (l = icon_view->priv->cell_list; l; l = l->next)
1970 GtkIconViewCellInfo *info = l->data;
1982 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1983 if (!cancel_editing)
1984 gtk_cell_editable_editing_done (icon_view->priv->editable);
1986 icon_view->priv->edited_item = item;
1988 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1992 * gtk_icon_view_set_cursor:
1993 * @icon_view: A #GtkIconView
1994 * @path: A #GtkTreePath
1995 * @cell: One of the cell renderers of @icon_view, or %NULL
1996 * @start_editing: %TRUE if the specified cell should start being edited.
1998 * Sets the current keyboard focus to be at @path, and selects it. This is
1999 * useful when you want to focus the user's attention on a particular item.
2000 * If @cell is not %NULL, then focus is given to the cell specified by
2001 * it. Additionally, if @start_editing is %TRUE, then editing should be
2002 * started in the specified cell.
2004 * This function is often followed by <literal>gtk_widget_grab_focus
2005 * (icon_view)</literal> in order to give keyboard focus to the widget.
2006 * Please note that editing can only happen when the widget is realized.
2011 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2013 GtkCellRenderer *cell,
2014 gboolean start_editing)
2016 GtkIconViewItem *item = NULL;
2017 GtkIconViewCellInfo *info = NULL;
2021 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2022 g_return_if_fail (path != NULL);
2023 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2025 gtk_icon_view_stop_editing (icon_view, TRUE);
2027 if (gtk_tree_path_get_depth (path) == 1)
2028 item = g_list_nth_data (icon_view->priv->items,
2029 gtk_tree_path_get_indices(path)[0]);
2035 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2039 if (info->cell == cell)
2048 g_return_if_fail (cell == NULL || info != NULL);
2050 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2051 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2053 if (info && start_editing)
2054 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2058 * gtk_icon_view_get_cursor:
2059 * @icon_view: A #GtkIconView
2060 * @path: Return location for the current cursor path, or %NULL
2061 * @cell: Return location the current focus cell, or %NULL
2063 * Fills in @path and @cell with the current cursor path and cell.
2064 * If the cursor isn't currently set, then *@path will be %NULL.
2065 * If no cell currently has focus, then *@cell will be %NULL.
2067 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2069 * Return value: %TRUE if the cursor is set.
2074 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2076 GtkCellRenderer **cell)
2078 GtkIconViewItem *item;
2079 GtkIconViewCellInfo *info;
2081 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2083 item = icon_view->priv->cursor_item;
2084 if (icon_view->priv->cursor_cell < 0)
2087 info = g_list_nth_data (icon_view->priv->cell_list,
2088 icon_view->priv->cursor_cell);
2093 *path = gtk_tree_path_new_from_indices (item->index, -1);
2106 return (item != NULL);
2110 gtk_icon_view_button_press (GtkWidget *widget,
2111 GdkEventButton *event)
2113 GtkIconView *icon_view;
2114 GtkIconViewItem *item;
2115 GtkIconViewCellInfo *info = NULL;
2116 gboolean dirty = FALSE;
2117 GtkCellRendererMode mode;
2118 gint cursor_cell = -1;
2120 icon_view = GTK_ICON_VIEW (widget);
2122 if (event->window != icon_view->priv->bin_window)
2125 if (!GTK_WIDGET_HAS_FOCUS (widget))
2126 gtk_widget_grab_focus (widget);
2128 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2130 item = gtk_icon_view_get_item_at_coords (icon_view,
2136 * We consider only the the cells' area as the item area if the
2137 * item is not selected, but if it *is* selected, the complete
2138 * selection rectangle is considered to be part of the item.
2140 if (item != NULL && (info != NULL || item->selected))
2144 g_object_get (info->cell, "mode", &mode, NULL);
2146 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2147 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2148 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2151 gtk_icon_view_scroll_to_item (icon_view, item);
2153 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2155 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2157 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2158 (event->state & GDK_SHIFT_MASK))
2160 gtk_icon_view_unselect_all_internal (icon_view);
2162 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2163 if (!icon_view->priv->anchor_item)
2164 icon_view->priv->anchor_item = item;
2166 gtk_icon_view_select_all_between (icon_view,
2167 icon_view->priv->anchor_item,
2173 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2174 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2175 (event->state & GDK_CONTROL_MASK))
2177 item->selected = !item->selected;
2178 gtk_icon_view_queue_draw_item (icon_view, item);
2183 gtk_icon_view_unselect_all_internal (icon_view);
2185 item->selected = TRUE;
2186 gtk_icon_view_queue_draw_item (icon_view, item);
2189 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2190 icon_view->priv->anchor_item = item;
2193 /* Save press to possibly begin a drag */
2194 if (icon_view->priv->pressed_button < 0)
2196 icon_view->priv->pressed_button = event->button;
2197 icon_view->priv->press_start_x = event->x;
2198 icon_view->priv->press_start_y = event->y;
2201 if (!icon_view->priv->last_single_clicked)
2202 icon_view->priv->last_single_clicked = item;
2204 /* cancel the current editing, if it exists */
2205 gtk_icon_view_stop_editing (icon_view, TRUE);
2209 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2210 gtk_icon_view_item_activate_cell (icon_view, item, info,
2212 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2213 gtk_icon_view_start_editing (icon_view, item, info,
2219 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2220 !(event->state & GDK_CONTROL_MASK))
2222 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2225 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2226 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2229 /* don't draw keyboard focus around an clicked-on item */
2230 icon_view->priv->draw_focus = FALSE;
2233 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2235 item = gtk_icon_view_get_item_at_coords (icon_view,
2240 if (item && item == icon_view->priv->last_single_clicked)
2244 path = gtk_tree_path_new_from_indices (item->index, -1);
2245 gtk_icon_view_item_activated (icon_view, path);
2246 gtk_tree_path_free (path);
2249 icon_view->priv->last_single_clicked = NULL;
2250 icon_view->priv->pressed_button = -1;
2254 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2256 return event->button == 1;
2260 gtk_icon_view_button_release (GtkWidget *widget,
2261 GdkEventButton *event)
2263 GtkIconView *icon_view;
2265 icon_view = GTK_ICON_VIEW (widget);
2267 if (icon_view->priv->pressed_button == event->button)
2268 icon_view->priv->pressed_button = -1;
2270 gtk_icon_view_stop_rubberbanding (icon_view);
2272 remove_scroll_timeout (icon_view);
2278 gtk_icon_view_key_press (GtkWidget *widget,
2281 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2283 if (icon_view->priv->doing_rubberband)
2285 if (event->keyval == GDK_Escape)
2286 gtk_icon_view_stop_rubberbanding (icon_view);
2291 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2295 gtk_icon_view_key_release (GtkWidget *widget,
2298 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2300 if (icon_view->priv->doing_rubberband)
2303 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2307 gtk_icon_view_update_rubberband (gpointer data)
2309 GtkIconView *icon_view;
2311 GdkRectangle old_area;
2312 GdkRectangle new_area;
2313 GdkRectangle common;
2314 GdkRegion *invalid_region;
2316 icon_view = GTK_ICON_VIEW (data);
2318 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2323 old_area.x = MIN (icon_view->priv->rubberband_x1,
2324 icon_view->priv->rubberband_x2);
2325 old_area.y = MIN (icon_view->priv->rubberband_y1,
2326 icon_view->priv->rubberband_y2);
2327 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2328 icon_view->priv->rubberband_x1) + 1;
2329 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2330 icon_view->priv->rubberband_y1) + 1;
2332 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2333 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2334 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2335 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2337 invalid_region = gdk_region_rectangle (&old_area);
2338 gdk_region_union_with_rect (invalid_region, &new_area);
2340 gdk_rectangle_intersect (&old_area, &new_area, &common);
2341 if (common.width > 2 && common.height > 2)
2343 GdkRegion *common_region;
2345 /* make sure the border is invalidated */
2351 common_region = gdk_region_rectangle (&common);
2353 gdk_region_subtract (invalid_region, common_region);
2354 gdk_region_destroy (common_region);
2357 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2359 gdk_region_destroy (invalid_region);
2361 icon_view->priv->rubberband_x2 = x;
2362 icon_view->priv->rubberband_y2 = y;
2364 gtk_icon_view_update_rubberband_selection (icon_view);
2368 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2374 g_assert (!icon_view->priv->doing_rubberband);
2376 for (items = icon_view->priv->items; items; items = items->next)
2378 GtkIconViewItem *item = items->data;
2380 item->selected_before_rubberbanding = item->selected;
2383 icon_view->priv->rubberband_x1 = x;
2384 icon_view->priv->rubberband_y1 = y;
2385 icon_view->priv->rubberband_x2 = x;
2386 icon_view->priv->rubberband_y2 = y;
2388 icon_view->priv->doing_rubberband = TRUE;
2390 gtk_grab_add (GTK_WIDGET (icon_view));
2394 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2396 if (!icon_view->priv->doing_rubberband)
2399 icon_view->priv->doing_rubberband = FALSE;
2401 gtk_grab_remove (GTK_WIDGET (icon_view));
2403 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2407 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2410 gint x, y, width, height;
2411 gboolean dirty = FALSE;
2413 x = MIN (icon_view->priv->rubberband_x1,
2414 icon_view->priv->rubberband_x2);
2415 y = MIN (icon_view->priv->rubberband_y1,
2416 icon_view->priv->rubberband_y2);
2417 width = ABS (icon_view->priv->rubberband_x1 -
2418 icon_view->priv->rubberband_x2);
2419 height = ABS (icon_view->priv->rubberband_y1 -
2420 icon_view->priv->rubberband_y2);
2422 for (items = icon_view->priv->items; items; items = items->next)
2424 GtkIconViewItem *item = items->data;
2428 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2429 x, y, width, height);
2431 selected = is_in ^ item->selected_before_rubberbanding;
2433 if (item->selected != selected)
2435 item->selected = selected;
2437 gtk_icon_view_queue_draw_item (icon_view, item);
2442 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2446 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2447 GtkIconViewItem *item,
2456 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2457 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2460 for (l = icon_view->priv->cell_list; l; l = l->next)
2462 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2464 if (!info->cell->visible)
2467 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2469 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2470 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2478 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2480 gboolean dirty = FALSE;
2483 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2486 for (items = icon_view->priv->items; items; items = items->next)
2488 GtkIconViewItem *item = items->data;
2492 item->selected = FALSE;
2494 gtk_icon_view_queue_draw_item (icon_view, item);
2495 gtk_icon_view_item_selected_changed (icon_view, item);
2503 /* GtkIconView signals */
2505 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2506 GtkAdjustment *hadj,
2507 GtkAdjustment *vadj)
2509 gboolean need_adjust = FALSE;
2512 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2514 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2516 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2518 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2520 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2522 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2523 0, 0, NULL, NULL, icon_view);
2524 g_object_unref (icon_view->priv->hadjustment);
2527 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2529 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2530 0, 0, NULL, NULL, icon_view);
2531 g_object_unref (icon_view->priv->vadjustment);
2534 if (icon_view->priv->hadjustment != hadj)
2536 icon_view->priv->hadjustment = hadj;
2537 g_object_ref_sink (icon_view->priv->hadjustment);
2539 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2540 G_CALLBACK (gtk_icon_view_adjustment_changed),
2545 if (icon_view->priv->vadjustment != vadj)
2547 icon_view->priv->vadjustment = vadj;
2548 g_object_ref_sink (icon_view->priv->vadjustment);
2550 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2551 G_CALLBACK (gtk_icon_view_adjustment_changed),
2557 gtk_icon_view_adjustment_changed (NULL, icon_view);
2561 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2563 gtk_icon_view_select_all (icon_view);
2567 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2569 gtk_icon_view_unselect_all (icon_view);
2573 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2575 gtk_icon_view_unselect_all (icon_view);
2577 if (icon_view->priv->cursor_item != NULL)
2578 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2582 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2585 GtkCellRendererMode mode;
2586 GtkIconViewCellInfo *info = NULL;
2588 if (!icon_view->priv->cursor_item)
2591 info = g_list_nth_data (icon_view->priv->cell_list,
2592 icon_view->priv->cursor_cell);
2596 g_object_get (info->cell, "mode", &mode, NULL);
2598 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2600 gtk_icon_view_item_activate_cell (icon_view,
2601 icon_view->priv->cursor_item,
2605 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2607 gtk_icon_view_start_editing (icon_view,
2608 icon_view->priv->cursor_item,
2614 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2615 gtk_icon_view_item_activated (icon_view, path);
2616 gtk_tree_path_free (path);
2622 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2624 if (!icon_view->priv->cursor_item)
2627 switch (icon_view->priv->selection_mode)
2629 case GTK_SELECTION_NONE:
2631 case GTK_SELECTION_BROWSE:
2632 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2634 case GTK_SELECTION_SINGLE:
2635 if (icon_view->priv->cursor_item->selected)
2636 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2638 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2640 case GTK_SELECTION_MULTIPLE:
2641 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2642 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2644 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2645 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2650 /* Internal functions */
2652 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2653 GtkIconView *icon_view)
2655 if (GTK_WIDGET_REALIZED (icon_view))
2657 gdk_window_move (icon_view->priv->bin_window,
2658 - icon_view->priv->hadjustment->value,
2659 - icon_view->priv->vadjustment->value);
2661 if (icon_view->priv->doing_rubberband)
2662 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2664 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2669 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2674 gint *maximum_width)
2677 gint x, current_width;
2678 GList *items, *last_item;
2685 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2686 max_height = g_new0 (gint, icon_view->priv->n_cells);
2693 gtk_widget_style_get (GTK_WIDGET (icon_view),
2694 "focus-line-width", &focus_width,
2697 x += icon_view->priv->margin + focus_width;
2698 current_width += 2 * (icon_view->priv->margin + focus_width);
2703 GtkIconViewItem *item = items->data;
2705 gtk_icon_view_calculate_item_size (icon_view, item);
2706 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2708 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2710 current_width += item->width;
2712 if (items != first_item)
2714 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2715 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2719 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2721 item->y = *y + focus_width;
2724 x = current_width - (icon_view->priv->margin + focus_width);
2726 for (i = 0; i < icon_view->priv->n_cells; i++)
2727 max_height[i] = MAX (max_height[i], item->box[i].height);
2729 if (current_width > *maximum_width)
2730 *maximum_width = current_width;
2736 items = items->next;
2741 /* Now go through the row again and align the icons */
2742 for (items = first_item; items != last_item; items = items->next)
2744 GtkIconViewItem *item = items->data;
2748 item->x = *maximum_width - item->width - item->x;
2749 item->col = col - 1 - item->col;
2752 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2754 /* We may want to readjust the new y coordinate. */
2755 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2756 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2759 g_free (max_height);
2765 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2768 if (upper != adj->upper)
2770 gdouble min = MAX (0.0, upper - adj->page_size);
2771 gboolean value_changed = FALSE;
2775 if (adj->value > min)
2778 value_changed = TRUE;
2781 gtk_adjustment_changed (adj);
2784 gtk_adjustment_value_changed (adj);
2789 gtk_icon_view_layout (GtkIconView *icon_view)
2791 gint y = 0, maximum_width = 0;
2797 if (icon_view->priv->layout_idle_id != 0)
2799 g_source_remove (icon_view->priv->layout_idle_id);
2800 icon_view->priv->layout_idle_id = 0;
2803 if (icon_view->priv->model == NULL)
2806 widget = GTK_WIDGET (icon_view);
2808 item_width = icon_view->priv->item_width;
2812 for (icons = icon_view->priv->items; icons; icons = icons->next)
2814 GtkIconViewItem *item = icons->data;
2815 gtk_icon_view_calculate_item_size (icon_view, item);
2816 item_width = MAX (item_width, item->width);
2821 icons = icon_view->priv->items;
2822 y += icon_view->priv->margin;
2827 gtk_icon_view_set_cell_data (icon_view, icons->data);
2828 adjust_wrap_width (icon_view, icons->data);
2833 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2835 &y, &maximum_width);
2838 while (icons != NULL);
2840 if (maximum_width != icon_view->priv->width)
2841 icon_view->priv->width = maximum_width;
2843 y += icon_view->priv->margin;
2845 if (y != icon_view->priv->height)
2846 icon_view->priv->height = y;
2848 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2849 icon_view->priv->width);
2850 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2851 icon_view->priv->height);
2853 if (icon_view->priv->width != widget->requisition.width ||
2854 icon_view->priv->height != widget->requisition.height)
2855 gtk_widget_queue_resize_no_redraw (widget);
2857 if (GTK_WIDGET_REALIZED (icon_view))
2858 gdk_window_resize (icon_view->priv->bin_window,
2859 MAX (icon_view->priv->width, widget->allocation.width),
2860 MAX (icon_view->priv->height, widget->allocation.height));
2862 if (icon_view->priv->scroll_to_path)
2866 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2867 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2868 icon_view->priv->scroll_to_path = NULL;
2870 gtk_icon_view_scroll_to_path (icon_view, path,
2871 icon_view->priv->scroll_to_use_align,
2872 icon_view->priv->scroll_to_row_align,
2873 icon_view->priv->scroll_to_col_align);
2874 gtk_tree_path_free (path);
2877 gtk_widget_queue_draw (widget);
2881 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2882 GtkIconViewItem *item,
2883 GtkIconViewCellInfo *info,
2884 GdkRectangle *cell_area)
2886 g_return_if_fail (info->position < item->n_cells);
2888 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2890 cell_area->x = item->box[info->position].x - item->before[info->position];
2891 cell_area->y = item->y + icon_view->priv->item_padding;
2892 cell_area->width = item->box[info->position].width +
2893 item->before[info->position] + item->after[info->position];
2894 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2898 cell_area->x = item->x + icon_view->priv->item_padding;
2899 cell_area->y = item->box[info->position].y - item->before[info->position];
2900 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2901 cell_area->height = item->box[info->position].height +
2902 item->before[info->position] + item->after[info->position];
2907 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2908 GtkIconViewItem *item,
2909 GtkIconViewCellInfo *info,
2912 g_return_if_fail (info->position < item->n_cells);
2914 *box = item->box[info->position];
2917 /* try to guess a reasonable wrap width for an implicit text cell renderer
2920 adjust_wrap_width (GtkIconView *icon_view,
2921 GtkIconViewItem *item)
2923 GtkIconViewCellInfo *text_info;
2924 GtkIconViewCellInfo *pixbuf_info;
2925 gint pixbuf_width, wrap_width;
2927 if (icon_view->priv->text_cell != -1 &&
2928 icon_view->priv->pixbuf_cell != -1)
2932 text_info = g_list_nth_data (icon_view->priv->cell_list,
2933 icon_view->priv->text_cell);
2934 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2935 icon_view->priv->pixbuf_cell);
2937 gtk_cell_renderer_get_size (pixbuf_info->cell,
2938 GTK_WIDGET (icon_view),
2944 if (icon_view->priv->item_width > 0)
2945 item_width = icon_view->priv->item_width;
2947 item_width = item->width;
2949 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2950 wrap_width = item_width;
2952 if (item->width == -1 && item_width <= 0)
2953 wrap_width = MAX (2 * pixbuf_width, 50);
2955 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2958 wrap_width -= icon_view->priv->item_padding * 2;
2960 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2961 g_object_set (text_info->cell, "width", wrap_width, NULL);
2966 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2967 GtkIconViewItem *item)
2972 if (item->width != -1 && item->height != -1)
2975 if (item->n_cells != icon_view->priv->n_cells)
2977 g_free (item->before);
2978 g_free (item->after);
2981 item->before = g_new0 (gint, icon_view->priv->n_cells);
2982 item->after = g_new0 (gint, icon_view->priv->n_cells);
2983 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2985 item->n_cells = icon_view->priv->n_cells;
2988 gtk_icon_view_set_cell_data (icon_view, item);
2990 spacing = icon_view->priv->spacing;
2994 for (l = icon_view->priv->cell_list; l; l = l->next)
2996 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2998 if (!info->cell->visible)
3001 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3003 &item->box[info->position].width,
3004 &item->box[info->position].height);
3006 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3008 item->width += item->box[info->position].width
3009 + (info->position > 0 ? spacing : 0);
3010 item->height = MAX (item->height, item->box[info->position].height);
3014 item->width = MAX (item->width, item->box[info->position].width);
3015 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3019 item->width += icon_view->priv->item_padding * 2;
3020 item->height += icon_view->priv->item_padding * 2;
3024 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3025 GtkIconViewItem *item,
3028 GdkRectangle cell_area;
3034 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3036 gtk_icon_view_set_cell_data (icon_view, item);
3038 spacing = icon_view->priv->spacing;
3041 for (i = 0; i < icon_view->priv->n_cells; i++)
3043 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3044 item->height = MAX (item->height, max_height[i]);
3046 item->height += max_height[i] + (i > 0 ? spacing : 0);
3049 cell_area.x = item->x + icon_view->priv->item_padding;
3050 cell_area.y = item->y + icon_view->priv->item_padding;
3052 for (k = 0; k < 2; k++)
3053 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3055 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3057 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3060 if (!info->cell->visible)
3063 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3065 /* We should not subtract icon_view->priv->item_padding from item->height,
3066 * because item->height is recalculated above using
3067 * max_height which does not contain item padding.
3069 cell_area.width = item->box[info->position].width;
3070 cell_area.height = item->height;
3074 /* item->width is not recalculated and thus needs to be
3075 * corrected for the padding.
3077 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3078 cell_area.height = max_height[i];
3081 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3083 &item->box[info->position].x, &item->box[info->position].y,
3084 &item->box[info->position].width, &item->box[info->position].height);
3086 item->box[info->position].x += cell_area.x;
3087 item->box[info->position].y += cell_area.y;
3088 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3090 item->before[info->position] = item->box[info->position].x - cell_area.x;
3091 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3092 cell_area.x += cell_area.width + spacing;
3096 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3098 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3099 cell_area.width = item->width;
3101 item->before[info->position] = item->box[info->position].y - cell_area.y;
3102 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3103 cell_area.y += cell_area.height + spacing;
3107 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3109 for (i = 0; i < icon_view->priv->n_cells; i++)
3111 item->box[i].x = item->x + item->width -
3112 (item->box[i].x + item->box[i].width - item->x);
3116 item->height += icon_view->priv->item_padding * 2;
3120 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3122 g_list_foreach (icon_view->priv->items,
3123 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3127 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3134 gtk_icon_view_paint_item (GtkIconView *icon_view,
3136 GtkIconViewItem *item,
3138 GdkDrawable *drawable,
3141 gboolean draw_focus)
3145 GdkRectangle cell_area, box;
3149 GtkCellRendererState flags;
3151 if (icon_view->priv->model == NULL)
3154 gtk_icon_view_set_cell_data (icon_view, item);
3156 gtk_widget_style_get (GTK_WIDGET (icon_view),
3157 "focus-line-width", &focus_width,
3160 padding = focus_width;
3164 flags = GTK_CELL_RENDERER_SELECTED;
3165 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3166 state = GTK_STATE_SELECTED;
3168 state = GTK_STATE_ACTIVE;
3173 state = GTK_STATE_NORMAL;
3176 #ifdef DEBUG_ICON_VIEW
3177 gdk_draw_rectangle (drawable,
3178 GTK_WIDGET (icon_view)->style->black_gc,
3181 item->width, item->height);
3186 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3187 (GdkWindow *) drawable,
3191 GTK_WIDGET (icon_view),
3194 item->width, item->height);
3197 for (l = icon_view->priv->cell_list; l; l = l->next)
3199 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3201 if (!info->cell->visible)
3204 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3206 #ifdef DEBUG_ICON_VIEW
3207 gdk_draw_rectangle (drawable,
3208 GTK_WIDGET (icon_view)->style->black_gc,
3210 x - item->x + cell_area.x,
3211 y - item->y + cell_area.y,
3212 cell_area.width, cell_area.height);
3214 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3216 gdk_draw_rectangle (drawable,
3217 GTK_WIDGET (icon_view)->style->black_gc,
3219 x - item->x + box.x,
3220 y - item->y + box.y,
3221 box.width, box.height);
3224 cell_area.x = x - item->x + cell_area.x;
3225 cell_area.y = y - item->y + cell_area.y;
3227 gtk_cell_renderer_render (info->cell,
3229 GTK_WIDGET (icon_view),
3230 &cell_area, &cell_area, area, flags);
3234 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3235 item == icon_view->priv->cursor_item)
3237 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3239 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3241 if (!info->cell->visible)
3244 /* If found a editable/activatable cell, draw focus on it. */
3245 if (icon_view->priv->cursor_cell < 0 &&
3246 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3247 icon_view->priv->cursor_cell = i;
3249 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3251 if (i == icon_view->priv->cursor_cell)
3253 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3257 GTK_WIDGET (icon_view),
3259 x - item->x + box.x - padding,
3260 y - item->y + box.y - padding,
3261 box.width + 2 * padding,
3262 box.height + 2 * padding);
3267 /* If there are no editable/activatable cells, draw focus
3268 * around the whole item.
3270 if (icon_view->priv->cursor_cell < 0)
3271 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3275 GTK_WIDGET (icon_view),
3279 item->width + 2 * padding,
3280 item->height + 2 * padding);
3285 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3290 GdkRectangle rubber_rect;
3291 GdkColor *fill_color_gdk;
3292 guchar fill_color_alpha;
3294 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3295 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3296 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3297 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3299 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3302 gtk_widget_style_get (GTK_WIDGET (icon_view),
3303 "selection-box-color", &fill_color_gdk,
3304 "selection-box-alpha", &fill_color_alpha,
3307 if (!fill_color_gdk)
3308 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3310 cairo_set_source_rgba (cr,
3311 fill_color_gdk->red / 65535.,
3312 fill_color_gdk->green / 65535.,
3313 fill_color_gdk->blue / 65535.,
3314 fill_color_alpha / 255.);
3317 gdk_cairo_rectangle (cr, &rect);
3321 /* Draw the border without alpha */
3322 cairo_set_source_rgb (cr,
3323 fill_color_gdk->red / 65535.,
3324 fill_color_gdk->green / 65535.,
3325 fill_color_gdk->blue / 65535.);
3326 cairo_rectangle (cr,
3327 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3328 rubber_rect.width - 1, rubber_rect.height - 1);
3332 gdk_color_free (fill_color_gdk);
3336 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3342 index = gtk_tree_path_get_indices (path)[0];
3344 for (l = icon_view->priv->items; l; l = l->next)
3346 GtkIconViewItem *item = l->data;
3348 if (item->index == index)
3350 gtk_icon_view_queue_draw_item (icon_view, item);
3357 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3358 GtkIconViewItem *item)
3363 gtk_widget_style_get (GTK_WIDGET (icon_view),
3364 "focus-line-width", &focus_width,
3367 rect.x = item->x - focus_width;
3368 rect.y = item->y - focus_width;
3369 rect.width = item->width + 2 * focus_width;
3370 rect.height = item->height + 2 * focus_width;
3372 if (icon_view->priv->bin_window)
3373 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3377 layout_callback (gpointer user_data)
3379 GtkIconView *icon_view;
3381 icon_view = GTK_ICON_VIEW (user_data);
3383 icon_view->priv->layout_idle_id = 0;
3385 gtk_icon_view_layout (icon_view);
3391 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3393 if (icon_view->priv->layout_idle_id != 0)
3396 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3400 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3401 GtkIconViewItem *item,
3405 AtkObject *item_obj;
3406 AtkObject *cursor_item_obj;
3408 if (icon_view->priv->cursor_item == item &&
3409 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3412 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3413 if (icon_view->priv->cursor_item != NULL)
3415 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3418 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3419 if (cursor_item_obj != NULL)
3420 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3423 icon_view->priv->cursor_item = item;
3424 if (cursor_cell >= 0)
3425 icon_view->priv->cursor_cell = cursor_cell;
3427 gtk_icon_view_queue_draw_item (icon_view, item);
3429 /* Notify that accessible focus object has changed */
3430 item_obj = atk_object_ref_accessible_child (obj, item->index);
3432 if (item_obj != NULL)
3434 atk_focus_tracker_notify (item_obj);
3435 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3436 g_object_unref (item_obj);
3441 static GtkIconViewItem *
3442 gtk_icon_view_item_new (void)
3444 GtkIconViewItem *item;
3446 item = g_new0 (GtkIconViewItem, 1);
3455 gtk_icon_view_item_free (GtkIconViewItem *item)
3457 g_return_if_fail (item != NULL);
3459 g_free (item->before);
3460 g_free (item->after);
3467 static GtkIconViewItem *
3468 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3471 gboolean only_in_cell,
3472 GtkIconViewCellInfo **cell_at_pos)
3478 *cell_at_pos = NULL;
3480 for (items = icon_view->priv->items; items; items = items->next)
3482 GtkIconViewItem *item = items->data;
3484 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3485 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3487 if (only_in_cell || cell_at_pos)
3489 gtk_icon_view_set_cell_data (icon_view, item);
3491 for (l = icon_view->priv->cell_list; l; l = l->next)
3493 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3495 if (!info->cell->visible)
3498 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3500 if ((x >= box.x && x <= box.x + box.width &&
3501 y >= box.y && y <= box.y + box.height) ||
3503 x <= box.x + box.width &&
3505 y <= box.y + box.height))
3508 *cell_at_pos = info;
3526 gtk_icon_view_select_item (GtkIconView *icon_view,
3527 GtkIconViewItem *item)
3529 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3530 g_return_if_fail (item != NULL);
3535 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3537 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3538 gtk_icon_view_unselect_all_internal (icon_view);
3540 item->selected = TRUE;
3542 gtk_icon_view_item_selected_changed (icon_view, item);
3543 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3545 gtk_icon_view_queue_draw_item (icon_view, item);
3550 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3551 GtkIconViewItem *item)
3553 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3554 g_return_if_fail (item != NULL);
3556 if (!item->selected)
3559 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3560 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3563 item->selected = FALSE;
3565 gtk_icon_view_item_selected_changed (icon_view, item);
3566 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3568 gtk_icon_view_queue_draw_item (icon_view, item);
3572 verify_items (GtkIconView *icon_view)
3577 for (items = icon_view->priv->items; items; items = items->next)
3579 GtkIconViewItem *item = items->data;
3581 if (item->index != i)
3582 g_error ("List item does not match its index: "
3583 "item index %d and list index %d\n", item->index, i);
3590 gtk_icon_view_row_changed (GtkTreeModel *model,
3595 GtkIconViewItem *item;
3597 GtkIconView *icon_view;
3599 icon_view = GTK_ICON_VIEW (data);
3601 gtk_icon_view_stop_editing (icon_view, TRUE);
3603 index = gtk_tree_path_get_indices(path)[0];
3604 item = g_list_nth_data (icon_view->priv->items, index);
3606 gtk_icon_view_item_invalidate_size (item);
3607 gtk_icon_view_queue_layout (icon_view);
3609 verify_items (icon_view);
3613 gtk_icon_view_row_inserted (GtkTreeModel *model,
3619 GtkIconViewItem *item;
3620 gboolean iters_persist;
3621 GtkIconView *icon_view;
3624 icon_view = GTK_ICON_VIEW (data);
3626 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3628 index = gtk_tree_path_get_indices(path)[0];
3630 item = gtk_icon_view_item_new ();
3635 item->index = index;
3637 /* FIXME: We can be more efficient here,
3638 we can store a tail pointer and use that when
3639 appending (which is a rather common operation)
3641 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3644 list = g_list_nth (icon_view->priv->items, index + 1);
3645 for (; list; list = list->next)
3652 verify_items (icon_view);
3654 gtk_icon_view_queue_layout (icon_view);
3658 gtk_icon_view_row_deleted (GtkTreeModel *model,
3663 GtkIconView *icon_view;
3664 GtkIconViewItem *item;
3666 gboolean emit = FALSE;
3668 icon_view = GTK_ICON_VIEW (data);
3670 index = gtk_tree_path_get_indices(path)[0];
3672 list = g_list_nth (icon_view->priv->items, index);
3675 gtk_icon_view_stop_editing (icon_view, TRUE);
3677 if (item == icon_view->priv->anchor_item)
3678 icon_view->priv->anchor_item = NULL;
3680 if (item == icon_view->priv->cursor_item)
3681 icon_view->priv->cursor_item = NULL;
3686 gtk_icon_view_item_free (item);
3688 for (next = list->next; next; next = next->next)
3695 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3697 verify_items (icon_view);
3699 gtk_icon_view_queue_layout (icon_view);
3702 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3706 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3707 GtkTreePath *parent,
3714 GtkIconView *icon_view;
3715 GList *items = NULL, *list;
3716 GtkIconViewItem **item_array;
3719 icon_view = GTK_ICON_VIEW (data);
3721 gtk_icon_view_stop_editing (icon_view, TRUE);
3723 length = gtk_tree_model_iter_n_children (model, NULL);
3725 order = g_new (gint, length);
3726 for (i = 0; i < length; i++)
3727 order [new_order[i]] = i;
3729 item_array = g_new (GtkIconViewItem *, length);
3730 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3731 item_array[order[i]] = list->data;
3734 for (i = length - 1; i >= 0; i--)
3736 item_array[i]->index = i;
3737 items = g_list_prepend (items, item_array[i]);
3740 g_free (item_array);
3741 g_list_free (icon_view->priv->items);
3742 icon_view->priv->items = items;
3744 gtk_icon_view_queue_layout (icon_view);
3746 verify_items (icon_view);
3750 gtk_icon_view_build_items (GtkIconView *icon_view)
3754 gboolean iters_persist;
3755 GList *items = NULL;
3757 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3759 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3767 GtkIconViewItem *item = gtk_icon_view_item_new ();
3776 items = g_list_prepend (items, item);
3778 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3780 icon_view->priv->items = g_list_reverse (items);
3784 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3787 GtkMovementStep step,
3791 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3792 I_("move-cursor"), 2,
3796 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3801 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3804 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3809 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3816 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3817 GtkMovementStep step,
3820 GdkModifierType state;
3822 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3823 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3824 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3825 step == GTK_MOVEMENT_DISPLAY_LINES ||
3826 step == GTK_MOVEMENT_PAGES ||
3827 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3829 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3832 gtk_icon_view_stop_editing (icon_view, FALSE);
3833 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3835 if (gtk_get_current_event_state (&state))
3837 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3838 icon_view->priv->ctrl_pressed = TRUE;
3839 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3840 icon_view->priv->shift_pressed = TRUE;
3842 /* else we assume not pressed */
3846 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3847 case GTK_MOVEMENT_VISUAL_POSITIONS:
3848 gtk_icon_view_move_cursor_left_right (icon_view, count);
3850 case GTK_MOVEMENT_DISPLAY_LINES:
3851 gtk_icon_view_move_cursor_up_down (icon_view, count);
3853 case GTK_MOVEMENT_PAGES:
3854 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3856 case GTK_MOVEMENT_BUFFER_ENDS:
3857 gtk_icon_view_move_cursor_start_end (icon_view, count);
3860 g_assert_not_reached ();
3863 icon_view->priv->ctrl_pressed = FALSE;
3864 icon_view->priv->shift_pressed = FALSE;
3866 icon_view->priv->draw_focus = TRUE;
3871 static GtkIconViewItem *
3872 find_item (GtkIconView *icon_view,
3873 GtkIconViewItem *current,
3879 GtkIconViewItem *item;
3881 /* FIXME: this could be more efficient
3883 row = current->row + row_ofs;
3884 col = current->col + col_ofs;
3886 for (items = icon_view->priv->items; items; items = items->next)
3889 if (item->row == row && item->col == col)
3897 find_cell (GtkIconView *icon_view,
3898 GtkIconViewItem *item,
3900 GtkOrientation orientation,
3910 if (icon_view->priv->orientation != orientation)
3913 gtk_icon_view_set_cell_data (icon_view, item);
3915 focusable = g_new0 (gint, icon_view->priv->n_cells);
3919 for (k = 0; k < 2; k++)
3920 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3922 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3924 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3927 if (!info->cell->visible)
3930 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3933 current = n_focusable;
3935 focusable[n_focusable] = i;
3941 if (n_focusable == 0)
3949 current = step > 0 ? 0 : n_focusable - 1;
3950 cell = focusable[current];
3953 if (current + *count < 0)
3956 *count = current + *count;
3958 else if (current + *count > n_focusable - 1)
3961 *count = current + *count - (n_focusable - 1);
3965 cell = focusable[current + *count];
3974 static GtkIconViewItem *
3975 find_item_page_up_down (GtkIconView *icon_view,
3976 GtkIconViewItem *current,
3983 y = current->y + count * icon_view->priv->vadjustment->page_size;
3985 item = g_list_find (icon_view->priv->items, current);
3990 for (next = item->next; next; next = next->next)
3992 if (((GtkIconViewItem *)next->data)->col == col)
3995 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4005 for (next = item->prev; next; next = next->prev)
4007 if (((GtkIconViewItem *)next->data)->col == col)
4010 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4024 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4025 GtkIconViewItem *anchor,
4026 GtkIconViewItem *cursor)
4029 GtkIconViewItem *item;
4030 gint row1, row2, col1, col2;
4031 gboolean dirty = FALSE;
4033 if (anchor->row < cursor->row)
4044 if (anchor->col < cursor->col)
4055 for (items = icon_view->priv->items; items; items = items->next)
4059 if (row1 <= item->row && item->row <= row2 &&
4060 col1 <= item->col && item->col <= col2)
4062 if (!item->selected)
4065 item->selected = TRUE;
4066 gtk_icon_view_item_selected_changed (icon_view, item);
4068 gtk_icon_view_queue_draw_item (icon_view, item);
4076 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4079 GtkIconViewItem *item;
4081 gboolean dirty = FALSE;
4084 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4087 if (!icon_view->priv->cursor_item)
4092 list = icon_view->priv->items;
4094 list = g_list_last (icon_view->priv->items);
4096 item = list ? list->data : NULL;
4101 item = icon_view->priv->cursor_item;
4102 cell = icon_view->priv->cursor_cell;
4103 step = count > 0 ? 1 : -1;
4106 cell = find_cell (icon_view, item, cell,
4107 GTK_ORIENTATION_VERTICAL,
4112 item = find_item (icon_view, item, step, 0);
4113 count = count - step;
4119 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4123 if (icon_view->priv->ctrl_pressed ||
4124 !icon_view->priv->shift_pressed ||
4125 !icon_view->priv->anchor_item ||
4126 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4127 icon_view->priv->anchor_item = item;
4129 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4131 if (!icon_view->priv->ctrl_pressed &&
4132 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4134 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4135 dirty = gtk_icon_view_select_all_between (icon_view,
4136 icon_view->priv->anchor_item,
4140 gtk_icon_view_scroll_to_item (icon_view, item);
4143 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4147 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4150 GtkIconViewItem *item;
4151 gboolean dirty = FALSE;
4153 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4156 if (!icon_view->priv->cursor_item)
4161 list = icon_view->priv->items;
4163 list = g_list_last (icon_view->priv->items);
4165 item = list ? list->data : NULL;
4168 item = find_item_page_up_down (icon_view,
4169 icon_view->priv->cursor_item,
4172 if (item == icon_view->priv->cursor_item)
4173 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4178 if (icon_view->priv->ctrl_pressed ||
4179 !icon_view->priv->shift_pressed ||
4180 !icon_view->priv->anchor_item ||
4181 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4182 icon_view->priv->anchor_item = item;
4184 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4186 if (!icon_view->priv->ctrl_pressed &&
4187 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4189 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4190 dirty = gtk_icon_view_select_all_between (icon_view,
4191 icon_view->priv->anchor_item,
4195 gtk_icon_view_scroll_to_item (icon_view, item);
4198 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4202 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4205 GtkIconViewItem *item;
4207 gboolean dirty = FALSE;
4210 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4213 if (!icon_view->priv->cursor_item)
4218 list = icon_view->priv->items;
4220 list = g_list_last (icon_view->priv->items);
4222 item = list ? list->data : NULL;
4226 item = icon_view->priv->cursor_item;
4227 cell = icon_view->priv->cursor_cell;
4228 step = count > 0 ? 1 : -1;
4231 cell = find_cell (icon_view, item, cell,
4232 GTK_ORIENTATION_HORIZONTAL,
4237 item = find_item (icon_view, item, 0, step);
4238 count = count - step;
4244 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4248 if (icon_view->priv->ctrl_pressed ||
4249 !icon_view->priv->shift_pressed ||
4250 !icon_view->priv->anchor_item ||
4251 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4252 icon_view->priv->anchor_item = item;
4254 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4256 if (!icon_view->priv->ctrl_pressed &&
4257 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4259 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4260 dirty = gtk_icon_view_select_all_between (icon_view,
4261 icon_view->priv->anchor_item,
4265 gtk_icon_view_scroll_to_item (icon_view, item);
4268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4272 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4275 GtkIconViewItem *item;
4277 gboolean dirty = FALSE;
4279 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4283 list = icon_view->priv->items;
4285 list = g_list_last (icon_view->priv->items);
4287 item = list ? list->data : NULL;
4289 if (item == icon_view->priv->cursor_item)
4290 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4295 if (icon_view->priv->ctrl_pressed ||
4296 !icon_view->priv->shift_pressed ||
4297 !icon_view->priv->anchor_item ||
4298 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4299 icon_view->priv->anchor_item = item;
4301 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4303 if (!icon_view->priv->ctrl_pressed &&
4304 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4306 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4307 dirty = gtk_icon_view_select_all_between (icon_view,
4308 icon_view->priv->anchor_item,
4312 gtk_icon_view_scroll_to_item (icon_view, item);
4315 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4319 * gtk_icon_view_scroll_to_path:
4320 * @icon_view: A #GtkIconView.
4321 * @path: The path of the item to move to.
4322 * @use_align: whether to use alignment arguments, or %FALSE.
4323 * @row_align: The vertical alignment of the item specified by @path.
4324 * @col_align: The horizontal alignment of the item specified by @path.
4326 * Moves the alignments of @icon_view to the position specified by @path.
4327 * @row_align determines where the row is placed, and @col_align determines
4328 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4329 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4332 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4333 * tree does the minimum amount of work to scroll the item onto the screen.
4334 * This means that the item will be scrolled to the edge closest to its current
4335 * position. If the item is currently visible on the screen, nothing is done.
4337 * This function only works if the model is set, and @path is a valid row on
4338 * the model. If the model changes before the @icon_view is realized, the
4339 * centered path will be modified to reflect this change.
4344 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4350 GtkIconViewItem *item = NULL;
4352 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4353 g_return_if_fail (path != NULL);
4354 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4355 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4357 if (gtk_tree_path_get_depth (path) > 0)
4358 item = g_list_nth_data (icon_view->priv->items,
4359 gtk_tree_path_get_indices(path)[0]);
4361 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4363 if (icon_view->priv->scroll_to_path)
4364 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4366 icon_view->priv->scroll_to_path = NULL;
4369 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4371 icon_view->priv->scroll_to_use_align = use_align;
4372 icon_view->priv->scroll_to_row_align = row_align;
4373 icon_view->priv->scroll_to_col_align = col_align;
4382 gfloat offset, value;
4384 gtk_widget_style_get (GTK_WIDGET (icon_view),
4385 "focus-line-width", &focus_width,
4388 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4390 offset = y + item->y - focus_width -
4391 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4392 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4393 icon_view->priv->vadjustment->lower,
4394 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4395 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4397 offset = x + item->x - focus_width -
4398 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4399 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4400 icon_view->priv->hadjustment->lower,
4401 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4402 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4404 gtk_adjustment_changed (icon_view->priv->hadjustment);
4405 gtk_adjustment_changed (icon_view->priv->vadjustment);
4408 gtk_icon_view_scroll_to_item (icon_view, item);
4413 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4414 GtkIconViewItem *item)
4416 gint x, y, width, height;
4419 gtk_widget_style_get (GTK_WIDGET (icon_view),
4420 "focus-line-width", &focus_width,
4423 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4425 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4427 if (y + item->y - focus_width < 0)
4428 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4429 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4430 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4431 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4432 icon_view->priv->vadjustment->value + y + item->y + item->height
4433 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4435 if (x + item->x - focus_width < 0)
4436 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4437 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4438 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4439 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4440 icon_view->priv->hadjustment->value + x + item->x + item->width
4441 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4443 gtk_adjustment_changed (icon_view->priv->hadjustment);
4444 gtk_adjustment_changed (icon_view->priv->vadjustment);
4447 /* GtkCellLayout implementation */
4448 static GtkIconViewCellInfo *
4449 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4450 GtkCellRenderer *renderer)
4454 for (i = icon_view->priv->cell_list; i; i = i->next)
4456 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4458 if (info->cell == renderer)
4466 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4467 GtkIconViewItem *item)
4470 gboolean iters_persist;
4473 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4479 path = gtk_tree_path_new_from_indices (item->index, -1);
4480 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4482 gtk_tree_path_free (path);
4487 for (i = icon_view->priv->cell_list; i; i = i->next)
4490 GtkIconViewCellInfo *info = i->data;
4492 g_object_freeze_notify (G_OBJECT (info->cell));
4494 for (j = info->attributes; j && j->next; j = j->next->next)
4496 gchar *property = j->data;
4497 gint column = GPOINTER_TO_INT (j->next->data);
4498 GValue value = {0, };
4500 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4502 g_object_set_property (G_OBJECT (info->cell),
4504 g_value_unset (&value);
4508 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4510 icon_view->priv->model,
4514 g_object_thaw_notify (G_OBJECT (info->cell));
4519 free_cell_attributes (GtkIconViewCellInfo *info)
4523 list = info->attributes;
4524 while (list && list->next)
4526 g_free (list->data);
4527 list = list->next->next;
4530 g_slist_free (info->attributes);
4531 info->attributes = NULL;
4535 free_cell_info (GtkIconViewCellInfo *info)
4537 free_cell_attributes (info);
4539 g_object_unref (info->cell);
4542 (* info->destroy) (info->func_data);
4548 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4549 GtkCellRenderer *renderer,
4552 GtkIconViewCellInfo *info;
4553 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4555 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4556 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4558 g_object_ref_sink (renderer);
4560 info = g_new0 (GtkIconViewCellInfo, 1);
4561 info->cell = renderer;
4562 info->expand = expand ? TRUE : FALSE;
4563 info->pack = GTK_PACK_START;
4564 info->position = icon_view->priv->n_cells;
4566 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4567 icon_view->priv->n_cells++;
4571 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4572 GtkCellRenderer *renderer,
4575 GtkIconViewCellInfo *info;
4576 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4578 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4579 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4581 g_object_ref_sink (renderer);
4583 info = g_new0 (GtkIconViewCellInfo, 1);
4584 info->cell = renderer;
4585 info->expand = expand ? TRUE : FALSE;
4586 info->pack = GTK_PACK_END;
4587 info->position = icon_view->priv->n_cells;
4589 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4590 icon_view->priv->n_cells++;
4594 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4595 GtkCellRenderer *renderer,
4596 const gchar *attribute,
4599 GtkIconViewCellInfo *info;
4600 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4602 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4603 g_return_if_fail (info != NULL);
4605 info->attributes = g_slist_prepend (info->attributes,
4606 GINT_TO_POINTER (column));
4607 info->attributes = g_slist_prepend (info->attributes,
4608 g_strdup (attribute));
4612 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4614 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4616 while (icon_view->priv->cell_list)
4618 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4619 free_cell_info (info);
4620 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4621 icon_view->priv->cell_list);
4624 icon_view->priv->n_cells = 0;
4628 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4629 GtkCellRenderer *cell,
4630 GtkCellLayoutDataFunc func,
4632 GDestroyNotify destroy)
4634 GtkIconViewCellInfo *info;
4635 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4637 info = gtk_icon_view_get_cell_info (icon_view, cell);
4638 g_return_if_fail (info != NULL);
4642 GDestroyNotify d = info->destroy;
4644 info->destroy = NULL;
4645 d (info->func_data);
4649 info->func_data = func_data;
4650 info->destroy = destroy;
4654 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4655 GtkCellRenderer *renderer)
4657 GtkIconViewCellInfo *info;
4659 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4661 free_cell_attributes (info);
4665 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4666 GtkCellRenderer *cell,
4669 GtkIconView *icon_view;
4671 GtkIconViewCellInfo *info;
4674 icon_view = GTK_ICON_VIEW (layout);
4676 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4678 info = gtk_icon_view_get_cell_info (icon_view, cell);
4680 g_return_if_fail (info != NULL);
4681 g_return_if_fail (position >= 0);
4683 link = g_list_find (icon_view->priv->cell_list, info);
4685 g_return_if_fail (link != NULL);
4687 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4689 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4692 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4699 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4703 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4705 GtkIconView *icon_view = (GtkIconView *)layout;
4706 GList *retval = NULL, *l;
4708 for (l = icon_view->priv->cell_list; l; l = l->next)
4710 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4712 retval = g_list_prepend (retval, info->cell);
4715 return g_list_reverse (retval);
4722 * gtk_icon_view_new:
4724 * Creates a new #GtkIconView widget
4726 * Return value: A newly created #GtkIconView widget
4731 gtk_icon_view_new (void)
4733 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4737 * gtk_icon_view_new_with_model:
4738 * @model: The model.
4740 * Creates a new #GtkIconView widget with the model @model.
4742 * Return value: A newly created #GtkIconView widget.
4747 gtk_icon_view_new_with_model (GtkTreeModel *model)
4749 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4753 * gtk_icon_view_convert_widget_to_bin_window_coords:
4754 * @icon_view: a #GtkIconView
4755 * @wx: X coordinate relative to the widget
4756 * @wy: Y coordinate relative to the widget
4757 * @bx: return location for bin_window X coordinate
4758 * @by: return location for bin_window Y coordinate
4760 * Converts widget coordinates to coordinates for the bin_window,
4761 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4766 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4774 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4776 if (icon_view->priv->bin_window)
4777 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4788 * gtk_icon_view_get_path_at_pos:
4789 * @icon_view: A #GtkIconView.
4790 * @x: The x position to be identified
4791 * @y: The y position to be identified
4793 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4794 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4795 * the cell at the specified position.
4796 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4797 * widget coordinates to bin_window coordinates.
4799 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4800 * if no icon exists at that position.
4805 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4809 GtkIconViewItem *item;
4812 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4814 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4819 path = gtk_tree_path_new_from_indices (item->index, -1);
4825 * gtk_icon_view_get_item_at_pos:
4826 * @icon_view: A #GtkIconView.
4827 * @x: The x position to be identified
4828 * @y: The y position to be identified
4829 * @path: Return location for the path, or %NULL
4830 * @cell: Return location for the renderer responsible for the cell
4831 * at (@x, @y), or %NULL
4833 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4834 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4835 * obtains the cell at the specified position. The returned path should
4836 * be freed with gtk_tree_path_free().
4837 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4838 * widget coordinates to bin_window coordinates.
4840 * Return value: %TRUE if an item exists at the specified position
4845 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4849 GtkCellRenderer **cell)
4851 GtkIconViewItem *item;
4852 GtkIconViewCellInfo *info;
4854 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4856 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4861 *path = gtk_tree_path_new_from_indices (item->index, -1);
4874 return (item != NULL);
4878 * gtk_icon_view_set_tooltip_item:
4879 * @icon_view: a #GtkIconView
4880 * @tooltip: a #GtkTooltip
4881 * @path: a #GtkTreePath
4883 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4884 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4885 * See also gtk_tooltip_set_tip_area().
4890 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4891 GtkTooltip *tooltip,
4894 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4895 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4897 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4901 * gtk_icon_view_set_tooltip_cell:
4902 * @icon_view: a #GtkIconView
4903 * @tooltip: a #GtkTooltip
4904 * @path: a #GtkTreePath
4905 * @cell: a #GtkCellRenderer or %NULL
4907 * Sets the tip area of @tooltip to the area which @cell occupies in
4908 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4910 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4915 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4916 GtkTooltip *tooltip,
4918 GtkCellRenderer *cell)
4921 GtkIconViewItem *item = NULL;
4922 GtkIconViewCellInfo *info = NULL;
4925 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4926 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4927 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4929 if (gtk_tree_path_get_depth (path) > 0)
4930 item = g_list_nth_data (icon_view->priv->items,
4931 gtk_tree_path_get_indices(path)[0]);
4938 info = gtk_icon_view_get_cell_info (icon_view, cell);
4939 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4945 rect.width = item->width;
4946 rect.height = item->height;
4949 if (icon_view->priv->bin_window)
4951 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4956 gtk_tooltip_set_tip_area (tooltip, &rect);
4961 * gtk_icon_view_get_tooltip_context:
4962 * @icon_view: an #GtkIconView
4963 * @x: the x coordinate (relative to widget coordinates)
4964 * @y: the y coordinate (relative to widget coordinates)
4965 * @keyboard_tip: whether this is a keyboard tooltip or not
4966 * @model: a pointer to receive a #GtkTreeModel or %NULL
4967 * @path: a pointer to receive a #GtkTreePath or %NULL
4968 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4970 * This function is supposed to be used in a #GtkWidget::query-tooltip
4971 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4972 * which are received in the signal handler, should be passed to this
4973 * function without modification.
4975 * The return value indicates whether there is an icon view item at the given
4976 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4977 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4978 * @model, @path and @iter which have been provided will be set to point to
4979 * that row and the corresponding model. @x and @y will always be converted
4980 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4982 * Return value: whether or not the given tooltip context points to a item
4987 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4990 gboolean keyboard_tip,
4991 GtkTreeModel **model,
4995 GtkTreePath *tmppath = NULL;
4997 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4998 g_return_val_if_fail (x != NULL, FALSE);
4999 g_return_val_if_fail (y != NULL, FALSE);
5003 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5010 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5013 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5018 *model = gtk_icon_view_get_model (icon_view);
5021 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5027 gtk_tree_path_free (tmppath);
5033 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5036 gboolean keyboard_tip,
5037 GtkTooltip *tooltip,
5043 GtkTreeModel *model;
5044 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5046 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5049 &model, &path, &iter))
5052 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5056 gtk_tree_path_free (path);
5060 gtk_tooltip_set_markup (tooltip, str);
5061 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5063 gtk_tree_path_free (path);
5071 * gtk_icon_view_set_tooltip_column:
5072 * @icon_view: a #GtkIconView
5073 * @column: an integer, which is a valid column number for @icon_view's model
5075 * If you only plan to have simple (text-only) tooltips on full items, you
5076 * can use this function to have #GtkIconView handle these automatically
5077 * for you. @column should be set to the column in @icon_view's model
5078 * containing the tooltip texts, or -1 to disable this feature.
5080 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5081 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5086 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5089 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5091 if (column == icon_view->priv->tooltip_column)
5096 g_signal_handlers_disconnect_by_func (icon_view,
5097 gtk_icon_view_set_tooltip_query_cb,
5099 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5103 if (icon_view->priv->tooltip_column == -1)
5105 g_signal_connect (icon_view, "query-tooltip",
5106 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5107 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5111 icon_view->priv->tooltip_column = column;
5112 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5116 * gtk_icon_view_get_tooltip_column:
5117 * @icon_view: a #GtkIconView
5119 * Returns the column of @icon_view's model which is being used for
5120 * displaying tooltips on @icon_view's rows.
5122 * Return value: the index of the tooltip column that is currently being
5123 * used, or -1 if this is disabled.
5128 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5130 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5132 return icon_view->priv->tooltip_column;
5136 * gtk_icon_view_get_visible_range:
5137 * @icon_view: A #GtkIconView
5138 * @start_path: Return location for start of region, or %NULL
5139 * @end_path: Return location for end of region, or %NULL
5141 * Sets @start_path and @end_path to be the first and last visible path.
5142 * Note that there may be invisible paths in between.
5144 * Both paths should be freed with gtk_tree_path_free() after use.
5146 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5151 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5152 GtkTreePath **start_path,
5153 GtkTreePath **end_path)
5155 gint start_index = -1;
5156 gint end_index = -1;
5159 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5161 if (icon_view->priv->hadjustment == NULL ||
5162 icon_view->priv->vadjustment == NULL)
5165 if (start_path == NULL && end_path == NULL)
5168 for (icons = icon_view->priv->items; icons; icons = icons->next)
5170 GtkIconViewItem *item = icons->data;
5172 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5173 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5174 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5175 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5177 if (start_index == -1)
5178 start_index = item->index;
5179 end_index = item->index;
5183 if (start_path && start_index != -1)
5184 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5185 if (end_path && end_index != -1)
5186 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5188 return start_index != -1;
5192 * gtk_icon_view_selected_foreach:
5193 * @icon_view: A #GtkIconView.
5194 * @func: The funcion to call for each selected icon.
5195 * @data: User data to pass to the function.
5197 * Calls a function for each selected icon. Note that the model or
5198 * selection cannot be modified from within this function.
5203 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5204 GtkIconViewForeachFunc func,
5209 for (list = icon_view->priv->items; list; list = list->next)
5211 GtkIconViewItem *item = list->data;
5212 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5215 (* func) (icon_view, path, data);
5217 gtk_tree_path_free (path);
5222 * gtk_icon_view_set_selection_mode:
5223 * @icon_view: A #GtkIconView.
5224 * @mode: The selection mode
5226 * Sets the selection mode of the @icon_view.
5231 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5232 GtkSelectionMode mode)
5234 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5236 if (mode == icon_view->priv->selection_mode)
5239 if (mode == GTK_SELECTION_NONE ||
5240 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5241 gtk_icon_view_unselect_all (icon_view);
5243 icon_view->priv->selection_mode = mode;
5245 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5249 * gtk_icon_view_get_selection_mode:
5250 * @icon_view: A #GtkIconView.
5252 * Gets the selection mode of the @icon_view.
5254 * Return value: the current selection mode
5259 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5261 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5263 return icon_view->priv->selection_mode;
5267 * gtk_icon_view_set_model:
5268 * @icon_view: A #GtkIconView.
5269 * @model: The model.
5271 * Sets the model for a #GtkIconView.
5272 * If the @icon_view already has a model set, it will remove
5273 * it before setting the new model. If @model is %NULL, then
5274 * it will unset the old model.
5279 gtk_icon_view_set_model (GtkIconView *icon_view,
5280 GtkTreeModel *model)
5282 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5283 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5285 if (icon_view->priv->model == model)
5288 if (icon_view->priv->scroll_to_path)
5290 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5291 icon_view->priv->scroll_to_path = NULL;
5294 gtk_icon_view_stop_editing (icon_view, TRUE);
5300 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5302 if (icon_view->priv->pixbuf_column != -1)
5304 column_type = gtk_tree_model_get_column_type (model,
5305 icon_view->priv->pixbuf_column);
5307 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5310 if (icon_view->priv->text_column != -1)
5312 column_type = gtk_tree_model_get_column_type (model,
5313 icon_view->priv->text_column);
5315 g_return_if_fail (column_type == G_TYPE_STRING);
5318 if (icon_view->priv->markup_column != -1)
5320 column_type = gtk_tree_model_get_column_type (model,
5321 icon_view->priv->markup_column);
5323 g_return_if_fail (column_type == G_TYPE_STRING);
5328 if (icon_view->priv->model)
5330 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5331 gtk_icon_view_row_changed,
5333 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5334 gtk_icon_view_row_inserted,
5336 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5337 gtk_icon_view_row_deleted,
5339 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5340 gtk_icon_view_rows_reordered,
5343 g_object_unref (icon_view->priv->model);
5345 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5346 g_list_free (icon_view->priv->items);
5347 icon_view->priv->items = NULL;
5348 icon_view->priv->anchor_item = NULL;
5349 icon_view->priv->cursor_item = NULL;
5350 icon_view->priv->last_single_clicked = NULL;
5351 icon_view->priv->width = 0;
5352 icon_view->priv->height = 0;
5355 icon_view->priv->model = model;
5357 if (icon_view->priv->model)
5359 g_object_ref (icon_view->priv->model);
5360 g_signal_connect (icon_view->priv->model,
5362 G_CALLBACK (gtk_icon_view_row_changed),
5364 g_signal_connect (icon_view->priv->model,
5366 G_CALLBACK (gtk_icon_view_row_inserted),
5368 g_signal_connect (icon_view->priv->model,
5370 G_CALLBACK (gtk_icon_view_row_deleted),
5372 g_signal_connect (icon_view->priv->model,
5374 G_CALLBACK (gtk_icon_view_rows_reordered),
5377 gtk_icon_view_build_items (icon_view);
5379 gtk_icon_view_queue_layout (icon_view);
5382 g_object_notify (G_OBJECT (icon_view), "model");
5384 if (GTK_WIDGET_REALIZED (icon_view))
5385 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5389 * gtk_icon_view_get_model:
5390 * @icon_view: a #GtkIconView
5392 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5395 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5400 gtk_icon_view_get_model (GtkIconView *icon_view)
5402 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5404 return icon_view->priv->model;
5408 update_text_cell (GtkIconView *icon_view)
5410 GtkIconViewCellInfo *info;
5414 if (icon_view->priv->text_column == -1 &&
5415 icon_view->priv->markup_column == -1)
5417 if (icon_view->priv->text_cell != -1)
5419 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5420 icon_view->priv->pixbuf_cell--;
5422 info = g_list_nth_data (icon_view->priv->cell_list,
5423 icon_view->priv->text_cell);
5425 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5427 free_cell_info (info);
5429 icon_view->priv->n_cells--;
5430 icon_view->priv->text_cell = -1;
5435 if (icon_view->priv->text_cell == -1)
5437 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5438 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5439 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5442 if (info->cell == cell)
5444 icon_view->priv->text_cell = i;
5450 info = g_list_nth_data (icon_view->priv->cell_list,
5451 icon_view->priv->text_cell);
5453 if (icon_view->priv->markup_column != -1)
5454 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5456 "markup", icon_view->priv->markup_column,
5459 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5461 "text", icon_view->priv->text_column,
5464 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5465 g_object_set (info->cell,
5466 "alignment", PANGO_ALIGN_CENTER,
5467 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5472 g_object_set (info->cell,
5473 "alignment", PANGO_ALIGN_LEFT,
5474 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5482 update_pixbuf_cell (GtkIconView *icon_view)
5484 GtkIconViewCellInfo *info;
5488 if (icon_view->priv->pixbuf_column == -1)
5490 if (icon_view->priv->pixbuf_cell != -1)
5492 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5493 icon_view->priv->text_cell--;
5495 info = g_list_nth_data (icon_view->priv->cell_list,
5496 icon_view->priv->pixbuf_cell);
5498 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5500 free_cell_info (info);
5502 icon_view->priv->n_cells--;
5503 icon_view->priv->pixbuf_cell = -1;
5508 if (icon_view->priv->pixbuf_cell == -1)
5510 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5512 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5513 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5516 if (info->cell == cell)
5518 icon_view->priv->pixbuf_cell = i;
5524 info = g_list_nth_data (icon_view->priv->cell_list,
5525 icon_view->priv->pixbuf_cell);
5527 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5529 "pixbuf", icon_view->priv->pixbuf_column,
5532 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5533 g_object_set (info->cell,
5538 g_object_set (info->cell,
5546 * gtk_icon_view_set_text_column:
5547 * @icon_view: A #GtkIconView.
5548 * @column: A column in the currently used model, or -1 to display no text
5550 * Sets the column with text for @icon_view to be @column. The text
5551 * column must be of type #G_TYPE_STRING.
5556 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5559 if (column == icon_view->priv->text_column)
5563 icon_view->priv->text_column = -1;
5566 if (icon_view->priv->model != NULL)
5570 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5572 g_return_if_fail (column_type == G_TYPE_STRING);
5575 icon_view->priv->text_column = column;
5578 gtk_icon_view_stop_editing (icon_view, TRUE);
5580 update_text_cell (icon_view);
5582 gtk_icon_view_invalidate_sizes (icon_view);
5583 gtk_icon_view_queue_layout (icon_view);
5585 g_object_notify (G_OBJECT (icon_view), "text-column");
5589 * gtk_icon_view_get_text_column:
5590 * @icon_view: A #GtkIconView.
5592 * Returns the column with text for @icon_view.
5594 * Returns: the text column, or -1 if it's unset.
5599 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5601 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5603 return icon_view->priv->text_column;
5607 * gtk_icon_view_set_markup_column:
5608 * @icon_view: A #GtkIconView.
5609 * @column: A column in the currently used model, or -1 to display no text
5611 * Sets the column with markup information for @icon_view to be
5612 * @column. The markup column must be of type #G_TYPE_STRING.
5613 * If the markup column is set to something, it overrides
5614 * the text column set by gtk_icon_view_set_text_column().
5619 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5622 if (column == icon_view->priv->markup_column)
5626 icon_view->priv->markup_column = -1;
5629 if (icon_view->priv->model != NULL)
5633 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5635 g_return_if_fail (column_type == G_TYPE_STRING);
5638 icon_view->priv->markup_column = column;
5641 gtk_icon_view_stop_editing (icon_view, TRUE);
5643 update_text_cell (icon_view);
5645 gtk_icon_view_invalidate_sizes (icon_view);
5646 gtk_icon_view_queue_layout (icon_view);
5648 g_object_notify (G_OBJECT (icon_view), "markup-column");
5652 * gtk_icon_view_get_markup_column:
5653 * @icon_view: A #GtkIconView.
5655 * Returns the column with markup text for @icon_view.
5657 * Returns: the markup column, or -1 if it's unset.
5662 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5664 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5666 return icon_view->priv->markup_column;
5670 * gtk_icon_view_set_pixbuf_column:
5671 * @icon_view: A #GtkIconView.
5672 * @column: A column in the currently used model, or -1 to disable
5674 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5675 * column must be of type #GDK_TYPE_PIXBUF
5680 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5683 if (column == icon_view->priv->pixbuf_column)
5687 icon_view->priv->pixbuf_column = -1;
5690 if (icon_view->priv->model != NULL)
5694 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5696 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5699 icon_view->priv->pixbuf_column = column;
5702 gtk_icon_view_stop_editing (icon_view, TRUE);
5704 update_pixbuf_cell (icon_view);
5706 gtk_icon_view_invalidate_sizes (icon_view);
5707 gtk_icon_view_queue_layout (icon_view);
5709 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5714 * gtk_icon_view_get_pixbuf_column:
5715 * @icon_view: A #GtkIconView.
5717 * Returns the column with pixbufs for @icon_view.
5719 * Returns: the pixbuf column, or -1 if it's unset.
5724 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5726 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5728 return icon_view->priv->pixbuf_column;
5732 * gtk_icon_view_select_path:
5733 * @icon_view: A #GtkIconView.
5734 * @path: The #GtkTreePath to be selected.
5736 * Selects the row at @path.
5741 gtk_icon_view_select_path (GtkIconView *icon_view,
5744 GtkIconViewItem *item = NULL;
5746 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5747 g_return_if_fail (icon_view->priv->model != NULL);
5748 g_return_if_fail (path != NULL);
5750 if (gtk_tree_path_get_depth (path) > 0)
5751 item = g_list_nth_data (icon_view->priv->items,
5752 gtk_tree_path_get_indices(path)[0]);
5755 gtk_icon_view_select_item (icon_view, item);
5759 * gtk_icon_view_unselect_path:
5760 * @icon_view: A #GtkIconView.
5761 * @path: The #GtkTreePath to be unselected.
5763 * Unselects the row at @path.
5768 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5771 GtkIconViewItem *item;
5773 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5774 g_return_if_fail (icon_view->priv->model != NULL);
5775 g_return_if_fail (path != NULL);
5777 item = g_list_nth_data (icon_view->priv->items,
5778 gtk_tree_path_get_indices(path)[0]);
5783 gtk_icon_view_unselect_item (icon_view, item);
5787 * gtk_icon_view_get_selected_items:
5788 * @icon_view: A #GtkIconView.
5790 * Creates a list of paths of all selected items. Additionally, if you are
5791 * planning on modifying the model after calling this function, you may
5792 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5793 * To do this, you can use gtk_tree_row_reference_new().
5795 * To free the return value, use:
5797 * g_list_foreach (list, gtk_tree_path_free, NULL);
5798 * g_list_free (list);
5801 * Return value: A #GList containing a #GtkTreePath for each selected row.
5806 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5809 GList *selected = NULL;
5811 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5813 for (list = icon_view->priv->items; list != NULL; list = list->next)
5815 GtkIconViewItem *item = list->data;
5819 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5821 selected = g_list_prepend (selected, path);
5829 * gtk_icon_view_select_all:
5830 * @icon_view: A #GtkIconView.
5832 * Selects all the icons. @icon_view must has its selection mode set
5833 * to #GTK_SELECTION_MULTIPLE.
5838 gtk_icon_view_select_all (GtkIconView *icon_view)
5841 gboolean dirty = FALSE;
5843 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5845 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5848 for (items = icon_view->priv->items; items; items = items->next)
5850 GtkIconViewItem *item = items->data;
5852 if (!item->selected)
5855 item->selected = TRUE;
5856 gtk_icon_view_queue_draw_item (icon_view, item);
5861 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5865 * gtk_icon_view_unselect_all:
5866 * @icon_view: A #GtkIconView.
5868 * Unselects all the icons.
5873 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5875 gboolean dirty = FALSE;
5877 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5879 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5882 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5885 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5889 * gtk_icon_view_path_is_selected:
5890 * @icon_view: A #GtkIconView.
5891 * @path: A #GtkTreePath to check selection on.
5893 * Returns %TRUE if the icon pointed to by @path is currently
5894 * selected. If @path does not point to a valid location, %FALSE is returned.
5896 * Return value: %TRUE if @path is selected.
5901 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5904 GtkIconViewItem *item;
5906 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5907 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5908 g_return_val_if_fail (path != NULL, FALSE);
5910 item = g_list_nth_data (icon_view->priv->items,
5911 gtk_tree_path_get_indices(path)[0]);
5916 return item->selected;
5920 * gtk_icon_view_item_activated:
5921 * @icon_view: A #GtkIconView
5922 * @path: The #GtkTreePath to be activated
5924 * Activates the item determined by @path.
5929 gtk_icon_view_item_activated (GtkIconView *icon_view,
5932 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5933 g_return_if_fail (path != NULL);
5935 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5939 * gtk_icon_view_set_orientation:
5940 * @icon_view: a #GtkIconView
5941 * @orientation: the relative position of texts and icons
5943 * Sets the ::orientation property which determines whether the labels
5944 * are drawn beside the icons instead of below.
5949 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5950 GtkOrientation orientation)
5952 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5954 if (icon_view->priv->orientation != orientation)
5956 icon_view->priv->orientation = orientation;
5958 gtk_icon_view_stop_editing (icon_view, TRUE);
5959 gtk_icon_view_invalidate_sizes (icon_view);
5960 gtk_icon_view_queue_layout (icon_view);
5962 update_text_cell (icon_view);
5963 update_pixbuf_cell (icon_view);
5965 g_object_notify (G_OBJECT (icon_view), "orientation");
5970 * gtk_icon_view_get_orientation:
5971 * @icon_view: a #GtkIconView
5973 * Returns the value of the ::orientation property which determines
5974 * whether the labels are drawn beside the icons instead of below.
5976 * Return value: the relative position of texts and icons
5981 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5983 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5984 GTK_ORIENTATION_VERTICAL);
5986 return icon_view->priv->orientation;
5990 * gtk_icon_view_set_columns:
5991 * @icon_view: a #GtkIconView
5992 * @columns: the number of columns
5994 * Sets the ::columns property which determines in how
5995 * many columns the icons are arranged. If @columns is
5996 * -1, the number of columns will be chosen automatically
5997 * to fill the available area.
6002 gtk_icon_view_set_columns (GtkIconView *icon_view,
6005 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6007 if (icon_view->priv->columns != columns)
6009 icon_view->priv->columns = columns;
6011 gtk_icon_view_stop_editing (icon_view, TRUE);
6012 gtk_icon_view_queue_layout (icon_view);
6014 g_object_notify (G_OBJECT (icon_view), "columns");
6019 * gtk_icon_view_get_columns:
6020 * @icon_view: a #GtkIconView
6022 * Returns the value of the ::columns property.
6024 * Return value: the number of columns, or -1
6029 gtk_icon_view_get_columns (GtkIconView *icon_view)
6031 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6033 return icon_view->priv->columns;
6037 * gtk_icon_view_set_item_width:
6038 * @icon_view: a #GtkIconView
6039 * @item_width: the width for each item
6041 * Sets the ::item-width property which specifies the width
6042 * to use for each item. If it is set to -1, the icon view will
6043 * automatically determine a suitable item size.
6048 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6051 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6053 if (icon_view->priv->item_width != item_width)
6055 icon_view->priv->item_width = item_width;
6057 gtk_icon_view_stop_editing (icon_view, TRUE);
6058 gtk_icon_view_invalidate_sizes (icon_view);
6059 gtk_icon_view_queue_layout (icon_view);
6061 update_text_cell (icon_view);
6063 g_object_notify (G_OBJECT (icon_view), "item-width");
6068 * gtk_icon_view_get_item_width:
6069 * @icon_view: a #GtkIconView
6071 * Returns the value of the ::item-width property.
6073 * Return value: the width of a single item, or -1
6078 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6080 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6082 return icon_view->priv->item_width;
6087 * gtk_icon_view_set_spacing:
6088 * @icon_view: a #GtkIconView
6089 * @spacing: the spacing
6091 * Sets the ::spacing property which specifies the space
6092 * which is inserted between the cells (i.e. the icon and
6093 * the text) of an item.
6098 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6101 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6103 if (icon_view->priv->spacing != spacing)
6105 icon_view->priv->spacing = spacing;
6107 gtk_icon_view_stop_editing (icon_view, TRUE);
6108 gtk_icon_view_invalidate_sizes (icon_view);
6109 gtk_icon_view_queue_layout (icon_view);
6111 g_object_notify (G_OBJECT (icon_view), "spacing");
6116 * gtk_icon_view_get_spacing:
6117 * @icon_view: a #GtkIconView
6119 * Returns the value of the ::spacing property.
6121 * Return value: the space between cells
6126 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6128 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6130 return icon_view->priv->spacing;
6134 * gtk_icon_view_set_row_spacing:
6135 * @icon_view: a #GtkIconView
6136 * @row_spacing: the row spacing
6138 * Sets the ::row-spacing property which specifies the space
6139 * which is inserted between the rows of the icon view.
6144 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6147 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6149 if (icon_view->priv->row_spacing != row_spacing)
6151 icon_view->priv->row_spacing = row_spacing;
6153 gtk_icon_view_stop_editing (icon_view, TRUE);
6154 gtk_icon_view_invalidate_sizes (icon_view);
6155 gtk_icon_view_queue_layout (icon_view);
6157 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6162 * gtk_icon_view_get_row_spacing:
6163 * @icon_view: a #GtkIconView
6165 * Returns the value of the ::row-spacing property.
6167 * Return value: the space between rows
6172 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6174 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6176 return icon_view->priv->row_spacing;
6180 * gtk_icon_view_set_column_spacing:
6181 * @icon_view: a #GtkIconView
6182 * @column_spacing: the column spacing
6184 * Sets the ::column-spacing property which specifies the space
6185 * which is inserted between the columns of the icon view.
6190 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6191 gint column_spacing)
6193 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6195 if (icon_view->priv->column_spacing != column_spacing)
6197 icon_view->priv->column_spacing = column_spacing;
6199 gtk_icon_view_stop_editing (icon_view, TRUE);
6200 gtk_icon_view_invalidate_sizes (icon_view);
6201 gtk_icon_view_queue_layout (icon_view);
6203 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6208 * gtk_icon_view_get_column_spacing:
6209 * @icon_view: a #GtkIconView
6211 * Returns the value of the ::column-spacing property.
6213 * Return value: the space between columns
6218 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6220 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6222 return icon_view->priv->column_spacing;
6226 * gtk_icon_view_set_margin:
6227 * @icon_view: a #GtkIconView
6228 * @margin: the margin
6230 * Sets the ::margin property which specifies the space
6231 * which is inserted at the top, bottom, left and right
6237 gtk_icon_view_set_margin (GtkIconView *icon_view,
6240 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6242 if (icon_view->priv->margin != margin)
6244 icon_view->priv->margin = margin;
6246 gtk_icon_view_stop_editing (icon_view, TRUE);
6247 gtk_icon_view_invalidate_sizes (icon_view);
6248 gtk_icon_view_queue_layout (icon_view);
6250 g_object_notify (G_OBJECT (icon_view), "margin");
6255 * gtk_icon_view_get_margin:
6256 * @icon_view: a #GtkIconView
6258 * Returns the value of the ::margin property.
6260 * Return value: the space at the borders
6265 gtk_icon_view_get_margin (GtkIconView *icon_view)
6267 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6269 return icon_view->priv->margin;
6273 * gtk_icon_view_set_item_padding:
6274 * @icon_view: a #GtkIconView
6275 * @column_spacing: the item padding
6277 * Sets the ::item-padding property which specifies the padding
6278 * around each of the icon view's items.
6283 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6286 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6288 if (icon_view->priv->item_padding != item_padding)
6290 icon_view->priv->item_padding = item_padding;
6292 gtk_icon_view_stop_editing (icon_view, TRUE);
6293 gtk_icon_view_invalidate_sizes (icon_view);
6294 gtk_icon_view_queue_layout (icon_view);
6296 g_object_notify (G_OBJECT (icon_view), "item-padding");
6301 * gtk_icon_view_get_item_padding:
6302 * @icon_view: a #GtkIconView
6304 * Returns the value of the ::item-padding property.
6306 * Return value: the padding around items
6311 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6313 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6315 return icon_view->priv->item_padding;
6318 /* Get/set whether drag_motion requested the drag data and
6319 * drag_data_received should thus not actually insert the data,
6320 * since the data doesn't result from a drop.
6323 set_status_pending (GdkDragContext *context,
6324 GdkDragAction suggested_action)
6326 g_object_set_data (G_OBJECT (context),
6327 I_("gtk-icon-view-status-pending"),
6328 GINT_TO_POINTER (suggested_action));
6331 static GdkDragAction
6332 get_status_pending (GdkDragContext *context)
6334 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6335 "gtk-icon-view-status-pending"));
6339 unset_reorderable (GtkIconView *icon_view)
6341 if (icon_view->priv->reorderable)
6343 icon_view->priv->reorderable = FALSE;
6344 g_object_notify (G_OBJECT (icon_view), "reorderable");
6349 set_source_row (GdkDragContext *context,
6350 GtkTreeModel *model,
6351 GtkTreePath *source_row)
6354 g_object_set_data_full (G_OBJECT (context),
6355 I_("gtk-icon-view-source-row"),
6356 gtk_tree_row_reference_new (model, source_row),
6357 (GDestroyNotify) gtk_tree_row_reference_free);
6359 g_object_set_data_full (G_OBJECT (context),
6360 I_("gtk-icon-view-source-row"),
6365 get_source_row (GdkDragContext *context)
6367 GtkTreeRowReference *ref;
6369 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6372 return gtk_tree_row_reference_get_path (ref);
6379 GtkTreeRowReference *dest_row;
6380 gboolean empty_view_drop;
6381 gboolean drop_append_mode;
6385 dest_row_free (gpointer data)
6387 DestRow *dr = (DestRow *)data;
6389 gtk_tree_row_reference_free (dr->dest_row);
6394 set_dest_row (GdkDragContext *context,
6395 GtkTreeModel *model,
6396 GtkTreePath *dest_row,
6397 gboolean empty_view_drop,
6398 gboolean drop_append_mode)
6404 g_object_set_data_full (G_OBJECT (context),
6405 I_("gtk-icon-view-dest-row"),
6410 dr = g_new0 (DestRow, 1);
6412 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6413 dr->empty_view_drop = empty_view_drop;
6414 dr->drop_append_mode = drop_append_mode;
6415 g_object_set_data_full (G_OBJECT (context),
6416 I_("gtk-icon-view-dest-row"),
6417 dr, (GDestroyNotify) dest_row_free);
6421 get_dest_row (GdkDragContext *context)
6425 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6429 GtkTreePath *path = NULL;
6432 path = gtk_tree_row_reference_get_path (dr->dest_row);
6433 else if (dr->empty_view_drop)
6434 path = gtk_tree_path_new_from_indices (0, -1);
6438 if (path && dr->drop_append_mode)
6439 gtk_tree_path_next (path);
6448 check_model_dnd (GtkTreeModel *model,
6449 GType required_iface,
6450 const gchar *signal)
6452 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6454 g_warning ("You must override the default '%s' handler "
6455 "on GtkIconView when using models that don't support "
6456 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6457 "is to connect to '%s' and call "
6458 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6459 "the default handler from running. Look at the source code "
6460 "for the default handler in gtkiconview.c to get an idea what "
6461 "your handler should do. (gtkiconview.c is in the GTK+ source "
6462 "code.) If you're using GTK+ from a language other than C, "
6463 "there may be a more natural way to override default handlers, e.g. via derivation.",
6464 signal, g_type_name (required_iface), signal);
6472 remove_scroll_timeout (GtkIconView *icon_view)
6474 if (icon_view->priv->scroll_timeout_id != 0)
6476 g_source_remove (icon_view->priv->scroll_timeout_id);
6478 icon_view->priv->scroll_timeout_id = 0;
6483 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6485 gint px, py, x, y, width, height;
6486 gint hoffset, voffset;
6489 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6490 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6492 /* see if we are near the edge. */
6493 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6495 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6497 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6499 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6503 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6504 icon_view->priv->vadjustment->lower,
6505 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6506 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6510 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6511 icon_view->priv->hadjustment->lower,
6512 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6513 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6519 drag_scroll_timeout (gpointer data)
6521 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6523 gtk_icon_view_autoscroll (icon_view);
6530 set_destination (GtkIconView *icon_view,
6531 GdkDragContext *context,
6534 GdkDragAction *suggested_action,
6538 GtkTreePath *path = NULL;
6539 GtkIconViewDropPosition pos;
6540 GtkIconViewDropPosition old_pos;
6541 GtkTreePath *old_dest_path = NULL;
6542 gboolean can_drop = FALSE;
6544 widget = GTK_WIDGET (icon_view);
6546 *suggested_action = 0;
6549 if (!icon_view->priv->dest_set)
6551 /* someone unset us as a drag dest, note that if
6552 * we return FALSE drag_leave isn't called
6555 gtk_icon_view_set_drag_dest_item (icon_view,
6557 GTK_ICON_VIEW_DROP_LEFT);
6559 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6561 return FALSE; /* no longer a drop site */
6564 *target = gtk_drag_dest_find_target (widget, context,
6565 gtk_drag_dest_get_target_list (widget));
6566 if (*target == GDK_NONE)
6569 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6572 GtkTreeModel *model;
6574 /* the row got dropped on empty space, let's setup a special case
6578 gtk_tree_path_free (path);
6580 model = gtk_icon_view_get_model (icon_view);
6582 n_children = gtk_tree_model_iter_n_children (model, NULL);
6585 pos = GTK_ICON_VIEW_DROP_BELOW;
6586 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6590 pos = GTK_ICON_VIEW_DROP_ABOVE;
6591 path = gtk_tree_path_new_from_indices (0, -1);
6601 gtk_icon_view_get_drag_dest_item (icon_view,
6606 gtk_tree_path_free (old_dest_path);
6608 if (TRUE /* FIXME if the location droppable predicate */)
6616 GtkWidget *source_widget;
6618 *suggested_action = context->suggested_action;
6619 source_widget = gtk_drag_get_source_widget (context);
6621 if (source_widget == widget)
6623 /* Default to MOVE, unless the user has
6624 * pressed ctrl or shift to affect available actions
6626 if ((context->actions & GDK_ACTION_MOVE) != 0)
6627 *suggested_action = GDK_ACTION_MOVE;
6630 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6635 /* can't drop here */
6636 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6638 GTK_ICON_VIEW_DROP_LEFT);
6642 gtk_tree_path_free (path);
6648 get_logical_destination (GtkIconView *icon_view,
6649 gboolean *drop_append_mode)
6651 /* adjust path to point to the row the drop goes in front of */
6652 GtkTreePath *path = NULL;
6653 GtkIconViewDropPosition pos;
6655 *drop_append_mode = FALSE;
6657 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6662 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6663 pos == GTK_ICON_VIEW_DROP_BELOW)
6666 GtkTreeModel *model = icon_view->priv->model;
6668 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6669 !gtk_tree_model_iter_next (model, &iter))
6670 *drop_append_mode = TRUE;
6673 *drop_append_mode = FALSE;
6674 gtk_tree_path_next (path);
6682 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6683 GdkEventMotion *event)
6685 GtkWidget *widget = GTK_WIDGET (icon_view);
6686 GdkDragContext *context;
6687 GtkTreePath *path = NULL;
6689 GtkTreeModel *model;
6690 gboolean retval = FALSE;
6692 if (!icon_view->priv->source_set)
6695 if (icon_view->priv->pressed_button < 0)
6698 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6699 icon_view->priv->press_start_x,
6700 icon_view->priv->press_start_y,
6701 event->x, event->y))
6704 model = gtk_icon_view_get_model (icon_view);
6709 button = icon_view->priv->pressed_button;
6710 icon_view->priv->pressed_button = -1;
6712 path = gtk_icon_view_get_path_at_pos (icon_view,
6713 icon_view->priv->press_start_x,
6714 icon_view->priv->press_start_y);
6719 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6720 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6724 /* FIXME Check whether we're a start button, if not return FALSE and
6728 /* Now we can begin the drag */
6732 context = gtk_drag_begin (widget,
6733 gtk_drag_source_get_target_list (widget),
6734 icon_view->priv->source_actions,
6738 set_source_row (context, model, path);
6742 gtk_tree_path_free (path);
6747 /* Source side drag signals */
6749 gtk_icon_view_drag_begin (GtkWidget *widget,
6750 GdkDragContext *context)
6752 GtkIconView *icon_view;
6753 GtkIconViewItem *item;
6758 icon_view = GTK_ICON_VIEW (widget);
6760 /* if the user uses a custom DnD impl, we don't set the icon here */
6761 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6764 item = gtk_icon_view_get_item_at_coords (icon_view,
6765 icon_view->priv->press_start_x,
6766 icon_view->priv->press_start_y,
6770 g_return_if_fail (item != NULL);
6772 x = icon_view->priv->press_start_x - item->x + 1;
6773 y = icon_view->priv->press_start_y - item->y + 1;
6775 path = gtk_tree_path_new_from_indices (item->index, -1);
6776 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6777 gtk_tree_path_free (path);
6779 gtk_drag_set_icon_pixmap (context,
6780 gdk_drawable_get_colormap (icon),
6785 g_object_unref (icon);
6789 gtk_icon_view_drag_end (GtkWidget *widget,
6790 GdkDragContext *context)
6796 gtk_icon_view_drag_data_get (GtkWidget *widget,
6797 GdkDragContext *context,
6798 GtkSelectionData *selection_data,
6802 GtkIconView *icon_view;
6803 GtkTreeModel *model;
6804 GtkTreePath *source_row;
6806 icon_view = GTK_ICON_VIEW (widget);
6807 model = gtk_icon_view_get_model (icon_view);
6812 if (!icon_view->priv->source_set)
6815 source_row = get_source_row (context);
6817 if (source_row == NULL)
6820 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6821 * any model; for DragSource models there are some other targets
6825 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6826 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6831 /* If drag_data_get does nothing, try providing row data. */
6832 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6833 gtk_tree_set_row_drag_data (selection_data,
6838 gtk_tree_path_free (source_row);
6842 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6843 GdkDragContext *context)
6845 GtkTreeModel *model;
6846 GtkIconView *icon_view;
6847 GtkTreePath *source_row;
6849 icon_view = GTK_ICON_VIEW (widget);
6850 model = gtk_icon_view_get_model (icon_view);
6852 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6855 if (!icon_view->priv->source_set)
6858 source_row = get_source_row (context);
6860 if (source_row == NULL)
6863 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6866 gtk_tree_path_free (source_row);
6868 set_source_row (context, NULL, NULL);
6871 /* Target side drag signals */
6873 gtk_icon_view_drag_leave (GtkWidget *widget,
6874 GdkDragContext *context,
6877 GtkIconView *icon_view;
6879 icon_view = GTK_ICON_VIEW (widget);
6881 /* unset any highlight row */
6882 gtk_icon_view_set_drag_dest_item (icon_view,
6884 GTK_ICON_VIEW_DROP_LEFT);
6886 remove_scroll_timeout (icon_view);
6890 gtk_icon_view_drag_motion (GtkWidget *widget,
6891 GdkDragContext *context,
6896 GtkTreePath *path = NULL;
6897 GtkIconViewDropPosition pos;
6898 GtkIconView *icon_view;
6899 GdkDragAction suggested_action = 0;
6903 icon_view = GTK_ICON_VIEW (widget);
6905 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6908 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6910 /* we only know this *after* set_desination_row */
6911 empty = icon_view->priv->empty_view_drop;
6913 if (path == NULL && !empty)
6915 /* Can't drop here. */
6916 gdk_drag_status (context, 0, time);
6920 if (icon_view->priv->scroll_timeout_id == 0)
6922 icon_view->priv->scroll_timeout_id =
6923 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6926 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6928 /* Request data so we can use the source row when
6929 * determining whether to accept the drop
6931 set_status_pending (context, suggested_action);
6932 gtk_drag_get_data (widget, context, target, time);
6936 set_status_pending (context, 0);
6937 gdk_drag_status (context, suggested_action, time);
6942 gtk_tree_path_free (path);
6948 gtk_icon_view_drag_drop (GtkWidget *widget,
6949 GdkDragContext *context,
6954 GtkIconView *icon_view;
6956 GdkDragAction suggested_action = 0;
6957 GdkAtom target = GDK_NONE;
6958 GtkTreeModel *model;
6959 gboolean drop_append_mode;
6961 icon_view = GTK_ICON_VIEW (widget);
6962 model = gtk_icon_view_get_model (icon_view);
6964 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6966 if (!icon_view->priv->dest_set)
6969 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6972 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6975 path = get_logical_destination (icon_view, &drop_append_mode);
6977 if (target != GDK_NONE && path != NULL)
6979 /* in case a motion had requested drag data, change things so we
6980 * treat drag data receives as a drop.
6982 set_status_pending (context, 0);
6983 set_dest_row (context, model, path,
6984 icon_view->priv->empty_view_drop, drop_append_mode);
6988 gtk_tree_path_free (path);
6990 /* Unset this thing */
6991 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6993 if (target != GDK_NONE)
6995 gtk_drag_get_data (widget, context, target, time);
7003 gtk_icon_view_drag_data_received (GtkWidget *widget,
7004 GdkDragContext *context,
7007 GtkSelectionData *selection_data,
7012 gboolean accepted = FALSE;
7013 GtkTreeModel *model;
7014 GtkIconView *icon_view;
7015 GtkTreePath *dest_row;
7016 GdkDragAction suggested_action;
7017 gboolean drop_append_mode;
7019 icon_view = GTK_ICON_VIEW (widget);
7020 model = gtk_icon_view_get_model (icon_view);
7022 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7025 if (!icon_view->priv->dest_set)
7028 suggested_action = get_status_pending (context);
7030 if (suggested_action)
7032 /* We are getting this data due to a request in drag_motion,
7033 * rather than due to a request in drag_drop, so we are just
7034 * supposed to call drag_status, not actually paste in the
7037 path = get_logical_destination (icon_view, &drop_append_mode);
7040 suggested_action = 0;
7042 if (suggested_action)
7044 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7047 suggested_action = 0;
7050 gdk_drag_status (context, suggested_action, time);
7053 gtk_tree_path_free (path);
7055 /* If you can't drop, remove user drop indicator until the next motion */
7056 if (suggested_action == 0)
7057 gtk_icon_view_set_drag_dest_item (icon_view,
7059 GTK_ICON_VIEW_DROP_LEFT);
7064 dest_row = get_dest_row (context);
7066 if (dest_row == NULL)
7069 if (selection_data->length >= 0)
7071 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7077 gtk_drag_finish (context,
7079 (context->action == GDK_ACTION_MOVE),
7082 gtk_tree_path_free (dest_row);
7085 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7088 /* Drag-and-Drop support */
7090 * gtk_icon_view_enable_model_drag_source:
7091 * @icon_view: a #GtkIconTreeView
7092 * @start_button_mask: Mask of allowed buttons to start drag
7093 * @targets: the table of targets that the drag will support
7094 * @n_targets: the number of items in @targets
7095 * @actions: the bitmask of possible actions for a drag from this
7098 * Turns @icon_view into a drag source for automatic DND. Calling this
7099 * method sets #GtkIconView:reorderable to %FALSE.
7104 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7105 GdkModifierType start_button_mask,
7106 const GtkTargetEntry *targets,
7108 GdkDragAction actions)
7110 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7112 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7114 icon_view->priv->start_button_mask = start_button_mask;
7115 icon_view->priv->source_actions = actions;
7117 icon_view->priv->source_set = TRUE;
7119 unset_reorderable (icon_view);
7123 * gtk_icon_view_enable_model_drag_dest:
7124 * @icon_view: a #GtkIconView
7125 * @targets: the table of targets that the drag will support
7126 * @n_targets: the number of items in @targets
7127 * @actions: the bitmask of possible actions for a drag to this
7130 * Turns @icon_view into a drop destination for automatic DND. Calling this
7131 * method sets #GtkIconView:reorderable to %FALSE.
7136 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7137 const GtkTargetEntry *targets,
7139 GdkDragAction actions)
7141 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7143 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7145 icon_view->priv->dest_actions = actions;
7147 icon_view->priv->dest_set = TRUE;
7149 unset_reorderable (icon_view);
7153 * gtk_icon_view_unset_model_drag_source:
7154 * @icon_view: a #GtkIconView
7156 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7157 * method sets #GtkIconView:reorderable to %FALSE.
7162 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7164 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7166 if (icon_view->priv->source_set)
7168 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7169 icon_view->priv->source_set = FALSE;
7172 unset_reorderable (icon_view);
7176 * gtk_icon_view_unset_model_drag_dest:
7177 * @icon_view: a #GtkIconView
7179 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7180 * method sets #GtkIconView:reorderable to %FALSE.
7185 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7187 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7189 if (icon_view->priv->dest_set)
7191 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7192 icon_view->priv->dest_set = FALSE;
7195 unset_reorderable (icon_view);
7198 /* These are useful to implement your own custom stuff. */
7200 * gtk_icon_view_set_drag_dest_item:
7201 * @icon_view: a #GtkIconView
7202 * @path: The path of the item to highlight, or %NULL.
7203 * @pos: Specifies where to drop, relative to the item
7205 * Sets the item that is highlighted for feedback.
7210 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7212 GtkIconViewDropPosition pos)
7214 /* Note; this function is exported to allow a custom DND
7215 * implementation, so it can't touch TreeViewDragInfo
7218 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7220 if (icon_view->priv->dest_item)
7222 GtkTreePath *current_path;
7223 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7224 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7225 icon_view->priv->dest_item = NULL;
7227 gtk_icon_view_queue_draw_path (icon_view, current_path);
7228 gtk_tree_path_free (current_path);
7231 /* special case a drop on an empty model */
7232 icon_view->priv->empty_view_drop = FALSE;
7233 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7234 && gtk_tree_path_get_depth (path) == 1
7235 && gtk_tree_path_get_indices (path)[0] == 0)
7239 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7242 if (n_children == 0)
7243 icon_view->priv->empty_view_drop = TRUE;
7246 icon_view->priv->dest_pos = pos;
7250 icon_view->priv->dest_item =
7251 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7252 icon_view->priv->model, path);
7254 gtk_icon_view_queue_draw_path (icon_view, path);
7259 * gtk_icon_view_get_drag_dest_item:
7260 * @icon_view: a #GtkIconView
7261 * @path: Return location for the path of the highlighted item, or %NULL.
7262 * @pos: Return location for the drop position, or %NULL
7264 * Gets information about the item that is highlighted for feedback.
7269 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7271 GtkIconViewDropPosition *pos)
7273 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7277 if (icon_view->priv->dest_item)
7278 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7284 *pos = icon_view->priv->dest_pos;
7288 * gtk_icon_view_get_dest_item_at_pos:
7289 * @icon_view: a #GtkIconView
7290 * @drag_x: the position to determine the destination item for
7291 * @drag_y: the position to determine the destination item for
7292 * @path: Return location for the path of the item, or %NULL.
7293 * @pos: Return location for the drop position, or %NULL
7295 * Determines the destination item for a given position.
7297 * Return value: whether there is an item at the given position.
7302 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7306 GtkIconViewDropPosition *pos)
7308 GtkIconViewItem *item;
7310 /* Note; this function is exported to allow a custom DND
7311 * implementation, so it can't touch TreeViewDragInfo
7314 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7315 g_return_val_if_fail (drag_x >= 0, FALSE);
7316 g_return_val_if_fail (drag_y >= 0, FALSE);
7317 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7323 item = gtk_icon_view_get_item_at_coords (icon_view,
7324 drag_x + icon_view->priv->hadjustment->value,
7325 drag_y + icon_view->priv->vadjustment->value,
7332 *path = gtk_tree_path_new_from_indices (item->index, -1);
7336 if (drag_x < item->x + item->width / 4)
7337 *pos = GTK_ICON_VIEW_DROP_LEFT;
7338 else if (drag_x > item->x + item->width * 3 / 4)
7339 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7340 else if (drag_y < item->y + item->height / 4)
7341 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7342 else if (drag_y > item->y + item->height * 3 / 4)
7343 *pos = GTK_ICON_VIEW_DROP_BELOW;
7345 *pos = GTK_ICON_VIEW_DROP_INTO;
7352 * gtk_icon_view_create_drag_icon:
7353 * @icon_view: a #GtkIconView
7354 * @path: a #GtkTreePath in @icon_view
7356 * Creates a #GdkPixmap representation of the item at @path.
7357 * This image is used for a drag icon.
7359 * Return value: a newly-allocated pixmap of the drag icon.
7364 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7369 GdkPixmap *drawable;
7374 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7375 g_return_val_if_fail (path != NULL, NULL);
7377 widget = GTK_WIDGET (icon_view);
7379 if (!GTK_WIDGET_REALIZED (widget))
7382 index = gtk_tree_path_get_indices (path)[0];
7384 for (l = icon_view->priv->items; l; l = l->next)
7386 GtkIconViewItem *item = l->data;
7388 if (index == item->index)
7390 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7395 cr = gdk_cairo_create (drawable);
7396 cairo_set_line_width (cr, 1.);
7398 gdk_cairo_set_source_color
7399 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7400 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7405 area.width = item->width;
7406 area.height = item->height;
7408 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7409 drawable, 1, 1, FALSE);
7411 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7412 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7425 * gtk_icon_view_get_reorderable:
7426 * @icon_view: a #GtkIconView
7428 * Retrieves whether the user can reorder the list via drag-and-drop.
7429 * See gtk_icon_view_set_reorderable().
7431 * Return value: %TRUE if the list can be reordered.
7436 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7438 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7440 return icon_view->priv->reorderable;
7443 static const GtkTargetEntry item_targets[] = {
7444 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7449 * gtk_icon_view_set_reorderable:
7450 * @icon_view: A #GtkIconView.
7451 * @reorderable: %TRUE, if the list of items can be reordered.
7453 * This function is a convenience function to allow you to reorder models that
7454 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7455 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7456 * the user can reorder the model by dragging and dropping rows. The
7457 * developer can listen to these changes by connecting to the model's
7458 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7459 * the icon view as a drag source and destination. Therefore, drag and
7460 * drop can not be used in a reorderable view for any other purpose.
7462 * This function does not give you any degree of control over the order -- any
7463 * reordering is allowed. If more control is needed, you should probably
7464 * handle drag and drop manually.
7469 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7470 gboolean reorderable)
7472 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7474 reorderable = reorderable != FALSE;
7476 if (icon_view->priv->reorderable == reorderable)
7481 gtk_icon_view_enable_model_drag_source (icon_view,
7484 G_N_ELEMENTS (item_targets),
7486 gtk_icon_view_enable_model_drag_dest (icon_view,
7488 G_N_ELEMENTS (item_targets),
7493 gtk_icon_view_unset_model_drag_source (icon_view);
7494 gtk_icon_view_unset_model_drag_dest (icon_view);
7497 icon_view->priv->reorderable = reorderable;
7499 g_object_notify (G_OBJECT (icon_view), "reorderable");
7503 /* Accessibility Support */
7505 static gpointer accessible_parent_class;
7506 static gpointer accessible_item_parent_class;
7507 static GQuark accessible_private_data_quark = 0;
7509 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7510 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7511 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7513 static GType gtk_icon_view_item_accessible_get_type (void);
7524 GtkIconViewItem *item;
7528 AtkStateSet *state_set;
7532 GtkTextBuffer *text_buffer;
7534 gchar *action_descriptions[LAST_ACTION];
7535 gchar *image_description;
7536 guint action_idle_handler;
7537 } GtkIconViewItemAccessible;
7539 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7545 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7550 typedef struct _GtkIconViewItemAccessibleClass
7552 AtkObjectClass parent_class;
7554 } GtkIconViewItemAccessibleClass;
7556 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7559 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7561 GtkIconViewItemAccessible *item;
7562 GtkIconView *icon_view;
7565 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7566 item->action_idle_handler = 0;
7568 if (item->widget != NULL)
7570 icon_view = GTK_ICON_VIEW (item->widget);
7571 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7572 gtk_icon_view_item_activated (icon_view, path);
7573 gtk_tree_path_free (path);
7580 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7583 GtkIconViewItemAccessible *item;
7585 if (i < 0 || i >= LAST_ACTION)
7588 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7590 if (!GTK_IS_ICON_VIEW (item->widget))
7593 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7598 case ACTION_ACTIVATE:
7599 if (!item->action_idle_handler)
7600 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7603 g_assert_not_reached ();
7611 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7616 static const gchar *
7617 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7620 GtkIconViewItemAccessible *item;
7622 if (i < 0 || i >= LAST_ACTION)
7625 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7627 if (item->action_descriptions[i])
7628 return item->action_descriptions[i];
7630 return gtk_icon_view_item_accessible_action_descriptions[i];
7633 static const gchar *
7634 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7637 if (i < 0 || i >= LAST_ACTION)
7640 return gtk_icon_view_item_accessible_action_names[i];
7644 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7646 const gchar *description)
7648 GtkIconViewItemAccessible *item;
7650 if (i < 0 || i >= LAST_ACTION)
7653 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7655 g_free (item->action_descriptions[i]);
7657 item->action_descriptions[i] = g_strdup (description);
7663 atk_action_item_interface_init (AtkActionIface *iface)
7665 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7666 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7667 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7668 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7669 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7672 static const gchar *
7673 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7675 GtkIconViewItemAccessible *item;
7677 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7679 return item->image_description;
7683 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7684 const gchar *description)
7686 GtkIconViewItemAccessible *item;
7688 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7690 g_free (item->image_description);
7691 item->image_description = g_strdup (description);
7697 get_pixbuf_box (GtkIconView *icon_view,
7698 GtkIconViewItem *item,
7703 for (l = icon_view->priv->cell_list; l; l = l->next)
7705 GtkIconViewCellInfo *info = l->data;
7707 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7709 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7719 get_text (GtkIconView *icon_view,
7720 GtkIconViewItem *item)
7725 for (l = icon_view->priv->cell_list; l; l = l->next)
7727 GtkIconViewCellInfo *info = l->data;
7729 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7731 g_object_get (info->cell, "text", &text, NULL);
7741 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7745 GtkIconViewItemAccessible *item;
7748 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7750 if (!GTK_IS_ICON_VIEW (item->widget))
7753 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7756 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7759 *height = box.height;
7764 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7767 AtkCoordType coord_type)
7769 GtkIconViewItemAccessible *item;
7772 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7774 if (!GTK_IS_ICON_VIEW (item->widget))
7777 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7780 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7782 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7784 *x+= box.x - item->item->x;
7785 *y+= box.y - item->item->y;
7791 atk_image_item_interface_init (AtkImageIface *iface)
7793 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7794 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7795 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7796 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7800 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7804 GtkIconViewItemAccessible *item;
7805 GtkTextIter start, end;
7806 GtkTextBuffer *buffer;
7808 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7810 if (!GTK_IS_ICON_VIEW (item->widget))
7813 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7816 buffer = item->text_buffer;
7817 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7819 gtk_text_buffer_get_end_iter (buffer, &end);
7821 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7823 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7827 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7830 GtkIconViewItemAccessible *item;
7831 GtkTextIter start, end;
7832 GtkTextBuffer *buffer;
7836 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7838 if (!GTK_IS_ICON_VIEW (item->widget))
7841 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7844 buffer = item->text_buffer;
7845 if (offset >= gtk_text_buffer_get_char_count (buffer))
7848 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7850 gtk_text_iter_forward_char (&end);
7851 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7852 unichar = g_utf8_get_char (string);
7860 get_pango_text_offsets (PangoLayout *layout,
7861 GtkTextBuffer *buffer,
7863 AtkTextBoundary boundary_type,
7867 GtkTextIter *start_iter,
7868 GtkTextIter *end_iter)
7870 PangoLayoutIter *iter;
7871 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7872 gint index, start_index, end_index;
7874 gboolean found = FALSE;
7876 text = pango_layout_get_text (layout);
7877 index = g_utf8_offset_to_pointer (text, offset) - text;
7878 iter = pango_layout_get_iter (layout);
7881 line = pango_layout_iter_get_line_readonly (iter);
7882 start_index = line->start_index;
7883 end_index = start_index + line->length;
7885 if (index >= start_index && index <= end_index)
7888 * Found line for offset
7894 * We want the previous line
7898 switch (boundary_type)
7900 case ATK_TEXT_BOUNDARY_LINE_START:
7901 end_index = start_index;
7902 start_index = prev_line->start_index;
7904 case ATK_TEXT_BOUNDARY_LINE_END:
7906 start_index = prev_prev_line->start_index +
7907 prev_prev_line->length;
7908 end_index = prev_line->start_index + prev_line->length;
7911 g_assert_not_reached();
7915 start_index = end_index = 0;
7918 switch (boundary_type)
7920 case ATK_TEXT_BOUNDARY_LINE_START:
7921 if (pango_layout_iter_next_line (iter))
7922 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7924 case ATK_TEXT_BOUNDARY_LINE_END:
7926 start_index = prev_line->start_index +
7930 g_assert_not_reached();
7935 * We want the next line
7937 if (pango_layout_iter_next_line (iter))
7939 line = pango_layout_iter_get_line_readonly (iter);
7940 switch (boundary_type)
7942 case ATK_TEXT_BOUNDARY_LINE_START:
7943 start_index = line->start_index;
7944 if (pango_layout_iter_next_line (iter))
7945 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7947 end_index = start_index + line->length;
7949 case ATK_TEXT_BOUNDARY_LINE_END:
7950 start_index = end_index;
7951 end_index = line->start_index + line->length;
7954 g_assert_not_reached();
7958 start_index = end_index;
7964 prev_prev_line = prev_line;
7967 while (pango_layout_iter_next_line (iter));
7971 start_index = prev_line->start_index + prev_line->length;
7972 end_index = start_index;
7974 pango_layout_iter_free (iter);
7975 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7976 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7978 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7979 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7984 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7986 AtkTextBoundary boundary_type,
7990 GtkIconViewItemAccessible *item;
7991 GtkTextIter start, end;
7992 GtkTextBuffer *buffer;
7994 GtkIconView *icon_view;
7997 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7999 if (!GTK_IS_ICON_VIEW (item->widget))
8002 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8005 buffer = item->text_buffer;
8007 if (!gtk_text_buffer_get_char_count (buffer))
8011 return g_strdup ("");
8013 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8017 switch (boundary_type)
8019 case ATK_TEXT_BOUNDARY_CHAR:
8020 gtk_text_iter_backward_char(&start);
8022 case ATK_TEXT_BOUNDARY_WORD_START:
8023 if (!gtk_text_iter_starts_word (&start))
8024 gtk_text_iter_backward_word_start (&start);
8026 gtk_text_iter_backward_word_start(&start);
8028 case ATK_TEXT_BOUNDARY_WORD_END:
8029 if (gtk_text_iter_inside_word (&start) &&
8030 !gtk_text_iter_starts_word (&start))
8031 gtk_text_iter_backward_word_start (&start);
8032 while (!gtk_text_iter_ends_word (&start))
8034 if (!gtk_text_iter_backward_char (&start))
8038 gtk_text_iter_backward_word_start(&start);
8039 while (!gtk_text_iter_ends_word (&start))
8041 if (!gtk_text_iter_backward_char (&start))
8045 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8046 if (!gtk_text_iter_starts_sentence (&start))
8047 gtk_text_iter_backward_sentence_start (&start);
8049 gtk_text_iter_backward_sentence_start (&start);
8051 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8052 if (gtk_text_iter_inside_sentence (&start) &&
8053 !gtk_text_iter_starts_sentence (&start))
8054 gtk_text_iter_backward_sentence_start (&start);
8055 while (!gtk_text_iter_ends_sentence (&start))
8057 if (!gtk_text_iter_backward_char (&start))
8061 gtk_text_iter_backward_sentence_start (&start);
8062 while (!gtk_text_iter_ends_sentence (&start))
8064 if (!gtk_text_iter_backward_char (&start))
8068 case ATK_TEXT_BOUNDARY_LINE_START:
8069 case ATK_TEXT_BOUNDARY_LINE_END:
8071 icon_view = GTK_ICON_VIEW (item->widget);
8072 /* FIXME we probably have to use GailTextCell to salvage this */
8073 gtk_icon_view_update_item_text (icon_view, item->item);
8074 get_pango_text_offsets (icon_view->priv->layout,
8087 *start_offset = gtk_text_iter_get_offset (&start);
8088 *end_offset = gtk_text_iter_get_offset (&end);
8090 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8094 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8096 AtkTextBoundary boundary_type,
8100 GtkIconViewItemAccessible *item;
8101 GtkTextIter start, end;
8102 GtkTextBuffer *buffer;
8104 GtkIconView *icon_view;
8107 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8109 if (!GTK_IS_ICON_VIEW (item->widget))
8112 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8115 buffer = item->text_buffer;
8117 if (!gtk_text_buffer_get_char_count (buffer))
8121 return g_strdup ("");
8123 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8127 switch (boundary_type)
8129 case ATK_TEXT_BOUNDARY_CHAR:
8130 gtk_text_iter_forward_char (&end);
8132 case ATK_TEXT_BOUNDARY_WORD_START:
8133 if (!gtk_text_iter_starts_word (&start))
8134 gtk_text_iter_backward_word_start (&start);
8135 if (gtk_text_iter_inside_word (&end))
8136 gtk_text_iter_forward_word_end (&end);
8137 while (!gtk_text_iter_starts_word (&end))
8139 if (!gtk_text_iter_forward_char (&end))
8143 case ATK_TEXT_BOUNDARY_WORD_END:
8144 if (gtk_text_iter_inside_word (&start) &&
8145 !gtk_text_iter_starts_word (&start))
8146 gtk_text_iter_backward_word_start (&start);
8147 while (!gtk_text_iter_ends_word (&start))
8149 if (!gtk_text_iter_backward_char (&start))
8152 gtk_text_iter_forward_word_end (&end);
8154 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8155 if (!gtk_text_iter_starts_sentence (&start))
8156 gtk_text_iter_backward_sentence_start (&start);
8157 if (gtk_text_iter_inside_sentence (&end))
8158 gtk_text_iter_forward_sentence_end (&end);
8159 while (!gtk_text_iter_starts_sentence (&end))
8161 if (!gtk_text_iter_forward_char (&end))
8165 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8166 if (gtk_text_iter_inside_sentence (&start) &&
8167 !gtk_text_iter_starts_sentence (&start))
8168 gtk_text_iter_backward_sentence_start (&start);
8169 while (!gtk_text_iter_ends_sentence (&start))
8171 if (!gtk_text_iter_backward_char (&start))
8174 gtk_text_iter_forward_sentence_end (&end);
8176 case ATK_TEXT_BOUNDARY_LINE_START:
8177 case ATK_TEXT_BOUNDARY_LINE_END:
8179 icon_view = GTK_ICON_VIEW (item->widget);
8180 /* FIXME we probably have to use GailTextCell to salvage this */
8181 gtk_icon_view_update_item_text (icon_view, item->item);
8182 get_pango_text_offsets (icon_view->priv->layout,
8196 *start_offset = gtk_text_iter_get_offset (&start);
8197 *end_offset = gtk_text_iter_get_offset (&end);
8199 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8203 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8205 AtkTextBoundary boundary_type,
8209 GtkIconViewItemAccessible *item;
8210 GtkTextIter start, end;
8211 GtkTextBuffer *buffer;
8213 GtkIconView *icon_view;
8216 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8218 if (!GTK_IS_ICON_VIEW (item->widget))
8221 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8224 buffer = item->text_buffer;
8226 if (!gtk_text_buffer_get_char_count (buffer))
8230 return g_strdup ("");
8232 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8236 switch (boundary_type)
8238 case ATK_TEXT_BOUNDARY_CHAR:
8239 gtk_text_iter_forward_char(&start);
8240 gtk_text_iter_forward_chars(&end, 2);
8242 case ATK_TEXT_BOUNDARY_WORD_START:
8243 if (gtk_text_iter_inside_word (&end))
8244 gtk_text_iter_forward_word_end (&end);
8245 while (!gtk_text_iter_starts_word (&end))
8247 if (!gtk_text_iter_forward_char (&end))
8251 if (!gtk_text_iter_is_end (&end))
8253 gtk_text_iter_forward_word_end (&end);
8254 while (!gtk_text_iter_starts_word (&end))
8256 if (!gtk_text_iter_forward_char (&end))
8261 case ATK_TEXT_BOUNDARY_WORD_END:
8262 gtk_text_iter_forward_word_end (&end);
8264 if (!gtk_text_iter_is_end (&end))
8265 gtk_text_iter_forward_word_end (&end);
8267 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8268 if (gtk_text_iter_inside_sentence (&end))
8269 gtk_text_iter_forward_sentence_end (&end);
8270 while (!gtk_text_iter_starts_sentence (&end))
8272 if (!gtk_text_iter_forward_char (&end))
8276 if (!gtk_text_iter_is_end (&end))
8278 gtk_text_iter_forward_sentence_end (&end);
8279 while (!gtk_text_iter_starts_sentence (&end))
8281 if (!gtk_text_iter_forward_char (&end))
8286 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8287 gtk_text_iter_forward_sentence_end (&end);
8289 if (!gtk_text_iter_is_end (&end))
8290 gtk_text_iter_forward_sentence_end (&end);
8292 case ATK_TEXT_BOUNDARY_LINE_START:
8293 case ATK_TEXT_BOUNDARY_LINE_END:
8295 icon_view = GTK_ICON_VIEW (item->widget);
8296 /* FIXME we probably have to use GailTextCell to salvage this */
8297 gtk_icon_view_update_item_text (icon_view, item->item);
8298 get_pango_text_offsets (icon_view->priv->layout,
8310 *start_offset = gtk_text_iter_get_offset (&start);
8311 *end_offset = gtk_text_iter_get_offset (&end);
8313 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8317 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8319 GtkIconViewItemAccessible *item;
8321 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8323 if (!GTK_IS_ICON_VIEW (item->widget))
8326 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8329 return gtk_text_buffer_get_char_count (item->text_buffer);
8333 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8339 AtkCoordType coord_type)
8341 GtkIconViewItemAccessible *item;
8343 GtkIconView *icon_view;
8344 PangoRectangle char_rect;
8345 const gchar *item_text;
8349 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8351 if (!GTK_IS_ICON_VIEW (item->widget))
8354 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8358 icon_view = GTK_ICON_VIEW (item->widget);
8359 /* FIXME we probably have to use GailTextCell to salvage this */
8360 gtk_icon_view_update_item_text (icon_view, item->item);
8361 item_text = pango_layout_get_text (icon_view->priv->layout);
8362 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8363 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8365 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8366 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8367 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8368 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8369 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8370 *width = char_rect.width / PANGO_SCALE;
8371 *height = char_rect.height / PANGO_SCALE;
8376 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8379 AtkCoordType coord_type)
8381 GtkIconViewItemAccessible *item;
8384 GtkIconView *icon_view;
8385 const gchar *item_text;
8390 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8392 if (!GTK_IS_ICON_VIEW (item->widget))
8395 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8399 icon_view = GTK_ICON_VIEW (item->widget);
8400 /* FIXME we probably have to use GailTextCell to salvage this */
8401 gtk_icon_view_update_item_text (icon_view, item->item);
8402 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8403 x -= l_x + item->item->layout_x - item->item->x;
8404 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8405 y -= l_y + item->item->layout_y - item->item->y;
8406 item_text = pango_layout_get_text (icon_view->priv->layout);
8407 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8418 offset = g_utf8_strlen (item_text, -1);
8420 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8426 atk_text_item_interface_init (AtkTextIface *iface)
8428 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8429 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8430 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8431 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8432 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8433 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8434 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8435 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8439 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8444 AtkCoordType coord_type)
8446 GtkIconViewItemAccessible *item;
8447 AtkObject *parent_obj;
8450 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8452 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8453 if (!GTK_IS_WIDGET (item->widget))
8456 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8459 *width = item->item->width;
8460 *height = item->item->height;
8461 if (gtk_icon_view_item_accessible_is_showing (item))
8463 parent_obj = gtk_widget_get_accessible (item->widget);
8464 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8465 *x = l_x + item->item->x;
8466 *y = l_y + item->item->y;
8476 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8478 GtkIconViewItemAccessible *item;
8479 GtkWidget *toplevel;
8481 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8483 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8484 if (!GTK_IS_WIDGET (item->widget))
8487 gtk_widget_grab_focus (item->widget);
8488 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8489 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8490 if (GTK_WIDGET_TOPLEVEL (toplevel))
8491 gtk_window_present (GTK_WINDOW (toplevel));
8497 atk_component_item_interface_init (AtkComponentIface *iface)
8499 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8500 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8504 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8505 AtkStateType state_type,
8506 gboolean emit_signal)
8510 rc = atk_state_set_add_state (item->state_set, state_type);
8512 * The signal should only be generated if the value changed,
8513 * not when the item is set up. So states that are set
8514 * initially should pass FALSE as the emit_signal argument.
8519 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8520 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8521 if (state_type == ATK_STATE_VISIBLE)
8522 g_signal_emit_by_name (item, "visible-data-changed");
8529 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8530 AtkStateType state_type,
8531 gboolean emit_signal)
8533 if (atk_state_set_contains_state (item->state_set, state_type))
8537 rc = atk_state_set_remove_state (item->state_set, state_type);
8539 * The signal should only be generated if the value changed,
8540 * not when the item is set up. So states that are set
8541 * initially should pass FALSE as the emit_signal argument.
8546 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8547 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8548 if (state_type == ATK_STATE_VISIBLE)
8549 g_signal_emit_by_name (item, "visible-data-changed");
8559 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8561 GtkIconView *icon_view;
8562 GdkRectangle visible_rect;
8563 gboolean is_showing;
8566 * An item is considered "SHOWING" if any part of the item is in the
8567 * visible rectangle.
8570 if (!GTK_IS_ICON_VIEW (item->widget))
8573 if (item->item == NULL)
8576 icon_view = GTK_ICON_VIEW (item->widget);
8578 if (icon_view->priv->hadjustment)
8579 visible_rect.x += icon_view->priv->hadjustment->value;
8581 if (icon_view->priv->hadjustment)
8582 visible_rect.y += icon_view->priv->vadjustment->value;
8583 visible_rect.width = item->widget->allocation.width;
8584 visible_rect.height = item->widget->allocation.height;
8586 if (((item->item->x + item->item->width) < visible_rect.x) ||
8587 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8588 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8589 (item->item->y > (visible_rect.y + visible_rect.height)))
8598 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8599 gboolean emit_signal)
8601 if (gtk_icon_view_item_accessible_is_showing (item))
8602 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8605 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8610 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8614 item->state_set = atk_state_set_new ();
8616 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8617 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8618 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8619 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8620 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8622 for (i = 0; i < LAST_ACTION; i++)
8623 item->action_descriptions[i] = NULL;
8625 item->image_description = NULL;
8627 item->action_idle_handler = 0;
8631 gtk_icon_view_item_accessible_finalize (GObject *object)
8633 GtkIconViewItemAccessible *item;
8636 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8638 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8641 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8643 if (item->state_set)
8644 g_object_unref (item->state_set);
8646 if (item->text_buffer)
8647 g_object_unref (item->text_buffer);
8649 for (i = 0; i < LAST_ACTION; i++)
8650 g_free (item->action_descriptions[i]);
8652 g_free (item->image_description);
8654 if (item->action_idle_handler)
8656 g_source_remove (item->action_idle_handler);
8657 item->action_idle_handler = 0;
8660 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8663 static G_CONST_RETURN gchar*
8664 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8670 GtkIconViewItemAccessible *item;
8671 GtkTextIter start_iter;
8672 GtkTextIter end_iter;
8674 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8676 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8677 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8679 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8684 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8686 GtkIconViewItemAccessible *item;
8688 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8689 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8692 return gtk_widget_get_accessible (item->widget);
8698 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8700 GtkIconViewItemAccessible *item;
8702 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8703 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8705 return item->item->index;
8708 static AtkStateSet *
8709 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8711 GtkIconViewItemAccessible *item;
8712 GtkIconView *icon_view;
8714 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8715 g_return_val_if_fail (item->state_set, NULL);
8720 icon_view = GTK_ICON_VIEW (item->widget);
8721 if (icon_view->priv->cursor_item == item->item)
8722 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8724 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8725 if (item->item->selected)
8726 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8728 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8730 return g_object_ref (item->state_set);
8734 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8736 GObjectClass *gobject_class;
8738 accessible_item_parent_class = g_type_class_peek_parent (klass);
8740 gobject_class = (GObjectClass *)klass;
8742 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8744 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8745 klass->get_name = gtk_icon_view_item_accessible_get_name;
8746 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8747 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8751 gtk_icon_view_item_accessible_get_type (void)
8753 static GType type = 0;
8757 const GTypeInfo tinfo =
8759 sizeof (GtkIconViewItemAccessibleClass),
8760 (GBaseInitFunc) NULL, /* base init */
8761 (GBaseFinalizeFunc) NULL, /* base finalize */
8762 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8763 (GClassFinalizeFunc) NULL, /* class finalize */
8764 NULL, /* class data */
8765 sizeof (GtkIconViewItemAccessible), /* instance size */
8766 0, /* nb preallocs */
8767 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8768 NULL /* value table */
8771 const GInterfaceInfo atk_component_info =
8773 (GInterfaceInitFunc) atk_component_item_interface_init,
8774 (GInterfaceFinalizeFunc) NULL,
8777 const GInterfaceInfo atk_action_info =
8779 (GInterfaceInitFunc) atk_action_item_interface_init,
8780 (GInterfaceFinalizeFunc) NULL,
8783 const GInterfaceInfo atk_image_info =
8785 (GInterfaceInitFunc) atk_image_item_interface_init,
8786 (GInterfaceFinalizeFunc) NULL,
8789 const GInterfaceInfo atk_text_info =
8791 (GInterfaceInitFunc) atk_text_item_interface_init,
8792 (GInterfaceFinalizeFunc) NULL,
8796 type = g_type_register_static (ATK_TYPE_OBJECT,
8797 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8798 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8799 &atk_component_info);
8800 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8802 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8804 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8811 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8812 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8813 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8815 static GType gtk_icon_view_accessible_get_type (void);
8820 } GtkIconViewAccessible;
8826 } GtkIconViewItemAccessibleInfo;
8832 GtkAdjustment *old_hadj;
8833 GtkAdjustment *old_vadj;
8835 GtkTreeModel *model;
8837 } GtkIconViewAccessiblePrivate;
8839 static GtkIconViewAccessiblePrivate *
8840 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8842 return g_object_get_qdata (G_OBJECT (accessible),
8843 accessible_private_data_quark);
8847 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8851 GtkIconViewItemAccessibleInfo *info;
8852 GtkIconViewItemAccessibleInfo *tmp_info;
8853 GtkIconViewAccessiblePrivate *priv;
8856 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8858 info->index = index;
8860 priv = gtk_icon_view_accessible_get_priv (accessible);
8861 items = priv->items;
8864 tmp_info = items->data;
8865 if (tmp_info->index > index)
8867 items = items->next;
8869 priv->items = g_list_insert_before (priv->items, items, info);
8870 priv->old_hadj = NULL;
8871 priv->old_vadj = NULL;
8875 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8877 GtkIconView *icon_view;
8880 widget = GTK_ACCESSIBLE (accessible)->widget;
8884 icon_view = GTK_ICON_VIEW (widget);
8886 return g_list_length (icon_view->priv->items);
8890 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8893 GtkIconViewAccessiblePrivate *priv;
8894 GtkIconViewItemAccessibleInfo *info;
8897 priv = gtk_icon_view_accessible_get_priv (accessible);
8898 items = priv->items;
8903 if (info->index == index)
8905 items = items->next;
8911 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8914 GtkIconView *icon_view;
8918 GtkIconViewItemAccessible *a11y_item;
8920 widget = GTK_ACCESSIBLE (accessible)->widget;
8924 icon_view = GTK_ICON_VIEW (widget);
8925 icons = g_list_nth (icon_view->priv->items, index);
8929 GtkIconViewItem *item = icons->data;
8931 g_return_val_if_fail (item->index == index, NULL);
8932 obj = gtk_icon_view_accessible_find_child (accessible, index);
8937 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8938 gtk_icon_view_item_accessible_info_new (accessible,
8941 obj->role = ATK_ROLE_ICON;
8942 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8943 a11y_item->item = item;
8944 a11y_item->widget = widget;
8945 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8947 gtk_icon_view_set_cell_data (icon_view, item);
8948 text = get_text (icon_view, item);
8951 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8955 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8956 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8964 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8967 GtkIconViewAccessiblePrivate *priv;
8968 GtkIconViewItemAccessibleInfo *info;
8969 GtkIconViewItemAccessible *item;
8972 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8976 gboolean act_on_item;
8978 widget = GTK_ACCESSIBLE (view)->widget;
8982 items = priv->items;
8984 act_on_item = (list == NULL);
8989 info = (GtkIconViewItemAccessibleInfo *)items->data;
8990 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8992 if (act_on_item == FALSE && list == items)
8996 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8998 items = items->next;
9004 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9005 GtkIconView *icon_view)
9008 GtkIconViewAccessible *view;
9011 * The scrollbars have changed
9013 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9014 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9016 gtk_icon_view_accessible_traverse_items (view, NULL);
9020 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9021 GtkAdjustment *hadj,
9022 GtkAdjustment *vadj)
9025 GtkIconViewAccessiblePrivate *priv;
9027 atk_obj = gtk_widget_get_accessible (widget);
9028 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9030 if (priv->old_hadj != hadj)
9034 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9035 (gpointer *)&priv->old_hadj);
9037 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9038 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9041 priv->old_hadj = hadj;
9044 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9045 (gpointer *)&priv->old_hadj);
9046 g_signal_connect (hadj,
9048 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9052 if (priv->old_vadj != vadj)
9056 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9057 (gpointer *)&priv->old_vadj);
9059 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9060 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9063 priv->old_vadj = vadj;
9066 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9067 (gpointer *)&priv->old_vadj);
9068 g_signal_connect (vadj,
9070 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9077 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9085 GtkIconView *icon_view;
9086 GtkIconViewItem *item;
9087 GtkIconViewAccessible *a11y_view;
9088 GtkIconViewItemAccessible *a11y_item;
9092 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9093 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9094 index = gtk_tree_path_get_indices(path)[0];
9095 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9096 gtk_icon_view_accessible_find_child (atk_obj, index));
9100 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9101 icon_view = GTK_ICON_VIEW (widget);
9102 item = a11y_item->item;
9104 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9106 if (!name || strcmp (name, "") == 0)
9108 gtk_icon_view_set_cell_data (icon_view, item);
9109 text = get_text (icon_view, item);
9112 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9118 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9124 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9129 GtkIconViewAccessiblePrivate *priv;
9130 GtkIconViewItemAccessibleInfo *info;
9131 GtkIconViewAccessible *view;
9132 GtkIconViewItemAccessible *item;
9138 index = gtk_tree_path_get_indices(path)[0];
9139 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9140 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9141 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9143 items = priv->items;
9148 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9149 if (info->index != item->item->index)
9151 if (info->index < index)
9152 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9154 if (tmp_list == NULL)
9157 info->index = item->item->index;
9160 items = items->next;
9162 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9163 g_signal_emit_by_name (atk_obj, "children-changed::add",
9169 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9173 GtkIconViewAccessiblePrivate *priv;
9174 GtkIconViewItemAccessibleInfo *info;
9175 GtkIconViewAccessible *view;
9176 GtkIconViewItemAccessible *item;
9179 GList *deleted_item;
9183 index = gtk_tree_path_get_indices(path)[0];
9184 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9185 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9186 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9188 items = priv->items;
9190 deleted_item = NULL;
9195 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9196 if (info->index == index)
9198 deleted_item = items;
9200 if (info->index != item->item->index)
9202 if (tmp_list == NULL)
9205 info->index = item->item->index;
9208 items = items->next;
9210 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9213 info = deleted_item->data;
9214 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9215 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9217 priv->items = g_list_remove_link (priv->items, deleted_item);
9225 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9226 GtkIconViewItemAccessibleInfo *i2)
9228 return i1->index - i2->index;
9232 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9238 GtkIconViewAccessiblePrivate *priv;
9239 GtkIconViewItemAccessibleInfo *info;
9240 GtkIconView *icon_view;
9241 GtkIconViewItemAccessible *item;
9247 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9248 icon_view = GTK_ICON_VIEW (user_data);
9249 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9251 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9253 order = g_new (gint, length);
9254 for (i = 0; i < length; i++)
9255 order [new_order[i]] = i;
9257 items = priv->items;
9261 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9262 info->index = order[info->index];
9263 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9264 items = items->next;
9267 priv->items = g_list_sort (priv->items,
9268 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9274 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9279 obj = G_OBJECT (model);
9280 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9281 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9282 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9283 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9287 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9291 obj = G_OBJECT (icon_view->priv->model);
9292 g_signal_connect_data (obj, "row-changed",
9293 (GCallback) gtk_icon_view_accessible_model_row_changed,
9294 icon_view, NULL, 0);
9295 g_signal_connect_data (obj, "row-inserted",
9296 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9297 icon_view, NULL, G_CONNECT_AFTER);
9298 g_signal_connect_data (obj, "row-deleted",
9299 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9300 icon_view, NULL, G_CONNECT_AFTER);
9301 g_signal_connect_data (obj, "rows-reordered",
9302 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9303 icon_view, NULL, G_CONNECT_AFTER);
9307 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9309 GtkIconViewItemAccessibleInfo *info;
9312 items = priv->items;
9315 info = (GtkIconViewItemAccessibleInfo *) items->data;
9316 g_object_unref (info->item);
9317 g_free (items->data);
9318 items = items->next;
9320 g_list_free (priv->items);
9325 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9328 GtkIconView *icon_view;
9331 GtkIconViewAccessiblePrivate *priv;
9333 if (strcmp (pspec->name, "model") == 0)
9335 widget = GTK_WIDGET (obj);
9336 atk_obj = gtk_widget_get_accessible (widget);
9337 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9340 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9341 (gpointer *)&priv->model);
9342 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9344 gtk_icon_view_accessible_clear_cache (priv);
9346 icon_view = GTK_ICON_VIEW (obj);
9347 priv->model = icon_view->priv->model;
9348 /* If there is no model the GtkIconView is probably being destroyed */
9351 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9352 gtk_icon_view_accessible_connect_model_signals (icon_view);
9360 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9363 GtkIconViewAccessiblePrivate *priv;
9364 GtkIconView *icon_view;
9366 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9367 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9369 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9370 g_object_set_qdata (G_OBJECT (accessible),
9371 accessible_private_data_quark,
9374 icon_view = GTK_ICON_VIEW (data);
9375 if (icon_view->priv->hadjustment)
9377 priv->old_hadj = icon_view->priv->hadjustment;
9378 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9379 g_signal_connect (icon_view->priv->hadjustment,
9381 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9384 if (icon_view->priv->vadjustment)
9386 priv->old_vadj = icon_view->priv->vadjustment;
9387 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9388 g_signal_connect (icon_view->priv->vadjustment,
9390 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9393 g_signal_connect_after (data,
9394 "set-scroll-adjustments",
9395 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9397 g_signal_connect (data,
9399 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9402 priv->model = icon_view->priv->model;
9405 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9406 gtk_icon_view_accessible_connect_model_signals (icon_view);
9409 accessible->role = ATK_ROLE_LAYERED_PANE;
9413 gtk_icon_view_accessible_finalize (GObject *object)
9415 GtkIconViewAccessiblePrivate *priv;
9417 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9418 gtk_icon_view_accessible_clear_cache (priv);
9422 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9426 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9427 GtkAccessible *accessible)
9430 GtkIconViewAccessiblePrivate *priv;
9432 atk_obj = ATK_OBJECT (accessible);
9433 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9436 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9437 (gpointer *)&priv->old_hadj);
9439 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9440 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9442 priv->old_hadj = NULL;
9446 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9447 (gpointer *)&priv->old_vadj);
9449 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9450 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9452 priv->old_vadj = NULL;
9457 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9459 if (accessible->widget)
9461 g_signal_connect_after (accessible->widget,
9463 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9466 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9470 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9472 GObjectClass *gobject_class;
9473 GtkAccessibleClass *accessible_class;
9475 accessible_parent_class = g_type_class_peek_parent (klass);
9477 gobject_class = (GObjectClass *)klass;
9478 accessible_class = (GtkAccessibleClass *)klass;
9480 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9482 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9483 klass->ref_child = gtk_icon_view_accessible_ref_child;
9484 klass->initialize = gtk_icon_view_accessible_initialize;
9486 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9488 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9492 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9495 AtkCoordType coord_type)
9498 GtkIconView *icon_view;
9499 GtkIconViewItem *item;
9502 widget = GTK_ACCESSIBLE (component)->widget;
9504 /* State is defunct */
9507 icon_view = GTK_ICON_VIEW (widget);
9508 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9509 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9511 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9517 atk_component_interface_init (AtkComponentIface *iface)
9519 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9523 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9527 GtkIconView *icon_view;
9528 GtkIconViewItem *item;
9530 widget = GTK_ACCESSIBLE (selection)->widget;
9534 icon_view = GTK_ICON_VIEW (widget);
9536 item = g_list_nth_data (icon_view->priv->items, i);
9541 gtk_icon_view_select_item (icon_view, item);
9547 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9550 GtkIconView *icon_view;
9552 widget = GTK_ACCESSIBLE (selection)->widget;
9556 icon_view = GTK_ICON_VIEW (widget);
9557 gtk_icon_view_unselect_all (icon_view);
9563 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9568 GtkIconView *icon_view;
9569 GtkIconViewItem *item;
9571 widget = GTK_ACCESSIBLE (selection)->widget;
9575 icon_view = GTK_ICON_VIEW (widget);
9577 l = icon_view->priv->items;
9584 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9595 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9598 GtkIconView *icon_view;
9599 GtkIconViewItem *item;
9603 widget = GTK_ACCESSIBLE (selection)->widget;
9607 icon_view = GTK_ICON_VIEW (widget);
9609 l = icon_view->priv->items;
9625 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9629 GtkIconView *icon_view;
9630 GtkIconViewItem *item;
9632 widget = GTK_ACCESSIBLE (selection)->widget;
9636 icon_view = GTK_ICON_VIEW (widget);
9638 item = g_list_nth_data (icon_view->priv->items, i);
9642 return item->selected;
9646 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9650 GtkIconView *icon_view;
9651 GtkIconViewItem *item;
9655 widget = GTK_ACCESSIBLE (selection)->widget;
9659 icon_view = GTK_ICON_VIEW (widget);
9660 l = icon_view->priv->items;
9669 gtk_icon_view_unselect_item (icon_view, item);
9681 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9684 GtkIconView *icon_view;
9686 widget = GTK_ACCESSIBLE (selection)->widget;
9690 icon_view = GTK_ICON_VIEW (widget);
9691 gtk_icon_view_select_all (icon_view);
9696 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9698 iface->add_selection = gtk_icon_view_accessible_add_selection;
9699 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9700 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9701 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9702 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9703 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9704 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9708 gtk_icon_view_accessible_get_type (void)
9710 static GType type = 0;
9717 (GBaseInitFunc) NULL, /* base init */
9718 (GBaseFinalizeFunc) NULL, /* base finalize */
9719 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9720 (GClassFinalizeFunc) NULL, /* class finalize */
9721 NULL, /* class data */
9722 0, /* instance size */
9723 0, /* nb preallocs */
9724 (GInstanceInitFunc) NULL, /* instance init */
9725 NULL /* value table */
9727 const GInterfaceInfo atk_component_info =
9729 (GInterfaceInitFunc) atk_component_interface_init,
9730 (GInterfaceFinalizeFunc) NULL,
9733 const GInterfaceInfo atk_selection_info =
9735 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9736 (GInterfaceFinalizeFunc) NULL,
9741 * Figure out the size of the class and instance
9742 * we are deriving from
9744 AtkObjectFactory *factory;
9747 GType derived_atk_type;
9749 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9750 factory = atk_registry_get_factory (atk_get_default_registry (),
9752 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9753 g_type_query (derived_atk_type, &query);
9754 tinfo.class_size = query.class_size;
9755 tinfo.instance_size = query.instance_size;
9757 type = g_type_register_static (derived_atk_type,
9758 I_("GtkIconViewAccessible"),
9760 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9761 &atk_component_info);
9762 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9763 &atk_selection_info);
9769 gtk_icon_view_accessible_new (GObject *obj)
9771 AtkObject *accessible;
9773 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9775 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9776 atk_object_initialize (accessible, obj);
9782 gtk_icon_view_accessible_factory_get_accessible_type (void)
9784 return gtk_icon_view_accessible_get_type ();
9788 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9790 return gtk_icon_view_accessible_new (obj);
9794 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9796 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9797 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9801 gtk_icon_view_accessible_factory_get_type (void)
9803 static GType type = 0;
9807 const GTypeInfo tinfo =
9809 sizeof (AtkObjectFactoryClass),
9810 NULL, /* base_init */
9811 NULL, /* base_finalize */
9812 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9813 NULL, /* class_finalize */
9814 NULL, /* class_data */
9815 sizeof (AtkObjectFactory),
9816 0, /* n_preallocs */
9820 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9821 I_("GtkIconViewAccessibleFactory"),
9829 gtk_icon_view_get_accessible (GtkWidget *widget)
9831 static gboolean first_time = TRUE;
9835 AtkObjectFactory *factory;
9836 AtkRegistry *registry;
9838 GType derived_atk_type;
9841 * Figure out whether accessibility is enabled by looking at the
9842 * type of the accessible object which would be created for
9843 * the parent type of GtkIconView.
9845 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9847 registry = atk_get_default_registry ();
9848 factory = atk_registry_get_factory (registry,
9850 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9851 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9852 atk_registry_set_factory_type (registry,
9854 gtk_icon_view_accessible_factory_get_type ());
9857 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9861 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9862 GtkBuilder *builder,
9864 const gchar *tagname,
9865 GMarkupParser *parser,
9868 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9869 tagname, parser, data))
9872 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9873 tagname, parser, data);
9877 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9878 GtkBuilder *builder,
9880 const gchar *tagname,
9883 if (strcmp (tagname, "attributes") == 0)
9884 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9887 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9893 #define __GTK_ICON_VIEW_C__
9894 #include "gtkaliasdef.c"