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"
36 #include "gtksignal.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.h"
43 #include "gtktreednd.h"
44 #include "gtkprivate.h"
47 #undef DEBUG_ICON_VIEW
49 #define SCROLL_EDGE_SIZE 15
51 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
53 typedef struct _GtkIconViewItem GtkIconViewItem;
54 struct _GtkIconViewItem
62 gint x, y, width, height;
65 * box[i] is the actual area occupied by cell i,
66 * before, after are used to calculate the cell
67 * area relative to the box.
68 * See gtk_icon_view_get_cell_area().
76 guint selected_before_rubberbanding : 1;
80 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
81 struct _GtkIconViewCellInfo
83 GtkCellRenderer *cell;
93 GtkCellLayoutDataFunc func;
95 GDestroyNotify destroy;
98 typedef struct _GtkIconViewChild GtkIconViewChild;
99 struct _GtkIconViewChild
102 GtkIconViewItem *item;
106 struct _GtkIconViewPrivate
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gboolean doing_rubberband;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
162 GdkModifierType start_button_mask;
167 GtkTargetList *source_targets;
168 GdkDragAction source_actions;
170 GtkTargetList *dest_targets;
171 GdkDragAction dest_actions;
173 GtkTreeRowReference *dest_item;
174 GtkIconViewDropPosition dest_pos;
177 GtkTreeRowReference *scroll_to_path;
178 gfloat scroll_to_row_align;
179 gfloat scroll_to_col_align;
180 guint scroll_to_use_align : 1;
182 guint source_set : 1;
184 guint reorderable : 1;
185 guint empty_view_drop :1;
187 guint ctrl_pressed : 1;
188 guint shift_pressed : 1;
201 ACTIVATE_CURSOR_ITEM,
225 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
226 static void gtk_icon_view_finalize (GObject *object);
227 static void gtk_icon_view_set_property (GObject *object,
231 static void gtk_icon_view_get_property (GObject *object,
236 /* GtkObject vfuncs */
237 static void gtk_icon_view_destroy (GtkObject *object);
239 /* GtkWidget vfuncs */
240 static void gtk_icon_view_realize (GtkWidget *widget);
241 static void gtk_icon_view_unrealize (GtkWidget *widget);
242 static void gtk_icon_view_style_set (GtkWidget *widget,
243 GtkStyle *previous_style);
244 static void gtk_icon_view_state_changed (GtkWidget *widget,
245 GtkStateType previous_state);
246 static void gtk_icon_view_size_request (GtkWidget *widget,
247 GtkRequisition *requisition);
248 static void gtk_icon_view_size_allocate (GtkWidget *widget,
249 GtkAllocation *allocation);
250 static gboolean gtk_icon_view_expose (GtkWidget *widget,
251 GdkEventExpose *expose);
252 static gboolean gtk_icon_view_motion (GtkWidget *widget,
253 GdkEventMotion *event);
254 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
255 GdkEventButton *event);
256 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
257 GdkEventButton *event);
258 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
260 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
262 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
265 /* GtkContainer vfuncs */
266 static void gtk_icon_view_remove (GtkContainer *container,
268 static void gtk_icon_view_forall (GtkContainer *container,
269 gboolean include_internals,
270 GtkCallback callback,
271 gpointer callback_data);
273 /* GtkIconView vfuncs */
274 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
276 GtkAdjustment *vadj);
277 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
278 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
279 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
280 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
281 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
283 /* Internal functions */
284 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
285 GtkIconView *icon_view);
286 static void gtk_icon_view_layout (GtkIconView *icon_view);
287 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
290 GtkIconViewItem *item,
292 GdkDrawable *drawable,
295 gboolean draw_focus);
296 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
299 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
302 GtkIconViewItem *item);
303 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
304 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
305 GtkIconViewItem *item,
307 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
310 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
311 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
312 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
313 GtkIconViewItem *item,
318 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
319 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
320 GtkIconViewItem *item);
321 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
322 GtkIconViewItem *item,
324 static void gtk_icon_view_update_rubberband (gpointer data);
325 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
326 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
327 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
330 GtkMovementStep step,
332 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
333 GtkMovementStep step,
335 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
337 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
343 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
344 GtkIconViewItem *item);
345 static void gtk_icon_view_select_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
350 GtkIconViewItem *anchor,
351 GtkIconViewItem *cursor);
352 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
355 gboolean only_in_cell,
356 GtkIconViewCellInfo **cell_at_pos);
357 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
358 GtkIconViewItem *item,
359 GtkIconViewCellInfo *cell_info,
360 GdkRectangle *cell_area);
361 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
362 GtkIconViewItem *item,
363 GtkIconViewCellInfo *info,
365 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
366 GtkCellRenderer *renderer);
367 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
368 GtkIconViewItem *item);
369 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
370 GtkCellRenderer *renderer,
372 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
377 const gchar *attribute,
379 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
380 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
381 GtkCellRenderer *renderer);
382 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
383 GtkCellRenderer *cell,
384 GtkCellLayoutDataFunc func,
386 GDestroyNotify destroy);
387 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
388 GtkCellRenderer *cell,
390 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
392 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
393 GtkIconViewItem *item,
394 GtkIconViewCellInfo *cell_info,
396 static void gtk_icon_view_put (GtkIconView *icon_view,
398 GtkIconViewItem *item,
400 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
401 GtkIconView *icon_view);
402 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
403 GtkIconViewItem *item,
404 GtkIconViewCellInfo *cell_info,
406 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
407 gboolean cancel_editing);
409 /* Source side drag signals */
410 static void gtk_icon_view_drag_begin (GtkWidget *widget,
411 GdkDragContext *context);
412 static void gtk_icon_view_drag_end (GtkWidget *widget,
413 GdkDragContext *context);
414 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
415 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
420 GdkDragContext *context);
422 /* Target side drag signals */
423 static void gtk_icon_view_drag_leave (GtkWidget *widget,
424 GdkDragContext *context,
426 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
427 GdkDragContext *context,
431 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
432 GdkDragContext *context,
436 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
437 GdkDragContext *context,
440 GtkSelectionData *selection_data,
443 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
444 GdkEventMotion *event);
446 static void remove_scroll_timeout (GtkIconView *icon_view);
447 static void clear_dest_info (GtkIconView *icon_view);
448 static void clear_source_info (GtkIconView *icon_view);
450 static void adjust_wrap_width (GtkIconView *icon_view,
451 GtkIconViewItem *item);
454 static GtkBuildableIface *parent_buildable_iface;
455 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
456 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
459 const gchar *tagname,
460 GMarkupParser *parser,
462 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
465 const gchar *tagname,
468 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
470 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
471 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
472 gtk_icon_view_cell_layout_init)
473 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
474 gtk_icon_view_buildable_init))
477 gtk_icon_view_class_init (GtkIconViewClass *klass)
479 GObjectClass *gobject_class;
480 GtkObjectClass *object_class;
481 GtkWidgetClass *widget_class;
482 GtkContainerClass *container_class;
483 GtkBindingSet *binding_set;
485 binding_set = gtk_binding_set_by_class (klass);
487 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
489 gobject_class = (GObjectClass *) klass;
490 object_class = (GtkObjectClass *) klass;
491 widget_class = (GtkWidgetClass *) klass;
492 container_class = (GtkContainerClass *) klass;
494 gobject_class->finalize = gtk_icon_view_finalize;
495 gobject_class->set_property = gtk_icon_view_set_property;
496 gobject_class->get_property = gtk_icon_view_get_property;
498 object_class->destroy = gtk_icon_view_destroy;
500 widget_class->realize = gtk_icon_view_realize;
501 widget_class->unrealize = gtk_icon_view_unrealize;
502 widget_class->style_set = gtk_icon_view_style_set;
503 widget_class->get_accessible = gtk_icon_view_get_accessible;
504 widget_class->size_request = gtk_icon_view_size_request;
505 widget_class->size_allocate = gtk_icon_view_size_allocate;
506 widget_class->expose_event = gtk_icon_view_expose;
507 widget_class->motion_notify_event = gtk_icon_view_motion;
508 widget_class->button_press_event = gtk_icon_view_button_press;
509 widget_class->button_release_event = gtk_icon_view_button_release;
510 widget_class->key_press_event = gtk_icon_view_key_press;
511 widget_class->key_release_event = gtk_icon_view_key_release;
512 widget_class->drag_begin = gtk_icon_view_drag_begin;
513 widget_class->drag_end = gtk_icon_view_drag_end;
514 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
515 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
516 widget_class->drag_leave = gtk_icon_view_drag_leave;
517 widget_class->drag_motion = gtk_icon_view_drag_motion;
518 widget_class->drag_drop = gtk_icon_view_drag_drop;
519 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
520 widget_class->state_changed = gtk_icon_view_state_changed;
522 container_class->remove = gtk_icon_view_remove;
523 container_class->forall = gtk_icon_view_forall;
525 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
526 klass->select_all = gtk_icon_view_real_select_all;
527 klass->unselect_all = gtk_icon_view_real_unselect_all;
528 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
529 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
530 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
531 klass->move_cursor = gtk_icon_view_real_move_cursor;
535 * GtkIconView:selection-mode:
537 * The ::selection-mode property specifies the selection mode of
538 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
539 * is enabled, for the other modes, only keyboard selection is possible.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_enum ("selection-mode",
546 P_("Selection mode"),
547 P_("The selection mode"),
548 GTK_TYPE_SELECTION_MODE,
549 GTK_SELECTION_SINGLE,
550 GTK_PARAM_READWRITE));
553 * GtkIconView:pixbuf-column:
555 * The ::pixbuf-column property contains the number of the model column
556 * containing the pixbufs which are displayed. The pixbuf column must be
557 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
558 * display of pixbufs.
562 g_object_class_install_property (gobject_class,
564 g_param_spec_int ("pixbuf-column",
566 P_("Model column used to retrieve the icon pixbuf from"),
568 GTK_PARAM_READWRITE));
571 * GtkIconView:text-column:
573 * The ::text-column property contains the number of the model column
574 * containing the texts which are displayed. The text column must be
575 * of type #G_TYPE_STRING. If this property and the :markup-column
576 * property are both set to -1, no texts are displayed.
580 g_object_class_install_property (gobject_class,
582 g_param_spec_int ("text-column",
584 P_("Model column used to retrieve the text from"),
586 GTK_PARAM_READWRITE));
590 * GtkIconView:markup-column:
592 * The ::markup-column property contains the number of the model column
593 * containing markup information to be displayed. The markup column must be
594 * of type #G_TYPE_STRING. If this property and the :text-column property
595 * are both set to column numbers, it overrides the text column.
596 * If both are set to -1, no texts are displayed.
600 g_object_class_install_property (gobject_class,
602 g_param_spec_int ("markup-column",
604 P_("Model column used to retrieve the text if using Pango markup"),
606 GTK_PARAM_READWRITE));
608 g_object_class_install_property (gobject_class,
610 g_param_spec_object ("model",
611 P_("Icon View Model"),
612 P_("The model for the icon view"),
614 GTK_PARAM_READWRITE));
617 * GtkIconView:columns:
619 * The columns property contains the number of the columns in which the
620 * items should be displayed. If it is -1, the number of columns will
621 * be chosen automatically to fill the available area.
625 g_object_class_install_property (gobject_class,
627 g_param_spec_int ("columns",
628 P_("Number of columns"),
629 P_("Number of columns to display"),
631 GTK_PARAM_READWRITE));
635 * GtkIconView:item-width:
637 * The item-width property specifies the width to use for each item.
638 * If it is set to -1, the icon view will automatically determine a
639 * suitable item size.
643 g_object_class_install_property (gobject_class,
645 g_param_spec_int ("item-width",
646 P_("Width for each item"),
647 P_("The width used for each item"),
649 GTK_PARAM_READWRITE));
652 * GtkIconView:spacing:
654 * The spacing property specifies the space which is inserted between
655 * the cells (i.e. the icon and the text) of an item.
659 g_object_class_install_property (gobject_class,
661 g_param_spec_int ("spacing",
663 P_("Space which is inserted between cells of an item"),
665 GTK_PARAM_READWRITE));
668 * GtkIconView:row-spacing:
670 * The row-spacing property specifies the space which is inserted between
671 * the rows of the icon view.
675 g_object_class_install_property (gobject_class,
677 g_param_spec_int ("row-spacing",
679 P_("Space which is inserted between grid rows"),
681 GTK_PARAM_READWRITE));
684 * GtkIconView:column-spacing:
686 * The column-spacing property specifies the space which is inserted between
687 * the columns of the icon view.
691 g_object_class_install_property (gobject_class,
693 g_param_spec_int ("column-spacing",
694 P_("Column Spacing"),
695 P_("Space which is inserted between grid columns"),
697 GTK_PARAM_READWRITE));
700 * GtkIconView:margin:
702 * The margin property specifies the space which is inserted
703 * at the edges of the icon view.
707 g_object_class_install_property (gobject_class,
709 g_param_spec_int ("margin",
711 P_("Space which is inserted at the edges of the icon view"),
713 GTK_PARAM_READWRITE));
717 * GtkIconView:orientation:
719 * The orientation property specifies how the cells (i.e. the icon and
720 * the text) of the item are positioned relative to each other.
724 g_object_class_install_property (gobject_class,
726 g_param_spec_enum ("orientation",
728 P_("How the text and icon of each item are positioned relative to each other"),
729 GTK_TYPE_ORIENTATION,
730 GTK_ORIENTATION_VERTICAL,
731 GTK_PARAM_READWRITE));
734 * GtkIconView:reorderable:
736 * The reorderable property specifies if the items can be reordered
741 g_object_class_install_property (gobject_class,
743 g_param_spec_boolean ("reorderable",
745 P_("View is reorderable"),
749 /* Style properties */
750 gtk_widget_class_install_style_property (widget_class,
751 g_param_spec_boxed ("selection-box-color",
752 P_("Selection Box Color"),
753 P_("Color of the selection box"),
755 GTK_PARAM_READABLE));
757 gtk_widget_class_install_style_property (widget_class,
758 g_param_spec_uchar ("selection-box-alpha",
759 P_("Selection Box Alpha"),
760 P_("Opacity of the selection box"),
763 GTK_PARAM_READABLE));
766 widget_class->set_scroll_adjustments_signal =
767 g_signal_new (I_("set_scroll_adjustments"),
768 G_TYPE_FROM_CLASS (gobject_class),
770 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
772 _gtk_marshal_VOID__OBJECT_OBJECT,
774 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
776 icon_view_signals[ITEM_ACTIVATED] =
777 g_signal_new (I_("item_activated"),
778 G_TYPE_FROM_CLASS (gobject_class),
780 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
782 g_cclosure_marshal_VOID__BOXED,
786 icon_view_signals[SELECTION_CHANGED] =
787 g_signal_new (I_("selection-changed"),
788 G_TYPE_FROM_CLASS (gobject_class),
790 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
792 g_cclosure_marshal_VOID__VOID,
795 icon_view_signals[SELECT_ALL] =
796 g_signal_new (I_("select_all"),
797 G_TYPE_FROM_CLASS (gobject_class),
798 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
799 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
801 g_cclosure_marshal_VOID__VOID,
804 icon_view_signals[UNSELECT_ALL] =
805 g_signal_new (I_("unselect_all"),
806 G_TYPE_FROM_CLASS (gobject_class),
807 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
808 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
810 g_cclosure_marshal_VOID__VOID,
813 icon_view_signals[SELECT_CURSOR_ITEM] =
814 g_signal_new (I_("select_cursor_item"),
815 G_TYPE_FROM_CLASS (gobject_class),
816 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
817 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
819 g_cclosure_marshal_VOID__VOID,
822 icon_view_signals[TOGGLE_CURSOR_ITEM] =
823 g_signal_new (I_("toggle_cursor_item"),
824 G_TYPE_FROM_CLASS (gobject_class),
825 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
826 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
828 g_cclosure_marshal_VOID__VOID,
831 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
832 g_signal_new (I_("activate_cursor_item"),
833 G_TYPE_FROM_CLASS (gobject_class),
834 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
835 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
837 _gtk_marshal_BOOLEAN__VOID,
840 icon_view_signals[MOVE_CURSOR] =
841 g_signal_new (I_("move_cursor"),
842 G_TYPE_FROM_CLASS (gobject_class),
843 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
844 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
846 _gtk_marshal_BOOLEAN__ENUM_INT,
848 GTK_TYPE_MOVEMENT_STEP,
852 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
854 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
856 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
857 "toggle_cursor_item", 0);
859 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
860 "activate_cursor_item", 0);
861 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
862 "activate_cursor_item", 0);
863 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
864 "activate_cursor_item", 0);
865 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
866 "activate_cursor_item", 0);
868 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
869 GTK_MOVEMENT_DISPLAY_LINES, -1);
870 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
871 GTK_MOVEMENT_DISPLAY_LINES, -1);
873 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
874 GTK_MOVEMENT_DISPLAY_LINES, 1);
875 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
876 GTK_MOVEMENT_DISPLAY_LINES, 1);
878 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
879 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
882 GTK_MOVEMENT_DISPLAY_LINES, 1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
885 GTK_MOVEMENT_BUFFER_ENDS, -1);
886 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
887 GTK_MOVEMENT_BUFFER_ENDS, -1);
889 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
890 GTK_MOVEMENT_BUFFER_ENDS, 1);
891 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
892 GTK_MOVEMENT_BUFFER_ENDS, 1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
895 GTK_MOVEMENT_PAGES, -1);
896 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
897 GTK_MOVEMENT_PAGES, -1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
900 GTK_MOVEMENT_PAGES, 1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
902 GTK_MOVEMENT_PAGES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
905 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
906 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
907 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
910 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
912 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
916 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
918 parent_buildable_iface = g_type_interface_peek_parent (iface);
919 iface->add_child = _gtk_cell_layout_buildable_add_child;
920 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
921 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
925 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
927 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
928 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
929 iface->clear = gtk_icon_view_cell_layout_clear;
930 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
931 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
932 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
933 iface->reorder = gtk_icon_view_cell_layout_reorder;
934 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
938 gtk_icon_view_init (GtkIconView *icon_view)
940 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
942 icon_view->priv->width = 0;
943 icon_view->priv->height = 0;
944 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
945 icon_view->priv->pressed_button = -1;
946 icon_view->priv->press_start_x = -1;
947 icon_view->priv->press_start_y = -1;
948 icon_view->priv->text_column = -1;
949 icon_view->priv->markup_column = -1;
950 icon_view->priv->pixbuf_column = -1;
951 icon_view->priv->text_cell = -1;
952 icon_view->priv->pixbuf_cell = -1;
954 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
956 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
958 icon_view->priv->cell_list = NULL;
959 icon_view->priv->n_cells = 0;
960 icon_view->priv->cursor_cell = -1;
962 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
964 icon_view->priv->columns = -1;
965 icon_view->priv->item_width = -1;
966 icon_view->priv->spacing = 0;
967 icon_view->priv->row_spacing = 6;
968 icon_view->priv->column_spacing = 6;
969 icon_view->priv->margin = 6;
973 gtk_icon_view_destroy (GtkObject *object)
975 GtkIconView *icon_view;
977 icon_view = GTK_ICON_VIEW (object);
979 gtk_icon_view_stop_editing (icon_view, TRUE);
981 gtk_icon_view_set_model (icon_view, NULL);
983 if (icon_view->priv->layout_idle_id != 0)
985 g_source_remove (icon_view->priv->layout_idle_id);
986 icon_view->priv->layout_idle_id = 0;
989 if (icon_view->priv->scroll_to_path != NULL)
991 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
992 icon_view->priv->scroll_to_path = NULL;
995 remove_scroll_timeout (icon_view);
997 if (icon_view->priv->hadjustment != NULL)
999 g_object_unref (icon_view->priv->hadjustment);
1000 icon_view->priv->hadjustment = NULL;
1003 if (icon_view->priv->vadjustment != NULL)
1005 g_object_unref (icon_view->priv->vadjustment);
1006 icon_view->priv->vadjustment = NULL;
1009 clear_dest_info (icon_view);
1010 clear_source_info (icon_view);
1012 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1015 /* GObject methods */
1017 gtk_icon_view_finalize (GObject *object)
1019 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1021 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1026 gtk_icon_view_set_property (GObject *object,
1028 const GValue *value,
1031 GtkIconView *icon_view;
1033 icon_view = GTK_ICON_VIEW (object);
1037 case PROP_SELECTION_MODE:
1038 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1040 case PROP_PIXBUF_COLUMN:
1041 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1043 case PROP_TEXT_COLUMN:
1044 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1046 case PROP_MARKUP_COLUMN:
1047 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1050 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1052 case PROP_ORIENTATION:
1053 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1056 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1058 case PROP_ITEM_WIDTH:
1059 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1062 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1064 case PROP_ROW_SPACING:
1065 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1067 case PROP_COLUMN_SPACING:
1068 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1071 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1073 case PROP_REORDERABLE:
1074 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1078 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1084 gtk_icon_view_get_property (GObject *object,
1089 GtkIconView *icon_view;
1091 icon_view = GTK_ICON_VIEW (object);
1095 case PROP_SELECTION_MODE:
1096 g_value_set_enum (value, icon_view->priv->selection_mode);
1098 case PROP_PIXBUF_COLUMN:
1099 g_value_set_int (value, icon_view->priv->pixbuf_column);
1101 case PROP_TEXT_COLUMN:
1102 g_value_set_int (value, icon_view->priv->text_column);
1104 case PROP_MARKUP_COLUMN:
1105 g_value_set_int (value, icon_view->priv->markup_column);
1108 g_value_set_object (value, icon_view->priv->model);
1110 case PROP_ORIENTATION:
1111 g_value_set_enum (value, icon_view->priv->orientation);
1114 g_value_set_int (value, icon_view->priv->columns);
1116 case PROP_ITEM_WIDTH:
1117 g_value_set_int (value, icon_view->priv->item_width);
1120 g_value_set_int (value, icon_view->priv->spacing);
1122 case PROP_ROW_SPACING:
1123 g_value_set_int (value, icon_view->priv->row_spacing);
1125 case PROP_COLUMN_SPACING:
1126 g_value_set_int (value, icon_view->priv->column_spacing);
1129 g_value_set_int (value, icon_view->priv->margin);
1131 case PROP_REORDERABLE:
1132 g_value_set_boolean (value, icon_view->priv->reorderable);
1136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1141 /* GtkWidget signals */
1143 gtk_icon_view_realize (GtkWidget *widget)
1145 GtkIconView *icon_view;
1146 GdkWindowAttr attributes;
1147 gint attributes_mask;
1149 icon_view = GTK_ICON_VIEW (widget);
1151 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1153 /* Make the main, clipping window */
1154 attributes.window_type = GDK_WINDOW_CHILD;
1155 attributes.x = widget->allocation.x;
1156 attributes.y = widget->allocation.y;
1157 attributes.width = widget->allocation.width;
1158 attributes.height = widget->allocation.height;
1159 attributes.wclass = GDK_INPUT_OUTPUT;
1160 attributes.visual = gtk_widget_get_visual (widget);
1161 attributes.colormap = gtk_widget_get_colormap (widget);
1162 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1164 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1166 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1167 &attributes, attributes_mask);
1168 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1169 gdk_window_set_user_data (widget->window, widget);
1171 /* Make the window for the icon view */
1174 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1175 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1176 attributes.event_mask = (GDK_EXPOSURE_MASK |
1178 GDK_POINTER_MOTION_MASK |
1179 GDK_BUTTON_PRESS_MASK |
1180 GDK_BUTTON_RELEASE_MASK |
1181 GDK_KEY_PRESS_MASK |
1182 GDK_KEY_RELEASE_MASK) |
1183 gtk_widget_get_events (widget);
1185 icon_view->priv->bin_window = gdk_window_new (widget->window,
1186 &attributes, attributes_mask);
1187 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1189 widget->style = gtk_style_attach (widget->style, widget->window);
1190 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1192 gdk_window_show (icon_view->priv->bin_window);
1196 gtk_icon_view_unrealize (GtkWidget *widget)
1198 GtkIconView *icon_view;
1200 icon_view = GTK_ICON_VIEW (widget);
1202 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1203 gdk_window_destroy (icon_view->priv->bin_window);
1204 icon_view->priv->bin_window = NULL;
1206 /* GtkWidget::unrealize destroys children and widget->window */
1207 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1208 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1212 gtk_icon_view_state_changed (GtkWidget *widget,
1213 GtkStateType previous_state)
1215 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1217 if (GTK_WIDGET_REALIZED (widget))
1219 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1220 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1223 gtk_widget_queue_draw (widget);
1227 gtk_icon_view_style_set (GtkWidget *widget,
1228 GtkStyle *previous_style)
1230 GtkIconView *icon_view;
1232 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1234 icon_view = GTK_ICON_VIEW (widget);
1236 if (GTK_WIDGET_REALIZED (widget))
1238 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1239 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1242 gtk_widget_queue_resize (widget);
1246 gtk_icon_view_size_request (GtkWidget *widget,
1247 GtkRequisition *requisition)
1249 GtkIconView *icon_view;
1252 icon_view = GTK_ICON_VIEW (widget);
1254 requisition->width = icon_view->priv->width;
1255 requisition->height = icon_view->priv->height;
1257 tmp_list = icon_view->priv->children;
1261 GtkIconViewChild *child = tmp_list->data;
1262 GtkRequisition child_requisition;
1264 tmp_list = tmp_list->next;
1266 if (GTK_WIDGET_VISIBLE (child->widget))
1267 gtk_widget_size_request (child->widget, &child_requisition);
1272 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1276 for (list = icon_view->priv->children; list; list = list->next)
1278 GtkIconViewChild *child = list->data;
1279 GtkAllocation allocation;
1281 /* totally ignore our child's requisition */
1282 if (child->cell < 0)
1284 allocation.x = child->item->x;
1285 allocation.y = child->item->y;
1286 allocation.width = child->item->width;
1287 allocation.height = child->item->height;
1291 GdkRectangle *box = &child->item->box[child->cell];
1293 allocation.x = box->x;
1294 allocation.y = box->y;
1295 allocation.width = box->width;
1296 allocation.height = box->height;
1299 gtk_widget_size_allocate (child->widget, &allocation);
1304 gtk_icon_view_size_allocate (GtkWidget *widget,
1305 GtkAllocation *allocation)
1307 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1309 GtkAdjustment *hadjustment, *vadjustment;
1311 widget->allocation = *allocation;
1313 if (GTK_WIDGET_REALIZED (widget))
1315 gdk_window_move_resize (widget->window,
1316 allocation->x, allocation->y,
1317 allocation->width, allocation->height);
1318 gdk_window_resize (icon_view->priv->bin_window,
1319 MAX (icon_view->priv->width, allocation->width),
1320 MAX (icon_view->priv->height, allocation->height));
1323 gtk_icon_view_layout (icon_view);
1325 gtk_icon_view_allocate_children (icon_view);
1327 hadjustment = icon_view->priv->hadjustment;
1328 vadjustment = icon_view->priv->vadjustment;
1330 hadjustment->page_size = allocation->width;
1331 hadjustment->page_increment = allocation->width * 0.9;
1332 hadjustment->step_increment = allocation->width * 0.1;
1333 hadjustment->lower = 0;
1334 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1336 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1337 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1339 vadjustment->page_size = allocation->height;
1340 vadjustment->page_increment = allocation->height * 0.9;
1341 vadjustment->step_increment = allocation->height * 0.1;
1342 vadjustment->lower = 0;
1343 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1345 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1346 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1348 if (GTK_WIDGET_REALIZED (widget) &&
1349 icon_view->priv->scroll_to_path)
1352 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1353 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1354 icon_view->priv->scroll_to_path = NULL;
1356 gtk_icon_view_scroll_to_path (icon_view, path,
1357 icon_view->priv->scroll_to_use_align,
1358 icon_view->priv->scroll_to_row_align,
1359 icon_view->priv->scroll_to_col_align);
1360 gtk_tree_path_free (path);
1364 gtk_adjustment_changed (hadjustment);
1365 gtk_adjustment_changed (vadjustment);
1370 gtk_icon_view_expose (GtkWidget *widget,
1371 GdkEventExpose *expose)
1373 GtkIconView *icon_view;
1378 GtkIconViewDropPosition dest_pos;
1379 GtkIconViewItem *dest_item = NULL;
1381 icon_view = GTK_ICON_VIEW (widget);
1383 if (expose->window != icon_view->priv->bin_window)
1386 cr = gdk_cairo_create (icon_view->priv->bin_window);
1387 cairo_set_line_width (cr, 1.);
1389 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1393 dest_index = gtk_tree_path_get_indices (path)[0];
1394 gtk_tree_path_free (path);
1399 for (icons = icon_view->priv->items; icons; icons = icons->next)
1401 GtkIconViewItem *item = icons->data;
1406 area.width = item->width;
1407 area.height = item->height;
1409 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1412 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1413 icon_view->priv->bin_window,
1414 item->x, item->y, TRUE);
1416 if (dest_index == item->index)
1424 case GTK_ICON_VIEW_DROP_INTO:
1425 gtk_paint_focus (widget->style,
1426 icon_view->priv->bin_window,
1427 GTK_WIDGET_STATE (widget),
1430 "iconview-drop-indicator",
1431 dest_item->x, dest_item->y,
1432 dest_item->width, dest_item->height);
1434 case GTK_ICON_VIEW_DROP_ABOVE:
1435 gtk_paint_focus (widget->style,
1436 icon_view->priv->bin_window,
1437 GTK_WIDGET_STATE (widget),
1440 "iconview-drop-indicator",
1441 dest_item->x, dest_item->y - 1,
1442 dest_item->width, 2);
1444 case GTK_ICON_VIEW_DROP_LEFT:
1445 gtk_paint_focus (widget->style,
1446 icon_view->priv->bin_window,
1447 GTK_WIDGET_STATE (widget),
1450 "iconview-drop-indicator",
1451 dest_item->x - 1, dest_item->y,
1452 2, dest_item->height);
1454 case GTK_ICON_VIEW_DROP_BELOW:
1455 gtk_paint_focus (widget->style,
1456 icon_view->priv->bin_window,
1457 GTK_WIDGET_STATE (widget),
1460 "iconview-drop-indicator",
1461 dest_item->x, dest_item->y + dest_item->height - 1,
1462 dest_item->width, 2);
1464 case GTK_ICON_VIEW_DROP_RIGHT:
1465 gtk_paint_focus (widget->style,
1466 icon_view->priv->bin_window,
1467 GTK_WIDGET_STATE (widget),
1470 "iconview-drop-indicator",
1471 dest_item->x + dest_item->width - 1, dest_item->y,
1472 2, dest_item->height);
1473 case GTK_ICON_VIEW_NO_DROP: ;
1478 if (icon_view->priv->doing_rubberband)
1480 GdkRectangle *rectangles;
1483 gdk_region_get_rectangles (expose->region,
1487 while (n_rectangles--)
1488 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1490 g_free (rectangles);
1495 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1501 rubberband_scroll_timeout (gpointer data)
1503 GtkIconView *icon_view;
1508 value = MIN (icon_view->priv->vadjustment->value +
1509 icon_view->priv->scroll_value_diff,
1510 icon_view->priv->vadjustment->upper -
1511 icon_view->priv->vadjustment->page_size);
1513 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1515 gtk_icon_view_update_rubberband (icon_view);
1521 gtk_icon_view_motion (GtkWidget *widget,
1522 GdkEventMotion *event)
1524 GtkIconView *icon_view;
1527 icon_view = GTK_ICON_VIEW (widget);
1529 gtk_icon_view_maybe_begin_drag (icon_view, event);
1531 if (icon_view->priv->doing_rubberband)
1533 gtk_icon_view_update_rubberband (widget);
1535 abs_y = event->y - icon_view->priv->height *
1536 (icon_view->priv->vadjustment->value /
1537 (icon_view->priv->vadjustment->upper -
1538 icon_view->priv->vadjustment->lower));
1540 if (abs_y < 0 || abs_y > widget->allocation.height)
1543 icon_view->priv->scroll_value_diff = abs_y;
1545 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1547 icon_view->priv->event_last_x = event->x;
1548 icon_view->priv->event_last_y = event->y;
1550 if (icon_view->priv->scroll_timeout_id == 0)
1551 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1555 remove_scroll_timeout (icon_view);
1562 gtk_icon_view_remove (GtkContainer *container,
1565 GtkIconView *icon_view;
1566 GtkIconViewChild *child = NULL;
1569 icon_view = GTK_ICON_VIEW (container);
1571 tmp_list = icon_view->priv->children;
1574 child = tmp_list->data;
1575 if (child->widget == widget)
1577 gtk_widget_unparent (widget);
1579 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1580 g_list_free_1 (tmp_list);
1585 tmp_list = tmp_list->next;
1590 gtk_icon_view_forall (GtkContainer *container,
1591 gboolean include_internals,
1592 GtkCallback callback,
1593 gpointer callback_data)
1595 GtkIconView *icon_view;
1596 GtkIconViewChild *child = NULL;
1599 icon_view = GTK_ICON_VIEW (container);
1601 tmp_list = icon_view->priv->children;
1604 child = tmp_list->data;
1605 tmp_list = tmp_list->next;
1607 (* callback) (child->widget, callback_data);
1612 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1613 GtkIconViewItem *item,
1614 GtkIconViewCellInfo *info,
1619 GdkRectangle cell_area;
1620 gboolean visible, mode;
1622 gtk_icon_view_set_cell_data (icon_view, item);
1624 g_object_get (info->cell,
1625 "visible", &visible,
1629 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1631 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1633 path = gtk_tree_path_new_from_indices (item->index, -1);
1634 path_string = gtk_tree_path_to_string (path);
1635 gtk_tree_path_free (path);
1637 gtk_cell_renderer_activate (info->cell,
1639 GTK_WIDGET (icon_view),
1645 g_free (path_string);
1650 gtk_icon_view_put (GtkIconView *icon_view,
1652 GtkIconViewItem *item,
1655 GtkIconViewChild *child;
1657 child = g_new (GtkIconViewChild, 1);
1659 child->widget = widget;
1663 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1665 if (GTK_WIDGET_REALIZED (icon_view))
1666 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1668 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1672 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1673 GtkIconView *icon_view)
1676 GtkIconViewItem *item;
1678 if (icon_view->priv->edited_item == NULL)
1681 item = icon_view->priv->edited_item;
1682 icon_view->priv->edited_item = NULL;
1683 icon_view->priv->editable = NULL;
1684 for (l = icon_view->priv->cell_list; l; l = l->next)
1686 GtkIconViewCellInfo *info = l->data;
1688 info->editing = FALSE;
1691 if (GTK_WIDGET_HAS_FOCUS (editable))
1692 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1694 g_signal_handlers_disconnect_by_func (editable,
1695 gtk_icon_view_remove_widget,
1698 gtk_container_remove (GTK_CONTAINER (icon_view),
1699 GTK_WIDGET (editable));
1701 gtk_icon_view_queue_draw_item (icon_view, item);
1706 gtk_icon_view_start_editing (GtkIconView *icon_view,
1707 GtkIconViewItem *item,
1708 GtkIconViewCellInfo *info,
1713 GdkRectangle cell_area;
1714 gboolean visible, mode;
1715 GtkCellEditable *editable;
1717 gtk_icon_view_set_cell_data (icon_view, item);
1719 g_object_get (info->cell,
1720 "visible", &visible,
1723 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1725 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1727 path = gtk_tree_path_new_from_indices (item->index, -1);
1728 path_string = gtk_tree_path_to_string (path);
1729 gtk_tree_path_free (path);
1731 editable = gtk_cell_renderer_start_editing (info->cell,
1733 GTK_WIDGET (icon_view),
1738 g_free (path_string);
1740 /* FIXME ugly special case */
1741 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1742 g_object_set (editable, "has-frame", TRUE, NULL);
1744 /* the rest corresponds to tree_view_real_start_editing... */
1745 icon_view->priv->edited_item = item;
1746 icon_view->priv->editable = editable;
1747 info->editing = TRUE;
1749 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1751 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1753 gtk_widget_grab_focus (GTK_WIDGET (editable));
1754 g_signal_connect (editable, "remove_widget",
1755 G_CALLBACK (gtk_icon_view_remove_widget),
1762 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1763 gboolean cancel_editing)
1765 GtkCellRenderer *cell = NULL;
1766 GtkIconViewItem *item;
1769 if (icon_view->priv->edited_item == NULL)
1773 * This is very evil. We need to do this, because
1774 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1775 * later on. If gtk_icon_view_row_changed notices
1776 * icon_view->priv->edited_item != NULL, it'll call
1777 * gtk_icon_view_stop_editing again. Bad things will happen then.
1779 * Please read that again if you intend to modify anything here.
1782 item = icon_view->priv->edited_item;
1783 icon_view->priv->edited_item = NULL;
1785 for (l = icon_view->priv->cell_list; l; l = l->next)
1787 GtkIconViewCellInfo *info = l->data;
1799 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1800 if (!cancel_editing)
1801 gtk_cell_editable_editing_done (icon_view->priv->editable);
1803 icon_view->priv->edited_item = item;
1805 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1809 * gtk_icon_view_set_cursor:
1810 * @icon_view: A #GtkIconView
1811 * @path: A #GtkTreePath
1812 * @cell: One of the cell renderers of @icon_view, or %NULL
1813 * @start_editing: %TRUE if the specified cell should start being edited.
1815 * Sets the current keyboard focus to be at @path, and selects it. This is
1816 * useful when you want to focus the user's attention on a particular item.
1817 * If @cell is not %NULL, then focus is given to the cell specified by
1818 * it. Additionally, if @start_editing is %TRUE, then editing should be
1819 * started in the specified cell.
1821 * This function is often followed by <literal>gtk_widget_grab_focus
1822 * (icon_view)</literal> in order to give keyboard focus to the widget.
1823 * Please note that editing can only happen when the widget is realized.
1828 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1830 GtkCellRenderer *cell,
1831 gboolean start_editing)
1833 GtkIconViewItem *item = NULL;
1834 GtkIconViewCellInfo *info = NULL;
1838 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1839 g_return_if_fail (path != NULL);
1840 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1842 gtk_icon_view_stop_editing (icon_view, TRUE);
1844 if (gtk_tree_path_get_depth (path) == 1)
1845 item = g_list_nth_data (icon_view->priv->items,
1846 gtk_tree_path_get_indices(path)[0]);
1852 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1856 if (info->cell == cell)
1865 g_return_if_fail (cell == NULL || info != NULL);
1867 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1868 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1870 if (info && start_editing)
1871 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1875 * gtk_icon_view_get_cursor:
1876 * @icon_view: A #GtkIconView
1877 * @path: Return location for the current cursor path, or %NULL
1878 * @cell: Return location the current focus cell, or %NULL
1880 * Fills in @path and @cell with the current cursor path and cell.
1881 * If the cursor isn't currently set, then *@path will be %NULL.
1882 * If no cell currently has focus, then *@cell will be %NULL.
1884 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1886 * Return value: %TRUE if the cursor is set.
1891 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1893 GtkCellRenderer **cell)
1895 GtkIconViewItem *item;
1896 GtkIconViewCellInfo *info;
1898 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1900 item = icon_view->priv->cursor_item;
1901 if (icon_view->priv->cursor_cell < 0)
1904 info = g_list_nth_data (icon_view->priv->cell_list,
1905 icon_view->priv->cursor_cell);
1910 *path = gtk_tree_path_new_from_indices (item->index, -1);
1923 return (item != NULL);
1927 gtk_icon_view_button_press (GtkWidget *widget,
1928 GdkEventButton *event)
1930 GtkIconView *icon_view;
1931 GtkIconViewItem *item;
1932 GtkIconViewCellInfo *info = NULL;
1933 gboolean dirty = FALSE;
1934 GtkCellRendererMode mode;
1937 icon_view = GTK_ICON_VIEW (widget);
1939 if (event->window != icon_view->priv->bin_window)
1942 if (!GTK_WIDGET_HAS_FOCUS (widget))
1943 gtk_widget_grab_focus (widget);
1945 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1947 item = gtk_icon_view_get_item_at_coords (icon_view,
1953 g_object_get (info->cell, "mode", &mode, NULL);
1955 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1956 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1957 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1961 gtk_icon_view_scroll_to_item (icon_view, item);
1963 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1965 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1967 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1968 (event->state & GDK_SHIFT_MASK))
1970 gtk_icon_view_unselect_all_internal (icon_view);
1972 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1973 if (!icon_view->priv->anchor_item)
1974 icon_view->priv->anchor_item = item;
1976 gtk_icon_view_select_all_between (icon_view,
1977 icon_view->priv->anchor_item,
1983 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1984 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1985 (event->state & GDK_CONTROL_MASK))
1987 item->selected = !item->selected;
1988 gtk_icon_view_queue_draw_item (icon_view, item);
1993 if (!item->selected)
1995 gtk_icon_view_unselect_all_internal (icon_view);
1997 item->selected = TRUE;
1998 gtk_icon_view_queue_draw_item (icon_view, item);
2002 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2003 icon_view->priv->anchor_item = item;
2006 /* Save press to possibly begin a drag */
2007 if (icon_view->priv->pressed_button < 0)
2009 icon_view->priv->pressed_button = event->button;
2010 icon_view->priv->press_start_x = event->x;
2011 icon_view->priv->press_start_y = event->y;
2014 if (!icon_view->priv->last_single_clicked)
2015 icon_view->priv->last_single_clicked = item;
2017 /* cancel the current editing, if it exists */
2018 gtk_icon_view_stop_editing (icon_view, TRUE);
2020 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2021 gtk_icon_view_item_activate_cell (icon_view, item, info,
2023 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2024 gtk_icon_view_start_editing (icon_view, item, info,
2029 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2030 !(event->state & GDK_CONTROL_MASK))
2032 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2035 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2036 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2041 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2043 item = gtk_icon_view_get_item_at_coords (icon_view,
2048 if (item && item == icon_view->priv->last_single_clicked)
2052 path = gtk_tree_path_new_from_indices (item->index, -1);
2053 gtk_icon_view_item_activated (icon_view, path);
2054 gtk_tree_path_free (path);
2057 icon_view->priv->last_single_clicked = NULL;
2058 icon_view->priv->pressed_button = -1;
2062 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2064 return event->button == 1;
2068 gtk_icon_view_button_release (GtkWidget *widget,
2069 GdkEventButton *event)
2071 GtkIconView *icon_view;
2073 icon_view = GTK_ICON_VIEW (widget);
2075 if (icon_view->priv->pressed_button == event->button)
2076 icon_view->priv->pressed_button = -1;
2078 gtk_icon_view_stop_rubberbanding (icon_view);
2080 remove_scroll_timeout (icon_view);
2086 gtk_icon_view_key_press (GtkWidget *widget,
2089 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2091 if (icon_view->priv->doing_rubberband)
2093 if (event->keyval == GDK_Escape)
2094 gtk_icon_view_stop_rubberbanding (icon_view);
2099 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2103 gtk_icon_view_key_release (GtkWidget *widget,
2106 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2108 if (icon_view->priv->doing_rubberband)
2111 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2115 gtk_icon_view_update_rubberband (gpointer data)
2117 GtkIconView *icon_view;
2119 GdkRectangle old_area;
2120 GdkRectangle new_area;
2121 GdkRectangle common;
2122 GdkRegion *invalid_region;
2124 icon_view = GTK_ICON_VIEW (data);
2126 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2131 old_area.x = MIN (icon_view->priv->rubberband_x1,
2132 icon_view->priv->rubberband_x2);
2133 old_area.y = MIN (icon_view->priv->rubberband_y1,
2134 icon_view->priv->rubberband_y2);
2135 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2136 icon_view->priv->rubberband_x1) + 1;
2137 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2138 icon_view->priv->rubberband_y1) + 1;
2140 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2141 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2142 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2143 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2145 invalid_region = gdk_region_rectangle (&old_area);
2146 gdk_region_union_with_rect (invalid_region, &new_area);
2148 gdk_rectangle_intersect (&old_area, &new_area, &common);
2149 if (common.width > 2 && common.height > 2)
2151 GdkRegion *common_region;
2153 /* make sure the border is invalidated */
2159 common_region = gdk_region_rectangle (&common);
2161 gdk_region_subtract (invalid_region, common_region);
2162 gdk_region_destroy (common_region);
2165 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2167 gdk_region_destroy (invalid_region);
2169 icon_view->priv->rubberband_x2 = x;
2170 icon_view->priv->rubberband_y2 = y;
2172 gtk_icon_view_update_rubberband_selection (icon_view);
2176 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2182 g_assert (!icon_view->priv->doing_rubberband);
2184 for (items = icon_view->priv->items; items; items = items->next)
2186 GtkIconViewItem *item = items->data;
2188 item->selected_before_rubberbanding = item->selected;
2191 icon_view->priv->rubberband_x1 = x;
2192 icon_view->priv->rubberband_y1 = y;
2193 icon_view->priv->rubberband_x2 = x;
2194 icon_view->priv->rubberband_y2 = y;
2196 icon_view->priv->doing_rubberband = TRUE;
2198 gtk_grab_add (GTK_WIDGET (icon_view));
2202 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2204 if (!icon_view->priv->doing_rubberband)
2207 icon_view->priv->doing_rubberband = FALSE;
2209 gtk_grab_remove (GTK_WIDGET (icon_view));
2211 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2215 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2218 gint x, y, width, height;
2219 gboolean dirty = FALSE;
2221 x = MIN (icon_view->priv->rubberband_x1,
2222 icon_view->priv->rubberband_x2);
2223 y = MIN (icon_view->priv->rubberband_y1,
2224 icon_view->priv->rubberband_y2);
2225 width = ABS (icon_view->priv->rubberband_x1 -
2226 icon_view->priv->rubberband_x2);
2227 height = ABS (icon_view->priv->rubberband_y1 -
2228 icon_view->priv->rubberband_y2);
2230 for (items = icon_view->priv->items; items; items = items->next)
2232 GtkIconViewItem *item = items->data;
2236 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2237 x, y, width, height);
2239 selected = is_in ^ item->selected_before_rubberbanding;
2241 if (item->selected != selected)
2243 item->selected = selected;
2245 gtk_icon_view_queue_draw_item (icon_view, item);
2250 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2254 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2255 GtkIconViewItem *item,
2264 for (l = icon_view->priv->cell_list; l; l = l->next)
2266 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2268 if (!info->cell->visible)
2271 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2273 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2274 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2282 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2284 gboolean dirty = FALSE;
2287 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2290 for (items = icon_view->priv->items; items; items = items->next)
2292 GtkIconViewItem *item = items->data;
2296 item->selected = FALSE;
2298 gtk_icon_view_queue_draw_item (icon_view, item);
2306 /* GtkIconView signals */
2308 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2309 GtkAdjustment *hadj,
2310 GtkAdjustment *vadj)
2312 gboolean need_adjust = FALSE;
2315 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2317 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2319 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2321 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2323 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2325 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2326 0, 0, NULL, NULL, icon_view);
2327 g_object_unref (icon_view->priv->hadjustment);
2330 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2332 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2333 0, 0, NULL, NULL, icon_view);
2334 g_object_unref (icon_view->priv->vadjustment);
2337 if (icon_view->priv->hadjustment != hadj)
2339 icon_view->priv->hadjustment = hadj;
2340 g_object_ref_sink (icon_view->priv->hadjustment);
2342 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2343 G_CALLBACK (gtk_icon_view_adjustment_changed),
2348 if (icon_view->priv->vadjustment != vadj)
2350 icon_view->priv->vadjustment = vadj;
2351 g_object_ref_sink (icon_view->priv->vadjustment);
2353 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2354 G_CALLBACK (gtk_icon_view_adjustment_changed),
2360 gtk_icon_view_adjustment_changed (NULL, icon_view);
2364 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2366 gtk_icon_view_select_all (icon_view);
2370 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2372 gtk_icon_view_unselect_all (icon_view);
2376 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2378 gtk_icon_view_unselect_all (icon_view);
2380 if (icon_view->priv->cursor_item != NULL)
2381 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2385 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2388 GtkCellRendererMode mode;
2389 GtkIconViewCellInfo *info = NULL;
2391 if (!icon_view->priv->cursor_item)
2394 info = g_list_nth_data (icon_view->priv->cell_list,
2395 icon_view->priv->cursor_cell);
2399 g_object_get (info->cell, "mode", &mode, NULL);
2401 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2403 gtk_icon_view_item_activate_cell (icon_view,
2404 icon_view->priv->cursor_item,
2408 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2410 gtk_icon_view_start_editing (icon_view,
2411 icon_view->priv->cursor_item,
2417 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2418 gtk_icon_view_item_activated (icon_view, path);
2419 gtk_tree_path_free (path);
2425 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2427 if (!icon_view->priv->cursor_item)
2430 switch (icon_view->priv->selection_mode)
2432 case GTK_SELECTION_NONE:
2434 case GTK_SELECTION_BROWSE:
2435 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2437 case GTK_SELECTION_SINGLE:
2438 if (icon_view->priv->cursor_item->selected)
2439 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2441 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2443 case GTK_SELECTION_MULTIPLE:
2444 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2445 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2447 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2452 /* Internal functions */
2454 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2455 GtkIconView *icon_view)
2457 if (GTK_WIDGET_REALIZED (icon_view))
2459 gdk_window_move (icon_view->priv->bin_window,
2460 - icon_view->priv->hadjustment->value,
2461 - icon_view->priv->vadjustment->value);
2463 if (icon_view->priv->doing_rubberband)
2464 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2466 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2471 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2476 gint *maximum_width)
2479 gint x, current_width;
2480 GList *items, *last_item;
2487 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2488 max_height = g_new0 (gint, icon_view->priv->n_cells);
2495 gtk_widget_style_get (GTK_WIDGET (icon_view),
2496 "focus-line-width", &focus_width,
2499 x += icon_view->priv->margin + focus_width;
2500 current_width += 2 * (icon_view->priv->margin + focus_width);
2505 GtkIconViewItem *item = items->data;
2507 gtk_icon_view_calculate_item_size (icon_view, item);
2508 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2510 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2512 current_width += item->width;
2514 if (items != first_item)
2516 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2517 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2521 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2523 item->y = *y + focus_width;
2524 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2526 x = current_width - (icon_view->priv->margin + focus_width);
2528 for (i = 0; i < icon_view->priv->n_cells; i++)
2529 max_height[i] = MAX (max_height[i], item->box[i].height);
2531 if (current_width > *maximum_width)
2532 *maximum_width = current_width;
2538 items = items->next;
2543 /* Now go through the row again and align the icons */
2544 for (items = first_item; items != last_item; items = items->next)
2546 GtkIconViewItem *item = items->data;
2548 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2550 /* We may want to readjust the new y coordinate. */
2551 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2552 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2555 item->col = col - 1 - item->col;
2558 g_free (max_height);
2564 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2567 if (upper != adj->upper)
2569 gdouble min = MAX (0.0, upper - adj->page_size);
2570 gboolean value_changed = FALSE;
2574 if (adj->value > min)
2577 value_changed = TRUE;
2580 gtk_adjustment_changed (adj);
2583 gtk_adjustment_value_changed (adj);
2588 gtk_icon_view_layout (GtkIconView *icon_view)
2590 gint y = 0, maximum_width = 0;
2596 if (icon_view->priv->layout_idle_id != 0)
2598 g_source_remove (icon_view->priv->layout_idle_id);
2599 icon_view->priv->layout_idle_id = 0;
2602 if (icon_view->priv->model == NULL)
2605 widget = GTK_WIDGET (icon_view);
2607 item_width = icon_view->priv->item_width;
2611 for (icons = icon_view->priv->items; icons; icons = icons->next)
2613 GtkIconViewItem *item = icons->data;
2614 gtk_icon_view_calculate_item_size (icon_view, item);
2615 item_width = MAX (item_width, item->width);
2620 icons = icon_view->priv->items;
2621 y += icon_view->priv->margin;
2626 gtk_icon_view_set_cell_data (icon_view, icons->data);
2627 adjust_wrap_width (icon_view, icons->data);
2632 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2634 &y, &maximum_width);
2637 while (icons != NULL);
2639 if (maximum_width != icon_view->priv->width)
2640 icon_view->priv->width = maximum_width;
2642 y += icon_view->priv->margin;
2644 if (y != icon_view->priv->height)
2645 icon_view->priv->height = y;
2647 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2648 icon_view->priv->width);
2649 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2650 icon_view->priv->height);
2652 if (icon_view->priv->width != widget->requisition.width ||
2653 icon_view->priv->height != widget->requisition.height)
2654 gtk_widget_queue_resize_no_redraw (widget);
2656 if (GTK_WIDGET_REALIZED (icon_view))
2657 gdk_window_resize (icon_view->priv->bin_window,
2658 MAX (icon_view->priv->width, widget->allocation.width),
2659 MAX (icon_view->priv->height, widget->allocation.height));
2661 if (icon_view->priv->scroll_to_path)
2665 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2666 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2667 icon_view->priv->scroll_to_path = NULL;
2669 gtk_icon_view_scroll_to_path (icon_view, path,
2670 icon_view->priv->scroll_to_use_align,
2671 icon_view->priv->scroll_to_row_align,
2672 icon_view->priv->scroll_to_col_align);
2673 gtk_tree_path_free (path);
2676 gtk_widget_queue_draw (widget);
2680 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2681 GtkIconViewItem *item,
2682 GtkIconViewCellInfo *info,
2683 GdkRectangle *cell_area)
2685 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2687 cell_area->x = item->box[info->position].x - item->before[info->position];
2688 cell_area->y = item->y;
2689 cell_area->width = item->box[info->position].width +
2690 item->before[info->position] + item->after[info->position];
2691 cell_area->height = item->height;
2695 cell_area->x = item->x;
2696 cell_area->y = item->box[info->position].y - item->before[info->position];
2697 cell_area->width = item->width;
2698 cell_area->height = item->box[info->position].height +
2699 item->before[info->position] + item->after[info->position];
2704 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2705 GtkIconViewItem *item,
2706 GtkIconViewCellInfo *info,
2709 *box = item->box[info->position];
2712 /* try to guess a reasonable wrap width for an implicit text cell renderer
2715 adjust_wrap_width (GtkIconView *icon_view,
2716 GtkIconViewItem *item)
2718 GtkIconViewCellInfo *text_info;
2719 GtkIconViewCellInfo *pixbuf_info;
2720 gint pixbuf_width, wrap_width;
2722 if (icon_view->priv->text_cell != -1 &&
2723 icon_view->priv->pixbuf_cell != -1)
2727 text_info = g_list_nth_data (icon_view->priv->cell_list,
2728 icon_view->priv->text_cell);
2729 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2730 icon_view->priv->pixbuf_cell);
2732 gtk_cell_renderer_get_size (pixbuf_info->cell,
2733 GTK_WIDGET (icon_view),
2739 if (icon_view->priv->item_width > 0)
2740 item_width = icon_view->priv->item_width;
2742 item_width = item->width;
2744 if (item->width == -1)
2747 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2749 wrap_width = MAX (2 * pixbuf_width, 50);
2751 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2752 wrap_width = item_width;
2754 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2756 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2757 g_object_set (text_info->cell, "width", wrap_width, NULL);
2762 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2763 GtkIconViewItem *item)
2768 if (item->width != -1 && item->height != -1)
2771 if (item->n_cells != icon_view->priv->n_cells)
2773 g_free (item->before);
2774 g_free (item->after);
2777 item->before = g_new0 (gint, icon_view->priv->n_cells);
2778 item->after = g_new0 (gint, icon_view->priv->n_cells);
2779 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2781 item->n_cells = icon_view->priv->n_cells;
2784 gtk_icon_view_set_cell_data (icon_view, item);
2786 spacing = icon_view->priv->spacing;
2790 for (l = icon_view->priv->cell_list; l; l = l->next)
2792 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2794 if (!info->cell->visible)
2797 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2799 &item->box[info->position].width,
2800 &item->box[info->position].height);
2802 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2804 item->width += item->box[info->position].width
2805 + (info->position > 0 ? spacing : 0);
2806 item->height = MAX (item->height, item->box[info->position].height);
2810 item->width = MAX (item->width, item->box[info->position].width);
2811 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2817 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2818 GtkIconViewItem *item,
2821 GdkRectangle cell_area;
2827 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2829 gtk_icon_view_set_cell_data (icon_view, item);
2831 spacing = icon_view->priv->spacing;
2834 for (i = 0; i < icon_view->priv->n_cells; i++)
2836 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2837 item->height = MAX (item->height, max_height[i]);
2839 item->height += max_height[i] + (i > 0 ? spacing : 0);
2842 cell_area.x = item->x;
2843 cell_area.y = item->y;
2845 for (k = 0; k < 2; k++)
2846 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2848 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2850 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2853 if (!info->cell->visible)
2856 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2858 cell_area.width = item->box[info->position].width;
2859 cell_area.height = item->height;
2863 cell_area.width = item->width;
2864 cell_area.height = max_height[i];
2867 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2869 &item->box[info->position].x, &item->box[info->position].y,
2870 &item->box[info->position].width, &item->box[info->position].height);
2872 item->box[info->position].x += cell_area.x;
2873 item->box[info->position].y += cell_area.y;
2874 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2876 item->before[info->position] = item->box[info->position].x - cell_area.x;
2877 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2878 cell_area.x += cell_area.width + spacing;
2882 if (item->box[info->position].width > item->width)
2884 item->width = item->box[info->position].width;
2885 cell_area.width = item->width;
2887 item->before[info->position] = item->box[info->position].y - cell_area.y;
2888 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2889 cell_area.y += cell_area.height + spacing;
2893 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2895 for (i = 0; i < icon_view->priv->n_cells; i++)
2897 item->box[i].x = item->x + item->width -
2898 (item->box[i].x + item->box[i].width - item->x);
2904 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2906 g_list_foreach (icon_view->priv->items,
2907 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2911 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2918 gtk_icon_view_paint_item (GtkIconView *icon_view,
2920 GtkIconViewItem *item,
2922 GdkDrawable *drawable,
2925 gboolean draw_focus)
2927 gint focus_width, focus_pad;
2929 GdkRectangle cell_area, box;
2933 GtkCellRendererState flags;
2935 if (icon_view->priv->model == NULL)
2938 gtk_icon_view_set_cell_data (icon_view, item);
2940 gtk_widget_style_get (GTK_WIDGET (icon_view),
2941 "focus-line-width", &focus_width,
2942 "focus-padding", &focus_pad,
2945 padding = focus_width;
2949 flags = GTK_CELL_RENDERER_SELECTED;
2950 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2951 state = GTK_STATE_SELECTED;
2953 state = GTK_STATE_ACTIVE;
2958 state = GTK_STATE_NORMAL;
2961 #ifdef DEBUG_ICON_VIEW
2962 gdk_draw_rectangle (drawable,
2963 GTK_WIDGET (icon_view)->style->black_gc,
2966 item->width, item->height);
2970 for (l = icon_view->priv->cell_list; l; l = l->next)
2972 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2974 if (!info->cell->visible)
2977 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2979 /* FIXME we hardwire background drawing behind text
2980 * cell renderers here
2982 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2984 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2985 cairo_rectangle (cr,
2986 x - item->x + box.x,
2987 y - item->y + box.y,
2988 box.width, box.height);
2993 for (l = icon_view->priv->cell_list; l; l = l->next)
2995 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2997 if (!info->cell->visible)
3000 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3002 #ifdef DEBUG_ICON_VIEW
3003 gdk_draw_rectangle (drawable,
3004 GTK_WIDGET (icon_view)->style->black_gc,
3006 x - item->x + cell_area.x,
3007 y - item->y + cell_area.y,
3008 cell_area.width, cell_area.height);
3010 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3012 gdk_draw_rectangle (drawable,
3013 GTK_WIDGET (icon_view)->style->black_gc,
3015 x - item->x + box.x,
3016 y - item->y + box.y,
3017 box.width, box.height);
3020 cell_area.x = x - item->x + cell_area.x;
3021 cell_area.y = y - item->y + cell_area.y;
3023 gtk_cell_renderer_render (info->cell,
3025 GTK_WIDGET (icon_view),
3026 &cell_area, &cell_area, area, flags);
3030 /* FIXME where to draw the focus with generic cell renderers ? */
3032 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3033 item == icon_view->priv->cursor_item)
3034 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3036 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3038 if (!info->cell->visible)
3041 if (icon_view->priv->cursor_cell < 0 &&
3042 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3043 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3044 icon_view->priv->cursor_cell = i;
3046 if (i == icon_view->priv->cursor_cell)
3048 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3050 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3054 GTK_WIDGET (icon_view),
3056 x - item->x + box.x - padding,
3057 y - item->y + box.y - padding,
3058 box.width + 2 * padding,
3059 box.height + 2 * padding);
3066 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3071 GdkRectangle rubber_rect;
3072 GdkColor *fill_color_gdk;
3073 guchar fill_color_alpha;
3075 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3076 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3077 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3078 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3080 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3083 gtk_widget_style_get (GTK_WIDGET (icon_view),
3084 "selection-box-color", &fill_color_gdk,
3085 "selection-box-alpha", &fill_color_alpha,
3088 if (!fill_color_gdk)
3089 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3091 cairo_set_source_rgba (cr,
3092 fill_color_gdk->red / 65535.,
3093 fill_color_gdk->green / 65535.,
3094 fill_color_gdk->blue / 65535.,
3095 fill_color_alpha / 255.);
3098 gdk_cairo_rectangle (cr, &rect);
3102 /* Draw the border without alpha */
3103 cairo_set_source_rgb (cr,
3104 fill_color_gdk->red / 65535.,
3105 fill_color_gdk->green / 65535.,
3106 fill_color_gdk->blue / 65535.);
3107 cairo_rectangle (cr,
3108 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3109 rubber_rect.width - 1, rubber_rect.height - 1);
3113 gdk_color_free (fill_color_gdk);
3117 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3123 index = gtk_tree_path_get_indices (path)[0];
3125 for (l = icon_view->priv->items; l; l = l->next)
3127 GtkIconViewItem *item = l->data;
3129 if (item->index == index)
3131 gtk_icon_view_queue_draw_item (icon_view, item);
3138 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3139 GtkIconViewItem *item)
3144 gtk_widget_style_get (GTK_WIDGET (icon_view),
3145 "focus-line-width", &focus_width,
3148 rect.x = item->x - focus_width;
3149 rect.y = item->y - focus_width;
3150 rect.width = item->width + 2 * focus_width;
3151 rect.height = item->height + 2 * focus_width;
3153 if (icon_view->priv->bin_window)
3154 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3158 layout_callback (gpointer user_data)
3160 GtkIconView *icon_view;
3162 icon_view = GTK_ICON_VIEW (user_data);
3164 icon_view->priv->layout_idle_id = 0;
3166 gtk_icon_view_layout (icon_view);
3172 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3174 if (icon_view->priv->layout_idle_id != 0)
3177 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3181 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3182 GtkIconViewItem *item,
3186 AtkObject *item_obj;
3188 if (icon_view->priv->cursor_item == item &&
3189 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3192 if (icon_view->priv->cursor_item != NULL)
3193 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3195 icon_view->priv->cursor_item = item;
3196 if (cursor_cell >= 0)
3197 icon_view->priv->cursor_cell = cursor_cell;
3199 gtk_icon_view_queue_draw_item (icon_view, item);
3201 /* Notify that accessible focus object has changed */
3202 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3203 item_obj = atk_object_ref_accessible_child (obj, item->index);
3205 if (item_obj != NULL)
3207 atk_focus_tracker_notify (item_obj);
3208 g_object_unref (item_obj);
3213 static GtkIconViewItem *
3214 gtk_icon_view_item_new (void)
3216 GtkIconViewItem *item;
3218 item = g_new0 (GtkIconViewItem, 1);
3227 gtk_icon_view_item_free (GtkIconViewItem *item)
3229 g_return_if_fail (item != NULL);
3231 g_free (item->before);
3232 g_free (item->after);
3239 static GtkIconViewItem *
3240 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3243 gboolean only_in_cell,
3244 GtkIconViewCellInfo **cell_at_pos)
3249 for (items = icon_view->priv->items; items; items = items->next)
3251 GtkIconViewItem *item = items->data;
3253 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3254 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3256 if (only_in_cell || cell_at_pos)
3258 gtk_icon_view_set_cell_data (icon_view, item);
3260 for (l = icon_view->priv->cell_list; l; l = l->next)
3262 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3264 if (!info->cell->visible)
3267 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3269 if ((x >= box.x && x <= box.x + box.width &&
3270 y >= box.y && y <= box.y + box.height) ||
3272 x <= box.x + box.width &&
3274 y <= box.y + box.height))
3277 *cell_at_pos = info;
3287 *cell_at_pos = NULL;
3298 gtk_icon_view_select_item (GtkIconView *icon_view,
3299 GtkIconViewItem *item)
3301 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3302 g_return_if_fail (item != NULL);
3307 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3309 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3310 gtk_icon_view_unselect_all_internal (icon_view);
3312 item->selected = TRUE;
3314 gtk_icon_view_queue_draw_item (icon_view, item);
3316 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3321 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3322 GtkIconViewItem *item)
3324 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3325 g_return_if_fail (item != NULL);
3327 if (!item->selected)
3330 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3331 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3334 item->selected = FALSE;
3336 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3338 gtk_icon_view_queue_draw_item (icon_view, item);
3342 verify_items (GtkIconView *icon_view)
3347 for (items = icon_view->priv->items; items; items = items->next)
3349 GtkIconViewItem *item = items->data;
3351 if (item->index != i)
3352 g_error ("List item does not match its index: "
3353 "item index %d and list index %d\n", item->index, i);
3360 gtk_icon_view_row_changed (GtkTreeModel *model,
3365 GtkIconViewItem *item;
3367 GtkIconView *icon_view;
3369 icon_view = GTK_ICON_VIEW (data);
3371 gtk_icon_view_stop_editing (icon_view, TRUE);
3373 index = gtk_tree_path_get_indices(path)[0];
3374 item = g_list_nth_data (icon_view->priv->items, index);
3376 gtk_icon_view_item_invalidate_size (item);
3377 gtk_icon_view_queue_layout (icon_view);
3379 verify_items (icon_view);
3383 gtk_icon_view_row_inserted (GtkTreeModel *model,
3389 GtkIconViewItem *item;
3390 gboolean iters_persist;
3391 GtkIconView *icon_view;
3394 icon_view = GTK_ICON_VIEW (data);
3396 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3398 index = gtk_tree_path_get_indices(path)[0];
3400 item = gtk_icon_view_item_new ();
3405 item->index = index;
3407 /* FIXME: We can be more efficient here,
3408 we can store a tail pointer and use that when
3409 appending (which is a rather common operation)
3411 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3414 list = g_list_nth (icon_view->priv->items, index + 1);
3415 for (; list; list = list->next)
3422 verify_items (icon_view);
3424 gtk_icon_view_queue_layout (icon_view);
3428 gtk_icon_view_row_deleted (GtkTreeModel *model,
3433 GtkIconView *icon_view;
3434 GtkIconViewItem *item;
3436 gboolean emit = FALSE;
3438 icon_view = GTK_ICON_VIEW (data);
3440 index = gtk_tree_path_get_indices(path)[0];
3442 list = g_list_nth (icon_view->priv->items, index);
3445 gtk_icon_view_stop_editing (icon_view, TRUE);
3447 if (item == icon_view->priv->anchor_item)
3448 icon_view->priv->anchor_item = NULL;
3450 if (item == icon_view->priv->cursor_item)
3451 icon_view->priv->cursor_item = NULL;
3456 gtk_icon_view_item_free (item);
3458 for (next = list->next; next; next = next->next)
3465 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3467 verify_items (icon_view);
3469 gtk_icon_view_queue_layout (icon_view);
3472 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3476 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3477 GtkTreePath *parent,
3484 GtkIconView *icon_view;
3485 GList *items = NULL, *list;
3486 GtkIconViewItem **item_array;
3489 icon_view = GTK_ICON_VIEW (data);
3491 gtk_icon_view_stop_editing (icon_view, TRUE);
3493 length = gtk_tree_model_iter_n_children (model, NULL);
3495 order = g_new (gint, length);
3496 for (i = 0; i < length; i++)
3497 order [new_order[i]] = i;
3499 item_array = g_new (GtkIconViewItem *, length);
3500 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3501 item_array[order[i]] = list->data;
3504 for (i = length - 1; i >= 0; i--)
3506 item_array[i]->index = i;
3507 items = g_list_prepend (items, item_array[i]);
3510 g_free (item_array);
3511 g_list_free (icon_view->priv->items);
3512 icon_view->priv->items = items;
3514 gtk_icon_view_queue_layout (icon_view);
3516 verify_items (icon_view);
3520 gtk_icon_view_build_items (GtkIconView *icon_view)
3524 gboolean iters_persist;
3525 GList *items = NULL;
3527 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3529 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3537 GtkIconViewItem *item = gtk_icon_view_item_new ();
3546 items = g_list_prepend (items, item);
3548 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3550 icon_view->priv->items = g_list_reverse (items);
3554 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3557 GtkMovementStep step,
3561 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3562 I_("move_cursor"), 2,
3566 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3571 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3574 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3579 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3586 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3587 GtkMovementStep step,
3590 GdkModifierType state;
3592 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3593 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3594 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3595 step == GTK_MOVEMENT_DISPLAY_LINES ||
3596 step == GTK_MOVEMENT_PAGES ||
3597 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3599 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3602 gtk_icon_view_stop_editing (icon_view, FALSE);
3603 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3605 if (gtk_get_current_event_state (&state))
3607 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3608 icon_view->priv->ctrl_pressed = TRUE;
3609 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3610 icon_view->priv->shift_pressed = TRUE;
3612 /* else we assume not pressed */
3616 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3617 case GTK_MOVEMENT_VISUAL_POSITIONS:
3618 gtk_icon_view_move_cursor_left_right (icon_view, count);
3620 case GTK_MOVEMENT_DISPLAY_LINES:
3621 gtk_icon_view_move_cursor_up_down (icon_view, count);
3623 case GTK_MOVEMENT_PAGES:
3624 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3626 case GTK_MOVEMENT_BUFFER_ENDS:
3627 gtk_icon_view_move_cursor_start_end (icon_view, count);
3630 g_assert_not_reached ();
3633 icon_view->priv->ctrl_pressed = FALSE;
3634 icon_view->priv->shift_pressed = FALSE;
3639 static GtkIconViewItem *
3640 find_item (GtkIconView *icon_view,
3641 GtkIconViewItem *current,
3647 GtkIconViewItem *item;
3649 /* FIXME: this could be more efficient
3651 row = current->row + row_ofs;
3652 col = current->col + col_ofs;
3654 for (items = icon_view->priv->items; items; items = items->next)
3657 if (item->row == row && item->col == col)
3665 find_cell (GtkIconView *icon_view,
3666 GtkIconViewItem *item,
3668 GtkOrientation orientation,
3679 if (icon_view->priv->orientation != orientation)
3682 gtk_icon_view_set_cell_data (icon_view, item);
3684 focusable = g_new0 (gint, icon_view->priv->n_cells);
3689 for (k = 0; k < 2; k++)
3690 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3692 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3694 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3697 if (!info->cell->visible)
3700 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3703 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3706 current = n_focusable;
3708 focusable[n_focusable] = i;
3714 if (n_focusable == 0)
3715 focusable[n_focusable++] = first_text;
3719 current = step > 0 ? 0 : n_focusable - 1;
3720 cell = focusable[current];
3723 if (current + *count < 0)
3726 *count = current + *count;
3728 else if (current + *count > n_focusable - 1)
3731 *count = current + *count - (n_focusable - 1);
3735 cell = focusable[current + *count];
3744 static GtkIconViewItem *
3745 find_item_page_up_down (GtkIconView *icon_view,
3746 GtkIconViewItem *current,
3753 y = current->y + count * icon_view->priv->vadjustment->page_size;
3755 item = g_list_find (icon_view->priv->items, current);
3760 for (next = item->next; next; next = next->next)
3762 if (((GtkIconViewItem *)next->data)->col == col)
3765 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3775 for (next = item->prev; next; next = next->prev)
3777 if (((GtkIconViewItem *)next->data)->col == col)
3780 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3794 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3795 GtkIconViewItem *anchor,
3796 GtkIconViewItem *cursor)
3799 GtkIconViewItem *item;
3800 gint row1, row2, col1, col2;
3801 gboolean dirty = FALSE;
3803 if (anchor->row < cursor->row)
3814 if (anchor->col < cursor->col)
3825 for (items = icon_view->priv->items; items; items = items->next)
3829 if (row1 <= item->row && item->row <= row2 &&
3830 col1 <= item->col && item->col <= col2)
3832 if (!item->selected)
3835 item->selected = TRUE;
3837 gtk_icon_view_queue_draw_item (icon_view, item);
3845 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3848 GtkIconViewItem *item;
3850 gboolean dirty = FALSE;
3853 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3856 if (!icon_view->priv->cursor_item)
3861 list = icon_view->priv->items;
3863 list = g_list_last (icon_view->priv->items);
3865 item = list ? list->data : NULL;
3870 item = icon_view->priv->cursor_item;
3871 cell = icon_view->priv->cursor_cell;
3872 step = count > 0 ? 1 : -1;
3875 cell = find_cell (icon_view, item, cell,
3876 GTK_ORIENTATION_VERTICAL,
3881 item = find_item (icon_view, item, step, 0);
3882 count = count - step;
3888 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3892 if (icon_view->priv->ctrl_pressed ||
3893 !icon_view->priv->shift_pressed ||
3894 !icon_view->priv->anchor_item ||
3895 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3896 icon_view->priv->anchor_item = item;
3898 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3900 if (!icon_view->priv->ctrl_pressed &&
3901 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3903 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3904 dirty = gtk_icon_view_select_all_between (icon_view,
3905 icon_view->priv->anchor_item,
3909 gtk_icon_view_scroll_to_item (icon_view, item);
3912 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3916 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3919 GtkIconViewItem *item;
3920 gboolean dirty = FALSE;
3922 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3925 if (!icon_view->priv->cursor_item)
3930 list = icon_view->priv->items;
3932 list = g_list_last (icon_view->priv->items);
3934 item = list ? list->data : NULL;
3937 item = find_item_page_up_down (icon_view,
3938 icon_view->priv->cursor_item,
3941 if (item == icon_view->priv->cursor_item)
3942 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3947 if (icon_view->priv->ctrl_pressed ||
3948 !icon_view->priv->shift_pressed ||
3949 !icon_view->priv->anchor_item ||
3950 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3951 icon_view->priv->anchor_item = item;
3953 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3955 if (!icon_view->priv->ctrl_pressed &&
3956 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3958 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3959 dirty = gtk_icon_view_select_all_between (icon_view,
3960 icon_view->priv->anchor_item,
3964 gtk_icon_view_scroll_to_item (icon_view, item);
3967 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3971 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3974 GtkIconViewItem *item;
3976 gboolean dirty = FALSE;
3979 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3982 if (!icon_view->priv->cursor_item)
3987 list = icon_view->priv->items;
3989 list = g_list_last (icon_view->priv->items);
3991 item = list ? list->data : NULL;
3995 item = icon_view->priv->cursor_item;
3996 cell = icon_view->priv->cursor_cell;
3997 step = count > 0 ? 1 : -1;
4000 cell = find_cell (icon_view, item, cell,
4001 GTK_ORIENTATION_HORIZONTAL,
4006 item = find_item (icon_view, item, 0, step);
4007 count = count - step;
4013 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4017 if (icon_view->priv->ctrl_pressed ||
4018 !icon_view->priv->shift_pressed ||
4019 !icon_view->priv->anchor_item ||
4020 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4021 icon_view->priv->anchor_item = item;
4023 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4025 if (!icon_view->priv->ctrl_pressed &&
4026 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4028 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4029 dirty = gtk_icon_view_select_all_between (icon_view,
4030 icon_view->priv->anchor_item,
4034 gtk_icon_view_scroll_to_item (icon_view, item);
4037 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4041 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4044 GtkIconViewItem *item;
4046 gboolean dirty = FALSE;
4048 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4052 list = icon_view->priv->items;
4054 list = g_list_last (icon_view->priv->items);
4056 item = list ? list->data : NULL;
4058 if (item == icon_view->priv->cursor_item)
4059 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4064 if (icon_view->priv->ctrl_pressed ||
4065 !icon_view->priv->shift_pressed ||
4066 !icon_view->priv->anchor_item ||
4067 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4068 icon_view->priv->anchor_item = item;
4070 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4072 if (!icon_view->priv->ctrl_pressed &&
4073 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4075 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4076 dirty = gtk_icon_view_select_all_between (icon_view,
4077 icon_view->priv->anchor_item,
4081 gtk_icon_view_scroll_to_item (icon_view, item);
4084 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4088 * gtk_icon_view_scroll_to_path:
4089 * @icon_view: A #GtkIconView.
4090 * @path: The path of the item to move to.
4091 * @use_align: whether to use alignment arguments, or %FALSE.
4092 * @row_align: The vertical alignment of the item specified by @path.
4093 * @col_align: The horizontal alignment of the item specified by @path.
4095 * Moves the alignments of @icon_view to the position specified by @path.
4096 * @row_align determines where the row is placed, and @col_align determines
4097 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4098 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4101 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4102 * tree does the minimum amount of work to scroll the item onto the screen.
4103 * This means that the item will be scrolled to the edge closest to its current
4104 * position. If the item is currently visible on the screen, nothing is done.
4106 * This function only works if the model is set, and @path is a valid row on
4107 * the model. If the model changes before the @icon_view is realized, the
4108 * centered path will be modified to reflect this change.
4113 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4119 GtkIconViewItem *item = NULL;
4121 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4122 g_return_if_fail (path != NULL);
4123 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4124 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4126 if (gtk_tree_path_get_depth (path) > 0)
4127 item = g_list_nth_data (icon_view->priv->items,
4128 gtk_tree_path_get_indices(path)[0]);
4130 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4132 if (icon_view->priv->scroll_to_path)
4133 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4135 icon_view->priv->scroll_to_path = NULL;
4138 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4140 icon_view->priv->scroll_to_use_align = use_align;
4141 icon_view->priv->scroll_to_row_align = row_align;
4142 icon_view->priv->scroll_to_col_align = col_align;
4151 gfloat offset, value;
4153 gtk_widget_style_get (GTK_WIDGET (icon_view),
4154 "focus-line-width", &focus_width,
4157 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4159 offset = y + item->y - focus_width -
4160 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4161 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4162 icon_view->priv->vadjustment->lower,
4163 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4164 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4166 offset = x + item->x - focus_width -
4167 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4168 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4169 icon_view->priv->hadjustment->lower,
4170 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4171 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4173 gtk_adjustment_changed (icon_view->priv->hadjustment);
4174 gtk_adjustment_changed (icon_view->priv->vadjustment);
4177 gtk_icon_view_scroll_to_item (icon_view, item);
4182 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4183 GtkIconViewItem *item)
4185 gint x, y, width, height;
4188 gtk_widget_style_get (GTK_WIDGET (icon_view),
4189 "focus-line-width", &focus_width,
4192 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4194 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4196 if (y + item->y - focus_width < 0)
4197 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4198 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4199 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4200 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4201 icon_view->priv->vadjustment->value + y + item->y + item->height
4202 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4204 if (x + item->x - focus_width < 0)
4205 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4206 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4207 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4208 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4209 icon_view->priv->hadjustment->value + x + item->x + item->width
4210 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4212 gtk_adjustment_changed (icon_view->priv->hadjustment);
4213 gtk_adjustment_changed (icon_view->priv->vadjustment);
4216 /* GtkCellLayout implementation */
4217 static GtkIconViewCellInfo *
4218 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4219 GtkCellRenderer *renderer)
4223 for (i = icon_view->priv->cell_list; i; i = i->next)
4225 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4227 if (info->cell == renderer)
4235 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4236 GtkIconViewItem *item)
4239 gboolean iters_persist;
4242 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4248 path = gtk_tree_path_new_from_indices (item->index, -1);
4249 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4251 gtk_tree_path_free (path);
4256 for (i = icon_view->priv->cell_list; i; i = i->next)
4259 GtkIconViewCellInfo *info = i->data;
4261 g_object_freeze_notify (G_OBJECT (info->cell));
4263 for (j = info->attributes; j && j->next; j = j->next->next)
4265 gchar *property = j->data;
4266 gint column = GPOINTER_TO_INT (j->next->data);
4267 GValue value = {0, };
4269 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4271 g_object_set_property (G_OBJECT (info->cell),
4273 g_value_unset (&value);
4277 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4279 icon_view->priv->model,
4283 g_object_thaw_notify (G_OBJECT (info->cell));
4288 free_cell_attributes (GtkIconViewCellInfo *info)
4292 list = info->attributes;
4293 while (list && list->next)
4295 g_free (list->data);
4296 list = list->next->next;
4299 g_slist_free (info->attributes);
4300 info->attributes = NULL;
4304 free_cell_info (GtkIconViewCellInfo *info)
4306 free_cell_attributes (info);
4308 g_object_unref (info->cell);
4311 (* info->destroy) (info->func_data);
4317 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4318 GtkCellRenderer *renderer,
4321 GtkIconViewCellInfo *info;
4322 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4324 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4325 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4327 g_object_ref_sink (renderer);
4329 info = g_new0 (GtkIconViewCellInfo, 1);
4330 info->cell = renderer;
4331 info->expand = expand ? TRUE : FALSE;
4332 info->pack = GTK_PACK_START;
4333 info->position = icon_view->priv->n_cells;
4335 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4336 icon_view->priv->n_cells++;
4340 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4341 GtkCellRenderer *renderer,
4344 GtkIconViewCellInfo *info;
4345 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4347 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4348 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4350 g_object_ref_sink (renderer);
4352 info = g_new0 (GtkIconViewCellInfo, 1);
4353 info->cell = renderer;
4354 info->expand = expand ? TRUE : FALSE;
4355 info->pack = GTK_PACK_END;
4356 info->position = icon_view->priv->n_cells;
4358 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4359 icon_view->priv->n_cells++;
4363 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4364 GtkCellRenderer *renderer,
4365 const gchar *attribute,
4368 GtkIconViewCellInfo *info;
4369 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4371 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4372 g_return_if_fail (info != NULL);
4374 info->attributes = g_slist_prepend (info->attributes,
4375 GINT_TO_POINTER (column));
4376 info->attributes = g_slist_prepend (info->attributes,
4377 g_strdup (attribute));
4381 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4383 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4385 while (icon_view->priv->cell_list)
4387 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4388 free_cell_info (info);
4389 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4390 icon_view->priv->cell_list);
4393 icon_view->priv->n_cells = 0;
4397 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4398 GtkCellRenderer *cell,
4399 GtkCellLayoutDataFunc func,
4401 GDestroyNotify destroy)
4403 GtkIconViewCellInfo *info;
4404 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4406 info = gtk_icon_view_get_cell_info (icon_view, cell);
4407 g_return_if_fail (info != NULL);
4411 GDestroyNotify d = info->destroy;
4413 info->destroy = NULL;
4414 d (info->func_data);
4418 info->func_data = func_data;
4419 info->destroy = destroy;
4423 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4424 GtkCellRenderer *renderer)
4426 GtkIconViewCellInfo *info;
4428 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4430 free_cell_attributes (info);
4434 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4435 GtkCellRenderer *cell,
4438 GtkIconView *icon_view;
4440 GtkIconViewCellInfo *info;
4443 icon_view = GTK_ICON_VIEW (layout);
4445 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4447 info = gtk_icon_view_get_cell_info (icon_view, cell);
4449 g_return_if_fail (info != NULL);
4450 g_return_if_fail (position >= 0);
4452 link = g_list_find (icon_view->priv->cell_list, info);
4454 g_return_if_fail (link != NULL);
4456 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4458 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4461 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4468 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4472 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4474 GtkIconView *icon_view = (GtkIconView *)layout;
4475 GList *retval = NULL, *l;
4477 for (l = icon_view->priv->cell_list; l; l = l->next)
4479 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4481 retval = g_list_prepend (retval, info->cell);
4484 return g_list_reverse (retval);
4491 * gtk_icon_view_new:
4493 * Creates a new #GtkIconView widget
4495 * Return value: A newly created #GtkIconView widget
4500 gtk_icon_view_new (void)
4502 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4506 * gtk_icon_view_new_with_model:
4507 * @model: The model.
4509 * Creates a new #GtkIconView widget with the model @model.
4511 * Return value: A newly created #GtkIconView widget.
4516 gtk_icon_view_new_with_model (GtkTreeModel *model)
4518 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4522 * gtk_icon_view_convert_widget_to_bin_window_coords:
4523 * @wx: X coordinate relative to the widget
4524 * @wy: Y coordinate relative to the widget
4525 * @bx: return location for bin_window X coordinate
4526 * @by: return location for bin_window Y coordinate
4528 * Converts widget coordinates to coordinates for the bin_window,
4529 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4534 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4542 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4544 if (icon_view->priv->bin_window)
4545 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4556 * gtk_icon_view_get_path_at_pos:
4557 * @icon_view: A #GtkIconView.
4558 * @x: The x position to be identified
4559 * @y: The y position to be identified
4561 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4562 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4563 * the cell at the specified position.
4564 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4565 * widget coordinates to bin_window coordinates.
4567 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4568 * if no icon exists at that position.
4573 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4577 GtkIconViewItem *item;
4581 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4583 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4588 path = gtk_tree_path_new_from_indices (item->index, -1);
4594 * gtk_icon_view_get_item_at_pos:
4595 * @icon_view: A #GtkIconView.
4596 * @x: The x position to be identified
4597 * @y: The y position to be identified
4598 * @path: Return location for the path, or %NULL
4599 * @cell: Return location for the renderer responsible for the cell
4600 * at (@x, @y), or %NULL
4602 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4603 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4604 * obtains the cell at the specified position. The returned path should
4605 * be freed with gtk_tree_path_free().
4606 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4607 * widget coordinates to bin_window coordinates.
4609 * Return value: %TRUE if an item exists at the specified position
4614 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4618 GtkCellRenderer **cell)
4620 GtkIconViewItem *item;
4621 GtkIconViewCellInfo *info;
4623 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4625 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4630 *path = gtk_tree_path_new_from_indices (item->index, -1);
4643 return (item != NULL);
4648 * gtk_icon_view_get_visible_range:
4649 * @icon_view: A #GtkIconView
4650 * @start_path: Return location for start of region, or %NULL
4651 * @end_path: Return location for end of region, or %NULL
4653 * Sets @start_path and @end_path to be the first and last visible path.
4654 * Note that there may be invisible paths in between.
4656 * Both paths should be freed with gtk_tree_path_free() after use.
4658 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4663 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4664 GtkTreePath **start_path,
4665 GtkTreePath **end_path)
4667 gint start_index = -1;
4668 gint end_index = -1;
4671 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4673 if (icon_view->priv->hadjustment == NULL ||
4674 icon_view->priv->vadjustment == NULL)
4677 if (start_path == NULL && end_path == NULL)
4680 for (icons = icon_view->priv->items; icons; icons = icons->next)
4682 GtkIconViewItem *item = icons->data;
4684 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4685 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4686 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4687 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4689 if (start_index == -1)
4690 start_index = item->index;
4691 end_index = item->index;
4695 if (start_path && start_index != -1)
4696 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4697 if (end_path && end_index != -1)
4698 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4700 return start_index != -1;
4704 * gtk_icon_view_selected_foreach:
4705 * @icon_view: A #GtkIconView.
4706 * @func: The funcion to call for each selected icon.
4707 * @data: User data to pass to the function.
4709 * Calls a function for each selected icon. Note that the model or
4710 * selection cannot be modified from within this function.
4715 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4716 GtkIconViewForeachFunc func,
4721 for (list = icon_view->priv->items; list; list = list->next)
4723 GtkIconViewItem *item = list->data;
4724 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4727 (* func) (icon_view, path, data);
4729 gtk_tree_path_free (path);
4734 * gtk_icon_view_set_selection_mode:
4735 * @icon_view: A #GtkIconView.
4736 * @mode: The selection mode
4738 * Sets the selection mode of the @icon_view.
4743 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4744 GtkSelectionMode mode)
4746 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4748 if (mode == icon_view->priv->selection_mode)
4751 if (mode == GTK_SELECTION_NONE ||
4752 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4753 gtk_icon_view_unselect_all (icon_view);
4755 icon_view->priv->selection_mode = mode;
4757 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4761 * gtk_icon_view_get_selection_mode:
4762 * @icon_view: A #GtkIconView.
4764 * Gets the selection mode of the @icon_view.
4766 * Return value: the current selection mode
4771 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4773 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4775 return icon_view->priv->selection_mode;
4779 * gtk_icon_view_set_model:
4780 * @icon_view: A #GtkIconView.
4781 * @model: The model.
4783 * Sets the model for a #GtkIconView.
4784 * If the @icon_view already has a model set, it will remove
4785 * it before setting the new model. If @model is %NULL, then
4786 * it will unset the old model.
4791 gtk_icon_view_set_model (GtkIconView *icon_view,
4792 GtkTreeModel *model)
4794 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4795 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4797 if (icon_view->priv->model == model)
4800 if (icon_view->priv->scroll_to_path)
4802 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4803 icon_view->priv->scroll_to_path = NULL;
4806 gtk_icon_view_stop_editing (icon_view, TRUE);
4812 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4814 if (icon_view->priv->pixbuf_column != -1)
4816 column_type = gtk_tree_model_get_column_type (model,
4817 icon_view->priv->pixbuf_column);
4819 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4822 if (icon_view->priv->text_column != -1)
4824 column_type = gtk_tree_model_get_column_type (model,
4825 icon_view->priv->text_column);
4827 g_return_if_fail (column_type == G_TYPE_STRING);
4830 if (icon_view->priv->markup_column != -1)
4832 column_type = gtk_tree_model_get_column_type (model,
4833 icon_view->priv->markup_column);
4835 g_return_if_fail (column_type == G_TYPE_STRING);
4840 if (icon_view->priv->model)
4842 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4843 gtk_icon_view_row_changed,
4845 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4846 gtk_icon_view_row_inserted,
4848 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4849 gtk_icon_view_row_deleted,
4851 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4852 gtk_icon_view_rows_reordered,
4855 g_object_unref (icon_view->priv->model);
4857 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4858 g_list_free (icon_view->priv->items);
4859 icon_view->priv->items = NULL;
4860 icon_view->priv->anchor_item = NULL;
4861 icon_view->priv->cursor_item = NULL;
4862 icon_view->priv->last_single_clicked = NULL;
4863 icon_view->priv->width = 0;
4864 icon_view->priv->height = 0;
4867 icon_view->priv->model = model;
4869 if (icon_view->priv->model)
4871 g_object_ref (icon_view->priv->model);
4872 g_signal_connect (icon_view->priv->model,
4874 G_CALLBACK (gtk_icon_view_row_changed),
4876 g_signal_connect (icon_view->priv->model,
4878 G_CALLBACK (gtk_icon_view_row_inserted),
4880 g_signal_connect (icon_view->priv->model,
4882 G_CALLBACK (gtk_icon_view_row_deleted),
4884 g_signal_connect (icon_view->priv->model,
4886 G_CALLBACK (gtk_icon_view_rows_reordered),
4889 gtk_icon_view_build_items (icon_view);
4891 gtk_icon_view_queue_layout (icon_view);
4894 g_object_notify (G_OBJECT (icon_view), "model");
4896 if (GTK_WIDGET_REALIZED (icon_view))
4897 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4901 * gtk_icon_view_get_model:
4902 * @icon_view: a #GtkIconView
4904 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4907 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4912 gtk_icon_view_get_model (GtkIconView *icon_view)
4914 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4916 return icon_view->priv->model;
4920 update_text_cell (GtkIconView *icon_view)
4922 GtkIconViewCellInfo *info;
4926 if (icon_view->priv->text_column == -1 &&
4927 icon_view->priv->markup_column == -1)
4929 if (icon_view->priv->text_cell != -1)
4931 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4932 icon_view->priv->pixbuf_cell--;
4934 info = g_list_nth_data (icon_view->priv->cell_list,
4935 icon_view->priv->text_cell);
4937 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4939 free_cell_info (info);
4941 icon_view->priv->n_cells--;
4942 icon_view->priv->text_cell = -1;
4947 if (icon_view->priv->text_cell == -1)
4949 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4950 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4951 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4954 if (info->cell == cell)
4956 icon_view->priv->text_cell = i;
4962 info = g_list_nth_data (icon_view->priv->cell_list,
4963 icon_view->priv->text_cell);
4965 if (icon_view->priv->markup_column != -1)
4966 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4968 "markup", icon_view->priv->markup_column,
4971 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4973 "text", icon_view->priv->text_column,
4976 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4977 g_object_set (info->cell,
4978 "alignment", PANGO_ALIGN_CENTER,
4979 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4984 g_object_set (info->cell,
4985 "alignment", PANGO_ALIGN_LEFT,
4986 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4994 update_pixbuf_cell (GtkIconView *icon_view)
4996 GtkIconViewCellInfo *info;
5000 if (icon_view->priv->pixbuf_column == -1)
5002 if (icon_view->priv->pixbuf_cell != -1)
5004 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5005 icon_view->priv->text_cell--;
5007 info = g_list_nth_data (icon_view->priv->cell_list,
5008 icon_view->priv->pixbuf_cell);
5010 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5012 free_cell_info (info);
5014 icon_view->priv->n_cells--;
5015 icon_view->priv->pixbuf_cell = -1;
5020 if (icon_view->priv->pixbuf_cell == -1)
5022 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5024 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5025 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5028 if (info->cell == cell)
5030 icon_view->priv->pixbuf_cell = i;
5036 info = g_list_nth_data (icon_view->priv->cell_list,
5037 icon_view->priv->pixbuf_cell);
5039 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5041 "pixbuf", icon_view->priv->pixbuf_column,
5044 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5045 g_object_set (info->cell,
5046 "follow-state", TRUE,
5051 g_object_set (info->cell,
5052 "follow-state", TRUE,
5060 * gtk_icon_view_set_text_column:
5061 * @icon_view: A #GtkIconView.
5062 * @column: A column in the currently used model, or -1 to display no text
5064 * Sets the column with text for @icon_view to be @column. The text
5065 * column must be of type #G_TYPE_STRING.
5070 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5073 if (column == icon_view->priv->text_column)
5077 icon_view->priv->text_column = -1;
5080 if (icon_view->priv->model != NULL)
5084 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5086 g_return_if_fail (column_type == G_TYPE_STRING);
5089 icon_view->priv->text_column = column;
5092 gtk_icon_view_stop_editing (icon_view, TRUE);
5094 update_text_cell (icon_view);
5096 gtk_icon_view_invalidate_sizes (icon_view);
5097 gtk_icon_view_queue_layout (icon_view);
5099 g_object_notify (G_OBJECT (icon_view), "text-column");
5103 * gtk_icon_view_get_text_column:
5104 * @icon_view: A #GtkIconView.
5106 * Returns the column with text for @icon_view.
5108 * Returns: the text column, or -1 if it's unset.
5113 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5115 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5117 return icon_view->priv->text_column;
5121 * gtk_icon_view_set_markup_column:
5122 * @icon_view: A #GtkIconView.
5123 * @column: A column in the currently used model, or -1 to display no text
5125 * Sets the column with markup information for @icon_view to be
5126 * @column. The markup column must be of type #G_TYPE_STRING.
5127 * If the markup column is set to something, it overrides
5128 * the text column set by gtk_icon_view_set_text_column().
5133 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5136 if (column == icon_view->priv->markup_column)
5140 icon_view->priv->markup_column = -1;
5143 if (icon_view->priv->model != NULL)
5147 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5149 g_return_if_fail (column_type == G_TYPE_STRING);
5152 icon_view->priv->markup_column = column;
5155 gtk_icon_view_stop_editing (icon_view, TRUE);
5157 update_text_cell (icon_view);
5159 gtk_icon_view_invalidate_sizes (icon_view);
5160 gtk_icon_view_queue_layout (icon_view);
5162 g_object_notify (G_OBJECT (icon_view), "markup-column");
5166 * gtk_icon_view_get_markup_column:
5167 * @icon_view: A #GtkIconView.
5169 * Returns the column with markup text for @icon_view.
5171 * Returns: the markup column, or -1 if it's unset.
5176 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5178 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5180 return icon_view->priv->markup_column;
5184 * gtk_icon_view_set_pixbuf_column:
5185 * @icon_view: A #GtkIconView.
5186 * @column: A column in the currently used model, or -1 to disable
5188 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5189 * column must be of type #GDK_TYPE_PIXBUF
5194 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5197 if (column == icon_view->priv->pixbuf_column)
5201 icon_view->priv->pixbuf_column = -1;
5204 if (icon_view->priv->model != NULL)
5208 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5210 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5213 icon_view->priv->pixbuf_column = column;
5216 gtk_icon_view_stop_editing (icon_view, TRUE);
5218 update_pixbuf_cell (icon_view);
5220 gtk_icon_view_invalidate_sizes (icon_view);
5221 gtk_icon_view_queue_layout (icon_view);
5223 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5228 * gtk_icon_view_get_pixbuf_column:
5229 * @icon_view: A #GtkIconView.
5231 * Returns the column with pixbufs for @icon_view.
5233 * Returns: the pixbuf column, or -1 if it's unset.
5238 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5240 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5242 return icon_view->priv->pixbuf_column;
5246 * gtk_icon_view_select_path:
5247 * @icon_view: A #GtkIconView.
5248 * @path: The #GtkTreePath to be selected.
5250 * Selects the row at @path.
5255 gtk_icon_view_select_path (GtkIconView *icon_view,
5258 GtkIconViewItem *item = NULL;
5260 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5261 g_return_if_fail (icon_view->priv->model != NULL);
5262 g_return_if_fail (path != NULL);
5264 if (gtk_tree_path_get_depth (path) > 0)
5265 item = g_list_nth_data (icon_view->priv->items,
5266 gtk_tree_path_get_indices(path)[0]);
5269 gtk_icon_view_select_item (icon_view, item);
5273 * gtk_icon_view_unselect_path:
5274 * @icon_view: A #GtkIconView.
5275 * @path: The #GtkTreePath to be unselected.
5277 * Unselects the row at @path.
5282 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5285 GtkIconViewItem *item;
5287 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5288 g_return_if_fail (icon_view->priv->model != NULL);
5289 g_return_if_fail (path != NULL);
5291 item = g_list_nth_data (icon_view->priv->items,
5292 gtk_tree_path_get_indices(path)[0]);
5297 gtk_icon_view_unselect_item (icon_view, item);
5301 * gtk_icon_view_get_selected_items:
5302 * @icon_view: A #GtkIconView.
5304 * Creates a list of paths of all selected items. Additionally, if you are
5305 * planning on modifying the model after calling this function, you may
5306 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5307 * To do this, you can use gtk_tree_row_reference_new().
5309 * To free the return value, use:
5310 * <informalexample><programlisting>
5311 * g_list_foreach (list, gtk_tree_path_free, NULL);
5312 * g_list_free (list);
5313 * </programlisting></informalexample>
5315 * Return value: A #GList containing a #GtkTreePath for each selected row.
5320 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5323 GList *selected = NULL;
5325 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5327 for (list = icon_view->priv->items; list != NULL; list = list->next)
5329 GtkIconViewItem *item = list->data;
5333 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5335 selected = g_list_prepend (selected, path);
5343 * gtk_icon_view_select_all:
5344 * @icon_view: A #GtkIconView.
5346 * Selects all the icons. @icon_view must has its selection mode set
5347 * to #GTK_SELECTION_MULTIPLE.
5352 gtk_icon_view_select_all (GtkIconView *icon_view)
5355 gboolean dirty = FALSE;
5357 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5359 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5362 for (items = icon_view->priv->items; items; items = items->next)
5364 GtkIconViewItem *item = items->data;
5366 if (!item->selected)
5369 item->selected = TRUE;
5370 gtk_icon_view_queue_draw_item (icon_view, item);
5375 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5379 * gtk_icon_view_unselect_all:
5380 * @icon_view: A #GtkIconView.
5382 * Unselects all the icons.
5387 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5389 gboolean dirty = FALSE;
5391 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5393 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5396 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5399 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5403 * gtk_icon_view_path_is_selected:
5404 * @icon_view: A #GtkIconView.
5405 * @path: A #GtkTreePath to check selection on.
5407 * Returns %TRUE if the icon pointed to by @path is currently
5408 * selected. If @path does not point to a valid location, %FALSE is returned.
5410 * Return value: %TRUE if @path is selected.
5415 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5418 GtkIconViewItem *item;
5420 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5421 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5422 g_return_val_if_fail (path != NULL, FALSE);
5424 item = g_list_nth_data (icon_view->priv->items,
5425 gtk_tree_path_get_indices(path)[0]);
5430 return item->selected;
5434 * gtk_icon_view_item_activated:
5435 * @icon_view: A #GtkIconView
5436 * @path: The #GtkTreePath to be activated
5438 * Activates the item determined by @path.
5443 gtk_icon_view_item_activated (GtkIconView *icon_view,
5446 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5447 g_return_if_fail (path != NULL);
5449 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5453 * gtk_icon_view_set_orientation:
5454 * @icon_view: a #GtkIconView
5455 * @orientation: the relative position of texts and icons
5457 * Sets the ::orientation property which determines whether the labels
5458 * are drawn beside the icons instead of below.
5463 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5464 GtkOrientation orientation)
5466 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5468 if (icon_view->priv->orientation != orientation)
5470 icon_view->priv->orientation = orientation;
5472 gtk_icon_view_stop_editing (icon_view, TRUE);
5473 gtk_icon_view_invalidate_sizes (icon_view);
5474 gtk_icon_view_queue_layout (icon_view);
5476 update_text_cell (icon_view);
5477 update_pixbuf_cell (icon_view);
5479 g_object_notify (G_OBJECT (icon_view), "orientation");
5484 * gtk_icon_view_get_orientation:
5485 * @icon_view: a #GtkIconView
5487 * Returns the value of the ::orientation property which determines
5488 * whether the labels are drawn beside the icons instead of below.
5490 * Return value: the relative position of texts and icons
5495 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5497 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5498 GTK_ORIENTATION_VERTICAL);
5500 return icon_view->priv->orientation;
5504 * gtk_icon_view_set_columns:
5505 * @icon_view: a #GtkIconView
5506 * @columns: the number of columns
5508 * Sets the ::columns property which determines in how
5509 * many columns the icons are arranged. If @columns is
5510 * -1, the number of columns will be chosen automatically
5511 * to fill the available area.
5516 gtk_icon_view_set_columns (GtkIconView *icon_view,
5519 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5521 if (icon_view->priv->columns != columns)
5523 icon_view->priv->columns = columns;
5525 gtk_icon_view_stop_editing (icon_view, TRUE);
5526 gtk_icon_view_queue_layout (icon_view);
5528 g_object_notify (G_OBJECT (icon_view), "columns");
5533 * gtk_icon_view_get_columns:
5534 * @icon_view: a #GtkIconView
5536 * Returns the value of the ::columns property.
5538 * Return value: the number of columns, or -1
5543 gtk_icon_view_get_columns (GtkIconView *icon_view)
5545 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5547 return icon_view->priv->columns;
5551 * gtk_icon_view_set_item_width:
5552 * @icon_view: a #GtkIconView
5553 * @item_width: the width for each item
5555 * Sets the ::item-width property which specifies the width
5556 * to use for each item. If it is set to -1, the icon view will
5557 * automatically determine a suitable item size.
5562 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5565 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5567 if (icon_view->priv->item_width != item_width)
5569 icon_view->priv->item_width = item_width;
5571 gtk_icon_view_stop_editing (icon_view, TRUE);
5572 gtk_icon_view_invalidate_sizes (icon_view);
5573 gtk_icon_view_queue_layout (icon_view);
5575 update_text_cell (icon_view);
5577 g_object_notify (G_OBJECT (icon_view), "item-width");
5582 * gtk_icon_view_get_item_width:
5583 * @icon_view: a #GtkIconView
5585 * Returns the value of the ::item-width property.
5587 * Return value: the width of a single item, or -1
5592 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5594 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5596 return icon_view->priv->item_width;
5601 * gtk_icon_view_set_spacing:
5602 * @icon_view: a #GtkIconView
5603 * @spacing: the spacing
5605 * Sets the ::spacing property which specifies the space
5606 * which is inserted between the cells (i.e. the icon and
5607 * the text) of an item.
5612 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5615 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5617 if (icon_view->priv->spacing != spacing)
5619 icon_view->priv->spacing = spacing;
5621 gtk_icon_view_stop_editing (icon_view, TRUE);
5622 gtk_icon_view_invalidate_sizes (icon_view);
5623 gtk_icon_view_queue_layout (icon_view);
5625 g_object_notify (G_OBJECT (icon_view), "spacing");
5630 * gtk_icon_view_get_spacing:
5631 * @icon_view: a #GtkIconView
5633 * Returns the value of the ::spacing property.
5635 * Return value: the space between cells
5640 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5642 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5644 return icon_view->priv->spacing;
5648 * gtk_icon_view_set_row_spacing:
5649 * @icon_view: a #GtkIconView
5650 * @row_spacing: the row spacing
5652 * Sets the ::row-spacing property which specifies the space
5653 * which is inserted between the rows of the icon view.
5658 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5661 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5663 if (icon_view->priv->row_spacing != row_spacing)
5665 icon_view->priv->row_spacing = row_spacing;
5667 gtk_icon_view_stop_editing (icon_view, TRUE);
5668 gtk_icon_view_invalidate_sizes (icon_view);
5669 gtk_icon_view_queue_layout (icon_view);
5671 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5676 * gtk_icon_view_get_row_spacing:
5677 * @icon_view: a #GtkIconView
5679 * Returns the value of the ::row-spacing property.
5681 * Return value: the space between rows
5686 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5688 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5690 return icon_view->priv->row_spacing;
5694 * gtk_icon_view_set_column_spacing:
5695 * @icon_view: a #GtkIconView
5696 * @column_spacing: the column spacing
5698 * Sets the ::column-spacing property which specifies the space
5699 * which is inserted between the columns of the icon view.
5704 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5705 gint column_spacing)
5707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5709 if (icon_view->priv->column_spacing != column_spacing)
5711 icon_view->priv->column_spacing = column_spacing;
5713 gtk_icon_view_stop_editing (icon_view, TRUE);
5714 gtk_icon_view_invalidate_sizes (icon_view);
5715 gtk_icon_view_queue_layout (icon_view);
5717 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5722 * gtk_icon_view_get_column_spacing:
5723 * @icon_view: a #GtkIconView
5725 * Returns the value of the ::column-spacing property.
5727 * Return value: the space between columns
5732 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5734 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5736 return icon_view->priv->column_spacing;
5740 * gtk_icon_view_set_margin:
5741 * @icon_view: a #GtkIconView
5742 * @margin: the margin
5744 * Sets the ::margin property which specifies the space
5745 * which is inserted at the top, bottom, left and right
5751 gtk_icon_view_set_margin (GtkIconView *icon_view,
5754 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5756 if (icon_view->priv->margin != margin)
5758 icon_view->priv->margin = margin;
5760 gtk_icon_view_stop_editing (icon_view, TRUE);
5761 gtk_icon_view_invalidate_sizes (icon_view);
5762 gtk_icon_view_queue_layout (icon_view);
5764 g_object_notify (G_OBJECT (icon_view), "margin");
5769 * gtk_icon_view_get_margin:
5770 * @icon_view: a #GtkIconView
5772 * Returns the value of the ::margin property.
5774 * Return value: the space at the borders
5779 gtk_icon_view_get_margin (GtkIconView *icon_view)
5781 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5783 return icon_view->priv->margin;
5787 /* Get/set whether drag_motion requested the drag data and
5788 * drag_data_received should thus not actually insert the data,
5789 * since the data doesn't result from a drop.
5792 set_status_pending (GdkDragContext *context,
5793 GdkDragAction suggested_action)
5795 g_object_set_data (G_OBJECT (context),
5796 I_("gtk-icon-view-status-pending"),
5797 GINT_TO_POINTER (suggested_action));
5800 static GdkDragAction
5801 get_status_pending (GdkDragContext *context)
5803 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5804 "gtk-icon-view-status-pending"));
5808 unset_reorderable (GtkIconView *icon_view)
5810 if (icon_view->priv->reorderable)
5812 icon_view->priv->reorderable = FALSE;
5813 g_object_notify (G_OBJECT (icon_view), "reorderable");
5818 clear_source_info (GtkIconView *icon_view)
5820 if (icon_view->priv->source_targets)
5821 gtk_target_list_unref (icon_view->priv->source_targets);
5822 icon_view->priv->source_targets = NULL;
5824 icon_view->priv->source_set = FALSE;
5828 clear_dest_info (GtkIconView *icon_view)
5830 if (icon_view->priv->dest_targets)
5831 gtk_target_list_unref (icon_view->priv->dest_targets);
5832 icon_view->priv->dest_targets = NULL;
5834 icon_view->priv->dest_set = FALSE;
5838 set_source_row (GdkDragContext *context,
5839 GtkTreeModel *model,
5840 GtkTreePath *source_row)
5843 g_object_set_data_full (G_OBJECT (context),
5844 I_("gtk-icon-view-source-row"),
5845 gtk_tree_row_reference_new (model, source_row),
5846 (GDestroyNotify) gtk_tree_row_reference_free);
5848 g_object_set_data_full (G_OBJECT (context),
5849 I_("gtk-icon-view-source-row"),
5854 get_source_row (GdkDragContext *context)
5856 GtkTreeRowReference *ref;
5858 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5861 return gtk_tree_row_reference_get_path (ref);
5868 GtkTreeRowReference *dest_row;
5869 gboolean empty_view_drop;
5870 gboolean drop_append_mode;
5874 dest_row_free (gpointer data)
5876 DestRow *dr = (DestRow *)data;
5878 gtk_tree_row_reference_free (dr->dest_row);
5883 set_dest_row (GdkDragContext *context,
5884 GtkTreeModel *model,
5885 GtkTreePath *dest_row,
5886 gboolean empty_view_drop,
5887 gboolean drop_append_mode)
5893 g_object_set_data_full (G_OBJECT (context),
5894 I_("gtk-icon-view-dest-row"),
5899 dr = g_new0 (DestRow, 1);
5901 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5902 dr->empty_view_drop = empty_view_drop;
5903 dr->drop_append_mode = drop_append_mode;
5904 g_object_set_data_full (G_OBJECT (context),
5905 I_("gtk-icon-view-dest-row"),
5906 dr, (GDestroyNotify) dest_row_free);
5910 get_dest_row (GdkDragContext *context)
5914 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5918 GtkTreePath *path = NULL;
5921 path = gtk_tree_row_reference_get_path (dr->dest_row);
5922 else if (dr->empty_view_drop)
5923 path = gtk_tree_path_new_from_indices (0, -1);
5927 if (path && dr->drop_append_mode)
5928 gtk_tree_path_next (path);
5937 check_model_dnd (GtkTreeModel *model,
5938 GType required_iface,
5939 const gchar *signal)
5941 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5943 g_warning ("You must override the default '%s' handler "
5944 "on GtkIconView when using models that don't support "
5945 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5946 "is to connect to '%s' and call "
5947 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5948 "the default handler from running. Look at the source code "
5949 "for the default handler in gtkiconview.c to get an idea what "
5950 "your handler should do. (gtkiconview.c is in the GTK+ source "
5951 "code.) If you're using GTK+ from a language other than C, "
5952 "there may be a more natural way to override default handlers, e.g. via derivation.",
5953 signal, g_type_name (required_iface), signal);
5961 remove_scroll_timeout (GtkIconView *icon_view)
5963 if (icon_view->priv->scroll_timeout_id != 0)
5965 g_source_remove (icon_view->priv->scroll_timeout_id);
5967 icon_view->priv->scroll_timeout_id = 0;
5972 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5974 gint px, py, x, y, width, height;
5975 gint hoffset, voffset;
5978 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5979 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5981 /* see if we are near the edge. */
5982 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5984 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5986 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5988 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5992 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5993 icon_view->priv->vadjustment->lower,
5994 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5995 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5999 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6000 icon_view->priv->hadjustment->lower,
6001 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6002 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6008 drag_scroll_timeout (gpointer data)
6010 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6012 gtk_icon_view_autoscroll (icon_view);
6019 set_destination (GtkIconView *icon_view,
6020 GdkDragContext *context,
6023 GdkDragAction *suggested_action,
6027 GtkTreePath *path = NULL;
6028 GtkIconViewDropPosition pos;
6029 GtkIconViewDropPosition old_pos;
6030 GtkTreePath *old_dest_path = NULL;
6031 gboolean can_drop = FALSE;
6033 widget = GTK_WIDGET (icon_view);
6035 *suggested_action = 0;
6038 if (!icon_view->priv->dest_set)
6040 /* someone unset us as a drag dest, note that if
6041 * we return FALSE drag_leave isn't called
6044 gtk_icon_view_set_drag_dest_item (icon_view,
6046 GTK_ICON_VIEW_DROP_LEFT);
6048 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6050 return FALSE; /* no longer a drop site */
6053 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6054 if (*target == GDK_NONE)
6057 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6060 GtkTreeModel *model;
6062 /* the row got dropped on empty space, let's setup a special case
6066 gtk_tree_path_free (path);
6068 model = gtk_icon_view_get_model (icon_view);
6070 n_children = gtk_tree_model_iter_n_children (model, NULL);
6073 pos = GTK_ICON_VIEW_DROP_BELOW;
6074 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6078 pos = GTK_ICON_VIEW_DROP_ABOVE;
6079 path = gtk_tree_path_new_from_indices (0, -1);
6089 gtk_icon_view_get_drag_dest_item (icon_view,
6094 gtk_tree_path_free (old_dest_path);
6096 if (TRUE /* FIXME if the location droppable predicate */)
6104 GtkWidget *source_widget;
6106 *suggested_action = context->suggested_action;
6107 source_widget = gtk_drag_get_source_widget (context);
6109 if (source_widget == widget)
6111 /* Default to MOVE, unless the user has
6112 * pressed ctrl or shift to affect available actions
6114 if ((context->actions & GDK_ACTION_MOVE) != 0)
6115 *suggested_action = GDK_ACTION_MOVE;
6118 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6123 /* can't drop here */
6124 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6126 GTK_ICON_VIEW_DROP_LEFT);
6130 gtk_tree_path_free (path);
6136 get_logical_destination (GtkIconView *icon_view,
6137 gboolean *drop_append_mode)
6139 /* adjust path to point to the row the drop goes in front of */
6140 GtkTreePath *path = NULL;
6141 GtkIconViewDropPosition pos;
6143 *drop_append_mode = FALSE;
6145 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6150 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6151 pos == GTK_ICON_VIEW_DROP_BELOW)
6154 GtkTreeModel *model = icon_view->priv->model;
6156 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6157 !gtk_tree_model_iter_next (model, &iter))
6158 *drop_append_mode = TRUE;
6161 *drop_append_mode = FALSE;
6162 gtk_tree_path_next (path);
6170 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6171 GdkEventMotion *event)
6173 GdkDragContext *context;
6174 GtkTreePath *path = NULL;
6176 GtkTreeModel *model;
6177 gboolean retval = FALSE;
6179 if (!icon_view->priv->source_set)
6182 if (icon_view->priv->pressed_button < 0)
6185 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6186 icon_view->priv->press_start_x,
6187 icon_view->priv->press_start_y,
6188 event->x, event->y))
6191 model = gtk_icon_view_get_model (icon_view);
6196 button = icon_view->priv->pressed_button;
6197 icon_view->priv->pressed_button = -1;
6199 path = gtk_icon_view_get_path_at_pos (icon_view,
6200 icon_view->priv->press_start_x,
6201 icon_view->priv->press_start_y);
6206 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6207 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6211 /* FIXME Check whether we're a start button, if not return FALSE and
6215 /* Now we can begin the drag */
6219 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6220 icon_view->priv->source_targets,
6221 icon_view->priv->source_actions,
6225 set_source_row (context, model, path);
6229 gtk_tree_path_free (path);
6234 /* Source side drag signals */
6236 gtk_icon_view_drag_begin (GtkWidget *widget,
6237 GdkDragContext *context)
6239 GtkIconView *icon_view;
6240 GtkIconViewItem *item;
6245 icon_view = GTK_ICON_VIEW (widget);
6247 /* if the user uses a custom DnD impl, we don't set the icon here */
6248 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6251 item = gtk_icon_view_get_item_at_coords (icon_view,
6252 icon_view->priv->press_start_x,
6253 icon_view->priv->press_start_y,
6257 g_return_if_fail (item != NULL);
6259 x = icon_view->priv->press_start_x - item->x + 1;
6260 y = icon_view->priv->press_start_y - item->y + 1;
6262 path = gtk_tree_path_new_from_indices (item->index, -1);
6263 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6264 gtk_tree_path_free (path);
6266 gtk_drag_set_icon_pixmap (context,
6267 gdk_drawable_get_colormap (icon),
6272 g_object_unref (icon);
6276 gtk_icon_view_drag_end (GtkWidget *widget,
6277 GdkDragContext *context)
6283 gtk_icon_view_drag_data_get (GtkWidget *widget,
6284 GdkDragContext *context,
6285 GtkSelectionData *selection_data,
6289 GtkIconView *icon_view;
6290 GtkTreeModel *model;
6291 GtkTreePath *source_row;
6293 icon_view = GTK_ICON_VIEW (widget);
6294 model = gtk_icon_view_get_model (icon_view);
6299 if (!icon_view->priv->dest_set)
6302 source_row = get_source_row (context);
6304 if (source_row == NULL)
6307 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6308 * any model; for DragSource models there are some other targets
6312 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6313 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6318 /* If drag_data_get does nothing, try providing row data. */
6319 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6320 gtk_tree_set_row_drag_data (selection_data,
6325 gtk_tree_path_free (source_row);
6329 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6330 GdkDragContext *context)
6332 GtkTreeModel *model;
6333 GtkIconView *icon_view;
6334 GtkTreePath *source_row;
6336 icon_view = GTK_ICON_VIEW (widget);
6337 model = gtk_icon_view_get_model (icon_view);
6339 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6342 if (!icon_view->priv->dest_set)
6345 source_row = get_source_row (context);
6347 if (source_row == NULL)
6350 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6353 gtk_tree_path_free (source_row);
6355 set_source_row (context, NULL, NULL);
6358 /* Target side drag signals */
6360 gtk_icon_view_drag_leave (GtkWidget *widget,
6361 GdkDragContext *context,
6364 GtkIconView *icon_view;
6366 icon_view = GTK_ICON_VIEW (widget);
6368 /* unset any highlight row */
6369 gtk_icon_view_set_drag_dest_item (icon_view,
6371 GTK_ICON_VIEW_DROP_LEFT);
6373 remove_scroll_timeout (icon_view);
6377 gtk_icon_view_drag_motion (GtkWidget *widget,
6378 GdkDragContext *context,
6383 GtkTreePath *path = NULL;
6384 GtkIconViewDropPosition pos;
6385 GtkIconView *icon_view;
6386 GdkDragAction suggested_action = 0;
6390 icon_view = GTK_ICON_VIEW (widget);
6392 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6395 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6397 /* we only know this *after* set_desination_row */
6398 empty = icon_view->priv->empty_view_drop;
6400 if (path == NULL && !empty)
6402 /* Can't drop here. */
6403 gdk_drag_status (context, 0, time);
6407 if (icon_view->priv->scroll_timeout_id == 0)
6409 icon_view->priv->scroll_timeout_id =
6410 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6413 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6415 /* Request data so we can use the source row when
6416 * determining whether to accept the drop
6418 set_status_pending (context, suggested_action);
6419 gtk_drag_get_data (widget, context, target, time);
6423 set_status_pending (context, 0);
6424 gdk_drag_status (context, suggested_action, time);
6429 gtk_tree_path_free (path);
6435 gtk_icon_view_drag_drop (GtkWidget *widget,
6436 GdkDragContext *context,
6441 GtkIconView *icon_view;
6443 GdkDragAction suggested_action = 0;
6444 GdkAtom target = GDK_NONE;
6445 GtkTreeModel *model;
6446 gboolean drop_append_mode;
6448 icon_view = GTK_ICON_VIEW (widget);
6449 model = gtk_icon_view_get_model (icon_view);
6451 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6453 if (!icon_view->priv->dest_set)
6456 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6459 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6462 path = get_logical_destination (icon_view, &drop_append_mode);
6464 if (target != GDK_NONE && path != NULL)
6466 /* in case a motion had requested drag data, change things so we
6467 * treat drag data receives as a drop.
6469 set_status_pending (context, 0);
6470 set_dest_row (context, model, path,
6471 icon_view->priv->empty_view_drop, drop_append_mode);
6475 gtk_tree_path_free (path);
6477 /* Unset this thing */
6478 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6480 if (target != GDK_NONE)
6482 gtk_drag_get_data (widget, context, target, time);
6490 gtk_icon_view_drag_data_received (GtkWidget *widget,
6491 GdkDragContext *context,
6494 GtkSelectionData *selection_data,
6499 gboolean accepted = FALSE;
6500 GtkTreeModel *model;
6501 GtkIconView *icon_view;
6502 GtkTreePath *dest_row;
6503 GdkDragAction suggested_action;
6504 gboolean drop_append_mode;
6506 icon_view = GTK_ICON_VIEW (widget);
6507 model = gtk_icon_view_get_model (icon_view);
6509 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6512 if (!icon_view->priv->dest_set)
6515 suggested_action = get_status_pending (context);
6517 if (suggested_action)
6519 /* We are getting this data due to a request in drag_motion,
6520 * rather than due to a request in drag_drop, so we are just
6521 * supposed to call drag_status, not actually paste in the
6524 path = get_logical_destination (icon_view, &drop_append_mode);
6527 suggested_action = 0;
6529 if (suggested_action)
6531 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6534 suggested_action = 0;
6537 gdk_drag_status (context, suggested_action, time);
6540 gtk_tree_path_free (path);
6542 /* If you can't drop, remove user drop indicator until the next motion */
6543 if (suggested_action == 0)
6544 gtk_icon_view_set_drag_dest_item (icon_view,
6546 GTK_ICON_VIEW_DROP_LEFT);
6551 dest_row = get_dest_row (context);
6553 if (dest_row == NULL)
6556 if (selection_data->length >= 0)
6558 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6564 gtk_drag_finish (context,
6566 (context->action == GDK_ACTION_MOVE),
6569 gtk_tree_path_free (dest_row);
6572 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6575 /* Drag-and-Drop support */
6577 * gtk_icon_view_enable_model_drag_source:
6578 * @icon_view: a #GtkIconTreeView
6579 * @start_button_mask: Mask of allowed buttons to start drag
6580 * @targets: the table of targets that the drag will support
6581 * @n_targets: the number of items in @targets
6582 * @actions: the bitmask of possible actions for a drag from this
6585 * Turns @icon_view into a drag source for automatic DND.
6590 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6591 GdkModifierType start_button_mask,
6592 const GtkTargetEntry *targets,
6594 GdkDragAction actions)
6596 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6598 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6600 clear_source_info (icon_view);
6601 icon_view->priv->start_button_mask = start_button_mask;
6602 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6603 icon_view->priv->source_actions = actions;
6605 icon_view->priv->source_set = TRUE;
6607 unset_reorderable (icon_view);
6611 * gtk_icon_view_enable_model_drag_dest:
6612 * @icon_view: a #GtkIconView
6613 * @targets: the table of targets that the drag will support
6614 * @n_targets: the number of items in @targets
6615 * @actions: the bitmask of possible actions for a drag to this
6618 * Turns @icon_view into a drop destination for automatic DND.
6623 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6624 const GtkTargetEntry *targets,
6626 GdkDragAction actions)
6628 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6630 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6632 clear_dest_info (icon_view);
6634 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6635 icon_view->priv->dest_actions = actions;
6637 icon_view->priv->dest_set = TRUE;
6639 unset_reorderable (icon_view);
6643 * gtk_icon_view_unset_model_drag_source:
6644 * @icon_view: a #GtkIconView
6646 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6651 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6653 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6655 if (icon_view->priv->source_set)
6657 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6658 clear_source_info (icon_view);
6661 unset_reorderable (icon_view);
6665 * gtk_icon_view_unset_model_drag_dest:
6666 * @icon_view: a #GtkIconView
6668 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6673 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6675 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6677 if (icon_view->priv->dest_set)
6679 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6680 clear_dest_info (icon_view);
6683 unset_reorderable (icon_view);
6686 /* These are useful to implement your own custom stuff. */
6688 * gtk_icon_view_set_drag_dest_item:
6689 * @icon_view: a #GtkIconView
6690 * @path: The path of the item to highlight, or %NULL.
6691 * @pos: Specifies where to drop, relative to the item
6693 * Sets the item that is highlighted for feedback.
6698 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6700 GtkIconViewDropPosition pos)
6702 /* Note; this function is exported to allow a custom DND
6703 * implementation, so it can't touch TreeViewDragInfo
6706 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6708 if (icon_view->priv->dest_item)
6710 GtkTreePath *current_path;
6711 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6712 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6713 icon_view->priv->dest_item = NULL;
6715 gtk_icon_view_queue_draw_path (icon_view, current_path);
6716 gtk_tree_path_free (current_path);
6719 /* special case a drop on an empty model */
6720 icon_view->priv->empty_view_drop = FALSE;
6721 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6722 && gtk_tree_path_get_depth (path) == 1
6723 && gtk_tree_path_get_indices (path)[0] == 0)
6727 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6730 if (n_children == 0)
6731 icon_view->priv->empty_view_drop = TRUE;
6734 icon_view->priv->dest_pos = pos;
6738 icon_view->priv->dest_item =
6739 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6740 icon_view->priv->model, path);
6742 gtk_icon_view_queue_draw_path (icon_view, path);
6747 * gtk_icon_view_get_drag_dest_item:
6748 * @icon_view: a #GtkIconView
6749 * @path: Return location for the path of the highlighted item, or %NULL.
6750 * @pos: Return location for the drop position, or %NULL
6752 * Gets information about the item that is highlighted for feedback.
6757 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6759 GtkIconViewDropPosition *pos)
6761 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6765 if (icon_view->priv->dest_item)
6766 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6772 *pos = icon_view->priv->dest_pos;
6776 * gtk_icon_view_get_dest_item_at_pos:
6777 * @icon_view: a #GtkIconView
6778 * @drag_x: the position to determine the destination item for
6779 * @drag_y: the position to determine the destination item for
6780 * @path: Return location for the path of the item, or %NULL.
6781 * @pos: Return location for the drop position, or %NULL
6783 * Determines the destination item for a given position.
6785 * Return value: whether there is an item at the given position.
6790 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6794 GtkIconViewDropPosition *pos)
6796 GtkIconViewItem *item;
6798 /* Note; this function is exported to allow a custom DND
6799 * implementation, so it can't touch TreeViewDragInfo
6802 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6803 g_return_val_if_fail (drag_x >= 0, FALSE);
6804 g_return_val_if_fail (drag_y >= 0, FALSE);
6805 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6811 item = gtk_icon_view_get_item_at_coords (icon_view,
6812 drag_x + icon_view->priv->hadjustment->value,
6813 drag_y + icon_view->priv->vadjustment->value,
6820 *path = gtk_tree_path_new_from_indices (item->index, -1);
6824 if (drag_x < item->x + item->width / 4)
6825 *pos = GTK_ICON_VIEW_DROP_LEFT;
6826 else if (drag_x > item->x + item->width * 3 / 4)
6827 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6828 else if (drag_y < item->y + item->height / 4)
6829 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6830 else if (drag_y > item->y + item->height * 3 / 4)
6831 *pos = GTK_ICON_VIEW_DROP_BELOW;
6833 *pos = GTK_ICON_VIEW_DROP_INTO;
6840 * gtk_icon_view_create_drag_icon:
6841 * @icon_view: a #GtkIconView
6842 * @path: a #GtkTreePath in @icon_view
6844 * Creates a #GdkPixmap representation of the item at @path.
6845 * This image is used for a drag icon.
6847 * Return value: a newly-allocated pixmap of the drag icon.
6852 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6857 GdkPixmap *drawable;
6862 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6863 g_return_val_if_fail (path != NULL, NULL);
6865 widget = GTK_WIDGET (icon_view);
6867 if (!GTK_WIDGET_REALIZED (widget))
6870 index = gtk_tree_path_get_indices (path)[0];
6872 for (l = icon_view->priv->items; l; l = l->next)
6874 GtkIconViewItem *item = l->data;
6876 if (index == item->index)
6878 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6883 cr = gdk_cairo_create (drawable);
6884 cairo_set_line_width (cr, 1.);
6886 gdk_cairo_set_source_color
6887 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6888 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6893 area.width = item->width;
6894 area.height = item->height;
6896 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6897 drawable, 1, 1, FALSE);
6899 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6900 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6913 * gtk_icon_view_get_reorderable:
6914 * @icon_view: a #GtkIconView
6916 * Retrieves whether the user can reorder the list via drag-and-drop.
6917 * See gtk_icon_view_set_reorderable().
6919 * Return value: %TRUE if the list can be reordered.
6924 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6926 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6928 return icon_view->priv->reorderable;
6931 static const GtkTargetEntry item_targets[] = {
6932 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6937 * gtk_icon_view_set_reorderable:
6938 * @icon_view: A #GtkIconView.
6939 * @reorderable: %TRUE, if the list of items can be reordered.
6941 * This function is a convenience function to allow you to reorder models that
6942 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6943 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6944 * the user can reorder the model by dragging and dropping rows. The
6945 * developer can listen to these changes by connecting to the model's
6946 * row_inserted and row_deleted signals.
6948 * This function does not give you any degree of control over the order -- any
6949 * reordering is allowed. If more control is needed, you should probably
6950 * handle drag and drop manually.
6955 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6956 gboolean reorderable)
6958 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6960 reorderable = reorderable != FALSE;
6962 if (icon_view->priv->reorderable == reorderable)
6967 gtk_icon_view_enable_model_drag_source (icon_view,
6970 G_N_ELEMENTS (item_targets),
6972 gtk_icon_view_enable_model_drag_dest (icon_view,
6974 G_N_ELEMENTS (item_targets),
6979 gtk_icon_view_unset_model_drag_source (icon_view);
6980 gtk_icon_view_unset_model_drag_dest (icon_view);
6983 icon_view->priv->reorderable = reorderable;
6985 g_object_notify (G_OBJECT (icon_view), "reorderable");
6989 /* Accessibility Support */
6991 static gpointer accessible_parent_class;
6992 static gpointer accessible_item_parent_class;
6993 static GQuark accessible_private_data_quark = 0;
6995 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6996 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6997 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6999 static GType gtk_icon_view_item_accessible_get_type (void);
7010 GtkIconViewItem *item;
7014 AtkStateSet *state_set;
7018 GtkTextBuffer *text_buffer;
7020 gchar *action_descriptions[LAST_ACTION];
7021 gchar *image_description;
7022 guint action_idle_handler;
7023 } GtkIconViewItemAccessible;
7025 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7031 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7036 typedef struct _GtkIconViewItemAccessibleClass
7038 AtkObjectClass parent_class;
7040 } GtkIconViewItemAccessibleClass;
7042 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7045 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7047 GtkIconViewItemAccessible *item;
7048 GtkIconView *icon_view;
7051 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7052 item->action_idle_handler = 0;
7054 if (item->widget != NULL)
7056 icon_view = GTK_ICON_VIEW (item->widget);
7057 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7058 gtk_icon_view_item_activated (icon_view, path);
7059 gtk_tree_path_free (path);
7066 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7069 GtkIconViewItemAccessible *item;
7071 if (i < 0 || i >= LAST_ACTION)
7074 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7076 if (!GTK_IS_ICON_VIEW (item->widget))
7079 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7084 case ACTION_ACTIVATE:
7085 if (!item->action_idle_handler)
7086 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7089 g_assert_not_reached ();
7097 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7102 static const gchar *
7103 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7106 GtkIconViewItemAccessible *item;
7108 if (i < 0 || i >= LAST_ACTION)
7111 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7113 if (item->action_descriptions[i])
7114 return item->action_descriptions[i];
7116 return gtk_icon_view_item_accessible_action_descriptions[i];
7119 static const gchar *
7120 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7123 if (i < 0 || i >= LAST_ACTION)
7126 return gtk_icon_view_item_accessible_action_names[i];
7130 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7132 const gchar *description)
7134 GtkIconViewItemAccessible *item;
7136 if (i < 0 || i >= LAST_ACTION)
7139 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7141 g_free (item->action_descriptions[i]);
7143 item->action_descriptions[i] = g_strdup (description);
7149 atk_action_item_interface_init (AtkActionIface *iface)
7151 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7152 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7153 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7154 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7155 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7158 static const gchar *
7159 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7161 GtkIconViewItemAccessible *item;
7163 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7165 return item->image_description;
7169 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7170 const gchar *description)
7172 GtkIconViewItemAccessible *item;
7174 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7176 g_free (item->image_description);
7177 item->image_description = g_strdup (item->image_description);
7183 get_pixbuf_box (GtkIconView *icon_view,
7184 GtkIconViewItem *item,
7189 for (l = icon_view->priv->cell_list; l; l = l->next)
7191 GtkIconViewCellInfo *info = l->data;
7193 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7195 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7205 get_text (GtkIconView *icon_view,
7206 GtkIconViewItem *item)
7211 for (l = icon_view->priv->cell_list; l; l = l->next)
7213 GtkIconViewCellInfo *info = l->data;
7215 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7217 g_object_get (info->cell, "text", &text, NULL);
7227 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7231 GtkIconViewItemAccessible *item;
7234 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7236 if (!GTK_IS_ICON_VIEW (item->widget))
7239 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7242 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7245 *height = box.height;
7250 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7253 AtkCoordType coord_type)
7255 GtkIconViewItemAccessible *item;
7258 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7260 if (!GTK_IS_ICON_VIEW (item->widget))
7263 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7266 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7268 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7270 *x+= box.x - item->item->x;
7271 *y+= box.y - item->item->y;
7277 atk_image_item_interface_init (AtkImageIface *iface)
7279 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7280 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7281 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7282 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7286 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7290 GtkIconViewItemAccessible *item;
7291 GtkTextIter start, end;
7292 GtkTextBuffer *buffer;
7294 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7296 if (!GTK_IS_ICON_VIEW (item->widget))
7299 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7302 buffer = item->text_buffer;
7303 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7305 gtk_text_buffer_get_end_iter (buffer, &end);
7307 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7309 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7313 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7316 GtkIconViewItemAccessible *item;
7317 GtkTextIter start, end;
7318 GtkTextBuffer *buffer;
7322 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7324 if (!GTK_IS_ICON_VIEW (item->widget))
7327 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7330 buffer = item->text_buffer;
7331 if (offset >= gtk_text_buffer_get_char_count (buffer))
7334 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7336 gtk_text_iter_forward_char (&end);
7337 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7338 unichar = g_utf8_get_char (string);
7346 get_pango_text_offsets (PangoLayout *layout,
7347 GtkTextBuffer *buffer,
7349 AtkTextBoundary boundary_type,
7353 GtkTextIter *start_iter,
7354 GtkTextIter *end_iter)
7356 PangoLayoutIter *iter;
7357 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7358 gint index, start_index, end_index;
7360 gboolean found = FALSE;
7362 text = pango_layout_get_text (layout);
7363 index = g_utf8_offset_to_pointer (text, offset) - text;
7364 iter = pango_layout_get_iter (layout);
7367 line = pango_layout_iter_get_line_readonly (iter);
7368 start_index = line->start_index;
7369 end_index = start_index + line->length;
7371 if (index >= start_index && index <= end_index)
7374 * Found line for offset
7380 * We want the previous line
7384 switch (boundary_type)
7386 case ATK_TEXT_BOUNDARY_LINE_START:
7387 end_index = start_index;
7388 start_index = prev_line->start_index;
7390 case ATK_TEXT_BOUNDARY_LINE_END:
7392 start_index = prev_prev_line->start_index +
7393 prev_prev_line->length;
7394 end_index = prev_line->start_index + prev_line->length;
7397 g_assert_not_reached();
7401 start_index = end_index = 0;
7404 switch (boundary_type)
7406 case ATK_TEXT_BOUNDARY_LINE_START:
7407 if (pango_layout_iter_next_line (iter))
7408 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7410 case ATK_TEXT_BOUNDARY_LINE_END:
7412 start_index = prev_line->start_index +
7416 g_assert_not_reached();
7421 * We want the next line
7423 if (pango_layout_iter_next_line (iter))
7425 line = pango_layout_iter_get_line_readonly (iter);
7426 switch (boundary_type)
7428 case ATK_TEXT_BOUNDARY_LINE_START:
7429 start_index = line->start_index;
7430 if (pango_layout_iter_next_line (iter))
7431 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7433 end_index = start_index + line->length;
7435 case ATK_TEXT_BOUNDARY_LINE_END:
7436 start_index = end_index;
7437 end_index = line->start_index + line->length;
7440 g_assert_not_reached();
7444 start_index = end_index;
7450 prev_prev_line = prev_line;
7453 while (pango_layout_iter_next_line (iter));
7457 start_index = prev_line->start_index + prev_line->length;
7458 end_index = start_index;
7460 pango_layout_iter_free (iter);
7461 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7462 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7464 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7465 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7470 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7472 AtkTextBoundary boundary_type,
7476 GtkIconViewItemAccessible *item;
7477 GtkTextIter start, end;
7478 GtkTextBuffer *buffer;
7480 GtkIconView *icon_view;
7483 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7485 if (!GTK_IS_ICON_VIEW (item->widget))
7488 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7491 buffer = item->text_buffer;
7493 if (!gtk_text_buffer_get_char_count (buffer))
7497 return g_strdup ("");
7499 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7503 switch (boundary_type)
7505 case ATK_TEXT_BOUNDARY_CHAR:
7506 gtk_text_iter_backward_char(&start);
7508 case ATK_TEXT_BOUNDARY_WORD_START:
7509 if (!gtk_text_iter_starts_word (&start))
7510 gtk_text_iter_backward_word_start (&start);
7512 gtk_text_iter_backward_word_start(&start);
7514 case ATK_TEXT_BOUNDARY_WORD_END:
7515 if (gtk_text_iter_inside_word (&start) &&
7516 !gtk_text_iter_starts_word (&start))
7517 gtk_text_iter_backward_word_start (&start);
7518 while (!gtk_text_iter_ends_word (&start))
7520 if (!gtk_text_iter_backward_char (&start))
7524 gtk_text_iter_backward_word_start(&start);
7525 while (!gtk_text_iter_ends_word (&start))
7527 if (!gtk_text_iter_backward_char (&start))
7531 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7532 if (!gtk_text_iter_starts_sentence (&start))
7533 gtk_text_iter_backward_sentence_start (&start);
7535 gtk_text_iter_backward_sentence_start (&start);
7537 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7538 if (gtk_text_iter_inside_sentence (&start) &&
7539 !gtk_text_iter_starts_sentence (&start))
7540 gtk_text_iter_backward_sentence_start (&start);
7541 while (!gtk_text_iter_ends_sentence (&start))
7543 if (!gtk_text_iter_backward_char (&start))
7547 gtk_text_iter_backward_sentence_start (&start);
7548 while (!gtk_text_iter_ends_sentence (&start))
7550 if (!gtk_text_iter_backward_char (&start))
7554 case ATK_TEXT_BOUNDARY_LINE_START:
7555 case ATK_TEXT_BOUNDARY_LINE_END:
7557 icon_view = GTK_ICON_VIEW (item->widget);
7558 /* FIXME we probably have to use GailTextCell to salvage this */
7559 gtk_icon_view_update_item_text (icon_view, item->item);
7560 get_pango_text_offsets (icon_view->priv->layout,
7573 *start_offset = gtk_text_iter_get_offset (&start);
7574 *end_offset = gtk_text_iter_get_offset (&end);
7576 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7580 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7582 AtkTextBoundary boundary_type,
7586 GtkIconViewItemAccessible *item;
7587 GtkTextIter start, end;
7588 GtkTextBuffer *buffer;
7590 GtkIconView *icon_view;
7593 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7595 if (!GTK_IS_ICON_VIEW (item->widget))
7598 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7601 buffer = item->text_buffer;
7603 if (!gtk_text_buffer_get_char_count (buffer))
7607 return g_strdup ("");
7609 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7613 switch (boundary_type)
7615 case ATK_TEXT_BOUNDARY_CHAR:
7616 gtk_text_iter_forward_char (&end);
7618 case ATK_TEXT_BOUNDARY_WORD_START:
7619 if (!gtk_text_iter_starts_word (&start))
7620 gtk_text_iter_backward_word_start (&start);
7621 if (gtk_text_iter_inside_word (&end))
7622 gtk_text_iter_forward_word_end (&end);
7623 while (!gtk_text_iter_starts_word (&end))
7625 if (!gtk_text_iter_forward_char (&end))
7629 case ATK_TEXT_BOUNDARY_WORD_END:
7630 if (gtk_text_iter_inside_word (&start) &&
7631 !gtk_text_iter_starts_word (&start))
7632 gtk_text_iter_backward_word_start (&start);
7633 while (!gtk_text_iter_ends_word (&start))
7635 if (!gtk_text_iter_backward_char (&start))
7638 gtk_text_iter_forward_word_end (&end);
7640 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7641 if (!gtk_text_iter_starts_sentence (&start))
7642 gtk_text_iter_backward_sentence_start (&start);
7643 if (gtk_text_iter_inside_sentence (&end))
7644 gtk_text_iter_forward_sentence_end (&end);
7645 while (!gtk_text_iter_starts_sentence (&end))
7647 if (!gtk_text_iter_forward_char (&end))
7651 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7652 if (gtk_text_iter_inside_sentence (&start) &&
7653 !gtk_text_iter_starts_sentence (&start))
7654 gtk_text_iter_backward_sentence_start (&start);
7655 while (!gtk_text_iter_ends_sentence (&start))
7657 if (!gtk_text_iter_backward_char (&start))
7660 gtk_text_iter_forward_sentence_end (&end);
7662 case ATK_TEXT_BOUNDARY_LINE_START:
7663 case ATK_TEXT_BOUNDARY_LINE_END:
7665 icon_view = GTK_ICON_VIEW (item->widget);
7666 /* FIXME we probably have to use GailTextCell to salvage this */
7667 gtk_icon_view_update_item_text (icon_view, item->item);
7668 get_pango_text_offsets (icon_view->priv->layout,
7682 *start_offset = gtk_text_iter_get_offset (&start);
7683 *end_offset = gtk_text_iter_get_offset (&end);
7685 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7689 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7691 AtkTextBoundary boundary_type,
7695 GtkIconViewItemAccessible *item;
7696 GtkTextIter start, end;
7697 GtkTextBuffer *buffer;
7699 GtkIconView *icon_view;
7702 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7704 if (!GTK_IS_ICON_VIEW (item->widget))
7707 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7710 buffer = item->text_buffer;
7712 if (!gtk_text_buffer_get_char_count (buffer))
7716 return g_strdup ("");
7718 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7722 switch (boundary_type)
7724 case ATK_TEXT_BOUNDARY_CHAR:
7725 gtk_text_iter_forward_char(&start);
7726 gtk_text_iter_forward_chars(&end, 2);
7728 case ATK_TEXT_BOUNDARY_WORD_START:
7729 if (gtk_text_iter_inside_word (&end))
7730 gtk_text_iter_forward_word_end (&end);
7731 while (!gtk_text_iter_starts_word (&end))
7733 if (!gtk_text_iter_forward_char (&end))
7737 if (!gtk_text_iter_is_end (&end))
7739 gtk_text_iter_forward_word_end (&end);
7740 while (!gtk_text_iter_starts_word (&end))
7742 if (!gtk_text_iter_forward_char (&end))
7747 case ATK_TEXT_BOUNDARY_WORD_END:
7748 gtk_text_iter_forward_word_end (&end);
7750 if (!gtk_text_iter_is_end (&end))
7751 gtk_text_iter_forward_word_end (&end);
7753 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7754 if (gtk_text_iter_inside_sentence (&end))
7755 gtk_text_iter_forward_sentence_end (&end);
7756 while (!gtk_text_iter_starts_sentence (&end))
7758 if (!gtk_text_iter_forward_char (&end))
7762 if (!gtk_text_iter_is_end (&end))
7764 gtk_text_iter_forward_sentence_end (&end);
7765 while (!gtk_text_iter_starts_sentence (&end))
7767 if (!gtk_text_iter_forward_char (&end))
7772 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7773 gtk_text_iter_forward_sentence_end (&end);
7775 if (!gtk_text_iter_is_end (&end))
7776 gtk_text_iter_forward_sentence_end (&end);
7778 case ATK_TEXT_BOUNDARY_LINE_START:
7779 case ATK_TEXT_BOUNDARY_LINE_END:
7781 icon_view = GTK_ICON_VIEW (item->widget);
7782 /* FIXME we probably have to use GailTextCell to salvage this */
7783 gtk_icon_view_update_item_text (icon_view, item->item);
7784 get_pango_text_offsets (icon_view->priv->layout,
7796 *start_offset = gtk_text_iter_get_offset (&start);
7797 *end_offset = gtk_text_iter_get_offset (&end);
7799 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7803 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7805 GtkIconViewItemAccessible *item;
7807 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7809 if (!GTK_IS_ICON_VIEW (item->widget))
7812 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7815 return gtk_text_buffer_get_char_count (item->text_buffer);
7819 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7825 AtkCoordType coord_type)
7827 GtkIconViewItemAccessible *item;
7829 GtkIconView *icon_view;
7830 PangoRectangle char_rect;
7831 const gchar *item_text;
7835 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7837 if (!GTK_IS_ICON_VIEW (item->widget))
7840 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7844 icon_view = GTK_ICON_VIEW (item->widget);
7845 /* FIXME we probably have to use GailTextCell to salvage this */
7846 gtk_icon_view_update_item_text (icon_view, item->item);
7847 item_text = pango_layout_get_text (icon_view->priv->layout);
7848 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7849 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7851 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7852 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7853 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7854 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7855 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7856 *width = char_rect.width / PANGO_SCALE;
7857 *height = char_rect.height / PANGO_SCALE;
7862 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7865 AtkCoordType coord_type)
7867 GtkIconViewItemAccessible *item;
7870 GtkIconView *icon_view;
7871 const gchar *item_text;
7876 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7878 if (!GTK_IS_ICON_VIEW (item->widget))
7881 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7885 icon_view = GTK_ICON_VIEW (item->widget);
7886 /* FIXME we probably have to use GailTextCell to salvage this */
7887 gtk_icon_view_update_item_text (icon_view, item->item);
7888 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7889 x -= l_x + item->item->layout_x - item->item->x;
7890 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7891 y -= l_y + item->item->layout_y - item->item->y;
7892 item_text = pango_layout_get_text (icon_view->priv->layout);
7893 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7904 offset = g_utf8_strlen (item_text, -1);
7906 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7912 atk_text_item_interface_init (AtkTextIface *iface)
7914 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7915 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7916 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7917 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7918 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7919 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7920 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7921 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7925 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7930 AtkCoordType coord_type)
7932 GtkIconViewItemAccessible *item;
7933 AtkObject *parent_obj;
7936 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7938 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7939 if (!GTK_IS_WIDGET (item->widget))
7942 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7945 *width = item->item->width;
7946 *height = item->item->height;
7947 if (gtk_icon_view_item_accessible_is_showing (item))
7949 parent_obj = gtk_widget_get_accessible (item->widget);
7950 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7951 *x = l_x + item->item->x;
7952 *y = l_y + item->item->y;
7962 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7964 GtkIconViewItemAccessible *item;
7965 GtkWidget *toplevel;
7967 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7969 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7970 if (!GTK_IS_WIDGET (item->widget))
7973 gtk_widget_grab_focus (item->widget);
7974 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7975 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7976 if (GTK_WIDGET_TOPLEVEL (toplevel))
7977 gtk_window_present (GTK_WINDOW (toplevel));
7983 atk_component_item_interface_init (AtkComponentIface *iface)
7985 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7986 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7990 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7991 AtkStateType state_type,
7992 gboolean emit_signal)
7996 rc = atk_state_set_add_state (item->state_set, state_type);
7998 * The signal should only be generated if the value changed,
7999 * not when the item is set up. So states that are set
8000 * initially should pass FALSE as the emit_signal argument.
8005 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8006 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8007 if (state_type == ATK_STATE_VISIBLE)
8008 g_signal_emit_by_name (item, "visible_data_changed");
8015 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8016 AtkStateType state_type,
8017 gboolean emit_signal)
8019 if (atk_state_set_contains_state (item->state_set, state_type))
8023 rc = atk_state_set_remove_state (item->state_set, state_type);
8025 * The signal should only be generated if the value changed,
8026 * not when the item is set up. So states that are set
8027 * initially should pass FALSE as the emit_signal argument.
8032 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8033 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8034 if (state_type == ATK_STATE_VISIBLE)
8035 g_signal_emit_by_name (item, "visible_data_changed");
8045 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8047 GtkIconView *icon_view;
8048 GdkRectangle visible_rect;
8049 gboolean is_showing;
8052 * An item is considered "SHOWING" if any part of the item is in the
8053 * visible rectangle.
8056 if (!GTK_IS_ICON_VIEW (item->widget))
8059 if (item->item == NULL)
8062 icon_view = GTK_ICON_VIEW (item->widget);
8064 if (icon_view->priv->hadjustment)
8065 visible_rect.x += icon_view->priv->hadjustment->value;
8067 if (icon_view->priv->hadjustment)
8068 visible_rect.y += icon_view->priv->vadjustment->value;
8069 visible_rect.width = item->widget->allocation.width;
8070 visible_rect.height = item->widget->allocation.height;
8072 if (((item->item->x + item->item->width) < visible_rect.x) ||
8073 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8074 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8075 (item->item->y > (visible_rect.y + visible_rect.height)))
8084 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8085 gboolean emit_signal)
8087 if (gtk_icon_view_item_accessible_is_showing (item))
8088 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8091 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8096 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8100 item->state_set = atk_state_set_new ();
8102 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8103 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8104 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8105 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8106 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8108 for (i = 0; i < LAST_ACTION; i++)
8109 item->action_descriptions[i] = NULL;
8111 item->image_description = NULL;
8113 item->action_idle_handler = 0;
8117 gtk_icon_view_item_accessible_finalize (GObject *object)
8119 GtkIconViewItemAccessible *item;
8122 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8124 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8127 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8129 if (item->state_set)
8130 g_object_unref (item->state_set);
8132 if (item->text_buffer)
8133 g_object_unref (item->text_buffer);
8135 for (i = 0; i < LAST_ACTION; i++)
8136 g_free (item->action_descriptions[i]);
8138 g_free (item->image_description);
8140 if (item->action_idle_handler)
8142 g_source_remove (item->action_idle_handler);
8143 item->action_idle_handler = 0;
8146 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8149 static G_CONST_RETURN gchar*
8150 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8156 GtkIconViewItemAccessible *item;
8157 GtkTextIter start_iter;
8158 GtkTextIter end_iter;
8160 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8162 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8163 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8165 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8170 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8172 GtkIconViewItemAccessible *item;
8174 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8175 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8178 return gtk_widget_get_accessible (item->widget);
8184 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8186 GtkIconViewItemAccessible *item;
8188 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8189 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8191 return item->item->index;
8194 static AtkStateSet *
8195 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8197 GtkIconViewItemAccessible *item;
8198 GtkIconView *icon_view;
8200 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8201 g_return_val_if_fail (item->state_set, NULL);
8206 icon_view = GTK_ICON_VIEW (item->widget);
8207 if (icon_view->priv->cursor_item == item->item)
8208 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8210 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8212 return g_object_ref (item->state_set);
8216 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8218 GObjectClass *gobject_class;
8220 accessible_item_parent_class = g_type_class_peek_parent (klass);
8222 gobject_class = (GObjectClass *)klass;
8224 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8226 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8227 klass->get_name = gtk_icon_view_item_accessible_get_name;
8228 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8229 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8233 gtk_icon_view_item_accessible_get_type (void)
8235 static GType type = 0;
8239 const GTypeInfo tinfo =
8241 sizeof (GtkIconViewItemAccessibleClass),
8242 (GBaseInitFunc) NULL, /* base init */
8243 (GBaseFinalizeFunc) NULL, /* base finalize */
8244 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8245 (GClassFinalizeFunc) NULL, /* class finalize */
8246 NULL, /* class data */
8247 sizeof (GtkIconViewItemAccessible), /* instance size */
8248 0, /* nb preallocs */
8249 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8250 NULL /* value table */
8253 static const GInterfaceInfo atk_component_info =
8255 (GInterfaceInitFunc) atk_component_item_interface_init,
8256 (GInterfaceFinalizeFunc) NULL,
8259 static const GInterfaceInfo atk_action_info =
8261 (GInterfaceInitFunc) atk_action_item_interface_init,
8262 (GInterfaceFinalizeFunc) NULL,
8265 static const GInterfaceInfo atk_image_info =
8267 (GInterfaceInitFunc) atk_image_item_interface_init,
8268 (GInterfaceFinalizeFunc) NULL,
8271 static const GInterfaceInfo atk_text_info =
8273 (GInterfaceInitFunc) atk_text_item_interface_init,
8274 (GInterfaceFinalizeFunc) NULL,
8278 type = g_type_register_static (ATK_TYPE_OBJECT,
8279 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8280 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8281 &atk_component_info);
8282 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8284 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8286 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8293 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8294 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8295 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8297 static GType gtk_icon_view_accessible_get_type (void);
8302 } GtkIconViewAccessible;
8308 } GtkIconViewItemAccessibleInfo;
8314 GtkAdjustment *old_hadj;
8315 GtkAdjustment *old_vadj;
8317 GtkTreeModel *model;
8319 } GtkIconViewAccessiblePrivate;
8321 static GtkIconViewAccessiblePrivate *
8322 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8324 return g_object_get_qdata (G_OBJECT (accessible),
8325 accessible_private_data_quark);
8329 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8333 GtkIconViewItemAccessibleInfo *info;
8334 GtkIconViewItemAccessibleInfo *tmp_info;
8335 GtkIconViewAccessiblePrivate *priv;
8338 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8340 info->index = index;
8342 priv = gtk_icon_view_accessible_get_priv (accessible);
8343 items = priv->items;
8346 tmp_info = items->data;
8347 if (tmp_info->index > index)
8349 items = items->next;
8351 priv->items = g_list_insert_before (priv->items, items, info);
8352 priv->old_hadj = NULL;
8353 priv->old_vadj = NULL;
8357 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8359 GtkIconView *icon_view;
8362 widget = GTK_ACCESSIBLE (accessible)->widget;
8366 icon_view = GTK_ICON_VIEW (widget);
8368 return g_list_length (icon_view->priv->items);
8372 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8375 GtkIconViewAccessiblePrivate *priv;
8376 GtkIconViewItemAccessibleInfo *info;
8379 priv = gtk_icon_view_accessible_get_priv (accessible);
8380 items = priv->items;
8385 if (info->index == index)
8387 items = items->next;
8393 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8396 GtkIconView *icon_view;
8400 GtkIconViewItemAccessible *a11y_item;
8402 widget = GTK_ACCESSIBLE (accessible)->widget;
8406 icon_view = GTK_ICON_VIEW (widget);
8407 icons = g_list_nth (icon_view->priv->items, index);
8411 GtkIconViewItem *item = icons->data;
8413 g_return_val_if_fail (item->index == index, NULL);
8414 obj = gtk_icon_view_accessible_find_child (accessible, index);
8419 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8420 gtk_icon_view_item_accessible_info_new (accessible,
8423 obj->role = ATK_ROLE_ICON;
8424 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8425 a11y_item->item = item;
8426 a11y_item->widget = widget;
8427 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8429 gtk_icon_view_set_cell_data (icon_view, item);
8430 text = get_text (icon_view, item);
8433 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8437 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8438 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8446 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8449 GtkIconViewAccessiblePrivate *priv;
8450 GtkIconViewItemAccessibleInfo *info;
8451 GtkIconViewItemAccessible *item;
8454 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8458 gboolean act_on_item;
8460 widget = GTK_ACCESSIBLE (view)->widget;
8464 items = priv->items;
8466 act_on_item = (list == NULL);
8471 info = (GtkIconViewItemAccessibleInfo *)items->data;
8472 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8474 if (act_on_item == FALSE && list == items)
8478 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8480 items = items->next;
8486 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8487 GtkIconView *icon_view)
8490 GtkIconViewAccessible *view;
8493 * The scrollbars have changed
8495 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8496 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8498 gtk_icon_view_accessible_traverse_items (view, NULL);
8502 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8503 GtkAdjustment *hadj,
8504 GtkAdjustment *vadj)
8507 GtkIconViewAccessiblePrivate *priv;
8509 atk_obj = gtk_widget_get_accessible (widget);
8510 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8512 if (priv->old_hadj != hadj)
8516 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8517 (gpointer *)&priv->old_hadj);
8519 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8520 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8523 priv->old_hadj = hadj;
8526 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8527 (gpointer *)&priv->old_hadj);
8528 g_signal_connect (hadj,
8530 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8534 if (priv->old_vadj != vadj)
8538 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8539 (gpointer *)&priv->old_vadj);
8541 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8542 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8545 priv->old_vadj = vadj;
8548 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8549 (gpointer *)&priv->old_vadj);
8550 g_signal_connect (vadj,
8552 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8559 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8566 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8567 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8573 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8578 GtkIconViewAccessiblePrivate *priv;
8579 GtkIconViewItemAccessibleInfo *info;
8580 GtkIconViewAccessible *view;
8581 GtkIconViewItemAccessible *item;
8587 index = gtk_tree_path_get_indices(path)[0];
8588 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8589 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8590 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8592 items = priv->items;
8597 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8598 if (info->index != item->item->index)
8600 if (info->index < index)
8601 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8603 if (tmp_list == NULL)
8606 info->index = item->item->index;
8609 items = items->next;
8611 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8612 g_signal_emit_by_name (atk_obj, "children_changed::add",
8618 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8622 GtkIconViewAccessiblePrivate *priv;
8623 GtkIconViewItemAccessibleInfo *info;
8624 GtkIconViewAccessible *view;
8625 GtkIconViewItemAccessible *item;
8628 GList *deleted_item;
8632 index = gtk_tree_path_get_indices(path)[0];
8633 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8634 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8635 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8637 items = priv->items;
8639 deleted_item = NULL;
8644 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8645 if (info->index == index)
8647 deleted_item = items;
8649 if (info->index != item->item->index)
8651 if (tmp_list == NULL)
8654 info->index = item->item->index;
8657 items = items->next;
8659 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8662 info = deleted_item->data;
8663 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8665 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8669 priv->items = g_list_remove_link (priv->items, deleted_item);
8677 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8678 GtkIconViewItemAccessibleInfo *i2)
8680 return i1->index - i2->index;
8684 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8690 GtkIconViewAccessiblePrivate *priv;
8691 GtkIconViewItemAccessibleInfo *info;
8692 GtkIconView *icon_view;
8693 GtkIconViewItemAccessible *item;
8697 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8698 icon_view = GTK_ICON_VIEW (user_data);
8699 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8701 items = priv->items;
8705 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8706 info->index = new_order[info->index];
8707 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8708 items = items->next;
8710 priv->items = g_list_sort (priv->items,
8711 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8717 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8722 obj = G_OBJECT (model);
8723 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8724 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8725 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8726 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8730 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8734 obj = G_OBJECT (icon_view->priv->model);
8735 g_signal_connect_data (obj, "row_changed",
8736 (GCallback) gtk_icon_view_accessible_model_row_changed,
8737 icon_view, NULL, 0);
8738 g_signal_connect_data (obj, "row_inserted",
8739 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8740 icon_view, NULL, G_CONNECT_AFTER);
8741 g_signal_connect_data (obj, "row_deleted",
8742 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8743 icon_view, NULL, G_CONNECT_AFTER);
8744 g_signal_connect_data (obj, "rows_reordered",
8745 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8746 icon_view, NULL, G_CONNECT_AFTER);
8750 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8752 GtkIconViewItemAccessibleInfo *info;
8755 items = priv->items;
8758 info = (GtkIconViewItemAccessibleInfo *) items->data;
8759 g_object_unref (info->item);
8760 g_free (items->data);
8761 items = items->next;
8763 g_list_free (priv->items);
8768 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8771 GtkIconView *icon_view;
8774 GtkIconViewAccessiblePrivate *priv;
8776 if (strcmp (pspec->name, "model") == 0)
8778 widget = GTK_WIDGET (obj);
8779 atk_obj = gtk_widget_get_accessible (widget);
8780 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8783 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8784 (gpointer *)&priv->model);
8785 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8787 gtk_icon_view_accessible_clear_cache (priv);
8789 icon_view = GTK_ICON_VIEW (obj);
8790 priv->model = icon_view->priv->model;
8791 /* If there is no model the GtkIconView is probably being destroyed */
8794 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8795 gtk_icon_view_accessible_connect_model_signals (icon_view);
8803 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8806 GtkIconViewAccessiblePrivate *priv;
8807 GtkIconView *icon_view;
8809 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8810 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8812 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8813 g_object_set_qdata (G_OBJECT (accessible),
8814 accessible_private_data_quark,
8817 icon_view = GTK_ICON_VIEW (data);
8818 if (icon_view->priv->hadjustment)
8820 priv->old_hadj = icon_view->priv->hadjustment;
8821 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8822 g_signal_connect (icon_view->priv->hadjustment,
8824 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8827 if (icon_view->priv->vadjustment)
8829 priv->old_vadj = icon_view->priv->vadjustment;
8830 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8831 g_signal_connect (icon_view->priv->vadjustment,
8833 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8836 g_signal_connect_after (data,
8837 "set_scroll_adjustments",
8838 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8840 g_signal_connect (data,
8842 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8845 priv->model = icon_view->priv->model;
8848 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8849 gtk_icon_view_accessible_connect_model_signals (icon_view);
8852 accessible->role = ATK_ROLE_LAYERED_PANE;
8856 gtk_icon_view_accessible_finalize (GObject *object)
8858 GtkIconViewAccessiblePrivate *priv;
8860 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8861 gtk_icon_view_accessible_clear_cache (priv);
8865 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8869 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8870 GtkAccessible *accessible)
8873 GtkIconViewAccessiblePrivate *priv;
8875 atk_obj = ATK_OBJECT (accessible);
8876 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8879 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8880 (gpointer *)&priv->old_hadj);
8882 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8883 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8885 priv->old_hadj = NULL;
8889 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8890 (gpointer *)&priv->old_vadj);
8892 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8893 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8895 priv->old_vadj = NULL;
8900 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8902 if (accessible->widget)
8904 g_signal_connect_after (accessible->widget,
8906 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8909 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8913 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8915 GObjectClass *gobject_class;
8916 GtkAccessibleClass *accessible_class;
8918 accessible_parent_class = g_type_class_peek_parent (klass);
8920 gobject_class = (GObjectClass *)klass;
8921 accessible_class = (GtkAccessibleClass *)klass;
8923 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8925 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8926 klass->ref_child = gtk_icon_view_accessible_ref_child;
8927 klass->initialize = gtk_icon_view_accessible_initialize;
8929 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8931 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8935 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8938 AtkCoordType coord_type)
8941 GtkIconView *icon_view;
8942 GtkIconViewItem *item;
8945 widget = GTK_ACCESSIBLE (component)->widget;
8947 /* State is defunct */
8950 icon_view = GTK_ICON_VIEW (widget);
8951 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8952 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8954 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8960 atk_component_interface_init (AtkComponentIface *iface)
8962 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8966 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8970 GtkIconView *icon_view;
8971 GtkIconViewItem *item;
8973 widget = GTK_ACCESSIBLE (selection)->widget;
8977 icon_view = GTK_ICON_VIEW (widget);
8979 item = g_list_nth_data (icon_view->priv->items, i);
8984 gtk_icon_view_select_item (icon_view, item);
8990 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8993 GtkIconView *icon_view;
8995 widget = GTK_ACCESSIBLE (selection)->widget;
8999 icon_view = GTK_ICON_VIEW (widget);
9000 gtk_icon_view_unselect_all (icon_view);
9006 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9011 GtkIconView *icon_view;
9012 GtkIconViewItem *item;
9014 widget = GTK_ACCESSIBLE (selection)->widget;
9018 icon_view = GTK_ICON_VIEW (widget);
9020 l = icon_view->priv->items;
9027 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9038 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9041 GtkIconView *icon_view;
9042 GtkIconViewItem *item;
9046 widget = GTK_ACCESSIBLE (selection)->widget;
9050 icon_view = GTK_ICON_VIEW (widget);
9052 l = icon_view->priv->items;
9068 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9072 GtkIconView *icon_view;
9073 GtkIconViewItem *item;
9075 widget = GTK_ACCESSIBLE (selection)->widget;
9079 icon_view = GTK_ICON_VIEW (widget);
9081 item = g_list_nth_data (icon_view->priv->items, i);
9085 return item->selected;
9089 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9093 GtkIconView *icon_view;
9094 GtkIconViewItem *item;
9098 widget = GTK_ACCESSIBLE (selection)->widget;
9102 icon_view = GTK_ICON_VIEW (widget);
9103 l = icon_view->priv->items;
9112 gtk_icon_view_unselect_item (icon_view, item);
9124 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9127 GtkIconView *icon_view;
9129 widget = GTK_ACCESSIBLE (selection)->widget;
9133 icon_view = GTK_ICON_VIEW (widget);
9134 gtk_icon_view_select_all (icon_view);
9139 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9141 iface->add_selection = gtk_icon_view_accessible_add_selection;
9142 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9143 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9144 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9145 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9146 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9147 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9151 gtk_icon_view_accessible_get_type (void)
9153 static GType type = 0;
9157 static GTypeInfo tinfo =
9160 (GBaseInitFunc) NULL, /* base init */
9161 (GBaseFinalizeFunc) NULL, /* base finalize */
9162 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9163 (GClassFinalizeFunc) NULL, /* class finalize */
9164 NULL, /* class data */
9165 0, /* instance size */
9166 0, /* nb preallocs */
9167 (GInstanceInitFunc) NULL, /* instance init */
9168 NULL /* value table */
9170 static const GInterfaceInfo atk_component_info =
9172 (GInterfaceInitFunc) atk_component_interface_init,
9173 (GInterfaceFinalizeFunc) NULL,
9176 static const GInterfaceInfo atk_selection_info =
9178 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9179 (GInterfaceFinalizeFunc) NULL,
9184 * Figure out the size of the class and instance
9185 * we are deriving from
9187 AtkObjectFactory *factory;
9190 GType derived_atk_type;
9192 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9193 factory = atk_registry_get_factory (atk_get_default_registry (),
9195 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9196 g_type_query (derived_atk_type, &query);
9197 tinfo.class_size = query.class_size;
9198 tinfo.instance_size = query.instance_size;
9200 type = g_type_register_static (derived_atk_type,
9201 I_("GtkIconViewAccessible"),
9203 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9204 &atk_component_info);
9205 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9206 &atk_selection_info);
9212 gtk_icon_view_accessible_new (GObject *obj)
9214 AtkObject *accessible;
9216 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9218 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9219 atk_object_initialize (accessible, obj);
9225 gtk_icon_view_accessible_factory_get_accessible_type (void)
9227 return gtk_icon_view_accessible_get_type ();
9231 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9233 return gtk_icon_view_accessible_new (obj);
9237 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9239 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9240 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9244 gtk_icon_view_accessible_factory_get_type (void)
9246 static GType type = 0;
9250 const GTypeInfo tinfo =
9252 sizeof (AtkObjectFactoryClass),
9253 NULL, /* base_init */
9254 NULL, /* base_finalize */
9255 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9256 NULL, /* class_finalize */
9257 NULL, /* class_data */
9258 sizeof (AtkObjectFactory),
9259 0, /* n_preallocs */
9263 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9264 I_("GtkIconViewAccessibleFactory"),
9272 gtk_icon_view_get_accessible (GtkWidget *widget)
9274 static gboolean first_time = TRUE;
9278 AtkObjectFactory *factory;
9279 AtkRegistry *registry;
9281 GType derived_atk_type;
9284 * Figure out whether accessibility is enabled by looking at the
9285 * type of the accessible object which would be created for
9286 * the parent type of GtkIconView.
9288 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9290 registry = atk_get_default_registry ();
9291 factory = atk_registry_get_factory (registry,
9293 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9294 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9295 atk_registry_set_factory_type (registry,
9297 gtk_icon_view_accessible_factory_get_type ());
9300 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9304 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9305 GtkBuilder *builder,
9307 const gchar *tagname,
9308 GMarkupParser *parser,
9311 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9312 tagname, parser, data))
9315 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9316 tagname, parser, data);
9320 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9321 GtkBuilder *builder,
9323 const gchar *tagname,
9326 if (strcmp (tagname, "attributes") == 0)
9327 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9330 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9336 #define __GTK_ICON_VIEW_C__
9337 #include "gtkaliasdef.c"