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 "gtkcellsizerequest.h"
33 #include "gtkmarshalers.h"
34 #include "gtkbindings.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.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 list model.
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.
60 #define SCROLL_EDGE_SIZE 15
62 typedef struct _GtkIconViewItem GtkIconViewItem;
63 struct _GtkIconViewItem
71 gint x, y, width, height;
74 * box[i] is the actual area occupied by cell i,
75 * before, after are used to calculate the cell
76 * area relative to the box.
77 * See gtk_icon_view_get_cell_area().
85 guint selected_before_rubberbanding : 1;
89 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
90 struct _GtkIconViewCellInfo
92 GtkCellRenderer *cell;
102 GtkCellLayoutDataFunc func;
104 GDestroyNotify destroy;
107 typedef struct _GtkIconViewChild GtkIconViewChild;
108 struct _GtkIconViewChild
111 GtkIconViewItem *item;
115 struct _GtkIconViewPrivate
119 GtkSelectionMode selection_mode;
121 GdkWindow *bin_window;
129 GtkAdjustment *hadjustment;
130 GtkAdjustment *vadjustment;
132 guint layout_idle_id;
134 gboolean doing_rubberband;
135 gint rubberband_x1, rubberband_y1;
136 gint rubberband_x2, rubberband_y2;
137 GdkDevice *rubberband_device;
139 guint scroll_timeout_id;
140 gint scroll_value_diff;
141 gint event_last_x, event_last_y;
143 GtkIconViewItem *anchor_item;
144 GtkIconViewItem *cursor_item;
145 GtkIconViewItem *edited_item;
146 GtkCellEditable *editable;
148 GtkIconViewItem *last_single_clicked;
155 GtkOrientation item_orientation;
175 GdkModifierType start_button_mask;
180 GdkDragAction source_actions;
181 GdkDragAction dest_actions;
183 GtkTreeRowReference *dest_item;
184 GtkIconViewDropPosition dest_pos;
187 GtkTreeRowReference *scroll_to_path;
188 gfloat scroll_to_row_align;
189 gfloat scroll_to_col_align;
190 guint scroll_to_use_align : 1;
192 guint source_set : 1;
194 guint reorderable : 1;
195 guint empty_view_drop :1;
197 guint ctrl_pressed : 1;
198 guint shift_pressed : 1;
200 guint draw_focus : 1;
213 ACTIVATE_CURSOR_ITEM,
225 PROP_ITEM_ORIENTATION,
239 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
240 static void gtk_icon_view_finalize (GObject *object);
241 static void gtk_icon_view_set_property (GObject *object,
245 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkObject vfuncs */
251 static void gtk_icon_view_destroy (GtkObject *object);
253 /* GtkWidget vfuncs */
254 static void gtk_icon_view_realize (GtkWidget *widget);
255 static void gtk_icon_view_unrealize (GtkWidget *widget);
256 static void gtk_icon_view_style_set (GtkWidget *widget,
257 GtkStyle *previous_style);
258 static void gtk_icon_view_state_changed (GtkWidget *widget,
259 GtkStateType previous_state);
260 static void gtk_icon_view_size_request (GtkWidget *widget,
261 GtkRequisition *requisition);
262 static void gtk_icon_view_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static gboolean gtk_icon_view_draw (GtkWidget *widget,
266 static gboolean gtk_icon_view_motion (GtkWidget *widget,
267 GdkEventMotion *event);
268 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
274 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
276 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
279 /* GtkContainer vfuncs */
280 static void gtk_icon_view_remove (GtkContainer *container,
282 static void gtk_icon_view_forall (GtkContainer *container,
283 gboolean include_internals,
284 GtkCallback callback,
285 gpointer callback_data);
287 /* GtkIconView vfuncs */
288 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
290 GtkAdjustment *vadj);
291 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
292 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
293 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
294 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
295 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
297 /* Internal functions */
298 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
299 GtkIconView *icon_view);
300 static void gtk_icon_view_layout (GtkIconView *icon_view);
301 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
303 GtkIconViewItem *item,
306 gboolean draw_focus);
307 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
309 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
311 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
312 GtkIconViewItem *item);
313 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
314 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
315 GtkIconViewItem *item,
317 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
321 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
322 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
323 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
324 GtkIconViewItem *item,
329 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
330 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
331 GtkIconViewItem *item);
332 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
333 GtkIconViewItem *item,
335 static void gtk_icon_view_update_rubberband (gpointer data);
336 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
337 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
338 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
341 GtkMovementStep step,
343 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
344 GtkMovementStep step,
346 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
348 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
350 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
352 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
354 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
355 GtkIconViewItem *item);
356 static void gtk_icon_view_select_item (GtkIconView *icon_view,
357 GtkIconViewItem *item);
358 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
359 GtkIconViewItem *item);
360 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
361 GtkIconViewItem *anchor,
362 GtkIconViewItem *cursor);
363 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
366 gboolean only_in_cell,
367 GtkIconViewCellInfo **cell_at_pos);
368 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
369 GtkIconViewItem *item,
370 GtkIconViewCellInfo *cell_info,
371 GdkRectangle *cell_area);
372 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
373 GtkIconViewItem *item,
374 GtkIconViewCellInfo *info,
376 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
377 GtkCellRenderer *renderer);
378 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
379 GtkIconViewItem *item);
380 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
381 GtkCellRenderer *renderer,
383 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
384 GtkCellRenderer *renderer,
386 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
387 GtkCellRenderer *renderer,
388 const gchar *attribute,
390 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
391 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
392 GtkCellRenderer *renderer);
393 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
394 GtkCellRenderer *cell,
395 GtkCellLayoutDataFunc func,
397 GDestroyNotify destroy);
398 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
399 GtkCellRenderer *cell,
401 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
403 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
404 GtkIconViewItem *item,
405 GtkIconViewCellInfo *cell_info,
407 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
408 GtkIconViewItem *item);
409 static void gtk_icon_view_put (GtkIconView *icon_view,
411 GtkIconViewItem *item,
413 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
414 GtkIconView *icon_view);
415 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
416 GtkIconViewItem *item,
417 GtkIconViewCellInfo *cell_info,
419 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
420 gboolean cancel_editing);
422 /* Source side drag signals */
423 static void gtk_icon_view_drag_begin (GtkWidget *widget,
424 GdkDragContext *context);
425 static void gtk_icon_view_drag_end (GtkWidget *widget,
426 GdkDragContext *context);
427 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
428 GdkDragContext *context,
429 GtkSelectionData *selection_data,
432 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
433 GdkDragContext *context);
435 /* Target side drag signals */
436 static void gtk_icon_view_drag_leave (GtkWidget *widget,
437 GdkDragContext *context,
439 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
440 GdkDragContext *context,
444 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
445 GdkDragContext *context,
449 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
450 GdkDragContext *context,
453 GtkSelectionData *selection_data,
456 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
457 GdkEventMotion *event);
459 static void remove_scroll_timeout (GtkIconView *icon_view);
461 static void adjust_wrap_width (GtkIconView *icon_view,
462 GtkIconViewItem *item);
465 static GtkBuildableIface *parent_buildable_iface;
466 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
467 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
470 const gchar *tagname,
471 GMarkupParser *parser,
473 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
476 const gchar *tagname,
479 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
481 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
482 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
483 gtk_icon_view_cell_layout_init)
484 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
485 gtk_icon_view_buildable_init))
488 gtk_icon_view_class_init (GtkIconViewClass *klass)
490 GObjectClass *gobject_class;
491 GtkObjectClass *object_class;
492 GtkWidgetClass *widget_class;
493 GtkContainerClass *container_class;
494 GtkBindingSet *binding_set;
496 binding_set = gtk_binding_set_by_class (klass);
498 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
500 gobject_class = (GObjectClass *) klass;
501 object_class = (GtkObjectClass *) klass;
502 widget_class = (GtkWidgetClass *) klass;
503 container_class = (GtkContainerClass *) klass;
505 gobject_class->finalize = gtk_icon_view_finalize;
506 gobject_class->set_property = gtk_icon_view_set_property;
507 gobject_class->get_property = gtk_icon_view_get_property;
509 object_class->destroy = gtk_icon_view_destroy;
511 widget_class->realize = gtk_icon_view_realize;
512 widget_class->unrealize = gtk_icon_view_unrealize;
513 widget_class->style_set = gtk_icon_view_style_set;
514 widget_class->get_accessible = gtk_icon_view_get_accessible;
515 widget_class->size_request = gtk_icon_view_size_request;
516 widget_class->size_allocate = gtk_icon_view_size_allocate;
517 widget_class->draw = gtk_icon_view_draw;
518 widget_class->motion_notify_event = gtk_icon_view_motion;
519 widget_class->button_press_event = gtk_icon_view_button_press;
520 widget_class->button_release_event = gtk_icon_view_button_release;
521 widget_class->key_press_event = gtk_icon_view_key_press;
522 widget_class->key_release_event = gtk_icon_view_key_release;
523 widget_class->drag_begin = gtk_icon_view_drag_begin;
524 widget_class->drag_end = gtk_icon_view_drag_end;
525 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
526 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
527 widget_class->drag_leave = gtk_icon_view_drag_leave;
528 widget_class->drag_motion = gtk_icon_view_drag_motion;
529 widget_class->drag_drop = gtk_icon_view_drag_drop;
530 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
531 widget_class->state_changed = gtk_icon_view_state_changed;
533 container_class->remove = gtk_icon_view_remove;
534 container_class->forall = gtk_icon_view_forall;
536 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
537 klass->select_all = gtk_icon_view_real_select_all;
538 klass->unselect_all = gtk_icon_view_real_unselect_all;
539 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
540 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
541 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
542 klass->move_cursor = gtk_icon_view_real_move_cursor;
546 * GtkIconView:selection-mode:
548 * The ::selection-mode property specifies the selection mode of
549 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
550 * is enabled, for the other modes, only keyboard selection is possible.
554 g_object_class_install_property (gobject_class,
556 g_param_spec_enum ("selection-mode",
557 P_("Selection mode"),
558 P_("The selection mode"),
559 GTK_TYPE_SELECTION_MODE,
560 GTK_SELECTION_SINGLE,
561 GTK_PARAM_READWRITE));
564 * GtkIconView:pixbuf-column:
566 * The ::pixbuf-column property contains the number of the model column
567 * containing the pixbufs which are displayed. The pixbuf column must be
568 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
569 * display of pixbufs.
573 g_object_class_install_property (gobject_class,
575 g_param_spec_int ("pixbuf-column",
577 P_("Model column used to retrieve the icon pixbuf from"),
579 GTK_PARAM_READWRITE));
582 * GtkIconView:text-column:
584 * The ::text-column property contains the number of the model column
585 * containing the texts which are displayed. The text column must be
586 * of type #G_TYPE_STRING. If this property and the :markup-column
587 * property are both set to -1, no texts are displayed.
591 g_object_class_install_property (gobject_class,
593 g_param_spec_int ("text-column",
595 P_("Model column used to retrieve the text from"),
597 GTK_PARAM_READWRITE));
601 * GtkIconView:markup-column:
603 * The ::markup-column property contains the number of the model column
604 * containing markup information to be displayed. The markup column must be
605 * of type #G_TYPE_STRING. If this property and the :text-column property
606 * are both set to column numbers, it overrides the text column.
607 * If both are set to -1, no texts are displayed.
611 g_object_class_install_property (gobject_class,
613 g_param_spec_int ("markup-column",
615 P_("Model column used to retrieve the text if using Pango markup"),
617 GTK_PARAM_READWRITE));
619 g_object_class_install_property (gobject_class,
621 g_param_spec_object ("model",
622 P_("Icon View Model"),
623 P_("The model for the icon view"),
625 GTK_PARAM_READWRITE));
628 * GtkIconView:columns:
630 * The columns property contains the number of the columns in which the
631 * items should be displayed. If it is -1, the number of columns will
632 * be chosen automatically to fill the available area.
636 g_object_class_install_property (gobject_class,
638 g_param_spec_int ("columns",
639 P_("Number of columns"),
640 P_("Number of columns to display"),
642 GTK_PARAM_READWRITE));
646 * GtkIconView:item-width:
648 * The item-width property specifies the width to use for each item.
649 * If it is set to -1, the icon view will automatically determine a
650 * suitable item size.
654 g_object_class_install_property (gobject_class,
656 g_param_spec_int ("item-width",
657 P_("Width for each item"),
658 P_("The width used for each item"),
660 GTK_PARAM_READWRITE));
663 * GtkIconView:spacing:
665 * The spacing property specifies the space which is inserted between
666 * the cells (i.e. the icon and the text) of an item.
670 g_object_class_install_property (gobject_class,
672 g_param_spec_int ("spacing",
674 P_("Space which is inserted between cells of an item"),
676 GTK_PARAM_READWRITE));
679 * GtkIconView:row-spacing:
681 * The row-spacing property specifies the space which is inserted between
682 * the rows of the icon view.
686 g_object_class_install_property (gobject_class,
688 g_param_spec_int ("row-spacing",
690 P_("Space which is inserted between grid rows"),
692 GTK_PARAM_READWRITE));
695 * GtkIconView:column-spacing:
697 * The column-spacing property specifies the space which is inserted between
698 * the columns of the icon view.
702 g_object_class_install_property (gobject_class,
704 g_param_spec_int ("column-spacing",
705 P_("Column Spacing"),
706 P_("Space which is inserted between grid columns"),
708 GTK_PARAM_READWRITE));
711 * GtkIconView:margin:
713 * The margin property specifies the space which is inserted
714 * at the edges of the icon view.
718 g_object_class_install_property (gobject_class,
720 g_param_spec_int ("margin",
722 P_("Space which is inserted at the edges of the icon view"),
724 GTK_PARAM_READWRITE));
727 * GtkIconView:item-orientation:
729 * The item-orientation property specifies how the cells (i.e. the icon and
730 * the text) of the item are positioned relative to each other.
734 g_object_class_install_property (gobject_class,
735 PROP_ITEM_ORIENTATION,
736 g_param_spec_enum ("item-orientation",
737 P_("Item Orientation"),
738 P_("How the text and icon of each item are positioned relative to each other"),
739 GTK_TYPE_ORIENTATION,
740 GTK_ORIENTATION_VERTICAL,
741 GTK_PARAM_READWRITE));
744 * GtkIconView:reorderable:
746 * The reorderable property specifies if the items can be reordered
751 g_object_class_install_property (gobject_class,
753 g_param_spec_boolean ("reorderable",
755 P_("View is reorderable"),
759 g_object_class_install_property (gobject_class,
761 g_param_spec_int ("tooltip-column",
762 P_("Tooltip Column"),
763 P_("The column in the model containing the tooltip texts for the items"),
767 GTK_PARAM_READWRITE));
770 * GtkIconView:item-padding:
772 * The item-padding property specifies the padding around each
773 * of the icon view's item.
777 g_object_class_install_property (gobject_class,
779 g_param_spec_int ("item-padding",
781 P_("Padding around icon view items"),
783 GTK_PARAM_READWRITE));
787 /* Style properties */
788 gtk_widget_class_install_style_property (widget_class,
789 g_param_spec_boxed ("selection-box-color",
790 P_("Selection Box Color"),
791 P_("Color of the selection box"),
793 GTK_PARAM_READABLE));
795 gtk_widget_class_install_style_property (widget_class,
796 g_param_spec_uchar ("selection-box-alpha",
797 P_("Selection Box Alpha"),
798 P_("Opacity of the selection box"),
801 GTK_PARAM_READABLE));
805 * GtkIconView::set-scroll-adjustments
806 * @horizontal: the horizontal #GtkAdjustment
807 * @vertical: the vertical #GtkAdjustment
809 * Set the scroll adjustments for the icon view. Usually scrolled containers
810 * like #GtkScrolledWindow will emit this signal to connect two instances
811 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
813 widget_class->set_scroll_adjustments_signal =
814 g_signal_new (I_("set-scroll-adjustments"),
815 G_TYPE_FROM_CLASS (gobject_class),
817 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
819 _gtk_marshal_VOID__OBJECT_OBJECT,
821 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
824 * GtkIconView::item-activated:
825 * @iconview: the object on which the signal is emitted
826 * @path: the #GtkTreePath for the activated item
828 * The ::item-activated signal is emitted when the method
829 * gtk_icon_view_item_activated() is called or the user double
830 * clicks an item. It is also emitted when a non-editable item
831 * is selected and one of the keys: Space, Return or Enter is
834 icon_view_signals[ITEM_ACTIVATED] =
835 g_signal_new (I_("item-activated"),
836 G_TYPE_FROM_CLASS (gobject_class),
838 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
840 g_cclosure_marshal_VOID__BOXED,
845 * GtkIconView::selection-changed:
846 * @iconview: the object on which the signal is emitted
848 * The ::selection-changed signal is emitted when the selection
849 * (i.e. the set of selected items) changes.
851 icon_view_signals[SELECTION_CHANGED] =
852 g_signal_new (I_("selection-changed"),
853 G_TYPE_FROM_CLASS (gobject_class),
855 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
857 g_cclosure_marshal_VOID__VOID,
861 * GtkIconView::select-all:
862 * @iconview: the object on which the signal is emitted
864 * A <link linkend="keybinding-signals">keybinding signal</link>
865 * which gets emitted when the user selects all items.
867 * Applications should not connect to it, but may emit it with
868 * g_signal_emit_by_name() if they need to control selection
871 * The default binding for this signal is Ctrl-a.
873 icon_view_signals[SELECT_ALL] =
874 g_signal_new (I_("select-all"),
875 G_TYPE_FROM_CLASS (gobject_class),
876 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
877 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
879 g_cclosure_marshal_VOID__VOID,
883 * GtkIconView::unselect-all:
884 * @iconview: the object on which the signal is emitted
886 * A <link linkend="keybinding-signals">keybinding signal</link>
887 * which gets emitted when the user unselects all items.
889 * Applications should not connect to it, but may emit it with
890 * g_signal_emit_by_name() if they need to control selection
893 * The default binding for this signal is Ctrl-Shift-a.
895 icon_view_signals[UNSELECT_ALL] =
896 g_signal_new (I_("unselect-all"),
897 G_TYPE_FROM_CLASS (gobject_class),
898 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
899 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
901 g_cclosure_marshal_VOID__VOID,
905 * GtkIconView::select-cursor-item:
906 * @iconview: the object on which the signal is emitted
908 * A <link linkend="keybinding-signals">keybinding signal</link>
909 * which gets emitted when the user selects the item that is currently
912 * Applications should not connect to it, but may emit it with
913 * g_signal_emit_by_name() if they need to control selection
916 * There is no default binding for this signal.
918 icon_view_signals[SELECT_CURSOR_ITEM] =
919 g_signal_new (I_("select-cursor-item"),
920 G_TYPE_FROM_CLASS (gobject_class),
921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
924 g_cclosure_marshal_VOID__VOID,
928 * GtkIconView::toggle-cursor-item:
929 * @iconview: the object on which the signal is emitted
931 * A <link linkend="keybinding-signals">keybinding signal</link>
932 * which gets emitted when the user toggles whether the currently
933 * focused item is selected or not. The exact effect of this
934 * depend on the selection mode.
936 * Applications should not connect to it, but may emit it with
937 * g_signal_emit_by_name() if they need to control selection
940 * There is no default binding for this signal is Ctrl-Space.
942 icon_view_signals[TOGGLE_CURSOR_ITEM] =
943 g_signal_new (I_("toggle-cursor-item"),
944 G_TYPE_FROM_CLASS (gobject_class),
945 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
946 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
948 g_cclosure_marshal_VOID__VOID,
952 * GtkIconView::activate-cursor-item:
953 * @iconview: the object on which the signal is emitted
955 * A <link linkend="keybinding-signals">keybinding signal</link>
956 * which gets emitted when the user activates the currently
959 * Applications should not connect to it, but may emit it with
960 * g_signal_emit_by_name() if they need to control activation
963 * The default bindings for this signal are Space, Return and Enter.
965 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
966 g_signal_new (I_("activate-cursor-item"),
967 G_TYPE_FROM_CLASS (gobject_class),
968 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
969 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
971 _gtk_marshal_BOOLEAN__VOID,
975 * GtkIconView::move-cursor:
976 * @iconview: the object which received the signal
977 * @step: the granularity of the move, as a #GtkMovementStep
978 * @count: the number of @step units to move
980 * The ::move-cursor signal is a
981 * <link linkend="keybinding-signals">keybinding signal</link>
982 * which gets emitted when the user initiates a cursor movement.
984 * Applications should not connect to it, but may emit it with
985 * g_signal_emit_by_name() if they need to control the cursor
988 * The default bindings for this signal include
990 * <listitem>Arrow keys which move by individual steps</listitem>
991 * <listitem>Home/End keys which move to the first/last item</listitem>
992 * <listitem>PageUp/PageDown which move by "pages"</listitem>
995 * All of these will extend the selection when combined with
996 * the Shift modifier.
998 icon_view_signals[MOVE_CURSOR] =
999 g_signal_new (I_("move-cursor"),
1000 G_TYPE_FROM_CLASS (gobject_class),
1001 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1002 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1004 _gtk_marshal_BOOLEAN__ENUM_INT,
1006 GTK_TYPE_MOVEMENT_STEP,
1010 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1012 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1014 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
1015 "toggle-cursor-item", 0);
1016 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
1017 "toggle-cursor-item", 0);
1019 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
1020 "activate-cursor-item", 0);
1021 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
1022 "activate-cursor-item", 0);
1023 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1024 "activate-cursor-item", 0);
1025 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1026 "activate-cursor-item", 0);
1027 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1028 "activate-cursor-item", 0);
1030 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1031 GTK_MOVEMENT_DISPLAY_LINES, -1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1033 GTK_MOVEMENT_DISPLAY_LINES, -1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1036 GTK_MOVEMENT_DISPLAY_LINES, 1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1038 GTK_MOVEMENT_DISPLAY_LINES, 1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1041 GTK_MOVEMENT_DISPLAY_LINES, -1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1044 GTK_MOVEMENT_DISPLAY_LINES, 1);
1046 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1047 GTK_MOVEMENT_BUFFER_ENDS, -1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1049 GTK_MOVEMENT_BUFFER_ENDS, -1);
1051 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1052 GTK_MOVEMENT_BUFFER_ENDS, 1);
1053 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1054 GTK_MOVEMENT_BUFFER_ENDS, 1);
1056 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1057 GTK_MOVEMENT_PAGES, -1);
1058 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1059 GTK_MOVEMENT_PAGES, -1);
1061 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1062 GTK_MOVEMENT_PAGES, 1);
1063 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1064 GTK_MOVEMENT_PAGES, 1);
1066 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1067 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1068 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1069 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1071 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1072 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1073 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1074 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1078 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1080 parent_buildable_iface = g_type_interface_peek_parent (iface);
1081 iface->add_child = _gtk_cell_layout_buildable_add_child;
1082 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1083 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1087 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1089 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1090 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1091 iface->clear = gtk_icon_view_cell_layout_clear;
1092 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1093 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1094 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1095 iface->reorder = gtk_icon_view_cell_layout_reorder;
1096 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1100 gtk_icon_view_init (GtkIconView *icon_view)
1102 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1104 GtkIconViewPrivate);
1106 icon_view->priv->width = 0;
1107 icon_view->priv->height = 0;
1108 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1109 icon_view->priv->pressed_button = -1;
1110 icon_view->priv->press_start_x = -1;
1111 icon_view->priv->press_start_y = -1;
1112 icon_view->priv->text_column = -1;
1113 icon_view->priv->markup_column = -1;
1114 icon_view->priv->pixbuf_column = -1;
1115 icon_view->priv->text_cell = -1;
1116 icon_view->priv->pixbuf_cell = -1;
1117 icon_view->priv->tooltip_column = -1;
1119 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1121 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1123 icon_view->priv->cell_list = NULL;
1124 icon_view->priv->n_cells = 0;
1125 icon_view->priv->cursor_cell = -1;
1127 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1129 icon_view->priv->columns = -1;
1130 icon_view->priv->item_width = -1;
1131 icon_view->priv->spacing = 0;
1132 icon_view->priv->row_spacing = 6;
1133 icon_view->priv->column_spacing = 6;
1134 icon_view->priv->margin = 6;
1135 icon_view->priv->item_padding = 6;
1137 icon_view->priv->draw_focus = TRUE;
1141 gtk_icon_view_destroy (GtkObject *object)
1143 GtkIconView *icon_view;
1145 icon_view = GTK_ICON_VIEW (object);
1147 gtk_icon_view_stop_editing (icon_view, TRUE);
1149 gtk_icon_view_set_model (icon_view, NULL);
1151 if (icon_view->priv->layout_idle_id != 0)
1153 g_source_remove (icon_view->priv->layout_idle_id);
1154 icon_view->priv->layout_idle_id = 0;
1157 if (icon_view->priv->scroll_to_path != NULL)
1159 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1160 icon_view->priv->scroll_to_path = NULL;
1163 remove_scroll_timeout (icon_view);
1165 if (icon_view->priv->hadjustment != NULL)
1167 g_object_unref (icon_view->priv->hadjustment);
1168 icon_view->priv->hadjustment = NULL;
1171 if (icon_view->priv->vadjustment != NULL)
1173 g_object_unref (icon_view->priv->vadjustment);
1174 icon_view->priv->vadjustment = NULL;
1177 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1180 /* GObject methods */
1182 gtk_icon_view_finalize (GObject *object)
1184 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1186 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1191 gtk_icon_view_set_property (GObject *object,
1193 const GValue *value,
1196 GtkIconView *icon_view;
1198 icon_view = GTK_ICON_VIEW (object);
1202 case PROP_SELECTION_MODE:
1203 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1205 case PROP_PIXBUF_COLUMN:
1206 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1208 case PROP_TEXT_COLUMN:
1209 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1211 case PROP_MARKUP_COLUMN:
1212 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1215 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1217 case PROP_ITEM_ORIENTATION:
1218 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1221 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1223 case PROP_ITEM_WIDTH:
1224 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1227 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1229 case PROP_ROW_SPACING:
1230 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1232 case PROP_COLUMN_SPACING:
1233 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1236 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1238 case PROP_REORDERABLE:
1239 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1242 case PROP_TOOLTIP_COLUMN:
1243 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1246 case PROP_ITEM_PADDING:
1247 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1251 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1257 gtk_icon_view_get_property (GObject *object,
1262 GtkIconView *icon_view;
1264 icon_view = GTK_ICON_VIEW (object);
1268 case PROP_SELECTION_MODE:
1269 g_value_set_enum (value, icon_view->priv->selection_mode);
1271 case PROP_PIXBUF_COLUMN:
1272 g_value_set_int (value, icon_view->priv->pixbuf_column);
1274 case PROP_TEXT_COLUMN:
1275 g_value_set_int (value, icon_view->priv->text_column);
1277 case PROP_MARKUP_COLUMN:
1278 g_value_set_int (value, icon_view->priv->markup_column);
1281 g_value_set_object (value, icon_view->priv->model);
1283 case PROP_ITEM_ORIENTATION:
1284 g_value_set_enum (value, icon_view->priv->item_orientation);
1287 g_value_set_int (value, icon_view->priv->columns);
1289 case PROP_ITEM_WIDTH:
1290 g_value_set_int (value, icon_view->priv->item_width);
1293 g_value_set_int (value, icon_view->priv->spacing);
1295 case PROP_ROW_SPACING:
1296 g_value_set_int (value, icon_view->priv->row_spacing);
1298 case PROP_COLUMN_SPACING:
1299 g_value_set_int (value, icon_view->priv->column_spacing);
1302 g_value_set_int (value, icon_view->priv->margin);
1304 case PROP_REORDERABLE:
1305 g_value_set_boolean (value, icon_view->priv->reorderable);
1307 case PROP_TOOLTIP_COLUMN:
1308 g_value_set_int (value, icon_view->priv->tooltip_column);
1311 case PROP_ITEM_PADDING:
1312 g_value_set_int (value, icon_view->priv->item_padding);
1316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1321 /* GtkWidget signals */
1323 gtk_icon_view_realize (GtkWidget *widget)
1325 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1326 GtkAllocation allocation;
1328 GdkWindowAttr attributes;
1329 gint attributes_mask;
1331 gtk_widget_set_realized (widget, TRUE);
1333 gtk_widget_get_allocation (widget, &allocation);
1335 /* Make the main, clipping window */
1336 attributes.window_type = GDK_WINDOW_CHILD;
1337 attributes.x = allocation.x;
1338 attributes.y = allocation.y;
1339 attributes.width = allocation.width;
1340 attributes.height = allocation.height;
1341 attributes.wclass = GDK_INPUT_OUTPUT;
1342 attributes.visual = gtk_widget_get_visual (widget);
1343 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1345 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1347 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1348 &attributes, attributes_mask);
1349 gtk_widget_set_window (widget, window);
1350 gdk_window_set_user_data (window, widget);
1352 gtk_widget_get_allocation (widget, &allocation);
1354 /* Make the window for the icon view */
1357 attributes.width = MAX (icon_view->priv->width, allocation.width);
1358 attributes.height = MAX (icon_view->priv->height, allocation.height);
1359 attributes.event_mask = (GDK_EXPOSURE_MASK |
1361 GDK_POINTER_MOTION_MASK |
1362 GDK_BUTTON_PRESS_MASK |
1363 GDK_BUTTON_RELEASE_MASK |
1364 GDK_KEY_PRESS_MASK |
1365 GDK_KEY_RELEASE_MASK) |
1366 gtk_widget_get_events (widget);
1368 icon_view->priv->bin_window = gdk_window_new (window,
1369 &attributes, attributes_mask);
1370 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1372 gtk_widget_style_attach (widget);
1373 gdk_window_set_background (icon_view->priv->bin_window,
1374 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1376 gdk_window_show (icon_view->priv->bin_window);
1380 gtk_icon_view_unrealize (GtkWidget *widget)
1382 GtkIconView *icon_view;
1384 icon_view = GTK_ICON_VIEW (widget);
1386 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1387 gdk_window_destroy (icon_view->priv->bin_window);
1388 icon_view->priv->bin_window = NULL;
1390 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1394 gtk_icon_view_state_changed (GtkWidget *widget,
1395 GtkStateType previous_state)
1397 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1401 if (gtk_widget_get_realized (widget))
1403 style = gtk_widget_get_style (widget);
1404 state = gtk_widget_get_state (widget);
1406 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1407 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1410 gtk_widget_queue_draw (widget);
1414 gtk_icon_view_style_set (GtkWidget *widget,
1415 GtkStyle *previous_style)
1417 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1421 if (gtk_widget_get_realized (widget))
1423 style = gtk_widget_get_style (widget);
1424 state = gtk_widget_get_state (widget);
1426 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1427 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1430 gtk_widget_queue_resize (widget);
1434 gtk_icon_view_size_request (GtkWidget *widget,
1435 GtkRequisition *requisition)
1437 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1440 requisition->width = icon_view->priv->width;
1441 requisition->height = icon_view->priv->height;
1443 tmp_list = icon_view->priv->children;
1447 GtkIconViewChild *child = tmp_list->data;
1448 GtkRequisition child_requisition;
1450 tmp_list = tmp_list->next;
1452 if (gtk_widget_get_visible (child->widget))
1453 gtk_widget_get_preferred_size (child->widget,
1454 &child_requisition, NULL);
1459 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1463 for (list = icon_view->priv->children; list; list = list->next)
1465 GtkIconViewChild *child = list->data;
1466 GtkAllocation allocation;
1468 /* totally ignore our child's requisition */
1469 if (child->cell < 0)
1471 allocation.x = child->item->x + icon_view->priv->item_padding;
1472 allocation.y = child->item->y + icon_view->priv->item_padding;
1473 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1474 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1478 GdkRectangle *box = &child->item->box[child->cell];
1480 allocation.x = box->x;
1481 allocation.y = box->y;
1482 allocation.width = box->width;
1483 allocation.height = box->height;
1486 gtk_widget_size_allocate (child->widget, &allocation);
1491 gtk_icon_view_size_allocate (GtkWidget *widget,
1492 GtkAllocation *allocation)
1494 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1496 GtkAdjustment *hadjustment, *vadjustment;
1498 gtk_widget_set_allocation (widget, allocation);
1500 if (gtk_widget_get_realized (widget))
1502 gdk_window_move_resize (gtk_widget_get_window (widget),
1503 allocation->x, allocation->y,
1504 allocation->width, allocation->height);
1505 gdk_window_resize (icon_view->priv->bin_window,
1506 MAX (icon_view->priv->width, allocation->width),
1507 MAX (icon_view->priv->height, allocation->height));
1510 gtk_icon_view_layout (icon_view);
1512 gtk_icon_view_allocate_children (icon_view);
1514 hadjustment = icon_view->priv->hadjustment;
1515 vadjustment = icon_view->priv->vadjustment;
1517 hadjustment->page_size = allocation->width;
1518 hadjustment->page_increment = allocation->width * 0.9;
1519 hadjustment->step_increment = allocation->width * 0.1;
1520 hadjustment->lower = 0;
1521 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1523 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1524 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1526 vadjustment->page_size = allocation->height;
1527 vadjustment->page_increment = allocation->height * 0.9;
1528 vadjustment->step_increment = allocation->height * 0.1;
1529 vadjustment->lower = 0;
1530 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1532 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1533 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1535 if (gtk_widget_get_realized (widget) &&
1536 icon_view->priv->scroll_to_path)
1539 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1540 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1541 icon_view->priv->scroll_to_path = NULL;
1543 gtk_icon_view_scroll_to_path (icon_view, path,
1544 icon_view->priv->scroll_to_use_align,
1545 icon_view->priv->scroll_to_row_align,
1546 icon_view->priv->scroll_to_col_align);
1547 gtk_tree_path_free (path);
1551 gtk_adjustment_changed (hadjustment);
1552 gtk_adjustment_changed (vadjustment);
1557 gtk_icon_view_draw (GtkWidget *widget,
1560 GtkIconView *icon_view;
1564 GtkIconViewDropPosition dest_pos;
1565 GtkIconViewItem *dest_item = NULL;
1568 icon_view = GTK_ICON_VIEW (widget);
1570 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1575 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
1576 cairo_translate (cr, x, y);
1578 /* If a layout has been scheduled, do it now so that all
1579 * cell view items have valid sizes before we proceed. */
1580 if (icon_view->priv->layout_idle_id != 0)
1581 gtk_icon_view_layout (icon_view);
1583 cairo_set_line_width (cr, 1.);
1585 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1589 dest_index = gtk_tree_path_get_indices (path)[0];
1590 gtk_tree_path_free (path);
1595 for (icons = icon_view->priv->items; icons; icons = icons->next)
1597 GtkIconViewItem *item = icons->data;
1601 cairo_rectangle (cr, item->x, item->y, item->width, item->height);
1604 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1606 gtk_icon_view_paint_item (icon_view, cr, item,
1608 icon_view->priv->draw_focus);
1610 if (dest_index == item->index)
1622 style = gtk_widget_get_style (widget);
1623 state = gtk_widget_get_state (widget);
1627 case GTK_ICON_VIEW_DROP_INTO:
1628 gtk_paint_focus (style,
1632 "iconview-drop-indicator",
1633 dest_item->x, dest_item->y,
1634 dest_item->width, dest_item->height);
1636 case GTK_ICON_VIEW_DROP_ABOVE:
1637 gtk_paint_focus (style,
1641 "iconview-drop-indicator",
1642 dest_item->x, dest_item->y - 1,
1643 dest_item->width, 2);
1645 case GTK_ICON_VIEW_DROP_LEFT:
1646 gtk_paint_focus (style,
1650 "iconview-drop-indicator",
1651 dest_item->x - 1, dest_item->y,
1652 2, dest_item->height);
1654 case GTK_ICON_VIEW_DROP_BELOW:
1655 gtk_paint_focus (style,
1659 "iconview-drop-indicator",
1660 dest_item->x, dest_item->y + dest_item->height - 1,
1661 dest_item->width, 2);
1663 case GTK_ICON_VIEW_DROP_RIGHT:
1664 gtk_paint_focus (style,
1668 "iconview-drop-indicator",
1669 dest_item->x + dest_item->width - 1, dest_item->y,
1670 2, dest_item->height);
1671 case GTK_ICON_VIEW_NO_DROP: ;
1676 if (icon_view->priv->doing_rubberband)
1677 gtk_icon_view_paint_rubberband (icon_view, cr);
1681 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1687 rubberband_scroll_timeout (gpointer data)
1689 GtkIconView *icon_view = data;
1691 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1692 icon_view->priv->vadjustment->value +
1693 icon_view->priv->scroll_value_diff);
1695 gtk_icon_view_update_rubberband (icon_view);
1701 gtk_icon_view_motion (GtkWidget *widget,
1702 GdkEventMotion *event)
1704 GtkAllocation allocation;
1705 GtkIconView *icon_view;
1708 icon_view = GTK_ICON_VIEW (widget);
1710 gtk_icon_view_maybe_begin_drag (icon_view, event);
1712 if (icon_view->priv->doing_rubberband)
1714 gtk_icon_view_update_rubberband (widget);
1716 abs_y = event->y - icon_view->priv->height *
1717 (icon_view->priv->vadjustment->value /
1718 (icon_view->priv->vadjustment->upper -
1719 icon_view->priv->vadjustment->lower));
1721 gtk_widget_get_allocation (widget, &allocation);
1723 if (abs_y < 0 || abs_y > allocation.height)
1726 icon_view->priv->scroll_value_diff = abs_y;
1728 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1730 icon_view->priv->event_last_x = event->x;
1731 icon_view->priv->event_last_y = event->y;
1733 if (icon_view->priv->scroll_timeout_id == 0)
1734 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1738 remove_scroll_timeout (icon_view);
1745 gtk_icon_view_remove (GtkContainer *container,
1748 GtkIconView *icon_view;
1749 GtkIconViewChild *child = NULL;
1752 icon_view = GTK_ICON_VIEW (container);
1754 tmp_list = icon_view->priv->children;
1757 child = tmp_list->data;
1758 if (child->widget == widget)
1760 gtk_widget_unparent (widget);
1762 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1763 g_list_free_1 (tmp_list);
1768 tmp_list = tmp_list->next;
1773 gtk_icon_view_forall (GtkContainer *container,
1774 gboolean include_internals,
1775 GtkCallback callback,
1776 gpointer callback_data)
1778 GtkIconView *icon_view;
1779 GtkIconViewChild *child = NULL;
1782 icon_view = GTK_ICON_VIEW (container);
1784 tmp_list = icon_view->priv->children;
1787 child = tmp_list->data;
1788 tmp_list = tmp_list->next;
1790 (* callback) (child->widget, callback_data);
1795 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1796 GtkIconViewItem *item,
1797 GtkIconViewCellInfo *info,
1802 GdkRectangle cell_area;
1803 gboolean visible, mode;
1805 gtk_icon_view_set_cell_data (icon_view, item);
1807 g_object_get (info->cell,
1808 "visible", &visible,
1812 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1814 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1816 path = gtk_tree_path_new_from_indices (item->index, -1);
1817 path_string = gtk_tree_path_to_string (path);
1818 gtk_tree_path_free (path);
1820 gtk_cell_renderer_activate (info->cell,
1822 GTK_WIDGET (icon_view),
1828 g_free (path_string);
1833 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1834 GtkIconViewItem *item)
1837 AtkObject *item_obj;
1839 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1842 item_obj = atk_object_ref_accessible_child (obj, item->index);
1843 if (item_obj != NULL)
1845 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1846 g_object_unref (item_obj);
1852 gtk_icon_view_put (GtkIconView *icon_view,
1854 GtkIconViewItem *item,
1857 GtkIconViewChild *child;
1859 child = g_new (GtkIconViewChild, 1);
1861 child->widget = widget;
1865 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1867 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1868 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1870 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1874 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1875 GtkIconView *icon_view)
1878 GtkIconViewItem *item;
1880 if (icon_view->priv->edited_item == NULL)
1883 item = icon_view->priv->edited_item;
1884 icon_view->priv->edited_item = NULL;
1885 icon_view->priv->editable = NULL;
1886 for (l = icon_view->priv->cell_list; l; l = l->next)
1888 GtkIconViewCellInfo *info = l->data;
1890 info->editing = FALSE;
1893 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1894 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1896 g_signal_handlers_disconnect_by_func (editable,
1897 gtk_icon_view_remove_widget,
1900 gtk_container_remove (GTK_CONTAINER (icon_view),
1901 GTK_WIDGET (editable));
1903 gtk_icon_view_queue_draw_item (icon_view, item);
1908 gtk_icon_view_start_editing (GtkIconView *icon_view,
1909 GtkIconViewItem *item,
1910 GtkIconViewCellInfo *info,
1915 GdkRectangle cell_area;
1916 gboolean visible, mode;
1917 GtkCellEditable *editable;
1919 gtk_icon_view_set_cell_data (icon_view, item);
1921 g_object_get (info->cell,
1922 "visible", &visible,
1925 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1927 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1929 path = gtk_tree_path_new_from_indices (item->index, -1);
1930 path_string = gtk_tree_path_to_string (path);
1931 gtk_tree_path_free (path);
1933 editable = gtk_cell_renderer_start_editing (info->cell,
1935 GTK_WIDGET (icon_view),
1940 g_free (path_string);
1942 /* the rest corresponds to tree_view_real_start_editing... */
1943 icon_view->priv->edited_item = item;
1944 icon_view->priv->editable = editable;
1945 info->editing = TRUE;
1947 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1949 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1951 gtk_widget_grab_focus (GTK_WIDGET (editable));
1952 g_signal_connect (editable, "remove-widget",
1953 G_CALLBACK (gtk_icon_view_remove_widget),
1960 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1961 gboolean cancel_editing)
1963 GtkCellRenderer *cell = NULL;
1964 GtkIconViewItem *item;
1967 if (icon_view->priv->edited_item == NULL)
1971 * This is very evil. We need to do this, because
1972 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1973 * later on. If gtk_icon_view_row_changed notices
1974 * icon_view->priv->edited_item != NULL, it'll call
1975 * gtk_icon_view_stop_editing again. Bad things will happen then.
1977 * Please read that again if you intend to modify anything here.
1980 item = icon_view->priv->edited_item;
1981 icon_view->priv->edited_item = NULL;
1983 for (l = icon_view->priv->cell_list; l; l = l->next)
1985 GtkIconViewCellInfo *info = l->data;
1997 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1998 if (!cancel_editing)
1999 gtk_cell_editable_editing_done (icon_view->priv->editable);
2001 icon_view->priv->edited_item = item;
2003 gtk_cell_editable_remove_widget (icon_view->priv->editable);
2007 * gtk_icon_view_set_cursor:
2008 * @icon_view: A #GtkIconView
2009 * @path: A #GtkTreePath
2010 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2011 * @start_editing: %TRUE if the specified cell should start being edited.
2013 * Sets the current keyboard focus to be at @path, and selects it. This is
2014 * useful when you want to focus the user's attention on a particular item.
2015 * If @cell is not %NULL, then focus is given to the cell specified by
2016 * it. Additionally, if @start_editing is %TRUE, then editing should be
2017 * started in the specified cell.
2019 * This function is often followed by <literal>gtk_widget_grab_focus
2020 * (icon_view)</literal> in order to give keyboard focus to the widget.
2021 * Please note that editing can only happen when the widget is realized.
2026 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2028 GtkCellRenderer *cell,
2029 gboolean start_editing)
2031 GtkIconViewItem *item = NULL;
2032 GtkIconViewCellInfo *info = NULL;
2036 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2037 g_return_if_fail (path != NULL);
2038 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2040 gtk_icon_view_stop_editing (icon_view, TRUE);
2042 if (gtk_tree_path_get_depth (path) == 1)
2043 item = g_list_nth_data (icon_view->priv->items,
2044 gtk_tree_path_get_indices(path)[0]);
2050 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2054 if (info->cell == cell)
2063 g_return_if_fail (cell == NULL || info != NULL);
2065 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2066 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2068 if (info && start_editing)
2069 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2073 * gtk_icon_view_get_cursor:
2074 * @icon_view: A #GtkIconView
2075 * @path: (allow-none): Return location for the current cursor path, or %NULL
2076 * @cell: (allow-none): Return location the current focus cell, or %NULL
2078 * Fills in @path and @cell with the current cursor path and cell.
2079 * If the cursor isn't currently set, then *@path will be %NULL.
2080 * If no cell currently has focus, then *@cell will be %NULL.
2082 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2084 * Return value: %TRUE if the cursor is set.
2089 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2091 GtkCellRenderer **cell)
2093 GtkIconViewItem *item;
2094 GtkIconViewCellInfo *info;
2096 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2098 item = icon_view->priv->cursor_item;
2099 if (icon_view->priv->cursor_cell < 0)
2102 info = g_list_nth_data (icon_view->priv->cell_list,
2103 icon_view->priv->cursor_cell);
2108 *path = gtk_tree_path_new_from_indices (item->index, -1);
2121 return (item != NULL);
2125 gtk_icon_view_button_press (GtkWidget *widget,
2126 GdkEventButton *event)
2128 GtkIconView *icon_view;
2129 GtkIconViewItem *item;
2130 GtkIconViewCellInfo *info = NULL;
2131 gboolean dirty = FALSE;
2132 GtkCellRendererMode mode;
2133 gint cursor_cell = -1;
2135 icon_view = GTK_ICON_VIEW (widget);
2137 if (event->window != icon_view->priv->bin_window)
2140 if (!gtk_widget_has_focus (widget))
2141 gtk_widget_grab_focus (widget);
2143 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2145 item = gtk_icon_view_get_item_at_coords (icon_view,
2151 * We consider only the the cells' area as the item area if the
2152 * item is not selected, but if it *is* selected, the complete
2153 * selection rectangle is considered to be part of the item.
2155 if (item != NULL && (info != NULL || item->selected))
2159 g_object_get (info->cell, "mode", &mode, NULL);
2161 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2162 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2163 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2166 gtk_icon_view_scroll_to_item (icon_view, item);
2168 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2170 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2172 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2173 (event->state & GDK_SHIFT_MASK))
2175 gtk_icon_view_unselect_all_internal (icon_view);
2177 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2178 if (!icon_view->priv->anchor_item)
2179 icon_view->priv->anchor_item = item;
2181 gtk_icon_view_select_all_between (icon_view,
2182 icon_view->priv->anchor_item,
2188 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2189 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2190 (event->state & GDK_CONTROL_MASK))
2192 item->selected = !item->selected;
2193 gtk_icon_view_queue_draw_item (icon_view, item);
2198 gtk_icon_view_unselect_all_internal (icon_view);
2200 item->selected = TRUE;
2201 gtk_icon_view_queue_draw_item (icon_view, item);
2204 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2205 icon_view->priv->anchor_item = item;
2208 /* Save press to possibly begin a drag */
2209 if (icon_view->priv->pressed_button < 0)
2211 icon_view->priv->pressed_button = event->button;
2212 icon_view->priv->press_start_x = event->x;
2213 icon_view->priv->press_start_y = event->y;
2216 if (!icon_view->priv->last_single_clicked)
2217 icon_view->priv->last_single_clicked = item;
2219 /* cancel the current editing, if it exists */
2220 gtk_icon_view_stop_editing (icon_view, TRUE);
2224 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2225 gtk_icon_view_item_activate_cell (icon_view, item, info,
2227 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2228 gtk_icon_view_start_editing (icon_view, item, info,
2234 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2235 !(event->state & GDK_CONTROL_MASK))
2237 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2240 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2241 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2244 /* don't draw keyboard focus around an clicked-on item */
2245 icon_view->priv->draw_focus = FALSE;
2248 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2250 item = gtk_icon_view_get_item_at_coords (icon_view,
2255 if (item && item == icon_view->priv->last_single_clicked)
2259 path = gtk_tree_path_new_from_indices (item->index, -1);
2260 gtk_icon_view_item_activated (icon_view, path);
2261 gtk_tree_path_free (path);
2264 icon_view->priv->last_single_clicked = NULL;
2265 icon_view->priv->pressed_button = -1;
2269 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2271 return event->button == 1;
2275 gtk_icon_view_button_release (GtkWidget *widget,
2276 GdkEventButton *event)
2278 GtkIconView *icon_view;
2280 icon_view = GTK_ICON_VIEW (widget);
2282 if (icon_view->priv->pressed_button == event->button)
2283 icon_view->priv->pressed_button = -1;
2285 gtk_icon_view_stop_rubberbanding (icon_view);
2287 remove_scroll_timeout (icon_view);
2293 gtk_icon_view_key_press (GtkWidget *widget,
2296 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2298 if (icon_view->priv->doing_rubberband)
2300 if (event->keyval == GDK_KEY_Escape)
2301 gtk_icon_view_stop_rubberbanding (icon_view);
2306 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2310 gtk_icon_view_key_release (GtkWidget *widget,
2313 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2315 if (icon_view->priv->doing_rubberband)
2318 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2322 gtk_icon_view_update_rubberband (gpointer data)
2324 GtkIconView *icon_view;
2326 GdkRectangle old_area;
2327 GdkRectangle new_area;
2328 GdkRectangle common;
2329 cairo_region_t *invalid_region;
2331 icon_view = GTK_ICON_VIEW (data);
2333 gdk_window_get_device_position (icon_view->priv->bin_window,
2334 icon_view->priv->rubberband_device,
2340 old_area.x = MIN (icon_view->priv->rubberband_x1,
2341 icon_view->priv->rubberband_x2);
2342 old_area.y = MIN (icon_view->priv->rubberband_y1,
2343 icon_view->priv->rubberband_y2);
2344 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2345 icon_view->priv->rubberband_x1) + 1;
2346 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2347 icon_view->priv->rubberband_y1) + 1;
2349 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2350 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2351 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2352 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2354 invalid_region = cairo_region_create_rectangle (&old_area);
2355 cairo_region_union_rectangle (invalid_region, &new_area);
2357 gdk_rectangle_intersect (&old_area, &new_area, &common);
2358 if (common.width > 2 && common.height > 2)
2360 cairo_region_t *common_region;
2362 /* make sure the border is invalidated */
2368 common_region = cairo_region_create_rectangle (&common);
2370 cairo_region_subtract (invalid_region, common_region);
2371 cairo_region_destroy (common_region);
2374 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2376 cairo_region_destroy (invalid_region);
2378 icon_view->priv->rubberband_x2 = x;
2379 icon_view->priv->rubberband_y2 = y;
2381 gtk_icon_view_update_rubberband_selection (icon_view);
2385 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2392 if (icon_view->priv->rubberband_device)
2395 for (items = icon_view->priv->items; items; items = items->next)
2397 GtkIconViewItem *item = items->data;
2399 item->selected_before_rubberbanding = item->selected;
2402 icon_view->priv->rubberband_x1 = x;
2403 icon_view->priv->rubberband_y1 = y;
2404 icon_view->priv->rubberband_x2 = x;
2405 icon_view->priv->rubberband_y2 = y;
2407 icon_view->priv->doing_rubberband = TRUE;
2408 icon_view->priv->rubberband_device = device;
2410 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2414 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2416 if (!icon_view->priv->doing_rubberband)
2419 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2420 icon_view->priv->rubberband_device);
2422 icon_view->priv->doing_rubberband = FALSE;
2423 icon_view->priv->rubberband_device = NULL;
2425 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2429 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2432 gint x, y, width, height;
2433 gboolean dirty = FALSE;
2435 x = MIN (icon_view->priv->rubberband_x1,
2436 icon_view->priv->rubberband_x2);
2437 y = MIN (icon_view->priv->rubberband_y1,
2438 icon_view->priv->rubberband_y2);
2439 width = ABS (icon_view->priv->rubberband_x1 -
2440 icon_view->priv->rubberband_x2);
2441 height = ABS (icon_view->priv->rubberband_y1 -
2442 icon_view->priv->rubberband_y2);
2444 for (items = icon_view->priv->items; items; items = items->next)
2446 GtkIconViewItem *item = items->data;
2450 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2451 x, y, width, height);
2453 selected = is_in ^ item->selected_before_rubberbanding;
2455 if (item->selected != selected)
2457 item->selected = selected;
2459 gtk_icon_view_queue_draw_item (icon_view, item);
2464 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2468 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2469 GtkIconViewItem *item,
2478 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2479 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2482 for (l = icon_view->priv->cell_list; l; l = l->next)
2484 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2486 if (!gtk_cell_renderer_get_visible (info->cell))
2489 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2491 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2492 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2500 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2502 gboolean dirty = FALSE;
2505 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2508 for (items = icon_view->priv->items; items; items = items->next)
2510 GtkIconViewItem *item = items->data;
2514 item->selected = FALSE;
2516 gtk_icon_view_queue_draw_item (icon_view, item);
2517 gtk_icon_view_item_selected_changed (icon_view, item);
2525 /* GtkIconView signals */
2527 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2528 GtkAdjustment *hadj,
2529 GtkAdjustment *vadj)
2531 gboolean need_adjust = FALSE;
2534 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2536 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2538 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2540 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2542 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2544 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2545 0, 0, NULL, NULL, icon_view);
2546 g_object_unref (icon_view->priv->hadjustment);
2549 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2551 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2552 0, 0, NULL, NULL, icon_view);
2553 g_object_unref (icon_view->priv->vadjustment);
2556 if (icon_view->priv->hadjustment != hadj)
2558 icon_view->priv->hadjustment = hadj;
2559 g_object_ref_sink (icon_view->priv->hadjustment);
2561 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2562 G_CALLBACK (gtk_icon_view_adjustment_changed),
2567 if (icon_view->priv->vadjustment != vadj)
2569 icon_view->priv->vadjustment = vadj;
2570 g_object_ref_sink (icon_view->priv->vadjustment);
2572 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2573 G_CALLBACK (gtk_icon_view_adjustment_changed),
2579 gtk_icon_view_adjustment_changed (NULL, icon_view);
2583 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2585 gtk_icon_view_select_all (icon_view);
2589 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2591 gtk_icon_view_unselect_all (icon_view);
2595 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2597 gtk_icon_view_unselect_all (icon_view);
2599 if (icon_view->priv->cursor_item != NULL)
2600 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2604 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2607 GtkCellRendererMode mode;
2608 GtkIconViewCellInfo *info = NULL;
2610 if (!icon_view->priv->cursor_item)
2613 info = g_list_nth_data (icon_view->priv->cell_list,
2614 icon_view->priv->cursor_cell);
2618 g_object_get (info->cell, "mode", &mode, NULL);
2620 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2622 gtk_icon_view_item_activate_cell (icon_view,
2623 icon_view->priv->cursor_item,
2627 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2629 gtk_icon_view_start_editing (icon_view,
2630 icon_view->priv->cursor_item,
2636 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2637 gtk_icon_view_item_activated (icon_view, path);
2638 gtk_tree_path_free (path);
2644 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2646 if (!icon_view->priv->cursor_item)
2649 switch (icon_view->priv->selection_mode)
2651 case GTK_SELECTION_NONE:
2653 case GTK_SELECTION_BROWSE:
2654 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2656 case GTK_SELECTION_SINGLE:
2657 if (icon_view->priv->cursor_item->selected)
2658 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2660 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2662 case GTK_SELECTION_MULTIPLE:
2663 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2664 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2666 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2667 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2672 /* Internal functions */
2674 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2675 GtkIconView *icon_view)
2677 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2679 gdk_window_move (icon_view->priv->bin_window,
2680 - icon_view->priv->hadjustment->value,
2681 - icon_view->priv->vadjustment->value);
2683 if (icon_view->priv->doing_rubberband)
2684 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2686 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2691 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2696 gint *maximum_width)
2698 GtkAllocation allocation;
2699 GtkWidget *widget = GTK_WIDGET (icon_view);
2701 gint x, current_width;
2702 GList *items, *last_item;
2709 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2710 max_height = g_new0 (gint, icon_view->priv->n_cells);
2717 gtk_widget_style_get (widget,
2718 "focus-line-width", &focus_width,
2721 x += icon_view->priv->margin + focus_width;
2722 current_width += 2 * (icon_view->priv->margin + focus_width);
2727 GtkIconViewItem *item = items->data;
2729 gtk_icon_view_calculate_item_size (icon_view, item);
2730 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2732 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2734 current_width += item->width;
2736 if (items != first_item)
2738 gtk_widget_get_allocation (widget, &allocation);
2740 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2741 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2745 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2747 item->y = *y + focus_width;
2750 x = current_width - (icon_view->priv->margin + focus_width);
2752 for (i = 0; i < icon_view->priv->n_cells; i++)
2753 max_height[i] = MAX (max_height[i], item->box[i].height);
2755 if (current_width > *maximum_width)
2756 *maximum_width = current_width;
2762 items = items->next;
2767 /* Now go through the row again and align the icons */
2768 for (items = first_item; items != last_item; items = items->next)
2770 GtkIconViewItem *item = items->data;
2774 item->x = *maximum_width - item->width - item->x;
2775 item->col = col - 1 - item->col;
2778 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2780 /* We may want to readjust the new y coordinate. */
2781 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2782 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2785 g_free (max_height);
2791 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2794 if (upper != adj->upper)
2796 gdouble min = MAX (0.0, upper - adj->page_size);
2797 gboolean value_changed = FALSE;
2801 if (adj->value > min)
2804 value_changed = TRUE;
2807 gtk_adjustment_changed (adj);
2810 gtk_adjustment_value_changed (adj);
2815 gtk_icon_view_layout (GtkIconView *icon_view)
2817 GtkAllocation allocation;
2820 gint y = 0, maximum_width = 0;
2823 gboolean size_changed = FALSE;
2825 if (icon_view->priv->layout_idle_id != 0)
2827 g_source_remove (icon_view->priv->layout_idle_id);
2828 icon_view->priv->layout_idle_id = 0;
2831 if (icon_view->priv->model == NULL)
2834 widget = GTK_WIDGET (icon_view);
2836 item_width = icon_view->priv->item_width;
2840 for (icons = icon_view->priv->items; icons; icons = icons->next)
2842 GtkIconViewItem *item = icons->data;
2843 gtk_icon_view_calculate_item_size (icon_view, item);
2844 item_width = MAX (item_width, item->width);
2849 icons = icon_view->priv->items;
2850 y += icon_view->priv->margin;
2855 gtk_icon_view_set_cell_data (icon_view, icons->data);
2856 adjust_wrap_width (icon_view, icons->data);
2861 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2863 &y, &maximum_width);
2866 while (icons != NULL);
2868 if (maximum_width != icon_view->priv->width)
2870 icon_view->priv->width = maximum_width;
2871 size_changed = TRUE;
2874 y += icon_view->priv->margin;
2876 if (y != icon_view->priv->height)
2878 icon_view->priv->height = y;
2879 size_changed = TRUE;
2882 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2883 icon_view->priv->width);
2884 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2885 icon_view->priv->height);
2888 gtk_widget_queue_resize_no_redraw (widget);
2890 gtk_widget_get_allocation (widget, &allocation);
2891 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2892 gdk_window_resize (icon_view->priv->bin_window,
2893 MAX (icon_view->priv->width, allocation.width),
2894 MAX (icon_view->priv->height, allocation.height));
2896 if (icon_view->priv->scroll_to_path)
2900 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2901 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2902 icon_view->priv->scroll_to_path = NULL;
2904 gtk_icon_view_scroll_to_path (icon_view, path,
2905 icon_view->priv->scroll_to_use_align,
2906 icon_view->priv->scroll_to_row_align,
2907 icon_view->priv->scroll_to_col_align);
2908 gtk_tree_path_free (path);
2911 gtk_widget_queue_draw (widget);
2915 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2916 GtkIconViewItem *item,
2917 GtkIconViewCellInfo *info,
2918 GdkRectangle *cell_area)
2920 g_return_if_fail (info->position < item->n_cells);
2922 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
2924 cell_area->x = item->box[info->position].x - item->before[info->position];
2925 cell_area->y = item->y + icon_view->priv->item_padding;
2926 cell_area->width = item->box[info->position].width +
2927 item->before[info->position] + item->after[info->position];
2928 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2932 cell_area->x = item->x + icon_view->priv->item_padding;
2933 cell_area->y = item->box[info->position].y - item->before[info->position];
2934 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2935 cell_area->height = item->box[info->position].height +
2936 item->before[info->position] + item->after[info->position];
2941 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2942 GtkIconViewItem *item,
2943 GtkIconViewCellInfo *info,
2946 g_return_if_fail (info->position < item->n_cells);
2948 *box = item->box[info->position];
2951 /* try to guess a reasonable wrap width for an implicit text cell renderer
2954 adjust_wrap_width (GtkIconView *icon_view,
2955 GtkIconViewItem *item)
2957 GtkIconViewCellInfo *text_info;
2958 GtkIconViewCellInfo *pixbuf_info;
2961 if (icon_view->priv->text_cell != -1 &&
2962 icon_view->priv->pixbuf_cell != -1)
2964 GtkRequisition min_size;
2967 text_info = g_list_nth_data (icon_view->priv->cell_list,
2968 icon_view->priv->text_cell);
2969 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2970 icon_view->priv->pixbuf_cell);
2972 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (pixbuf_info->cell),
2973 GTK_WIDGET (icon_view),
2976 if (icon_view->priv->item_width > 0)
2977 item_width = icon_view->priv->item_width;
2979 item_width = item->width;
2981 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
2982 wrap_width = item_width;
2984 if (item->width == -1 && item_width <= 0)
2985 wrap_width = MAX (2 * min_size.width, 50);
2987 wrap_width = item_width - min_size.width - icon_view->priv->spacing;
2990 wrap_width -= icon_view->priv->item_padding * 2;
2992 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2993 g_object_set (text_info->cell, "width", wrap_width, NULL);
2998 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2999 GtkIconViewItem *item)
3001 GtkRequisition min_size;
3005 if (item->width != -1 && item->height != -1)
3008 if (item->n_cells != icon_view->priv->n_cells)
3010 g_free (item->before);
3011 g_free (item->after);
3014 item->before = g_new0 (gint, icon_view->priv->n_cells);
3015 item->after = g_new0 (gint, icon_view->priv->n_cells);
3016 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
3018 item->n_cells = icon_view->priv->n_cells;
3021 gtk_icon_view_set_cell_data (icon_view, item);
3023 spacing = icon_view->priv->spacing;
3027 for (l = icon_view->priv->cell_list; l; l = l->next)
3029 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3031 if (!gtk_cell_renderer_get_visible (info->cell))
3034 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
3035 GTK_WIDGET (icon_view),
3037 item->box[info->position].width = min_size.width;
3038 item->box[info->position].height = min_size.height;
3040 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3042 item->width += item->box[info->position].width
3043 + (info->position > 0 ? spacing : 0);
3044 item->height = MAX (item->height, item->box[info->position].height);
3048 item->width = MAX (item->width, item->box[info->position].width);
3049 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3053 item->width += icon_view->priv->item_padding * 2;
3054 item->height += icon_view->priv->item_padding * 2;
3058 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3059 GtkIconViewItem *item,
3062 GtkRequisition min_size;
3063 GdkRectangle cell_area;
3069 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3071 gtk_icon_view_set_cell_data (icon_view, item);
3073 spacing = icon_view->priv->spacing;
3076 for (i = 0; i < icon_view->priv->n_cells; i++)
3078 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3079 item->height = MAX (item->height, max_height[i]);
3081 item->height += max_height[i] + (i > 0 ? spacing : 0);
3084 cell_area.x = item->x + icon_view->priv->item_padding;
3085 cell_area.y = item->y + icon_view->priv->item_padding;
3087 for (k = 0; k < 2; k++)
3088 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3090 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3092 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3095 if (!gtk_cell_renderer_get_visible (info->cell))
3098 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3100 /* We should not subtract icon_view->priv->item_padding from item->height,
3101 * because item->height is recalculated above using
3102 * max_height which does not contain item padding.
3104 cell_area.width = item->box[info->position].width;
3105 cell_area.height = item->height;
3109 /* item->width is not recalculated and thus needs to be
3110 * corrected for the padding.
3112 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3113 cell_area.height = max_height[i];
3116 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
3117 GTK_WIDGET (icon_view),
3119 item->box[info->position].width = min_size.width;
3120 item->box[info->position].height = min_size.height;
3122 _gtk_cell_renderer_calc_offset (info->cell, &cell_area,
3123 gtk_widget_get_direction (GTK_WIDGET (icon_view)),
3124 item->box[info->position].width, item->box[info->position].height,
3125 &item->box[info->position].x, &item->box[info->position].y);
3126 item->box[info->position].x += cell_area.x;
3127 item->box[info->position].y += cell_area.y;
3129 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3131 item->before[info->position] = item->box[info->position].x - cell_area.x;
3132 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3133 cell_area.x += cell_area.width + spacing;
3137 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3139 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3140 cell_area.width = item->width;
3142 item->before[info->position] = item->box[info->position].y - cell_area.y;
3143 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3144 cell_area.y += cell_area.height + spacing;
3148 if (rtl && icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3150 for (i = 0; i < icon_view->priv->n_cells; i++)
3152 item->box[i].x = item->x + item->width -
3153 (item->box[i].x + item->box[i].width - item->x);
3157 item->height += icon_view->priv->item_padding * 2;
3161 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3163 g_list_foreach (icon_view->priv->items,
3164 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3168 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3175 gtk_icon_view_paint_item (GtkIconView *icon_view,
3177 GtkIconViewItem *item,
3180 gboolean draw_focus)
3184 GdkRectangle cell_area, box;
3188 GtkCellRendererState flags;
3190 GtkWidget *widget = GTK_WIDGET (icon_view);
3192 if (icon_view->priv->model == NULL)
3195 gtk_icon_view_set_cell_data (icon_view, item);
3197 style = gtk_widget_get_style (widget);
3198 gtk_widget_style_get (widget,
3199 "focus-line-width", &focus_width,
3202 padding = focus_width;
3206 flags = GTK_CELL_RENDERER_SELECTED;
3207 if (gtk_widget_has_focus (widget))
3208 state = GTK_STATE_SELECTED;
3210 state = GTK_STATE_ACTIVE;
3215 state = GTK_STATE_NORMAL;
3220 gtk_paint_flat_box (style,
3224 GTK_WIDGET (icon_view),
3227 item->width, item->height);
3230 for (l = icon_view->priv->cell_list; l; l = l->next)
3232 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3234 if (!gtk_cell_renderer_get_visible (info->cell))
3237 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3239 cell_area.x = x - item->x + cell_area.x;
3240 cell_area.y = y - item->y + cell_area.y;
3242 gtk_cell_renderer_render (info->cell,
3245 &cell_area, &cell_area, flags);
3249 gtk_widget_has_focus (widget) &&
3250 item == icon_view->priv->cursor_item)
3252 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3254 GtkCellRendererMode mode;
3255 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3257 if (!gtk_cell_renderer_get_visible (info->cell))
3260 /* If found a editable/activatable cell, draw focus on it. */
3261 g_object_get (info->cell, "mode", &mode, NULL);
3262 if (icon_view->priv->cursor_cell < 0 &&
3263 mode != GTK_CELL_RENDERER_MODE_INERT)
3264 icon_view->priv->cursor_cell = i;
3266 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3268 if (i == icon_view->priv->cursor_cell)
3270 gtk_paint_focus (style,
3275 x - item->x + box.x - padding,
3276 y - item->y + box.y - padding,
3277 box.width + 2 * padding,
3278 box.height + 2 * padding);
3283 /* If there are no editable/activatable cells, draw focus
3284 * around the whole item.
3286 if (icon_view->priv->cursor_cell < 0)
3287 gtk_paint_focus (style,
3294 item->width + 2 * padding,
3295 item->height + 2 * padding);
3300 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3304 GdkColor *fill_color_gdk;
3305 guchar fill_color_alpha;
3309 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3310 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3311 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3312 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3314 gtk_widget_style_get (GTK_WIDGET (icon_view),
3315 "selection-box-color", &fill_color_gdk,
3316 "selection-box-alpha", &fill_color_alpha,
3319 if (!fill_color_gdk)
3320 fill_color_gdk = gdk_color_copy (>k_widget_get_style (GTK_WIDGET (icon_view))->base[GTK_STATE_SELECTED]);
3322 gdk_cairo_set_source_color (cr, fill_color_gdk);
3324 gdk_cairo_rectangle (cr, &rect);
3327 cairo_paint_with_alpha (cr, fill_color_alpha / 255.);
3329 cairo_rectangle (cr,
3330 rect.x + 0.5, rect.y + 0.5,
3331 rect.width - 1, rect.height - 1);
3334 gdk_color_free (fill_color_gdk);
3340 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3346 index = gtk_tree_path_get_indices (path)[0];
3348 for (l = icon_view->priv->items; l; l = l->next)
3350 GtkIconViewItem *item = l->data;
3352 if (item->index == index)
3354 gtk_icon_view_queue_draw_item (icon_view, item);
3361 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3362 GtkIconViewItem *item)
3367 gtk_widget_style_get (GTK_WIDGET (icon_view),
3368 "focus-line-width", &focus_width,
3371 rect.x = item->x - focus_width;
3372 rect.y = item->y - focus_width;
3373 rect.width = item->width + 2 * focus_width;
3374 rect.height = item->height + 2 * focus_width;
3376 if (icon_view->priv->bin_window)
3377 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3381 layout_callback (gpointer user_data)
3383 GtkIconView *icon_view;
3385 icon_view = GTK_ICON_VIEW (user_data);
3387 icon_view->priv->layout_idle_id = 0;
3389 gtk_icon_view_layout (icon_view);
3395 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3397 if (icon_view->priv->layout_idle_id != 0)
3400 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3404 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3405 GtkIconViewItem *item,
3409 AtkObject *item_obj;
3410 AtkObject *cursor_item_obj;
3412 if (icon_view->priv->cursor_item == item &&
3413 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3416 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3417 if (icon_view->priv->cursor_item != NULL)
3419 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3422 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3423 if (cursor_item_obj != NULL)
3424 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3427 icon_view->priv->cursor_item = item;
3428 if (cursor_cell >= 0)
3429 icon_view->priv->cursor_cell = cursor_cell;
3431 gtk_icon_view_queue_draw_item (icon_view, item);
3433 /* Notify that accessible focus object has changed */
3434 item_obj = atk_object_ref_accessible_child (obj, item->index);
3436 if (item_obj != NULL)
3438 atk_focus_tracker_notify (item_obj);
3439 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3440 g_object_unref (item_obj);
3445 static GtkIconViewItem *
3446 gtk_icon_view_item_new (void)
3448 GtkIconViewItem *item;
3450 item = g_new0 (GtkIconViewItem, 1);
3459 gtk_icon_view_item_free (GtkIconViewItem *item)
3461 g_return_if_fail (item != NULL);
3463 g_free (item->before);
3464 g_free (item->after);
3471 static GtkIconViewItem *
3472 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3475 gboolean only_in_cell,
3476 GtkIconViewCellInfo **cell_at_pos)
3482 *cell_at_pos = NULL;
3484 for (items = icon_view->priv->items; items; items = items->next)
3486 GtkIconViewItem *item = items->data;
3488 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3489 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3491 if (only_in_cell || cell_at_pos)
3493 gtk_icon_view_set_cell_data (icon_view, item);
3495 for (l = icon_view->priv->cell_list; l; l = l->next)
3497 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3499 if (!gtk_cell_renderer_get_visible (info->cell))
3502 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3504 if ((x >= box.x && x <= box.x + box.width &&
3505 y >= box.y && y <= box.y + box.height) ||
3507 x <= box.x + box.width &&
3509 y <= box.y + box.height))
3512 *cell_at_pos = info;
3530 gtk_icon_view_select_item (GtkIconView *icon_view,
3531 GtkIconViewItem *item)
3533 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3534 g_return_if_fail (item != NULL);
3539 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3541 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3542 gtk_icon_view_unselect_all_internal (icon_view);
3544 item->selected = TRUE;
3546 gtk_icon_view_item_selected_changed (icon_view, item);
3547 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3549 gtk_icon_view_queue_draw_item (icon_view, item);
3554 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3555 GtkIconViewItem *item)
3557 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3558 g_return_if_fail (item != NULL);
3560 if (!item->selected)
3563 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3564 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3567 item->selected = FALSE;
3569 gtk_icon_view_item_selected_changed (icon_view, item);
3570 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3572 gtk_icon_view_queue_draw_item (icon_view, item);
3576 verify_items (GtkIconView *icon_view)
3581 for (items = icon_view->priv->items; items; items = items->next)
3583 GtkIconViewItem *item = items->data;
3585 if (item->index != i)
3586 g_error ("List item does not match its index: "
3587 "item index %d and list index %d\n", item->index, i);
3594 gtk_icon_view_row_changed (GtkTreeModel *model,
3599 GtkIconViewItem *item;
3601 GtkIconView *icon_view;
3603 icon_view = GTK_ICON_VIEW (data);
3605 gtk_icon_view_stop_editing (icon_view, TRUE);
3607 index = gtk_tree_path_get_indices(path)[0];
3608 item = g_list_nth_data (icon_view->priv->items, index);
3610 gtk_icon_view_item_invalidate_size (item);
3611 gtk_icon_view_queue_layout (icon_view);
3613 verify_items (icon_view);
3617 gtk_icon_view_row_inserted (GtkTreeModel *model,
3623 GtkIconViewItem *item;
3624 gboolean iters_persist;
3625 GtkIconView *icon_view;
3628 icon_view = GTK_ICON_VIEW (data);
3630 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3632 index = gtk_tree_path_get_indices(path)[0];
3634 item = gtk_icon_view_item_new ();
3639 item->index = index;
3641 /* FIXME: We can be more efficient here,
3642 we can store a tail pointer and use that when
3643 appending (which is a rather common operation)
3645 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3648 list = g_list_nth (icon_view->priv->items, index + 1);
3649 for (; list; list = list->next)
3656 verify_items (icon_view);
3658 gtk_icon_view_queue_layout (icon_view);
3662 gtk_icon_view_row_deleted (GtkTreeModel *model,
3667 GtkIconView *icon_view;
3668 GtkIconViewItem *item;
3670 gboolean emit = FALSE;
3672 icon_view = GTK_ICON_VIEW (data);
3674 index = gtk_tree_path_get_indices(path)[0];
3676 list = g_list_nth (icon_view->priv->items, index);
3679 gtk_icon_view_stop_editing (icon_view, TRUE);
3681 if (item == icon_view->priv->anchor_item)
3682 icon_view->priv->anchor_item = NULL;
3684 if (item == icon_view->priv->cursor_item)
3685 icon_view->priv->cursor_item = NULL;
3690 gtk_icon_view_item_free (item);
3692 for (next = list->next; next; next = next->next)
3699 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3701 verify_items (icon_view);
3703 gtk_icon_view_queue_layout (icon_view);
3706 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3710 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3711 GtkTreePath *parent,
3718 GtkIconView *icon_view;
3719 GList *items = NULL, *list;
3720 GtkIconViewItem **item_array;
3723 icon_view = GTK_ICON_VIEW (data);
3725 gtk_icon_view_stop_editing (icon_view, TRUE);
3727 length = gtk_tree_model_iter_n_children (model, NULL);
3729 order = g_new (gint, length);
3730 for (i = 0; i < length; i++)
3731 order [new_order[i]] = i;
3733 item_array = g_new (GtkIconViewItem *, length);
3734 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3735 item_array[order[i]] = list->data;
3738 for (i = length - 1; i >= 0; i--)
3740 item_array[i]->index = i;
3741 items = g_list_prepend (items, item_array[i]);
3744 g_free (item_array);
3745 g_list_free (icon_view->priv->items);
3746 icon_view->priv->items = items;
3748 gtk_icon_view_queue_layout (icon_view);
3750 verify_items (icon_view);
3754 gtk_icon_view_build_items (GtkIconView *icon_view)
3758 gboolean iters_persist;
3759 GList *items = NULL;
3761 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3763 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3771 GtkIconViewItem *item = gtk_icon_view_item_new ();
3780 items = g_list_prepend (items, item);
3782 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3784 icon_view->priv->items = g_list_reverse (items);
3788 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3791 GtkMovementStep step,
3795 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3796 I_("move-cursor"), 2,
3800 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3805 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3808 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3813 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3820 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3821 GtkMovementStep step,
3824 GdkModifierType state;
3826 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3827 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3828 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3829 step == GTK_MOVEMENT_DISPLAY_LINES ||
3830 step == GTK_MOVEMENT_PAGES ||
3831 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3833 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3836 gtk_icon_view_stop_editing (icon_view, FALSE);
3837 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3839 if (gtk_get_current_event_state (&state))
3841 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3842 icon_view->priv->ctrl_pressed = TRUE;
3843 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3844 icon_view->priv->shift_pressed = TRUE;
3846 /* else we assume not pressed */
3850 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3851 case GTK_MOVEMENT_VISUAL_POSITIONS:
3852 gtk_icon_view_move_cursor_left_right (icon_view, count);
3854 case GTK_MOVEMENT_DISPLAY_LINES:
3855 gtk_icon_view_move_cursor_up_down (icon_view, count);
3857 case GTK_MOVEMENT_PAGES:
3858 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3860 case GTK_MOVEMENT_BUFFER_ENDS:
3861 gtk_icon_view_move_cursor_start_end (icon_view, count);
3864 g_assert_not_reached ();
3867 icon_view->priv->ctrl_pressed = FALSE;
3868 icon_view->priv->shift_pressed = FALSE;
3870 icon_view->priv->draw_focus = TRUE;
3875 static GtkIconViewItem *
3876 find_item (GtkIconView *icon_view,
3877 GtkIconViewItem *current,
3883 GtkIconViewItem *item;
3885 /* FIXME: this could be more efficient
3887 row = current->row + row_ofs;
3888 col = current->col + col_ofs;
3890 for (items = icon_view->priv->items; items; items = items->next)
3893 if (item->row == row && item->col == col)
3901 find_cell (GtkIconView *icon_view,
3902 GtkIconViewItem *item,
3904 GtkOrientation orientation,
3914 if (icon_view->priv->item_orientation != orientation)
3917 gtk_icon_view_set_cell_data (icon_view, item);
3919 focusable = g_new0 (gint, icon_view->priv->n_cells);
3923 for (k = 0; k < 2; k++)
3924 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3926 GtkCellRendererMode mode;
3927 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3929 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3932 if (!gtk_cell_renderer_get_visible (info->cell))
3935 g_object_get (info->cell, "mode", &mode, NULL);
3936 if (mode != GTK_CELL_RENDERER_MODE_INERT)
3939 current = n_focusable;
3941 focusable[n_focusable] = i;
3947 if (n_focusable == 0)
3955 current = step > 0 ? 0 : n_focusable - 1;
3956 cell = focusable[current];
3959 if (current + *count < 0)
3962 *count = current + *count;
3964 else if (current + *count > n_focusable - 1)
3967 *count = current + *count - (n_focusable - 1);
3971 cell = focusable[current + *count];
3980 static GtkIconViewItem *
3981 find_item_page_up_down (GtkIconView *icon_view,
3982 GtkIconViewItem *current,
3989 y = current->y + count * icon_view->priv->vadjustment->page_size;
3991 item = g_list_find (icon_view->priv->items, current);
3996 for (next = item->next; next; next = next->next)
3998 if (((GtkIconViewItem *)next->data)->col == col)
4001 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4011 for (next = item->prev; next; next = next->prev)
4013 if (((GtkIconViewItem *)next->data)->col == col)
4016 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4030 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4031 GtkIconViewItem *anchor,
4032 GtkIconViewItem *cursor)
4035 GtkIconViewItem *item;
4036 gint row1, row2, col1, col2;
4037 gboolean dirty = FALSE;
4039 if (anchor->row < cursor->row)
4050 if (anchor->col < cursor->col)
4061 for (items = icon_view->priv->items; items; items = items->next)
4065 if (row1 <= item->row && item->row <= row2 &&
4066 col1 <= item->col && item->col <= col2)
4068 if (!item->selected)
4071 item->selected = TRUE;
4072 gtk_icon_view_item_selected_changed (icon_view, item);
4074 gtk_icon_view_queue_draw_item (icon_view, item);
4082 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4085 GtkIconViewItem *item;
4087 gboolean dirty = FALSE;
4089 GtkDirectionType direction;
4091 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4094 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4096 if (!icon_view->priv->cursor_item)
4101 list = icon_view->priv->items;
4103 list = g_list_last (icon_view->priv->items);
4105 item = list ? list->data : NULL;
4110 item = icon_view->priv->cursor_item;
4111 cell = icon_view->priv->cursor_cell;
4112 step = count > 0 ? 1 : -1;
4115 cell = find_cell (icon_view, item, cell,
4116 GTK_ORIENTATION_VERTICAL,
4121 item = find_item (icon_view, item, step, 0);
4122 count = count - step;
4128 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4130 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4132 gtk_widget_child_focus (toplevel,
4133 direction == GTK_DIR_UP ?
4134 GTK_DIR_TAB_BACKWARD :
4135 GTK_DIR_TAB_FORWARD);
4141 if (icon_view->priv->ctrl_pressed ||
4142 !icon_view->priv->shift_pressed ||
4143 !icon_view->priv->anchor_item ||
4144 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4145 icon_view->priv->anchor_item = item;
4147 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4149 if (!icon_view->priv->ctrl_pressed &&
4150 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4152 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4153 dirty = gtk_icon_view_select_all_between (icon_view,
4154 icon_view->priv->anchor_item,
4158 gtk_icon_view_scroll_to_item (icon_view, item);
4161 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4165 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4168 GtkIconViewItem *item;
4169 gboolean dirty = FALSE;
4171 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4174 if (!icon_view->priv->cursor_item)
4179 list = icon_view->priv->items;
4181 list = g_list_last (icon_view->priv->items);
4183 item = list ? list->data : NULL;
4186 item = find_item_page_up_down (icon_view,
4187 icon_view->priv->cursor_item,
4190 if (item == icon_view->priv->cursor_item)
4191 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4196 if (icon_view->priv->ctrl_pressed ||
4197 !icon_view->priv->shift_pressed ||
4198 !icon_view->priv->anchor_item ||
4199 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4200 icon_view->priv->anchor_item = item;
4202 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4204 if (!icon_view->priv->ctrl_pressed &&
4205 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4207 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4208 dirty = gtk_icon_view_select_all_between (icon_view,
4209 icon_view->priv->anchor_item,
4213 gtk_icon_view_scroll_to_item (icon_view, item);
4216 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4220 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4223 GtkIconViewItem *item;
4225 gboolean dirty = FALSE;
4227 GtkDirectionType direction;
4229 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4232 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4234 if (!icon_view->priv->cursor_item)
4239 list = icon_view->priv->items;
4241 list = g_list_last (icon_view->priv->items);
4243 item = list ? list->data : NULL;
4247 item = icon_view->priv->cursor_item;
4248 cell = icon_view->priv->cursor_cell;
4249 step = count > 0 ? 1 : -1;
4252 cell = find_cell (icon_view, item, cell,
4253 GTK_ORIENTATION_HORIZONTAL,
4258 item = find_item (icon_view, item, 0, step);
4259 count = count - step;
4265 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4267 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4269 gtk_widget_child_focus (toplevel,
4270 direction == GTK_DIR_LEFT ?
4271 GTK_DIR_TAB_BACKWARD :
4272 GTK_DIR_TAB_FORWARD);
4278 if (icon_view->priv->ctrl_pressed ||
4279 !icon_view->priv->shift_pressed ||
4280 !icon_view->priv->anchor_item ||
4281 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4282 icon_view->priv->anchor_item = item;
4284 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4286 if (!icon_view->priv->ctrl_pressed &&
4287 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4289 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4290 dirty = gtk_icon_view_select_all_between (icon_view,
4291 icon_view->priv->anchor_item,
4295 gtk_icon_view_scroll_to_item (icon_view, item);
4298 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4302 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4305 GtkIconViewItem *item;
4307 gboolean dirty = FALSE;
4309 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4313 list = icon_view->priv->items;
4315 list = g_list_last (icon_view->priv->items);
4317 item = list ? list->data : NULL;
4319 if (item == icon_view->priv->cursor_item)
4320 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4325 if (icon_view->priv->ctrl_pressed ||
4326 !icon_view->priv->shift_pressed ||
4327 !icon_view->priv->anchor_item ||
4328 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4329 icon_view->priv->anchor_item = item;
4331 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4333 if (!icon_view->priv->ctrl_pressed &&
4334 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4336 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4337 dirty = gtk_icon_view_select_all_between (icon_view,
4338 icon_view->priv->anchor_item,
4342 gtk_icon_view_scroll_to_item (icon_view, item);
4345 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4349 * gtk_icon_view_scroll_to_path:
4350 * @icon_view: A #GtkIconView.
4351 * @path: The path of the item to move to.
4352 * @use_align: whether to use alignment arguments, or %FALSE.
4353 * @row_align: The vertical alignment of the item specified by @path.
4354 * @col_align: The horizontal alignment of the item specified by @path.
4356 * Moves the alignments of @icon_view to the position specified by @path.
4357 * @row_align determines where the row is placed, and @col_align determines
4358 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4359 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4362 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4363 * tree does the minimum amount of work to scroll the item onto the screen.
4364 * This means that the item will be scrolled to the edge closest to its current
4365 * position. If the item is currently visible on the screen, nothing is done.
4367 * This function only works if the model is set, and @path is a valid row on
4368 * the model. If the model changes before the @icon_view is realized, the
4369 * centered path will be modified to reflect this change.
4374 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4380 GtkIconViewItem *item = NULL;
4383 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4384 g_return_if_fail (path != NULL);
4385 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4386 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4388 widget = GTK_WIDGET (icon_view);
4390 if (gtk_tree_path_get_depth (path) > 0)
4391 item = g_list_nth_data (icon_view->priv->items,
4392 gtk_tree_path_get_indices(path)[0]);
4394 if (!item || item->width < 0 ||
4395 !gtk_widget_get_realized (widget))
4397 if (icon_view->priv->scroll_to_path)
4398 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4400 icon_view->priv->scroll_to_path = NULL;
4403 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4405 icon_view->priv->scroll_to_use_align = use_align;
4406 icon_view->priv->scroll_to_row_align = row_align;
4407 icon_view->priv->scroll_to_col_align = col_align;
4414 GtkAllocation allocation;
4419 gtk_widget_style_get (widget,
4420 "focus-line-width", &focus_width,
4423 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4425 gtk_widget_get_allocation (widget, &allocation);
4427 offset = y + item->y - focus_width - row_align * (allocation.height - item->height);
4429 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4430 icon_view->priv->vadjustment->value + offset);
4432 offset = x + item->x - focus_width - col_align * (allocation.width - item->width);
4434 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4435 icon_view->priv->hadjustment->value + offset);
4437 gtk_adjustment_changed (icon_view->priv->hadjustment);
4438 gtk_adjustment_changed (icon_view->priv->vadjustment);
4441 gtk_icon_view_scroll_to_item (icon_view, item);
4446 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4447 GtkIconViewItem *item)
4449 GtkAllocation allocation;
4450 GtkWidget *widget = GTK_WIDGET (icon_view);
4451 gint x, y, width, height;
4454 gtk_widget_style_get (widget,
4455 "focus-line-width", &focus_width,
4458 width = gdk_window_get_width (icon_view->priv->bin_window);
4459 height = gdk_window_get_height (icon_view->priv->bin_window);
4460 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4462 gtk_widget_get_allocation (widget, &allocation);
4464 if (y + item->y - focus_width < 0)
4465 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4466 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4467 else if (y + item->y + item->height + focus_width > allocation.height)
4468 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4469 icon_view->priv->vadjustment->value + y + item->y + item->height
4470 + focus_width - allocation.height);
4472 if (x + item->x - focus_width < 0)
4473 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4474 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4475 else if (x + item->x + item->width + focus_width > allocation.width)
4476 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4477 icon_view->priv->hadjustment->value + x + item->x + item->width
4478 + focus_width - allocation.width);
4480 gtk_adjustment_changed (icon_view->priv->hadjustment);
4481 gtk_adjustment_changed (icon_view->priv->vadjustment);
4484 /* GtkCellLayout implementation */
4485 static GtkIconViewCellInfo *
4486 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4487 GtkCellRenderer *renderer)
4491 for (i = icon_view->priv->cell_list; i; i = i->next)
4493 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4495 if (info->cell == renderer)
4503 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4504 GtkIconViewItem *item)
4507 gboolean iters_persist;
4510 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4516 path = gtk_tree_path_new_from_indices (item->index, -1);
4517 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4519 gtk_tree_path_free (path);
4524 for (i = icon_view->priv->cell_list; i; i = i->next)
4527 GtkIconViewCellInfo *info = i->data;
4529 g_object_freeze_notify (G_OBJECT (info->cell));
4531 for (j = info->attributes; j && j->next; j = j->next->next)
4533 gchar *property = j->data;
4534 gint column = GPOINTER_TO_INT (j->next->data);
4535 GValue value = {0, };
4537 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4539 g_object_set_property (G_OBJECT (info->cell),
4541 g_value_unset (&value);
4545 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4547 icon_view->priv->model,
4551 g_object_thaw_notify (G_OBJECT (info->cell));
4556 free_cell_attributes (GtkIconViewCellInfo *info)
4560 list = info->attributes;
4561 while (list && list->next)
4563 g_free (list->data);
4564 list = list->next->next;
4567 g_slist_free (info->attributes);
4568 info->attributes = NULL;
4572 free_cell_info (GtkIconViewCellInfo *info)
4574 free_cell_attributes (info);
4576 g_object_unref (info->cell);
4579 (* info->destroy) (info->func_data);
4585 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4586 GtkCellRenderer *renderer,
4589 GtkIconViewCellInfo *info;
4590 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4592 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4593 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4595 g_object_ref_sink (renderer);
4597 info = g_new0 (GtkIconViewCellInfo, 1);
4598 info->cell = renderer;
4599 info->expand = expand ? TRUE : FALSE;
4600 info->pack = GTK_PACK_START;
4601 info->position = icon_view->priv->n_cells;
4603 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4604 icon_view->priv->n_cells++;
4608 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4609 GtkCellRenderer *renderer,
4612 GtkIconViewCellInfo *info;
4613 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4615 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4616 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4618 g_object_ref_sink (renderer);
4620 info = g_new0 (GtkIconViewCellInfo, 1);
4621 info->cell = renderer;
4622 info->expand = expand ? TRUE : FALSE;
4623 info->pack = GTK_PACK_END;
4624 info->position = icon_view->priv->n_cells;
4626 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4627 icon_view->priv->n_cells++;
4631 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4632 GtkCellRenderer *renderer,
4633 const gchar *attribute,
4636 GtkIconViewCellInfo *info;
4637 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4639 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4640 g_return_if_fail (info != NULL);
4642 info->attributes = g_slist_prepend (info->attributes,
4643 GINT_TO_POINTER (column));
4644 info->attributes = g_slist_prepend (info->attributes,
4645 g_strdup (attribute));
4649 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4651 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4653 while (icon_view->priv->cell_list)
4655 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4656 free_cell_info (info);
4657 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4658 icon_view->priv->cell_list);
4661 icon_view->priv->n_cells = 0;
4665 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4666 GtkCellRenderer *cell,
4667 GtkCellLayoutDataFunc func,
4669 GDestroyNotify destroy)
4671 GtkIconViewCellInfo *info;
4672 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4674 info = gtk_icon_view_get_cell_info (icon_view, cell);
4675 g_return_if_fail (info != NULL);
4679 GDestroyNotify d = info->destroy;
4681 info->destroy = NULL;
4682 d (info->func_data);
4686 info->func_data = func_data;
4687 info->destroy = destroy;
4691 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4692 GtkCellRenderer *renderer)
4694 GtkIconViewCellInfo *info;
4696 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4698 free_cell_attributes (info);
4702 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4703 GtkCellRenderer *cell,
4706 GtkIconView *icon_view;
4708 GtkIconViewCellInfo *info;
4711 icon_view = GTK_ICON_VIEW (layout);
4713 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4715 info = gtk_icon_view_get_cell_info (icon_view, cell);
4717 g_return_if_fail (info != NULL);
4718 g_return_if_fail (position >= 0);
4720 link = g_list_find (icon_view->priv->cell_list, info);
4722 g_return_if_fail (link != NULL);
4724 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4726 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4729 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4736 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4740 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4742 GtkIconView *icon_view = (GtkIconView *)layout;
4743 GList *retval = NULL, *l;
4745 for (l = icon_view->priv->cell_list; l; l = l->next)
4747 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4749 retval = g_list_prepend (retval, info->cell);
4752 return g_list_reverse (retval);
4759 * gtk_icon_view_new:
4761 * Creates a new #GtkIconView widget
4763 * Return value: A newly created #GtkIconView widget
4768 gtk_icon_view_new (void)
4770 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4774 * gtk_icon_view_new_with_model:
4775 * @model: The model.
4777 * Creates a new #GtkIconView widget with the model @model.
4779 * Return value: A newly created #GtkIconView widget.
4784 gtk_icon_view_new_with_model (GtkTreeModel *model)
4786 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4790 * gtk_icon_view_convert_widget_to_bin_window_coords:
4791 * @icon_view: a #GtkIconView
4792 * @wx: X coordinate relative to the widget
4793 * @wy: Y coordinate relative to the widget
4794 * @bx: return location for bin_window X coordinate
4795 * @by: return location for bin_window Y coordinate
4797 * Converts widget coordinates to coordinates for the bin_window,
4798 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4803 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4811 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4813 if (icon_view->priv->bin_window)
4814 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4825 * gtk_icon_view_get_path_at_pos:
4826 * @icon_view: A #GtkIconView.
4827 * @x: The x position to be identified
4828 * @y: The y position to be identified
4830 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4831 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4832 * the cell at the specified position.
4833 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4834 * widget coordinates to bin_window coordinates.
4836 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4837 * if no icon exists at that position.
4842 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4846 GtkIconViewItem *item;
4849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4851 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4856 path = gtk_tree_path_new_from_indices (item->index, -1);
4862 * gtk_icon_view_get_item_at_pos:
4863 * @icon_view: A #GtkIconView.
4864 * @x: The x position to be identified
4865 * @y: The y position to be identified
4866 * @path: (allow-none): Return location for the path, or %NULL
4867 * @cell: Return location for the renderer responsible for the cell
4868 * at (@x, @y), or %NULL
4870 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4871 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4872 * obtains the cell at the specified position. The returned path should
4873 * be freed with gtk_tree_path_free().
4874 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4875 * widget coordinates to bin_window coordinates.
4877 * Return value: %TRUE if an item exists at the specified position
4882 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4886 GtkCellRenderer **cell)
4888 GtkIconViewItem *item;
4889 GtkIconViewCellInfo *info;
4891 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4893 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4898 *path = gtk_tree_path_new_from_indices (item->index, -1);
4911 return (item != NULL);
4915 * gtk_icon_view_set_tooltip_item:
4916 * @icon_view: a #GtkIconView
4917 * @tooltip: a #GtkTooltip
4918 * @path: a #GtkTreePath
4920 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4921 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4922 * See also gtk_tooltip_set_tip_area().
4927 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4928 GtkTooltip *tooltip,
4931 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4932 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4934 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4938 * gtk_icon_view_set_tooltip_cell:
4939 * @icon_view: a #GtkIconView
4940 * @tooltip: a #GtkTooltip
4941 * @path: a #GtkTreePath
4942 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4944 * Sets the tip area of @tooltip to the area which @cell occupies in
4945 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4947 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4952 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4953 GtkTooltip *tooltip,
4955 GtkCellRenderer *cell)
4958 GtkIconViewItem *item = NULL;
4959 GtkIconViewCellInfo *info = NULL;
4962 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4963 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4964 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4966 if (gtk_tree_path_get_depth (path) > 0)
4967 item = g_list_nth_data (icon_view->priv->items,
4968 gtk_tree_path_get_indices(path)[0]);
4975 info = gtk_icon_view_get_cell_info (icon_view, cell);
4976 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4982 rect.width = item->width;
4983 rect.height = item->height;
4986 if (icon_view->priv->bin_window)
4988 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4993 gtk_tooltip_set_tip_area (tooltip, &rect);
4998 * gtk_icon_view_get_tooltip_context:
4999 * @icon_view: an #GtkIconView
5000 * @x: the x coordinate (relative to widget coordinates)
5001 * @y: the y coordinate (relative to widget coordinates)
5002 * @keyboard_tip: whether this is a keyboard tooltip or not
5003 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5004 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
5005 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5007 * This function is supposed to be used in a #GtkWidget::query-tooltip
5008 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5009 * which are received in the signal handler, should be passed to this
5010 * function without modification.
5012 * The return value indicates whether there is an icon view item at the given
5013 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5014 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5015 * @model, @path and @iter which have been provided will be set to point to
5016 * that row and the corresponding model. @x and @y will always be converted
5017 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5019 * Return value: whether or not the given tooltip context points to a item
5024 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5027 gboolean keyboard_tip,
5028 GtkTreeModel **model,
5032 GtkTreePath *tmppath = NULL;
5034 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5035 g_return_val_if_fail (x != NULL, FALSE);
5036 g_return_val_if_fail (y != NULL, FALSE);
5040 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5047 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5050 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5055 *model = gtk_icon_view_get_model (icon_view);
5058 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5064 gtk_tree_path_free (tmppath);
5070 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5073 gboolean keyboard_tip,
5074 GtkTooltip *tooltip,
5080 GtkTreeModel *model;
5081 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5083 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5086 &model, &path, &iter))
5089 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5093 gtk_tree_path_free (path);
5097 gtk_tooltip_set_markup (tooltip, str);
5098 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5100 gtk_tree_path_free (path);
5108 * gtk_icon_view_set_tooltip_column:
5109 * @icon_view: a #GtkIconView
5110 * @column: an integer, which is a valid column number for @icon_view's model
5112 * If you only plan to have simple (text-only) tooltips on full items, you
5113 * can use this function to have #GtkIconView handle these automatically
5114 * for you. @column should be set to the column in @icon_view's model
5115 * containing the tooltip texts, or -1 to disable this feature.
5117 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5118 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5123 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5126 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5128 if (column == icon_view->priv->tooltip_column)
5133 g_signal_handlers_disconnect_by_func (icon_view,
5134 gtk_icon_view_set_tooltip_query_cb,
5136 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5140 if (icon_view->priv->tooltip_column == -1)
5142 g_signal_connect (icon_view, "query-tooltip",
5143 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5144 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5148 icon_view->priv->tooltip_column = column;
5149 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5153 * gtk_icon_view_get_tooltip_column:
5154 * @icon_view: a #GtkIconView
5156 * Returns the column of @icon_view's model which is being used for
5157 * displaying tooltips on @icon_view's rows.
5159 * Return value: the index of the tooltip column that is currently being
5160 * used, or -1 if this is disabled.
5165 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5167 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5169 return icon_view->priv->tooltip_column;
5173 * gtk_icon_view_get_visible_range:
5174 * @icon_view: A #GtkIconView
5175 * @start_path: (allow-none): Return location for start of region, or %NULL
5176 * @end_path: (allow-none): Return location for end of region, or %NULL
5178 * Sets @start_path and @end_path to be the first and last visible path.
5179 * Note that there may be invisible paths in between.
5181 * Both paths should be freed with gtk_tree_path_free() after use.
5183 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5188 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5189 GtkTreePath **start_path,
5190 GtkTreePath **end_path)
5192 gint start_index = -1;
5193 gint end_index = -1;
5196 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5198 if (icon_view->priv->hadjustment == NULL ||
5199 icon_view->priv->vadjustment == NULL)
5202 if (start_path == NULL && end_path == NULL)
5205 for (icons = icon_view->priv->items; icons; icons = icons->next)
5207 GtkIconViewItem *item = icons->data;
5209 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5210 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5211 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5212 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5214 if (start_index == -1)
5215 start_index = item->index;
5216 end_index = item->index;
5220 if (start_path && start_index != -1)
5221 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5222 if (end_path && end_index != -1)
5223 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5225 return start_index != -1;
5229 * gtk_icon_view_selected_foreach:
5230 * @icon_view: A #GtkIconView.
5231 * @func: (scope call): The function to call for each selected icon.
5232 * @data: User data to pass to the function.
5234 * Calls a function for each selected icon. Note that the model or
5235 * selection cannot be modified from within this function.
5240 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5241 GtkIconViewForeachFunc func,
5246 for (list = icon_view->priv->items; list; list = list->next)
5248 GtkIconViewItem *item = list->data;
5249 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5252 (* func) (icon_view, path, data);
5254 gtk_tree_path_free (path);
5259 * gtk_icon_view_set_selection_mode:
5260 * @icon_view: A #GtkIconView.
5261 * @mode: The selection mode
5263 * Sets the selection mode of the @icon_view.
5268 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5269 GtkSelectionMode mode)
5271 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5273 if (mode == icon_view->priv->selection_mode)
5276 if (mode == GTK_SELECTION_NONE ||
5277 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5278 gtk_icon_view_unselect_all (icon_view);
5280 icon_view->priv->selection_mode = mode;
5282 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5286 * gtk_icon_view_get_selection_mode:
5287 * @icon_view: A #GtkIconView.
5289 * Gets the selection mode of the @icon_view.
5291 * Return value: the current selection mode
5296 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5298 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5300 return icon_view->priv->selection_mode;
5304 * gtk_icon_view_set_model:
5305 * @icon_view: A #GtkIconView.
5306 * @model: (allow-none): The model.
5308 * Sets the model for a #GtkIconView.
5309 * If the @icon_view already has a model set, it will remove
5310 * it before setting the new model. If @model is %NULL, then
5311 * it will unset the old model.
5316 gtk_icon_view_set_model (GtkIconView *icon_view,
5317 GtkTreeModel *model)
5319 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5320 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5322 if (icon_view->priv->model == model)
5325 if (icon_view->priv->scroll_to_path)
5327 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5328 icon_view->priv->scroll_to_path = NULL;
5331 gtk_icon_view_stop_editing (icon_view, TRUE);
5337 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5339 if (icon_view->priv->pixbuf_column != -1)
5341 column_type = gtk_tree_model_get_column_type (model,
5342 icon_view->priv->pixbuf_column);
5344 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5347 if (icon_view->priv->text_column != -1)
5349 column_type = gtk_tree_model_get_column_type (model,
5350 icon_view->priv->text_column);
5352 g_return_if_fail (column_type == G_TYPE_STRING);
5355 if (icon_view->priv->markup_column != -1)
5357 column_type = gtk_tree_model_get_column_type (model,
5358 icon_view->priv->markup_column);
5360 g_return_if_fail (column_type == G_TYPE_STRING);
5365 if (icon_view->priv->model)
5367 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5368 gtk_icon_view_row_changed,
5370 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5371 gtk_icon_view_row_inserted,
5373 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5374 gtk_icon_view_row_deleted,
5376 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5377 gtk_icon_view_rows_reordered,
5380 g_object_unref (icon_view->priv->model);
5382 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5383 g_list_free (icon_view->priv->items);
5384 icon_view->priv->items = NULL;
5385 icon_view->priv->anchor_item = NULL;
5386 icon_view->priv->cursor_item = NULL;
5387 icon_view->priv->last_single_clicked = NULL;
5388 icon_view->priv->width = 0;
5389 icon_view->priv->height = 0;
5392 icon_view->priv->model = model;
5394 if (icon_view->priv->model)
5396 g_object_ref (icon_view->priv->model);
5397 g_signal_connect (icon_view->priv->model,
5399 G_CALLBACK (gtk_icon_view_row_changed),
5401 g_signal_connect (icon_view->priv->model,
5403 G_CALLBACK (gtk_icon_view_row_inserted),
5405 g_signal_connect (icon_view->priv->model,
5407 G_CALLBACK (gtk_icon_view_row_deleted),
5409 g_signal_connect (icon_view->priv->model,
5411 G_CALLBACK (gtk_icon_view_rows_reordered),
5414 gtk_icon_view_build_items (icon_view);
5416 gtk_icon_view_queue_layout (icon_view);
5419 g_object_notify (G_OBJECT (icon_view), "model");
5421 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5422 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5426 * gtk_icon_view_get_model:
5427 * @icon_view: a #GtkIconView
5429 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5432 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5433 * currently being used.
5438 gtk_icon_view_get_model (GtkIconView *icon_view)
5440 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5442 return icon_view->priv->model;
5446 update_text_cell (GtkIconView *icon_view)
5448 GtkIconViewCellInfo *info;
5452 if (icon_view->priv->text_column == -1 &&
5453 icon_view->priv->markup_column == -1)
5455 if (icon_view->priv->text_cell != -1)
5457 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5458 icon_view->priv->pixbuf_cell--;
5460 info = g_list_nth_data (icon_view->priv->cell_list,
5461 icon_view->priv->text_cell);
5463 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5465 free_cell_info (info);
5467 icon_view->priv->n_cells--;
5468 icon_view->priv->text_cell = -1;
5473 if (icon_view->priv->text_cell == -1)
5475 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5476 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5477 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5480 if (info->cell == cell)
5482 icon_view->priv->text_cell = i;
5488 info = g_list_nth_data (icon_view->priv->cell_list,
5489 icon_view->priv->text_cell);
5491 if (icon_view->priv->markup_column != -1)
5492 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5494 "markup", icon_view->priv->markup_column,
5497 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5499 "text", icon_view->priv->text_column,
5502 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5503 g_object_set (info->cell,
5504 "alignment", PANGO_ALIGN_CENTER,
5505 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5510 g_object_set (info->cell,
5511 "alignment", PANGO_ALIGN_LEFT,
5512 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5520 update_pixbuf_cell (GtkIconView *icon_view)
5522 GtkIconViewCellInfo *info;
5526 if (icon_view->priv->pixbuf_column == -1)
5528 if (icon_view->priv->pixbuf_cell != -1)
5530 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5531 icon_view->priv->text_cell--;
5533 info = g_list_nth_data (icon_view->priv->cell_list,
5534 icon_view->priv->pixbuf_cell);
5536 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5538 free_cell_info (info);
5540 icon_view->priv->n_cells--;
5541 icon_view->priv->pixbuf_cell = -1;
5546 if (icon_view->priv->pixbuf_cell == -1)
5548 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5550 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5551 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5554 if (info->cell == cell)
5556 icon_view->priv->pixbuf_cell = i;
5562 info = g_list_nth_data (icon_view->priv->cell_list,
5563 icon_view->priv->pixbuf_cell);
5565 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5567 "pixbuf", icon_view->priv->pixbuf_column,
5570 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5571 g_object_set (info->cell,
5576 g_object_set (info->cell,
5584 * gtk_icon_view_set_text_column:
5585 * @icon_view: A #GtkIconView.
5586 * @column: A column in the currently used model, or -1 to display no text
5588 * Sets the column with text for @icon_view to be @column. The text
5589 * column must be of type #G_TYPE_STRING.
5594 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5597 if (column == icon_view->priv->text_column)
5601 icon_view->priv->text_column = -1;
5604 if (icon_view->priv->model != NULL)
5608 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5610 g_return_if_fail (column_type == G_TYPE_STRING);
5613 icon_view->priv->text_column = column;
5616 gtk_icon_view_stop_editing (icon_view, TRUE);
5618 update_text_cell (icon_view);
5620 gtk_icon_view_invalidate_sizes (icon_view);
5621 gtk_icon_view_queue_layout (icon_view);
5623 g_object_notify (G_OBJECT (icon_view), "text-column");
5627 * gtk_icon_view_get_text_column:
5628 * @icon_view: A #GtkIconView.
5630 * Returns the column with text for @icon_view.
5632 * Returns: the text column, or -1 if it's unset.
5637 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5639 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5641 return icon_view->priv->text_column;
5645 * gtk_icon_view_set_markup_column:
5646 * @icon_view: A #GtkIconView.
5647 * @column: A column in the currently used model, or -1 to display no text
5649 * Sets the column with markup information for @icon_view to be
5650 * @column. The markup column must be of type #G_TYPE_STRING.
5651 * If the markup column is set to something, it overrides
5652 * the text column set by gtk_icon_view_set_text_column().
5657 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5660 if (column == icon_view->priv->markup_column)
5664 icon_view->priv->markup_column = -1;
5667 if (icon_view->priv->model != NULL)
5671 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5673 g_return_if_fail (column_type == G_TYPE_STRING);
5676 icon_view->priv->markup_column = column;
5679 gtk_icon_view_stop_editing (icon_view, TRUE);
5681 update_text_cell (icon_view);
5683 gtk_icon_view_invalidate_sizes (icon_view);
5684 gtk_icon_view_queue_layout (icon_view);
5686 g_object_notify (G_OBJECT (icon_view), "markup-column");
5690 * gtk_icon_view_get_markup_column:
5691 * @icon_view: A #GtkIconView.
5693 * Returns the column with markup text for @icon_view.
5695 * Returns: the markup column, or -1 if it's unset.
5700 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5702 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5704 return icon_view->priv->markup_column;
5708 * gtk_icon_view_set_pixbuf_column:
5709 * @icon_view: A #GtkIconView.
5710 * @column: A column in the currently used model, or -1 to disable
5712 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5713 * column must be of type #GDK_TYPE_PIXBUF
5718 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5721 if (column == icon_view->priv->pixbuf_column)
5725 icon_view->priv->pixbuf_column = -1;
5728 if (icon_view->priv->model != NULL)
5732 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5734 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5737 icon_view->priv->pixbuf_column = column;
5740 gtk_icon_view_stop_editing (icon_view, TRUE);
5742 update_pixbuf_cell (icon_view);
5744 gtk_icon_view_invalidate_sizes (icon_view);
5745 gtk_icon_view_queue_layout (icon_view);
5747 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5752 * gtk_icon_view_get_pixbuf_column:
5753 * @icon_view: A #GtkIconView.
5755 * Returns the column with pixbufs for @icon_view.
5757 * Returns: the pixbuf column, or -1 if it's unset.
5762 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5764 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5766 return icon_view->priv->pixbuf_column;
5770 * gtk_icon_view_select_path:
5771 * @icon_view: A #GtkIconView.
5772 * @path: The #GtkTreePath to be selected.
5774 * Selects the row at @path.
5779 gtk_icon_view_select_path (GtkIconView *icon_view,
5782 GtkIconViewItem *item = NULL;
5784 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5785 g_return_if_fail (icon_view->priv->model != NULL);
5786 g_return_if_fail (path != NULL);
5788 if (gtk_tree_path_get_depth (path) > 0)
5789 item = g_list_nth_data (icon_view->priv->items,
5790 gtk_tree_path_get_indices(path)[0]);
5793 gtk_icon_view_select_item (icon_view, item);
5797 * gtk_icon_view_unselect_path:
5798 * @icon_view: A #GtkIconView.
5799 * @path: The #GtkTreePath to be unselected.
5801 * Unselects the row at @path.
5806 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5809 GtkIconViewItem *item;
5811 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5812 g_return_if_fail (icon_view->priv->model != NULL);
5813 g_return_if_fail (path != NULL);
5815 item = g_list_nth_data (icon_view->priv->items,
5816 gtk_tree_path_get_indices(path)[0]);
5821 gtk_icon_view_unselect_item (icon_view, item);
5825 * gtk_icon_view_get_selected_items:
5826 * @icon_view: A #GtkIconView.
5828 * Creates a list of paths of all selected items. Additionally, if you are
5829 * planning on modifying the model after calling this function, you may
5830 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5831 * To do this, you can use gtk_tree_row_reference_new().
5833 * To free the return value, use:
5835 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5836 * g_list_free (list);
5839 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5844 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5847 GList *selected = NULL;
5849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5851 for (list = icon_view->priv->items; list != NULL; list = list->next)
5853 GtkIconViewItem *item = list->data;
5857 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5859 selected = g_list_prepend (selected, path);
5867 * gtk_icon_view_select_all:
5868 * @icon_view: A #GtkIconView.
5870 * Selects all the icons. @icon_view must has its selection mode set
5871 * to #GTK_SELECTION_MULTIPLE.
5876 gtk_icon_view_select_all (GtkIconView *icon_view)
5879 gboolean dirty = FALSE;
5881 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5883 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5886 for (items = icon_view->priv->items; items; items = items->next)
5888 GtkIconViewItem *item = items->data;
5890 if (!item->selected)
5893 item->selected = TRUE;
5894 gtk_icon_view_queue_draw_item (icon_view, item);
5899 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5903 * gtk_icon_view_unselect_all:
5904 * @icon_view: A #GtkIconView.
5906 * Unselects all the icons.
5911 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5913 gboolean dirty = FALSE;
5915 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5917 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5920 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5923 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5927 * gtk_icon_view_path_is_selected:
5928 * @icon_view: A #GtkIconView.
5929 * @path: A #GtkTreePath to check selection on.
5931 * Returns %TRUE if the icon pointed to by @path is currently
5932 * selected. If @path does not point to a valid location, %FALSE is returned.
5934 * Return value: %TRUE if @path is selected.
5939 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5942 GtkIconViewItem *item;
5944 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5945 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5946 g_return_val_if_fail (path != NULL, FALSE);
5948 item = g_list_nth_data (icon_view->priv->items,
5949 gtk_tree_path_get_indices(path)[0]);
5954 return item->selected;
5958 * gtk_icon_view_get_item_row:
5959 * @icon_view: a #GtkIconView
5960 * @path: the #GtkTreePath of the item
5962 * Gets the row in which the item @path is currently
5963 * displayed. Row numbers start at 0.
5965 * Returns: The row in which the item is displayed
5970 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5973 GtkIconViewItem *item;
5975 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5976 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5977 g_return_val_if_fail (path != NULL, -1);
5979 item = g_list_nth_data (icon_view->priv->items,
5980 gtk_tree_path_get_indices(path)[0]);
5989 * gtk_icon_view_get_item_column:
5990 * @icon_view: a #GtkIconView
5991 * @path: the #GtkTreePath of the item
5993 * Gets the column in which the item @path is currently
5994 * displayed. Column numbers start at 0.
5996 * Returns: The column in which the item is displayed
6001 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6004 GtkIconViewItem *item;
6006 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6007 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6008 g_return_val_if_fail (path != NULL, -1);
6010 item = g_list_nth_data (icon_view->priv->items,
6011 gtk_tree_path_get_indices(path)[0]);
6020 * gtk_icon_view_item_activated:
6021 * @icon_view: A #GtkIconView
6022 * @path: The #GtkTreePath to be activated
6024 * Activates the item determined by @path.
6029 gtk_icon_view_item_activated (GtkIconView *icon_view,
6032 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6033 g_return_if_fail (path != NULL);
6035 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6039 * gtk_icon_view_set_item_orientation:
6040 * @icon_view: a #GtkIconView
6041 * @orientation: the relative position of texts and icons
6043 * Sets the ::item-orientation property which determines whether the labels
6044 * are drawn beside the icons instead of below.
6049 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
6050 GtkOrientation orientation)
6052 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6054 if (icon_view->priv->item_orientation != orientation)
6056 icon_view->priv->item_orientation = orientation;
6058 gtk_icon_view_stop_editing (icon_view, TRUE);
6059 gtk_icon_view_invalidate_sizes (icon_view);
6060 gtk_icon_view_queue_layout (icon_view);
6062 update_text_cell (icon_view);
6063 update_pixbuf_cell (icon_view);
6065 g_object_notify (G_OBJECT (icon_view), "item-orientation");
6070 * gtk_icon_view_get_item_orientation:
6071 * @icon_view: a #GtkIconView
6073 * Returns the value of the ::item-orientation property which determines
6074 * whether the labels are drawn beside the icons instead of below.
6076 * Return value: the relative position of texts and icons
6081 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
6083 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6084 GTK_ORIENTATION_VERTICAL);
6086 return icon_view->priv->item_orientation;
6090 * gtk_icon_view_set_columns:
6091 * @icon_view: a #GtkIconView
6092 * @columns: the number of columns
6094 * Sets the ::columns property which determines in how
6095 * many columns the icons are arranged. If @columns is
6096 * -1, the number of columns will be chosen automatically
6097 * to fill the available area.
6102 gtk_icon_view_set_columns (GtkIconView *icon_view,
6105 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6107 if (icon_view->priv->columns != columns)
6109 icon_view->priv->columns = columns;
6111 gtk_icon_view_stop_editing (icon_view, TRUE);
6112 gtk_icon_view_queue_layout (icon_view);
6114 g_object_notify (G_OBJECT (icon_view), "columns");
6119 * gtk_icon_view_get_columns:
6120 * @icon_view: a #GtkIconView
6122 * Returns the value of the ::columns property.
6124 * Return value: the number of columns, or -1
6129 gtk_icon_view_get_columns (GtkIconView *icon_view)
6131 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6133 return icon_view->priv->columns;
6137 * gtk_icon_view_set_item_width:
6138 * @icon_view: a #GtkIconView
6139 * @item_width: the width for each item
6141 * Sets the ::item-width property which specifies the width
6142 * to use for each item. If it is set to -1, the icon view will
6143 * automatically determine a suitable item size.
6148 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6151 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6153 if (icon_view->priv->item_width != item_width)
6155 icon_view->priv->item_width = item_width;
6157 gtk_icon_view_stop_editing (icon_view, TRUE);
6158 gtk_icon_view_invalidate_sizes (icon_view);
6159 gtk_icon_view_queue_layout (icon_view);
6161 update_text_cell (icon_view);
6163 g_object_notify (G_OBJECT (icon_view), "item-width");
6168 * gtk_icon_view_get_item_width:
6169 * @icon_view: a #GtkIconView
6171 * Returns the value of the ::item-width property.
6173 * Return value: the width of a single item, or -1
6178 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6180 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6182 return icon_view->priv->item_width;
6187 * gtk_icon_view_set_spacing:
6188 * @icon_view: a #GtkIconView
6189 * @spacing: the spacing
6191 * Sets the ::spacing property which specifies the space
6192 * which is inserted between the cells (i.e. the icon and
6193 * the text) of an item.
6198 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6201 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6203 if (icon_view->priv->spacing != spacing)
6205 icon_view->priv->spacing = spacing;
6207 gtk_icon_view_stop_editing (icon_view, TRUE);
6208 gtk_icon_view_invalidate_sizes (icon_view);
6209 gtk_icon_view_queue_layout (icon_view);
6211 g_object_notify (G_OBJECT (icon_view), "spacing");
6216 * gtk_icon_view_get_spacing:
6217 * @icon_view: a #GtkIconView
6219 * Returns the value of the ::spacing property.
6221 * Return value: the space between cells
6226 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6228 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6230 return icon_view->priv->spacing;
6234 * gtk_icon_view_set_row_spacing:
6235 * @icon_view: a #GtkIconView
6236 * @row_spacing: the row spacing
6238 * Sets the ::row-spacing property which specifies the space
6239 * which is inserted between the rows of the icon view.
6244 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6247 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6249 if (icon_view->priv->row_spacing != row_spacing)
6251 icon_view->priv->row_spacing = row_spacing;
6253 gtk_icon_view_stop_editing (icon_view, TRUE);
6254 gtk_icon_view_invalidate_sizes (icon_view);
6255 gtk_icon_view_queue_layout (icon_view);
6257 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6262 * gtk_icon_view_get_row_spacing:
6263 * @icon_view: a #GtkIconView
6265 * Returns the value of the ::row-spacing property.
6267 * Return value: the space between rows
6272 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6274 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6276 return icon_view->priv->row_spacing;
6280 * gtk_icon_view_set_column_spacing:
6281 * @icon_view: a #GtkIconView
6282 * @column_spacing: the column spacing
6284 * Sets the ::column-spacing property which specifies the space
6285 * which is inserted between the columns of the icon view.
6290 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6291 gint column_spacing)
6293 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6295 if (icon_view->priv->column_spacing != column_spacing)
6297 icon_view->priv->column_spacing = column_spacing;
6299 gtk_icon_view_stop_editing (icon_view, TRUE);
6300 gtk_icon_view_invalidate_sizes (icon_view);
6301 gtk_icon_view_queue_layout (icon_view);
6303 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6308 * gtk_icon_view_get_column_spacing:
6309 * @icon_view: a #GtkIconView
6311 * Returns the value of the ::column-spacing property.
6313 * Return value: the space between columns
6318 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6320 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6322 return icon_view->priv->column_spacing;
6326 * gtk_icon_view_set_margin:
6327 * @icon_view: a #GtkIconView
6328 * @margin: the margin
6330 * Sets the ::margin property which specifies the space
6331 * which is inserted at the top, bottom, left and right
6337 gtk_icon_view_set_margin (GtkIconView *icon_view,
6340 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6342 if (icon_view->priv->margin != margin)
6344 icon_view->priv->margin = margin;
6346 gtk_icon_view_stop_editing (icon_view, TRUE);
6347 gtk_icon_view_invalidate_sizes (icon_view);
6348 gtk_icon_view_queue_layout (icon_view);
6350 g_object_notify (G_OBJECT (icon_view), "margin");
6355 * gtk_icon_view_get_margin:
6356 * @icon_view: a #GtkIconView
6358 * Returns the value of the ::margin property.
6360 * Return value: the space at the borders
6365 gtk_icon_view_get_margin (GtkIconView *icon_view)
6367 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6369 return icon_view->priv->margin;
6373 * gtk_icon_view_set_item_padding:
6374 * @icon_view: a #GtkIconView
6375 * @item_padding: the item padding
6377 * Sets the #GtkIconView:item-padding property which specifies the padding
6378 * around each of the icon view's items.
6383 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6386 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6388 if (icon_view->priv->item_padding != item_padding)
6390 icon_view->priv->item_padding = item_padding;
6392 gtk_icon_view_stop_editing (icon_view, TRUE);
6393 gtk_icon_view_invalidate_sizes (icon_view);
6394 gtk_icon_view_queue_layout (icon_view);
6396 g_object_notify (G_OBJECT (icon_view), "item-padding");
6401 * gtk_icon_view_get_item_padding:
6402 * @icon_view: a #GtkIconView
6404 * Returns the value of the ::item-padding property.
6406 * Return value: the padding around items
6411 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6413 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6415 return icon_view->priv->item_padding;
6418 /* Get/set whether drag_motion requested the drag data and
6419 * drag_data_received should thus not actually insert the data,
6420 * since the data doesn't result from a drop.
6423 set_status_pending (GdkDragContext *context,
6424 GdkDragAction suggested_action)
6426 g_object_set_data (G_OBJECT (context),
6427 I_("gtk-icon-view-status-pending"),
6428 GINT_TO_POINTER (suggested_action));
6431 static GdkDragAction
6432 get_status_pending (GdkDragContext *context)
6434 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6435 "gtk-icon-view-status-pending"));
6439 unset_reorderable (GtkIconView *icon_view)
6441 if (icon_view->priv->reorderable)
6443 icon_view->priv->reorderable = FALSE;
6444 g_object_notify (G_OBJECT (icon_view), "reorderable");
6449 set_source_row (GdkDragContext *context,
6450 GtkTreeModel *model,
6451 GtkTreePath *source_row)
6454 g_object_set_data_full (G_OBJECT (context),
6455 I_("gtk-icon-view-source-row"),
6456 gtk_tree_row_reference_new (model, source_row),
6457 (GDestroyNotify) gtk_tree_row_reference_free);
6459 g_object_set_data_full (G_OBJECT (context),
6460 I_("gtk-icon-view-source-row"),
6465 get_source_row (GdkDragContext *context)
6467 GtkTreeRowReference *ref;
6469 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6472 return gtk_tree_row_reference_get_path (ref);
6479 GtkTreeRowReference *dest_row;
6480 gboolean empty_view_drop;
6481 gboolean drop_append_mode;
6485 dest_row_free (gpointer data)
6487 DestRow *dr = (DestRow *)data;
6489 gtk_tree_row_reference_free (dr->dest_row);
6494 set_dest_row (GdkDragContext *context,
6495 GtkTreeModel *model,
6496 GtkTreePath *dest_row,
6497 gboolean empty_view_drop,
6498 gboolean drop_append_mode)
6504 g_object_set_data_full (G_OBJECT (context),
6505 I_("gtk-icon-view-dest-row"),
6510 dr = g_new0 (DestRow, 1);
6512 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6513 dr->empty_view_drop = empty_view_drop;
6514 dr->drop_append_mode = drop_append_mode;
6515 g_object_set_data_full (G_OBJECT (context),
6516 I_("gtk-icon-view-dest-row"),
6517 dr, (GDestroyNotify) dest_row_free);
6521 get_dest_row (GdkDragContext *context)
6525 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6529 GtkTreePath *path = NULL;
6532 path = gtk_tree_row_reference_get_path (dr->dest_row);
6533 else if (dr->empty_view_drop)
6534 path = gtk_tree_path_new_from_indices (0, -1);
6538 if (path && dr->drop_append_mode)
6539 gtk_tree_path_next (path);
6548 check_model_dnd (GtkTreeModel *model,
6549 GType required_iface,
6550 const gchar *signal)
6552 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6554 g_warning ("You must override the default '%s' handler "
6555 "on GtkIconView when using models that don't support "
6556 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6557 "is to connect to '%s' and call "
6558 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6559 "the default handler from running. Look at the source code "
6560 "for the default handler in gtkiconview.c to get an idea what "
6561 "your handler should do. (gtkiconview.c is in the GTK+ source "
6562 "code.) If you're using GTK+ from a language other than C, "
6563 "there may be a more natural way to override default handlers, e.g. via derivation.",
6564 signal, g_type_name (required_iface), signal);
6572 remove_scroll_timeout (GtkIconView *icon_view)
6574 if (icon_view->priv->scroll_timeout_id != 0)
6576 g_source_remove (icon_view->priv->scroll_timeout_id);
6578 icon_view->priv->scroll_timeout_id = 0;
6583 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6586 gint px, py, x, y, width, height;
6587 gint hoffset, voffset;
6589 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6591 gdk_window_get_pointer (window, &px, &py, NULL);
6592 gdk_window_get_geometry (window, &x, &y, &width, &height, NULL);
6594 /* see if we are near the edge. */
6595 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6597 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6599 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6601 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6604 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6605 icon_view->priv->vadjustment->value + voffset);
6608 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6609 icon_view->priv->hadjustment->value + hoffset);
6614 drag_scroll_timeout (gpointer data)
6616 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6618 gtk_icon_view_autoscroll (icon_view);
6625 set_destination (GtkIconView *icon_view,
6626 GdkDragContext *context,
6629 GdkDragAction *suggested_action,
6633 GtkTreePath *path = NULL;
6634 GtkIconViewDropPosition pos;
6635 GtkIconViewDropPosition old_pos;
6636 GtkTreePath *old_dest_path = NULL;
6637 gboolean can_drop = FALSE;
6639 widget = GTK_WIDGET (icon_view);
6641 *suggested_action = 0;
6644 if (!icon_view->priv->dest_set)
6646 /* someone unset us as a drag dest, note that if
6647 * we return FALSE drag_leave isn't called
6650 gtk_icon_view_set_drag_dest_item (icon_view,
6652 GTK_ICON_VIEW_DROP_LEFT);
6654 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6656 return FALSE; /* no longer a drop site */
6659 *target = gtk_drag_dest_find_target (widget, context,
6660 gtk_drag_dest_get_target_list (widget));
6661 if (*target == GDK_NONE)
6664 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6667 GtkTreeModel *model;
6669 /* the row got dropped on empty space, let's setup a special case
6673 gtk_tree_path_free (path);
6675 model = gtk_icon_view_get_model (icon_view);
6677 n_children = gtk_tree_model_iter_n_children (model, NULL);
6680 pos = GTK_ICON_VIEW_DROP_BELOW;
6681 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6685 pos = GTK_ICON_VIEW_DROP_ABOVE;
6686 path = gtk_tree_path_new_from_indices (0, -1);
6696 gtk_icon_view_get_drag_dest_item (icon_view,
6701 gtk_tree_path_free (old_dest_path);
6703 if (TRUE /* FIXME if the location droppable predicate */)
6711 GtkWidget *source_widget;
6713 *suggested_action = context->suggested_action;
6714 source_widget = gtk_drag_get_source_widget (context);
6716 if (source_widget == widget)
6718 /* Default to MOVE, unless the user has
6719 * pressed ctrl or shift to affect available actions
6721 if ((context->actions & GDK_ACTION_MOVE) != 0)
6722 *suggested_action = GDK_ACTION_MOVE;
6725 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6730 /* can't drop here */
6731 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6733 GTK_ICON_VIEW_DROP_LEFT);
6737 gtk_tree_path_free (path);
6743 get_logical_destination (GtkIconView *icon_view,
6744 gboolean *drop_append_mode)
6746 /* adjust path to point to the row the drop goes in front of */
6747 GtkTreePath *path = NULL;
6748 GtkIconViewDropPosition pos;
6750 *drop_append_mode = FALSE;
6752 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6757 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6758 pos == GTK_ICON_VIEW_DROP_BELOW)
6761 GtkTreeModel *model = icon_view->priv->model;
6763 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6764 !gtk_tree_model_iter_next (model, &iter))
6765 *drop_append_mode = TRUE;
6768 *drop_append_mode = FALSE;
6769 gtk_tree_path_next (path);
6777 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6778 GdkEventMotion *event)
6780 GtkWidget *widget = GTK_WIDGET (icon_view);
6781 GdkDragContext *context;
6782 GtkTreePath *path = NULL;
6784 GtkTreeModel *model;
6785 gboolean retval = FALSE;
6787 if (!icon_view->priv->source_set)
6790 if (icon_view->priv->pressed_button < 0)
6793 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6794 icon_view->priv->press_start_x,
6795 icon_view->priv->press_start_y,
6796 event->x, event->y))
6799 model = gtk_icon_view_get_model (icon_view);
6804 button = icon_view->priv->pressed_button;
6805 icon_view->priv->pressed_button = -1;
6807 path = gtk_icon_view_get_path_at_pos (icon_view,
6808 icon_view->priv->press_start_x,
6809 icon_view->priv->press_start_y);
6814 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6815 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6819 /* FIXME Check whether we're a start button, if not return FALSE and
6823 /* Now we can begin the drag */
6827 context = gtk_drag_begin (widget,
6828 gtk_drag_source_get_target_list (widget),
6829 icon_view->priv->source_actions,
6833 set_source_row (context, model, path);
6837 gtk_tree_path_free (path);
6842 /* Source side drag signals */
6844 gtk_icon_view_drag_begin (GtkWidget *widget,
6845 GdkDragContext *context)
6847 GtkIconView *icon_view;
6848 GtkIconViewItem *item;
6849 cairo_surface_t *icon;
6853 icon_view = GTK_ICON_VIEW (widget);
6855 /* if the user uses a custom DnD impl, we don't set the icon here */
6856 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6859 item = gtk_icon_view_get_item_at_coords (icon_view,
6860 icon_view->priv->press_start_x,
6861 icon_view->priv->press_start_y,
6865 g_return_if_fail (item != NULL);
6867 x = icon_view->priv->press_start_x - item->x + 1;
6868 y = icon_view->priv->press_start_y - item->y + 1;
6870 path = gtk_tree_path_new_from_indices (item->index, -1);
6871 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6872 gtk_tree_path_free (path);
6874 cairo_surface_set_device_offset (icon, -x, -y);
6876 gtk_drag_set_icon_surface (context, icon);
6878 cairo_surface_destroy (icon);
6882 gtk_icon_view_drag_end (GtkWidget *widget,
6883 GdkDragContext *context)
6889 gtk_icon_view_drag_data_get (GtkWidget *widget,
6890 GdkDragContext *context,
6891 GtkSelectionData *selection_data,
6895 GtkIconView *icon_view;
6896 GtkTreeModel *model;
6897 GtkTreePath *source_row;
6899 icon_view = GTK_ICON_VIEW (widget);
6900 model = gtk_icon_view_get_model (icon_view);
6905 if (!icon_view->priv->source_set)
6908 source_row = get_source_row (context);
6910 if (source_row == NULL)
6913 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6914 * any model; for DragSource models there are some other targets
6918 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6919 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6924 /* If drag_data_get does nothing, try providing row data. */
6925 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6926 gtk_tree_set_row_drag_data (selection_data,
6931 gtk_tree_path_free (source_row);
6935 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6936 GdkDragContext *context)
6938 GtkTreeModel *model;
6939 GtkIconView *icon_view;
6940 GtkTreePath *source_row;
6942 icon_view = GTK_ICON_VIEW (widget);
6943 model = gtk_icon_view_get_model (icon_view);
6945 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6948 if (!icon_view->priv->source_set)
6951 source_row = get_source_row (context);
6953 if (source_row == NULL)
6956 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6959 gtk_tree_path_free (source_row);
6961 set_source_row (context, NULL, NULL);
6964 /* Target side drag signals */
6966 gtk_icon_view_drag_leave (GtkWidget *widget,
6967 GdkDragContext *context,
6970 GtkIconView *icon_view;
6972 icon_view = GTK_ICON_VIEW (widget);
6974 /* unset any highlight row */
6975 gtk_icon_view_set_drag_dest_item (icon_view,
6977 GTK_ICON_VIEW_DROP_LEFT);
6979 remove_scroll_timeout (icon_view);
6983 gtk_icon_view_drag_motion (GtkWidget *widget,
6984 GdkDragContext *context,
6989 GtkTreePath *path = NULL;
6990 GtkIconViewDropPosition pos;
6991 GtkIconView *icon_view;
6992 GdkDragAction suggested_action = 0;
6996 icon_view = GTK_ICON_VIEW (widget);
6998 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7001 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7003 /* we only know this *after* set_desination_row */
7004 empty = icon_view->priv->empty_view_drop;
7006 if (path == NULL && !empty)
7008 /* Can't drop here. */
7009 gdk_drag_status (context, 0, time);
7013 if (icon_view->priv->scroll_timeout_id == 0)
7015 icon_view->priv->scroll_timeout_id =
7016 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7019 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7021 /* Request data so we can use the source row when
7022 * determining whether to accept the drop
7024 set_status_pending (context, suggested_action);
7025 gtk_drag_get_data (widget, context, target, time);
7029 set_status_pending (context, 0);
7030 gdk_drag_status (context, suggested_action, time);
7035 gtk_tree_path_free (path);
7041 gtk_icon_view_drag_drop (GtkWidget *widget,
7042 GdkDragContext *context,
7047 GtkIconView *icon_view;
7049 GdkDragAction suggested_action = 0;
7050 GdkAtom target = GDK_NONE;
7051 GtkTreeModel *model;
7052 gboolean drop_append_mode;
7054 icon_view = GTK_ICON_VIEW (widget);
7055 model = gtk_icon_view_get_model (icon_view);
7057 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7059 if (!icon_view->priv->dest_set)
7062 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7065 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7068 path = get_logical_destination (icon_view, &drop_append_mode);
7070 if (target != GDK_NONE && path != NULL)
7072 /* in case a motion had requested drag data, change things so we
7073 * treat drag data receives as a drop.
7075 set_status_pending (context, 0);
7076 set_dest_row (context, model, path,
7077 icon_view->priv->empty_view_drop, drop_append_mode);
7081 gtk_tree_path_free (path);
7083 /* Unset this thing */
7084 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7086 if (target != GDK_NONE)
7088 gtk_drag_get_data (widget, context, target, time);
7096 gtk_icon_view_drag_data_received (GtkWidget *widget,
7097 GdkDragContext *context,
7100 GtkSelectionData *selection_data,
7105 gboolean accepted = FALSE;
7106 GtkTreeModel *model;
7107 GtkIconView *icon_view;
7108 GtkTreePath *dest_row;
7109 GdkDragAction suggested_action;
7110 gboolean drop_append_mode;
7112 icon_view = GTK_ICON_VIEW (widget);
7113 model = gtk_icon_view_get_model (icon_view);
7115 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7118 if (!icon_view->priv->dest_set)
7121 suggested_action = get_status_pending (context);
7123 if (suggested_action)
7125 /* We are getting this data due to a request in drag_motion,
7126 * rather than due to a request in drag_drop, so we are just
7127 * supposed to call drag_status, not actually paste in the
7130 path = get_logical_destination (icon_view, &drop_append_mode);
7133 suggested_action = 0;
7135 if (suggested_action)
7137 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7140 suggested_action = 0;
7143 gdk_drag_status (context, suggested_action, time);
7146 gtk_tree_path_free (path);
7148 /* If you can't drop, remove user drop indicator until the next motion */
7149 if (suggested_action == 0)
7150 gtk_icon_view_set_drag_dest_item (icon_view,
7152 GTK_ICON_VIEW_DROP_LEFT);
7157 dest_row = get_dest_row (context);
7159 if (dest_row == NULL)
7162 if (selection_data->length >= 0)
7164 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7170 gtk_drag_finish (context,
7172 (context->action == GDK_ACTION_MOVE),
7175 gtk_tree_path_free (dest_row);
7178 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7181 /* Drag-and-Drop support */
7183 * gtk_icon_view_enable_model_drag_source:
7184 * @icon_view: a #GtkIconTreeView
7185 * @start_button_mask: Mask of allowed buttons to start drag
7186 * @targets: the table of targets that the drag will support
7187 * @n_targets: the number of items in @targets
7188 * @actions: the bitmask of possible actions for a drag from this
7191 * Turns @icon_view into a drag source for automatic DND. Calling this
7192 * method sets #GtkIconView:reorderable to %FALSE.
7197 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7198 GdkModifierType start_button_mask,
7199 const GtkTargetEntry *targets,
7201 GdkDragAction actions)
7203 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7205 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7207 icon_view->priv->start_button_mask = start_button_mask;
7208 icon_view->priv->source_actions = actions;
7210 icon_view->priv->source_set = TRUE;
7212 unset_reorderable (icon_view);
7216 * gtk_icon_view_enable_model_drag_dest:
7217 * @icon_view: a #GtkIconView
7218 * @targets: the table of targets that the drag will support
7219 * @n_targets: the number of items in @targets
7220 * @actions: the bitmask of possible actions for a drag to this
7223 * Turns @icon_view into a drop destination for automatic DND. Calling this
7224 * method sets #GtkIconView:reorderable to %FALSE.
7229 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7230 const GtkTargetEntry *targets,
7232 GdkDragAction actions)
7234 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7236 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7238 icon_view->priv->dest_actions = actions;
7240 icon_view->priv->dest_set = TRUE;
7242 unset_reorderable (icon_view);
7246 * gtk_icon_view_unset_model_drag_source:
7247 * @icon_view: a #GtkIconView
7249 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7250 * method sets #GtkIconView:reorderable to %FALSE.
7255 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7257 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7259 if (icon_view->priv->source_set)
7261 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7262 icon_view->priv->source_set = FALSE;
7265 unset_reorderable (icon_view);
7269 * gtk_icon_view_unset_model_drag_dest:
7270 * @icon_view: a #GtkIconView
7272 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7273 * method sets #GtkIconView:reorderable to %FALSE.
7278 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7280 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7282 if (icon_view->priv->dest_set)
7284 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7285 icon_view->priv->dest_set = FALSE;
7288 unset_reorderable (icon_view);
7291 /* These are useful to implement your own custom stuff. */
7293 * gtk_icon_view_set_drag_dest_item:
7294 * @icon_view: a #GtkIconView
7295 * @path: (allow-none): The path of the item to highlight, or %NULL.
7296 * @pos: Specifies where to drop, relative to the item
7298 * Sets the item that is highlighted for feedback.
7303 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7305 GtkIconViewDropPosition pos)
7307 /* Note; this function is exported to allow a custom DND
7308 * implementation, so it can't touch TreeViewDragInfo
7311 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7313 if (icon_view->priv->dest_item)
7315 GtkTreePath *current_path;
7316 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7317 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7318 icon_view->priv->dest_item = NULL;
7320 gtk_icon_view_queue_draw_path (icon_view, current_path);
7321 gtk_tree_path_free (current_path);
7324 /* special case a drop on an empty model */
7325 icon_view->priv->empty_view_drop = FALSE;
7326 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7327 && gtk_tree_path_get_depth (path) == 1
7328 && gtk_tree_path_get_indices (path)[0] == 0)
7332 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7335 if (n_children == 0)
7336 icon_view->priv->empty_view_drop = TRUE;
7339 icon_view->priv->dest_pos = pos;
7343 icon_view->priv->dest_item =
7344 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7345 icon_view->priv->model, path);
7347 gtk_icon_view_queue_draw_path (icon_view, path);
7352 * gtk_icon_view_get_drag_dest_item:
7353 * @icon_view: a #GtkIconView
7354 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7355 * @pos: (allow-none): Return location for the drop position, or %NULL
7357 * Gets information about the item that is highlighted for feedback.
7362 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7364 GtkIconViewDropPosition *pos)
7366 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7370 if (icon_view->priv->dest_item)
7371 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7377 *pos = icon_view->priv->dest_pos;
7381 * gtk_icon_view_get_dest_item_at_pos:
7382 * @icon_view: a #GtkIconView
7383 * @drag_x: the position to determine the destination item for
7384 * @drag_y: the position to determine the destination item for
7385 * @path: (allow-none): Return location for the path of the item, or %NULL.
7386 * @pos: (allow-none): Return location for the drop position, or %NULL
7388 * Determines the destination item for a given position.
7390 * Return value: whether there is an item at the given position.
7395 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7399 GtkIconViewDropPosition *pos)
7401 GtkIconViewItem *item;
7403 /* Note; this function is exported to allow a custom DND
7404 * implementation, so it can't touch TreeViewDragInfo
7407 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7408 g_return_val_if_fail (drag_x >= 0, FALSE);
7409 g_return_val_if_fail (drag_y >= 0, FALSE);
7410 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7416 item = gtk_icon_view_get_item_at_coords (icon_view,
7417 drag_x + icon_view->priv->hadjustment->value,
7418 drag_y + icon_view->priv->vadjustment->value,
7425 *path = gtk_tree_path_new_from_indices (item->index, -1);
7429 if (drag_x < item->x + item->width / 4)
7430 *pos = GTK_ICON_VIEW_DROP_LEFT;
7431 else if (drag_x > item->x + item->width * 3 / 4)
7432 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7433 else if (drag_y < item->y + item->height / 4)
7434 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7435 else if (drag_y > item->y + item->height * 3 / 4)
7436 *pos = GTK_ICON_VIEW_DROP_BELOW;
7438 *pos = GTK_ICON_VIEW_DROP_INTO;
7445 * gtk_icon_view_create_drag_icon:
7446 * @icon_view: a #GtkIconView
7447 * @path: a #GtkTreePath in @icon_view
7449 * Creates a #cairo_surface_t representation of the item at @path.
7450 * This image is used for a drag icon.
7452 * Return value: (transfer full) a newly-allocated surface of the drag icon.
7457 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7462 cairo_surface_t *surface;
7466 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7467 g_return_val_if_fail (path != NULL, NULL);
7469 widget = GTK_WIDGET (icon_view);
7471 if (!gtk_widget_get_realized (widget))
7474 index = gtk_tree_path_get_indices (path)[0];
7476 for (l = icon_view->priv->items; l; l = l->next)
7478 GtkIconViewItem *item = l->data;
7480 if (index == item->index)
7482 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7483 CAIRO_CONTENT_COLOR,
7487 cr = cairo_create (surface);
7488 cairo_set_line_width (cr, 1.);
7490 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
7491 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7496 cairo_rectangle (cr, 0, 0, item->width, item->height);
7499 gtk_icon_view_paint_item (icon_view, cr, item, 1, 1, FALSE);
7503 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7504 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7517 * gtk_icon_view_get_reorderable:
7518 * @icon_view: a #GtkIconView
7520 * Retrieves whether the user can reorder the list via drag-and-drop.
7521 * See gtk_icon_view_set_reorderable().
7523 * Return value: %TRUE if the list can be reordered.
7528 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7530 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7532 return icon_view->priv->reorderable;
7535 static const GtkTargetEntry item_targets[] = {
7536 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7541 * gtk_icon_view_set_reorderable:
7542 * @icon_view: A #GtkIconView.
7543 * @reorderable: %TRUE, if the list of items can be reordered.
7545 * This function is a convenience function to allow you to reorder models that
7546 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7547 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7548 * the user can reorder the model by dragging and dropping rows. The
7549 * developer can listen to these changes by connecting to the model's
7550 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7551 * the icon view as a drag source and destination. Therefore, drag and
7552 * drop can not be used in a reorderable view for any other purpose.
7554 * This function does not give you any degree of control over the order -- any
7555 * reordering is allowed. If more control is needed, you should probably
7556 * handle drag and drop manually.
7561 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7562 gboolean reorderable)
7564 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7566 reorderable = reorderable != FALSE;
7568 if (icon_view->priv->reorderable == reorderable)
7573 gtk_icon_view_enable_model_drag_source (icon_view,
7576 G_N_ELEMENTS (item_targets),
7578 gtk_icon_view_enable_model_drag_dest (icon_view,
7580 G_N_ELEMENTS (item_targets),
7585 gtk_icon_view_unset_model_drag_source (icon_view);
7586 gtk_icon_view_unset_model_drag_dest (icon_view);
7589 icon_view->priv->reorderable = reorderable;
7591 g_object_notify (G_OBJECT (icon_view), "reorderable");
7595 /* Accessibility Support */
7597 static gpointer accessible_parent_class;
7598 static gpointer accessible_item_parent_class;
7599 static GQuark accessible_private_data_quark = 0;
7601 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7602 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7603 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7605 static GType gtk_icon_view_item_accessible_get_type (void);
7616 GtkIconViewItem *item;
7620 AtkStateSet *state_set;
7624 GtkTextBuffer *text_buffer;
7626 gchar *action_descriptions[LAST_ACTION];
7627 gchar *image_description;
7628 guint action_idle_handler;
7629 } GtkIconViewItemAccessible;
7631 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7637 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7642 typedef struct _GtkIconViewItemAccessibleClass
7644 AtkObjectClass parent_class;
7646 } GtkIconViewItemAccessibleClass;
7648 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7651 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7653 GtkIconViewItemAccessible *item;
7654 GtkIconView *icon_view;
7657 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7658 item->action_idle_handler = 0;
7660 if (item->widget != NULL)
7662 icon_view = GTK_ICON_VIEW (item->widget);
7663 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7664 gtk_icon_view_item_activated (icon_view, path);
7665 gtk_tree_path_free (path);
7672 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7675 GtkIconViewItemAccessible *item;
7677 if (i < 0 || i >= LAST_ACTION)
7680 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7682 if (!GTK_IS_ICON_VIEW (item->widget))
7685 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7690 case ACTION_ACTIVATE:
7691 if (!item->action_idle_handler)
7692 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7695 g_assert_not_reached ();
7703 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7708 static const gchar *
7709 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7712 GtkIconViewItemAccessible *item;
7714 if (i < 0 || i >= LAST_ACTION)
7717 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7719 if (item->action_descriptions[i])
7720 return item->action_descriptions[i];
7722 return gtk_icon_view_item_accessible_action_descriptions[i];
7725 static const gchar *
7726 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7729 if (i < 0 || i >= LAST_ACTION)
7732 return gtk_icon_view_item_accessible_action_names[i];
7736 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7738 const gchar *description)
7740 GtkIconViewItemAccessible *item;
7742 if (i < 0 || i >= LAST_ACTION)
7745 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7747 g_free (item->action_descriptions[i]);
7749 item->action_descriptions[i] = g_strdup (description);
7755 atk_action_item_interface_init (AtkActionIface *iface)
7757 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7758 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7759 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7760 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7761 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7764 static const gchar *
7765 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7767 GtkIconViewItemAccessible *item;
7769 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7771 return item->image_description;
7775 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7776 const gchar *description)
7778 GtkIconViewItemAccessible *item;
7780 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7782 g_free (item->image_description);
7783 item->image_description = g_strdup (description);
7789 get_pixbuf_box (GtkIconView *icon_view,
7790 GtkIconViewItem *item,
7795 for (l = icon_view->priv->cell_list; l; l = l->next)
7797 GtkIconViewCellInfo *info = l->data;
7799 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7801 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7811 get_text (GtkIconView *icon_view,
7812 GtkIconViewItem *item)
7817 for (l = icon_view->priv->cell_list; l; l = l->next)
7819 GtkIconViewCellInfo *info = l->data;
7821 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7823 g_object_get (info->cell, "text", &text, NULL);
7833 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7837 GtkIconViewItemAccessible *item;
7840 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7842 if (!GTK_IS_ICON_VIEW (item->widget))
7845 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7848 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7851 *height = box.height;
7856 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7859 AtkCoordType coord_type)
7861 GtkIconViewItemAccessible *item;
7864 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7866 if (!GTK_IS_ICON_VIEW (item->widget))
7869 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7872 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7874 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7876 *x+= box.x - item->item->x;
7877 *y+= box.y - item->item->y;
7883 atk_image_item_interface_init (AtkImageIface *iface)
7885 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7886 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7887 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7888 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7892 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7896 GtkIconViewItemAccessible *item;
7897 GtkTextIter start, end;
7898 GtkTextBuffer *buffer;
7900 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7902 if (!GTK_IS_ICON_VIEW (item->widget))
7905 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7908 buffer = item->text_buffer;
7909 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7911 gtk_text_buffer_get_end_iter (buffer, &end);
7913 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7915 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7919 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7922 GtkIconViewItemAccessible *item;
7923 GtkTextIter start, end;
7924 GtkTextBuffer *buffer;
7928 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7930 if (!GTK_IS_ICON_VIEW (item->widget))
7933 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7936 buffer = item->text_buffer;
7937 if (offset >= gtk_text_buffer_get_char_count (buffer))
7940 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7942 gtk_text_iter_forward_char (&end);
7943 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7944 unichar = g_utf8_get_char (string);
7952 get_pango_text_offsets (PangoLayout *layout,
7953 GtkTextBuffer *buffer,
7955 AtkTextBoundary boundary_type,
7959 GtkTextIter *start_iter,
7960 GtkTextIter *end_iter)
7962 PangoLayoutIter *iter;
7963 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7964 gint index, start_index, end_index;
7966 gboolean found = FALSE;
7968 text = pango_layout_get_text (layout);
7969 index = g_utf8_offset_to_pointer (text, offset) - text;
7970 iter = pango_layout_get_iter (layout);
7973 line = pango_layout_iter_get_line_readonly (iter);
7974 start_index = line->start_index;
7975 end_index = start_index + line->length;
7977 if (index >= start_index && index <= end_index)
7980 * Found line for offset
7986 * We want the previous line
7990 switch (boundary_type)
7992 case ATK_TEXT_BOUNDARY_LINE_START:
7993 end_index = start_index;
7994 start_index = prev_line->start_index;
7996 case ATK_TEXT_BOUNDARY_LINE_END:
7998 start_index = prev_prev_line->start_index +
7999 prev_prev_line->length;
8000 end_index = prev_line->start_index + prev_line->length;
8003 g_assert_not_reached();
8007 start_index = end_index = 0;
8010 switch (boundary_type)
8012 case ATK_TEXT_BOUNDARY_LINE_START:
8013 if (pango_layout_iter_next_line (iter))
8014 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8016 case ATK_TEXT_BOUNDARY_LINE_END:
8018 start_index = prev_line->start_index +
8022 g_assert_not_reached();
8027 * We want the next line
8029 if (pango_layout_iter_next_line (iter))
8031 line = pango_layout_iter_get_line_readonly (iter);
8032 switch (boundary_type)
8034 case ATK_TEXT_BOUNDARY_LINE_START:
8035 start_index = line->start_index;
8036 if (pango_layout_iter_next_line (iter))
8037 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8039 end_index = start_index + line->length;
8041 case ATK_TEXT_BOUNDARY_LINE_END:
8042 start_index = end_index;
8043 end_index = line->start_index + line->length;
8046 g_assert_not_reached();
8050 start_index = end_index;
8056 prev_prev_line = prev_line;
8059 while (pango_layout_iter_next_line (iter));
8063 start_index = prev_line->start_index + prev_line->length;
8064 end_index = start_index;
8066 pango_layout_iter_free (iter);
8067 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8068 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8070 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8071 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8076 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8078 AtkTextBoundary boundary_type,
8082 GtkIconViewItemAccessible *item;
8083 GtkTextIter start, end;
8084 GtkTextBuffer *buffer;
8086 GtkIconView *icon_view;
8089 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8091 if (!GTK_IS_ICON_VIEW (item->widget))
8094 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8097 buffer = item->text_buffer;
8099 if (!gtk_text_buffer_get_char_count (buffer))
8103 return g_strdup ("");
8105 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8109 switch (boundary_type)
8111 case ATK_TEXT_BOUNDARY_CHAR:
8112 gtk_text_iter_backward_char(&start);
8114 case ATK_TEXT_BOUNDARY_WORD_START:
8115 if (!gtk_text_iter_starts_word (&start))
8116 gtk_text_iter_backward_word_start (&start);
8118 gtk_text_iter_backward_word_start(&start);
8120 case ATK_TEXT_BOUNDARY_WORD_END:
8121 if (gtk_text_iter_inside_word (&start) &&
8122 !gtk_text_iter_starts_word (&start))
8123 gtk_text_iter_backward_word_start (&start);
8124 while (!gtk_text_iter_ends_word (&start))
8126 if (!gtk_text_iter_backward_char (&start))
8130 gtk_text_iter_backward_word_start(&start);
8131 while (!gtk_text_iter_ends_word (&start))
8133 if (!gtk_text_iter_backward_char (&start))
8137 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8138 if (!gtk_text_iter_starts_sentence (&start))
8139 gtk_text_iter_backward_sentence_start (&start);
8141 gtk_text_iter_backward_sentence_start (&start);
8143 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8144 if (gtk_text_iter_inside_sentence (&start) &&
8145 !gtk_text_iter_starts_sentence (&start))
8146 gtk_text_iter_backward_sentence_start (&start);
8147 while (!gtk_text_iter_ends_sentence (&start))
8149 if (!gtk_text_iter_backward_char (&start))
8153 gtk_text_iter_backward_sentence_start (&start);
8154 while (!gtk_text_iter_ends_sentence (&start))
8156 if (!gtk_text_iter_backward_char (&start))
8160 case ATK_TEXT_BOUNDARY_LINE_START:
8161 case ATK_TEXT_BOUNDARY_LINE_END:
8163 icon_view = GTK_ICON_VIEW (item->widget);
8164 /* FIXME we probably have to use GailTextCell to salvage this */
8165 gtk_icon_view_update_item_text (icon_view, item->item);
8166 get_pango_text_offsets (icon_view->priv->layout,
8179 *start_offset = gtk_text_iter_get_offset (&start);
8180 *end_offset = gtk_text_iter_get_offset (&end);
8182 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8186 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8188 AtkTextBoundary boundary_type,
8192 GtkIconViewItemAccessible *item;
8193 GtkTextIter start, end;
8194 GtkTextBuffer *buffer;
8196 GtkIconView *icon_view;
8199 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8201 if (!GTK_IS_ICON_VIEW (item->widget))
8204 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8207 buffer = item->text_buffer;
8209 if (!gtk_text_buffer_get_char_count (buffer))
8213 return g_strdup ("");
8215 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8219 switch (boundary_type)
8221 case ATK_TEXT_BOUNDARY_CHAR:
8222 gtk_text_iter_forward_char (&end);
8224 case ATK_TEXT_BOUNDARY_WORD_START:
8225 if (!gtk_text_iter_starts_word (&start))
8226 gtk_text_iter_backward_word_start (&start);
8227 if (gtk_text_iter_inside_word (&end))
8228 gtk_text_iter_forward_word_end (&end);
8229 while (!gtk_text_iter_starts_word (&end))
8231 if (!gtk_text_iter_forward_char (&end))
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))
8244 gtk_text_iter_forward_word_end (&end);
8246 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8247 if (!gtk_text_iter_starts_sentence (&start))
8248 gtk_text_iter_backward_sentence_start (&start);
8249 if (gtk_text_iter_inside_sentence (&end))
8250 gtk_text_iter_forward_sentence_end (&end);
8251 while (!gtk_text_iter_starts_sentence (&end))
8253 if (!gtk_text_iter_forward_char (&end))
8257 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8258 if (gtk_text_iter_inside_sentence (&start) &&
8259 !gtk_text_iter_starts_sentence (&start))
8260 gtk_text_iter_backward_sentence_start (&start);
8261 while (!gtk_text_iter_ends_sentence (&start))
8263 if (!gtk_text_iter_backward_char (&start))
8266 gtk_text_iter_forward_sentence_end (&end);
8268 case ATK_TEXT_BOUNDARY_LINE_START:
8269 case ATK_TEXT_BOUNDARY_LINE_END:
8271 icon_view = GTK_ICON_VIEW (item->widget);
8272 /* FIXME we probably have to use GailTextCell to salvage this */
8273 gtk_icon_view_update_item_text (icon_view, item->item);
8274 get_pango_text_offsets (icon_view->priv->layout,
8288 *start_offset = gtk_text_iter_get_offset (&start);
8289 *end_offset = gtk_text_iter_get_offset (&end);
8291 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8295 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8297 AtkTextBoundary boundary_type,
8301 GtkIconViewItemAccessible *item;
8302 GtkTextIter start, end;
8303 GtkTextBuffer *buffer;
8305 GtkIconView *icon_view;
8308 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8310 if (!GTK_IS_ICON_VIEW (item->widget))
8313 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8316 buffer = item->text_buffer;
8318 if (!gtk_text_buffer_get_char_count (buffer))
8322 return g_strdup ("");
8324 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8328 switch (boundary_type)
8330 case ATK_TEXT_BOUNDARY_CHAR:
8331 gtk_text_iter_forward_char(&start);
8332 gtk_text_iter_forward_chars(&end, 2);
8334 case ATK_TEXT_BOUNDARY_WORD_START:
8335 if (gtk_text_iter_inside_word (&end))
8336 gtk_text_iter_forward_word_end (&end);
8337 while (!gtk_text_iter_starts_word (&end))
8339 if (!gtk_text_iter_forward_char (&end))
8343 if (!gtk_text_iter_is_end (&end))
8345 gtk_text_iter_forward_word_end (&end);
8346 while (!gtk_text_iter_starts_word (&end))
8348 if (!gtk_text_iter_forward_char (&end))
8353 case ATK_TEXT_BOUNDARY_WORD_END:
8354 gtk_text_iter_forward_word_end (&end);
8356 if (!gtk_text_iter_is_end (&end))
8357 gtk_text_iter_forward_word_end (&end);
8359 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8360 if (gtk_text_iter_inside_sentence (&end))
8361 gtk_text_iter_forward_sentence_end (&end);
8362 while (!gtk_text_iter_starts_sentence (&end))
8364 if (!gtk_text_iter_forward_char (&end))
8368 if (!gtk_text_iter_is_end (&end))
8370 gtk_text_iter_forward_sentence_end (&end);
8371 while (!gtk_text_iter_starts_sentence (&end))
8373 if (!gtk_text_iter_forward_char (&end))
8378 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8379 gtk_text_iter_forward_sentence_end (&end);
8381 if (!gtk_text_iter_is_end (&end))
8382 gtk_text_iter_forward_sentence_end (&end);
8384 case ATK_TEXT_BOUNDARY_LINE_START:
8385 case ATK_TEXT_BOUNDARY_LINE_END:
8387 icon_view = GTK_ICON_VIEW (item->widget);
8388 /* FIXME we probably have to use GailTextCell to salvage this */
8389 gtk_icon_view_update_item_text (icon_view, item->item);
8390 get_pango_text_offsets (icon_view->priv->layout,
8402 *start_offset = gtk_text_iter_get_offset (&start);
8403 *end_offset = gtk_text_iter_get_offset (&end);
8405 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8409 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8411 GtkIconViewItemAccessible *item;
8413 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8415 if (!GTK_IS_ICON_VIEW (item->widget))
8418 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8421 return gtk_text_buffer_get_char_count (item->text_buffer);
8425 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8431 AtkCoordType coord_type)
8433 GtkIconViewItemAccessible *item;
8435 GtkIconView *icon_view;
8436 PangoRectangle char_rect;
8437 const gchar *item_text;
8441 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8443 if (!GTK_IS_ICON_VIEW (item->widget))
8446 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8450 icon_view = GTK_ICON_VIEW (item->widget);
8451 /* FIXME we probably have to use GailTextCell to salvage this */
8452 gtk_icon_view_update_item_text (icon_view, item->item);
8453 item_text = pango_layout_get_text (icon_view->priv->layout);
8454 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8455 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8457 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8458 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8459 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8460 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8461 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8462 *width = char_rect.width / PANGO_SCALE;
8463 *height = char_rect.height / PANGO_SCALE;
8468 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8471 AtkCoordType coord_type)
8473 GtkIconViewItemAccessible *item;
8476 GtkIconView *icon_view;
8477 const gchar *item_text;
8482 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8484 if (!GTK_IS_ICON_VIEW (item->widget))
8487 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8491 icon_view = GTK_ICON_VIEW (item->widget);
8492 /* FIXME we probably have to use GailTextCell to salvage this */
8493 gtk_icon_view_update_item_text (icon_view, item->item);
8494 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8495 x -= l_x + item->item->layout_x - item->item->x;
8496 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8497 y -= l_y + item->item->layout_y - item->item->y;
8498 item_text = pango_layout_get_text (icon_view->priv->layout);
8499 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8510 offset = g_utf8_strlen (item_text, -1);
8512 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8518 atk_text_item_interface_init (AtkTextIface *iface)
8520 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8521 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8522 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8523 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8524 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8525 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8526 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8527 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8531 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8536 AtkCoordType coord_type)
8538 GtkIconViewItemAccessible *item;
8539 AtkObject *parent_obj;
8542 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8544 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8545 if (!GTK_IS_WIDGET (item->widget))
8548 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8551 *width = item->item->width;
8552 *height = item->item->height;
8553 if (gtk_icon_view_item_accessible_is_showing (item))
8555 parent_obj = gtk_widget_get_accessible (item->widget);
8556 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8557 *x = l_x + item->item->x;
8558 *y = l_y + item->item->y;
8568 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8570 GtkIconViewItemAccessible *item;
8571 GtkWidget *toplevel;
8573 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8575 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8576 if (!GTK_IS_WIDGET (item->widget))
8579 gtk_widget_grab_focus (item->widget);
8580 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8581 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8582 if (gtk_widget_is_toplevel (toplevel))
8583 gtk_window_present (GTK_WINDOW (toplevel));
8589 atk_component_item_interface_init (AtkComponentIface *iface)
8591 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8592 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8596 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8597 AtkStateType state_type,
8598 gboolean emit_signal)
8602 rc = atk_state_set_add_state (item->state_set, state_type);
8604 * The signal should only be generated if the value changed,
8605 * not when the item is set up. So states that are set
8606 * initially should pass FALSE as the emit_signal argument.
8611 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8612 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8613 if (state_type == ATK_STATE_VISIBLE)
8614 g_signal_emit_by_name (item, "visible-data-changed");
8621 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8622 AtkStateType state_type,
8623 gboolean emit_signal)
8625 if (atk_state_set_contains_state (item->state_set, state_type))
8629 rc = atk_state_set_remove_state (item->state_set, state_type);
8631 * The signal should only be generated if the value changed,
8632 * not when the item is set up. So states that are set
8633 * initially should pass FALSE as the emit_signal argument.
8638 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8639 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8640 if (state_type == ATK_STATE_VISIBLE)
8641 g_signal_emit_by_name (item, "visible-data-changed");
8651 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8653 GtkAllocation allocation;
8654 GtkIconView *icon_view;
8655 GdkRectangle visible_rect;
8656 gboolean is_showing;
8659 * An item is considered "SHOWING" if any part of the item is in the
8660 * visible rectangle.
8663 if (!GTK_IS_ICON_VIEW (item->widget))
8666 if (item->item == NULL)
8669 gtk_widget_get_allocation (item->widget, &allocation);
8671 icon_view = GTK_ICON_VIEW (item->widget);
8673 if (icon_view->priv->hadjustment)
8674 visible_rect.x += icon_view->priv->hadjustment->value;
8676 if (icon_view->priv->hadjustment)
8677 visible_rect.y += icon_view->priv->vadjustment->value;
8678 visible_rect.width = allocation.width;
8679 visible_rect.height = allocation.height;
8681 if (((item->item->x + item->item->width) < visible_rect.x) ||
8682 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8683 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8684 (item->item->y > (visible_rect.y + visible_rect.height)))
8693 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8694 gboolean emit_signal)
8696 if (gtk_icon_view_item_accessible_is_showing (item))
8697 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8700 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8705 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8709 item->state_set = atk_state_set_new ();
8711 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8712 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8713 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8714 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8715 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8717 for (i = 0; i < LAST_ACTION; i++)
8718 item->action_descriptions[i] = NULL;
8720 item->image_description = NULL;
8722 item->action_idle_handler = 0;
8726 gtk_icon_view_item_accessible_finalize (GObject *object)
8728 GtkIconViewItemAccessible *item;
8731 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8733 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8736 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8738 if (item->state_set)
8739 g_object_unref (item->state_set);
8741 if (item->text_buffer)
8742 g_object_unref (item->text_buffer);
8744 for (i = 0; i < LAST_ACTION; i++)
8745 g_free (item->action_descriptions[i]);
8747 g_free (item->image_description);
8749 if (item->action_idle_handler)
8751 g_source_remove (item->action_idle_handler);
8752 item->action_idle_handler = 0;
8755 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8758 static G_CONST_RETURN gchar*
8759 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8765 GtkIconViewItemAccessible *item;
8766 GtkTextIter start_iter;
8767 GtkTextIter end_iter;
8769 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8771 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8772 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8774 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8779 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8781 GtkIconViewItemAccessible *item;
8783 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8784 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8787 return gtk_widget_get_accessible (item->widget);
8793 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8795 GtkIconViewItemAccessible *item;
8797 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8798 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8800 return item->item->index;
8803 static AtkStateSet *
8804 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8806 GtkIconViewItemAccessible *item;
8807 GtkIconView *icon_view;
8809 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8810 g_return_val_if_fail (item->state_set, NULL);
8815 icon_view = GTK_ICON_VIEW (item->widget);
8816 if (icon_view->priv->cursor_item == item->item)
8817 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8819 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8820 if (item->item->selected)
8821 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8823 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8825 return g_object_ref (item->state_set);
8829 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8831 GObjectClass *gobject_class;
8833 accessible_item_parent_class = g_type_class_peek_parent (klass);
8835 gobject_class = (GObjectClass *)klass;
8837 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8839 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8840 klass->get_name = gtk_icon_view_item_accessible_get_name;
8841 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8842 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8846 gtk_icon_view_item_accessible_get_type (void)
8848 static GType type = 0;
8852 const GTypeInfo tinfo =
8854 sizeof (GtkIconViewItemAccessibleClass),
8855 (GBaseInitFunc) NULL, /* base init */
8856 (GBaseFinalizeFunc) NULL, /* base finalize */
8857 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8858 (GClassFinalizeFunc) NULL, /* class finalize */
8859 NULL, /* class data */
8860 sizeof (GtkIconViewItemAccessible), /* instance size */
8861 0, /* nb preallocs */
8862 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8863 NULL /* value table */
8866 const GInterfaceInfo atk_component_info =
8868 (GInterfaceInitFunc) atk_component_item_interface_init,
8869 (GInterfaceFinalizeFunc) NULL,
8872 const GInterfaceInfo atk_action_info =
8874 (GInterfaceInitFunc) atk_action_item_interface_init,
8875 (GInterfaceFinalizeFunc) NULL,
8878 const GInterfaceInfo atk_image_info =
8880 (GInterfaceInitFunc) atk_image_item_interface_init,
8881 (GInterfaceFinalizeFunc) NULL,
8884 const GInterfaceInfo atk_text_info =
8886 (GInterfaceInitFunc) atk_text_item_interface_init,
8887 (GInterfaceFinalizeFunc) NULL,
8891 type = g_type_register_static (ATK_TYPE_OBJECT,
8892 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8893 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8894 &atk_component_info);
8895 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8897 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8899 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8906 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8907 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8908 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8910 static GType gtk_icon_view_accessible_get_type (void);
8915 } GtkIconViewAccessible;
8921 } GtkIconViewItemAccessibleInfo;
8927 GtkAdjustment *old_hadj;
8928 GtkAdjustment *old_vadj;
8930 GtkTreeModel *model;
8932 } GtkIconViewAccessiblePrivate;
8934 static GtkIconViewAccessiblePrivate *
8935 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8937 return g_object_get_qdata (G_OBJECT (accessible),
8938 accessible_private_data_quark);
8942 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8946 GtkIconViewItemAccessibleInfo *info;
8947 GtkIconViewItemAccessibleInfo *tmp_info;
8948 GtkIconViewAccessiblePrivate *priv;
8951 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8953 info->index = index;
8955 priv = gtk_icon_view_accessible_get_priv (accessible);
8956 items = priv->items;
8959 tmp_info = items->data;
8960 if (tmp_info->index > index)
8962 items = items->next;
8964 priv->items = g_list_insert_before (priv->items, items, info);
8965 priv->old_hadj = NULL;
8966 priv->old_vadj = NULL;
8970 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8972 GtkIconView *icon_view;
8975 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8979 icon_view = GTK_ICON_VIEW (widget);
8981 return g_list_length (icon_view->priv->items);
8985 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8988 GtkIconViewAccessiblePrivate *priv;
8989 GtkIconViewItemAccessibleInfo *info;
8992 priv = gtk_icon_view_accessible_get_priv (accessible);
8993 items = priv->items;
8998 if (info->index == index)
9000 items = items->next;
9006 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9009 GtkIconView *icon_view;
9013 GtkIconViewItemAccessible *a11y_item;
9015 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9019 icon_view = GTK_ICON_VIEW (widget);
9020 icons = g_list_nth (icon_view->priv->items, index);
9024 GtkIconViewItem *item = icons->data;
9026 g_return_val_if_fail (item->index == index, NULL);
9027 obj = gtk_icon_view_accessible_find_child (accessible, index);
9032 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9033 gtk_icon_view_item_accessible_info_new (accessible,
9036 obj->role = ATK_ROLE_ICON;
9037 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9038 a11y_item->item = item;
9039 a11y_item->widget = widget;
9040 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9042 gtk_icon_view_set_cell_data (icon_view, item);
9043 text = get_text (icon_view, item);
9046 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9050 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9051 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9059 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9062 GtkIconViewAccessiblePrivate *priv;
9063 GtkIconViewItemAccessibleInfo *info;
9064 GtkIconViewItemAccessible *item;
9067 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9071 gboolean act_on_item;
9073 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9077 items = priv->items;
9079 act_on_item = (list == NULL);
9084 info = (GtkIconViewItemAccessibleInfo *)items->data;
9085 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9087 if (act_on_item == FALSE && list == items)
9091 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9093 items = items->next;
9099 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9100 GtkIconView *icon_view)
9103 GtkIconViewAccessible *view;
9106 * The scrollbars have changed
9108 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9109 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9111 gtk_icon_view_accessible_traverse_items (view, NULL);
9115 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9116 GtkAdjustment *hadj,
9117 GtkAdjustment *vadj)
9120 GtkIconViewAccessiblePrivate *priv;
9122 atk_obj = gtk_widget_get_accessible (widget);
9123 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9125 if (priv->old_hadj != hadj)
9129 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9130 (gpointer *)&priv->old_hadj);
9132 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9133 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9136 priv->old_hadj = hadj;
9139 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9140 (gpointer *)&priv->old_hadj);
9141 g_signal_connect (hadj,
9143 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9147 if (priv->old_vadj != vadj)
9151 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9152 (gpointer *)&priv->old_vadj);
9154 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9155 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9158 priv->old_vadj = vadj;
9161 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9162 (gpointer *)&priv->old_vadj);
9163 g_signal_connect (vadj,
9165 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9172 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9180 GtkIconView *icon_view;
9181 GtkIconViewItem *item;
9182 GtkIconViewAccessible *a11y_view;
9183 GtkIconViewItemAccessible *a11y_item;
9187 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9188 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9189 index = gtk_tree_path_get_indices(path)[0];
9190 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9191 gtk_icon_view_accessible_find_child (atk_obj, index));
9195 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9196 icon_view = GTK_ICON_VIEW (widget);
9197 item = a11y_item->item;
9199 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9201 if (!name || strcmp (name, "") == 0)
9203 gtk_icon_view_set_cell_data (icon_view, item);
9204 text = get_text (icon_view, item);
9207 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9213 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9219 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9224 GtkIconViewAccessiblePrivate *priv;
9225 GtkIconViewItemAccessibleInfo *info;
9226 GtkIconViewAccessible *view;
9227 GtkIconViewItemAccessible *item;
9233 index = gtk_tree_path_get_indices(path)[0];
9234 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9235 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9236 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9238 items = priv->items;
9243 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9244 if (info->index != item->item->index)
9246 if (info->index < index)
9247 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9249 if (tmp_list == NULL)
9252 info->index = item->item->index;
9255 items = items->next;
9257 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9258 g_signal_emit_by_name (atk_obj, "children-changed::add",
9264 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9268 GtkIconViewAccessiblePrivate *priv;
9269 GtkIconViewItemAccessibleInfo *info;
9270 GtkIconViewAccessible *view;
9271 GtkIconViewItemAccessible *item;
9274 GList *deleted_item;
9278 index = gtk_tree_path_get_indices(path)[0];
9279 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9280 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9281 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9283 items = priv->items;
9285 deleted_item = NULL;
9290 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9291 if (info->index == index)
9293 deleted_item = items;
9295 if (info->index != item->item->index)
9297 if (tmp_list == NULL)
9300 info->index = item->item->index;
9303 items = items->next;
9305 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9308 info = deleted_item->data;
9309 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9310 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9312 priv->items = g_list_remove_link (priv->items, deleted_item);
9320 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9321 GtkIconViewItemAccessibleInfo *i2)
9323 return i1->index - i2->index;
9327 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9333 GtkIconViewAccessiblePrivate *priv;
9334 GtkIconViewItemAccessibleInfo *info;
9335 GtkIconView *icon_view;
9336 GtkIconViewItemAccessible *item;
9342 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9343 icon_view = GTK_ICON_VIEW (user_data);
9344 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9346 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9348 order = g_new (gint, length);
9349 for (i = 0; i < length; i++)
9350 order [new_order[i]] = i;
9352 items = priv->items;
9356 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9357 info->index = order[info->index];
9358 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9359 items = items->next;
9362 priv->items = g_list_sort (priv->items,
9363 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9369 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9374 obj = G_OBJECT (model);
9375 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9376 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9377 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9378 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9382 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9386 obj = G_OBJECT (icon_view->priv->model);
9387 g_signal_connect_data (obj, "row-changed",
9388 (GCallback) gtk_icon_view_accessible_model_row_changed,
9389 icon_view, NULL, 0);
9390 g_signal_connect_data (obj, "row-inserted",
9391 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9392 icon_view, NULL, G_CONNECT_AFTER);
9393 g_signal_connect_data (obj, "row-deleted",
9394 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9395 icon_view, NULL, G_CONNECT_AFTER);
9396 g_signal_connect_data (obj, "rows-reordered",
9397 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9398 icon_view, NULL, G_CONNECT_AFTER);
9402 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9404 GtkIconViewItemAccessibleInfo *info;
9407 items = priv->items;
9410 info = (GtkIconViewItemAccessibleInfo *) items->data;
9411 g_object_unref (info->item);
9412 g_free (items->data);
9413 items = items->next;
9415 g_list_free (priv->items);
9420 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9423 GtkIconView *icon_view;
9426 GtkIconViewAccessiblePrivate *priv;
9428 if (strcmp (pspec->name, "model") == 0)
9430 widget = GTK_WIDGET (obj);
9431 atk_obj = gtk_widget_get_accessible (widget);
9432 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9435 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9436 (gpointer *)&priv->model);
9437 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9439 gtk_icon_view_accessible_clear_cache (priv);
9441 icon_view = GTK_ICON_VIEW (obj);
9442 priv->model = icon_view->priv->model;
9443 /* If there is no model the GtkIconView is probably being destroyed */
9446 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9447 gtk_icon_view_accessible_connect_model_signals (icon_view);
9455 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9458 GtkIconViewAccessiblePrivate *priv;
9459 GtkIconView *icon_view;
9461 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9462 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9464 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9465 g_object_set_qdata (G_OBJECT (accessible),
9466 accessible_private_data_quark,
9469 icon_view = GTK_ICON_VIEW (data);
9470 if (icon_view->priv->hadjustment)
9472 priv->old_hadj = icon_view->priv->hadjustment;
9473 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9474 g_signal_connect (icon_view->priv->hadjustment,
9476 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9479 if (icon_view->priv->vadjustment)
9481 priv->old_vadj = icon_view->priv->vadjustment;
9482 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9483 g_signal_connect (icon_view->priv->vadjustment,
9485 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9488 g_signal_connect_after (data,
9489 "set-scroll-adjustments",
9490 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9492 g_signal_connect (data,
9494 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9497 priv->model = icon_view->priv->model;
9500 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9501 gtk_icon_view_accessible_connect_model_signals (icon_view);
9504 accessible->role = ATK_ROLE_LAYERED_PANE;
9508 gtk_icon_view_accessible_finalize (GObject *object)
9510 GtkIconViewAccessiblePrivate *priv;
9512 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9513 gtk_icon_view_accessible_clear_cache (priv);
9517 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9521 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9522 GtkAccessible *accessible)
9525 GtkIconViewAccessiblePrivate *priv;
9527 atk_obj = ATK_OBJECT (accessible);
9528 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9531 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9532 (gpointer *)&priv->old_hadj);
9534 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9535 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9537 priv->old_hadj = NULL;
9541 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9542 (gpointer *)&priv->old_vadj);
9544 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9545 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9547 priv->old_vadj = NULL;
9552 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9556 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9559 g_signal_connect_after (widget,
9561 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9564 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9568 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9570 GObjectClass *gobject_class;
9571 GtkAccessibleClass *accessible_class;
9573 accessible_parent_class = g_type_class_peek_parent (klass);
9575 gobject_class = (GObjectClass *)klass;
9576 accessible_class = (GtkAccessibleClass *)klass;
9578 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9580 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9581 klass->ref_child = gtk_icon_view_accessible_ref_child;
9582 klass->initialize = gtk_icon_view_accessible_initialize;
9584 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9586 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9590 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9593 AtkCoordType coord_type)
9596 GtkIconView *icon_view;
9597 GtkIconViewItem *item;
9600 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9602 /* State is defunct */
9605 icon_view = GTK_ICON_VIEW (widget);
9606 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9607 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9609 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9615 atk_component_interface_init (AtkComponentIface *iface)
9617 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9621 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9625 GtkIconView *icon_view;
9626 GtkIconViewItem *item;
9628 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9632 icon_view = GTK_ICON_VIEW (widget);
9634 item = g_list_nth_data (icon_view->priv->items, i);
9639 gtk_icon_view_select_item (icon_view, item);
9645 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9648 GtkIconView *icon_view;
9650 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9654 icon_view = GTK_ICON_VIEW (widget);
9655 gtk_icon_view_unselect_all (icon_view);
9661 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9666 GtkIconView *icon_view;
9667 GtkIconViewItem *item;
9669 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9673 icon_view = GTK_ICON_VIEW (widget);
9675 l = icon_view->priv->items;
9682 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9693 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9696 GtkIconView *icon_view;
9697 GtkIconViewItem *item;
9701 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9705 icon_view = GTK_ICON_VIEW (widget);
9707 l = icon_view->priv->items;
9723 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9727 GtkIconView *icon_view;
9728 GtkIconViewItem *item;
9730 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9734 icon_view = GTK_ICON_VIEW (widget);
9736 item = g_list_nth_data (icon_view->priv->items, i);
9740 return item->selected;
9744 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9748 GtkIconView *icon_view;
9749 GtkIconViewItem *item;
9753 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9757 icon_view = GTK_ICON_VIEW (widget);
9758 l = icon_view->priv->items;
9767 gtk_icon_view_unselect_item (icon_view, item);
9779 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9782 GtkIconView *icon_view;
9784 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9788 icon_view = GTK_ICON_VIEW (widget);
9789 gtk_icon_view_select_all (icon_view);
9794 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9796 iface->add_selection = gtk_icon_view_accessible_add_selection;
9797 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9798 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9799 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9800 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9801 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9802 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9806 gtk_icon_view_accessible_get_type (void)
9808 static GType type = 0;
9815 (GBaseInitFunc) NULL, /* base init */
9816 (GBaseFinalizeFunc) NULL, /* base finalize */
9817 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9818 (GClassFinalizeFunc) NULL, /* class finalize */
9819 NULL, /* class data */
9820 0, /* instance size */
9821 0, /* nb preallocs */
9822 (GInstanceInitFunc) NULL, /* instance init */
9823 NULL /* value table */
9825 const GInterfaceInfo atk_component_info =
9827 (GInterfaceInitFunc) atk_component_interface_init,
9828 (GInterfaceFinalizeFunc) NULL,
9831 const GInterfaceInfo atk_selection_info =
9833 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9834 (GInterfaceFinalizeFunc) NULL,
9839 * Figure out the size of the class and instance
9840 * we are deriving from
9842 AtkObjectFactory *factory;
9845 GType derived_atk_type;
9847 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9848 factory = atk_registry_get_factory (atk_get_default_registry (),
9850 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9851 g_type_query (derived_atk_type, &query);
9852 tinfo.class_size = query.class_size;
9853 tinfo.instance_size = query.instance_size;
9855 type = g_type_register_static (derived_atk_type,
9856 I_("GtkIconViewAccessible"),
9858 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9859 &atk_component_info);
9860 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9861 &atk_selection_info);
9867 gtk_icon_view_accessible_new (GObject *obj)
9869 AtkObject *accessible;
9871 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9873 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9874 atk_object_initialize (accessible, obj);
9880 gtk_icon_view_accessible_factory_get_accessible_type (void)
9882 return gtk_icon_view_accessible_get_type ();
9886 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9888 return gtk_icon_view_accessible_new (obj);
9892 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9894 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9895 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9899 gtk_icon_view_accessible_factory_get_type (void)
9901 static GType type = 0;
9905 const GTypeInfo tinfo =
9907 sizeof (AtkObjectFactoryClass),
9908 NULL, /* base_init */
9909 NULL, /* base_finalize */
9910 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9911 NULL, /* class_finalize */
9912 NULL, /* class_data */
9913 sizeof (AtkObjectFactory),
9914 0, /* n_preallocs */
9918 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9919 I_("GtkIconViewAccessibleFactory"),
9927 gtk_icon_view_get_accessible (GtkWidget *widget)
9929 static gboolean first_time = TRUE;
9933 AtkObjectFactory *factory;
9934 AtkRegistry *registry;
9936 GType derived_atk_type;
9939 * Figure out whether accessibility is enabled by looking at the
9940 * type of the accessible object which would be created for
9941 * the parent type of GtkIconView.
9943 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9945 registry = atk_get_default_registry ();
9946 factory = atk_registry_get_factory (registry,
9948 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9949 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9950 atk_registry_set_factory_type (registry,
9952 gtk_icon_view_accessible_factory_get_type ());
9955 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9959 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9960 GtkBuilder *builder,
9962 const gchar *tagname,
9963 GMarkupParser *parser,
9966 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9967 tagname, parser, data))
9970 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9971 tagname, parser, data);
9975 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9976 GtkBuilder *builder,
9978 const gchar *tagname,
9981 if (strcmp (tagname, "attributes") == 0)
9982 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9985 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,