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 "gtkscrollable.h"
43 #include "gtksizerequest.h"
44 #include "gtktreednd.h"
45 #include "gtkprivate.h"
50 * @short_description: A widget which displays a list of icons in a grid
52 * #GtkIconView provides an alternative view on a #GtkTreeModel.
53 * It displays the model as a grid of icons with labels. Like
54 * #GtkTreeView, it allows to select one or multiple items
55 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
56 * In addition to selection with the arrow keys, #GtkIconView supports
57 * rubberband selection, which is controlled by dragging the pointer.
59 * Note that if the tree model is backed by an actual tree store (as
60 * opposed to a flat list where the mapping to icons is obvious),
61 * #GtkIconView will only display the first level of the tree and
62 * ignore the tree's branches.
65 #define SCROLL_EDGE_SIZE 15
67 #define GTK_ICON_VIEW_PRIORITY_LAYOUT (GDK_PRIORITY_REDRAW + 5)
69 typedef struct _GtkIconViewItem GtkIconViewItem;
70 struct _GtkIconViewItem
78 gint x, y, width, height;
81 * box[i] is the actual area occupied by cell i,
82 * before, after are used to calculate the cell
83 * area relative to the box.
84 * See gtk_icon_view_get_cell_area().
92 guint selected_before_rubberbanding : 1;
96 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
97 struct _GtkIconViewCellInfo
99 GtkCellRenderer *cell;
109 GtkCellLayoutDataFunc func;
111 GDestroyNotify destroy;
114 typedef struct _GtkIconViewChild GtkIconViewChild;
115 struct _GtkIconViewChild
118 GtkIconViewItem *item;
122 struct _GtkIconViewPrivate
126 GtkSelectionMode selection_mode;
128 GdkWindow *bin_window;
136 GtkAdjustment *hadjustment;
137 GtkAdjustment *vadjustment;
139 guint layout_idle_id;
141 gboolean doing_rubberband;
142 gint rubberband_x1, rubberband_y1;
143 gint rubberband_x2, rubberband_y2;
144 GdkDevice *rubberband_device;
146 guint scroll_timeout_id;
147 gint scroll_value_diff;
148 gint event_last_x, event_last_y;
150 GtkIconViewItem *anchor_item;
151 GtkIconViewItem *cursor_item;
152 GtkIconViewItem *edited_item;
153 GtkCellEditable *editable;
155 GtkIconViewItem *last_single_clicked;
162 GtkOrientation item_orientation;
182 GdkModifierType start_button_mask;
187 GdkDragAction source_actions;
188 GdkDragAction dest_actions;
190 GtkTreeRowReference *dest_item;
191 GtkIconViewDropPosition dest_pos;
194 GtkTreeRowReference *scroll_to_path;
195 gfloat scroll_to_row_align;
196 gfloat scroll_to_col_align;
197 guint scroll_to_use_align : 1;
199 guint source_set : 1;
201 guint reorderable : 1;
202 guint empty_view_drop :1;
204 guint ctrl_pressed : 1;
205 guint shift_pressed : 1;
207 guint draw_focus : 1;
209 /* GtkScrollablePolicy needs to be checked when
210 * driving the scrollable adjustment values */
211 guint hscroll_policy : 1;
212 guint vscroll_policy : 1;
225 ACTIVATE_CURSOR_ITEM,
237 PROP_ITEM_ORIENTATION,
249 /* For scrollable interface */
257 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
258 static void gtk_icon_view_finalize (GObject *object);
259 static void gtk_icon_view_set_property (GObject *object,
263 static void gtk_icon_view_get_property (GObject *object,
267 /* GtkWidget vfuncs */
268 static void gtk_icon_view_destroy (GtkWidget *widget);
269 static void gtk_icon_view_realize (GtkWidget *widget);
270 static void gtk_icon_view_unrealize (GtkWidget *widget);
271 static void gtk_icon_view_style_set (GtkWidget *widget,
272 GtkStyle *previous_style);
273 static void gtk_icon_view_state_changed (GtkWidget *widget,
274 GtkStateType previous_state);
275 static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
278 static void gtk_icon_view_get_preferred_height (GtkWidget *widget,
281 static void gtk_icon_view_size_allocate (GtkWidget *widget,
282 GtkAllocation *allocation);
283 static gboolean gtk_icon_view_draw (GtkWidget *widget,
285 static gboolean gtk_icon_view_motion (GtkWidget *widget,
286 GdkEventMotion *event);
287 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
288 GdkEventButton *event);
289 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
290 GdkEventButton *event);
291 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
293 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
295 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
298 /* GtkContainer vfuncs */
299 static void gtk_icon_view_remove (GtkContainer *container,
301 static void gtk_icon_view_forall (GtkContainer *container,
302 gboolean include_internals,
303 GtkCallback callback,
304 gpointer callback_data);
306 /* GtkIconView vfuncs */
307 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
308 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
309 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
310 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
311 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
313 /* Internal functions */
314 static void gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view);
315 static void gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view);
316 static void gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
317 GtkAdjustment *adjustment);
318 static void gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
319 GtkAdjustment *adjustment);
320 static void gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
321 GtkOrientation orientation,
322 GtkAdjustment *adjustment);
323 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
324 GtkIconView *icon_view);
325 static void gtk_icon_view_layout (GtkIconView *icon_view);
326 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
328 GtkIconViewItem *item,
331 gboolean draw_focus);
332 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
334 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
336 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
337 GtkIconViewItem *item);
338 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
339 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
340 GtkIconViewItem *item,
342 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
346 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
347 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
348 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
349 GtkIconViewItem *item,
354 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
355 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
356 GtkIconViewItem *item);
357 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
358 GtkIconViewItem *item,
360 static void gtk_icon_view_update_rubberband (gpointer data);
361 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
362 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
363 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
366 GtkMovementStep step,
368 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
369 GtkMovementStep step,
371 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
373 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
375 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
377 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
379 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
380 GtkIconViewItem *item);
381 static void gtk_icon_view_select_item (GtkIconView *icon_view,
382 GtkIconViewItem *item);
383 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
384 GtkIconViewItem *item);
385 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
386 GtkIconViewItem *anchor,
387 GtkIconViewItem *cursor);
388 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
391 gboolean only_in_cell,
392 GtkIconViewCellInfo **cell_at_pos);
393 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
394 GtkIconViewItem *item,
395 GtkIconViewCellInfo *cell_info,
396 GdkRectangle *cell_area);
397 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
398 GtkIconViewItem *item,
399 GtkIconViewCellInfo *info,
401 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
402 GtkCellRenderer *renderer);
403 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
404 GtkIconViewItem *item);
405 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
406 GtkCellRenderer *renderer,
408 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
409 GtkCellRenderer *renderer,
411 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
412 GtkCellRenderer *renderer,
413 const gchar *attribute,
415 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
416 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
417 GtkCellRenderer *renderer);
418 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
419 GtkCellRenderer *cell,
420 GtkCellLayoutDataFunc func,
422 GDestroyNotify destroy);
423 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
424 GtkCellRenderer *cell,
426 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
428 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
429 GtkIconViewItem *item,
430 GtkIconViewCellInfo *cell_info,
432 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
433 GtkIconViewItem *item);
434 static void gtk_icon_view_put (GtkIconView *icon_view,
436 GtkIconViewItem *item,
438 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
439 GtkIconView *icon_view);
440 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
441 GtkIconViewItem *item,
442 GtkIconViewCellInfo *cell_info,
444 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
445 gboolean cancel_editing);
447 /* Source side drag signals */
448 static void gtk_icon_view_drag_begin (GtkWidget *widget,
449 GdkDragContext *context);
450 static void gtk_icon_view_drag_end (GtkWidget *widget,
451 GdkDragContext *context);
452 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
453 GdkDragContext *context,
454 GtkSelectionData *selection_data,
457 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
458 GdkDragContext *context);
460 /* Target side drag signals */
461 static void gtk_icon_view_drag_leave (GtkWidget *widget,
462 GdkDragContext *context,
464 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
465 GdkDragContext *context,
469 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
470 GdkDragContext *context,
474 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
475 GdkDragContext *context,
478 GtkSelectionData *selection_data,
481 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
482 GdkEventMotion *event);
484 static void remove_scroll_timeout (GtkIconView *icon_view);
486 static void adjust_wrap_width (GtkIconView *icon_view,
487 GtkIconViewItem *item);
490 static GtkBuildableIface *parent_buildable_iface;
491 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
492 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
495 const gchar *tagname,
496 GMarkupParser *parser,
498 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
501 const gchar *tagname,
504 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
506 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
507 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
508 gtk_icon_view_cell_layout_init)
509 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
510 gtk_icon_view_buildable_init)
511 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
514 gtk_icon_view_class_init (GtkIconViewClass *klass)
516 GObjectClass *gobject_class;
517 GtkWidgetClass *widget_class;
518 GtkContainerClass *container_class;
519 GtkBindingSet *binding_set;
521 binding_set = gtk_binding_set_by_class (klass);
523 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
525 gobject_class = (GObjectClass *) klass;
526 widget_class = (GtkWidgetClass *) klass;
527 container_class = (GtkContainerClass *) klass;
529 gobject_class->finalize = gtk_icon_view_finalize;
530 gobject_class->set_property = gtk_icon_view_set_property;
531 gobject_class->get_property = gtk_icon_view_get_property;
533 widget_class->destroy = gtk_icon_view_destroy;
534 widget_class->realize = gtk_icon_view_realize;
535 widget_class->unrealize = gtk_icon_view_unrealize;
536 widget_class->style_set = gtk_icon_view_style_set;
537 widget_class->get_accessible = gtk_icon_view_get_accessible;
538 widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
539 widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
540 widget_class->size_allocate = gtk_icon_view_size_allocate;
541 widget_class->draw = gtk_icon_view_draw;
542 widget_class->motion_notify_event = gtk_icon_view_motion;
543 widget_class->button_press_event = gtk_icon_view_button_press;
544 widget_class->button_release_event = gtk_icon_view_button_release;
545 widget_class->key_press_event = gtk_icon_view_key_press;
546 widget_class->key_release_event = gtk_icon_view_key_release;
547 widget_class->drag_begin = gtk_icon_view_drag_begin;
548 widget_class->drag_end = gtk_icon_view_drag_end;
549 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
550 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
551 widget_class->drag_leave = gtk_icon_view_drag_leave;
552 widget_class->drag_motion = gtk_icon_view_drag_motion;
553 widget_class->drag_drop = gtk_icon_view_drag_drop;
554 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
555 widget_class->state_changed = gtk_icon_view_state_changed;
557 container_class->remove = gtk_icon_view_remove;
558 container_class->forall = gtk_icon_view_forall;
560 klass->select_all = gtk_icon_view_real_select_all;
561 klass->unselect_all = gtk_icon_view_real_unselect_all;
562 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
563 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
564 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
565 klass->move_cursor = gtk_icon_view_real_move_cursor;
569 * GtkIconView:selection-mode:
571 * The ::selection-mode property specifies the selection mode of
572 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
573 * is enabled, for the other modes, only keyboard selection is possible.
577 g_object_class_install_property (gobject_class,
579 g_param_spec_enum ("selection-mode",
580 P_("Selection mode"),
581 P_("The selection mode"),
582 GTK_TYPE_SELECTION_MODE,
583 GTK_SELECTION_SINGLE,
584 GTK_PARAM_READWRITE));
587 * GtkIconView:pixbuf-column:
589 * The ::pixbuf-column property contains the number of the model column
590 * containing the pixbufs which are displayed. The pixbuf column must be
591 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
592 * display of pixbufs.
596 g_object_class_install_property (gobject_class,
598 g_param_spec_int ("pixbuf-column",
600 P_("Model column used to retrieve the icon pixbuf from"),
602 GTK_PARAM_READWRITE));
605 * GtkIconView:text-column:
607 * The ::text-column property contains the number of the model column
608 * containing the texts which are displayed. The text column must be
609 * of type #G_TYPE_STRING. If this property and the :markup-column
610 * property are both set to -1, no texts are displayed.
614 g_object_class_install_property (gobject_class,
616 g_param_spec_int ("text-column",
618 P_("Model column used to retrieve the text from"),
620 GTK_PARAM_READWRITE));
624 * GtkIconView:markup-column:
626 * The ::markup-column property contains the number of the model column
627 * containing markup information to be displayed. The markup column must be
628 * of type #G_TYPE_STRING. If this property and the :text-column property
629 * are both set to column numbers, it overrides the text column.
630 * If both are set to -1, no texts are displayed.
634 g_object_class_install_property (gobject_class,
636 g_param_spec_int ("markup-column",
638 P_("Model column used to retrieve the text if using Pango markup"),
640 GTK_PARAM_READWRITE));
642 g_object_class_install_property (gobject_class,
644 g_param_spec_object ("model",
645 P_("Icon View Model"),
646 P_("The model for the icon view"),
648 GTK_PARAM_READWRITE));
651 * GtkIconView:columns:
653 * The columns property contains the number of the columns in which the
654 * items should be displayed. If it is -1, the number of columns will
655 * be chosen automatically to fill the available area.
659 g_object_class_install_property (gobject_class,
661 g_param_spec_int ("columns",
662 P_("Number of columns"),
663 P_("Number of columns to display"),
665 GTK_PARAM_READWRITE));
669 * GtkIconView:item-width:
671 * The item-width property specifies the width to use for each item.
672 * If it is set to -1, the icon view will automatically determine a
673 * suitable item size.
677 g_object_class_install_property (gobject_class,
679 g_param_spec_int ("item-width",
680 P_("Width for each item"),
681 P_("The width used for each item"),
683 GTK_PARAM_READWRITE));
686 * GtkIconView:spacing:
688 * The spacing property specifies the space which is inserted between
689 * the cells (i.e. the icon and the text) of an item.
693 g_object_class_install_property (gobject_class,
695 g_param_spec_int ("spacing",
697 P_("Space which is inserted between cells of an item"),
699 GTK_PARAM_READWRITE));
702 * GtkIconView:row-spacing:
704 * The row-spacing property specifies the space which is inserted between
705 * the rows of the icon view.
709 g_object_class_install_property (gobject_class,
711 g_param_spec_int ("row-spacing",
713 P_("Space which is inserted between grid rows"),
715 GTK_PARAM_READWRITE));
718 * GtkIconView:column-spacing:
720 * The column-spacing property specifies the space which is inserted between
721 * the columns of the icon view.
725 g_object_class_install_property (gobject_class,
727 g_param_spec_int ("column-spacing",
728 P_("Column Spacing"),
729 P_("Space which is inserted between grid columns"),
731 GTK_PARAM_READWRITE));
734 * GtkIconView:margin:
736 * The margin property specifies the space which is inserted
737 * at the edges of the icon view.
741 g_object_class_install_property (gobject_class,
743 g_param_spec_int ("margin",
745 P_("Space which is inserted at the edges of the icon view"),
747 GTK_PARAM_READWRITE));
750 * GtkIconView:item-orientation:
752 * The item-orientation property specifies how the cells (i.e. the icon and
753 * the text) of the item are positioned relative to each other.
757 g_object_class_install_property (gobject_class,
758 PROP_ITEM_ORIENTATION,
759 g_param_spec_enum ("item-orientation",
760 P_("Item Orientation"),
761 P_("How the text and icon of each item are positioned relative to each other"),
762 GTK_TYPE_ORIENTATION,
763 GTK_ORIENTATION_VERTICAL,
764 GTK_PARAM_READWRITE));
767 * GtkIconView:reorderable:
769 * The reorderable property specifies if the items can be reordered
774 g_object_class_install_property (gobject_class,
776 g_param_spec_boolean ("reorderable",
778 P_("View is reorderable"),
782 g_object_class_install_property (gobject_class,
784 g_param_spec_int ("tooltip-column",
785 P_("Tooltip Column"),
786 P_("The column in the model containing the tooltip texts for the items"),
790 GTK_PARAM_READWRITE));
793 * GtkIconView:item-padding:
795 * The item-padding property specifies the padding around each
796 * of the icon view's item.
800 g_object_class_install_property (gobject_class,
802 g_param_spec_int ("item-padding",
804 P_("Padding around icon view items"),
806 GTK_PARAM_READWRITE));
808 /* Scrollable interface properties */
809 g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
810 g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
811 g_object_class_override_property (gobject_class, PROP_HSCROLL_POLICY, "hscroll-policy");
812 g_object_class_override_property (gobject_class, PROP_VSCROLL_POLICY, "vscroll-policy");
814 /* Style properties */
815 gtk_widget_class_install_style_property (widget_class,
816 g_param_spec_boxed ("selection-box-color",
817 P_("Selection Box Color"),
818 P_("Color of the selection box"),
820 GTK_PARAM_READABLE));
822 gtk_widget_class_install_style_property (widget_class,
823 g_param_spec_uchar ("selection-box-alpha",
824 P_("Selection Box Alpha"),
825 P_("Opacity of the selection box"),
828 GTK_PARAM_READABLE));
832 * GtkIconView::item-activated:
833 * @iconview: the object on which the signal is emitted
834 * @path: the #GtkTreePath for the activated item
836 * The ::item-activated signal is emitted when the method
837 * gtk_icon_view_item_activated() is called or the user double
838 * clicks an item. It is also emitted when a non-editable item
839 * is selected and one of the keys: Space, Return or Enter is
842 icon_view_signals[ITEM_ACTIVATED] =
843 g_signal_new (I_("item-activated"),
844 G_TYPE_FROM_CLASS (gobject_class),
846 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
848 g_cclosure_marshal_VOID__BOXED,
853 * GtkIconView::selection-changed:
854 * @iconview: the object on which the signal is emitted
856 * The ::selection-changed signal is emitted when the selection
857 * (i.e. the set of selected items) changes.
859 icon_view_signals[SELECTION_CHANGED] =
860 g_signal_new (I_("selection-changed"),
861 G_TYPE_FROM_CLASS (gobject_class),
863 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
865 g_cclosure_marshal_VOID__VOID,
869 * GtkIconView::select-all:
870 * @iconview: the object on which the signal is emitted
872 * A <link linkend="keybinding-signals">keybinding signal</link>
873 * which gets emitted when the user selects all items.
875 * Applications should not connect to it, but may emit it with
876 * g_signal_emit_by_name() if they need to control selection
879 * The default binding for this signal is Ctrl-a.
881 icon_view_signals[SELECT_ALL] =
882 g_signal_new (I_("select-all"),
883 G_TYPE_FROM_CLASS (gobject_class),
884 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
885 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
887 g_cclosure_marshal_VOID__VOID,
891 * GtkIconView::unselect-all:
892 * @iconview: the object on which the signal is emitted
894 * A <link linkend="keybinding-signals">keybinding signal</link>
895 * which gets emitted when the user unselects all items.
897 * Applications should not connect to it, but may emit it with
898 * g_signal_emit_by_name() if they need to control selection
901 * The default binding for this signal is Ctrl-Shift-a.
903 icon_view_signals[UNSELECT_ALL] =
904 g_signal_new (I_("unselect-all"),
905 G_TYPE_FROM_CLASS (gobject_class),
906 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
907 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
909 g_cclosure_marshal_VOID__VOID,
913 * GtkIconView::select-cursor-item:
914 * @iconview: the object on which the signal is emitted
916 * A <link linkend="keybinding-signals">keybinding signal</link>
917 * which gets emitted when the user selects the item that is currently
920 * Applications should not connect to it, but may emit it with
921 * g_signal_emit_by_name() if they need to control selection
924 * There is no default binding for this signal.
926 icon_view_signals[SELECT_CURSOR_ITEM] =
927 g_signal_new (I_("select-cursor-item"),
928 G_TYPE_FROM_CLASS (gobject_class),
929 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
930 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
932 g_cclosure_marshal_VOID__VOID,
936 * GtkIconView::toggle-cursor-item:
937 * @iconview: the object on which the signal is emitted
939 * A <link linkend="keybinding-signals">keybinding signal</link>
940 * which gets emitted when the user toggles whether the currently
941 * focused item is selected or not. The exact effect of this
942 * depend on the selection mode.
944 * Applications should not connect to it, but may emit it with
945 * g_signal_emit_by_name() if they need to control selection
948 * There is no default binding for this signal is Ctrl-Space.
950 icon_view_signals[TOGGLE_CURSOR_ITEM] =
951 g_signal_new (I_("toggle-cursor-item"),
952 G_TYPE_FROM_CLASS (gobject_class),
953 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
954 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
956 g_cclosure_marshal_VOID__VOID,
960 * GtkIconView::activate-cursor-item:
961 * @iconview: the object on which the signal is emitted
963 * A <link linkend="keybinding-signals">keybinding signal</link>
964 * which gets emitted when the user activates the currently
967 * Applications should not connect to it, but may emit it with
968 * g_signal_emit_by_name() if they need to control activation
971 * The default bindings for this signal are Space, Return and Enter.
973 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
974 g_signal_new (I_("activate-cursor-item"),
975 G_TYPE_FROM_CLASS (gobject_class),
976 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
977 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
979 _gtk_marshal_BOOLEAN__VOID,
983 * GtkIconView::move-cursor:
984 * @iconview: the object which received the signal
985 * @step: the granularity of the move, as a #GtkMovementStep
986 * @count: the number of @step units to move
988 * The ::move-cursor signal is a
989 * <link linkend="keybinding-signals">keybinding signal</link>
990 * which gets emitted when the user initiates a cursor movement.
992 * Applications should not connect to it, but may emit it with
993 * g_signal_emit_by_name() if they need to control the cursor
996 * The default bindings for this signal include
998 * <listitem>Arrow keys which move by individual steps</listitem>
999 * <listitem>Home/End keys which move to the first/last item</listitem>
1000 * <listitem>PageUp/PageDown which move by "pages"</listitem>
1003 * All of these will extend the selection when combined with
1004 * the Shift modifier.
1006 icon_view_signals[MOVE_CURSOR] =
1007 g_signal_new (I_("move-cursor"),
1008 G_TYPE_FROM_CLASS (gobject_class),
1009 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1010 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1012 _gtk_marshal_BOOLEAN__ENUM_INT,
1014 GTK_TYPE_MOVEMENT_STEP,
1018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
1023 "toggle-cursor-item", 0);
1024 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
1025 "toggle-cursor-item", 0);
1027 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
1028 "activate-cursor-item", 0);
1029 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
1030 "activate-cursor-item", 0);
1031 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1032 "activate-cursor-item", 0);
1033 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1034 "activate-cursor-item", 0);
1035 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1036 "activate-cursor-item", 0);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1039 GTK_MOVEMENT_DISPLAY_LINES, -1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1041 GTK_MOVEMENT_DISPLAY_LINES, -1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1044 GTK_MOVEMENT_DISPLAY_LINES, 1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1046 GTK_MOVEMENT_DISPLAY_LINES, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1049 GTK_MOVEMENT_DISPLAY_LINES, -1);
1051 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1052 GTK_MOVEMENT_DISPLAY_LINES, 1);
1054 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1055 GTK_MOVEMENT_BUFFER_ENDS, -1);
1056 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1057 GTK_MOVEMENT_BUFFER_ENDS, -1);
1059 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1060 GTK_MOVEMENT_BUFFER_ENDS, 1);
1061 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1062 GTK_MOVEMENT_BUFFER_ENDS, 1);
1064 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1065 GTK_MOVEMENT_PAGES, -1);
1066 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1067 GTK_MOVEMENT_PAGES, -1);
1069 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1070 GTK_MOVEMENT_PAGES, 1);
1071 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1072 GTK_MOVEMENT_PAGES, 1);
1074 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1075 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1076 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1077 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1079 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1080 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1081 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1082 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1086 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1088 parent_buildable_iface = g_type_interface_peek_parent (iface);
1089 iface->add_child = _gtk_cell_layout_buildable_add_child;
1090 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1091 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1095 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1097 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1098 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1099 iface->clear = gtk_icon_view_cell_layout_clear;
1100 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1101 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1102 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1103 iface->reorder = gtk_icon_view_cell_layout_reorder;
1104 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1108 gtk_icon_view_init (GtkIconView *icon_view)
1110 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1112 GtkIconViewPrivate);
1114 icon_view->priv->width = 0;
1115 icon_view->priv->height = 0;
1116 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1117 icon_view->priv->pressed_button = -1;
1118 icon_view->priv->press_start_x = -1;
1119 icon_view->priv->press_start_y = -1;
1120 icon_view->priv->text_column = -1;
1121 icon_view->priv->markup_column = -1;
1122 icon_view->priv->pixbuf_column = -1;
1123 icon_view->priv->text_cell = -1;
1124 icon_view->priv->pixbuf_cell = -1;
1125 icon_view->priv->tooltip_column = -1;
1127 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1129 icon_view->priv->cell_list = NULL;
1130 icon_view->priv->n_cells = 0;
1131 icon_view->priv->cursor_cell = -1;
1133 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1135 icon_view->priv->columns = -1;
1136 icon_view->priv->item_width = -1;
1137 icon_view->priv->spacing = 0;
1138 icon_view->priv->row_spacing = 6;
1139 icon_view->priv->column_spacing = 6;
1140 icon_view->priv->margin = 6;
1141 icon_view->priv->item_padding = 6;
1143 icon_view->priv->draw_focus = TRUE;
1146 /* GObject methods */
1148 gtk_icon_view_finalize (GObject *object)
1150 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1152 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1157 gtk_icon_view_set_property (GObject *object,
1159 const GValue *value,
1162 GtkIconView *icon_view;
1164 icon_view = GTK_ICON_VIEW (object);
1168 case PROP_SELECTION_MODE:
1169 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1171 case PROP_PIXBUF_COLUMN:
1172 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1174 case PROP_TEXT_COLUMN:
1175 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1177 case PROP_MARKUP_COLUMN:
1178 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1181 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1183 case PROP_ITEM_ORIENTATION:
1184 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1187 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1189 case PROP_ITEM_WIDTH:
1190 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1193 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1195 case PROP_ROW_SPACING:
1196 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1198 case PROP_COLUMN_SPACING:
1199 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1202 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1204 case PROP_REORDERABLE:
1205 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1208 case PROP_TOOLTIP_COLUMN:
1209 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1212 case PROP_ITEM_PADDING:
1213 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1216 case PROP_HADJUSTMENT:
1217 gtk_icon_view_set_hadjustment (icon_view, g_value_get_object (value));
1219 case PROP_VADJUSTMENT:
1220 gtk_icon_view_set_vadjustment (icon_view, g_value_get_object (value));
1222 case PROP_HSCROLL_POLICY:
1223 icon_view->priv->hscroll_policy = g_value_get_enum (value);
1224 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1226 case PROP_VSCROLL_POLICY:
1227 icon_view->priv->vscroll_policy = g_value_get_enum (value);
1228 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
1232 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1238 gtk_icon_view_get_property (GObject *object,
1243 GtkIconView *icon_view;
1245 icon_view = GTK_ICON_VIEW (object);
1249 case PROP_SELECTION_MODE:
1250 g_value_set_enum (value, icon_view->priv->selection_mode);
1252 case PROP_PIXBUF_COLUMN:
1253 g_value_set_int (value, icon_view->priv->pixbuf_column);
1255 case PROP_TEXT_COLUMN:
1256 g_value_set_int (value, icon_view->priv->text_column);
1258 case PROP_MARKUP_COLUMN:
1259 g_value_set_int (value, icon_view->priv->markup_column);
1262 g_value_set_object (value, icon_view->priv->model);
1264 case PROP_ITEM_ORIENTATION:
1265 g_value_set_enum (value, icon_view->priv->item_orientation);
1268 g_value_set_int (value, icon_view->priv->columns);
1270 case PROP_ITEM_WIDTH:
1271 g_value_set_int (value, icon_view->priv->item_width);
1274 g_value_set_int (value, icon_view->priv->spacing);
1276 case PROP_ROW_SPACING:
1277 g_value_set_int (value, icon_view->priv->row_spacing);
1279 case PROP_COLUMN_SPACING:
1280 g_value_set_int (value, icon_view->priv->column_spacing);
1283 g_value_set_int (value, icon_view->priv->margin);
1285 case PROP_REORDERABLE:
1286 g_value_set_boolean (value, icon_view->priv->reorderable);
1288 case PROP_TOOLTIP_COLUMN:
1289 g_value_set_int (value, icon_view->priv->tooltip_column);
1292 case PROP_ITEM_PADDING:
1293 g_value_set_int (value, icon_view->priv->item_padding);
1296 case PROP_HADJUSTMENT:
1297 g_value_set_object (value, icon_view->priv->hadjustment);
1299 case PROP_VADJUSTMENT:
1300 g_value_set_object (value, icon_view->priv->vadjustment);
1302 case PROP_HSCROLL_POLICY:
1303 g_value_set_enum (value, icon_view->priv->hscroll_policy);
1305 case PROP_VSCROLL_POLICY:
1306 g_value_set_enum (value, icon_view->priv->vscroll_policy);
1310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1315 /* GtkWidget methods */
1317 gtk_icon_view_destroy (GtkWidget *widget)
1319 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1321 gtk_icon_view_stop_editing (icon_view, TRUE);
1323 gtk_icon_view_set_model (icon_view, NULL);
1325 if (icon_view->priv->layout_idle_id != 0)
1327 g_source_remove (icon_view->priv->layout_idle_id);
1328 icon_view->priv->layout_idle_id = 0;
1331 if (icon_view->priv->scroll_to_path != NULL)
1333 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1334 icon_view->priv->scroll_to_path = NULL;
1337 remove_scroll_timeout (icon_view);
1339 if (icon_view->priv->hadjustment != NULL)
1341 g_object_unref (icon_view->priv->hadjustment);
1342 icon_view->priv->hadjustment = NULL;
1345 if (icon_view->priv->vadjustment != NULL)
1347 g_object_unref (icon_view->priv->vadjustment);
1348 icon_view->priv->vadjustment = NULL;
1351 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->destroy (widget);
1355 gtk_icon_view_realize (GtkWidget *widget)
1357 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1358 GtkAllocation allocation;
1360 GdkWindowAttr attributes;
1361 gint attributes_mask;
1363 gtk_widget_set_realized (widget, TRUE);
1365 gtk_widget_get_allocation (widget, &allocation);
1367 /* Make the main, clipping window */
1368 attributes.window_type = GDK_WINDOW_CHILD;
1369 attributes.x = allocation.x;
1370 attributes.y = allocation.y;
1371 attributes.width = allocation.width;
1372 attributes.height = allocation.height;
1373 attributes.wclass = GDK_INPUT_OUTPUT;
1374 attributes.visual = gtk_widget_get_visual (widget);
1375 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1377 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1379 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1380 &attributes, attributes_mask);
1381 gtk_widget_set_window (widget, window);
1382 gdk_window_set_user_data (window, widget);
1384 gtk_widget_get_allocation (widget, &allocation);
1386 /* Make the window for the icon view */
1389 attributes.width = MAX (icon_view->priv->width, allocation.width);
1390 attributes.height = MAX (icon_view->priv->height, allocation.height);
1391 attributes.event_mask = (GDK_EXPOSURE_MASK |
1393 GDK_POINTER_MOTION_MASK |
1394 GDK_BUTTON_PRESS_MASK |
1395 GDK_BUTTON_RELEASE_MASK |
1396 GDK_KEY_PRESS_MASK |
1397 GDK_KEY_RELEASE_MASK) |
1398 gtk_widget_get_events (widget);
1400 icon_view->priv->bin_window = gdk_window_new (window,
1401 &attributes, attributes_mask);
1402 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1404 gtk_widget_style_attach (widget);
1405 gdk_window_set_background (icon_view->priv->bin_window,
1406 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1408 gdk_window_show (icon_view->priv->bin_window);
1412 gtk_icon_view_unrealize (GtkWidget *widget)
1414 GtkIconView *icon_view;
1416 icon_view = GTK_ICON_VIEW (widget);
1418 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1419 gdk_window_destroy (icon_view->priv->bin_window);
1420 icon_view->priv->bin_window = NULL;
1422 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1426 gtk_icon_view_state_changed (GtkWidget *widget,
1427 GtkStateType previous_state)
1429 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1433 if (gtk_widget_get_realized (widget))
1435 style = gtk_widget_get_style (widget);
1436 state = gtk_widget_get_state (widget);
1438 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1439 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1442 gtk_widget_queue_draw (widget);
1446 gtk_icon_view_style_set (GtkWidget *widget,
1447 GtkStyle *previous_style)
1449 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1453 if (gtk_widget_get_realized (widget))
1455 style = gtk_widget_get_style (widget);
1456 state = gtk_widget_get_state (widget);
1458 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1459 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1462 gtk_widget_queue_resize (widget);
1466 gtk_icon_view_get_preferred_width (GtkWidget *widget,
1470 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->width;
1474 gtk_icon_view_get_preferred_height (GtkWidget *widget,
1478 *minimum = *natural = GTK_ICON_VIEW (widget)->priv->height;
1482 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1486 for (list = icon_view->priv->children; list; list = list->next)
1488 GtkIconViewChild *child = list->data;
1489 GtkAllocation allocation;
1491 /* totally ignore our child's requisition */
1492 if (child->cell < 0)
1494 allocation.x = child->item->x + icon_view->priv->item_padding;
1495 allocation.y = child->item->y + icon_view->priv->item_padding;
1496 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1497 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1501 GdkRectangle *box = &child->item->box[child->cell];
1503 allocation.x = box->x;
1504 allocation.y = box->y;
1505 allocation.width = box->width;
1506 allocation.height = box->height;
1509 gtk_widget_size_allocate (child->widget, &allocation);
1514 gtk_icon_view_size_allocate (GtkWidget *widget,
1515 GtkAllocation *allocation)
1517 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1519 gtk_widget_set_allocation (widget, allocation);
1521 if (gtk_widget_get_realized (widget))
1523 gdk_window_move_resize (gtk_widget_get_window (widget),
1524 allocation->x, allocation->y,
1525 allocation->width, allocation->height);
1526 gdk_window_resize (icon_view->priv->bin_window,
1527 MAX (icon_view->priv->width, allocation->width),
1528 MAX (icon_view->priv->height, allocation->height));
1531 gtk_icon_view_layout (icon_view);
1533 gtk_icon_view_allocate_children (icon_view);
1535 /* Delay signal emission */
1536 g_object_freeze_notify (G_OBJECT (icon_view->priv->hadjustment));
1537 g_object_freeze_notify (G_OBJECT (icon_view->priv->vadjustment));
1539 gtk_icon_view_set_hadjustment_values (icon_view);
1540 gtk_icon_view_set_vadjustment_values (icon_view);
1542 if (gtk_widget_get_realized (widget) &&
1543 icon_view->priv->scroll_to_path)
1546 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1547 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1548 icon_view->priv->scroll_to_path = NULL;
1550 gtk_icon_view_scroll_to_path (icon_view, path,
1551 icon_view->priv->scroll_to_use_align,
1552 icon_view->priv->scroll_to_row_align,
1553 icon_view->priv->scroll_to_col_align);
1554 gtk_tree_path_free (path);
1557 /* Emit any pending signals now */
1558 g_object_thaw_notify (G_OBJECT (icon_view->priv->hadjustment));
1559 g_object_thaw_notify (G_OBJECT (icon_view->priv->vadjustment));
1563 gtk_icon_view_draw (GtkWidget *widget,
1566 GtkIconView *icon_view;
1570 GtkIconViewDropPosition dest_pos;
1571 GtkIconViewItem *dest_item = NULL;
1573 icon_view = GTK_ICON_VIEW (widget);
1575 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1580 gtk_cairo_transform_to_window (cr, widget, icon_view->priv->bin_window);
1582 cairo_set_line_width (cr, 1.);
1584 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1588 dest_index = gtk_tree_path_get_indices (path)[0];
1589 gtk_tree_path_free (path);
1594 for (icons = icon_view->priv->items; icons; icons = icons->next)
1596 GtkIconViewItem *item = icons->data;
1600 cairo_rectangle (cr, item->x, item->y, item->width, item->height);
1603 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1605 gtk_icon_view_paint_item (icon_view, cr, item,
1607 icon_view->priv->draw_focus);
1609 if (dest_index == item->index)
1621 style = gtk_widget_get_style (widget);
1622 state = gtk_widget_get_state (widget);
1626 case GTK_ICON_VIEW_DROP_INTO:
1627 gtk_paint_focus (style,
1631 "iconview-drop-indicator",
1632 dest_item->x, dest_item->y,
1633 dest_item->width, dest_item->height);
1635 case GTK_ICON_VIEW_DROP_ABOVE:
1636 gtk_paint_focus (style,
1640 "iconview-drop-indicator",
1641 dest_item->x, dest_item->y - 1,
1642 dest_item->width, 2);
1644 case GTK_ICON_VIEW_DROP_LEFT:
1645 gtk_paint_focus (style,
1649 "iconview-drop-indicator",
1650 dest_item->x - 1, dest_item->y,
1651 2, dest_item->height);
1653 case GTK_ICON_VIEW_DROP_BELOW:
1654 gtk_paint_focus (style,
1658 "iconview-drop-indicator",
1659 dest_item->x, dest_item->y + dest_item->height - 1,
1660 dest_item->width, 2);
1662 case GTK_ICON_VIEW_DROP_RIGHT:
1663 gtk_paint_focus (style,
1667 "iconview-drop-indicator",
1668 dest_item->x + dest_item->width - 1, dest_item->y,
1669 2, dest_item->height);
1670 case GTK_ICON_VIEW_NO_DROP: ;
1675 if (icon_view->priv->doing_rubberband)
1676 gtk_icon_view_paint_rubberband (icon_view, cr);
1680 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1686 rubberband_scroll_timeout (gpointer data)
1688 GtkIconView *icon_view = data;
1690 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1691 icon_view->priv->vadjustment->value +
1692 icon_view->priv->scroll_value_diff);
1694 gtk_icon_view_update_rubberband (icon_view);
1700 gtk_icon_view_motion (GtkWidget *widget,
1701 GdkEventMotion *event)
1703 GtkAllocation allocation;
1704 GtkIconView *icon_view;
1707 icon_view = GTK_ICON_VIEW (widget);
1709 gtk_icon_view_maybe_begin_drag (icon_view, event);
1711 if (icon_view->priv->doing_rubberband)
1713 gtk_icon_view_update_rubberband (widget);
1715 abs_y = event->y - icon_view->priv->height *
1716 (icon_view->priv->vadjustment->value /
1717 (icon_view->priv->vadjustment->upper -
1718 icon_view->priv->vadjustment->lower));
1720 gtk_widget_get_allocation (widget, &allocation);
1722 if (abs_y < 0 || abs_y > allocation.height)
1725 icon_view->priv->scroll_value_diff = abs_y;
1727 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1729 icon_view->priv->event_last_x = event->x;
1730 icon_view->priv->event_last_y = event->y;
1732 if (icon_view->priv->scroll_timeout_id == 0)
1733 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1737 remove_scroll_timeout (icon_view);
1744 gtk_icon_view_remove (GtkContainer *container,
1747 GtkIconView *icon_view;
1748 GtkIconViewChild *child = NULL;
1751 icon_view = GTK_ICON_VIEW (container);
1753 tmp_list = icon_view->priv->children;
1756 child = tmp_list->data;
1757 if (child->widget == widget)
1759 gtk_widget_unparent (widget);
1761 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1762 g_list_free_1 (tmp_list);
1767 tmp_list = tmp_list->next;
1772 gtk_icon_view_forall (GtkContainer *container,
1773 gboolean include_internals,
1774 GtkCallback callback,
1775 gpointer callback_data)
1777 GtkIconView *icon_view;
1778 GtkIconViewChild *child = NULL;
1781 icon_view = GTK_ICON_VIEW (container);
1783 tmp_list = icon_view->priv->children;
1786 child = tmp_list->data;
1787 tmp_list = tmp_list->next;
1789 (* callback) (child->widget, callback_data);
1794 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1795 GtkIconViewItem *item,
1796 GtkIconViewCellInfo *info,
1801 GdkRectangle cell_area;
1802 gboolean visible, mode;
1804 gtk_icon_view_set_cell_data (icon_view, item);
1806 g_object_get (info->cell,
1807 "visible", &visible,
1811 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1813 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1815 path = gtk_tree_path_new_from_indices (item->index, -1);
1816 path_string = gtk_tree_path_to_string (path);
1817 gtk_tree_path_free (path);
1819 gtk_cell_renderer_activate (info->cell,
1821 GTK_WIDGET (icon_view),
1827 g_free (path_string);
1832 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1833 GtkIconViewItem *item)
1836 AtkObject *item_obj;
1838 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1841 item_obj = atk_object_ref_accessible_child (obj, item->index);
1842 if (item_obj != NULL)
1844 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1845 g_object_unref (item_obj);
1851 gtk_icon_view_put (GtkIconView *icon_view,
1853 GtkIconViewItem *item,
1856 GtkIconViewChild *child;
1858 child = g_new (GtkIconViewChild, 1);
1860 child->widget = widget;
1864 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1866 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1867 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1869 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1873 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1874 GtkIconView *icon_view)
1877 GtkIconViewItem *item;
1879 if (icon_view->priv->edited_item == NULL)
1882 item = icon_view->priv->edited_item;
1883 icon_view->priv->edited_item = NULL;
1884 icon_view->priv->editable = NULL;
1885 for (l = icon_view->priv->cell_list; l; l = l->next)
1887 GtkIconViewCellInfo *info = l->data;
1889 info->editing = FALSE;
1892 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1893 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1895 g_signal_handlers_disconnect_by_func (editable,
1896 gtk_icon_view_remove_widget,
1899 gtk_container_remove (GTK_CONTAINER (icon_view),
1900 GTK_WIDGET (editable));
1902 gtk_icon_view_queue_draw_item (icon_view, item);
1907 gtk_icon_view_start_editing (GtkIconView *icon_view,
1908 GtkIconViewItem *item,
1909 GtkIconViewCellInfo *info,
1914 GdkRectangle cell_area;
1915 gboolean visible, mode;
1916 GtkCellEditable *editable;
1918 gtk_icon_view_set_cell_data (icon_view, item);
1920 g_object_get (info->cell,
1921 "visible", &visible,
1924 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1926 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1928 path = gtk_tree_path_new_from_indices (item->index, -1);
1929 path_string = gtk_tree_path_to_string (path);
1930 gtk_tree_path_free (path);
1932 editable = gtk_cell_renderer_start_editing (info->cell,
1934 GTK_WIDGET (icon_view),
1939 g_free (path_string);
1941 /* the rest corresponds to tree_view_real_start_editing... */
1942 icon_view->priv->edited_item = item;
1943 icon_view->priv->editable = editable;
1944 info->editing = TRUE;
1946 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1948 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1950 gtk_widget_grab_focus (GTK_WIDGET (editable));
1951 g_signal_connect (editable, "remove-widget",
1952 G_CALLBACK (gtk_icon_view_remove_widget),
1959 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1960 gboolean cancel_editing)
1962 GtkCellRenderer *cell = NULL;
1963 GtkIconViewItem *item;
1966 if (icon_view->priv->edited_item == NULL)
1970 * This is very evil. We need to do this, because
1971 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1972 * later on. If gtk_icon_view_row_changed notices
1973 * icon_view->priv->edited_item != NULL, it'll call
1974 * gtk_icon_view_stop_editing again. Bad things will happen then.
1976 * Please read that again if you intend to modify anything here.
1979 item = icon_view->priv->edited_item;
1980 icon_view->priv->edited_item = NULL;
1982 for (l = icon_view->priv->cell_list; l; l = l->next)
1984 GtkIconViewCellInfo *info = l->data;
1996 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1997 if (!cancel_editing)
1998 gtk_cell_editable_editing_done (icon_view->priv->editable);
2000 icon_view->priv->edited_item = item;
2002 gtk_cell_editable_remove_widget (icon_view->priv->editable);
2006 * gtk_icon_view_set_cursor:
2007 * @icon_view: A #GtkIconView
2008 * @path: A #GtkTreePath
2009 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2010 * @start_editing: %TRUE if the specified cell should start being edited.
2012 * Sets the current keyboard focus to be at @path, and selects it. This is
2013 * useful when you want to focus the user's attention on a particular item.
2014 * If @cell is not %NULL, then focus is given to the cell specified by
2015 * it. Additionally, if @start_editing is %TRUE, then editing should be
2016 * started in the specified cell.
2018 * This function is often followed by <literal>gtk_widget_grab_focus
2019 * (icon_view)</literal> in order to give keyboard focus to the widget.
2020 * Please note that editing can only happen when the widget is realized.
2025 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2027 GtkCellRenderer *cell,
2028 gboolean start_editing)
2030 GtkIconViewItem *item = NULL;
2031 GtkIconViewCellInfo *info = NULL;
2035 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2036 g_return_if_fail (path != NULL);
2037 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2039 gtk_icon_view_stop_editing (icon_view, TRUE);
2041 if (gtk_tree_path_get_depth (path) == 1)
2042 item = g_list_nth_data (icon_view->priv->items,
2043 gtk_tree_path_get_indices(path)[0]);
2049 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2053 if (info->cell == cell)
2062 g_return_if_fail (cell == NULL || info != NULL);
2064 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2065 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2067 if (info && start_editing)
2068 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2072 * gtk_icon_view_get_cursor:
2073 * @icon_view: A #GtkIconView
2074 * @path: (allow-none): Return location for the current cursor path, or %NULL
2075 * @cell: (allow-none): Return location the current focus cell, or %NULL
2077 * Fills in @path and @cell with the current cursor path and cell.
2078 * If the cursor isn't currently set, then *@path will be %NULL.
2079 * If no cell currently has focus, then *@cell will be %NULL.
2081 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2083 * Return value: %TRUE if the cursor is set.
2088 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2090 GtkCellRenderer **cell)
2092 GtkIconViewItem *item;
2093 GtkIconViewCellInfo *info;
2095 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2097 item = icon_view->priv->cursor_item;
2098 if (icon_view->priv->cursor_cell < 0)
2101 info = g_list_nth_data (icon_view->priv->cell_list,
2102 icon_view->priv->cursor_cell);
2107 *path = gtk_tree_path_new_from_indices (item->index, -1);
2120 return (item != NULL);
2124 gtk_icon_view_button_press (GtkWidget *widget,
2125 GdkEventButton *event)
2127 GtkIconView *icon_view;
2128 GtkIconViewItem *item;
2129 GtkIconViewCellInfo *info = NULL;
2130 gboolean dirty = FALSE;
2131 GtkCellRendererMode mode;
2132 gint cursor_cell = -1;
2134 icon_view = GTK_ICON_VIEW (widget);
2136 if (event->window != icon_view->priv->bin_window)
2139 if (!gtk_widget_has_focus (widget))
2140 gtk_widget_grab_focus (widget);
2142 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2144 item = gtk_icon_view_get_item_at_coords (icon_view,
2150 * We consider only the the cells' area as the item area if the
2151 * item is not selected, but if it *is* selected, the complete
2152 * selection rectangle is considered to be part of the item.
2154 if (item != NULL && (info != NULL || item->selected))
2158 g_object_get (info->cell, "mode", &mode, NULL);
2160 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2161 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2162 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2165 gtk_icon_view_scroll_to_item (icon_view, item);
2167 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2169 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2171 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2172 (event->state & GDK_SHIFT_MASK))
2174 gtk_icon_view_unselect_all_internal (icon_view);
2176 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2177 if (!icon_view->priv->anchor_item)
2178 icon_view->priv->anchor_item = item;
2180 gtk_icon_view_select_all_between (icon_view,
2181 icon_view->priv->anchor_item,
2187 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2188 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2189 (event->state & GDK_CONTROL_MASK))
2191 item->selected = !item->selected;
2192 gtk_icon_view_queue_draw_item (icon_view, item);
2197 gtk_icon_view_unselect_all_internal (icon_view);
2199 item->selected = TRUE;
2200 gtk_icon_view_queue_draw_item (icon_view, item);
2203 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2204 icon_view->priv->anchor_item = item;
2207 /* Save press to possibly begin a drag */
2208 if (icon_view->priv->pressed_button < 0)
2210 icon_view->priv->pressed_button = event->button;
2211 icon_view->priv->press_start_x = event->x;
2212 icon_view->priv->press_start_y = event->y;
2215 if (!icon_view->priv->last_single_clicked)
2216 icon_view->priv->last_single_clicked = item;
2218 /* cancel the current editing, if it exists */
2219 gtk_icon_view_stop_editing (icon_view, TRUE);
2223 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2224 gtk_icon_view_item_activate_cell (icon_view, item, info,
2226 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2227 gtk_icon_view_start_editing (icon_view, item, info,
2233 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2234 !(event->state & GDK_CONTROL_MASK))
2236 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2239 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2240 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2243 /* don't draw keyboard focus around an clicked-on item */
2244 icon_view->priv->draw_focus = FALSE;
2247 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2249 item = gtk_icon_view_get_item_at_coords (icon_view,
2254 if (item && item == icon_view->priv->last_single_clicked)
2258 path = gtk_tree_path_new_from_indices (item->index, -1);
2259 gtk_icon_view_item_activated (icon_view, path);
2260 gtk_tree_path_free (path);
2263 icon_view->priv->last_single_clicked = NULL;
2264 icon_view->priv->pressed_button = -1;
2268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2270 return event->button == 1;
2274 gtk_icon_view_button_release (GtkWidget *widget,
2275 GdkEventButton *event)
2277 GtkIconView *icon_view;
2279 icon_view = GTK_ICON_VIEW (widget);
2281 if (icon_view->priv->pressed_button == event->button)
2282 icon_view->priv->pressed_button = -1;
2284 gtk_icon_view_stop_rubberbanding (icon_view);
2286 remove_scroll_timeout (icon_view);
2292 gtk_icon_view_key_press (GtkWidget *widget,
2295 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2297 if (icon_view->priv->doing_rubberband)
2299 if (event->keyval == GDK_KEY_Escape)
2300 gtk_icon_view_stop_rubberbanding (icon_view);
2305 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2309 gtk_icon_view_key_release (GtkWidget *widget,
2312 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2314 if (icon_view->priv->doing_rubberband)
2317 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2321 gtk_icon_view_update_rubberband (gpointer data)
2323 GtkIconView *icon_view;
2325 GdkRectangle old_area;
2326 GdkRectangle new_area;
2327 GdkRectangle common;
2328 cairo_region_t *invalid_region;
2330 icon_view = GTK_ICON_VIEW (data);
2332 gdk_window_get_device_position (icon_view->priv->bin_window,
2333 icon_view->priv->rubberband_device,
2339 old_area.x = MIN (icon_view->priv->rubberband_x1,
2340 icon_view->priv->rubberband_x2);
2341 old_area.y = MIN (icon_view->priv->rubberband_y1,
2342 icon_view->priv->rubberband_y2);
2343 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2344 icon_view->priv->rubberband_x1) + 1;
2345 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2346 icon_view->priv->rubberband_y1) + 1;
2348 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2349 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2350 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2351 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2353 invalid_region = cairo_region_create_rectangle (&old_area);
2354 cairo_region_union_rectangle (invalid_region, &new_area);
2356 gdk_rectangle_intersect (&old_area, &new_area, &common);
2357 if (common.width > 2 && common.height > 2)
2359 cairo_region_t *common_region;
2361 /* make sure the border is invalidated */
2367 common_region = cairo_region_create_rectangle (&common);
2369 cairo_region_subtract (invalid_region, common_region);
2370 cairo_region_destroy (common_region);
2373 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2375 cairo_region_destroy (invalid_region);
2377 icon_view->priv->rubberband_x2 = x;
2378 icon_view->priv->rubberband_y2 = y;
2380 gtk_icon_view_update_rubberband_selection (icon_view);
2384 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2391 if (icon_view->priv->rubberband_device)
2394 for (items = icon_view->priv->items; items; items = items->next)
2396 GtkIconViewItem *item = items->data;
2398 item->selected_before_rubberbanding = item->selected;
2401 icon_view->priv->rubberband_x1 = x;
2402 icon_view->priv->rubberband_y1 = y;
2403 icon_view->priv->rubberband_x2 = x;
2404 icon_view->priv->rubberband_y2 = y;
2406 icon_view->priv->doing_rubberband = TRUE;
2407 icon_view->priv->rubberband_device = device;
2409 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2413 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2415 if (!icon_view->priv->doing_rubberband)
2418 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2419 icon_view->priv->rubberband_device);
2421 icon_view->priv->doing_rubberband = FALSE;
2422 icon_view->priv->rubberband_device = NULL;
2424 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2428 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2431 gint x, y, width, height;
2432 gboolean dirty = FALSE;
2434 x = MIN (icon_view->priv->rubberband_x1,
2435 icon_view->priv->rubberband_x2);
2436 y = MIN (icon_view->priv->rubberband_y1,
2437 icon_view->priv->rubberband_y2);
2438 width = ABS (icon_view->priv->rubberband_x1 -
2439 icon_view->priv->rubberband_x2);
2440 height = ABS (icon_view->priv->rubberband_y1 -
2441 icon_view->priv->rubberband_y2);
2443 for (items = icon_view->priv->items; items; items = items->next)
2445 GtkIconViewItem *item = items->data;
2449 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2450 x, y, width, height);
2452 selected = is_in ^ item->selected_before_rubberbanding;
2454 if (item->selected != selected)
2456 item->selected = selected;
2458 gtk_icon_view_queue_draw_item (icon_view, item);
2463 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2467 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2468 GtkIconViewItem *item,
2477 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2478 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2481 for (l = icon_view->priv->cell_list; l; l = l->next)
2483 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2485 if (!gtk_cell_renderer_get_visible (info->cell))
2488 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2490 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2491 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2499 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2501 gboolean dirty = FALSE;
2504 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2507 for (items = icon_view->priv->items; items; items = items->next)
2509 GtkIconViewItem *item = items->data;
2513 item->selected = FALSE;
2515 gtk_icon_view_queue_draw_item (icon_view, item);
2516 gtk_icon_view_item_selected_changed (icon_view, item);
2524 /* GtkIconView signals */
2526 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2528 gtk_icon_view_select_all (icon_view);
2532 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2534 gtk_icon_view_unselect_all (icon_view);
2538 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2540 gtk_icon_view_unselect_all (icon_view);
2542 if (icon_view->priv->cursor_item != NULL)
2543 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2547 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2550 GtkCellRendererMode mode;
2551 GtkIconViewCellInfo *info = NULL;
2553 if (!icon_view->priv->cursor_item)
2556 info = g_list_nth_data (icon_view->priv->cell_list,
2557 icon_view->priv->cursor_cell);
2561 g_object_get (info->cell, "mode", &mode, NULL);
2563 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2565 gtk_icon_view_item_activate_cell (icon_view,
2566 icon_view->priv->cursor_item,
2570 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2572 gtk_icon_view_start_editing (icon_view,
2573 icon_view->priv->cursor_item,
2579 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2580 gtk_icon_view_item_activated (icon_view, path);
2581 gtk_tree_path_free (path);
2587 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2589 if (!icon_view->priv->cursor_item)
2592 switch (icon_view->priv->selection_mode)
2594 case GTK_SELECTION_NONE:
2596 case GTK_SELECTION_BROWSE:
2597 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2599 case GTK_SELECTION_SINGLE:
2600 if (icon_view->priv->cursor_item->selected)
2601 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2603 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2605 case GTK_SELECTION_MULTIPLE:
2606 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2607 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2609 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2610 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2615 /* Internal functions */
2617 gtk_icon_view_process_updates (GtkIconView *icon_view)
2619 /* Prior to drawing, we check if a layout has been scheduled. If so,
2620 * do it now that all cell view items have valid sizes before we proceeed
2621 * (and resize the bin_window if required).
2623 if (icon_view->priv->layout_idle_id != 0)
2624 gtk_icon_view_layout (icon_view);
2626 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2630 gtk_icon_view_set_hadjustment_values (GtkIconView *icon_view)
2632 GtkAllocation allocation;
2633 GtkAdjustment *adj = icon_view->priv->hadjustment;
2634 gdouble old_page_size;
2640 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2642 old_value = gtk_adjustment_get_value (adj);
2643 old_upper = gtk_adjustment_get_upper (adj);
2644 old_page_size = gtk_adjustment_get_page_size (adj);
2645 new_upper = MAX (allocation.width, icon_view->priv->width);
2650 "page-size", (gdouble)allocation.width,
2651 "step-increment", allocation.width * 0.1,
2652 "page-increment", allocation.width * 0.9,
2655 if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
2657 /* Make sure no scrolling occurs for RTL locales also (if possible) */
2658 /* Quick explanation:
2659 * In LTR locales, leftmost portion of visible rectangle should stay
2660 * fixed, which means left edge of scrollbar thumb should remain fixed
2661 * and thus adjustment's value should stay the same.
2663 * In RTL locales, we want to keep rightmost portion of visible
2664 * rectangle fixed. This means right edge of thumb should remain fixed.
2665 * In this case, upper - value - page_size should remain constant.
2667 new_value = (new_upper - allocation.width) -
2668 (old_upper - old_value - old_page_size);
2669 new_value = CLAMP (new_value, 0, new_upper - allocation.width);
2672 new_value = CLAMP (old_value, 0, new_upper - allocation.width);
2674 if (new_value != old_value)
2675 gtk_adjustment_set_value (adj, new_value);
2679 gtk_icon_view_set_vadjustment_values (GtkIconView *icon_view)
2681 GtkAllocation allocation;
2682 GtkAdjustment *adj = icon_view->priv->vadjustment;
2687 gtk_widget_get_allocation (GTK_WIDGET (icon_view), &allocation);
2689 old_value = gtk_adjustment_get_value (adj);
2690 new_upper = MAX (allocation.height, icon_view->priv->height);
2695 "page-size", (gdouble)allocation.height,
2696 "step-increment", allocation.height * 0.1,
2697 "page-increment", allocation.height * 0.9,
2700 new_value = CLAMP (old_value, 0, new_upper - allocation.height);
2701 if (new_value != old_value)
2702 gtk_adjustment_set_value (adj, new_value);
2706 gtk_icon_view_set_hadjustment (GtkIconView *icon_view,
2707 GtkAdjustment *adjustment)
2709 GtkIconViewPrivate *priv = icon_view->priv;
2712 if (adjustment && priv->hadjustment == adjustment)
2715 if (priv->hadjustment != NULL)
2717 g_signal_handlers_disconnect_matched (priv->hadjustment,
2718 G_SIGNAL_MATCH_DATA,
2719 0, 0, NULL, NULL, icon_view);
2720 g_object_unref (priv->hadjustment);
2724 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2727 g_signal_connect (adjustment, "value-changed",
2728 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2729 priv->hadjustment = g_object_ref_sink (adjustment);
2730 gtk_icon_view_set_hadjustment_values (icon_view);
2732 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2733 gtk_icon_view_accessible_set_adjustment (atk_obj,
2734 GTK_ORIENTATION_HORIZONTAL,
2737 g_object_notify (G_OBJECT (icon_view), "hadjustment");
2741 gtk_icon_view_set_vadjustment (GtkIconView *icon_view,
2742 GtkAdjustment *adjustment)
2744 GtkIconViewPrivate *priv = icon_view->priv;
2747 if (adjustment && priv->vadjustment == adjustment)
2750 if (priv->vadjustment != NULL)
2752 g_signal_handlers_disconnect_matched (priv->vadjustment,
2753 G_SIGNAL_MATCH_DATA,
2754 0, 0, NULL, NULL, icon_view);
2755 g_object_unref (priv->vadjustment);
2759 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
2762 g_signal_connect (adjustment, "value-changed",
2763 G_CALLBACK (gtk_icon_view_adjustment_changed), icon_view);
2764 priv->vadjustment = g_object_ref_sink (adjustment);
2765 gtk_icon_view_set_vadjustment_values (icon_view);
2767 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
2768 gtk_icon_view_accessible_set_adjustment (atk_obj,
2769 GTK_ORIENTATION_VERTICAL,
2772 g_object_notify (G_OBJECT (icon_view), "vadjustment");
2776 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2777 GtkIconView *icon_view)
2779 GtkIconViewPrivate *priv = icon_view->priv;
2781 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2783 gdk_window_move (priv->bin_window,
2784 - priv->hadjustment->value,
2785 - priv->vadjustment->value);
2787 if (icon_view->priv->doing_rubberband)
2788 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2790 gtk_icon_view_process_updates (icon_view);
2795 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2800 gint *maximum_width)
2802 GtkAllocation allocation;
2803 GtkWidget *widget = GTK_WIDGET (icon_view);
2805 gint x, current_width;
2806 GList *items, *last_item;
2813 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2814 max_height = g_new0 (gint, icon_view->priv->n_cells);
2821 gtk_widget_style_get (widget,
2822 "focus-line-width", &focus_width,
2825 x += icon_view->priv->margin + focus_width;
2826 current_width += 2 * (icon_view->priv->margin + focus_width);
2831 GtkIconViewItem *item = items->data;
2833 gtk_icon_view_calculate_item_size (icon_view, item);
2834 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2836 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2838 current_width += item->width;
2840 if (items != first_item)
2842 gtk_widget_get_allocation (widget, &allocation);
2844 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2845 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2849 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2851 item->y = *y + focus_width;
2854 x = current_width - (icon_view->priv->margin + focus_width);
2856 for (i = 0; i < icon_view->priv->n_cells; i++)
2857 max_height[i] = MAX (max_height[i], item->box[i].height);
2859 if (current_width > *maximum_width)
2860 *maximum_width = current_width;
2866 items = items->next;
2871 /* Now go through the row again and align the icons */
2872 for (items = first_item; items != last_item; items = items->next)
2874 GtkIconViewItem *item = items->data;
2878 item->x = *maximum_width - item->width - item->x;
2879 item->col = col - 1 - item->col;
2882 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2884 /* We may want to readjust the new y coordinate. */
2885 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2886 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2889 g_free (max_height);
2895 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2898 if (upper != adj->upper)
2900 gdouble min = MAX (0.0, upper - adj->page_size);
2901 gboolean value_changed = FALSE;
2905 if (adj->value > min)
2908 value_changed = TRUE;
2911 gtk_adjustment_changed (adj);
2914 gtk_adjustment_value_changed (adj);
2919 gtk_icon_view_layout (GtkIconView *icon_view)
2921 GtkAllocation allocation;
2924 gint y = 0, maximum_width = 0;
2927 gboolean size_changed = FALSE;
2929 if (icon_view->priv->layout_idle_id != 0)
2931 g_source_remove (icon_view->priv->layout_idle_id);
2932 icon_view->priv->layout_idle_id = 0;
2935 if (icon_view->priv->model == NULL)
2938 widget = GTK_WIDGET (icon_view);
2940 item_width = icon_view->priv->item_width;
2944 for (icons = icon_view->priv->items; icons; icons = icons->next)
2946 GtkIconViewItem *item = icons->data;
2947 gtk_icon_view_calculate_item_size (icon_view, item);
2948 item_width = MAX (item_width, item->width);
2953 icons = icon_view->priv->items;
2954 y += icon_view->priv->margin;
2959 gtk_icon_view_set_cell_data (icon_view, icons->data);
2960 adjust_wrap_width (icon_view, icons->data);
2965 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2967 &y, &maximum_width);
2970 while (icons != NULL);
2972 if (maximum_width != icon_view->priv->width)
2974 icon_view->priv->width = maximum_width;
2975 size_changed = TRUE;
2978 y += icon_view->priv->margin;
2980 if (y != icon_view->priv->height)
2982 icon_view->priv->height = y;
2983 size_changed = TRUE;
2986 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2987 icon_view->priv->width);
2988 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2989 icon_view->priv->height);
2992 gtk_widget_queue_resize_no_redraw (widget);
2994 gtk_widget_get_allocation (widget, &allocation);
2995 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2996 gdk_window_resize (icon_view->priv->bin_window,
2997 MAX (icon_view->priv->width, allocation.width),
2998 MAX (icon_view->priv->height, allocation.height));
3000 if (icon_view->priv->scroll_to_path)
3004 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
3005 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3006 icon_view->priv->scroll_to_path = NULL;
3008 gtk_icon_view_scroll_to_path (icon_view, path,
3009 icon_view->priv->scroll_to_use_align,
3010 icon_view->priv->scroll_to_row_align,
3011 icon_view->priv->scroll_to_col_align);
3012 gtk_tree_path_free (path);
3015 gtk_widget_queue_draw (widget);
3019 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
3020 GtkIconViewItem *item,
3021 GtkIconViewCellInfo *info,
3022 GdkRectangle *cell_area)
3024 g_return_if_fail (info->position < item->n_cells);
3026 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3028 cell_area->x = item->box[info->position].x - item->before[info->position];
3029 cell_area->y = item->y + icon_view->priv->item_padding;
3030 cell_area->width = item->box[info->position].width +
3031 item->before[info->position] + item->after[info->position];
3032 cell_area->height = item->height - icon_view->priv->item_padding * 2;
3036 cell_area->x = item->x + icon_view->priv->item_padding;
3037 cell_area->y = item->box[info->position].y - item->before[info->position];
3038 cell_area->width = item->width - icon_view->priv->item_padding * 2;
3039 cell_area->height = item->box[info->position].height +
3040 item->before[info->position] + item->after[info->position];
3045 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
3046 GtkIconViewItem *item,
3047 GtkIconViewCellInfo *info,
3050 g_return_if_fail (info->position < item->n_cells);
3052 *box = item->box[info->position];
3055 /* try to guess a reasonable wrap width for an implicit text cell renderer
3058 adjust_wrap_width (GtkIconView *icon_view,
3059 GtkIconViewItem *item)
3061 GtkIconViewCellInfo *text_info;
3062 GtkIconViewCellInfo *pixbuf_info;
3065 if (icon_view->priv->text_cell != -1 &&
3066 icon_view->priv->pixbuf_cell != -1)
3068 GtkRequisition min_size;
3071 text_info = g_list_nth_data (icon_view->priv->cell_list,
3072 icon_view->priv->text_cell);
3073 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
3074 icon_view->priv->pixbuf_cell);
3076 gtk_cell_renderer_get_preferred_size (pixbuf_info->cell,
3077 GTK_WIDGET (icon_view),
3080 if (icon_view->priv->item_width > 0)
3081 item_width = icon_view->priv->item_width;
3083 item_width = item->width;
3085 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
3086 wrap_width = item_width;
3088 if (item->width == -1 && item_width <= 0)
3089 wrap_width = MAX (2 * min_size.width, 50);
3091 wrap_width = item_width - min_size.width - icon_view->priv->spacing;
3094 wrap_width -= icon_view->priv->item_padding * 2;
3096 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
3097 g_object_set (text_info->cell, "width", wrap_width, NULL);
3102 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
3103 GtkIconViewItem *item)
3105 GtkRequisition min_size;
3109 if (item->width != -1 && item->height != -1)
3112 if (item->n_cells != icon_view->priv->n_cells)
3114 g_free (item->before);
3115 g_free (item->after);
3118 item->before = g_new0 (gint, icon_view->priv->n_cells);
3119 item->after = g_new0 (gint, icon_view->priv->n_cells);
3120 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
3122 item->n_cells = icon_view->priv->n_cells;
3125 gtk_icon_view_set_cell_data (icon_view, item);
3127 spacing = icon_view->priv->spacing;
3131 for (l = icon_view->priv->cell_list; l; l = l->next)
3133 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3135 if (!gtk_cell_renderer_get_visible (info->cell))
3138 gtk_cell_renderer_get_preferred_size (info->cell,
3139 GTK_WIDGET (icon_view),
3141 item->box[info->position].width = min_size.width;
3142 item->box[info->position].height = min_size.height;
3144 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3146 item->width += item->box[info->position].width
3147 + (info->position > 0 ? spacing : 0);
3148 item->height = MAX (item->height, item->box[info->position].height);
3152 item->width = MAX (item->width, item->box[info->position].width);
3153 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3157 item->width += icon_view->priv->item_padding * 2;
3158 item->height += icon_view->priv->item_padding * 2;
3162 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3163 GtkIconViewItem *item,
3166 GtkRequisition min_size;
3167 GdkRectangle cell_area;
3173 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3175 gtk_icon_view_set_cell_data (icon_view, item);
3177 spacing = icon_view->priv->spacing;
3180 for (i = 0; i < icon_view->priv->n_cells; i++)
3182 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3183 item->height = MAX (item->height, max_height[i]);
3185 item->height += max_height[i] + (i > 0 ? spacing : 0);
3188 cell_area.x = item->x + icon_view->priv->item_padding;
3189 cell_area.y = item->y + icon_view->priv->item_padding;
3191 for (k = 0; k < 2; k++)
3192 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3194 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3196 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3199 if (!gtk_cell_renderer_get_visible (info->cell))
3202 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3204 /* We should not subtract icon_view->priv->item_padding from item->height,
3205 * because item->height is recalculated above using
3206 * max_height which does not contain item padding.
3208 cell_area.width = item->box[info->position].width;
3209 cell_area.height = item->height;
3213 /* item->width is not recalculated and thus needs to be
3214 * corrected for the padding.
3216 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3217 cell_area.height = max_height[i];
3220 gtk_cell_renderer_get_preferred_size (info->cell,
3221 GTK_WIDGET (icon_view),
3223 item->box[info->position].width = min_size.width;
3224 item->box[info->position].height = min_size.height;
3226 _gtk_cell_renderer_calc_offset (info->cell, &cell_area,
3227 gtk_widget_get_direction (GTK_WIDGET (icon_view)),
3228 item->box[info->position].width, item->box[info->position].height,
3229 &item->box[info->position].x, &item->box[info->position].y);
3230 item->box[info->position].x += cell_area.x;
3231 item->box[info->position].y += cell_area.y;
3233 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3235 item->before[info->position] = item->box[info->position].x - cell_area.x;
3236 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3237 cell_area.x += cell_area.width + spacing;
3241 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3243 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3244 cell_area.width = item->width;
3246 item->before[info->position] = item->box[info->position].y - cell_area.y;
3247 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3248 cell_area.y += cell_area.height + spacing;
3252 if (rtl && icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3254 for (i = 0; i < icon_view->priv->n_cells; i++)
3256 item->box[i].x = item->x + item->width -
3257 (item->box[i].x + item->box[i].width - item->x);
3261 item->height += icon_view->priv->item_padding * 2;
3265 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3267 g_list_foreach (icon_view->priv->items,
3268 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3272 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3279 gtk_icon_view_paint_item (GtkIconView *icon_view,
3281 GtkIconViewItem *item,
3284 gboolean draw_focus)
3288 GdkRectangle cell_area, box;
3292 GtkCellRendererState flags;
3294 GtkWidget *widget = GTK_WIDGET (icon_view);
3296 if (icon_view->priv->model == NULL)
3299 gtk_icon_view_set_cell_data (icon_view, item);
3301 style = gtk_widget_get_style (widget);
3302 gtk_widget_style_get (widget,
3303 "focus-line-width", &focus_width,
3306 padding = focus_width;
3310 flags = GTK_CELL_RENDERER_SELECTED;
3311 if (gtk_widget_has_focus (widget))
3312 state = GTK_STATE_SELECTED;
3314 state = GTK_STATE_ACTIVE;
3319 state = GTK_STATE_NORMAL;
3324 gtk_paint_flat_box (style,
3328 GTK_WIDGET (icon_view),
3331 item->width, item->height);
3334 for (l = icon_view->priv->cell_list; l; l = l->next)
3336 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3338 if (!gtk_cell_renderer_get_visible (info->cell))
3341 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3343 cell_area.x = x - item->x + cell_area.x;
3344 cell_area.y = y - item->y + cell_area.y;
3346 gtk_cell_renderer_render (info->cell,
3349 &cell_area, &cell_area, flags);
3353 gtk_widget_has_focus (widget) &&
3354 item == icon_view->priv->cursor_item)
3356 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3358 GtkCellRendererMode mode;
3359 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3361 if (!gtk_cell_renderer_get_visible (info->cell))
3364 /* If found a editable/activatable cell, draw focus on it. */
3365 g_object_get (info->cell, "mode", &mode, NULL);
3366 if (icon_view->priv->cursor_cell < 0 &&
3367 mode != GTK_CELL_RENDERER_MODE_INERT)
3368 icon_view->priv->cursor_cell = i;
3370 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3372 if (i == icon_view->priv->cursor_cell)
3374 gtk_paint_focus (style,
3379 x - item->x + box.x - padding,
3380 y - item->y + box.y - padding,
3381 box.width + 2 * padding,
3382 box.height + 2 * padding);
3387 /* If there are no editable/activatable cells, draw focus
3388 * around the whole item.
3390 if (icon_view->priv->cursor_cell < 0)
3391 gtk_paint_focus (style,
3398 item->width + 2 * padding,
3399 item->height + 2 * padding);
3404 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3408 GdkColor *fill_color_gdk;
3409 guchar fill_color_alpha;
3413 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3414 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3415 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3416 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3418 gtk_widget_style_get (GTK_WIDGET (icon_view),
3419 "selection-box-color", &fill_color_gdk,
3420 "selection-box-alpha", &fill_color_alpha,
3423 if (!fill_color_gdk)
3424 fill_color_gdk = gdk_color_copy (>k_widget_get_style (GTK_WIDGET (icon_view))->base[GTK_STATE_SELECTED]);
3426 gdk_cairo_set_source_color (cr, fill_color_gdk);
3428 gdk_cairo_rectangle (cr, &rect);
3431 cairo_paint_with_alpha (cr, fill_color_alpha / 255.);
3433 cairo_rectangle (cr,
3434 rect.x + 0.5, rect.y + 0.5,
3435 rect.width - 1, rect.height - 1);
3438 gdk_color_free (fill_color_gdk);
3444 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3450 index = gtk_tree_path_get_indices (path)[0];
3452 for (l = icon_view->priv->items; l; l = l->next)
3454 GtkIconViewItem *item = l->data;
3456 if (item->index == index)
3458 gtk_icon_view_queue_draw_item (icon_view, item);
3465 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3466 GtkIconViewItem *item)
3471 gtk_widget_style_get (GTK_WIDGET (icon_view),
3472 "focus-line-width", &focus_width,
3475 rect.x = item->x - focus_width;
3476 rect.y = item->y - focus_width;
3477 rect.width = item->width + 2 * focus_width;
3478 rect.height = item->height + 2 * focus_width;
3480 if (icon_view->priv->bin_window)
3481 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3485 layout_callback (gpointer user_data)
3487 GtkIconView *icon_view;
3489 icon_view = GTK_ICON_VIEW (user_data);
3491 icon_view->priv->layout_idle_id = 0;
3493 gtk_icon_view_layout (icon_view);
3499 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3501 if (icon_view->priv->layout_idle_id != 0)
3504 icon_view->priv->layout_idle_id =
3505 gdk_threads_add_idle_full (GTK_ICON_VIEW_PRIORITY_LAYOUT,
3506 layout_callback, icon_view, NULL);
3510 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3511 GtkIconViewItem *item,
3515 AtkObject *item_obj;
3516 AtkObject *cursor_item_obj;
3518 if (icon_view->priv->cursor_item == item &&
3519 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3522 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3523 if (icon_view->priv->cursor_item != NULL)
3525 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3528 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3529 if (cursor_item_obj != NULL)
3530 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3533 icon_view->priv->cursor_item = item;
3534 if (cursor_cell >= 0)
3535 icon_view->priv->cursor_cell = cursor_cell;
3537 gtk_icon_view_queue_draw_item (icon_view, item);
3539 /* Notify that accessible focus object has changed */
3540 item_obj = atk_object_ref_accessible_child (obj, item->index);
3542 if (item_obj != NULL)
3544 atk_focus_tracker_notify (item_obj);
3545 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3546 g_object_unref (item_obj);
3551 static GtkIconViewItem *
3552 gtk_icon_view_item_new (void)
3554 GtkIconViewItem *item;
3556 item = g_new0 (GtkIconViewItem, 1);
3565 gtk_icon_view_item_free (GtkIconViewItem *item)
3567 g_return_if_fail (item != NULL);
3569 g_free (item->before);
3570 g_free (item->after);
3577 static GtkIconViewItem *
3578 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3581 gboolean only_in_cell,
3582 GtkIconViewCellInfo **cell_at_pos)
3588 *cell_at_pos = NULL;
3590 for (items = icon_view->priv->items; items; items = items->next)
3592 GtkIconViewItem *item = items->data;
3594 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3595 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3597 if (only_in_cell || cell_at_pos)
3599 gtk_icon_view_set_cell_data (icon_view, item);
3601 for (l = icon_view->priv->cell_list; l; l = l->next)
3603 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3605 if (!gtk_cell_renderer_get_visible (info->cell))
3608 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3610 if ((x >= box.x && x <= box.x + box.width &&
3611 y >= box.y && y <= box.y + box.height) ||
3613 x <= box.x + box.width &&
3615 y <= box.y + box.height))
3618 *cell_at_pos = info;
3636 gtk_icon_view_select_item (GtkIconView *icon_view,
3637 GtkIconViewItem *item)
3639 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3640 g_return_if_fail (item != NULL);
3645 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3647 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3648 gtk_icon_view_unselect_all_internal (icon_view);
3650 item->selected = TRUE;
3652 gtk_icon_view_item_selected_changed (icon_view, item);
3653 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3655 gtk_icon_view_queue_draw_item (icon_view, item);
3660 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3661 GtkIconViewItem *item)
3663 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3664 g_return_if_fail (item != NULL);
3666 if (!item->selected)
3669 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3670 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3673 item->selected = FALSE;
3675 gtk_icon_view_item_selected_changed (icon_view, item);
3676 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3678 gtk_icon_view_queue_draw_item (icon_view, item);
3682 verify_items (GtkIconView *icon_view)
3687 for (items = icon_view->priv->items; items; items = items->next)
3689 GtkIconViewItem *item = items->data;
3691 if (item->index != i)
3692 g_error ("List item does not match its index: "
3693 "item index %d and list index %d\n", item->index, i);
3700 gtk_icon_view_row_changed (GtkTreeModel *model,
3705 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3706 GtkIconViewItem *item;
3709 /* ignore changes in branches */
3710 if (gtk_tree_path_get_depth (path) > 1)
3713 gtk_icon_view_stop_editing (icon_view, TRUE);
3715 index = gtk_tree_path_get_indices(path)[0];
3716 item = g_list_nth_data (icon_view->priv->items, index);
3718 gtk_icon_view_item_invalidate_size (item);
3719 gtk_icon_view_queue_layout (icon_view);
3721 verify_items (icon_view);
3725 gtk_icon_view_row_inserted (GtkTreeModel *model,
3730 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3732 GtkIconViewItem *item;
3733 gboolean iters_persist;
3736 /* ignore changes in branches */
3737 if (gtk_tree_path_get_depth (path) > 1)
3740 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3742 index = gtk_tree_path_get_indices(path)[0];
3744 item = gtk_icon_view_item_new ();
3749 item->index = index;
3751 /* FIXME: We can be more efficient here,
3752 we can store a tail pointer and use that when
3753 appending (which is a rather common operation)
3755 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3758 list = g_list_nth (icon_view->priv->items, index + 1);
3759 for (; list; list = list->next)
3766 verify_items (icon_view);
3768 gtk_icon_view_queue_layout (icon_view);
3772 gtk_icon_view_row_deleted (GtkTreeModel *model,
3776 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3778 GtkIconViewItem *item;
3780 gboolean emit = FALSE;
3782 /* ignore changes in branches */
3783 if (gtk_tree_path_get_depth (path) > 1)
3786 index = gtk_tree_path_get_indices(path)[0];
3788 list = g_list_nth (icon_view->priv->items, index);
3791 gtk_icon_view_stop_editing (icon_view, TRUE);
3793 if (item == icon_view->priv->anchor_item)
3794 icon_view->priv->anchor_item = NULL;
3796 if (item == icon_view->priv->cursor_item)
3797 icon_view->priv->cursor_item = NULL;
3802 gtk_icon_view_item_free (item);
3804 for (next = list->next; next; next = next->next)
3811 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3813 verify_items (icon_view);
3815 gtk_icon_view_queue_layout (icon_view);
3818 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3822 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3823 GtkTreePath *parent,
3828 GtkIconView *icon_view = GTK_ICON_VIEW (data);
3831 GList *items = NULL, *list;
3832 GtkIconViewItem **item_array;
3835 /* ignore changes in branches */
3839 gtk_icon_view_stop_editing (icon_view, TRUE);
3841 length = gtk_tree_model_iter_n_children (model, NULL);
3843 order = g_new (gint, length);
3844 for (i = 0; i < length; i++)
3845 order [new_order[i]] = i;
3847 item_array = g_new (GtkIconViewItem *, length);
3848 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3849 item_array[order[i]] = list->data;
3852 for (i = length - 1; i >= 0; i--)
3854 item_array[i]->index = i;
3855 items = g_list_prepend (items, item_array[i]);
3858 g_free (item_array);
3859 g_list_free (icon_view->priv->items);
3860 icon_view->priv->items = items;
3862 gtk_icon_view_queue_layout (icon_view);
3864 verify_items (icon_view);
3868 gtk_icon_view_build_items (GtkIconView *icon_view)
3872 gboolean iters_persist;
3873 GList *items = NULL;
3875 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3877 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3885 GtkIconViewItem *item = gtk_icon_view_item_new ();
3894 items = g_list_prepend (items, item);
3896 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3898 icon_view->priv->items = g_list_reverse (items);
3902 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3905 GtkMovementStep step,
3909 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3910 I_("move-cursor"), 2,
3914 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3919 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3922 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3927 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3934 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3935 GtkMovementStep step,
3938 GdkModifierType state;
3940 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3941 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3942 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3943 step == GTK_MOVEMENT_DISPLAY_LINES ||
3944 step == GTK_MOVEMENT_PAGES ||
3945 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3947 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3950 gtk_icon_view_stop_editing (icon_view, FALSE);
3951 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3953 if (gtk_get_current_event_state (&state))
3955 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3956 icon_view->priv->ctrl_pressed = TRUE;
3957 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3958 icon_view->priv->shift_pressed = TRUE;
3960 /* else we assume not pressed */
3964 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3965 case GTK_MOVEMENT_VISUAL_POSITIONS:
3966 gtk_icon_view_move_cursor_left_right (icon_view, count);
3968 case GTK_MOVEMENT_DISPLAY_LINES:
3969 gtk_icon_view_move_cursor_up_down (icon_view, count);
3971 case GTK_MOVEMENT_PAGES:
3972 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3974 case GTK_MOVEMENT_BUFFER_ENDS:
3975 gtk_icon_view_move_cursor_start_end (icon_view, count);
3978 g_assert_not_reached ();
3981 icon_view->priv->ctrl_pressed = FALSE;
3982 icon_view->priv->shift_pressed = FALSE;
3984 icon_view->priv->draw_focus = TRUE;
3989 static GtkIconViewItem *
3990 find_item (GtkIconView *icon_view,
3991 GtkIconViewItem *current,
3997 GtkIconViewItem *item;
3999 /* FIXME: this could be more efficient
4001 row = current->row + row_ofs;
4002 col = current->col + col_ofs;
4004 for (items = icon_view->priv->items; items; items = items->next)
4007 if (item->row == row && item->col == col)
4015 find_cell (GtkIconView *icon_view,
4016 GtkIconViewItem *item,
4018 GtkOrientation orientation,
4028 if (icon_view->priv->item_orientation != orientation)
4031 gtk_icon_view_set_cell_data (icon_view, item);
4033 focusable = g_new0 (gint, icon_view->priv->n_cells);
4037 for (k = 0; k < 2; k++)
4038 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4040 GtkCellRendererMode mode;
4041 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4043 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
4046 if (!gtk_cell_renderer_get_visible (info->cell))
4049 g_object_get (info->cell, "mode", &mode, NULL);
4050 if (mode != GTK_CELL_RENDERER_MODE_INERT)
4053 current = n_focusable;
4055 focusable[n_focusable] = i;
4061 if (n_focusable == 0)
4069 current = step > 0 ? 0 : n_focusable - 1;
4070 cell = focusable[current];
4073 if (current + *count < 0)
4076 *count = current + *count;
4078 else if (current + *count > n_focusable - 1)
4081 *count = current + *count - (n_focusable - 1);
4085 cell = focusable[current + *count];
4094 static GtkIconViewItem *
4095 find_item_page_up_down (GtkIconView *icon_view,
4096 GtkIconViewItem *current,
4103 y = current->y + count * icon_view->priv->vadjustment->page_size;
4105 item = g_list_find (icon_view->priv->items, current);
4110 for (next = item->next; next; next = next->next)
4112 if (((GtkIconViewItem *)next->data)->col == col)
4115 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4125 for (next = item->prev; next; next = next->prev)
4127 if (((GtkIconViewItem *)next->data)->col == col)
4130 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4144 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4145 GtkIconViewItem *anchor,
4146 GtkIconViewItem *cursor)
4149 GtkIconViewItem *item;
4150 gint row1, row2, col1, col2;
4151 gboolean dirty = FALSE;
4153 if (anchor->row < cursor->row)
4164 if (anchor->col < cursor->col)
4175 for (items = icon_view->priv->items; items; items = items->next)
4179 if (row1 <= item->row && item->row <= row2 &&
4180 col1 <= item->col && item->col <= col2)
4182 if (!item->selected)
4185 item->selected = TRUE;
4186 gtk_icon_view_item_selected_changed (icon_view, item);
4188 gtk_icon_view_queue_draw_item (icon_view, item);
4196 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4199 GtkIconViewItem *item;
4201 gboolean dirty = FALSE;
4203 GtkDirectionType direction;
4205 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4208 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4210 if (!icon_view->priv->cursor_item)
4215 list = icon_view->priv->items;
4217 list = g_list_last (icon_view->priv->items);
4219 item = list ? list->data : NULL;
4224 item = icon_view->priv->cursor_item;
4225 cell = icon_view->priv->cursor_cell;
4226 step = count > 0 ? 1 : -1;
4229 cell = find_cell (icon_view, item, cell,
4230 GTK_ORIENTATION_VERTICAL,
4235 item = find_item (icon_view, item, step, 0);
4236 count = count - step;
4242 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4244 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4246 gtk_widget_child_focus (toplevel,
4247 direction == GTK_DIR_UP ?
4248 GTK_DIR_TAB_BACKWARD :
4249 GTK_DIR_TAB_FORWARD);
4255 if (icon_view->priv->ctrl_pressed ||
4256 !icon_view->priv->shift_pressed ||
4257 !icon_view->priv->anchor_item ||
4258 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4259 icon_view->priv->anchor_item = item;
4261 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4263 if (!icon_view->priv->ctrl_pressed &&
4264 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4266 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4267 dirty = gtk_icon_view_select_all_between (icon_view,
4268 icon_view->priv->anchor_item,
4272 gtk_icon_view_scroll_to_item (icon_view, item);
4275 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4279 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4282 GtkIconViewItem *item;
4283 gboolean dirty = FALSE;
4285 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4288 if (!icon_view->priv->cursor_item)
4293 list = icon_view->priv->items;
4295 list = g_list_last (icon_view->priv->items);
4297 item = list ? list->data : NULL;
4300 item = find_item_page_up_down (icon_view,
4301 icon_view->priv->cursor_item,
4304 if (item == icon_view->priv->cursor_item)
4305 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4310 if (icon_view->priv->ctrl_pressed ||
4311 !icon_view->priv->shift_pressed ||
4312 !icon_view->priv->anchor_item ||
4313 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4314 icon_view->priv->anchor_item = item;
4316 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4318 if (!icon_view->priv->ctrl_pressed &&
4319 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4321 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4322 dirty = gtk_icon_view_select_all_between (icon_view,
4323 icon_view->priv->anchor_item,
4327 gtk_icon_view_scroll_to_item (icon_view, item);
4330 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4334 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4337 GtkIconViewItem *item;
4339 gboolean dirty = FALSE;
4341 GtkDirectionType direction;
4343 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4346 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4348 if (!icon_view->priv->cursor_item)
4353 list = icon_view->priv->items;
4355 list = g_list_last (icon_view->priv->items);
4357 item = list ? list->data : NULL;
4361 item = icon_view->priv->cursor_item;
4362 cell = icon_view->priv->cursor_cell;
4363 step = count > 0 ? 1 : -1;
4366 cell = find_cell (icon_view, item, cell,
4367 GTK_ORIENTATION_HORIZONTAL,
4372 item = find_item (icon_view, item, 0, step);
4373 count = count - step;
4379 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4381 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4383 gtk_widget_child_focus (toplevel,
4384 direction == GTK_DIR_LEFT ?
4385 GTK_DIR_TAB_BACKWARD :
4386 GTK_DIR_TAB_FORWARD);
4392 if (icon_view->priv->ctrl_pressed ||
4393 !icon_view->priv->shift_pressed ||
4394 !icon_view->priv->anchor_item ||
4395 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4396 icon_view->priv->anchor_item = item;
4398 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4400 if (!icon_view->priv->ctrl_pressed &&
4401 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4403 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4404 dirty = gtk_icon_view_select_all_between (icon_view,
4405 icon_view->priv->anchor_item,
4409 gtk_icon_view_scroll_to_item (icon_view, item);
4412 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4416 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4419 GtkIconViewItem *item;
4421 gboolean dirty = FALSE;
4423 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4427 list = icon_view->priv->items;
4429 list = g_list_last (icon_view->priv->items);
4431 item = list ? list->data : NULL;
4433 if (item == icon_view->priv->cursor_item)
4434 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4439 if (icon_view->priv->ctrl_pressed ||
4440 !icon_view->priv->shift_pressed ||
4441 !icon_view->priv->anchor_item ||
4442 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4443 icon_view->priv->anchor_item = item;
4445 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4447 if (!icon_view->priv->ctrl_pressed &&
4448 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4450 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4451 dirty = gtk_icon_view_select_all_between (icon_view,
4452 icon_view->priv->anchor_item,
4456 gtk_icon_view_scroll_to_item (icon_view, item);
4459 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4463 * gtk_icon_view_scroll_to_path:
4464 * @icon_view: A #GtkIconView.
4465 * @path: The path of the item to move to.
4466 * @use_align: whether to use alignment arguments, or %FALSE.
4467 * @row_align: The vertical alignment of the item specified by @path.
4468 * @col_align: The horizontal alignment of the item specified by @path.
4470 * Moves the alignments of @icon_view to the position specified by @path.
4471 * @row_align determines where the row is placed, and @col_align determines
4472 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4473 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4476 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4477 * tree does the minimum amount of work to scroll the item onto the screen.
4478 * This means that the item will be scrolled to the edge closest to its current
4479 * position. If the item is currently visible on the screen, nothing is done.
4481 * This function only works if the model is set, and @path is a valid row on
4482 * the model. If the model changes before the @icon_view is realized, the
4483 * centered path will be modified to reflect this change.
4488 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4494 GtkIconViewItem *item = NULL;
4497 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4498 g_return_if_fail (path != NULL);
4499 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4500 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4502 widget = GTK_WIDGET (icon_view);
4504 if (gtk_tree_path_get_depth (path) > 0)
4505 item = g_list_nth_data (icon_view->priv->items,
4506 gtk_tree_path_get_indices(path)[0]);
4508 if (!item || item->width < 0 ||
4509 !gtk_widget_get_realized (widget))
4511 if (icon_view->priv->scroll_to_path)
4512 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4514 icon_view->priv->scroll_to_path = NULL;
4517 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4519 icon_view->priv->scroll_to_use_align = use_align;
4520 icon_view->priv->scroll_to_row_align = row_align;
4521 icon_view->priv->scroll_to_col_align = col_align;
4528 GtkAllocation allocation;
4533 gtk_widget_style_get (widget,
4534 "focus-line-width", &focus_width,
4537 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4539 gtk_widget_get_allocation (widget, &allocation);
4541 offset = y + item->y - focus_width - row_align * (allocation.height - item->height);
4543 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4544 icon_view->priv->vadjustment->value + offset);
4546 offset = x + item->x - focus_width - col_align * (allocation.width - item->width);
4548 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4549 icon_view->priv->hadjustment->value + offset);
4551 gtk_adjustment_changed (icon_view->priv->hadjustment);
4552 gtk_adjustment_changed (icon_view->priv->vadjustment);
4555 gtk_icon_view_scroll_to_item (icon_view, item);
4560 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4561 GtkIconViewItem *item)
4563 GtkAllocation allocation;
4564 GtkWidget *widget = GTK_WIDGET (icon_view);
4565 gint x, y, width, height;
4568 gtk_widget_style_get (widget,
4569 "focus-line-width", &focus_width,
4572 width = gdk_window_get_width (icon_view->priv->bin_window);
4573 height = gdk_window_get_height (icon_view->priv->bin_window);
4574 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4576 gtk_widget_get_allocation (widget, &allocation);
4578 if (y + item->y - focus_width < 0)
4579 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4580 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4581 else if (y + item->y + item->height + focus_width > allocation.height)
4582 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4583 icon_view->priv->vadjustment->value + y + item->y + item->height
4584 + focus_width - allocation.height);
4586 if (x + item->x - focus_width < 0)
4587 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4588 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4589 else if (x + item->x + item->width + focus_width > allocation.width)
4590 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4591 icon_view->priv->hadjustment->value + x + item->x + item->width
4592 + focus_width - allocation.width);
4594 gtk_adjustment_changed (icon_view->priv->hadjustment);
4595 gtk_adjustment_changed (icon_view->priv->vadjustment);
4598 /* GtkCellLayout implementation */
4599 static GtkIconViewCellInfo *
4600 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4601 GtkCellRenderer *renderer)
4605 for (i = icon_view->priv->cell_list; i; i = i->next)
4607 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4609 if (info->cell == renderer)
4617 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4618 GtkIconViewItem *item)
4621 gboolean iters_persist;
4624 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4630 path = gtk_tree_path_new_from_indices (item->index, -1);
4631 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4633 gtk_tree_path_free (path);
4638 for (i = icon_view->priv->cell_list; i; i = i->next)
4641 GtkIconViewCellInfo *info = i->data;
4643 g_object_freeze_notify (G_OBJECT (info->cell));
4645 for (j = info->attributes; j && j->next; j = j->next->next)
4647 gchar *property = j->data;
4648 gint column = GPOINTER_TO_INT (j->next->data);
4649 GValue value = {0, };
4651 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4653 g_object_set_property (G_OBJECT (info->cell),
4655 g_value_unset (&value);
4659 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4661 icon_view->priv->model,
4665 g_object_thaw_notify (G_OBJECT (info->cell));
4670 free_cell_attributes (GtkIconViewCellInfo *info)
4674 list = info->attributes;
4675 while (list && list->next)
4677 g_free (list->data);
4678 list = list->next->next;
4681 g_slist_free (info->attributes);
4682 info->attributes = NULL;
4686 free_cell_info (GtkIconViewCellInfo *info)
4688 free_cell_attributes (info);
4690 g_object_unref (info->cell);
4693 (* info->destroy) (info->func_data);
4699 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4700 GtkCellRenderer *renderer,
4703 GtkIconViewCellInfo *info;
4704 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4706 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4707 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4709 g_object_ref_sink (renderer);
4711 info = g_new0 (GtkIconViewCellInfo, 1);
4712 info->cell = renderer;
4713 info->expand = expand ? TRUE : FALSE;
4714 info->pack = GTK_PACK_START;
4715 info->position = icon_view->priv->n_cells;
4717 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4718 icon_view->priv->n_cells++;
4722 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4723 GtkCellRenderer *renderer,
4726 GtkIconViewCellInfo *info;
4727 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4729 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4730 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4732 g_object_ref_sink (renderer);
4734 info = g_new0 (GtkIconViewCellInfo, 1);
4735 info->cell = renderer;
4736 info->expand = expand ? TRUE : FALSE;
4737 info->pack = GTK_PACK_END;
4738 info->position = icon_view->priv->n_cells;
4740 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4741 icon_view->priv->n_cells++;
4745 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4746 GtkCellRenderer *renderer,
4747 const gchar *attribute,
4750 GtkIconViewCellInfo *info;
4751 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4753 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4754 g_return_if_fail (info != NULL);
4756 info->attributes = g_slist_prepend (info->attributes,
4757 GINT_TO_POINTER (column));
4758 info->attributes = g_slist_prepend (info->attributes,
4759 g_strdup (attribute));
4763 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4765 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4767 while (icon_view->priv->cell_list)
4769 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4770 free_cell_info (info);
4771 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4772 icon_view->priv->cell_list);
4775 icon_view->priv->n_cells = 0;
4779 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4780 GtkCellRenderer *cell,
4781 GtkCellLayoutDataFunc func,
4783 GDestroyNotify destroy)
4785 GtkIconViewCellInfo *info;
4786 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4788 info = gtk_icon_view_get_cell_info (icon_view, cell);
4789 g_return_if_fail (info != NULL);
4793 GDestroyNotify d = info->destroy;
4795 info->destroy = NULL;
4796 d (info->func_data);
4800 info->func_data = func_data;
4801 info->destroy = destroy;
4805 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4806 GtkCellRenderer *renderer)
4808 GtkIconViewCellInfo *info;
4810 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4812 free_cell_attributes (info);
4816 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4817 GtkCellRenderer *cell,
4820 GtkIconView *icon_view;
4822 GtkIconViewCellInfo *info;
4825 icon_view = GTK_ICON_VIEW (layout);
4827 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4829 info = gtk_icon_view_get_cell_info (icon_view, cell);
4831 g_return_if_fail (info != NULL);
4832 g_return_if_fail (position >= 0);
4834 link = g_list_find (icon_view->priv->cell_list, info);
4836 g_return_if_fail (link != NULL);
4838 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4840 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4843 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4850 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4854 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4856 GtkIconView *icon_view = (GtkIconView *)layout;
4857 GList *retval = NULL, *l;
4859 for (l = icon_view->priv->cell_list; l; l = l->next)
4861 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4863 retval = g_list_prepend (retval, info->cell);
4866 return g_list_reverse (retval);
4873 * gtk_icon_view_new:
4875 * Creates a new #GtkIconView widget
4877 * Return value: A newly created #GtkIconView widget
4882 gtk_icon_view_new (void)
4884 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4888 * gtk_icon_view_new_with_model:
4889 * @model: The model.
4891 * Creates a new #GtkIconView widget with the model @model.
4893 * Return value: A newly created #GtkIconView widget.
4898 gtk_icon_view_new_with_model (GtkTreeModel *model)
4900 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4904 * gtk_icon_view_convert_widget_to_bin_window_coords:
4905 * @icon_view: a #GtkIconView
4906 * @wx: X coordinate relative to the widget
4907 * @wy: Y coordinate relative to the widget
4908 * @bx: return location for bin_window X coordinate
4909 * @by: return location for bin_window Y coordinate
4911 * Converts widget coordinates to coordinates for the bin_window,
4912 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4917 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4925 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4927 if (icon_view->priv->bin_window)
4928 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4939 * gtk_icon_view_get_path_at_pos:
4940 * @icon_view: A #GtkIconView.
4941 * @x: The x position to be identified
4942 * @y: The y position to be identified
4944 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4945 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4946 * the cell at the specified position.
4947 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4948 * widget coordinates to bin_window coordinates.
4950 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4951 * if no icon exists at that position.
4956 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4960 GtkIconViewItem *item;
4963 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4965 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4970 path = gtk_tree_path_new_from_indices (item->index, -1);
4976 * gtk_icon_view_get_item_at_pos:
4977 * @icon_view: A #GtkIconView.
4978 * @x: The x position to be identified
4979 * @y: The y position to be identified
4980 * @path: (allow-none): Return location for the path, or %NULL
4981 * @cell: Return location for the renderer responsible for the cell
4982 * at (@x, @y), or %NULL
4984 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4985 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4986 * obtains the cell at the specified position. The returned path should
4987 * be freed with gtk_tree_path_free().
4988 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4989 * widget coordinates to bin_window coordinates.
4991 * Return value: %TRUE if an item exists at the specified position
4996 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
5000 GtkCellRenderer **cell)
5002 GtkIconViewItem *item;
5003 GtkIconViewCellInfo *info;
5005 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5007 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
5012 *path = gtk_tree_path_new_from_indices (item->index, -1);
5025 return (item != NULL);
5029 * gtk_icon_view_set_tooltip_item:
5030 * @icon_view: a #GtkIconView
5031 * @tooltip: a #GtkTooltip
5032 * @path: a #GtkTreePath
5034 * Sets the tip area of @tooltip to be the area covered by the item at @path.
5035 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
5036 * See also gtk_tooltip_set_tip_area().
5041 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
5042 GtkTooltip *tooltip,
5045 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5046 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
5048 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
5052 * gtk_icon_view_set_tooltip_cell:
5053 * @icon_view: a #GtkIconView
5054 * @tooltip: a #GtkTooltip
5055 * @path: a #GtkTreePath
5056 * @cell: (allow-none): a #GtkCellRenderer or %NULL
5058 * Sets the tip area of @tooltip to the area which @cell occupies in
5059 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
5061 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
5066 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
5067 GtkTooltip *tooltip,
5069 GtkCellRenderer *cell)
5072 GtkIconViewItem *item = NULL;
5073 GtkIconViewCellInfo *info = NULL;
5076 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5077 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
5078 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
5080 if (gtk_tree_path_get_depth (path) > 0)
5081 item = g_list_nth_data (icon_view->priv->items,
5082 gtk_tree_path_get_indices(path)[0]);
5089 info = gtk_icon_view_get_cell_info (icon_view, cell);
5090 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
5096 rect.width = item->width;
5097 rect.height = item->height;
5100 if (icon_view->priv->bin_window)
5102 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
5107 gtk_tooltip_set_tip_area (tooltip, &rect);
5112 * gtk_icon_view_get_tooltip_context:
5113 * @icon_view: an #GtkIconView
5114 * @x: the x coordinate (relative to widget coordinates)
5115 * @y: the y coordinate (relative to widget coordinates)
5116 * @keyboard_tip: whether this is a keyboard tooltip or not
5117 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5118 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
5119 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5121 * This function is supposed to be used in a #GtkWidget::query-tooltip
5122 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5123 * which are received in the signal handler, should be passed to this
5124 * function without modification.
5126 * The return value indicates whether there is an icon view item at the given
5127 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5128 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5129 * @model, @path and @iter which have been provided will be set to point to
5130 * that row and the corresponding model. @x and @y will always be converted
5131 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5133 * Return value: whether or not the given tooltip context points to a item
5138 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5141 gboolean keyboard_tip,
5142 GtkTreeModel **model,
5146 GtkTreePath *tmppath = NULL;
5148 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5149 g_return_val_if_fail (x != NULL, FALSE);
5150 g_return_val_if_fail (y != NULL, FALSE);
5154 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5161 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5164 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5169 *model = gtk_icon_view_get_model (icon_view);
5172 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5178 gtk_tree_path_free (tmppath);
5184 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5187 gboolean keyboard_tip,
5188 GtkTooltip *tooltip,
5194 GtkTreeModel *model;
5195 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5197 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5200 &model, &path, &iter))
5203 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5207 gtk_tree_path_free (path);
5211 gtk_tooltip_set_markup (tooltip, str);
5212 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5214 gtk_tree_path_free (path);
5222 * gtk_icon_view_set_tooltip_column:
5223 * @icon_view: a #GtkIconView
5224 * @column: an integer, which is a valid column number for @icon_view's model
5226 * If you only plan to have simple (text-only) tooltips on full items, you
5227 * can use this function to have #GtkIconView handle these automatically
5228 * for you. @column should be set to the column in @icon_view's model
5229 * containing the tooltip texts, or -1 to disable this feature.
5231 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5232 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5234 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
5235 * so &, <, etc have to be escaped in the text.
5240 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5243 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5245 if (column == icon_view->priv->tooltip_column)
5250 g_signal_handlers_disconnect_by_func (icon_view,
5251 gtk_icon_view_set_tooltip_query_cb,
5253 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5257 if (icon_view->priv->tooltip_column == -1)
5259 g_signal_connect (icon_view, "query-tooltip",
5260 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5261 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5265 icon_view->priv->tooltip_column = column;
5266 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5270 * gtk_icon_view_get_tooltip_column:
5271 * @icon_view: a #GtkIconView
5273 * Returns the column of @icon_view's model which is being used for
5274 * displaying tooltips on @icon_view's rows.
5276 * Return value: the index of the tooltip column that is currently being
5277 * used, or -1 if this is disabled.
5282 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5284 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5286 return icon_view->priv->tooltip_column;
5290 * gtk_icon_view_get_visible_range:
5291 * @icon_view: A #GtkIconView
5292 * @start_path: (allow-none): Return location for start of region, or %NULL
5293 * @end_path: (allow-none): Return location for end of region, or %NULL
5295 * Sets @start_path and @end_path to be the first and last visible path.
5296 * Note that there may be invisible paths in between.
5298 * Both paths should be freed with gtk_tree_path_free() after use.
5300 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5305 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5306 GtkTreePath **start_path,
5307 GtkTreePath **end_path)
5309 gint start_index = -1;
5310 gint end_index = -1;
5313 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5315 if (icon_view->priv->hadjustment == NULL ||
5316 icon_view->priv->vadjustment == NULL)
5319 if (start_path == NULL && end_path == NULL)
5322 for (icons = icon_view->priv->items; icons; icons = icons->next)
5324 GtkIconViewItem *item = icons->data;
5326 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5327 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5328 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5329 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5331 if (start_index == -1)
5332 start_index = item->index;
5333 end_index = item->index;
5337 if (start_path && start_index != -1)
5338 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5339 if (end_path && end_index != -1)
5340 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5342 return start_index != -1;
5346 * gtk_icon_view_selected_foreach:
5347 * @icon_view: A #GtkIconView.
5348 * @func: (scope call): The function to call for each selected icon.
5349 * @data: User data to pass to the function.
5351 * Calls a function for each selected icon. Note that the model or
5352 * selection cannot be modified from within this function.
5357 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5358 GtkIconViewForeachFunc func,
5363 for (list = icon_view->priv->items; list; list = list->next)
5365 GtkIconViewItem *item = list->data;
5366 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5369 (* func) (icon_view, path, data);
5371 gtk_tree_path_free (path);
5376 * gtk_icon_view_set_selection_mode:
5377 * @icon_view: A #GtkIconView.
5378 * @mode: The selection mode
5380 * Sets the selection mode of the @icon_view.
5385 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5386 GtkSelectionMode mode)
5388 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5390 if (mode == icon_view->priv->selection_mode)
5393 if (mode == GTK_SELECTION_NONE ||
5394 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5395 gtk_icon_view_unselect_all (icon_view);
5397 icon_view->priv->selection_mode = mode;
5399 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5403 * gtk_icon_view_get_selection_mode:
5404 * @icon_view: A #GtkIconView.
5406 * Gets the selection mode of the @icon_view.
5408 * Return value: the current selection mode
5413 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5415 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5417 return icon_view->priv->selection_mode;
5421 * gtk_icon_view_set_model:
5422 * @icon_view: A #GtkIconView.
5423 * @model: (allow-none): The model.
5425 * Sets the model for a #GtkIconView.
5426 * If the @icon_view already has a model set, it will remove
5427 * it before setting the new model. If @model is %NULL, then
5428 * it will unset the old model.
5433 gtk_icon_view_set_model (GtkIconView *icon_view,
5434 GtkTreeModel *model)
5436 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5437 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5439 if (icon_view->priv->model == model)
5442 if (icon_view->priv->scroll_to_path)
5444 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5445 icon_view->priv->scroll_to_path = NULL;
5448 gtk_icon_view_stop_editing (icon_view, TRUE);
5454 if (icon_view->priv->pixbuf_column != -1)
5456 column_type = gtk_tree_model_get_column_type (model,
5457 icon_view->priv->pixbuf_column);
5459 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5462 if (icon_view->priv->text_column != -1)
5464 column_type = gtk_tree_model_get_column_type (model,
5465 icon_view->priv->text_column);
5467 g_return_if_fail (column_type == G_TYPE_STRING);
5470 if (icon_view->priv->markup_column != -1)
5472 column_type = gtk_tree_model_get_column_type (model,
5473 icon_view->priv->markup_column);
5475 g_return_if_fail (column_type == G_TYPE_STRING);
5480 if (icon_view->priv->model)
5482 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5483 gtk_icon_view_row_changed,
5485 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5486 gtk_icon_view_row_inserted,
5488 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5489 gtk_icon_view_row_deleted,
5491 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5492 gtk_icon_view_rows_reordered,
5495 g_object_unref (icon_view->priv->model);
5497 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5498 g_list_free (icon_view->priv->items);
5499 icon_view->priv->items = NULL;
5500 icon_view->priv->anchor_item = NULL;
5501 icon_view->priv->cursor_item = NULL;
5502 icon_view->priv->last_single_clicked = NULL;
5503 icon_view->priv->width = 0;
5504 icon_view->priv->height = 0;
5507 icon_view->priv->model = model;
5509 if (icon_view->priv->model)
5511 g_object_ref (icon_view->priv->model);
5512 g_signal_connect (icon_view->priv->model,
5514 G_CALLBACK (gtk_icon_view_row_changed),
5516 g_signal_connect (icon_view->priv->model,
5518 G_CALLBACK (gtk_icon_view_row_inserted),
5520 g_signal_connect (icon_view->priv->model,
5522 G_CALLBACK (gtk_icon_view_row_deleted),
5524 g_signal_connect (icon_view->priv->model,
5526 G_CALLBACK (gtk_icon_view_rows_reordered),
5529 gtk_icon_view_build_items (icon_view);
5531 gtk_icon_view_queue_layout (icon_view);
5534 g_object_notify (G_OBJECT (icon_view), "model");
5536 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5537 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5541 * gtk_icon_view_get_model:
5542 * @icon_view: a #GtkIconView
5544 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5547 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5548 * currently being used.
5553 gtk_icon_view_get_model (GtkIconView *icon_view)
5555 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5557 return icon_view->priv->model;
5561 update_text_cell (GtkIconView *icon_view)
5563 GtkIconViewCellInfo *info;
5567 if (icon_view->priv->text_column == -1 &&
5568 icon_view->priv->markup_column == -1)
5570 if (icon_view->priv->text_cell != -1)
5572 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5573 icon_view->priv->pixbuf_cell--;
5575 info = g_list_nth_data (icon_view->priv->cell_list,
5576 icon_view->priv->text_cell);
5578 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5580 free_cell_info (info);
5582 icon_view->priv->n_cells--;
5583 icon_view->priv->text_cell = -1;
5588 if (icon_view->priv->text_cell == -1)
5590 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5591 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5592 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5595 if (info->cell == cell)
5597 icon_view->priv->text_cell = i;
5603 info = g_list_nth_data (icon_view->priv->cell_list,
5604 icon_view->priv->text_cell);
5606 if (icon_view->priv->markup_column != -1)
5607 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5609 "markup", icon_view->priv->markup_column,
5612 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5614 "text", icon_view->priv->text_column,
5617 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5618 g_object_set (info->cell,
5619 "alignment", PANGO_ALIGN_CENTER,
5620 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5625 g_object_set (info->cell,
5626 "alignment", PANGO_ALIGN_LEFT,
5627 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5635 update_pixbuf_cell (GtkIconView *icon_view)
5637 GtkIconViewCellInfo *info;
5641 if (icon_view->priv->pixbuf_column == -1)
5643 if (icon_view->priv->pixbuf_cell != -1)
5645 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5646 icon_view->priv->text_cell--;
5648 info = g_list_nth_data (icon_view->priv->cell_list,
5649 icon_view->priv->pixbuf_cell);
5651 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5653 free_cell_info (info);
5655 icon_view->priv->n_cells--;
5656 icon_view->priv->pixbuf_cell = -1;
5661 if (icon_view->priv->pixbuf_cell == -1)
5663 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5665 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5666 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5669 if (info->cell == cell)
5671 icon_view->priv->pixbuf_cell = i;
5677 info = g_list_nth_data (icon_view->priv->cell_list,
5678 icon_view->priv->pixbuf_cell);
5680 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5682 "pixbuf", icon_view->priv->pixbuf_column,
5685 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5686 g_object_set (info->cell,
5691 g_object_set (info->cell,
5699 * gtk_icon_view_set_text_column:
5700 * @icon_view: A #GtkIconView.
5701 * @column: A column in the currently used model, or -1 to display no text
5703 * Sets the column with text for @icon_view to be @column. The text
5704 * column must be of type #G_TYPE_STRING.
5709 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5712 if (column == icon_view->priv->text_column)
5716 icon_view->priv->text_column = -1;
5719 if (icon_view->priv->model != NULL)
5723 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5725 g_return_if_fail (column_type == G_TYPE_STRING);
5728 icon_view->priv->text_column = column;
5731 gtk_icon_view_stop_editing (icon_view, TRUE);
5733 update_text_cell (icon_view);
5735 gtk_icon_view_invalidate_sizes (icon_view);
5736 gtk_icon_view_queue_layout (icon_view);
5738 g_object_notify (G_OBJECT (icon_view), "text-column");
5742 * gtk_icon_view_get_text_column:
5743 * @icon_view: A #GtkIconView.
5745 * Returns the column with text for @icon_view.
5747 * Returns: the text column, or -1 if it's unset.
5752 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5754 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5756 return icon_view->priv->text_column;
5760 * gtk_icon_view_set_markup_column:
5761 * @icon_view: A #GtkIconView.
5762 * @column: A column in the currently used model, or -1 to display no text
5764 * Sets the column with markup information for @icon_view to be
5765 * @column. The markup column must be of type #G_TYPE_STRING.
5766 * If the markup column is set to something, it overrides
5767 * the text column set by gtk_icon_view_set_text_column().
5772 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5775 if (column == icon_view->priv->markup_column)
5779 icon_view->priv->markup_column = -1;
5782 if (icon_view->priv->model != NULL)
5786 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5788 g_return_if_fail (column_type == G_TYPE_STRING);
5791 icon_view->priv->markup_column = column;
5794 gtk_icon_view_stop_editing (icon_view, TRUE);
5796 update_text_cell (icon_view);
5798 gtk_icon_view_invalidate_sizes (icon_view);
5799 gtk_icon_view_queue_layout (icon_view);
5801 g_object_notify (G_OBJECT (icon_view), "markup-column");
5805 * gtk_icon_view_get_markup_column:
5806 * @icon_view: A #GtkIconView.
5808 * Returns the column with markup text for @icon_view.
5810 * Returns: the markup column, or -1 if it's unset.
5815 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5817 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5819 return icon_view->priv->markup_column;
5823 * gtk_icon_view_set_pixbuf_column:
5824 * @icon_view: A #GtkIconView.
5825 * @column: A column in the currently used model, or -1 to disable
5827 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5828 * column must be of type #GDK_TYPE_PIXBUF
5833 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5836 if (column == icon_view->priv->pixbuf_column)
5840 icon_view->priv->pixbuf_column = -1;
5843 if (icon_view->priv->model != NULL)
5847 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5849 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5852 icon_view->priv->pixbuf_column = column;
5855 gtk_icon_view_stop_editing (icon_view, TRUE);
5857 update_pixbuf_cell (icon_view);
5859 gtk_icon_view_invalidate_sizes (icon_view);
5860 gtk_icon_view_queue_layout (icon_view);
5862 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5867 * gtk_icon_view_get_pixbuf_column:
5868 * @icon_view: A #GtkIconView.
5870 * Returns the column with pixbufs for @icon_view.
5872 * Returns: the pixbuf column, or -1 if it's unset.
5877 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5879 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5881 return icon_view->priv->pixbuf_column;
5885 * gtk_icon_view_select_path:
5886 * @icon_view: A #GtkIconView.
5887 * @path: The #GtkTreePath to be selected.
5889 * Selects the row at @path.
5894 gtk_icon_view_select_path (GtkIconView *icon_view,
5897 GtkIconViewItem *item = NULL;
5899 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5900 g_return_if_fail (icon_view->priv->model != NULL);
5901 g_return_if_fail (path != NULL);
5903 if (gtk_tree_path_get_depth (path) > 0)
5904 item = g_list_nth_data (icon_view->priv->items,
5905 gtk_tree_path_get_indices(path)[0]);
5908 gtk_icon_view_select_item (icon_view, item);
5912 * gtk_icon_view_unselect_path:
5913 * @icon_view: A #GtkIconView.
5914 * @path: The #GtkTreePath to be unselected.
5916 * Unselects the row at @path.
5921 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5924 GtkIconViewItem *item;
5926 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5927 g_return_if_fail (icon_view->priv->model != NULL);
5928 g_return_if_fail (path != NULL);
5930 item = g_list_nth_data (icon_view->priv->items,
5931 gtk_tree_path_get_indices(path)[0]);
5936 gtk_icon_view_unselect_item (icon_view, item);
5940 * gtk_icon_view_get_selected_items:
5941 * @icon_view: A #GtkIconView.
5943 * Creates a list of paths of all selected items. Additionally, if you are
5944 * planning on modifying the model after calling this function, you may
5945 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5946 * To do this, you can use gtk_tree_row_reference_new().
5948 * To free the return value, use:
5950 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5951 * g_list_free (list);
5954 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5959 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5962 GList *selected = NULL;
5964 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5966 for (list = icon_view->priv->items; list != NULL; list = list->next)
5968 GtkIconViewItem *item = list->data;
5972 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5974 selected = g_list_prepend (selected, path);
5982 * gtk_icon_view_select_all:
5983 * @icon_view: A #GtkIconView.
5985 * Selects all the icons. @icon_view must has its selection mode set
5986 * to #GTK_SELECTION_MULTIPLE.
5991 gtk_icon_view_select_all (GtkIconView *icon_view)
5994 gboolean dirty = FALSE;
5996 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5998 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
6001 for (items = icon_view->priv->items; items; items = items->next)
6003 GtkIconViewItem *item = items->data;
6005 if (!item->selected)
6008 item->selected = TRUE;
6009 gtk_icon_view_queue_draw_item (icon_view, item);
6014 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
6018 * gtk_icon_view_unselect_all:
6019 * @icon_view: A #GtkIconView.
6021 * Unselects all the icons.
6026 gtk_icon_view_unselect_all (GtkIconView *icon_view)
6028 gboolean dirty = FALSE;
6030 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6032 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
6035 dirty = gtk_icon_view_unselect_all_internal (icon_view);
6038 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
6042 * gtk_icon_view_path_is_selected:
6043 * @icon_view: A #GtkIconView.
6044 * @path: A #GtkTreePath to check selection on.
6046 * Returns %TRUE if the icon pointed to by @path is currently
6047 * selected. If @path does not point to a valid location, %FALSE is returned.
6049 * Return value: %TRUE if @path is selected.
6054 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
6057 GtkIconViewItem *item;
6059 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6060 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
6061 g_return_val_if_fail (path != NULL, FALSE);
6063 item = g_list_nth_data (icon_view->priv->items,
6064 gtk_tree_path_get_indices(path)[0]);
6069 return item->selected;
6073 * gtk_icon_view_get_item_row:
6074 * @icon_view: a #GtkIconView
6075 * @path: the #GtkTreePath of the item
6077 * Gets the row in which the item @path is currently
6078 * displayed. Row numbers start at 0.
6080 * Returns: The row in which the item is displayed
6085 gtk_icon_view_get_item_row (GtkIconView *icon_view,
6088 GtkIconViewItem *item;
6090 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6091 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6092 g_return_val_if_fail (path != NULL, -1);
6094 item = g_list_nth_data (icon_view->priv->items,
6095 gtk_tree_path_get_indices(path)[0]);
6104 * gtk_icon_view_get_item_column:
6105 * @icon_view: a #GtkIconView
6106 * @path: the #GtkTreePath of the item
6108 * Gets the column in which the item @path is currently
6109 * displayed. Column numbers start at 0.
6111 * Returns: The column in which the item is displayed
6116 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6119 GtkIconViewItem *item;
6121 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6122 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6123 g_return_val_if_fail (path != NULL, -1);
6125 item = g_list_nth_data (icon_view->priv->items,
6126 gtk_tree_path_get_indices(path)[0]);
6135 * gtk_icon_view_item_activated:
6136 * @icon_view: A #GtkIconView
6137 * @path: The #GtkTreePath to be activated
6139 * Activates the item determined by @path.
6144 gtk_icon_view_item_activated (GtkIconView *icon_view,
6147 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6148 g_return_if_fail (path != NULL);
6150 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6154 * gtk_icon_view_set_item_orientation:
6155 * @icon_view: a #GtkIconView
6156 * @orientation: the relative position of texts and icons
6158 * Sets the ::item-orientation property which determines whether the labels
6159 * are drawn beside the icons instead of below.
6164 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
6165 GtkOrientation orientation)
6167 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6169 if (icon_view->priv->item_orientation != orientation)
6171 icon_view->priv->item_orientation = orientation;
6173 gtk_icon_view_stop_editing (icon_view, TRUE);
6174 gtk_icon_view_invalidate_sizes (icon_view);
6175 gtk_icon_view_queue_layout (icon_view);
6177 update_text_cell (icon_view);
6178 update_pixbuf_cell (icon_view);
6180 g_object_notify (G_OBJECT (icon_view), "item-orientation");
6185 * gtk_icon_view_get_item_orientation:
6186 * @icon_view: a #GtkIconView
6188 * Returns the value of the ::item-orientation property which determines
6189 * whether the labels are drawn beside the icons instead of below.
6191 * Return value: the relative position of texts and icons
6196 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
6198 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6199 GTK_ORIENTATION_VERTICAL);
6201 return icon_view->priv->item_orientation;
6205 * gtk_icon_view_set_columns:
6206 * @icon_view: a #GtkIconView
6207 * @columns: the number of columns
6209 * Sets the ::columns property which determines in how
6210 * many columns the icons are arranged. If @columns is
6211 * -1, the number of columns will be chosen automatically
6212 * to fill the available area.
6217 gtk_icon_view_set_columns (GtkIconView *icon_view,
6220 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6222 if (icon_view->priv->columns != columns)
6224 icon_view->priv->columns = columns;
6226 gtk_icon_view_stop_editing (icon_view, TRUE);
6227 gtk_icon_view_queue_layout (icon_view);
6229 g_object_notify (G_OBJECT (icon_view), "columns");
6234 * gtk_icon_view_get_columns:
6235 * @icon_view: a #GtkIconView
6237 * Returns the value of the ::columns property.
6239 * Return value: the number of columns, or -1
6244 gtk_icon_view_get_columns (GtkIconView *icon_view)
6246 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6248 return icon_view->priv->columns;
6252 * gtk_icon_view_set_item_width:
6253 * @icon_view: a #GtkIconView
6254 * @item_width: the width for each item
6256 * Sets the ::item-width property which specifies the width
6257 * to use for each item. If it is set to -1, the icon view will
6258 * automatically determine a suitable item size.
6263 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6266 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6268 if (icon_view->priv->item_width != item_width)
6270 icon_view->priv->item_width = item_width;
6272 gtk_icon_view_stop_editing (icon_view, TRUE);
6273 gtk_icon_view_invalidate_sizes (icon_view);
6274 gtk_icon_view_queue_layout (icon_view);
6276 update_text_cell (icon_view);
6278 g_object_notify (G_OBJECT (icon_view), "item-width");
6283 * gtk_icon_view_get_item_width:
6284 * @icon_view: a #GtkIconView
6286 * Returns the value of the ::item-width property.
6288 * Return value: the width of a single item, or -1
6293 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6295 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6297 return icon_view->priv->item_width;
6302 * gtk_icon_view_set_spacing:
6303 * @icon_view: a #GtkIconView
6304 * @spacing: the spacing
6306 * Sets the ::spacing property which specifies the space
6307 * which is inserted between the cells (i.e. the icon and
6308 * the text) of an item.
6313 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6316 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6318 if (icon_view->priv->spacing != spacing)
6320 icon_view->priv->spacing = spacing;
6322 gtk_icon_view_stop_editing (icon_view, TRUE);
6323 gtk_icon_view_invalidate_sizes (icon_view);
6324 gtk_icon_view_queue_layout (icon_view);
6326 g_object_notify (G_OBJECT (icon_view), "spacing");
6331 * gtk_icon_view_get_spacing:
6332 * @icon_view: a #GtkIconView
6334 * Returns the value of the ::spacing property.
6336 * Return value: the space between cells
6341 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6343 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6345 return icon_view->priv->spacing;
6349 * gtk_icon_view_set_row_spacing:
6350 * @icon_view: a #GtkIconView
6351 * @row_spacing: the row spacing
6353 * Sets the ::row-spacing property which specifies the space
6354 * which is inserted between the rows of the icon view.
6359 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6362 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6364 if (icon_view->priv->row_spacing != row_spacing)
6366 icon_view->priv->row_spacing = row_spacing;
6368 gtk_icon_view_stop_editing (icon_view, TRUE);
6369 gtk_icon_view_invalidate_sizes (icon_view);
6370 gtk_icon_view_queue_layout (icon_view);
6372 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6377 * gtk_icon_view_get_row_spacing:
6378 * @icon_view: a #GtkIconView
6380 * Returns the value of the ::row-spacing property.
6382 * Return value: the space between rows
6387 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6389 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6391 return icon_view->priv->row_spacing;
6395 * gtk_icon_view_set_column_spacing:
6396 * @icon_view: a #GtkIconView
6397 * @column_spacing: the column spacing
6399 * Sets the ::column-spacing property which specifies the space
6400 * which is inserted between the columns of the icon view.
6405 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6406 gint column_spacing)
6408 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6410 if (icon_view->priv->column_spacing != column_spacing)
6412 icon_view->priv->column_spacing = column_spacing;
6414 gtk_icon_view_stop_editing (icon_view, TRUE);
6415 gtk_icon_view_invalidate_sizes (icon_view);
6416 gtk_icon_view_queue_layout (icon_view);
6418 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6423 * gtk_icon_view_get_column_spacing:
6424 * @icon_view: a #GtkIconView
6426 * Returns the value of the ::column-spacing property.
6428 * Return value: the space between columns
6433 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6435 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6437 return icon_view->priv->column_spacing;
6441 * gtk_icon_view_set_margin:
6442 * @icon_view: a #GtkIconView
6443 * @margin: the margin
6445 * Sets the ::margin property which specifies the space
6446 * which is inserted at the top, bottom, left and right
6452 gtk_icon_view_set_margin (GtkIconView *icon_view,
6455 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6457 if (icon_view->priv->margin != margin)
6459 icon_view->priv->margin = margin;
6461 gtk_icon_view_stop_editing (icon_view, TRUE);
6462 gtk_icon_view_invalidate_sizes (icon_view);
6463 gtk_icon_view_queue_layout (icon_view);
6465 g_object_notify (G_OBJECT (icon_view), "margin");
6470 * gtk_icon_view_get_margin:
6471 * @icon_view: a #GtkIconView
6473 * Returns the value of the ::margin property.
6475 * Return value: the space at the borders
6480 gtk_icon_view_get_margin (GtkIconView *icon_view)
6482 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6484 return icon_view->priv->margin;
6488 * gtk_icon_view_set_item_padding:
6489 * @icon_view: a #GtkIconView
6490 * @item_padding: the item padding
6492 * Sets the #GtkIconView:item-padding property which specifies the padding
6493 * around each of the icon view's items.
6498 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6501 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6503 if (icon_view->priv->item_padding != item_padding)
6505 icon_view->priv->item_padding = item_padding;
6507 gtk_icon_view_stop_editing (icon_view, TRUE);
6508 gtk_icon_view_invalidate_sizes (icon_view);
6509 gtk_icon_view_queue_layout (icon_view);
6511 g_object_notify (G_OBJECT (icon_view), "item-padding");
6516 * gtk_icon_view_get_item_padding:
6517 * @icon_view: a #GtkIconView
6519 * Returns the value of the ::item-padding property.
6521 * Return value: the padding around items
6526 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6528 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6530 return icon_view->priv->item_padding;
6533 /* Get/set whether drag_motion requested the drag data and
6534 * drag_data_received should thus not actually insert the data,
6535 * since the data doesn't result from a drop.
6538 set_status_pending (GdkDragContext *context,
6539 GdkDragAction suggested_action)
6541 g_object_set_data (G_OBJECT (context),
6542 I_("gtk-icon-view-status-pending"),
6543 GINT_TO_POINTER (suggested_action));
6546 static GdkDragAction
6547 get_status_pending (GdkDragContext *context)
6549 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6550 "gtk-icon-view-status-pending"));
6554 unset_reorderable (GtkIconView *icon_view)
6556 if (icon_view->priv->reorderable)
6558 icon_view->priv->reorderable = FALSE;
6559 g_object_notify (G_OBJECT (icon_view), "reorderable");
6564 set_source_row (GdkDragContext *context,
6565 GtkTreeModel *model,
6566 GtkTreePath *source_row)
6569 g_object_set_data_full (G_OBJECT (context),
6570 I_("gtk-icon-view-source-row"),
6571 gtk_tree_row_reference_new (model, source_row),
6572 (GDestroyNotify) gtk_tree_row_reference_free);
6574 g_object_set_data_full (G_OBJECT (context),
6575 I_("gtk-icon-view-source-row"),
6580 get_source_row (GdkDragContext *context)
6582 GtkTreeRowReference *ref;
6584 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6587 return gtk_tree_row_reference_get_path (ref);
6594 GtkTreeRowReference *dest_row;
6595 gboolean empty_view_drop;
6596 gboolean drop_append_mode;
6600 dest_row_free (gpointer data)
6602 DestRow *dr = (DestRow *)data;
6604 gtk_tree_row_reference_free (dr->dest_row);
6609 set_dest_row (GdkDragContext *context,
6610 GtkTreeModel *model,
6611 GtkTreePath *dest_row,
6612 gboolean empty_view_drop,
6613 gboolean drop_append_mode)
6619 g_object_set_data_full (G_OBJECT (context),
6620 I_("gtk-icon-view-dest-row"),
6625 dr = g_new0 (DestRow, 1);
6627 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6628 dr->empty_view_drop = empty_view_drop;
6629 dr->drop_append_mode = drop_append_mode;
6630 g_object_set_data_full (G_OBJECT (context),
6631 I_("gtk-icon-view-dest-row"),
6632 dr, (GDestroyNotify) dest_row_free);
6636 get_dest_row (GdkDragContext *context)
6640 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6644 GtkTreePath *path = NULL;
6647 path = gtk_tree_row_reference_get_path (dr->dest_row);
6648 else if (dr->empty_view_drop)
6649 path = gtk_tree_path_new_from_indices (0, -1);
6653 if (path && dr->drop_append_mode)
6654 gtk_tree_path_next (path);
6663 check_model_dnd (GtkTreeModel *model,
6664 GType required_iface,
6665 const gchar *signal)
6667 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6669 g_warning ("You must override the default '%s' handler "
6670 "on GtkIconView when using models that don't support "
6671 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6672 "is to connect to '%s' and call "
6673 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6674 "the default handler from running. Look at the source code "
6675 "for the default handler in gtkiconview.c to get an idea what "
6676 "your handler should do. (gtkiconview.c is in the GTK+ source "
6677 "code.) If you're using GTK+ from a language other than C, "
6678 "there may be a more natural way to override default handlers, e.g. via derivation.",
6679 signal, g_type_name (required_iface), signal);
6687 remove_scroll_timeout (GtkIconView *icon_view)
6689 if (icon_view->priv->scroll_timeout_id != 0)
6691 g_source_remove (icon_view->priv->scroll_timeout_id);
6693 icon_view->priv->scroll_timeout_id = 0;
6698 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6701 gint px, py, x, y, width, height;
6702 gint hoffset, voffset;
6704 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6706 gdk_window_get_pointer (window, &px, &py, NULL);
6707 gdk_window_get_geometry (window, &x, &y, &width, &height);
6709 /* see if we are near the edge. */
6710 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6712 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6714 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6716 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6719 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6720 icon_view->priv->vadjustment->value + voffset);
6723 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6724 icon_view->priv->hadjustment->value + hoffset);
6729 drag_scroll_timeout (gpointer data)
6731 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6733 gtk_icon_view_autoscroll (icon_view);
6740 set_destination (GtkIconView *icon_view,
6741 GdkDragContext *context,
6744 GdkDragAction *suggested_action,
6748 GtkTreePath *path = NULL;
6749 GtkIconViewDropPosition pos;
6750 GtkIconViewDropPosition old_pos;
6751 GtkTreePath *old_dest_path = NULL;
6752 gboolean can_drop = FALSE;
6754 widget = GTK_WIDGET (icon_view);
6756 *suggested_action = 0;
6759 if (!icon_view->priv->dest_set)
6761 /* someone unset us as a drag dest, note that if
6762 * we return FALSE drag_leave isn't called
6765 gtk_icon_view_set_drag_dest_item (icon_view,
6767 GTK_ICON_VIEW_DROP_LEFT);
6769 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6771 return FALSE; /* no longer a drop site */
6774 *target = gtk_drag_dest_find_target (widget, context,
6775 gtk_drag_dest_get_target_list (widget));
6776 if (*target == GDK_NONE)
6779 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6782 GtkTreeModel *model;
6784 /* the row got dropped on empty space, let's setup a special case
6788 gtk_tree_path_free (path);
6790 model = gtk_icon_view_get_model (icon_view);
6792 n_children = gtk_tree_model_iter_n_children (model, NULL);
6795 pos = GTK_ICON_VIEW_DROP_BELOW;
6796 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6800 pos = GTK_ICON_VIEW_DROP_ABOVE;
6801 path = gtk_tree_path_new_from_indices (0, -1);
6811 gtk_icon_view_get_drag_dest_item (icon_view,
6816 gtk_tree_path_free (old_dest_path);
6818 if (TRUE /* FIXME if the location droppable predicate */)
6826 GtkWidget *source_widget;
6828 *suggested_action = context->suggested_action;
6829 source_widget = gtk_drag_get_source_widget (context);
6831 if (source_widget == widget)
6833 /* Default to MOVE, unless the user has
6834 * pressed ctrl or shift to affect available actions
6836 if ((context->actions & GDK_ACTION_MOVE) != 0)
6837 *suggested_action = GDK_ACTION_MOVE;
6840 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6845 /* can't drop here */
6846 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6848 GTK_ICON_VIEW_DROP_LEFT);
6852 gtk_tree_path_free (path);
6858 get_logical_destination (GtkIconView *icon_view,
6859 gboolean *drop_append_mode)
6861 /* adjust path to point to the row the drop goes in front of */
6862 GtkTreePath *path = NULL;
6863 GtkIconViewDropPosition pos;
6865 *drop_append_mode = FALSE;
6867 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6872 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6873 pos == GTK_ICON_VIEW_DROP_BELOW)
6876 GtkTreeModel *model = icon_view->priv->model;
6878 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6879 !gtk_tree_model_iter_next (model, &iter))
6880 *drop_append_mode = TRUE;
6883 *drop_append_mode = FALSE;
6884 gtk_tree_path_next (path);
6892 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6893 GdkEventMotion *event)
6895 GtkWidget *widget = GTK_WIDGET (icon_view);
6896 GdkDragContext *context;
6897 GtkTreePath *path = NULL;
6899 GtkTreeModel *model;
6900 gboolean retval = FALSE;
6902 if (!icon_view->priv->source_set)
6905 if (icon_view->priv->pressed_button < 0)
6908 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6909 icon_view->priv->press_start_x,
6910 icon_view->priv->press_start_y,
6911 event->x, event->y))
6914 model = gtk_icon_view_get_model (icon_view);
6919 button = icon_view->priv->pressed_button;
6920 icon_view->priv->pressed_button = -1;
6922 path = gtk_icon_view_get_path_at_pos (icon_view,
6923 icon_view->priv->press_start_x,
6924 icon_view->priv->press_start_y);
6929 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6930 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6934 /* FIXME Check whether we're a start button, if not return FALSE and
6938 /* Now we can begin the drag */
6942 context = gtk_drag_begin (widget,
6943 gtk_drag_source_get_target_list (widget),
6944 icon_view->priv->source_actions,
6948 set_source_row (context, model, path);
6952 gtk_tree_path_free (path);
6957 /* Source side drag signals */
6959 gtk_icon_view_drag_begin (GtkWidget *widget,
6960 GdkDragContext *context)
6962 GtkIconView *icon_view;
6963 GtkIconViewItem *item;
6964 cairo_surface_t *icon;
6968 icon_view = GTK_ICON_VIEW (widget);
6970 /* if the user uses a custom DnD impl, we don't set the icon here */
6971 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6974 item = gtk_icon_view_get_item_at_coords (icon_view,
6975 icon_view->priv->press_start_x,
6976 icon_view->priv->press_start_y,
6980 g_return_if_fail (item != NULL);
6982 x = icon_view->priv->press_start_x - item->x + 1;
6983 y = icon_view->priv->press_start_y - item->y + 1;
6985 path = gtk_tree_path_new_from_indices (item->index, -1);
6986 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6987 gtk_tree_path_free (path);
6989 cairo_surface_set_device_offset (icon, -x, -y);
6991 gtk_drag_set_icon_surface (context, icon);
6993 cairo_surface_destroy (icon);
6997 gtk_icon_view_drag_end (GtkWidget *widget,
6998 GdkDragContext *context)
7004 gtk_icon_view_drag_data_get (GtkWidget *widget,
7005 GdkDragContext *context,
7006 GtkSelectionData *selection_data,
7010 GtkIconView *icon_view;
7011 GtkTreeModel *model;
7012 GtkTreePath *source_row;
7014 icon_view = GTK_ICON_VIEW (widget);
7015 model = gtk_icon_view_get_model (icon_view);
7020 if (!icon_view->priv->source_set)
7023 source_row = get_source_row (context);
7025 if (source_row == NULL)
7028 /* We can implement the GTK_TREE_MODEL_ROW target generically for
7029 * any model; for DragSource models there are some other targets
7033 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
7034 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
7039 /* If drag_data_get does nothing, try providing row data. */
7040 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7041 gtk_tree_set_row_drag_data (selection_data,
7046 gtk_tree_path_free (source_row);
7050 gtk_icon_view_drag_data_delete (GtkWidget *widget,
7051 GdkDragContext *context)
7053 GtkTreeModel *model;
7054 GtkIconView *icon_view;
7055 GtkTreePath *source_row;
7057 icon_view = GTK_ICON_VIEW (widget);
7058 model = gtk_icon_view_get_model (icon_view);
7060 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
7063 if (!icon_view->priv->source_set)
7066 source_row = get_source_row (context);
7068 if (source_row == NULL)
7071 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
7074 gtk_tree_path_free (source_row);
7076 set_source_row (context, NULL, NULL);
7079 /* Target side drag signals */
7081 gtk_icon_view_drag_leave (GtkWidget *widget,
7082 GdkDragContext *context,
7085 GtkIconView *icon_view;
7087 icon_view = GTK_ICON_VIEW (widget);
7089 /* unset any highlight row */
7090 gtk_icon_view_set_drag_dest_item (icon_view,
7092 GTK_ICON_VIEW_DROP_LEFT);
7094 remove_scroll_timeout (icon_view);
7098 gtk_icon_view_drag_motion (GtkWidget *widget,
7099 GdkDragContext *context,
7104 GtkTreePath *path = NULL;
7105 GtkIconViewDropPosition pos;
7106 GtkIconView *icon_view;
7107 GdkDragAction suggested_action = 0;
7111 icon_view = GTK_ICON_VIEW (widget);
7113 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7116 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7118 /* we only know this *after* set_desination_row */
7119 empty = icon_view->priv->empty_view_drop;
7121 if (path == NULL && !empty)
7123 /* Can't drop here. */
7124 gdk_drag_status (context, 0, time);
7128 if (icon_view->priv->scroll_timeout_id == 0)
7130 icon_view->priv->scroll_timeout_id =
7131 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7134 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7136 /* Request data so we can use the source row when
7137 * determining whether to accept the drop
7139 set_status_pending (context, suggested_action);
7140 gtk_drag_get_data (widget, context, target, time);
7144 set_status_pending (context, 0);
7145 gdk_drag_status (context, suggested_action, time);
7150 gtk_tree_path_free (path);
7156 gtk_icon_view_drag_drop (GtkWidget *widget,
7157 GdkDragContext *context,
7162 GtkIconView *icon_view;
7164 GdkDragAction suggested_action = 0;
7165 GdkAtom target = GDK_NONE;
7166 GtkTreeModel *model;
7167 gboolean drop_append_mode;
7169 icon_view = GTK_ICON_VIEW (widget);
7170 model = gtk_icon_view_get_model (icon_view);
7172 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7174 if (!icon_view->priv->dest_set)
7177 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7180 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7183 path = get_logical_destination (icon_view, &drop_append_mode);
7185 if (target != GDK_NONE && path != NULL)
7187 /* in case a motion had requested drag data, change things so we
7188 * treat drag data receives as a drop.
7190 set_status_pending (context, 0);
7191 set_dest_row (context, model, path,
7192 icon_view->priv->empty_view_drop, drop_append_mode);
7196 gtk_tree_path_free (path);
7198 /* Unset this thing */
7199 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7201 if (target != GDK_NONE)
7203 gtk_drag_get_data (widget, context, target, time);
7211 gtk_icon_view_drag_data_received (GtkWidget *widget,
7212 GdkDragContext *context,
7215 GtkSelectionData *selection_data,
7220 gboolean accepted = FALSE;
7221 GtkTreeModel *model;
7222 GtkIconView *icon_view;
7223 GtkTreePath *dest_row;
7224 GdkDragAction suggested_action;
7225 gboolean drop_append_mode;
7227 icon_view = GTK_ICON_VIEW (widget);
7228 model = gtk_icon_view_get_model (icon_view);
7230 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7233 if (!icon_view->priv->dest_set)
7236 suggested_action = get_status_pending (context);
7238 if (suggested_action)
7240 /* We are getting this data due to a request in drag_motion,
7241 * rather than due to a request in drag_drop, so we are just
7242 * supposed to call drag_status, not actually paste in the
7245 path = get_logical_destination (icon_view, &drop_append_mode);
7248 suggested_action = 0;
7250 if (suggested_action)
7252 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7255 suggested_action = 0;
7258 gdk_drag_status (context, suggested_action, time);
7261 gtk_tree_path_free (path);
7263 /* If you can't drop, remove user drop indicator until the next motion */
7264 if (suggested_action == 0)
7265 gtk_icon_view_set_drag_dest_item (icon_view,
7267 GTK_ICON_VIEW_DROP_LEFT);
7272 dest_row = get_dest_row (context);
7274 if (dest_row == NULL)
7277 if (selection_data->length >= 0)
7279 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7285 gtk_drag_finish (context,
7287 (context->action == GDK_ACTION_MOVE),
7290 gtk_tree_path_free (dest_row);
7293 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7296 /* Drag-and-Drop support */
7298 * gtk_icon_view_enable_model_drag_source:
7299 * @icon_view: a #GtkIconTreeView
7300 * @start_button_mask: Mask of allowed buttons to start drag
7301 * @targets: the table of targets that the drag will support
7302 * @n_targets: the number of items in @targets
7303 * @actions: the bitmask of possible actions for a drag from this
7306 * Turns @icon_view into a drag source for automatic DND. Calling this
7307 * method sets #GtkIconView:reorderable to %FALSE.
7312 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7313 GdkModifierType start_button_mask,
7314 const GtkTargetEntry *targets,
7316 GdkDragAction actions)
7318 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7320 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7322 icon_view->priv->start_button_mask = start_button_mask;
7323 icon_view->priv->source_actions = actions;
7325 icon_view->priv->source_set = TRUE;
7327 unset_reorderable (icon_view);
7331 * gtk_icon_view_enable_model_drag_dest:
7332 * @icon_view: a #GtkIconView
7333 * @targets: the table of targets that the drag will support
7334 * @n_targets: the number of items in @targets
7335 * @actions: the bitmask of possible actions for a drag to this
7338 * Turns @icon_view into a drop destination for automatic DND. Calling this
7339 * method sets #GtkIconView:reorderable to %FALSE.
7344 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7345 const GtkTargetEntry *targets,
7347 GdkDragAction actions)
7349 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7351 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7353 icon_view->priv->dest_actions = actions;
7355 icon_view->priv->dest_set = TRUE;
7357 unset_reorderable (icon_view);
7361 * gtk_icon_view_unset_model_drag_source:
7362 * @icon_view: a #GtkIconView
7364 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7365 * method sets #GtkIconView:reorderable to %FALSE.
7370 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7372 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7374 if (icon_view->priv->source_set)
7376 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7377 icon_view->priv->source_set = FALSE;
7380 unset_reorderable (icon_view);
7384 * gtk_icon_view_unset_model_drag_dest:
7385 * @icon_view: a #GtkIconView
7387 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7388 * method sets #GtkIconView:reorderable to %FALSE.
7393 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7395 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7397 if (icon_view->priv->dest_set)
7399 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7400 icon_view->priv->dest_set = FALSE;
7403 unset_reorderable (icon_view);
7406 /* These are useful to implement your own custom stuff. */
7408 * gtk_icon_view_set_drag_dest_item:
7409 * @icon_view: a #GtkIconView
7410 * @path: (allow-none): The path of the item to highlight, or %NULL.
7411 * @pos: Specifies where to drop, relative to the item
7413 * Sets the item that is highlighted for feedback.
7418 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7420 GtkIconViewDropPosition pos)
7422 /* Note; this function is exported to allow a custom DND
7423 * implementation, so it can't touch TreeViewDragInfo
7426 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7428 if (icon_view->priv->dest_item)
7430 GtkTreePath *current_path;
7431 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7432 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7433 icon_view->priv->dest_item = NULL;
7435 gtk_icon_view_queue_draw_path (icon_view, current_path);
7436 gtk_tree_path_free (current_path);
7439 /* special case a drop on an empty model */
7440 icon_view->priv->empty_view_drop = FALSE;
7441 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7442 && gtk_tree_path_get_depth (path) == 1
7443 && gtk_tree_path_get_indices (path)[0] == 0)
7447 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7450 if (n_children == 0)
7451 icon_view->priv->empty_view_drop = TRUE;
7454 icon_view->priv->dest_pos = pos;
7458 icon_view->priv->dest_item =
7459 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7460 icon_view->priv->model, path);
7462 gtk_icon_view_queue_draw_path (icon_view, path);
7467 * gtk_icon_view_get_drag_dest_item:
7468 * @icon_view: a #GtkIconView
7469 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7470 * @pos: (allow-none): Return location for the drop position, or %NULL
7472 * Gets information about the item that is highlighted for feedback.
7477 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7479 GtkIconViewDropPosition *pos)
7481 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7485 if (icon_view->priv->dest_item)
7486 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7492 *pos = icon_view->priv->dest_pos;
7496 * gtk_icon_view_get_dest_item_at_pos:
7497 * @icon_view: a #GtkIconView
7498 * @drag_x: the position to determine the destination item for
7499 * @drag_y: the position to determine the destination item for
7500 * @path: (allow-none): Return location for the path of the item, or %NULL.
7501 * @pos: (allow-none): Return location for the drop position, or %NULL
7503 * Determines the destination item for a given position.
7505 * Return value: whether there is an item at the given position.
7510 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7514 GtkIconViewDropPosition *pos)
7516 GtkIconViewItem *item;
7518 /* Note; this function is exported to allow a custom DND
7519 * implementation, so it can't touch TreeViewDragInfo
7522 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7523 g_return_val_if_fail (drag_x >= 0, FALSE);
7524 g_return_val_if_fail (drag_y >= 0, FALSE);
7525 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7531 item = gtk_icon_view_get_item_at_coords (icon_view,
7532 drag_x + icon_view->priv->hadjustment->value,
7533 drag_y + icon_view->priv->vadjustment->value,
7540 *path = gtk_tree_path_new_from_indices (item->index, -1);
7544 if (drag_x < item->x + item->width / 4)
7545 *pos = GTK_ICON_VIEW_DROP_LEFT;
7546 else if (drag_x > item->x + item->width * 3 / 4)
7547 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7548 else if (drag_y < item->y + item->height / 4)
7549 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7550 else if (drag_y > item->y + item->height * 3 / 4)
7551 *pos = GTK_ICON_VIEW_DROP_BELOW;
7553 *pos = GTK_ICON_VIEW_DROP_INTO;
7560 * gtk_icon_view_create_drag_icon:
7561 * @icon_view: a #GtkIconView
7562 * @path: a #GtkTreePath in @icon_view
7564 * Creates a #cairo_surface_t representation of the item at @path.
7565 * This image is used for a drag icon.
7567 * Return value: (transfer full) a newly-allocated surface of the drag icon.
7572 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7577 cairo_surface_t *surface;
7581 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7582 g_return_val_if_fail (path != NULL, NULL);
7584 widget = GTK_WIDGET (icon_view);
7586 if (!gtk_widget_get_realized (widget))
7589 index = gtk_tree_path_get_indices (path)[0];
7591 for (l = icon_view->priv->items; l; l = l->next)
7593 GtkIconViewItem *item = l->data;
7595 if (index == item->index)
7597 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7598 CAIRO_CONTENT_COLOR,
7602 cr = cairo_create (surface);
7603 cairo_set_line_width (cr, 1.);
7605 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
7606 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7611 cairo_rectangle (cr, 0, 0, item->width, item->height);
7614 gtk_icon_view_paint_item (icon_view, cr, item, 1, 1, FALSE);
7618 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7619 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7632 * gtk_icon_view_get_reorderable:
7633 * @icon_view: a #GtkIconView
7635 * Retrieves whether the user can reorder the list via drag-and-drop.
7636 * See gtk_icon_view_set_reorderable().
7638 * Return value: %TRUE if the list can be reordered.
7643 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7645 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7647 return icon_view->priv->reorderable;
7650 static const GtkTargetEntry item_targets[] = {
7651 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7656 * gtk_icon_view_set_reorderable:
7657 * @icon_view: A #GtkIconView.
7658 * @reorderable: %TRUE, if the list of items can be reordered.
7660 * This function is a convenience function to allow you to reorder models that
7661 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7662 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7663 * the user can reorder the model by dragging and dropping rows. The
7664 * developer can listen to these changes by connecting to the model's
7665 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7666 * the icon view as a drag source and destination. Therefore, drag and
7667 * drop can not be used in a reorderable view for any other purpose.
7669 * This function does not give you any degree of control over the order -- any
7670 * reordering is allowed. If more control is needed, you should probably
7671 * handle drag and drop manually.
7676 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7677 gboolean reorderable)
7679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7681 reorderable = reorderable != FALSE;
7683 if (icon_view->priv->reorderable == reorderable)
7688 gtk_icon_view_enable_model_drag_source (icon_view,
7691 G_N_ELEMENTS (item_targets),
7693 gtk_icon_view_enable_model_drag_dest (icon_view,
7695 G_N_ELEMENTS (item_targets),
7700 gtk_icon_view_unset_model_drag_source (icon_view);
7701 gtk_icon_view_unset_model_drag_dest (icon_view);
7704 icon_view->priv->reorderable = reorderable;
7706 g_object_notify (G_OBJECT (icon_view), "reorderable");
7710 /* Accessibility Support */
7712 static gpointer accessible_parent_class;
7713 static gpointer accessible_item_parent_class;
7714 static GQuark accessible_private_data_quark = 0;
7716 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7717 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7718 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7720 static GType gtk_icon_view_item_accessible_get_type (void);
7731 GtkIconViewItem *item;
7735 AtkStateSet *state_set;
7739 GtkTextBuffer *text_buffer;
7741 gchar *action_descriptions[LAST_ACTION];
7742 gchar *image_description;
7743 guint action_idle_handler;
7744 } GtkIconViewItemAccessible;
7746 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7752 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7757 typedef struct _GtkIconViewItemAccessibleClass
7759 AtkObjectClass parent_class;
7761 } GtkIconViewItemAccessibleClass;
7763 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7766 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7768 GtkIconViewItemAccessible *item;
7769 GtkIconView *icon_view;
7772 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7773 item->action_idle_handler = 0;
7775 if (item->widget != NULL)
7777 icon_view = GTK_ICON_VIEW (item->widget);
7778 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7779 gtk_icon_view_item_activated (icon_view, path);
7780 gtk_tree_path_free (path);
7787 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7790 GtkIconViewItemAccessible *item;
7792 if (i < 0 || i >= LAST_ACTION)
7795 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7797 if (!GTK_IS_ICON_VIEW (item->widget))
7800 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7805 case ACTION_ACTIVATE:
7806 if (!item->action_idle_handler)
7807 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7810 g_assert_not_reached ();
7818 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7823 static const gchar *
7824 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7827 GtkIconViewItemAccessible *item;
7829 if (i < 0 || i >= LAST_ACTION)
7832 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7834 if (item->action_descriptions[i])
7835 return item->action_descriptions[i];
7837 return gtk_icon_view_item_accessible_action_descriptions[i];
7840 static const gchar *
7841 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7844 if (i < 0 || i >= LAST_ACTION)
7847 return gtk_icon_view_item_accessible_action_names[i];
7851 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7853 const gchar *description)
7855 GtkIconViewItemAccessible *item;
7857 if (i < 0 || i >= LAST_ACTION)
7860 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7862 g_free (item->action_descriptions[i]);
7864 item->action_descriptions[i] = g_strdup (description);
7870 atk_action_item_interface_init (AtkActionIface *iface)
7872 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7873 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7874 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7875 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7876 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7879 static const gchar *
7880 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7882 GtkIconViewItemAccessible *item;
7884 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7886 return item->image_description;
7890 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7891 const gchar *description)
7893 GtkIconViewItemAccessible *item;
7895 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7897 g_free (item->image_description);
7898 item->image_description = g_strdup (description);
7904 get_pixbuf_box (GtkIconView *icon_view,
7905 GtkIconViewItem *item,
7910 for (l = icon_view->priv->cell_list; l; l = l->next)
7912 GtkIconViewCellInfo *info = l->data;
7914 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7916 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7926 get_text (GtkIconView *icon_view,
7927 GtkIconViewItem *item)
7932 for (l = icon_view->priv->cell_list; l; l = l->next)
7934 GtkIconViewCellInfo *info = l->data;
7936 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7938 g_object_get (info->cell, "text", &text, NULL);
7948 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7952 GtkIconViewItemAccessible *item;
7955 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7957 if (!GTK_IS_ICON_VIEW (item->widget))
7960 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7963 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7966 *height = box.height;
7971 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7974 AtkCoordType coord_type)
7976 GtkIconViewItemAccessible *item;
7979 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7981 if (!GTK_IS_ICON_VIEW (item->widget))
7984 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7987 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7989 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7991 *x+= box.x - item->item->x;
7992 *y+= box.y - item->item->y;
7998 atk_image_item_interface_init (AtkImageIface *iface)
8000 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
8001 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
8002 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
8003 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
8007 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
8011 GtkIconViewItemAccessible *item;
8012 GtkTextIter start, end;
8013 GtkTextBuffer *buffer;
8015 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8017 if (!GTK_IS_ICON_VIEW (item->widget))
8020 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8023 buffer = item->text_buffer;
8024 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
8026 gtk_text_buffer_get_end_iter (buffer, &end);
8028 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
8030 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8034 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
8037 GtkIconViewItemAccessible *item;
8038 GtkTextIter start, end;
8039 GtkTextBuffer *buffer;
8043 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8045 if (!GTK_IS_ICON_VIEW (item->widget))
8048 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8051 buffer = item->text_buffer;
8052 if (offset >= gtk_text_buffer_get_char_count (buffer))
8055 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8057 gtk_text_iter_forward_char (&end);
8058 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
8059 unichar = g_utf8_get_char (string);
8067 get_pango_text_offsets (PangoLayout *layout,
8068 GtkTextBuffer *buffer,
8070 AtkTextBoundary boundary_type,
8074 GtkTextIter *start_iter,
8075 GtkTextIter *end_iter)
8077 PangoLayoutIter *iter;
8078 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
8079 gint index, start_index, end_index;
8081 gboolean found = FALSE;
8083 text = pango_layout_get_text (layout);
8084 index = g_utf8_offset_to_pointer (text, offset) - text;
8085 iter = pango_layout_get_iter (layout);
8088 line = pango_layout_iter_get_line_readonly (iter);
8089 start_index = line->start_index;
8090 end_index = start_index + line->length;
8092 if (index >= start_index && index <= end_index)
8095 * Found line for offset
8101 * We want the previous line
8105 switch (boundary_type)
8107 case ATK_TEXT_BOUNDARY_LINE_START:
8108 end_index = start_index;
8109 start_index = prev_line->start_index;
8111 case ATK_TEXT_BOUNDARY_LINE_END:
8113 start_index = prev_prev_line->start_index +
8114 prev_prev_line->length;
8115 end_index = prev_line->start_index + prev_line->length;
8118 g_assert_not_reached();
8122 start_index = end_index = 0;
8125 switch (boundary_type)
8127 case ATK_TEXT_BOUNDARY_LINE_START:
8128 if (pango_layout_iter_next_line (iter))
8129 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8131 case ATK_TEXT_BOUNDARY_LINE_END:
8133 start_index = prev_line->start_index +
8137 g_assert_not_reached();
8142 * We want the next line
8144 if (pango_layout_iter_next_line (iter))
8146 line = pango_layout_iter_get_line_readonly (iter);
8147 switch (boundary_type)
8149 case ATK_TEXT_BOUNDARY_LINE_START:
8150 start_index = line->start_index;
8151 if (pango_layout_iter_next_line (iter))
8152 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8154 end_index = start_index + line->length;
8156 case ATK_TEXT_BOUNDARY_LINE_END:
8157 start_index = end_index;
8158 end_index = line->start_index + line->length;
8161 g_assert_not_reached();
8165 start_index = end_index;
8171 prev_prev_line = prev_line;
8174 while (pango_layout_iter_next_line (iter));
8178 start_index = prev_line->start_index + prev_line->length;
8179 end_index = start_index;
8181 pango_layout_iter_free (iter);
8182 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8183 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8185 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8186 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8191 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8193 AtkTextBoundary boundary_type,
8197 GtkIconViewItemAccessible *item;
8198 GtkTextIter start, end;
8199 GtkTextBuffer *buffer;
8201 GtkIconView *icon_view;
8204 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8206 if (!GTK_IS_ICON_VIEW (item->widget))
8209 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8212 buffer = item->text_buffer;
8214 if (!gtk_text_buffer_get_char_count (buffer))
8218 return g_strdup ("");
8220 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8224 switch (boundary_type)
8226 case ATK_TEXT_BOUNDARY_CHAR:
8227 gtk_text_iter_backward_char(&start);
8229 case ATK_TEXT_BOUNDARY_WORD_START:
8230 if (!gtk_text_iter_starts_word (&start))
8231 gtk_text_iter_backward_word_start (&start);
8233 gtk_text_iter_backward_word_start(&start);
8235 case ATK_TEXT_BOUNDARY_WORD_END:
8236 if (gtk_text_iter_inside_word (&start) &&
8237 !gtk_text_iter_starts_word (&start))
8238 gtk_text_iter_backward_word_start (&start);
8239 while (!gtk_text_iter_ends_word (&start))
8241 if (!gtk_text_iter_backward_char (&start))
8245 gtk_text_iter_backward_word_start(&start);
8246 while (!gtk_text_iter_ends_word (&start))
8248 if (!gtk_text_iter_backward_char (&start))
8252 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8253 if (!gtk_text_iter_starts_sentence (&start))
8254 gtk_text_iter_backward_sentence_start (&start);
8256 gtk_text_iter_backward_sentence_start (&start);
8258 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8259 if (gtk_text_iter_inside_sentence (&start) &&
8260 !gtk_text_iter_starts_sentence (&start))
8261 gtk_text_iter_backward_sentence_start (&start);
8262 while (!gtk_text_iter_ends_sentence (&start))
8264 if (!gtk_text_iter_backward_char (&start))
8268 gtk_text_iter_backward_sentence_start (&start);
8269 while (!gtk_text_iter_ends_sentence (&start))
8271 if (!gtk_text_iter_backward_char (&start))
8275 case ATK_TEXT_BOUNDARY_LINE_START:
8276 case ATK_TEXT_BOUNDARY_LINE_END:
8278 icon_view = GTK_ICON_VIEW (item->widget);
8279 /* FIXME we probably have to use GailTextCell to salvage this */
8280 gtk_icon_view_update_item_text (icon_view, item->item);
8281 get_pango_text_offsets (icon_view->priv->layout,
8294 *start_offset = gtk_text_iter_get_offset (&start);
8295 *end_offset = gtk_text_iter_get_offset (&end);
8297 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8301 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8303 AtkTextBoundary boundary_type,
8307 GtkIconViewItemAccessible *item;
8308 GtkTextIter start, end;
8309 GtkTextBuffer *buffer;
8311 GtkIconView *icon_view;
8314 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8316 if (!GTK_IS_ICON_VIEW (item->widget))
8319 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8322 buffer = item->text_buffer;
8324 if (!gtk_text_buffer_get_char_count (buffer))
8328 return g_strdup ("");
8330 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8334 switch (boundary_type)
8336 case ATK_TEXT_BOUNDARY_CHAR:
8337 gtk_text_iter_forward_char (&end);
8339 case ATK_TEXT_BOUNDARY_WORD_START:
8340 if (!gtk_text_iter_starts_word (&start))
8341 gtk_text_iter_backward_word_start (&start);
8342 if (gtk_text_iter_inside_word (&end))
8343 gtk_text_iter_forward_word_end (&end);
8344 while (!gtk_text_iter_starts_word (&end))
8346 if (!gtk_text_iter_forward_char (&end))
8350 case ATK_TEXT_BOUNDARY_WORD_END:
8351 if (gtk_text_iter_inside_word (&start) &&
8352 !gtk_text_iter_starts_word (&start))
8353 gtk_text_iter_backward_word_start (&start);
8354 while (!gtk_text_iter_ends_word (&start))
8356 if (!gtk_text_iter_backward_char (&start))
8359 gtk_text_iter_forward_word_end (&end);
8361 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8362 if (!gtk_text_iter_starts_sentence (&start))
8363 gtk_text_iter_backward_sentence_start (&start);
8364 if (gtk_text_iter_inside_sentence (&end))
8365 gtk_text_iter_forward_sentence_end (&end);
8366 while (!gtk_text_iter_starts_sentence (&end))
8368 if (!gtk_text_iter_forward_char (&end))
8372 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8373 if (gtk_text_iter_inside_sentence (&start) &&
8374 !gtk_text_iter_starts_sentence (&start))
8375 gtk_text_iter_backward_sentence_start (&start);
8376 while (!gtk_text_iter_ends_sentence (&start))
8378 if (!gtk_text_iter_backward_char (&start))
8381 gtk_text_iter_forward_sentence_end (&end);
8383 case ATK_TEXT_BOUNDARY_LINE_START:
8384 case ATK_TEXT_BOUNDARY_LINE_END:
8386 icon_view = GTK_ICON_VIEW (item->widget);
8387 /* FIXME we probably have to use GailTextCell to salvage this */
8388 gtk_icon_view_update_item_text (icon_view, item->item);
8389 get_pango_text_offsets (icon_view->priv->layout,
8403 *start_offset = gtk_text_iter_get_offset (&start);
8404 *end_offset = gtk_text_iter_get_offset (&end);
8406 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8410 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8412 AtkTextBoundary boundary_type,
8416 GtkIconViewItemAccessible *item;
8417 GtkTextIter start, end;
8418 GtkTextBuffer *buffer;
8420 GtkIconView *icon_view;
8423 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8425 if (!GTK_IS_ICON_VIEW (item->widget))
8428 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8431 buffer = item->text_buffer;
8433 if (!gtk_text_buffer_get_char_count (buffer))
8437 return g_strdup ("");
8439 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8443 switch (boundary_type)
8445 case ATK_TEXT_BOUNDARY_CHAR:
8446 gtk_text_iter_forward_char(&start);
8447 gtk_text_iter_forward_chars(&end, 2);
8449 case ATK_TEXT_BOUNDARY_WORD_START:
8450 if (gtk_text_iter_inside_word (&end))
8451 gtk_text_iter_forward_word_end (&end);
8452 while (!gtk_text_iter_starts_word (&end))
8454 if (!gtk_text_iter_forward_char (&end))
8458 if (!gtk_text_iter_is_end (&end))
8460 gtk_text_iter_forward_word_end (&end);
8461 while (!gtk_text_iter_starts_word (&end))
8463 if (!gtk_text_iter_forward_char (&end))
8468 case ATK_TEXT_BOUNDARY_WORD_END:
8469 gtk_text_iter_forward_word_end (&end);
8471 if (!gtk_text_iter_is_end (&end))
8472 gtk_text_iter_forward_word_end (&end);
8474 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8475 if (gtk_text_iter_inside_sentence (&end))
8476 gtk_text_iter_forward_sentence_end (&end);
8477 while (!gtk_text_iter_starts_sentence (&end))
8479 if (!gtk_text_iter_forward_char (&end))
8483 if (!gtk_text_iter_is_end (&end))
8485 gtk_text_iter_forward_sentence_end (&end);
8486 while (!gtk_text_iter_starts_sentence (&end))
8488 if (!gtk_text_iter_forward_char (&end))
8493 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8494 gtk_text_iter_forward_sentence_end (&end);
8496 if (!gtk_text_iter_is_end (&end))
8497 gtk_text_iter_forward_sentence_end (&end);
8499 case ATK_TEXT_BOUNDARY_LINE_START:
8500 case ATK_TEXT_BOUNDARY_LINE_END:
8502 icon_view = GTK_ICON_VIEW (item->widget);
8503 /* FIXME we probably have to use GailTextCell to salvage this */
8504 gtk_icon_view_update_item_text (icon_view, item->item);
8505 get_pango_text_offsets (icon_view->priv->layout,
8517 *start_offset = gtk_text_iter_get_offset (&start);
8518 *end_offset = gtk_text_iter_get_offset (&end);
8520 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8524 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8526 GtkIconViewItemAccessible *item;
8528 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8530 if (!GTK_IS_ICON_VIEW (item->widget))
8533 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8536 return gtk_text_buffer_get_char_count (item->text_buffer);
8540 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8546 AtkCoordType coord_type)
8548 GtkIconViewItemAccessible *item;
8550 GtkIconView *icon_view;
8551 PangoRectangle char_rect;
8552 const gchar *item_text;
8556 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8558 if (!GTK_IS_ICON_VIEW (item->widget))
8561 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8565 icon_view = GTK_ICON_VIEW (item->widget);
8566 /* FIXME we probably have to use GailTextCell to salvage this */
8567 gtk_icon_view_update_item_text (icon_view, item->item);
8568 item_text = pango_layout_get_text (icon_view->priv->layout);
8569 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8570 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8572 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8573 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8574 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8575 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8576 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8577 *width = char_rect.width / PANGO_SCALE;
8578 *height = char_rect.height / PANGO_SCALE;
8583 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8586 AtkCoordType coord_type)
8588 GtkIconViewItemAccessible *item;
8591 GtkIconView *icon_view;
8592 const gchar *item_text;
8597 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8599 if (!GTK_IS_ICON_VIEW (item->widget))
8602 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8606 icon_view = GTK_ICON_VIEW (item->widget);
8607 /* FIXME we probably have to use GailTextCell to salvage this */
8608 gtk_icon_view_update_item_text (icon_view, item->item);
8609 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8610 x -= l_x + item->item->layout_x - item->item->x;
8611 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8612 y -= l_y + item->item->layout_y - item->item->y;
8613 item_text = pango_layout_get_text (icon_view->priv->layout);
8614 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8625 offset = g_utf8_strlen (item_text, -1);
8627 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8633 atk_text_item_interface_init (AtkTextIface *iface)
8635 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8636 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8637 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8638 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8639 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8640 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8641 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8642 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8646 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8651 AtkCoordType coord_type)
8653 GtkIconViewItemAccessible *item;
8654 AtkObject *parent_obj;
8657 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8659 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8660 if (!GTK_IS_WIDGET (item->widget))
8663 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8666 *width = item->item->width;
8667 *height = item->item->height;
8668 if (gtk_icon_view_item_accessible_is_showing (item))
8670 parent_obj = gtk_widget_get_accessible (item->widget);
8671 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8672 *x = l_x + item->item->x;
8673 *y = l_y + item->item->y;
8683 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8685 GtkIconViewItemAccessible *item;
8686 GtkWidget *toplevel;
8688 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8690 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8691 if (!GTK_IS_WIDGET (item->widget))
8694 gtk_widget_grab_focus (item->widget);
8695 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8696 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8697 if (gtk_widget_is_toplevel (toplevel))
8698 gtk_window_present (GTK_WINDOW (toplevel));
8704 atk_component_item_interface_init (AtkComponentIface *iface)
8706 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8707 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8711 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8712 AtkStateType state_type,
8713 gboolean emit_signal)
8717 rc = atk_state_set_add_state (item->state_set, state_type);
8719 * The signal should only be generated if the value changed,
8720 * not when the item is set up. So states that are set
8721 * initially should pass FALSE as the emit_signal argument.
8726 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8727 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8728 if (state_type == ATK_STATE_VISIBLE)
8729 g_signal_emit_by_name (item, "visible-data-changed");
8736 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8737 AtkStateType state_type,
8738 gboolean emit_signal)
8740 if (atk_state_set_contains_state (item->state_set, state_type))
8744 rc = atk_state_set_remove_state (item->state_set, state_type);
8746 * The signal should only be generated if the value changed,
8747 * not when the item is set up. So states that are set
8748 * initially should pass FALSE as the emit_signal argument.
8753 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8754 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8755 if (state_type == ATK_STATE_VISIBLE)
8756 g_signal_emit_by_name (item, "visible-data-changed");
8766 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8768 GtkAllocation allocation;
8769 GtkIconView *icon_view;
8770 GdkRectangle visible_rect;
8771 gboolean is_showing;
8774 * An item is considered "SHOWING" if any part of the item is in the
8775 * visible rectangle.
8778 if (!GTK_IS_ICON_VIEW (item->widget))
8781 if (item->item == NULL)
8784 gtk_widget_get_allocation (item->widget, &allocation);
8786 icon_view = GTK_ICON_VIEW (item->widget);
8788 if (icon_view->priv->hadjustment)
8789 visible_rect.x += icon_view->priv->hadjustment->value;
8791 if (icon_view->priv->hadjustment)
8792 visible_rect.y += icon_view->priv->vadjustment->value;
8793 visible_rect.width = allocation.width;
8794 visible_rect.height = allocation.height;
8796 if (((item->item->x + item->item->width) < visible_rect.x) ||
8797 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8798 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8799 (item->item->y > (visible_rect.y + visible_rect.height)))
8808 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8809 gboolean emit_signal)
8811 if (gtk_icon_view_item_accessible_is_showing (item))
8812 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8815 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8820 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8824 item->state_set = atk_state_set_new ();
8826 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8827 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8828 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8829 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8830 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8832 for (i = 0; i < LAST_ACTION; i++)
8833 item->action_descriptions[i] = NULL;
8835 item->image_description = NULL;
8837 item->action_idle_handler = 0;
8841 gtk_icon_view_item_accessible_finalize (GObject *object)
8843 GtkIconViewItemAccessible *item;
8846 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8848 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8851 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8853 if (item->state_set)
8854 g_object_unref (item->state_set);
8856 if (item->text_buffer)
8857 g_object_unref (item->text_buffer);
8859 for (i = 0; i < LAST_ACTION; i++)
8860 g_free (item->action_descriptions[i]);
8862 g_free (item->image_description);
8864 if (item->action_idle_handler)
8866 g_source_remove (item->action_idle_handler);
8867 item->action_idle_handler = 0;
8870 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8873 static G_CONST_RETURN gchar*
8874 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8880 GtkIconViewItemAccessible *item;
8881 GtkTextIter start_iter;
8882 GtkTextIter end_iter;
8884 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8886 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8887 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8889 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8894 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8896 GtkIconViewItemAccessible *item;
8898 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8899 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8902 return gtk_widget_get_accessible (item->widget);
8908 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8910 GtkIconViewItemAccessible *item;
8912 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8913 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8915 return item->item->index;
8918 static AtkStateSet *
8919 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8921 GtkIconViewItemAccessible *item;
8922 GtkIconView *icon_view;
8924 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8925 g_return_val_if_fail (item->state_set, NULL);
8930 icon_view = GTK_ICON_VIEW (item->widget);
8931 if (icon_view->priv->cursor_item == item->item)
8932 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8934 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8935 if (item->item->selected)
8936 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8938 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8940 return g_object_ref (item->state_set);
8944 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8946 GObjectClass *gobject_class;
8948 accessible_item_parent_class = g_type_class_peek_parent (klass);
8950 gobject_class = (GObjectClass *)klass;
8952 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8954 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8955 klass->get_name = gtk_icon_view_item_accessible_get_name;
8956 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8957 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8961 gtk_icon_view_item_accessible_get_type (void)
8963 static GType type = 0;
8967 const GTypeInfo tinfo =
8969 sizeof (GtkIconViewItemAccessibleClass),
8970 (GBaseInitFunc) NULL, /* base init */
8971 (GBaseFinalizeFunc) NULL, /* base finalize */
8972 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8973 (GClassFinalizeFunc) NULL, /* class finalize */
8974 NULL, /* class data */
8975 sizeof (GtkIconViewItemAccessible), /* instance size */
8976 0, /* nb preallocs */
8977 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8978 NULL /* value table */
8981 const GInterfaceInfo atk_component_info =
8983 (GInterfaceInitFunc) atk_component_item_interface_init,
8984 (GInterfaceFinalizeFunc) NULL,
8987 const GInterfaceInfo atk_action_info =
8989 (GInterfaceInitFunc) atk_action_item_interface_init,
8990 (GInterfaceFinalizeFunc) NULL,
8993 const GInterfaceInfo atk_image_info =
8995 (GInterfaceInitFunc) atk_image_item_interface_init,
8996 (GInterfaceFinalizeFunc) NULL,
8999 const GInterfaceInfo atk_text_info =
9001 (GInterfaceInitFunc) atk_text_item_interface_init,
9002 (GInterfaceFinalizeFunc) NULL,
9006 type = g_type_register_static (ATK_TYPE_OBJECT,
9007 I_("GtkIconViewItemAccessible"), &tinfo, 0);
9008 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9009 &atk_component_info);
9010 g_type_add_interface_static (type, ATK_TYPE_ACTION,
9012 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
9014 g_type_add_interface_static (type, ATK_TYPE_TEXT,
9021 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
9022 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
9023 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
9025 static GType gtk_icon_view_accessible_get_type (void);
9030 } GtkIconViewAccessible;
9036 } GtkIconViewItemAccessibleInfo;
9042 GtkAdjustment *old_hadj;
9043 GtkAdjustment *old_vadj;
9045 GtkTreeModel *model;
9047 } GtkIconViewAccessiblePrivate;
9049 static GtkIconViewAccessiblePrivate *
9050 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
9052 return g_object_get_qdata (G_OBJECT (accessible),
9053 accessible_private_data_quark);
9057 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
9061 GtkIconViewItemAccessibleInfo *info;
9062 GtkIconViewItemAccessibleInfo *tmp_info;
9063 GtkIconViewAccessiblePrivate *priv;
9066 info = g_new (GtkIconViewItemAccessibleInfo, 1);
9068 info->index = index;
9070 priv = gtk_icon_view_accessible_get_priv (accessible);
9071 items = priv->items;
9074 tmp_info = items->data;
9075 if (tmp_info->index > index)
9077 items = items->next;
9079 priv->items = g_list_insert_before (priv->items, items, info);
9080 priv->old_hadj = NULL;
9081 priv->old_vadj = NULL;
9085 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
9087 GtkIconView *icon_view;
9090 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9094 icon_view = GTK_ICON_VIEW (widget);
9096 return g_list_length (icon_view->priv->items);
9100 gtk_icon_view_accessible_find_child (AtkObject *accessible,
9103 GtkIconViewAccessiblePrivate *priv;
9104 GtkIconViewItemAccessibleInfo *info;
9107 priv = gtk_icon_view_accessible_get_priv (accessible);
9108 items = priv->items;
9113 if (info->index == index)
9115 items = items->next;
9121 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9124 GtkIconView *icon_view;
9128 GtkIconViewItemAccessible *a11y_item;
9130 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9134 icon_view = GTK_ICON_VIEW (widget);
9135 icons = g_list_nth (icon_view->priv->items, index);
9139 GtkIconViewItem *item = icons->data;
9141 g_return_val_if_fail (item->index == index, NULL);
9142 obj = gtk_icon_view_accessible_find_child (accessible, index);
9147 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9148 gtk_icon_view_item_accessible_info_new (accessible,
9151 obj->role = ATK_ROLE_ICON;
9152 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9153 a11y_item->item = item;
9154 a11y_item->widget = widget;
9155 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9157 gtk_icon_view_set_cell_data (icon_view, item);
9158 text = get_text (icon_view, item);
9161 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9165 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9166 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9174 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9177 GtkIconViewAccessiblePrivate *priv;
9178 GtkIconViewItemAccessibleInfo *info;
9179 GtkIconViewItemAccessible *item;
9182 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9186 gboolean act_on_item;
9188 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9192 items = priv->items;
9194 act_on_item = (list == NULL);
9199 info = (GtkIconViewItemAccessibleInfo *)items->data;
9200 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9202 if (act_on_item == FALSE && list == items)
9206 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9208 items = items->next;
9214 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9215 GtkIconViewAccessible *view)
9217 gtk_icon_view_accessible_traverse_items (view, NULL);
9221 gtk_icon_view_accessible_set_adjustment (AtkObject *accessible,
9222 GtkOrientation orientation,
9223 GtkAdjustment *adjustment)
9225 GtkIconViewAccessiblePrivate *priv;
9226 GtkAdjustment **old_adj_ptr;
9228 priv = gtk_icon_view_accessible_get_priv (accessible);
9230 /* Adjustments are set for the first time in constructor and priv is not
9231 * initialized at that time, so skip this first setting. */
9235 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9237 if (priv->old_hadj == adjustment)
9240 old_adj_ptr = &priv->old_hadj;
9244 if (priv->old_vadj == adjustment)
9247 old_adj_ptr = &priv->old_vadj;
9250 /* Disconnect signal handlers */
9253 g_object_remove_weak_pointer (G_OBJECT (*old_adj_ptr),
9254 (gpointer *)&priv->old_hadj);
9255 g_signal_handlers_disconnect_by_func (*old_adj_ptr,
9256 gtk_icon_view_accessible_adjustment_changed,
9260 /* Connect signal */
9261 *old_adj_ptr = adjustment;
9262 g_object_add_weak_pointer (G_OBJECT (adjustment), (gpointer *)old_adj_ptr);
9263 g_signal_connect (adjustment, "value-changed",
9264 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9269 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9277 GtkIconView *icon_view;
9278 GtkIconViewItem *item;
9279 GtkIconViewAccessible *a11y_view;
9280 GtkIconViewItemAccessible *a11y_item;
9284 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9285 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9286 index = gtk_tree_path_get_indices(path)[0];
9287 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9288 gtk_icon_view_accessible_find_child (atk_obj, index));
9292 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9293 icon_view = GTK_ICON_VIEW (widget);
9294 item = a11y_item->item;
9296 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9298 if (!name || strcmp (name, "") == 0)
9300 gtk_icon_view_set_cell_data (icon_view, item);
9301 text = get_text (icon_view, item);
9304 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9310 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9316 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9321 GtkIconViewAccessiblePrivate *priv;
9322 GtkIconViewItemAccessibleInfo *info;
9323 GtkIconViewAccessible *view;
9324 GtkIconViewItemAccessible *item;
9330 index = gtk_tree_path_get_indices(path)[0];
9331 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9332 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9333 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9335 items = priv->items;
9340 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9341 if (info->index != item->item->index)
9343 if (info->index < index)
9344 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9346 if (tmp_list == NULL)
9349 info->index = item->item->index;
9352 items = items->next;
9354 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9355 g_signal_emit_by_name (atk_obj, "children-changed::add",
9361 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9365 GtkIconViewAccessiblePrivate *priv;
9366 GtkIconViewItemAccessibleInfo *info;
9367 GtkIconViewAccessible *view;
9368 GtkIconViewItemAccessible *item;
9371 GList *deleted_item;
9375 index = gtk_tree_path_get_indices(path)[0];
9376 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9377 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9378 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9380 items = priv->items;
9382 deleted_item = NULL;
9387 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9388 if (info->index == index)
9390 deleted_item = items;
9392 if (info->index != item->item->index)
9394 if (tmp_list == NULL)
9397 info->index = item->item->index;
9400 items = items->next;
9402 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9405 info = deleted_item->data;
9406 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9407 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9409 priv->items = g_list_remove_link (priv->items, deleted_item);
9417 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9418 GtkIconViewItemAccessibleInfo *i2)
9420 return i1->index - i2->index;
9424 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9430 GtkIconViewAccessiblePrivate *priv;
9431 GtkIconViewItemAccessibleInfo *info;
9432 GtkIconView *icon_view;
9433 GtkIconViewItemAccessible *item;
9439 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9440 icon_view = GTK_ICON_VIEW (user_data);
9441 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9443 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9445 order = g_new (gint, length);
9446 for (i = 0; i < length; i++)
9447 order [new_order[i]] = i;
9449 items = priv->items;
9453 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9454 info->index = order[info->index];
9455 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9456 items = items->next;
9459 priv->items = g_list_sort (priv->items,
9460 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9466 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9471 obj = G_OBJECT (model);
9472 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9473 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9474 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9475 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9479 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9483 obj = G_OBJECT (icon_view->priv->model);
9484 g_signal_connect_data (obj, "row-changed",
9485 (GCallback) gtk_icon_view_accessible_model_row_changed,
9486 icon_view, NULL, 0);
9487 g_signal_connect_data (obj, "row-inserted",
9488 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9489 icon_view, NULL, G_CONNECT_AFTER);
9490 g_signal_connect_data (obj, "row-deleted",
9491 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9492 icon_view, NULL, G_CONNECT_AFTER);
9493 g_signal_connect_data (obj, "rows-reordered",
9494 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9495 icon_view, NULL, G_CONNECT_AFTER);
9499 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9501 GtkIconViewItemAccessibleInfo *info;
9504 items = priv->items;
9507 info = (GtkIconViewItemAccessibleInfo *) items->data;
9508 g_object_unref (info->item);
9509 g_free (items->data);
9510 items = items->next;
9512 g_list_free (priv->items);
9517 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9520 GtkIconView *icon_view;
9523 GtkIconViewAccessiblePrivate *priv;
9525 if (strcmp (pspec->name, "model") == 0)
9527 widget = GTK_WIDGET (obj);
9528 atk_obj = gtk_widget_get_accessible (widget);
9529 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9532 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9533 (gpointer *)&priv->model);
9534 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9536 gtk_icon_view_accessible_clear_cache (priv);
9538 icon_view = GTK_ICON_VIEW (obj);
9539 priv->model = icon_view->priv->model;
9540 /* If there is no model the GtkIconView is probably being destroyed */
9543 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9544 gtk_icon_view_accessible_connect_model_signals (icon_view);
9552 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9555 GtkIconViewAccessiblePrivate *priv;
9556 GtkIconView *icon_view;
9558 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9559 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9561 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9562 g_object_set_qdata (G_OBJECT (accessible),
9563 accessible_private_data_quark,
9566 icon_view = GTK_ICON_VIEW (data);
9567 if (icon_view->priv->hadjustment)
9568 gtk_icon_view_accessible_set_adjustment (accessible,
9569 GTK_ORIENTATION_HORIZONTAL,
9570 icon_view->priv->hadjustment);
9571 if (icon_view->priv->vadjustment)
9572 gtk_icon_view_accessible_set_adjustment (accessible,
9573 GTK_ORIENTATION_VERTICAL,
9574 icon_view->priv->vadjustment);
9575 g_signal_connect (data,
9577 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9580 priv->model = icon_view->priv->model;
9583 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9584 gtk_icon_view_accessible_connect_model_signals (icon_view);
9587 accessible->role = ATK_ROLE_LAYERED_PANE;
9591 gtk_icon_view_accessible_finalize (GObject *object)
9593 GtkIconViewAccessiblePrivate *priv;
9595 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9596 gtk_icon_view_accessible_clear_cache (priv);
9600 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9604 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9605 GtkAccessible *accessible)
9608 GtkIconViewAccessiblePrivate *priv;
9610 atk_obj = ATK_OBJECT (accessible);
9611 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9614 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9615 (gpointer *)&priv->old_hadj);
9617 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9618 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9620 priv->old_hadj = NULL;
9624 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9625 (gpointer *)&priv->old_vadj);
9627 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9628 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9630 priv->old_vadj = NULL;
9635 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9639 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9642 g_signal_connect_after (widget,
9644 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9647 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9651 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9653 GObjectClass *gobject_class;
9654 GtkAccessibleClass *accessible_class;
9656 accessible_parent_class = g_type_class_peek_parent (klass);
9658 gobject_class = (GObjectClass *)klass;
9659 accessible_class = (GtkAccessibleClass *)klass;
9661 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9663 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9664 klass->ref_child = gtk_icon_view_accessible_ref_child;
9665 klass->initialize = gtk_icon_view_accessible_initialize;
9667 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9669 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9673 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9676 AtkCoordType coord_type)
9679 GtkIconView *icon_view;
9680 GtkIconViewItem *item;
9683 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9685 /* State is defunct */
9688 icon_view = GTK_ICON_VIEW (widget);
9689 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9690 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9692 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9698 atk_component_interface_init (AtkComponentIface *iface)
9700 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9704 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9708 GtkIconView *icon_view;
9709 GtkIconViewItem *item;
9711 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9715 icon_view = GTK_ICON_VIEW (widget);
9717 item = g_list_nth_data (icon_view->priv->items, i);
9722 gtk_icon_view_select_item (icon_view, item);
9728 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9731 GtkIconView *icon_view;
9733 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9737 icon_view = GTK_ICON_VIEW (widget);
9738 gtk_icon_view_unselect_all (icon_view);
9744 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9749 GtkIconView *icon_view;
9750 GtkIconViewItem *item;
9752 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9756 icon_view = GTK_ICON_VIEW (widget);
9758 l = icon_view->priv->items;
9765 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9776 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9779 GtkIconView *icon_view;
9780 GtkIconViewItem *item;
9784 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9788 icon_view = GTK_ICON_VIEW (widget);
9790 l = icon_view->priv->items;
9806 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9810 GtkIconView *icon_view;
9811 GtkIconViewItem *item;
9813 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9817 icon_view = GTK_ICON_VIEW (widget);
9819 item = g_list_nth_data (icon_view->priv->items, i);
9823 return item->selected;
9827 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9831 GtkIconView *icon_view;
9832 GtkIconViewItem *item;
9836 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9840 icon_view = GTK_ICON_VIEW (widget);
9841 l = icon_view->priv->items;
9850 gtk_icon_view_unselect_item (icon_view, item);
9862 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9865 GtkIconView *icon_view;
9867 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9871 icon_view = GTK_ICON_VIEW (widget);
9872 gtk_icon_view_select_all (icon_view);
9877 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9879 iface->add_selection = gtk_icon_view_accessible_add_selection;
9880 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9881 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9882 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9883 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9884 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9885 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9889 gtk_icon_view_accessible_get_type (void)
9891 static GType type = 0;
9898 (GBaseInitFunc) NULL, /* base init */
9899 (GBaseFinalizeFunc) NULL, /* base finalize */
9900 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9901 (GClassFinalizeFunc) NULL, /* class finalize */
9902 NULL, /* class data */
9903 0, /* instance size */
9904 0, /* nb preallocs */
9905 (GInstanceInitFunc) NULL, /* instance init */
9906 NULL /* value table */
9908 const GInterfaceInfo atk_component_info =
9910 (GInterfaceInitFunc) atk_component_interface_init,
9911 (GInterfaceFinalizeFunc) NULL,
9914 const GInterfaceInfo atk_selection_info =
9916 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9917 (GInterfaceFinalizeFunc) NULL,
9922 * Figure out the size of the class and instance
9923 * we are deriving from
9925 AtkObjectFactory *factory;
9928 GType derived_atk_type;
9930 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9931 factory = atk_registry_get_factory (atk_get_default_registry (),
9933 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9934 g_type_query (derived_atk_type, &query);
9935 tinfo.class_size = query.class_size;
9936 tinfo.instance_size = query.instance_size;
9938 type = g_type_register_static (derived_atk_type,
9939 I_("GtkIconViewAccessible"),
9941 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9942 &atk_component_info);
9943 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9944 &atk_selection_info);
9950 gtk_icon_view_accessible_new (GObject *obj)
9952 AtkObject *accessible;
9954 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9956 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9957 atk_object_initialize (accessible, obj);
9963 gtk_icon_view_accessible_factory_get_accessible_type (void)
9965 return gtk_icon_view_accessible_get_type ();
9969 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9971 return gtk_icon_view_accessible_new (obj);
9975 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9977 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9978 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9982 gtk_icon_view_accessible_factory_get_type (void)
9984 static GType type = 0;
9988 const GTypeInfo tinfo =
9990 sizeof (AtkObjectFactoryClass),
9991 NULL, /* base_init */
9992 NULL, /* base_finalize */
9993 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9994 NULL, /* class_finalize */
9995 NULL, /* class_data */
9996 sizeof (AtkObjectFactory),
9997 0, /* n_preallocs */
10001 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
10002 I_("GtkIconViewAccessibleFactory"),
10010 gtk_icon_view_get_accessible (GtkWidget *widget)
10012 static gboolean first_time = TRUE;
10016 AtkObjectFactory *factory;
10017 AtkRegistry *registry;
10018 GType derived_type;
10019 GType derived_atk_type;
10022 * Figure out whether accessibility is enabled by looking at the
10023 * type of the accessible object which would be created for
10024 * the parent type of GtkIconView.
10026 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
10028 registry = atk_get_default_registry ();
10029 factory = atk_registry_get_factory (registry,
10031 derived_atk_type = atk_object_factory_get_accessible_type (factory);
10032 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
10033 atk_registry_set_factory_type (registry,
10034 GTK_TYPE_ICON_VIEW,
10035 gtk_icon_view_accessible_factory_get_type ());
10036 first_time = FALSE;
10038 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
10042 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
10043 GtkBuilder *builder,
10045 const gchar *tagname,
10046 GMarkupParser *parser,
10049 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
10050 tagname, parser, data))
10053 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
10054 tagname, parser, data);
10058 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
10059 GtkBuilder *builder,
10061 const gchar *tagname,
10064 if (strcmp (tagname, "attributes") == 0)
10065 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
10068 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,