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"
48 * @short_description: A widget which displays a list of icons in a grid
50 * #GtkIconView provides an alternative view on a list model.
51 * It displays the model as a grid of icons with labels. Like
52 * #GtkTreeView, it allows to select one or multiple items
53 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
54 * In addition to selection with the arrow keys, #GtkIconView supports
55 * rubberband selection, which is controlled by dragging the pointer.
58 #define SCROLL_EDGE_SIZE 15
60 typedef struct _GtkIconViewItem GtkIconViewItem;
61 struct _GtkIconViewItem
69 gint x, y, width, height;
72 * box[i] is the actual area occupied by cell i,
73 * before, after are used to calculate the cell
74 * area relative to the box.
75 * See gtk_icon_view_get_cell_area().
83 guint selected_before_rubberbanding : 1;
87 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
88 struct _GtkIconViewCellInfo
90 GtkCellRenderer *cell;
100 GtkCellLayoutDataFunc func;
102 GDestroyNotify destroy;
105 typedef struct _GtkIconViewChild GtkIconViewChild;
106 struct _GtkIconViewChild
109 GtkIconViewItem *item;
113 struct _GtkIconViewPrivate
117 GtkSelectionMode selection_mode;
119 GdkWindow *bin_window;
127 GtkAdjustment *hadjustment;
128 GtkAdjustment *vadjustment;
130 guint layout_idle_id;
132 gboolean doing_rubberband;
133 gint rubberband_x1, rubberband_y1;
134 gint rubberband_x2, rubberband_y2;
135 GdkDevice *rubberband_device;
137 guint scroll_timeout_id;
138 gint scroll_value_diff;
139 gint event_last_x, event_last_y;
141 GtkIconViewItem *anchor_item;
142 GtkIconViewItem *cursor_item;
143 GtkIconViewItem *edited_item;
144 GtkCellEditable *editable;
146 GtkIconViewItem *last_single_clicked;
153 GtkOrientation item_orientation;
173 GdkModifierType start_button_mask;
178 GdkDragAction source_actions;
179 GdkDragAction dest_actions;
181 GtkTreeRowReference *dest_item;
182 GtkIconViewDropPosition dest_pos;
185 GtkTreeRowReference *scroll_to_path;
186 gfloat scroll_to_row_align;
187 gfloat scroll_to_col_align;
188 guint scroll_to_use_align : 1;
190 guint source_set : 1;
192 guint reorderable : 1;
193 guint empty_view_drop :1;
195 guint ctrl_pressed : 1;
196 guint shift_pressed : 1;
198 guint draw_focus : 1;
211 ACTIVATE_CURSOR_ITEM,
223 PROP_ITEM_ORIENTATION,
237 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
238 static void gtk_icon_view_finalize (GObject *object);
239 static void gtk_icon_view_set_property (GObject *object,
243 static void gtk_icon_view_get_property (GObject *object,
248 /* GtkObject vfuncs */
249 static void gtk_icon_view_destroy (GtkObject *object);
251 /* GtkWidget vfuncs */
252 static void gtk_icon_view_realize (GtkWidget *widget);
253 static void gtk_icon_view_unrealize (GtkWidget *widget);
254 static void gtk_icon_view_style_set (GtkWidget *widget,
255 GtkStyle *previous_style);
256 static void gtk_icon_view_state_changed (GtkWidget *widget,
257 GtkStateType previous_state);
258 static void gtk_icon_view_size_request (GtkWidget *widget,
259 GtkRequisition *requisition);
260 static void gtk_icon_view_size_allocate (GtkWidget *widget,
261 GtkAllocation *allocation);
262 static gboolean gtk_icon_view_expose (GtkWidget *widget,
263 GdkEventExpose *expose);
264 static gboolean gtk_icon_view_motion (GtkWidget *widget,
265 GdkEventMotion *event);
266 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
267 GdkEventButton *event);
268 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
272 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
274 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
277 /* GtkContainer vfuncs */
278 static void gtk_icon_view_remove (GtkContainer *container,
280 static void gtk_icon_view_forall (GtkContainer *container,
281 gboolean include_internals,
282 GtkCallback callback,
283 gpointer callback_data);
285 /* GtkIconView vfuncs */
286 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
288 GtkAdjustment *vadj);
289 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
290 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
291 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
292 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
293 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
295 /* Internal functions */
296 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
297 GtkIconView *icon_view);
298 static void gtk_icon_view_layout (GtkIconView *icon_view);
299 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
302 GtkIconViewItem *item,
304 GdkDrawable *drawable,
307 gboolean draw_focus);
308 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
311 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
313 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
314 GtkIconViewItem *item);
315 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
316 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
317 GtkIconViewItem *item,
319 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
323 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
324 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
325 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
326 GtkIconViewItem *item,
331 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
332 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
333 GtkIconViewItem *item);
334 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
335 GtkIconViewItem *item,
337 static void gtk_icon_view_update_rubberband (gpointer data);
338 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
339 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
340 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
343 GtkMovementStep step,
345 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
346 GtkMovementStep step,
348 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
350 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
352 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
354 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
356 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
357 GtkIconViewItem *item);
358 static void gtk_icon_view_select_item (GtkIconView *icon_view,
359 GtkIconViewItem *item);
360 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
363 GtkIconViewItem *anchor,
364 GtkIconViewItem *cursor);
365 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
368 gboolean only_in_cell,
369 GtkIconViewCellInfo **cell_at_pos);
370 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
371 GtkIconViewItem *item,
372 GtkIconViewCellInfo *cell_info,
373 GdkRectangle *cell_area);
374 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
375 GtkIconViewItem *item,
376 GtkIconViewCellInfo *info,
378 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
379 GtkCellRenderer *renderer);
380 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
381 GtkIconViewItem *item);
382 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
383 GtkCellRenderer *renderer,
385 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
386 GtkCellRenderer *renderer,
388 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
389 GtkCellRenderer *renderer,
390 const gchar *attribute,
392 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
393 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
394 GtkCellRenderer *renderer);
395 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
396 GtkCellRenderer *cell,
397 GtkCellLayoutDataFunc func,
399 GDestroyNotify destroy);
400 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
401 GtkCellRenderer *cell,
403 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
405 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
406 GtkIconViewItem *item,
407 GtkIconViewCellInfo *cell_info,
409 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
410 GtkIconViewItem *item);
411 static void gtk_icon_view_put (GtkIconView *icon_view,
413 GtkIconViewItem *item,
415 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
416 GtkIconView *icon_view);
417 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
418 GtkIconViewItem *item,
419 GtkIconViewCellInfo *cell_info,
421 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
422 gboolean cancel_editing);
424 /* Source side drag signals */
425 static void gtk_icon_view_drag_begin (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_icon_view_drag_end (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
430 GdkDragContext *context,
431 GtkSelectionData *selection_data,
434 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
435 GdkDragContext *context);
437 /* Target side drag signals */
438 static void gtk_icon_view_drag_leave (GtkWidget *widget,
439 GdkDragContext *context,
441 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
442 GdkDragContext *context,
446 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
447 GdkDragContext *context,
451 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
452 GdkDragContext *context,
455 GtkSelectionData *selection_data,
458 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
459 GdkEventMotion *event);
461 static void remove_scroll_timeout (GtkIconView *icon_view);
463 static void adjust_wrap_width (GtkIconView *icon_view,
464 GtkIconViewItem *item);
467 static GtkBuildableIface *parent_buildable_iface;
468 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
469 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
472 const gchar *tagname,
473 GMarkupParser *parser,
475 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
478 const gchar *tagname,
481 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
483 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
484 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
485 gtk_icon_view_cell_layout_init)
486 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
487 gtk_icon_view_buildable_init))
490 gtk_icon_view_class_init (GtkIconViewClass *klass)
492 GObjectClass *gobject_class;
493 GtkObjectClass *object_class;
494 GtkWidgetClass *widget_class;
495 GtkContainerClass *container_class;
496 GtkBindingSet *binding_set;
498 binding_set = gtk_binding_set_by_class (klass);
500 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
502 gobject_class = (GObjectClass *) klass;
503 object_class = (GtkObjectClass *) klass;
504 widget_class = (GtkWidgetClass *) klass;
505 container_class = (GtkContainerClass *) klass;
507 gobject_class->finalize = gtk_icon_view_finalize;
508 gobject_class->set_property = gtk_icon_view_set_property;
509 gobject_class->get_property = gtk_icon_view_get_property;
511 object_class->destroy = gtk_icon_view_destroy;
513 widget_class->realize = gtk_icon_view_realize;
514 widget_class->unrealize = gtk_icon_view_unrealize;
515 widget_class->style_set = gtk_icon_view_style_set;
516 widget_class->get_accessible = gtk_icon_view_get_accessible;
517 widget_class->size_request = gtk_icon_view_size_request;
518 widget_class->size_allocate = gtk_icon_view_size_allocate;
519 widget_class->expose_event = gtk_icon_view_expose;
520 widget_class->motion_notify_event = gtk_icon_view_motion;
521 widget_class->button_press_event = gtk_icon_view_button_press;
522 widget_class->button_release_event = gtk_icon_view_button_release;
523 widget_class->key_press_event = gtk_icon_view_key_press;
524 widget_class->key_release_event = gtk_icon_view_key_release;
525 widget_class->drag_begin = gtk_icon_view_drag_begin;
526 widget_class->drag_end = gtk_icon_view_drag_end;
527 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
528 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
529 widget_class->drag_leave = gtk_icon_view_drag_leave;
530 widget_class->drag_motion = gtk_icon_view_drag_motion;
531 widget_class->drag_drop = gtk_icon_view_drag_drop;
532 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
533 widget_class->state_changed = gtk_icon_view_state_changed;
535 container_class->remove = gtk_icon_view_remove;
536 container_class->forall = gtk_icon_view_forall;
538 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
539 klass->select_all = gtk_icon_view_real_select_all;
540 klass->unselect_all = gtk_icon_view_real_unselect_all;
541 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
542 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
543 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
544 klass->move_cursor = gtk_icon_view_real_move_cursor;
548 * GtkIconView:selection-mode:
550 * The ::selection-mode property specifies the selection mode of
551 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
552 * is enabled, for the other modes, only keyboard selection is possible.
556 g_object_class_install_property (gobject_class,
558 g_param_spec_enum ("selection-mode",
559 P_("Selection mode"),
560 P_("The selection mode"),
561 GTK_TYPE_SELECTION_MODE,
562 GTK_SELECTION_SINGLE,
563 GTK_PARAM_READWRITE));
566 * GtkIconView:pixbuf-column:
568 * The ::pixbuf-column property contains the number of the model column
569 * containing the pixbufs which are displayed. The pixbuf column must be
570 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
571 * display of pixbufs.
575 g_object_class_install_property (gobject_class,
577 g_param_spec_int ("pixbuf-column",
579 P_("Model column used to retrieve the icon pixbuf from"),
581 GTK_PARAM_READWRITE));
584 * GtkIconView:text-column:
586 * The ::text-column property contains the number of the model column
587 * containing the texts which are displayed. The text column must be
588 * of type #G_TYPE_STRING. If this property and the :markup-column
589 * property are both set to -1, no texts are displayed.
593 g_object_class_install_property (gobject_class,
595 g_param_spec_int ("text-column",
597 P_("Model column used to retrieve the text from"),
599 GTK_PARAM_READWRITE));
603 * GtkIconView:markup-column:
605 * The ::markup-column property contains the number of the model column
606 * containing markup information to be displayed. The markup column must be
607 * of type #G_TYPE_STRING. If this property and the :text-column property
608 * are both set to column numbers, it overrides the text column.
609 * If both are set to -1, no texts are displayed.
613 g_object_class_install_property (gobject_class,
615 g_param_spec_int ("markup-column",
617 P_("Model column used to retrieve the text if using Pango markup"),
619 GTK_PARAM_READWRITE));
621 g_object_class_install_property (gobject_class,
623 g_param_spec_object ("model",
624 P_("Icon View Model"),
625 P_("The model for the icon view"),
627 GTK_PARAM_READWRITE));
630 * GtkIconView:columns:
632 * The columns property contains the number of the columns in which the
633 * items should be displayed. If it is -1, the number of columns will
634 * be chosen automatically to fill the available area.
638 g_object_class_install_property (gobject_class,
640 g_param_spec_int ("columns",
641 P_("Number of columns"),
642 P_("Number of columns to display"),
644 GTK_PARAM_READWRITE));
648 * GtkIconView:item-width:
650 * The item-width property specifies the width to use for each item.
651 * If it is set to -1, the icon view will automatically determine a
652 * suitable item size.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("item-width",
659 P_("Width for each item"),
660 P_("The width used for each item"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView:spacing:
667 * The spacing property specifies the space which is inserted between
668 * the cells (i.e. the icon and the text) of an item.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("spacing",
676 P_("Space which is inserted between cells of an item"),
678 GTK_PARAM_READWRITE));
681 * GtkIconView:row-spacing:
683 * The row-spacing property specifies the space which is inserted between
684 * the rows of the icon view.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("row-spacing",
692 P_("Space which is inserted between grid rows"),
694 GTK_PARAM_READWRITE));
697 * GtkIconView:column-spacing:
699 * The column-spacing property specifies the space which is inserted between
700 * the columns of the icon view.
704 g_object_class_install_property (gobject_class,
706 g_param_spec_int ("column-spacing",
707 P_("Column Spacing"),
708 P_("Space which is inserted between grid columns"),
710 GTK_PARAM_READWRITE));
713 * GtkIconView:margin:
715 * The margin property specifies the space which is inserted
716 * at the edges of the icon view.
720 g_object_class_install_property (gobject_class,
722 g_param_spec_int ("margin",
724 P_("Space which is inserted at the edges of the icon view"),
726 GTK_PARAM_READWRITE));
729 * GtkIconView:item-orientation:
731 * The item-orientation property specifies how the cells (i.e. the icon and
732 * the text) of the item are positioned relative to each other.
736 g_object_class_install_property (gobject_class,
737 PROP_ITEM_ORIENTATION,
738 g_param_spec_enum ("item-orientation",
739 P_("Item Orientation"),
740 P_("How the text and icon of each item are positioned relative to each other"),
741 GTK_TYPE_ORIENTATION,
742 GTK_ORIENTATION_VERTICAL,
743 GTK_PARAM_READWRITE));
746 * GtkIconView:reorderable:
748 * The reorderable property specifies if the items can be reordered
753 g_object_class_install_property (gobject_class,
755 g_param_spec_boolean ("reorderable",
757 P_("View is reorderable"),
761 g_object_class_install_property (gobject_class,
763 g_param_spec_int ("tooltip-column",
764 P_("Tooltip Column"),
765 P_("The column in the model containing the tooltip texts for the items"),
769 GTK_PARAM_READWRITE));
772 * GtkIconView:item-padding:
774 * The item-padding property specifies the padding around each
775 * of the icon view's item.
779 g_object_class_install_property (gobject_class,
781 g_param_spec_int ("item-padding",
783 P_("Padding around icon view items"),
785 GTK_PARAM_READWRITE));
789 /* Style properties */
790 gtk_widget_class_install_style_property (widget_class,
791 g_param_spec_boxed ("selection-box-color",
792 P_("Selection Box Color"),
793 P_("Color of the selection box"),
795 GTK_PARAM_READABLE));
797 gtk_widget_class_install_style_property (widget_class,
798 g_param_spec_uchar ("selection-box-alpha",
799 P_("Selection Box Alpha"),
800 P_("Opacity of the selection box"),
803 GTK_PARAM_READABLE));
807 * GtkIconView::set-scroll-adjustments
808 * @horizontal: the horizontal #GtkAdjustment
809 * @vertical: the vertical #GtkAdjustment
811 * Set the scroll adjustments for the icon view. Usually scrolled containers
812 * like #GtkScrolledWindow will emit this signal to connect two instances
813 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
815 widget_class->set_scroll_adjustments_signal =
816 g_signal_new (I_("set-scroll-adjustments"),
817 G_TYPE_FROM_CLASS (gobject_class),
819 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
821 _gtk_marshal_VOID__OBJECT_OBJECT,
823 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
826 * GtkIconView::item-activated:
827 * @iconview: the object on which the signal is emitted
828 * @path: the #GtkTreePath for the activated item
830 * The ::item-activated signal is emitted when the method
831 * gtk_icon_view_item_activated() is called or the user double
832 * clicks an item. It is also emitted when a non-editable item
833 * is selected and one of the keys: Space, Return or Enter is
836 icon_view_signals[ITEM_ACTIVATED] =
837 g_signal_new (I_("item-activated"),
838 G_TYPE_FROM_CLASS (gobject_class),
840 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
842 g_cclosure_marshal_VOID__BOXED,
847 * GtkIconView::selection-changed:
848 * @iconview: the object on which the signal is emitted
850 * The ::selection-changed signal is emitted when the selection
851 * (i.e. the set of selected items) changes.
853 icon_view_signals[SELECTION_CHANGED] =
854 g_signal_new (I_("selection-changed"),
855 G_TYPE_FROM_CLASS (gobject_class),
857 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
859 g_cclosure_marshal_VOID__VOID,
863 * GtkIconView::select-all:
864 * @iconview: the object on which the signal is emitted
866 * A <link linkend="keybinding-signals">keybinding signal</link>
867 * which gets emitted when the user selects all items.
869 * Applications should not connect to it, but may emit it with
870 * g_signal_emit_by_name() if they need to control selection
873 * The default binding for this signal is Ctrl-a.
875 icon_view_signals[SELECT_ALL] =
876 g_signal_new (I_("select-all"),
877 G_TYPE_FROM_CLASS (gobject_class),
878 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
879 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
881 g_cclosure_marshal_VOID__VOID,
885 * GtkIconView::unselect-all:
886 * @iconview: the object on which the signal is emitted
888 * A <link linkend="keybinding-signals">keybinding signal</link>
889 * which gets emitted when the user unselects all items.
891 * Applications should not connect to it, but may emit it with
892 * g_signal_emit_by_name() if they need to control selection
895 * The default binding for this signal is Ctrl-Shift-a.
897 icon_view_signals[UNSELECT_ALL] =
898 g_signal_new (I_("unselect-all"),
899 G_TYPE_FROM_CLASS (gobject_class),
900 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
901 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
903 g_cclosure_marshal_VOID__VOID,
907 * GtkIconView::select-cursor-item:
908 * @iconview: the object on which the signal is emitted
910 * A <link linkend="keybinding-signals">keybinding signal</link>
911 * which gets emitted when the user selects the item that is currently
914 * Applications should not connect to it, but may emit it with
915 * g_signal_emit_by_name() if they need to control selection
918 * There is no default binding for this signal.
920 icon_view_signals[SELECT_CURSOR_ITEM] =
921 g_signal_new (I_("select-cursor-item"),
922 G_TYPE_FROM_CLASS (gobject_class),
923 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
924 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
926 g_cclosure_marshal_VOID__VOID,
930 * GtkIconView::toggle-cursor-item:
931 * @iconview: the object on which the signal is emitted
933 * A <link linkend="keybinding-signals">keybinding signal</link>
934 * which gets emitted when the user toggles whether the currently
935 * focused item is selected or not. The exact effect of this
936 * depend on the selection mode.
938 * Applications should not connect to it, but may emit it with
939 * g_signal_emit_by_name() if they need to control selection
942 * There is no default binding for this signal is Ctrl-Space.
944 icon_view_signals[TOGGLE_CURSOR_ITEM] =
945 g_signal_new (I_("toggle-cursor-item"),
946 G_TYPE_FROM_CLASS (gobject_class),
947 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
948 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
950 g_cclosure_marshal_VOID__VOID,
954 * GtkIconView::activate-cursor-item:
955 * @iconview: the object on which the signal is emitted
957 * A <link linkend="keybinding-signals">keybinding signal</link>
958 * which gets emitted when the user activates the currently
961 * Applications should not connect to it, but may emit it with
962 * g_signal_emit_by_name() if they need to control activation
965 * The default bindings for this signal are Space, Return and Enter.
967 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
968 g_signal_new (I_("activate-cursor-item"),
969 G_TYPE_FROM_CLASS (gobject_class),
970 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
971 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
973 _gtk_marshal_BOOLEAN__VOID,
977 * GtkIconView::move-cursor:
978 * @iconview: the object which received the signal
979 * @step: the granularity of the move, as a #GtkMovementStep
980 * @count: the number of @step units to move
982 * The ::move-cursor signal is a
983 * <link linkend="keybinding-signals">keybinding signal</link>
984 * which gets emitted when the user initiates a cursor movement.
986 * Applications should not connect to it, but may emit it with
987 * g_signal_emit_by_name() if they need to control the cursor
990 * The default bindings for this signal include
992 * <listitem>Arrow keys which move by individual steps</listitem>
993 * <listitem>Home/End keys which move to the first/last item</listitem>
994 * <listitem>PageUp/PageDown which move by "pages"</listitem>
997 * All of these will extend the selection when combined with
998 * the Shift modifier.
1000 icon_view_signals[MOVE_CURSOR] =
1001 g_signal_new (I_("move-cursor"),
1002 G_TYPE_FROM_CLASS (gobject_class),
1003 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1004 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1006 _gtk_marshal_BOOLEAN__ENUM_INT,
1008 GTK_TYPE_MOVEMENT_STEP,
1012 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1014 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1016 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1017 "toggle-cursor-item", 0);
1018 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1019 "toggle-cursor-item", 0);
1021 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1022 "activate-cursor-item", 0);
1023 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1024 "activate-cursor-item", 0);
1025 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1026 "activate-cursor-item", 0);
1027 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1028 "activate-cursor-item", 0);
1029 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1030 "activate-cursor-item", 0);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1033 GTK_MOVEMENT_DISPLAY_LINES, -1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1035 GTK_MOVEMENT_DISPLAY_LINES, -1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1038 GTK_MOVEMENT_DISPLAY_LINES, 1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1040 GTK_MOVEMENT_DISPLAY_LINES, 1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1043 GTK_MOVEMENT_DISPLAY_LINES, -1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1046 GTK_MOVEMENT_DISPLAY_LINES, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1049 GTK_MOVEMENT_BUFFER_ENDS, -1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1051 GTK_MOVEMENT_BUFFER_ENDS, -1);
1053 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1054 GTK_MOVEMENT_BUFFER_ENDS, 1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1056 GTK_MOVEMENT_BUFFER_ENDS, 1);
1058 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1059 GTK_MOVEMENT_PAGES, -1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1061 GTK_MOVEMENT_PAGES, -1);
1063 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1064 GTK_MOVEMENT_PAGES, 1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1066 GTK_MOVEMENT_PAGES, 1);
1068 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1069 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1070 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1071 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1073 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1074 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1075 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1076 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1080 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1082 parent_buildable_iface = g_type_interface_peek_parent (iface);
1083 iface->add_child = _gtk_cell_layout_buildable_add_child;
1084 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1085 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1089 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1091 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1092 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1093 iface->clear = gtk_icon_view_cell_layout_clear;
1094 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1095 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1096 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1097 iface->reorder = gtk_icon_view_cell_layout_reorder;
1098 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1102 gtk_icon_view_init (GtkIconView *icon_view)
1104 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1106 GtkIconViewPrivate);
1108 icon_view->priv->width = 0;
1109 icon_view->priv->height = 0;
1110 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1111 icon_view->priv->pressed_button = -1;
1112 icon_view->priv->press_start_x = -1;
1113 icon_view->priv->press_start_y = -1;
1114 icon_view->priv->text_column = -1;
1115 icon_view->priv->markup_column = -1;
1116 icon_view->priv->pixbuf_column = -1;
1117 icon_view->priv->text_cell = -1;
1118 icon_view->priv->pixbuf_cell = -1;
1119 icon_view->priv->tooltip_column = -1;
1121 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1123 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1125 icon_view->priv->cell_list = NULL;
1126 icon_view->priv->n_cells = 0;
1127 icon_view->priv->cursor_cell = -1;
1129 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1131 icon_view->priv->columns = -1;
1132 icon_view->priv->item_width = -1;
1133 icon_view->priv->spacing = 0;
1134 icon_view->priv->row_spacing = 6;
1135 icon_view->priv->column_spacing = 6;
1136 icon_view->priv->margin = 6;
1137 icon_view->priv->item_padding = 6;
1139 icon_view->priv->draw_focus = TRUE;
1143 gtk_icon_view_destroy (GtkObject *object)
1145 GtkIconView *icon_view;
1147 icon_view = GTK_ICON_VIEW (object);
1149 gtk_icon_view_stop_editing (icon_view, TRUE);
1151 gtk_icon_view_set_model (icon_view, NULL);
1153 if (icon_view->priv->layout_idle_id != 0)
1155 g_source_remove (icon_view->priv->layout_idle_id);
1156 icon_view->priv->layout_idle_id = 0;
1159 if (icon_view->priv->scroll_to_path != NULL)
1161 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1162 icon_view->priv->scroll_to_path = NULL;
1165 remove_scroll_timeout (icon_view);
1167 if (icon_view->priv->hadjustment != NULL)
1169 g_object_unref (icon_view->priv->hadjustment);
1170 icon_view->priv->hadjustment = NULL;
1173 if (icon_view->priv->vadjustment != NULL)
1175 g_object_unref (icon_view->priv->vadjustment);
1176 icon_view->priv->vadjustment = NULL;
1179 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1182 /* GObject methods */
1184 gtk_icon_view_finalize (GObject *object)
1186 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1188 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1193 gtk_icon_view_set_property (GObject *object,
1195 const GValue *value,
1198 GtkIconView *icon_view;
1200 icon_view = GTK_ICON_VIEW (object);
1204 case PROP_SELECTION_MODE:
1205 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1207 case PROP_PIXBUF_COLUMN:
1208 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1210 case PROP_TEXT_COLUMN:
1211 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1213 case PROP_MARKUP_COLUMN:
1214 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1217 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1219 case PROP_ITEM_ORIENTATION:
1220 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1223 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1225 case PROP_ITEM_WIDTH:
1226 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1229 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1231 case PROP_ROW_SPACING:
1232 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1234 case PROP_COLUMN_SPACING:
1235 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1238 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1240 case PROP_REORDERABLE:
1241 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1244 case PROP_TOOLTIP_COLUMN:
1245 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1248 case PROP_ITEM_PADDING:
1249 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1259 gtk_icon_view_get_property (GObject *object,
1264 GtkIconView *icon_view;
1266 icon_view = GTK_ICON_VIEW (object);
1270 case PROP_SELECTION_MODE:
1271 g_value_set_enum (value, icon_view->priv->selection_mode);
1273 case PROP_PIXBUF_COLUMN:
1274 g_value_set_int (value, icon_view->priv->pixbuf_column);
1276 case PROP_TEXT_COLUMN:
1277 g_value_set_int (value, icon_view->priv->text_column);
1279 case PROP_MARKUP_COLUMN:
1280 g_value_set_int (value, icon_view->priv->markup_column);
1283 g_value_set_object (value, icon_view->priv->model);
1285 case PROP_ITEM_ORIENTATION:
1286 g_value_set_enum (value, icon_view->priv->item_orientation);
1289 g_value_set_int (value, icon_view->priv->columns);
1291 case PROP_ITEM_WIDTH:
1292 g_value_set_int (value, icon_view->priv->item_width);
1295 g_value_set_int (value, icon_view->priv->spacing);
1297 case PROP_ROW_SPACING:
1298 g_value_set_int (value, icon_view->priv->row_spacing);
1300 case PROP_COLUMN_SPACING:
1301 g_value_set_int (value, icon_view->priv->column_spacing);
1304 g_value_set_int (value, icon_view->priv->margin);
1306 case PROP_REORDERABLE:
1307 g_value_set_boolean (value, icon_view->priv->reorderable);
1309 case PROP_TOOLTIP_COLUMN:
1310 g_value_set_int (value, icon_view->priv->tooltip_column);
1313 case PROP_ITEM_PADDING:
1314 g_value_set_int (value, icon_view->priv->item_padding);
1318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1323 /* GtkWidget signals */
1325 gtk_icon_view_realize (GtkWidget *widget)
1327 GtkIconView *icon_view;
1328 GdkWindowAttr attributes;
1329 gint attributes_mask;
1331 icon_view = GTK_ICON_VIEW (widget);
1333 gtk_widget_set_realized (widget, TRUE);
1335 /* Make the main, clipping window */
1336 attributes.window_type = GDK_WINDOW_CHILD;
1337 attributes.x = widget->allocation.x;
1338 attributes.y = widget->allocation.y;
1339 attributes.width = widget->allocation.width;
1340 attributes.height = widget->allocation.height;
1341 attributes.wclass = GDK_INPUT_OUTPUT;
1342 attributes.visual = gtk_widget_get_visual (widget);
1343 attributes.colormap = gtk_widget_get_colormap (widget);
1344 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1346 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1348 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1349 &attributes, attributes_mask);
1350 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1351 gdk_window_set_user_data (widget->window, widget);
1353 /* Make the window for the icon view */
1356 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1357 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1358 attributes.event_mask = (GDK_EXPOSURE_MASK |
1360 GDK_POINTER_MOTION_MASK |
1361 GDK_BUTTON_PRESS_MASK |
1362 GDK_BUTTON_RELEASE_MASK |
1363 GDK_KEY_PRESS_MASK |
1364 GDK_KEY_RELEASE_MASK) |
1365 gtk_widget_get_events (widget);
1367 icon_view->priv->bin_window = gdk_window_new (widget->window,
1368 &attributes, attributes_mask);
1369 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1371 widget->style = gtk_style_attach (widget->style, widget->window);
1372 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1374 gdk_window_show (icon_view->priv->bin_window);
1378 gtk_icon_view_unrealize (GtkWidget *widget)
1380 GtkIconView *icon_view;
1382 icon_view = GTK_ICON_VIEW (widget);
1384 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1385 gdk_window_destroy (icon_view->priv->bin_window);
1386 icon_view->priv->bin_window = NULL;
1388 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1392 gtk_icon_view_state_changed (GtkWidget *widget,
1393 GtkStateType previous_state)
1395 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1397 if (gtk_widget_get_realized (widget))
1399 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1400 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1403 gtk_widget_queue_draw (widget);
1407 gtk_icon_view_style_set (GtkWidget *widget,
1408 GtkStyle *previous_style)
1410 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1412 if (gtk_widget_get_realized (widget))
1414 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1415 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1418 gtk_widget_queue_resize (widget);
1422 gtk_icon_view_size_request (GtkWidget *widget,
1423 GtkRequisition *requisition)
1425 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1428 requisition->width = icon_view->priv->width;
1429 requisition->height = icon_view->priv->height;
1431 tmp_list = icon_view->priv->children;
1435 GtkIconViewChild *child = tmp_list->data;
1436 GtkRequisition child_requisition;
1438 tmp_list = tmp_list->next;
1440 if (gtk_widget_get_visible (child->widget))
1441 gtk_widget_size_request (child->widget, &child_requisition);
1446 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1450 for (list = icon_view->priv->children; list; list = list->next)
1452 GtkIconViewChild *child = list->data;
1453 GtkAllocation allocation;
1455 /* totally ignore our child's requisition */
1456 if (child->cell < 0)
1458 allocation.x = child->item->x + icon_view->priv->item_padding;
1459 allocation.y = child->item->y + icon_view->priv->item_padding;
1460 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1461 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1465 GdkRectangle *box = &child->item->box[child->cell];
1467 allocation.x = box->x;
1468 allocation.y = box->y;
1469 allocation.width = box->width;
1470 allocation.height = box->height;
1473 gtk_widget_size_allocate (child->widget, &allocation);
1478 gtk_icon_view_size_allocate (GtkWidget *widget,
1479 GtkAllocation *allocation)
1481 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1483 GtkAdjustment *hadjustment, *vadjustment;
1485 widget->allocation = *allocation;
1487 if (gtk_widget_get_realized (widget))
1489 gdk_window_move_resize (widget->window,
1490 allocation->x, allocation->y,
1491 allocation->width, allocation->height);
1492 gdk_window_resize (icon_view->priv->bin_window,
1493 MAX (icon_view->priv->width, allocation->width),
1494 MAX (icon_view->priv->height, allocation->height));
1497 gtk_icon_view_layout (icon_view);
1499 gtk_icon_view_allocate_children (icon_view);
1501 hadjustment = icon_view->priv->hadjustment;
1502 vadjustment = icon_view->priv->vadjustment;
1504 hadjustment->page_size = allocation->width;
1505 hadjustment->page_increment = allocation->width * 0.9;
1506 hadjustment->step_increment = allocation->width * 0.1;
1507 hadjustment->lower = 0;
1508 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1510 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1511 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1513 vadjustment->page_size = allocation->height;
1514 vadjustment->page_increment = allocation->height * 0.9;
1515 vadjustment->step_increment = allocation->height * 0.1;
1516 vadjustment->lower = 0;
1517 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1519 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1520 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1522 if (gtk_widget_get_realized (widget) &&
1523 icon_view->priv->scroll_to_path)
1526 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1527 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1528 icon_view->priv->scroll_to_path = NULL;
1530 gtk_icon_view_scroll_to_path (icon_view, path,
1531 icon_view->priv->scroll_to_use_align,
1532 icon_view->priv->scroll_to_row_align,
1533 icon_view->priv->scroll_to_col_align);
1534 gtk_tree_path_free (path);
1538 gtk_adjustment_changed (hadjustment);
1539 gtk_adjustment_changed (vadjustment);
1544 gtk_icon_view_expose (GtkWidget *widget,
1545 GdkEventExpose *expose)
1547 GtkIconView *icon_view;
1552 GtkIconViewDropPosition dest_pos;
1553 GtkIconViewItem *dest_item = NULL;
1555 icon_view = GTK_ICON_VIEW (widget);
1557 if (expose->window != icon_view->priv->bin_window)
1560 /* If a layout has been scheduled, do it now so that all
1561 * cell view items have valid sizes before we proceed. */
1562 if (icon_view->priv->layout_idle_id != 0)
1563 gtk_icon_view_layout (icon_view);
1565 cr = gdk_cairo_create (icon_view->priv->bin_window);
1566 cairo_set_line_width (cr, 1.);
1568 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1572 dest_index = gtk_tree_path_get_indices (path)[0];
1573 gtk_tree_path_free (path);
1578 for (icons = icon_view->priv->items; icons; icons = icons->next)
1580 GtkIconViewItem *item = icons->data;
1585 area.width = item->width;
1586 area.height = item->height;
1588 if (cairo_region_contains_rectangle (expose->region, &area) == CAIRO_REGION_OVERLAP_OUT)
1591 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1592 icon_view->priv->bin_window,
1594 icon_view->priv->draw_focus);
1596 if (dest_index == item->index)
1604 case GTK_ICON_VIEW_DROP_INTO:
1605 gtk_paint_focus (widget->style,
1606 icon_view->priv->bin_window,
1607 gtk_widget_get_state (widget),
1610 "iconview-drop-indicator",
1611 dest_item->x, dest_item->y,
1612 dest_item->width, dest_item->height);
1614 case GTK_ICON_VIEW_DROP_ABOVE:
1615 gtk_paint_focus (widget->style,
1616 icon_view->priv->bin_window,
1617 gtk_widget_get_state (widget),
1620 "iconview-drop-indicator",
1621 dest_item->x, dest_item->y - 1,
1622 dest_item->width, 2);
1624 case GTK_ICON_VIEW_DROP_LEFT:
1625 gtk_paint_focus (widget->style,
1626 icon_view->priv->bin_window,
1627 gtk_widget_get_state (widget),
1630 "iconview-drop-indicator",
1631 dest_item->x - 1, dest_item->y,
1632 2, dest_item->height);
1634 case GTK_ICON_VIEW_DROP_BELOW:
1635 gtk_paint_focus (widget->style,
1636 icon_view->priv->bin_window,
1637 gtk_widget_get_state (widget),
1640 "iconview-drop-indicator",
1641 dest_item->x, dest_item->y + dest_item->height - 1,
1642 dest_item->width, 2);
1644 case GTK_ICON_VIEW_DROP_RIGHT:
1645 gtk_paint_focus (widget->style,
1646 icon_view->priv->bin_window,
1647 gtk_widget_get_state (widget),
1650 "iconview-drop-indicator",
1651 dest_item->x + dest_item->width - 1, dest_item->y,
1652 2, dest_item->height);
1653 case GTK_ICON_VIEW_NO_DROP: ;
1658 if (icon_view->priv->doing_rubberband)
1660 cairo_rectangle_int_t rectangle;
1663 n_rectangles = cairo_region_num_rectangles (expose->region);
1665 while (n_rectangles--)
1667 cairo_region_get_rectangle (expose->region, n_rectangles, &rectangle);
1668 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangle);
1674 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1680 rubberband_scroll_timeout (gpointer data)
1682 GtkIconView *icon_view = data;
1684 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1685 icon_view->priv->vadjustment->value +
1686 icon_view->priv->scroll_value_diff);
1688 gtk_icon_view_update_rubberband (icon_view);
1694 gtk_icon_view_motion (GtkWidget *widget,
1695 GdkEventMotion *event)
1697 GtkIconView *icon_view;
1700 icon_view = GTK_ICON_VIEW (widget);
1702 gtk_icon_view_maybe_begin_drag (icon_view, event);
1704 if (icon_view->priv->doing_rubberband)
1706 gtk_icon_view_update_rubberband (widget);
1708 abs_y = event->y - icon_view->priv->height *
1709 (icon_view->priv->vadjustment->value /
1710 (icon_view->priv->vadjustment->upper -
1711 icon_view->priv->vadjustment->lower));
1713 if (abs_y < 0 || abs_y > widget->allocation.height)
1716 icon_view->priv->scroll_value_diff = abs_y;
1718 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1720 icon_view->priv->event_last_x = event->x;
1721 icon_view->priv->event_last_y = event->y;
1723 if (icon_view->priv->scroll_timeout_id == 0)
1724 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1728 remove_scroll_timeout (icon_view);
1735 gtk_icon_view_remove (GtkContainer *container,
1738 GtkIconView *icon_view;
1739 GtkIconViewChild *child = NULL;
1742 icon_view = GTK_ICON_VIEW (container);
1744 tmp_list = icon_view->priv->children;
1747 child = tmp_list->data;
1748 if (child->widget == widget)
1750 gtk_widget_unparent (widget);
1752 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1753 g_list_free_1 (tmp_list);
1758 tmp_list = tmp_list->next;
1763 gtk_icon_view_forall (GtkContainer *container,
1764 gboolean include_internals,
1765 GtkCallback callback,
1766 gpointer callback_data)
1768 GtkIconView *icon_view;
1769 GtkIconViewChild *child = NULL;
1772 icon_view = GTK_ICON_VIEW (container);
1774 tmp_list = icon_view->priv->children;
1777 child = tmp_list->data;
1778 tmp_list = tmp_list->next;
1780 (* callback) (child->widget, callback_data);
1785 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1786 GtkIconViewItem *item,
1787 GtkIconViewCellInfo *info,
1792 GdkRectangle cell_area;
1793 gboolean visible, mode;
1795 gtk_icon_view_set_cell_data (icon_view, item);
1797 g_object_get (info->cell,
1798 "visible", &visible,
1802 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1804 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1806 path = gtk_tree_path_new_from_indices (item->index, -1);
1807 path_string = gtk_tree_path_to_string (path);
1808 gtk_tree_path_free (path);
1810 gtk_cell_renderer_activate (info->cell,
1812 GTK_WIDGET (icon_view),
1818 g_free (path_string);
1823 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1824 GtkIconViewItem *item)
1827 AtkObject *item_obj;
1829 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1832 item_obj = atk_object_ref_accessible_child (obj, item->index);
1833 if (item_obj != NULL)
1835 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1836 g_object_unref (item_obj);
1842 gtk_icon_view_put (GtkIconView *icon_view,
1844 GtkIconViewItem *item,
1847 GtkIconViewChild *child;
1849 child = g_new (GtkIconViewChild, 1);
1851 child->widget = widget;
1855 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1857 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1858 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1860 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1864 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1865 GtkIconView *icon_view)
1868 GtkIconViewItem *item;
1870 if (icon_view->priv->edited_item == NULL)
1873 item = icon_view->priv->edited_item;
1874 icon_view->priv->edited_item = NULL;
1875 icon_view->priv->editable = NULL;
1876 for (l = icon_view->priv->cell_list; l; l = l->next)
1878 GtkIconViewCellInfo *info = l->data;
1880 info->editing = FALSE;
1883 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1884 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1886 g_signal_handlers_disconnect_by_func (editable,
1887 gtk_icon_view_remove_widget,
1890 gtk_container_remove (GTK_CONTAINER (icon_view),
1891 GTK_WIDGET (editable));
1893 gtk_icon_view_queue_draw_item (icon_view, item);
1898 gtk_icon_view_start_editing (GtkIconView *icon_view,
1899 GtkIconViewItem *item,
1900 GtkIconViewCellInfo *info,
1905 GdkRectangle cell_area;
1906 gboolean visible, mode;
1907 GtkCellEditable *editable;
1909 gtk_icon_view_set_cell_data (icon_view, item);
1911 g_object_get (info->cell,
1912 "visible", &visible,
1915 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1917 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1919 path = gtk_tree_path_new_from_indices (item->index, -1);
1920 path_string = gtk_tree_path_to_string (path);
1921 gtk_tree_path_free (path);
1923 editable = gtk_cell_renderer_start_editing (info->cell,
1925 GTK_WIDGET (icon_view),
1930 g_free (path_string);
1932 /* the rest corresponds to tree_view_real_start_editing... */
1933 icon_view->priv->edited_item = item;
1934 icon_view->priv->editable = editable;
1935 info->editing = TRUE;
1937 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1939 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1941 gtk_widget_grab_focus (GTK_WIDGET (editable));
1942 g_signal_connect (editable, "remove-widget",
1943 G_CALLBACK (gtk_icon_view_remove_widget),
1950 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1951 gboolean cancel_editing)
1953 GtkCellRenderer *cell = NULL;
1954 GtkIconViewItem *item;
1957 if (icon_view->priv->edited_item == NULL)
1961 * This is very evil. We need to do this, because
1962 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1963 * later on. If gtk_icon_view_row_changed notices
1964 * icon_view->priv->edited_item != NULL, it'll call
1965 * gtk_icon_view_stop_editing again. Bad things will happen then.
1967 * Please read that again if you intend to modify anything here.
1970 item = icon_view->priv->edited_item;
1971 icon_view->priv->edited_item = NULL;
1973 for (l = icon_view->priv->cell_list; l; l = l->next)
1975 GtkIconViewCellInfo *info = l->data;
1987 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1988 if (!cancel_editing)
1989 gtk_cell_editable_editing_done (icon_view->priv->editable);
1991 icon_view->priv->edited_item = item;
1993 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1997 * gtk_icon_view_set_cursor:
1998 * @icon_view: A #GtkIconView
1999 * @path: A #GtkTreePath
2000 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2001 * @start_editing: %TRUE if the specified cell should start being edited.
2003 * Sets the current keyboard focus to be at @path, and selects it. This is
2004 * useful when you want to focus the user's attention on a particular item.
2005 * If @cell is not %NULL, then focus is given to the cell specified by
2006 * it. Additionally, if @start_editing is %TRUE, then editing should be
2007 * started in the specified cell.
2009 * This function is often followed by <literal>gtk_widget_grab_focus
2010 * (icon_view)</literal> in order to give keyboard focus to the widget.
2011 * Please note that editing can only happen when the widget is realized.
2016 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2018 GtkCellRenderer *cell,
2019 gboolean start_editing)
2021 GtkIconViewItem *item = NULL;
2022 GtkIconViewCellInfo *info = NULL;
2026 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2027 g_return_if_fail (path != NULL);
2028 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2030 gtk_icon_view_stop_editing (icon_view, TRUE);
2032 if (gtk_tree_path_get_depth (path) == 1)
2033 item = g_list_nth_data (icon_view->priv->items,
2034 gtk_tree_path_get_indices(path)[0]);
2040 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2044 if (info->cell == cell)
2053 g_return_if_fail (cell == NULL || info != NULL);
2055 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2056 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2058 if (info && start_editing)
2059 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2063 * gtk_icon_view_get_cursor:
2064 * @icon_view: A #GtkIconView
2065 * @path: (allow-none): Return location for the current cursor path, or %NULL
2066 * @cell: (allow-none): Return location the current focus cell, or %NULL
2068 * Fills in @path and @cell with the current cursor path and cell.
2069 * If the cursor isn't currently set, then *@path will be %NULL.
2070 * If no cell currently has focus, then *@cell will be %NULL.
2072 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2074 * Return value: %TRUE if the cursor is set.
2079 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2081 GtkCellRenderer **cell)
2083 GtkIconViewItem *item;
2084 GtkIconViewCellInfo *info;
2086 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2088 item = icon_view->priv->cursor_item;
2089 if (icon_view->priv->cursor_cell < 0)
2092 info = g_list_nth_data (icon_view->priv->cell_list,
2093 icon_view->priv->cursor_cell);
2098 *path = gtk_tree_path_new_from_indices (item->index, -1);
2111 return (item != NULL);
2115 gtk_icon_view_button_press (GtkWidget *widget,
2116 GdkEventButton *event)
2118 GtkIconView *icon_view;
2119 GtkIconViewItem *item;
2120 GtkIconViewCellInfo *info = NULL;
2121 gboolean dirty = FALSE;
2122 GtkCellRendererMode mode;
2123 gint cursor_cell = -1;
2125 icon_view = GTK_ICON_VIEW (widget);
2127 if (event->window != icon_view->priv->bin_window)
2130 if (!gtk_widget_has_focus (widget))
2131 gtk_widget_grab_focus (widget);
2133 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2135 item = gtk_icon_view_get_item_at_coords (icon_view,
2141 * We consider only the the cells' area as the item area if the
2142 * item is not selected, but if it *is* selected, the complete
2143 * selection rectangle is considered to be part of the item.
2145 if (item != NULL && (info != NULL || item->selected))
2149 g_object_get (info->cell, "mode", &mode, NULL);
2151 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2152 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2153 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2156 gtk_icon_view_scroll_to_item (icon_view, item);
2158 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2160 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2162 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2163 (event->state & GDK_SHIFT_MASK))
2165 gtk_icon_view_unselect_all_internal (icon_view);
2167 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2168 if (!icon_view->priv->anchor_item)
2169 icon_view->priv->anchor_item = item;
2171 gtk_icon_view_select_all_between (icon_view,
2172 icon_view->priv->anchor_item,
2178 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2179 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2180 (event->state & GDK_CONTROL_MASK))
2182 item->selected = !item->selected;
2183 gtk_icon_view_queue_draw_item (icon_view, item);
2188 gtk_icon_view_unselect_all_internal (icon_view);
2190 item->selected = TRUE;
2191 gtk_icon_view_queue_draw_item (icon_view, item);
2194 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2195 icon_view->priv->anchor_item = item;
2198 /* Save press to possibly begin a drag */
2199 if (icon_view->priv->pressed_button < 0)
2201 icon_view->priv->pressed_button = event->button;
2202 icon_view->priv->press_start_x = event->x;
2203 icon_view->priv->press_start_y = event->y;
2206 if (!icon_view->priv->last_single_clicked)
2207 icon_view->priv->last_single_clicked = item;
2209 /* cancel the current editing, if it exists */
2210 gtk_icon_view_stop_editing (icon_view, TRUE);
2214 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2215 gtk_icon_view_item_activate_cell (icon_view, item, info,
2217 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2218 gtk_icon_view_start_editing (icon_view, item, info,
2224 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2225 !(event->state & GDK_CONTROL_MASK))
2227 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2230 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2231 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2234 /* don't draw keyboard focus around an clicked-on item */
2235 icon_view->priv->draw_focus = FALSE;
2238 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2240 item = gtk_icon_view_get_item_at_coords (icon_view,
2245 if (item && item == icon_view->priv->last_single_clicked)
2249 path = gtk_tree_path_new_from_indices (item->index, -1);
2250 gtk_icon_view_item_activated (icon_view, path);
2251 gtk_tree_path_free (path);
2254 icon_view->priv->last_single_clicked = NULL;
2255 icon_view->priv->pressed_button = -1;
2259 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2261 return event->button == 1;
2265 gtk_icon_view_button_release (GtkWidget *widget,
2266 GdkEventButton *event)
2268 GtkIconView *icon_view;
2270 icon_view = GTK_ICON_VIEW (widget);
2272 if (icon_view->priv->pressed_button == event->button)
2273 icon_view->priv->pressed_button = -1;
2275 gtk_icon_view_stop_rubberbanding (icon_view);
2277 remove_scroll_timeout (icon_view);
2283 gtk_icon_view_key_press (GtkWidget *widget,
2286 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2288 if (icon_view->priv->doing_rubberband)
2290 if (event->keyval == GDK_Escape)
2291 gtk_icon_view_stop_rubberbanding (icon_view);
2296 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2300 gtk_icon_view_key_release (GtkWidget *widget,
2303 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2305 if (icon_view->priv->doing_rubberband)
2308 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2312 gtk_icon_view_update_rubberband (gpointer data)
2314 GtkIconView *icon_view;
2316 GdkRectangle old_area;
2317 GdkRectangle new_area;
2318 GdkRectangle common;
2319 cairo_region_t *invalid_region;
2321 icon_view = GTK_ICON_VIEW (data);
2323 gdk_window_get_device_position (icon_view->priv->bin_window,
2324 icon_view->priv->rubberband_device,
2330 old_area.x = MIN (icon_view->priv->rubberband_x1,
2331 icon_view->priv->rubberband_x2);
2332 old_area.y = MIN (icon_view->priv->rubberband_y1,
2333 icon_view->priv->rubberband_y2);
2334 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2335 icon_view->priv->rubberband_x1) + 1;
2336 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2337 icon_view->priv->rubberband_y1) + 1;
2339 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2340 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2341 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2342 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2344 invalid_region = cairo_region_create_rectangle (&old_area);
2345 cairo_region_union_rectangle (invalid_region, &new_area);
2347 gdk_rectangle_intersect (&old_area, &new_area, &common);
2348 if (common.width > 2 && common.height > 2)
2350 cairo_region_t *common_region;
2352 /* make sure the border is invalidated */
2358 common_region = cairo_region_create_rectangle (&common);
2360 cairo_region_subtract (invalid_region, common_region);
2361 cairo_region_destroy (common_region);
2364 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2366 cairo_region_destroy (invalid_region);
2368 icon_view->priv->rubberband_x2 = x;
2369 icon_view->priv->rubberband_y2 = y;
2371 gtk_icon_view_update_rubberband_selection (icon_view);
2375 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2382 if (icon_view->priv->rubberband_device)
2385 for (items = icon_view->priv->items; items; items = items->next)
2387 GtkIconViewItem *item = items->data;
2389 item->selected_before_rubberbanding = item->selected;
2392 icon_view->priv->rubberband_x1 = x;
2393 icon_view->priv->rubberband_y1 = y;
2394 icon_view->priv->rubberband_x2 = x;
2395 icon_view->priv->rubberband_y2 = y;
2397 icon_view->priv->doing_rubberband = TRUE;
2398 icon_view->priv->rubberband_device = device;
2400 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2404 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2406 if (!icon_view->priv->doing_rubberband)
2409 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2410 icon_view->priv->rubberband_device);
2412 icon_view->priv->doing_rubberband = FALSE;
2413 icon_view->priv->rubberband_device = NULL;
2415 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2419 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2422 gint x, y, width, height;
2423 gboolean dirty = FALSE;
2425 x = MIN (icon_view->priv->rubberband_x1,
2426 icon_view->priv->rubberband_x2);
2427 y = MIN (icon_view->priv->rubberband_y1,
2428 icon_view->priv->rubberband_y2);
2429 width = ABS (icon_view->priv->rubberband_x1 -
2430 icon_view->priv->rubberband_x2);
2431 height = ABS (icon_view->priv->rubberband_y1 -
2432 icon_view->priv->rubberband_y2);
2434 for (items = icon_view->priv->items; items; items = items->next)
2436 GtkIconViewItem *item = items->data;
2440 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2441 x, y, width, height);
2443 selected = is_in ^ item->selected_before_rubberbanding;
2445 if (item->selected != selected)
2447 item->selected = selected;
2449 gtk_icon_view_queue_draw_item (icon_view, item);
2454 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2458 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2459 GtkIconViewItem *item,
2468 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2469 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2472 for (l = icon_view->priv->cell_list; l; l = l->next)
2474 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2476 if (!gtk_cell_renderer_get_visible (info->cell))
2479 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2481 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2482 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2490 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2492 gboolean dirty = FALSE;
2495 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2498 for (items = icon_view->priv->items; items; items = items->next)
2500 GtkIconViewItem *item = items->data;
2504 item->selected = FALSE;
2506 gtk_icon_view_queue_draw_item (icon_view, item);
2507 gtk_icon_view_item_selected_changed (icon_view, item);
2515 /* GtkIconView signals */
2517 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2518 GtkAdjustment *hadj,
2519 GtkAdjustment *vadj)
2521 gboolean need_adjust = FALSE;
2524 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2526 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2528 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2530 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2532 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2534 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2535 0, 0, NULL, NULL, icon_view);
2536 g_object_unref (icon_view->priv->hadjustment);
2539 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2541 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2542 0, 0, NULL, NULL, icon_view);
2543 g_object_unref (icon_view->priv->vadjustment);
2546 if (icon_view->priv->hadjustment != hadj)
2548 icon_view->priv->hadjustment = hadj;
2549 g_object_ref_sink (icon_view->priv->hadjustment);
2551 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2552 G_CALLBACK (gtk_icon_view_adjustment_changed),
2557 if (icon_view->priv->vadjustment != vadj)
2559 icon_view->priv->vadjustment = vadj;
2560 g_object_ref_sink (icon_view->priv->vadjustment);
2562 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2563 G_CALLBACK (gtk_icon_view_adjustment_changed),
2569 gtk_icon_view_adjustment_changed (NULL, icon_view);
2573 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2575 gtk_icon_view_select_all (icon_view);
2579 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2581 gtk_icon_view_unselect_all (icon_view);
2585 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2587 gtk_icon_view_unselect_all (icon_view);
2589 if (icon_view->priv->cursor_item != NULL)
2590 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2594 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2597 GtkCellRendererMode mode;
2598 GtkIconViewCellInfo *info = NULL;
2600 if (!icon_view->priv->cursor_item)
2603 info = g_list_nth_data (icon_view->priv->cell_list,
2604 icon_view->priv->cursor_cell);
2608 g_object_get (info->cell, "mode", &mode, NULL);
2610 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2612 gtk_icon_view_item_activate_cell (icon_view,
2613 icon_view->priv->cursor_item,
2617 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2619 gtk_icon_view_start_editing (icon_view,
2620 icon_view->priv->cursor_item,
2626 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2627 gtk_icon_view_item_activated (icon_view, path);
2628 gtk_tree_path_free (path);
2634 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2636 if (!icon_view->priv->cursor_item)
2639 switch (icon_view->priv->selection_mode)
2641 case GTK_SELECTION_NONE:
2643 case GTK_SELECTION_BROWSE:
2644 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2646 case GTK_SELECTION_SINGLE:
2647 if (icon_view->priv->cursor_item->selected)
2648 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2650 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2652 case GTK_SELECTION_MULTIPLE:
2653 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2654 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2656 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2657 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2662 /* Internal functions */
2664 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2665 GtkIconView *icon_view)
2667 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2669 gdk_window_move (icon_view->priv->bin_window,
2670 - icon_view->priv->hadjustment->value,
2671 - icon_view->priv->vadjustment->value);
2673 if (icon_view->priv->doing_rubberband)
2674 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2676 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2681 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2686 gint *maximum_width)
2689 gint x, current_width;
2690 GList *items, *last_item;
2697 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2698 max_height = g_new0 (gint, icon_view->priv->n_cells);
2705 gtk_widget_style_get (GTK_WIDGET (icon_view),
2706 "focus-line-width", &focus_width,
2709 x += icon_view->priv->margin + focus_width;
2710 current_width += 2 * (icon_view->priv->margin + focus_width);
2715 GtkIconViewItem *item = items->data;
2717 gtk_icon_view_calculate_item_size (icon_view, item);
2718 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2720 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2722 current_width += item->width;
2724 if (items != first_item)
2726 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2727 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2731 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2733 item->y = *y + focus_width;
2736 x = current_width - (icon_view->priv->margin + focus_width);
2738 for (i = 0; i < icon_view->priv->n_cells; i++)
2739 max_height[i] = MAX (max_height[i], item->box[i].height);
2741 if (current_width > *maximum_width)
2742 *maximum_width = current_width;
2748 items = items->next;
2753 /* Now go through the row again and align the icons */
2754 for (items = first_item; items != last_item; items = items->next)
2756 GtkIconViewItem *item = items->data;
2760 item->x = *maximum_width - item->width - item->x;
2761 item->col = col - 1 - item->col;
2764 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2766 /* We may want to readjust the new y coordinate. */
2767 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2768 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2771 g_free (max_height);
2777 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2780 if (upper != adj->upper)
2782 gdouble min = MAX (0.0, upper - adj->page_size);
2783 gboolean value_changed = FALSE;
2787 if (adj->value > min)
2790 value_changed = TRUE;
2793 gtk_adjustment_changed (adj);
2796 gtk_adjustment_value_changed (adj);
2801 gtk_icon_view_layout (GtkIconView *icon_view)
2803 gint y = 0, maximum_width = 0;
2809 if (icon_view->priv->layout_idle_id != 0)
2811 g_source_remove (icon_view->priv->layout_idle_id);
2812 icon_view->priv->layout_idle_id = 0;
2815 if (icon_view->priv->model == NULL)
2818 widget = GTK_WIDGET (icon_view);
2820 item_width = icon_view->priv->item_width;
2824 for (icons = icon_view->priv->items; icons; icons = icons->next)
2826 GtkIconViewItem *item = icons->data;
2827 gtk_icon_view_calculate_item_size (icon_view, item);
2828 item_width = MAX (item_width, item->width);
2833 icons = icon_view->priv->items;
2834 y += icon_view->priv->margin;
2839 gtk_icon_view_set_cell_data (icon_view, icons->data);
2840 adjust_wrap_width (icon_view, icons->data);
2845 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2847 &y, &maximum_width);
2850 while (icons != NULL);
2852 if (maximum_width != icon_view->priv->width)
2853 icon_view->priv->width = maximum_width;
2855 y += icon_view->priv->margin;
2857 if (y != icon_view->priv->height)
2858 icon_view->priv->height = y;
2860 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2861 icon_view->priv->width);
2862 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2863 icon_view->priv->height);
2865 if (icon_view->priv->width != widget->requisition.width ||
2866 icon_view->priv->height != widget->requisition.height)
2867 gtk_widget_queue_resize_no_redraw (widget);
2869 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2870 gdk_window_resize (icon_view->priv->bin_window,
2871 MAX (icon_view->priv->width, widget->allocation.width),
2872 MAX (icon_view->priv->height, widget->allocation.height));
2874 if (icon_view->priv->scroll_to_path)
2878 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2879 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2880 icon_view->priv->scroll_to_path = NULL;
2882 gtk_icon_view_scroll_to_path (icon_view, path,
2883 icon_view->priv->scroll_to_use_align,
2884 icon_view->priv->scroll_to_row_align,
2885 icon_view->priv->scroll_to_col_align);
2886 gtk_tree_path_free (path);
2889 gtk_widget_queue_draw (widget);
2893 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2894 GtkIconViewItem *item,
2895 GtkIconViewCellInfo *info,
2896 GdkRectangle *cell_area)
2898 g_return_if_fail (info->position < item->n_cells);
2900 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
2902 cell_area->x = item->box[info->position].x - item->before[info->position];
2903 cell_area->y = item->y + icon_view->priv->item_padding;
2904 cell_area->width = item->box[info->position].width +
2905 item->before[info->position] + item->after[info->position];
2906 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2910 cell_area->x = item->x + icon_view->priv->item_padding;
2911 cell_area->y = item->box[info->position].y - item->before[info->position];
2912 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2913 cell_area->height = item->box[info->position].height +
2914 item->before[info->position] + item->after[info->position];
2919 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2920 GtkIconViewItem *item,
2921 GtkIconViewCellInfo *info,
2924 g_return_if_fail (info->position < item->n_cells);
2926 *box = item->box[info->position];
2929 /* try to guess a reasonable wrap width for an implicit text cell renderer
2932 adjust_wrap_width (GtkIconView *icon_view,
2933 GtkIconViewItem *item)
2935 GtkIconViewCellInfo *text_info;
2936 GtkIconViewCellInfo *pixbuf_info;
2937 gint pixbuf_width, wrap_width;
2939 if (icon_view->priv->text_cell != -1 &&
2940 icon_view->priv->pixbuf_cell != -1)
2944 text_info = g_list_nth_data (icon_view->priv->cell_list,
2945 icon_view->priv->text_cell);
2946 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2947 icon_view->priv->pixbuf_cell);
2949 gtk_cell_renderer_get_size (pixbuf_info->cell,
2950 GTK_WIDGET (icon_view),
2956 if (icon_view->priv->item_width > 0)
2957 item_width = icon_view->priv->item_width;
2959 item_width = item->width;
2961 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
2962 wrap_width = item_width;
2964 if (item->width == -1 && item_width <= 0)
2965 wrap_width = MAX (2 * pixbuf_width, 50);
2967 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2970 wrap_width -= icon_view->priv->item_padding * 2;
2972 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2973 g_object_set (text_info->cell, "width", wrap_width, NULL);
2978 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2979 GtkIconViewItem *item)
2984 if (item->width != -1 && item->height != -1)
2987 if (item->n_cells != icon_view->priv->n_cells)
2989 g_free (item->before);
2990 g_free (item->after);
2993 item->before = g_new0 (gint, icon_view->priv->n_cells);
2994 item->after = g_new0 (gint, icon_view->priv->n_cells);
2995 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2997 item->n_cells = icon_view->priv->n_cells;
3000 gtk_icon_view_set_cell_data (icon_view, item);
3002 spacing = icon_view->priv->spacing;
3006 for (l = icon_view->priv->cell_list; l; l = l->next)
3008 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3010 if (!gtk_cell_renderer_get_visible (info->cell))
3013 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3015 &item->box[info->position].width,
3016 &item->box[info->position].height);
3018 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3020 item->width += item->box[info->position].width
3021 + (info->position > 0 ? spacing : 0);
3022 item->height = MAX (item->height, item->box[info->position].height);
3026 item->width = MAX (item->width, item->box[info->position].width);
3027 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3031 item->width += icon_view->priv->item_padding * 2;
3032 item->height += icon_view->priv->item_padding * 2;
3036 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3037 GtkIconViewItem *item,
3040 GdkRectangle cell_area;
3046 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3048 gtk_icon_view_set_cell_data (icon_view, item);
3050 spacing = icon_view->priv->spacing;
3053 for (i = 0; i < icon_view->priv->n_cells; i++)
3055 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3056 item->height = MAX (item->height, max_height[i]);
3058 item->height += max_height[i] + (i > 0 ? spacing : 0);
3061 cell_area.x = item->x + icon_view->priv->item_padding;
3062 cell_area.y = item->y + icon_view->priv->item_padding;
3064 for (k = 0; k < 2; k++)
3065 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3067 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3069 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3072 if (!gtk_cell_renderer_get_visible (info->cell))
3075 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3077 /* We should not subtract icon_view->priv->item_padding from item->height,
3078 * because item->height is recalculated above using
3079 * max_height which does not contain item padding.
3081 cell_area.width = item->box[info->position].width;
3082 cell_area.height = item->height;
3086 /* item->width is not recalculated and thus needs to be
3087 * corrected for the padding.
3089 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3090 cell_area.height = max_height[i];
3093 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3095 &item->box[info->position].x, &item->box[info->position].y,
3096 &item->box[info->position].width, &item->box[info->position].height);
3098 item->box[info->position].x += cell_area.x;
3099 item->box[info->position].y += cell_area.y;
3100 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3102 item->before[info->position] = item->box[info->position].x - cell_area.x;
3103 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3104 cell_area.x += cell_area.width + spacing;
3108 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3110 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3111 cell_area.width = item->width;
3113 item->before[info->position] = item->box[info->position].y - cell_area.y;
3114 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3115 cell_area.y += cell_area.height + spacing;
3119 if (rtl && icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3121 for (i = 0; i < icon_view->priv->n_cells; i++)
3123 item->box[i].x = item->x + item->width -
3124 (item->box[i].x + item->box[i].width - item->x);
3128 item->height += icon_view->priv->item_padding * 2;
3132 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3134 g_list_foreach (icon_view->priv->items,
3135 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3139 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3146 gtk_icon_view_paint_item (GtkIconView *icon_view,
3148 GtkIconViewItem *item,
3150 GdkDrawable *drawable,
3153 gboolean draw_focus)
3157 GdkRectangle cell_area, box;
3161 GtkCellRendererState flags;
3163 if (icon_view->priv->model == NULL)
3166 gtk_icon_view_set_cell_data (icon_view, item);
3168 gtk_widget_style_get (GTK_WIDGET (icon_view),
3169 "focus-line-width", &focus_width,
3172 padding = focus_width;
3176 flags = GTK_CELL_RENDERER_SELECTED;
3177 if (gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3178 state = GTK_STATE_SELECTED;
3180 state = GTK_STATE_ACTIVE;
3185 state = GTK_STATE_NORMAL;
3190 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3191 (GdkWindow *) drawable,
3195 GTK_WIDGET (icon_view),
3198 item->width, item->height);
3201 for (l = icon_view->priv->cell_list; l; l = l->next)
3203 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3205 if (!gtk_cell_renderer_get_visible (info->cell))
3208 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3210 cell_area.x = x - item->x + cell_area.x;
3211 cell_area.y = y - item->y + cell_area.y;
3213 gtk_cell_renderer_render (info->cell,
3215 GTK_WIDGET (icon_view),
3216 &cell_area, &cell_area, area, flags);
3220 gtk_widget_has_focus (GTK_WIDGET (icon_view)) &&
3221 item == icon_view->priv->cursor_item)
3223 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3225 GtkCellRendererMode mode;
3226 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3228 if (!gtk_cell_renderer_get_visible (info->cell))
3231 /* If found a editable/activatable cell, draw focus on it. */
3232 g_object_get (info->cell, "mode", &mode, NULL);
3233 if (icon_view->priv->cursor_cell < 0 &&
3234 mode != GTK_CELL_RENDERER_MODE_INERT)
3235 icon_view->priv->cursor_cell = i;
3237 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3239 if (i == icon_view->priv->cursor_cell)
3241 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3245 GTK_WIDGET (icon_view),
3247 x - item->x + box.x - padding,
3248 y - item->y + box.y - padding,
3249 box.width + 2 * padding,
3250 box.height + 2 * padding);
3255 /* If there are no editable/activatable cells, draw focus
3256 * around the whole item.
3258 if (icon_view->priv->cursor_cell < 0)
3259 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3263 GTK_WIDGET (icon_view),
3267 item->width + 2 * padding,
3268 item->height + 2 * padding);
3273 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3278 GdkRectangle rubber_rect;
3279 GdkColor *fill_color_gdk;
3280 guchar fill_color_alpha;
3282 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3283 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3284 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3285 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3287 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3290 gtk_widget_style_get (GTK_WIDGET (icon_view),
3291 "selection-box-color", &fill_color_gdk,
3292 "selection-box-alpha", &fill_color_alpha,
3295 if (!fill_color_gdk)
3296 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3298 cairo_set_source_rgba (cr,
3299 fill_color_gdk->red / 65535.,
3300 fill_color_gdk->green / 65535.,
3301 fill_color_gdk->blue / 65535.,
3302 fill_color_alpha / 255.);
3305 gdk_cairo_rectangle (cr, &rect);
3309 /* Draw the border without alpha */
3310 cairo_set_source_rgb (cr,
3311 fill_color_gdk->red / 65535.,
3312 fill_color_gdk->green / 65535.,
3313 fill_color_gdk->blue / 65535.);
3314 cairo_rectangle (cr,
3315 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3316 rubber_rect.width - 1, rubber_rect.height - 1);
3320 gdk_color_free (fill_color_gdk);
3324 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3330 index = gtk_tree_path_get_indices (path)[0];
3332 for (l = icon_view->priv->items; l; l = l->next)
3334 GtkIconViewItem *item = l->data;
3336 if (item->index == index)
3338 gtk_icon_view_queue_draw_item (icon_view, item);
3345 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3346 GtkIconViewItem *item)
3351 gtk_widget_style_get (GTK_WIDGET (icon_view),
3352 "focus-line-width", &focus_width,
3355 rect.x = item->x - focus_width;
3356 rect.y = item->y - focus_width;
3357 rect.width = item->width + 2 * focus_width;
3358 rect.height = item->height + 2 * focus_width;
3360 if (icon_view->priv->bin_window)
3361 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3365 layout_callback (gpointer user_data)
3367 GtkIconView *icon_view;
3369 icon_view = GTK_ICON_VIEW (user_data);
3371 icon_view->priv->layout_idle_id = 0;
3373 gtk_icon_view_layout (icon_view);
3379 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3381 if (icon_view->priv->layout_idle_id != 0)
3384 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3388 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3389 GtkIconViewItem *item,
3393 AtkObject *item_obj;
3394 AtkObject *cursor_item_obj;
3396 if (icon_view->priv->cursor_item == item &&
3397 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3400 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3401 if (icon_view->priv->cursor_item != NULL)
3403 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3406 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3407 if (cursor_item_obj != NULL)
3408 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3411 icon_view->priv->cursor_item = item;
3412 if (cursor_cell >= 0)
3413 icon_view->priv->cursor_cell = cursor_cell;
3415 gtk_icon_view_queue_draw_item (icon_view, item);
3417 /* Notify that accessible focus object has changed */
3418 item_obj = atk_object_ref_accessible_child (obj, item->index);
3420 if (item_obj != NULL)
3422 atk_focus_tracker_notify (item_obj);
3423 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3424 g_object_unref (item_obj);
3429 static GtkIconViewItem *
3430 gtk_icon_view_item_new (void)
3432 GtkIconViewItem *item;
3434 item = g_new0 (GtkIconViewItem, 1);
3443 gtk_icon_view_item_free (GtkIconViewItem *item)
3445 g_return_if_fail (item != NULL);
3447 g_free (item->before);
3448 g_free (item->after);
3455 static GtkIconViewItem *
3456 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3459 gboolean only_in_cell,
3460 GtkIconViewCellInfo **cell_at_pos)
3466 *cell_at_pos = NULL;
3468 for (items = icon_view->priv->items; items; items = items->next)
3470 GtkIconViewItem *item = items->data;
3472 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3473 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3475 if (only_in_cell || cell_at_pos)
3477 gtk_icon_view_set_cell_data (icon_view, item);
3479 for (l = icon_view->priv->cell_list; l; l = l->next)
3481 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3483 if (!gtk_cell_renderer_get_visible (info->cell))
3486 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3488 if ((x >= box.x && x <= box.x + box.width &&
3489 y >= box.y && y <= box.y + box.height) ||
3491 x <= box.x + box.width &&
3493 y <= box.y + box.height))
3496 *cell_at_pos = info;
3514 gtk_icon_view_select_item (GtkIconView *icon_view,
3515 GtkIconViewItem *item)
3517 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3518 g_return_if_fail (item != NULL);
3523 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3525 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3526 gtk_icon_view_unselect_all_internal (icon_view);
3528 item->selected = TRUE;
3530 gtk_icon_view_item_selected_changed (icon_view, item);
3531 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3533 gtk_icon_view_queue_draw_item (icon_view, item);
3538 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3539 GtkIconViewItem *item)
3541 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3542 g_return_if_fail (item != NULL);
3544 if (!item->selected)
3547 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3548 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3551 item->selected = FALSE;
3553 gtk_icon_view_item_selected_changed (icon_view, item);
3554 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3556 gtk_icon_view_queue_draw_item (icon_view, item);
3560 verify_items (GtkIconView *icon_view)
3565 for (items = icon_view->priv->items; items; items = items->next)
3567 GtkIconViewItem *item = items->data;
3569 if (item->index != i)
3570 g_error ("List item does not match its index: "
3571 "item index %d and list index %d\n", item->index, i);
3578 gtk_icon_view_row_changed (GtkTreeModel *model,
3583 GtkIconViewItem *item;
3585 GtkIconView *icon_view;
3587 icon_view = GTK_ICON_VIEW (data);
3589 gtk_icon_view_stop_editing (icon_view, TRUE);
3591 index = gtk_tree_path_get_indices(path)[0];
3592 item = g_list_nth_data (icon_view->priv->items, index);
3594 gtk_icon_view_item_invalidate_size (item);
3595 gtk_icon_view_queue_layout (icon_view);
3597 verify_items (icon_view);
3601 gtk_icon_view_row_inserted (GtkTreeModel *model,
3607 GtkIconViewItem *item;
3608 gboolean iters_persist;
3609 GtkIconView *icon_view;
3612 icon_view = GTK_ICON_VIEW (data);
3614 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3616 index = gtk_tree_path_get_indices(path)[0];
3618 item = gtk_icon_view_item_new ();
3623 item->index = index;
3625 /* FIXME: We can be more efficient here,
3626 we can store a tail pointer and use that when
3627 appending (which is a rather common operation)
3629 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3632 list = g_list_nth (icon_view->priv->items, index + 1);
3633 for (; list; list = list->next)
3640 verify_items (icon_view);
3642 gtk_icon_view_queue_layout (icon_view);
3646 gtk_icon_view_row_deleted (GtkTreeModel *model,
3651 GtkIconView *icon_view;
3652 GtkIconViewItem *item;
3654 gboolean emit = FALSE;
3656 icon_view = GTK_ICON_VIEW (data);
3658 index = gtk_tree_path_get_indices(path)[0];
3660 list = g_list_nth (icon_view->priv->items, index);
3663 gtk_icon_view_stop_editing (icon_view, TRUE);
3665 if (item == icon_view->priv->anchor_item)
3666 icon_view->priv->anchor_item = NULL;
3668 if (item == icon_view->priv->cursor_item)
3669 icon_view->priv->cursor_item = NULL;
3674 gtk_icon_view_item_free (item);
3676 for (next = list->next; next; next = next->next)
3683 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3685 verify_items (icon_view);
3687 gtk_icon_view_queue_layout (icon_view);
3690 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3694 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3695 GtkTreePath *parent,
3702 GtkIconView *icon_view;
3703 GList *items = NULL, *list;
3704 GtkIconViewItem **item_array;
3707 icon_view = GTK_ICON_VIEW (data);
3709 gtk_icon_view_stop_editing (icon_view, TRUE);
3711 length = gtk_tree_model_iter_n_children (model, NULL);
3713 order = g_new (gint, length);
3714 for (i = 0; i < length; i++)
3715 order [new_order[i]] = i;
3717 item_array = g_new (GtkIconViewItem *, length);
3718 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3719 item_array[order[i]] = list->data;
3722 for (i = length - 1; i >= 0; i--)
3724 item_array[i]->index = i;
3725 items = g_list_prepend (items, item_array[i]);
3728 g_free (item_array);
3729 g_list_free (icon_view->priv->items);
3730 icon_view->priv->items = items;
3732 gtk_icon_view_queue_layout (icon_view);
3734 verify_items (icon_view);
3738 gtk_icon_view_build_items (GtkIconView *icon_view)
3742 gboolean iters_persist;
3743 GList *items = NULL;
3745 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3747 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3755 GtkIconViewItem *item = gtk_icon_view_item_new ();
3764 items = g_list_prepend (items, item);
3766 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3768 icon_view->priv->items = g_list_reverse (items);
3772 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3775 GtkMovementStep step,
3779 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3780 I_("move-cursor"), 2,
3784 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3789 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3792 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3797 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3804 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3805 GtkMovementStep step,
3808 GdkModifierType state;
3810 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3811 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3812 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3813 step == GTK_MOVEMENT_DISPLAY_LINES ||
3814 step == GTK_MOVEMENT_PAGES ||
3815 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3817 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3820 gtk_icon_view_stop_editing (icon_view, FALSE);
3821 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3823 if (gtk_get_current_event_state (&state))
3825 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3826 icon_view->priv->ctrl_pressed = TRUE;
3827 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3828 icon_view->priv->shift_pressed = TRUE;
3830 /* else we assume not pressed */
3834 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3835 case GTK_MOVEMENT_VISUAL_POSITIONS:
3836 gtk_icon_view_move_cursor_left_right (icon_view, count);
3838 case GTK_MOVEMENT_DISPLAY_LINES:
3839 gtk_icon_view_move_cursor_up_down (icon_view, count);
3841 case GTK_MOVEMENT_PAGES:
3842 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3844 case GTK_MOVEMENT_BUFFER_ENDS:
3845 gtk_icon_view_move_cursor_start_end (icon_view, count);
3848 g_assert_not_reached ();
3851 icon_view->priv->ctrl_pressed = FALSE;
3852 icon_view->priv->shift_pressed = FALSE;
3854 icon_view->priv->draw_focus = TRUE;
3859 static GtkIconViewItem *
3860 find_item (GtkIconView *icon_view,
3861 GtkIconViewItem *current,
3867 GtkIconViewItem *item;
3869 /* FIXME: this could be more efficient
3871 row = current->row + row_ofs;
3872 col = current->col + col_ofs;
3874 for (items = icon_view->priv->items; items; items = items->next)
3877 if (item->row == row && item->col == col)
3885 find_cell (GtkIconView *icon_view,
3886 GtkIconViewItem *item,
3888 GtkOrientation orientation,
3898 if (icon_view->priv->item_orientation != orientation)
3901 gtk_icon_view_set_cell_data (icon_view, item);
3903 focusable = g_new0 (gint, icon_view->priv->n_cells);
3907 for (k = 0; k < 2; k++)
3908 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3910 GtkCellRendererMode mode;
3911 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3913 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3916 if (!gtk_cell_renderer_get_visible (info->cell))
3919 g_object_get (info->cell, "mode", &mode, NULL);
3920 if (mode != GTK_CELL_RENDERER_MODE_INERT)
3923 current = n_focusable;
3925 focusable[n_focusable] = i;
3931 if (n_focusable == 0)
3939 current = step > 0 ? 0 : n_focusable - 1;
3940 cell = focusable[current];
3943 if (current + *count < 0)
3946 *count = current + *count;
3948 else if (current + *count > n_focusable - 1)
3951 *count = current + *count - (n_focusable - 1);
3955 cell = focusable[current + *count];
3964 static GtkIconViewItem *
3965 find_item_page_up_down (GtkIconView *icon_view,
3966 GtkIconViewItem *current,
3973 y = current->y + count * icon_view->priv->vadjustment->page_size;
3975 item = g_list_find (icon_view->priv->items, current);
3980 for (next = item->next; next; next = next->next)
3982 if (((GtkIconViewItem *)next->data)->col == col)
3985 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3995 for (next = item->prev; next; next = next->prev)
3997 if (((GtkIconViewItem *)next->data)->col == col)
4000 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4014 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4015 GtkIconViewItem *anchor,
4016 GtkIconViewItem *cursor)
4019 GtkIconViewItem *item;
4020 gint row1, row2, col1, col2;
4021 gboolean dirty = FALSE;
4023 if (anchor->row < cursor->row)
4034 if (anchor->col < cursor->col)
4045 for (items = icon_view->priv->items; items; items = items->next)
4049 if (row1 <= item->row && item->row <= row2 &&
4050 col1 <= item->col && item->col <= col2)
4052 if (!item->selected)
4055 item->selected = TRUE;
4056 gtk_icon_view_item_selected_changed (icon_view, item);
4058 gtk_icon_view_queue_draw_item (icon_view, item);
4066 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4069 GtkIconViewItem *item;
4071 gboolean dirty = FALSE;
4073 GtkDirectionType direction;
4075 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4078 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4080 if (!icon_view->priv->cursor_item)
4085 list = icon_view->priv->items;
4087 list = g_list_last (icon_view->priv->items);
4089 item = list ? list->data : NULL;
4094 item = icon_view->priv->cursor_item;
4095 cell = icon_view->priv->cursor_cell;
4096 step = count > 0 ? 1 : -1;
4099 cell = find_cell (icon_view, item, cell,
4100 GTK_ORIENTATION_VERTICAL,
4105 item = find_item (icon_view, item, step, 0);
4106 count = count - step;
4112 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4114 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4116 gtk_widget_child_focus (toplevel,
4117 direction == GTK_DIR_UP ?
4118 GTK_DIR_TAB_BACKWARD :
4119 GTK_DIR_TAB_FORWARD);
4125 if (icon_view->priv->ctrl_pressed ||
4126 !icon_view->priv->shift_pressed ||
4127 !icon_view->priv->anchor_item ||
4128 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4129 icon_view->priv->anchor_item = item;
4131 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4133 if (!icon_view->priv->ctrl_pressed &&
4134 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4136 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4137 dirty = gtk_icon_view_select_all_between (icon_view,
4138 icon_view->priv->anchor_item,
4142 gtk_icon_view_scroll_to_item (icon_view, item);
4145 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4149 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4152 GtkIconViewItem *item;
4153 gboolean dirty = FALSE;
4155 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4158 if (!icon_view->priv->cursor_item)
4163 list = icon_view->priv->items;
4165 list = g_list_last (icon_view->priv->items);
4167 item = list ? list->data : NULL;
4170 item = find_item_page_up_down (icon_view,
4171 icon_view->priv->cursor_item,
4174 if (item == icon_view->priv->cursor_item)
4175 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4180 if (icon_view->priv->ctrl_pressed ||
4181 !icon_view->priv->shift_pressed ||
4182 !icon_view->priv->anchor_item ||
4183 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4184 icon_view->priv->anchor_item = item;
4186 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4188 if (!icon_view->priv->ctrl_pressed &&
4189 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4191 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4192 dirty = gtk_icon_view_select_all_between (icon_view,
4193 icon_view->priv->anchor_item,
4197 gtk_icon_view_scroll_to_item (icon_view, item);
4200 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4204 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4207 GtkIconViewItem *item;
4209 gboolean dirty = FALSE;
4211 GtkDirectionType direction;
4213 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4216 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4218 if (!icon_view->priv->cursor_item)
4223 list = icon_view->priv->items;
4225 list = g_list_last (icon_view->priv->items);
4227 item = list ? list->data : NULL;
4231 item = icon_view->priv->cursor_item;
4232 cell = icon_view->priv->cursor_cell;
4233 step = count > 0 ? 1 : -1;
4236 cell = find_cell (icon_view, item, cell,
4237 GTK_ORIENTATION_HORIZONTAL,
4242 item = find_item (icon_view, item, 0, step);
4243 count = count - step;
4249 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4251 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4253 gtk_widget_child_focus (toplevel,
4254 direction == GTK_DIR_LEFT ?
4255 GTK_DIR_TAB_BACKWARD :
4256 GTK_DIR_TAB_FORWARD);
4262 if (icon_view->priv->ctrl_pressed ||
4263 !icon_view->priv->shift_pressed ||
4264 !icon_view->priv->anchor_item ||
4265 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4266 icon_view->priv->anchor_item = item;
4268 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4270 if (!icon_view->priv->ctrl_pressed &&
4271 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4273 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4274 dirty = gtk_icon_view_select_all_between (icon_view,
4275 icon_view->priv->anchor_item,
4279 gtk_icon_view_scroll_to_item (icon_view, item);
4282 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4286 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4289 GtkIconViewItem *item;
4291 gboolean dirty = FALSE;
4293 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4297 list = icon_view->priv->items;
4299 list = g_list_last (icon_view->priv->items);
4301 item = list ? list->data : NULL;
4303 if (item == icon_view->priv->cursor_item)
4304 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4309 if (icon_view->priv->ctrl_pressed ||
4310 !icon_view->priv->shift_pressed ||
4311 !icon_view->priv->anchor_item ||
4312 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4313 icon_view->priv->anchor_item = item;
4315 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4317 if (!icon_view->priv->ctrl_pressed &&
4318 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4320 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4321 dirty = gtk_icon_view_select_all_between (icon_view,
4322 icon_view->priv->anchor_item,
4326 gtk_icon_view_scroll_to_item (icon_view, item);
4329 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4333 * gtk_icon_view_scroll_to_path:
4334 * @icon_view: A #GtkIconView.
4335 * @path: The path of the item to move to.
4336 * @use_align: whether to use alignment arguments, or %FALSE.
4337 * @row_align: The vertical alignment of the item specified by @path.
4338 * @col_align: The horizontal alignment of the item specified by @path.
4340 * Moves the alignments of @icon_view to the position specified by @path.
4341 * @row_align determines where the row is placed, and @col_align determines
4342 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4343 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4346 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4347 * tree does the minimum amount of work to scroll the item onto the screen.
4348 * This means that the item will be scrolled to the edge closest to its current
4349 * position. If the item is currently visible on the screen, nothing is done.
4351 * This function only works if the model is set, and @path is a valid row on
4352 * the model. If the model changes before the @icon_view is realized, the
4353 * centered path will be modified to reflect this change.
4358 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4364 GtkIconViewItem *item = NULL;
4366 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4367 g_return_if_fail (path != NULL);
4368 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4369 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4371 if (gtk_tree_path_get_depth (path) > 0)
4372 item = g_list_nth_data (icon_view->priv->items,
4373 gtk_tree_path_get_indices(path)[0]);
4375 if (!item || item->width < 0 ||
4376 !gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4378 if (icon_view->priv->scroll_to_path)
4379 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4381 icon_view->priv->scroll_to_path = NULL;
4384 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4386 icon_view->priv->scroll_to_use_align = use_align;
4387 icon_view->priv->scroll_to_row_align = row_align;
4388 icon_view->priv->scroll_to_col_align = col_align;
4399 gtk_widget_style_get (GTK_WIDGET (icon_view),
4400 "focus-line-width", &focus_width,
4403 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4405 offset = y + item->y - focus_width -
4406 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4408 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4409 icon_view->priv->vadjustment->value + offset);
4411 offset = x + item->x - focus_width -
4412 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4414 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4415 icon_view->priv->hadjustment->value + offset);
4417 gtk_adjustment_changed (icon_view->priv->hadjustment);
4418 gtk_adjustment_changed (icon_view->priv->vadjustment);
4421 gtk_icon_view_scroll_to_item (icon_view, item);
4426 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4427 GtkIconViewItem *item)
4429 gint x, y, width, height;
4432 gtk_widget_style_get (GTK_WIDGET (icon_view),
4433 "focus-line-width", &focus_width,
4436 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4438 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4440 if (y + item->y - focus_width < 0)
4441 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4442 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4443 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4444 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4445 icon_view->priv->vadjustment->value + y + item->y + item->height
4446 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4448 if (x + item->x - focus_width < 0)
4449 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4450 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4451 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4452 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4453 icon_view->priv->hadjustment->value + x + item->x + item->width
4454 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4456 gtk_adjustment_changed (icon_view->priv->hadjustment);
4457 gtk_adjustment_changed (icon_view->priv->vadjustment);
4460 /* GtkCellLayout implementation */
4461 static GtkIconViewCellInfo *
4462 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4463 GtkCellRenderer *renderer)
4467 for (i = icon_view->priv->cell_list; i; i = i->next)
4469 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4471 if (info->cell == renderer)
4479 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4480 GtkIconViewItem *item)
4483 gboolean iters_persist;
4486 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4492 path = gtk_tree_path_new_from_indices (item->index, -1);
4493 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4495 gtk_tree_path_free (path);
4500 for (i = icon_view->priv->cell_list; i; i = i->next)
4503 GtkIconViewCellInfo *info = i->data;
4505 g_object_freeze_notify (G_OBJECT (info->cell));
4507 for (j = info->attributes; j && j->next; j = j->next->next)
4509 gchar *property = j->data;
4510 gint column = GPOINTER_TO_INT (j->next->data);
4511 GValue value = {0, };
4513 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4515 g_object_set_property (G_OBJECT (info->cell),
4517 g_value_unset (&value);
4521 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4523 icon_view->priv->model,
4527 g_object_thaw_notify (G_OBJECT (info->cell));
4532 free_cell_attributes (GtkIconViewCellInfo *info)
4536 list = info->attributes;
4537 while (list && list->next)
4539 g_free (list->data);
4540 list = list->next->next;
4543 g_slist_free (info->attributes);
4544 info->attributes = NULL;
4548 free_cell_info (GtkIconViewCellInfo *info)
4550 free_cell_attributes (info);
4552 g_object_unref (info->cell);
4555 (* info->destroy) (info->func_data);
4561 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4562 GtkCellRenderer *renderer,
4565 GtkIconViewCellInfo *info;
4566 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4568 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4569 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4571 g_object_ref_sink (renderer);
4573 info = g_new0 (GtkIconViewCellInfo, 1);
4574 info->cell = renderer;
4575 info->expand = expand ? TRUE : FALSE;
4576 info->pack = GTK_PACK_START;
4577 info->position = icon_view->priv->n_cells;
4579 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4580 icon_view->priv->n_cells++;
4584 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4585 GtkCellRenderer *renderer,
4588 GtkIconViewCellInfo *info;
4589 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4591 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4592 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4594 g_object_ref_sink (renderer);
4596 info = g_new0 (GtkIconViewCellInfo, 1);
4597 info->cell = renderer;
4598 info->expand = expand ? TRUE : FALSE;
4599 info->pack = GTK_PACK_END;
4600 info->position = icon_view->priv->n_cells;
4602 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4603 icon_view->priv->n_cells++;
4607 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4608 GtkCellRenderer *renderer,
4609 const gchar *attribute,
4612 GtkIconViewCellInfo *info;
4613 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4615 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4616 g_return_if_fail (info != NULL);
4618 info->attributes = g_slist_prepend (info->attributes,
4619 GINT_TO_POINTER (column));
4620 info->attributes = g_slist_prepend (info->attributes,
4621 g_strdup (attribute));
4625 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4627 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4629 while (icon_view->priv->cell_list)
4631 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4632 free_cell_info (info);
4633 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4634 icon_view->priv->cell_list);
4637 icon_view->priv->n_cells = 0;
4641 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4642 GtkCellRenderer *cell,
4643 GtkCellLayoutDataFunc func,
4645 GDestroyNotify destroy)
4647 GtkIconViewCellInfo *info;
4648 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4650 info = gtk_icon_view_get_cell_info (icon_view, cell);
4651 g_return_if_fail (info != NULL);
4655 GDestroyNotify d = info->destroy;
4657 info->destroy = NULL;
4658 d (info->func_data);
4662 info->func_data = func_data;
4663 info->destroy = destroy;
4667 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4668 GtkCellRenderer *renderer)
4670 GtkIconViewCellInfo *info;
4672 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4674 free_cell_attributes (info);
4678 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4679 GtkCellRenderer *cell,
4682 GtkIconView *icon_view;
4684 GtkIconViewCellInfo *info;
4687 icon_view = GTK_ICON_VIEW (layout);
4689 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4691 info = gtk_icon_view_get_cell_info (icon_view, cell);
4693 g_return_if_fail (info != NULL);
4694 g_return_if_fail (position >= 0);
4696 link = g_list_find (icon_view->priv->cell_list, info);
4698 g_return_if_fail (link != NULL);
4700 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4702 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4705 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4712 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4716 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4718 GtkIconView *icon_view = (GtkIconView *)layout;
4719 GList *retval = NULL, *l;
4721 for (l = icon_view->priv->cell_list; l; l = l->next)
4723 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4725 retval = g_list_prepend (retval, info->cell);
4728 return g_list_reverse (retval);
4735 * gtk_icon_view_new:
4737 * Creates a new #GtkIconView widget
4739 * Return value: A newly created #GtkIconView widget
4744 gtk_icon_view_new (void)
4746 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4750 * gtk_icon_view_new_with_model:
4751 * @model: The model.
4753 * Creates a new #GtkIconView widget with the model @model.
4755 * Return value: A newly created #GtkIconView widget.
4760 gtk_icon_view_new_with_model (GtkTreeModel *model)
4762 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4766 * gtk_icon_view_convert_widget_to_bin_window_coords:
4767 * @icon_view: a #GtkIconView
4768 * @wx: X coordinate relative to the widget
4769 * @wy: Y coordinate relative to the widget
4770 * @bx: return location for bin_window X coordinate
4771 * @by: return location for bin_window Y coordinate
4773 * Converts widget coordinates to coordinates for the bin_window,
4774 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4779 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4787 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4789 if (icon_view->priv->bin_window)
4790 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4801 * gtk_icon_view_get_path_at_pos:
4802 * @icon_view: A #GtkIconView.
4803 * @x: The x position to be identified
4804 * @y: The y position to be identified
4806 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4807 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4808 * the cell at the specified position.
4809 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4810 * widget coordinates to bin_window coordinates.
4812 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4813 * if no icon exists at that position.
4818 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4822 GtkIconViewItem *item;
4825 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4827 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4832 path = gtk_tree_path_new_from_indices (item->index, -1);
4838 * gtk_icon_view_get_item_at_pos:
4839 * @icon_view: A #GtkIconView.
4840 * @x: The x position to be identified
4841 * @y: The y position to be identified
4842 * @path: (allow-none): Return location for the path, or %NULL
4843 * @cell: Return location for the renderer responsible for the cell
4844 * at (@x, @y), or %NULL
4846 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4847 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4848 * obtains the cell at the specified position. The returned path should
4849 * be freed with gtk_tree_path_free().
4850 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4851 * widget coordinates to bin_window coordinates.
4853 * Return value: %TRUE if an item exists at the specified position
4858 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4862 GtkCellRenderer **cell)
4864 GtkIconViewItem *item;
4865 GtkIconViewCellInfo *info;
4867 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4869 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4874 *path = gtk_tree_path_new_from_indices (item->index, -1);
4887 return (item != NULL);
4891 * gtk_icon_view_set_tooltip_item:
4892 * @icon_view: a #GtkIconView
4893 * @tooltip: a #GtkTooltip
4894 * @path: a #GtkTreePath
4896 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4897 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4898 * See also gtk_tooltip_set_tip_area().
4903 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4904 GtkTooltip *tooltip,
4907 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4908 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4910 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4914 * gtk_icon_view_set_tooltip_cell:
4915 * @icon_view: a #GtkIconView
4916 * @tooltip: a #GtkTooltip
4917 * @path: a #GtkTreePath
4918 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4920 * Sets the tip area of @tooltip to the area which @cell occupies in
4921 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4923 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4928 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4929 GtkTooltip *tooltip,
4931 GtkCellRenderer *cell)
4934 GtkIconViewItem *item = NULL;
4935 GtkIconViewCellInfo *info = NULL;
4938 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4939 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4940 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4942 if (gtk_tree_path_get_depth (path) > 0)
4943 item = g_list_nth_data (icon_view->priv->items,
4944 gtk_tree_path_get_indices(path)[0]);
4951 info = gtk_icon_view_get_cell_info (icon_view, cell);
4952 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4958 rect.width = item->width;
4959 rect.height = item->height;
4962 if (icon_view->priv->bin_window)
4964 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4969 gtk_tooltip_set_tip_area (tooltip, &rect);
4974 * gtk_icon_view_get_tooltip_context:
4975 * @icon_view: an #GtkIconView
4976 * @x: the x coordinate (relative to widget coordinates)
4977 * @y: the y coordinate (relative to widget coordinates)
4978 * @keyboard_tip: whether this is a keyboard tooltip or not
4979 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4980 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
4981 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4983 * This function is supposed to be used in a #GtkWidget::query-tooltip
4984 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4985 * which are received in the signal handler, should be passed to this
4986 * function without modification.
4988 * The return value indicates whether there is an icon view item at the given
4989 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4990 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4991 * @model, @path and @iter which have been provided will be set to point to
4992 * that row and the corresponding model. @x and @y will always be converted
4993 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4995 * Return value: whether or not the given tooltip context points to a item
5000 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5003 gboolean keyboard_tip,
5004 GtkTreeModel **model,
5008 GtkTreePath *tmppath = NULL;
5010 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5011 g_return_val_if_fail (x != NULL, FALSE);
5012 g_return_val_if_fail (y != NULL, FALSE);
5016 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5023 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5026 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5031 *model = gtk_icon_view_get_model (icon_view);
5034 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5040 gtk_tree_path_free (tmppath);
5046 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5049 gboolean keyboard_tip,
5050 GtkTooltip *tooltip,
5056 GtkTreeModel *model;
5057 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5059 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5062 &model, &path, &iter))
5065 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5069 gtk_tree_path_free (path);
5073 gtk_tooltip_set_markup (tooltip, str);
5074 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5076 gtk_tree_path_free (path);
5084 * gtk_icon_view_set_tooltip_column:
5085 * @icon_view: a #GtkIconView
5086 * @column: an integer, which is a valid column number for @icon_view's model
5088 * If you only plan to have simple (text-only) tooltips on full items, you
5089 * can use this function to have #GtkIconView handle these automatically
5090 * for you. @column should be set to the column in @icon_view's model
5091 * containing the tooltip texts, or -1 to disable this feature.
5093 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5094 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5099 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5102 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5104 if (column == icon_view->priv->tooltip_column)
5109 g_signal_handlers_disconnect_by_func (icon_view,
5110 gtk_icon_view_set_tooltip_query_cb,
5112 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5116 if (icon_view->priv->tooltip_column == -1)
5118 g_signal_connect (icon_view, "query-tooltip",
5119 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5120 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5124 icon_view->priv->tooltip_column = column;
5125 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5129 * gtk_icon_view_get_tooltip_column:
5130 * @icon_view: a #GtkIconView
5132 * Returns the column of @icon_view's model which is being used for
5133 * displaying tooltips on @icon_view's rows.
5135 * Return value: the index of the tooltip column that is currently being
5136 * used, or -1 if this is disabled.
5141 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5143 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5145 return icon_view->priv->tooltip_column;
5149 * gtk_icon_view_get_visible_range:
5150 * @icon_view: A #GtkIconView
5151 * @start_path: (allow-none): Return location for start of region, or %NULL
5152 * @end_path: (allow-none): Return location for end of region, or %NULL
5154 * Sets @start_path and @end_path to be the first and last visible path.
5155 * Note that there may be invisible paths in between.
5157 * Both paths should be freed with gtk_tree_path_free() after use.
5159 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5164 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5165 GtkTreePath **start_path,
5166 GtkTreePath **end_path)
5168 gint start_index = -1;
5169 gint end_index = -1;
5172 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5174 if (icon_view->priv->hadjustment == NULL ||
5175 icon_view->priv->vadjustment == NULL)
5178 if (start_path == NULL && end_path == NULL)
5181 for (icons = icon_view->priv->items; icons; icons = icons->next)
5183 GtkIconViewItem *item = icons->data;
5185 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5186 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5187 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5188 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5190 if (start_index == -1)
5191 start_index = item->index;
5192 end_index = item->index;
5196 if (start_path && start_index != -1)
5197 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5198 if (end_path && end_index != -1)
5199 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5201 return start_index != -1;
5205 * gtk_icon_view_selected_foreach:
5206 * @icon_view: A #GtkIconView.
5207 * @func: The function to call for each selected icon.
5208 * @data: User data to pass to the function.
5210 * Calls a function for each selected icon. Note that the model or
5211 * selection cannot be modified from within this function.
5216 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5217 GtkIconViewForeachFunc func,
5222 for (list = icon_view->priv->items; list; list = list->next)
5224 GtkIconViewItem *item = list->data;
5225 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5228 (* func) (icon_view, path, data);
5230 gtk_tree_path_free (path);
5235 * gtk_icon_view_set_selection_mode:
5236 * @icon_view: A #GtkIconView.
5237 * @mode: The selection mode
5239 * Sets the selection mode of the @icon_view.
5244 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5245 GtkSelectionMode mode)
5247 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5249 if (mode == icon_view->priv->selection_mode)
5252 if (mode == GTK_SELECTION_NONE ||
5253 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5254 gtk_icon_view_unselect_all (icon_view);
5256 icon_view->priv->selection_mode = mode;
5258 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5262 * gtk_icon_view_get_selection_mode:
5263 * @icon_view: A #GtkIconView.
5265 * Gets the selection mode of the @icon_view.
5267 * Return value: the current selection mode
5272 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5274 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5276 return icon_view->priv->selection_mode;
5280 * gtk_icon_view_set_model:
5281 * @icon_view: A #GtkIconView.
5282 * @model: (allow-none): The model.
5284 * Sets the model for a #GtkIconView.
5285 * If the @icon_view already has a model set, it will remove
5286 * it before setting the new model. If @model is %NULL, then
5287 * it will unset the old model.
5292 gtk_icon_view_set_model (GtkIconView *icon_view,
5293 GtkTreeModel *model)
5295 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5296 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5298 if (icon_view->priv->model == model)
5301 if (icon_view->priv->scroll_to_path)
5303 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5304 icon_view->priv->scroll_to_path = NULL;
5307 gtk_icon_view_stop_editing (icon_view, TRUE);
5313 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5315 if (icon_view->priv->pixbuf_column != -1)
5317 column_type = gtk_tree_model_get_column_type (model,
5318 icon_view->priv->pixbuf_column);
5320 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5323 if (icon_view->priv->text_column != -1)
5325 column_type = gtk_tree_model_get_column_type (model,
5326 icon_view->priv->text_column);
5328 g_return_if_fail (column_type == G_TYPE_STRING);
5331 if (icon_view->priv->markup_column != -1)
5333 column_type = gtk_tree_model_get_column_type (model,
5334 icon_view->priv->markup_column);
5336 g_return_if_fail (column_type == G_TYPE_STRING);
5341 if (icon_view->priv->model)
5343 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5344 gtk_icon_view_row_changed,
5346 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5347 gtk_icon_view_row_inserted,
5349 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5350 gtk_icon_view_row_deleted,
5352 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5353 gtk_icon_view_rows_reordered,
5356 g_object_unref (icon_view->priv->model);
5358 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5359 g_list_free (icon_view->priv->items);
5360 icon_view->priv->items = NULL;
5361 icon_view->priv->anchor_item = NULL;
5362 icon_view->priv->cursor_item = NULL;
5363 icon_view->priv->last_single_clicked = NULL;
5364 icon_view->priv->width = 0;
5365 icon_view->priv->height = 0;
5368 icon_view->priv->model = model;
5370 if (icon_view->priv->model)
5372 g_object_ref (icon_view->priv->model);
5373 g_signal_connect (icon_view->priv->model,
5375 G_CALLBACK (gtk_icon_view_row_changed),
5377 g_signal_connect (icon_view->priv->model,
5379 G_CALLBACK (gtk_icon_view_row_inserted),
5381 g_signal_connect (icon_view->priv->model,
5383 G_CALLBACK (gtk_icon_view_row_deleted),
5385 g_signal_connect (icon_view->priv->model,
5387 G_CALLBACK (gtk_icon_view_rows_reordered),
5390 gtk_icon_view_build_items (icon_view);
5392 gtk_icon_view_queue_layout (icon_view);
5395 g_object_notify (G_OBJECT (icon_view), "model");
5397 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5398 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5402 * gtk_icon_view_get_model:
5403 * @icon_view: a #GtkIconView
5405 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5408 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5413 gtk_icon_view_get_model (GtkIconView *icon_view)
5415 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5417 return icon_view->priv->model;
5421 update_text_cell (GtkIconView *icon_view)
5423 GtkIconViewCellInfo *info;
5427 if (icon_view->priv->text_column == -1 &&
5428 icon_view->priv->markup_column == -1)
5430 if (icon_view->priv->text_cell != -1)
5432 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5433 icon_view->priv->pixbuf_cell--;
5435 info = g_list_nth_data (icon_view->priv->cell_list,
5436 icon_view->priv->text_cell);
5438 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5440 free_cell_info (info);
5442 icon_view->priv->n_cells--;
5443 icon_view->priv->text_cell = -1;
5448 if (icon_view->priv->text_cell == -1)
5450 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5451 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5452 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5455 if (info->cell == cell)
5457 icon_view->priv->text_cell = i;
5463 info = g_list_nth_data (icon_view->priv->cell_list,
5464 icon_view->priv->text_cell);
5466 if (icon_view->priv->markup_column != -1)
5467 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5469 "markup", icon_view->priv->markup_column,
5472 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5474 "text", icon_view->priv->text_column,
5477 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5478 g_object_set (info->cell,
5479 "alignment", PANGO_ALIGN_CENTER,
5480 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5485 g_object_set (info->cell,
5486 "alignment", PANGO_ALIGN_LEFT,
5487 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5495 update_pixbuf_cell (GtkIconView *icon_view)
5497 GtkIconViewCellInfo *info;
5501 if (icon_view->priv->pixbuf_column == -1)
5503 if (icon_view->priv->pixbuf_cell != -1)
5505 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5506 icon_view->priv->text_cell--;
5508 info = g_list_nth_data (icon_view->priv->cell_list,
5509 icon_view->priv->pixbuf_cell);
5511 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5513 free_cell_info (info);
5515 icon_view->priv->n_cells--;
5516 icon_view->priv->pixbuf_cell = -1;
5521 if (icon_view->priv->pixbuf_cell == -1)
5523 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5525 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5526 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5529 if (info->cell == cell)
5531 icon_view->priv->pixbuf_cell = i;
5537 info = g_list_nth_data (icon_view->priv->cell_list,
5538 icon_view->priv->pixbuf_cell);
5540 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5542 "pixbuf", icon_view->priv->pixbuf_column,
5545 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5546 g_object_set (info->cell,
5551 g_object_set (info->cell,
5559 * gtk_icon_view_set_text_column:
5560 * @icon_view: A #GtkIconView.
5561 * @column: A column in the currently used model, or -1 to display no text
5563 * Sets the column with text for @icon_view to be @column. The text
5564 * column must be of type #G_TYPE_STRING.
5569 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5572 if (column == icon_view->priv->text_column)
5576 icon_view->priv->text_column = -1;
5579 if (icon_view->priv->model != NULL)
5583 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5585 g_return_if_fail (column_type == G_TYPE_STRING);
5588 icon_view->priv->text_column = column;
5591 gtk_icon_view_stop_editing (icon_view, TRUE);
5593 update_text_cell (icon_view);
5595 gtk_icon_view_invalidate_sizes (icon_view);
5596 gtk_icon_view_queue_layout (icon_view);
5598 g_object_notify (G_OBJECT (icon_view), "text-column");
5602 * gtk_icon_view_get_text_column:
5603 * @icon_view: A #GtkIconView.
5605 * Returns the column with text for @icon_view.
5607 * Returns: the text column, or -1 if it's unset.
5612 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5614 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5616 return icon_view->priv->text_column;
5620 * gtk_icon_view_set_markup_column:
5621 * @icon_view: A #GtkIconView.
5622 * @column: A column in the currently used model, or -1 to display no text
5624 * Sets the column with markup information for @icon_view to be
5625 * @column. The markup column must be of type #G_TYPE_STRING.
5626 * If the markup column is set to something, it overrides
5627 * the text column set by gtk_icon_view_set_text_column().
5632 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5635 if (column == icon_view->priv->markup_column)
5639 icon_view->priv->markup_column = -1;
5642 if (icon_view->priv->model != NULL)
5646 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5648 g_return_if_fail (column_type == G_TYPE_STRING);
5651 icon_view->priv->markup_column = column;
5654 gtk_icon_view_stop_editing (icon_view, TRUE);
5656 update_text_cell (icon_view);
5658 gtk_icon_view_invalidate_sizes (icon_view);
5659 gtk_icon_view_queue_layout (icon_view);
5661 g_object_notify (G_OBJECT (icon_view), "markup-column");
5665 * gtk_icon_view_get_markup_column:
5666 * @icon_view: A #GtkIconView.
5668 * Returns the column with markup text for @icon_view.
5670 * Returns: the markup column, or -1 if it's unset.
5675 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5677 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5679 return icon_view->priv->markup_column;
5683 * gtk_icon_view_set_pixbuf_column:
5684 * @icon_view: A #GtkIconView.
5685 * @column: A column in the currently used model, or -1 to disable
5687 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5688 * column must be of type #GDK_TYPE_PIXBUF
5693 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5696 if (column == icon_view->priv->pixbuf_column)
5700 icon_view->priv->pixbuf_column = -1;
5703 if (icon_view->priv->model != NULL)
5707 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5709 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5712 icon_view->priv->pixbuf_column = column;
5715 gtk_icon_view_stop_editing (icon_view, TRUE);
5717 update_pixbuf_cell (icon_view);
5719 gtk_icon_view_invalidate_sizes (icon_view);
5720 gtk_icon_view_queue_layout (icon_view);
5722 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5727 * gtk_icon_view_get_pixbuf_column:
5728 * @icon_view: A #GtkIconView.
5730 * Returns the column with pixbufs for @icon_view.
5732 * Returns: the pixbuf column, or -1 if it's unset.
5737 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5739 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5741 return icon_view->priv->pixbuf_column;
5745 * gtk_icon_view_select_path:
5746 * @icon_view: A #GtkIconView.
5747 * @path: The #GtkTreePath to be selected.
5749 * Selects the row at @path.
5754 gtk_icon_view_select_path (GtkIconView *icon_view,
5757 GtkIconViewItem *item = NULL;
5759 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5760 g_return_if_fail (icon_view->priv->model != NULL);
5761 g_return_if_fail (path != NULL);
5763 if (gtk_tree_path_get_depth (path) > 0)
5764 item = g_list_nth_data (icon_view->priv->items,
5765 gtk_tree_path_get_indices(path)[0]);
5768 gtk_icon_view_select_item (icon_view, item);
5772 * gtk_icon_view_unselect_path:
5773 * @icon_view: A #GtkIconView.
5774 * @path: The #GtkTreePath to be unselected.
5776 * Unselects the row at @path.
5781 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5784 GtkIconViewItem *item;
5786 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5787 g_return_if_fail (icon_view->priv->model != NULL);
5788 g_return_if_fail (path != NULL);
5790 item = g_list_nth_data (icon_view->priv->items,
5791 gtk_tree_path_get_indices(path)[0]);
5796 gtk_icon_view_unselect_item (icon_view, item);
5800 * gtk_icon_view_get_selected_items:
5801 * @icon_view: A #GtkIconView.
5803 * Creates a list of paths of all selected items. Additionally, if you are
5804 * planning on modifying the model after calling this function, you may
5805 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5806 * To do this, you can use gtk_tree_row_reference_new().
5808 * To free the return value, use:
5810 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5811 * g_list_free (list);
5814 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5819 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5822 GList *selected = NULL;
5824 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5826 for (list = icon_view->priv->items; list != NULL; list = list->next)
5828 GtkIconViewItem *item = list->data;
5832 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5834 selected = g_list_prepend (selected, path);
5842 * gtk_icon_view_select_all:
5843 * @icon_view: A #GtkIconView.
5845 * Selects all the icons. @icon_view must has its selection mode set
5846 * to #GTK_SELECTION_MULTIPLE.
5851 gtk_icon_view_select_all (GtkIconView *icon_view)
5854 gboolean dirty = FALSE;
5856 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5858 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5861 for (items = icon_view->priv->items; items; items = items->next)
5863 GtkIconViewItem *item = items->data;
5865 if (!item->selected)
5868 item->selected = TRUE;
5869 gtk_icon_view_queue_draw_item (icon_view, item);
5874 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5878 * gtk_icon_view_unselect_all:
5879 * @icon_view: A #GtkIconView.
5881 * Unselects all the icons.
5886 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5888 gboolean dirty = FALSE;
5890 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5892 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5895 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5898 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5902 * gtk_icon_view_path_is_selected:
5903 * @icon_view: A #GtkIconView.
5904 * @path: A #GtkTreePath to check selection on.
5906 * Returns %TRUE if the icon pointed to by @path is currently
5907 * selected. If @path does not point to a valid location, %FALSE is returned.
5909 * Return value: %TRUE if @path is selected.
5914 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5917 GtkIconViewItem *item;
5919 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5920 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5921 g_return_val_if_fail (path != NULL, FALSE);
5923 item = g_list_nth_data (icon_view->priv->items,
5924 gtk_tree_path_get_indices(path)[0]);
5929 return item->selected;
5933 * gtk_icon_view_get_item_row:
5934 * @icon_view: a #GtkIconView
5935 * @path: the #GtkTreePath of the item
5937 * Gets the row in which the item @path is currently
5938 * displayed. Row numbers start at 0.
5940 * Returns: The row in which the item is displayed
5945 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5948 GtkIconViewItem *item;
5950 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5951 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5952 g_return_val_if_fail (path != NULL, FALSE);
5954 item = g_list_nth_data (icon_view->priv->items,
5955 gtk_tree_path_get_indices(path)[0]);
5964 * gtk_icon_view_get_item_column:
5965 * @icon_view: a #GtkIconView
5966 * @path: the #GtkTreePath of the item
5968 * Gets the column in which the item @path is currently
5969 * displayed. Column numbers start at 0.
5971 * Returns: The column in which the item is displayed
5976 gtk_icon_view_get_item_column (GtkIconView *icon_view,
5979 GtkIconViewItem *item;
5981 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5982 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5983 g_return_val_if_fail (path != NULL, FALSE);
5985 item = g_list_nth_data (icon_view->priv->items,
5986 gtk_tree_path_get_indices(path)[0]);
5995 * gtk_icon_view_item_activated:
5996 * @icon_view: A #GtkIconView
5997 * @path: The #GtkTreePath to be activated
5999 * Activates the item determined by @path.
6004 gtk_icon_view_item_activated (GtkIconView *icon_view,
6007 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6008 g_return_if_fail (path != NULL);
6010 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6014 * gtk_icon_view_set_item_orientation:
6015 * @icon_view: a #GtkIconView
6016 * @orientation: the relative position of texts and icons
6018 * Sets the ::item-orientation property which determines whether the labels
6019 * are drawn beside the icons instead of below.
6024 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
6025 GtkOrientation orientation)
6027 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6029 if (icon_view->priv->item_orientation != orientation)
6031 icon_view->priv->item_orientation = orientation;
6033 gtk_icon_view_stop_editing (icon_view, TRUE);
6034 gtk_icon_view_invalidate_sizes (icon_view);
6035 gtk_icon_view_queue_layout (icon_view);
6037 update_text_cell (icon_view);
6038 update_pixbuf_cell (icon_view);
6040 g_object_notify (G_OBJECT (icon_view), "item-orientation");
6045 * gtk_icon_view_get_item_orientation:
6046 * @icon_view: a #GtkIconView
6048 * Returns the value of the ::item-orientation property which determines
6049 * whether the labels are drawn beside the icons instead of below.
6051 * Return value: the relative position of texts and icons
6056 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
6058 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6059 GTK_ORIENTATION_VERTICAL);
6061 return icon_view->priv->item_orientation;
6065 * gtk_icon_view_set_columns:
6066 * @icon_view: a #GtkIconView
6067 * @columns: the number of columns
6069 * Sets the ::columns property which determines in how
6070 * many columns the icons are arranged. If @columns is
6071 * -1, the number of columns will be chosen automatically
6072 * to fill the available area.
6077 gtk_icon_view_set_columns (GtkIconView *icon_view,
6080 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6082 if (icon_view->priv->columns != columns)
6084 icon_view->priv->columns = columns;
6086 gtk_icon_view_stop_editing (icon_view, TRUE);
6087 gtk_icon_view_queue_layout (icon_view);
6089 g_object_notify (G_OBJECT (icon_view), "columns");
6094 * gtk_icon_view_get_columns:
6095 * @icon_view: a #GtkIconView
6097 * Returns the value of the ::columns property.
6099 * Return value: the number of columns, or -1
6104 gtk_icon_view_get_columns (GtkIconView *icon_view)
6106 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6108 return icon_view->priv->columns;
6112 * gtk_icon_view_set_item_width:
6113 * @icon_view: a #GtkIconView
6114 * @item_width: the width for each item
6116 * Sets the ::item-width property which specifies the width
6117 * to use for each item. If it is set to -1, the icon view will
6118 * automatically determine a suitable item size.
6123 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6126 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6128 if (icon_view->priv->item_width != item_width)
6130 icon_view->priv->item_width = item_width;
6132 gtk_icon_view_stop_editing (icon_view, TRUE);
6133 gtk_icon_view_invalidate_sizes (icon_view);
6134 gtk_icon_view_queue_layout (icon_view);
6136 update_text_cell (icon_view);
6138 g_object_notify (G_OBJECT (icon_view), "item-width");
6143 * gtk_icon_view_get_item_width:
6144 * @icon_view: a #GtkIconView
6146 * Returns the value of the ::item-width property.
6148 * Return value: the width of a single item, or -1
6153 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6155 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6157 return icon_view->priv->item_width;
6162 * gtk_icon_view_set_spacing:
6163 * @icon_view: a #GtkIconView
6164 * @spacing: the spacing
6166 * Sets the ::spacing property which specifies the space
6167 * which is inserted between the cells (i.e. the icon and
6168 * the text) of an item.
6173 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6176 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6178 if (icon_view->priv->spacing != spacing)
6180 icon_view->priv->spacing = spacing;
6182 gtk_icon_view_stop_editing (icon_view, TRUE);
6183 gtk_icon_view_invalidate_sizes (icon_view);
6184 gtk_icon_view_queue_layout (icon_view);
6186 g_object_notify (G_OBJECT (icon_view), "spacing");
6191 * gtk_icon_view_get_spacing:
6192 * @icon_view: a #GtkIconView
6194 * Returns the value of the ::spacing property.
6196 * Return value: the space between cells
6201 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6203 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6205 return icon_view->priv->spacing;
6209 * gtk_icon_view_set_row_spacing:
6210 * @icon_view: a #GtkIconView
6211 * @row_spacing: the row spacing
6213 * Sets the ::row-spacing property which specifies the space
6214 * which is inserted between the rows of the icon view.
6219 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6222 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6224 if (icon_view->priv->row_spacing != row_spacing)
6226 icon_view->priv->row_spacing = row_spacing;
6228 gtk_icon_view_stop_editing (icon_view, TRUE);
6229 gtk_icon_view_invalidate_sizes (icon_view);
6230 gtk_icon_view_queue_layout (icon_view);
6232 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6237 * gtk_icon_view_get_row_spacing:
6238 * @icon_view: a #GtkIconView
6240 * Returns the value of the ::row-spacing property.
6242 * Return value: the space between rows
6247 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6249 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6251 return icon_view->priv->row_spacing;
6255 * gtk_icon_view_set_column_spacing:
6256 * @icon_view: a #GtkIconView
6257 * @column_spacing: the column spacing
6259 * Sets the ::column-spacing property which specifies the space
6260 * which is inserted between the columns of the icon view.
6265 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6266 gint column_spacing)
6268 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6270 if (icon_view->priv->column_spacing != column_spacing)
6272 icon_view->priv->column_spacing = column_spacing;
6274 gtk_icon_view_stop_editing (icon_view, TRUE);
6275 gtk_icon_view_invalidate_sizes (icon_view);
6276 gtk_icon_view_queue_layout (icon_view);
6278 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6283 * gtk_icon_view_get_column_spacing:
6284 * @icon_view: a #GtkIconView
6286 * Returns the value of the ::column-spacing property.
6288 * Return value: the space between columns
6293 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6295 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6297 return icon_view->priv->column_spacing;
6301 * gtk_icon_view_set_margin:
6302 * @icon_view: a #GtkIconView
6303 * @margin: the margin
6305 * Sets the ::margin property which specifies the space
6306 * which is inserted at the top, bottom, left and right
6312 gtk_icon_view_set_margin (GtkIconView *icon_view,
6315 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6317 if (icon_view->priv->margin != margin)
6319 icon_view->priv->margin = margin;
6321 gtk_icon_view_stop_editing (icon_view, TRUE);
6322 gtk_icon_view_invalidate_sizes (icon_view);
6323 gtk_icon_view_queue_layout (icon_view);
6325 g_object_notify (G_OBJECT (icon_view), "margin");
6330 * gtk_icon_view_get_margin:
6331 * @icon_view: a #GtkIconView
6333 * Returns the value of the ::margin property.
6335 * Return value: the space at the borders
6340 gtk_icon_view_get_margin (GtkIconView *icon_view)
6342 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6344 return icon_view->priv->margin;
6348 * gtk_icon_view_set_item_padding:
6349 * @icon_view: a #GtkIconView
6350 * @item_padding: the item padding
6352 * Sets the #GtkIconView:item-padding property which specifies the padding
6353 * around each of the icon view's items.
6358 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6361 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6363 if (icon_view->priv->item_padding != item_padding)
6365 icon_view->priv->item_padding = item_padding;
6367 gtk_icon_view_stop_editing (icon_view, TRUE);
6368 gtk_icon_view_invalidate_sizes (icon_view);
6369 gtk_icon_view_queue_layout (icon_view);
6371 g_object_notify (G_OBJECT (icon_view), "item-padding");
6376 * gtk_icon_view_get_item_padding:
6377 * @icon_view: a #GtkIconView
6379 * Returns the value of the ::item-padding property.
6381 * Return value: the padding around items
6386 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6388 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6390 return icon_view->priv->item_padding;
6393 /* Get/set whether drag_motion requested the drag data and
6394 * drag_data_received should thus not actually insert the data,
6395 * since the data doesn't result from a drop.
6398 set_status_pending (GdkDragContext *context,
6399 GdkDragAction suggested_action)
6401 g_object_set_data (G_OBJECT (context),
6402 I_("gtk-icon-view-status-pending"),
6403 GINT_TO_POINTER (suggested_action));
6406 static GdkDragAction
6407 get_status_pending (GdkDragContext *context)
6409 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6410 "gtk-icon-view-status-pending"));
6414 unset_reorderable (GtkIconView *icon_view)
6416 if (icon_view->priv->reorderable)
6418 icon_view->priv->reorderable = FALSE;
6419 g_object_notify (G_OBJECT (icon_view), "reorderable");
6424 set_source_row (GdkDragContext *context,
6425 GtkTreeModel *model,
6426 GtkTreePath *source_row)
6429 g_object_set_data_full (G_OBJECT (context),
6430 I_("gtk-icon-view-source-row"),
6431 gtk_tree_row_reference_new (model, source_row),
6432 (GDestroyNotify) gtk_tree_row_reference_free);
6434 g_object_set_data_full (G_OBJECT (context),
6435 I_("gtk-icon-view-source-row"),
6440 get_source_row (GdkDragContext *context)
6442 GtkTreeRowReference *ref;
6444 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6447 return gtk_tree_row_reference_get_path (ref);
6454 GtkTreeRowReference *dest_row;
6455 gboolean empty_view_drop;
6456 gboolean drop_append_mode;
6460 dest_row_free (gpointer data)
6462 DestRow *dr = (DestRow *)data;
6464 gtk_tree_row_reference_free (dr->dest_row);
6469 set_dest_row (GdkDragContext *context,
6470 GtkTreeModel *model,
6471 GtkTreePath *dest_row,
6472 gboolean empty_view_drop,
6473 gboolean drop_append_mode)
6479 g_object_set_data_full (G_OBJECT (context),
6480 I_("gtk-icon-view-dest-row"),
6485 dr = g_new0 (DestRow, 1);
6487 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6488 dr->empty_view_drop = empty_view_drop;
6489 dr->drop_append_mode = drop_append_mode;
6490 g_object_set_data_full (G_OBJECT (context),
6491 I_("gtk-icon-view-dest-row"),
6492 dr, (GDestroyNotify) dest_row_free);
6496 get_dest_row (GdkDragContext *context)
6500 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6504 GtkTreePath *path = NULL;
6507 path = gtk_tree_row_reference_get_path (dr->dest_row);
6508 else if (dr->empty_view_drop)
6509 path = gtk_tree_path_new_from_indices (0, -1);
6513 if (path && dr->drop_append_mode)
6514 gtk_tree_path_next (path);
6523 check_model_dnd (GtkTreeModel *model,
6524 GType required_iface,
6525 const gchar *signal)
6527 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6529 g_warning ("You must override the default '%s' handler "
6530 "on GtkIconView when using models that don't support "
6531 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6532 "is to connect to '%s' and call "
6533 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6534 "the default handler from running. Look at the source code "
6535 "for the default handler in gtkiconview.c to get an idea what "
6536 "your handler should do. (gtkiconview.c is in the GTK+ source "
6537 "code.) If you're using GTK+ from a language other than C, "
6538 "there may be a more natural way to override default handlers, e.g. via derivation.",
6539 signal, g_type_name (required_iface), signal);
6547 remove_scroll_timeout (GtkIconView *icon_view)
6549 if (icon_view->priv->scroll_timeout_id != 0)
6551 g_source_remove (icon_view->priv->scroll_timeout_id);
6553 icon_view->priv->scroll_timeout_id = 0;
6558 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6560 gint px, py, x, y, width, height;
6561 gint hoffset, voffset;
6563 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6564 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6566 /* see if we are near the edge. */
6567 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6569 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6571 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6573 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6576 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6577 icon_view->priv->vadjustment->value + voffset);
6580 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6581 icon_view->priv->hadjustment->value + hoffset);
6586 drag_scroll_timeout (gpointer data)
6588 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6590 gtk_icon_view_autoscroll (icon_view);
6597 set_destination (GtkIconView *icon_view,
6598 GdkDragContext *context,
6601 GdkDragAction *suggested_action,
6605 GtkTreePath *path = NULL;
6606 GtkIconViewDropPosition pos;
6607 GtkIconViewDropPosition old_pos;
6608 GtkTreePath *old_dest_path = NULL;
6609 gboolean can_drop = FALSE;
6611 widget = GTK_WIDGET (icon_view);
6613 *suggested_action = 0;
6616 if (!icon_view->priv->dest_set)
6618 /* someone unset us as a drag dest, note that if
6619 * we return FALSE drag_leave isn't called
6622 gtk_icon_view_set_drag_dest_item (icon_view,
6624 GTK_ICON_VIEW_DROP_LEFT);
6626 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6628 return FALSE; /* no longer a drop site */
6631 *target = gtk_drag_dest_find_target (widget, context,
6632 gtk_drag_dest_get_target_list (widget));
6633 if (*target == GDK_NONE)
6636 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6639 GtkTreeModel *model;
6641 /* the row got dropped on empty space, let's setup a special case
6645 gtk_tree_path_free (path);
6647 model = gtk_icon_view_get_model (icon_view);
6649 n_children = gtk_tree_model_iter_n_children (model, NULL);
6652 pos = GTK_ICON_VIEW_DROP_BELOW;
6653 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6657 pos = GTK_ICON_VIEW_DROP_ABOVE;
6658 path = gtk_tree_path_new_from_indices (0, -1);
6668 gtk_icon_view_get_drag_dest_item (icon_view,
6673 gtk_tree_path_free (old_dest_path);
6675 if (TRUE /* FIXME if the location droppable predicate */)
6683 GtkWidget *source_widget;
6685 *suggested_action = context->suggested_action;
6686 source_widget = gtk_drag_get_source_widget (context);
6688 if (source_widget == widget)
6690 /* Default to MOVE, unless the user has
6691 * pressed ctrl or shift to affect available actions
6693 if ((context->actions & GDK_ACTION_MOVE) != 0)
6694 *suggested_action = GDK_ACTION_MOVE;
6697 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6702 /* can't drop here */
6703 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6705 GTK_ICON_VIEW_DROP_LEFT);
6709 gtk_tree_path_free (path);
6715 get_logical_destination (GtkIconView *icon_view,
6716 gboolean *drop_append_mode)
6718 /* adjust path to point to the row the drop goes in front of */
6719 GtkTreePath *path = NULL;
6720 GtkIconViewDropPosition pos;
6722 *drop_append_mode = FALSE;
6724 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6729 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6730 pos == GTK_ICON_VIEW_DROP_BELOW)
6733 GtkTreeModel *model = icon_view->priv->model;
6735 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6736 !gtk_tree_model_iter_next (model, &iter))
6737 *drop_append_mode = TRUE;
6740 *drop_append_mode = FALSE;
6741 gtk_tree_path_next (path);
6749 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6750 GdkEventMotion *event)
6752 GtkWidget *widget = GTK_WIDGET (icon_view);
6753 GdkDragContext *context;
6754 GtkTreePath *path = NULL;
6756 GtkTreeModel *model;
6757 gboolean retval = FALSE;
6759 if (!icon_view->priv->source_set)
6762 if (icon_view->priv->pressed_button < 0)
6765 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6766 icon_view->priv->press_start_x,
6767 icon_view->priv->press_start_y,
6768 event->x, event->y))
6771 model = gtk_icon_view_get_model (icon_view);
6776 button = icon_view->priv->pressed_button;
6777 icon_view->priv->pressed_button = -1;
6779 path = gtk_icon_view_get_path_at_pos (icon_view,
6780 icon_view->priv->press_start_x,
6781 icon_view->priv->press_start_y);
6786 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6787 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6791 /* FIXME Check whether we're a start button, if not return FALSE and
6795 /* Now we can begin the drag */
6799 context = gtk_drag_begin (widget,
6800 gtk_drag_source_get_target_list (widget),
6801 icon_view->priv->source_actions,
6805 set_source_row (context, model, path);
6809 gtk_tree_path_free (path);
6814 /* Source side drag signals */
6816 gtk_icon_view_drag_begin (GtkWidget *widget,
6817 GdkDragContext *context)
6819 GtkIconView *icon_view;
6820 GtkIconViewItem *item;
6825 icon_view = GTK_ICON_VIEW (widget);
6827 /* if the user uses a custom DnD impl, we don't set the icon here */
6828 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6831 item = gtk_icon_view_get_item_at_coords (icon_view,
6832 icon_view->priv->press_start_x,
6833 icon_view->priv->press_start_y,
6837 g_return_if_fail (item != NULL);
6839 x = icon_view->priv->press_start_x - item->x + 1;
6840 y = icon_view->priv->press_start_y - item->y + 1;
6842 path = gtk_tree_path_new_from_indices (item->index, -1);
6843 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6844 gtk_tree_path_free (path);
6846 gtk_drag_set_icon_pixmap (context,
6847 gdk_drawable_get_colormap (icon),
6852 g_object_unref (icon);
6856 gtk_icon_view_drag_end (GtkWidget *widget,
6857 GdkDragContext *context)
6863 gtk_icon_view_drag_data_get (GtkWidget *widget,
6864 GdkDragContext *context,
6865 GtkSelectionData *selection_data,
6869 GtkIconView *icon_view;
6870 GtkTreeModel *model;
6871 GtkTreePath *source_row;
6873 icon_view = GTK_ICON_VIEW (widget);
6874 model = gtk_icon_view_get_model (icon_view);
6879 if (!icon_view->priv->source_set)
6882 source_row = get_source_row (context);
6884 if (source_row == NULL)
6887 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6888 * any model; for DragSource models there are some other targets
6892 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6893 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6898 /* If drag_data_get does nothing, try providing row data. */
6899 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6900 gtk_tree_set_row_drag_data (selection_data,
6905 gtk_tree_path_free (source_row);
6909 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6910 GdkDragContext *context)
6912 GtkTreeModel *model;
6913 GtkIconView *icon_view;
6914 GtkTreePath *source_row;
6916 icon_view = GTK_ICON_VIEW (widget);
6917 model = gtk_icon_view_get_model (icon_view);
6919 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6922 if (!icon_view->priv->source_set)
6925 source_row = get_source_row (context);
6927 if (source_row == NULL)
6930 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6933 gtk_tree_path_free (source_row);
6935 set_source_row (context, NULL, NULL);
6938 /* Target side drag signals */
6940 gtk_icon_view_drag_leave (GtkWidget *widget,
6941 GdkDragContext *context,
6944 GtkIconView *icon_view;
6946 icon_view = GTK_ICON_VIEW (widget);
6948 /* unset any highlight row */
6949 gtk_icon_view_set_drag_dest_item (icon_view,
6951 GTK_ICON_VIEW_DROP_LEFT);
6953 remove_scroll_timeout (icon_view);
6957 gtk_icon_view_drag_motion (GtkWidget *widget,
6958 GdkDragContext *context,
6963 GtkTreePath *path = NULL;
6964 GtkIconViewDropPosition pos;
6965 GtkIconView *icon_view;
6966 GdkDragAction suggested_action = 0;
6970 icon_view = GTK_ICON_VIEW (widget);
6972 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6975 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6977 /* we only know this *after* set_desination_row */
6978 empty = icon_view->priv->empty_view_drop;
6980 if (path == NULL && !empty)
6982 /* Can't drop here. */
6983 gdk_drag_status (context, 0, time);
6987 if (icon_view->priv->scroll_timeout_id == 0)
6989 icon_view->priv->scroll_timeout_id =
6990 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6993 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6995 /* Request data so we can use the source row when
6996 * determining whether to accept the drop
6998 set_status_pending (context, suggested_action);
6999 gtk_drag_get_data (widget, context, target, time);
7003 set_status_pending (context, 0);
7004 gdk_drag_status (context, suggested_action, time);
7009 gtk_tree_path_free (path);
7015 gtk_icon_view_drag_drop (GtkWidget *widget,
7016 GdkDragContext *context,
7021 GtkIconView *icon_view;
7023 GdkDragAction suggested_action = 0;
7024 GdkAtom target = GDK_NONE;
7025 GtkTreeModel *model;
7026 gboolean drop_append_mode;
7028 icon_view = GTK_ICON_VIEW (widget);
7029 model = gtk_icon_view_get_model (icon_view);
7031 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7033 if (!icon_view->priv->dest_set)
7036 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7039 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7042 path = get_logical_destination (icon_view, &drop_append_mode);
7044 if (target != GDK_NONE && path != NULL)
7046 /* in case a motion had requested drag data, change things so we
7047 * treat drag data receives as a drop.
7049 set_status_pending (context, 0);
7050 set_dest_row (context, model, path,
7051 icon_view->priv->empty_view_drop, drop_append_mode);
7055 gtk_tree_path_free (path);
7057 /* Unset this thing */
7058 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7060 if (target != GDK_NONE)
7062 gtk_drag_get_data (widget, context, target, time);
7070 gtk_icon_view_drag_data_received (GtkWidget *widget,
7071 GdkDragContext *context,
7074 GtkSelectionData *selection_data,
7079 gboolean accepted = FALSE;
7080 GtkTreeModel *model;
7081 GtkIconView *icon_view;
7082 GtkTreePath *dest_row;
7083 GdkDragAction suggested_action;
7084 gboolean drop_append_mode;
7086 icon_view = GTK_ICON_VIEW (widget);
7087 model = gtk_icon_view_get_model (icon_view);
7089 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7092 if (!icon_view->priv->dest_set)
7095 suggested_action = get_status_pending (context);
7097 if (suggested_action)
7099 /* We are getting this data due to a request in drag_motion,
7100 * rather than due to a request in drag_drop, so we are just
7101 * supposed to call drag_status, not actually paste in the
7104 path = get_logical_destination (icon_view, &drop_append_mode);
7107 suggested_action = 0;
7109 if (suggested_action)
7111 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7114 suggested_action = 0;
7117 gdk_drag_status (context, suggested_action, time);
7120 gtk_tree_path_free (path);
7122 /* If you can't drop, remove user drop indicator until the next motion */
7123 if (suggested_action == 0)
7124 gtk_icon_view_set_drag_dest_item (icon_view,
7126 GTK_ICON_VIEW_DROP_LEFT);
7131 dest_row = get_dest_row (context);
7133 if (dest_row == NULL)
7136 if (selection_data->length >= 0)
7138 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7144 gtk_drag_finish (context,
7146 (context->action == GDK_ACTION_MOVE),
7149 gtk_tree_path_free (dest_row);
7152 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7155 /* Drag-and-Drop support */
7157 * gtk_icon_view_enable_model_drag_source:
7158 * @icon_view: a #GtkIconTreeView
7159 * @start_button_mask: Mask of allowed buttons to start drag
7160 * @targets: the table of targets that the drag will support
7161 * @n_targets: the number of items in @targets
7162 * @actions: the bitmask of possible actions for a drag from this
7165 * Turns @icon_view into a drag source for automatic DND. Calling this
7166 * method sets #GtkIconView:reorderable to %FALSE.
7171 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7172 GdkModifierType start_button_mask,
7173 const GtkTargetEntry *targets,
7175 GdkDragAction actions)
7177 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7179 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7181 icon_view->priv->start_button_mask = start_button_mask;
7182 icon_view->priv->source_actions = actions;
7184 icon_view->priv->source_set = TRUE;
7186 unset_reorderable (icon_view);
7190 * gtk_icon_view_enable_model_drag_dest:
7191 * @icon_view: a #GtkIconView
7192 * @targets: the table of targets that the drag will support
7193 * @n_targets: the number of items in @targets
7194 * @actions: the bitmask of possible actions for a drag to this
7197 * Turns @icon_view into a drop destination for automatic DND. Calling this
7198 * method sets #GtkIconView:reorderable to %FALSE.
7203 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7204 const GtkTargetEntry *targets,
7206 GdkDragAction actions)
7208 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7210 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7212 icon_view->priv->dest_actions = actions;
7214 icon_view->priv->dest_set = TRUE;
7216 unset_reorderable (icon_view);
7220 * gtk_icon_view_unset_model_drag_source:
7221 * @icon_view: a #GtkIconView
7223 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7224 * method sets #GtkIconView:reorderable to %FALSE.
7229 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7231 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7233 if (icon_view->priv->source_set)
7235 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7236 icon_view->priv->source_set = FALSE;
7239 unset_reorderable (icon_view);
7243 * gtk_icon_view_unset_model_drag_dest:
7244 * @icon_view: a #GtkIconView
7246 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7247 * method sets #GtkIconView:reorderable to %FALSE.
7252 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7254 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7256 if (icon_view->priv->dest_set)
7258 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7259 icon_view->priv->dest_set = FALSE;
7262 unset_reorderable (icon_view);
7265 /* These are useful to implement your own custom stuff. */
7267 * gtk_icon_view_set_drag_dest_item:
7268 * @icon_view: a #GtkIconView
7269 * @path: (allow-none): The path of the item to highlight, or %NULL.
7270 * @pos: Specifies where to drop, relative to the item
7272 * Sets the item that is highlighted for feedback.
7277 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7279 GtkIconViewDropPosition pos)
7281 /* Note; this function is exported to allow a custom DND
7282 * implementation, so it can't touch TreeViewDragInfo
7285 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7287 if (icon_view->priv->dest_item)
7289 GtkTreePath *current_path;
7290 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7291 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7292 icon_view->priv->dest_item = NULL;
7294 gtk_icon_view_queue_draw_path (icon_view, current_path);
7295 gtk_tree_path_free (current_path);
7298 /* special case a drop on an empty model */
7299 icon_view->priv->empty_view_drop = FALSE;
7300 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7301 && gtk_tree_path_get_depth (path) == 1
7302 && gtk_tree_path_get_indices (path)[0] == 0)
7306 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7309 if (n_children == 0)
7310 icon_view->priv->empty_view_drop = TRUE;
7313 icon_view->priv->dest_pos = pos;
7317 icon_view->priv->dest_item =
7318 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7319 icon_view->priv->model, path);
7321 gtk_icon_view_queue_draw_path (icon_view, path);
7326 * gtk_icon_view_get_drag_dest_item:
7327 * @icon_view: a #GtkIconView
7328 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7329 * @pos: (allow-none): Return location for the drop position, or %NULL
7331 * Gets information about the item that is highlighted for feedback.
7336 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7338 GtkIconViewDropPosition *pos)
7340 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7344 if (icon_view->priv->dest_item)
7345 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7351 *pos = icon_view->priv->dest_pos;
7355 * gtk_icon_view_get_dest_item_at_pos:
7356 * @icon_view: a #GtkIconView
7357 * @drag_x: the position to determine the destination item for
7358 * @drag_y: the position to determine the destination item for
7359 * @path: (allow-none): Return location for the path of the item, or %NULL.
7360 * @pos: (allow-none): Return location for the drop position, or %NULL
7362 * Determines the destination item for a given position.
7364 * Return value: whether there is an item at the given position.
7369 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7373 GtkIconViewDropPosition *pos)
7375 GtkIconViewItem *item;
7377 /* Note; this function is exported to allow a custom DND
7378 * implementation, so it can't touch TreeViewDragInfo
7381 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7382 g_return_val_if_fail (drag_x >= 0, FALSE);
7383 g_return_val_if_fail (drag_y >= 0, FALSE);
7384 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7390 item = gtk_icon_view_get_item_at_coords (icon_view,
7391 drag_x + icon_view->priv->hadjustment->value,
7392 drag_y + icon_view->priv->vadjustment->value,
7399 *path = gtk_tree_path_new_from_indices (item->index, -1);
7403 if (drag_x < item->x + item->width / 4)
7404 *pos = GTK_ICON_VIEW_DROP_LEFT;
7405 else if (drag_x > item->x + item->width * 3 / 4)
7406 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7407 else if (drag_y < item->y + item->height / 4)
7408 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7409 else if (drag_y > item->y + item->height * 3 / 4)
7410 *pos = GTK_ICON_VIEW_DROP_BELOW;
7412 *pos = GTK_ICON_VIEW_DROP_INTO;
7419 * gtk_icon_view_create_drag_icon:
7420 * @icon_view: a #GtkIconView
7421 * @path: a #GtkTreePath in @icon_view
7423 * Creates a #GdkPixmap representation of the item at @path.
7424 * This image is used for a drag icon.
7426 * Return value: a newly-allocated pixmap of the drag icon.
7431 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7436 GdkPixmap *drawable;
7441 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7442 g_return_val_if_fail (path != NULL, NULL);
7444 widget = GTK_WIDGET (icon_view);
7446 if (!gtk_widget_get_realized (widget))
7449 index = gtk_tree_path_get_indices (path)[0];
7451 for (l = icon_view->priv->items; l; l = l->next)
7453 GtkIconViewItem *item = l->data;
7455 if (index == item->index)
7457 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7462 cr = gdk_cairo_create (drawable);
7463 cairo_set_line_width (cr, 1.);
7465 gdk_cairo_set_source_color
7466 (cr, &widget->style->base[gtk_widget_get_state (widget)]);
7467 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7472 area.width = item->width;
7473 area.height = item->height;
7475 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7476 drawable, 1, 1, FALSE);
7478 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7479 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7492 * gtk_icon_view_get_reorderable:
7493 * @icon_view: a #GtkIconView
7495 * Retrieves whether the user can reorder the list via drag-and-drop.
7496 * See gtk_icon_view_set_reorderable().
7498 * Return value: %TRUE if the list can be reordered.
7503 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7505 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7507 return icon_view->priv->reorderable;
7510 static const GtkTargetEntry item_targets[] = {
7511 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7516 * gtk_icon_view_set_reorderable:
7517 * @icon_view: A #GtkIconView.
7518 * @reorderable: %TRUE, if the list of items can be reordered.
7520 * This function is a convenience function to allow you to reorder models that
7521 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7522 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7523 * the user can reorder the model by dragging and dropping rows. The
7524 * developer can listen to these changes by connecting to the model's
7525 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7526 * the icon view as a drag source and destination. Therefore, drag and
7527 * drop can not be used in a reorderable view for any other purpose.
7529 * This function does not give you any degree of control over the order -- any
7530 * reordering is allowed. If more control is needed, you should probably
7531 * handle drag and drop manually.
7536 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7537 gboolean reorderable)
7539 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7541 reorderable = reorderable != FALSE;
7543 if (icon_view->priv->reorderable == reorderable)
7548 gtk_icon_view_enable_model_drag_source (icon_view,
7551 G_N_ELEMENTS (item_targets),
7553 gtk_icon_view_enable_model_drag_dest (icon_view,
7555 G_N_ELEMENTS (item_targets),
7560 gtk_icon_view_unset_model_drag_source (icon_view);
7561 gtk_icon_view_unset_model_drag_dest (icon_view);
7564 icon_view->priv->reorderable = reorderable;
7566 g_object_notify (G_OBJECT (icon_view), "reorderable");
7570 /* Accessibility Support */
7572 static gpointer accessible_parent_class;
7573 static gpointer accessible_item_parent_class;
7574 static GQuark accessible_private_data_quark = 0;
7576 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7577 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7578 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7580 static GType gtk_icon_view_item_accessible_get_type (void);
7591 GtkIconViewItem *item;
7595 AtkStateSet *state_set;
7599 GtkTextBuffer *text_buffer;
7601 gchar *action_descriptions[LAST_ACTION];
7602 gchar *image_description;
7603 guint action_idle_handler;
7604 } GtkIconViewItemAccessible;
7606 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7612 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7617 typedef struct _GtkIconViewItemAccessibleClass
7619 AtkObjectClass parent_class;
7621 } GtkIconViewItemAccessibleClass;
7623 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7626 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7628 GtkIconViewItemAccessible *item;
7629 GtkIconView *icon_view;
7632 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7633 item->action_idle_handler = 0;
7635 if (item->widget != NULL)
7637 icon_view = GTK_ICON_VIEW (item->widget);
7638 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7639 gtk_icon_view_item_activated (icon_view, path);
7640 gtk_tree_path_free (path);
7647 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7650 GtkIconViewItemAccessible *item;
7652 if (i < 0 || i >= LAST_ACTION)
7655 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7657 if (!GTK_IS_ICON_VIEW (item->widget))
7660 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7665 case ACTION_ACTIVATE:
7666 if (!item->action_idle_handler)
7667 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7670 g_assert_not_reached ();
7678 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7683 static const gchar *
7684 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7687 GtkIconViewItemAccessible *item;
7689 if (i < 0 || i >= LAST_ACTION)
7692 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7694 if (item->action_descriptions[i])
7695 return item->action_descriptions[i];
7697 return gtk_icon_view_item_accessible_action_descriptions[i];
7700 static const gchar *
7701 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7704 if (i < 0 || i >= LAST_ACTION)
7707 return gtk_icon_view_item_accessible_action_names[i];
7711 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7713 const gchar *description)
7715 GtkIconViewItemAccessible *item;
7717 if (i < 0 || i >= LAST_ACTION)
7720 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7722 g_free (item->action_descriptions[i]);
7724 item->action_descriptions[i] = g_strdup (description);
7730 atk_action_item_interface_init (AtkActionIface *iface)
7732 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7733 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7734 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7735 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7736 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7739 static const gchar *
7740 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7742 GtkIconViewItemAccessible *item;
7744 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7746 return item->image_description;
7750 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7751 const gchar *description)
7753 GtkIconViewItemAccessible *item;
7755 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7757 g_free (item->image_description);
7758 item->image_description = g_strdup (description);
7764 get_pixbuf_box (GtkIconView *icon_view,
7765 GtkIconViewItem *item,
7770 for (l = icon_view->priv->cell_list; l; l = l->next)
7772 GtkIconViewCellInfo *info = l->data;
7774 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7776 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7786 get_text (GtkIconView *icon_view,
7787 GtkIconViewItem *item)
7792 for (l = icon_view->priv->cell_list; l; l = l->next)
7794 GtkIconViewCellInfo *info = l->data;
7796 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7798 g_object_get (info->cell, "text", &text, NULL);
7808 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7812 GtkIconViewItemAccessible *item;
7815 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7817 if (!GTK_IS_ICON_VIEW (item->widget))
7820 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7823 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7826 *height = box.height;
7831 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7834 AtkCoordType coord_type)
7836 GtkIconViewItemAccessible *item;
7839 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7841 if (!GTK_IS_ICON_VIEW (item->widget))
7844 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7847 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7849 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7851 *x+= box.x - item->item->x;
7852 *y+= box.y - item->item->y;
7858 atk_image_item_interface_init (AtkImageIface *iface)
7860 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7861 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7862 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7863 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7867 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7871 GtkIconViewItemAccessible *item;
7872 GtkTextIter start, end;
7873 GtkTextBuffer *buffer;
7875 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7877 if (!GTK_IS_ICON_VIEW (item->widget))
7880 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7883 buffer = item->text_buffer;
7884 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7886 gtk_text_buffer_get_end_iter (buffer, &end);
7888 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7890 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7894 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7897 GtkIconViewItemAccessible *item;
7898 GtkTextIter start, end;
7899 GtkTextBuffer *buffer;
7903 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7905 if (!GTK_IS_ICON_VIEW (item->widget))
7908 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7911 buffer = item->text_buffer;
7912 if (offset >= gtk_text_buffer_get_char_count (buffer))
7915 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7917 gtk_text_iter_forward_char (&end);
7918 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7919 unichar = g_utf8_get_char (string);
7927 get_pango_text_offsets (PangoLayout *layout,
7928 GtkTextBuffer *buffer,
7930 AtkTextBoundary boundary_type,
7934 GtkTextIter *start_iter,
7935 GtkTextIter *end_iter)
7937 PangoLayoutIter *iter;
7938 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7939 gint index, start_index, end_index;
7941 gboolean found = FALSE;
7943 text = pango_layout_get_text (layout);
7944 index = g_utf8_offset_to_pointer (text, offset) - text;
7945 iter = pango_layout_get_iter (layout);
7948 line = pango_layout_iter_get_line_readonly (iter);
7949 start_index = line->start_index;
7950 end_index = start_index + line->length;
7952 if (index >= start_index && index <= end_index)
7955 * Found line for offset
7961 * We want the previous line
7965 switch (boundary_type)
7967 case ATK_TEXT_BOUNDARY_LINE_START:
7968 end_index = start_index;
7969 start_index = prev_line->start_index;
7971 case ATK_TEXT_BOUNDARY_LINE_END:
7973 start_index = prev_prev_line->start_index +
7974 prev_prev_line->length;
7975 end_index = prev_line->start_index + prev_line->length;
7978 g_assert_not_reached();
7982 start_index = end_index = 0;
7985 switch (boundary_type)
7987 case ATK_TEXT_BOUNDARY_LINE_START:
7988 if (pango_layout_iter_next_line (iter))
7989 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7991 case ATK_TEXT_BOUNDARY_LINE_END:
7993 start_index = prev_line->start_index +
7997 g_assert_not_reached();
8002 * We want the next line
8004 if (pango_layout_iter_next_line (iter))
8006 line = pango_layout_iter_get_line_readonly (iter);
8007 switch (boundary_type)
8009 case ATK_TEXT_BOUNDARY_LINE_START:
8010 start_index = line->start_index;
8011 if (pango_layout_iter_next_line (iter))
8012 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8014 end_index = start_index + line->length;
8016 case ATK_TEXT_BOUNDARY_LINE_END:
8017 start_index = end_index;
8018 end_index = line->start_index + line->length;
8021 g_assert_not_reached();
8025 start_index = end_index;
8031 prev_prev_line = prev_line;
8034 while (pango_layout_iter_next_line (iter));
8038 start_index = prev_line->start_index + prev_line->length;
8039 end_index = start_index;
8041 pango_layout_iter_free (iter);
8042 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8043 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8045 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8046 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8051 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8053 AtkTextBoundary boundary_type,
8057 GtkIconViewItemAccessible *item;
8058 GtkTextIter start, end;
8059 GtkTextBuffer *buffer;
8061 GtkIconView *icon_view;
8064 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8066 if (!GTK_IS_ICON_VIEW (item->widget))
8069 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8072 buffer = item->text_buffer;
8074 if (!gtk_text_buffer_get_char_count (buffer))
8078 return g_strdup ("");
8080 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8084 switch (boundary_type)
8086 case ATK_TEXT_BOUNDARY_CHAR:
8087 gtk_text_iter_backward_char(&start);
8089 case ATK_TEXT_BOUNDARY_WORD_START:
8090 if (!gtk_text_iter_starts_word (&start))
8091 gtk_text_iter_backward_word_start (&start);
8093 gtk_text_iter_backward_word_start(&start);
8095 case ATK_TEXT_BOUNDARY_WORD_END:
8096 if (gtk_text_iter_inside_word (&start) &&
8097 !gtk_text_iter_starts_word (&start))
8098 gtk_text_iter_backward_word_start (&start);
8099 while (!gtk_text_iter_ends_word (&start))
8101 if (!gtk_text_iter_backward_char (&start))
8105 gtk_text_iter_backward_word_start(&start);
8106 while (!gtk_text_iter_ends_word (&start))
8108 if (!gtk_text_iter_backward_char (&start))
8112 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8113 if (!gtk_text_iter_starts_sentence (&start))
8114 gtk_text_iter_backward_sentence_start (&start);
8116 gtk_text_iter_backward_sentence_start (&start);
8118 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8119 if (gtk_text_iter_inside_sentence (&start) &&
8120 !gtk_text_iter_starts_sentence (&start))
8121 gtk_text_iter_backward_sentence_start (&start);
8122 while (!gtk_text_iter_ends_sentence (&start))
8124 if (!gtk_text_iter_backward_char (&start))
8128 gtk_text_iter_backward_sentence_start (&start);
8129 while (!gtk_text_iter_ends_sentence (&start))
8131 if (!gtk_text_iter_backward_char (&start))
8135 case ATK_TEXT_BOUNDARY_LINE_START:
8136 case ATK_TEXT_BOUNDARY_LINE_END:
8138 icon_view = GTK_ICON_VIEW (item->widget);
8139 /* FIXME we probably have to use GailTextCell to salvage this */
8140 gtk_icon_view_update_item_text (icon_view, item->item);
8141 get_pango_text_offsets (icon_view->priv->layout,
8154 *start_offset = gtk_text_iter_get_offset (&start);
8155 *end_offset = gtk_text_iter_get_offset (&end);
8157 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8161 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8163 AtkTextBoundary boundary_type,
8167 GtkIconViewItemAccessible *item;
8168 GtkTextIter start, end;
8169 GtkTextBuffer *buffer;
8171 GtkIconView *icon_view;
8174 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8176 if (!GTK_IS_ICON_VIEW (item->widget))
8179 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8182 buffer = item->text_buffer;
8184 if (!gtk_text_buffer_get_char_count (buffer))
8188 return g_strdup ("");
8190 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8194 switch (boundary_type)
8196 case ATK_TEXT_BOUNDARY_CHAR:
8197 gtk_text_iter_forward_char (&end);
8199 case ATK_TEXT_BOUNDARY_WORD_START:
8200 if (!gtk_text_iter_starts_word (&start))
8201 gtk_text_iter_backward_word_start (&start);
8202 if (gtk_text_iter_inside_word (&end))
8203 gtk_text_iter_forward_word_end (&end);
8204 while (!gtk_text_iter_starts_word (&end))
8206 if (!gtk_text_iter_forward_char (&end))
8210 case ATK_TEXT_BOUNDARY_WORD_END:
8211 if (gtk_text_iter_inside_word (&start) &&
8212 !gtk_text_iter_starts_word (&start))
8213 gtk_text_iter_backward_word_start (&start);
8214 while (!gtk_text_iter_ends_word (&start))
8216 if (!gtk_text_iter_backward_char (&start))
8219 gtk_text_iter_forward_word_end (&end);
8221 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8222 if (!gtk_text_iter_starts_sentence (&start))
8223 gtk_text_iter_backward_sentence_start (&start);
8224 if (gtk_text_iter_inside_sentence (&end))
8225 gtk_text_iter_forward_sentence_end (&end);
8226 while (!gtk_text_iter_starts_sentence (&end))
8228 if (!gtk_text_iter_forward_char (&end))
8232 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8233 if (gtk_text_iter_inside_sentence (&start) &&
8234 !gtk_text_iter_starts_sentence (&start))
8235 gtk_text_iter_backward_sentence_start (&start);
8236 while (!gtk_text_iter_ends_sentence (&start))
8238 if (!gtk_text_iter_backward_char (&start))
8241 gtk_text_iter_forward_sentence_end (&end);
8243 case ATK_TEXT_BOUNDARY_LINE_START:
8244 case ATK_TEXT_BOUNDARY_LINE_END:
8246 icon_view = GTK_ICON_VIEW (item->widget);
8247 /* FIXME we probably have to use GailTextCell to salvage this */
8248 gtk_icon_view_update_item_text (icon_view, item->item);
8249 get_pango_text_offsets (icon_view->priv->layout,
8263 *start_offset = gtk_text_iter_get_offset (&start);
8264 *end_offset = gtk_text_iter_get_offset (&end);
8266 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8270 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8272 AtkTextBoundary boundary_type,
8276 GtkIconViewItemAccessible *item;
8277 GtkTextIter start, end;
8278 GtkTextBuffer *buffer;
8280 GtkIconView *icon_view;
8283 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8285 if (!GTK_IS_ICON_VIEW (item->widget))
8288 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8291 buffer = item->text_buffer;
8293 if (!gtk_text_buffer_get_char_count (buffer))
8297 return g_strdup ("");
8299 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8303 switch (boundary_type)
8305 case ATK_TEXT_BOUNDARY_CHAR:
8306 gtk_text_iter_forward_char(&start);
8307 gtk_text_iter_forward_chars(&end, 2);
8309 case ATK_TEXT_BOUNDARY_WORD_START:
8310 if (gtk_text_iter_inside_word (&end))
8311 gtk_text_iter_forward_word_end (&end);
8312 while (!gtk_text_iter_starts_word (&end))
8314 if (!gtk_text_iter_forward_char (&end))
8318 if (!gtk_text_iter_is_end (&end))
8320 gtk_text_iter_forward_word_end (&end);
8321 while (!gtk_text_iter_starts_word (&end))
8323 if (!gtk_text_iter_forward_char (&end))
8328 case ATK_TEXT_BOUNDARY_WORD_END:
8329 gtk_text_iter_forward_word_end (&end);
8331 if (!gtk_text_iter_is_end (&end))
8332 gtk_text_iter_forward_word_end (&end);
8334 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8335 if (gtk_text_iter_inside_sentence (&end))
8336 gtk_text_iter_forward_sentence_end (&end);
8337 while (!gtk_text_iter_starts_sentence (&end))
8339 if (!gtk_text_iter_forward_char (&end))
8343 if (!gtk_text_iter_is_end (&end))
8345 gtk_text_iter_forward_sentence_end (&end);
8346 while (!gtk_text_iter_starts_sentence (&end))
8348 if (!gtk_text_iter_forward_char (&end))
8353 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8354 gtk_text_iter_forward_sentence_end (&end);
8356 if (!gtk_text_iter_is_end (&end))
8357 gtk_text_iter_forward_sentence_end (&end);
8359 case ATK_TEXT_BOUNDARY_LINE_START:
8360 case ATK_TEXT_BOUNDARY_LINE_END:
8362 icon_view = GTK_ICON_VIEW (item->widget);
8363 /* FIXME we probably have to use GailTextCell to salvage this */
8364 gtk_icon_view_update_item_text (icon_view, item->item);
8365 get_pango_text_offsets (icon_view->priv->layout,
8377 *start_offset = gtk_text_iter_get_offset (&start);
8378 *end_offset = gtk_text_iter_get_offset (&end);
8380 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8384 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8386 GtkIconViewItemAccessible *item;
8388 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8390 if (!GTK_IS_ICON_VIEW (item->widget))
8393 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8396 return gtk_text_buffer_get_char_count (item->text_buffer);
8400 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8406 AtkCoordType coord_type)
8408 GtkIconViewItemAccessible *item;
8410 GtkIconView *icon_view;
8411 PangoRectangle char_rect;
8412 const gchar *item_text;
8416 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8418 if (!GTK_IS_ICON_VIEW (item->widget))
8421 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8425 icon_view = GTK_ICON_VIEW (item->widget);
8426 /* FIXME we probably have to use GailTextCell to salvage this */
8427 gtk_icon_view_update_item_text (icon_view, item->item);
8428 item_text = pango_layout_get_text (icon_view->priv->layout);
8429 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8430 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8432 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8433 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8434 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8435 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8436 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8437 *width = char_rect.width / PANGO_SCALE;
8438 *height = char_rect.height / PANGO_SCALE;
8443 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8446 AtkCoordType coord_type)
8448 GtkIconViewItemAccessible *item;
8451 GtkIconView *icon_view;
8452 const gchar *item_text;
8457 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8459 if (!GTK_IS_ICON_VIEW (item->widget))
8462 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8466 icon_view = GTK_ICON_VIEW (item->widget);
8467 /* FIXME we probably have to use GailTextCell to salvage this */
8468 gtk_icon_view_update_item_text (icon_view, item->item);
8469 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8470 x -= l_x + item->item->layout_x - item->item->x;
8471 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8472 y -= l_y + item->item->layout_y - item->item->y;
8473 item_text = pango_layout_get_text (icon_view->priv->layout);
8474 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8485 offset = g_utf8_strlen (item_text, -1);
8487 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8493 atk_text_item_interface_init (AtkTextIface *iface)
8495 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8496 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8497 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8498 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8499 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8500 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8501 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8502 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8506 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8511 AtkCoordType coord_type)
8513 GtkIconViewItemAccessible *item;
8514 AtkObject *parent_obj;
8517 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8519 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8520 if (!GTK_IS_WIDGET (item->widget))
8523 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8526 *width = item->item->width;
8527 *height = item->item->height;
8528 if (gtk_icon_view_item_accessible_is_showing (item))
8530 parent_obj = gtk_widget_get_accessible (item->widget);
8531 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8532 *x = l_x + item->item->x;
8533 *y = l_y + item->item->y;
8543 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8545 GtkIconViewItemAccessible *item;
8546 GtkWidget *toplevel;
8548 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8550 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8551 if (!GTK_IS_WIDGET (item->widget))
8554 gtk_widget_grab_focus (item->widget);
8555 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8556 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8557 if (gtk_widget_is_toplevel (toplevel))
8558 gtk_window_present (GTK_WINDOW (toplevel));
8564 atk_component_item_interface_init (AtkComponentIface *iface)
8566 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8567 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8571 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8572 AtkStateType state_type,
8573 gboolean emit_signal)
8577 rc = atk_state_set_add_state (item->state_set, state_type);
8579 * The signal should only be generated if the value changed,
8580 * not when the item is set up. So states that are set
8581 * initially should pass FALSE as the emit_signal argument.
8586 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8587 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8588 if (state_type == ATK_STATE_VISIBLE)
8589 g_signal_emit_by_name (item, "visible-data-changed");
8596 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8597 AtkStateType state_type,
8598 gboolean emit_signal)
8600 if (atk_state_set_contains_state (item->state_set, state_type))
8604 rc = atk_state_set_remove_state (item->state_set, state_type);
8606 * The signal should only be generated if the value changed,
8607 * not when the item is set up. So states that are set
8608 * initially should pass FALSE as the emit_signal argument.
8613 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8614 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8615 if (state_type == ATK_STATE_VISIBLE)
8616 g_signal_emit_by_name (item, "visible-data-changed");
8626 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8628 GtkIconView *icon_view;
8629 GdkRectangle visible_rect;
8630 gboolean is_showing;
8633 * An item is considered "SHOWING" if any part of the item is in the
8634 * visible rectangle.
8637 if (!GTK_IS_ICON_VIEW (item->widget))
8640 if (item->item == NULL)
8643 icon_view = GTK_ICON_VIEW (item->widget);
8645 if (icon_view->priv->hadjustment)
8646 visible_rect.x += icon_view->priv->hadjustment->value;
8648 if (icon_view->priv->hadjustment)
8649 visible_rect.y += icon_view->priv->vadjustment->value;
8650 visible_rect.width = item->widget->allocation.width;
8651 visible_rect.height = item->widget->allocation.height;
8653 if (((item->item->x + item->item->width) < visible_rect.x) ||
8654 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8655 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8656 (item->item->y > (visible_rect.y + visible_rect.height)))
8665 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8666 gboolean emit_signal)
8668 if (gtk_icon_view_item_accessible_is_showing (item))
8669 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8672 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8677 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8681 item->state_set = atk_state_set_new ();
8683 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8684 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8685 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8686 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8687 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8689 for (i = 0; i < LAST_ACTION; i++)
8690 item->action_descriptions[i] = NULL;
8692 item->image_description = NULL;
8694 item->action_idle_handler = 0;
8698 gtk_icon_view_item_accessible_finalize (GObject *object)
8700 GtkIconViewItemAccessible *item;
8703 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8705 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8708 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8710 if (item->state_set)
8711 g_object_unref (item->state_set);
8713 if (item->text_buffer)
8714 g_object_unref (item->text_buffer);
8716 for (i = 0; i < LAST_ACTION; i++)
8717 g_free (item->action_descriptions[i]);
8719 g_free (item->image_description);
8721 if (item->action_idle_handler)
8723 g_source_remove (item->action_idle_handler);
8724 item->action_idle_handler = 0;
8727 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8730 static G_CONST_RETURN gchar*
8731 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8737 GtkIconViewItemAccessible *item;
8738 GtkTextIter start_iter;
8739 GtkTextIter end_iter;
8741 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8743 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8744 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8746 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8751 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8753 GtkIconViewItemAccessible *item;
8755 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8756 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8759 return gtk_widget_get_accessible (item->widget);
8765 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8767 GtkIconViewItemAccessible *item;
8769 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8770 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8772 return item->item->index;
8775 static AtkStateSet *
8776 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8778 GtkIconViewItemAccessible *item;
8779 GtkIconView *icon_view;
8781 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8782 g_return_val_if_fail (item->state_set, NULL);
8787 icon_view = GTK_ICON_VIEW (item->widget);
8788 if (icon_view->priv->cursor_item == item->item)
8789 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8791 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8792 if (item->item->selected)
8793 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8795 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8797 return g_object_ref (item->state_set);
8801 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8803 GObjectClass *gobject_class;
8805 accessible_item_parent_class = g_type_class_peek_parent (klass);
8807 gobject_class = (GObjectClass *)klass;
8809 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8811 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8812 klass->get_name = gtk_icon_view_item_accessible_get_name;
8813 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8814 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8818 gtk_icon_view_item_accessible_get_type (void)
8820 static GType type = 0;
8824 const GTypeInfo tinfo =
8826 sizeof (GtkIconViewItemAccessibleClass),
8827 (GBaseInitFunc) NULL, /* base init */
8828 (GBaseFinalizeFunc) NULL, /* base finalize */
8829 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8830 (GClassFinalizeFunc) NULL, /* class finalize */
8831 NULL, /* class data */
8832 sizeof (GtkIconViewItemAccessible), /* instance size */
8833 0, /* nb preallocs */
8834 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8835 NULL /* value table */
8838 const GInterfaceInfo atk_component_info =
8840 (GInterfaceInitFunc) atk_component_item_interface_init,
8841 (GInterfaceFinalizeFunc) NULL,
8844 const GInterfaceInfo atk_action_info =
8846 (GInterfaceInitFunc) atk_action_item_interface_init,
8847 (GInterfaceFinalizeFunc) NULL,
8850 const GInterfaceInfo atk_image_info =
8852 (GInterfaceInitFunc) atk_image_item_interface_init,
8853 (GInterfaceFinalizeFunc) NULL,
8856 const GInterfaceInfo atk_text_info =
8858 (GInterfaceInitFunc) atk_text_item_interface_init,
8859 (GInterfaceFinalizeFunc) NULL,
8863 type = g_type_register_static (ATK_TYPE_OBJECT,
8864 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8865 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8866 &atk_component_info);
8867 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8869 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8871 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8878 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8879 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8880 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8882 static GType gtk_icon_view_accessible_get_type (void);
8887 } GtkIconViewAccessible;
8893 } GtkIconViewItemAccessibleInfo;
8899 GtkAdjustment *old_hadj;
8900 GtkAdjustment *old_vadj;
8902 GtkTreeModel *model;
8904 } GtkIconViewAccessiblePrivate;
8906 static GtkIconViewAccessiblePrivate *
8907 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8909 return g_object_get_qdata (G_OBJECT (accessible),
8910 accessible_private_data_quark);
8914 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8918 GtkIconViewItemAccessibleInfo *info;
8919 GtkIconViewItemAccessibleInfo *tmp_info;
8920 GtkIconViewAccessiblePrivate *priv;
8923 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8925 info->index = index;
8927 priv = gtk_icon_view_accessible_get_priv (accessible);
8928 items = priv->items;
8931 tmp_info = items->data;
8932 if (tmp_info->index > index)
8934 items = items->next;
8936 priv->items = g_list_insert_before (priv->items, items, info);
8937 priv->old_hadj = NULL;
8938 priv->old_vadj = NULL;
8942 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8944 GtkIconView *icon_view;
8947 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8951 icon_view = GTK_ICON_VIEW (widget);
8953 return g_list_length (icon_view->priv->items);
8957 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8960 GtkIconViewAccessiblePrivate *priv;
8961 GtkIconViewItemAccessibleInfo *info;
8964 priv = gtk_icon_view_accessible_get_priv (accessible);
8965 items = priv->items;
8970 if (info->index == index)
8972 items = items->next;
8978 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8981 GtkIconView *icon_view;
8985 GtkIconViewItemAccessible *a11y_item;
8987 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8991 icon_view = GTK_ICON_VIEW (widget);
8992 icons = g_list_nth (icon_view->priv->items, index);
8996 GtkIconViewItem *item = icons->data;
8998 g_return_val_if_fail (item->index == index, NULL);
8999 obj = gtk_icon_view_accessible_find_child (accessible, index);
9004 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9005 gtk_icon_view_item_accessible_info_new (accessible,
9008 obj->role = ATK_ROLE_ICON;
9009 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9010 a11y_item->item = item;
9011 a11y_item->widget = widget;
9012 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9014 gtk_icon_view_set_cell_data (icon_view, item);
9015 text = get_text (icon_view, item);
9018 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9022 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9023 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9031 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9034 GtkIconViewAccessiblePrivate *priv;
9035 GtkIconViewItemAccessibleInfo *info;
9036 GtkIconViewItemAccessible *item;
9039 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9043 gboolean act_on_item;
9045 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9049 items = priv->items;
9051 act_on_item = (list == NULL);
9056 info = (GtkIconViewItemAccessibleInfo *)items->data;
9057 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9059 if (act_on_item == FALSE && list == items)
9063 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9065 items = items->next;
9071 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9072 GtkIconView *icon_view)
9075 GtkIconViewAccessible *view;
9078 * The scrollbars have changed
9080 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9081 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9083 gtk_icon_view_accessible_traverse_items (view, NULL);
9087 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9088 GtkAdjustment *hadj,
9089 GtkAdjustment *vadj)
9092 GtkIconViewAccessiblePrivate *priv;
9094 atk_obj = gtk_widget_get_accessible (widget);
9095 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9097 if (priv->old_hadj != hadj)
9101 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9102 (gpointer *)&priv->old_hadj);
9104 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9105 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9108 priv->old_hadj = hadj;
9111 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9112 (gpointer *)&priv->old_hadj);
9113 g_signal_connect (hadj,
9115 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9119 if (priv->old_vadj != vadj)
9123 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9124 (gpointer *)&priv->old_vadj);
9126 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9127 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9130 priv->old_vadj = vadj;
9133 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9134 (gpointer *)&priv->old_vadj);
9135 g_signal_connect (vadj,
9137 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9144 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9152 GtkIconView *icon_view;
9153 GtkIconViewItem *item;
9154 GtkIconViewAccessible *a11y_view;
9155 GtkIconViewItemAccessible *a11y_item;
9159 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9160 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9161 index = gtk_tree_path_get_indices(path)[0];
9162 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9163 gtk_icon_view_accessible_find_child (atk_obj, index));
9167 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9168 icon_view = GTK_ICON_VIEW (widget);
9169 item = a11y_item->item;
9171 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9173 if (!name || strcmp (name, "") == 0)
9175 gtk_icon_view_set_cell_data (icon_view, item);
9176 text = get_text (icon_view, item);
9179 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9185 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9191 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9196 GtkIconViewAccessiblePrivate *priv;
9197 GtkIconViewItemAccessibleInfo *info;
9198 GtkIconViewAccessible *view;
9199 GtkIconViewItemAccessible *item;
9205 index = gtk_tree_path_get_indices(path)[0];
9206 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9207 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9208 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9210 items = priv->items;
9215 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9216 if (info->index != item->item->index)
9218 if (info->index < index)
9219 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9221 if (tmp_list == NULL)
9224 info->index = item->item->index;
9227 items = items->next;
9229 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9230 g_signal_emit_by_name (atk_obj, "children-changed::add",
9236 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9240 GtkIconViewAccessiblePrivate *priv;
9241 GtkIconViewItemAccessibleInfo *info;
9242 GtkIconViewAccessible *view;
9243 GtkIconViewItemAccessible *item;
9246 GList *deleted_item;
9250 index = gtk_tree_path_get_indices(path)[0];
9251 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9252 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9253 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9255 items = priv->items;
9257 deleted_item = NULL;
9262 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9263 if (info->index == index)
9265 deleted_item = items;
9267 if (info->index != item->item->index)
9269 if (tmp_list == NULL)
9272 info->index = item->item->index;
9275 items = items->next;
9277 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9280 info = deleted_item->data;
9281 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9282 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9284 priv->items = g_list_remove_link (priv->items, deleted_item);
9292 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9293 GtkIconViewItemAccessibleInfo *i2)
9295 return i1->index - i2->index;
9299 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9305 GtkIconViewAccessiblePrivate *priv;
9306 GtkIconViewItemAccessibleInfo *info;
9307 GtkIconView *icon_view;
9308 GtkIconViewItemAccessible *item;
9314 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9315 icon_view = GTK_ICON_VIEW (user_data);
9316 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9318 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9320 order = g_new (gint, length);
9321 for (i = 0; i < length; i++)
9322 order [new_order[i]] = i;
9324 items = priv->items;
9328 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9329 info->index = order[info->index];
9330 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9331 items = items->next;
9334 priv->items = g_list_sort (priv->items,
9335 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9341 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9346 obj = G_OBJECT (model);
9347 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9348 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9349 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9350 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9354 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9358 obj = G_OBJECT (icon_view->priv->model);
9359 g_signal_connect_data (obj, "row-changed",
9360 (GCallback) gtk_icon_view_accessible_model_row_changed,
9361 icon_view, NULL, 0);
9362 g_signal_connect_data (obj, "row-inserted",
9363 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9364 icon_view, NULL, G_CONNECT_AFTER);
9365 g_signal_connect_data (obj, "row-deleted",
9366 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9367 icon_view, NULL, G_CONNECT_AFTER);
9368 g_signal_connect_data (obj, "rows-reordered",
9369 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9370 icon_view, NULL, G_CONNECT_AFTER);
9374 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9376 GtkIconViewItemAccessibleInfo *info;
9379 items = priv->items;
9382 info = (GtkIconViewItemAccessibleInfo *) items->data;
9383 g_object_unref (info->item);
9384 g_free (items->data);
9385 items = items->next;
9387 g_list_free (priv->items);
9392 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9395 GtkIconView *icon_view;
9398 GtkIconViewAccessiblePrivate *priv;
9400 if (strcmp (pspec->name, "model") == 0)
9402 widget = GTK_WIDGET (obj);
9403 atk_obj = gtk_widget_get_accessible (widget);
9404 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9407 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9408 (gpointer *)&priv->model);
9409 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9411 gtk_icon_view_accessible_clear_cache (priv);
9413 icon_view = GTK_ICON_VIEW (obj);
9414 priv->model = icon_view->priv->model;
9415 /* If there is no model the GtkIconView is probably being destroyed */
9418 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9419 gtk_icon_view_accessible_connect_model_signals (icon_view);
9427 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9430 GtkIconViewAccessiblePrivate *priv;
9431 GtkIconView *icon_view;
9433 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9434 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9436 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9437 g_object_set_qdata (G_OBJECT (accessible),
9438 accessible_private_data_quark,
9441 icon_view = GTK_ICON_VIEW (data);
9442 if (icon_view->priv->hadjustment)
9444 priv->old_hadj = icon_view->priv->hadjustment;
9445 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9446 g_signal_connect (icon_view->priv->hadjustment,
9448 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9451 if (icon_view->priv->vadjustment)
9453 priv->old_vadj = icon_view->priv->vadjustment;
9454 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9455 g_signal_connect (icon_view->priv->vadjustment,
9457 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9460 g_signal_connect_after (data,
9461 "set-scroll-adjustments",
9462 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9464 g_signal_connect (data,
9466 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9469 priv->model = icon_view->priv->model;
9472 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9473 gtk_icon_view_accessible_connect_model_signals (icon_view);
9476 accessible->role = ATK_ROLE_LAYERED_PANE;
9480 gtk_icon_view_accessible_finalize (GObject *object)
9482 GtkIconViewAccessiblePrivate *priv;
9484 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9485 gtk_icon_view_accessible_clear_cache (priv);
9489 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9493 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9494 GtkAccessible *accessible)
9497 GtkIconViewAccessiblePrivate *priv;
9499 atk_obj = ATK_OBJECT (accessible);
9500 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9503 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9504 (gpointer *)&priv->old_hadj);
9506 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9507 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9509 priv->old_hadj = NULL;
9513 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9514 (gpointer *)&priv->old_vadj);
9516 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9517 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9519 priv->old_vadj = NULL;
9524 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9528 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9531 g_signal_connect_after (widget,
9533 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9536 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9540 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9542 GObjectClass *gobject_class;
9543 GtkAccessibleClass *accessible_class;
9545 accessible_parent_class = g_type_class_peek_parent (klass);
9547 gobject_class = (GObjectClass *)klass;
9548 accessible_class = (GtkAccessibleClass *)klass;
9550 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9552 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9553 klass->ref_child = gtk_icon_view_accessible_ref_child;
9554 klass->initialize = gtk_icon_view_accessible_initialize;
9556 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9558 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9562 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9565 AtkCoordType coord_type)
9568 GtkIconView *icon_view;
9569 GtkIconViewItem *item;
9572 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9574 /* State is defunct */
9577 icon_view = GTK_ICON_VIEW (widget);
9578 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9579 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9581 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9587 atk_component_interface_init (AtkComponentIface *iface)
9589 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9593 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9597 GtkIconView *icon_view;
9598 GtkIconViewItem *item;
9600 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9604 icon_view = GTK_ICON_VIEW (widget);
9606 item = g_list_nth_data (icon_view->priv->items, i);
9611 gtk_icon_view_select_item (icon_view, item);
9617 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9620 GtkIconView *icon_view;
9622 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9626 icon_view = GTK_ICON_VIEW (widget);
9627 gtk_icon_view_unselect_all (icon_view);
9633 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9638 GtkIconView *icon_view;
9639 GtkIconViewItem *item;
9641 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9645 icon_view = GTK_ICON_VIEW (widget);
9647 l = icon_view->priv->items;
9654 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9665 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9668 GtkIconView *icon_view;
9669 GtkIconViewItem *item;
9673 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9677 icon_view = GTK_ICON_VIEW (widget);
9679 l = icon_view->priv->items;
9695 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9699 GtkIconView *icon_view;
9700 GtkIconViewItem *item;
9702 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9706 icon_view = GTK_ICON_VIEW (widget);
9708 item = g_list_nth_data (icon_view->priv->items, i);
9712 return item->selected;
9716 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9720 GtkIconView *icon_view;
9721 GtkIconViewItem *item;
9725 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9729 icon_view = GTK_ICON_VIEW (widget);
9730 l = icon_view->priv->items;
9739 gtk_icon_view_unselect_item (icon_view, item);
9751 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9754 GtkIconView *icon_view;
9756 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9760 icon_view = GTK_ICON_VIEW (widget);
9761 gtk_icon_view_select_all (icon_view);
9766 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9768 iface->add_selection = gtk_icon_view_accessible_add_selection;
9769 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9770 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9771 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9772 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9773 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9774 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9778 gtk_icon_view_accessible_get_type (void)
9780 static GType type = 0;
9787 (GBaseInitFunc) NULL, /* base init */
9788 (GBaseFinalizeFunc) NULL, /* base finalize */
9789 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9790 (GClassFinalizeFunc) NULL, /* class finalize */
9791 NULL, /* class data */
9792 0, /* instance size */
9793 0, /* nb preallocs */
9794 (GInstanceInitFunc) NULL, /* instance init */
9795 NULL /* value table */
9797 const GInterfaceInfo atk_component_info =
9799 (GInterfaceInitFunc) atk_component_interface_init,
9800 (GInterfaceFinalizeFunc) NULL,
9803 const GInterfaceInfo atk_selection_info =
9805 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9806 (GInterfaceFinalizeFunc) NULL,
9811 * Figure out the size of the class and instance
9812 * we are deriving from
9814 AtkObjectFactory *factory;
9817 GType derived_atk_type;
9819 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9820 factory = atk_registry_get_factory (atk_get_default_registry (),
9822 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9823 g_type_query (derived_atk_type, &query);
9824 tinfo.class_size = query.class_size;
9825 tinfo.instance_size = query.instance_size;
9827 type = g_type_register_static (derived_atk_type,
9828 I_("GtkIconViewAccessible"),
9830 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9831 &atk_component_info);
9832 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9833 &atk_selection_info);
9839 gtk_icon_view_accessible_new (GObject *obj)
9841 AtkObject *accessible;
9843 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9845 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9846 atk_object_initialize (accessible, obj);
9852 gtk_icon_view_accessible_factory_get_accessible_type (void)
9854 return gtk_icon_view_accessible_get_type ();
9858 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9860 return gtk_icon_view_accessible_new (obj);
9864 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9866 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9867 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9871 gtk_icon_view_accessible_factory_get_type (void)
9873 static GType type = 0;
9877 const GTypeInfo tinfo =
9879 sizeof (AtkObjectFactoryClass),
9880 NULL, /* base_init */
9881 NULL, /* base_finalize */
9882 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9883 NULL, /* class_finalize */
9884 NULL, /* class_data */
9885 sizeof (AtkObjectFactory),
9886 0, /* n_preallocs */
9890 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9891 I_("GtkIconViewAccessibleFactory"),
9899 gtk_icon_view_get_accessible (GtkWidget *widget)
9901 static gboolean first_time = TRUE;
9905 AtkObjectFactory *factory;
9906 AtkRegistry *registry;
9908 GType derived_atk_type;
9911 * Figure out whether accessibility is enabled by looking at the
9912 * type of the accessible object which would be created for
9913 * the parent type of GtkIconView.
9915 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9917 registry = atk_get_default_registry ();
9918 factory = atk_registry_get_factory (registry,
9920 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9921 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9922 atk_registry_set_factory_type (registry,
9924 gtk_icon_view_accessible_factory_get_type ());
9927 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9931 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9932 GtkBuilder *builder,
9934 const gchar *tagname,
9935 GMarkupParser *parser,
9938 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9939 tagname, parser, data))
9942 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9943 tagname, parser, data);
9947 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9948 GtkBuilder *builder,
9950 const gchar *tagname,
9953 if (strcmp (tagname, "attributes") == 0)
9954 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9957 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,