2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtktextbuffer.h"
42 #include "gtksizerequest.h"
43 #include "gtktreednd.h"
44 #include "gtkprivate.h"
49 * @short_description: A widget which displays a list of icons in a grid
51 * #GtkIconView provides an alternative view on a list model.
52 * It displays the model as a grid of icons with labels. Like
53 * #GtkTreeView, it allows to select one or multiple items
54 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
55 * In addition to selection with the arrow keys, #GtkIconView supports
56 * rubberband selection, which is controlled by dragging the pointer.
59 #define SCROLL_EDGE_SIZE 15
61 typedef struct _GtkIconViewItem GtkIconViewItem;
62 struct _GtkIconViewItem
70 gint x, y, width, height;
73 * box[i] is the actual area occupied by cell i,
74 * before, after are used to calculate the cell
75 * area relative to the box.
76 * See gtk_icon_view_get_cell_area().
84 guint selected_before_rubberbanding : 1;
88 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
89 struct _GtkIconViewCellInfo
91 GtkCellRenderer *cell;
101 GtkCellLayoutDataFunc func;
103 GDestroyNotify destroy;
106 typedef struct _GtkIconViewChild GtkIconViewChild;
107 struct _GtkIconViewChild
110 GtkIconViewItem *item;
114 struct _GtkIconViewPrivate
118 GtkSelectionMode selection_mode;
120 GdkWindow *bin_window;
128 GtkAdjustment *hadjustment;
129 GtkAdjustment *vadjustment;
131 guint layout_idle_id;
133 gboolean doing_rubberband;
134 gint rubberband_x1, rubberband_y1;
135 gint rubberband_x2, rubberband_y2;
136 GdkDevice *rubberband_device;
138 guint scroll_timeout_id;
139 gint scroll_value_diff;
140 gint event_last_x, event_last_y;
142 GtkIconViewItem *anchor_item;
143 GtkIconViewItem *cursor_item;
144 GtkIconViewItem *edited_item;
145 GtkCellEditable *editable;
147 GtkIconViewItem *last_single_clicked;
154 GtkOrientation item_orientation;
174 GdkModifierType start_button_mask;
179 GdkDragAction source_actions;
180 GdkDragAction dest_actions;
182 GtkTreeRowReference *dest_item;
183 GtkIconViewDropPosition dest_pos;
186 GtkTreeRowReference *scroll_to_path;
187 gfloat scroll_to_row_align;
188 gfloat scroll_to_col_align;
189 guint scroll_to_use_align : 1;
191 guint source_set : 1;
193 guint reorderable : 1;
194 guint empty_view_drop :1;
196 guint ctrl_pressed : 1;
197 guint shift_pressed : 1;
199 guint draw_focus : 1;
212 ACTIVATE_CURSOR_ITEM,
224 PROP_ITEM_ORIENTATION,
238 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
239 static void gtk_icon_view_finalize (GObject *object);
240 static void gtk_icon_view_set_property (GObject *object,
244 static void gtk_icon_view_get_property (GObject *object,
249 /* GtkObject vfuncs */
250 static void gtk_icon_view_destroy (GtkObject *object);
252 /* GtkWidget vfuncs */
253 static void gtk_icon_view_realize (GtkWidget *widget);
254 static void gtk_icon_view_unrealize (GtkWidget *widget);
255 static void gtk_icon_view_style_set (GtkWidget *widget,
256 GtkStyle *previous_style);
257 static void gtk_icon_view_state_changed (GtkWidget *widget,
258 GtkStateType previous_state);
259 static void gtk_icon_view_size_request (GtkWidget *widget,
260 GtkRequisition *requisition);
261 static void gtk_icon_view_size_allocate (GtkWidget *widget,
262 GtkAllocation *allocation);
263 static gboolean gtk_icon_view_draw (GtkWidget *widget,
265 static gboolean gtk_icon_view_motion (GtkWidget *widget,
266 GdkEventMotion *event);
267 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
268 GdkEventButton *event);
269 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
270 GdkEventButton *event);
271 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
273 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
275 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
278 /* GtkContainer vfuncs */
279 static void gtk_icon_view_remove (GtkContainer *container,
281 static void gtk_icon_view_forall (GtkContainer *container,
282 gboolean include_internals,
283 GtkCallback callback,
284 gpointer callback_data);
286 /* GtkIconView vfuncs */
287 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
289 GtkAdjustment *vadj);
290 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
291 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
292 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
293 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
294 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
296 /* Internal functions */
297 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
298 GtkIconView *icon_view);
299 static void gtk_icon_view_layout (GtkIconView *icon_view);
300 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
302 GtkIconViewItem *item,
305 gboolean draw_focus);
306 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
308 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
310 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
311 GtkIconViewItem *item);
312 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
313 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
314 GtkIconViewItem *item,
316 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
320 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
321 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
322 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
323 GtkIconViewItem *item,
328 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
329 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
330 GtkIconViewItem *item);
331 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
332 GtkIconViewItem *item,
334 static void gtk_icon_view_update_rubberband (gpointer data);
335 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
336 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
337 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
340 GtkMovementStep step,
342 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
343 GtkMovementStep step,
345 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
347 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
349 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
351 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
353 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
354 GtkIconViewItem *item);
355 static void gtk_icon_view_select_item (GtkIconView *icon_view,
356 GtkIconViewItem *item);
357 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
358 GtkIconViewItem *item);
359 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
360 GtkIconViewItem *anchor,
361 GtkIconViewItem *cursor);
362 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
365 gboolean only_in_cell,
366 GtkIconViewCellInfo **cell_at_pos);
367 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
368 GtkIconViewItem *item,
369 GtkIconViewCellInfo *cell_info,
370 GdkRectangle *cell_area);
371 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
372 GtkIconViewItem *item,
373 GtkIconViewCellInfo *info,
375 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
376 GtkCellRenderer *renderer);
377 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
378 GtkIconViewItem *item);
379 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
380 GtkCellRenderer *renderer,
382 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
383 GtkCellRenderer *renderer,
385 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
386 GtkCellRenderer *renderer,
387 const gchar *attribute,
389 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
390 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
391 GtkCellRenderer *renderer);
392 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
393 GtkCellRenderer *cell,
394 GtkCellLayoutDataFunc func,
396 GDestroyNotify destroy);
397 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
398 GtkCellRenderer *cell,
400 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
402 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
403 GtkIconViewItem *item,
404 GtkIconViewCellInfo *cell_info,
406 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
407 GtkIconViewItem *item);
408 static void gtk_icon_view_put (GtkIconView *icon_view,
410 GtkIconViewItem *item,
412 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
413 GtkIconView *icon_view);
414 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
415 GtkIconViewItem *item,
416 GtkIconViewCellInfo *cell_info,
418 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
419 gboolean cancel_editing);
421 /* Source side drag signals */
422 static void gtk_icon_view_drag_begin (GtkWidget *widget,
423 GdkDragContext *context);
424 static void gtk_icon_view_drag_end (GtkWidget *widget,
425 GdkDragContext *context);
426 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
427 GdkDragContext *context,
428 GtkSelectionData *selection_data,
431 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
432 GdkDragContext *context);
434 /* Target side drag signals */
435 static void gtk_icon_view_drag_leave (GtkWidget *widget,
436 GdkDragContext *context,
438 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
439 GdkDragContext *context,
443 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
444 GdkDragContext *context,
448 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
449 GdkDragContext *context,
452 GtkSelectionData *selection_data,
455 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
456 GdkEventMotion *event);
458 static void remove_scroll_timeout (GtkIconView *icon_view);
460 static void adjust_wrap_width (GtkIconView *icon_view,
461 GtkIconViewItem *item);
464 static GtkBuildableIface *parent_buildable_iface;
465 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
466 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
469 const gchar *tagname,
470 GMarkupParser *parser,
472 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
475 const gchar *tagname,
478 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
480 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
481 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
482 gtk_icon_view_cell_layout_init)
483 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
484 gtk_icon_view_buildable_init))
487 gtk_icon_view_class_init (GtkIconViewClass *klass)
489 GObjectClass *gobject_class;
490 GtkObjectClass *object_class;
491 GtkWidgetClass *widget_class;
492 GtkContainerClass *container_class;
493 GtkBindingSet *binding_set;
495 binding_set = gtk_binding_set_by_class (klass);
497 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
499 gobject_class = (GObjectClass *) klass;
500 object_class = (GtkObjectClass *) klass;
501 widget_class = (GtkWidgetClass *) klass;
502 container_class = (GtkContainerClass *) klass;
504 gobject_class->finalize = gtk_icon_view_finalize;
505 gobject_class->set_property = gtk_icon_view_set_property;
506 gobject_class->get_property = gtk_icon_view_get_property;
508 object_class->destroy = gtk_icon_view_destroy;
510 widget_class->realize = gtk_icon_view_realize;
511 widget_class->unrealize = gtk_icon_view_unrealize;
512 widget_class->style_set = gtk_icon_view_style_set;
513 widget_class->get_accessible = gtk_icon_view_get_accessible;
514 widget_class->size_request = gtk_icon_view_size_request;
515 widget_class->size_allocate = gtk_icon_view_size_allocate;
516 widget_class->draw = gtk_icon_view_draw;
517 widget_class->motion_notify_event = gtk_icon_view_motion;
518 widget_class->button_press_event = gtk_icon_view_button_press;
519 widget_class->button_release_event = gtk_icon_view_button_release;
520 widget_class->key_press_event = gtk_icon_view_key_press;
521 widget_class->key_release_event = gtk_icon_view_key_release;
522 widget_class->drag_begin = gtk_icon_view_drag_begin;
523 widget_class->drag_end = gtk_icon_view_drag_end;
524 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
525 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
526 widget_class->drag_leave = gtk_icon_view_drag_leave;
527 widget_class->drag_motion = gtk_icon_view_drag_motion;
528 widget_class->drag_drop = gtk_icon_view_drag_drop;
529 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
530 widget_class->state_changed = gtk_icon_view_state_changed;
532 container_class->remove = gtk_icon_view_remove;
533 container_class->forall = gtk_icon_view_forall;
535 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
536 klass->select_all = gtk_icon_view_real_select_all;
537 klass->unselect_all = gtk_icon_view_real_unselect_all;
538 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
539 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
540 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
541 klass->move_cursor = gtk_icon_view_real_move_cursor;
545 * GtkIconView:selection-mode:
547 * The ::selection-mode property specifies the selection mode of
548 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
549 * is enabled, for the other modes, only keyboard selection is possible.
553 g_object_class_install_property (gobject_class,
555 g_param_spec_enum ("selection-mode",
556 P_("Selection mode"),
557 P_("The selection mode"),
558 GTK_TYPE_SELECTION_MODE,
559 GTK_SELECTION_SINGLE,
560 GTK_PARAM_READWRITE));
563 * GtkIconView:pixbuf-column:
565 * The ::pixbuf-column property contains the number of the model column
566 * containing the pixbufs which are displayed. The pixbuf column must be
567 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
568 * display of pixbufs.
572 g_object_class_install_property (gobject_class,
574 g_param_spec_int ("pixbuf-column",
576 P_("Model column used to retrieve the icon pixbuf from"),
578 GTK_PARAM_READWRITE));
581 * GtkIconView:text-column:
583 * The ::text-column property contains the number of the model column
584 * containing the texts which are displayed. The text column must be
585 * of type #G_TYPE_STRING. If this property and the :markup-column
586 * property are both set to -1, no texts are displayed.
590 g_object_class_install_property (gobject_class,
592 g_param_spec_int ("text-column",
594 P_("Model column used to retrieve the text from"),
596 GTK_PARAM_READWRITE));
600 * GtkIconView:markup-column:
602 * The ::markup-column property contains the number of the model column
603 * containing markup information to be displayed. The markup column must be
604 * of type #G_TYPE_STRING. If this property and the :text-column property
605 * are both set to column numbers, it overrides the text column.
606 * If both are set to -1, no texts are displayed.
610 g_object_class_install_property (gobject_class,
612 g_param_spec_int ("markup-column",
614 P_("Model column used to retrieve the text if using Pango markup"),
616 GTK_PARAM_READWRITE));
618 g_object_class_install_property (gobject_class,
620 g_param_spec_object ("model",
621 P_("Icon View Model"),
622 P_("The model for the icon view"),
624 GTK_PARAM_READWRITE));
627 * GtkIconView:columns:
629 * The columns property contains the number of the columns in which the
630 * items should be displayed. If it is -1, the number of columns will
631 * be chosen automatically to fill the available area.
635 g_object_class_install_property (gobject_class,
637 g_param_spec_int ("columns",
638 P_("Number of columns"),
639 P_("Number of columns to display"),
641 GTK_PARAM_READWRITE));
645 * GtkIconView:item-width:
647 * The item-width property specifies the width to use for each item.
648 * If it is set to -1, the icon view will automatically determine a
649 * suitable item size.
653 g_object_class_install_property (gobject_class,
655 g_param_spec_int ("item-width",
656 P_("Width for each item"),
657 P_("The width used for each item"),
659 GTK_PARAM_READWRITE));
662 * GtkIconView:spacing:
664 * The spacing property specifies the space which is inserted between
665 * the cells (i.e. the icon and the text) of an item.
669 g_object_class_install_property (gobject_class,
671 g_param_spec_int ("spacing",
673 P_("Space which is inserted between cells of an item"),
675 GTK_PARAM_READWRITE));
678 * GtkIconView:row-spacing:
680 * The row-spacing property specifies the space which is inserted between
681 * the rows of the icon view.
685 g_object_class_install_property (gobject_class,
687 g_param_spec_int ("row-spacing",
689 P_("Space which is inserted between grid rows"),
691 GTK_PARAM_READWRITE));
694 * GtkIconView:column-spacing:
696 * The column-spacing property specifies the space which is inserted between
697 * the columns of the icon view.
701 g_object_class_install_property (gobject_class,
703 g_param_spec_int ("column-spacing",
704 P_("Column Spacing"),
705 P_("Space which is inserted between grid columns"),
707 GTK_PARAM_READWRITE));
710 * GtkIconView:margin:
712 * The margin property specifies the space which is inserted
713 * at the edges of the icon view.
717 g_object_class_install_property (gobject_class,
719 g_param_spec_int ("margin",
721 P_("Space which is inserted at the edges of the icon view"),
723 GTK_PARAM_READWRITE));
726 * GtkIconView:item-orientation:
728 * The item-orientation property specifies how the cells (i.e. the icon and
729 * the text) of the item are positioned relative to each other.
733 g_object_class_install_property (gobject_class,
734 PROP_ITEM_ORIENTATION,
735 g_param_spec_enum ("item-orientation",
736 P_("Item Orientation"),
737 P_("How the text and icon of each item are positioned relative to each other"),
738 GTK_TYPE_ORIENTATION,
739 GTK_ORIENTATION_VERTICAL,
740 GTK_PARAM_READWRITE));
743 * GtkIconView:reorderable:
745 * The reorderable property specifies if the items can be reordered
750 g_object_class_install_property (gobject_class,
752 g_param_spec_boolean ("reorderable",
754 P_("View is reorderable"),
758 g_object_class_install_property (gobject_class,
760 g_param_spec_int ("tooltip-column",
761 P_("Tooltip Column"),
762 P_("The column in the model containing the tooltip texts for the items"),
766 GTK_PARAM_READWRITE));
769 * GtkIconView:item-padding:
771 * The item-padding property specifies the padding around each
772 * of the icon view's item.
776 g_object_class_install_property (gobject_class,
778 g_param_spec_int ("item-padding",
780 P_("Padding around icon view items"),
782 GTK_PARAM_READWRITE));
786 /* Style properties */
787 gtk_widget_class_install_style_property (widget_class,
788 g_param_spec_boxed ("selection-box-color",
789 P_("Selection Box Color"),
790 P_("Color of the selection box"),
792 GTK_PARAM_READABLE));
794 gtk_widget_class_install_style_property (widget_class,
795 g_param_spec_uchar ("selection-box-alpha",
796 P_("Selection Box Alpha"),
797 P_("Opacity of the selection box"),
800 GTK_PARAM_READABLE));
804 * GtkIconView::set-scroll-adjustments
805 * @horizontal: the horizontal #GtkAdjustment
806 * @vertical: the vertical #GtkAdjustment
808 * Set the scroll adjustments for the icon view. Usually scrolled containers
809 * like #GtkScrolledWindow will emit this signal to connect two instances
810 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
812 widget_class->set_scroll_adjustments_signal =
813 g_signal_new (I_("set-scroll-adjustments"),
814 G_TYPE_FROM_CLASS (gobject_class),
816 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
818 _gtk_marshal_VOID__OBJECT_OBJECT,
820 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
823 * GtkIconView::item-activated:
824 * @iconview: the object on which the signal is emitted
825 * @path: the #GtkTreePath for the activated item
827 * The ::item-activated signal is emitted when the method
828 * gtk_icon_view_item_activated() is called or the user double
829 * clicks an item. It is also emitted when a non-editable item
830 * is selected and one of the keys: Space, Return or Enter is
833 icon_view_signals[ITEM_ACTIVATED] =
834 g_signal_new (I_("item-activated"),
835 G_TYPE_FROM_CLASS (gobject_class),
837 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
839 g_cclosure_marshal_VOID__BOXED,
844 * GtkIconView::selection-changed:
845 * @iconview: the object on which the signal is emitted
847 * The ::selection-changed signal is emitted when the selection
848 * (i.e. the set of selected items) changes.
850 icon_view_signals[SELECTION_CHANGED] =
851 g_signal_new (I_("selection-changed"),
852 G_TYPE_FROM_CLASS (gobject_class),
854 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
856 g_cclosure_marshal_VOID__VOID,
860 * GtkIconView::select-all:
861 * @iconview: the object on which the signal is emitted
863 * A <link linkend="keybinding-signals">keybinding signal</link>
864 * which gets emitted when the user selects all items.
866 * Applications should not connect to it, but may emit it with
867 * g_signal_emit_by_name() if they need to control selection
870 * The default binding for this signal is Ctrl-a.
872 icon_view_signals[SELECT_ALL] =
873 g_signal_new (I_("select-all"),
874 G_TYPE_FROM_CLASS (gobject_class),
875 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
876 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
878 g_cclosure_marshal_VOID__VOID,
882 * GtkIconView::unselect-all:
883 * @iconview: the object on which the signal is emitted
885 * A <link linkend="keybinding-signals">keybinding signal</link>
886 * which gets emitted when the user unselects all items.
888 * Applications should not connect to it, but may emit it with
889 * g_signal_emit_by_name() if they need to control selection
892 * The default binding for this signal is Ctrl-Shift-a.
894 icon_view_signals[UNSELECT_ALL] =
895 g_signal_new (I_("unselect-all"),
896 G_TYPE_FROM_CLASS (gobject_class),
897 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
898 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
900 g_cclosure_marshal_VOID__VOID,
904 * GtkIconView::select-cursor-item:
905 * @iconview: the object on which the signal is emitted
907 * A <link linkend="keybinding-signals">keybinding signal</link>
908 * which gets emitted when the user selects the item that is currently
911 * Applications should not connect to it, but may emit it with
912 * g_signal_emit_by_name() if they need to control selection
915 * There is no default binding for this signal.
917 icon_view_signals[SELECT_CURSOR_ITEM] =
918 g_signal_new (I_("select-cursor-item"),
919 G_TYPE_FROM_CLASS (gobject_class),
920 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
921 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
923 g_cclosure_marshal_VOID__VOID,
927 * GtkIconView::toggle-cursor-item:
928 * @iconview: the object on which the signal is emitted
930 * A <link linkend="keybinding-signals">keybinding signal</link>
931 * which gets emitted when the user toggles whether the currently
932 * focused item is selected or not. The exact effect of this
933 * depend on the selection mode.
935 * Applications should not connect to it, but may emit it with
936 * g_signal_emit_by_name() if they need to control selection
939 * There is no default binding for this signal is Ctrl-Space.
941 icon_view_signals[TOGGLE_CURSOR_ITEM] =
942 g_signal_new (I_("toggle-cursor-item"),
943 G_TYPE_FROM_CLASS (gobject_class),
944 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
945 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
947 g_cclosure_marshal_VOID__VOID,
951 * GtkIconView::activate-cursor-item:
952 * @iconview: the object on which the signal is emitted
954 * A <link linkend="keybinding-signals">keybinding signal</link>
955 * which gets emitted when the user activates the currently
958 * Applications should not connect to it, but may emit it with
959 * g_signal_emit_by_name() if they need to control activation
962 * The default bindings for this signal are Space, Return and Enter.
964 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
965 g_signal_new (I_("activate-cursor-item"),
966 G_TYPE_FROM_CLASS (gobject_class),
967 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
968 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
970 _gtk_marshal_BOOLEAN__VOID,
974 * GtkIconView::move-cursor:
975 * @iconview: the object which received the signal
976 * @step: the granularity of the move, as a #GtkMovementStep
977 * @count: the number of @step units to move
979 * The ::move-cursor signal is a
980 * <link linkend="keybinding-signals">keybinding signal</link>
981 * which gets emitted when the user initiates a cursor movement.
983 * Applications should not connect to it, but may emit it with
984 * g_signal_emit_by_name() if they need to control the cursor
987 * The default bindings for this signal include
989 * <listitem>Arrow keys which move by individual steps</listitem>
990 * <listitem>Home/End keys which move to the first/last item</listitem>
991 * <listitem>PageUp/PageDown which move by "pages"</listitem>
994 * All of these will extend the selection when combined with
995 * the Shift modifier.
997 icon_view_signals[MOVE_CURSOR] =
998 g_signal_new (I_("move-cursor"),
999 G_TYPE_FROM_CLASS (gobject_class),
1000 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1001 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1003 _gtk_marshal_BOOLEAN__ENUM_INT,
1005 GTK_TYPE_MOVEMENT_STEP,
1009 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1011 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1013 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
1014 "toggle-cursor-item", 0);
1015 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
1016 "toggle-cursor-item", 0);
1018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
1019 "activate-cursor-item", 0);
1020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
1021 "activate-cursor-item", 0);
1022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1023 "activate-cursor-item", 0);
1024 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1025 "activate-cursor-item", 0);
1026 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1027 "activate-cursor-item", 0);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1030 GTK_MOVEMENT_DISPLAY_LINES, -1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1032 GTK_MOVEMENT_DISPLAY_LINES, -1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1035 GTK_MOVEMENT_DISPLAY_LINES, 1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1037 GTK_MOVEMENT_DISPLAY_LINES, 1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1040 GTK_MOVEMENT_DISPLAY_LINES, -1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1043 GTK_MOVEMENT_DISPLAY_LINES, 1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1046 GTK_MOVEMENT_BUFFER_ENDS, -1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1048 GTK_MOVEMENT_BUFFER_ENDS, -1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1051 GTK_MOVEMENT_BUFFER_ENDS, 1);
1052 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1053 GTK_MOVEMENT_BUFFER_ENDS, 1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1056 GTK_MOVEMENT_PAGES, -1);
1057 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1058 GTK_MOVEMENT_PAGES, -1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1061 GTK_MOVEMENT_PAGES, 1);
1062 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1063 GTK_MOVEMENT_PAGES, 1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1066 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1067 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1068 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1070 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1071 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1072 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1073 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1077 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1079 parent_buildable_iface = g_type_interface_peek_parent (iface);
1080 iface->add_child = _gtk_cell_layout_buildable_add_child;
1081 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1082 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1086 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1088 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1089 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1090 iface->clear = gtk_icon_view_cell_layout_clear;
1091 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1092 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1093 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1094 iface->reorder = gtk_icon_view_cell_layout_reorder;
1095 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1099 gtk_icon_view_init (GtkIconView *icon_view)
1101 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1103 GtkIconViewPrivate);
1105 icon_view->priv->width = 0;
1106 icon_view->priv->height = 0;
1107 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1108 icon_view->priv->pressed_button = -1;
1109 icon_view->priv->press_start_x = -1;
1110 icon_view->priv->press_start_y = -1;
1111 icon_view->priv->text_column = -1;
1112 icon_view->priv->markup_column = -1;
1113 icon_view->priv->pixbuf_column = -1;
1114 icon_view->priv->text_cell = -1;
1115 icon_view->priv->pixbuf_cell = -1;
1116 icon_view->priv->tooltip_column = -1;
1118 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1120 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1122 icon_view->priv->cell_list = NULL;
1123 icon_view->priv->n_cells = 0;
1124 icon_view->priv->cursor_cell = -1;
1126 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1128 icon_view->priv->columns = -1;
1129 icon_view->priv->item_width = -1;
1130 icon_view->priv->spacing = 0;
1131 icon_view->priv->row_spacing = 6;
1132 icon_view->priv->column_spacing = 6;
1133 icon_view->priv->margin = 6;
1134 icon_view->priv->item_padding = 6;
1136 icon_view->priv->draw_focus = TRUE;
1140 gtk_icon_view_destroy (GtkObject *object)
1142 GtkIconView *icon_view;
1144 icon_view = GTK_ICON_VIEW (object);
1146 gtk_icon_view_stop_editing (icon_view, TRUE);
1148 gtk_icon_view_set_model (icon_view, NULL);
1150 if (icon_view->priv->layout_idle_id != 0)
1152 g_source_remove (icon_view->priv->layout_idle_id);
1153 icon_view->priv->layout_idle_id = 0;
1156 if (icon_view->priv->scroll_to_path != NULL)
1158 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1159 icon_view->priv->scroll_to_path = NULL;
1162 remove_scroll_timeout (icon_view);
1164 if (icon_view->priv->hadjustment != NULL)
1166 g_object_unref (icon_view->priv->hadjustment);
1167 icon_view->priv->hadjustment = NULL;
1170 if (icon_view->priv->vadjustment != NULL)
1172 g_object_unref (icon_view->priv->vadjustment);
1173 icon_view->priv->vadjustment = NULL;
1176 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1179 /* GObject methods */
1181 gtk_icon_view_finalize (GObject *object)
1183 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1185 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1190 gtk_icon_view_set_property (GObject *object,
1192 const GValue *value,
1195 GtkIconView *icon_view;
1197 icon_view = GTK_ICON_VIEW (object);
1201 case PROP_SELECTION_MODE:
1202 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1204 case PROP_PIXBUF_COLUMN:
1205 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1207 case PROP_TEXT_COLUMN:
1208 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1210 case PROP_MARKUP_COLUMN:
1211 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1214 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1216 case PROP_ITEM_ORIENTATION:
1217 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1220 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1222 case PROP_ITEM_WIDTH:
1223 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1226 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1228 case PROP_ROW_SPACING:
1229 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1231 case PROP_COLUMN_SPACING:
1232 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1235 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1237 case PROP_REORDERABLE:
1238 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1241 case PROP_TOOLTIP_COLUMN:
1242 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1245 case PROP_ITEM_PADDING:
1246 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1256 gtk_icon_view_get_property (GObject *object,
1261 GtkIconView *icon_view;
1263 icon_view = GTK_ICON_VIEW (object);
1267 case PROP_SELECTION_MODE:
1268 g_value_set_enum (value, icon_view->priv->selection_mode);
1270 case PROP_PIXBUF_COLUMN:
1271 g_value_set_int (value, icon_view->priv->pixbuf_column);
1273 case PROP_TEXT_COLUMN:
1274 g_value_set_int (value, icon_view->priv->text_column);
1276 case PROP_MARKUP_COLUMN:
1277 g_value_set_int (value, icon_view->priv->markup_column);
1280 g_value_set_object (value, icon_view->priv->model);
1282 case PROP_ITEM_ORIENTATION:
1283 g_value_set_enum (value, icon_view->priv->item_orientation);
1286 g_value_set_int (value, icon_view->priv->columns);
1288 case PROP_ITEM_WIDTH:
1289 g_value_set_int (value, icon_view->priv->item_width);
1292 g_value_set_int (value, icon_view->priv->spacing);
1294 case PROP_ROW_SPACING:
1295 g_value_set_int (value, icon_view->priv->row_spacing);
1297 case PROP_COLUMN_SPACING:
1298 g_value_set_int (value, icon_view->priv->column_spacing);
1301 g_value_set_int (value, icon_view->priv->margin);
1303 case PROP_REORDERABLE:
1304 g_value_set_boolean (value, icon_view->priv->reorderable);
1306 case PROP_TOOLTIP_COLUMN:
1307 g_value_set_int (value, icon_view->priv->tooltip_column);
1310 case PROP_ITEM_PADDING:
1311 g_value_set_int (value, icon_view->priv->item_padding);
1315 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1320 /* GtkWidget signals */
1322 gtk_icon_view_realize (GtkWidget *widget)
1324 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1325 GtkAllocation allocation;
1327 GdkWindowAttr attributes;
1328 gint attributes_mask;
1330 gtk_widget_set_realized (widget, TRUE);
1332 gtk_widget_get_allocation (widget, &allocation);
1334 /* Make the main, clipping window */
1335 attributes.window_type = GDK_WINDOW_CHILD;
1336 attributes.x = allocation.x;
1337 attributes.y = allocation.y;
1338 attributes.width = allocation.width;
1339 attributes.height = allocation.height;
1340 attributes.wclass = GDK_INPUT_OUTPUT;
1341 attributes.visual = gtk_widget_get_visual (widget);
1342 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1344 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1346 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1347 &attributes, attributes_mask);
1348 gtk_widget_set_window (widget, window);
1349 gdk_window_set_user_data (window, widget);
1351 gtk_widget_get_allocation (widget, &allocation);
1353 /* Make the window for the icon view */
1356 attributes.width = MAX (icon_view->priv->width, allocation.width);
1357 attributes.height = MAX (icon_view->priv->height, allocation.height);
1358 attributes.event_mask = (GDK_EXPOSURE_MASK |
1360 GDK_POINTER_MOTION_MASK |
1361 GDK_BUTTON_PRESS_MASK |
1362 GDK_BUTTON_RELEASE_MASK |
1363 GDK_KEY_PRESS_MASK |
1364 GDK_KEY_RELEASE_MASK) |
1365 gtk_widget_get_events (widget);
1367 icon_view->priv->bin_window = gdk_window_new (window,
1368 &attributes, attributes_mask);
1369 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1371 gtk_widget_style_attach (widget);
1372 gdk_window_set_background (icon_view->priv->bin_window,
1373 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1375 gdk_window_show (icon_view->priv->bin_window);
1379 gtk_icon_view_unrealize (GtkWidget *widget)
1381 GtkIconView *icon_view;
1383 icon_view = GTK_ICON_VIEW (widget);
1385 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1386 gdk_window_destroy (icon_view->priv->bin_window);
1387 icon_view->priv->bin_window = NULL;
1389 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1393 gtk_icon_view_state_changed (GtkWidget *widget,
1394 GtkStateType previous_state)
1396 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1400 if (gtk_widget_get_realized (widget))
1402 style = gtk_widget_get_style (widget);
1403 state = gtk_widget_get_state (widget);
1405 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1406 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1409 gtk_widget_queue_draw (widget);
1413 gtk_icon_view_style_set (GtkWidget *widget,
1414 GtkStyle *previous_style)
1416 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1420 if (gtk_widget_get_realized (widget))
1422 style = gtk_widget_get_style (widget);
1423 state = gtk_widget_get_state (widget);
1425 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1426 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1429 gtk_widget_queue_resize (widget);
1433 gtk_icon_view_size_request (GtkWidget *widget,
1434 GtkRequisition *requisition)
1436 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1439 requisition->width = icon_view->priv->width;
1440 requisition->height = icon_view->priv->height;
1442 tmp_list = icon_view->priv->children;
1446 GtkIconViewChild *child = tmp_list->data;
1447 GtkRequisition child_requisition;
1449 tmp_list = tmp_list->next;
1451 if (gtk_widget_get_visible (child->widget))
1452 gtk_widget_get_preferred_size (child->widget,
1453 &child_requisition, NULL);
1458 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1462 for (list = icon_view->priv->children; list; list = list->next)
1464 GtkIconViewChild *child = list->data;
1465 GtkAllocation allocation;
1467 /* totally ignore our child's requisition */
1468 if (child->cell < 0)
1470 allocation.x = child->item->x + icon_view->priv->item_padding;
1471 allocation.y = child->item->y + icon_view->priv->item_padding;
1472 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1473 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1477 GdkRectangle *box = &child->item->box[child->cell];
1479 allocation.x = box->x;
1480 allocation.y = box->y;
1481 allocation.width = box->width;
1482 allocation.height = box->height;
1485 gtk_widget_size_allocate (child->widget, &allocation);
1490 gtk_icon_view_size_allocate (GtkWidget *widget,
1491 GtkAllocation *allocation)
1493 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1495 GtkAdjustment *hadjustment, *vadjustment;
1497 gtk_widget_set_allocation (widget, allocation);
1499 if (gtk_widget_get_realized (widget))
1501 gdk_window_move_resize (gtk_widget_get_window (widget),
1502 allocation->x, allocation->y,
1503 allocation->width, allocation->height);
1504 gdk_window_resize (icon_view->priv->bin_window,
1505 MAX (icon_view->priv->width, allocation->width),
1506 MAX (icon_view->priv->height, allocation->height));
1509 gtk_icon_view_layout (icon_view);
1511 gtk_icon_view_allocate_children (icon_view);
1513 hadjustment = icon_view->priv->hadjustment;
1514 vadjustment = icon_view->priv->vadjustment;
1516 hadjustment->page_size = allocation->width;
1517 hadjustment->page_increment = allocation->width * 0.9;
1518 hadjustment->step_increment = allocation->width * 0.1;
1519 hadjustment->lower = 0;
1520 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1522 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1523 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1525 vadjustment->page_size = allocation->height;
1526 vadjustment->page_increment = allocation->height * 0.9;
1527 vadjustment->step_increment = allocation->height * 0.1;
1528 vadjustment->lower = 0;
1529 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1531 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1532 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1534 if (gtk_widget_get_realized (widget) &&
1535 icon_view->priv->scroll_to_path)
1538 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1539 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1540 icon_view->priv->scroll_to_path = NULL;
1542 gtk_icon_view_scroll_to_path (icon_view, path,
1543 icon_view->priv->scroll_to_use_align,
1544 icon_view->priv->scroll_to_row_align,
1545 icon_view->priv->scroll_to_col_align);
1546 gtk_tree_path_free (path);
1550 gtk_adjustment_changed (hadjustment);
1551 gtk_adjustment_changed (vadjustment);
1556 gtk_icon_view_draw (GtkWidget *widget,
1559 GtkIconView *icon_view;
1563 GtkIconViewDropPosition dest_pos;
1564 GtkIconViewItem *dest_item = NULL;
1567 icon_view = GTK_ICON_VIEW (widget);
1569 if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
1574 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
1575 cairo_translate (cr, x, y);
1577 /* If a layout has been scheduled, do it now so that all
1578 * cell view items have valid sizes before we proceed. */
1579 if (icon_view->priv->layout_idle_id != 0)
1580 gtk_icon_view_layout (icon_view);
1582 cairo_set_line_width (cr, 1.);
1584 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1588 dest_index = gtk_tree_path_get_indices (path)[0];
1589 gtk_tree_path_free (path);
1594 for (icons = icon_view->priv->items; icons; icons = icons->next)
1596 GtkIconViewItem *item = icons->data;
1600 cairo_rectangle (cr, item->x, item->y, item->width, item->height);
1603 if (gdk_cairo_get_clip_rectangle (cr, NULL))
1605 gtk_icon_view_paint_item (icon_view, cr, item,
1607 icon_view->priv->draw_focus);
1609 if (dest_index == item->index)
1621 style = gtk_widget_get_style (widget);
1622 state = gtk_widget_get_state (widget);
1626 case GTK_ICON_VIEW_DROP_INTO:
1627 gtk_paint_focus (style,
1631 "iconview-drop-indicator",
1632 dest_item->x, dest_item->y,
1633 dest_item->width, dest_item->height);
1635 case GTK_ICON_VIEW_DROP_ABOVE:
1636 gtk_paint_focus (style,
1640 "iconview-drop-indicator",
1641 dest_item->x, dest_item->y - 1,
1642 dest_item->width, 2);
1644 case GTK_ICON_VIEW_DROP_LEFT:
1645 gtk_paint_focus (style,
1649 "iconview-drop-indicator",
1650 dest_item->x - 1, dest_item->y,
1651 2, dest_item->height);
1653 case GTK_ICON_VIEW_DROP_BELOW:
1654 gtk_paint_focus (style,
1658 "iconview-drop-indicator",
1659 dest_item->x, dest_item->y + dest_item->height - 1,
1660 dest_item->width, 2);
1662 case GTK_ICON_VIEW_DROP_RIGHT:
1663 gtk_paint_focus (style,
1667 "iconview-drop-indicator",
1668 dest_item->x + dest_item->width - 1, dest_item->y,
1669 2, dest_item->height);
1670 case GTK_ICON_VIEW_NO_DROP: ;
1675 if (icon_view->priv->doing_rubberband)
1676 gtk_icon_view_paint_rubberband (icon_view, cr);
1680 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->draw (widget, cr);
1686 rubberband_scroll_timeout (gpointer data)
1688 GtkIconView *icon_view = data;
1690 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1691 icon_view->priv->vadjustment->value +
1692 icon_view->priv->scroll_value_diff);
1694 gtk_icon_view_update_rubberband (icon_view);
1700 gtk_icon_view_motion (GtkWidget *widget,
1701 GdkEventMotion *event)
1703 GtkAllocation allocation;
1704 GtkIconView *icon_view;
1707 icon_view = GTK_ICON_VIEW (widget);
1709 gtk_icon_view_maybe_begin_drag (icon_view, event);
1711 if (icon_view->priv->doing_rubberband)
1713 gtk_icon_view_update_rubberband (widget);
1715 abs_y = event->y - icon_view->priv->height *
1716 (icon_view->priv->vadjustment->value /
1717 (icon_view->priv->vadjustment->upper -
1718 icon_view->priv->vadjustment->lower));
1720 gtk_widget_get_allocation (widget, &allocation);
1722 if (abs_y < 0 || abs_y > allocation.height)
1725 icon_view->priv->scroll_value_diff = abs_y;
1727 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1729 icon_view->priv->event_last_x = event->x;
1730 icon_view->priv->event_last_y = event->y;
1732 if (icon_view->priv->scroll_timeout_id == 0)
1733 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1737 remove_scroll_timeout (icon_view);
1744 gtk_icon_view_remove (GtkContainer *container,
1747 GtkIconView *icon_view;
1748 GtkIconViewChild *child = NULL;
1751 icon_view = GTK_ICON_VIEW (container);
1753 tmp_list = icon_view->priv->children;
1756 child = tmp_list->data;
1757 if (child->widget == widget)
1759 gtk_widget_unparent (widget);
1761 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1762 g_list_free_1 (tmp_list);
1767 tmp_list = tmp_list->next;
1772 gtk_icon_view_forall (GtkContainer *container,
1773 gboolean include_internals,
1774 GtkCallback callback,
1775 gpointer callback_data)
1777 GtkIconView *icon_view;
1778 GtkIconViewChild *child = NULL;
1781 icon_view = GTK_ICON_VIEW (container);
1783 tmp_list = icon_view->priv->children;
1786 child = tmp_list->data;
1787 tmp_list = tmp_list->next;
1789 (* callback) (child->widget, callback_data);
1794 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1795 GtkIconViewItem *item,
1796 GtkIconViewCellInfo *info,
1801 GdkRectangle cell_area;
1802 gboolean visible, mode;
1804 gtk_icon_view_set_cell_data (icon_view, item);
1806 g_object_get (info->cell,
1807 "visible", &visible,
1811 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1813 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1815 path = gtk_tree_path_new_from_indices (item->index, -1);
1816 path_string = gtk_tree_path_to_string (path);
1817 gtk_tree_path_free (path);
1819 gtk_cell_renderer_activate (info->cell,
1821 GTK_WIDGET (icon_view),
1827 g_free (path_string);
1832 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1833 GtkIconViewItem *item)
1836 AtkObject *item_obj;
1838 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1841 item_obj = atk_object_ref_accessible_child (obj, item->index);
1842 if (item_obj != NULL)
1844 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1845 g_object_unref (item_obj);
1851 gtk_icon_view_put (GtkIconView *icon_view,
1853 GtkIconViewItem *item,
1856 GtkIconViewChild *child;
1858 child = g_new (GtkIconViewChild, 1);
1860 child->widget = widget;
1864 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1866 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1867 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1869 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1873 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1874 GtkIconView *icon_view)
1877 GtkIconViewItem *item;
1879 if (icon_view->priv->edited_item == NULL)
1882 item = icon_view->priv->edited_item;
1883 icon_view->priv->edited_item = NULL;
1884 icon_view->priv->editable = NULL;
1885 for (l = icon_view->priv->cell_list; l; l = l->next)
1887 GtkIconViewCellInfo *info = l->data;
1889 info->editing = FALSE;
1892 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1893 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1895 g_signal_handlers_disconnect_by_func (editable,
1896 gtk_icon_view_remove_widget,
1899 gtk_container_remove (GTK_CONTAINER (icon_view),
1900 GTK_WIDGET (editable));
1902 gtk_icon_view_queue_draw_item (icon_view, item);
1907 gtk_icon_view_start_editing (GtkIconView *icon_view,
1908 GtkIconViewItem *item,
1909 GtkIconViewCellInfo *info,
1914 GdkRectangle cell_area;
1915 gboolean visible, mode;
1916 GtkCellEditable *editable;
1918 gtk_icon_view_set_cell_data (icon_view, item);
1920 g_object_get (info->cell,
1921 "visible", &visible,
1924 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1926 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1928 path = gtk_tree_path_new_from_indices (item->index, -1);
1929 path_string = gtk_tree_path_to_string (path);
1930 gtk_tree_path_free (path);
1932 editable = gtk_cell_renderer_start_editing (info->cell,
1934 GTK_WIDGET (icon_view),
1939 g_free (path_string);
1941 /* the rest corresponds to tree_view_real_start_editing... */
1942 icon_view->priv->edited_item = item;
1943 icon_view->priv->editable = editable;
1944 info->editing = TRUE;
1946 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1948 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1950 gtk_widget_grab_focus (GTK_WIDGET (editable));
1951 g_signal_connect (editable, "remove-widget",
1952 G_CALLBACK (gtk_icon_view_remove_widget),
1959 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1960 gboolean cancel_editing)
1962 GtkCellRenderer *cell = NULL;
1963 GtkIconViewItem *item;
1966 if (icon_view->priv->edited_item == NULL)
1970 * This is very evil. We need to do this, because
1971 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1972 * later on. If gtk_icon_view_row_changed notices
1973 * icon_view->priv->edited_item != NULL, it'll call
1974 * gtk_icon_view_stop_editing again. Bad things will happen then.
1976 * Please read that again if you intend to modify anything here.
1979 item = icon_view->priv->edited_item;
1980 icon_view->priv->edited_item = NULL;
1982 for (l = icon_view->priv->cell_list; l; l = l->next)
1984 GtkIconViewCellInfo *info = l->data;
1996 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1997 if (!cancel_editing)
1998 gtk_cell_editable_editing_done (icon_view->priv->editable);
2000 icon_view->priv->edited_item = item;
2002 gtk_cell_editable_remove_widget (icon_view->priv->editable);
2006 * gtk_icon_view_set_cursor:
2007 * @icon_view: A #GtkIconView
2008 * @path: A #GtkTreePath
2009 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2010 * @start_editing: %TRUE if the specified cell should start being edited.
2012 * Sets the current keyboard focus to be at @path, and selects it. This is
2013 * useful when you want to focus the user's attention on a particular item.
2014 * If @cell is not %NULL, then focus is given to the cell specified by
2015 * it. Additionally, if @start_editing is %TRUE, then editing should be
2016 * started in the specified cell.
2018 * This function is often followed by <literal>gtk_widget_grab_focus
2019 * (icon_view)</literal> in order to give keyboard focus to the widget.
2020 * Please note that editing can only happen when the widget is realized.
2025 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2027 GtkCellRenderer *cell,
2028 gboolean start_editing)
2030 GtkIconViewItem *item = NULL;
2031 GtkIconViewCellInfo *info = NULL;
2035 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2036 g_return_if_fail (path != NULL);
2037 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2039 gtk_icon_view_stop_editing (icon_view, TRUE);
2041 if (gtk_tree_path_get_depth (path) == 1)
2042 item = g_list_nth_data (icon_view->priv->items,
2043 gtk_tree_path_get_indices(path)[0]);
2049 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2053 if (info->cell == cell)
2062 g_return_if_fail (cell == NULL || info != NULL);
2064 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2065 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2067 if (info && start_editing)
2068 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2072 * gtk_icon_view_get_cursor:
2073 * @icon_view: A #GtkIconView
2074 * @path: (allow-none): Return location for the current cursor path, or %NULL
2075 * @cell: (allow-none): Return location the current focus cell, or %NULL
2077 * Fills in @path and @cell with the current cursor path and cell.
2078 * If the cursor isn't currently set, then *@path will be %NULL.
2079 * If no cell currently has focus, then *@cell will be %NULL.
2081 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2083 * Return value: %TRUE if the cursor is set.
2088 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2090 GtkCellRenderer **cell)
2092 GtkIconViewItem *item;
2093 GtkIconViewCellInfo *info;
2095 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2097 item = icon_view->priv->cursor_item;
2098 if (icon_view->priv->cursor_cell < 0)
2101 info = g_list_nth_data (icon_view->priv->cell_list,
2102 icon_view->priv->cursor_cell);
2107 *path = gtk_tree_path_new_from_indices (item->index, -1);
2120 return (item != NULL);
2124 gtk_icon_view_button_press (GtkWidget *widget,
2125 GdkEventButton *event)
2127 GtkIconView *icon_view;
2128 GtkIconViewItem *item;
2129 GtkIconViewCellInfo *info = NULL;
2130 gboolean dirty = FALSE;
2131 GtkCellRendererMode mode;
2132 gint cursor_cell = -1;
2134 icon_view = GTK_ICON_VIEW (widget);
2136 if (event->window != icon_view->priv->bin_window)
2139 if (!gtk_widget_has_focus (widget))
2140 gtk_widget_grab_focus (widget);
2142 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2144 item = gtk_icon_view_get_item_at_coords (icon_view,
2150 * We consider only the the cells' area as the item area if the
2151 * item is not selected, but if it *is* selected, the complete
2152 * selection rectangle is considered to be part of the item.
2154 if (item != NULL && (info != NULL || item->selected))
2158 g_object_get (info->cell, "mode", &mode, NULL);
2160 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2161 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2162 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2165 gtk_icon_view_scroll_to_item (icon_view, item);
2167 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2169 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2171 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2172 (event->state & GDK_SHIFT_MASK))
2174 gtk_icon_view_unselect_all_internal (icon_view);
2176 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2177 if (!icon_view->priv->anchor_item)
2178 icon_view->priv->anchor_item = item;
2180 gtk_icon_view_select_all_between (icon_view,
2181 icon_view->priv->anchor_item,
2187 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2188 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2189 (event->state & GDK_CONTROL_MASK))
2191 item->selected = !item->selected;
2192 gtk_icon_view_queue_draw_item (icon_view, item);
2197 gtk_icon_view_unselect_all_internal (icon_view);
2199 item->selected = TRUE;
2200 gtk_icon_view_queue_draw_item (icon_view, item);
2203 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2204 icon_view->priv->anchor_item = item;
2207 /* Save press to possibly begin a drag */
2208 if (icon_view->priv->pressed_button < 0)
2210 icon_view->priv->pressed_button = event->button;
2211 icon_view->priv->press_start_x = event->x;
2212 icon_view->priv->press_start_y = event->y;
2215 if (!icon_view->priv->last_single_clicked)
2216 icon_view->priv->last_single_clicked = item;
2218 /* cancel the current editing, if it exists */
2219 gtk_icon_view_stop_editing (icon_view, TRUE);
2223 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2224 gtk_icon_view_item_activate_cell (icon_view, item, info,
2226 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2227 gtk_icon_view_start_editing (icon_view, item, info,
2233 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2234 !(event->state & GDK_CONTROL_MASK))
2236 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2239 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2240 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2243 /* don't draw keyboard focus around an clicked-on item */
2244 icon_view->priv->draw_focus = FALSE;
2247 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2249 item = gtk_icon_view_get_item_at_coords (icon_view,
2254 if (item && item == icon_view->priv->last_single_clicked)
2258 path = gtk_tree_path_new_from_indices (item->index, -1);
2259 gtk_icon_view_item_activated (icon_view, path);
2260 gtk_tree_path_free (path);
2263 icon_view->priv->last_single_clicked = NULL;
2264 icon_view->priv->pressed_button = -1;
2268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2270 return event->button == 1;
2274 gtk_icon_view_button_release (GtkWidget *widget,
2275 GdkEventButton *event)
2277 GtkIconView *icon_view;
2279 icon_view = GTK_ICON_VIEW (widget);
2281 if (icon_view->priv->pressed_button == event->button)
2282 icon_view->priv->pressed_button = -1;
2284 gtk_icon_view_stop_rubberbanding (icon_view);
2286 remove_scroll_timeout (icon_view);
2292 gtk_icon_view_key_press (GtkWidget *widget,
2295 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2297 if (icon_view->priv->doing_rubberband)
2299 if (event->keyval == GDK_KEY_Escape)
2300 gtk_icon_view_stop_rubberbanding (icon_view);
2305 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2309 gtk_icon_view_key_release (GtkWidget *widget,
2312 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2314 if (icon_view->priv->doing_rubberband)
2317 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2321 gtk_icon_view_update_rubberband (gpointer data)
2323 GtkIconView *icon_view;
2325 GdkRectangle old_area;
2326 GdkRectangle new_area;
2327 GdkRectangle common;
2328 cairo_region_t *invalid_region;
2330 icon_view = GTK_ICON_VIEW (data);
2332 gdk_window_get_device_position (icon_view->priv->bin_window,
2333 icon_view->priv->rubberband_device,
2339 old_area.x = MIN (icon_view->priv->rubberband_x1,
2340 icon_view->priv->rubberband_x2);
2341 old_area.y = MIN (icon_view->priv->rubberband_y1,
2342 icon_view->priv->rubberband_y2);
2343 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2344 icon_view->priv->rubberband_x1) + 1;
2345 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2346 icon_view->priv->rubberband_y1) + 1;
2348 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2349 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2350 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2351 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2353 invalid_region = cairo_region_create_rectangle (&old_area);
2354 cairo_region_union_rectangle (invalid_region, &new_area);
2356 gdk_rectangle_intersect (&old_area, &new_area, &common);
2357 if (common.width > 2 && common.height > 2)
2359 cairo_region_t *common_region;
2361 /* make sure the border is invalidated */
2367 common_region = cairo_region_create_rectangle (&common);
2369 cairo_region_subtract (invalid_region, common_region);
2370 cairo_region_destroy (common_region);
2373 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2375 cairo_region_destroy (invalid_region);
2377 icon_view->priv->rubberband_x2 = x;
2378 icon_view->priv->rubberband_y2 = y;
2380 gtk_icon_view_update_rubberband_selection (icon_view);
2384 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2391 if (icon_view->priv->rubberband_device)
2394 for (items = icon_view->priv->items; items; items = items->next)
2396 GtkIconViewItem *item = items->data;
2398 item->selected_before_rubberbanding = item->selected;
2401 icon_view->priv->rubberband_x1 = x;
2402 icon_view->priv->rubberband_y1 = y;
2403 icon_view->priv->rubberband_x2 = x;
2404 icon_view->priv->rubberband_y2 = y;
2406 icon_view->priv->doing_rubberband = TRUE;
2407 icon_view->priv->rubberband_device = device;
2409 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2413 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2415 if (!icon_view->priv->doing_rubberband)
2418 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2419 icon_view->priv->rubberband_device);
2421 icon_view->priv->doing_rubberband = FALSE;
2422 icon_view->priv->rubberband_device = NULL;
2424 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2428 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2431 gint x, y, width, height;
2432 gboolean dirty = FALSE;
2434 x = MIN (icon_view->priv->rubberband_x1,
2435 icon_view->priv->rubberband_x2);
2436 y = MIN (icon_view->priv->rubberband_y1,
2437 icon_view->priv->rubberband_y2);
2438 width = ABS (icon_view->priv->rubberband_x1 -
2439 icon_view->priv->rubberband_x2);
2440 height = ABS (icon_view->priv->rubberband_y1 -
2441 icon_view->priv->rubberband_y2);
2443 for (items = icon_view->priv->items; items; items = items->next)
2445 GtkIconViewItem *item = items->data;
2449 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2450 x, y, width, height);
2452 selected = is_in ^ item->selected_before_rubberbanding;
2454 if (item->selected != selected)
2456 item->selected = selected;
2458 gtk_icon_view_queue_draw_item (icon_view, item);
2463 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2467 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2468 GtkIconViewItem *item,
2477 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2478 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2481 for (l = icon_view->priv->cell_list; l; l = l->next)
2483 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2485 if (!gtk_cell_renderer_get_visible (info->cell))
2488 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2490 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2491 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2499 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2501 gboolean dirty = FALSE;
2504 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2507 for (items = icon_view->priv->items; items; items = items->next)
2509 GtkIconViewItem *item = items->data;
2513 item->selected = FALSE;
2515 gtk_icon_view_queue_draw_item (icon_view, item);
2516 gtk_icon_view_item_selected_changed (icon_view, item);
2524 /* GtkIconView signals */
2526 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2527 GtkAdjustment *hadj,
2528 GtkAdjustment *vadj)
2530 gboolean need_adjust = FALSE;
2533 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2535 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2537 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2539 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2541 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2543 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2544 0, 0, NULL, NULL, icon_view);
2545 g_object_unref (icon_view->priv->hadjustment);
2548 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2550 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2551 0, 0, NULL, NULL, icon_view);
2552 g_object_unref (icon_view->priv->vadjustment);
2555 if (icon_view->priv->hadjustment != hadj)
2557 icon_view->priv->hadjustment = hadj;
2558 g_object_ref_sink (icon_view->priv->hadjustment);
2560 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2561 G_CALLBACK (gtk_icon_view_adjustment_changed),
2566 if (icon_view->priv->vadjustment != vadj)
2568 icon_view->priv->vadjustment = vadj;
2569 g_object_ref_sink (icon_view->priv->vadjustment);
2571 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2572 G_CALLBACK (gtk_icon_view_adjustment_changed),
2578 gtk_icon_view_adjustment_changed (NULL, icon_view);
2582 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2584 gtk_icon_view_select_all (icon_view);
2588 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2590 gtk_icon_view_unselect_all (icon_view);
2594 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2596 gtk_icon_view_unselect_all (icon_view);
2598 if (icon_view->priv->cursor_item != NULL)
2599 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2603 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2606 GtkCellRendererMode mode;
2607 GtkIconViewCellInfo *info = NULL;
2609 if (!icon_view->priv->cursor_item)
2612 info = g_list_nth_data (icon_view->priv->cell_list,
2613 icon_view->priv->cursor_cell);
2617 g_object_get (info->cell, "mode", &mode, NULL);
2619 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2621 gtk_icon_view_item_activate_cell (icon_view,
2622 icon_view->priv->cursor_item,
2626 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2628 gtk_icon_view_start_editing (icon_view,
2629 icon_view->priv->cursor_item,
2635 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2636 gtk_icon_view_item_activated (icon_view, path);
2637 gtk_tree_path_free (path);
2643 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2645 if (!icon_view->priv->cursor_item)
2648 switch (icon_view->priv->selection_mode)
2650 case GTK_SELECTION_NONE:
2652 case GTK_SELECTION_BROWSE:
2653 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2655 case GTK_SELECTION_SINGLE:
2656 if (icon_view->priv->cursor_item->selected)
2657 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2659 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2661 case GTK_SELECTION_MULTIPLE:
2662 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2663 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2665 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2666 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2671 /* Internal functions */
2673 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2674 GtkIconView *icon_view)
2676 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2678 gdk_window_move (icon_view->priv->bin_window,
2679 - icon_view->priv->hadjustment->value,
2680 - icon_view->priv->vadjustment->value);
2682 if (icon_view->priv->doing_rubberband)
2683 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2685 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2690 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2695 gint *maximum_width)
2697 GtkAllocation allocation;
2698 GtkWidget *widget = GTK_WIDGET (icon_view);
2700 gint x, current_width;
2701 GList *items, *last_item;
2708 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2709 max_height = g_new0 (gint, icon_view->priv->n_cells);
2716 gtk_widget_style_get (widget,
2717 "focus-line-width", &focus_width,
2720 x += icon_view->priv->margin + focus_width;
2721 current_width += 2 * (icon_view->priv->margin + focus_width);
2726 GtkIconViewItem *item = items->data;
2728 gtk_icon_view_calculate_item_size (icon_view, item);
2729 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2731 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2733 current_width += item->width;
2735 if (items != first_item)
2737 gtk_widget_get_allocation (widget, &allocation);
2739 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2740 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2744 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2746 item->y = *y + focus_width;
2749 x = current_width - (icon_view->priv->margin + focus_width);
2751 for (i = 0; i < icon_view->priv->n_cells; i++)
2752 max_height[i] = MAX (max_height[i], item->box[i].height);
2754 if (current_width > *maximum_width)
2755 *maximum_width = current_width;
2761 items = items->next;
2766 /* Now go through the row again and align the icons */
2767 for (items = first_item; items != last_item; items = items->next)
2769 GtkIconViewItem *item = items->data;
2773 item->x = *maximum_width - item->width - item->x;
2774 item->col = col - 1 - item->col;
2777 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2779 /* We may want to readjust the new y coordinate. */
2780 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2781 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2784 g_free (max_height);
2790 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2793 if (upper != adj->upper)
2795 gdouble min = MAX (0.0, upper - adj->page_size);
2796 gboolean value_changed = FALSE;
2800 if (adj->value > min)
2803 value_changed = TRUE;
2806 gtk_adjustment_changed (adj);
2809 gtk_adjustment_value_changed (adj);
2814 gtk_icon_view_layout (GtkIconView *icon_view)
2816 GtkAllocation allocation;
2819 gint y = 0, maximum_width = 0;
2822 gboolean size_changed = FALSE;
2824 if (icon_view->priv->layout_idle_id != 0)
2826 g_source_remove (icon_view->priv->layout_idle_id);
2827 icon_view->priv->layout_idle_id = 0;
2830 if (icon_view->priv->model == NULL)
2833 widget = GTK_WIDGET (icon_view);
2835 item_width = icon_view->priv->item_width;
2839 for (icons = icon_view->priv->items; icons; icons = icons->next)
2841 GtkIconViewItem *item = icons->data;
2842 gtk_icon_view_calculate_item_size (icon_view, item);
2843 item_width = MAX (item_width, item->width);
2848 icons = icon_view->priv->items;
2849 y += icon_view->priv->margin;
2854 gtk_icon_view_set_cell_data (icon_view, icons->data);
2855 adjust_wrap_width (icon_view, icons->data);
2860 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2862 &y, &maximum_width);
2865 while (icons != NULL);
2867 if (maximum_width != icon_view->priv->width)
2869 icon_view->priv->width = maximum_width;
2870 size_changed = TRUE;
2873 y += icon_view->priv->margin;
2875 if (y != icon_view->priv->height)
2877 icon_view->priv->height = y;
2878 size_changed = TRUE;
2881 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2882 icon_view->priv->width);
2883 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2884 icon_view->priv->height);
2887 gtk_widget_queue_resize_no_redraw (widget);
2889 gtk_widget_get_allocation (widget, &allocation);
2890 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2891 gdk_window_resize (icon_view->priv->bin_window,
2892 MAX (icon_view->priv->width, allocation.width),
2893 MAX (icon_view->priv->height, allocation.height));
2895 if (icon_view->priv->scroll_to_path)
2899 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2900 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2901 icon_view->priv->scroll_to_path = NULL;
2903 gtk_icon_view_scroll_to_path (icon_view, path,
2904 icon_view->priv->scroll_to_use_align,
2905 icon_view->priv->scroll_to_row_align,
2906 icon_view->priv->scroll_to_col_align);
2907 gtk_tree_path_free (path);
2910 gtk_widget_queue_draw (widget);
2914 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2915 GtkIconViewItem *item,
2916 GtkIconViewCellInfo *info,
2917 GdkRectangle *cell_area)
2919 g_return_if_fail (info->position < item->n_cells);
2921 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
2923 cell_area->x = item->box[info->position].x - item->before[info->position];
2924 cell_area->y = item->y + icon_view->priv->item_padding;
2925 cell_area->width = item->box[info->position].width +
2926 item->before[info->position] + item->after[info->position];
2927 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2931 cell_area->x = item->x + icon_view->priv->item_padding;
2932 cell_area->y = item->box[info->position].y - item->before[info->position];
2933 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2934 cell_area->height = item->box[info->position].height +
2935 item->before[info->position] + item->after[info->position];
2940 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2941 GtkIconViewItem *item,
2942 GtkIconViewCellInfo *info,
2945 g_return_if_fail (info->position < item->n_cells);
2947 *box = item->box[info->position];
2950 /* try to guess a reasonable wrap width for an implicit text cell renderer
2953 adjust_wrap_width (GtkIconView *icon_view,
2954 GtkIconViewItem *item)
2956 GtkIconViewCellInfo *text_info;
2957 GtkIconViewCellInfo *pixbuf_info;
2960 if (icon_view->priv->text_cell != -1 &&
2961 icon_view->priv->pixbuf_cell != -1)
2963 GtkRequisition min_size;
2966 text_info = g_list_nth_data (icon_view->priv->cell_list,
2967 icon_view->priv->text_cell);
2968 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2969 icon_view->priv->pixbuf_cell);
2971 gtk_cell_renderer_get_preferred_size (pixbuf_info->cell,
2972 GTK_WIDGET (icon_view),
2975 if (icon_view->priv->item_width > 0)
2976 item_width = icon_view->priv->item_width;
2978 item_width = item->width;
2980 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
2981 wrap_width = item_width;
2983 if (item->width == -1 && item_width <= 0)
2984 wrap_width = MAX (2 * min_size.width, 50);
2986 wrap_width = item_width - min_size.width - icon_view->priv->spacing;
2989 wrap_width -= icon_view->priv->item_padding * 2;
2991 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2992 g_object_set (text_info->cell, "width", wrap_width, NULL);
2997 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2998 GtkIconViewItem *item)
3000 GtkRequisition min_size;
3004 if (item->width != -1 && item->height != -1)
3007 if (item->n_cells != icon_view->priv->n_cells)
3009 g_free (item->before);
3010 g_free (item->after);
3013 item->before = g_new0 (gint, icon_view->priv->n_cells);
3014 item->after = g_new0 (gint, icon_view->priv->n_cells);
3015 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
3017 item->n_cells = icon_view->priv->n_cells;
3020 gtk_icon_view_set_cell_data (icon_view, item);
3022 spacing = icon_view->priv->spacing;
3026 for (l = icon_view->priv->cell_list; l; l = l->next)
3028 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3030 if (!gtk_cell_renderer_get_visible (info->cell))
3033 gtk_cell_renderer_get_preferred_size (info->cell,
3034 GTK_WIDGET (icon_view),
3036 item->box[info->position].width = min_size.width;
3037 item->box[info->position].height = min_size.height;
3039 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3041 item->width += item->box[info->position].width
3042 + (info->position > 0 ? spacing : 0);
3043 item->height = MAX (item->height, item->box[info->position].height);
3047 item->width = MAX (item->width, item->box[info->position].width);
3048 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3052 item->width += icon_view->priv->item_padding * 2;
3053 item->height += icon_view->priv->item_padding * 2;
3057 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3058 GtkIconViewItem *item,
3061 GtkRequisition min_size;
3062 GdkRectangle cell_area;
3068 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3070 gtk_icon_view_set_cell_data (icon_view, item);
3072 spacing = icon_view->priv->spacing;
3075 for (i = 0; i < icon_view->priv->n_cells; i++)
3077 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3078 item->height = MAX (item->height, max_height[i]);
3080 item->height += max_height[i] + (i > 0 ? spacing : 0);
3083 cell_area.x = item->x + icon_view->priv->item_padding;
3084 cell_area.y = item->y + icon_view->priv->item_padding;
3086 for (k = 0; k < 2; k++)
3087 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3089 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3091 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3094 if (!gtk_cell_renderer_get_visible (info->cell))
3097 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3099 /* We should not subtract icon_view->priv->item_padding from item->height,
3100 * because item->height is recalculated above using
3101 * max_height which does not contain item padding.
3103 cell_area.width = item->box[info->position].width;
3104 cell_area.height = item->height;
3108 /* item->width is not recalculated and thus needs to be
3109 * corrected for the padding.
3111 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3112 cell_area.height = max_height[i];
3115 gtk_cell_renderer_get_preferred_size (info->cell,
3116 GTK_WIDGET (icon_view),
3118 item->box[info->position].width = min_size.width;
3119 item->box[info->position].height = min_size.height;
3121 _gtk_cell_renderer_calc_offset (info->cell, &cell_area,
3122 gtk_widget_get_direction (GTK_WIDGET (icon_view)),
3123 item->box[info->position].width, item->box[info->position].height,
3124 &item->box[info->position].x, &item->box[info->position].y);
3125 item->box[info->position].x += cell_area.x;
3126 item->box[info->position].y += cell_area.y;
3128 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3130 item->before[info->position] = item->box[info->position].x - cell_area.x;
3131 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3132 cell_area.x += cell_area.width + spacing;
3136 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3138 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3139 cell_area.width = item->width;
3141 item->before[info->position] = item->box[info->position].y - cell_area.y;
3142 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3143 cell_area.y += cell_area.height + spacing;
3147 if (rtl && icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3149 for (i = 0; i < icon_view->priv->n_cells; i++)
3151 item->box[i].x = item->x + item->width -
3152 (item->box[i].x + item->box[i].width - item->x);
3156 item->height += icon_view->priv->item_padding * 2;
3160 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3162 g_list_foreach (icon_view->priv->items,
3163 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3167 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3174 gtk_icon_view_paint_item (GtkIconView *icon_view,
3176 GtkIconViewItem *item,
3179 gboolean draw_focus)
3183 GdkRectangle cell_area, box;
3187 GtkCellRendererState flags;
3189 GtkWidget *widget = GTK_WIDGET (icon_view);
3191 if (icon_view->priv->model == NULL)
3194 gtk_icon_view_set_cell_data (icon_view, item);
3196 style = gtk_widget_get_style (widget);
3197 gtk_widget_style_get (widget,
3198 "focus-line-width", &focus_width,
3201 padding = focus_width;
3205 flags = GTK_CELL_RENDERER_SELECTED;
3206 if (gtk_widget_has_focus (widget))
3207 state = GTK_STATE_SELECTED;
3209 state = GTK_STATE_ACTIVE;
3214 state = GTK_STATE_NORMAL;
3219 gtk_paint_flat_box (style,
3223 GTK_WIDGET (icon_view),
3226 item->width, item->height);
3229 for (l = icon_view->priv->cell_list; l; l = l->next)
3231 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3233 if (!gtk_cell_renderer_get_visible (info->cell))
3236 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3238 cell_area.x = x - item->x + cell_area.x;
3239 cell_area.y = y - item->y + cell_area.y;
3241 gtk_cell_renderer_render (info->cell,
3244 &cell_area, &cell_area, flags);
3248 gtk_widget_has_focus (widget) &&
3249 item == icon_view->priv->cursor_item)
3251 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3253 GtkCellRendererMode mode;
3254 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3256 if (!gtk_cell_renderer_get_visible (info->cell))
3259 /* If found a editable/activatable cell, draw focus on it. */
3260 g_object_get (info->cell, "mode", &mode, NULL);
3261 if (icon_view->priv->cursor_cell < 0 &&
3262 mode != GTK_CELL_RENDERER_MODE_INERT)
3263 icon_view->priv->cursor_cell = i;
3265 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3267 if (i == icon_view->priv->cursor_cell)
3269 gtk_paint_focus (style,
3274 x - item->x + box.x - padding,
3275 y - item->y + box.y - padding,
3276 box.width + 2 * padding,
3277 box.height + 2 * padding);
3282 /* If there are no editable/activatable cells, draw focus
3283 * around the whole item.
3285 if (icon_view->priv->cursor_cell < 0)
3286 gtk_paint_focus (style,
3293 item->width + 2 * padding,
3294 item->height + 2 * padding);
3299 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3303 GdkColor *fill_color_gdk;
3304 guchar fill_color_alpha;
3308 rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3309 rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3310 rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3311 rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3313 gtk_widget_style_get (GTK_WIDGET (icon_view),
3314 "selection-box-color", &fill_color_gdk,
3315 "selection-box-alpha", &fill_color_alpha,
3318 if (!fill_color_gdk)
3319 fill_color_gdk = gdk_color_copy (>k_widget_get_style (GTK_WIDGET (icon_view))->base[GTK_STATE_SELECTED]);
3321 gdk_cairo_set_source_color (cr, fill_color_gdk);
3323 gdk_cairo_rectangle (cr, &rect);
3326 cairo_paint_with_alpha (cr, fill_color_alpha / 255.);
3328 cairo_rectangle (cr,
3329 rect.x + 0.5, rect.y + 0.5,
3330 rect.width - 1, rect.height - 1);
3333 gdk_color_free (fill_color_gdk);
3339 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3345 index = gtk_tree_path_get_indices (path)[0];
3347 for (l = icon_view->priv->items; l; l = l->next)
3349 GtkIconViewItem *item = l->data;
3351 if (item->index == index)
3353 gtk_icon_view_queue_draw_item (icon_view, item);
3360 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3361 GtkIconViewItem *item)
3366 gtk_widget_style_get (GTK_WIDGET (icon_view),
3367 "focus-line-width", &focus_width,
3370 rect.x = item->x - focus_width;
3371 rect.y = item->y - focus_width;
3372 rect.width = item->width + 2 * focus_width;
3373 rect.height = item->height + 2 * focus_width;
3375 if (icon_view->priv->bin_window)
3376 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3380 layout_callback (gpointer user_data)
3382 GtkIconView *icon_view;
3384 icon_view = GTK_ICON_VIEW (user_data);
3386 icon_view->priv->layout_idle_id = 0;
3388 gtk_icon_view_layout (icon_view);
3394 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3396 if (icon_view->priv->layout_idle_id != 0)
3399 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3403 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3404 GtkIconViewItem *item,
3408 AtkObject *item_obj;
3409 AtkObject *cursor_item_obj;
3411 if (icon_view->priv->cursor_item == item &&
3412 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3415 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3416 if (icon_view->priv->cursor_item != NULL)
3418 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3421 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3422 if (cursor_item_obj != NULL)
3423 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3426 icon_view->priv->cursor_item = item;
3427 if (cursor_cell >= 0)
3428 icon_view->priv->cursor_cell = cursor_cell;
3430 gtk_icon_view_queue_draw_item (icon_view, item);
3432 /* Notify that accessible focus object has changed */
3433 item_obj = atk_object_ref_accessible_child (obj, item->index);
3435 if (item_obj != NULL)
3437 atk_focus_tracker_notify (item_obj);
3438 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3439 g_object_unref (item_obj);
3444 static GtkIconViewItem *
3445 gtk_icon_view_item_new (void)
3447 GtkIconViewItem *item;
3449 item = g_new0 (GtkIconViewItem, 1);
3458 gtk_icon_view_item_free (GtkIconViewItem *item)
3460 g_return_if_fail (item != NULL);
3462 g_free (item->before);
3463 g_free (item->after);
3470 static GtkIconViewItem *
3471 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3474 gboolean only_in_cell,
3475 GtkIconViewCellInfo **cell_at_pos)
3481 *cell_at_pos = NULL;
3483 for (items = icon_view->priv->items; items; items = items->next)
3485 GtkIconViewItem *item = items->data;
3487 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3488 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3490 if (only_in_cell || cell_at_pos)
3492 gtk_icon_view_set_cell_data (icon_view, item);
3494 for (l = icon_view->priv->cell_list; l; l = l->next)
3496 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3498 if (!gtk_cell_renderer_get_visible (info->cell))
3501 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3503 if ((x >= box.x && x <= box.x + box.width &&
3504 y >= box.y && y <= box.y + box.height) ||
3506 x <= box.x + box.width &&
3508 y <= box.y + box.height))
3511 *cell_at_pos = info;
3529 gtk_icon_view_select_item (GtkIconView *icon_view,
3530 GtkIconViewItem *item)
3532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3533 g_return_if_fail (item != NULL);
3538 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3540 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3541 gtk_icon_view_unselect_all_internal (icon_view);
3543 item->selected = TRUE;
3545 gtk_icon_view_item_selected_changed (icon_view, item);
3546 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3548 gtk_icon_view_queue_draw_item (icon_view, item);
3553 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3554 GtkIconViewItem *item)
3556 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3557 g_return_if_fail (item != NULL);
3559 if (!item->selected)
3562 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3563 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3566 item->selected = FALSE;
3568 gtk_icon_view_item_selected_changed (icon_view, item);
3569 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3571 gtk_icon_view_queue_draw_item (icon_view, item);
3575 verify_items (GtkIconView *icon_view)
3580 for (items = icon_view->priv->items; items; items = items->next)
3582 GtkIconViewItem *item = items->data;
3584 if (item->index != i)
3585 g_error ("List item does not match its index: "
3586 "item index %d and list index %d\n", item->index, i);
3593 gtk_icon_view_row_changed (GtkTreeModel *model,
3598 GtkIconViewItem *item;
3600 GtkIconView *icon_view;
3602 icon_view = GTK_ICON_VIEW (data);
3604 gtk_icon_view_stop_editing (icon_view, TRUE);
3606 index = gtk_tree_path_get_indices(path)[0];
3607 item = g_list_nth_data (icon_view->priv->items, index);
3609 gtk_icon_view_item_invalidate_size (item);
3610 gtk_icon_view_queue_layout (icon_view);
3612 verify_items (icon_view);
3616 gtk_icon_view_row_inserted (GtkTreeModel *model,
3622 GtkIconViewItem *item;
3623 gboolean iters_persist;
3624 GtkIconView *icon_view;
3627 icon_view = GTK_ICON_VIEW (data);
3629 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3631 index = gtk_tree_path_get_indices(path)[0];
3633 item = gtk_icon_view_item_new ();
3638 item->index = index;
3640 /* FIXME: We can be more efficient here,
3641 we can store a tail pointer and use that when
3642 appending (which is a rather common operation)
3644 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3647 list = g_list_nth (icon_view->priv->items, index + 1);
3648 for (; list; list = list->next)
3655 verify_items (icon_view);
3657 gtk_icon_view_queue_layout (icon_view);
3661 gtk_icon_view_row_deleted (GtkTreeModel *model,
3666 GtkIconView *icon_view;
3667 GtkIconViewItem *item;
3669 gboolean emit = FALSE;
3671 icon_view = GTK_ICON_VIEW (data);
3673 index = gtk_tree_path_get_indices(path)[0];
3675 list = g_list_nth (icon_view->priv->items, index);
3678 gtk_icon_view_stop_editing (icon_view, TRUE);
3680 if (item == icon_view->priv->anchor_item)
3681 icon_view->priv->anchor_item = NULL;
3683 if (item == icon_view->priv->cursor_item)
3684 icon_view->priv->cursor_item = NULL;
3689 gtk_icon_view_item_free (item);
3691 for (next = list->next; next; next = next->next)
3698 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3700 verify_items (icon_view);
3702 gtk_icon_view_queue_layout (icon_view);
3705 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3709 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3710 GtkTreePath *parent,
3717 GtkIconView *icon_view;
3718 GList *items = NULL, *list;
3719 GtkIconViewItem **item_array;
3722 icon_view = GTK_ICON_VIEW (data);
3724 gtk_icon_view_stop_editing (icon_view, TRUE);
3726 length = gtk_tree_model_iter_n_children (model, NULL);
3728 order = g_new (gint, length);
3729 for (i = 0; i < length; i++)
3730 order [new_order[i]] = i;
3732 item_array = g_new (GtkIconViewItem *, length);
3733 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3734 item_array[order[i]] = list->data;
3737 for (i = length - 1; i >= 0; i--)
3739 item_array[i]->index = i;
3740 items = g_list_prepend (items, item_array[i]);
3743 g_free (item_array);
3744 g_list_free (icon_view->priv->items);
3745 icon_view->priv->items = items;
3747 gtk_icon_view_queue_layout (icon_view);
3749 verify_items (icon_view);
3753 gtk_icon_view_build_items (GtkIconView *icon_view)
3757 gboolean iters_persist;
3758 GList *items = NULL;
3760 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3762 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3770 GtkIconViewItem *item = gtk_icon_view_item_new ();
3779 items = g_list_prepend (items, item);
3781 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3783 icon_view->priv->items = g_list_reverse (items);
3787 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3790 GtkMovementStep step,
3794 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3795 I_("move-cursor"), 2,
3799 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3804 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3807 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3812 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3819 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3820 GtkMovementStep step,
3823 GdkModifierType state;
3825 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3826 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3827 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3828 step == GTK_MOVEMENT_DISPLAY_LINES ||
3829 step == GTK_MOVEMENT_PAGES ||
3830 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3832 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3835 gtk_icon_view_stop_editing (icon_view, FALSE);
3836 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3838 if (gtk_get_current_event_state (&state))
3840 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3841 icon_view->priv->ctrl_pressed = TRUE;
3842 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3843 icon_view->priv->shift_pressed = TRUE;
3845 /* else we assume not pressed */
3849 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3850 case GTK_MOVEMENT_VISUAL_POSITIONS:
3851 gtk_icon_view_move_cursor_left_right (icon_view, count);
3853 case GTK_MOVEMENT_DISPLAY_LINES:
3854 gtk_icon_view_move_cursor_up_down (icon_view, count);
3856 case GTK_MOVEMENT_PAGES:
3857 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3859 case GTK_MOVEMENT_BUFFER_ENDS:
3860 gtk_icon_view_move_cursor_start_end (icon_view, count);
3863 g_assert_not_reached ();
3866 icon_view->priv->ctrl_pressed = FALSE;
3867 icon_view->priv->shift_pressed = FALSE;
3869 icon_view->priv->draw_focus = TRUE;
3874 static GtkIconViewItem *
3875 find_item (GtkIconView *icon_view,
3876 GtkIconViewItem *current,
3882 GtkIconViewItem *item;
3884 /* FIXME: this could be more efficient
3886 row = current->row + row_ofs;
3887 col = current->col + col_ofs;
3889 for (items = icon_view->priv->items; items; items = items->next)
3892 if (item->row == row && item->col == col)
3900 find_cell (GtkIconView *icon_view,
3901 GtkIconViewItem *item,
3903 GtkOrientation orientation,
3913 if (icon_view->priv->item_orientation != orientation)
3916 gtk_icon_view_set_cell_data (icon_view, item);
3918 focusable = g_new0 (gint, icon_view->priv->n_cells);
3922 for (k = 0; k < 2; k++)
3923 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3925 GtkCellRendererMode mode;
3926 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3928 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3931 if (!gtk_cell_renderer_get_visible (info->cell))
3934 g_object_get (info->cell, "mode", &mode, NULL);
3935 if (mode != GTK_CELL_RENDERER_MODE_INERT)
3938 current = n_focusable;
3940 focusable[n_focusable] = i;
3946 if (n_focusable == 0)
3954 current = step > 0 ? 0 : n_focusable - 1;
3955 cell = focusable[current];
3958 if (current + *count < 0)
3961 *count = current + *count;
3963 else if (current + *count > n_focusable - 1)
3966 *count = current + *count - (n_focusable - 1);
3970 cell = focusable[current + *count];
3979 static GtkIconViewItem *
3980 find_item_page_up_down (GtkIconView *icon_view,
3981 GtkIconViewItem *current,
3988 y = current->y + count * icon_view->priv->vadjustment->page_size;
3990 item = g_list_find (icon_view->priv->items, current);
3995 for (next = item->next; next; next = next->next)
3997 if (((GtkIconViewItem *)next->data)->col == col)
4000 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4010 for (next = item->prev; next; next = next->prev)
4012 if (((GtkIconViewItem *)next->data)->col == col)
4015 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4029 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4030 GtkIconViewItem *anchor,
4031 GtkIconViewItem *cursor)
4034 GtkIconViewItem *item;
4035 gint row1, row2, col1, col2;
4036 gboolean dirty = FALSE;
4038 if (anchor->row < cursor->row)
4049 if (anchor->col < cursor->col)
4060 for (items = icon_view->priv->items; items; items = items->next)
4064 if (row1 <= item->row && item->row <= row2 &&
4065 col1 <= item->col && item->col <= col2)
4067 if (!item->selected)
4070 item->selected = TRUE;
4071 gtk_icon_view_item_selected_changed (icon_view, item);
4073 gtk_icon_view_queue_draw_item (icon_view, item);
4081 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4084 GtkIconViewItem *item;
4086 gboolean dirty = FALSE;
4088 GtkDirectionType direction;
4090 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4093 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4095 if (!icon_view->priv->cursor_item)
4100 list = icon_view->priv->items;
4102 list = g_list_last (icon_view->priv->items);
4104 item = list ? list->data : NULL;
4109 item = icon_view->priv->cursor_item;
4110 cell = icon_view->priv->cursor_cell;
4111 step = count > 0 ? 1 : -1;
4114 cell = find_cell (icon_view, item, cell,
4115 GTK_ORIENTATION_VERTICAL,
4120 item = find_item (icon_view, item, step, 0);
4121 count = count - step;
4127 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4129 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4131 gtk_widget_child_focus (toplevel,
4132 direction == GTK_DIR_UP ?
4133 GTK_DIR_TAB_BACKWARD :
4134 GTK_DIR_TAB_FORWARD);
4140 if (icon_view->priv->ctrl_pressed ||
4141 !icon_view->priv->shift_pressed ||
4142 !icon_view->priv->anchor_item ||
4143 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4144 icon_view->priv->anchor_item = item;
4146 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4148 if (!icon_view->priv->ctrl_pressed &&
4149 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4151 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4152 dirty = gtk_icon_view_select_all_between (icon_view,
4153 icon_view->priv->anchor_item,
4157 gtk_icon_view_scroll_to_item (icon_view, item);
4160 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4164 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4167 GtkIconViewItem *item;
4168 gboolean dirty = FALSE;
4170 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4173 if (!icon_view->priv->cursor_item)
4178 list = icon_view->priv->items;
4180 list = g_list_last (icon_view->priv->items);
4182 item = list ? list->data : NULL;
4185 item = find_item_page_up_down (icon_view,
4186 icon_view->priv->cursor_item,
4189 if (item == icon_view->priv->cursor_item)
4190 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4195 if (icon_view->priv->ctrl_pressed ||
4196 !icon_view->priv->shift_pressed ||
4197 !icon_view->priv->anchor_item ||
4198 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4199 icon_view->priv->anchor_item = item;
4201 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4203 if (!icon_view->priv->ctrl_pressed &&
4204 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4206 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4207 dirty = gtk_icon_view_select_all_between (icon_view,
4208 icon_view->priv->anchor_item,
4212 gtk_icon_view_scroll_to_item (icon_view, item);
4215 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4219 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4222 GtkIconViewItem *item;
4224 gboolean dirty = FALSE;
4226 GtkDirectionType direction;
4228 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4231 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4233 if (!icon_view->priv->cursor_item)
4238 list = icon_view->priv->items;
4240 list = g_list_last (icon_view->priv->items);
4242 item = list ? list->data : NULL;
4246 item = icon_view->priv->cursor_item;
4247 cell = icon_view->priv->cursor_cell;
4248 step = count > 0 ? 1 : -1;
4251 cell = find_cell (icon_view, item, cell,
4252 GTK_ORIENTATION_HORIZONTAL,
4257 item = find_item (icon_view, item, 0, step);
4258 count = count - step;
4264 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4266 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4268 gtk_widget_child_focus (toplevel,
4269 direction == GTK_DIR_LEFT ?
4270 GTK_DIR_TAB_BACKWARD :
4271 GTK_DIR_TAB_FORWARD);
4277 if (icon_view->priv->ctrl_pressed ||
4278 !icon_view->priv->shift_pressed ||
4279 !icon_view->priv->anchor_item ||
4280 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4281 icon_view->priv->anchor_item = item;
4283 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4285 if (!icon_view->priv->ctrl_pressed &&
4286 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4288 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4289 dirty = gtk_icon_view_select_all_between (icon_view,
4290 icon_view->priv->anchor_item,
4294 gtk_icon_view_scroll_to_item (icon_view, item);
4297 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4301 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4304 GtkIconViewItem *item;
4306 gboolean dirty = FALSE;
4308 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4312 list = icon_view->priv->items;
4314 list = g_list_last (icon_view->priv->items);
4316 item = list ? list->data : NULL;
4318 if (item == icon_view->priv->cursor_item)
4319 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4324 if (icon_view->priv->ctrl_pressed ||
4325 !icon_view->priv->shift_pressed ||
4326 !icon_view->priv->anchor_item ||
4327 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4328 icon_view->priv->anchor_item = item;
4330 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4332 if (!icon_view->priv->ctrl_pressed &&
4333 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4335 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4336 dirty = gtk_icon_view_select_all_between (icon_view,
4337 icon_view->priv->anchor_item,
4341 gtk_icon_view_scroll_to_item (icon_view, item);
4344 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4348 * gtk_icon_view_scroll_to_path:
4349 * @icon_view: A #GtkIconView.
4350 * @path: The path of the item to move to.
4351 * @use_align: whether to use alignment arguments, or %FALSE.
4352 * @row_align: The vertical alignment of the item specified by @path.
4353 * @col_align: The horizontal alignment of the item specified by @path.
4355 * Moves the alignments of @icon_view to the position specified by @path.
4356 * @row_align determines where the row is placed, and @col_align determines
4357 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4358 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4361 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4362 * tree does the minimum amount of work to scroll the item onto the screen.
4363 * This means that the item will be scrolled to the edge closest to its current
4364 * position. If the item is currently visible on the screen, nothing is done.
4366 * This function only works if the model is set, and @path is a valid row on
4367 * the model. If the model changes before the @icon_view is realized, the
4368 * centered path will be modified to reflect this change.
4373 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4379 GtkIconViewItem *item = NULL;
4382 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4383 g_return_if_fail (path != NULL);
4384 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4385 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4387 widget = GTK_WIDGET (icon_view);
4389 if (gtk_tree_path_get_depth (path) > 0)
4390 item = g_list_nth_data (icon_view->priv->items,
4391 gtk_tree_path_get_indices(path)[0]);
4393 if (!item || item->width < 0 ||
4394 !gtk_widget_get_realized (widget))
4396 if (icon_view->priv->scroll_to_path)
4397 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4399 icon_view->priv->scroll_to_path = NULL;
4402 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4404 icon_view->priv->scroll_to_use_align = use_align;
4405 icon_view->priv->scroll_to_row_align = row_align;
4406 icon_view->priv->scroll_to_col_align = col_align;
4413 GtkAllocation allocation;
4418 gtk_widget_style_get (widget,
4419 "focus-line-width", &focus_width,
4422 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4424 gtk_widget_get_allocation (widget, &allocation);
4426 offset = y + item->y - focus_width - row_align * (allocation.height - item->height);
4428 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4429 icon_view->priv->vadjustment->value + offset);
4431 offset = x + item->x - focus_width - col_align * (allocation.width - item->width);
4433 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4434 icon_view->priv->hadjustment->value + offset);
4436 gtk_adjustment_changed (icon_view->priv->hadjustment);
4437 gtk_adjustment_changed (icon_view->priv->vadjustment);
4440 gtk_icon_view_scroll_to_item (icon_view, item);
4445 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4446 GtkIconViewItem *item)
4448 GtkAllocation allocation;
4449 GtkWidget *widget = GTK_WIDGET (icon_view);
4450 gint x, y, width, height;
4453 gtk_widget_style_get (widget,
4454 "focus-line-width", &focus_width,
4457 width = gdk_window_get_width (icon_view->priv->bin_window);
4458 height = gdk_window_get_height (icon_view->priv->bin_window);
4459 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4461 gtk_widget_get_allocation (widget, &allocation);
4463 if (y + item->y - focus_width < 0)
4464 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4465 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4466 else if (y + item->y + item->height + focus_width > allocation.height)
4467 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4468 icon_view->priv->vadjustment->value + y + item->y + item->height
4469 + focus_width - allocation.height);
4471 if (x + item->x - focus_width < 0)
4472 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4473 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4474 else if (x + item->x + item->width + focus_width > allocation.width)
4475 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4476 icon_view->priv->hadjustment->value + x + item->x + item->width
4477 + focus_width - allocation.width);
4479 gtk_adjustment_changed (icon_view->priv->hadjustment);
4480 gtk_adjustment_changed (icon_view->priv->vadjustment);
4483 /* GtkCellLayout implementation */
4484 static GtkIconViewCellInfo *
4485 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4486 GtkCellRenderer *renderer)
4490 for (i = icon_view->priv->cell_list; i; i = i->next)
4492 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4494 if (info->cell == renderer)
4502 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4503 GtkIconViewItem *item)
4506 gboolean iters_persist;
4509 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4515 path = gtk_tree_path_new_from_indices (item->index, -1);
4516 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4518 gtk_tree_path_free (path);
4523 for (i = icon_view->priv->cell_list; i; i = i->next)
4526 GtkIconViewCellInfo *info = i->data;
4528 g_object_freeze_notify (G_OBJECT (info->cell));
4530 for (j = info->attributes; j && j->next; j = j->next->next)
4532 gchar *property = j->data;
4533 gint column = GPOINTER_TO_INT (j->next->data);
4534 GValue value = {0, };
4536 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4538 g_object_set_property (G_OBJECT (info->cell),
4540 g_value_unset (&value);
4544 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4546 icon_view->priv->model,
4550 g_object_thaw_notify (G_OBJECT (info->cell));
4555 free_cell_attributes (GtkIconViewCellInfo *info)
4559 list = info->attributes;
4560 while (list && list->next)
4562 g_free (list->data);
4563 list = list->next->next;
4566 g_slist_free (info->attributes);
4567 info->attributes = NULL;
4571 free_cell_info (GtkIconViewCellInfo *info)
4573 free_cell_attributes (info);
4575 g_object_unref (info->cell);
4578 (* info->destroy) (info->func_data);
4584 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4585 GtkCellRenderer *renderer,
4588 GtkIconViewCellInfo *info;
4589 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4591 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4592 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4594 g_object_ref_sink (renderer);
4596 info = g_new0 (GtkIconViewCellInfo, 1);
4597 info->cell = renderer;
4598 info->expand = expand ? TRUE : FALSE;
4599 info->pack = GTK_PACK_START;
4600 info->position = icon_view->priv->n_cells;
4602 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4603 icon_view->priv->n_cells++;
4607 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4608 GtkCellRenderer *renderer,
4611 GtkIconViewCellInfo *info;
4612 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4614 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4615 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4617 g_object_ref_sink (renderer);
4619 info = g_new0 (GtkIconViewCellInfo, 1);
4620 info->cell = renderer;
4621 info->expand = expand ? TRUE : FALSE;
4622 info->pack = GTK_PACK_END;
4623 info->position = icon_view->priv->n_cells;
4625 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4626 icon_view->priv->n_cells++;
4630 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4631 GtkCellRenderer *renderer,
4632 const gchar *attribute,
4635 GtkIconViewCellInfo *info;
4636 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4638 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4639 g_return_if_fail (info != NULL);
4641 info->attributes = g_slist_prepend (info->attributes,
4642 GINT_TO_POINTER (column));
4643 info->attributes = g_slist_prepend (info->attributes,
4644 g_strdup (attribute));
4648 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4650 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4652 while (icon_view->priv->cell_list)
4654 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4655 free_cell_info (info);
4656 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4657 icon_view->priv->cell_list);
4660 icon_view->priv->n_cells = 0;
4664 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4665 GtkCellRenderer *cell,
4666 GtkCellLayoutDataFunc func,
4668 GDestroyNotify destroy)
4670 GtkIconViewCellInfo *info;
4671 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4673 info = gtk_icon_view_get_cell_info (icon_view, cell);
4674 g_return_if_fail (info != NULL);
4678 GDestroyNotify d = info->destroy;
4680 info->destroy = NULL;
4681 d (info->func_data);
4685 info->func_data = func_data;
4686 info->destroy = destroy;
4690 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4691 GtkCellRenderer *renderer)
4693 GtkIconViewCellInfo *info;
4695 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4697 free_cell_attributes (info);
4701 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4702 GtkCellRenderer *cell,
4705 GtkIconView *icon_view;
4707 GtkIconViewCellInfo *info;
4710 icon_view = GTK_ICON_VIEW (layout);
4712 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4714 info = gtk_icon_view_get_cell_info (icon_view, cell);
4716 g_return_if_fail (info != NULL);
4717 g_return_if_fail (position >= 0);
4719 link = g_list_find (icon_view->priv->cell_list, info);
4721 g_return_if_fail (link != NULL);
4723 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4725 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4728 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4735 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4739 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4741 GtkIconView *icon_view = (GtkIconView *)layout;
4742 GList *retval = NULL, *l;
4744 for (l = icon_view->priv->cell_list; l; l = l->next)
4746 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4748 retval = g_list_prepend (retval, info->cell);
4751 return g_list_reverse (retval);
4758 * gtk_icon_view_new:
4760 * Creates a new #GtkIconView widget
4762 * Return value: A newly created #GtkIconView widget
4767 gtk_icon_view_new (void)
4769 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4773 * gtk_icon_view_new_with_model:
4774 * @model: The model.
4776 * Creates a new #GtkIconView widget with the model @model.
4778 * Return value: A newly created #GtkIconView widget.
4783 gtk_icon_view_new_with_model (GtkTreeModel *model)
4785 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4789 * gtk_icon_view_convert_widget_to_bin_window_coords:
4790 * @icon_view: a #GtkIconView
4791 * @wx: X coordinate relative to the widget
4792 * @wy: Y coordinate relative to the widget
4793 * @bx: return location for bin_window X coordinate
4794 * @by: return location for bin_window Y coordinate
4796 * Converts widget coordinates to coordinates for the bin_window,
4797 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4802 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4810 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4812 if (icon_view->priv->bin_window)
4813 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4824 * gtk_icon_view_get_path_at_pos:
4825 * @icon_view: A #GtkIconView.
4826 * @x: The x position to be identified
4827 * @y: The y position to be identified
4829 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4830 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4831 * the cell at the specified position.
4832 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4833 * widget coordinates to bin_window coordinates.
4835 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4836 * if no icon exists at that position.
4841 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4845 GtkIconViewItem *item;
4848 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4850 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4855 path = gtk_tree_path_new_from_indices (item->index, -1);
4861 * gtk_icon_view_get_item_at_pos:
4862 * @icon_view: A #GtkIconView.
4863 * @x: The x position to be identified
4864 * @y: The y position to be identified
4865 * @path: (allow-none): Return location for the path, or %NULL
4866 * @cell: Return location for the renderer responsible for the cell
4867 * at (@x, @y), or %NULL
4869 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4870 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4871 * obtains the cell at the specified position. The returned path should
4872 * be freed with gtk_tree_path_free().
4873 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4874 * widget coordinates to bin_window coordinates.
4876 * Return value: %TRUE if an item exists at the specified position
4881 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4885 GtkCellRenderer **cell)
4887 GtkIconViewItem *item;
4888 GtkIconViewCellInfo *info;
4890 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4892 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4897 *path = gtk_tree_path_new_from_indices (item->index, -1);
4910 return (item != NULL);
4914 * gtk_icon_view_set_tooltip_item:
4915 * @icon_view: a #GtkIconView
4916 * @tooltip: a #GtkTooltip
4917 * @path: a #GtkTreePath
4919 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4920 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4921 * See also gtk_tooltip_set_tip_area().
4926 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4927 GtkTooltip *tooltip,
4930 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4931 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4933 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4937 * gtk_icon_view_set_tooltip_cell:
4938 * @icon_view: a #GtkIconView
4939 * @tooltip: a #GtkTooltip
4940 * @path: a #GtkTreePath
4941 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4943 * Sets the tip area of @tooltip to the area which @cell occupies in
4944 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4946 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4951 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4952 GtkTooltip *tooltip,
4954 GtkCellRenderer *cell)
4957 GtkIconViewItem *item = NULL;
4958 GtkIconViewCellInfo *info = NULL;
4961 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4962 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4963 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4965 if (gtk_tree_path_get_depth (path) > 0)
4966 item = g_list_nth_data (icon_view->priv->items,
4967 gtk_tree_path_get_indices(path)[0]);
4974 info = gtk_icon_view_get_cell_info (icon_view, cell);
4975 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4981 rect.width = item->width;
4982 rect.height = item->height;
4985 if (icon_view->priv->bin_window)
4987 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4992 gtk_tooltip_set_tip_area (tooltip, &rect);
4997 * gtk_icon_view_get_tooltip_context:
4998 * @icon_view: an #GtkIconView
4999 * @x: the x coordinate (relative to widget coordinates)
5000 * @y: the y coordinate (relative to widget coordinates)
5001 * @keyboard_tip: whether this is a keyboard tooltip or not
5002 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5003 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
5004 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5006 * This function is supposed to be used in a #GtkWidget::query-tooltip
5007 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5008 * which are received in the signal handler, should be passed to this
5009 * function without modification.
5011 * The return value indicates whether there is an icon view item at the given
5012 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5013 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5014 * @model, @path and @iter which have been provided will be set to point to
5015 * that row and the corresponding model. @x and @y will always be converted
5016 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5018 * Return value: whether or not the given tooltip context points to a item
5023 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5026 gboolean keyboard_tip,
5027 GtkTreeModel **model,
5031 GtkTreePath *tmppath = NULL;
5033 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5034 g_return_val_if_fail (x != NULL, FALSE);
5035 g_return_val_if_fail (y != NULL, FALSE);
5039 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5046 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5049 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5054 *model = gtk_icon_view_get_model (icon_view);
5057 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5063 gtk_tree_path_free (tmppath);
5069 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5072 gboolean keyboard_tip,
5073 GtkTooltip *tooltip,
5079 GtkTreeModel *model;
5080 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5082 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5085 &model, &path, &iter))
5088 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5092 gtk_tree_path_free (path);
5096 gtk_tooltip_set_markup (tooltip, str);
5097 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5099 gtk_tree_path_free (path);
5107 * gtk_icon_view_set_tooltip_column:
5108 * @icon_view: a #GtkIconView
5109 * @column: an integer, which is a valid column number for @icon_view's model
5111 * If you only plan to have simple (text-only) tooltips on full items, you
5112 * can use this function to have #GtkIconView handle these automatically
5113 * for you. @column should be set to the column in @icon_view's model
5114 * containing the tooltip texts, or -1 to disable this feature.
5116 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5117 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5122 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5125 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5127 if (column == icon_view->priv->tooltip_column)
5132 g_signal_handlers_disconnect_by_func (icon_view,
5133 gtk_icon_view_set_tooltip_query_cb,
5135 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5139 if (icon_view->priv->tooltip_column == -1)
5141 g_signal_connect (icon_view, "query-tooltip",
5142 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5143 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5147 icon_view->priv->tooltip_column = column;
5148 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5152 * gtk_icon_view_get_tooltip_column:
5153 * @icon_view: a #GtkIconView
5155 * Returns the column of @icon_view's model which is being used for
5156 * displaying tooltips on @icon_view's rows.
5158 * Return value: the index of the tooltip column that is currently being
5159 * used, or -1 if this is disabled.
5164 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5166 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5168 return icon_view->priv->tooltip_column;
5172 * gtk_icon_view_get_visible_range:
5173 * @icon_view: A #GtkIconView
5174 * @start_path: (allow-none): Return location for start of region, or %NULL
5175 * @end_path: (allow-none): Return location for end of region, or %NULL
5177 * Sets @start_path and @end_path to be the first and last visible path.
5178 * Note that there may be invisible paths in between.
5180 * Both paths should be freed with gtk_tree_path_free() after use.
5182 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5187 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5188 GtkTreePath **start_path,
5189 GtkTreePath **end_path)
5191 gint start_index = -1;
5192 gint end_index = -1;
5195 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5197 if (icon_view->priv->hadjustment == NULL ||
5198 icon_view->priv->vadjustment == NULL)
5201 if (start_path == NULL && end_path == NULL)
5204 for (icons = icon_view->priv->items; icons; icons = icons->next)
5206 GtkIconViewItem *item = icons->data;
5208 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5209 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5210 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5211 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5213 if (start_index == -1)
5214 start_index = item->index;
5215 end_index = item->index;
5219 if (start_path && start_index != -1)
5220 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5221 if (end_path && end_index != -1)
5222 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5224 return start_index != -1;
5228 * gtk_icon_view_selected_foreach:
5229 * @icon_view: A #GtkIconView.
5230 * @func: (scope call): The function to call for each selected icon.
5231 * @data: User data to pass to the function.
5233 * Calls a function for each selected icon. Note that the model or
5234 * selection cannot be modified from within this function.
5239 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5240 GtkIconViewForeachFunc func,
5245 for (list = icon_view->priv->items; list; list = list->next)
5247 GtkIconViewItem *item = list->data;
5248 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5251 (* func) (icon_view, path, data);
5253 gtk_tree_path_free (path);
5258 * gtk_icon_view_set_selection_mode:
5259 * @icon_view: A #GtkIconView.
5260 * @mode: The selection mode
5262 * Sets the selection mode of the @icon_view.
5267 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5268 GtkSelectionMode mode)
5270 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5272 if (mode == icon_view->priv->selection_mode)
5275 if (mode == GTK_SELECTION_NONE ||
5276 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5277 gtk_icon_view_unselect_all (icon_view);
5279 icon_view->priv->selection_mode = mode;
5281 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5285 * gtk_icon_view_get_selection_mode:
5286 * @icon_view: A #GtkIconView.
5288 * Gets the selection mode of the @icon_view.
5290 * Return value: the current selection mode
5295 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5297 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5299 return icon_view->priv->selection_mode;
5303 * gtk_icon_view_set_model:
5304 * @icon_view: A #GtkIconView.
5305 * @model: (allow-none): The model.
5307 * Sets the model for a #GtkIconView.
5308 * If the @icon_view already has a model set, it will remove
5309 * it before setting the new model. If @model is %NULL, then
5310 * it will unset the old model.
5315 gtk_icon_view_set_model (GtkIconView *icon_view,
5316 GtkTreeModel *model)
5318 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5319 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5321 if (icon_view->priv->model == model)
5324 if (icon_view->priv->scroll_to_path)
5326 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5327 icon_view->priv->scroll_to_path = NULL;
5330 gtk_icon_view_stop_editing (icon_view, TRUE);
5336 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5338 if (icon_view->priv->pixbuf_column != -1)
5340 column_type = gtk_tree_model_get_column_type (model,
5341 icon_view->priv->pixbuf_column);
5343 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5346 if (icon_view->priv->text_column != -1)
5348 column_type = gtk_tree_model_get_column_type (model,
5349 icon_view->priv->text_column);
5351 g_return_if_fail (column_type == G_TYPE_STRING);
5354 if (icon_view->priv->markup_column != -1)
5356 column_type = gtk_tree_model_get_column_type (model,
5357 icon_view->priv->markup_column);
5359 g_return_if_fail (column_type == G_TYPE_STRING);
5364 if (icon_view->priv->model)
5366 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5367 gtk_icon_view_row_changed,
5369 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5370 gtk_icon_view_row_inserted,
5372 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5373 gtk_icon_view_row_deleted,
5375 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5376 gtk_icon_view_rows_reordered,
5379 g_object_unref (icon_view->priv->model);
5381 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5382 g_list_free (icon_view->priv->items);
5383 icon_view->priv->items = NULL;
5384 icon_view->priv->anchor_item = NULL;
5385 icon_view->priv->cursor_item = NULL;
5386 icon_view->priv->last_single_clicked = NULL;
5387 icon_view->priv->width = 0;
5388 icon_view->priv->height = 0;
5391 icon_view->priv->model = model;
5393 if (icon_view->priv->model)
5395 g_object_ref (icon_view->priv->model);
5396 g_signal_connect (icon_view->priv->model,
5398 G_CALLBACK (gtk_icon_view_row_changed),
5400 g_signal_connect (icon_view->priv->model,
5402 G_CALLBACK (gtk_icon_view_row_inserted),
5404 g_signal_connect (icon_view->priv->model,
5406 G_CALLBACK (gtk_icon_view_row_deleted),
5408 g_signal_connect (icon_view->priv->model,
5410 G_CALLBACK (gtk_icon_view_rows_reordered),
5413 gtk_icon_view_build_items (icon_view);
5415 gtk_icon_view_queue_layout (icon_view);
5418 g_object_notify (G_OBJECT (icon_view), "model");
5420 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5421 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5425 * gtk_icon_view_get_model:
5426 * @icon_view: a #GtkIconView
5428 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5431 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5432 * currently being used.
5437 gtk_icon_view_get_model (GtkIconView *icon_view)
5439 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5441 return icon_view->priv->model;
5445 update_text_cell (GtkIconView *icon_view)
5447 GtkIconViewCellInfo *info;
5451 if (icon_view->priv->text_column == -1 &&
5452 icon_view->priv->markup_column == -1)
5454 if (icon_view->priv->text_cell != -1)
5456 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5457 icon_view->priv->pixbuf_cell--;
5459 info = g_list_nth_data (icon_view->priv->cell_list,
5460 icon_view->priv->text_cell);
5462 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5464 free_cell_info (info);
5466 icon_view->priv->n_cells--;
5467 icon_view->priv->text_cell = -1;
5472 if (icon_view->priv->text_cell == -1)
5474 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5475 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5476 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5479 if (info->cell == cell)
5481 icon_view->priv->text_cell = i;
5487 info = g_list_nth_data (icon_view->priv->cell_list,
5488 icon_view->priv->text_cell);
5490 if (icon_view->priv->markup_column != -1)
5491 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5493 "markup", icon_view->priv->markup_column,
5496 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5498 "text", icon_view->priv->text_column,
5501 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5502 g_object_set (info->cell,
5503 "alignment", PANGO_ALIGN_CENTER,
5504 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5509 g_object_set (info->cell,
5510 "alignment", PANGO_ALIGN_LEFT,
5511 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5519 update_pixbuf_cell (GtkIconView *icon_view)
5521 GtkIconViewCellInfo *info;
5525 if (icon_view->priv->pixbuf_column == -1)
5527 if (icon_view->priv->pixbuf_cell != -1)
5529 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5530 icon_view->priv->text_cell--;
5532 info = g_list_nth_data (icon_view->priv->cell_list,
5533 icon_view->priv->pixbuf_cell);
5535 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5537 free_cell_info (info);
5539 icon_view->priv->n_cells--;
5540 icon_view->priv->pixbuf_cell = -1;
5545 if (icon_view->priv->pixbuf_cell == -1)
5547 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5549 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5550 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5553 if (info->cell == cell)
5555 icon_view->priv->pixbuf_cell = i;
5561 info = g_list_nth_data (icon_view->priv->cell_list,
5562 icon_view->priv->pixbuf_cell);
5564 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5566 "pixbuf", icon_view->priv->pixbuf_column,
5569 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5570 g_object_set (info->cell,
5575 g_object_set (info->cell,
5583 * gtk_icon_view_set_text_column:
5584 * @icon_view: A #GtkIconView.
5585 * @column: A column in the currently used model, or -1 to display no text
5587 * Sets the column with text for @icon_view to be @column. The text
5588 * column must be of type #G_TYPE_STRING.
5593 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5596 if (column == icon_view->priv->text_column)
5600 icon_view->priv->text_column = -1;
5603 if (icon_view->priv->model != NULL)
5607 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5609 g_return_if_fail (column_type == G_TYPE_STRING);
5612 icon_view->priv->text_column = column;
5615 gtk_icon_view_stop_editing (icon_view, TRUE);
5617 update_text_cell (icon_view);
5619 gtk_icon_view_invalidate_sizes (icon_view);
5620 gtk_icon_view_queue_layout (icon_view);
5622 g_object_notify (G_OBJECT (icon_view), "text-column");
5626 * gtk_icon_view_get_text_column:
5627 * @icon_view: A #GtkIconView.
5629 * Returns the column with text for @icon_view.
5631 * Returns: the text column, or -1 if it's unset.
5636 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5638 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5640 return icon_view->priv->text_column;
5644 * gtk_icon_view_set_markup_column:
5645 * @icon_view: A #GtkIconView.
5646 * @column: A column in the currently used model, or -1 to display no text
5648 * Sets the column with markup information for @icon_view to be
5649 * @column. The markup column must be of type #G_TYPE_STRING.
5650 * If the markup column is set to something, it overrides
5651 * the text column set by gtk_icon_view_set_text_column().
5656 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5659 if (column == icon_view->priv->markup_column)
5663 icon_view->priv->markup_column = -1;
5666 if (icon_view->priv->model != NULL)
5670 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5672 g_return_if_fail (column_type == G_TYPE_STRING);
5675 icon_view->priv->markup_column = column;
5678 gtk_icon_view_stop_editing (icon_view, TRUE);
5680 update_text_cell (icon_view);
5682 gtk_icon_view_invalidate_sizes (icon_view);
5683 gtk_icon_view_queue_layout (icon_view);
5685 g_object_notify (G_OBJECT (icon_view), "markup-column");
5689 * gtk_icon_view_get_markup_column:
5690 * @icon_view: A #GtkIconView.
5692 * Returns the column with markup text for @icon_view.
5694 * Returns: the markup column, or -1 if it's unset.
5699 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5701 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5703 return icon_view->priv->markup_column;
5707 * gtk_icon_view_set_pixbuf_column:
5708 * @icon_view: A #GtkIconView.
5709 * @column: A column in the currently used model, or -1 to disable
5711 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5712 * column must be of type #GDK_TYPE_PIXBUF
5717 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5720 if (column == icon_view->priv->pixbuf_column)
5724 icon_view->priv->pixbuf_column = -1;
5727 if (icon_view->priv->model != NULL)
5731 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5733 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5736 icon_view->priv->pixbuf_column = column;
5739 gtk_icon_view_stop_editing (icon_view, TRUE);
5741 update_pixbuf_cell (icon_view);
5743 gtk_icon_view_invalidate_sizes (icon_view);
5744 gtk_icon_view_queue_layout (icon_view);
5746 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5751 * gtk_icon_view_get_pixbuf_column:
5752 * @icon_view: A #GtkIconView.
5754 * Returns the column with pixbufs for @icon_view.
5756 * Returns: the pixbuf column, or -1 if it's unset.
5761 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5763 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5765 return icon_view->priv->pixbuf_column;
5769 * gtk_icon_view_select_path:
5770 * @icon_view: A #GtkIconView.
5771 * @path: The #GtkTreePath to be selected.
5773 * Selects the row at @path.
5778 gtk_icon_view_select_path (GtkIconView *icon_view,
5781 GtkIconViewItem *item = NULL;
5783 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5784 g_return_if_fail (icon_view->priv->model != NULL);
5785 g_return_if_fail (path != NULL);
5787 if (gtk_tree_path_get_depth (path) > 0)
5788 item = g_list_nth_data (icon_view->priv->items,
5789 gtk_tree_path_get_indices(path)[0]);
5792 gtk_icon_view_select_item (icon_view, item);
5796 * gtk_icon_view_unselect_path:
5797 * @icon_view: A #GtkIconView.
5798 * @path: The #GtkTreePath to be unselected.
5800 * Unselects the row at @path.
5805 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5808 GtkIconViewItem *item;
5810 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5811 g_return_if_fail (icon_view->priv->model != NULL);
5812 g_return_if_fail (path != NULL);
5814 item = g_list_nth_data (icon_view->priv->items,
5815 gtk_tree_path_get_indices(path)[0]);
5820 gtk_icon_view_unselect_item (icon_view, item);
5824 * gtk_icon_view_get_selected_items:
5825 * @icon_view: A #GtkIconView.
5827 * Creates a list of paths of all selected items. Additionally, if you are
5828 * planning on modifying the model after calling this function, you may
5829 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5830 * To do this, you can use gtk_tree_row_reference_new().
5832 * To free the return value, use:
5834 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5835 * g_list_free (list);
5838 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5843 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5846 GList *selected = NULL;
5848 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5850 for (list = icon_view->priv->items; list != NULL; list = list->next)
5852 GtkIconViewItem *item = list->data;
5856 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5858 selected = g_list_prepend (selected, path);
5866 * gtk_icon_view_select_all:
5867 * @icon_view: A #GtkIconView.
5869 * Selects all the icons. @icon_view must has its selection mode set
5870 * to #GTK_SELECTION_MULTIPLE.
5875 gtk_icon_view_select_all (GtkIconView *icon_view)
5878 gboolean dirty = FALSE;
5880 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5882 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5885 for (items = icon_view->priv->items; items; items = items->next)
5887 GtkIconViewItem *item = items->data;
5889 if (!item->selected)
5892 item->selected = TRUE;
5893 gtk_icon_view_queue_draw_item (icon_view, item);
5898 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5902 * gtk_icon_view_unselect_all:
5903 * @icon_view: A #GtkIconView.
5905 * Unselects all the icons.
5910 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5912 gboolean dirty = FALSE;
5914 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5916 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5919 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5922 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5926 * gtk_icon_view_path_is_selected:
5927 * @icon_view: A #GtkIconView.
5928 * @path: A #GtkTreePath to check selection on.
5930 * Returns %TRUE if the icon pointed to by @path is currently
5931 * selected. If @path does not point to a valid location, %FALSE is returned.
5933 * Return value: %TRUE if @path is selected.
5938 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5941 GtkIconViewItem *item;
5943 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5944 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5945 g_return_val_if_fail (path != NULL, FALSE);
5947 item = g_list_nth_data (icon_view->priv->items,
5948 gtk_tree_path_get_indices(path)[0]);
5953 return item->selected;
5957 * gtk_icon_view_get_item_row:
5958 * @icon_view: a #GtkIconView
5959 * @path: the #GtkTreePath of the item
5961 * Gets the row in which the item @path is currently
5962 * displayed. Row numbers start at 0.
5964 * Returns: The row in which the item is displayed
5969 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5972 GtkIconViewItem *item;
5974 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5975 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
5976 g_return_val_if_fail (path != NULL, -1);
5978 item = g_list_nth_data (icon_view->priv->items,
5979 gtk_tree_path_get_indices(path)[0]);
5988 * gtk_icon_view_get_item_column:
5989 * @icon_view: a #GtkIconView
5990 * @path: the #GtkTreePath of the item
5992 * Gets the column in which the item @path is currently
5993 * displayed. Column numbers start at 0.
5995 * Returns: The column in which the item is displayed
6000 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6003 GtkIconViewItem *item;
6005 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6006 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6007 g_return_val_if_fail (path != NULL, -1);
6009 item = g_list_nth_data (icon_view->priv->items,
6010 gtk_tree_path_get_indices(path)[0]);
6019 * gtk_icon_view_item_activated:
6020 * @icon_view: A #GtkIconView
6021 * @path: The #GtkTreePath to be activated
6023 * Activates the item determined by @path.
6028 gtk_icon_view_item_activated (GtkIconView *icon_view,
6031 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6032 g_return_if_fail (path != NULL);
6034 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6038 * gtk_icon_view_set_item_orientation:
6039 * @icon_view: a #GtkIconView
6040 * @orientation: the relative position of texts and icons
6042 * Sets the ::item-orientation property which determines whether the labels
6043 * are drawn beside the icons instead of below.
6048 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
6049 GtkOrientation orientation)
6051 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6053 if (icon_view->priv->item_orientation != orientation)
6055 icon_view->priv->item_orientation = orientation;
6057 gtk_icon_view_stop_editing (icon_view, TRUE);
6058 gtk_icon_view_invalidate_sizes (icon_view);
6059 gtk_icon_view_queue_layout (icon_view);
6061 update_text_cell (icon_view);
6062 update_pixbuf_cell (icon_view);
6064 g_object_notify (G_OBJECT (icon_view), "item-orientation");
6069 * gtk_icon_view_get_item_orientation:
6070 * @icon_view: a #GtkIconView
6072 * Returns the value of the ::item-orientation property which determines
6073 * whether the labels are drawn beside the icons instead of below.
6075 * Return value: the relative position of texts and icons
6080 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
6082 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6083 GTK_ORIENTATION_VERTICAL);
6085 return icon_view->priv->item_orientation;
6089 * gtk_icon_view_set_columns:
6090 * @icon_view: a #GtkIconView
6091 * @columns: the number of columns
6093 * Sets the ::columns property which determines in how
6094 * many columns the icons are arranged. If @columns is
6095 * -1, the number of columns will be chosen automatically
6096 * to fill the available area.
6101 gtk_icon_view_set_columns (GtkIconView *icon_view,
6104 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6106 if (icon_view->priv->columns != columns)
6108 icon_view->priv->columns = columns;
6110 gtk_icon_view_stop_editing (icon_view, TRUE);
6111 gtk_icon_view_queue_layout (icon_view);
6113 g_object_notify (G_OBJECT (icon_view), "columns");
6118 * gtk_icon_view_get_columns:
6119 * @icon_view: a #GtkIconView
6121 * Returns the value of the ::columns property.
6123 * Return value: the number of columns, or -1
6128 gtk_icon_view_get_columns (GtkIconView *icon_view)
6130 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6132 return icon_view->priv->columns;
6136 * gtk_icon_view_set_item_width:
6137 * @icon_view: a #GtkIconView
6138 * @item_width: the width for each item
6140 * Sets the ::item-width property which specifies the width
6141 * to use for each item. If it is set to -1, the icon view will
6142 * automatically determine a suitable item size.
6147 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6150 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6152 if (icon_view->priv->item_width != item_width)
6154 icon_view->priv->item_width = item_width;
6156 gtk_icon_view_stop_editing (icon_view, TRUE);
6157 gtk_icon_view_invalidate_sizes (icon_view);
6158 gtk_icon_view_queue_layout (icon_view);
6160 update_text_cell (icon_view);
6162 g_object_notify (G_OBJECT (icon_view), "item-width");
6167 * gtk_icon_view_get_item_width:
6168 * @icon_view: a #GtkIconView
6170 * Returns the value of the ::item-width property.
6172 * Return value: the width of a single item, or -1
6177 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6179 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6181 return icon_view->priv->item_width;
6186 * gtk_icon_view_set_spacing:
6187 * @icon_view: a #GtkIconView
6188 * @spacing: the spacing
6190 * Sets the ::spacing property which specifies the space
6191 * which is inserted between the cells (i.e. the icon and
6192 * the text) of an item.
6197 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6200 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6202 if (icon_view->priv->spacing != spacing)
6204 icon_view->priv->spacing = spacing;
6206 gtk_icon_view_stop_editing (icon_view, TRUE);
6207 gtk_icon_view_invalidate_sizes (icon_view);
6208 gtk_icon_view_queue_layout (icon_view);
6210 g_object_notify (G_OBJECT (icon_view), "spacing");
6215 * gtk_icon_view_get_spacing:
6216 * @icon_view: a #GtkIconView
6218 * Returns the value of the ::spacing property.
6220 * Return value: the space between cells
6225 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6227 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6229 return icon_view->priv->spacing;
6233 * gtk_icon_view_set_row_spacing:
6234 * @icon_view: a #GtkIconView
6235 * @row_spacing: the row spacing
6237 * Sets the ::row-spacing property which specifies the space
6238 * which is inserted between the rows of the icon view.
6243 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6246 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6248 if (icon_view->priv->row_spacing != row_spacing)
6250 icon_view->priv->row_spacing = row_spacing;
6252 gtk_icon_view_stop_editing (icon_view, TRUE);
6253 gtk_icon_view_invalidate_sizes (icon_view);
6254 gtk_icon_view_queue_layout (icon_view);
6256 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6261 * gtk_icon_view_get_row_spacing:
6262 * @icon_view: a #GtkIconView
6264 * Returns the value of the ::row-spacing property.
6266 * Return value: the space between rows
6271 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6273 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6275 return icon_view->priv->row_spacing;
6279 * gtk_icon_view_set_column_spacing:
6280 * @icon_view: a #GtkIconView
6281 * @column_spacing: the column spacing
6283 * Sets the ::column-spacing property which specifies the space
6284 * which is inserted between the columns of the icon view.
6289 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6290 gint column_spacing)
6292 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6294 if (icon_view->priv->column_spacing != column_spacing)
6296 icon_view->priv->column_spacing = column_spacing;
6298 gtk_icon_view_stop_editing (icon_view, TRUE);
6299 gtk_icon_view_invalidate_sizes (icon_view);
6300 gtk_icon_view_queue_layout (icon_view);
6302 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6307 * gtk_icon_view_get_column_spacing:
6308 * @icon_view: a #GtkIconView
6310 * Returns the value of the ::column-spacing property.
6312 * Return value: the space between columns
6317 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6319 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6321 return icon_view->priv->column_spacing;
6325 * gtk_icon_view_set_margin:
6326 * @icon_view: a #GtkIconView
6327 * @margin: the margin
6329 * Sets the ::margin property which specifies the space
6330 * which is inserted at the top, bottom, left and right
6336 gtk_icon_view_set_margin (GtkIconView *icon_view,
6339 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6341 if (icon_view->priv->margin != margin)
6343 icon_view->priv->margin = margin;
6345 gtk_icon_view_stop_editing (icon_view, TRUE);
6346 gtk_icon_view_invalidate_sizes (icon_view);
6347 gtk_icon_view_queue_layout (icon_view);
6349 g_object_notify (G_OBJECT (icon_view), "margin");
6354 * gtk_icon_view_get_margin:
6355 * @icon_view: a #GtkIconView
6357 * Returns the value of the ::margin property.
6359 * Return value: the space at the borders
6364 gtk_icon_view_get_margin (GtkIconView *icon_view)
6366 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6368 return icon_view->priv->margin;
6372 * gtk_icon_view_set_item_padding:
6373 * @icon_view: a #GtkIconView
6374 * @item_padding: the item padding
6376 * Sets the #GtkIconView:item-padding property which specifies the padding
6377 * around each of the icon view's items.
6382 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6385 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6387 if (icon_view->priv->item_padding != item_padding)
6389 icon_view->priv->item_padding = item_padding;
6391 gtk_icon_view_stop_editing (icon_view, TRUE);
6392 gtk_icon_view_invalidate_sizes (icon_view);
6393 gtk_icon_view_queue_layout (icon_view);
6395 g_object_notify (G_OBJECT (icon_view), "item-padding");
6400 * gtk_icon_view_get_item_padding:
6401 * @icon_view: a #GtkIconView
6403 * Returns the value of the ::item-padding property.
6405 * Return value: the padding around items
6410 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6412 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6414 return icon_view->priv->item_padding;
6417 /* Get/set whether drag_motion requested the drag data and
6418 * drag_data_received should thus not actually insert the data,
6419 * since the data doesn't result from a drop.
6422 set_status_pending (GdkDragContext *context,
6423 GdkDragAction suggested_action)
6425 g_object_set_data (G_OBJECT (context),
6426 I_("gtk-icon-view-status-pending"),
6427 GINT_TO_POINTER (suggested_action));
6430 static GdkDragAction
6431 get_status_pending (GdkDragContext *context)
6433 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6434 "gtk-icon-view-status-pending"));
6438 unset_reorderable (GtkIconView *icon_view)
6440 if (icon_view->priv->reorderable)
6442 icon_view->priv->reorderable = FALSE;
6443 g_object_notify (G_OBJECT (icon_view), "reorderable");
6448 set_source_row (GdkDragContext *context,
6449 GtkTreeModel *model,
6450 GtkTreePath *source_row)
6453 g_object_set_data_full (G_OBJECT (context),
6454 I_("gtk-icon-view-source-row"),
6455 gtk_tree_row_reference_new (model, source_row),
6456 (GDestroyNotify) gtk_tree_row_reference_free);
6458 g_object_set_data_full (G_OBJECT (context),
6459 I_("gtk-icon-view-source-row"),
6464 get_source_row (GdkDragContext *context)
6466 GtkTreeRowReference *ref;
6468 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6471 return gtk_tree_row_reference_get_path (ref);
6478 GtkTreeRowReference *dest_row;
6479 gboolean empty_view_drop;
6480 gboolean drop_append_mode;
6484 dest_row_free (gpointer data)
6486 DestRow *dr = (DestRow *)data;
6488 gtk_tree_row_reference_free (dr->dest_row);
6493 set_dest_row (GdkDragContext *context,
6494 GtkTreeModel *model,
6495 GtkTreePath *dest_row,
6496 gboolean empty_view_drop,
6497 gboolean drop_append_mode)
6503 g_object_set_data_full (G_OBJECT (context),
6504 I_("gtk-icon-view-dest-row"),
6509 dr = g_new0 (DestRow, 1);
6511 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6512 dr->empty_view_drop = empty_view_drop;
6513 dr->drop_append_mode = drop_append_mode;
6514 g_object_set_data_full (G_OBJECT (context),
6515 I_("gtk-icon-view-dest-row"),
6516 dr, (GDestroyNotify) dest_row_free);
6520 get_dest_row (GdkDragContext *context)
6524 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6528 GtkTreePath *path = NULL;
6531 path = gtk_tree_row_reference_get_path (dr->dest_row);
6532 else if (dr->empty_view_drop)
6533 path = gtk_tree_path_new_from_indices (0, -1);
6537 if (path && dr->drop_append_mode)
6538 gtk_tree_path_next (path);
6547 check_model_dnd (GtkTreeModel *model,
6548 GType required_iface,
6549 const gchar *signal)
6551 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6553 g_warning ("You must override the default '%s' handler "
6554 "on GtkIconView when using models that don't support "
6555 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6556 "is to connect to '%s' and call "
6557 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6558 "the default handler from running. Look at the source code "
6559 "for the default handler in gtkiconview.c to get an idea what "
6560 "your handler should do. (gtkiconview.c is in the GTK+ source "
6561 "code.) If you're using GTK+ from a language other than C, "
6562 "there may be a more natural way to override default handlers, e.g. via derivation.",
6563 signal, g_type_name (required_iface), signal);
6571 remove_scroll_timeout (GtkIconView *icon_view)
6573 if (icon_view->priv->scroll_timeout_id != 0)
6575 g_source_remove (icon_view->priv->scroll_timeout_id);
6577 icon_view->priv->scroll_timeout_id = 0;
6582 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6585 gint px, py, x, y, width, height;
6586 gint hoffset, voffset;
6588 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6590 gdk_window_get_pointer (window, &px, &py, NULL);
6591 gdk_window_get_geometry (window, &x, &y, &width, &height, NULL);
6593 /* see if we are near the edge. */
6594 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6596 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6598 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6600 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6603 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6604 icon_view->priv->vadjustment->value + voffset);
6607 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6608 icon_view->priv->hadjustment->value + hoffset);
6613 drag_scroll_timeout (gpointer data)
6615 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6617 gtk_icon_view_autoscroll (icon_view);
6624 set_destination (GtkIconView *icon_view,
6625 GdkDragContext *context,
6628 GdkDragAction *suggested_action,
6632 GtkTreePath *path = NULL;
6633 GtkIconViewDropPosition pos;
6634 GtkIconViewDropPosition old_pos;
6635 GtkTreePath *old_dest_path = NULL;
6636 gboolean can_drop = FALSE;
6638 widget = GTK_WIDGET (icon_view);
6640 *suggested_action = 0;
6643 if (!icon_view->priv->dest_set)
6645 /* someone unset us as a drag dest, note that if
6646 * we return FALSE drag_leave isn't called
6649 gtk_icon_view_set_drag_dest_item (icon_view,
6651 GTK_ICON_VIEW_DROP_LEFT);
6653 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6655 return FALSE; /* no longer a drop site */
6658 *target = gtk_drag_dest_find_target (widget, context,
6659 gtk_drag_dest_get_target_list (widget));
6660 if (*target == GDK_NONE)
6663 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6666 GtkTreeModel *model;
6668 /* the row got dropped on empty space, let's setup a special case
6672 gtk_tree_path_free (path);
6674 model = gtk_icon_view_get_model (icon_view);
6676 n_children = gtk_tree_model_iter_n_children (model, NULL);
6679 pos = GTK_ICON_VIEW_DROP_BELOW;
6680 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6684 pos = GTK_ICON_VIEW_DROP_ABOVE;
6685 path = gtk_tree_path_new_from_indices (0, -1);
6695 gtk_icon_view_get_drag_dest_item (icon_view,
6700 gtk_tree_path_free (old_dest_path);
6702 if (TRUE /* FIXME if the location droppable predicate */)
6710 GtkWidget *source_widget;
6712 *suggested_action = context->suggested_action;
6713 source_widget = gtk_drag_get_source_widget (context);
6715 if (source_widget == widget)
6717 /* Default to MOVE, unless the user has
6718 * pressed ctrl or shift to affect available actions
6720 if ((context->actions & GDK_ACTION_MOVE) != 0)
6721 *suggested_action = GDK_ACTION_MOVE;
6724 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6729 /* can't drop here */
6730 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6732 GTK_ICON_VIEW_DROP_LEFT);
6736 gtk_tree_path_free (path);
6742 get_logical_destination (GtkIconView *icon_view,
6743 gboolean *drop_append_mode)
6745 /* adjust path to point to the row the drop goes in front of */
6746 GtkTreePath *path = NULL;
6747 GtkIconViewDropPosition pos;
6749 *drop_append_mode = FALSE;
6751 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6756 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6757 pos == GTK_ICON_VIEW_DROP_BELOW)
6760 GtkTreeModel *model = icon_view->priv->model;
6762 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6763 !gtk_tree_model_iter_next (model, &iter))
6764 *drop_append_mode = TRUE;
6767 *drop_append_mode = FALSE;
6768 gtk_tree_path_next (path);
6776 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6777 GdkEventMotion *event)
6779 GtkWidget *widget = GTK_WIDGET (icon_view);
6780 GdkDragContext *context;
6781 GtkTreePath *path = NULL;
6783 GtkTreeModel *model;
6784 gboolean retval = FALSE;
6786 if (!icon_view->priv->source_set)
6789 if (icon_view->priv->pressed_button < 0)
6792 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6793 icon_view->priv->press_start_x,
6794 icon_view->priv->press_start_y,
6795 event->x, event->y))
6798 model = gtk_icon_view_get_model (icon_view);
6803 button = icon_view->priv->pressed_button;
6804 icon_view->priv->pressed_button = -1;
6806 path = gtk_icon_view_get_path_at_pos (icon_view,
6807 icon_view->priv->press_start_x,
6808 icon_view->priv->press_start_y);
6813 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6814 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6818 /* FIXME Check whether we're a start button, if not return FALSE and
6822 /* Now we can begin the drag */
6826 context = gtk_drag_begin (widget,
6827 gtk_drag_source_get_target_list (widget),
6828 icon_view->priv->source_actions,
6832 set_source_row (context, model, path);
6836 gtk_tree_path_free (path);
6841 /* Source side drag signals */
6843 gtk_icon_view_drag_begin (GtkWidget *widget,
6844 GdkDragContext *context)
6846 GtkIconView *icon_view;
6847 GtkIconViewItem *item;
6848 cairo_surface_t *icon;
6852 icon_view = GTK_ICON_VIEW (widget);
6854 /* if the user uses a custom DnD impl, we don't set the icon here */
6855 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6858 item = gtk_icon_view_get_item_at_coords (icon_view,
6859 icon_view->priv->press_start_x,
6860 icon_view->priv->press_start_y,
6864 g_return_if_fail (item != NULL);
6866 x = icon_view->priv->press_start_x - item->x + 1;
6867 y = icon_view->priv->press_start_y - item->y + 1;
6869 path = gtk_tree_path_new_from_indices (item->index, -1);
6870 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6871 gtk_tree_path_free (path);
6873 cairo_surface_set_device_offset (icon, -x, -y);
6875 gtk_drag_set_icon_surface (context, icon);
6877 cairo_surface_destroy (icon);
6881 gtk_icon_view_drag_end (GtkWidget *widget,
6882 GdkDragContext *context)
6888 gtk_icon_view_drag_data_get (GtkWidget *widget,
6889 GdkDragContext *context,
6890 GtkSelectionData *selection_data,
6894 GtkIconView *icon_view;
6895 GtkTreeModel *model;
6896 GtkTreePath *source_row;
6898 icon_view = GTK_ICON_VIEW (widget);
6899 model = gtk_icon_view_get_model (icon_view);
6904 if (!icon_view->priv->source_set)
6907 source_row = get_source_row (context);
6909 if (source_row == NULL)
6912 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6913 * any model; for DragSource models there are some other targets
6917 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6918 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6923 /* If drag_data_get does nothing, try providing row data. */
6924 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6925 gtk_tree_set_row_drag_data (selection_data,
6930 gtk_tree_path_free (source_row);
6934 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6935 GdkDragContext *context)
6937 GtkTreeModel *model;
6938 GtkIconView *icon_view;
6939 GtkTreePath *source_row;
6941 icon_view = GTK_ICON_VIEW (widget);
6942 model = gtk_icon_view_get_model (icon_view);
6944 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6947 if (!icon_view->priv->source_set)
6950 source_row = get_source_row (context);
6952 if (source_row == NULL)
6955 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6958 gtk_tree_path_free (source_row);
6960 set_source_row (context, NULL, NULL);
6963 /* Target side drag signals */
6965 gtk_icon_view_drag_leave (GtkWidget *widget,
6966 GdkDragContext *context,
6969 GtkIconView *icon_view;
6971 icon_view = GTK_ICON_VIEW (widget);
6973 /* unset any highlight row */
6974 gtk_icon_view_set_drag_dest_item (icon_view,
6976 GTK_ICON_VIEW_DROP_LEFT);
6978 remove_scroll_timeout (icon_view);
6982 gtk_icon_view_drag_motion (GtkWidget *widget,
6983 GdkDragContext *context,
6988 GtkTreePath *path = NULL;
6989 GtkIconViewDropPosition pos;
6990 GtkIconView *icon_view;
6991 GdkDragAction suggested_action = 0;
6995 icon_view = GTK_ICON_VIEW (widget);
6997 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7000 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7002 /* we only know this *after* set_desination_row */
7003 empty = icon_view->priv->empty_view_drop;
7005 if (path == NULL && !empty)
7007 /* Can't drop here. */
7008 gdk_drag_status (context, 0, time);
7012 if (icon_view->priv->scroll_timeout_id == 0)
7014 icon_view->priv->scroll_timeout_id =
7015 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7018 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7020 /* Request data so we can use the source row when
7021 * determining whether to accept the drop
7023 set_status_pending (context, suggested_action);
7024 gtk_drag_get_data (widget, context, target, time);
7028 set_status_pending (context, 0);
7029 gdk_drag_status (context, suggested_action, time);
7034 gtk_tree_path_free (path);
7040 gtk_icon_view_drag_drop (GtkWidget *widget,
7041 GdkDragContext *context,
7046 GtkIconView *icon_view;
7048 GdkDragAction suggested_action = 0;
7049 GdkAtom target = GDK_NONE;
7050 GtkTreeModel *model;
7051 gboolean drop_append_mode;
7053 icon_view = GTK_ICON_VIEW (widget);
7054 model = gtk_icon_view_get_model (icon_view);
7056 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7058 if (!icon_view->priv->dest_set)
7061 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7064 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7067 path = get_logical_destination (icon_view, &drop_append_mode);
7069 if (target != GDK_NONE && path != NULL)
7071 /* in case a motion had requested drag data, change things so we
7072 * treat drag data receives as a drop.
7074 set_status_pending (context, 0);
7075 set_dest_row (context, model, path,
7076 icon_view->priv->empty_view_drop, drop_append_mode);
7080 gtk_tree_path_free (path);
7082 /* Unset this thing */
7083 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7085 if (target != GDK_NONE)
7087 gtk_drag_get_data (widget, context, target, time);
7095 gtk_icon_view_drag_data_received (GtkWidget *widget,
7096 GdkDragContext *context,
7099 GtkSelectionData *selection_data,
7104 gboolean accepted = FALSE;
7105 GtkTreeModel *model;
7106 GtkIconView *icon_view;
7107 GtkTreePath *dest_row;
7108 GdkDragAction suggested_action;
7109 gboolean drop_append_mode;
7111 icon_view = GTK_ICON_VIEW (widget);
7112 model = gtk_icon_view_get_model (icon_view);
7114 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7117 if (!icon_view->priv->dest_set)
7120 suggested_action = get_status_pending (context);
7122 if (suggested_action)
7124 /* We are getting this data due to a request in drag_motion,
7125 * rather than due to a request in drag_drop, so we are just
7126 * supposed to call drag_status, not actually paste in the
7129 path = get_logical_destination (icon_view, &drop_append_mode);
7132 suggested_action = 0;
7134 if (suggested_action)
7136 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7139 suggested_action = 0;
7142 gdk_drag_status (context, suggested_action, time);
7145 gtk_tree_path_free (path);
7147 /* If you can't drop, remove user drop indicator until the next motion */
7148 if (suggested_action == 0)
7149 gtk_icon_view_set_drag_dest_item (icon_view,
7151 GTK_ICON_VIEW_DROP_LEFT);
7156 dest_row = get_dest_row (context);
7158 if (dest_row == NULL)
7161 if (selection_data->length >= 0)
7163 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7169 gtk_drag_finish (context,
7171 (context->action == GDK_ACTION_MOVE),
7174 gtk_tree_path_free (dest_row);
7177 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7180 /* Drag-and-Drop support */
7182 * gtk_icon_view_enable_model_drag_source:
7183 * @icon_view: a #GtkIconTreeView
7184 * @start_button_mask: Mask of allowed buttons to start drag
7185 * @targets: the table of targets that the drag will support
7186 * @n_targets: the number of items in @targets
7187 * @actions: the bitmask of possible actions for a drag from this
7190 * Turns @icon_view into a drag source for automatic DND. Calling this
7191 * method sets #GtkIconView:reorderable to %FALSE.
7196 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7197 GdkModifierType start_button_mask,
7198 const GtkTargetEntry *targets,
7200 GdkDragAction actions)
7202 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7204 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7206 icon_view->priv->start_button_mask = start_button_mask;
7207 icon_view->priv->source_actions = actions;
7209 icon_view->priv->source_set = TRUE;
7211 unset_reorderable (icon_view);
7215 * gtk_icon_view_enable_model_drag_dest:
7216 * @icon_view: a #GtkIconView
7217 * @targets: the table of targets that the drag will support
7218 * @n_targets: the number of items in @targets
7219 * @actions: the bitmask of possible actions for a drag to this
7222 * Turns @icon_view into a drop destination for automatic DND. Calling this
7223 * method sets #GtkIconView:reorderable to %FALSE.
7228 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7229 const GtkTargetEntry *targets,
7231 GdkDragAction actions)
7233 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7235 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7237 icon_view->priv->dest_actions = actions;
7239 icon_view->priv->dest_set = TRUE;
7241 unset_reorderable (icon_view);
7245 * gtk_icon_view_unset_model_drag_source:
7246 * @icon_view: a #GtkIconView
7248 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7249 * method sets #GtkIconView:reorderable to %FALSE.
7254 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7256 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7258 if (icon_view->priv->source_set)
7260 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7261 icon_view->priv->source_set = FALSE;
7264 unset_reorderable (icon_view);
7268 * gtk_icon_view_unset_model_drag_dest:
7269 * @icon_view: a #GtkIconView
7271 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7272 * method sets #GtkIconView:reorderable to %FALSE.
7277 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7279 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7281 if (icon_view->priv->dest_set)
7283 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7284 icon_view->priv->dest_set = FALSE;
7287 unset_reorderable (icon_view);
7290 /* These are useful to implement your own custom stuff. */
7292 * gtk_icon_view_set_drag_dest_item:
7293 * @icon_view: a #GtkIconView
7294 * @path: (allow-none): The path of the item to highlight, or %NULL.
7295 * @pos: Specifies where to drop, relative to the item
7297 * Sets the item that is highlighted for feedback.
7302 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7304 GtkIconViewDropPosition pos)
7306 /* Note; this function is exported to allow a custom DND
7307 * implementation, so it can't touch TreeViewDragInfo
7310 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7312 if (icon_view->priv->dest_item)
7314 GtkTreePath *current_path;
7315 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7316 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7317 icon_view->priv->dest_item = NULL;
7319 gtk_icon_view_queue_draw_path (icon_view, current_path);
7320 gtk_tree_path_free (current_path);
7323 /* special case a drop on an empty model */
7324 icon_view->priv->empty_view_drop = FALSE;
7325 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7326 && gtk_tree_path_get_depth (path) == 1
7327 && gtk_tree_path_get_indices (path)[0] == 0)
7331 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7334 if (n_children == 0)
7335 icon_view->priv->empty_view_drop = TRUE;
7338 icon_view->priv->dest_pos = pos;
7342 icon_view->priv->dest_item =
7343 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7344 icon_view->priv->model, path);
7346 gtk_icon_view_queue_draw_path (icon_view, path);
7351 * gtk_icon_view_get_drag_dest_item:
7352 * @icon_view: a #GtkIconView
7353 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7354 * @pos: (allow-none): Return location for the drop position, or %NULL
7356 * Gets information about the item that is highlighted for feedback.
7361 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7363 GtkIconViewDropPosition *pos)
7365 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7369 if (icon_view->priv->dest_item)
7370 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7376 *pos = icon_view->priv->dest_pos;
7380 * gtk_icon_view_get_dest_item_at_pos:
7381 * @icon_view: a #GtkIconView
7382 * @drag_x: the position to determine the destination item for
7383 * @drag_y: the position to determine the destination item for
7384 * @path: (allow-none): Return location for the path of the item, or %NULL.
7385 * @pos: (allow-none): Return location for the drop position, or %NULL
7387 * Determines the destination item for a given position.
7389 * Return value: whether there is an item at the given position.
7394 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7398 GtkIconViewDropPosition *pos)
7400 GtkIconViewItem *item;
7402 /* Note; this function is exported to allow a custom DND
7403 * implementation, so it can't touch TreeViewDragInfo
7406 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7407 g_return_val_if_fail (drag_x >= 0, FALSE);
7408 g_return_val_if_fail (drag_y >= 0, FALSE);
7409 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7415 item = gtk_icon_view_get_item_at_coords (icon_view,
7416 drag_x + icon_view->priv->hadjustment->value,
7417 drag_y + icon_view->priv->vadjustment->value,
7424 *path = gtk_tree_path_new_from_indices (item->index, -1);
7428 if (drag_x < item->x + item->width / 4)
7429 *pos = GTK_ICON_VIEW_DROP_LEFT;
7430 else if (drag_x > item->x + item->width * 3 / 4)
7431 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7432 else if (drag_y < item->y + item->height / 4)
7433 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7434 else if (drag_y > item->y + item->height * 3 / 4)
7435 *pos = GTK_ICON_VIEW_DROP_BELOW;
7437 *pos = GTK_ICON_VIEW_DROP_INTO;
7444 * gtk_icon_view_create_drag_icon:
7445 * @icon_view: a #GtkIconView
7446 * @path: a #GtkTreePath in @icon_view
7448 * Creates a #cairo_surface_t representation of the item at @path.
7449 * This image is used for a drag icon.
7451 * Return value: (transfer full) a newly-allocated surface of the drag icon.
7456 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7461 cairo_surface_t *surface;
7465 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7466 g_return_val_if_fail (path != NULL, NULL);
7468 widget = GTK_WIDGET (icon_view);
7470 if (!gtk_widget_get_realized (widget))
7473 index = gtk_tree_path_get_indices (path)[0];
7475 for (l = icon_view->priv->items; l; l = l->next)
7477 GtkIconViewItem *item = l->data;
7479 if (index == item->index)
7481 surface = gdk_window_create_similar_surface (icon_view->priv->bin_window,
7482 CAIRO_CONTENT_COLOR,
7486 cr = cairo_create (surface);
7487 cairo_set_line_width (cr, 1.);
7489 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
7490 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7495 cairo_rectangle (cr, 0, 0, item->width, item->height);
7498 gtk_icon_view_paint_item (icon_view, cr, item, 1, 1, FALSE);
7502 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7503 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7516 * gtk_icon_view_get_reorderable:
7517 * @icon_view: a #GtkIconView
7519 * Retrieves whether the user can reorder the list via drag-and-drop.
7520 * See gtk_icon_view_set_reorderable().
7522 * Return value: %TRUE if the list can be reordered.
7527 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7529 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7531 return icon_view->priv->reorderable;
7534 static const GtkTargetEntry item_targets[] = {
7535 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7540 * gtk_icon_view_set_reorderable:
7541 * @icon_view: A #GtkIconView.
7542 * @reorderable: %TRUE, if the list of items can be reordered.
7544 * This function is a convenience function to allow you to reorder models that
7545 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7546 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7547 * the user can reorder the model by dragging and dropping rows. The
7548 * developer can listen to these changes by connecting to the model's
7549 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7550 * the icon view as a drag source and destination. Therefore, drag and
7551 * drop can not be used in a reorderable view for any other purpose.
7553 * This function does not give you any degree of control over the order -- any
7554 * reordering is allowed. If more control is needed, you should probably
7555 * handle drag and drop manually.
7560 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7561 gboolean reorderable)
7563 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7565 reorderable = reorderable != FALSE;
7567 if (icon_view->priv->reorderable == reorderable)
7572 gtk_icon_view_enable_model_drag_source (icon_view,
7575 G_N_ELEMENTS (item_targets),
7577 gtk_icon_view_enable_model_drag_dest (icon_view,
7579 G_N_ELEMENTS (item_targets),
7584 gtk_icon_view_unset_model_drag_source (icon_view);
7585 gtk_icon_view_unset_model_drag_dest (icon_view);
7588 icon_view->priv->reorderable = reorderable;
7590 g_object_notify (G_OBJECT (icon_view), "reorderable");
7594 /* Accessibility Support */
7596 static gpointer accessible_parent_class;
7597 static gpointer accessible_item_parent_class;
7598 static GQuark accessible_private_data_quark = 0;
7600 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7601 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7602 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7604 static GType gtk_icon_view_item_accessible_get_type (void);
7615 GtkIconViewItem *item;
7619 AtkStateSet *state_set;
7623 GtkTextBuffer *text_buffer;
7625 gchar *action_descriptions[LAST_ACTION];
7626 gchar *image_description;
7627 guint action_idle_handler;
7628 } GtkIconViewItemAccessible;
7630 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7636 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7641 typedef struct _GtkIconViewItemAccessibleClass
7643 AtkObjectClass parent_class;
7645 } GtkIconViewItemAccessibleClass;
7647 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7650 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7652 GtkIconViewItemAccessible *item;
7653 GtkIconView *icon_view;
7656 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7657 item->action_idle_handler = 0;
7659 if (item->widget != NULL)
7661 icon_view = GTK_ICON_VIEW (item->widget);
7662 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7663 gtk_icon_view_item_activated (icon_view, path);
7664 gtk_tree_path_free (path);
7671 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7674 GtkIconViewItemAccessible *item;
7676 if (i < 0 || i >= LAST_ACTION)
7679 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7681 if (!GTK_IS_ICON_VIEW (item->widget))
7684 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7689 case ACTION_ACTIVATE:
7690 if (!item->action_idle_handler)
7691 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7694 g_assert_not_reached ();
7702 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7707 static const gchar *
7708 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7711 GtkIconViewItemAccessible *item;
7713 if (i < 0 || i >= LAST_ACTION)
7716 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7718 if (item->action_descriptions[i])
7719 return item->action_descriptions[i];
7721 return gtk_icon_view_item_accessible_action_descriptions[i];
7724 static const gchar *
7725 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7728 if (i < 0 || i >= LAST_ACTION)
7731 return gtk_icon_view_item_accessible_action_names[i];
7735 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7737 const gchar *description)
7739 GtkIconViewItemAccessible *item;
7741 if (i < 0 || i >= LAST_ACTION)
7744 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7746 g_free (item->action_descriptions[i]);
7748 item->action_descriptions[i] = g_strdup (description);
7754 atk_action_item_interface_init (AtkActionIface *iface)
7756 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7757 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7758 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7759 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7760 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7763 static const gchar *
7764 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7766 GtkIconViewItemAccessible *item;
7768 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7770 return item->image_description;
7774 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7775 const gchar *description)
7777 GtkIconViewItemAccessible *item;
7779 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7781 g_free (item->image_description);
7782 item->image_description = g_strdup (description);
7788 get_pixbuf_box (GtkIconView *icon_view,
7789 GtkIconViewItem *item,
7794 for (l = icon_view->priv->cell_list; l; l = l->next)
7796 GtkIconViewCellInfo *info = l->data;
7798 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7800 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7810 get_text (GtkIconView *icon_view,
7811 GtkIconViewItem *item)
7816 for (l = icon_view->priv->cell_list; l; l = l->next)
7818 GtkIconViewCellInfo *info = l->data;
7820 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7822 g_object_get (info->cell, "text", &text, NULL);
7832 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7836 GtkIconViewItemAccessible *item;
7839 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7841 if (!GTK_IS_ICON_VIEW (item->widget))
7844 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7847 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7850 *height = box.height;
7855 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7858 AtkCoordType coord_type)
7860 GtkIconViewItemAccessible *item;
7863 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7865 if (!GTK_IS_ICON_VIEW (item->widget))
7868 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7871 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7873 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7875 *x+= box.x - item->item->x;
7876 *y+= box.y - item->item->y;
7882 atk_image_item_interface_init (AtkImageIface *iface)
7884 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7885 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7886 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7887 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7891 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7895 GtkIconViewItemAccessible *item;
7896 GtkTextIter start, end;
7897 GtkTextBuffer *buffer;
7899 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7901 if (!GTK_IS_ICON_VIEW (item->widget))
7904 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7907 buffer = item->text_buffer;
7908 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7910 gtk_text_buffer_get_end_iter (buffer, &end);
7912 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7914 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7918 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7921 GtkIconViewItemAccessible *item;
7922 GtkTextIter start, end;
7923 GtkTextBuffer *buffer;
7927 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7929 if (!GTK_IS_ICON_VIEW (item->widget))
7932 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7935 buffer = item->text_buffer;
7936 if (offset >= gtk_text_buffer_get_char_count (buffer))
7939 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7941 gtk_text_iter_forward_char (&end);
7942 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7943 unichar = g_utf8_get_char (string);
7951 get_pango_text_offsets (PangoLayout *layout,
7952 GtkTextBuffer *buffer,
7954 AtkTextBoundary boundary_type,
7958 GtkTextIter *start_iter,
7959 GtkTextIter *end_iter)
7961 PangoLayoutIter *iter;
7962 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7963 gint index, start_index, end_index;
7965 gboolean found = FALSE;
7967 text = pango_layout_get_text (layout);
7968 index = g_utf8_offset_to_pointer (text, offset) - text;
7969 iter = pango_layout_get_iter (layout);
7972 line = pango_layout_iter_get_line_readonly (iter);
7973 start_index = line->start_index;
7974 end_index = start_index + line->length;
7976 if (index >= start_index && index <= end_index)
7979 * Found line for offset
7985 * We want the previous line
7989 switch (boundary_type)
7991 case ATK_TEXT_BOUNDARY_LINE_START:
7992 end_index = start_index;
7993 start_index = prev_line->start_index;
7995 case ATK_TEXT_BOUNDARY_LINE_END:
7997 start_index = prev_prev_line->start_index +
7998 prev_prev_line->length;
7999 end_index = prev_line->start_index + prev_line->length;
8002 g_assert_not_reached();
8006 start_index = end_index = 0;
8009 switch (boundary_type)
8011 case ATK_TEXT_BOUNDARY_LINE_START:
8012 if (pango_layout_iter_next_line (iter))
8013 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8015 case ATK_TEXT_BOUNDARY_LINE_END:
8017 start_index = prev_line->start_index +
8021 g_assert_not_reached();
8026 * We want the next line
8028 if (pango_layout_iter_next_line (iter))
8030 line = pango_layout_iter_get_line_readonly (iter);
8031 switch (boundary_type)
8033 case ATK_TEXT_BOUNDARY_LINE_START:
8034 start_index = line->start_index;
8035 if (pango_layout_iter_next_line (iter))
8036 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8038 end_index = start_index + line->length;
8040 case ATK_TEXT_BOUNDARY_LINE_END:
8041 start_index = end_index;
8042 end_index = line->start_index + line->length;
8045 g_assert_not_reached();
8049 start_index = end_index;
8055 prev_prev_line = prev_line;
8058 while (pango_layout_iter_next_line (iter));
8062 start_index = prev_line->start_index + prev_line->length;
8063 end_index = start_index;
8065 pango_layout_iter_free (iter);
8066 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8067 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8069 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8070 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8075 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8077 AtkTextBoundary boundary_type,
8081 GtkIconViewItemAccessible *item;
8082 GtkTextIter start, end;
8083 GtkTextBuffer *buffer;
8085 GtkIconView *icon_view;
8088 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8090 if (!GTK_IS_ICON_VIEW (item->widget))
8093 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8096 buffer = item->text_buffer;
8098 if (!gtk_text_buffer_get_char_count (buffer))
8102 return g_strdup ("");
8104 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8108 switch (boundary_type)
8110 case ATK_TEXT_BOUNDARY_CHAR:
8111 gtk_text_iter_backward_char(&start);
8113 case ATK_TEXT_BOUNDARY_WORD_START:
8114 if (!gtk_text_iter_starts_word (&start))
8115 gtk_text_iter_backward_word_start (&start);
8117 gtk_text_iter_backward_word_start(&start);
8119 case ATK_TEXT_BOUNDARY_WORD_END:
8120 if (gtk_text_iter_inside_word (&start) &&
8121 !gtk_text_iter_starts_word (&start))
8122 gtk_text_iter_backward_word_start (&start);
8123 while (!gtk_text_iter_ends_word (&start))
8125 if (!gtk_text_iter_backward_char (&start))
8129 gtk_text_iter_backward_word_start(&start);
8130 while (!gtk_text_iter_ends_word (&start))
8132 if (!gtk_text_iter_backward_char (&start))
8136 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8137 if (!gtk_text_iter_starts_sentence (&start))
8138 gtk_text_iter_backward_sentence_start (&start);
8140 gtk_text_iter_backward_sentence_start (&start);
8142 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8143 if (gtk_text_iter_inside_sentence (&start) &&
8144 !gtk_text_iter_starts_sentence (&start))
8145 gtk_text_iter_backward_sentence_start (&start);
8146 while (!gtk_text_iter_ends_sentence (&start))
8148 if (!gtk_text_iter_backward_char (&start))
8152 gtk_text_iter_backward_sentence_start (&start);
8153 while (!gtk_text_iter_ends_sentence (&start))
8155 if (!gtk_text_iter_backward_char (&start))
8159 case ATK_TEXT_BOUNDARY_LINE_START:
8160 case ATK_TEXT_BOUNDARY_LINE_END:
8162 icon_view = GTK_ICON_VIEW (item->widget);
8163 /* FIXME we probably have to use GailTextCell to salvage this */
8164 gtk_icon_view_update_item_text (icon_view, item->item);
8165 get_pango_text_offsets (icon_view->priv->layout,
8178 *start_offset = gtk_text_iter_get_offset (&start);
8179 *end_offset = gtk_text_iter_get_offset (&end);
8181 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8185 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8187 AtkTextBoundary boundary_type,
8191 GtkIconViewItemAccessible *item;
8192 GtkTextIter start, end;
8193 GtkTextBuffer *buffer;
8195 GtkIconView *icon_view;
8198 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8200 if (!GTK_IS_ICON_VIEW (item->widget))
8203 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8206 buffer = item->text_buffer;
8208 if (!gtk_text_buffer_get_char_count (buffer))
8212 return g_strdup ("");
8214 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8218 switch (boundary_type)
8220 case ATK_TEXT_BOUNDARY_CHAR:
8221 gtk_text_iter_forward_char (&end);
8223 case ATK_TEXT_BOUNDARY_WORD_START:
8224 if (!gtk_text_iter_starts_word (&start))
8225 gtk_text_iter_backward_word_start (&start);
8226 if (gtk_text_iter_inside_word (&end))
8227 gtk_text_iter_forward_word_end (&end);
8228 while (!gtk_text_iter_starts_word (&end))
8230 if (!gtk_text_iter_forward_char (&end))
8234 case ATK_TEXT_BOUNDARY_WORD_END:
8235 if (gtk_text_iter_inside_word (&start) &&
8236 !gtk_text_iter_starts_word (&start))
8237 gtk_text_iter_backward_word_start (&start);
8238 while (!gtk_text_iter_ends_word (&start))
8240 if (!gtk_text_iter_backward_char (&start))
8243 gtk_text_iter_forward_word_end (&end);
8245 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8246 if (!gtk_text_iter_starts_sentence (&start))
8247 gtk_text_iter_backward_sentence_start (&start);
8248 if (gtk_text_iter_inside_sentence (&end))
8249 gtk_text_iter_forward_sentence_end (&end);
8250 while (!gtk_text_iter_starts_sentence (&end))
8252 if (!gtk_text_iter_forward_char (&end))
8256 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8257 if (gtk_text_iter_inside_sentence (&start) &&
8258 !gtk_text_iter_starts_sentence (&start))
8259 gtk_text_iter_backward_sentence_start (&start);
8260 while (!gtk_text_iter_ends_sentence (&start))
8262 if (!gtk_text_iter_backward_char (&start))
8265 gtk_text_iter_forward_sentence_end (&end);
8267 case ATK_TEXT_BOUNDARY_LINE_START:
8268 case ATK_TEXT_BOUNDARY_LINE_END:
8270 icon_view = GTK_ICON_VIEW (item->widget);
8271 /* FIXME we probably have to use GailTextCell to salvage this */
8272 gtk_icon_view_update_item_text (icon_view, item->item);
8273 get_pango_text_offsets (icon_view->priv->layout,
8287 *start_offset = gtk_text_iter_get_offset (&start);
8288 *end_offset = gtk_text_iter_get_offset (&end);
8290 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8294 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8296 AtkTextBoundary boundary_type,
8300 GtkIconViewItemAccessible *item;
8301 GtkTextIter start, end;
8302 GtkTextBuffer *buffer;
8304 GtkIconView *icon_view;
8307 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8309 if (!GTK_IS_ICON_VIEW (item->widget))
8312 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8315 buffer = item->text_buffer;
8317 if (!gtk_text_buffer_get_char_count (buffer))
8321 return g_strdup ("");
8323 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8327 switch (boundary_type)
8329 case ATK_TEXT_BOUNDARY_CHAR:
8330 gtk_text_iter_forward_char(&start);
8331 gtk_text_iter_forward_chars(&end, 2);
8333 case ATK_TEXT_BOUNDARY_WORD_START:
8334 if (gtk_text_iter_inside_word (&end))
8335 gtk_text_iter_forward_word_end (&end);
8336 while (!gtk_text_iter_starts_word (&end))
8338 if (!gtk_text_iter_forward_char (&end))
8342 if (!gtk_text_iter_is_end (&end))
8344 gtk_text_iter_forward_word_end (&end);
8345 while (!gtk_text_iter_starts_word (&end))
8347 if (!gtk_text_iter_forward_char (&end))
8352 case ATK_TEXT_BOUNDARY_WORD_END:
8353 gtk_text_iter_forward_word_end (&end);
8355 if (!gtk_text_iter_is_end (&end))
8356 gtk_text_iter_forward_word_end (&end);
8358 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8359 if (gtk_text_iter_inside_sentence (&end))
8360 gtk_text_iter_forward_sentence_end (&end);
8361 while (!gtk_text_iter_starts_sentence (&end))
8363 if (!gtk_text_iter_forward_char (&end))
8367 if (!gtk_text_iter_is_end (&end))
8369 gtk_text_iter_forward_sentence_end (&end);
8370 while (!gtk_text_iter_starts_sentence (&end))
8372 if (!gtk_text_iter_forward_char (&end))
8377 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8378 gtk_text_iter_forward_sentence_end (&end);
8380 if (!gtk_text_iter_is_end (&end))
8381 gtk_text_iter_forward_sentence_end (&end);
8383 case ATK_TEXT_BOUNDARY_LINE_START:
8384 case ATK_TEXT_BOUNDARY_LINE_END:
8386 icon_view = GTK_ICON_VIEW (item->widget);
8387 /* FIXME we probably have to use GailTextCell to salvage this */
8388 gtk_icon_view_update_item_text (icon_view, item->item);
8389 get_pango_text_offsets (icon_view->priv->layout,
8401 *start_offset = gtk_text_iter_get_offset (&start);
8402 *end_offset = gtk_text_iter_get_offset (&end);
8404 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8408 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8410 GtkIconViewItemAccessible *item;
8412 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8414 if (!GTK_IS_ICON_VIEW (item->widget))
8417 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8420 return gtk_text_buffer_get_char_count (item->text_buffer);
8424 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8430 AtkCoordType coord_type)
8432 GtkIconViewItemAccessible *item;
8434 GtkIconView *icon_view;
8435 PangoRectangle char_rect;
8436 const gchar *item_text;
8440 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8442 if (!GTK_IS_ICON_VIEW (item->widget))
8445 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8449 icon_view = GTK_ICON_VIEW (item->widget);
8450 /* FIXME we probably have to use GailTextCell to salvage this */
8451 gtk_icon_view_update_item_text (icon_view, item->item);
8452 item_text = pango_layout_get_text (icon_view->priv->layout);
8453 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8454 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8456 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8457 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8458 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8459 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8460 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8461 *width = char_rect.width / PANGO_SCALE;
8462 *height = char_rect.height / PANGO_SCALE;
8467 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8470 AtkCoordType coord_type)
8472 GtkIconViewItemAccessible *item;
8475 GtkIconView *icon_view;
8476 const gchar *item_text;
8481 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8483 if (!GTK_IS_ICON_VIEW (item->widget))
8486 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8490 icon_view = GTK_ICON_VIEW (item->widget);
8491 /* FIXME we probably have to use GailTextCell to salvage this */
8492 gtk_icon_view_update_item_text (icon_view, item->item);
8493 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8494 x -= l_x + item->item->layout_x - item->item->x;
8495 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8496 y -= l_y + item->item->layout_y - item->item->y;
8497 item_text = pango_layout_get_text (icon_view->priv->layout);
8498 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8509 offset = g_utf8_strlen (item_text, -1);
8511 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8517 atk_text_item_interface_init (AtkTextIface *iface)
8519 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8520 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8521 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8522 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8523 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8524 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8525 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8526 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8530 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8535 AtkCoordType coord_type)
8537 GtkIconViewItemAccessible *item;
8538 AtkObject *parent_obj;
8541 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8543 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8544 if (!GTK_IS_WIDGET (item->widget))
8547 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8550 *width = item->item->width;
8551 *height = item->item->height;
8552 if (gtk_icon_view_item_accessible_is_showing (item))
8554 parent_obj = gtk_widget_get_accessible (item->widget);
8555 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8556 *x = l_x + item->item->x;
8557 *y = l_y + item->item->y;
8567 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8569 GtkIconViewItemAccessible *item;
8570 GtkWidget *toplevel;
8572 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8574 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8575 if (!GTK_IS_WIDGET (item->widget))
8578 gtk_widget_grab_focus (item->widget);
8579 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8580 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8581 if (gtk_widget_is_toplevel (toplevel))
8582 gtk_window_present (GTK_WINDOW (toplevel));
8588 atk_component_item_interface_init (AtkComponentIface *iface)
8590 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8591 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8595 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8596 AtkStateType state_type,
8597 gboolean emit_signal)
8601 rc = atk_state_set_add_state (item->state_set, state_type);
8603 * The signal should only be generated if the value changed,
8604 * not when the item is set up. So states that are set
8605 * initially should pass FALSE as the emit_signal argument.
8610 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8611 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8612 if (state_type == ATK_STATE_VISIBLE)
8613 g_signal_emit_by_name (item, "visible-data-changed");
8620 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8621 AtkStateType state_type,
8622 gboolean emit_signal)
8624 if (atk_state_set_contains_state (item->state_set, state_type))
8628 rc = atk_state_set_remove_state (item->state_set, state_type);
8630 * The signal should only be generated if the value changed,
8631 * not when the item is set up. So states that are set
8632 * initially should pass FALSE as the emit_signal argument.
8637 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8638 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8639 if (state_type == ATK_STATE_VISIBLE)
8640 g_signal_emit_by_name (item, "visible-data-changed");
8650 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8652 GtkAllocation allocation;
8653 GtkIconView *icon_view;
8654 GdkRectangle visible_rect;
8655 gboolean is_showing;
8658 * An item is considered "SHOWING" if any part of the item is in the
8659 * visible rectangle.
8662 if (!GTK_IS_ICON_VIEW (item->widget))
8665 if (item->item == NULL)
8668 gtk_widget_get_allocation (item->widget, &allocation);
8670 icon_view = GTK_ICON_VIEW (item->widget);
8672 if (icon_view->priv->hadjustment)
8673 visible_rect.x += icon_view->priv->hadjustment->value;
8675 if (icon_view->priv->hadjustment)
8676 visible_rect.y += icon_view->priv->vadjustment->value;
8677 visible_rect.width = allocation.width;
8678 visible_rect.height = allocation.height;
8680 if (((item->item->x + item->item->width) < visible_rect.x) ||
8681 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8682 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8683 (item->item->y > (visible_rect.y + visible_rect.height)))
8692 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8693 gboolean emit_signal)
8695 if (gtk_icon_view_item_accessible_is_showing (item))
8696 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8699 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8704 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8708 item->state_set = atk_state_set_new ();
8710 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8711 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8712 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8713 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8714 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8716 for (i = 0; i < LAST_ACTION; i++)
8717 item->action_descriptions[i] = NULL;
8719 item->image_description = NULL;
8721 item->action_idle_handler = 0;
8725 gtk_icon_view_item_accessible_finalize (GObject *object)
8727 GtkIconViewItemAccessible *item;
8730 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8732 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8735 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8737 if (item->state_set)
8738 g_object_unref (item->state_set);
8740 if (item->text_buffer)
8741 g_object_unref (item->text_buffer);
8743 for (i = 0; i < LAST_ACTION; i++)
8744 g_free (item->action_descriptions[i]);
8746 g_free (item->image_description);
8748 if (item->action_idle_handler)
8750 g_source_remove (item->action_idle_handler);
8751 item->action_idle_handler = 0;
8754 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8757 static G_CONST_RETURN gchar*
8758 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8764 GtkIconViewItemAccessible *item;
8765 GtkTextIter start_iter;
8766 GtkTextIter end_iter;
8768 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8770 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8771 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8773 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8778 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8780 GtkIconViewItemAccessible *item;
8782 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8783 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8786 return gtk_widget_get_accessible (item->widget);
8792 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8794 GtkIconViewItemAccessible *item;
8796 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8797 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8799 return item->item->index;
8802 static AtkStateSet *
8803 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8805 GtkIconViewItemAccessible *item;
8806 GtkIconView *icon_view;
8808 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8809 g_return_val_if_fail (item->state_set, NULL);
8814 icon_view = GTK_ICON_VIEW (item->widget);
8815 if (icon_view->priv->cursor_item == item->item)
8816 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8818 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8819 if (item->item->selected)
8820 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8822 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8824 return g_object_ref (item->state_set);
8828 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8830 GObjectClass *gobject_class;
8832 accessible_item_parent_class = g_type_class_peek_parent (klass);
8834 gobject_class = (GObjectClass *)klass;
8836 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8838 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8839 klass->get_name = gtk_icon_view_item_accessible_get_name;
8840 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8841 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8845 gtk_icon_view_item_accessible_get_type (void)
8847 static GType type = 0;
8851 const GTypeInfo tinfo =
8853 sizeof (GtkIconViewItemAccessibleClass),
8854 (GBaseInitFunc) NULL, /* base init */
8855 (GBaseFinalizeFunc) NULL, /* base finalize */
8856 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8857 (GClassFinalizeFunc) NULL, /* class finalize */
8858 NULL, /* class data */
8859 sizeof (GtkIconViewItemAccessible), /* instance size */
8860 0, /* nb preallocs */
8861 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8862 NULL /* value table */
8865 const GInterfaceInfo atk_component_info =
8867 (GInterfaceInitFunc) atk_component_item_interface_init,
8868 (GInterfaceFinalizeFunc) NULL,
8871 const GInterfaceInfo atk_action_info =
8873 (GInterfaceInitFunc) atk_action_item_interface_init,
8874 (GInterfaceFinalizeFunc) NULL,
8877 const GInterfaceInfo atk_image_info =
8879 (GInterfaceInitFunc) atk_image_item_interface_init,
8880 (GInterfaceFinalizeFunc) NULL,
8883 const GInterfaceInfo atk_text_info =
8885 (GInterfaceInitFunc) atk_text_item_interface_init,
8886 (GInterfaceFinalizeFunc) NULL,
8890 type = g_type_register_static (ATK_TYPE_OBJECT,
8891 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8892 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8893 &atk_component_info);
8894 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8896 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8898 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8905 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8906 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8907 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8909 static GType gtk_icon_view_accessible_get_type (void);
8914 } GtkIconViewAccessible;
8920 } GtkIconViewItemAccessibleInfo;
8926 GtkAdjustment *old_hadj;
8927 GtkAdjustment *old_vadj;
8929 GtkTreeModel *model;
8931 } GtkIconViewAccessiblePrivate;
8933 static GtkIconViewAccessiblePrivate *
8934 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8936 return g_object_get_qdata (G_OBJECT (accessible),
8937 accessible_private_data_quark);
8941 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8945 GtkIconViewItemAccessibleInfo *info;
8946 GtkIconViewItemAccessibleInfo *tmp_info;
8947 GtkIconViewAccessiblePrivate *priv;
8950 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8952 info->index = index;
8954 priv = gtk_icon_view_accessible_get_priv (accessible);
8955 items = priv->items;
8958 tmp_info = items->data;
8959 if (tmp_info->index > index)
8961 items = items->next;
8963 priv->items = g_list_insert_before (priv->items, items, info);
8964 priv->old_hadj = NULL;
8965 priv->old_vadj = NULL;
8969 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8971 GtkIconView *icon_view;
8974 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8978 icon_view = GTK_ICON_VIEW (widget);
8980 return g_list_length (icon_view->priv->items);
8984 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8987 GtkIconViewAccessiblePrivate *priv;
8988 GtkIconViewItemAccessibleInfo *info;
8991 priv = gtk_icon_view_accessible_get_priv (accessible);
8992 items = priv->items;
8997 if (info->index == index)
8999 items = items->next;
9005 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9008 GtkIconView *icon_view;
9012 GtkIconViewItemAccessible *a11y_item;
9014 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9018 icon_view = GTK_ICON_VIEW (widget);
9019 icons = g_list_nth (icon_view->priv->items, index);
9023 GtkIconViewItem *item = icons->data;
9025 g_return_val_if_fail (item->index == index, NULL);
9026 obj = gtk_icon_view_accessible_find_child (accessible, index);
9031 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9032 gtk_icon_view_item_accessible_info_new (accessible,
9035 obj->role = ATK_ROLE_ICON;
9036 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9037 a11y_item->item = item;
9038 a11y_item->widget = widget;
9039 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9041 gtk_icon_view_set_cell_data (icon_view, item);
9042 text = get_text (icon_view, item);
9045 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9049 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9050 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9058 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9061 GtkIconViewAccessiblePrivate *priv;
9062 GtkIconViewItemAccessibleInfo *info;
9063 GtkIconViewItemAccessible *item;
9066 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9070 gboolean act_on_item;
9072 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9076 items = priv->items;
9078 act_on_item = (list == NULL);
9083 info = (GtkIconViewItemAccessibleInfo *)items->data;
9084 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9086 if (act_on_item == FALSE && list == items)
9090 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9092 items = items->next;
9098 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9099 GtkIconView *icon_view)
9102 GtkIconViewAccessible *view;
9105 * The scrollbars have changed
9107 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9108 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9110 gtk_icon_view_accessible_traverse_items (view, NULL);
9114 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9115 GtkAdjustment *hadj,
9116 GtkAdjustment *vadj)
9119 GtkIconViewAccessiblePrivate *priv;
9121 atk_obj = gtk_widget_get_accessible (widget);
9122 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9124 if (priv->old_hadj != hadj)
9128 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9129 (gpointer *)&priv->old_hadj);
9131 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9132 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9135 priv->old_hadj = hadj;
9138 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9139 (gpointer *)&priv->old_hadj);
9140 g_signal_connect (hadj,
9142 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9146 if (priv->old_vadj != vadj)
9150 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9151 (gpointer *)&priv->old_vadj);
9153 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9154 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9157 priv->old_vadj = vadj;
9160 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9161 (gpointer *)&priv->old_vadj);
9162 g_signal_connect (vadj,
9164 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9171 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9179 GtkIconView *icon_view;
9180 GtkIconViewItem *item;
9181 GtkIconViewAccessible *a11y_view;
9182 GtkIconViewItemAccessible *a11y_item;
9186 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9187 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9188 index = gtk_tree_path_get_indices(path)[0];
9189 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9190 gtk_icon_view_accessible_find_child (atk_obj, index));
9194 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9195 icon_view = GTK_ICON_VIEW (widget);
9196 item = a11y_item->item;
9198 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9200 if (!name || strcmp (name, "") == 0)
9202 gtk_icon_view_set_cell_data (icon_view, item);
9203 text = get_text (icon_view, item);
9206 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9212 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9218 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9223 GtkIconViewAccessiblePrivate *priv;
9224 GtkIconViewItemAccessibleInfo *info;
9225 GtkIconViewAccessible *view;
9226 GtkIconViewItemAccessible *item;
9232 index = gtk_tree_path_get_indices(path)[0];
9233 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9234 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9235 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9237 items = priv->items;
9242 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9243 if (info->index != item->item->index)
9245 if (info->index < index)
9246 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9248 if (tmp_list == NULL)
9251 info->index = item->item->index;
9254 items = items->next;
9256 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9257 g_signal_emit_by_name (atk_obj, "children-changed::add",
9263 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9267 GtkIconViewAccessiblePrivate *priv;
9268 GtkIconViewItemAccessibleInfo *info;
9269 GtkIconViewAccessible *view;
9270 GtkIconViewItemAccessible *item;
9273 GList *deleted_item;
9277 index = gtk_tree_path_get_indices(path)[0];
9278 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9279 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9280 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9282 items = priv->items;
9284 deleted_item = NULL;
9289 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9290 if (info->index == index)
9292 deleted_item = items;
9294 if (info->index != item->item->index)
9296 if (tmp_list == NULL)
9299 info->index = item->item->index;
9302 items = items->next;
9304 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9307 info = deleted_item->data;
9308 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9309 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9311 priv->items = g_list_remove_link (priv->items, deleted_item);
9319 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9320 GtkIconViewItemAccessibleInfo *i2)
9322 return i1->index - i2->index;
9326 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9332 GtkIconViewAccessiblePrivate *priv;
9333 GtkIconViewItemAccessibleInfo *info;
9334 GtkIconView *icon_view;
9335 GtkIconViewItemAccessible *item;
9341 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9342 icon_view = GTK_ICON_VIEW (user_data);
9343 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9345 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9347 order = g_new (gint, length);
9348 for (i = 0; i < length; i++)
9349 order [new_order[i]] = i;
9351 items = priv->items;
9355 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9356 info->index = order[info->index];
9357 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9358 items = items->next;
9361 priv->items = g_list_sort (priv->items,
9362 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9368 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9373 obj = G_OBJECT (model);
9374 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9375 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9376 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9377 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9381 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9385 obj = G_OBJECT (icon_view->priv->model);
9386 g_signal_connect_data (obj, "row-changed",
9387 (GCallback) gtk_icon_view_accessible_model_row_changed,
9388 icon_view, NULL, 0);
9389 g_signal_connect_data (obj, "row-inserted",
9390 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9391 icon_view, NULL, G_CONNECT_AFTER);
9392 g_signal_connect_data (obj, "row-deleted",
9393 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9394 icon_view, NULL, G_CONNECT_AFTER);
9395 g_signal_connect_data (obj, "rows-reordered",
9396 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9397 icon_view, NULL, G_CONNECT_AFTER);
9401 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9403 GtkIconViewItemAccessibleInfo *info;
9406 items = priv->items;
9409 info = (GtkIconViewItemAccessibleInfo *) items->data;
9410 g_object_unref (info->item);
9411 g_free (items->data);
9412 items = items->next;
9414 g_list_free (priv->items);
9419 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9422 GtkIconView *icon_view;
9425 GtkIconViewAccessiblePrivate *priv;
9427 if (strcmp (pspec->name, "model") == 0)
9429 widget = GTK_WIDGET (obj);
9430 atk_obj = gtk_widget_get_accessible (widget);
9431 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9434 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9435 (gpointer *)&priv->model);
9436 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9438 gtk_icon_view_accessible_clear_cache (priv);
9440 icon_view = GTK_ICON_VIEW (obj);
9441 priv->model = icon_view->priv->model;
9442 /* If there is no model the GtkIconView is probably being destroyed */
9445 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9446 gtk_icon_view_accessible_connect_model_signals (icon_view);
9454 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9457 GtkIconViewAccessiblePrivate *priv;
9458 GtkIconView *icon_view;
9460 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9461 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9463 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9464 g_object_set_qdata (G_OBJECT (accessible),
9465 accessible_private_data_quark,
9468 icon_view = GTK_ICON_VIEW (data);
9469 if (icon_view->priv->hadjustment)
9471 priv->old_hadj = icon_view->priv->hadjustment;
9472 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9473 g_signal_connect (icon_view->priv->hadjustment,
9475 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9478 if (icon_view->priv->vadjustment)
9480 priv->old_vadj = icon_view->priv->vadjustment;
9481 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9482 g_signal_connect (icon_view->priv->vadjustment,
9484 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9487 g_signal_connect_after (data,
9488 "set-scroll-adjustments",
9489 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9491 g_signal_connect (data,
9493 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9496 priv->model = icon_view->priv->model;
9499 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9500 gtk_icon_view_accessible_connect_model_signals (icon_view);
9503 accessible->role = ATK_ROLE_LAYERED_PANE;
9507 gtk_icon_view_accessible_finalize (GObject *object)
9509 GtkIconViewAccessiblePrivate *priv;
9511 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9512 gtk_icon_view_accessible_clear_cache (priv);
9516 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9520 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9521 GtkAccessible *accessible)
9524 GtkIconViewAccessiblePrivate *priv;
9526 atk_obj = ATK_OBJECT (accessible);
9527 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9530 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9531 (gpointer *)&priv->old_hadj);
9533 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9534 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9536 priv->old_hadj = NULL;
9540 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9541 (gpointer *)&priv->old_vadj);
9543 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9544 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9546 priv->old_vadj = NULL;
9551 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9555 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9558 g_signal_connect_after (widget,
9560 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9563 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9567 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9569 GObjectClass *gobject_class;
9570 GtkAccessibleClass *accessible_class;
9572 accessible_parent_class = g_type_class_peek_parent (klass);
9574 gobject_class = (GObjectClass *)klass;
9575 accessible_class = (GtkAccessibleClass *)klass;
9577 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9579 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9580 klass->ref_child = gtk_icon_view_accessible_ref_child;
9581 klass->initialize = gtk_icon_view_accessible_initialize;
9583 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9585 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9589 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9592 AtkCoordType coord_type)
9595 GtkIconView *icon_view;
9596 GtkIconViewItem *item;
9599 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9601 /* State is defunct */
9604 icon_view = GTK_ICON_VIEW (widget);
9605 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9606 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9608 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9614 atk_component_interface_init (AtkComponentIface *iface)
9616 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9620 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9624 GtkIconView *icon_view;
9625 GtkIconViewItem *item;
9627 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9631 icon_view = GTK_ICON_VIEW (widget);
9633 item = g_list_nth_data (icon_view->priv->items, i);
9638 gtk_icon_view_select_item (icon_view, item);
9644 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9647 GtkIconView *icon_view;
9649 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9653 icon_view = GTK_ICON_VIEW (widget);
9654 gtk_icon_view_unselect_all (icon_view);
9660 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9665 GtkIconView *icon_view;
9666 GtkIconViewItem *item;
9668 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9672 icon_view = GTK_ICON_VIEW (widget);
9674 l = icon_view->priv->items;
9681 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9692 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9695 GtkIconView *icon_view;
9696 GtkIconViewItem *item;
9700 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9704 icon_view = GTK_ICON_VIEW (widget);
9706 l = icon_view->priv->items;
9722 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9726 GtkIconView *icon_view;
9727 GtkIconViewItem *item;
9729 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9733 icon_view = GTK_ICON_VIEW (widget);
9735 item = g_list_nth_data (icon_view->priv->items, i);
9739 return item->selected;
9743 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9747 GtkIconView *icon_view;
9748 GtkIconViewItem *item;
9752 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9756 icon_view = GTK_ICON_VIEW (widget);
9757 l = icon_view->priv->items;
9766 gtk_icon_view_unselect_item (icon_view, item);
9778 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9781 GtkIconView *icon_view;
9783 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9787 icon_view = GTK_ICON_VIEW (widget);
9788 gtk_icon_view_select_all (icon_view);
9793 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9795 iface->add_selection = gtk_icon_view_accessible_add_selection;
9796 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9797 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9798 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9799 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9800 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9801 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9805 gtk_icon_view_accessible_get_type (void)
9807 static GType type = 0;
9814 (GBaseInitFunc) NULL, /* base init */
9815 (GBaseFinalizeFunc) NULL, /* base finalize */
9816 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9817 (GClassFinalizeFunc) NULL, /* class finalize */
9818 NULL, /* class data */
9819 0, /* instance size */
9820 0, /* nb preallocs */
9821 (GInstanceInitFunc) NULL, /* instance init */
9822 NULL /* value table */
9824 const GInterfaceInfo atk_component_info =
9826 (GInterfaceInitFunc) atk_component_interface_init,
9827 (GInterfaceFinalizeFunc) NULL,
9830 const GInterfaceInfo atk_selection_info =
9832 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9833 (GInterfaceFinalizeFunc) NULL,
9838 * Figure out the size of the class and instance
9839 * we are deriving from
9841 AtkObjectFactory *factory;
9844 GType derived_atk_type;
9846 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9847 factory = atk_registry_get_factory (atk_get_default_registry (),
9849 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9850 g_type_query (derived_atk_type, &query);
9851 tinfo.class_size = query.class_size;
9852 tinfo.instance_size = query.instance_size;
9854 type = g_type_register_static (derived_atk_type,
9855 I_("GtkIconViewAccessible"),
9857 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9858 &atk_component_info);
9859 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9860 &atk_selection_info);
9866 gtk_icon_view_accessible_new (GObject *obj)
9868 AtkObject *accessible;
9870 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9872 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9873 atk_object_initialize (accessible, obj);
9879 gtk_icon_view_accessible_factory_get_accessible_type (void)
9881 return gtk_icon_view_accessible_get_type ();
9885 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9887 return gtk_icon_view_accessible_new (obj);
9891 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9893 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9894 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9898 gtk_icon_view_accessible_factory_get_type (void)
9900 static GType type = 0;
9904 const GTypeInfo tinfo =
9906 sizeof (AtkObjectFactoryClass),
9907 NULL, /* base_init */
9908 NULL, /* base_finalize */
9909 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9910 NULL, /* class_finalize */
9911 NULL, /* class_data */
9912 sizeof (AtkObjectFactory),
9913 0, /* n_preallocs */
9917 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9918 I_("GtkIconViewAccessibleFactory"),
9926 gtk_icon_view_get_accessible (GtkWidget *widget)
9928 static gboolean first_time = TRUE;
9932 AtkObjectFactory *factory;
9933 AtkRegistry *registry;
9935 GType derived_atk_type;
9938 * Figure out whether accessibility is enabled by looking at the
9939 * type of the accessible object which would be created for
9940 * the parent type of GtkIconView.
9942 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9944 registry = atk_get_default_registry ();
9945 factory = atk_registry_get_factory (registry,
9947 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9948 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9949 atk_registry_set_factory_type (registry,
9951 gtk_icon_view_accessible_factory_get_type ());
9954 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9958 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9959 GtkBuilder *builder,
9961 const gchar *tagname,
9962 GMarkupParser *parser,
9965 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9966 tagname, parser, data))
9969 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9970 tagname, parser, data);
9974 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9975 GtkBuilder *builder,
9977 const gchar *tagname,
9980 if (strcmp (tagname, "attributes") == 0)
9981 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9984 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,