2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtktextbuffer.h"
42 #include "gtktreednd.h"
43 #include "gtkprivate.h"
46 #undef DEBUG_ICON_VIEW
48 #define SCROLL_EDGE_SIZE 15
49 #define ITEM_PADDING 6
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;
163 guint draw_focus : 1;
166 GdkModifierType start_button_mask;
171 GdkDragAction source_actions;
172 GdkDragAction dest_actions;
174 GtkTreeRowReference *dest_item;
175 GtkIconViewDropPosition dest_pos;
178 GtkTreeRowReference *scroll_to_path;
179 gfloat scroll_to_row_align;
180 gfloat scroll_to_col_align;
181 guint scroll_to_use_align : 1;
183 guint source_set : 1;
185 guint reorderable : 1;
186 guint empty_view_drop :1;
188 guint ctrl_pressed : 1;
189 guint shift_pressed : 1;
202 ACTIVATE_CURSOR_ITEM,
227 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
228 static void gtk_icon_view_finalize (GObject *object);
229 static void gtk_icon_view_set_property (GObject *object,
233 static void gtk_icon_view_get_property (GObject *object,
238 /* GtkObject vfuncs */
239 static void gtk_icon_view_destroy (GtkObject *object);
241 /* GtkWidget vfuncs */
242 static void gtk_icon_view_realize (GtkWidget *widget);
243 static void gtk_icon_view_unrealize (GtkWidget *widget);
244 static void gtk_icon_view_style_set (GtkWidget *widget,
245 GtkStyle *previous_style);
246 static void gtk_icon_view_state_changed (GtkWidget *widget,
247 GtkStateType previous_state);
248 static void gtk_icon_view_size_request (GtkWidget *widget,
249 GtkRequisition *requisition);
250 static void gtk_icon_view_size_allocate (GtkWidget *widget,
251 GtkAllocation *allocation);
252 static gboolean gtk_icon_view_expose (GtkWidget *widget,
253 GdkEventExpose *expose);
254 static gboolean gtk_icon_view_motion (GtkWidget *widget,
255 GdkEventMotion *event);
256 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
257 GdkEventButton *event);
258 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
259 GdkEventButton *event);
260 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
262 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
264 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
267 /* GtkContainer vfuncs */
268 static void gtk_icon_view_remove (GtkContainer *container,
270 static void gtk_icon_view_forall (GtkContainer *container,
271 gboolean include_internals,
272 GtkCallback callback,
273 gpointer callback_data);
275 /* GtkIconView vfuncs */
276 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
278 GtkAdjustment *vadj);
279 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
280 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
282 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
283 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
285 /* Internal functions */
286 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
287 GtkIconView *icon_view);
288 static void gtk_icon_view_layout (GtkIconView *icon_view);
289 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
292 GtkIconViewItem *item,
294 GdkDrawable *drawable,
297 gboolean draw_focus);
298 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
303 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
304 GtkIconViewItem *item);
305 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
306 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
307 GtkIconViewItem *item,
309 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
312 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
313 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
314 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
315 GtkIconViewItem *item,
320 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
321 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
322 GtkIconViewItem *item);
323 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
324 GtkIconViewItem *item,
326 static void gtk_icon_view_update_rubberband (gpointer data);
327 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
328 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
329 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
332 GtkMovementStep step,
334 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
335 GtkMovementStep step,
337 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
343 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
345 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_select_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
350 GtkIconViewItem *item);
351 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
352 GtkIconViewItem *anchor,
353 GtkIconViewItem *cursor);
354 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
357 gboolean only_in_cell,
358 GtkIconViewCellInfo **cell_at_pos);
359 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
360 GtkIconViewItem *item,
361 GtkIconViewCellInfo *cell_info,
362 GdkRectangle *cell_area);
363 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
364 GtkIconViewItem *item,
365 GtkIconViewCellInfo *info,
367 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
368 GtkCellRenderer *renderer);
369 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
370 GtkIconViewItem *item);
371 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
372 GtkCellRenderer *renderer,
374 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
375 GtkCellRenderer *renderer,
377 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
378 GtkCellRenderer *renderer,
379 const gchar *attribute,
381 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
382 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
383 GtkCellRenderer *renderer);
384 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
385 GtkCellRenderer *cell,
386 GtkCellLayoutDataFunc func,
388 GDestroyNotify destroy);
389 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
390 GtkCellRenderer *cell,
392 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
394 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
395 GtkIconViewItem *item,
396 GtkIconViewCellInfo *cell_info,
398 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
399 GtkIconViewItem *item);
400 static void gtk_icon_view_put (GtkIconView *icon_view,
402 GtkIconViewItem *item,
404 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
405 GtkIconView *icon_view);
406 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
407 GtkIconViewItem *item,
408 GtkIconViewCellInfo *cell_info,
410 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
411 gboolean cancel_editing);
413 /* Source side drag signals */
414 static void gtk_icon_view_drag_begin (GtkWidget *widget,
415 GdkDragContext *context);
416 static void gtk_icon_view_drag_end (GtkWidget *widget,
417 GdkDragContext *context);
418 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
426 /* Target side drag signals */
427 static void gtk_icon_view_drag_leave (GtkWidget *widget,
428 GdkDragContext *context,
430 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
431 GdkDragContext *context,
435 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
436 GdkDragContext *context,
440 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
441 GdkDragContext *context,
444 GtkSelectionData *selection_data,
447 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
448 GdkEventMotion *event);
450 static void remove_scroll_timeout (GtkIconView *icon_view);
452 static void adjust_wrap_width (GtkIconView *icon_view,
453 GtkIconViewItem *item);
456 static GtkBuildableIface *parent_buildable_iface;
457 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
458 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
461 const gchar *tagname,
462 GMarkupParser *parser,
464 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
467 const gchar *tagname,
470 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
472 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
473 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
474 gtk_icon_view_cell_layout_init)
475 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
476 gtk_icon_view_buildable_init))
479 gtk_icon_view_class_init (GtkIconViewClass *klass)
481 GObjectClass *gobject_class;
482 GtkObjectClass *object_class;
483 GtkWidgetClass *widget_class;
484 GtkContainerClass *container_class;
485 GtkBindingSet *binding_set;
487 binding_set = gtk_binding_set_by_class (klass);
489 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
491 gobject_class = (GObjectClass *) klass;
492 object_class = (GtkObjectClass *) klass;
493 widget_class = (GtkWidgetClass *) klass;
494 container_class = (GtkContainerClass *) klass;
496 gobject_class->finalize = gtk_icon_view_finalize;
497 gobject_class->set_property = gtk_icon_view_set_property;
498 gobject_class->get_property = gtk_icon_view_get_property;
500 object_class->destroy = gtk_icon_view_destroy;
502 widget_class->realize = gtk_icon_view_realize;
503 widget_class->unrealize = gtk_icon_view_unrealize;
504 widget_class->style_set = gtk_icon_view_style_set;
505 widget_class->get_accessible = gtk_icon_view_get_accessible;
506 widget_class->size_request = gtk_icon_view_size_request;
507 widget_class->size_allocate = gtk_icon_view_size_allocate;
508 widget_class->expose_event = gtk_icon_view_expose;
509 widget_class->motion_notify_event = gtk_icon_view_motion;
510 widget_class->button_press_event = gtk_icon_view_button_press;
511 widget_class->button_release_event = gtk_icon_view_button_release;
512 widget_class->key_press_event = gtk_icon_view_key_press;
513 widget_class->key_release_event = gtk_icon_view_key_release;
514 widget_class->drag_begin = gtk_icon_view_drag_begin;
515 widget_class->drag_end = gtk_icon_view_drag_end;
516 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
517 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
518 widget_class->drag_leave = gtk_icon_view_drag_leave;
519 widget_class->drag_motion = gtk_icon_view_drag_motion;
520 widget_class->drag_drop = gtk_icon_view_drag_drop;
521 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
522 widget_class->state_changed = gtk_icon_view_state_changed;
524 container_class->remove = gtk_icon_view_remove;
525 container_class->forall = gtk_icon_view_forall;
527 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
528 klass->select_all = gtk_icon_view_real_select_all;
529 klass->unselect_all = gtk_icon_view_real_unselect_all;
530 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
531 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
532 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
533 klass->move_cursor = gtk_icon_view_real_move_cursor;
537 * GtkIconView:selection-mode:
539 * The ::selection-mode property specifies the selection mode of
540 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
541 * is enabled, for the other modes, only keyboard selection is possible.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_enum ("selection-mode",
548 P_("Selection mode"),
549 P_("The selection mode"),
550 GTK_TYPE_SELECTION_MODE,
551 GTK_SELECTION_SINGLE,
552 GTK_PARAM_READWRITE));
555 * GtkIconView:pixbuf-column:
557 * The ::pixbuf-column property contains the number of the model column
558 * containing the pixbufs which are displayed. The pixbuf column must be
559 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
560 * display of pixbufs.
564 g_object_class_install_property (gobject_class,
566 g_param_spec_int ("pixbuf-column",
568 P_("Model column used to retrieve the icon pixbuf from"),
570 GTK_PARAM_READWRITE));
573 * GtkIconView:text-column:
575 * The ::text-column property contains the number of the model column
576 * containing the texts which are displayed. The text column must be
577 * of type #G_TYPE_STRING. If this property and the :markup-column
578 * property are both set to -1, no texts are displayed.
582 g_object_class_install_property (gobject_class,
584 g_param_spec_int ("text-column",
586 P_("Model column used to retrieve the text from"),
588 GTK_PARAM_READWRITE));
592 * GtkIconView:markup-column:
594 * The ::markup-column property contains the number of the model column
595 * containing markup information to be displayed. The markup column must be
596 * of type #G_TYPE_STRING. If this property and the :text-column property
597 * are both set to column numbers, it overrides the text column.
598 * If both are set to -1, no texts are displayed.
602 g_object_class_install_property (gobject_class,
604 g_param_spec_int ("markup-column",
606 P_("Model column used to retrieve the text if using Pango markup"),
608 GTK_PARAM_READWRITE));
610 g_object_class_install_property (gobject_class,
612 g_param_spec_object ("model",
613 P_("Icon View Model"),
614 P_("The model for the icon view"),
616 GTK_PARAM_READWRITE));
619 * GtkIconView:columns:
621 * The columns property contains the number of the columns in which the
622 * items should be displayed. If it is -1, the number of columns will
623 * be chosen automatically to fill the available area.
627 g_object_class_install_property (gobject_class,
629 g_param_spec_int ("columns",
630 P_("Number of columns"),
631 P_("Number of columns to display"),
633 GTK_PARAM_READWRITE));
637 * GtkIconView:item-width:
639 * The item-width property specifies the width to use for each item.
640 * If it is set to -1, the icon view will automatically determine a
641 * suitable item size.
645 g_object_class_install_property (gobject_class,
647 g_param_spec_int ("item-width",
648 P_("Width for each item"),
649 P_("The width used for each item"),
651 GTK_PARAM_READWRITE));
654 * GtkIconView:spacing:
656 * The spacing property specifies the space which is inserted between
657 * the cells (i.e. the icon and the text) of an item.
661 g_object_class_install_property (gobject_class,
663 g_param_spec_int ("spacing",
665 P_("Space which is inserted between cells of an item"),
667 GTK_PARAM_READWRITE));
670 * GtkIconView:row-spacing:
672 * The row-spacing property specifies the space which is inserted between
673 * the rows of the icon view.
677 g_object_class_install_property (gobject_class,
679 g_param_spec_int ("row-spacing",
681 P_("Space which is inserted between grid rows"),
683 GTK_PARAM_READWRITE));
686 * GtkIconView:column-spacing:
688 * The column-spacing property specifies the space which is inserted between
689 * the columns of the icon view.
693 g_object_class_install_property (gobject_class,
695 g_param_spec_int ("column-spacing",
696 P_("Column Spacing"),
697 P_("Space which is inserted between grid columns"),
699 GTK_PARAM_READWRITE));
702 * GtkIconView:margin:
704 * The margin property specifies the space which is inserted
705 * at the edges of the icon view.
709 g_object_class_install_property (gobject_class,
711 g_param_spec_int ("margin",
713 P_("Space which is inserted at the edges of the icon view"),
715 GTK_PARAM_READWRITE));
719 * GtkIconView:orientation:
721 * The orientation property specifies how the cells (i.e. the icon and
722 * the text) of the item are positioned relative to each other.
726 g_object_class_install_property (gobject_class,
728 g_param_spec_enum ("orientation",
730 P_("How the text and icon of each item are positioned relative to each other"),
731 GTK_TYPE_ORIENTATION,
732 GTK_ORIENTATION_VERTICAL,
733 GTK_PARAM_READWRITE));
736 * GtkIconView:reorderable:
738 * The reorderable property specifies if the items can be reordered
743 g_object_class_install_property (gobject_class,
745 g_param_spec_boolean ("reorderable",
747 P_("View is reorderable"),
751 g_object_class_install_property (gobject_class,
753 g_param_spec_int ("tooltip-column",
754 P_("Tooltip Column"),
755 P_("The column in the model containing the tooltip texts for the items"),
759 GTK_PARAM_READWRITE));
763 /* Style properties */
764 gtk_widget_class_install_style_property (widget_class,
765 g_param_spec_boxed ("selection-box-color",
766 P_("Selection Box Color"),
767 P_("Color of the selection box"),
769 GTK_PARAM_READABLE));
771 gtk_widget_class_install_style_property (widget_class,
772 g_param_spec_uchar ("selection-box-alpha",
773 P_("Selection Box Alpha"),
774 P_("Opacity of the selection box"),
777 GTK_PARAM_READABLE));
781 * GtkIconView::set-scroll-adjustments
782 * @horizontal: the horizontal #GtkAdjustment
783 * @vertical: the vertical #GtkAdjustment
785 * Set the scroll adjustments for the icon view. Usually scrolled containers
786 * like #GtkScrolledWindow will emit this signal to connect two instances
787 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
789 widget_class->set_scroll_adjustments_signal =
790 g_signal_new (I_("set-scroll-adjustments"),
791 G_TYPE_FROM_CLASS (gobject_class),
793 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
795 _gtk_marshal_VOID__OBJECT_OBJECT,
797 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
799 icon_view_signals[ITEM_ACTIVATED] =
800 g_signal_new (I_("item-activated"),
801 G_TYPE_FROM_CLASS (gobject_class),
803 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
805 g_cclosure_marshal_VOID__BOXED,
809 icon_view_signals[SELECTION_CHANGED] =
810 g_signal_new (I_("selection-changed"),
811 G_TYPE_FROM_CLASS (gobject_class),
813 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
815 g_cclosure_marshal_VOID__VOID,
818 icon_view_signals[SELECT_ALL] =
819 g_signal_new (I_("select-all"),
820 G_TYPE_FROM_CLASS (gobject_class),
821 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
822 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
824 g_cclosure_marshal_VOID__VOID,
827 icon_view_signals[UNSELECT_ALL] =
828 g_signal_new (I_("unselect-all"),
829 G_TYPE_FROM_CLASS (gobject_class),
830 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
831 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
833 g_cclosure_marshal_VOID__VOID,
836 icon_view_signals[SELECT_CURSOR_ITEM] =
837 g_signal_new (I_("select-cursor-item"),
838 G_TYPE_FROM_CLASS (gobject_class),
839 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
840 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
842 g_cclosure_marshal_VOID__VOID,
845 icon_view_signals[TOGGLE_CURSOR_ITEM] =
846 g_signal_new (I_("toggle-cursor-item"),
847 G_TYPE_FROM_CLASS (gobject_class),
848 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
849 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
851 g_cclosure_marshal_VOID__VOID,
854 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
855 g_signal_new (I_("activate-cursor-item"),
856 G_TYPE_FROM_CLASS (gobject_class),
857 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
858 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
860 _gtk_marshal_BOOLEAN__VOID,
863 icon_view_signals[MOVE_CURSOR] =
864 g_signal_new (I_("move-cursor"),
865 G_TYPE_FROM_CLASS (gobject_class),
866 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
867 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
869 _gtk_marshal_BOOLEAN__ENUM_INT,
871 GTK_TYPE_MOVEMENT_STEP,
875 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
877 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
879 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
880 "toggle-cursor-item", 0);
881 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
882 "toggle-cursor-item", 0);
884 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
885 "activate-cursor-item", 0);
886 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
887 "activate-cursor-item", 0);
888 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
889 "activate-cursor-item", 0);
890 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
891 "activate-cursor-item", 0);
892 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
893 "activate-cursor-item", 0);
895 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
896 GTK_MOVEMENT_DISPLAY_LINES, -1);
897 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
898 GTK_MOVEMENT_DISPLAY_LINES, -1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
901 GTK_MOVEMENT_DISPLAY_LINES, 1);
902 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
903 GTK_MOVEMENT_DISPLAY_LINES, 1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
906 GTK_MOVEMENT_DISPLAY_LINES, -1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
909 GTK_MOVEMENT_DISPLAY_LINES, 1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
912 GTK_MOVEMENT_BUFFER_ENDS, -1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
914 GTK_MOVEMENT_BUFFER_ENDS, -1);
916 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
917 GTK_MOVEMENT_BUFFER_ENDS, 1);
918 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
919 GTK_MOVEMENT_BUFFER_ENDS, 1);
921 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
922 GTK_MOVEMENT_PAGES, -1);
923 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
924 GTK_MOVEMENT_PAGES, -1);
926 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
927 GTK_MOVEMENT_PAGES, 1);
928 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
929 GTK_MOVEMENT_PAGES, 1);
931 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
932 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
933 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
934 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
936 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
937 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
938 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
939 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
943 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
945 parent_buildable_iface = g_type_interface_peek_parent (iface);
946 iface->add_child = _gtk_cell_layout_buildable_add_child;
947 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
948 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
952 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
954 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
955 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
956 iface->clear = gtk_icon_view_cell_layout_clear;
957 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
958 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
959 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
960 iface->reorder = gtk_icon_view_cell_layout_reorder;
961 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
965 gtk_icon_view_init (GtkIconView *icon_view)
967 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
969 icon_view->priv->width = 0;
970 icon_view->priv->height = 0;
971 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
972 icon_view->priv->pressed_button = -1;
973 icon_view->priv->press_start_x = -1;
974 icon_view->priv->press_start_y = -1;
975 icon_view->priv->text_column = -1;
976 icon_view->priv->markup_column = -1;
977 icon_view->priv->pixbuf_column = -1;
978 icon_view->priv->text_cell = -1;
979 icon_view->priv->pixbuf_cell = -1;
980 icon_view->priv->tooltip_column = -1;
982 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
984 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
986 icon_view->priv->cell_list = NULL;
987 icon_view->priv->n_cells = 0;
988 icon_view->priv->cursor_cell = -1;
990 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
992 icon_view->priv->columns = -1;
993 icon_view->priv->item_width = -1;
994 icon_view->priv->spacing = 0;
995 icon_view->priv->row_spacing = 6;
996 icon_view->priv->column_spacing = 6;
997 icon_view->priv->margin = 6;
999 icon_view->priv->draw_focus = TRUE;
1003 gtk_icon_view_destroy (GtkObject *object)
1005 GtkIconView *icon_view;
1007 icon_view = GTK_ICON_VIEW (object);
1009 gtk_icon_view_stop_editing (icon_view, TRUE);
1011 gtk_icon_view_set_model (icon_view, NULL);
1013 if (icon_view->priv->layout_idle_id != 0)
1015 g_source_remove (icon_view->priv->layout_idle_id);
1016 icon_view->priv->layout_idle_id = 0;
1019 if (icon_view->priv->scroll_to_path != NULL)
1021 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1022 icon_view->priv->scroll_to_path = NULL;
1025 remove_scroll_timeout (icon_view);
1027 if (icon_view->priv->hadjustment != NULL)
1029 g_object_unref (icon_view->priv->hadjustment);
1030 icon_view->priv->hadjustment = NULL;
1033 if (icon_view->priv->vadjustment != NULL)
1035 g_object_unref (icon_view->priv->vadjustment);
1036 icon_view->priv->vadjustment = NULL;
1039 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1042 /* GObject methods */
1044 gtk_icon_view_finalize (GObject *object)
1046 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1048 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1053 gtk_icon_view_set_property (GObject *object,
1055 const GValue *value,
1058 GtkIconView *icon_view;
1060 icon_view = GTK_ICON_VIEW (object);
1064 case PROP_SELECTION_MODE:
1065 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1067 case PROP_PIXBUF_COLUMN:
1068 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1070 case PROP_TEXT_COLUMN:
1071 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1073 case PROP_MARKUP_COLUMN:
1074 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1077 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1079 case PROP_ORIENTATION:
1080 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1083 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1085 case PROP_ITEM_WIDTH:
1086 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1089 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1091 case PROP_ROW_SPACING:
1092 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1094 case PROP_COLUMN_SPACING:
1095 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1098 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1100 case PROP_REORDERABLE:
1101 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1104 case PROP_TOOLTIP_COLUMN:
1105 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1115 gtk_icon_view_get_property (GObject *object,
1120 GtkIconView *icon_view;
1122 icon_view = GTK_ICON_VIEW (object);
1126 case PROP_SELECTION_MODE:
1127 g_value_set_enum (value, icon_view->priv->selection_mode);
1129 case PROP_PIXBUF_COLUMN:
1130 g_value_set_int (value, icon_view->priv->pixbuf_column);
1132 case PROP_TEXT_COLUMN:
1133 g_value_set_int (value, icon_view->priv->text_column);
1135 case PROP_MARKUP_COLUMN:
1136 g_value_set_int (value, icon_view->priv->markup_column);
1139 g_value_set_object (value, icon_view->priv->model);
1141 case PROP_ORIENTATION:
1142 g_value_set_enum (value, icon_view->priv->orientation);
1145 g_value_set_int (value, icon_view->priv->columns);
1147 case PROP_ITEM_WIDTH:
1148 g_value_set_int (value, icon_view->priv->item_width);
1151 g_value_set_int (value, icon_view->priv->spacing);
1153 case PROP_ROW_SPACING:
1154 g_value_set_int (value, icon_view->priv->row_spacing);
1156 case PROP_COLUMN_SPACING:
1157 g_value_set_int (value, icon_view->priv->column_spacing);
1160 g_value_set_int (value, icon_view->priv->margin);
1162 case PROP_REORDERABLE:
1163 g_value_set_boolean (value, icon_view->priv->reorderable);
1165 case PROP_TOOLTIP_COLUMN:
1166 g_value_set_int (value, icon_view->priv->tooltip_column);
1170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1175 /* GtkWidget signals */
1177 gtk_icon_view_realize (GtkWidget *widget)
1179 GtkIconView *icon_view;
1180 GdkWindowAttr attributes;
1181 gint attributes_mask;
1183 icon_view = GTK_ICON_VIEW (widget);
1185 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1187 /* Make the main, clipping window */
1188 attributes.window_type = GDK_WINDOW_CHILD;
1189 attributes.x = widget->allocation.x;
1190 attributes.y = widget->allocation.y;
1191 attributes.width = widget->allocation.width;
1192 attributes.height = widget->allocation.height;
1193 attributes.wclass = GDK_INPUT_OUTPUT;
1194 attributes.visual = gtk_widget_get_visual (widget);
1195 attributes.colormap = gtk_widget_get_colormap (widget);
1196 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1198 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1200 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1201 &attributes, attributes_mask);
1202 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1203 gdk_window_set_user_data (widget->window, widget);
1205 /* Make the window for the icon view */
1208 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1209 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1210 attributes.event_mask = (GDK_EXPOSURE_MASK |
1212 GDK_POINTER_MOTION_MASK |
1213 GDK_BUTTON_PRESS_MASK |
1214 GDK_BUTTON_RELEASE_MASK |
1215 GDK_KEY_PRESS_MASK |
1216 GDK_KEY_RELEASE_MASK) |
1217 gtk_widget_get_events (widget);
1219 icon_view->priv->bin_window = gdk_window_new (widget->window,
1220 &attributes, attributes_mask);
1221 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1223 widget->style = gtk_style_attach (widget->style, widget->window);
1224 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1226 gdk_window_show (icon_view->priv->bin_window);
1230 gtk_icon_view_unrealize (GtkWidget *widget)
1232 GtkIconView *icon_view;
1234 icon_view = GTK_ICON_VIEW (widget);
1236 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1237 gdk_window_destroy (icon_view->priv->bin_window);
1238 icon_view->priv->bin_window = NULL;
1240 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1244 gtk_icon_view_state_changed (GtkWidget *widget,
1245 GtkStateType previous_state)
1247 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1249 if (GTK_WIDGET_REALIZED (widget))
1251 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1252 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1255 gtk_widget_queue_draw (widget);
1259 gtk_icon_view_style_set (GtkWidget *widget,
1260 GtkStyle *previous_style)
1262 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1264 if (GTK_WIDGET_REALIZED (widget))
1266 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1267 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1270 gtk_widget_queue_resize (widget);
1274 gtk_icon_view_size_request (GtkWidget *widget,
1275 GtkRequisition *requisition)
1277 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1280 requisition->width = icon_view->priv->width;
1281 requisition->height = icon_view->priv->height;
1283 tmp_list = icon_view->priv->children;
1287 GtkIconViewChild *child = tmp_list->data;
1288 GtkRequisition child_requisition;
1290 tmp_list = tmp_list->next;
1292 if (GTK_WIDGET_VISIBLE (child->widget))
1293 gtk_widget_size_request (child->widget, &child_requisition);
1298 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1302 for (list = icon_view->priv->children; list; list = list->next)
1304 GtkIconViewChild *child = list->data;
1305 GtkAllocation allocation;
1307 /* totally ignore our child's requisition */
1308 if (child->cell < 0)
1310 allocation.x = child->item->x + ITEM_PADDING;
1311 allocation.y = child->item->y + ITEM_PADDING;
1312 allocation.width = child->item->width - ITEM_PADDING * 2;
1313 allocation.height = child->item->height - ITEM_PADDING * 2;
1317 GdkRectangle *box = &child->item->box[child->cell];
1319 allocation.x = box->x;
1320 allocation.y = box->y;
1321 allocation.width = box->width;
1322 allocation.height = box->height;
1325 gtk_widget_size_allocate (child->widget, &allocation);
1330 gtk_icon_view_size_allocate (GtkWidget *widget,
1331 GtkAllocation *allocation)
1333 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1335 GtkAdjustment *hadjustment, *vadjustment;
1337 widget->allocation = *allocation;
1339 if (GTK_WIDGET_REALIZED (widget))
1341 gdk_window_move_resize (widget->window,
1342 allocation->x, allocation->y,
1343 allocation->width, allocation->height);
1344 gdk_window_resize (icon_view->priv->bin_window,
1345 MAX (icon_view->priv->width, allocation->width),
1346 MAX (icon_view->priv->height, allocation->height));
1349 gtk_icon_view_layout (icon_view);
1351 gtk_icon_view_allocate_children (icon_view);
1353 hadjustment = icon_view->priv->hadjustment;
1354 vadjustment = icon_view->priv->vadjustment;
1356 hadjustment->page_size = allocation->width;
1357 hadjustment->page_increment = allocation->width * 0.9;
1358 hadjustment->step_increment = allocation->width * 0.1;
1359 hadjustment->lower = 0;
1360 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1362 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1363 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1365 vadjustment->page_size = allocation->height;
1366 vadjustment->page_increment = allocation->height * 0.9;
1367 vadjustment->step_increment = allocation->height * 0.1;
1368 vadjustment->lower = 0;
1369 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1371 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1372 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1374 if (GTK_WIDGET_REALIZED (widget) &&
1375 icon_view->priv->scroll_to_path)
1378 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1379 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1380 icon_view->priv->scroll_to_path = NULL;
1382 gtk_icon_view_scroll_to_path (icon_view, path,
1383 icon_view->priv->scroll_to_use_align,
1384 icon_view->priv->scroll_to_row_align,
1385 icon_view->priv->scroll_to_col_align);
1386 gtk_tree_path_free (path);
1390 gtk_adjustment_changed (hadjustment);
1391 gtk_adjustment_changed (vadjustment);
1396 gtk_icon_view_expose (GtkWidget *widget,
1397 GdkEventExpose *expose)
1399 GtkIconView *icon_view;
1404 GtkIconViewDropPosition dest_pos;
1405 GtkIconViewItem *dest_item = NULL;
1407 icon_view = GTK_ICON_VIEW (widget);
1409 if (expose->window != icon_view->priv->bin_window)
1412 cr = gdk_cairo_create (icon_view->priv->bin_window);
1413 cairo_set_line_width (cr, 1.);
1415 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1419 dest_index = gtk_tree_path_get_indices (path)[0];
1420 gtk_tree_path_free (path);
1425 for (icons = icon_view->priv->items; icons; icons = icons->next)
1427 GtkIconViewItem *item = icons->data;
1432 area.width = item->width;
1433 area.height = item->height;
1435 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1438 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1439 icon_view->priv->bin_window,
1441 icon_view->priv->draw_focus);
1443 if (dest_index == item->index)
1451 case GTK_ICON_VIEW_DROP_INTO:
1452 gtk_paint_focus (widget->style,
1453 icon_view->priv->bin_window,
1454 GTK_WIDGET_STATE (widget),
1457 "iconview-drop-indicator",
1458 dest_item->x, dest_item->y,
1459 dest_item->width, dest_item->height);
1461 case GTK_ICON_VIEW_DROP_ABOVE:
1462 gtk_paint_focus (widget->style,
1463 icon_view->priv->bin_window,
1464 GTK_WIDGET_STATE (widget),
1467 "iconview-drop-indicator",
1468 dest_item->x, dest_item->y - 1,
1469 dest_item->width, 2);
1471 case GTK_ICON_VIEW_DROP_LEFT:
1472 gtk_paint_focus (widget->style,
1473 icon_view->priv->bin_window,
1474 GTK_WIDGET_STATE (widget),
1477 "iconview-drop-indicator",
1478 dest_item->x - 1, dest_item->y,
1479 2, dest_item->height);
1481 case GTK_ICON_VIEW_DROP_BELOW:
1482 gtk_paint_focus (widget->style,
1483 icon_view->priv->bin_window,
1484 GTK_WIDGET_STATE (widget),
1487 "iconview-drop-indicator",
1488 dest_item->x, dest_item->y + dest_item->height - 1,
1489 dest_item->width, 2);
1491 case GTK_ICON_VIEW_DROP_RIGHT:
1492 gtk_paint_focus (widget->style,
1493 icon_view->priv->bin_window,
1494 GTK_WIDGET_STATE (widget),
1497 "iconview-drop-indicator",
1498 dest_item->x + dest_item->width - 1, dest_item->y,
1499 2, dest_item->height);
1500 case GTK_ICON_VIEW_NO_DROP: ;
1505 if (icon_view->priv->doing_rubberband)
1507 GdkRectangle *rectangles;
1510 gdk_region_get_rectangles (expose->region,
1514 while (n_rectangles--)
1515 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1517 g_free (rectangles);
1522 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1528 rubberband_scroll_timeout (gpointer data)
1530 GtkIconView *icon_view = data;
1532 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1533 icon_view->priv->vadjustment->value +
1534 icon_view->priv->scroll_value_diff);
1536 gtk_icon_view_update_rubberband (icon_view);
1542 gtk_icon_view_motion (GtkWidget *widget,
1543 GdkEventMotion *event)
1545 GtkIconView *icon_view;
1548 icon_view = GTK_ICON_VIEW (widget);
1550 gtk_icon_view_maybe_begin_drag (icon_view, event);
1552 if (icon_view->priv->doing_rubberband)
1554 gtk_icon_view_update_rubberband (widget);
1556 abs_y = event->y - icon_view->priv->height *
1557 (icon_view->priv->vadjustment->value /
1558 (icon_view->priv->vadjustment->upper -
1559 icon_view->priv->vadjustment->lower));
1561 if (abs_y < 0 || abs_y > widget->allocation.height)
1564 icon_view->priv->scroll_value_diff = abs_y;
1566 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1568 icon_view->priv->event_last_x = event->x;
1569 icon_view->priv->event_last_y = event->y;
1571 if (icon_view->priv->scroll_timeout_id == 0)
1572 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1576 remove_scroll_timeout (icon_view);
1583 gtk_icon_view_remove (GtkContainer *container,
1586 GtkIconView *icon_view;
1587 GtkIconViewChild *child = NULL;
1590 icon_view = GTK_ICON_VIEW (container);
1592 tmp_list = icon_view->priv->children;
1595 child = tmp_list->data;
1596 if (child->widget == widget)
1598 gtk_widget_unparent (widget);
1600 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1601 g_list_free_1 (tmp_list);
1606 tmp_list = tmp_list->next;
1611 gtk_icon_view_forall (GtkContainer *container,
1612 gboolean include_internals,
1613 GtkCallback callback,
1614 gpointer callback_data)
1616 GtkIconView *icon_view;
1617 GtkIconViewChild *child = NULL;
1620 icon_view = GTK_ICON_VIEW (container);
1622 tmp_list = icon_view->priv->children;
1625 child = tmp_list->data;
1626 tmp_list = tmp_list->next;
1628 (* callback) (child->widget, callback_data);
1633 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1634 GtkIconViewItem *item,
1635 GtkIconViewCellInfo *info,
1640 GdkRectangle cell_area;
1641 gboolean visible, mode;
1643 gtk_icon_view_set_cell_data (icon_view, item);
1645 g_object_get (info->cell,
1646 "visible", &visible,
1650 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1652 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1654 path = gtk_tree_path_new_from_indices (item->index, -1);
1655 path_string = gtk_tree_path_to_string (path);
1656 gtk_tree_path_free (path);
1658 gtk_cell_renderer_activate (info->cell,
1660 GTK_WIDGET (icon_view),
1666 g_free (path_string);
1671 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1672 GtkIconViewItem *item)
1675 AtkObject *item_obj;
1677 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1680 item_obj = atk_object_ref_accessible_child (obj, item->index);
1681 if (item_obj != NULL)
1683 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1684 g_object_unref (item_obj);
1690 gtk_icon_view_put (GtkIconView *icon_view,
1692 GtkIconViewItem *item,
1695 GtkIconViewChild *child;
1697 child = g_new (GtkIconViewChild, 1);
1699 child->widget = widget;
1703 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1705 if (GTK_WIDGET_REALIZED (icon_view))
1706 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1708 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1712 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1713 GtkIconView *icon_view)
1716 GtkIconViewItem *item;
1718 if (icon_view->priv->edited_item == NULL)
1721 item = icon_view->priv->edited_item;
1722 icon_view->priv->edited_item = NULL;
1723 icon_view->priv->editable = NULL;
1724 for (l = icon_view->priv->cell_list; l; l = l->next)
1726 GtkIconViewCellInfo *info = l->data;
1728 info->editing = FALSE;
1731 if (GTK_WIDGET_HAS_FOCUS (editable))
1732 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1734 g_signal_handlers_disconnect_by_func (editable,
1735 gtk_icon_view_remove_widget,
1738 gtk_container_remove (GTK_CONTAINER (icon_view),
1739 GTK_WIDGET (editable));
1741 gtk_icon_view_queue_draw_item (icon_view, item);
1746 gtk_icon_view_start_editing (GtkIconView *icon_view,
1747 GtkIconViewItem *item,
1748 GtkIconViewCellInfo *info,
1753 GdkRectangle cell_area;
1754 gboolean visible, mode;
1755 GtkCellEditable *editable;
1757 gtk_icon_view_set_cell_data (icon_view, item);
1759 g_object_get (info->cell,
1760 "visible", &visible,
1763 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1765 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1767 path = gtk_tree_path_new_from_indices (item->index, -1);
1768 path_string = gtk_tree_path_to_string (path);
1769 gtk_tree_path_free (path);
1771 editable = gtk_cell_renderer_start_editing (info->cell,
1773 GTK_WIDGET (icon_view),
1778 g_free (path_string);
1780 /* the rest corresponds to tree_view_real_start_editing... */
1781 icon_view->priv->edited_item = item;
1782 icon_view->priv->editable = editable;
1783 info->editing = TRUE;
1785 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1787 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1789 gtk_widget_grab_focus (GTK_WIDGET (editable));
1790 g_signal_connect (editable, "remove-widget",
1791 G_CALLBACK (gtk_icon_view_remove_widget),
1798 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1799 gboolean cancel_editing)
1801 GtkCellRenderer *cell = NULL;
1802 GtkIconViewItem *item;
1805 if (icon_view->priv->edited_item == NULL)
1809 * This is very evil. We need to do this, because
1810 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1811 * later on. If gtk_icon_view_row_changed notices
1812 * icon_view->priv->edited_item != NULL, it'll call
1813 * gtk_icon_view_stop_editing again. Bad things will happen then.
1815 * Please read that again if you intend to modify anything here.
1818 item = icon_view->priv->edited_item;
1819 icon_view->priv->edited_item = NULL;
1821 for (l = icon_view->priv->cell_list; l; l = l->next)
1823 GtkIconViewCellInfo *info = l->data;
1835 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1836 if (!cancel_editing)
1837 gtk_cell_editable_editing_done (icon_view->priv->editable);
1839 icon_view->priv->edited_item = item;
1841 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1845 * gtk_icon_view_set_cursor:
1846 * @icon_view: A #GtkIconView
1847 * @path: A #GtkTreePath
1848 * @cell: One of the cell renderers of @icon_view, or %NULL
1849 * @start_editing: %TRUE if the specified cell should start being edited.
1851 * Sets the current keyboard focus to be at @path, and selects it. This is
1852 * useful when you want to focus the user's attention on a particular item.
1853 * If @cell is not %NULL, then focus is given to the cell specified by
1854 * it. Additionally, if @start_editing is %TRUE, then editing should be
1855 * started in the specified cell.
1857 * This function is often followed by <literal>gtk_widget_grab_focus
1858 * (icon_view)</literal> in order to give keyboard focus to the widget.
1859 * Please note that editing can only happen when the widget is realized.
1864 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1866 GtkCellRenderer *cell,
1867 gboolean start_editing)
1869 GtkIconViewItem *item = NULL;
1870 GtkIconViewCellInfo *info = NULL;
1874 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1875 g_return_if_fail (path != NULL);
1876 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1878 gtk_icon_view_stop_editing (icon_view, TRUE);
1880 if (gtk_tree_path_get_depth (path) == 1)
1881 item = g_list_nth_data (icon_view->priv->items,
1882 gtk_tree_path_get_indices(path)[0]);
1888 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1892 if (info->cell == cell)
1901 g_return_if_fail (cell == NULL || info != NULL);
1903 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1904 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1906 if (info && start_editing)
1907 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1911 * gtk_icon_view_get_cursor:
1912 * @icon_view: A #GtkIconView
1913 * @path: Return location for the current cursor path, or %NULL
1914 * @cell: Return location the current focus cell, or %NULL
1916 * Fills in @path and @cell with the current cursor path and cell.
1917 * If the cursor isn't currently set, then *@path will be %NULL.
1918 * If no cell currently has focus, then *@cell will be %NULL.
1920 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1922 * Return value: %TRUE if the cursor is set.
1927 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1929 GtkCellRenderer **cell)
1931 GtkIconViewItem *item;
1932 GtkIconViewCellInfo *info;
1934 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1936 item = icon_view->priv->cursor_item;
1937 if (icon_view->priv->cursor_cell < 0)
1940 info = g_list_nth_data (icon_view->priv->cell_list,
1941 icon_view->priv->cursor_cell);
1946 *path = gtk_tree_path_new_from_indices (item->index, -1);
1959 return (item != NULL);
1963 gtk_icon_view_button_press (GtkWidget *widget,
1964 GdkEventButton *event)
1966 GtkIconView *icon_view;
1967 GtkIconViewItem *item;
1968 GtkIconViewCellInfo *info = NULL;
1969 gboolean dirty = FALSE;
1970 GtkCellRendererMode mode;
1971 gint cursor_cell = -1;
1973 icon_view = GTK_ICON_VIEW (widget);
1975 if (event->window != icon_view->priv->bin_window)
1978 if (!GTK_WIDGET_HAS_FOCUS (widget))
1979 gtk_widget_grab_focus (widget);
1981 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1983 item = gtk_icon_view_get_item_at_coords (icon_view,
1989 * We consider only the the cells' area as the item area if the
1990 * item is not selected, but if it *is* selected, the complete
1991 * selection rectangle is considered to be part of the item.
1993 if (item != NULL && (info != NULL || item->selected))
1997 g_object_get (info->cell, "mode", &mode, NULL);
1999 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2000 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2001 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2004 gtk_icon_view_scroll_to_item (icon_view, item);
2006 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2008 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2010 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2011 (event->state & GDK_SHIFT_MASK))
2013 gtk_icon_view_unselect_all_internal (icon_view);
2015 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2016 if (!icon_view->priv->anchor_item)
2017 icon_view->priv->anchor_item = item;
2019 gtk_icon_view_select_all_between (icon_view,
2020 icon_view->priv->anchor_item,
2026 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2027 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2028 (event->state & GDK_CONTROL_MASK))
2030 item->selected = !item->selected;
2031 gtk_icon_view_queue_draw_item (icon_view, item);
2036 if (!item->selected)
2038 gtk_icon_view_unselect_all_internal (icon_view);
2040 item->selected = TRUE;
2041 gtk_icon_view_queue_draw_item (icon_view, item);
2045 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2046 icon_view->priv->anchor_item = item;
2049 /* Save press to possibly begin a drag */
2050 if (icon_view->priv->pressed_button < 0)
2052 icon_view->priv->pressed_button = event->button;
2053 icon_view->priv->press_start_x = event->x;
2054 icon_view->priv->press_start_y = event->y;
2057 if (!icon_view->priv->last_single_clicked)
2058 icon_view->priv->last_single_clicked = item;
2060 /* cancel the current editing, if it exists */
2061 gtk_icon_view_stop_editing (icon_view, TRUE);
2065 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2066 gtk_icon_view_item_activate_cell (icon_view, item, info,
2068 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2069 gtk_icon_view_start_editing (icon_view, item, info,
2075 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2076 !(event->state & GDK_CONTROL_MASK))
2078 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2081 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2082 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2085 /* don't draw keyboard focus around an clicked-on item */
2086 icon_view->priv->draw_focus = FALSE;
2089 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2091 item = gtk_icon_view_get_item_at_coords (icon_view,
2096 if (item && item == icon_view->priv->last_single_clicked)
2100 path = gtk_tree_path_new_from_indices (item->index, -1);
2101 gtk_icon_view_item_activated (icon_view, path);
2102 gtk_tree_path_free (path);
2105 icon_view->priv->last_single_clicked = NULL;
2106 icon_view->priv->pressed_button = -1;
2110 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2112 return event->button == 1;
2116 gtk_icon_view_button_release (GtkWidget *widget,
2117 GdkEventButton *event)
2119 GtkIconView *icon_view;
2121 icon_view = GTK_ICON_VIEW (widget);
2123 if (icon_view->priv->pressed_button == event->button)
2124 icon_view->priv->pressed_button = -1;
2126 gtk_icon_view_stop_rubberbanding (icon_view);
2128 remove_scroll_timeout (icon_view);
2134 gtk_icon_view_key_press (GtkWidget *widget,
2137 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2139 if (icon_view->priv->doing_rubberband)
2141 if (event->keyval == GDK_Escape)
2142 gtk_icon_view_stop_rubberbanding (icon_view);
2147 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2151 gtk_icon_view_key_release (GtkWidget *widget,
2154 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2156 if (icon_view->priv->doing_rubberband)
2159 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2163 gtk_icon_view_update_rubberband (gpointer data)
2165 GtkIconView *icon_view;
2167 GdkRectangle old_area;
2168 GdkRectangle new_area;
2169 GdkRectangle common;
2170 GdkRegion *invalid_region;
2172 icon_view = GTK_ICON_VIEW (data);
2174 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2179 old_area.x = MIN (icon_view->priv->rubberband_x1,
2180 icon_view->priv->rubberband_x2);
2181 old_area.y = MIN (icon_view->priv->rubberband_y1,
2182 icon_view->priv->rubberband_y2);
2183 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2184 icon_view->priv->rubberband_x1) + 1;
2185 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2186 icon_view->priv->rubberband_y1) + 1;
2188 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2189 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2190 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2191 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2193 invalid_region = gdk_region_rectangle (&old_area);
2194 gdk_region_union_with_rect (invalid_region, &new_area);
2196 gdk_rectangle_intersect (&old_area, &new_area, &common);
2197 if (common.width > 2 && common.height > 2)
2199 GdkRegion *common_region;
2201 /* make sure the border is invalidated */
2207 common_region = gdk_region_rectangle (&common);
2209 gdk_region_subtract (invalid_region, common_region);
2210 gdk_region_destroy (common_region);
2213 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2215 gdk_region_destroy (invalid_region);
2217 icon_view->priv->rubberband_x2 = x;
2218 icon_view->priv->rubberband_y2 = y;
2220 gtk_icon_view_update_rubberband_selection (icon_view);
2224 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2230 g_assert (!icon_view->priv->doing_rubberband);
2232 for (items = icon_view->priv->items; items; items = items->next)
2234 GtkIconViewItem *item = items->data;
2236 item->selected_before_rubberbanding = item->selected;
2239 icon_view->priv->rubberband_x1 = x;
2240 icon_view->priv->rubberband_y1 = y;
2241 icon_view->priv->rubberband_x2 = x;
2242 icon_view->priv->rubberband_y2 = y;
2244 icon_view->priv->doing_rubberband = TRUE;
2246 gtk_grab_add (GTK_WIDGET (icon_view));
2250 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2252 if (!icon_view->priv->doing_rubberband)
2255 icon_view->priv->doing_rubberband = FALSE;
2257 gtk_grab_remove (GTK_WIDGET (icon_view));
2259 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2263 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2266 gint x, y, width, height;
2267 gboolean dirty = FALSE;
2269 x = MIN (icon_view->priv->rubberband_x1,
2270 icon_view->priv->rubberband_x2);
2271 y = MIN (icon_view->priv->rubberband_y1,
2272 icon_view->priv->rubberband_y2);
2273 width = ABS (icon_view->priv->rubberband_x1 -
2274 icon_view->priv->rubberband_x2);
2275 height = ABS (icon_view->priv->rubberband_y1 -
2276 icon_view->priv->rubberband_y2);
2278 for (items = icon_view->priv->items; items; items = items->next)
2280 GtkIconViewItem *item = items->data;
2284 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2285 x, y, width, height);
2287 selected = is_in ^ item->selected_before_rubberbanding;
2289 if (item->selected != selected)
2291 item->selected = selected;
2293 gtk_icon_view_queue_draw_item (icon_view, item);
2298 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2302 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2303 GtkIconViewItem *item,
2312 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2313 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2316 for (l = icon_view->priv->cell_list; l; l = l->next)
2318 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2320 if (!info->cell->visible)
2323 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2325 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2326 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2334 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2336 gboolean dirty = FALSE;
2339 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2342 for (items = icon_view->priv->items; items; items = items->next)
2344 GtkIconViewItem *item = items->data;
2348 item->selected = FALSE;
2350 gtk_icon_view_queue_draw_item (icon_view, item);
2351 gtk_icon_view_item_selected_changed (icon_view, item);
2359 /* GtkIconView signals */
2361 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2362 GtkAdjustment *hadj,
2363 GtkAdjustment *vadj)
2365 gboolean need_adjust = FALSE;
2368 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2370 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2372 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2374 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2376 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2378 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2379 0, 0, NULL, NULL, icon_view);
2380 g_object_unref (icon_view->priv->hadjustment);
2383 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2385 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2386 0, 0, NULL, NULL, icon_view);
2387 g_object_unref (icon_view->priv->vadjustment);
2390 if (icon_view->priv->hadjustment != hadj)
2392 icon_view->priv->hadjustment = hadj;
2393 g_object_ref_sink (icon_view->priv->hadjustment);
2395 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2396 G_CALLBACK (gtk_icon_view_adjustment_changed),
2401 if (icon_view->priv->vadjustment != vadj)
2403 icon_view->priv->vadjustment = vadj;
2404 g_object_ref_sink (icon_view->priv->vadjustment);
2406 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2407 G_CALLBACK (gtk_icon_view_adjustment_changed),
2413 gtk_icon_view_adjustment_changed (NULL, icon_view);
2417 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2419 gtk_icon_view_select_all (icon_view);
2423 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2425 gtk_icon_view_unselect_all (icon_view);
2429 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2431 gtk_icon_view_unselect_all (icon_view);
2433 if (icon_view->priv->cursor_item != NULL)
2434 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2438 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2441 GtkCellRendererMode mode;
2442 GtkIconViewCellInfo *info = NULL;
2444 if (!icon_view->priv->cursor_item)
2447 info = g_list_nth_data (icon_view->priv->cell_list,
2448 icon_view->priv->cursor_cell);
2452 g_object_get (info->cell, "mode", &mode, NULL);
2454 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2456 gtk_icon_view_item_activate_cell (icon_view,
2457 icon_view->priv->cursor_item,
2461 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2463 gtk_icon_view_start_editing (icon_view,
2464 icon_view->priv->cursor_item,
2470 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2471 gtk_icon_view_item_activated (icon_view, path);
2472 gtk_tree_path_free (path);
2478 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2480 if (!icon_view->priv->cursor_item)
2483 switch (icon_view->priv->selection_mode)
2485 case GTK_SELECTION_NONE:
2487 case GTK_SELECTION_BROWSE:
2488 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2490 case GTK_SELECTION_SINGLE:
2491 if (icon_view->priv->cursor_item->selected)
2492 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2494 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2496 case GTK_SELECTION_MULTIPLE:
2497 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2498 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2500 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2501 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2506 /* Internal functions */
2508 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2509 GtkIconView *icon_view)
2511 if (GTK_WIDGET_REALIZED (icon_view))
2513 gdk_window_move (icon_view->priv->bin_window,
2514 - icon_view->priv->hadjustment->value,
2515 - icon_view->priv->vadjustment->value);
2517 if (icon_view->priv->doing_rubberband)
2518 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2520 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2525 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2530 gint *maximum_width)
2533 gint x, current_width;
2534 GList *items, *last_item;
2541 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2542 max_height = g_new0 (gint, icon_view->priv->n_cells);
2549 gtk_widget_style_get (GTK_WIDGET (icon_view),
2550 "focus-line-width", &focus_width,
2553 x += icon_view->priv->margin + focus_width;
2554 current_width += 2 * (icon_view->priv->margin + focus_width);
2559 GtkIconViewItem *item = items->data;
2561 gtk_icon_view_calculate_item_size (icon_view, item);
2562 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2564 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2566 current_width += item->width;
2568 if (items != first_item)
2570 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2571 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2575 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2577 item->y = *y + focus_width;
2580 x = current_width - (icon_view->priv->margin + focus_width);
2582 for (i = 0; i < icon_view->priv->n_cells; i++)
2583 max_height[i] = MAX (max_height[i], item->box[i].height);
2585 if (current_width > *maximum_width)
2586 *maximum_width = current_width;
2592 items = items->next;
2597 /* Now go through the row again and align the icons */
2598 for (items = first_item; items != last_item; items = items->next)
2600 GtkIconViewItem *item = items->data;
2604 item->x = *maximum_width - item->width - item->x;
2605 item->col = col - 1 - item->col;
2608 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2610 /* We may want to readjust the new y coordinate. */
2611 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2612 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2615 g_free (max_height);
2621 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2624 if (upper != adj->upper)
2626 gdouble min = MAX (0.0, upper - adj->page_size);
2627 gboolean value_changed = FALSE;
2631 if (adj->value > min)
2634 value_changed = TRUE;
2637 gtk_adjustment_changed (adj);
2640 gtk_adjustment_value_changed (adj);
2645 gtk_icon_view_layout (GtkIconView *icon_view)
2647 gint y = 0, maximum_width = 0;
2653 if (icon_view->priv->layout_idle_id != 0)
2655 g_source_remove (icon_view->priv->layout_idle_id);
2656 icon_view->priv->layout_idle_id = 0;
2659 if (icon_view->priv->model == NULL)
2662 widget = GTK_WIDGET (icon_view);
2664 item_width = icon_view->priv->item_width;
2668 for (icons = icon_view->priv->items; icons; icons = icons->next)
2670 GtkIconViewItem *item = icons->data;
2671 gtk_icon_view_calculate_item_size (icon_view, item);
2672 item_width = MAX (item_width, item->width);
2677 icons = icon_view->priv->items;
2678 y += icon_view->priv->margin;
2683 gtk_icon_view_set_cell_data (icon_view, icons->data);
2684 adjust_wrap_width (icon_view, icons->data);
2689 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2691 &y, &maximum_width);
2694 while (icons != NULL);
2696 if (maximum_width != icon_view->priv->width)
2697 icon_view->priv->width = maximum_width;
2699 y += icon_view->priv->margin;
2701 if (y != icon_view->priv->height)
2702 icon_view->priv->height = y;
2704 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2705 icon_view->priv->width);
2706 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2707 icon_view->priv->height);
2709 if (icon_view->priv->width != widget->requisition.width ||
2710 icon_view->priv->height != widget->requisition.height)
2711 gtk_widget_queue_resize_no_redraw (widget);
2713 if (GTK_WIDGET_REALIZED (icon_view))
2714 gdk_window_resize (icon_view->priv->bin_window,
2715 MAX (icon_view->priv->width, widget->allocation.width),
2716 MAX (icon_view->priv->height, widget->allocation.height));
2718 if (icon_view->priv->scroll_to_path)
2722 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2723 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2724 icon_view->priv->scroll_to_path = NULL;
2726 gtk_icon_view_scroll_to_path (icon_view, path,
2727 icon_view->priv->scroll_to_use_align,
2728 icon_view->priv->scroll_to_row_align,
2729 icon_view->priv->scroll_to_col_align);
2730 gtk_tree_path_free (path);
2733 gtk_widget_queue_draw (widget);
2737 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2738 GtkIconViewItem *item,
2739 GtkIconViewCellInfo *info,
2740 GdkRectangle *cell_area)
2742 g_return_if_fail (info->position < item->n_cells);
2744 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2746 cell_area->x = item->box[info->position].x - item->before[info->position];
2747 cell_area->y = item->y + ITEM_PADDING;
2748 cell_area->width = item->box[info->position].width +
2749 item->before[info->position] + item->after[info->position];
2750 cell_area->height = item->height - ITEM_PADDING * 2;
2754 cell_area->x = item->x + ITEM_PADDING;
2755 cell_area->y = item->box[info->position].y - item->before[info->position];
2756 cell_area->width = item->width - ITEM_PADDING * 2;
2757 cell_area->height = item->box[info->position].height +
2758 item->before[info->position] + item->after[info->position];
2763 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2764 GtkIconViewItem *item,
2765 GtkIconViewCellInfo *info,
2768 g_return_if_fail (info->position < item->n_cells);
2770 *box = item->box[info->position];
2773 /* try to guess a reasonable wrap width for an implicit text cell renderer
2776 adjust_wrap_width (GtkIconView *icon_view,
2777 GtkIconViewItem *item)
2779 GtkIconViewCellInfo *text_info;
2780 GtkIconViewCellInfo *pixbuf_info;
2781 gint pixbuf_width, wrap_width;
2783 if (icon_view->priv->text_cell != -1 &&
2784 icon_view->priv->pixbuf_cell != -1)
2788 text_info = g_list_nth_data (icon_view->priv->cell_list,
2789 icon_view->priv->text_cell);
2790 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2791 icon_view->priv->pixbuf_cell);
2793 gtk_cell_renderer_get_size (pixbuf_info->cell,
2794 GTK_WIDGET (icon_view),
2800 if (icon_view->priv->item_width > 0)
2801 item_width = icon_view->priv->item_width;
2803 item_width = item->width;
2805 if (item->width == -1)
2808 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2810 wrap_width = MAX (2 * pixbuf_width, 50);
2812 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2813 wrap_width = item_width;
2815 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2817 wrap_width -= ITEM_PADDING * 2;
2819 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2820 g_object_set (text_info->cell, "width", wrap_width, NULL);
2825 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2826 GtkIconViewItem *item)
2831 if (item->width != -1 && item->height != -1)
2834 if (item->n_cells != icon_view->priv->n_cells)
2836 g_free (item->before);
2837 g_free (item->after);
2840 item->before = g_new0 (gint, icon_view->priv->n_cells);
2841 item->after = g_new0 (gint, icon_view->priv->n_cells);
2842 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2844 item->n_cells = icon_view->priv->n_cells;
2847 gtk_icon_view_set_cell_data (icon_view, item);
2849 spacing = icon_view->priv->spacing;
2853 for (l = icon_view->priv->cell_list; l; l = l->next)
2855 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2857 if (!info->cell->visible)
2860 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2862 &item->box[info->position].width,
2863 &item->box[info->position].height);
2865 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2867 item->width += item->box[info->position].width
2868 + (info->position > 0 ? spacing : 0);
2869 item->height = MAX (item->height, item->box[info->position].height);
2873 item->width = MAX (item->width, item->box[info->position].width);
2874 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2878 item->width += ITEM_PADDING * 2;
2879 item->height += ITEM_PADDING * 2;
2883 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2884 GtkIconViewItem *item,
2887 GdkRectangle cell_area;
2893 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2895 gtk_icon_view_set_cell_data (icon_view, item);
2897 spacing = icon_view->priv->spacing;
2900 for (i = 0; i < icon_view->priv->n_cells; i++)
2902 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2903 item->height = MAX (item->height, max_height[i]);
2905 item->height += max_height[i] + (i > 0 ? spacing : 0);
2908 cell_area.x = item->x + ITEM_PADDING;
2909 cell_area.y = item->y + ITEM_PADDING;
2911 for (k = 0; k < 2; k++)
2912 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2914 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2916 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2919 if (!info->cell->visible)
2922 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2924 /* We should not subtract ITEM_PADDING from item->height,
2925 * because item->height is recalculated above using
2926 * max_height which does not contain item padding.
2928 cell_area.width = item->box[info->position].width;
2929 cell_area.height = item->height;
2933 /* item->width is not recalculated and thus needs to be
2934 * corrected for the padding.
2936 cell_area.width = item->width - 2 * ITEM_PADDING;
2937 cell_area.height = max_height[i];
2940 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2942 &item->box[info->position].x, &item->box[info->position].y,
2943 &item->box[info->position].width, &item->box[info->position].height);
2945 item->box[info->position].x += cell_area.x;
2946 item->box[info->position].y += cell_area.y;
2947 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2949 item->before[info->position] = item->box[info->position].x - cell_area.x;
2950 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2951 cell_area.x += cell_area.width + spacing;
2955 if (item->box[info->position].width > item->width - ITEM_PADDING * 2)
2957 item->width = item->box[info->position].width + ITEM_PADDING * 2;
2958 cell_area.width = item->width;
2960 item->before[info->position] = item->box[info->position].y - cell_area.y;
2961 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2962 cell_area.y += cell_area.height + spacing;
2966 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2968 for (i = 0; i < icon_view->priv->n_cells; i++)
2970 item->box[i].x = item->x + item->width -
2971 (item->box[i].x + item->box[i].width - item->x);
2975 item->height += ITEM_PADDING * 2;
2979 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2981 g_list_foreach (icon_view->priv->items,
2982 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2986 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2993 gtk_icon_view_paint_item (GtkIconView *icon_view,
2995 GtkIconViewItem *item,
2997 GdkDrawable *drawable,
3000 gboolean draw_focus)
3004 GdkRectangle cell_area, box;
3008 GtkCellRendererState flags;
3010 if (icon_view->priv->model == NULL)
3013 gtk_icon_view_set_cell_data (icon_view, item);
3015 gtk_widget_style_get (GTK_WIDGET (icon_view),
3016 "focus-line-width", &focus_width,
3019 padding = focus_width;
3023 flags = GTK_CELL_RENDERER_SELECTED;
3024 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3025 state = GTK_STATE_SELECTED;
3027 state = GTK_STATE_ACTIVE;
3032 state = GTK_STATE_NORMAL;
3035 #ifdef DEBUG_ICON_VIEW
3036 gdk_draw_rectangle (drawable,
3037 GTK_WIDGET (icon_view)->style->black_gc,
3040 item->width, item->height);
3045 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3046 (GdkWindow *) drawable,
3050 GTK_WIDGET (icon_view),
3053 item->width, item->height);
3056 for (l = icon_view->priv->cell_list; l; l = l->next)
3058 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3060 if (!info->cell->visible)
3063 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3065 #ifdef DEBUG_ICON_VIEW
3066 gdk_draw_rectangle (drawable,
3067 GTK_WIDGET (icon_view)->style->black_gc,
3069 x - item->x + cell_area.x,
3070 y - item->y + cell_area.y,
3071 cell_area.width, cell_area.height);
3073 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3075 gdk_draw_rectangle (drawable,
3076 GTK_WIDGET (icon_view)->style->black_gc,
3078 x - item->x + box.x,
3079 y - item->y + box.y,
3080 box.width, box.height);
3083 cell_area.x = x - item->x + cell_area.x;
3084 cell_area.y = y - item->y + cell_area.y;
3086 gtk_cell_renderer_render (info->cell,
3088 GTK_WIDGET (icon_view),
3089 &cell_area, &cell_area, area, flags);
3093 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3094 item == icon_view->priv->cursor_item)
3096 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3098 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3100 if (!info->cell->visible)
3103 /* If found a editable/activatable cell, draw focus on it. */
3104 if (icon_view->priv->cursor_cell < 0 &&
3105 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3106 icon_view->priv->cursor_cell = i;
3108 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3110 if (i == icon_view->priv->cursor_cell)
3112 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3116 GTK_WIDGET (icon_view),
3118 x - item->x + box.x - padding,
3119 y - item->y + box.y - padding,
3120 box.width + 2 * padding,
3121 box.height + 2 * padding);
3126 /* If there are no editable/activatable cells, draw focus
3127 * around the whole item.
3129 if (icon_view->priv->cursor_cell < 0)
3130 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3134 GTK_WIDGET (icon_view),
3138 item->width + 2 * padding,
3139 item->height + 2 * padding);
3144 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3149 GdkRectangle rubber_rect;
3150 GdkColor *fill_color_gdk;
3151 guchar fill_color_alpha;
3153 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3154 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3155 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3156 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3158 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3161 gtk_widget_style_get (GTK_WIDGET (icon_view),
3162 "selection-box-color", &fill_color_gdk,
3163 "selection-box-alpha", &fill_color_alpha,
3166 if (!fill_color_gdk)
3167 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3169 cairo_set_source_rgba (cr,
3170 fill_color_gdk->red / 65535.,
3171 fill_color_gdk->green / 65535.,
3172 fill_color_gdk->blue / 65535.,
3173 fill_color_alpha / 255.);
3176 gdk_cairo_rectangle (cr, &rect);
3180 /* Draw the border without alpha */
3181 cairo_set_source_rgb (cr,
3182 fill_color_gdk->red / 65535.,
3183 fill_color_gdk->green / 65535.,
3184 fill_color_gdk->blue / 65535.);
3185 cairo_rectangle (cr,
3186 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3187 rubber_rect.width - 1, rubber_rect.height - 1);
3191 gdk_color_free (fill_color_gdk);
3195 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3201 index = gtk_tree_path_get_indices (path)[0];
3203 for (l = icon_view->priv->items; l; l = l->next)
3205 GtkIconViewItem *item = l->data;
3207 if (item->index == index)
3209 gtk_icon_view_queue_draw_item (icon_view, item);
3216 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3217 GtkIconViewItem *item)
3222 gtk_widget_style_get (GTK_WIDGET (icon_view),
3223 "focus-line-width", &focus_width,
3226 rect.x = item->x - focus_width;
3227 rect.y = item->y - focus_width;
3228 rect.width = item->width + 2 * focus_width;
3229 rect.height = item->height + 2 * focus_width;
3231 if (icon_view->priv->bin_window)
3232 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3236 layout_callback (gpointer user_data)
3238 GtkIconView *icon_view;
3240 icon_view = GTK_ICON_VIEW (user_data);
3242 icon_view->priv->layout_idle_id = 0;
3244 gtk_icon_view_layout (icon_view);
3250 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3252 if (icon_view->priv->layout_idle_id != 0)
3255 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3259 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3260 GtkIconViewItem *item,
3264 AtkObject *item_obj;
3265 AtkObject *cursor_item_obj;
3267 if (icon_view->priv->cursor_item == item &&
3268 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3271 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3272 if (icon_view->priv->cursor_item != NULL)
3274 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3277 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3278 if (cursor_item_obj != NULL)
3279 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3282 icon_view->priv->cursor_item = item;
3283 if (cursor_cell >= 0)
3284 icon_view->priv->cursor_cell = cursor_cell;
3286 gtk_icon_view_queue_draw_item (icon_view, item);
3288 /* Notify that accessible focus object has changed */
3289 item_obj = atk_object_ref_accessible_child (obj, item->index);
3291 if (item_obj != NULL)
3293 atk_focus_tracker_notify (item_obj);
3294 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3295 g_object_unref (item_obj);
3300 static GtkIconViewItem *
3301 gtk_icon_view_item_new (void)
3303 GtkIconViewItem *item;
3305 item = g_new0 (GtkIconViewItem, 1);
3314 gtk_icon_view_item_free (GtkIconViewItem *item)
3316 g_return_if_fail (item != NULL);
3318 g_free (item->before);
3319 g_free (item->after);
3326 static GtkIconViewItem *
3327 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3330 gboolean only_in_cell,
3331 GtkIconViewCellInfo **cell_at_pos)
3336 for (items = icon_view->priv->items; items; items = items->next)
3338 GtkIconViewItem *item = items->data;
3340 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3341 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3343 if (only_in_cell || cell_at_pos)
3345 gtk_icon_view_set_cell_data (icon_view, item);
3347 for (l = icon_view->priv->cell_list; l; l = l->next)
3349 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3351 if (!info->cell->visible)
3354 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3356 if ((x >= box.x && x <= box.x + box.width &&
3357 y >= box.y && y <= box.y + box.height) ||
3359 x <= box.x + box.width &&
3361 y <= box.y + box.height))
3364 *cell_at_pos = info;
3374 *cell_at_pos = NULL;
3385 gtk_icon_view_select_item (GtkIconView *icon_view,
3386 GtkIconViewItem *item)
3388 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3389 g_return_if_fail (item != NULL);
3394 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3396 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3397 gtk_icon_view_unselect_all_internal (icon_view);
3399 item->selected = TRUE;
3401 gtk_icon_view_item_selected_changed (icon_view, item);
3402 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3404 gtk_icon_view_queue_draw_item (icon_view, item);
3409 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3410 GtkIconViewItem *item)
3412 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3413 g_return_if_fail (item != NULL);
3415 if (!item->selected)
3418 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3419 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3422 item->selected = FALSE;
3424 gtk_icon_view_item_selected_changed (icon_view, item);
3425 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3427 gtk_icon_view_queue_draw_item (icon_view, item);
3431 verify_items (GtkIconView *icon_view)
3436 for (items = icon_view->priv->items; items; items = items->next)
3438 GtkIconViewItem *item = items->data;
3440 if (item->index != i)
3441 g_error ("List item does not match its index: "
3442 "item index %d and list index %d\n", item->index, i);
3449 gtk_icon_view_row_changed (GtkTreeModel *model,
3454 GtkIconViewItem *item;
3456 GtkIconView *icon_view;
3458 icon_view = GTK_ICON_VIEW (data);
3460 gtk_icon_view_stop_editing (icon_view, TRUE);
3462 index = gtk_tree_path_get_indices(path)[0];
3463 item = g_list_nth_data (icon_view->priv->items, index);
3465 gtk_icon_view_item_invalidate_size (item);
3466 gtk_icon_view_queue_layout (icon_view);
3468 verify_items (icon_view);
3472 gtk_icon_view_row_inserted (GtkTreeModel *model,
3478 GtkIconViewItem *item;
3479 gboolean iters_persist;
3480 GtkIconView *icon_view;
3483 icon_view = GTK_ICON_VIEW (data);
3485 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3487 index = gtk_tree_path_get_indices(path)[0];
3489 item = gtk_icon_view_item_new ();
3494 item->index = index;
3496 /* FIXME: We can be more efficient here,
3497 we can store a tail pointer and use that when
3498 appending (which is a rather common operation)
3500 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3503 list = g_list_nth (icon_view->priv->items, index + 1);
3504 for (; list; list = list->next)
3511 verify_items (icon_view);
3513 gtk_icon_view_queue_layout (icon_view);
3517 gtk_icon_view_row_deleted (GtkTreeModel *model,
3522 GtkIconView *icon_view;
3523 GtkIconViewItem *item;
3525 gboolean emit = FALSE;
3527 icon_view = GTK_ICON_VIEW (data);
3529 index = gtk_tree_path_get_indices(path)[0];
3531 list = g_list_nth (icon_view->priv->items, index);
3534 gtk_icon_view_stop_editing (icon_view, TRUE);
3536 if (item == icon_view->priv->anchor_item)
3537 icon_view->priv->anchor_item = NULL;
3539 if (item == icon_view->priv->cursor_item)
3540 icon_view->priv->cursor_item = NULL;
3545 gtk_icon_view_item_free (item);
3547 for (next = list->next; next; next = next->next)
3554 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3556 verify_items (icon_view);
3558 gtk_icon_view_queue_layout (icon_view);
3561 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3565 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3566 GtkTreePath *parent,
3573 GtkIconView *icon_view;
3574 GList *items = NULL, *list;
3575 GtkIconViewItem **item_array;
3578 icon_view = GTK_ICON_VIEW (data);
3580 gtk_icon_view_stop_editing (icon_view, TRUE);
3582 length = gtk_tree_model_iter_n_children (model, NULL);
3584 order = g_new (gint, length);
3585 for (i = 0; i < length; i++)
3586 order [new_order[i]] = i;
3588 item_array = g_new (GtkIconViewItem *, length);
3589 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3590 item_array[order[i]] = list->data;
3593 for (i = length - 1; i >= 0; i--)
3595 item_array[i]->index = i;
3596 items = g_list_prepend (items, item_array[i]);
3599 g_free (item_array);
3600 g_list_free (icon_view->priv->items);
3601 icon_view->priv->items = items;
3603 gtk_icon_view_queue_layout (icon_view);
3605 verify_items (icon_view);
3609 gtk_icon_view_build_items (GtkIconView *icon_view)
3613 gboolean iters_persist;
3614 GList *items = NULL;
3616 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3618 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3626 GtkIconViewItem *item = gtk_icon_view_item_new ();
3635 items = g_list_prepend (items, item);
3637 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3639 icon_view->priv->items = g_list_reverse (items);
3643 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3646 GtkMovementStep step,
3650 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3651 I_("move-cursor"), 2,
3655 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3660 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3663 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3668 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3675 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3676 GtkMovementStep step,
3679 GdkModifierType state;
3681 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3682 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3683 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3684 step == GTK_MOVEMENT_DISPLAY_LINES ||
3685 step == GTK_MOVEMENT_PAGES ||
3686 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3688 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3691 gtk_icon_view_stop_editing (icon_view, FALSE);
3692 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3694 if (gtk_get_current_event_state (&state))
3696 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3697 icon_view->priv->ctrl_pressed = TRUE;
3698 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3699 icon_view->priv->shift_pressed = TRUE;
3701 /* else we assume not pressed */
3705 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3706 case GTK_MOVEMENT_VISUAL_POSITIONS:
3707 gtk_icon_view_move_cursor_left_right (icon_view, count);
3709 case GTK_MOVEMENT_DISPLAY_LINES:
3710 gtk_icon_view_move_cursor_up_down (icon_view, count);
3712 case GTK_MOVEMENT_PAGES:
3713 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3715 case GTK_MOVEMENT_BUFFER_ENDS:
3716 gtk_icon_view_move_cursor_start_end (icon_view, count);
3719 g_assert_not_reached ();
3722 icon_view->priv->ctrl_pressed = FALSE;
3723 icon_view->priv->shift_pressed = FALSE;
3725 icon_view->priv->draw_focus = TRUE;
3730 static GtkIconViewItem *
3731 find_item (GtkIconView *icon_view,
3732 GtkIconViewItem *current,
3738 GtkIconViewItem *item;
3740 /* FIXME: this could be more efficient
3742 row = current->row + row_ofs;
3743 col = current->col + col_ofs;
3745 for (items = icon_view->priv->items; items; items = items->next)
3748 if (item->row == row && item->col == col)
3756 find_cell (GtkIconView *icon_view,
3757 GtkIconViewItem *item,
3759 GtkOrientation orientation,
3769 if (icon_view->priv->orientation != orientation)
3772 gtk_icon_view_set_cell_data (icon_view, item);
3774 focusable = g_new0 (gint, icon_view->priv->n_cells);
3778 for (k = 0; k < 2; k++)
3779 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3781 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3783 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3786 if (!info->cell->visible)
3789 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3792 current = n_focusable;
3794 focusable[n_focusable] = i;
3800 if (n_focusable == 0)
3808 current = step > 0 ? 0 : n_focusable - 1;
3809 cell = focusable[current];
3812 if (current + *count < 0)
3815 *count = current + *count;
3817 else if (current + *count > n_focusable - 1)
3820 *count = current + *count - (n_focusable - 1);
3824 cell = focusable[current + *count];
3833 static GtkIconViewItem *
3834 find_item_page_up_down (GtkIconView *icon_view,
3835 GtkIconViewItem *current,
3842 y = current->y + count * icon_view->priv->vadjustment->page_size;
3844 item = g_list_find (icon_view->priv->items, current);
3849 for (next = item->next; next; next = next->next)
3851 if (((GtkIconViewItem *)next->data)->col == col)
3854 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3864 for (next = item->prev; next; next = next->prev)
3866 if (((GtkIconViewItem *)next->data)->col == col)
3869 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3883 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3884 GtkIconViewItem *anchor,
3885 GtkIconViewItem *cursor)
3888 GtkIconViewItem *item;
3889 gint row1, row2, col1, col2;
3890 gboolean dirty = FALSE;
3892 if (anchor->row < cursor->row)
3903 if (anchor->col < cursor->col)
3914 for (items = icon_view->priv->items; items; items = items->next)
3918 if (row1 <= item->row && item->row <= row2 &&
3919 col1 <= item->col && item->col <= col2)
3921 if (!item->selected)
3924 item->selected = TRUE;
3925 gtk_icon_view_item_selected_changed (icon_view, item);
3927 gtk_icon_view_queue_draw_item (icon_view, item);
3935 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3938 GtkIconViewItem *item;
3940 gboolean dirty = FALSE;
3943 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3946 if (!icon_view->priv->cursor_item)
3951 list = icon_view->priv->items;
3953 list = g_list_last (icon_view->priv->items);
3955 item = list ? list->data : NULL;
3960 item = icon_view->priv->cursor_item;
3961 cell = icon_view->priv->cursor_cell;
3962 step = count > 0 ? 1 : -1;
3965 cell = find_cell (icon_view, item, cell,
3966 GTK_ORIENTATION_VERTICAL,
3971 item = find_item (icon_view, item, step, 0);
3972 count = count - step;
3978 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3982 if (icon_view->priv->ctrl_pressed ||
3983 !icon_view->priv->shift_pressed ||
3984 !icon_view->priv->anchor_item ||
3985 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3986 icon_view->priv->anchor_item = item;
3988 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3990 if (!icon_view->priv->ctrl_pressed &&
3991 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3993 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3994 dirty = gtk_icon_view_select_all_between (icon_view,
3995 icon_view->priv->anchor_item,
3999 gtk_icon_view_scroll_to_item (icon_view, item);
4002 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4006 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4009 GtkIconViewItem *item;
4010 gboolean dirty = FALSE;
4012 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4015 if (!icon_view->priv->cursor_item)
4020 list = icon_view->priv->items;
4022 list = g_list_last (icon_view->priv->items);
4024 item = list ? list->data : NULL;
4027 item = find_item_page_up_down (icon_view,
4028 icon_view->priv->cursor_item,
4031 if (item == icon_view->priv->cursor_item)
4032 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4037 if (icon_view->priv->ctrl_pressed ||
4038 !icon_view->priv->shift_pressed ||
4039 !icon_view->priv->anchor_item ||
4040 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4041 icon_view->priv->anchor_item = item;
4043 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4045 if (!icon_view->priv->ctrl_pressed &&
4046 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4048 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4049 dirty = gtk_icon_view_select_all_between (icon_view,
4050 icon_view->priv->anchor_item,
4054 gtk_icon_view_scroll_to_item (icon_view, item);
4057 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4061 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4064 GtkIconViewItem *item;
4066 gboolean dirty = FALSE;
4069 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4072 if (!icon_view->priv->cursor_item)
4077 list = icon_view->priv->items;
4079 list = g_list_last (icon_view->priv->items);
4081 item = list ? list->data : NULL;
4085 item = icon_view->priv->cursor_item;
4086 cell = icon_view->priv->cursor_cell;
4087 step = count > 0 ? 1 : -1;
4090 cell = find_cell (icon_view, item, cell,
4091 GTK_ORIENTATION_HORIZONTAL,
4096 item = find_item (icon_view, item, 0, step);
4097 count = count - step;
4103 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4107 if (icon_view->priv->ctrl_pressed ||
4108 !icon_view->priv->shift_pressed ||
4109 !icon_view->priv->anchor_item ||
4110 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4111 icon_view->priv->anchor_item = item;
4113 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4115 if (!icon_view->priv->ctrl_pressed &&
4116 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4118 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4119 dirty = gtk_icon_view_select_all_between (icon_view,
4120 icon_view->priv->anchor_item,
4124 gtk_icon_view_scroll_to_item (icon_view, item);
4127 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4131 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4134 GtkIconViewItem *item;
4136 gboolean dirty = FALSE;
4138 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4142 list = icon_view->priv->items;
4144 list = g_list_last (icon_view->priv->items);
4146 item = list ? list->data : NULL;
4148 if (item == icon_view->priv->cursor_item)
4149 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4154 if (icon_view->priv->ctrl_pressed ||
4155 !icon_view->priv->shift_pressed ||
4156 !icon_view->priv->anchor_item ||
4157 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4158 icon_view->priv->anchor_item = item;
4160 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4162 if (!icon_view->priv->ctrl_pressed &&
4163 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4165 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4166 dirty = gtk_icon_view_select_all_between (icon_view,
4167 icon_view->priv->anchor_item,
4171 gtk_icon_view_scroll_to_item (icon_view, item);
4174 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4178 * gtk_icon_view_scroll_to_path:
4179 * @icon_view: A #GtkIconView.
4180 * @path: The path of the item to move to.
4181 * @use_align: whether to use alignment arguments, or %FALSE.
4182 * @row_align: The vertical alignment of the item specified by @path.
4183 * @col_align: The horizontal alignment of the item specified by @path.
4185 * Moves the alignments of @icon_view to the position specified by @path.
4186 * @row_align determines where the row is placed, and @col_align determines
4187 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4188 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4191 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4192 * tree does the minimum amount of work to scroll the item onto the screen.
4193 * This means that the item will be scrolled to the edge closest to its current
4194 * position. If the item is currently visible on the screen, nothing is done.
4196 * This function only works if the model is set, and @path is a valid row on
4197 * the model. If the model changes before the @icon_view is realized, the
4198 * centered path will be modified to reflect this change.
4203 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4209 GtkIconViewItem *item = NULL;
4211 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4212 g_return_if_fail (path != NULL);
4213 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4214 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4216 if (gtk_tree_path_get_depth (path) > 0)
4217 item = g_list_nth_data (icon_view->priv->items,
4218 gtk_tree_path_get_indices(path)[0]);
4220 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4222 if (icon_view->priv->scroll_to_path)
4223 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4225 icon_view->priv->scroll_to_path = NULL;
4228 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4230 icon_view->priv->scroll_to_use_align = use_align;
4231 icon_view->priv->scroll_to_row_align = row_align;
4232 icon_view->priv->scroll_to_col_align = col_align;
4243 gtk_widget_style_get (GTK_WIDGET (icon_view),
4244 "focus-line-width", &focus_width,
4247 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4249 offset = y + item->y - focus_width -
4250 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4252 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4253 icon_view->priv->vadjustment->value + offset);
4255 offset = x + item->x - focus_width -
4256 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4258 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4259 icon_view->priv->hadjustment->value + offset);
4261 gtk_adjustment_changed (icon_view->priv->hadjustment);
4262 gtk_adjustment_changed (icon_view->priv->vadjustment);
4265 gtk_icon_view_scroll_to_item (icon_view, item);
4270 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4271 GtkIconViewItem *item)
4273 gint x, y, width, height;
4276 gtk_widget_style_get (GTK_WIDGET (icon_view),
4277 "focus-line-width", &focus_width,
4280 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4282 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4284 if (y + item->y - focus_width < 0)
4285 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4286 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4287 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4288 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4289 icon_view->priv->vadjustment->value + y + item->y + item->height
4290 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4292 if (x + item->x - focus_width < 0)
4293 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4294 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4295 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4296 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4297 icon_view->priv->hadjustment->value + x + item->x + item->width
4298 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4300 gtk_adjustment_changed (icon_view->priv->hadjustment);
4301 gtk_adjustment_changed (icon_view->priv->vadjustment);
4304 /* GtkCellLayout implementation */
4305 static GtkIconViewCellInfo *
4306 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4307 GtkCellRenderer *renderer)
4311 for (i = icon_view->priv->cell_list; i; i = i->next)
4313 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4315 if (info->cell == renderer)
4323 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4324 GtkIconViewItem *item)
4327 gboolean iters_persist;
4330 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4336 path = gtk_tree_path_new_from_indices (item->index, -1);
4337 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4339 gtk_tree_path_free (path);
4344 for (i = icon_view->priv->cell_list; i; i = i->next)
4347 GtkIconViewCellInfo *info = i->data;
4349 g_object_freeze_notify (G_OBJECT (info->cell));
4351 for (j = info->attributes; j && j->next; j = j->next->next)
4353 gchar *property = j->data;
4354 gint column = GPOINTER_TO_INT (j->next->data);
4355 GValue value = {0, };
4357 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4359 g_object_set_property (G_OBJECT (info->cell),
4361 g_value_unset (&value);
4365 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4367 icon_view->priv->model,
4371 g_object_thaw_notify (G_OBJECT (info->cell));
4376 free_cell_attributes (GtkIconViewCellInfo *info)
4380 list = info->attributes;
4381 while (list && list->next)
4383 g_free (list->data);
4384 list = list->next->next;
4387 g_slist_free (info->attributes);
4388 info->attributes = NULL;
4392 free_cell_info (GtkIconViewCellInfo *info)
4394 free_cell_attributes (info);
4396 g_object_unref (info->cell);
4399 (* info->destroy) (info->func_data);
4405 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4406 GtkCellRenderer *renderer,
4409 GtkIconViewCellInfo *info;
4410 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4412 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4413 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4415 g_object_ref_sink (renderer);
4417 info = g_new0 (GtkIconViewCellInfo, 1);
4418 info->cell = renderer;
4419 info->expand = expand ? TRUE : FALSE;
4420 info->pack = GTK_PACK_START;
4421 info->position = icon_view->priv->n_cells;
4423 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4424 icon_view->priv->n_cells++;
4428 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4429 GtkCellRenderer *renderer,
4432 GtkIconViewCellInfo *info;
4433 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4435 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4436 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4438 g_object_ref_sink (renderer);
4440 info = g_new0 (GtkIconViewCellInfo, 1);
4441 info->cell = renderer;
4442 info->expand = expand ? TRUE : FALSE;
4443 info->pack = GTK_PACK_END;
4444 info->position = icon_view->priv->n_cells;
4446 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4447 icon_view->priv->n_cells++;
4451 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4452 GtkCellRenderer *renderer,
4453 const gchar *attribute,
4456 GtkIconViewCellInfo *info;
4457 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4459 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4460 g_return_if_fail (info != NULL);
4462 info->attributes = g_slist_prepend (info->attributes,
4463 GINT_TO_POINTER (column));
4464 info->attributes = g_slist_prepend (info->attributes,
4465 g_strdup (attribute));
4469 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4471 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4473 while (icon_view->priv->cell_list)
4475 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4476 free_cell_info (info);
4477 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4478 icon_view->priv->cell_list);
4481 icon_view->priv->n_cells = 0;
4485 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4486 GtkCellRenderer *cell,
4487 GtkCellLayoutDataFunc func,
4489 GDestroyNotify destroy)
4491 GtkIconViewCellInfo *info;
4492 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4494 info = gtk_icon_view_get_cell_info (icon_view, cell);
4495 g_return_if_fail (info != NULL);
4499 GDestroyNotify d = info->destroy;
4501 info->destroy = NULL;
4502 d (info->func_data);
4506 info->func_data = func_data;
4507 info->destroy = destroy;
4511 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4512 GtkCellRenderer *renderer)
4514 GtkIconViewCellInfo *info;
4516 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4518 free_cell_attributes (info);
4522 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4523 GtkCellRenderer *cell,
4526 GtkIconView *icon_view;
4528 GtkIconViewCellInfo *info;
4531 icon_view = GTK_ICON_VIEW (layout);
4533 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4535 info = gtk_icon_view_get_cell_info (icon_view, cell);
4537 g_return_if_fail (info != NULL);
4538 g_return_if_fail (position >= 0);
4540 link = g_list_find (icon_view->priv->cell_list, info);
4542 g_return_if_fail (link != NULL);
4544 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4546 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4549 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4556 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4560 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4562 GtkIconView *icon_view = (GtkIconView *)layout;
4563 GList *retval = NULL, *l;
4565 for (l = icon_view->priv->cell_list; l; l = l->next)
4567 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4569 retval = g_list_prepend (retval, info->cell);
4572 return g_list_reverse (retval);
4579 * gtk_icon_view_new:
4581 * Creates a new #GtkIconView widget
4583 * Return value: A newly created #GtkIconView widget
4588 gtk_icon_view_new (void)
4590 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4594 * gtk_icon_view_new_with_model:
4595 * @model: The model.
4597 * Creates a new #GtkIconView widget with the model @model.
4599 * Return value: A newly created #GtkIconView widget.
4604 gtk_icon_view_new_with_model (GtkTreeModel *model)
4606 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4610 * gtk_icon_view_convert_widget_to_bin_window_coords:
4611 * @icon_view: a #GtkIconView
4612 * @wx: X coordinate relative to the widget
4613 * @wy: Y coordinate relative to the widget
4614 * @bx: return location for bin_window X coordinate
4615 * @by: return location for bin_window Y coordinate
4617 * Converts widget coordinates to coordinates for the bin_window,
4618 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4623 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4631 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4633 if (icon_view->priv->bin_window)
4634 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4645 * gtk_icon_view_get_path_at_pos:
4646 * @icon_view: A #GtkIconView.
4647 * @x: The x position to be identified
4648 * @y: The y position to be identified
4650 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4651 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4652 * the cell at the specified position.
4653 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4654 * widget coordinates to bin_window coordinates.
4656 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4657 * if no icon exists at that position.
4662 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4666 GtkIconViewItem *item;
4669 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4671 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4676 path = gtk_tree_path_new_from_indices (item->index, -1);
4682 * gtk_icon_view_get_item_at_pos:
4683 * @icon_view: A #GtkIconView.
4684 * @x: The x position to be identified
4685 * @y: The y position to be identified
4686 * @path: Return location for the path, or %NULL
4687 * @cell: Return location for the renderer responsible for the cell
4688 * at (@x, @y), or %NULL
4690 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4691 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4692 * obtains the cell at the specified position. The returned path should
4693 * be freed with gtk_tree_path_free().
4694 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4695 * widget coordinates to bin_window coordinates.
4697 * Return value: %TRUE if an item exists at the specified position
4702 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4706 GtkCellRenderer **cell)
4708 GtkIconViewItem *item;
4709 GtkIconViewCellInfo *info;
4711 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4713 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4718 *path = gtk_tree_path_new_from_indices (item->index, -1);
4731 return (item != NULL);
4735 * gtk_icon_view_set_tooltip_item:
4736 * @icon_view: a #GtkIconView
4737 * @tooltip: a #GtkTooltip
4738 * @path: a #GtkTreePath
4740 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4741 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4742 * See also gtk_tooltip_set_tip_area().
4747 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4748 GtkTooltip *tooltip,
4751 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4752 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4754 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4758 * gtk_icon_view_set_tooltip_cell:
4759 * @icon_view: a #GtkIconView
4760 * @tooltip: a #GtkTooltip
4761 * @path: a #GtkTreePath
4762 * @cell: a #GtkCellRenderer or %NULL
4764 * Sets the tip area of @tooltip to the area which @cell occupies in
4765 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4767 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4772 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4773 GtkTooltip *tooltip,
4775 GtkCellRenderer *cell)
4778 GtkIconViewItem *item = NULL;
4779 GtkIconViewCellInfo *info = NULL;
4782 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4783 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4784 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4786 if (gtk_tree_path_get_depth (path) > 0)
4787 item = g_list_nth_data (icon_view->priv->items,
4788 gtk_tree_path_get_indices(path)[0]);
4795 info = gtk_icon_view_get_cell_info (icon_view, cell);
4796 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4802 rect.width = item->width;
4803 rect.height = item->height;
4806 if (icon_view->priv->bin_window)
4808 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4813 gtk_tooltip_set_tip_area (tooltip, &rect);
4818 * gtk_icon_view_get_tooltip_context:
4819 * @icon_view: an #GtkIconView
4820 * @x: the x coordinate (relative to widget coordinates)
4821 * @y: the y coordinate (relative to widget coordinates)
4822 * @keyboard_tip: whether this is a keyboard tooltip or not
4823 * @model: a pointer to receive a #GtkTreeModel or %NULL
4824 * @path: a pointer to receive a #GtkTreePath or %NULL
4825 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4827 * This function is supposed to be used in a #GtkWidget::query-tooltip
4828 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4829 * which are received in the signal handler, should be passed to this
4830 * function without modification.
4832 * The return value indicates whether there is an icon view item at the given
4833 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4834 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4835 * @model, @path and @iter which have been provided will be set to point to
4836 * that row and the corresponding model. @x and @y will always be converted
4837 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4839 * Return value: whether or not the given tooltip context points to a item
4844 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4847 gboolean keyboard_tip,
4848 GtkTreeModel **model,
4852 GtkTreePath *tmppath = NULL;
4854 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4855 g_return_val_if_fail (x != NULL, FALSE);
4856 g_return_val_if_fail (y != NULL, FALSE);
4860 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4867 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4870 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4875 *model = gtk_icon_view_get_model (icon_view);
4878 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4884 gtk_tree_path_free (tmppath);
4890 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4893 gboolean keyboard_tip,
4894 GtkTooltip *tooltip,
4900 GtkTreeModel *model;
4901 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4903 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4906 &model, &path, &iter))
4909 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4913 gtk_tree_path_free (path);
4917 gtk_tooltip_set_markup (tooltip, str);
4918 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4920 gtk_tree_path_free (path);
4928 * gtk_icon_view_set_tooltip_column:
4929 * @icon_view: a #GtkIconView
4930 * @column: an integer, which is a valid column number for @icon_view's model
4932 * If you only plan to have simple (text-only) tooltips on full items, you
4933 * can use this function to have #GtkIconView handle these automatically
4934 * for you. @column should be set to the column in @icon_view's model
4935 * containing the tooltip texts, or -1 to disable this feature.
4937 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4938 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4943 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4946 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4948 if (column == icon_view->priv->tooltip_column)
4953 g_signal_handlers_disconnect_by_func (icon_view,
4954 gtk_icon_view_set_tooltip_query_cb,
4956 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4960 if (icon_view->priv->tooltip_column == -1)
4962 g_signal_connect (icon_view, "query-tooltip",
4963 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4964 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4968 icon_view->priv->tooltip_column = column;
4969 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4973 * gtk_icon_view_get_tooltip_column:
4974 * @icon_view: a #GtkIconView
4976 * Returns the column of @icon_view's model which is being used for
4977 * displaying tooltips on @icon_view's rows.
4979 * Return value: the index of the tooltip column that is currently being
4980 * used, or -1 if this is disabled.
4985 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4987 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4989 return icon_view->priv->tooltip_column;
4993 * gtk_icon_view_get_visible_range:
4994 * @icon_view: A #GtkIconView
4995 * @start_path: Return location for start of region, or %NULL
4996 * @end_path: Return location for end of region, or %NULL
4998 * Sets @start_path and @end_path to be the first and last visible path.
4999 * Note that there may be invisible paths in between.
5001 * Both paths should be freed with gtk_tree_path_free() after use.
5003 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5008 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5009 GtkTreePath **start_path,
5010 GtkTreePath **end_path)
5012 gint start_index = -1;
5013 gint end_index = -1;
5016 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5018 if (icon_view->priv->hadjustment == NULL ||
5019 icon_view->priv->vadjustment == NULL)
5022 if (start_path == NULL && end_path == NULL)
5025 for (icons = icon_view->priv->items; icons; icons = icons->next)
5027 GtkIconViewItem *item = icons->data;
5029 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5030 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5031 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5032 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5034 if (start_index == -1)
5035 start_index = item->index;
5036 end_index = item->index;
5040 if (start_path && start_index != -1)
5041 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5042 if (end_path && end_index != -1)
5043 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5045 return start_index != -1;
5049 * gtk_icon_view_selected_foreach:
5050 * @icon_view: A #GtkIconView.
5051 * @func: The funcion to call for each selected icon.
5052 * @data: User data to pass to the function.
5054 * Calls a function for each selected icon. Note that the model or
5055 * selection cannot be modified from within this function.
5060 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5061 GtkIconViewForeachFunc func,
5066 for (list = icon_view->priv->items; list; list = list->next)
5068 GtkIconViewItem *item = list->data;
5069 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5072 (* func) (icon_view, path, data);
5074 gtk_tree_path_free (path);
5079 * gtk_icon_view_set_selection_mode:
5080 * @icon_view: A #GtkIconView.
5081 * @mode: The selection mode
5083 * Sets the selection mode of the @icon_view.
5088 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5089 GtkSelectionMode mode)
5091 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5093 if (mode == icon_view->priv->selection_mode)
5096 if (mode == GTK_SELECTION_NONE ||
5097 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5098 gtk_icon_view_unselect_all (icon_view);
5100 icon_view->priv->selection_mode = mode;
5102 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5106 * gtk_icon_view_get_selection_mode:
5107 * @icon_view: A #GtkIconView.
5109 * Gets the selection mode of the @icon_view.
5111 * Return value: the current selection mode
5116 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5118 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5120 return icon_view->priv->selection_mode;
5124 * gtk_icon_view_set_model:
5125 * @icon_view: A #GtkIconView.
5126 * @model: The model.
5128 * Sets the model for a #GtkIconView.
5129 * If the @icon_view already has a model set, it will remove
5130 * it before setting the new model. If @model is %NULL, then
5131 * it will unset the old model.
5136 gtk_icon_view_set_model (GtkIconView *icon_view,
5137 GtkTreeModel *model)
5139 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5140 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5142 if (icon_view->priv->model == model)
5145 if (icon_view->priv->scroll_to_path)
5147 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5148 icon_view->priv->scroll_to_path = NULL;
5151 gtk_icon_view_stop_editing (icon_view, TRUE);
5157 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5159 if (icon_view->priv->pixbuf_column != -1)
5161 column_type = gtk_tree_model_get_column_type (model,
5162 icon_view->priv->pixbuf_column);
5164 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5167 if (icon_view->priv->text_column != -1)
5169 column_type = gtk_tree_model_get_column_type (model,
5170 icon_view->priv->text_column);
5172 g_return_if_fail (column_type == G_TYPE_STRING);
5175 if (icon_view->priv->markup_column != -1)
5177 column_type = gtk_tree_model_get_column_type (model,
5178 icon_view->priv->markup_column);
5180 g_return_if_fail (column_type == G_TYPE_STRING);
5185 if (icon_view->priv->model)
5187 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5188 gtk_icon_view_row_changed,
5190 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5191 gtk_icon_view_row_inserted,
5193 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5194 gtk_icon_view_row_deleted,
5196 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5197 gtk_icon_view_rows_reordered,
5200 g_object_unref (icon_view->priv->model);
5202 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5203 g_list_free (icon_view->priv->items);
5204 icon_view->priv->items = NULL;
5205 icon_view->priv->anchor_item = NULL;
5206 icon_view->priv->cursor_item = NULL;
5207 icon_view->priv->last_single_clicked = NULL;
5208 icon_view->priv->width = 0;
5209 icon_view->priv->height = 0;
5212 icon_view->priv->model = model;
5214 if (icon_view->priv->model)
5216 g_object_ref (icon_view->priv->model);
5217 g_signal_connect (icon_view->priv->model,
5219 G_CALLBACK (gtk_icon_view_row_changed),
5221 g_signal_connect (icon_view->priv->model,
5223 G_CALLBACK (gtk_icon_view_row_inserted),
5225 g_signal_connect (icon_view->priv->model,
5227 G_CALLBACK (gtk_icon_view_row_deleted),
5229 g_signal_connect (icon_view->priv->model,
5231 G_CALLBACK (gtk_icon_view_rows_reordered),
5234 gtk_icon_view_build_items (icon_view);
5236 gtk_icon_view_queue_layout (icon_view);
5239 g_object_notify (G_OBJECT (icon_view), "model");
5241 if (GTK_WIDGET_REALIZED (icon_view))
5242 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5246 * gtk_icon_view_get_model:
5247 * @icon_view: a #GtkIconView
5249 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5252 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5257 gtk_icon_view_get_model (GtkIconView *icon_view)
5259 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5261 return icon_view->priv->model;
5265 update_text_cell (GtkIconView *icon_view)
5267 GtkIconViewCellInfo *info;
5271 if (icon_view->priv->text_column == -1 &&
5272 icon_view->priv->markup_column == -1)
5274 if (icon_view->priv->text_cell != -1)
5276 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5277 icon_view->priv->pixbuf_cell--;
5279 info = g_list_nth_data (icon_view->priv->cell_list,
5280 icon_view->priv->text_cell);
5282 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5284 free_cell_info (info);
5286 icon_view->priv->n_cells--;
5287 icon_view->priv->text_cell = -1;
5292 if (icon_view->priv->text_cell == -1)
5294 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5295 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5296 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5299 if (info->cell == cell)
5301 icon_view->priv->text_cell = i;
5307 info = g_list_nth_data (icon_view->priv->cell_list,
5308 icon_view->priv->text_cell);
5310 if (icon_view->priv->markup_column != -1)
5311 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5313 "markup", icon_view->priv->markup_column,
5316 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5318 "text", icon_view->priv->text_column,
5321 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5322 g_object_set (info->cell,
5323 "alignment", PANGO_ALIGN_CENTER,
5324 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5329 g_object_set (info->cell,
5330 "alignment", PANGO_ALIGN_LEFT,
5331 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5339 update_pixbuf_cell (GtkIconView *icon_view)
5341 GtkIconViewCellInfo *info;
5345 if (icon_view->priv->pixbuf_column == -1)
5347 if (icon_view->priv->pixbuf_cell != -1)
5349 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5350 icon_view->priv->text_cell--;
5352 info = g_list_nth_data (icon_view->priv->cell_list,
5353 icon_view->priv->pixbuf_cell);
5355 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5357 free_cell_info (info);
5359 icon_view->priv->n_cells--;
5360 icon_view->priv->pixbuf_cell = -1;
5365 if (icon_view->priv->pixbuf_cell == -1)
5367 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5369 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5370 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5373 if (info->cell == cell)
5375 icon_view->priv->pixbuf_cell = i;
5381 info = g_list_nth_data (icon_view->priv->cell_list,
5382 icon_view->priv->pixbuf_cell);
5384 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5386 "pixbuf", icon_view->priv->pixbuf_column,
5389 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5390 g_object_set (info->cell,
5395 g_object_set (info->cell,
5403 * gtk_icon_view_set_text_column:
5404 * @icon_view: A #GtkIconView.
5405 * @column: A column in the currently used model, or -1 to display no text
5407 * Sets the column with text for @icon_view to be @column. The text
5408 * column must be of type #G_TYPE_STRING.
5413 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5416 if (column == icon_view->priv->text_column)
5420 icon_view->priv->text_column = -1;
5423 if (icon_view->priv->model != NULL)
5427 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5429 g_return_if_fail (column_type == G_TYPE_STRING);
5432 icon_view->priv->text_column = column;
5435 gtk_icon_view_stop_editing (icon_view, TRUE);
5437 update_text_cell (icon_view);
5439 gtk_icon_view_invalidate_sizes (icon_view);
5440 gtk_icon_view_queue_layout (icon_view);
5442 g_object_notify (G_OBJECT (icon_view), "text-column");
5446 * gtk_icon_view_get_text_column:
5447 * @icon_view: A #GtkIconView.
5449 * Returns the column with text for @icon_view.
5451 * Returns: the text column, or -1 if it's unset.
5456 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5458 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5460 return icon_view->priv->text_column;
5464 * gtk_icon_view_set_markup_column:
5465 * @icon_view: A #GtkIconView.
5466 * @column: A column in the currently used model, or -1 to display no text
5468 * Sets the column with markup information for @icon_view to be
5469 * @column. The markup column must be of type #G_TYPE_STRING.
5470 * If the markup column is set to something, it overrides
5471 * the text column set by gtk_icon_view_set_text_column().
5476 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5479 if (column == icon_view->priv->markup_column)
5483 icon_view->priv->markup_column = -1;
5486 if (icon_view->priv->model != NULL)
5490 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5492 g_return_if_fail (column_type == G_TYPE_STRING);
5495 icon_view->priv->markup_column = column;
5498 gtk_icon_view_stop_editing (icon_view, TRUE);
5500 update_text_cell (icon_view);
5502 gtk_icon_view_invalidate_sizes (icon_view);
5503 gtk_icon_view_queue_layout (icon_view);
5505 g_object_notify (G_OBJECT (icon_view), "markup-column");
5509 * gtk_icon_view_get_markup_column:
5510 * @icon_view: A #GtkIconView.
5512 * Returns the column with markup text for @icon_view.
5514 * Returns: the markup column, or -1 if it's unset.
5519 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5521 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5523 return icon_view->priv->markup_column;
5527 * gtk_icon_view_set_pixbuf_column:
5528 * @icon_view: A #GtkIconView.
5529 * @column: A column in the currently used model, or -1 to disable
5531 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5532 * column must be of type #GDK_TYPE_PIXBUF
5537 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5540 if (column == icon_view->priv->pixbuf_column)
5544 icon_view->priv->pixbuf_column = -1;
5547 if (icon_view->priv->model != NULL)
5551 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5553 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5556 icon_view->priv->pixbuf_column = column;
5559 gtk_icon_view_stop_editing (icon_view, TRUE);
5561 update_pixbuf_cell (icon_view);
5563 gtk_icon_view_invalidate_sizes (icon_view);
5564 gtk_icon_view_queue_layout (icon_view);
5566 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5571 * gtk_icon_view_get_pixbuf_column:
5572 * @icon_view: A #GtkIconView.
5574 * Returns the column with pixbufs for @icon_view.
5576 * Returns: the pixbuf column, or -1 if it's unset.
5581 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5583 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5585 return icon_view->priv->pixbuf_column;
5589 * gtk_icon_view_select_path:
5590 * @icon_view: A #GtkIconView.
5591 * @path: The #GtkTreePath to be selected.
5593 * Selects the row at @path.
5598 gtk_icon_view_select_path (GtkIconView *icon_view,
5601 GtkIconViewItem *item = NULL;
5603 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5604 g_return_if_fail (icon_view->priv->model != NULL);
5605 g_return_if_fail (path != NULL);
5607 if (gtk_tree_path_get_depth (path) > 0)
5608 item = g_list_nth_data (icon_view->priv->items,
5609 gtk_tree_path_get_indices(path)[0]);
5612 gtk_icon_view_select_item (icon_view, item);
5616 * gtk_icon_view_unselect_path:
5617 * @icon_view: A #GtkIconView.
5618 * @path: The #GtkTreePath to be unselected.
5620 * Unselects the row at @path.
5625 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5628 GtkIconViewItem *item;
5630 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5631 g_return_if_fail (icon_view->priv->model != NULL);
5632 g_return_if_fail (path != NULL);
5634 item = g_list_nth_data (icon_view->priv->items,
5635 gtk_tree_path_get_indices(path)[0]);
5640 gtk_icon_view_unselect_item (icon_view, item);
5644 * gtk_icon_view_get_selected_items:
5645 * @icon_view: A #GtkIconView.
5647 * Creates a list of paths of all selected items. Additionally, if you are
5648 * planning on modifying the model after calling this function, you may
5649 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5650 * To do this, you can use gtk_tree_row_reference_new().
5652 * To free the return value, use:
5654 * g_list_foreach (list, gtk_tree_path_free, NULL);
5655 * g_list_free (list);
5658 * Return value: A #GList containing a #GtkTreePath for each selected row.
5663 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5666 GList *selected = NULL;
5668 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5670 for (list = icon_view->priv->items; list != NULL; list = list->next)
5672 GtkIconViewItem *item = list->data;
5676 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5678 selected = g_list_prepend (selected, path);
5686 * gtk_icon_view_select_all:
5687 * @icon_view: A #GtkIconView.
5689 * Selects all the icons. @icon_view must has its selection mode set
5690 * to #GTK_SELECTION_MULTIPLE.
5695 gtk_icon_view_select_all (GtkIconView *icon_view)
5698 gboolean dirty = FALSE;
5700 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5702 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5705 for (items = icon_view->priv->items; items; items = items->next)
5707 GtkIconViewItem *item = items->data;
5709 if (!item->selected)
5712 item->selected = TRUE;
5713 gtk_icon_view_queue_draw_item (icon_view, item);
5718 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5722 * gtk_icon_view_unselect_all:
5723 * @icon_view: A #GtkIconView.
5725 * Unselects all the icons.
5730 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5732 gboolean dirty = FALSE;
5734 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5736 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5739 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5742 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5746 * gtk_icon_view_path_is_selected:
5747 * @icon_view: A #GtkIconView.
5748 * @path: A #GtkTreePath to check selection on.
5750 * Returns %TRUE if the icon pointed to by @path is currently
5751 * selected. If @path does not point to a valid location, %FALSE is returned.
5753 * Return value: %TRUE if @path is selected.
5758 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5761 GtkIconViewItem *item;
5763 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5764 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5765 g_return_val_if_fail (path != NULL, FALSE);
5767 item = g_list_nth_data (icon_view->priv->items,
5768 gtk_tree_path_get_indices(path)[0]);
5773 return item->selected;
5777 * gtk_icon_view_item_activated:
5778 * @icon_view: A #GtkIconView
5779 * @path: The #GtkTreePath to be activated
5781 * Activates the item determined by @path.
5786 gtk_icon_view_item_activated (GtkIconView *icon_view,
5789 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5790 g_return_if_fail (path != NULL);
5792 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5796 * gtk_icon_view_set_orientation:
5797 * @icon_view: a #GtkIconView
5798 * @orientation: the relative position of texts and icons
5800 * Sets the ::orientation property which determines whether the labels
5801 * are drawn beside the icons instead of below.
5806 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5807 GtkOrientation orientation)
5809 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5811 if (icon_view->priv->orientation != orientation)
5813 icon_view->priv->orientation = orientation;
5815 gtk_icon_view_stop_editing (icon_view, TRUE);
5816 gtk_icon_view_invalidate_sizes (icon_view);
5817 gtk_icon_view_queue_layout (icon_view);
5819 update_text_cell (icon_view);
5820 update_pixbuf_cell (icon_view);
5822 g_object_notify (G_OBJECT (icon_view), "orientation");
5827 * gtk_icon_view_get_orientation:
5828 * @icon_view: a #GtkIconView
5830 * Returns the value of the ::orientation property which determines
5831 * whether the labels are drawn beside the icons instead of below.
5833 * Return value: the relative position of texts and icons
5838 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5840 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5841 GTK_ORIENTATION_VERTICAL);
5843 return icon_view->priv->orientation;
5847 * gtk_icon_view_set_columns:
5848 * @icon_view: a #GtkIconView
5849 * @columns: the number of columns
5851 * Sets the ::columns property which determines in how
5852 * many columns the icons are arranged. If @columns is
5853 * -1, the number of columns will be chosen automatically
5854 * to fill the available area.
5859 gtk_icon_view_set_columns (GtkIconView *icon_view,
5862 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5864 if (icon_view->priv->columns != columns)
5866 icon_view->priv->columns = columns;
5868 gtk_icon_view_stop_editing (icon_view, TRUE);
5869 gtk_icon_view_queue_layout (icon_view);
5871 g_object_notify (G_OBJECT (icon_view), "columns");
5876 * gtk_icon_view_get_columns:
5877 * @icon_view: a #GtkIconView
5879 * Returns the value of the ::columns property.
5881 * Return value: the number of columns, or -1
5886 gtk_icon_view_get_columns (GtkIconView *icon_view)
5888 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5890 return icon_view->priv->columns;
5894 * gtk_icon_view_set_item_width:
5895 * @icon_view: a #GtkIconView
5896 * @item_width: the width for each item
5898 * Sets the ::item-width property which specifies the width
5899 * to use for each item. If it is set to -1, the icon view will
5900 * automatically determine a suitable item size.
5905 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5908 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5910 if (icon_view->priv->item_width != item_width)
5912 icon_view->priv->item_width = item_width;
5914 gtk_icon_view_stop_editing (icon_view, TRUE);
5915 gtk_icon_view_invalidate_sizes (icon_view);
5916 gtk_icon_view_queue_layout (icon_view);
5918 update_text_cell (icon_view);
5920 g_object_notify (G_OBJECT (icon_view), "item-width");
5925 * gtk_icon_view_get_item_width:
5926 * @icon_view: a #GtkIconView
5928 * Returns the value of the ::item-width property.
5930 * Return value: the width of a single item, or -1
5935 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5937 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5939 return icon_view->priv->item_width;
5944 * gtk_icon_view_set_spacing:
5945 * @icon_view: a #GtkIconView
5946 * @spacing: the spacing
5948 * Sets the ::spacing property which specifies the space
5949 * which is inserted between the cells (i.e. the icon and
5950 * the text) of an item.
5955 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5958 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5960 if (icon_view->priv->spacing != spacing)
5962 icon_view->priv->spacing = spacing;
5964 gtk_icon_view_stop_editing (icon_view, TRUE);
5965 gtk_icon_view_invalidate_sizes (icon_view);
5966 gtk_icon_view_queue_layout (icon_view);
5968 g_object_notify (G_OBJECT (icon_view), "spacing");
5973 * gtk_icon_view_get_spacing:
5974 * @icon_view: a #GtkIconView
5976 * Returns the value of the ::spacing property.
5978 * Return value: the space between cells
5983 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5985 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5987 return icon_view->priv->spacing;
5991 * gtk_icon_view_set_row_spacing:
5992 * @icon_view: a #GtkIconView
5993 * @row_spacing: the row spacing
5995 * Sets the ::row-spacing property which specifies the space
5996 * which is inserted between the rows of the icon view.
6001 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6004 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6006 if (icon_view->priv->row_spacing != row_spacing)
6008 icon_view->priv->row_spacing = row_spacing;
6010 gtk_icon_view_stop_editing (icon_view, TRUE);
6011 gtk_icon_view_invalidate_sizes (icon_view);
6012 gtk_icon_view_queue_layout (icon_view);
6014 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6019 * gtk_icon_view_get_row_spacing:
6020 * @icon_view: a #GtkIconView
6022 * Returns the value of the ::row-spacing property.
6024 * Return value: the space between rows
6029 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6031 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6033 return icon_view->priv->row_spacing;
6037 * gtk_icon_view_set_column_spacing:
6038 * @icon_view: a #GtkIconView
6039 * @column_spacing: the column spacing
6041 * Sets the ::column-spacing property which specifies the space
6042 * which is inserted between the columns of the icon view.
6047 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6048 gint column_spacing)
6050 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6052 if (icon_view->priv->column_spacing != column_spacing)
6054 icon_view->priv->column_spacing = column_spacing;
6056 gtk_icon_view_stop_editing (icon_view, TRUE);
6057 gtk_icon_view_invalidate_sizes (icon_view);
6058 gtk_icon_view_queue_layout (icon_view);
6060 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6065 * gtk_icon_view_get_column_spacing:
6066 * @icon_view: a #GtkIconView
6068 * Returns the value of the ::column-spacing property.
6070 * Return value: the space between columns
6075 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6077 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6079 return icon_view->priv->column_spacing;
6083 * gtk_icon_view_set_margin:
6084 * @icon_view: a #GtkIconView
6085 * @margin: the margin
6087 * Sets the ::margin property which specifies the space
6088 * which is inserted at the top, bottom, left and right
6094 gtk_icon_view_set_margin (GtkIconView *icon_view,
6097 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6099 if (icon_view->priv->margin != margin)
6101 icon_view->priv->margin = margin;
6103 gtk_icon_view_stop_editing (icon_view, TRUE);
6104 gtk_icon_view_invalidate_sizes (icon_view);
6105 gtk_icon_view_queue_layout (icon_view);
6107 g_object_notify (G_OBJECT (icon_view), "margin");
6112 * gtk_icon_view_get_margin:
6113 * @icon_view: a #GtkIconView
6115 * Returns the value of the ::margin property.
6117 * Return value: the space at the borders
6122 gtk_icon_view_get_margin (GtkIconView *icon_view)
6124 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6126 return icon_view->priv->margin;
6130 /* Get/set whether drag_motion requested the drag data and
6131 * drag_data_received should thus not actually insert the data,
6132 * since the data doesn't result from a drop.
6135 set_status_pending (GdkDragContext *context,
6136 GdkDragAction suggested_action)
6138 g_object_set_data (G_OBJECT (context),
6139 I_("gtk-icon-view-status-pending"),
6140 GINT_TO_POINTER (suggested_action));
6143 static GdkDragAction
6144 get_status_pending (GdkDragContext *context)
6146 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6147 "gtk-icon-view-status-pending"));
6151 unset_reorderable (GtkIconView *icon_view)
6153 if (icon_view->priv->reorderable)
6155 icon_view->priv->reorderable = FALSE;
6156 g_object_notify (G_OBJECT (icon_view), "reorderable");
6161 set_source_row (GdkDragContext *context,
6162 GtkTreeModel *model,
6163 GtkTreePath *source_row)
6166 g_object_set_data_full (G_OBJECT (context),
6167 I_("gtk-icon-view-source-row"),
6168 gtk_tree_row_reference_new (model, source_row),
6169 (GDestroyNotify) gtk_tree_row_reference_free);
6171 g_object_set_data_full (G_OBJECT (context),
6172 I_("gtk-icon-view-source-row"),
6177 get_source_row (GdkDragContext *context)
6179 GtkTreeRowReference *ref;
6181 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6184 return gtk_tree_row_reference_get_path (ref);
6191 GtkTreeRowReference *dest_row;
6192 gboolean empty_view_drop;
6193 gboolean drop_append_mode;
6197 dest_row_free (gpointer data)
6199 DestRow *dr = (DestRow *)data;
6201 gtk_tree_row_reference_free (dr->dest_row);
6206 set_dest_row (GdkDragContext *context,
6207 GtkTreeModel *model,
6208 GtkTreePath *dest_row,
6209 gboolean empty_view_drop,
6210 gboolean drop_append_mode)
6216 g_object_set_data_full (G_OBJECT (context),
6217 I_("gtk-icon-view-dest-row"),
6222 dr = g_new0 (DestRow, 1);
6224 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6225 dr->empty_view_drop = empty_view_drop;
6226 dr->drop_append_mode = drop_append_mode;
6227 g_object_set_data_full (G_OBJECT (context),
6228 I_("gtk-icon-view-dest-row"),
6229 dr, (GDestroyNotify) dest_row_free);
6233 get_dest_row (GdkDragContext *context)
6237 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6241 GtkTreePath *path = NULL;
6244 path = gtk_tree_row_reference_get_path (dr->dest_row);
6245 else if (dr->empty_view_drop)
6246 path = gtk_tree_path_new_from_indices (0, -1);
6250 if (path && dr->drop_append_mode)
6251 gtk_tree_path_next (path);
6260 check_model_dnd (GtkTreeModel *model,
6261 GType required_iface,
6262 const gchar *signal)
6264 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6266 g_warning ("You must override the default '%s' handler "
6267 "on GtkIconView when using models that don't support "
6268 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6269 "is to connect to '%s' and call "
6270 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6271 "the default handler from running. Look at the source code "
6272 "for the default handler in gtkiconview.c to get an idea what "
6273 "your handler should do. (gtkiconview.c is in the GTK+ source "
6274 "code.) If you're using GTK+ from a language other than C, "
6275 "there may be a more natural way to override default handlers, e.g. via derivation.",
6276 signal, g_type_name (required_iface), signal);
6284 remove_scroll_timeout (GtkIconView *icon_view)
6286 if (icon_view->priv->scroll_timeout_id != 0)
6288 g_source_remove (icon_view->priv->scroll_timeout_id);
6290 icon_view->priv->scroll_timeout_id = 0;
6295 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6297 gint px, py, x, y, width, height;
6298 gint hoffset, voffset;
6300 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6301 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6303 /* see if we are near the edge. */
6304 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6306 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6308 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6310 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6313 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6314 icon_view->priv->vadjustment->value + voffset);
6317 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6318 icon_view->priv->hadjustment->value + hoffset);
6323 drag_scroll_timeout (gpointer data)
6325 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6327 gtk_icon_view_autoscroll (icon_view);
6334 set_destination (GtkIconView *icon_view,
6335 GdkDragContext *context,
6338 GdkDragAction *suggested_action,
6342 GtkTreePath *path = NULL;
6343 GtkIconViewDropPosition pos;
6344 GtkIconViewDropPosition old_pos;
6345 GtkTreePath *old_dest_path = NULL;
6346 gboolean can_drop = FALSE;
6348 widget = GTK_WIDGET (icon_view);
6350 *suggested_action = 0;
6353 if (!icon_view->priv->dest_set)
6355 /* someone unset us as a drag dest, note that if
6356 * we return FALSE drag_leave isn't called
6359 gtk_icon_view_set_drag_dest_item (icon_view,
6361 GTK_ICON_VIEW_DROP_LEFT);
6363 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6365 return FALSE; /* no longer a drop site */
6368 *target = gtk_drag_dest_find_target (widget, context,
6369 gtk_drag_dest_get_target_list (widget));
6370 if (*target == GDK_NONE)
6373 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6376 GtkTreeModel *model;
6378 /* the row got dropped on empty space, let's setup a special case
6382 gtk_tree_path_free (path);
6384 model = gtk_icon_view_get_model (icon_view);
6386 n_children = gtk_tree_model_iter_n_children (model, NULL);
6389 pos = GTK_ICON_VIEW_DROP_BELOW;
6390 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6394 pos = GTK_ICON_VIEW_DROP_ABOVE;
6395 path = gtk_tree_path_new_from_indices (0, -1);
6405 gtk_icon_view_get_drag_dest_item (icon_view,
6410 gtk_tree_path_free (old_dest_path);
6412 if (TRUE /* FIXME if the location droppable predicate */)
6420 GtkWidget *source_widget;
6422 *suggested_action = context->suggested_action;
6423 source_widget = gtk_drag_get_source_widget (context);
6425 if (source_widget == widget)
6427 /* Default to MOVE, unless the user has
6428 * pressed ctrl or shift to affect available actions
6430 if ((context->actions & GDK_ACTION_MOVE) != 0)
6431 *suggested_action = GDK_ACTION_MOVE;
6434 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6439 /* can't drop here */
6440 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6442 GTK_ICON_VIEW_DROP_LEFT);
6446 gtk_tree_path_free (path);
6452 get_logical_destination (GtkIconView *icon_view,
6453 gboolean *drop_append_mode)
6455 /* adjust path to point to the row the drop goes in front of */
6456 GtkTreePath *path = NULL;
6457 GtkIconViewDropPosition pos;
6459 *drop_append_mode = FALSE;
6461 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6466 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6467 pos == GTK_ICON_VIEW_DROP_BELOW)
6470 GtkTreeModel *model = icon_view->priv->model;
6472 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6473 !gtk_tree_model_iter_next (model, &iter))
6474 *drop_append_mode = TRUE;
6477 *drop_append_mode = FALSE;
6478 gtk_tree_path_next (path);
6486 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6487 GdkEventMotion *event)
6489 GtkWidget *widget = GTK_WIDGET (icon_view);
6490 GdkDragContext *context;
6491 GtkTreePath *path = NULL;
6493 GtkTreeModel *model;
6494 gboolean retval = FALSE;
6496 if (!icon_view->priv->source_set)
6499 if (icon_view->priv->pressed_button < 0)
6502 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6503 icon_view->priv->press_start_x,
6504 icon_view->priv->press_start_y,
6505 event->x, event->y))
6508 model = gtk_icon_view_get_model (icon_view);
6513 button = icon_view->priv->pressed_button;
6514 icon_view->priv->pressed_button = -1;
6516 path = gtk_icon_view_get_path_at_pos (icon_view,
6517 icon_view->priv->press_start_x,
6518 icon_view->priv->press_start_y);
6523 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6524 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6528 /* FIXME Check whether we're a start button, if not return FALSE and
6532 /* Now we can begin the drag */
6536 context = gtk_drag_begin (widget,
6537 gtk_drag_source_get_target_list (widget),
6538 icon_view->priv->source_actions,
6542 set_source_row (context, model, path);
6546 gtk_tree_path_free (path);
6551 /* Source side drag signals */
6553 gtk_icon_view_drag_begin (GtkWidget *widget,
6554 GdkDragContext *context)
6556 GtkIconView *icon_view;
6557 GtkIconViewItem *item;
6562 icon_view = GTK_ICON_VIEW (widget);
6564 /* if the user uses a custom DnD impl, we don't set the icon here */
6565 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6568 item = gtk_icon_view_get_item_at_coords (icon_view,
6569 icon_view->priv->press_start_x,
6570 icon_view->priv->press_start_y,
6574 g_return_if_fail (item != NULL);
6576 x = icon_view->priv->press_start_x - item->x + 1;
6577 y = icon_view->priv->press_start_y - item->y + 1;
6579 path = gtk_tree_path_new_from_indices (item->index, -1);
6580 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6581 gtk_tree_path_free (path);
6583 gtk_drag_set_icon_pixmap (context,
6584 gdk_drawable_get_colormap (icon),
6589 g_object_unref (icon);
6593 gtk_icon_view_drag_end (GtkWidget *widget,
6594 GdkDragContext *context)
6600 gtk_icon_view_drag_data_get (GtkWidget *widget,
6601 GdkDragContext *context,
6602 GtkSelectionData *selection_data,
6606 GtkIconView *icon_view;
6607 GtkTreeModel *model;
6608 GtkTreePath *source_row;
6610 icon_view = GTK_ICON_VIEW (widget);
6611 model = gtk_icon_view_get_model (icon_view);
6616 if (!icon_view->priv->source_set)
6619 source_row = get_source_row (context);
6621 if (source_row == NULL)
6624 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6625 * any model; for DragSource models there are some other targets
6629 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6630 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6635 /* If drag_data_get does nothing, try providing row data. */
6636 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6637 gtk_tree_set_row_drag_data (selection_data,
6642 gtk_tree_path_free (source_row);
6646 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6647 GdkDragContext *context)
6649 GtkTreeModel *model;
6650 GtkIconView *icon_view;
6651 GtkTreePath *source_row;
6653 icon_view = GTK_ICON_VIEW (widget);
6654 model = gtk_icon_view_get_model (icon_view);
6656 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6659 if (!icon_view->priv->source_set)
6662 source_row = get_source_row (context);
6664 if (source_row == NULL)
6667 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6670 gtk_tree_path_free (source_row);
6672 set_source_row (context, NULL, NULL);
6675 /* Target side drag signals */
6677 gtk_icon_view_drag_leave (GtkWidget *widget,
6678 GdkDragContext *context,
6681 GtkIconView *icon_view;
6683 icon_view = GTK_ICON_VIEW (widget);
6685 /* unset any highlight row */
6686 gtk_icon_view_set_drag_dest_item (icon_view,
6688 GTK_ICON_VIEW_DROP_LEFT);
6690 remove_scroll_timeout (icon_view);
6694 gtk_icon_view_drag_motion (GtkWidget *widget,
6695 GdkDragContext *context,
6700 GtkTreePath *path = NULL;
6701 GtkIconViewDropPosition pos;
6702 GtkIconView *icon_view;
6703 GdkDragAction suggested_action = 0;
6707 icon_view = GTK_ICON_VIEW (widget);
6709 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6712 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6714 /* we only know this *after* set_desination_row */
6715 empty = icon_view->priv->empty_view_drop;
6717 if (path == NULL && !empty)
6719 /* Can't drop here. */
6720 gdk_drag_status (context, 0, time);
6724 if (icon_view->priv->scroll_timeout_id == 0)
6726 icon_view->priv->scroll_timeout_id =
6727 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6730 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6732 /* Request data so we can use the source row when
6733 * determining whether to accept the drop
6735 set_status_pending (context, suggested_action);
6736 gtk_drag_get_data (widget, context, target, time);
6740 set_status_pending (context, 0);
6741 gdk_drag_status (context, suggested_action, time);
6746 gtk_tree_path_free (path);
6752 gtk_icon_view_drag_drop (GtkWidget *widget,
6753 GdkDragContext *context,
6758 GtkIconView *icon_view;
6760 GdkDragAction suggested_action = 0;
6761 GdkAtom target = GDK_NONE;
6762 GtkTreeModel *model;
6763 gboolean drop_append_mode;
6765 icon_view = GTK_ICON_VIEW (widget);
6766 model = gtk_icon_view_get_model (icon_view);
6768 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6770 if (!icon_view->priv->dest_set)
6773 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6776 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6779 path = get_logical_destination (icon_view, &drop_append_mode);
6781 if (target != GDK_NONE && path != NULL)
6783 /* in case a motion had requested drag data, change things so we
6784 * treat drag data receives as a drop.
6786 set_status_pending (context, 0);
6787 set_dest_row (context, model, path,
6788 icon_view->priv->empty_view_drop, drop_append_mode);
6792 gtk_tree_path_free (path);
6794 /* Unset this thing */
6795 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6797 if (target != GDK_NONE)
6799 gtk_drag_get_data (widget, context, target, time);
6807 gtk_icon_view_drag_data_received (GtkWidget *widget,
6808 GdkDragContext *context,
6811 GtkSelectionData *selection_data,
6816 gboolean accepted = FALSE;
6817 GtkTreeModel *model;
6818 GtkIconView *icon_view;
6819 GtkTreePath *dest_row;
6820 GdkDragAction suggested_action;
6821 gboolean drop_append_mode;
6823 icon_view = GTK_ICON_VIEW (widget);
6824 model = gtk_icon_view_get_model (icon_view);
6826 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6829 if (!icon_view->priv->dest_set)
6832 suggested_action = get_status_pending (context);
6834 if (suggested_action)
6836 /* We are getting this data due to a request in drag_motion,
6837 * rather than due to a request in drag_drop, so we are just
6838 * supposed to call drag_status, not actually paste in the
6841 path = get_logical_destination (icon_view, &drop_append_mode);
6844 suggested_action = 0;
6846 if (suggested_action)
6848 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6851 suggested_action = 0;
6854 gdk_drag_status (context, suggested_action, time);
6857 gtk_tree_path_free (path);
6859 /* If you can't drop, remove user drop indicator until the next motion */
6860 if (suggested_action == 0)
6861 gtk_icon_view_set_drag_dest_item (icon_view,
6863 GTK_ICON_VIEW_DROP_LEFT);
6868 dest_row = get_dest_row (context);
6870 if (dest_row == NULL)
6873 if (selection_data->length >= 0)
6875 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6881 gtk_drag_finish (context,
6883 (context->action == GDK_ACTION_MOVE),
6886 gtk_tree_path_free (dest_row);
6889 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6892 /* Drag-and-Drop support */
6894 * gtk_icon_view_enable_model_drag_source:
6895 * @icon_view: a #GtkIconTreeView
6896 * @start_button_mask: Mask of allowed buttons to start drag
6897 * @targets: the table of targets that the drag will support
6898 * @n_targets: the number of items in @targets
6899 * @actions: the bitmask of possible actions for a drag from this
6902 * Turns @icon_view into a drag source for automatic DND.
6907 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6908 GdkModifierType start_button_mask,
6909 const GtkTargetEntry *targets,
6911 GdkDragAction actions)
6913 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6915 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6917 icon_view->priv->start_button_mask = start_button_mask;
6918 icon_view->priv->source_actions = actions;
6920 icon_view->priv->source_set = TRUE;
6922 unset_reorderable (icon_view);
6926 * gtk_icon_view_enable_model_drag_dest:
6927 * @icon_view: a #GtkIconView
6928 * @targets: the table of targets that the drag will support
6929 * @n_targets: the number of items in @targets
6930 * @actions: the bitmask of possible actions for a drag to this
6933 * Turns @icon_view into a drop destination for automatic DND.
6938 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6939 const GtkTargetEntry *targets,
6941 GdkDragAction actions)
6943 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6945 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
6947 icon_view->priv->dest_actions = actions;
6949 icon_view->priv->dest_set = TRUE;
6951 unset_reorderable (icon_view);
6955 * gtk_icon_view_unset_model_drag_source:
6956 * @icon_view: a #GtkIconView
6958 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6963 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6965 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6967 if (icon_view->priv->source_set)
6969 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6970 icon_view->priv->source_set = FALSE;
6973 unset_reorderable (icon_view);
6977 * gtk_icon_view_unset_model_drag_dest:
6978 * @icon_view: a #GtkIconView
6980 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6985 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6987 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6989 if (icon_view->priv->dest_set)
6991 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6992 icon_view->priv->dest_set = FALSE;
6995 unset_reorderable (icon_view);
6998 /* These are useful to implement your own custom stuff. */
7000 * gtk_icon_view_set_drag_dest_item:
7001 * @icon_view: a #GtkIconView
7002 * @path: The path of the item to highlight, or %NULL.
7003 * @pos: Specifies where to drop, relative to the item
7005 * Sets the item that is highlighted for feedback.
7010 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7012 GtkIconViewDropPosition pos)
7014 /* Note; this function is exported to allow a custom DND
7015 * implementation, so it can't touch TreeViewDragInfo
7018 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7020 if (icon_view->priv->dest_item)
7022 GtkTreePath *current_path;
7023 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7024 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7025 icon_view->priv->dest_item = NULL;
7027 gtk_icon_view_queue_draw_path (icon_view, current_path);
7028 gtk_tree_path_free (current_path);
7031 /* special case a drop on an empty model */
7032 icon_view->priv->empty_view_drop = FALSE;
7033 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7034 && gtk_tree_path_get_depth (path) == 1
7035 && gtk_tree_path_get_indices (path)[0] == 0)
7039 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7042 if (n_children == 0)
7043 icon_view->priv->empty_view_drop = TRUE;
7046 icon_view->priv->dest_pos = pos;
7050 icon_view->priv->dest_item =
7051 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7052 icon_view->priv->model, path);
7054 gtk_icon_view_queue_draw_path (icon_view, path);
7059 * gtk_icon_view_get_drag_dest_item:
7060 * @icon_view: a #GtkIconView
7061 * @path: Return location for the path of the highlighted item, or %NULL.
7062 * @pos: Return location for the drop position, or %NULL
7064 * Gets information about the item that is highlighted for feedback.
7069 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7071 GtkIconViewDropPosition *pos)
7073 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7077 if (icon_view->priv->dest_item)
7078 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7084 *pos = icon_view->priv->dest_pos;
7088 * gtk_icon_view_get_dest_item_at_pos:
7089 * @icon_view: a #GtkIconView
7090 * @drag_x: the position to determine the destination item for
7091 * @drag_y: the position to determine the destination item for
7092 * @path: Return location for the path of the item, or %NULL.
7093 * @pos: Return location for the drop position, or %NULL
7095 * Determines the destination item for a given position.
7097 * Return value: whether there is an item at the given position.
7102 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7106 GtkIconViewDropPosition *pos)
7108 GtkIconViewItem *item;
7110 /* Note; this function is exported to allow a custom DND
7111 * implementation, so it can't touch TreeViewDragInfo
7114 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7115 g_return_val_if_fail (drag_x >= 0, FALSE);
7116 g_return_val_if_fail (drag_y >= 0, FALSE);
7117 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7123 item = gtk_icon_view_get_item_at_coords (icon_view,
7124 drag_x + icon_view->priv->hadjustment->value,
7125 drag_y + icon_view->priv->vadjustment->value,
7132 *path = gtk_tree_path_new_from_indices (item->index, -1);
7136 if (drag_x < item->x + item->width / 4)
7137 *pos = GTK_ICON_VIEW_DROP_LEFT;
7138 else if (drag_x > item->x + item->width * 3 / 4)
7139 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7140 else if (drag_y < item->y + item->height / 4)
7141 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7142 else if (drag_y > item->y + item->height * 3 / 4)
7143 *pos = GTK_ICON_VIEW_DROP_BELOW;
7145 *pos = GTK_ICON_VIEW_DROP_INTO;
7152 * gtk_icon_view_create_drag_icon:
7153 * @icon_view: a #GtkIconView
7154 * @path: a #GtkTreePath in @icon_view
7156 * Creates a #GdkPixmap representation of the item at @path.
7157 * This image is used for a drag icon.
7159 * Return value: a newly-allocated pixmap of the drag icon.
7164 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7169 GdkPixmap *drawable;
7174 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7175 g_return_val_if_fail (path != NULL, NULL);
7177 widget = GTK_WIDGET (icon_view);
7179 if (!GTK_WIDGET_REALIZED (widget))
7182 index = gtk_tree_path_get_indices (path)[0];
7184 for (l = icon_view->priv->items; l; l = l->next)
7186 GtkIconViewItem *item = l->data;
7188 if (index == item->index)
7190 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7195 cr = gdk_cairo_create (drawable);
7196 cairo_set_line_width (cr, 1.);
7198 gdk_cairo_set_source_color
7199 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7200 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7205 area.width = item->width;
7206 area.height = item->height;
7208 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7209 drawable, 1, 1, FALSE);
7211 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7212 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7225 * gtk_icon_view_get_reorderable:
7226 * @icon_view: a #GtkIconView
7228 * Retrieves whether the user can reorder the list via drag-and-drop.
7229 * See gtk_icon_view_set_reorderable().
7231 * Return value: %TRUE if the list can be reordered.
7236 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7238 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7240 return icon_view->priv->reorderable;
7243 static const GtkTargetEntry item_targets[] = {
7244 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7249 * gtk_icon_view_set_reorderable:
7250 * @icon_view: A #GtkIconView.
7251 * @reorderable: %TRUE, if the list of items can be reordered.
7253 * This function is a convenience function to allow you to reorder models that
7254 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7255 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7256 * the user can reorder the model by dragging and dropping rows. The
7257 * developer can listen to these changes by connecting to the model's
7258 * row_inserted and row_deleted signals.
7260 * This function does not give you any degree of control over the order -- any
7261 * reordering is allowed. If more control is needed, you should probably
7262 * handle drag and drop manually.
7267 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7268 gboolean reorderable)
7270 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7272 reorderable = reorderable != FALSE;
7274 if (icon_view->priv->reorderable == reorderable)
7279 gtk_icon_view_enable_model_drag_source (icon_view,
7282 G_N_ELEMENTS (item_targets),
7284 gtk_icon_view_enable_model_drag_dest (icon_view,
7286 G_N_ELEMENTS (item_targets),
7291 gtk_icon_view_unset_model_drag_source (icon_view);
7292 gtk_icon_view_unset_model_drag_dest (icon_view);
7295 icon_view->priv->reorderable = reorderable;
7297 g_object_notify (G_OBJECT (icon_view), "reorderable");
7301 /* Accessibility Support */
7303 static gpointer accessible_parent_class;
7304 static gpointer accessible_item_parent_class;
7305 static GQuark accessible_private_data_quark = 0;
7307 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7308 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7309 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7311 static GType gtk_icon_view_item_accessible_get_type (void);
7322 GtkIconViewItem *item;
7326 AtkStateSet *state_set;
7330 GtkTextBuffer *text_buffer;
7332 gchar *action_descriptions[LAST_ACTION];
7333 gchar *image_description;
7334 guint action_idle_handler;
7335 } GtkIconViewItemAccessible;
7337 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7343 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7348 typedef struct _GtkIconViewItemAccessibleClass
7350 AtkObjectClass parent_class;
7352 } GtkIconViewItemAccessibleClass;
7354 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7357 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7359 GtkIconViewItemAccessible *item;
7360 GtkIconView *icon_view;
7363 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7364 item->action_idle_handler = 0;
7366 if (item->widget != NULL)
7368 icon_view = GTK_ICON_VIEW (item->widget);
7369 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7370 gtk_icon_view_item_activated (icon_view, path);
7371 gtk_tree_path_free (path);
7378 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7381 GtkIconViewItemAccessible *item;
7383 if (i < 0 || i >= LAST_ACTION)
7386 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7388 if (!GTK_IS_ICON_VIEW (item->widget))
7391 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7396 case ACTION_ACTIVATE:
7397 if (!item->action_idle_handler)
7398 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7401 g_assert_not_reached ();
7409 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7414 static const gchar *
7415 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7418 GtkIconViewItemAccessible *item;
7420 if (i < 0 || i >= LAST_ACTION)
7423 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7425 if (item->action_descriptions[i])
7426 return item->action_descriptions[i];
7428 return gtk_icon_view_item_accessible_action_descriptions[i];
7431 static const gchar *
7432 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7435 if (i < 0 || i >= LAST_ACTION)
7438 return gtk_icon_view_item_accessible_action_names[i];
7442 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7444 const gchar *description)
7446 GtkIconViewItemAccessible *item;
7448 if (i < 0 || i >= LAST_ACTION)
7451 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7453 g_free (item->action_descriptions[i]);
7455 item->action_descriptions[i] = g_strdup (description);
7461 atk_action_item_interface_init (AtkActionIface *iface)
7463 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7464 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7465 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7466 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7467 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7470 static const gchar *
7471 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7473 GtkIconViewItemAccessible *item;
7475 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7477 return item->image_description;
7481 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7482 const gchar *description)
7484 GtkIconViewItemAccessible *item;
7486 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7488 g_free (item->image_description);
7489 item->image_description = g_strdup (item->image_description);
7495 get_pixbuf_box (GtkIconView *icon_view,
7496 GtkIconViewItem *item,
7501 for (l = icon_view->priv->cell_list; l; l = l->next)
7503 GtkIconViewCellInfo *info = l->data;
7505 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7507 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7517 get_text (GtkIconView *icon_view,
7518 GtkIconViewItem *item)
7523 for (l = icon_view->priv->cell_list; l; l = l->next)
7525 GtkIconViewCellInfo *info = l->data;
7527 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7529 g_object_get (info->cell, "text", &text, NULL);
7539 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7543 GtkIconViewItemAccessible *item;
7546 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7548 if (!GTK_IS_ICON_VIEW (item->widget))
7551 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7554 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7557 *height = box.height;
7562 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7565 AtkCoordType coord_type)
7567 GtkIconViewItemAccessible *item;
7570 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7572 if (!GTK_IS_ICON_VIEW (item->widget))
7575 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7578 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7580 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7582 *x+= box.x - item->item->x;
7583 *y+= box.y - item->item->y;
7589 atk_image_item_interface_init (AtkImageIface *iface)
7591 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7592 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7593 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7594 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7598 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7602 GtkIconViewItemAccessible *item;
7603 GtkTextIter start, end;
7604 GtkTextBuffer *buffer;
7606 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7608 if (!GTK_IS_ICON_VIEW (item->widget))
7611 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7614 buffer = item->text_buffer;
7615 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7617 gtk_text_buffer_get_end_iter (buffer, &end);
7619 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7621 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7625 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7628 GtkIconViewItemAccessible *item;
7629 GtkTextIter start, end;
7630 GtkTextBuffer *buffer;
7634 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7636 if (!GTK_IS_ICON_VIEW (item->widget))
7639 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7642 buffer = item->text_buffer;
7643 if (offset >= gtk_text_buffer_get_char_count (buffer))
7646 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7648 gtk_text_iter_forward_char (&end);
7649 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7650 unichar = g_utf8_get_char (string);
7658 get_pango_text_offsets (PangoLayout *layout,
7659 GtkTextBuffer *buffer,
7661 AtkTextBoundary boundary_type,
7665 GtkTextIter *start_iter,
7666 GtkTextIter *end_iter)
7668 PangoLayoutIter *iter;
7669 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7670 gint index, start_index, end_index;
7672 gboolean found = FALSE;
7674 text = pango_layout_get_text (layout);
7675 index = g_utf8_offset_to_pointer (text, offset) - text;
7676 iter = pango_layout_get_iter (layout);
7679 line = pango_layout_iter_get_line_readonly (iter);
7680 start_index = line->start_index;
7681 end_index = start_index + line->length;
7683 if (index >= start_index && index <= end_index)
7686 * Found line for offset
7692 * We want the previous line
7696 switch (boundary_type)
7698 case ATK_TEXT_BOUNDARY_LINE_START:
7699 end_index = start_index;
7700 start_index = prev_line->start_index;
7702 case ATK_TEXT_BOUNDARY_LINE_END:
7704 start_index = prev_prev_line->start_index +
7705 prev_prev_line->length;
7706 end_index = prev_line->start_index + prev_line->length;
7709 g_assert_not_reached();
7713 start_index = end_index = 0;
7716 switch (boundary_type)
7718 case ATK_TEXT_BOUNDARY_LINE_START:
7719 if (pango_layout_iter_next_line (iter))
7720 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7722 case ATK_TEXT_BOUNDARY_LINE_END:
7724 start_index = prev_line->start_index +
7728 g_assert_not_reached();
7733 * We want the next line
7735 if (pango_layout_iter_next_line (iter))
7737 line = pango_layout_iter_get_line_readonly (iter);
7738 switch (boundary_type)
7740 case ATK_TEXT_BOUNDARY_LINE_START:
7741 start_index = line->start_index;
7742 if (pango_layout_iter_next_line (iter))
7743 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7745 end_index = start_index + line->length;
7747 case ATK_TEXT_BOUNDARY_LINE_END:
7748 start_index = end_index;
7749 end_index = line->start_index + line->length;
7752 g_assert_not_reached();
7756 start_index = end_index;
7762 prev_prev_line = prev_line;
7765 while (pango_layout_iter_next_line (iter));
7769 start_index = prev_line->start_index + prev_line->length;
7770 end_index = start_index;
7772 pango_layout_iter_free (iter);
7773 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7774 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7776 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7777 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7782 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7784 AtkTextBoundary boundary_type,
7788 GtkIconViewItemAccessible *item;
7789 GtkTextIter start, end;
7790 GtkTextBuffer *buffer;
7792 GtkIconView *icon_view;
7795 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7797 if (!GTK_IS_ICON_VIEW (item->widget))
7800 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7803 buffer = item->text_buffer;
7805 if (!gtk_text_buffer_get_char_count (buffer))
7809 return g_strdup ("");
7811 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7815 switch (boundary_type)
7817 case ATK_TEXT_BOUNDARY_CHAR:
7818 gtk_text_iter_backward_char(&start);
7820 case ATK_TEXT_BOUNDARY_WORD_START:
7821 if (!gtk_text_iter_starts_word (&start))
7822 gtk_text_iter_backward_word_start (&start);
7824 gtk_text_iter_backward_word_start(&start);
7826 case ATK_TEXT_BOUNDARY_WORD_END:
7827 if (gtk_text_iter_inside_word (&start) &&
7828 !gtk_text_iter_starts_word (&start))
7829 gtk_text_iter_backward_word_start (&start);
7830 while (!gtk_text_iter_ends_word (&start))
7832 if (!gtk_text_iter_backward_char (&start))
7836 gtk_text_iter_backward_word_start(&start);
7837 while (!gtk_text_iter_ends_word (&start))
7839 if (!gtk_text_iter_backward_char (&start))
7843 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7844 if (!gtk_text_iter_starts_sentence (&start))
7845 gtk_text_iter_backward_sentence_start (&start);
7847 gtk_text_iter_backward_sentence_start (&start);
7849 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7850 if (gtk_text_iter_inside_sentence (&start) &&
7851 !gtk_text_iter_starts_sentence (&start))
7852 gtk_text_iter_backward_sentence_start (&start);
7853 while (!gtk_text_iter_ends_sentence (&start))
7855 if (!gtk_text_iter_backward_char (&start))
7859 gtk_text_iter_backward_sentence_start (&start);
7860 while (!gtk_text_iter_ends_sentence (&start))
7862 if (!gtk_text_iter_backward_char (&start))
7866 case ATK_TEXT_BOUNDARY_LINE_START:
7867 case ATK_TEXT_BOUNDARY_LINE_END:
7869 icon_view = GTK_ICON_VIEW (item->widget);
7870 /* FIXME we probably have to use GailTextCell to salvage this */
7871 gtk_icon_view_update_item_text (icon_view, item->item);
7872 get_pango_text_offsets (icon_view->priv->layout,
7885 *start_offset = gtk_text_iter_get_offset (&start);
7886 *end_offset = gtk_text_iter_get_offset (&end);
7888 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7892 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7894 AtkTextBoundary boundary_type,
7898 GtkIconViewItemAccessible *item;
7899 GtkTextIter start, end;
7900 GtkTextBuffer *buffer;
7902 GtkIconView *icon_view;
7905 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7907 if (!GTK_IS_ICON_VIEW (item->widget))
7910 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7913 buffer = item->text_buffer;
7915 if (!gtk_text_buffer_get_char_count (buffer))
7919 return g_strdup ("");
7921 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7925 switch (boundary_type)
7927 case ATK_TEXT_BOUNDARY_CHAR:
7928 gtk_text_iter_forward_char (&end);
7930 case ATK_TEXT_BOUNDARY_WORD_START:
7931 if (!gtk_text_iter_starts_word (&start))
7932 gtk_text_iter_backward_word_start (&start);
7933 if (gtk_text_iter_inside_word (&end))
7934 gtk_text_iter_forward_word_end (&end);
7935 while (!gtk_text_iter_starts_word (&end))
7937 if (!gtk_text_iter_forward_char (&end))
7941 case ATK_TEXT_BOUNDARY_WORD_END:
7942 if (gtk_text_iter_inside_word (&start) &&
7943 !gtk_text_iter_starts_word (&start))
7944 gtk_text_iter_backward_word_start (&start);
7945 while (!gtk_text_iter_ends_word (&start))
7947 if (!gtk_text_iter_backward_char (&start))
7950 gtk_text_iter_forward_word_end (&end);
7952 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7953 if (!gtk_text_iter_starts_sentence (&start))
7954 gtk_text_iter_backward_sentence_start (&start);
7955 if (gtk_text_iter_inside_sentence (&end))
7956 gtk_text_iter_forward_sentence_end (&end);
7957 while (!gtk_text_iter_starts_sentence (&end))
7959 if (!gtk_text_iter_forward_char (&end))
7963 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7964 if (gtk_text_iter_inside_sentence (&start) &&
7965 !gtk_text_iter_starts_sentence (&start))
7966 gtk_text_iter_backward_sentence_start (&start);
7967 while (!gtk_text_iter_ends_sentence (&start))
7969 if (!gtk_text_iter_backward_char (&start))
7972 gtk_text_iter_forward_sentence_end (&end);
7974 case ATK_TEXT_BOUNDARY_LINE_START:
7975 case ATK_TEXT_BOUNDARY_LINE_END:
7977 icon_view = GTK_ICON_VIEW (item->widget);
7978 /* FIXME we probably have to use GailTextCell to salvage this */
7979 gtk_icon_view_update_item_text (icon_view, item->item);
7980 get_pango_text_offsets (icon_view->priv->layout,
7994 *start_offset = gtk_text_iter_get_offset (&start);
7995 *end_offset = gtk_text_iter_get_offset (&end);
7997 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8001 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8003 AtkTextBoundary boundary_type,
8007 GtkIconViewItemAccessible *item;
8008 GtkTextIter start, end;
8009 GtkTextBuffer *buffer;
8011 GtkIconView *icon_view;
8014 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8016 if (!GTK_IS_ICON_VIEW (item->widget))
8019 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8022 buffer = item->text_buffer;
8024 if (!gtk_text_buffer_get_char_count (buffer))
8028 return g_strdup ("");
8030 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8034 switch (boundary_type)
8036 case ATK_TEXT_BOUNDARY_CHAR:
8037 gtk_text_iter_forward_char(&start);
8038 gtk_text_iter_forward_chars(&end, 2);
8040 case ATK_TEXT_BOUNDARY_WORD_START:
8041 if (gtk_text_iter_inside_word (&end))
8042 gtk_text_iter_forward_word_end (&end);
8043 while (!gtk_text_iter_starts_word (&end))
8045 if (!gtk_text_iter_forward_char (&end))
8049 if (!gtk_text_iter_is_end (&end))
8051 gtk_text_iter_forward_word_end (&end);
8052 while (!gtk_text_iter_starts_word (&end))
8054 if (!gtk_text_iter_forward_char (&end))
8059 case ATK_TEXT_BOUNDARY_WORD_END:
8060 gtk_text_iter_forward_word_end (&end);
8062 if (!gtk_text_iter_is_end (&end))
8063 gtk_text_iter_forward_word_end (&end);
8065 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8066 if (gtk_text_iter_inside_sentence (&end))
8067 gtk_text_iter_forward_sentence_end (&end);
8068 while (!gtk_text_iter_starts_sentence (&end))
8070 if (!gtk_text_iter_forward_char (&end))
8074 if (!gtk_text_iter_is_end (&end))
8076 gtk_text_iter_forward_sentence_end (&end);
8077 while (!gtk_text_iter_starts_sentence (&end))
8079 if (!gtk_text_iter_forward_char (&end))
8084 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8085 gtk_text_iter_forward_sentence_end (&end);
8087 if (!gtk_text_iter_is_end (&end))
8088 gtk_text_iter_forward_sentence_end (&end);
8090 case ATK_TEXT_BOUNDARY_LINE_START:
8091 case ATK_TEXT_BOUNDARY_LINE_END:
8093 icon_view = GTK_ICON_VIEW (item->widget);
8094 /* FIXME we probably have to use GailTextCell to salvage this */
8095 gtk_icon_view_update_item_text (icon_view, item->item);
8096 get_pango_text_offsets (icon_view->priv->layout,
8108 *start_offset = gtk_text_iter_get_offset (&start);
8109 *end_offset = gtk_text_iter_get_offset (&end);
8111 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8115 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8117 GtkIconViewItemAccessible *item;
8119 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8121 if (!GTK_IS_ICON_VIEW (item->widget))
8124 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8127 return gtk_text_buffer_get_char_count (item->text_buffer);
8131 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8137 AtkCoordType coord_type)
8139 GtkIconViewItemAccessible *item;
8141 GtkIconView *icon_view;
8142 PangoRectangle char_rect;
8143 const gchar *item_text;
8147 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8149 if (!GTK_IS_ICON_VIEW (item->widget))
8152 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8156 icon_view = GTK_ICON_VIEW (item->widget);
8157 /* FIXME we probably have to use GailTextCell to salvage this */
8158 gtk_icon_view_update_item_text (icon_view, item->item);
8159 item_text = pango_layout_get_text (icon_view->priv->layout);
8160 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8161 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8163 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8164 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8165 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8166 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8167 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8168 *width = char_rect.width / PANGO_SCALE;
8169 *height = char_rect.height / PANGO_SCALE;
8174 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8177 AtkCoordType coord_type)
8179 GtkIconViewItemAccessible *item;
8182 GtkIconView *icon_view;
8183 const gchar *item_text;
8188 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8190 if (!GTK_IS_ICON_VIEW (item->widget))
8193 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8197 icon_view = GTK_ICON_VIEW (item->widget);
8198 /* FIXME we probably have to use GailTextCell to salvage this */
8199 gtk_icon_view_update_item_text (icon_view, item->item);
8200 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8201 x -= l_x + item->item->layout_x - item->item->x;
8202 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8203 y -= l_y + item->item->layout_y - item->item->y;
8204 item_text = pango_layout_get_text (icon_view->priv->layout);
8205 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8216 offset = g_utf8_strlen (item_text, -1);
8218 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8224 atk_text_item_interface_init (AtkTextIface *iface)
8226 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8227 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8228 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8229 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8230 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8231 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8232 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8233 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8237 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8242 AtkCoordType coord_type)
8244 GtkIconViewItemAccessible *item;
8245 AtkObject *parent_obj;
8248 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8250 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8251 if (!GTK_IS_WIDGET (item->widget))
8254 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8257 *width = item->item->width;
8258 *height = item->item->height;
8259 if (gtk_icon_view_item_accessible_is_showing (item))
8261 parent_obj = gtk_widget_get_accessible (item->widget);
8262 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8263 *x = l_x + item->item->x;
8264 *y = l_y + item->item->y;
8274 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8276 GtkIconViewItemAccessible *item;
8277 GtkWidget *toplevel;
8279 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8281 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8282 if (!GTK_IS_WIDGET (item->widget))
8285 gtk_widget_grab_focus (item->widget);
8286 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8287 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8288 if (GTK_WIDGET_TOPLEVEL (toplevel))
8289 gtk_window_present (GTK_WINDOW (toplevel));
8295 atk_component_item_interface_init (AtkComponentIface *iface)
8297 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8298 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8302 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8303 AtkStateType state_type,
8304 gboolean emit_signal)
8308 rc = atk_state_set_add_state (item->state_set, state_type);
8310 * The signal should only be generated if the value changed,
8311 * not when the item is set up. So states that are set
8312 * initially should pass FALSE as the emit_signal argument.
8317 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8318 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8319 if (state_type == ATK_STATE_VISIBLE)
8320 g_signal_emit_by_name (item, "visible-data-changed");
8327 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8328 AtkStateType state_type,
8329 gboolean emit_signal)
8331 if (atk_state_set_contains_state (item->state_set, state_type))
8335 rc = atk_state_set_remove_state (item->state_set, state_type);
8337 * The signal should only be generated if the value changed,
8338 * not when the item is set up. So states that are set
8339 * initially should pass FALSE as the emit_signal argument.
8344 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8345 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8346 if (state_type == ATK_STATE_VISIBLE)
8347 g_signal_emit_by_name (item, "visible-data-changed");
8357 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8359 GtkIconView *icon_view;
8360 GdkRectangle visible_rect;
8361 gboolean is_showing;
8364 * An item is considered "SHOWING" if any part of the item is in the
8365 * visible rectangle.
8368 if (!GTK_IS_ICON_VIEW (item->widget))
8371 if (item->item == NULL)
8374 icon_view = GTK_ICON_VIEW (item->widget);
8376 if (icon_view->priv->hadjustment)
8377 visible_rect.x += icon_view->priv->hadjustment->value;
8379 if (icon_view->priv->hadjustment)
8380 visible_rect.y += icon_view->priv->vadjustment->value;
8381 visible_rect.width = item->widget->allocation.width;
8382 visible_rect.height = item->widget->allocation.height;
8384 if (((item->item->x + item->item->width) < visible_rect.x) ||
8385 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8386 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8387 (item->item->y > (visible_rect.y + visible_rect.height)))
8396 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8397 gboolean emit_signal)
8399 if (gtk_icon_view_item_accessible_is_showing (item))
8400 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8403 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8408 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8412 item->state_set = atk_state_set_new ();
8414 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8415 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8416 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8417 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8418 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8420 for (i = 0; i < LAST_ACTION; i++)
8421 item->action_descriptions[i] = NULL;
8423 item->image_description = NULL;
8425 item->action_idle_handler = 0;
8429 gtk_icon_view_item_accessible_finalize (GObject *object)
8431 GtkIconViewItemAccessible *item;
8434 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8436 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8439 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8441 if (item->state_set)
8442 g_object_unref (item->state_set);
8444 if (item->text_buffer)
8445 g_object_unref (item->text_buffer);
8447 for (i = 0; i < LAST_ACTION; i++)
8448 g_free (item->action_descriptions[i]);
8450 g_free (item->image_description);
8452 if (item->action_idle_handler)
8454 g_source_remove (item->action_idle_handler);
8455 item->action_idle_handler = 0;
8458 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8461 static G_CONST_RETURN gchar*
8462 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8468 GtkIconViewItemAccessible *item;
8469 GtkTextIter start_iter;
8470 GtkTextIter end_iter;
8472 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8474 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8475 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8477 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8482 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8484 GtkIconViewItemAccessible *item;
8486 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8487 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8490 return gtk_widget_get_accessible (item->widget);
8496 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8498 GtkIconViewItemAccessible *item;
8500 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8501 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8503 return item->item->index;
8506 static AtkStateSet *
8507 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8509 GtkIconViewItemAccessible *item;
8510 GtkIconView *icon_view;
8512 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8513 g_return_val_if_fail (item->state_set, NULL);
8518 icon_view = GTK_ICON_VIEW (item->widget);
8519 if (icon_view->priv->cursor_item == item->item)
8520 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8522 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8523 if (item->item->selected)
8524 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8526 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8528 return g_object_ref (item->state_set);
8532 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8534 GObjectClass *gobject_class;
8536 accessible_item_parent_class = g_type_class_peek_parent (klass);
8538 gobject_class = (GObjectClass *)klass;
8540 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8542 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8543 klass->get_name = gtk_icon_view_item_accessible_get_name;
8544 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8545 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8549 gtk_icon_view_item_accessible_get_type (void)
8551 static GType type = 0;
8555 const GTypeInfo tinfo =
8557 sizeof (GtkIconViewItemAccessibleClass),
8558 (GBaseInitFunc) NULL, /* base init */
8559 (GBaseFinalizeFunc) NULL, /* base finalize */
8560 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8561 (GClassFinalizeFunc) NULL, /* class finalize */
8562 NULL, /* class data */
8563 sizeof (GtkIconViewItemAccessible), /* instance size */
8564 0, /* nb preallocs */
8565 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8566 NULL /* value table */
8569 static const GInterfaceInfo atk_component_info =
8571 (GInterfaceInitFunc) atk_component_item_interface_init,
8572 (GInterfaceFinalizeFunc) NULL,
8575 static const GInterfaceInfo atk_action_info =
8577 (GInterfaceInitFunc) atk_action_item_interface_init,
8578 (GInterfaceFinalizeFunc) NULL,
8581 static const GInterfaceInfo atk_image_info =
8583 (GInterfaceInitFunc) atk_image_item_interface_init,
8584 (GInterfaceFinalizeFunc) NULL,
8587 static const GInterfaceInfo atk_text_info =
8589 (GInterfaceInitFunc) atk_text_item_interface_init,
8590 (GInterfaceFinalizeFunc) NULL,
8594 type = g_type_register_static (ATK_TYPE_OBJECT,
8595 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8596 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8597 &atk_component_info);
8598 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8600 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8602 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8609 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8610 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8611 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8613 static GType gtk_icon_view_accessible_get_type (void);
8618 } GtkIconViewAccessible;
8624 } GtkIconViewItemAccessibleInfo;
8630 GtkAdjustment *old_hadj;
8631 GtkAdjustment *old_vadj;
8633 GtkTreeModel *model;
8635 } GtkIconViewAccessiblePrivate;
8637 static GtkIconViewAccessiblePrivate *
8638 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8640 return g_object_get_qdata (G_OBJECT (accessible),
8641 accessible_private_data_quark);
8645 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8649 GtkIconViewItemAccessibleInfo *info;
8650 GtkIconViewItemAccessibleInfo *tmp_info;
8651 GtkIconViewAccessiblePrivate *priv;
8654 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8656 info->index = index;
8658 priv = gtk_icon_view_accessible_get_priv (accessible);
8659 items = priv->items;
8662 tmp_info = items->data;
8663 if (tmp_info->index > index)
8665 items = items->next;
8667 priv->items = g_list_insert_before (priv->items, items, info);
8668 priv->old_hadj = NULL;
8669 priv->old_vadj = NULL;
8673 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8675 GtkIconView *icon_view;
8678 widget = GTK_ACCESSIBLE (accessible)->widget;
8682 icon_view = GTK_ICON_VIEW (widget);
8684 return g_list_length (icon_view->priv->items);
8688 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8691 GtkIconViewAccessiblePrivate *priv;
8692 GtkIconViewItemAccessibleInfo *info;
8695 priv = gtk_icon_view_accessible_get_priv (accessible);
8696 items = priv->items;
8701 if (info->index == index)
8703 items = items->next;
8709 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8712 GtkIconView *icon_view;
8716 GtkIconViewItemAccessible *a11y_item;
8718 widget = GTK_ACCESSIBLE (accessible)->widget;
8722 icon_view = GTK_ICON_VIEW (widget);
8723 icons = g_list_nth (icon_view->priv->items, index);
8727 GtkIconViewItem *item = icons->data;
8729 g_return_val_if_fail (item->index == index, NULL);
8730 obj = gtk_icon_view_accessible_find_child (accessible, index);
8735 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8736 gtk_icon_view_item_accessible_info_new (accessible,
8739 obj->role = ATK_ROLE_ICON;
8740 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8741 a11y_item->item = item;
8742 a11y_item->widget = widget;
8743 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8745 gtk_icon_view_set_cell_data (icon_view, item);
8746 text = get_text (icon_view, item);
8749 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8753 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8754 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8762 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8765 GtkIconViewAccessiblePrivate *priv;
8766 GtkIconViewItemAccessibleInfo *info;
8767 GtkIconViewItemAccessible *item;
8770 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8774 gboolean act_on_item;
8776 widget = GTK_ACCESSIBLE (view)->widget;
8780 items = priv->items;
8782 act_on_item = (list == NULL);
8787 info = (GtkIconViewItemAccessibleInfo *)items->data;
8788 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8790 if (act_on_item == FALSE && list == items)
8794 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8796 items = items->next;
8802 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8803 GtkIconView *icon_view)
8806 GtkIconViewAccessible *view;
8809 * The scrollbars have changed
8811 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8812 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8814 gtk_icon_view_accessible_traverse_items (view, NULL);
8818 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8819 GtkAdjustment *hadj,
8820 GtkAdjustment *vadj)
8823 GtkIconViewAccessiblePrivate *priv;
8825 atk_obj = gtk_widget_get_accessible (widget);
8826 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8828 if (priv->old_hadj != hadj)
8832 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8833 (gpointer *)&priv->old_hadj);
8835 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8836 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8839 priv->old_hadj = hadj;
8842 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8843 (gpointer *)&priv->old_hadj);
8844 g_signal_connect (hadj,
8846 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8850 if (priv->old_vadj != vadj)
8854 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8855 (gpointer *)&priv->old_vadj);
8857 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8858 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8861 priv->old_vadj = vadj;
8864 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8865 (gpointer *)&priv->old_vadj);
8866 g_signal_connect (vadj,
8868 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8875 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8883 GtkIconView *icon_view;
8884 GtkIconViewItem *item;
8885 GtkIconViewAccessible *a11y_view;
8886 GtkIconViewItemAccessible *a11y_item;
8889 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8890 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8891 index = gtk_tree_path_get_indices(path)[0];
8892 a11y_item = gtk_icon_view_accessible_find_child (atk_obj, index);
8896 widget = GTK_ACCESSIBLE (atk_obj)->widget;
8897 icon_view = GTK_ICON_VIEW (widget);
8898 item = a11y_item->item;
8900 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
8902 if (!name || strcmp (name, "") == 0)
8904 gtk_icon_view_set_cell_data (icon_view, item);
8905 text = get_text (icon_view, item);
8908 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8914 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8920 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8925 GtkIconViewAccessiblePrivate *priv;
8926 GtkIconViewItemAccessibleInfo *info;
8927 GtkIconViewAccessible *view;
8928 GtkIconViewItemAccessible *item;
8934 index = gtk_tree_path_get_indices(path)[0];
8935 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8936 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8937 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8939 items = priv->items;
8944 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8945 if (info->index != item->item->index)
8947 if (info->index < index)
8948 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8950 if (tmp_list == NULL)
8953 info->index = item->item->index;
8956 items = items->next;
8958 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8959 g_signal_emit_by_name (atk_obj, "children-changed::add",
8965 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8969 GtkIconViewAccessiblePrivate *priv;
8970 GtkIconViewItemAccessibleInfo *info;
8971 GtkIconViewAccessible *view;
8972 GtkIconViewItemAccessible *item;
8975 GList *deleted_item;
8979 index = gtk_tree_path_get_indices(path)[0];
8980 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8981 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8982 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8984 items = priv->items;
8986 deleted_item = NULL;
8991 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8992 if (info->index == index)
8994 deleted_item = items;
8996 if (info->index != item->item->index)
8998 if (tmp_list == NULL)
9001 info->index = item->item->index;
9004 items = items->next;
9006 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9009 info = deleted_item->data;
9010 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9011 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9013 priv->items = g_list_remove_link (priv->items, deleted_item);
9021 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9022 GtkIconViewItemAccessibleInfo *i2)
9024 return i1->index - i2->index;
9028 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9034 GtkIconViewAccessiblePrivate *priv;
9035 GtkIconViewItemAccessibleInfo *info;
9036 GtkIconView *icon_view;
9037 GtkIconViewItemAccessible *item;
9043 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9044 icon_view = GTK_ICON_VIEW (user_data);
9045 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9047 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9049 order = g_new (gint, length);
9050 for (i = 0; i < length; i++)
9051 order [new_order[i]] = i;
9053 items = priv->items;
9057 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9058 info->index = order[info->index];
9059 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9060 items = items->next;
9063 priv->items = g_list_sort (priv->items,
9064 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9070 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9075 obj = G_OBJECT (model);
9076 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9077 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9078 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9079 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9083 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9087 obj = G_OBJECT (icon_view->priv->model);
9088 g_signal_connect_data (obj, "row-changed",
9089 (GCallback) gtk_icon_view_accessible_model_row_changed,
9090 icon_view, NULL, 0);
9091 g_signal_connect_data (obj, "row-inserted",
9092 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9093 icon_view, NULL, G_CONNECT_AFTER);
9094 g_signal_connect_data (obj, "row-deleted",
9095 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9096 icon_view, NULL, G_CONNECT_AFTER);
9097 g_signal_connect_data (obj, "rows-reordered",
9098 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9099 icon_view, NULL, G_CONNECT_AFTER);
9103 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9105 GtkIconViewItemAccessibleInfo *info;
9108 items = priv->items;
9111 info = (GtkIconViewItemAccessibleInfo *) items->data;
9112 g_object_unref (info->item);
9113 g_free (items->data);
9114 items = items->next;
9116 g_list_free (priv->items);
9121 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9124 GtkIconView *icon_view;
9127 GtkIconViewAccessiblePrivate *priv;
9129 if (strcmp (pspec->name, "model") == 0)
9131 widget = GTK_WIDGET (obj);
9132 atk_obj = gtk_widget_get_accessible (widget);
9133 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9136 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9137 (gpointer *)&priv->model);
9138 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9140 gtk_icon_view_accessible_clear_cache (priv);
9142 icon_view = GTK_ICON_VIEW (obj);
9143 priv->model = icon_view->priv->model;
9144 /* If there is no model the GtkIconView is probably being destroyed */
9147 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9148 gtk_icon_view_accessible_connect_model_signals (icon_view);
9156 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9159 GtkIconViewAccessiblePrivate *priv;
9160 GtkIconView *icon_view;
9162 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9163 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9165 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9166 g_object_set_qdata (G_OBJECT (accessible),
9167 accessible_private_data_quark,
9170 icon_view = GTK_ICON_VIEW (data);
9171 if (icon_view->priv->hadjustment)
9173 priv->old_hadj = icon_view->priv->hadjustment;
9174 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9175 g_signal_connect (icon_view->priv->hadjustment,
9177 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9180 if (icon_view->priv->vadjustment)
9182 priv->old_vadj = icon_view->priv->vadjustment;
9183 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9184 g_signal_connect (icon_view->priv->vadjustment,
9186 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9189 g_signal_connect_after (data,
9190 "set-scroll-adjustments",
9191 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9193 g_signal_connect (data,
9195 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9198 priv->model = icon_view->priv->model;
9201 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9202 gtk_icon_view_accessible_connect_model_signals (icon_view);
9205 accessible->role = ATK_ROLE_LAYERED_PANE;
9209 gtk_icon_view_accessible_finalize (GObject *object)
9211 GtkIconViewAccessiblePrivate *priv;
9213 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9214 gtk_icon_view_accessible_clear_cache (priv);
9218 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9222 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9223 GtkAccessible *accessible)
9226 GtkIconViewAccessiblePrivate *priv;
9228 atk_obj = ATK_OBJECT (accessible);
9229 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9232 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9233 (gpointer *)&priv->old_hadj);
9235 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9236 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9238 priv->old_hadj = NULL;
9242 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9243 (gpointer *)&priv->old_vadj);
9245 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9246 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9248 priv->old_vadj = NULL;
9253 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9255 if (accessible->widget)
9257 g_signal_connect_after (accessible->widget,
9259 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9262 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9266 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9268 GObjectClass *gobject_class;
9269 GtkAccessibleClass *accessible_class;
9271 accessible_parent_class = g_type_class_peek_parent (klass);
9273 gobject_class = (GObjectClass *)klass;
9274 accessible_class = (GtkAccessibleClass *)klass;
9276 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9278 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9279 klass->ref_child = gtk_icon_view_accessible_ref_child;
9280 klass->initialize = gtk_icon_view_accessible_initialize;
9282 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9284 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9288 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9291 AtkCoordType coord_type)
9294 GtkIconView *icon_view;
9295 GtkIconViewItem *item;
9298 widget = GTK_ACCESSIBLE (component)->widget;
9300 /* State is defunct */
9303 icon_view = GTK_ICON_VIEW (widget);
9304 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9305 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9307 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9313 atk_component_interface_init (AtkComponentIface *iface)
9315 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9319 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9323 GtkIconView *icon_view;
9324 GtkIconViewItem *item;
9326 widget = GTK_ACCESSIBLE (selection)->widget;
9330 icon_view = GTK_ICON_VIEW (widget);
9332 item = g_list_nth_data (icon_view->priv->items, i);
9337 gtk_icon_view_select_item (icon_view, item);
9343 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9346 GtkIconView *icon_view;
9348 widget = GTK_ACCESSIBLE (selection)->widget;
9352 icon_view = GTK_ICON_VIEW (widget);
9353 gtk_icon_view_unselect_all (icon_view);
9359 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9364 GtkIconView *icon_view;
9365 GtkIconViewItem *item;
9367 widget = GTK_ACCESSIBLE (selection)->widget;
9371 icon_view = GTK_ICON_VIEW (widget);
9373 l = icon_view->priv->items;
9380 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9391 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9394 GtkIconView *icon_view;
9395 GtkIconViewItem *item;
9399 widget = GTK_ACCESSIBLE (selection)->widget;
9403 icon_view = GTK_ICON_VIEW (widget);
9405 l = icon_view->priv->items;
9421 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9425 GtkIconView *icon_view;
9426 GtkIconViewItem *item;
9428 widget = GTK_ACCESSIBLE (selection)->widget;
9432 icon_view = GTK_ICON_VIEW (widget);
9434 item = g_list_nth_data (icon_view->priv->items, i);
9438 return item->selected;
9442 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9446 GtkIconView *icon_view;
9447 GtkIconViewItem *item;
9451 widget = GTK_ACCESSIBLE (selection)->widget;
9455 icon_view = GTK_ICON_VIEW (widget);
9456 l = icon_view->priv->items;
9465 gtk_icon_view_unselect_item (icon_view, item);
9477 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9480 GtkIconView *icon_view;
9482 widget = GTK_ACCESSIBLE (selection)->widget;
9486 icon_view = GTK_ICON_VIEW (widget);
9487 gtk_icon_view_select_all (icon_view);
9492 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9494 iface->add_selection = gtk_icon_view_accessible_add_selection;
9495 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9496 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9497 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9498 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9499 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9500 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9504 gtk_icon_view_accessible_get_type (void)
9506 static GType type = 0;
9510 static GTypeInfo tinfo =
9513 (GBaseInitFunc) NULL, /* base init */
9514 (GBaseFinalizeFunc) NULL, /* base finalize */
9515 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9516 (GClassFinalizeFunc) NULL, /* class finalize */
9517 NULL, /* class data */
9518 0, /* instance size */
9519 0, /* nb preallocs */
9520 (GInstanceInitFunc) NULL, /* instance init */
9521 NULL /* value table */
9523 static const GInterfaceInfo atk_component_info =
9525 (GInterfaceInitFunc) atk_component_interface_init,
9526 (GInterfaceFinalizeFunc) NULL,
9529 static const GInterfaceInfo atk_selection_info =
9531 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9532 (GInterfaceFinalizeFunc) NULL,
9537 * Figure out the size of the class and instance
9538 * we are deriving from
9540 AtkObjectFactory *factory;
9543 GType derived_atk_type;
9545 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9546 factory = atk_registry_get_factory (atk_get_default_registry (),
9548 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9549 g_type_query (derived_atk_type, &query);
9550 tinfo.class_size = query.class_size;
9551 tinfo.instance_size = query.instance_size;
9553 type = g_type_register_static (derived_atk_type,
9554 I_("GtkIconViewAccessible"),
9556 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9557 &atk_component_info);
9558 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9559 &atk_selection_info);
9565 gtk_icon_view_accessible_new (GObject *obj)
9567 AtkObject *accessible;
9569 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9571 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9572 atk_object_initialize (accessible, obj);
9578 gtk_icon_view_accessible_factory_get_accessible_type (void)
9580 return gtk_icon_view_accessible_get_type ();
9584 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9586 return gtk_icon_view_accessible_new (obj);
9590 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9592 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9593 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9597 gtk_icon_view_accessible_factory_get_type (void)
9599 static GType type = 0;
9603 const GTypeInfo tinfo =
9605 sizeof (AtkObjectFactoryClass),
9606 NULL, /* base_init */
9607 NULL, /* base_finalize */
9608 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9609 NULL, /* class_finalize */
9610 NULL, /* class_data */
9611 sizeof (AtkObjectFactory),
9612 0, /* n_preallocs */
9616 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9617 I_("GtkIconViewAccessibleFactory"),
9625 gtk_icon_view_get_accessible (GtkWidget *widget)
9627 static gboolean first_time = TRUE;
9631 AtkObjectFactory *factory;
9632 AtkRegistry *registry;
9634 GType derived_atk_type;
9637 * Figure out whether accessibility is enabled by looking at the
9638 * type of the accessible object which would be created for
9639 * the parent type of GtkIconView.
9641 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9643 registry = atk_get_default_registry ();
9644 factory = atk_registry_get_factory (registry,
9646 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9647 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9648 atk_registry_set_factory_type (registry,
9650 gtk_icon_view_accessible_factory_get_type ());
9653 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9657 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9658 GtkBuilder *builder,
9660 const gchar *tagname,
9661 GMarkupParser *parser,
9664 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9665 tagname, parser, data))
9668 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9669 tagname, parser, data);
9673 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9674 GtkBuilder *builder,
9676 const gchar *tagname,
9679 if (strcmp (tagname, "attributes") == 0)
9680 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9683 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9689 #define __GTK_ICON_VIEW_C__
9690 #include "gtkaliasdef.c"