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
50 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
52 typedef struct _GtkIconViewItem GtkIconViewItem;
53 struct _GtkIconViewItem
61 gint x, y, width, height;
64 * box[i] is the actual area occupied by cell i,
65 * before, after are used to calculate the cell
66 * area relative to the box.
67 * See gtk_icon_view_get_cell_area().
75 guint selected_before_rubberbanding : 1;
79 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
80 struct _GtkIconViewCellInfo
82 GtkCellRenderer *cell;
92 GtkCellLayoutDataFunc func;
94 GDestroyNotify destroy;
97 typedef struct _GtkIconViewChild GtkIconViewChild;
98 struct _GtkIconViewChild
101 GtkIconViewItem *item;
105 struct _GtkIconViewPrivate
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gboolean doing_rubberband;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
134 GtkIconViewItem *edited_item;
135 GtkCellEditable *editable;
137 GtkIconViewItem *last_single_clicked;
144 GtkOrientation orientation;
163 GdkModifierType start_button_mask;
168 GtkTargetList *source_targets;
169 GdkDragAction source_actions;
171 GtkTargetList *dest_targets;
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);
451 static void clear_dest_info (GtkIconView *icon_view);
452 static void clear_source_info (GtkIconView *icon_view);
454 static void adjust_wrap_width (GtkIconView *icon_view,
455 GtkIconViewItem *item);
458 static GtkBuildableIface *parent_buildable_iface;
459 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
460 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
463 const gchar *tagname,
464 GMarkupParser *parser,
466 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
469 const gchar *tagname,
472 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
474 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
475 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
476 gtk_icon_view_cell_layout_init)
477 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
478 gtk_icon_view_buildable_init))
481 gtk_icon_view_class_init (GtkIconViewClass *klass)
483 GObjectClass *gobject_class;
484 GtkObjectClass *object_class;
485 GtkWidgetClass *widget_class;
486 GtkContainerClass *container_class;
487 GtkBindingSet *binding_set;
489 binding_set = gtk_binding_set_by_class (klass);
491 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
493 gobject_class = (GObjectClass *) klass;
494 object_class = (GtkObjectClass *) klass;
495 widget_class = (GtkWidgetClass *) klass;
496 container_class = (GtkContainerClass *) klass;
498 gobject_class->finalize = gtk_icon_view_finalize;
499 gobject_class->set_property = gtk_icon_view_set_property;
500 gobject_class->get_property = gtk_icon_view_get_property;
502 object_class->destroy = gtk_icon_view_destroy;
504 widget_class->realize = gtk_icon_view_realize;
505 widget_class->unrealize = gtk_icon_view_unrealize;
506 widget_class->style_set = gtk_icon_view_style_set;
507 widget_class->get_accessible = gtk_icon_view_get_accessible;
508 widget_class->size_request = gtk_icon_view_size_request;
509 widget_class->size_allocate = gtk_icon_view_size_allocate;
510 widget_class->expose_event = gtk_icon_view_expose;
511 widget_class->motion_notify_event = gtk_icon_view_motion;
512 widget_class->button_press_event = gtk_icon_view_button_press;
513 widget_class->button_release_event = gtk_icon_view_button_release;
514 widget_class->key_press_event = gtk_icon_view_key_press;
515 widget_class->key_release_event = gtk_icon_view_key_release;
516 widget_class->drag_begin = gtk_icon_view_drag_begin;
517 widget_class->drag_end = gtk_icon_view_drag_end;
518 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
519 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
520 widget_class->drag_leave = gtk_icon_view_drag_leave;
521 widget_class->drag_motion = gtk_icon_view_drag_motion;
522 widget_class->drag_drop = gtk_icon_view_drag_drop;
523 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
524 widget_class->state_changed = gtk_icon_view_state_changed;
526 container_class->remove = gtk_icon_view_remove;
527 container_class->forall = gtk_icon_view_forall;
529 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
530 klass->select_all = gtk_icon_view_real_select_all;
531 klass->unselect_all = gtk_icon_view_real_unselect_all;
532 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
533 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
534 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
535 klass->move_cursor = gtk_icon_view_real_move_cursor;
539 * GtkIconView:selection-mode:
541 * The ::selection-mode property specifies the selection mode of
542 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
543 * is enabled, for the other modes, only keyboard selection is possible.
547 g_object_class_install_property (gobject_class,
549 g_param_spec_enum ("selection-mode",
550 P_("Selection mode"),
551 P_("The selection mode"),
552 GTK_TYPE_SELECTION_MODE,
553 GTK_SELECTION_SINGLE,
554 GTK_PARAM_READWRITE));
557 * GtkIconView:pixbuf-column:
559 * The ::pixbuf-column property contains the number of the model column
560 * containing the pixbufs which are displayed. The pixbuf column must be
561 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
562 * display of pixbufs.
566 g_object_class_install_property (gobject_class,
568 g_param_spec_int ("pixbuf-column",
570 P_("Model column used to retrieve the icon pixbuf from"),
572 GTK_PARAM_READWRITE));
575 * GtkIconView:text-column:
577 * The ::text-column property contains the number of the model column
578 * containing the texts which are displayed. The text column must be
579 * of type #G_TYPE_STRING. If this property and the :markup-column
580 * property are both set to -1, no texts are displayed.
584 g_object_class_install_property (gobject_class,
586 g_param_spec_int ("text-column",
588 P_("Model column used to retrieve the text from"),
590 GTK_PARAM_READWRITE));
594 * GtkIconView:markup-column:
596 * The ::markup-column property contains the number of the model column
597 * containing markup information to be displayed. The markup column must be
598 * of type #G_TYPE_STRING. If this property and the :text-column property
599 * are both set to column numbers, it overrides the text column.
600 * If both are set to -1, no texts are displayed.
604 g_object_class_install_property (gobject_class,
606 g_param_spec_int ("markup-column",
608 P_("Model column used to retrieve the text if using Pango markup"),
610 GTK_PARAM_READWRITE));
612 g_object_class_install_property (gobject_class,
614 g_param_spec_object ("model",
615 P_("Icon View Model"),
616 P_("The model for the icon view"),
618 GTK_PARAM_READWRITE));
621 * GtkIconView:columns:
623 * The columns property contains the number of the columns in which the
624 * items should be displayed. If it is -1, the number of columns will
625 * be chosen automatically to fill the available area.
629 g_object_class_install_property (gobject_class,
631 g_param_spec_int ("columns",
632 P_("Number of columns"),
633 P_("Number of columns to display"),
635 GTK_PARAM_READWRITE));
639 * GtkIconView:item-width:
641 * The item-width property specifies the width to use for each item.
642 * If it is set to -1, the icon view will automatically determine a
643 * suitable item size.
647 g_object_class_install_property (gobject_class,
649 g_param_spec_int ("item-width",
650 P_("Width for each item"),
651 P_("The width used for each item"),
653 GTK_PARAM_READWRITE));
656 * GtkIconView:spacing:
658 * The spacing property specifies the space which is inserted between
659 * the cells (i.e. the icon and the text) of an item.
663 g_object_class_install_property (gobject_class,
665 g_param_spec_int ("spacing",
667 P_("Space which is inserted between cells of an item"),
669 GTK_PARAM_READWRITE));
672 * GtkIconView:row-spacing:
674 * The row-spacing property specifies the space which is inserted between
675 * the rows of the icon view.
679 g_object_class_install_property (gobject_class,
681 g_param_spec_int ("row-spacing",
683 P_("Space which is inserted between grid rows"),
685 GTK_PARAM_READWRITE));
688 * GtkIconView:column-spacing:
690 * The column-spacing property specifies the space which is inserted between
691 * the columns of the icon view.
695 g_object_class_install_property (gobject_class,
697 g_param_spec_int ("column-spacing",
698 P_("Column Spacing"),
699 P_("Space which is inserted between grid columns"),
701 GTK_PARAM_READWRITE));
704 * GtkIconView:margin:
706 * The margin property specifies the space which is inserted
707 * at the edges of the icon view.
711 g_object_class_install_property (gobject_class,
713 g_param_spec_int ("margin",
715 P_("Space which is inserted at the edges of the icon view"),
717 GTK_PARAM_READWRITE));
721 * GtkIconView:orientation:
723 * The orientation property specifies how the cells (i.e. the icon and
724 * the text) of the item are positioned relative to each other.
728 g_object_class_install_property (gobject_class,
730 g_param_spec_enum ("orientation",
732 P_("How the text and icon of each item are positioned relative to each other"),
733 GTK_TYPE_ORIENTATION,
734 GTK_ORIENTATION_VERTICAL,
735 GTK_PARAM_READWRITE));
738 * GtkIconView:reorderable:
740 * The reorderable property specifies if the items can be reordered
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("reorderable",
749 P_("View is reorderable"),
753 g_object_class_install_property (gobject_class,
755 g_param_spec_int ("tooltip-column",
756 P_("Tooltip Column"),
757 P_("The column in the model containing the tooltip texts for the items"),
761 GTK_PARAM_READWRITE));
765 /* Style properties */
766 gtk_widget_class_install_style_property (widget_class,
767 g_param_spec_boxed ("selection-box-color",
768 P_("Selection Box Color"),
769 P_("Color of the selection box"),
771 GTK_PARAM_READABLE));
773 gtk_widget_class_install_style_property (widget_class,
774 g_param_spec_uchar ("selection-box-alpha",
775 P_("Selection Box Alpha"),
776 P_("Opacity of the selection box"),
779 GTK_PARAM_READABLE));
782 widget_class->set_scroll_adjustments_signal =
783 g_signal_new (I_("set_scroll_adjustments"),
784 G_TYPE_FROM_CLASS (gobject_class),
786 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
788 _gtk_marshal_VOID__OBJECT_OBJECT,
790 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
792 icon_view_signals[ITEM_ACTIVATED] =
793 g_signal_new (I_("item_activated"),
794 G_TYPE_FROM_CLASS (gobject_class),
796 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
798 g_cclosure_marshal_VOID__BOXED,
802 icon_view_signals[SELECTION_CHANGED] =
803 g_signal_new (I_("selection-changed"),
804 G_TYPE_FROM_CLASS (gobject_class),
806 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
808 g_cclosure_marshal_VOID__VOID,
811 icon_view_signals[SELECT_ALL] =
812 g_signal_new (I_("select_all"),
813 G_TYPE_FROM_CLASS (gobject_class),
814 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
815 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
817 g_cclosure_marshal_VOID__VOID,
820 icon_view_signals[UNSELECT_ALL] =
821 g_signal_new (I_("unselect_all"),
822 G_TYPE_FROM_CLASS (gobject_class),
823 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
824 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
826 g_cclosure_marshal_VOID__VOID,
829 icon_view_signals[SELECT_CURSOR_ITEM] =
830 g_signal_new (I_("select_cursor_item"),
831 G_TYPE_FROM_CLASS (gobject_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
835 g_cclosure_marshal_VOID__VOID,
838 icon_view_signals[TOGGLE_CURSOR_ITEM] =
839 g_signal_new (I_("toggle_cursor_item"),
840 G_TYPE_FROM_CLASS (gobject_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
844 g_cclosure_marshal_VOID__VOID,
847 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
848 g_signal_new (I_("activate_cursor_item"),
849 G_TYPE_FROM_CLASS (gobject_class),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
853 _gtk_marshal_BOOLEAN__VOID,
856 icon_view_signals[MOVE_CURSOR] =
857 g_signal_new (I_("move_cursor"),
858 G_TYPE_FROM_CLASS (gobject_class),
859 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
860 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
862 _gtk_marshal_BOOLEAN__ENUM_INT,
864 GTK_TYPE_MOVEMENT_STEP,
868 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
870 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
872 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
873 "toggle_cursor_item", 0);
874 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
875 "toggle_cursor_item", 0);
877 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
878 "activate_cursor_item", 0);
879 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
880 "activate_cursor_item", 0);
881 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
882 "activate_cursor_item", 0);
883 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
884 "activate_cursor_item", 0);
885 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
886 "activate_cursor_item", 0);
888 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
889 GTK_MOVEMENT_DISPLAY_LINES, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
891 GTK_MOVEMENT_DISPLAY_LINES, -1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
894 GTK_MOVEMENT_DISPLAY_LINES, 1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
896 GTK_MOVEMENT_DISPLAY_LINES, 1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
899 GTK_MOVEMENT_DISPLAY_LINES, -1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
902 GTK_MOVEMENT_DISPLAY_LINES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
905 GTK_MOVEMENT_BUFFER_ENDS, -1);
906 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
907 GTK_MOVEMENT_BUFFER_ENDS, -1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
910 GTK_MOVEMENT_BUFFER_ENDS, 1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
912 GTK_MOVEMENT_BUFFER_ENDS, 1);
914 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
915 GTK_MOVEMENT_PAGES, -1);
916 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
917 GTK_MOVEMENT_PAGES, -1);
919 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
920 GTK_MOVEMENT_PAGES, 1);
921 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
922 GTK_MOVEMENT_PAGES, 1);
924 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
925 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
926 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
927 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
929 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
930 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
931 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
932 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
936 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
938 parent_buildable_iface = g_type_interface_peek_parent (iface);
939 iface->add_child = _gtk_cell_layout_buildable_add_child;
940 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
941 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
945 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
947 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
948 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
949 iface->clear = gtk_icon_view_cell_layout_clear;
950 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
951 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
952 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
953 iface->reorder = gtk_icon_view_cell_layout_reorder;
954 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
958 gtk_icon_view_init (GtkIconView *icon_view)
960 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
962 icon_view->priv->width = 0;
963 icon_view->priv->height = 0;
964 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
965 icon_view->priv->pressed_button = -1;
966 icon_view->priv->press_start_x = -1;
967 icon_view->priv->press_start_y = -1;
968 icon_view->priv->text_column = -1;
969 icon_view->priv->markup_column = -1;
970 icon_view->priv->pixbuf_column = -1;
971 icon_view->priv->text_cell = -1;
972 icon_view->priv->pixbuf_cell = -1;
973 icon_view->priv->tooltip_column = -1;
975 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
977 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
979 icon_view->priv->cell_list = NULL;
980 icon_view->priv->n_cells = 0;
981 icon_view->priv->cursor_cell = -1;
983 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
985 icon_view->priv->columns = -1;
986 icon_view->priv->item_width = -1;
987 icon_view->priv->spacing = 0;
988 icon_view->priv->row_spacing = 6;
989 icon_view->priv->column_spacing = 6;
990 icon_view->priv->margin = 6;
994 gtk_icon_view_destroy (GtkObject *object)
996 GtkIconView *icon_view;
998 icon_view = GTK_ICON_VIEW (object);
1000 gtk_icon_view_stop_editing (icon_view, TRUE);
1002 gtk_icon_view_set_model (icon_view, NULL);
1004 if (icon_view->priv->layout_idle_id != 0)
1006 g_source_remove (icon_view->priv->layout_idle_id);
1007 icon_view->priv->layout_idle_id = 0;
1010 if (icon_view->priv->scroll_to_path != NULL)
1012 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1013 icon_view->priv->scroll_to_path = NULL;
1016 remove_scroll_timeout (icon_view);
1018 if (icon_view->priv->hadjustment != NULL)
1020 g_object_unref (icon_view->priv->hadjustment);
1021 icon_view->priv->hadjustment = NULL;
1024 if (icon_view->priv->vadjustment != NULL)
1026 g_object_unref (icon_view->priv->vadjustment);
1027 icon_view->priv->vadjustment = NULL;
1030 clear_dest_info (icon_view);
1031 clear_source_info (icon_view);
1033 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1036 /* GObject methods */
1038 gtk_icon_view_finalize (GObject *object)
1040 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1042 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1047 gtk_icon_view_set_property (GObject *object,
1049 const GValue *value,
1052 GtkIconView *icon_view;
1054 icon_view = GTK_ICON_VIEW (object);
1058 case PROP_SELECTION_MODE:
1059 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1061 case PROP_PIXBUF_COLUMN:
1062 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1064 case PROP_TEXT_COLUMN:
1065 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1067 case PROP_MARKUP_COLUMN:
1068 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1071 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1073 case PROP_ORIENTATION:
1074 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1077 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1079 case PROP_ITEM_WIDTH:
1080 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1083 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1085 case PROP_ROW_SPACING:
1086 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1088 case PROP_COLUMN_SPACING:
1089 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1092 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1094 case PROP_REORDERABLE:
1095 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1098 case PROP_TOOLTIP_COLUMN:
1099 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1109 gtk_icon_view_get_property (GObject *object,
1114 GtkIconView *icon_view;
1116 icon_view = GTK_ICON_VIEW (object);
1120 case PROP_SELECTION_MODE:
1121 g_value_set_enum (value, icon_view->priv->selection_mode);
1123 case PROP_PIXBUF_COLUMN:
1124 g_value_set_int (value, icon_view->priv->pixbuf_column);
1126 case PROP_TEXT_COLUMN:
1127 g_value_set_int (value, icon_view->priv->text_column);
1129 case PROP_MARKUP_COLUMN:
1130 g_value_set_int (value, icon_view->priv->markup_column);
1133 g_value_set_object (value, icon_view->priv->model);
1135 case PROP_ORIENTATION:
1136 g_value_set_enum (value, icon_view->priv->orientation);
1139 g_value_set_int (value, icon_view->priv->columns);
1141 case PROP_ITEM_WIDTH:
1142 g_value_set_int (value, icon_view->priv->item_width);
1145 g_value_set_int (value, icon_view->priv->spacing);
1147 case PROP_ROW_SPACING:
1148 g_value_set_int (value, icon_view->priv->row_spacing);
1150 case PROP_COLUMN_SPACING:
1151 g_value_set_int (value, icon_view->priv->column_spacing);
1154 g_value_set_int (value, icon_view->priv->margin);
1156 case PROP_REORDERABLE:
1157 g_value_set_boolean (value, icon_view->priv->reorderable);
1159 case PROP_TOOLTIP_COLUMN:
1160 g_value_set_int (value, icon_view->priv->tooltip_column);
1164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1169 /* GtkWidget signals */
1171 gtk_icon_view_realize (GtkWidget *widget)
1173 GtkIconView *icon_view;
1174 GdkWindowAttr attributes;
1175 gint attributes_mask;
1177 icon_view = GTK_ICON_VIEW (widget);
1179 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1181 /* Make the main, clipping window */
1182 attributes.window_type = GDK_WINDOW_CHILD;
1183 attributes.x = widget->allocation.x;
1184 attributes.y = widget->allocation.y;
1185 attributes.width = widget->allocation.width;
1186 attributes.height = widget->allocation.height;
1187 attributes.wclass = GDK_INPUT_OUTPUT;
1188 attributes.visual = gtk_widget_get_visual (widget);
1189 attributes.colormap = gtk_widget_get_colormap (widget);
1190 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1192 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1194 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1195 &attributes, attributes_mask);
1196 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1197 gdk_window_set_user_data (widget->window, widget);
1199 /* Make the window for the icon view */
1202 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1203 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1204 attributes.event_mask = (GDK_EXPOSURE_MASK |
1206 GDK_POINTER_MOTION_MASK |
1207 GDK_BUTTON_PRESS_MASK |
1208 GDK_BUTTON_RELEASE_MASK |
1209 GDK_KEY_PRESS_MASK |
1210 GDK_KEY_RELEASE_MASK) |
1211 gtk_widget_get_events (widget);
1213 icon_view->priv->bin_window = gdk_window_new (widget->window,
1214 &attributes, attributes_mask);
1215 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1217 widget->style = gtk_style_attach (widget->style, widget->window);
1218 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1220 gdk_window_show (icon_view->priv->bin_window);
1224 gtk_icon_view_unrealize (GtkWidget *widget)
1226 GtkIconView *icon_view;
1228 icon_view = GTK_ICON_VIEW (widget);
1230 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1231 gdk_window_destroy (icon_view->priv->bin_window);
1232 icon_view->priv->bin_window = NULL;
1234 /* GtkWidget::unrealize destroys children and widget->window */
1235 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1236 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1240 gtk_icon_view_state_changed (GtkWidget *widget,
1241 GtkStateType previous_state)
1243 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1245 if (GTK_WIDGET_REALIZED (widget))
1247 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1248 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1251 gtk_widget_queue_draw (widget);
1255 gtk_icon_view_style_set (GtkWidget *widget,
1256 GtkStyle *previous_style)
1258 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1260 if (GTK_WIDGET_REALIZED (widget))
1262 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1263 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1266 gtk_widget_queue_resize (widget);
1270 gtk_icon_view_size_request (GtkWidget *widget,
1271 GtkRequisition *requisition)
1273 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1276 requisition->width = icon_view->priv->width;
1277 requisition->height = icon_view->priv->height;
1279 tmp_list = icon_view->priv->children;
1283 GtkIconViewChild *child = tmp_list->data;
1284 GtkRequisition child_requisition;
1286 tmp_list = tmp_list->next;
1288 if (GTK_WIDGET_VISIBLE (child->widget))
1289 gtk_widget_size_request (child->widget, &child_requisition);
1294 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1298 for (list = icon_view->priv->children; list; list = list->next)
1300 GtkIconViewChild *child = list->data;
1301 GtkAllocation allocation;
1303 /* totally ignore our child's requisition */
1304 if (child->cell < 0)
1306 allocation.x = child->item->x;
1307 allocation.y = child->item->y;
1308 allocation.width = child->item->width;
1309 allocation.height = child->item->height;
1313 GdkRectangle *box = &child->item->box[child->cell];
1315 allocation.x = box->x;
1316 allocation.y = box->y;
1317 allocation.width = box->width;
1318 allocation.height = box->height;
1321 gtk_widget_size_allocate (child->widget, &allocation);
1326 gtk_icon_view_size_allocate (GtkWidget *widget,
1327 GtkAllocation *allocation)
1329 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1331 GtkAdjustment *hadjustment, *vadjustment;
1333 widget->allocation = *allocation;
1335 if (GTK_WIDGET_REALIZED (widget))
1337 gdk_window_move_resize (widget->window,
1338 allocation->x, allocation->y,
1339 allocation->width, allocation->height);
1340 gdk_window_resize (icon_view->priv->bin_window,
1341 MAX (icon_view->priv->width, allocation->width),
1342 MAX (icon_view->priv->height, allocation->height));
1345 gtk_icon_view_layout (icon_view);
1347 gtk_icon_view_allocate_children (icon_view);
1349 hadjustment = icon_view->priv->hadjustment;
1350 vadjustment = icon_view->priv->vadjustment;
1352 hadjustment->page_size = allocation->width;
1353 hadjustment->page_increment = allocation->width * 0.9;
1354 hadjustment->step_increment = allocation->width * 0.1;
1355 hadjustment->lower = 0;
1356 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1358 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1359 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1361 vadjustment->page_size = allocation->height;
1362 vadjustment->page_increment = allocation->height * 0.9;
1363 vadjustment->step_increment = allocation->height * 0.1;
1364 vadjustment->lower = 0;
1365 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1367 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1368 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1370 if (GTK_WIDGET_REALIZED (widget) &&
1371 icon_view->priv->scroll_to_path)
1374 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1375 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1376 icon_view->priv->scroll_to_path = NULL;
1378 gtk_icon_view_scroll_to_path (icon_view, path,
1379 icon_view->priv->scroll_to_use_align,
1380 icon_view->priv->scroll_to_row_align,
1381 icon_view->priv->scroll_to_col_align);
1382 gtk_tree_path_free (path);
1386 gtk_adjustment_changed (hadjustment);
1387 gtk_adjustment_changed (vadjustment);
1392 gtk_icon_view_expose (GtkWidget *widget,
1393 GdkEventExpose *expose)
1395 GtkIconView *icon_view;
1400 GtkIconViewDropPosition dest_pos;
1401 GtkIconViewItem *dest_item = NULL;
1403 icon_view = GTK_ICON_VIEW (widget);
1405 if (expose->window != icon_view->priv->bin_window)
1408 cr = gdk_cairo_create (icon_view->priv->bin_window);
1409 cairo_set_line_width (cr, 1.);
1411 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1415 dest_index = gtk_tree_path_get_indices (path)[0];
1416 gtk_tree_path_free (path);
1421 for (icons = icon_view->priv->items; icons; icons = icons->next)
1423 GtkIconViewItem *item = icons->data;
1428 area.width = item->width;
1429 area.height = item->height;
1431 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1434 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1435 icon_view->priv->bin_window,
1436 item->x, item->y, TRUE);
1438 if (dest_index == item->index)
1446 case GTK_ICON_VIEW_DROP_INTO:
1447 gtk_paint_focus (widget->style,
1448 icon_view->priv->bin_window,
1449 GTK_WIDGET_STATE (widget),
1452 "iconview-drop-indicator",
1453 dest_item->x, dest_item->y,
1454 dest_item->width, dest_item->height);
1456 case GTK_ICON_VIEW_DROP_ABOVE:
1457 gtk_paint_focus (widget->style,
1458 icon_view->priv->bin_window,
1459 GTK_WIDGET_STATE (widget),
1462 "iconview-drop-indicator",
1463 dest_item->x, dest_item->y - 1,
1464 dest_item->width, 2);
1466 case GTK_ICON_VIEW_DROP_LEFT:
1467 gtk_paint_focus (widget->style,
1468 icon_view->priv->bin_window,
1469 GTK_WIDGET_STATE (widget),
1472 "iconview-drop-indicator",
1473 dest_item->x - 1, dest_item->y,
1474 2, dest_item->height);
1476 case GTK_ICON_VIEW_DROP_BELOW:
1477 gtk_paint_focus (widget->style,
1478 icon_view->priv->bin_window,
1479 GTK_WIDGET_STATE (widget),
1482 "iconview-drop-indicator",
1483 dest_item->x, dest_item->y + dest_item->height - 1,
1484 dest_item->width, 2);
1486 case GTK_ICON_VIEW_DROP_RIGHT:
1487 gtk_paint_focus (widget->style,
1488 icon_view->priv->bin_window,
1489 GTK_WIDGET_STATE (widget),
1492 "iconview-drop-indicator",
1493 dest_item->x + dest_item->width - 1, dest_item->y,
1494 2, dest_item->height);
1495 case GTK_ICON_VIEW_NO_DROP: ;
1500 if (icon_view->priv->doing_rubberband)
1502 GdkRectangle *rectangles;
1505 gdk_region_get_rectangles (expose->region,
1509 while (n_rectangles--)
1510 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1512 g_free (rectangles);
1517 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1523 rubberband_scroll_timeout (gpointer data)
1525 GtkIconView *icon_view = data;
1527 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1528 icon_view->priv->vadjustment->value +
1529 icon_view->priv->scroll_value_diff);
1531 gtk_icon_view_update_rubberband (icon_view);
1537 gtk_icon_view_motion (GtkWidget *widget,
1538 GdkEventMotion *event)
1540 GtkIconView *icon_view;
1543 icon_view = GTK_ICON_VIEW (widget);
1545 gtk_icon_view_maybe_begin_drag (icon_view, event);
1547 if (icon_view->priv->doing_rubberband)
1549 gtk_icon_view_update_rubberband (widget);
1551 abs_y = event->y - icon_view->priv->height *
1552 (icon_view->priv->vadjustment->value /
1553 (icon_view->priv->vadjustment->upper -
1554 icon_view->priv->vadjustment->lower));
1556 if (abs_y < 0 || abs_y > widget->allocation.height)
1559 icon_view->priv->scroll_value_diff = abs_y;
1561 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1563 icon_view->priv->event_last_x = event->x;
1564 icon_view->priv->event_last_y = event->y;
1566 if (icon_view->priv->scroll_timeout_id == 0)
1567 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1571 remove_scroll_timeout (icon_view);
1578 gtk_icon_view_remove (GtkContainer *container,
1581 GtkIconView *icon_view;
1582 GtkIconViewChild *child = NULL;
1585 icon_view = GTK_ICON_VIEW (container);
1587 tmp_list = icon_view->priv->children;
1590 child = tmp_list->data;
1591 if (child->widget == widget)
1593 gtk_widget_unparent (widget);
1595 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1596 g_list_free_1 (tmp_list);
1601 tmp_list = tmp_list->next;
1606 gtk_icon_view_forall (GtkContainer *container,
1607 gboolean include_internals,
1608 GtkCallback callback,
1609 gpointer callback_data)
1611 GtkIconView *icon_view;
1612 GtkIconViewChild *child = NULL;
1615 icon_view = GTK_ICON_VIEW (container);
1617 tmp_list = icon_view->priv->children;
1620 child = tmp_list->data;
1621 tmp_list = tmp_list->next;
1623 (* callback) (child->widget, callback_data);
1628 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1629 GtkIconViewItem *item,
1630 GtkIconViewCellInfo *info,
1635 GdkRectangle cell_area;
1636 gboolean visible, mode;
1638 gtk_icon_view_set_cell_data (icon_view, item);
1640 g_object_get (info->cell,
1641 "visible", &visible,
1645 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1647 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1649 path = gtk_tree_path_new_from_indices (item->index, -1);
1650 path_string = gtk_tree_path_to_string (path);
1651 gtk_tree_path_free (path);
1653 gtk_cell_renderer_activate (info->cell,
1655 GTK_WIDGET (icon_view),
1661 g_free (path_string);
1666 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1667 GtkIconViewItem *item)
1670 AtkObject *item_obj;
1672 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1675 item_obj = atk_object_ref_accessible_child (obj, item->index);
1676 if (item_obj != NULL)
1678 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1679 g_object_unref (item_obj);
1685 gtk_icon_view_put (GtkIconView *icon_view,
1687 GtkIconViewItem *item,
1690 GtkIconViewChild *child;
1692 child = g_new (GtkIconViewChild, 1);
1694 child->widget = widget;
1698 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1700 if (GTK_WIDGET_REALIZED (icon_view))
1701 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1703 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1707 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1708 GtkIconView *icon_view)
1711 GtkIconViewItem *item;
1713 if (icon_view->priv->edited_item == NULL)
1716 item = icon_view->priv->edited_item;
1717 icon_view->priv->edited_item = NULL;
1718 icon_view->priv->editable = NULL;
1719 for (l = icon_view->priv->cell_list; l; l = l->next)
1721 GtkIconViewCellInfo *info = l->data;
1723 info->editing = FALSE;
1726 if (GTK_WIDGET_HAS_FOCUS (editable))
1727 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1729 g_signal_handlers_disconnect_by_func (editable,
1730 gtk_icon_view_remove_widget,
1733 gtk_container_remove (GTK_CONTAINER (icon_view),
1734 GTK_WIDGET (editable));
1736 gtk_icon_view_queue_draw_item (icon_view, item);
1741 gtk_icon_view_start_editing (GtkIconView *icon_view,
1742 GtkIconViewItem *item,
1743 GtkIconViewCellInfo *info,
1748 GdkRectangle cell_area;
1749 gboolean visible, mode;
1750 GtkCellEditable *editable;
1752 gtk_icon_view_set_cell_data (icon_view, item);
1754 g_object_get (info->cell,
1755 "visible", &visible,
1758 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1760 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1762 path = gtk_tree_path_new_from_indices (item->index, -1);
1763 path_string = gtk_tree_path_to_string (path);
1764 gtk_tree_path_free (path);
1766 editable = gtk_cell_renderer_start_editing (info->cell,
1768 GTK_WIDGET (icon_view),
1773 g_free (path_string);
1775 /* FIXME ugly special case */
1776 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1777 g_object_set (editable, "has-frame", TRUE, NULL);
1779 /* the rest corresponds to tree_view_real_start_editing... */
1780 icon_view->priv->edited_item = item;
1781 icon_view->priv->editable = editable;
1782 info->editing = TRUE;
1784 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1786 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1788 gtk_widget_grab_focus (GTK_WIDGET (editable));
1789 g_signal_connect (editable, "remove_widget",
1790 G_CALLBACK (gtk_icon_view_remove_widget),
1797 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1798 gboolean cancel_editing)
1800 GtkCellRenderer *cell = NULL;
1801 GtkIconViewItem *item;
1804 if (icon_view->priv->edited_item == NULL)
1808 * This is very evil. We need to do this, because
1809 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1810 * later on. If gtk_icon_view_row_changed notices
1811 * icon_view->priv->edited_item != NULL, it'll call
1812 * gtk_icon_view_stop_editing again. Bad things will happen then.
1814 * Please read that again if you intend to modify anything here.
1817 item = icon_view->priv->edited_item;
1818 icon_view->priv->edited_item = NULL;
1820 for (l = icon_view->priv->cell_list; l; l = l->next)
1822 GtkIconViewCellInfo *info = l->data;
1834 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1835 if (!cancel_editing)
1836 gtk_cell_editable_editing_done (icon_view->priv->editable);
1838 icon_view->priv->edited_item = item;
1840 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1844 * gtk_icon_view_set_cursor:
1845 * @icon_view: A #GtkIconView
1846 * @path: A #GtkTreePath
1847 * @cell: One of the cell renderers of @icon_view, or %NULL
1848 * @start_editing: %TRUE if the specified cell should start being edited.
1850 * Sets the current keyboard focus to be at @path, and selects it. This is
1851 * useful when you want to focus the user's attention on a particular item.
1852 * If @cell is not %NULL, then focus is given to the cell specified by
1853 * it. Additionally, if @start_editing is %TRUE, then editing should be
1854 * started in the specified cell.
1856 * This function is often followed by <literal>gtk_widget_grab_focus
1857 * (icon_view)</literal> in order to give keyboard focus to the widget.
1858 * Please note that editing can only happen when the widget is realized.
1863 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1865 GtkCellRenderer *cell,
1866 gboolean start_editing)
1868 GtkIconViewItem *item = NULL;
1869 GtkIconViewCellInfo *info = NULL;
1873 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1874 g_return_if_fail (path != NULL);
1875 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1877 gtk_icon_view_stop_editing (icon_view, TRUE);
1879 if (gtk_tree_path_get_depth (path) == 1)
1880 item = g_list_nth_data (icon_view->priv->items,
1881 gtk_tree_path_get_indices(path)[0]);
1887 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1891 if (info->cell == cell)
1900 g_return_if_fail (cell == NULL || info != NULL);
1902 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1903 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1905 if (info && start_editing)
1906 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1910 * gtk_icon_view_get_cursor:
1911 * @icon_view: A #GtkIconView
1912 * @path: Return location for the current cursor path, or %NULL
1913 * @cell: Return location the current focus cell, or %NULL
1915 * Fills in @path and @cell with the current cursor path and cell.
1916 * If the cursor isn't currently set, then *@path will be %NULL.
1917 * If no cell currently has focus, then *@cell will be %NULL.
1919 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1921 * Return value: %TRUE if the cursor is set.
1926 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1928 GtkCellRenderer **cell)
1930 GtkIconViewItem *item;
1931 GtkIconViewCellInfo *info;
1933 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1935 item = icon_view->priv->cursor_item;
1936 if (icon_view->priv->cursor_cell < 0)
1939 info = g_list_nth_data (icon_view->priv->cell_list,
1940 icon_view->priv->cursor_cell);
1945 *path = gtk_tree_path_new_from_indices (item->index, -1);
1958 return (item != NULL);
1962 gtk_icon_view_button_press (GtkWidget *widget,
1963 GdkEventButton *event)
1965 GtkIconView *icon_view;
1966 GtkIconViewItem *item;
1967 GtkIconViewCellInfo *info = NULL;
1968 gboolean dirty = FALSE;
1969 GtkCellRendererMode mode;
1972 icon_view = GTK_ICON_VIEW (widget);
1974 if (event->window != icon_view->priv->bin_window)
1977 if (!GTK_WIDGET_HAS_FOCUS (widget))
1978 gtk_widget_grab_focus (widget);
1980 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1982 item = gtk_icon_view_get_item_at_coords (icon_view,
1988 g_object_get (info->cell, "mode", &mode, NULL);
1990 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1991 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1992 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1996 gtk_icon_view_scroll_to_item (icon_view, item);
1998 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2000 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2002 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2003 (event->state & GDK_SHIFT_MASK))
2005 gtk_icon_view_unselect_all_internal (icon_view);
2007 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2008 if (!icon_view->priv->anchor_item)
2009 icon_view->priv->anchor_item = item;
2011 gtk_icon_view_select_all_between (icon_view,
2012 icon_view->priv->anchor_item,
2018 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2019 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2020 (event->state & GDK_CONTROL_MASK))
2022 item->selected = !item->selected;
2023 gtk_icon_view_queue_draw_item (icon_view, item);
2028 if (!item->selected)
2030 gtk_icon_view_unselect_all_internal (icon_view);
2032 item->selected = TRUE;
2033 gtk_icon_view_queue_draw_item (icon_view, item);
2037 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2038 icon_view->priv->anchor_item = item;
2041 /* Save press to possibly begin a drag */
2042 if (icon_view->priv->pressed_button < 0)
2044 icon_view->priv->pressed_button = event->button;
2045 icon_view->priv->press_start_x = event->x;
2046 icon_view->priv->press_start_y = event->y;
2049 if (!icon_view->priv->last_single_clicked)
2050 icon_view->priv->last_single_clicked = item;
2052 /* cancel the current editing, if it exists */
2053 gtk_icon_view_stop_editing (icon_view, TRUE);
2055 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2056 gtk_icon_view_item_activate_cell (icon_view, item, info,
2058 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2059 gtk_icon_view_start_editing (icon_view, item, info,
2064 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2065 !(event->state & GDK_CONTROL_MASK))
2067 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2070 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2071 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2076 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2078 item = gtk_icon_view_get_item_at_coords (icon_view,
2083 if (item && item == icon_view->priv->last_single_clicked)
2087 path = gtk_tree_path_new_from_indices (item->index, -1);
2088 gtk_icon_view_item_activated (icon_view, path);
2089 gtk_tree_path_free (path);
2092 icon_view->priv->last_single_clicked = NULL;
2093 icon_view->priv->pressed_button = -1;
2097 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2099 return event->button == 1;
2103 gtk_icon_view_button_release (GtkWidget *widget,
2104 GdkEventButton *event)
2106 GtkIconView *icon_view;
2108 icon_view = GTK_ICON_VIEW (widget);
2110 if (icon_view->priv->pressed_button == event->button)
2111 icon_view->priv->pressed_button = -1;
2113 gtk_icon_view_stop_rubberbanding (icon_view);
2115 remove_scroll_timeout (icon_view);
2121 gtk_icon_view_key_press (GtkWidget *widget,
2124 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2126 if (icon_view->priv->doing_rubberband)
2128 if (event->keyval == GDK_Escape)
2129 gtk_icon_view_stop_rubberbanding (icon_view);
2134 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2138 gtk_icon_view_key_release (GtkWidget *widget,
2141 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2143 if (icon_view->priv->doing_rubberband)
2146 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2150 gtk_icon_view_update_rubberband (gpointer data)
2152 GtkIconView *icon_view;
2154 GdkRectangle old_area;
2155 GdkRectangle new_area;
2156 GdkRectangle common;
2157 GdkRegion *invalid_region;
2159 icon_view = GTK_ICON_VIEW (data);
2161 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2166 old_area.x = MIN (icon_view->priv->rubberband_x1,
2167 icon_view->priv->rubberband_x2);
2168 old_area.y = MIN (icon_view->priv->rubberband_y1,
2169 icon_view->priv->rubberband_y2);
2170 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2171 icon_view->priv->rubberband_x1) + 1;
2172 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2173 icon_view->priv->rubberband_y1) + 1;
2175 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2176 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2177 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2178 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2180 invalid_region = gdk_region_rectangle (&old_area);
2181 gdk_region_union_with_rect (invalid_region, &new_area);
2183 gdk_rectangle_intersect (&old_area, &new_area, &common);
2184 if (common.width > 2 && common.height > 2)
2186 GdkRegion *common_region;
2188 /* make sure the border is invalidated */
2194 common_region = gdk_region_rectangle (&common);
2196 gdk_region_subtract (invalid_region, common_region);
2197 gdk_region_destroy (common_region);
2200 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2202 gdk_region_destroy (invalid_region);
2204 icon_view->priv->rubberband_x2 = x;
2205 icon_view->priv->rubberband_y2 = y;
2207 gtk_icon_view_update_rubberband_selection (icon_view);
2211 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2217 g_assert (!icon_view->priv->doing_rubberband);
2219 for (items = icon_view->priv->items; items; items = items->next)
2221 GtkIconViewItem *item = items->data;
2223 item->selected_before_rubberbanding = item->selected;
2226 icon_view->priv->rubberband_x1 = x;
2227 icon_view->priv->rubberband_y1 = y;
2228 icon_view->priv->rubberband_x2 = x;
2229 icon_view->priv->rubberband_y2 = y;
2231 icon_view->priv->doing_rubberband = TRUE;
2233 gtk_grab_add (GTK_WIDGET (icon_view));
2237 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2239 if (!icon_view->priv->doing_rubberband)
2242 icon_view->priv->doing_rubberband = FALSE;
2244 gtk_grab_remove (GTK_WIDGET (icon_view));
2246 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2250 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2253 gint x, y, width, height;
2254 gboolean dirty = FALSE;
2256 x = MIN (icon_view->priv->rubberband_x1,
2257 icon_view->priv->rubberband_x2);
2258 y = MIN (icon_view->priv->rubberband_y1,
2259 icon_view->priv->rubberband_y2);
2260 width = ABS (icon_view->priv->rubberband_x1 -
2261 icon_view->priv->rubberband_x2);
2262 height = ABS (icon_view->priv->rubberband_y1 -
2263 icon_view->priv->rubberband_y2);
2265 for (items = icon_view->priv->items; items; items = items->next)
2267 GtkIconViewItem *item = items->data;
2271 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2272 x, y, width, height);
2274 selected = is_in ^ item->selected_before_rubberbanding;
2276 if (item->selected != selected)
2278 item->selected = selected;
2280 gtk_icon_view_queue_draw_item (icon_view, item);
2285 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2289 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2290 GtkIconViewItem *item,
2299 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2300 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2303 for (l = icon_view->priv->cell_list; l; l = l->next)
2305 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2307 if (!info->cell->visible)
2310 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2312 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2313 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2321 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2323 gboolean dirty = FALSE;
2326 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2329 for (items = icon_view->priv->items; items; items = items->next)
2331 GtkIconViewItem *item = items->data;
2335 item->selected = FALSE;
2337 gtk_icon_view_queue_draw_item (icon_view, item);
2338 gtk_icon_view_item_selected_changed (icon_view, item);
2346 /* GtkIconView signals */
2348 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2349 GtkAdjustment *hadj,
2350 GtkAdjustment *vadj)
2352 gboolean need_adjust = FALSE;
2355 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2357 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2359 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2361 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2363 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2365 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2366 0, 0, NULL, NULL, icon_view);
2367 g_object_unref (icon_view->priv->hadjustment);
2370 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2372 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2373 0, 0, NULL, NULL, icon_view);
2374 g_object_unref (icon_view->priv->vadjustment);
2377 if (icon_view->priv->hadjustment != hadj)
2379 icon_view->priv->hadjustment = hadj;
2380 g_object_ref_sink (icon_view->priv->hadjustment);
2382 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2383 G_CALLBACK (gtk_icon_view_adjustment_changed),
2388 if (icon_view->priv->vadjustment != vadj)
2390 icon_view->priv->vadjustment = vadj;
2391 g_object_ref_sink (icon_view->priv->vadjustment);
2393 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2394 G_CALLBACK (gtk_icon_view_adjustment_changed),
2400 gtk_icon_view_adjustment_changed (NULL, icon_view);
2404 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2406 gtk_icon_view_select_all (icon_view);
2410 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2412 gtk_icon_view_unselect_all (icon_view);
2416 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2418 gtk_icon_view_unselect_all (icon_view);
2420 if (icon_view->priv->cursor_item != NULL)
2421 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2425 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2428 GtkCellRendererMode mode;
2429 GtkIconViewCellInfo *info = NULL;
2431 if (!icon_view->priv->cursor_item)
2434 info = g_list_nth_data (icon_view->priv->cell_list,
2435 icon_view->priv->cursor_cell);
2439 g_object_get (info->cell, "mode", &mode, NULL);
2441 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2443 gtk_icon_view_item_activate_cell (icon_view,
2444 icon_view->priv->cursor_item,
2448 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2450 gtk_icon_view_start_editing (icon_view,
2451 icon_view->priv->cursor_item,
2457 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2458 gtk_icon_view_item_activated (icon_view, path);
2459 gtk_tree_path_free (path);
2465 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2467 if (!icon_view->priv->cursor_item)
2470 switch (icon_view->priv->selection_mode)
2472 case GTK_SELECTION_NONE:
2474 case GTK_SELECTION_BROWSE:
2475 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2477 case GTK_SELECTION_SINGLE:
2478 if (icon_view->priv->cursor_item->selected)
2479 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2481 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2483 case GTK_SELECTION_MULTIPLE:
2484 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2485 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2487 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2488 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2493 /* Internal functions */
2495 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2496 GtkIconView *icon_view)
2498 if (GTK_WIDGET_REALIZED (icon_view))
2500 gdk_window_move (icon_view->priv->bin_window,
2501 - icon_view->priv->hadjustment->value,
2502 - icon_view->priv->vadjustment->value);
2504 if (icon_view->priv->doing_rubberband)
2505 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2507 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2512 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2517 gint *maximum_width)
2520 gint x, current_width;
2521 GList *items, *last_item;
2528 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2529 max_height = g_new0 (gint, icon_view->priv->n_cells);
2536 gtk_widget_style_get (GTK_WIDGET (icon_view),
2537 "focus-line-width", &focus_width,
2540 x += icon_view->priv->margin + focus_width;
2541 current_width += 2 * (icon_view->priv->margin + focus_width);
2546 GtkIconViewItem *item = items->data;
2548 gtk_icon_view_calculate_item_size (icon_view, item);
2549 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2551 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2553 current_width += item->width;
2555 if (items != first_item)
2557 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2558 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2562 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2564 item->y = *y + focus_width;
2565 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2567 x = current_width - (icon_view->priv->margin + focus_width);
2569 for (i = 0; i < icon_view->priv->n_cells; i++)
2570 max_height[i] = MAX (max_height[i], item->box[i].height);
2572 if (current_width > *maximum_width)
2573 *maximum_width = current_width;
2579 items = items->next;
2584 /* Now go through the row again and align the icons */
2585 for (items = first_item; items != last_item; items = items->next)
2587 GtkIconViewItem *item = items->data;
2589 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2591 /* We may want to readjust the new y coordinate. */
2592 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2593 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2596 item->col = col - 1 - item->col;
2599 g_free (max_height);
2605 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2608 if (upper != adj->upper)
2610 gdouble min = MAX (0.0, upper - adj->page_size);
2611 gboolean value_changed = FALSE;
2615 if (adj->value > min)
2618 value_changed = TRUE;
2621 gtk_adjustment_changed (adj);
2624 gtk_adjustment_value_changed (adj);
2629 gtk_icon_view_layout (GtkIconView *icon_view)
2631 gint y = 0, maximum_width = 0;
2637 if (icon_view->priv->layout_idle_id != 0)
2639 g_source_remove (icon_view->priv->layout_idle_id);
2640 icon_view->priv->layout_idle_id = 0;
2643 if (icon_view->priv->model == NULL)
2646 widget = GTK_WIDGET (icon_view);
2648 item_width = icon_view->priv->item_width;
2652 for (icons = icon_view->priv->items; icons; icons = icons->next)
2654 GtkIconViewItem *item = icons->data;
2655 gtk_icon_view_calculate_item_size (icon_view, item);
2656 item_width = MAX (item_width, item->width);
2661 icons = icon_view->priv->items;
2662 y += icon_view->priv->margin;
2667 gtk_icon_view_set_cell_data (icon_view, icons->data);
2668 adjust_wrap_width (icon_view, icons->data);
2673 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2675 &y, &maximum_width);
2678 while (icons != NULL);
2680 if (maximum_width != icon_view->priv->width)
2681 icon_view->priv->width = maximum_width;
2683 y += icon_view->priv->margin;
2685 if (y != icon_view->priv->height)
2686 icon_view->priv->height = y;
2688 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2689 icon_view->priv->width);
2690 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2691 icon_view->priv->height);
2693 if (icon_view->priv->width != widget->requisition.width ||
2694 icon_view->priv->height != widget->requisition.height)
2695 gtk_widget_queue_resize_no_redraw (widget);
2697 if (GTK_WIDGET_REALIZED (icon_view))
2698 gdk_window_resize (icon_view->priv->bin_window,
2699 MAX (icon_view->priv->width, widget->allocation.width),
2700 MAX (icon_view->priv->height, widget->allocation.height));
2702 if (icon_view->priv->scroll_to_path)
2706 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2707 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2708 icon_view->priv->scroll_to_path = NULL;
2710 gtk_icon_view_scroll_to_path (icon_view, path,
2711 icon_view->priv->scroll_to_use_align,
2712 icon_view->priv->scroll_to_row_align,
2713 icon_view->priv->scroll_to_col_align);
2714 gtk_tree_path_free (path);
2717 gtk_widget_queue_draw (widget);
2721 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2722 GtkIconViewItem *item,
2723 GtkIconViewCellInfo *info,
2724 GdkRectangle *cell_area)
2726 g_return_if_fail (info->position < item->n_cells);
2728 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2730 cell_area->x = item->box[info->position].x - item->before[info->position];
2731 cell_area->y = item->y;
2732 cell_area->width = item->box[info->position].width +
2733 item->before[info->position] + item->after[info->position];
2734 cell_area->height = item->height;
2738 cell_area->x = item->x;
2739 cell_area->y = item->box[info->position].y - item->before[info->position];
2740 cell_area->width = item->width;
2741 cell_area->height = item->box[info->position].height +
2742 item->before[info->position] + item->after[info->position];
2747 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2748 GtkIconViewItem *item,
2749 GtkIconViewCellInfo *info,
2752 g_return_if_fail (info->position < item->n_cells);
2754 *box = item->box[info->position];
2757 /* try to guess a reasonable wrap width for an implicit text cell renderer
2760 adjust_wrap_width (GtkIconView *icon_view,
2761 GtkIconViewItem *item)
2763 GtkIconViewCellInfo *text_info;
2764 GtkIconViewCellInfo *pixbuf_info;
2765 gint pixbuf_width, wrap_width;
2767 if (icon_view->priv->text_cell != -1 &&
2768 icon_view->priv->pixbuf_cell != -1)
2772 text_info = g_list_nth_data (icon_view->priv->cell_list,
2773 icon_view->priv->text_cell);
2774 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2775 icon_view->priv->pixbuf_cell);
2777 gtk_cell_renderer_get_size (pixbuf_info->cell,
2778 GTK_WIDGET (icon_view),
2784 if (icon_view->priv->item_width > 0)
2785 item_width = icon_view->priv->item_width;
2787 item_width = item->width;
2789 if (item->width == -1)
2792 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2794 wrap_width = MAX (2 * pixbuf_width, 50);
2796 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2797 wrap_width = item_width;
2799 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2801 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2802 g_object_set (text_info->cell, "width", wrap_width, NULL);
2807 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2808 GtkIconViewItem *item)
2813 if (item->width != -1 && item->height != -1)
2816 if (item->n_cells != icon_view->priv->n_cells)
2818 g_free (item->before);
2819 g_free (item->after);
2822 item->before = g_new0 (gint, icon_view->priv->n_cells);
2823 item->after = g_new0 (gint, icon_view->priv->n_cells);
2824 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2826 item->n_cells = icon_view->priv->n_cells;
2829 gtk_icon_view_set_cell_data (icon_view, item);
2831 spacing = icon_view->priv->spacing;
2835 for (l = icon_view->priv->cell_list; l; l = l->next)
2837 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2839 if (!info->cell->visible)
2842 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2844 &item->box[info->position].width,
2845 &item->box[info->position].height);
2847 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2849 item->width += item->box[info->position].width
2850 + (info->position > 0 ? spacing : 0);
2851 item->height = MAX (item->height, item->box[info->position].height);
2855 item->width = MAX (item->width, item->box[info->position].width);
2856 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2862 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2863 GtkIconViewItem *item,
2866 GdkRectangle cell_area;
2872 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2874 gtk_icon_view_set_cell_data (icon_view, item);
2876 spacing = icon_view->priv->spacing;
2879 for (i = 0; i < icon_view->priv->n_cells; i++)
2881 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2882 item->height = MAX (item->height, max_height[i]);
2884 item->height += max_height[i] + (i > 0 ? spacing : 0);
2887 cell_area.x = item->x;
2888 cell_area.y = item->y;
2890 for (k = 0; k < 2; k++)
2891 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2893 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2895 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2898 if (!info->cell->visible)
2901 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2903 cell_area.width = item->box[info->position].width;
2904 cell_area.height = item->height;
2908 cell_area.width = item->width;
2909 cell_area.height = max_height[i];
2912 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2914 &item->box[info->position].x, &item->box[info->position].y,
2915 &item->box[info->position].width, &item->box[info->position].height);
2917 item->box[info->position].x += cell_area.x;
2918 item->box[info->position].y += cell_area.y;
2919 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2921 item->before[info->position] = item->box[info->position].x - cell_area.x;
2922 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2923 cell_area.x += cell_area.width + spacing;
2927 if (item->box[info->position].width > item->width)
2929 item->width = item->box[info->position].width;
2930 cell_area.width = item->width;
2932 item->before[info->position] = item->box[info->position].y - cell_area.y;
2933 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2934 cell_area.y += cell_area.height + spacing;
2938 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2940 for (i = 0; i < icon_view->priv->n_cells; i++)
2942 item->box[i].x = item->x + item->width -
2943 (item->box[i].x + item->box[i].width - item->x);
2949 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2951 g_list_foreach (icon_view->priv->items,
2952 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2956 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2963 gtk_icon_view_paint_item (GtkIconView *icon_view,
2965 GtkIconViewItem *item,
2967 GdkDrawable *drawable,
2970 gboolean draw_focus)
2974 GdkRectangle cell_area, box;
2978 GtkCellRendererState flags;
2980 if (icon_view->priv->model == NULL)
2983 gtk_icon_view_set_cell_data (icon_view, item);
2985 gtk_widget_style_get (GTK_WIDGET (icon_view),
2986 "focus-line-width", &focus_width,
2989 padding = focus_width;
2993 flags = GTK_CELL_RENDERER_SELECTED;
2994 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2995 state = GTK_STATE_SELECTED;
2997 state = GTK_STATE_ACTIVE;
3002 state = GTK_STATE_NORMAL;
3005 #ifdef DEBUG_ICON_VIEW
3006 gdk_draw_rectangle (drawable,
3007 GTK_WIDGET (icon_view)->style->black_gc,
3010 item->width, item->height);
3014 for (l = icon_view->priv->cell_list; l; l = l->next)
3016 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3018 if (!info->cell->visible)
3021 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3023 /* FIXME we hardwire background drawing behind text
3024 * cell renderers here
3026 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3028 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
3029 cairo_rectangle (cr,
3030 x - item->x + box.x,
3031 y - item->y + box.y,
3032 box.width, box.height);
3037 for (l = icon_view->priv->cell_list; l; l = l->next)
3039 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3041 if (!info->cell->visible)
3044 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3046 #ifdef DEBUG_ICON_VIEW
3047 gdk_draw_rectangle (drawable,
3048 GTK_WIDGET (icon_view)->style->black_gc,
3050 x - item->x + cell_area.x,
3051 y - item->y + cell_area.y,
3052 cell_area.width, cell_area.height);
3054 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3056 gdk_draw_rectangle (drawable,
3057 GTK_WIDGET (icon_view)->style->black_gc,
3059 x - item->x + box.x,
3060 y - item->y + box.y,
3061 box.width, box.height);
3064 cell_area.x = x - item->x + cell_area.x;
3065 cell_area.y = y - item->y + cell_area.y;
3067 gtk_cell_renderer_render (info->cell,
3069 GTK_WIDGET (icon_view),
3070 &cell_area, &cell_area, area, flags);
3074 /* FIXME where to draw the focus with generic cell renderers ? */
3076 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3077 item == icon_view->priv->cursor_item)
3078 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3080 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3082 if (!info->cell->visible)
3085 if (icon_view->priv->cursor_cell < 0 &&
3086 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3087 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3088 icon_view->priv->cursor_cell = i;
3090 if (i == icon_view->priv->cursor_cell)
3092 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3094 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3098 GTK_WIDGET (icon_view),
3100 x - item->x + box.x - padding,
3101 y - item->y + box.y - padding,
3102 box.width + 2 * padding,
3103 box.height + 2 * padding);
3110 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3115 GdkRectangle rubber_rect;
3116 GdkColor *fill_color_gdk;
3117 guchar fill_color_alpha;
3119 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3120 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3121 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3122 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3124 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3127 gtk_widget_style_get (GTK_WIDGET (icon_view),
3128 "selection-box-color", &fill_color_gdk,
3129 "selection-box-alpha", &fill_color_alpha,
3132 if (!fill_color_gdk)
3133 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3135 cairo_set_source_rgba (cr,
3136 fill_color_gdk->red / 65535.,
3137 fill_color_gdk->green / 65535.,
3138 fill_color_gdk->blue / 65535.,
3139 fill_color_alpha / 255.);
3142 gdk_cairo_rectangle (cr, &rect);
3146 /* Draw the border without alpha */
3147 cairo_set_source_rgb (cr,
3148 fill_color_gdk->red / 65535.,
3149 fill_color_gdk->green / 65535.,
3150 fill_color_gdk->blue / 65535.);
3151 cairo_rectangle (cr,
3152 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3153 rubber_rect.width - 1, rubber_rect.height - 1);
3157 gdk_color_free (fill_color_gdk);
3161 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3167 index = gtk_tree_path_get_indices (path)[0];
3169 for (l = icon_view->priv->items; l; l = l->next)
3171 GtkIconViewItem *item = l->data;
3173 if (item->index == index)
3175 gtk_icon_view_queue_draw_item (icon_view, item);
3182 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3183 GtkIconViewItem *item)
3188 gtk_widget_style_get (GTK_WIDGET (icon_view),
3189 "focus-line-width", &focus_width,
3192 rect.x = item->x - focus_width;
3193 rect.y = item->y - focus_width;
3194 rect.width = item->width + 2 * focus_width;
3195 rect.height = item->height + 2 * focus_width;
3197 if (icon_view->priv->bin_window)
3198 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3202 layout_callback (gpointer user_data)
3204 GtkIconView *icon_view;
3206 icon_view = GTK_ICON_VIEW (user_data);
3208 icon_view->priv->layout_idle_id = 0;
3210 gtk_icon_view_layout (icon_view);
3216 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3218 if (icon_view->priv->layout_idle_id != 0)
3221 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3225 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3226 GtkIconViewItem *item,
3230 AtkObject *item_obj;
3231 AtkObject *cursor_item_obj;
3233 if (icon_view->priv->cursor_item == item &&
3234 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3237 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3238 if (icon_view->priv->cursor_item != NULL)
3240 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3243 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3244 if (cursor_item_obj != NULL)
3245 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3248 icon_view->priv->cursor_item = item;
3249 if (cursor_cell >= 0)
3250 icon_view->priv->cursor_cell = cursor_cell;
3252 gtk_icon_view_queue_draw_item (icon_view, item);
3254 /* Notify that accessible focus object has changed */
3255 item_obj = atk_object_ref_accessible_child (obj, item->index);
3257 if (item_obj != NULL)
3259 atk_focus_tracker_notify (item_obj);
3260 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3261 g_object_unref (item_obj);
3266 static GtkIconViewItem *
3267 gtk_icon_view_item_new (void)
3269 GtkIconViewItem *item;
3271 item = g_new0 (GtkIconViewItem, 1);
3280 gtk_icon_view_item_free (GtkIconViewItem *item)
3282 g_return_if_fail (item != NULL);
3284 g_free (item->before);
3285 g_free (item->after);
3292 static GtkIconViewItem *
3293 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3296 gboolean only_in_cell,
3297 GtkIconViewCellInfo **cell_at_pos)
3302 for (items = icon_view->priv->items; items; items = items->next)
3304 GtkIconViewItem *item = items->data;
3306 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3307 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3309 if (only_in_cell || cell_at_pos)
3311 gtk_icon_view_set_cell_data (icon_view, item);
3313 for (l = icon_view->priv->cell_list; l; l = l->next)
3315 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3317 if (!info->cell->visible)
3320 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3322 if ((x >= box.x && x <= box.x + box.width &&
3323 y >= box.y && y <= box.y + box.height) ||
3325 x <= box.x + box.width &&
3327 y <= box.y + box.height))
3330 *cell_at_pos = info;
3340 *cell_at_pos = NULL;
3351 gtk_icon_view_select_item (GtkIconView *icon_view,
3352 GtkIconViewItem *item)
3354 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3355 g_return_if_fail (item != NULL);
3360 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3362 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3363 gtk_icon_view_unselect_all_internal (icon_view);
3365 item->selected = TRUE;
3367 gtk_icon_view_item_selected_changed (icon_view, item);
3368 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3370 gtk_icon_view_queue_draw_item (icon_view, item);
3375 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3376 GtkIconViewItem *item)
3378 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3379 g_return_if_fail (item != NULL);
3381 if (!item->selected)
3384 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3385 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3388 item->selected = FALSE;
3390 gtk_icon_view_item_selected_changed (icon_view, item);
3391 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3393 gtk_icon_view_queue_draw_item (icon_view, item);
3397 verify_items (GtkIconView *icon_view)
3402 for (items = icon_view->priv->items; items; items = items->next)
3404 GtkIconViewItem *item = items->data;
3406 if (item->index != i)
3407 g_error ("List item does not match its index: "
3408 "item index %d and list index %d\n", item->index, i);
3415 gtk_icon_view_row_changed (GtkTreeModel *model,
3420 GtkIconViewItem *item;
3422 GtkIconView *icon_view;
3424 icon_view = GTK_ICON_VIEW (data);
3426 gtk_icon_view_stop_editing (icon_view, TRUE);
3428 index = gtk_tree_path_get_indices(path)[0];
3429 item = g_list_nth_data (icon_view->priv->items, index);
3431 gtk_icon_view_item_invalidate_size (item);
3432 gtk_icon_view_queue_layout (icon_view);
3434 verify_items (icon_view);
3438 gtk_icon_view_row_inserted (GtkTreeModel *model,
3444 GtkIconViewItem *item;
3445 gboolean iters_persist;
3446 GtkIconView *icon_view;
3449 icon_view = GTK_ICON_VIEW (data);
3451 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3453 index = gtk_tree_path_get_indices(path)[0];
3455 item = gtk_icon_view_item_new ();
3460 item->index = index;
3462 /* FIXME: We can be more efficient here,
3463 we can store a tail pointer and use that when
3464 appending (which is a rather common operation)
3466 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3469 list = g_list_nth (icon_view->priv->items, index + 1);
3470 for (; list; list = list->next)
3477 verify_items (icon_view);
3479 gtk_icon_view_queue_layout (icon_view);
3483 gtk_icon_view_row_deleted (GtkTreeModel *model,
3488 GtkIconView *icon_view;
3489 GtkIconViewItem *item;
3491 gboolean emit = FALSE;
3493 icon_view = GTK_ICON_VIEW (data);
3495 index = gtk_tree_path_get_indices(path)[0];
3497 list = g_list_nth (icon_view->priv->items, index);
3500 gtk_icon_view_stop_editing (icon_view, TRUE);
3502 if (item == icon_view->priv->anchor_item)
3503 icon_view->priv->anchor_item = NULL;
3505 if (item == icon_view->priv->cursor_item)
3506 icon_view->priv->cursor_item = NULL;
3511 gtk_icon_view_item_free (item);
3513 for (next = list->next; next; next = next->next)
3520 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3522 verify_items (icon_view);
3524 gtk_icon_view_queue_layout (icon_view);
3527 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3531 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3532 GtkTreePath *parent,
3539 GtkIconView *icon_view;
3540 GList *items = NULL, *list;
3541 GtkIconViewItem **item_array;
3544 icon_view = GTK_ICON_VIEW (data);
3546 gtk_icon_view_stop_editing (icon_view, TRUE);
3548 length = gtk_tree_model_iter_n_children (model, NULL);
3550 order = g_new (gint, length);
3551 for (i = 0; i < length; i++)
3552 order [new_order[i]] = i;
3554 item_array = g_new (GtkIconViewItem *, length);
3555 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3556 item_array[order[i]] = list->data;
3559 for (i = length - 1; i >= 0; i--)
3561 item_array[i]->index = i;
3562 items = g_list_prepend (items, item_array[i]);
3565 g_free (item_array);
3566 g_list_free (icon_view->priv->items);
3567 icon_view->priv->items = items;
3569 gtk_icon_view_queue_layout (icon_view);
3571 verify_items (icon_view);
3575 gtk_icon_view_build_items (GtkIconView *icon_view)
3579 gboolean iters_persist;
3580 GList *items = NULL;
3582 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3584 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3592 GtkIconViewItem *item = gtk_icon_view_item_new ();
3601 items = g_list_prepend (items, item);
3603 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3605 icon_view->priv->items = g_list_reverse (items);
3609 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3612 GtkMovementStep step,
3616 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3617 I_("move_cursor"), 2,
3621 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3626 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3629 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3634 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3641 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3642 GtkMovementStep step,
3645 GdkModifierType state;
3647 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3648 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3649 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3650 step == GTK_MOVEMENT_DISPLAY_LINES ||
3651 step == GTK_MOVEMENT_PAGES ||
3652 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3654 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3657 gtk_icon_view_stop_editing (icon_view, FALSE);
3658 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3660 if (gtk_get_current_event_state (&state))
3662 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3663 icon_view->priv->ctrl_pressed = TRUE;
3664 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3665 icon_view->priv->shift_pressed = TRUE;
3667 /* else we assume not pressed */
3671 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3672 case GTK_MOVEMENT_VISUAL_POSITIONS:
3673 gtk_icon_view_move_cursor_left_right (icon_view, count);
3675 case GTK_MOVEMENT_DISPLAY_LINES:
3676 gtk_icon_view_move_cursor_up_down (icon_view, count);
3678 case GTK_MOVEMENT_PAGES:
3679 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3681 case GTK_MOVEMENT_BUFFER_ENDS:
3682 gtk_icon_view_move_cursor_start_end (icon_view, count);
3685 g_assert_not_reached ();
3688 icon_view->priv->ctrl_pressed = FALSE;
3689 icon_view->priv->shift_pressed = FALSE;
3694 static GtkIconViewItem *
3695 find_item (GtkIconView *icon_view,
3696 GtkIconViewItem *current,
3702 GtkIconViewItem *item;
3704 /* FIXME: this could be more efficient
3706 row = current->row + row_ofs;
3707 col = current->col + col_ofs;
3709 for (items = icon_view->priv->items; items; items = items->next)
3712 if (item->row == row && item->col == col)
3720 find_cell (GtkIconView *icon_view,
3721 GtkIconViewItem *item,
3723 GtkOrientation orientation,
3734 if (icon_view->priv->orientation != orientation)
3737 gtk_icon_view_set_cell_data (icon_view, item);
3739 focusable = g_new0 (gint, icon_view->priv->n_cells);
3744 for (k = 0; k < 2; k++)
3745 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3747 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3749 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3752 if (!info->cell->visible)
3755 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3758 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3761 current = n_focusable;
3763 focusable[n_focusable] = i;
3769 if (n_focusable == 0)
3770 focusable[n_focusable++] = first_text;
3774 current = step > 0 ? 0 : n_focusable - 1;
3775 cell = focusable[current];
3778 if (current + *count < 0)
3781 *count = current + *count;
3783 else if (current + *count > n_focusable - 1)
3786 *count = current + *count - (n_focusable - 1);
3790 cell = focusable[current + *count];
3799 static GtkIconViewItem *
3800 find_item_page_up_down (GtkIconView *icon_view,
3801 GtkIconViewItem *current,
3808 y = current->y + count * icon_view->priv->vadjustment->page_size;
3810 item = g_list_find (icon_view->priv->items, current);
3815 for (next = item->next; next; next = next->next)
3817 if (((GtkIconViewItem *)next->data)->col == col)
3820 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3830 for (next = item->prev; next; next = next->prev)
3832 if (((GtkIconViewItem *)next->data)->col == col)
3835 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3849 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3850 GtkIconViewItem *anchor,
3851 GtkIconViewItem *cursor)
3854 GtkIconViewItem *item;
3855 gint row1, row2, col1, col2;
3856 gboolean dirty = FALSE;
3858 if (anchor->row < cursor->row)
3869 if (anchor->col < cursor->col)
3880 for (items = icon_view->priv->items; items; items = items->next)
3884 if (row1 <= item->row && item->row <= row2 &&
3885 col1 <= item->col && item->col <= col2)
3887 if (!item->selected)
3890 item->selected = TRUE;
3891 gtk_icon_view_item_selected_changed (icon_view, item);
3893 gtk_icon_view_queue_draw_item (icon_view, item);
3901 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3904 GtkIconViewItem *item;
3906 gboolean dirty = FALSE;
3909 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3912 if (!icon_view->priv->cursor_item)
3917 list = icon_view->priv->items;
3919 list = g_list_last (icon_view->priv->items);
3921 item = list ? list->data : NULL;
3926 item = icon_view->priv->cursor_item;
3927 cell = icon_view->priv->cursor_cell;
3928 step = count > 0 ? 1 : -1;
3931 cell = find_cell (icon_view, item, cell,
3932 GTK_ORIENTATION_VERTICAL,
3937 item = find_item (icon_view, item, step, 0);
3938 count = count - step;
3944 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3948 if (icon_view->priv->ctrl_pressed ||
3949 !icon_view->priv->shift_pressed ||
3950 !icon_view->priv->anchor_item ||
3951 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3952 icon_view->priv->anchor_item = item;
3954 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3956 if (!icon_view->priv->ctrl_pressed &&
3957 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3959 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3960 dirty = gtk_icon_view_select_all_between (icon_view,
3961 icon_view->priv->anchor_item,
3965 gtk_icon_view_scroll_to_item (icon_view, item);
3968 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3972 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3975 GtkIconViewItem *item;
3976 gboolean dirty = FALSE;
3978 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3981 if (!icon_view->priv->cursor_item)
3986 list = icon_view->priv->items;
3988 list = g_list_last (icon_view->priv->items);
3990 item = list ? list->data : NULL;
3993 item = find_item_page_up_down (icon_view,
3994 icon_view->priv->cursor_item,
3997 if (item == icon_view->priv->cursor_item)
3998 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4003 if (icon_view->priv->ctrl_pressed ||
4004 !icon_view->priv->shift_pressed ||
4005 !icon_view->priv->anchor_item ||
4006 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4007 icon_view->priv->anchor_item = item;
4009 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4011 if (!icon_view->priv->ctrl_pressed &&
4012 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4014 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4015 dirty = gtk_icon_view_select_all_between (icon_view,
4016 icon_view->priv->anchor_item,
4020 gtk_icon_view_scroll_to_item (icon_view, item);
4023 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4027 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4030 GtkIconViewItem *item;
4032 gboolean dirty = FALSE;
4035 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4038 if (!icon_view->priv->cursor_item)
4043 list = icon_view->priv->items;
4045 list = g_list_last (icon_view->priv->items);
4047 item = list ? list->data : NULL;
4051 item = icon_view->priv->cursor_item;
4052 cell = icon_view->priv->cursor_cell;
4053 step = count > 0 ? 1 : -1;
4056 cell = find_cell (icon_view, item, cell,
4057 GTK_ORIENTATION_HORIZONTAL,
4062 item = find_item (icon_view, item, 0, step);
4063 count = count - step;
4069 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4073 if (icon_view->priv->ctrl_pressed ||
4074 !icon_view->priv->shift_pressed ||
4075 !icon_view->priv->anchor_item ||
4076 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4077 icon_view->priv->anchor_item = item;
4079 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4081 if (!icon_view->priv->ctrl_pressed &&
4082 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4084 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4085 dirty = gtk_icon_view_select_all_between (icon_view,
4086 icon_view->priv->anchor_item,
4090 gtk_icon_view_scroll_to_item (icon_view, item);
4093 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4097 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4100 GtkIconViewItem *item;
4102 gboolean dirty = FALSE;
4104 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4108 list = icon_view->priv->items;
4110 list = g_list_last (icon_view->priv->items);
4112 item = list ? list->data : NULL;
4114 if (item == icon_view->priv->cursor_item)
4115 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4120 if (icon_view->priv->ctrl_pressed ||
4121 !icon_view->priv->shift_pressed ||
4122 !icon_view->priv->anchor_item ||
4123 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4124 icon_view->priv->anchor_item = item;
4126 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4128 if (!icon_view->priv->ctrl_pressed &&
4129 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4131 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4132 dirty = gtk_icon_view_select_all_between (icon_view,
4133 icon_view->priv->anchor_item,
4137 gtk_icon_view_scroll_to_item (icon_view, item);
4140 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4144 * gtk_icon_view_scroll_to_path:
4145 * @icon_view: A #GtkIconView.
4146 * @path: The path of the item to move to.
4147 * @use_align: whether to use alignment arguments, or %FALSE.
4148 * @row_align: The vertical alignment of the item specified by @path.
4149 * @col_align: The horizontal alignment of the item specified by @path.
4151 * Moves the alignments of @icon_view to the position specified by @path.
4152 * @row_align determines where the row is placed, and @col_align determines
4153 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4154 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4157 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4158 * tree does the minimum amount of work to scroll the item onto the screen.
4159 * This means that the item will be scrolled to the edge closest to its current
4160 * position. If the item is currently visible on the screen, nothing is done.
4162 * This function only works if the model is set, and @path is a valid row on
4163 * the model. If the model changes before the @icon_view is realized, the
4164 * centered path will be modified to reflect this change.
4169 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4175 GtkIconViewItem *item = NULL;
4177 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4178 g_return_if_fail (path != NULL);
4179 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4180 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4182 if (gtk_tree_path_get_depth (path) > 0)
4183 item = g_list_nth_data (icon_view->priv->items,
4184 gtk_tree_path_get_indices(path)[0]);
4186 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4188 if (icon_view->priv->scroll_to_path)
4189 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4191 icon_view->priv->scroll_to_path = NULL;
4194 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4196 icon_view->priv->scroll_to_use_align = use_align;
4197 icon_view->priv->scroll_to_row_align = row_align;
4198 icon_view->priv->scroll_to_col_align = col_align;
4209 gtk_widget_style_get (GTK_WIDGET (icon_view),
4210 "focus-line-width", &focus_width,
4213 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4215 offset = y + item->y - focus_width -
4216 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4218 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4219 icon_view->priv->vadjustment->value + offset);
4221 offset = x + item->x - focus_width -
4222 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4224 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4225 icon_view->priv->hadjustment->value + offset);
4227 gtk_adjustment_changed (icon_view->priv->hadjustment);
4228 gtk_adjustment_changed (icon_view->priv->vadjustment);
4231 gtk_icon_view_scroll_to_item (icon_view, item);
4236 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4237 GtkIconViewItem *item)
4239 gint x, y, width, height;
4242 gtk_widget_style_get (GTK_WIDGET (icon_view),
4243 "focus-line-width", &focus_width,
4246 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4248 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4250 if (y + item->y - focus_width < 0)
4251 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4252 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4253 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4254 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4255 icon_view->priv->vadjustment->value + y + item->y + item->height
4256 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4258 if (x + item->x - focus_width < 0)
4259 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4260 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4261 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4262 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4263 icon_view->priv->hadjustment->value + x + item->x + item->width
4264 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4266 gtk_adjustment_changed (icon_view->priv->hadjustment);
4267 gtk_adjustment_changed (icon_view->priv->vadjustment);
4270 /* GtkCellLayout implementation */
4271 static GtkIconViewCellInfo *
4272 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4273 GtkCellRenderer *renderer)
4277 for (i = icon_view->priv->cell_list; i; i = i->next)
4279 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4281 if (info->cell == renderer)
4289 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4290 GtkIconViewItem *item)
4293 gboolean iters_persist;
4296 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4302 path = gtk_tree_path_new_from_indices (item->index, -1);
4303 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4305 gtk_tree_path_free (path);
4310 for (i = icon_view->priv->cell_list; i; i = i->next)
4313 GtkIconViewCellInfo *info = i->data;
4315 g_object_freeze_notify (G_OBJECT (info->cell));
4317 for (j = info->attributes; j && j->next; j = j->next->next)
4319 gchar *property = j->data;
4320 gint column = GPOINTER_TO_INT (j->next->data);
4321 GValue value = {0, };
4323 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4325 g_object_set_property (G_OBJECT (info->cell),
4327 g_value_unset (&value);
4331 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4333 icon_view->priv->model,
4337 g_object_thaw_notify (G_OBJECT (info->cell));
4342 free_cell_attributes (GtkIconViewCellInfo *info)
4346 list = info->attributes;
4347 while (list && list->next)
4349 g_free (list->data);
4350 list = list->next->next;
4353 g_slist_free (info->attributes);
4354 info->attributes = NULL;
4358 free_cell_info (GtkIconViewCellInfo *info)
4360 free_cell_attributes (info);
4362 g_object_unref (info->cell);
4365 (* info->destroy) (info->func_data);
4371 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4372 GtkCellRenderer *renderer,
4375 GtkIconViewCellInfo *info;
4376 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4378 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4379 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4381 g_object_ref_sink (renderer);
4383 info = g_new0 (GtkIconViewCellInfo, 1);
4384 info->cell = renderer;
4385 info->expand = expand ? TRUE : FALSE;
4386 info->pack = GTK_PACK_START;
4387 info->position = icon_view->priv->n_cells;
4389 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4390 icon_view->priv->n_cells++;
4394 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4395 GtkCellRenderer *renderer,
4398 GtkIconViewCellInfo *info;
4399 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4401 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4402 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4404 g_object_ref_sink (renderer);
4406 info = g_new0 (GtkIconViewCellInfo, 1);
4407 info->cell = renderer;
4408 info->expand = expand ? TRUE : FALSE;
4409 info->pack = GTK_PACK_END;
4410 info->position = icon_view->priv->n_cells;
4412 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4413 icon_view->priv->n_cells++;
4417 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4418 GtkCellRenderer *renderer,
4419 const gchar *attribute,
4422 GtkIconViewCellInfo *info;
4423 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4425 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4426 g_return_if_fail (info != NULL);
4428 info->attributes = g_slist_prepend (info->attributes,
4429 GINT_TO_POINTER (column));
4430 info->attributes = g_slist_prepend (info->attributes,
4431 g_strdup (attribute));
4435 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4437 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4439 while (icon_view->priv->cell_list)
4441 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4442 free_cell_info (info);
4443 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4444 icon_view->priv->cell_list);
4447 icon_view->priv->n_cells = 0;
4451 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4452 GtkCellRenderer *cell,
4453 GtkCellLayoutDataFunc func,
4455 GDestroyNotify destroy)
4457 GtkIconViewCellInfo *info;
4458 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4460 info = gtk_icon_view_get_cell_info (icon_view, cell);
4461 g_return_if_fail (info != NULL);
4465 GDestroyNotify d = info->destroy;
4467 info->destroy = NULL;
4468 d (info->func_data);
4472 info->func_data = func_data;
4473 info->destroy = destroy;
4477 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4478 GtkCellRenderer *renderer)
4480 GtkIconViewCellInfo *info;
4482 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4484 free_cell_attributes (info);
4488 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4489 GtkCellRenderer *cell,
4492 GtkIconView *icon_view;
4494 GtkIconViewCellInfo *info;
4497 icon_view = GTK_ICON_VIEW (layout);
4499 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4501 info = gtk_icon_view_get_cell_info (icon_view, cell);
4503 g_return_if_fail (info != NULL);
4504 g_return_if_fail (position >= 0);
4506 link = g_list_find (icon_view->priv->cell_list, info);
4508 g_return_if_fail (link != NULL);
4510 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4512 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4515 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4522 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4526 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4528 GtkIconView *icon_view = (GtkIconView *)layout;
4529 GList *retval = NULL, *l;
4531 for (l = icon_view->priv->cell_list; l; l = l->next)
4533 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4535 retval = g_list_prepend (retval, info->cell);
4538 return g_list_reverse (retval);
4545 * gtk_icon_view_new:
4547 * Creates a new #GtkIconView widget
4549 * Return value: A newly created #GtkIconView widget
4554 gtk_icon_view_new (void)
4556 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4560 * gtk_icon_view_new_with_model:
4561 * @model: The model.
4563 * Creates a new #GtkIconView widget with the model @model.
4565 * Return value: A newly created #GtkIconView widget.
4570 gtk_icon_view_new_with_model (GtkTreeModel *model)
4572 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4576 * gtk_icon_view_convert_widget_to_bin_window_coords:
4577 * @icon_view: a #GtkIconView
4578 * @wx: X coordinate relative to the widget
4579 * @wy: Y coordinate relative to the widget
4580 * @bx: return location for bin_window X coordinate
4581 * @by: return location for bin_window Y coordinate
4583 * Converts widget coordinates to coordinates for the bin_window,
4584 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4589 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4597 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4599 if (icon_view->priv->bin_window)
4600 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4611 * gtk_icon_view_get_path_at_pos:
4612 * @icon_view: A #GtkIconView.
4613 * @x: The x position to be identified
4614 * @y: The y position to be identified
4616 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4617 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4618 * the cell at the specified position.
4619 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4620 * widget coordinates to bin_window coordinates.
4622 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4623 * if no icon exists at that position.
4628 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4632 GtkIconViewItem *item;
4635 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4637 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4642 path = gtk_tree_path_new_from_indices (item->index, -1);
4648 * gtk_icon_view_get_item_at_pos:
4649 * @icon_view: A #GtkIconView.
4650 * @x: The x position to be identified
4651 * @y: The y position to be identified
4652 * @path: Return location for the path, or %NULL
4653 * @cell: Return location for the renderer responsible for the cell
4654 * at (@x, @y), or %NULL
4656 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4657 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4658 * obtains the cell at the specified position. The returned path should
4659 * be freed with gtk_tree_path_free().
4660 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4661 * widget coordinates to bin_window coordinates.
4663 * Return value: %TRUE if an item exists at the specified position
4668 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4672 GtkCellRenderer **cell)
4674 GtkIconViewItem *item;
4675 GtkIconViewCellInfo *info;
4677 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4679 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4684 *path = gtk_tree_path_new_from_indices (item->index, -1);
4697 return (item != NULL);
4701 * gtk_icon_view_set_tooltip_item:
4702 * @icon_view: a #GtkIconView
4703 * @tooltip: a #GtkTooltip
4704 * @path: a #GtkTreePath
4706 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4707 * See also gtk_tooltip_set_tip_area().
4712 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4713 GtkTooltip *tooltip,
4716 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4717 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4719 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4723 * gtk_icon_view_set_tooltip_cell:
4724 * @icon_view: a #GtkIconView
4725 * @tooltip: a #GtkTooltip
4726 * @path: a #GtkTreePath
4727 * @cell: a #GtkCellRenderer or %NULL
4729 * Sets the tip area of @tooltip to the area which @cell occupies in
4730 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4735 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4736 GtkTooltip *tooltip,
4738 GtkCellRenderer *cell)
4741 GtkIconViewItem *item = NULL;
4742 GtkIconViewCellInfo *info = NULL;
4745 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4746 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4747 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4749 if (gtk_tree_path_get_depth (path) > 0)
4750 item = g_list_nth_data (icon_view->priv->items,
4751 gtk_tree_path_get_indices(path)[0]);
4758 info = gtk_icon_view_get_cell_info (icon_view, cell);
4759 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4765 rect.width = item->width;
4766 rect.height = item->height;
4769 if (icon_view->priv->bin_window)
4771 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4776 gtk_tooltip_set_tip_area (tooltip, &rect);
4781 * gtk_icon_view_get_tooltip_context:
4782 * @icon_view: an #GtkIconView
4783 * @x: the x coordinate (relative to widget coordinates)
4784 * @y: the y coordinate (relative to widget coordinates)
4785 * @keyboard_tip: whether this is a keyboard tooltip or not
4786 * @model: a pointer to receive a #GtkTreeModel or %NULL
4787 * @path: a pointer to receive a #GtkTreePath or %NULL
4788 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4790 * This function is supposed to be used in a #GtkWidget::query-tooltip
4791 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4792 * which are received in the signal handler, should be passed to this
4793 * function without modification.
4795 * The return value indicates whether there is an icon view item at the given
4796 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4797 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4798 * @model, @path and @iter which have been provided will be set to point to
4799 * that row and the corresponding model. @x and @y will always be converted
4800 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4802 * Return value: whether or not the given tooltip context points to a item
4807 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4810 gboolean keyboard_tip,
4811 GtkTreeModel **model,
4815 GtkTreePath *tmppath = NULL;
4817 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4818 g_return_val_if_fail (x != NULL, FALSE);
4819 g_return_val_if_fail (y != NULL, FALSE);
4823 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4830 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4833 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4838 *model = gtk_icon_view_get_model (icon_view);
4841 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4847 gtk_tree_path_free (tmppath);
4853 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4856 gboolean keyboard_tip,
4857 GtkTooltip *tooltip,
4863 GtkTreeModel *model;
4864 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4866 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4869 &model, &path, &iter))
4872 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4876 gtk_tree_path_free (path);
4880 gtk_tooltip_set_markup (tooltip, str);
4881 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4883 gtk_tree_path_free (path);
4891 * gtk_icon_view_set_tooltip_column:
4892 * @icon_view: a #GtkIconView
4893 * @column: an integer, which is a valid column number for @icon_view's model
4895 * If you only plan to have simple (text-only) tooltips on full items, you
4896 * can use this function to have #GtkIconView handle these automatically
4897 * for you. @column should be set to the column in @icon_view's model
4898 * containing the tooltip texts, or -1 to disable this feature.
4900 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4901 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4906 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4909 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4911 if (column == icon_view->priv->tooltip_column)
4916 g_signal_handlers_disconnect_by_func (icon_view,
4917 gtk_icon_view_set_tooltip_query_cb,
4919 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4923 if (icon_view->priv->tooltip_column == -1)
4925 g_signal_connect (icon_view, "query-tooltip",
4926 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4927 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4931 icon_view->priv->tooltip_column = column;
4932 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4936 * gtk_icon_view_get_tooltip_column:
4937 * @icon_view: a #GtkIconView
4939 * Returns the column of @icon_view's model which is being used for
4940 * displaying tooltips on @icon_view's rows.
4942 * Return value: the index of the tooltip column that is currently being
4943 * used, or -1 if this is disabled.
4948 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4950 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4952 return icon_view->priv->tooltip_column;
4956 * gtk_icon_view_get_visible_range:
4957 * @icon_view: A #GtkIconView
4958 * @start_path: Return location for start of region, or %NULL
4959 * @end_path: Return location for end of region, or %NULL
4961 * Sets @start_path and @end_path to be the first and last visible path.
4962 * Note that there may be invisible paths in between.
4964 * Both paths should be freed with gtk_tree_path_free() after use.
4966 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4971 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4972 GtkTreePath **start_path,
4973 GtkTreePath **end_path)
4975 gint start_index = -1;
4976 gint end_index = -1;
4979 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4981 if (icon_view->priv->hadjustment == NULL ||
4982 icon_view->priv->vadjustment == NULL)
4985 if (start_path == NULL && end_path == NULL)
4988 for (icons = icon_view->priv->items; icons; icons = icons->next)
4990 GtkIconViewItem *item = icons->data;
4992 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4993 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4994 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4995 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4997 if (start_index == -1)
4998 start_index = item->index;
4999 end_index = item->index;
5003 if (start_path && start_index != -1)
5004 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5005 if (end_path && end_index != -1)
5006 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5008 return start_index != -1;
5012 * gtk_icon_view_selected_foreach:
5013 * @icon_view: A #GtkIconView.
5014 * @func: The funcion to call for each selected icon.
5015 * @data: User data to pass to the function.
5017 * Calls a function for each selected icon. Note that the model or
5018 * selection cannot be modified from within this function.
5023 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5024 GtkIconViewForeachFunc func,
5029 for (list = icon_view->priv->items; list; list = list->next)
5031 GtkIconViewItem *item = list->data;
5032 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5035 (* func) (icon_view, path, data);
5037 gtk_tree_path_free (path);
5042 * gtk_icon_view_set_selection_mode:
5043 * @icon_view: A #GtkIconView.
5044 * @mode: The selection mode
5046 * Sets the selection mode of the @icon_view.
5051 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5052 GtkSelectionMode mode)
5054 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5056 if (mode == icon_view->priv->selection_mode)
5059 if (mode == GTK_SELECTION_NONE ||
5060 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5061 gtk_icon_view_unselect_all (icon_view);
5063 icon_view->priv->selection_mode = mode;
5065 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5069 * gtk_icon_view_get_selection_mode:
5070 * @icon_view: A #GtkIconView.
5072 * Gets the selection mode of the @icon_view.
5074 * Return value: the current selection mode
5079 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5081 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5083 return icon_view->priv->selection_mode;
5087 * gtk_icon_view_set_model:
5088 * @icon_view: A #GtkIconView.
5089 * @model: The model.
5091 * Sets the model for a #GtkIconView.
5092 * If the @icon_view already has a model set, it will remove
5093 * it before setting the new model. If @model is %NULL, then
5094 * it will unset the old model.
5099 gtk_icon_view_set_model (GtkIconView *icon_view,
5100 GtkTreeModel *model)
5102 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5103 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5105 if (icon_view->priv->model == model)
5108 if (icon_view->priv->scroll_to_path)
5110 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5111 icon_view->priv->scroll_to_path = NULL;
5114 gtk_icon_view_stop_editing (icon_view, TRUE);
5120 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5122 if (icon_view->priv->pixbuf_column != -1)
5124 column_type = gtk_tree_model_get_column_type (model,
5125 icon_view->priv->pixbuf_column);
5127 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5130 if (icon_view->priv->text_column != -1)
5132 column_type = gtk_tree_model_get_column_type (model,
5133 icon_view->priv->text_column);
5135 g_return_if_fail (column_type == G_TYPE_STRING);
5138 if (icon_view->priv->markup_column != -1)
5140 column_type = gtk_tree_model_get_column_type (model,
5141 icon_view->priv->markup_column);
5143 g_return_if_fail (column_type == G_TYPE_STRING);
5148 if (icon_view->priv->model)
5150 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5151 gtk_icon_view_row_changed,
5153 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5154 gtk_icon_view_row_inserted,
5156 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5157 gtk_icon_view_row_deleted,
5159 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5160 gtk_icon_view_rows_reordered,
5163 g_object_unref (icon_view->priv->model);
5165 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5166 g_list_free (icon_view->priv->items);
5167 icon_view->priv->items = NULL;
5168 icon_view->priv->anchor_item = NULL;
5169 icon_view->priv->cursor_item = NULL;
5170 icon_view->priv->last_single_clicked = NULL;
5171 icon_view->priv->width = 0;
5172 icon_view->priv->height = 0;
5175 icon_view->priv->model = model;
5177 if (icon_view->priv->model)
5179 g_object_ref (icon_view->priv->model);
5180 g_signal_connect (icon_view->priv->model,
5182 G_CALLBACK (gtk_icon_view_row_changed),
5184 g_signal_connect (icon_view->priv->model,
5186 G_CALLBACK (gtk_icon_view_row_inserted),
5188 g_signal_connect (icon_view->priv->model,
5190 G_CALLBACK (gtk_icon_view_row_deleted),
5192 g_signal_connect (icon_view->priv->model,
5194 G_CALLBACK (gtk_icon_view_rows_reordered),
5197 gtk_icon_view_build_items (icon_view);
5199 gtk_icon_view_queue_layout (icon_view);
5202 g_object_notify (G_OBJECT (icon_view), "model");
5204 if (GTK_WIDGET_REALIZED (icon_view))
5205 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5209 * gtk_icon_view_get_model:
5210 * @icon_view: a #GtkIconView
5212 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5215 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5220 gtk_icon_view_get_model (GtkIconView *icon_view)
5222 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5224 return icon_view->priv->model;
5228 update_text_cell (GtkIconView *icon_view)
5230 GtkIconViewCellInfo *info;
5234 if (icon_view->priv->text_column == -1 &&
5235 icon_view->priv->markup_column == -1)
5237 if (icon_view->priv->text_cell != -1)
5239 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5240 icon_view->priv->pixbuf_cell--;
5242 info = g_list_nth_data (icon_view->priv->cell_list,
5243 icon_view->priv->text_cell);
5245 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5247 free_cell_info (info);
5249 icon_view->priv->n_cells--;
5250 icon_view->priv->text_cell = -1;
5255 if (icon_view->priv->text_cell == -1)
5257 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5258 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5259 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5262 if (info->cell == cell)
5264 icon_view->priv->text_cell = i;
5270 info = g_list_nth_data (icon_view->priv->cell_list,
5271 icon_view->priv->text_cell);
5273 if (icon_view->priv->markup_column != -1)
5274 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5276 "markup", icon_view->priv->markup_column,
5279 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5281 "text", icon_view->priv->text_column,
5284 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5285 g_object_set (info->cell,
5286 "alignment", PANGO_ALIGN_CENTER,
5287 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5292 g_object_set (info->cell,
5293 "alignment", PANGO_ALIGN_LEFT,
5294 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5302 update_pixbuf_cell (GtkIconView *icon_view)
5304 GtkIconViewCellInfo *info;
5308 if (icon_view->priv->pixbuf_column == -1)
5310 if (icon_view->priv->pixbuf_cell != -1)
5312 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5313 icon_view->priv->text_cell--;
5315 info = g_list_nth_data (icon_view->priv->cell_list,
5316 icon_view->priv->pixbuf_cell);
5318 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5320 free_cell_info (info);
5322 icon_view->priv->n_cells--;
5323 icon_view->priv->pixbuf_cell = -1;
5328 if (icon_view->priv->pixbuf_cell == -1)
5330 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5332 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5333 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5336 if (info->cell == cell)
5338 icon_view->priv->pixbuf_cell = i;
5344 info = g_list_nth_data (icon_view->priv->cell_list,
5345 icon_view->priv->pixbuf_cell);
5347 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5349 "pixbuf", icon_view->priv->pixbuf_column,
5352 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5353 g_object_set (info->cell,
5354 "follow-state", TRUE,
5359 g_object_set (info->cell,
5360 "follow-state", TRUE,
5368 * gtk_icon_view_set_text_column:
5369 * @icon_view: A #GtkIconView.
5370 * @column: A column in the currently used model, or -1 to display no text
5372 * Sets the column with text for @icon_view to be @column. The text
5373 * column must be of type #G_TYPE_STRING.
5378 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5381 if (column == icon_view->priv->text_column)
5385 icon_view->priv->text_column = -1;
5388 if (icon_view->priv->model != NULL)
5392 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5394 g_return_if_fail (column_type == G_TYPE_STRING);
5397 icon_view->priv->text_column = column;
5400 gtk_icon_view_stop_editing (icon_view, TRUE);
5402 update_text_cell (icon_view);
5404 gtk_icon_view_invalidate_sizes (icon_view);
5405 gtk_icon_view_queue_layout (icon_view);
5407 g_object_notify (G_OBJECT (icon_view), "text-column");
5411 * gtk_icon_view_get_text_column:
5412 * @icon_view: A #GtkIconView.
5414 * Returns the column with text for @icon_view.
5416 * Returns: the text column, or -1 if it's unset.
5421 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5423 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5425 return icon_view->priv->text_column;
5429 * gtk_icon_view_set_markup_column:
5430 * @icon_view: A #GtkIconView.
5431 * @column: A column in the currently used model, or -1 to display no text
5433 * Sets the column with markup information for @icon_view to be
5434 * @column. The markup column must be of type #G_TYPE_STRING.
5435 * If the markup column is set to something, it overrides
5436 * the text column set by gtk_icon_view_set_text_column().
5441 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5444 if (column == icon_view->priv->markup_column)
5448 icon_view->priv->markup_column = -1;
5451 if (icon_view->priv->model != NULL)
5455 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5457 g_return_if_fail (column_type == G_TYPE_STRING);
5460 icon_view->priv->markup_column = column;
5463 gtk_icon_view_stop_editing (icon_view, TRUE);
5465 update_text_cell (icon_view);
5467 gtk_icon_view_invalidate_sizes (icon_view);
5468 gtk_icon_view_queue_layout (icon_view);
5470 g_object_notify (G_OBJECT (icon_view), "markup-column");
5474 * gtk_icon_view_get_markup_column:
5475 * @icon_view: A #GtkIconView.
5477 * Returns the column with markup text for @icon_view.
5479 * Returns: the markup column, or -1 if it's unset.
5484 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5486 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5488 return icon_view->priv->markup_column;
5492 * gtk_icon_view_set_pixbuf_column:
5493 * @icon_view: A #GtkIconView.
5494 * @column: A column in the currently used model, or -1 to disable
5496 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5497 * column must be of type #GDK_TYPE_PIXBUF
5502 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5505 if (column == icon_view->priv->pixbuf_column)
5509 icon_view->priv->pixbuf_column = -1;
5512 if (icon_view->priv->model != NULL)
5516 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5518 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5521 icon_view->priv->pixbuf_column = column;
5524 gtk_icon_view_stop_editing (icon_view, TRUE);
5526 update_pixbuf_cell (icon_view);
5528 gtk_icon_view_invalidate_sizes (icon_view);
5529 gtk_icon_view_queue_layout (icon_view);
5531 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5536 * gtk_icon_view_get_pixbuf_column:
5537 * @icon_view: A #GtkIconView.
5539 * Returns the column with pixbufs for @icon_view.
5541 * Returns: the pixbuf column, or -1 if it's unset.
5546 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5548 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5550 return icon_view->priv->pixbuf_column;
5554 * gtk_icon_view_select_path:
5555 * @icon_view: A #GtkIconView.
5556 * @path: The #GtkTreePath to be selected.
5558 * Selects the row at @path.
5563 gtk_icon_view_select_path (GtkIconView *icon_view,
5566 GtkIconViewItem *item = NULL;
5568 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5569 g_return_if_fail (icon_view->priv->model != NULL);
5570 g_return_if_fail (path != NULL);
5572 if (gtk_tree_path_get_depth (path) > 0)
5573 item = g_list_nth_data (icon_view->priv->items,
5574 gtk_tree_path_get_indices(path)[0]);
5577 gtk_icon_view_select_item (icon_view, item);
5581 * gtk_icon_view_unselect_path:
5582 * @icon_view: A #GtkIconView.
5583 * @path: The #GtkTreePath to be unselected.
5585 * Unselects the row at @path.
5590 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5593 GtkIconViewItem *item;
5595 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5596 g_return_if_fail (icon_view->priv->model != NULL);
5597 g_return_if_fail (path != NULL);
5599 item = g_list_nth_data (icon_view->priv->items,
5600 gtk_tree_path_get_indices(path)[0]);
5605 gtk_icon_view_unselect_item (icon_view, item);
5609 * gtk_icon_view_get_selected_items:
5610 * @icon_view: A #GtkIconView.
5612 * Creates a list of paths of all selected items. Additionally, if you are
5613 * planning on modifying the model after calling this function, you may
5614 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5615 * To do this, you can use gtk_tree_row_reference_new().
5617 * To free the return value, use:
5619 * g_list_foreach (list, gtk_tree_path_free, NULL);
5620 * g_list_free (list);
5623 * Return value: A #GList containing a #GtkTreePath for each selected row.
5628 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5631 GList *selected = NULL;
5633 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5635 for (list = icon_view->priv->items; list != NULL; list = list->next)
5637 GtkIconViewItem *item = list->data;
5641 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5643 selected = g_list_prepend (selected, path);
5651 * gtk_icon_view_select_all:
5652 * @icon_view: A #GtkIconView.
5654 * Selects all the icons. @icon_view must has its selection mode set
5655 * to #GTK_SELECTION_MULTIPLE.
5660 gtk_icon_view_select_all (GtkIconView *icon_view)
5663 gboolean dirty = FALSE;
5665 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5667 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5670 for (items = icon_view->priv->items; items; items = items->next)
5672 GtkIconViewItem *item = items->data;
5674 if (!item->selected)
5677 item->selected = TRUE;
5678 gtk_icon_view_queue_draw_item (icon_view, item);
5683 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5687 * gtk_icon_view_unselect_all:
5688 * @icon_view: A #GtkIconView.
5690 * Unselects all the icons.
5695 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5697 gboolean dirty = FALSE;
5699 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5701 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5704 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5707 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5711 * gtk_icon_view_path_is_selected:
5712 * @icon_view: A #GtkIconView.
5713 * @path: A #GtkTreePath to check selection on.
5715 * Returns %TRUE if the icon pointed to by @path is currently
5716 * selected. If @path does not point to a valid location, %FALSE is returned.
5718 * Return value: %TRUE if @path is selected.
5723 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5726 GtkIconViewItem *item;
5728 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5729 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5730 g_return_val_if_fail (path != NULL, FALSE);
5732 item = g_list_nth_data (icon_view->priv->items,
5733 gtk_tree_path_get_indices(path)[0]);
5738 return item->selected;
5742 * gtk_icon_view_item_activated:
5743 * @icon_view: A #GtkIconView
5744 * @path: The #GtkTreePath to be activated
5746 * Activates the item determined by @path.
5751 gtk_icon_view_item_activated (GtkIconView *icon_view,
5754 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5755 g_return_if_fail (path != NULL);
5757 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5761 * gtk_icon_view_set_orientation:
5762 * @icon_view: a #GtkIconView
5763 * @orientation: the relative position of texts and icons
5765 * Sets the ::orientation property which determines whether the labels
5766 * are drawn beside the icons instead of below.
5771 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5772 GtkOrientation orientation)
5774 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5776 if (icon_view->priv->orientation != orientation)
5778 icon_view->priv->orientation = orientation;
5780 gtk_icon_view_stop_editing (icon_view, TRUE);
5781 gtk_icon_view_invalidate_sizes (icon_view);
5782 gtk_icon_view_queue_layout (icon_view);
5784 update_text_cell (icon_view);
5785 update_pixbuf_cell (icon_view);
5787 g_object_notify (G_OBJECT (icon_view), "orientation");
5792 * gtk_icon_view_get_orientation:
5793 * @icon_view: a #GtkIconView
5795 * Returns the value of the ::orientation property which determines
5796 * whether the labels are drawn beside the icons instead of below.
5798 * Return value: the relative position of texts and icons
5803 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5805 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5806 GTK_ORIENTATION_VERTICAL);
5808 return icon_view->priv->orientation;
5812 * gtk_icon_view_set_columns:
5813 * @icon_view: a #GtkIconView
5814 * @columns: the number of columns
5816 * Sets the ::columns property which determines in how
5817 * many columns the icons are arranged. If @columns is
5818 * -1, the number of columns will be chosen automatically
5819 * to fill the available area.
5824 gtk_icon_view_set_columns (GtkIconView *icon_view,
5827 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5829 if (icon_view->priv->columns != columns)
5831 icon_view->priv->columns = columns;
5833 gtk_icon_view_stop_editing (icon_view, TRUE);
5834 gtk_icon_view_queue_layout (icon_view);
5836 g_object_notify (G_OBJECT (icon_view), "columns");
5841 * gtk_icon_view_get_columns:
5842 * @icon_view: a #GtkIconView
5844 * Returns the value of the ::columns property.
5846 * Return value: the number of columns, or -1
5851 gtk_icon_view_get_columns (GtkIconView *icon_view)
5853 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5855 return icon_view->priv->columns;
5859 * gtk_icon_view_set_item_width:
5860 * @icon_view: a #GtkIconView
5861 * @item_width: the width for each item
5863 * Sets the ::item-width property which specifies the width
5864 * to use for each item. If it is set to -1, the icon view will
5865 * automatically determine a suitable item size.
5870 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5873 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5875 if (icon_view->priv->item_width != item_width)
5877 icon_view->priv->item_width = item_width;
5879 gtk_icon_view_stop_editing (icon_view, TRUE);
5880 gtk_icon_view_invalidate_sizes (icon_view);
5881 gtk_icon_view_queue_layout (icon_view);
5883 update_text_cell (icon_view);
5885 g_object_notify (G_OBJECT (icon_view), "item-width");
5890 * gtk_icon_view_get_item_width:
5891 * @icon_view: a #GtkIconView
5893 * Returns the value of the ::item-width property.
5895 * Return value: the width of a single item, or -1
5900 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5902 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5904 return icon_view->priv->item_width;
5909 * gtk_icon_view_set_spacing:
5910 * @icon_view: a #GtkIconView
5911 * @spacing: the spacing
5913 * Sets the ::spacing property which specifies the space
5914 * which is inserted between the cells (i.e. the icon and
5915 * the text) of an item.
5920 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5923 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5925 if (icon_view->priv->spacing != spacing)
5927 icon_view->priv->spacing = spacing;
5929 gtk_icon_view_stop_editing (icon_view, TRUE);
5930 gtk_icon_view_invalidate_sizes (icon_view);
5931 gtk_icon_view_queue_layout (icon_view);
5933 g_object_notify (G_OBJECT (icon_view), "spacing");
5938 * gtk_icon_view_get_spacing:
5939 * @icon_view: a #GtkIconView
5941 * Returns the value of the ::spacing property.
5943 * Return value: the space between cells
5948 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5950 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5952 return icon_view->priv->spacing;
5956 * gtk_icon_view_set_row_spacing:
5957 * @icon_view: a #GtkIconView
5958 * @row_spacing: the row spacing
5960 * Sets the ::row-spacing property which specifies the space
5961 * which is inserted between the rows of the icon view.
5966 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5969 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5971 if (icon_view->priv->row_spacing != row_spacing)
5973 icon_view->priv->row_spacing = row_spacing;
5975 gtk_icon_view_stop_editing (icon_view, TRUE);
5976 gtk_icon_view_invalidate_sizes (icon_view);
5977 gtk_icon_view_queue_layout (icon_view);
5979 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5984 * gtk_icon_view_get_row_spacing:
5985 * @icon_view: a #GtkIconView
5987 * Returns the value of the ::row-spacing property.
5989 * Return value: the space between rows
5994 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5996 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5998 return icon_view->priv->row_spacing;
6002 * gtk_icon_view_set_column_spacing:
6003 * @icon_view: a #GtkIconView
6004 * @column_spacing: the column spacing
6006 * Sets the ::column-spacing property which specifies the space
6007 * which is inserted between the columns of the icon view.
6012 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6013 gint column_spacing)
6015 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6017 if (icon_view->priv->column_spacing != column_spacing)
6019 icon_view->priv->column_spacing = column_spacing;
6021 gtk_icon_view_stop_editing (icon_view, TRUE);
6022 gtk_icon_view_invalidate_sizes (icon_view);
6023 gtk_icon_view_queue_layout (icon_view);
6025 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6030 * gtk_icon_view_get_column_spacing:
6031 * @icon_view: a #GtkIconView
6033 * Returns the value of the ::column-spacing property.
6035 * Return value: the space between columns
6040 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6042 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6044 return icon_view->priv->column_spacing;
6048 * gtk_icon_view_set_margin:
6049 * @icon_view: a #GtkIconView
6050 * @margin: the margin
6052 * Sets the ::margin property which specifies the space
6053 * which is inserted at the top, bottom, left and right
6059 gtk_icon_view_set_margin (GtkIconView *icon_view,
6062 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6064 if (icon_view->priv->margin != margin)
6066 icon_view->priv->margin = margin;
6068 gtk_icon_view_stop_editing (icon_view, TRUE);
6069 gtk_icon_view_invalidate_sizes (icon_view);
6070 gtk_icon_view_queue_layout (icon_view);
6072 g_object_notify (G_OBJECT (icon_view), "margin");
6077 * gtk_icon_view_get_margin:
6078 * @icon_view: a #GtkIconView
6080 * Returns the value of the ::margin property.
6082 * Return value: the space at the borders
6087 gtk_icon_view_get_margin (GtkIconView *icon_view)
6089 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6091 return icon_view->priv->margin;
6095 /* Get/set whether drag_motion requested the drag data and
6096 * drag_data_received should thus not actually insert the data,
6097 * since the data doesn't result from a drop.
6100 set_status_pending (GdkDragContext *context,
6101 GdkDragAction suggested_action)
6103 g_object_set_data (G_OBJECT (context),
6104 I_("gtk-icon-view-status-pending"),
6105 GINT_TO_POINTER (suggested_action));
6108 static GdkDragAction
6109 get_status_pending (GdkDragContext *context)
6111 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6112 "gtk-icon-view-status-pending"));
6116 unset_reorderable (GtkIconView *icon_view)
6118 if (icon_view->priv->reorderable)
6120 icon_view->priv->reorderable = FALSE;
6121 g_object_notify (G_OBJECT (icon_view), "reorderable");
6126 clear_source_info (GtkIconView *icon_view)
6128 if (icon_view->priv->source_targets)
6129 gtk_target_list_unref (icon_view->priv->source_targets);
6130 icon_view->priv->source_targets = NULL;
6132 icon_view->priv->source_set = FALSE;
6136 clear_dest_info (GtkIconView *icon_view)
6138 if (icon_view->priv->dest_targets)
6139 gtk_target_list_unref (icon_view->priv->dest_targets);
6140 icon_view->priv->dest_targets = NULL;
6142 icon_view->priv->dest_set = FALSE;
6146 set_source_row (GdkDragContext *context,
6147 GtkTreeModel *model,
6148 GtkTreePath *source_row)
6151 g_object_set_data_full (G_OBJECT (context),
6152 I_("gtk-icon-view-source-row"),
6153 gtk_tree_row_reference_new (model, source_row),
6154 (GDestroyNotify) gtk_tree_row_reference_free);
6156 g_object_set_data_full (G_OBJECT (context),
6157 I_("gtk-icon-view-source-row"),
6162 get_source_row (GdkDragContext *context)
6164 GtkTreeRowReference *ref;
6166 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6169 return gtk_tree_row_reference_get_path (ref);
6176 GtkTreeRowReference *dest_row;
6177 gboolean empty_view_drop;
6178 gboolean drop_append_mode;
6182 dest_row_free (gpointer data)
6184 DestRow *dr = (DestRow *)data;
6186 gtk_tree_row_reference_free (dr->dest_row);
6191 set_dest_row (GdkDragContext *context,
6192 GtkTreeModel *model,
6193 GtkTreePath *dest_row,
6194 gboolean empty_view_drop,
6195 gboolean drop_append_mode)
6201 g_object_set_data_full (G_OBJECT (context),
6202 I_("gtk-icon-view-dest-row"),
6207 dr = g_new0 (DestRow, 1);
6209 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6210 dr->empty_view_drop = empty_view_drop;
6211 dr->drop_append_mode = drop_append_mode;
6212 g_object_set_data_full (G_OBJECT (context),
6213 I_("gtk-icon-view-dest-row"),
6214 dr, (GDestroyNotify) dest_row_free);
6218 get_dest_row (GdkDragContext *context)
6222 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6226 GtkTreePath *path = NULL;
6229 path = gtk_tree_row_reference_get_path (dr->dest_row);
6230 else if (dr->empty_view_drop)
6231 path = gtk_tree_path_new_from_indices (0, -1);
6235 if (path && dr->drop_append_mode)
6236 gtk_tree_path_next (path);
6245 check_model_dnd (GtkTreeModel *model,
6246 GType required_iface,
6247 const gchar *signal)
6249 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6251 g_warning ("You must override the default '%s' handler "
6252 "on GtkIconView when using models that don't support "
6253 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6254 "is to connect to '%s' and call "
6255 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6256 "the default handler from running. Look at the source code "
6257 "for the default handler in gtkiconview.c to get an idea what "
6258 "your handler should do. (gtkiconview.c is in the GTK+ source "
6259 "code.) If you're using GTK+ from a language other than C, "
6260 "there may be a more natural way to override default handlers, e.g. via derivation.",
6261 signal, g_type_name (required_iface), signal);
6269 remove_scroll_timeout (GtkIconView *icon_view)
6271 if (icon_view->priv->scroll_timeout_id != 0)
6273 g_source_remove (icon_view->priv->scroll_timeout_id);
6275 icon_view->priv->scroll_timeout_id = 0;
6280 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6282 gint px, py, x, y, width, height;
6283 gint hoffset, voffset;
6285 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6286 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6288 /* see if we are near the edge. */
6289 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6291 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6293 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6295 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6298 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6299 icon_view->priv->vadjustment->value + voffset);
6302 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6303 icon_view->priv->hadjustment->value + hoffset);
6308 drag_scroll_timeout (gpointer data)
6310 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6312 gtk_icon_view_autoscroll (icon_view);
6319 set_destination (GtkIconView *icon_view,
6320 GdkDragContext *context,
6323 GdkDragAction *suggested_action,
6327 GtkTreePath *path = NULL;
6328 GtkIconViewDropPosition pos;
6329 GtkIconViewDropPosition old_pos;
6330 GtkTreePath *old_dest_path = NULL;
6331 gboolean can_drop = FALSE;
6333 widget = GTK_WIDGET (icon_view);
6335 *suggested_action = 0;
6338 if (!icon_view->priv->dest_set)
6340 /* someone unset us as a drag dest, note that if
6341 * we return FALSE drag_leave isn't called
6344 gtk_icon_view_set_drag_dest_item (icon_view,
6346 GTK_ICON_VIEW_DROP_LEFT);
6348 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6350 return FALSE; /* no longer a drop site */
6353 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6354 if (*target == GDK_NONE)
6357 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6360 GtkTreeModel *model;
6362 /* the row got dropped on empty space, let's setup a special case
6366 gtk_tree_path_free (path);
6368 model = gtk_icon_view_get_model (icon_view);
6370 n_children = gtk_tree_model_iter_n_children (model, NULL);
6373 pos = GTK_ICON_VIEW_DROP_BELOW;
6374 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6378 pos = GTK_ICON_VIEW_DROP_ABOVE;
6379 path = gtk_tree_path_new_from_indices (0, -1);
6389 gtk_icon_view_get_drag_dest_item (icon_view,
6394 gtk_tree_path_free (old_dest_path);
6396 if (TRUE /* FIXME if the location droppable predicate */)
6404 GtkWidget *source_widget;
6406 *suggested_action = context->suggested_action;
6407 source_widget = gtk_drag_get_source_widget (context);
6409 if (source_widget == widget)
6411 /* Default to MOVE, unless the user has
6412 * pressed ctrl or shift to affect available actions
6414 if ((context->actions & GDK_ACTION_MOVE) != 0)
6415 *suggested_action = GDK_ACTION_MOVE;
6418 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6423 /* can't drop here */
6424 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6426 GTK_ICON_VIEW_DROP_LEFT);
6430 gtk_tree_path_free (path);
6436 get_logical_destination (GtkIconView *icon_view,
6437 gboolean *drop_append_mode)
6439 /* adjust path to point to the row the drop goes in front of */
6440 GtkTreePath *path = NULL;
6441 GtkIconViewDropPosition pos;
6443 *drop_append_mode = FALSE;
6445 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6450 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6451 pos == GTK_ICON_VIEW_DROP_BELOW)
6454 GtkTreeModel *model = icon_view->priv->model;
6456 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6457 !gtk_tree_model_iter_next (model, &iter))
6458 *drop_append_mode = TRUE;
6461 *drop_append_mode = FALSE;
6462 gtk_tree_path_next (path);
6470 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6471 GdkEventMotion *event)
6473 GdkDragContext *context;
6474 GtkTreePath *path = NULL;
6476 GtkTreeModel *model;
6477 gboolean retval = FALSE;
6479 if (!icon_view->priv->source_set)
6482 if (icon_view->priv->pressed_button < 0)
6485 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6486 icon_view->priv->press_start_x,
6487 icon_view->priv->press_start_y,
6488 event->x, event->y))
6491 model = gtk_icon_view_get_model (icon_view);
6496 button = icon_view->priv->pressed_button;
6497 icon_view->priv->pressed_button = -1;
6499 path = gtk_icon_view_get_path_at_pos (icon_view,
6500 icon_view->priv->press_start_x,
6501 icon_view->priv->press_start_y);
6506 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6507 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6511 /* FIXME Check whether we're a start button, if not return FALSE and
6515 /* Now we can begin the drag */
6519 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6520 icon_view->priv->source_targets,
6521 icon_view->priv->source_actions,
6525 set_source_row (context, model, path);
6529 gtk_tree_path_free (path);
6534 /* Source side drag signals */
6536 gtk_icon_view_drag_begin (GtkWidget *widget,
6537 GdkDragContext *context)
6539 GtkIconView *icon_view;
6540 GtkIconViewItem *item;
6545 icon_view = GTK_ICON_VIEW (widget);
6547 /* if the user uses a custom DnD impl, we don't set the icon here */
6548 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6551 item = gtk_icon_view_get_item_at_coords (icon_view,
6552 icon_view->priv->press_start_x,
6553 icon_view->priv->press_start_y,
6557 g_return_if_fail (item != NULL);
6559 x = icon_view->priv->press_start_x - item->x + 1;
6560 y = icon_view->priv->press_start_y - item->y + 1;
6562 path = gtk_tree_path_new_from_indices (item->index, -1);
6563 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6564 gtk_tree_path_free (path);
6566 gtk_drag_set_icon_pixmap (context,
6567 gdk_drawable_get_colormap (icon),
6572 g_object_unref (icon);
6576 gtk_icon_view_drag_end (GtkWidget *widget,
6577 GdkDragContext *context)
6583 gtk_icon_view_drag_data_get (GtkWidget *widget,
6584 GdkDragContext *context,
6585 GtkSelectionData *selection_data,
6589 GtkIconView *icon_view;
6590 GtkTreeModel *model;
6591 GtkTreePath *source_row;
6593 icon_view = GTK_ICON_VIEW (widget);
6594 model = gtk_icon_view_get_model (icon_view);
6599 if (!icon_view->priv->dest_set)
6602 source_row = get_source_row (context);
6604 if (source_row == NULL)
6607 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6608 * any model; for DragSource models there are some other targets
6612 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6613 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6618 /* If drag_data_get does nothing, try providing row data. */
6619 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6620 gtk_tree_set_row_drag_data (selection_data,
6625 gtk_tree_path_free (source_row);
6629 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6630 GdkDragContext *context)
6632 GtkTreeModel *model;
6633 GtkIconView *icon_view;
6634 GtkTreePath *source_row;
6636 icon_view = GTK_ICON_VIEW (widget);
6637 model = gtk_icon_view_get_model (icon_view);
6639 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6642 if (!icon_view->priv->dest_set)
6645 source_row = get_source_row (context);
6647 if (source_row == NULL)
6650 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6653 gtk_tree_path_free (source_row);
6655 set_source_row (context, NULL, NULL);
6658 /* Target side drag signals */
6660 gtk_icon_view_drag_leave (GtkWidget *widget,
6661 GdkDragContext *context,
6664 GtkIconView *icon_view;
6666 icon_view = GTK_ICON_VIEW (widget);
6668 /* unset any highlight row */
6669 gtk_icon_view_set_drag_dest_item (icon_view,
6671 GTK_ICON_VIEW_DROP_LEFT);
6673 remove_scroll_timeout (icon_view);
6677 gtk_icon_view_drag_motion (GtkWidget *widget,
6678 GdkDragContext *context,
6683 GtkTreePath *path = NULL;
6684 GtkIconViewDropPosition pos;
6685 GtkIconView *icon_view;
6686 GdkDragAction suggested_action = 0;
6690 icon_view = GTK_ICON_VIEW (widget);
6692 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6695 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6697 /* we only know this *after* set_desination_row */
6698 empty = icon_view->priv->empty_view_drop;
6700 if (path == NULL && !empty)
6702 /* Can't drop here. */
6703 gdk_drag_status (context, 0, time);
6707 if (icon_view->priv->scroll_timeout_id == 0)
6709 icon_view->priv->scroll_timeout_id =
6710 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6713 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6715 /* Request data so we can use the source row when
6716 * determining whether to accept the drop
6718 set_status_pending (context, suggested_action);
6719 gtk_drag_get_data (widget, context, target, time);
6723 set_status_pending (context, 0);
6724 gdk_drag_status (context, suggested_action, time);
6729 gtk_tree_path_free (path);
6735 gtk_icon_view_drag_drop (GtkWidget *widget,
6736 GdkDragContext *context,
6741 GtkIconView *icon_view;
6743 GdkDragAction suggested_action = 0;
6744 GdkAtom target = GDK_NONE;
6745 GtkTreeModel *model;
6746 gboolean drop_append_mode;
6748 icon_view = GTK_ICON_VIEW (widget);
6749 model = gtk_icon_view_get_model (icon_view);
6751 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6753 if (!icon_view->priv->dest_set)
6756 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6759 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6762 path = get_logical_destination (icon_view, &drop_append_mode);
6764 if (target != GDK_NONE && path != NULL)
6766 /* in case a motion had requested drag data, change things so we
6767 * treat drag data receives as a drop.
6769 set_status_pending (context, 0);
6770 set_dest_row (context, model, path,
6771 icon_view->priv->empty_view_drop, drop_append_mode);
6775 gtk_tree_path_free (path);
6777 /* Unset this thing */
6778 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6780 if (target != GDK_NONE)
6782 gtk_drag_get_data (widget, context, target, time);
6790 gtk_icon_view_drag_data_received (GtkWidget *widget,
6791 GdkDragContext *context,
6794 GtkSelectionData *selection_data,
6799 gboolean accepted = FALSE;
6800 GtkTreeModel *model;
6801 GtkIconView *icon_view;
6802 GtkTreePath *dest_row;
6803 GdkDragAction suggested_action;
6804 gboolean drop_append_mode;
6806 icon_view = GTK_ICON_VIEW (widget);
6807 model = gtk_icon_view_get_model (icon_view);
6809 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6812 if (!icon_view->priv->dest_set)
6815 suggested_action = get_status_pending (context);
6817 if (suggested_action)
6819 /* We are getting this data due to a request in drag_motion,
6820 * rather than due to a request in drag_drop, so we are just
6821 * supposed to call drag_status, not actually paste in the
6824 path = get_logical_destination (icon_view, &drop_append_mode);
6827 suggested_action = 0;
6829 if (suggested_action)
6831 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6834 suggested_action = 0;
6837 gdk_drag_status (context, suggested_action, time);
6840 gtk_tree_path_free (path);
6842 /* If you can't drop, remove user drop indicator until the next motion */
6843 if (suggested_action == 0)
6844 gtk_icon_view_set_drag_dest_item (icon_view,
6846 GTK_ICON_VIEW_DROP_LEFT);
6851 dest_row = get_dest_row (context);
6853 if (dest_row == NULL)
6856 if (selection_data->length >= 0)
6858 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6864 gtk_drag_finish (context,
6866 (context->action == GDK_ACTION_MOVE),
6869 gtk_tree_path_free (dest_row);
6872 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6875 /* Drag-and-Drop support */
6877 * gtk_icon_view_enable_model_drag_source:
6878 * @icon_view: a #GtkIconTreeView
6879 * @start_button_mask: Mask of allowed buttons to start drag
6880 * @targets: the table of targets that the drag will support
6881 * @n_targets: the number of items in @targets
6882 * @actions: the bitmask of possible actions for a drag from this
6885 * Turns @icon_view into a drag source for automatic DND.
6890 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6891 GdkModifierType start_button_mask,
6892 const GtkTargetEntry *targets,
6894 GdkDragAction actions)
6896 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6898 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6900 clear_source_info (icon_view);
6901 icon_view->priv->start_button_mask = start_button_mask;
6902 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6903 icon_view->priv->source_actions = actions;
6905 icon_view->priv->source_set = TRUE;
6907 unset_reorderable (icon_view);
6911 * gtk_icon_view_enable_model_drag_dest:
6912 * @icon_view: a #GtkIconView
6913 * @targets: the table of targets that the drag will support
6914 * @n_targets: the number of items in @targets
6915 * @actions: the bitmask of possible actions for a drag to this
6918 * Turns @icon_view into a drop destination for automatic DND.
6923 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6924 const GtkTargetEntry *targets,
6926 GdkDragAction actions)
6928 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6930 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6932 clear_dest_info (icon_view);
6934 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6935 icon_view->priv->dest_actions = actions;
6937 icon_view->priv->dest_set = TRUE;
6939 unset_reorderable (icon_view);
6943 * gtk_icon_view_unset_model_drag_source:
6944 * @icon_view: a #GtkIconView
6946 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6951 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6953 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6955 if (icon_view->priv->source_set)
6957 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6958 clear_source_info (icon_view);
6961 unset_reorderable (icon_view);
6965 * gtk_icon_view_unset_model_drag_dest:
6966 * @icon_view: a #GtkIconView
6968 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6973 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6975 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6977 if (icon_view->priv->dest_set)
6979 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6980 clear_dest_info (icon_view);
6983 unset_reorderable (icon_view);
6986 /* These are useful to implement your own custom stuff. */
6988 * gtk_icon_view_set_drag_dest_item:
6989 * @icon_view: a #GtkIconView
6990 * @path: The path of the item to highlight, or %NULL.
6991 * @pos: Specifies where to drop, relative to the item
6993 * Sets the item that is highlighted for feedback.
6998 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7000 GtkIconViewDropPosition pos)
7002 /* Note; this function is exported to allow a custom DND
7003 * implementation, so it can't touch TreeViewDragInfo
7006 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7008 if (icon_view->priv->dest_item)
7010 GtkTreePath *current_path;
7011 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7012 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7013 icon_view->priv->dest_item = NULL;
7015 gtk_icon_view_queue_draw_path (icon_view, current_path);
7016 gtk_tree_path_free (current_path);
7019 /* special case a drop on an empty model */
7020 icon_view->priv->empty_view_drop = FALSE;
7021 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7022 && gtk_tree_path_get_depth (path) == 1
7023 && gtk_tree_path_get_indices (path)[0] == 0)
7027 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7030 if (n_children == 0)
7031 icon_view->priv->empty_view_drop = TRUE;
7034 icon_view->priv->dest_pos = pos;
7038 icon_view->priv->dest_item =
7039 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7040 icon_view->priv->model, path);
7042 gtk_icon_view_queue_draw_path (icon_view, path);
7047 * gtk_icon_view_get_drag_dest_item:
7048 * @icon_view: a #GtkIconView
7049 * @path: Return location for the path of the highlighted item, or %NULL.
7050 * @pos: Return location for the drop position, or %NULL
7052 * Gets information about the item that is highlighted for feedback.
7057 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7059 GtkIconViewDropPosition *pos)
7061 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7065 if (icon_view->priv->dest_item)
7066 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7072 *pos = icon_view->priv->dest_pos;
7076 * gtk_icon_view_get_dest_item_at_pos:
7077 * @icon_view: a #GtkIconView
7078 * @drag_x: the position to determine the destination item for
7079 * @drag_y: the position to determine the destination item for
7080 * @path: Return location for the path of the item, or %NULL.
7081 * @pos: Return location for the drop position, or %NULL
7083 * Determines the destination item for a given position.
7085 * Return value: whether there is an item at the given position.
7090 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7094 GtkIconViewDropPosition *pos)
7096 GtkIconViewItem *item;
7098 /* Note; this function is exported to allow a custom DND
7099 * implementation, so it can't touch TreeViewDragInfo
7102 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7103 g_return_val_if_fail (drag_x >= 0, FALSE);
7104 g_return_val_if_fail (drag_y >= 0, FALSE);
7105 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7111 item = gtk_icon_view_get_item_at_coords (icon_view,
7112 drag_x + icon_view->priv->hadjustment->value,
7113 drag_y + icon_view->priv->vadjustment->value,
7120 *path = gtk_tree_path_new_from_indices (item->index, -1);
7124 if (drag_x < item->x + item->width / 4)
7125 *pos = GTK_ICON_VIEW_DROP_LEFT;
7126 else if (drag_x > item->x + item->width * 3 / 4)
7127 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7128 else if (drag_y < item->y + item->height / 4)
7129 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7130 else if (drag_y > item->y + item->height * 3 / 4)
7131 *pos = GTK_ICON_VIEW_DROP_BELOW;
7133 *pos = GTK_ICON_VIEW_DROP_INTO;
7140 * gtk_icon_view_create_drag_icon:
7141 * @icon_view: a #GtkIconView
7142 * @path: a #GtkTreePath in @icon_view
7144 * Creates a #GdkPixmap representation of the item at @path.
7145 * This image is used for a drag icon.
7147 * Return value: a newly-allocated pixmap of the drag icon.
7152 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7157 GdkPixmap *drawable;
7162 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7163 g_return_val_if_fail (path != NULL, NULL);
7165 widget = GTK_WIDGET (icon_view);
7167 if (!GTK_WIDGET_REALIZED (widget))
7170 index = gtk_tree_path_get_indices (path)[0];
7172 for (l = icon_view->priv->items; l; l = l->next)
7174 GtkIconViewItem *item = l->data;
7176 if (index == item->index)
7178 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7183 cr = gdk_cairo_create (drawable);
7184 cairo_set_line_width (cr, 1.);
7186 gdk_cairo_set_source_color
7187 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7188 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7193 area.width = item->width;
7194 area.height = item->height;
7196 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7197 drawable, 1, 1, FALSE);
7199 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7200 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7213 * gtk_icon_view_get_reorderable:
7214 * @icon_view: a #GtkIconView
7216 * Retrieves whether the user can reorder the list via drag-and-drop.
7217 * See gtk_icon_view_set_reorderable().
7219 * Return value: %TRUE if the list can be reordered.
7224 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7226 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7228 return icon_view->priv->reorderable;
7231 static const GtkTargetEntry item_targets[] = {
7232 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7237 * gtk_icon_view_set_reorderable:
7238 * @icon_view: A #GtkIconView.
7239 * @reorderable: %TRUE, if the list of items can be reordered.
7241 * This function is a convenience function to allow you to reorder models that
7242 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7243 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7244 * the user can reorder the model by dragging and dropping rows. The
7245 * developer can listen to these changes by connecting to the model's
7246 * row_inserted and row_deleted signals.
7248 * This function does not give you any degree of control over the order -- any
7249 * reordering is allowed. If more control is needed, you should probably
7250 * handle drag and drop manually.
7255 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7256 gboolean reorderable)
7258 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7260 reorderable = reorderable != FALSE;
7262 if (icon_view->priv->reorderable == reorderable)
7267 gtk_icon_view_enable_model_drag_source (icon_view,
7270 G_N_ELEMENTS (item_targets),
7272 gtk_icon_view_enable_model_drag_dest (icon_view,
7274 G_N_ELEMENTS (item_targets),
7279 gtk_icon_view_unset_model_drag_source (icon_view);
7280 gtk_icon_view_unset_model_drag_dest (icon_view);
7283 icon_view->priv->reorderable = reorderable;
7285 g_object_notify (G_OBJECT (icon_view), "reorderable");
7289 /* Accessibility Support */
7291 static gpointer accessible_parent_class;
7292 static gpointer accessible_item_parent_class;
7293 static GQuark accessible_private_data_quark = 0;
7295 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7296 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7297 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7299 static GType gtk_icon_view_item_accessible_get_type (void);
7310 GtkIconViewItem *item;
7314 AtkStateSet *state_set;
7318 GtkTextBuffer *text_buffer;
7320 gchar *action_descriptions[LAST_ACTION];
7321 gchar *image_description;
7322 guint action_idle_handler;
7323 } GtkIconViewItemAccessible;
7325 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7331 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7336 typedef struct _GtkIconViewItemAccessibleClass
7338 AtkObjectClass parent_class;
7340 } GtkIconViewItemAccessibleClass;
7342 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7345 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7347 GtkIconViewItemAccessible *item;
7348 GtkIconView *icon_view;
7351 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7352 item->action_idle_handler = 0;
7354 if (item->widget != NULL)
7356 icon_view = GTK_ICON_VIEW (item->widget);
7357 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7358 gtk_icon_view_item_activated (icon_view, path);
7359 gtk_tree_path_free (path);
7366 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7369 GtkIconViewItemAccessible *item;
7371 if (i < 0 || i >= LAST_ACTION)
7374 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7376 if (!GTK_IS_ICON_VIEW (item->widget))
7379 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7384 case ACTION_ACTIVATE:
7385 if (!item->action_idle_handler)
7386 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7389 g_assert_not_reached ();
7397 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7402 static const gchar *
7403 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7406 GtkIconViewItemAccessible *item;
7408 if (i < 0 || i >= LAST_ACTION)
7411 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7413 if (item->action_descriptions[i])
7414 return item->action_descriptions[i];
7416 return gtk_icon_view_item_accessible_action_descriptions[i];
7419 static const gchar *
7420 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7423 if (i < 0 || i >= LAST_ACTION)
7426 return gtk_icon_view_item_accessible_action_names[i];
7430 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7432 const gchar *description)
7434 GtkIconViewItemAccessible *item;
7436 if (i < 0 || i >= LAST_ACTION)
7439 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7441 g_free (item->action_descriptions[i]);
7443 item->action_descriptions[i] = g_strdup (description);
7449 atk_action_item_interface_init (AtkActionIface *iface)
7451 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7452 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7453 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7454 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7455 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7458 static const gchar *
7459 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7461 GtkIconViewItemAccessible *item;
7463 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7465 return item->image_description;
7469 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7470 const gchar *description)
7472 GtkIconViewItemAccessible *item;
7474 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7476 g_free (item->image_description);
7477 item->image_description = g_strdup (item->image_description);
7483 get_pixbuf_box (GtkIconView *icon_view,
7484 GtkIconViewItem *item,
7489 for (l = icon_view->priv->cell_list; l; l = l->next)
7491 GtkIconViewCellInfo *info = l->data;
7493 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7495 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7505 get_text (GtkIconView *icon_view,
7506 GtkIconViewItem *item)
7511 for (l = icon_view->priv->cell_list; l; l = l->next)
7513 GtkIconViewCellInfo *info = l->data;
7515 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7517 g_object_get (info->cell, "text", &text, NULL);
7527 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7531 GtkIconViewItemAccessible *item;
7534 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7536 if (!GTK_IS_ICON_VIEW (item->widget))
7539 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7542 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7545 *height = box.height;
7550 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7553 AtkCoordType coord_type)
7555 GtkIconViewItemAccessible *item;
7558 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7560 if (!GTK_IS_ICON_VIEW (item->widget))
7563 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7566 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7568 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7570 *x+= box.x - item->item->x;
7571 *y+= box.y - item->item->y;
7577 atk_image_item_interface_init (AtkImageIface *iface)
7579 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7580 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7581 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7582 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7586 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7590 GtkIconViewItemAccessible *item;
7591 GtkTextIter start, end;
7592 GtkTextBuffer *buffer;
7594 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7596 if (!GTK_IS_ICON_VIEW (item->widget))
7599 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7602 buffer = item->text_buffer;
7603 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7605 gtk_text_buffer_get_end_iter (buffer, &end);
7607 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7609 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7613 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7616 GtkIconViewItemAccessible *item;
7617 GtkTextIter start, end;
7618 GtkTextBuffer *buffer;
7622 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7624 if (!GTK_IS_ICON_VIEW (item->widget))
7627 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7630 buffer = item->text_buffer;
7631 if (offset >= gtk_text_buffer_get_char_count (buffer))
7634 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7636 gtk_text_iter_forward_char (&end);
7637 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7638 unichar = g_utf8_get_char (string);
7646 get_pango_text_offsets (PangoLayout *layout,
7647 GtkTextBuffer *buffer,
7649 AtkTextBoundary boundary_type,
7653 GtkTextIter *start_iter,
7654 GtkTextIter *end_iter)
7656 PangoLayoutIter *iter;
7657 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7658 gint index, start_index, end_index;
7660 gboolean found = FALSE;
7662 text = pango_layout_get_text (layout);
7663 index = g_utf8_offset_to_pointer (text, offset) - text;
7664 iter = pango_layout_get_iter (layout);
7667 line = pango_layout_iter_get_line_readonly (iter);
7668 start_index = line->start_index;
7669 end_index = start_index + line->length;
7671 if (index >= start_index && index <= end_index)
7674 * Found line for offset
7680 * We want the previous line
7684 switch (boundary_type)
7686 case ATK_TEXT_BOUNDARY_LINE_START:
7687 end_index = start_index;
7688 start_index = prev_line->start_index;
7690 case ATK_TEXT_BOUNDARY_LINE_END:
7692 start_index = prev_prev_line->start_index +
7693 prev_prev_line->length;
7694 end_index = prev_line->start_index + prev_line->length;
7697 g_assert_not_reached();
7701 start_index = end_index = 0;
7704 switch (boundary_type)
7706 case ATK_TEXT_BOUNDARY_LINE_START:
7707 if (pango_layout_iter_next_line (iter))
7708 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7710 case ATK_TEXT_BOUNDARY_LINE_END:
7712 start_index = prev_line->start_index +
7716 g_assert_not_reached();
7721 * We want the next line
7723 if (pango_layout_iter_next_line (iter))
7725 line = pango_layout_iter_get_line_readonly (iter);
7726 switch (boundary_type)
7728 case ATK_TEXT_BOUNDARY_LINE_START:
7729 start_index = line->start_index;
7730 if (pango_layout_iter_next_line (iter))
7731 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7733 end_index = start_index + line->length;
7735 case ATK_TEXT_BOUNDARY_LINE_END:
7736 start_index = end_index;
7737 end_index = line->start_index + line->length;
7740 g_assert_not_reached();
7744 start_index = end_index;
7750 prev_prev_line = prev_line;
7753 while (pango_layout_iter_next_line (iter));
7757 start_index = prev_line->start_index + prev_line->length;
7758 end_index = start_index;
7760 pango_layout_iter_free (iter);
7761 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7762 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7764 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7765 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7770 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7772 AtkTextBoundary boundary_type,
7776 GtkIconViewItemAccessible *item;
7777 GtkTextIter start, end;
7778 GtkTextBuffer *buffer;
7780 GtkIconView *icon_view;
7783 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7785 if (!GTK_IS_ICON_VIEW (item->widget))
7788 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7791 buffer = item->text_buffer;
7793 if (!gtk_text_buffer_get_char_count (buffer))
7797 return g_strdup ("");
7799 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7803 switch (boundary_type)
7805 case ATK_TEXT_BOUNDARY_CHAR:
7806 gtk_text_iter_backward_char(&start);
7808 case ATK_TEXT_BOUNDARY_WORD_START:
7809 if (!gtk_text_iter_starts_word (&start))
7810 gtk_text_iter_backward_word_start (&start);
7812 gtk_text_iter_backward_word_start(&start);
7814 case ATK_TEXT_BOUNDARY_WORD_END:
7815 if (gtk_text_iter_inside_word (&start) &&
7816 !gtk_text_iter_starts_word (&start))
7817 gtk_text_iter_backward_word_start (&start);
7818 while (!gtk_text_iter_ends_word (&start))
7820 if (!gtk_text_iter_backward_char (&start))
7824 gtk_text_iter_backward_word_start(&start);
7825 while (!gtk_text_iter_ends_word (&start))
7827 if (!gtk_text_iter_backward_char (&start))
7831 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7832 if (!gtk_text_iter_starts_sentence (&start))
7833 gtk_text_iter_backward_sentence_start (&start);
7835 gtk_text_iter_backward_sentence_start (&start);
7837 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7838 if (gtk_text_iter_inside_sentence (&start) &&
7839 !gtk_text_iter_starts_sentence (&start))
7840 gtk_text_iter_backward_sentence_start (&start);
7841 while (!gtk_text_iter_ends_sentence (&start))
7843 if (!gtk_text_iter_backward_char (&start))
7847 gtk_text_iter_backward_sentence_start (&start);
7848 while (!gtk_text_iter_ends_sentence (&start))
7850 if (!gtk_text_iter_backward_char (&start))
7854 case ATK_TEXT_BOUNDARY_LINE_START:
7855 case ATK_TEXT_BOUNDARY_LINE_END:
7857 icon_view = GTK_ICON_VIEW (item->widget);
7858 /* FIXME we probably have to use GailTextCell to salvage this */
7859 gtk_icon_view_update_item_text (icon_view, item->item);
7860 get_pango_text_offsets (icon_view->priv->layout,
7873 *start_offset = gtk_text_iter_get_offset (&start);
7874 *end_offset = gtk_text_iter_get_offset (&end);
7876 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7880 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7882 AtkTextBoundary boundary_type,
7886 GtkIconViewItemAccessible *item;
7887 GtkTextIter start, end;
7888 GtkTextBuffer *buffer;
7890 GtkIconView *icon_view;
7893 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7895 if (!GTK_IS_ICON_VIEW (item->widget))
7898 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7901 buffer = item->text_buffer;
7903 if (!gtk_text_buffer_get_char_count (buffer))
7907 return g_strdup ("");
7909 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7913 switch (boundary_type)
7915 case ATK_TEXT_BOUNDARY_CHAR:
7916 gtk_text_iter_forward_char (&end);
7918 case ATK_TEXT_BOUNDARY_WORD_START:
7919 if (!gtk_text_iter_starts_word (&start))
7920 gtk_text_iter_backward_word_start (&start);
7921 if (gtk_text_iter_inside_word (&end))
7922 gtk_text_iter_forward_word_end (&end);
7923 while (!gtk_text_iter_starts_word (&end))
7925 if (!gtk_text_iter_forward_char (&end))
7929 case ATK_TEXT_BOUNDARY_WORD_END:
7930 if (gtk_text_iter_inside_word (&start) &&
7931 !gtk_text_iter_starts_word (&start))
7932 gtk_text_iter_backward_word_start (&start);
7933 while (!gtk_text_iter_ends_word (&start))
7935 if (!gtk_text_iter_backward_char (&start))
7938 gtk_text_iter_forward_word_end (&end);
7940 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7941 if (!gtk_text_iter_starts_sentence (&start))
7942 gtk_text_iter_backward_sentence_start (&start);
7943 if (gtk_text_iter_inside_sentence (&end))
7944 gtk_text_iter_forward_sentence_end (&end);
7945 while (!gtk_text_iter_starts_sentence (&end))
7947 if (!gtk_text_iter_forward_char (&end))
7951 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7952 if (gtk_text_iter_inside_sentence (&start) &&
7953 !gtk_text_iter_starts_sentence (&start))
7954 gtk_text_iter_backward_sentence_start (&start);
7955 while (!gtk_text_iter_ends_sentence (&start))
7957 if (!gtk_text_iter_backward_char (&start))
7960 gtk_text_iter_forward_sentence_end (&end);
7962 case ATK_TEXT_BOUNDARY_LINE_START:
7963 case ATK_TEXT_BOUNDARY_LINE_END:
7965 icon_view = GTK_ICON_VIEW (item->widget);
7966 /* FIXME we probably have to use GailTextCell to salvage this */
7967 gtk_icon_view_update_item_text (icon_view, item->item);
7968 get_pango_text_offsets (icon_view->priv->layout,
7982 *start_offset = gtk_text_iter_get_offset (&start);
7983 *end_offset = gtk_text_iter_get_offset (&end);
7985 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7989 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7991 AtkTextBoundary boundary_type,
7995 GtkIconViewItemAccessible *item;
7996 GtkTextIter start, end;
7997 GtkTextBuffer *buffer;
7999 GtkIconView *icon_view;
8002 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8004 if (!GTK_IS_ICON_VIEW (item->widget))
8007 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8010 buffer = item->text_buffer;
8012 if (!gtk_text_buffer_get_char_count (buffer))
8016 return g_strdup ("");
8018 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8022 switch (boundary_type)
8024 case ATK_TEXT_BOUNDARY_CHAR:
8025 gtk_text_iter_forward_char(&start);
8026 gtk_text_iter_forward_chars(&end, 2);
8028 case ATK_TEXT_BOUNDARY_WORD_START:
8029 if (gtk_text_iter_inside_word (&end))
8030 gtk_text_iter_forward_word_end (&end);
8031 while (!gtk_text_iter_starts_word (&end))
8033 if (!gtk_text_iter_forward_char (&end))
8037 if (!gtk_text_iter_is_end (&end))
8039 gtk_text_iter_forward_word_end (&end);
8040 while (!gtk_text_iter_starts_word (&end))
8042 if (!gtk_text_iter_forward_char (&end))
8047 case ATK_TEXT_BOUNDARY_WORD_END:
8048 gtk_text_iter_forward_word_end (&end);
8050 if (!gtk_text_iter_is_end (&end))
8051 gtk_text_iter_forward_word_end (&end);
8053 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8054 if (gtk_text_iter_inside_sentence (&end))
8055 gtk_text_iter_forward_sentence_end (&end);
8056 while (!gtk_text_iter_starts_sentence (&end))
8058 if (!gtk_text_iter_forward_char (&end))
8062 if (!gtk_text_iter_is_end (&end))
8064 gtk_text_iter_forward_sentence_end (&end);
8065 while (!gtk_text_iter_starts_sentence (&end))
8067 if (!gtk_text_iter_forward_char (&end))
8072 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8073 gtk_text_iter_forward_sentence_end (&end);
8075 if (!gtk_text_iter_is_end (&end))
8076 gtk_text_iter_forward_sentence_end (&end);
8078 case ATK_TEXT_BOUNDARY_LINE_START:
8079 case ATK_TEXT_BOUNDARY_LINE_END:
8081 icon_view = GTK_ICON_VIEW (item->widget);
8082 /* FIXME we probably have to use GailTextCell to salvage this */
8083 gtk_icon_view_update_item_text (icon_view, item->item);
8084 get_pango_text_offsets (icon_view->priv->layout,
8096 *start_offset = gtk_text_iter_get_offset (&start);
8097 *end_offset = gtk_text_iter_get_offset (&end);
8099 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8103 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8105 GtkIconViewItemAccessible *item;
8107 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8109 if (!GTK_IS_ICON_VIEW (item->widget))
8112 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8115 return gtk_text_buffer_get_char_count (item->text_buffer);
8119 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8125 AtkCoordType coord_type)
8127 GtkIconViewItemAccessible *item;
8129 GtkIconView *icon_view;
8130 PangoRectangle char_rect;
8131 const gchar *item_text;
8135 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8137 if (!GTK_IS_ICON_VIEW (item->widget))
8140 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8144 icon_view = GTK_ICON_VIEW (item->widget);
8145 /* FIXME we probably have to use GailTextCell to salvage this */
8146 gtk_icon_view_update_item_text (icon_view, item->item);
8147 item_text = pango_layout_get_text (icon_view->priv->layout);
8148 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8149 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8151 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8152 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8153 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8154 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8155 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8156 *width = char_rect.width / PANGO_SCALE;
8157 *height = char_rect.height / PANGO_SCALE;
8162 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8165 AtkCoordType coord_type)
8167 GtkIconViewItemAccessible *item;
8170 GtkIconView *icon_view;
8171 const gchar *item_text;
8176 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8178 if (!GTK_IS_ICON_VIEW (item->widget))
8181 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8185 icon_view = GTK_ICON_VIEW (item->widget);
8186 /* FIXME we probably have to use GailTextCell to salvage this */
8187 gtk_icon_view_update_item_text (icon_view, item->item);
8188 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8189 x -= l_x + item->item->layout_x - item->item->x;
8190 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8191 y -= l_y + item->item->layout_y - item->item->y;
8192 item_text = pango_layout_get_text (icon_view->priv->layout);
8193 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8204 offset = g_utf8_strlen (item_text, -1);
8206 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8212 atk_text_item_interface_init (AtkTextIface *iface)
8214 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8215 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8216 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8217 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8218 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8219 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8220 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8221 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8225 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8230 AtkCoordType coord_type)
8232 GtkIconViewItemAccessible *item;
8233 AtkObject *parent_obj;
8236 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8238 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8239 if (!GTK_IS_WIDGET (item->widget))
8242 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8245 *width = item->item->width;
8246 *height = item->item->height;
8247 if (gtk_icon_view_item_accessible_is_showing (item))
8249 parent_obj = gtk_widget_get_accessible (item->widget);
8250 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8251 *x = l_x + item->item->x;
8252 *y = l_y + item->item->y;
8262 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8264 GtkIconViewItemAccessible *item;
8265 GtkWidget *toplevel;
8267 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8269 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8270 if (!GTK_IS_WIDGET (item->widget))
8273 gtk_widget_grab_focus (item->widget);
8274 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8275 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8276 if (GTK_WIDGET_TOPLEVEL (toplevel))
8277 gtk_window_present (GTK_WINDOW (toplevel));
8283 atk_component_item_interface_init (AtkComponentIface *iface)
8285 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8286 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8290 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8291 AtkStateType state_type,
8292 gboolean emit_signal)
8296 rc = atk_state_set_add_state (item->state_set, state_type);
8298 * The signal should only be generated if the value changed,
8299 * not when the item is set up. So states that are set
8300 * initially should pass FALSE as the emit_signal argument.
8305 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8306 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8307 if (state_type == ATK_STATE_VISIBLE)
8308 g_signal_emit_by_name (item, "visible_data_changed");
8315 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8316 AtkStateType state_type,
8317 gboolean emit_signal)
8319 if (atk_state_set_contains_state (item->state_set, state_type))
8323 rc = atk_state_set_remove_state (item->state_set, state_type);
8325 * The signal should only be generated if the value changed,
8326 * not when the item is set up. So states that are set
8327 * initially should pass FALSE as the emit_signal argument.
8332 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8333 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8334 if (state_type == ATK_STATE_VISIBLE)
8335 g_signal_emit_by_name (item, "visible_data_changed");
8345 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8347 GtkIconView *icon_view;
8348 GdkRectangle visible_rect;
8349 gboolean is_showing;
8352 * An item is considered "SHOWING" if any part of the item is in the
8353 * visible rectangle.
8356 if (!GTK_IS_ICON_VIEW (item->widget))
8359 if (item->item == NULL)
8362 icon_view = GTK_ICON_VIEW (item->widget);
8364 if (icon_view->priv->hadjustment)
8365 visible_rect.x += icon_view->priv->hadjustment->value;
8367 if (icon_view->priv->hadjustment)
8368 visible_rect.y += icon_view->priv->vadjustment->value;
8369 visible_rect.width = item->widget->allocation.width;
8370 visible_rect.height = item->widget->allocation.height;
8372 if (((item->item->x + item->item->width) < visible_rect.x) ||
8373 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8374 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8375 (item->item->y > (visible_rect.y + visible_rect.height)))
8384 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8385 gboolean emit_signal)
8387 if (gtk_icon_view_item_accessible_is_showing (item))
8388 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8391 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8396 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8400 item->state_set = atk_state_set_new ();
8402 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8403 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8404 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8405 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8406 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8408 for (i = 0; i < LAST_ACTION; i++)
8409 item->action_descriptions[i] = NULL;
8411 item->image_description = NULL;
8413 item->action_idle_handler = 0;
8417 gtk_icon_view_item_accessible_finalize (GObject *object)
8419 GtkIconViewItemAccessible *item;
8422 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8424 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8427 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8429 if (item->state_set)
8430 g_object_unref (item->state_set);
8432 if (item->text_buffer)
8433 g_object_unref (item->text_buffer);
8435 for (i = 0; i < LAST_ACTION; i++)
8436 g_free (item->action_descriptions[i]);
8438 g_free (item->image_description);
8440 if (item->action_idle_handler)
8442 g_source_remove (item->action_idle_handler);
8443 item->action_idle_handler = 0;
8446 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8449 static G_CONST_RETURN gchar*
8450 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8456 GtkIconViewItemAccessible *item;
8457 GtkTextIter start_iter;
8458 GtkTextIter end_iter;
8460 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8462 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8463 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8465 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8470 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8472 GtkIconViewItemAccessible *item;
8474 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8475 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8478 return gtk_widget_get_accessible (item->widget);
8484 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8486 GtkIconViewItemAccessible *item;
8488 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8489 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8491 return item->item->index;
8494 static AtkStateSet *
8495 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8497 GtkIconViewItemAccessible *item;
8498 GtkIconView *icon_view;
8500 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8501 g_return_val_if_fail (item->state_set, NULL);
8506 icon_view = GTK_ICON_VIEW (item->widget);
8507 if (icon_view->priv->cursor_item == item->item)
8508 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8510 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8511 if (item->item->selected)
8512 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8514 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8516 return g_object_ref (item->state_set);
8520 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8522 GObjectClass *gobject_class;
8524 accessible_item_parent_class = g_type_class_peek_parent (klass);
8526 gobject_class = (GObjectClass *)klass;
8528 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8530 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8531 klass->get_name = gtk_icon_view_item_accessible_get_name;
8532 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8533 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8537 gtk_icon_view_item_accessible_get_type (void)
8539 static GType type = 0;
8543 const GTypeInfo tinfo =
8545 sizeof (GtkIconViewItemAccessibleClass),
8546 (GBaseInitFunc) NULL, /* base init */
8547 (GBaseFinalizeFunc) NULL, /* base finalize */
8548 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8549 (GClassFinalizeFunc) NULL, /* class finalize */
8550 NULL, /* class data */
8551 sizeof (GtkIconViewItemAccessible), /* instance size */
8552 0, /* nb preallocs */
8553 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8554 NULL /* value table */
8557 static const GInterfaceInfo atk_component_info =
8559 (GInterfaceInitFunc) atk_component_item_interface_init,
8560 (GInterfaceFinalizeFunc) NULL,
8563 static const GInterfaceInfo atk_action_info =
8565 (GInterfaceInitFunc) atk_action_item_interface_init,
8566 (GInterfaceFinalizeFunc) NULL,
8569 static const GInterfaceInfo atk_image_info =
8571 (GInterfaceInitFunc) atk_image_item_interface_init,
8572 (GInterfaceFinalizeFunc) NULL,
8575 static const GInterfaceInfo atk_text_info =
8577 (GInterfaceInitFunc) atk_text_item_interface_init,
8578 (GInterfaceFinalizeFunc) NULL,
8582 type = g_type_register_static (ATK_TYPE_OBJECT,
8583 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8584 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8585 &atk_component_info);
8586 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8588 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8590 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8597 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8598 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8599 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8601 static GType gtk_icon_view_accessible_get_type (void);
8606 } GtkIconViewAccessible;
8612 } GtkIconViewItemAccessibleInfo;
8618 GtkAdjustment *old_hadj;
8619 GtkAdjustment *old_vadj;
8621 GtkTreeModel *model;
8623 } GtkIconViewAccessiblePrivate;
8625 static GtkIconViewAccessiblePrivate *
8626 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8628 return g_object_get_qdata (G_OBJECT (accessible),
8629 accessible_private_data_quark);
8633 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8637 GtkIconViewItemAccessibleInfo *info;
8638 GtkIconViewItemAccessibleInfo *tmp_info;
8639 GtkIconViewAccessiblePrivate *priv;
8642 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8644 info->index = index;
8646 priv = gtk_icon_view_accessible_get_priv (accessible);
8647 items = priv->items;
8650 tmp_info = items->data;
8651 if (tmp_info->index > index)
8653 items = items->next;
8655 priv->items = g_list_insert_before (priv->items, items, info);
8656 priv->old_hadj = NULL;
8657 priv->old_vadj = NULL;
8661 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8663 GtkIconView *icon_view;
8666 widget = GTK_ACCESSIBLE (accessible)->widget;
8670 icon_view = GTK_ICON_VIEW (widget);
8672 return g_list_length (icon_view->priv->items);
8676 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8679 GtkIconViewAccessiblePrivate *priv;
8680 GtkIconViewItemAccessibleInfo *info;
8683 priv = gtk_icon_view_accessible_get_priv (accessible);
8684 items = priv->items;
8689 if (info->index == index)
8691 items = items->next;
8697 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8700 GtkIconView *icon_view;
8704 GtkIconViewItemAccessible *a11y_item;
8706 widget = GTK_ACCESSIBLE (accessible)->widget;
8710 icon_view = GTK_ICON_VIEW (widget);
8711 icons = g_list_nth (icon_view->priv->items, index);
8715 GtkIconViewItem *item = icons->data;
8717 g_return_val_if_fail (item->index == index, NULL);
8718 obj = gtk_icon_view_accessible_find_child (accessible, index);
8723 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8724 gtk_icon_view_item_accessible_info_new (accessible,
8727 obj->role = ATK_ROLE_ICON;
8728 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8729 a11y_item->item = item;
8730 a11y_item->widget = widget;
8731 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8733 gtk_icon_view_set_cell_data (icon_view, item);
8734 text = get_text (icon_view, item);
8737 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8741 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8742 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8750 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8753 GtkIconViewAccessiblePrivate *priv;
8754 GtkIconViewItemAccessibleInfo *info;
8755 GtkIconViewItemAccessible *item;
8758 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8762 gboolean act_on_item;
8764 widget = GTK_ACCESSIBLE (view)->widget;
8768 items = priv->items;
8770 act_on_item = (list == NULL);
8775 info = (GtkIconViewItemAccessibleInfo *)items->data;
8776 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8778 if (act_on_item == FALSE && list == items)
8782 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8784 items = items->next;
8790 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8791 GtkIconView *icon_view)
8794 GtkIconViewAccessible *view;
8797 * The scrollbars have changed
8799 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8800 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8802 gtk_icon_view_accessible_traverse_items (view, NULL);
8806 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8807 GtkAdjustment *hadj,
8808 GtkAdjustment *vadj)
8811 GtkIconViewAccessiblePrivate *priv;
8813 atk_obj = gtk_widget_get_accessible (widget);
8814 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8816 if (priv->old_hadj != hadj)
8820 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8821 (gpointer *)&priv->old_hadj);
8823 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8824 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8827 priv->old_hadj = hadj;
8830 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8831 (gpointer *)&priv->old_hadj);
8832 g_signal_connect (hadj,
8834 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8838 if (priv->old_vadj != vadj)
8842 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8843 (gpointer *)&priv->old_vadj);
8845 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8846 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8849 priv->old_vadj = vadj;
8852 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8853 (gpointer *)&priv->old_vadj);
8854 g_signal_connect (vadj,
8856 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8863 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8870 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8871 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8877 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8882 GtkIconViewAccessiblePrivate *priv;
8883 GtkIconViewItemAccessibleInfo *info;
8884 GtkIconViewAccessible *view;
8885 GtkIconViewItemAccessible *item;
8891 index = gtk_tree_path_get_indices(path)[0];
8892 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8893 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8894 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8896 items = priv->items;
8901 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8902 if (info->index != item->item->index)
8904 if (info->index < index)
8905 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8907 if (tmp_list == NULL)
8910 info->index = item->item->index;
8913 items = items->next;
8915 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8916 g_signal_emit_by_name (atk_obj, "children_changed::add",
8922 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8926 GtkIconViewAccessiblePrivate *priv;
8927 GtkIconViewItemAccessibleInfo *info;
8928 GtkIconViewAccessible *view;
8929 GtkIconViewItemAccessible *item;
8932 GList *deleted_item;
8936 index = gtk_tree_path_get_indices(path)[0];
8937 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8938 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8939 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8941 items = priv->items;
8943 deleted_item = NULL;
8948 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8949 if (info->index == index)
8951 deleted_item = items;
8953 if (info->index != item->item->index)
8955 if (tmp_list == NULL)
8958 info->index = item->item->index;
8961 items = items->next;
8963 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8966 info = deleted_item->data;
8967 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8968 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8970 priv->items = g_list_remove_link (priv->items, deleted_item);
8978 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8979 GtkIconViewItemAccessibleInfo *i2)
8981 return i1->index - i2->index;
8985 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8991 GtkIconViewAccessiblePrivate *priv;
8992 GtkIconViewItemAccessibleInfo *info;
8993 GtkIconView *icon_view;
8994 GtkIconViewItemAccessible *item;
8998 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8999 icon_view = GTK_ICON_VIEW (user_data);
9000 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9002 items = priv->items;
9006 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9007 info->index = new_order[info->index];
9008 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9009 items = items->next;
9011 priv->items = g_list_sort (priv->items,
9012 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9018 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9023 obj = G_OBJECT (model);
9024 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9025 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9026 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9027 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9031 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9035 obj = G_OBJECT (icon_view->priv->model);
9036 g_signal_connect_data (obj, "row_changed",
9037 (GCallback) gtk_icon_view_accessible_model_row_changed,
9038 icon_view, NULL, 0);
9039 g_signal_connect_data (obj, "row_inserted",
9040 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9041 icon_view, NULL, G_CONNECT_AFTER);
9042 g_signal_connect_data (obj, "row_deleted",
9043 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9044 icon_view, NULL, G_CONNECT_AFTER);
9045 g_signal_connect_data (obj, "rows_reordered",
9046 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9047 icon_view, NULL, G_CONNECT_AFTER);
9051 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9053 GtkIconViewItemAccessibleInfo *info;
9056 items = priv->items;
9059 info = (GtkIconViewItemAccessibleInfo *) items->data;
9060 g_object_unref (info->item);
9061 g_free (items->data);
9062 items = items->next;
9064 g_list_free (priv->items);
9069 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9072 GtkIconView *icon_view;
9075 GtkIconViewAccessiblePrivate *priv;
9077 if (strcmp (pspec->name, "model") == 0)
9079 widget = GTK_WIDGET (obj);
9080 atk_obj = gtk_widget_get_accessible (widget);
9081 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9084 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9085 (gpointer *)&priv->model);
9086 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9088 gtk_icon_view_accessible_clear_cache (priv);
9090 icon_view = GTK_ICON_VIEW (obj);
9091 priv->model = icon_view->priv->model;
9092 /* If there is no model the GtkIconView is probably being destroyed */
9095 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9096 gtk_icon_view_accessible_connect_model_signals (icon_view);
9104 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9107 GtkIconViewAccessiblePrivate *priv;
9108 GtkIconView *icon_view;
9110 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9111 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9113 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9114 g_object_set_qdata (G_OBJECT (accessible),
9115 accessible_private_data_quark,
9118 icon_view = GTK_ICON_VIEW (data);
9119 if (icon_view->priv->hadjustment)
9121 priv->old_hadj = icon_view->priv->hadjustment;
9122 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9123 g_signal_connect (icon_view->priv->hadjustment,
9125 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9128 if (icon_view->priv->vadjustment)
9130 priv->old_vadj = icon_view->priv->vadjustment;
9131 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9132 g_signal_connect (icon_view->priv->vadjustment,
9134 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9137 g_signal_connect_after (data,
9138 "set_scroll_adjustments",
9139 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9141 g_signal_connect (data,
9143 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9146 priv->model = icon_view->priv->model;
9149 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9150 gtk_icon_view_accessible_connect_model_signals (icon_view);
9153 accessible->role = ATK_ROLE_LAYERED_PANE;
9157 gtk_icon_view_accessible_finalize (GObject *object)
9159 GtkIconViewAccessiblePrivate *priv;
9161 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9162 gtk_icon_view_accessible_clear_cache (priv);
9166 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9170 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9171 GtkAccessible *accessible)
9174 GtkIconViewAccessiblePrivate *priv;
9176 atk_obj = ATK_OBJECT (accessible);
9177 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9180 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9181 (gpointer *)&priv->old_hadj);
9183 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9184 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9186 priv->old_hadj = NULL;
9190 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9191 (gpointer *)&priv->old_vadj);
9193 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9194 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9196 priv->old_vadj = NULL;
9201 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9203 if (accessible->widget)
9205 g_signal_connect_after (accessible->widget,
9207 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9210 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9214 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9216 GObjectClass *gobject_class;
9217 GtkAccessibleClass *accessible_class;
9219 accessible_parent_class = g_type_class_peek_parent (klass);
9221 gobject_class = (GObjectClass *)klass;
9222 accessible_class = (GtkAccessibleClass *)klass;
9224 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9226 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9227 klass->ref_child = gtk_icon_view_accessible_ref_child;
9228 klass->initialize = gtk_icon_view_accessible_initialize;
9230 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9232 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9236 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9239 AtkCoordType coord_type)
9242 GtkIconView *icon_view;
9243 GtkIconViewItem *item;
9246 widget = GTK_ACCESSIBLE (component)->widget;
9248 /* State is defunct */
9251 icon_view = GTK_ICON_VIEW (widget);
9252 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9253 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9255 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9261 atk_component_interface_init (AtkComponentIface *iface)
9263 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9267 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9271 GtkIconView *icon_view;
9272 GtkIconViewItem *item;
9274 widget = GTK_ACCESSIBLE (selection)->widget;
9278 icon_view = GTK_ICON_VIEW (widget);
9280 item = g_list_nth_data (icon_view->priv->items, i);
9285 gtk_icon_view_select_item (icon_view, item);
9291 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9294 GtkIconView *icon_view;
9296 widget = GTK_ACCESSIBLE (selection)->widget;
9300 icon_view = GTK_ICON_VIEW (widget);
9301 gtk_icon_view_unselect_all (icon_view);
9307 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9312 GtkIconView *icon_view;
9313 GtkIconViewItem *item;
9315 widget = GTK_ACCESSIBLE (selection)->widget;
9319 icon_view = GTK_ICON_VIEW (widget);
9321 l = icon_view->priv->items;
9328 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9339 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9342 GtkIconView *icon_view;
9343 GtkIconViewItem *item;
9347 widget = GTK_ACCESSIBLE (selection)->widget;
9351 icon_view = GTK_ICON_VIEW (widget);
9353 l = icon_view->priv->items;
9369 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9373 GtkIconView *icon_view;
9374 GtkIconViewItem *item;
9376 widget = GTK_ACCESSIBLE (selection)->widget;
9380 icon_view = GTK_ICON_VIEW (widget);
9382 item = g_list_nth_data (icon_view->priv->items, i);
9386 return item->selected;
9390 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9394 GtkIconView *icon_view;
9395 GtkIconViewItem *item;
9399 widget = GTK_ACCESSIBLE (selection)->widget;
9403 icon_view = GTK_ICON_VIEW (widget);
9404 l = icon_view->priv->items;
9413 gtk_icon_view_unselect_item (icon_view, item);
9425 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9428 GtkIconView *icon_view;
9430 widget = GTK_ACCESSIBLE (selection)->widget;
9434 icon_view = GTK_ICON_VIEW (widget);
9435 gtk_icon_view_select_all (icon_view);
9440 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9442 iface->add_selection = gtk_icon_view_accessible_add_selection;
9443 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9444 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9445 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9446 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9447 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9448 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9452 gtk_icon_view_accessible_get_type (void)
9454 static GType type = 0;
9458 static GTypeInfo tinfo =
9461 (GBaseInitFunc) NULL, /* base init */
9462 (GBaseFinalizeFunc) NULL, /* base finalize */
9463 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9464 (GClassFinalizeFunc) NULL, /* class finalize */
9465 NULL, /* class data */
9466 0, /* instance size */
9467 0, /* nb preallocs */
9468 (GInstanceInitFunc) NULL, /* instance init */
9469 NULL /* value table */
9471 static const GInterfaceInfo atk_component_info =
9473 (GInterfaceInitFunc) atk_component_interface_init,
9474 (GInterfaceFinalizeFunc) NULL,
9477 static const GInterfaceInfo atk_selection_info =
9479 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9480 (GInterfaceFinalizeFunc) NULL,
9485 * Figure out the size of the class and instance
9486 * we are deriving from
9488 AtkObjectFactory *factory;
9491 GType derived_atk_type;
9493 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9494 factory = atk_registry_get_factory (atk_get_default_registry (),
9496 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9497 g_type_query (derived_atk_type, &query);
9498 tinfo.class_size = query.class_size;
9499 tinfo.instance_size = query.instance_size;
9501 type = g_type_register_static (derived_atk_type,
9502 I_("GtkIconViewAccessible"),
9504 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9505 &atk_component_info);
9506 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9507 &atk_selection_info);
9513 gtk_icon_view_accessible_new (GObject *obj)
9515 AtkObject *accessible;
9517 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9519 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9520 atk_object_initialize (accessible, obj);
9526 gtk_icon_view_accessible_factory_get_accessible_type (void)
9528 return gtk_icon_view_accessible_get_type ();
9532 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9534 return gtk_icon_view_accessible_new (obj);
9538 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9540 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9541 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9545 gtk_icon_view_accessible_factory_get_type (void)
9547 static GType type = 0;
9551 const GTypeInfo tinfo =
9553 sizeof (AtkObjectFactoryClass),
9554 NULL, /* base_init */
9555 NULL, /* base_finalize */
9556 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9557 NULL, /* class_finalize */
9558 NULL, /* class_data */
9559 sizeof (AtkObjectFactory),
9560 0, /* n_preallocs */
9564 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9565 I_("GtkIconViewAccessibleFactory"),
9573 gtk_icon_view_get_accessible (GtkWidget *widget)
9575 static gboolean first_time = TRUE;
9579 AtkObjectFactory *factory;
9580 AtkRegistry *registry;
9582 GType derived_atk_type;
9585 * Figure out whether accessibility is enabled by looking at the
9586 * type of the accessible object which would be created for
9587 * the parent type of GtkIconView.
9589 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9591 registry = atk_get_default_registry ();
9592 factory = atk_registry_get_factory (registry,
9594 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9595 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9596 atk_registry_set_factory_type (registry,
9598 gtk_icon_view_accessible_factory_get_type ());
9601 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9605 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9606 GtkBuilder *builder,
9608 const gchar *tagname,
9609 GMarkupParser *parser,
9612 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9613 tagname, parser, data))
9616 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9617 tagname, parser, data);
9621 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9622 GtkBuilder *builder,
9624 const gchar *tagname,
9627 if (strcmp (tagname, "attributes") == 0)
9628 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9631 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9637 #define __GTK_ICON_VIEW_C__
9638 #include "gtkaliasdef.c"