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 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1238 gtk_icon_view_state_changed (GtkWidget *widget,
1239 GtkStateType previous_state)
1241 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1243 if (GTK_WIDGET_REALIZED (widget))
1245 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1246 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1249 gtk_widget_queue_draw (widget);
1253 gtk_icon_view_style_set (GtkWidget *widget,
1254 GtkStyle *previous_style)
1256 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1258 if (GTK_WIDGET_REALIZED (widget))
1260 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1261 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1264 gtk_widget_queue_resize (widget);
1268 gtk_icon_view_size_request (GtkWidget *widget,
1269 GtkRequisition *requisition)
1271 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1274 requisition->width = icon_view->priv->width;
1275 requisition->height = icon_view->priv->height;
1277 tmp_list = icon_view->priv->children;
1281 GtkIconViewChild *child = tmp_list->data;
1282 GtkRequisition child_requisition;
1284 tmp_list = tmp_list->next;
1286 if (GTK_WIDGET_VISIBLE (child->widget))
1287 gtk_widget_size_request (child->widget, &child_requisition);
1292 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1296 for (list = icon_view->priv->children; list; list = list->next)
1298 GtkIconViewChild *child = list->data;
1299 GtkAllocation allocation;
1301 /* totally ignore our child's requisition */
1302 if (child->cell < 0)
1304 allocation.x = child->item->x;
1305 allocation.y = child->item->y;
1306 allocation.width = child->item->width;
1307 allocation.height = child->item->height;
1311 GdkRectangle *box = &child->item->box[child->cell];
1313 allocation.x = box->x;
1314 allocation.y = box->y;
1315 allocation.width = box->width;
1316 allocation.height = box->height;
1319 gtk_widget_size_allocate (child->widget, &allocation);
1324 gtk_icon_view_size_allocate (GtkWidget *widget,
1325 GtkAllocation *allocation)
1327 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1329 GtkAdjustment *hadjustment, *vadjustment;
1331 widget->allocation = *allocation;
1333 if (GTK_WIDGET_REALIZED (widget))
1335 gdk_window_move_resize (widget->window,
1336 allocation->x, allocation->y,
1337 allocation->width, allocation->height);
1338 gdk_window_resize (icon_view->priv->bin_window,
1339 MAX (icon_view->priv->width, allocation->width),
1340 MAX (icon_view->priv->height, allocation->height));
1343 gtk_icon_view_layout (icon_view);
1345 gtk_icon_view_allocate_children (icon_view);
1347 hadjustment = icon_view->priv->hadjustment;
1348 vadjustment = icon_view->priv->vadjustment;
1350 hadjustment->page_size = allocation->width;
1351 hadjustment->page_increment = allocation->width * 0.9;
1352 hadjustment->step_increment = allocation->width * 0.1;
1353 hadjustment->lower = 0;
1354 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1356 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1357 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1359 vadjustment->page_size = allocation->height;
1360 vadjustment->page_increment = allocation->height * 0.9;
1361 vadjustment->step_increment = allocation->height * 0.1;
1362 vadjustment->lower = 0;
1363 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1365 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1366 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1368 if (GTK_WIDGET_REALIZED (widget) &&
1369 icon_view->priv->scroll_to_path)
1372 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1373 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1374 icon_view->priv->scroll_to_path = NULL;
1376 gtk_icon_view_scroll_to_path (icon_view, path,
1377 icon_view->priv->scroll_to_use_align,
1378 icon_view->priv->scroll_to_row_align,
1379 icon_view->priv->scroll_to_col_align);
1380 gtk_tree_path_free (path);
1384 gtk_adjustment_changed (hadjustment);
1385 gtk_adjustment_changed (vadjustment);
1390 gtk_icon_view_expose (GtkWidget *widget,
1391 GdkEventExpose *expose)
1393 GtkIconView *icon_view;
1398 GtkIconViewDropPosition dest_pos;
1399 GtkIconViewItem *dest_item = NULL;
1401 icon_view = GTK_ICON_VIEW (widget);
1403 if (expose->window != icon_view->priv->bin_window)
1406 cr = gdk_cairo_create (icon_view->priv->bin_window);
1407 cairo_set_line_width (cr, 1.);
1409 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1413 dest_index = gtk_tree_path_get_indices (path)[0];
1414 gtk_tree_path_free (path);
1419 for (icons = icon_view->priv->items; icons; icons = icons->next)
1421 GtkIconViewItem *item = icons->data;
1426 area.width = item->width;
1427 area.height = item->height;
1429 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1432 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1433 icon_view->priv->bin_window,
1434 item->x, item->y, TRUE);
1436 if (dest_index == item->index)
1444 case GTK_ICON_VIEW_DROP_INTO:
1445 gtk_paint_focus (widget->style,
1446 icon_view->priv->bin_window,
1447 GTK_WIDGET_STATE (widget),
1450 "iconview-drop-indicator",
1451 dest_item->x, dest_item->y,
1452 dest_item->width, dest_item->height);
1454 case GTK_ICON_VIEW_DROP_ABOVE:
1455 gtk_paint_focus (widget->style,
1456 icon_view->priv->bin_window,
1457 GTK_WIDGET_STATE (widget),
1460 "iconview-drop-indicator",
1461 dest_item->x, dest_item->y - 1,
1462 dest_item->width, 2);
1464 case GTK_ICON_VIEW_DROP_LEFT:
1465 gtk_paint_focus (widget->style,
1466 icon_view->priv->bin_window,
1467 GTK_WIDGET_STATE (widget),
1470 "iconview-drop-indicator",
1471 dest_item->x - 1, dest_item->y,
1472 2, dest_item->height);
1474 case GTK_ICON_VIEW_DROP_BELOW:
1475 gtk_paint_focus (widget->style,
1476 icon_view->priv->bin_window,
1477 GTK_WIDGET_STATE (widget),
1480 "iconview-drop-indicator",
1481 dest_item->x, dest_item->y + dest_item->height - 1,
1482 dest_item->width, 2);
1484 case GTK_ICON_VIEW_DROP_RIGHT:
1485 gtk_paint_focus (widget->style,
1486 icon_view->priv->bin_window,
1487 GTK_WIDGET_STATE (widget),
1490 "iconview-drop-indicator",
1491 dest_item->x + dest_item->width - 1, dest_item->y,
1492 2, dest_item->height);
1493 case GTK_ICON_VIEW_NO_DROP: ;
1498 if (icon_view->priv->doing_rubberband)
1500 GdkRectangle *rectangles;
1503 gdk_region_get_rectangles (expose->region,
1507 while (n_rectangles--)
1508 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1510 g_free (rectangles);
1515 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1521 rubberband_scroll_timeout (gpointer data)
1523 GtkIconView *icon_view = data;
1525 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1526 icon_view->priv->vadjustment->value +
1527 icon_view->priv->scroll_value_diff);
1529 gtk_icon_view_update_rubberband (icon_view);
1535 gtk_icon_view_motion (GtkWidget *widget,
1536 GdkEventMotion *event)
1538 GtkIconView *icon_view;
1541 icon_view = GTK_ICON_VIEW (widget);
1543 gtk_icon_view_maybe_begin_drag (icon_view, event);
1545 if (icon_view->priv->doing_rubberband)
1547 gtk_icon_view_update_rubberband (widget);
1549 abs_y = event->y - icon_view->priv->height *
1550 (icon_view->priv->vadjustment->value /
1551 (icon_view->priv->vadjustment->upper -
1552 icon_view->priv->vadjustment->lower));
1554 if (abs_y < 0 || abs_y > widget->allocation.height)
1557 icon_view->priv->scroll_value_diff = abs_y;
1559 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1561 icon_view->priv->event_last_x = event->x;
1562 icon_view->priv->event_last_y = event->y;
1564 if (icon_view->priv->scroll_timeout_id == 0)
1565 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1569 remove_scroll_timeout (icon_view);
1576 gtk_icon_view_remove (GtkContainer *container,
1579 GtkIconView *icon_view;
1580 GtkIconViewChild *child = NULL;
1583 icon_view = GTK_ICON_VIEW (container);
1585 tmp_list = icon_view->priv->children;
1588 child = tmp_list->data;
1589 if (child->widget == widget)
1591 gtk_widget_unparent (widget);
1593 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1594 g_list_free_1 (tmp_list);
1599 tmp_list = tmp_list->next;
1604 gtk_icon_view_forall (GtkContainer *container,
1605 gboolean include_internals,
1606 GtkCallback callback,
1607 gpointer callback_data)
1609 GtkIconView *icon_view;
1610 GtkIconViewChild *child = NULL;
1613 icon_view = GTK_ICON_VIEW (container);
1615 tmp_list = icon_view->priv->children;
1618 child = tmp_list->data;
1619 tmp_list = tmp_list->next;
1621 (* callback) (child->widget, callback_data);
1626 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1627 GtkIconViewItem *item,
1628 GtkIconViewCellInfo *info,
1633 GdkRectangle cell_area;
1634 gboolean visible, mode;
1636 gtk_icon_view_set_cell_data (icon_view, item);
1638 g_object_get (info->cell,
1639 "visible", &visible,
1643 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1645 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1647 path = gtk_tree_path_new_from_indices (item->index, -1);
1648 path_string = gtk_tree_path_to_string (path);
1649 gtk_tree_path_free (path);
1651 gtk_cell_renderer_activate (info->cell,
1653 GTK_WIDGET (icon_view),
1659 g_free (path_string);
1664 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1665 GtkIconViewItem *item)
1668 AtkObject *item_obj;
1670 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1673 item_obj = atk_object_ref_accessible_child (obj, item->index);
1674 if (item_obj != NULL)
1676 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1677 g_object_unref (item_obj);
1683 gtk_icon_view_put (GtkIconView *icon_view,
1685 GtkIconViewItem *item,
1688 GtkIconViewChild *child;
1690 child = g_new (GtkIconViewChild, 1);
1692 child->widget = widget;
1696 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1698 if (GTK_WIDGET_REALIZED (icon_view))
1699 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1701 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1705 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1706 GtkIconView *icon_view)
1709 GtkIconViewItem *item;
1711 if (icon_view->priv->edited_item == NULL)
1714 item = icon_view->priv->edited_item;
1715 icon_view->priv->edited_item = NULL;
1716 icon_view->priv->editable = NULL;
1717 for (l = icon_view->priv->cell_list; l; l = l->next)
1719 GtkIconViewCellInfo *info = l->data;
1721 info->editing = FALSE;
1724 if (GTK_WIDGET_HAS_FOCUS (editable))
1725 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1727 g_signal_handlers_disconnect_by_func (editable,
1728 gtk_icon_view_remove_widget,
1731 gtk_container_remove (GTK_CONTAINER (icon_view),
1732 GTK_WIDGET (editable));
1734 gtk_icon_view_queue_draw_item (icon_view, item);
1739 gtk_icon_view_start_editing (GtkIconView *icon_view,
1740 GtkIconViewItem *item,
1741 GtkIconViewCellInfo *info,
1746 GdkRectangle cell_area;
1747 gboolean visible, mode;
1748 GtkCellEditable *editable;
1750 gtk_icon_view_set_cell_data (icon_view, item);
1752 g_object_get (info->cell,
1753 "visible", &visible,
1756 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1758 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1760 path = gtk_tree_path_new_from_indices (item->index, -1);
1761 path_string = gtk_tree_path_to_string (path);
1762 gtk_tree_path_free (path);
1764 editable = gtk_cell_renderer_start_editing (info->cell,
1766 GTK_WIDGET (icon_view),
1771 g_free (path_string);
1773 /* FIXME ugly special case */
1774 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1775 g_object_set (editable, "has-frame", TRUE, NULL);
1777 /* the rest corresponds to tree_view_real_start_editing... */
1778 icon_view->priv->edited_item = item;
1779 icon_view->priv->editable = editable;
1780 info->editing = TRUE;
1782 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1784 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1786 gtk_widget_grab_focus (GTK_WIDGET (editable));
1787 g_signal_connect (editable, "remove-widget",
1788 G_CALLBACK (gtk_icon_view_remove_widget),
1795 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1796 gboolean cancel_editing)
1798 GtkCellRenderer *cell = NULL;
1799 GtkIconViewItem *item;
1802 if (icon_view->priv->edited_item == NULL)
1806 * This is very evil. We need to do this, because
1807 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1808 * later on. If gtk_icon_view_row_changed notices
1809 * icon_view->priv->edited_item != NULL, it'll call
1810 * gtk_icon_view_stop_editing again. Bad things will happen then.
1812 * Please read that again if you intend to modify anything here.
1815 item = icon_view->priv->edited_item;
1816 icon_view->priv->edited_item = NULL;
1818 for (l = icon_view->priv->cell_list; l; l = l->next)
1820 GtkIconViewCellInfo *info = l->data;
1832 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1833 if (!cancel_editing)
1834 gtk_cell_editable_editing_done (icon_view->priv->editable);
1836 icon_view->priv->edited_item = item;
1838 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1842 * gtk_icon_view_set_cursor:
1843 * @icon_view: A #GtkIconView
1844 * @path: A #GtkTreePath
1845 * @cell: One of the cell renderers of @icon_view, or %NULL
1846 * @start_editing: %TRUE if the specified cell should start being edited.
1848 * Sets the current keyboard focus to be at @path, and selects it. This is
1849 * useful when you want to focus the user's attention on a particular item.
1850 * If @cell is not %NULL, then focus is given to the cell specified by
1851 * it. Additionally, if @start_editing is %TRUE, then editing should be
1852 * started in the specified cell.
1854 * This function is often followed by <literal>gtk_widget_grab_focus
1855 * (icon_view)</literal> in order to give keyboard focus to the widget.
1856 * Please note that editing can only happen when the widget is realized.
1861 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1863 GtkCellRenderer *cell,
1864 gboolean start_editing)
1866 GtkIconViewItem *item = NULL;
1867 GtkIconViewCellInfo *info = NULL;
1871 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1872 g_return_if_fail (path != NULL);
1873 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1875 gtk_icon_view_stop_editing (icon_view, TRUE);
1877 if (gtk_tree_path_get_depth (path) == 1)
1878 item = g_list_nth_data (icon_view->priv->items,
1879 gtk_tree_path_get_indices(path)[0]);
1885 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1889 if (info->cell == cell)
1898 g_return_if_fail (cell == NULL || info != NULL);
1900 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1901 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1903 if (info && start_editing)
1904 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1908 * gtk_icon_view_get_cursor:
1909 * @icon_view: A #GtkIconView
1910 * @path: Return location for the current cursor path, or %NULL
1911 * @cell: Return location the current focus cell, or %NULL
1913 * Fills in @path and @cell with the current cursor path and cell.
1914 * If the cursor isn't currently set, then *@path will be %NULL.
1915 * If no cell currently has focus, then *@cell will be %NULL.
1917 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1919 * Return value: %TRUE if the cursor is set.
1924 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1926 GtkCellRenderer **cell)
1928 GtkIconViewItem *item;
1929 GtkIconViewCellInfo *info;
1931 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1933 item = icon_view->priv->cursor_item;
1934 if (icon_view->priv->cursor_cell < 0)
1937 info = g_list_nth_data (icon_view->priv->cell_list,
1938 icon_view->priv->cursor_cell);
1943 *path = gtk_tree_path_new_from_indices (item->index, -1);
1956 return (item != NULL);
1960 gtk_icon_view_button_press (GtkWidget *widget,
1961 GdkEventButton *event)
1963 GtkIconView *icon_view;
1964 GtkIconViewItem *item;
1965 GtkIconViewCellInfo *info = NULL;
1966 gboolean dirty = FALSE;
1967 GtkCellRendererMode mode;
1970 icon_view = GTK_ICON_VIEW (widget);
1972 if (event->window != icon_view->priv->bin_window)
1975 if (!GTK_WIDGET_HAS_FOCUS (widget))
1976 gtk_widget_grab_focus (widget);
1978 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1980 item = gtk_icon_view_get_item_at_coords (icon_view,
1986 g_object_get (info->cell, "mode", &mode, NULL);
1988 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1989 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1990 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1994 gtk_icon_view_scroll_to_item (icon_view, item);
1996 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1998 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2000 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2001 (event->state & GDK_SHIFT_MASK))
2003 gtk_icon_view_unselect_all_internal (icon_view);
2005 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2006 if (!icon_view->priv->anchor_item)
2007 icon_view->priv->anchor_item = item;
2009 gtk_icon_view_select_all_between (icon_view,
2010 icon_view->priv->anchor_item,
2016 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2017 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2018 (event->state & GDK_CONTROL_MASK))
2020 item->selected = !item->selected;
2021 gtk_icon_view_queue_draw_item (icon_view, item);
2026 if (!item->selected)
2028 gtk_icon_view_unselect_all_internal (icon_view);
2030 item->selected = TRUE;
2031 gtk_icon_view_queue_draw_item (icon_view, item);
2035 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2036 icon_view->priv->anchor_item = item;
2039 /* Save press to possibly begin a drag */
2040 if (icon_view->priv->pressed_button < 0)
2042 icon_view->priv->pressed_button = event->button;
2043 icon_view->priv->press_start_x = event->x;
2044 icon_view->priv->press_start_y = event->y;
2047 if (!icon_view->priv->last_single_clicked)
2048 icon_view->priv->last_single_clicked = item;
2050 /* cancel the current editing, if it exists */
2051 gtk_icon_view_stop_editing (icon_view, TRUE);
2053 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2054 gtk_icon_view_item_activate_cell (icon_view, item, info,
2056 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2057 gtk_icon_view_start_editing (icon_view, item, info,
2062 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2063 !(event->state & GDK_CONTROL_MASK))
2065 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2068 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2069 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2074 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2076 item = gtk_icon_view_get_item_at_coords (icon_view,
2081 if (item && item == icon_view->priv->last_single_clicked)
2085 path = gtk_tree_path_new_from_indices (item->index, -1);
2086 gtk_icon_view_item_activated (icon_view, path);
2087 gtk_tree_path_free (path);
2090 icon_view->priv->last_single_clicked = NULL;
2091 icon_view->priv->pressed_button = -1;
2095 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2097 return event->button == 1;
2101 gtk_icon_view_button_release (GtkWidget *widget,
2102 GdkEventButton *event)
2104 GtkIconView *icon_view;
2106 icon_view = GTK_ICON_VIEW (widget);
2108 if (icon_view->priv->pressed_button == event->button)
2109 icon_view->priv->pressed_button = -1;
2111 gtk_icon_view_stop_rubberbanding (icon_view);
2113 remove_scroll_timeout (icon_view);
2119 gtk_icon_view_key_press (GtkWidget *widget,
2122 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2124 if (icon_view->priv->doing_rubberband)
2126 if (event->keyval == GDK_Escape)
2127 gtk_icon_view_stop_rubberbanding (icon_view);
2132 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2136 gtk_icon_view_key_release (GtkWidget *widget,
2139 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2141 if (icon_view->priv->doing_rubberband)
2144 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2148 gtk_icon_view_update_rubberband (gpointer data)
2150 GtkIconView *icon_view;
2152 GdkRectangle old_area;
2153 GdkRectangle new_area;
2154 GdkRectangle common;
2155 GdkRegion *invalid_region;
2157 icon_view = GTK_ICON_VIEW (data);
2159 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2164 old_area.x = MIN (icon_view->priv->rubberband_x1,
2165 icon_view->priv->rubberband_x2);
2166 old_area.y = MIN (icon_view->priv->rubberband_y1,
2167 icon_view->priv->rubberband_y2);
2168 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2169 icon_view->priv->rubberband_x1) + 1;
2170 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2171 icon_view->priv->rubberband_y1) + 1;
2173 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2174 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2175 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2176 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2178 invalid_region = gdk_region_rectangle (&old_area);
2179 gdk_region_union_with_rect (invalid_region, &new_area);
2181 gdk_rectangle_intersect (&old_area, &new_area, &common);
2182 if (common.width > 2 && common.height > 2)
2184 GdkRegion *common_region;
2186 /* make sure the border is invalidated */
2192 common_region = gdk_region_rectangle (&common);
2194 gdk_region_subtract (invalid_region, common_region);
2195 gdk_region_destroy (common_region);
2198 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2200 gdk_region_destroy (invalid_region);
2202 icon_view->priv->rubberband_x2 = x;
2203 icon_view->priv->rubberband_y2 = y;
2205 gtk_icon_view_update_rubberband_selection (icon_view);
2209 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2215 g_assert (!icon_view->priv->doing_rubberband);
2217 for (items = icon_view->priv->items; items; items = items->next)
2219 GtkIconViewItem *item = items->data;
2221 item->selected_before_rubberbanding = item->selected;
2224 icon_view->priv->rubberband_x1 = x;
2225 icon_view->priv->rubberband_y1 = y;
2226 icon_view->priv->rubberband_x2 = x;
2227 icon_view->priv->rubberband_y2 = y;
2229 icon_view->priv->doing_rubberband = TRUE;
2231 gtk_grab_add (GTK_WIDGET (icon_view));
2235 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2237 if (!icon_view->priv->doing_rubberband)
2240 icon_view->priv->doing_rubberband = FALSE;
2242 gtk_grab_remove (GTK_WIDGET (icon_view));
2244 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2248 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2251 gint x, y, width, height;
2252 gboolean dirty = FALSE;
2254 x = MIN (icon_view->priv->rubberband_x1,
2255 icon_view->priv->rubberband_x2);
2256 y = MIN (icon_view->priv->rubberband_y1,
2257 icon_view->priv->rubberband_y2);
2258 width = ABS (icon_view->priv->rubberband_x1 -
2259 icon_view->priv->rubberband_x2);
2260 height = ABS (icon_view->priv->rubberband_y1 -
2261 icon_view->priv->rubberband_y2);
2263 for (items = icon_view->priv->items; items; items = items->next)
2265 GtkIconViewItem *item = items->data;
2269 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2270 x, y, width, height);
2272 selected = is_in ^ item->selected_before_rubberbanding;
2274 if (item->selected != selected)
2276 item->selected = selected;
2278 gtk_icon_view_queue_draw_item (icon_view, item);
2283 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2287 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2288 GtkIconViewItem *item,
2297 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2298 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2301 for (l = icon_view->priv->cell_list; l; l = l->next)
2303 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2305 if (!info->cell->visible)
2308 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2310 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2311 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2319 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2321 gboolean dirty = FALSE;
2324 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2327 for (items = icon_view->priv->items; items; items = items->next)
2329 GtkIconViewItem *item = items->data;
2333 item->selected = FALSE;
2335 gtk_icon_view_queue_draw_item (icon_view, item);
2336 gtk_icon_view_item_selected_changed (icon_view, item);
2344 /* GtkIconView signals */
2346 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2347 GtkAdjustment *hadj,
2348 GtkAdjustment *vadj)
2350 gboolean need_adjust = FALSE;
2353 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2355 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2357 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2359 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2361 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2363 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2364 0, 0, NULL, NULL, icon_view);
2365 g_object_unref (icon_view->priv->hadjustment);
2368 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2370 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2371 0, 0, NULL, NULL, icon_view);
2372 g_object_unref (icon_view->priv->vadjustment);
2375 if (icon_view->priv->hadjustment != hadj)
2377 icon_view->priv->hadjustment = hadj;
2378 g_object_ref_sink (icon_view->priv->hadjustment);
2380 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2381 G_CALLBACK (gtk_icon_view_adjustment_changed),
2386 if (icon_view->priv->vadjustment != vadj)
2388 icon_view->priv->vadjustment = vadj;
2389 g_object_ref_sink (icon_view->priv->vadjustment);
2391 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2392 G_CALLBACK (gtk_icon_view_adjustment_changed),
2398 gtk_icon_view_adjustment_changed (NULL, icon_view);
2402 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2404 gtk_icon_view_select_all (icon_view);
2408 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2410 gtk_icon_view_unselect_all (icon_view);
2414 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2416 gtk_icon_view_unselect_all (icon_view);
2418 if (icon_view->priv->cursor_item != NULL)
2419 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2423 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2426 GtkCellRendererMode mode;
2427 GtkIconViewCellInfo *info = NULL;
2429 if (!icon_view->priv->cursor_item)
2432 info = g_list_nth_data (icon_view->priv->cell_list,
2433 icon_view->priv->cursor_cell);
2437 g_object_get (info->cell, "mode", &mode, NULL);
2439 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2441 gtk_icon_view_item_activate_cell (icon_view,
2442 icon_view->priv->cursor_item,
2446 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2448 gtk_icon_view_start_editing (icon_view,
2449 icon_view->priv->cursor_item,
2455 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2456 gtk_icon_view_item_activated (icon_view, path);
2457 gtk_tree_path_free (path);
2463 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2465 if (!icon_view->priv->cursor_item)
2468 switch (icon_view->priv->selection_mode)
2470 case GTK_SELECTION_NONE:
2472 case GTK_SELECTION_BROWSE:
2473 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2475 case GTK_SELECTION_SINGLE:
2476 if (icon_view->priv->cursor_item->selected)
2477 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2479 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2481 case GTK_SELECTION_MULTIPLE:
2482 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2483 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2485 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2486 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2491 /* Internal functions */
2493 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2494 GtkIconView *icon_view)
2496 if (GTK_WIDGET_REALIZED (icon_view))
2498 gdk_window_move (icon_view->priv->bin_window,
2499 - icon_view->priv->hadjustment->value,
2500 - icon_view->priv->vadjustment->value);
2502 if (icon_view->priv->doing_rubberband)
2503 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2505 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2510 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2515 gint *maximum_width)
2518 gint x, current_width;
2519 GList *items, *last_item;
2526 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2527 max_height = g_new0 (gint, icon_view->priv->n_cells);
2534 gtk_widget_style_get (GTK_WIDGET (icon_view),
2535 "focus-line-width", &focus_width,
2538 x += icon_view->priv->margin + focus_width;
2539 current_width += 2 * (icon_view->priv->margin + focus_width);
2544 GtkIconViewItem *item = items->data;
2546 gtk_icon_view_calculate_item_size (icon_view, item);
2547 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2549 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2551 current_width += item->width;
2553 if (items != first_item)
2555 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2556 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2560 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2562 item->y = *y + focus_width;
2563 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2565 x = current_width - (icon_view->priv->margin + focus_width);
2567 for (i = 0; i < icon_view->priv->n_cells; i++)
2568 max_height[i] = MAX (max_height[i], item->box[i].height);
2570 if (current_width > *maximum_width)
2571 *maximum_width = current_width;
2577 items = items->next;
2582 /* Now go through the row again and align the icons */
2583 for (items = first_item; items != last_item; items = items->next)
2585 GtkIconViewItem *item = items->data;
2587 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2589 /* We may want to readjust the new y coordinate. */
2590 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2591 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2594 item->col = col - 1 - item->col;
2597 g_free (max_height);
2603 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2606 if (upper != adj->upper)
2608 gdouble min = MAX (0.0, upper - adj->page_size);
2609 gboolean value_changed = FALSE;
2613 if (adj->value > min)
2616 value_changed = TRUE;
2619 gtk_adjustment_changed (adj);
2622 gtk_adjustment_value_changed (adj);
2627 gtk_icon_view_layout (GtkIconView *icon_view)
2629 gint y = 0, maximum_width = 0;
2635 if (icon_view->priv->layout_idle_id != 0)
2637 g_source_remove (icon_view->priv->layout_idle_id);
2638 icon_view->priv->layout_idle_id = 0;
2641 if (icon_view->priv->model == NULL)
2644 widget = GTK_WIDGET (icon_view);
2646 item_width = icon_view->priv->item_width;
2650 for (icons = icon_view->priv->items; icons; icons = icons->next)
2652 GtkIconViewItem *item = icons->data;
2653 gtk_icon_view_calculate_item_size (icon_view, item);
2654 item_width = MAX (item_width, item->width);
2659 icons = icon_view->priv->items;
2660 y += icon_view->priv->margin;
2665 gtk_icon_view_set_cell_data (icon_view, icons->data);
2666 adjust_wrap_width (icon_view, icons->data);
2671 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2673 &y, &maximum_width);
2676 while (icons != NULL);
2678 if (maximum_width != icon_view->priv->width)
2679 icon_view->priv->width = maximum_width;
2681 y += icon_view->priv->margin;
2683 if (y != icon_view->priv->height)
2684 icon_view->priv->height = y;
2686 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2687 icon_view->priv->width);
2688 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2689 icon_view->priv->height);
2691 if (icon_view->priv->width != widget->requisition.width ||
2692 icon_view->priv->height != widget->requisition.height)
2693 gtk_widget_queue_resize_no_redraw (widget);
2695 if (GTK_WIDGET_REALIZED (icon_view))
2696 gdk_window_resize (icon_view->priv->bin_window,
2697 MAX (icon_view->priv->width, widget->allocation.width),
2698 MAX (icon_view->priv->height, widget->allocation.height));
2700 if (icon_view->priv->scroll_to_path)
2704 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2705 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2706 icon_view->priv->scroll_to_path = NULL;
2708 gtk_icon_view_scroll_to_path (icon_view, path,
2709 icon_view->priv->scroll_to_use_align,
2710 icon_view->priv->scroll_to_row_align,
2711 icon_view->priv->scroll_to_col_align);
2712 gtk_tree_path_free (path);
2715 gtk_widget_queue_draw (widget);
2719 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2720 GtkIconViewItem *item,
2721 GtkIconViewCellInfo *info,
2722 GdkRectangle *cell_area)
2724 g_return_if_fail (info->position < item->n_cells);
2726 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2728 cell_area->x = item->box[info->position].x - item->before[info->position];
2729 cell_area->y = item->y;
2730 cell_area->width = item->box[info->position].width +
2731 item->before[info->position] + item->after[info->position];
2732 cell_area->height = item->height;
2736 cell_area->x = item->x;
2737 cell_area->y = item->box[info->position].y - item->before[info->position];
2738 cell_area->width = item->width;
2739 cell_area->height = item->box[info->position].height +
2740 item->before[info->position] + item->after[info->position];
2745 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2746 GtkIconViewItem *item,
2747 GtkIconViewCellInfo *info,
2750 g_return_if_fail (info->position < item->n_cells);
2752 *box = item->box[info->position];
2755 /* try to guess a reasonable wrap width for an implicit text cell renderer
2758 adjust_wrap_width (GtkIconView *icon_view,
2759 GtkIconViewItem *item)
2761 GtkIconViewCellInfo *text_info;
2762 GtkIconViewCellInfo *pixbuf_info;
2763 gint pixbuf_width, wrap_width;
2765 if (icon_view->priv->text_cell != -1 &&
2766 icon_view->priv->pixbuf_cell != -1)
2770 text_info = g_list_nth_data (icon_view->priv->cell_list,
2771 icon_view->priv->text_cell);
2772 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2773 icon_view->priv->pixbuf_cell);
2775 gtk_cell_renderer_get_size (pixbuf_info->cell,
2776 GTK_WIDGET (icon_view),
2782 if (icon_view->priv->item_width > 0)
2783 item_width = icon_view->priv->item_width;
2785 item_width = item->width;
2787 if (item->width == -1)
2790 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2792 wrap_width = MAX (2 * pixbuf_width, 50);
2794 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2795 wrap_width = item_width;
2797 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2799 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2800 g_object_set (text_info->cell, "width", wrap_width, NULL);
2805 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2806 GtkIconViewItem *item)
2811 if (item->width != -1 && item->height != -1)
2814 if (item->n_cells != icon_view->priv->n_cells)
2816 g_free (item->before);
2817 g_free (item->after);
2820 item->before = g_new0 (gint, icon_view->priv->n_cells);
2821 item->after = g_new0 (gint, icon_view->priv->n_cells);
2822 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2824 item->n_cells = icon_view->priv->n_cells;
2827 gtk_icon_view_set_cell_data (icon_view, item);
2829 spacing = icon_view->priv->spacing;
2833 for (l = icon_view->priv->cell_list; l; l = l->next)
2835 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2837 if (!info->cell->visible)
2840 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2842 &item->box[info->position].width,
2843 &item->box[info->position].height);
2845 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2847 item->width += item->box[info->position].width
2848 + (info->position > 0 ? spacing : 0);
2849 item->height = MAX (item->height, item->box[info->position].height);
2853 item->width = MAX (item->width, item->box[info->position].width);
2854 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2860 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2861 GtkIconViewItem *item,
2864 GdkRectangle cell_area;
2870 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2872 gtk_icon_view_set_cell_data (icon_view, item);
2874 spacing = icon_view->priv->spacing;
2877 for (i = 0; i < icon_view->priv->n_cells; i++)
2879 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2880 item->height = MAX (item->height, max_height[i]);
2882 item->height += max_height[i] + (i > 0 ? spacing : 0);
2885 cell_area.x = item->x;
2886 cell_area.y = item->y;
2888 for (k = 0; k < 2; k++)
2889 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2891 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2893 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2896 if (!info->cell->visible)
2899 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2901 cell_area.width = item->box[info->position].width;
2902 cell_area.height = item->height;
2906 cell_area.width = item->width;
2907 cell_area.height = max_height[i];
2910 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2912 &item->box[info->position].x, &item->box[info->position].y,
2913 &item->box[info->position].width, &item->box[info->position].height);
2915 item->box[info->position].x += cell_area.x;
2916 item->box[info->position].y += cell_area.y;
2917 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2919 item->before[info->position] = item->box[info->position].x - cell_area.x;
2920 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2921 cell_area.x += cell_area.width + spacing;
2925 if (item->box[info->position].width > item->width)
2927 item->width = item->box[info->position].width;
2928 cell_area.width = item->width;
2930 item->before[info->position] = item->box[info->position].y - cell_area.y;
2931 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2932 cell_area.y += cell_area.height + spacing;
2936 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2938 for (i = 0; i < icon_view->priv->n_cells; i++)
2940 item->box[i].x = item->x + item->width -
2941 (item->box[i].x + item->box[i].width - item->x);
2947 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2949 g_list_foreach (icon_view->priv->items,
2950 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2954 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2961 gtk_icon_view_paint_item (GtkIconView *icon_view,
2963 GtkIconViewItem *item,
2965 GdkDrawable *drawable,
2968 gboolean draw_focus)
2972 GdkRectangle cell_area, box;
2976 GtkCellRendererState flags;
2978 if (icon_view->priv->model == NULL)
2981 gtk_icon_view_set_cell_data (icon_view, item);
2983 gtk_widget_style_get (GTK_WIDGET (icon_view),
2984 "focus-line-width", &focus_width,
2987 padding = focus_width;
2991 flags = GTK_CELL_RENDERER_SELECTED;
2992 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2993 state = GTK_STATE_SELECTED;
2995 state = GTK_STATE_ACTIVE;
3000 state = GTK_STATE_NORMAL;
3003 #ifdef DEBUG_ICON_VIEW
3004 gdk_draw_rectangle (drawable,
3005 GTK_WIDGET (icon_view)->style->black_gc,
3008 item->width, item->height);
3012 for (l = icon_view->priv->cell_list; l; l = l->next)
3014 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3016 if (!info->cell->visible)
3019 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3021 /* FIXME we hardwire background drawing behind text
3022 * cell renderers here
3024 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3026 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
3027 cairo_rectangle (cr,
3028 x - item->x + box.x,
3029 y - item->y + box.y,
3030 box.width, box.height);
3035 for (l = icon_view->priv->cell_list; l; l = l->next)
3037 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3039 if (!info->cell->visible)
3042 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3044 #ifdef DEBUG_ICON_VIEW
3045 gdk_draw_rectangle (drawable,
3046 GTK_WIDGET (icon_view)->style->black_gc,
3048 x - item->x + cell_area.x,
3049 y - item->y + cell_area.y,
3050 cell_area.width, cell_area.height);
3052 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3054 gdk_draw_rectangle (drawable,
3055 GTK_WIDGET (icon_view)->style->black_gc,
3057 x - item->x + box.x,
3058 y - item->y + box.y,
3059 box.width, box.height);
3062 cell_area.x = x - item->x + cell_area.x;
3063 cell_area.y = y - item->y + cell_area.y;
3065 gtk_cell_renderer_render (info->cell,
3067 GTK_WIDGET (icon_view),
3068 &cell_area, &cell_area, area, flags);
3072 /* FIXME where to draw the focus with generic cell renderers ? */
3074 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3075 item == icon_view->priv->cursor_item)
3076 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3078 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3080 if (!info->cell->visible)
3083 if (icon_view->priv->cursor_cell < 0 &&
3084 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3085 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3086 icon_view->priv->cursor_cell = i;
3088 if (i == icon_view->priv->cursor_cell)
3090 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3092 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3096 GTK_WIDGET (icon_view),
3098 x - item->x + box.x - padding,
3099 y - item->y + box.y - padding,
3100 box.width + 2 * padding,
3101 box.height + 2 * padding);
3108 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3113 GdkRectangle rubber_rect;
3114 GdkColor *fill_color_gdk;
3115 guchar fill_color_alpha;
3117 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3118 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3119 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3120 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3122 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3125 gtk_widget_style_get (GTK_WIDGET (icon_view),
3126 "selection-box-color", &fill_color_gdk,
3127 "selection-box-alpha", &fill_color_alpha,
3130 if (!fill_color_gdk)
3131 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3133 cairo_set_source_rgba (cr,
3134 fill_color_gdk->red / 65535.,
3135 fill_color_gdk->green / 65535.,
3136 fill_color_gdk->blue / 65535.,
3137 fill_color_alpha / 255.);
3140 gdk_cairo_rectangle (cr, &rect);
3144 /* Draw the border without alpha */
3145 cairo_set_source_rgb (cr,
3146 fill_color_gdk->red / 65535.,
3147 fill_color_gdk->green / 65535.,
3148 fill_color_gdk->blue / 65535.);
3149 cairo_rectangle (cr,
3150 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3151 rubber_rect.width - 1, rubber_rect.height - 1);
3155 gdk_color_free (fill_color_gdk);
3159 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3165 index = gtk_tree_path_get_indices (path)[0];
3167 for (l = icon_view->priv->items; l; l = l->next)
3169 GtkIconViewItem *item = l->data;
3171 if (item->index == index)
3173 gtk_icon_view_queue_draw_item (icon_view, item);
3180 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3181 GtkIconViewItem *item)
3186 gtk_widget_style_get (GTK_WIDGET (icon_view),
3187 "focus-line-width", &focus_width,
3190 rect.x = item->x - focus_width;
3191 rect.y = item->y - focus_width;
3192 rect.width = item->width + 2 * focus_width;
3193 rect.height = item->height + 2 * focus_width;
3195 if (icon_view->priv->bin_window)
3196 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3200 layout_callback (gpointer user_data)
3202 GtkIconView *icon_view;
3204 icon_view = GTK_ICON_VIEW (user_data);
3206 icon_view->priv->layout_idle_id = 0;
3208 gtk_icon_view_layout (icon_view);
3214 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3216 if (icon_view->priv->layout_idle_id != 0)
3219 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3223 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3224 GtkIconViewItem *item,
3228 AtkObject *item_obj;
3229 AtkObject *cursor_item_obj;
3231 if (icon_view->priv->cursor_item == item &&
3232 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3235 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3236 if (icon_view->priv->cursor_item != NULL)
3238 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3241 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3242 if (cursor_item_obj != NULL)
3243 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3246 icon_view->priv->cursor_item = item;
3247 if (cursor_cell >= 0)
3248 icon_view->priv->cursor_cell = cursor_cell;
3250 gtk_icon_view_queue_draw_item (icon_view, item);
3252 /* Notify that accessible focus object has changed */
3253 item_obj = atk_object_ref_accessible_child (obj, item->index);
3255 if (item_obj != NULL)
3257 atk_focus_tracker_notify (item_obj);
3258 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3259 g_object_unref (item_obj);
3264 static GtkIconViewItem *
3265 gtk_icon_view_item_new (void)
3267 GtkIconViewItem *item;
3269 item = g_new0 (GtkIconViewItem, 1);
3278 gtk_icon_view_item_free (GtkIconViewItem *item)
3280 g_return_if_fail (item != NULL);
3282 g_free (item->before);
3283 g_free (item->after);
3290 static GtkIconViewItem *
3291 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3294 gboolean only_in_cell,
3295 GtkIconViewCellInfo **cell_at_pos)
3300 for (items = icon_view->priv->items; items; items = items->next)
3302 GtkIconViewItem *item = items->data;
3304 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3305 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3307 if (only_in_cell || cell_at_pos)
3309 gtk_icon_view_set_cell_data (icon_view, item);
3311 for (l = icon_view->priv->cell_list; l; l = l->next)
3313 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3315 if (!info->cell->visible)
3318 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3320 if ((x >= box.x && x <= box.x + box.width &&
3321 y >= box.y && y <= box.y + box.height) ||
3323 x <= box.x + box.width &&
3325 y <= box.y + box.height))
3328 *cell_at_pos = info;
3338 *cell_at_pos = NULL;
3349 gtk_icon_view_select_item (GtkIconView *icon_view,
3350 GtkIconViewItem *item)
3352 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3353 g_return_if_fail (item != NULL);
3358 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3360 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3361 gtk_icon_view_unselect_all_internal (icon_view);
3363 item->selected = TRUE;
3365 gtk_icon_view_item_selected_changed (icon_view, item);
3366 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3368 gtk_icon_view_queue_draw_item (icon_view, item);
3373 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3374 GtkIconViewItem *item)
3376 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3377 g_return_if_fail (item != NULL);
3379 if (!item->selected)
3382 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3383 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3386 item->selected = FALSE;
3388 gtk_icon_view_item_selected_changed (icon_view, item);
3389 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3391 gtk_icon_view_queue_draw_item (icon_view, item);
3395 verify_items (GtkIconView *icon_view)
3400 for (items = icon_view->priv->items; items; items = items->next)
3402 GtkIconViewItem *item = items->data;
3404 if (item->index != i)
3405 g_error ("List item does not match its index: "
3406 "item index %d and list index %d\n", item->index, i);
3413 gtk_icon_view_row_changed (GtkTreeModel *model,
3418 GtkIconViewItem *item;
3420 GtkIconView *icon_view;
3422 icon_view = GTK_ICON_VIEW (data);
3424 gtk_icon_view_stop_editing (icon_view, TRUE);
3426 index = gtk_tree_path_get_indices(path)[0];
3427 item = g_list_nth_data (icon_view->priv->items, index);
3429 gtk_icon_view_item_invalidate_size (item);
3430 gtk_icon_view_queue_layout (icon_view);
3432 verify_items (icon_view);
3436 gtk_icon_view_row_inserted (GtkTreeModel *model,
3442 GtkIconViewItem *item;
3443 gboolean iters_persist;
3444 GtkIconView *icon_view;
3447 icon_view = GTK_ICON_VIEW (data);
3449 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3451 index = gtk_tree_path_get_indices(path)[0];
3453 item = gtk_icon_view_item_new ();
3458 item->index = index;
3460 /* FIXME: We can be more efficient here,
3461 we can store a tail pointer and use that when
3462 appending (which is a rather common operation)
3464 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3467 list = g_list_nth (icon_view->priv->items, index + 1);
3468 for (; list; list = list->next)
3475 verify_items (icon_view);
3477 gtk_icon_view_queue_layout (icon_view);
3481 gtk_icon_view_row_deleted (GtkTreeModel *model,
3486 GtkIconView *icon_view;
3487 GtkIconViewItem *item;
3489 gboolean emit = FALSE;
3491 icon_view = GTK_ICON_VIEW (data);
3493 index = gtk_tree_path_get_indices(path)[0];
3495 list = g_list_nth (icon_view->priv->items, index);
3498 gtk_icon_view_stop_editing (icon_view, TRUE);
3500 if (item == icon_view->priv->anchor_item)
3501 icon_view->priv->anchor_item = NULL;
3503 if (item == icon_view->priv->cursor_item)
3504 icon_view->priv->cursor_item = NULL;
3509 gtk_icon_view_item_free (item);
3511 for (next = list->next; next; next = next->next)
3518 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3520 verify_items (icon_view);
3522 gtk_icon_view_queue_layout (icon_view);
3525 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3529 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3530 GtkTreePath *parent,
3537 GtkIconView *icon_view;
3538 GList *items = NULL, *list;
3539 GtkIconViewItem **item_array;
3542 icon_view = GTK_ICON_VIEW (data);
3544 gtk_icon_view_stop_editing (icon_view, TRUE);
3546 length = gtk_tree_model_iter_n_children (model, NULL);
3548 order = g_new (gint, length);
3549 for (i = 0; i < length; i++)
3550 order [new_order[i]] = i;
3552 item_array = g_new (GtkIconViewItem *, length);
3553 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3554 item_array[order[i]] = list->data;
3557 for (i = length - 1; i >= 0; i--)
3559 item_array[i]->index = i;
3560 items = g_list_prepend (items, item_array[i]);
3563 g_free (item_array);
3564 g_list_free (icon_view->priv->items);
3565 icon_view->priv->items = items;
3567 gtk_icon_view_queue_layout (icon_view);
3569 verify_items (icon_view);
3573 gtk_icon_view_build_items (GtkIconView *icon_view)
3577 gboolean iters_persist;
3578 GList *items = NULL;
3580 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3582 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3590 GtkIconViewItem *item = gtk_icon_view_item_new ();
3599 items = g_list_prepend (items, item);
3601 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3603 icon_view->priv->items = g_list_reverse (items);
3607 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3610 GtkMovementStep step,
3614 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3615 I_("move-cursor"), 2,
3619 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3624 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3627 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3632 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3639 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3640 GtkMovementStep step,
3643 GdkModifierType state;
3645 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3646 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3647 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3648 step == GTK_MOVEMENT_DISPLAY_LINES ||
3649 step == GTK_MOVEMENT_PAGES ||
3650 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3652 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3655 gtk_icon_view_stop_editing (icon_view, FALSE);
3656 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3658 if (gtk_get_current_event_state (&state))
3660 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3661 icon_view->priv->ctrl_pressed = TRUE;
3662 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3663 icon_view->priv->shift_pressed = TRUE;
3665 /* else we assume not pressed */
3669 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3670 case GTK_MOVEMENT_VISUAL_POSITIONS:
3671 gtk_icon_view_move_cursor_left_right (icon_view, count);
3673 case GTK_MOVEMENT_DISPLAY_LINES:
3674 gtk_icon_view_move_cursor_up_down (icon_view, count);
3676 case GTK_MOVEMENT_PAGES:
3677 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3679 case GTK_MOVEMENT_BUFFER_ENDS:
3680 gtk_icon_view_move_cursor_start_end (icon_view, count);
3683 g_assert_not_reached ();
3686 icon_view->priv->ctrl_pressed = FALSE;
3687 icon_view->priv->shift_pressed = FALSE;
3692 static GtkIconViewItem *
3693 find_item (GtkIconView *icon_view,
3694 GtkIconViewItem *current,
3700 GtkIconViewItem *item;
3702 /* FIXME: this could be more efficient
3704 row = current->row + row_ofs;
3705 col = current->col + col_ofs;
3707 for (items = icon_view->priv->items; items; items = items->next)
3710 if (item->row == row && item->col == col)
3718 find_cell (GtkIconView *icon_view,
3719 GtkIconViewItem *item,
3721 GtkOrientation orientation,
3732 if (icon_view->priv->orientation != orientation)
3735 gtk_icon_view_set_cell_data (icon_view, item);
3737 focusable = g_new0 (gint, icon_view->priv->n_cells);
3742 for (k = 0; k < 2; k++)
3743 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3745 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3747 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3750 if (!info->cell->visible)
3753 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3756 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3759 current = n_focusable;
3761 focusable[n_focusable] = i;
3767 if (n_focusable == 0)
3768 focusable[n_focusable++] = first_text;
3772 current = step > 0 ? 0 : n_focusable - 1;
3773 cell = focusable[current];
3776 if (current + *count < 0)
3779 *count = current + *count;
3781 else if (current + *count > n_focusable - 1)
3784 *count = current + *count - (n_focusable - 1);
3788 cell = focusable[current + *count];
3797 static GtkIconViewItem *
3798 find_item_page_up_down (GtkIconView *icon_view,
3799 GtkIconViewItem *current,
3806 y = current->y + count * icon_view->priv->vadjustment->page_size;
3808 item = g_list_find (icon_view->priv->items, current);
3813 for (next = item->next; next; next = next->next)
3815 if (((GtkIconViewItem *)next->data)->col == col)
3818 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3828 for (next = item->prev; next; next = next->prev)
3830 if (((GtkIconViewItem *)next->data)->col == col)
3833 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3847 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3848 GtkIconViewItem *anchor,
3849 GtkIconViewItem *cursor)
3852 GtkIconViewItem *item;
3853 gint row1, row2, col1, col2;
3854 gboolean dirty = FALSE;
3856 if (anchor->row < cursor->row)
3867 if (anchor->col < cursor->col)
3878 for (items = icon_view->priv->items; items; items = items->next)
3882 if (row1 <= item->row && item->row <= row2 &&
3883 col1 <= item->col && item->col <= col2)
3885 if (!item->selected)
3888 item->selected = TRUE;
3889 gtk_icon_view_item_selected_changed (icon_view, item);
3891 gtk_icon_view_queue_draw_item (icon_view, item);
3899 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3902 GtkIconViewItem *item;
3904 gboolean dirty = FALSE;
3907 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3910 if (!icon_view->priv->cursor_item)
3915 list = icon_view->priv->items;
3917 list = g_list_last (icon_view->priv->items);
3919 item = list ? list->data : NULL;
3924 item = icon_view->priv->cursor_item;
3925 cell = icon_view->priv->cursor_cell;
3926 step = count > 0 ? 1 : -1;
3929 cell = find_cell (icon_view, item, cell,
3930 GTK_ORIENTATION_VERTICAL,
3935 item = find_item (icon_view, item, step, 0);
3936 count = count - step;
3942 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3946 if (icon_view->priv->ctrl_pressed ||
3947 !icon_view->priv->shift_pressed ||
3948 !icon_view->priv->anchor_item ||
3949 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3950 icon_view->priv->anchor_item = item;
3952 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3954 if (!icon_view->priv->ctrl_pressed &&
3955 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3957 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3958 dirty = gtk_icon_view_select_all_between (icon_view,
3959 icon_view->priv->anchor_item,
3963 gtk_icon_view_scroll_to_item (icon_view, item);
3966 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3970 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3973 GtkIconViewItem *item;
3974 gboolean dirty = FALSE;
3976 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3979 if (!icon_view->priv->cursor_item)
3984 list = icon_view->priv->items;
3986 list = g_list_last (icon_view->priv->items);
3988 item = list ? list->data : NULL;
3991 item = find_item_page_up_down (icon_view,
3992 icon_view->priv->cursor_item,
3995 if (item == icon_view->priv->cursor_item)
3996 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4001 if (icon_view->priv->ctrl_pressed ||
4002 !icon_view->priv->shift_pressed ||
4003 !icon_view->priv->anchor_item ||
4004 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4005 icon_view->priv->anchor_item = item;
4007 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4009 if (!icon_view->priv->ctrl_pressed &&
4010 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4012 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4013 dirty = gtk_icon_view_select_all_between (icon_view,
4014 icon_view->priv->anchor_item,
4018 gtk_icon_view_scroll_to_item (icon_view, item);
4021 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4025 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4028 GtkIconViewItem *item;
4030 gboolean dirty = FALSE;
4033 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4036 if (!icon_view->priv->cursor_item)
4041 list = icon_view->priv->items;
4043 list = g_list_last (icon_view->priv->items);
4045 item = list ? list->data : NULL;
4049 item = icon_view->priv->cursor_item;
4050 cell = icon_view->priv->cursor_cell;
4051 step = count > 0 ? 1 : -1;
4054 cell = find_cell (icon_view, item, cell,
4055 GTK_ORIENTATION_HORIZONTAL,
4060 item = find_item (icon_view, item, 0, step);
4061 count = count - step;
4067 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4071 if (icon_view->priv->ctrl_pressed ||
4072 !icon_view->priv->shift_pressed ||
4073 !icon_view->priv->anchor_item ||
4074 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4075 icon_view->priv->anchor_item = item;
4077 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4079 if (!icon_view->priv->ctrl_pressed &&
4080 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4082 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4083 dirty = gtk_icon_view_select_all_between (icon_view,
4084 icon_view->priv->anchor_item,
4088 gtk_icon_view_scroll_to_item (icon_view, item);
4091 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4095 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4098 GtkIconViewItem *item;
4100 gboolean dirty = FALSE;
4102 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4106 list = icon_view->priv->items;
4108 list = g_list_last (icon_view->priv->items);
4110 item = list ? list->data : NULL;
4112 if (item == icon_view->priv->cursor_item)
4113 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4118 if (icon_view->priv->ctrl_pressed ||
4119 !icon_view->priv->shift_pressed ||
4120 !icon_view->priv->anchor_item ||
4121 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4122 icon_view->priv->anchor_item = item;
4124 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4126 if (!icon_view->priv->ctrl_pressed &&
4127 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4129 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4130 dirty = gtk_icon_view_select_all_between (icon_view,
4131 icon_view->priv->anchor_item,
4135 gtk_icon_view_scroll_to_item (icon_view, item);
4138 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4142 * gtk_icon_view_scroll_to_path:
4143 * @icon_view: A #GtkIconView.
4144 * @path: The path of the item to move to.
4145 * @use_align: whether to use alignment arguments, or %FALSE.
4146 * @row_align: The vertical alignment of the item specified by @path.
4147 * @col_align: The horizontal alignment of the item specified by @path.
4149 * Moves the alignments of @icon_view to the position specified by @path.
4150 * @row_align determines where the row is placed, and @col_align determines
4151 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4152 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4155 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4156 * tree does the minimum amount of work to scroll the item onto the screen.
4157 * This means that the item will be scrolled to the edge closest to its current
4158 * position. If the item is currently visible on the screen, nothing is done.
4160 * This function only works if the model is set, and @path is a valid row on
4161 * the model. If the model changes before the @icon_view is realized, the
4162 * centered path will be modified to reflect this change.
4167 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4173 GtkIconViewItem *item = NULL;
4175 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4176 g_return_if_fail (path != NULL);
4177 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4178 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4180 if (gtk_tree_path_get_depth (path) > 0)
4181 item = g_list_nth_data (icon_view->priv->items,
4182 gtk_tree_path_get_indices(path)[0]);
4184 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4186 if (icon_view->priv->scroll_to_path)
4187 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4189 icon_view->priv->scroll_to_path = NULL;
4192 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4194 icon_view->priv->scroll_to_use_align = use_align;
4195 icon_view->priv->scroll_to_row_align = row_align;
4196 icon_view->priv->scroll_to_col_align = col_align;
4207 gtk_widget_style_get (GTK_WIDGET (icon_view),
4208 "focus-line-width", &focus_width,
4211 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4213 offset = y + item->y - focus_width -
4214 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4216 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4217 icon_view->priv->vadjustment->value + offset);
4219 offset = x + item->x - focus_width -
4220 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4222 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4223 icon_view->priv->hadjustment->value + offset);
4225 gtk_adjustment_changed (icon_view->priv->hadjustment);
4226 gtk_adjustment_changed (icon_view->priv->vadjustment);
4229 gtk_icon_view_scroll_to_item (icon_view, item);
4234 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4235 GtkIconViewItem *item)
4237 gint x, y, width, height;
4240 gtk_widget_style_get (GTK_WIDGET (icon_view),
4241 "focus-line-width", &focus_width,
4244 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4246 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4248 if (y + item->y - focus_width < 0)
4249 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4250 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4251 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4252 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4253 icon_view->priv->vadjustment->value + y + item->y + item->height
4254 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4256 if (x + item->x - focus_width < 0)
4257 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4258 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4259 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4260 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4261 icon_view->priv->hadjustment->value + x + item->x + item->width
4262 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4264 gtk_adjustment_changed (icon_view->priv->hadjustment);
4265 gtk_adjustment_changed (icon_view->priv->vadjustment);
4268 /* GtkCellLayout implementation */
4269 static GtkIconViewCellInfo *
4270 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4271 GtkCellRenderer *renderer)
4275 for (i = icon_view->priv->cell_list; i; i = i->next)
4277 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4279 if (info->cell == renderer)
4287 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4288 GtkIconViewItem *item)
4291 gboolean iters_persist;
4294 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4300 path = gtk_tree_path_new_from_indices (item->index, -1);
4301 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4303 gtk_tree_path_free (path);
4308 for (i = icon_view->priv->cell_list; i; i = i->next)
4311 GtkIconViewCellInfo *info = i->data;
4313 g_object_freeze_notify (G_OBJECT (info->cell));
4315 for (j = info->attributes; j && j->next; j = j->next->next)
4317 gchar *property = j->data;
4318 gint column = GPOINTER_TO_INT (j->next->data);
4319 GValue value = {0, };
4321 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4323 g_object_set_property (G_OBJECT (info->cell),
4325 g_value_unset (&value);
4329 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4331 icon_view->priv->model,
4335 g_object_thaw_notify (G_OBJECT (info->cell));
4340 free_cell_attributes (GtkIconViewCellInfo *info)
4344 list = info->attributes;
4345 while (list && list->next)
4347 g_free (list->data);
4348 list = list->next->next;
4351 g_slist_free (info->attributes);
4352 info->attributes = NULL;
4356 free_cell_info (GtkIconViewCellInfo *info)
4358 free_cell_attributes (info);
4360 g_object_unref (info->cell);
4363 (* info->destroy) (info->func_data);
4369 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4370 GtkCellRenderer *renderer,
4373 GtkIconViewCellInfo *info;
4374 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4376 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4377 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4379 g_object_ref_sink (renderer);
4381 info = g_new0 (GtkIconViewCellInfo, 1);
4382 info->cell = renderer;
4383 info->expand = expand ? TRUE : FALSE;
4384 info->pack = GTK_PACK_START;
4385 info->position = icon_view->priv->n_cells;
4387 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4388 icon_view->priv->n_cells++;
4392 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4393 GtkCellRenderer *renderer,
4396 GtkIconViewCellInfo *info;
4397 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4399 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4400 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4402 g_object_ref_sink (renderer);
4404 info = g_new0 (GtkIconViewCellInfo, 1);
4405 info->cell = renderer;
4406 info->expand = expand ? TRUE : FALSE;
4407 info->pack = GTK_PACK_END;
4408 info->position = icon_view->priv->n_cells;
4410 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4411 icon_view->priv->n_cells++;
4415 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4416 GtkCellRenderer *renderer,
4417 const gchar *attribute,
4420 GtkIconViewCellInfo *info;
4421 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4423 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4424 g_return_if_fail (info != NULL);
4426 info->attributes = g_slist_prepend (info->attributes,
4427 GINT_TO_POINTER (column));
4428 info->attributes = g_slist_prepend (info->attributes,
4429 g_strdup (attribute));
4433 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4435 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4437 while (icon_view->priv->cell_list)
4439 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4440 free_cell_info (info);
4441 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4442 icon_view->priv->cell_list);
4445 icon_view->priv->n_cells = 0;
4449 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4450 GtkCellRenderer *cell,
4451 GtkCellLayoutDataFunc func,
4453 GDestroyNotify destroy)
4455 GtkIconViewCellInfo *info;
4456 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4458 info = gtk_icon_view_get_cell_info (icon_view, cell);
4459 g_return_if_fail (info != NULL);
4463 GDestroyNotify d = info->destroy;
4465 info->destroy = NULL;
4466 d (info->func_data);
4470 info->func_data = func_data;
4471 info->destroy = destroy;
4475 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4476 GtkCellRenderer *renderer)
4478 GtkIconViewCellInfo *info;
4480 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4482 free_cell_attributes (info);
4486 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4487 GtkCellRenderer *cell,
4490 GtkIconView *icon_view;
4492 GtkIconViewCellInfo *info;
4495 icon_view = GTK_ICON_VIEW (layout);
4497 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4499 info = gtk_icon_view_get_cell_info (icon_view, cell);
4501 g_return_if_fail (info != NULL);
4502 g_return_if_fail (position >= 0);
4504 link = g_list_find (icon_view->priv->cell_list, info);
4506 g_return_if_fail (link != NULL);
4508 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4510 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4513 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4520 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4524 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4526 GtkIconView *icon_view = (GtkIconView *)layout;
4527 GList *retval = NULL, *l;
4529 for (l = icon_view->priv->cell_list; l; l = l->next)
4531 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4533 retval = g_list_prepend (retval, info->cell);
4536 return g_list_reverse (retval);
4543 * gtk_icon_view_new:
4545 * Creates a new #GtkIconView widget
4547 * Return value: A newly created #GtkIconView widget
4552 gtk_icon_view_new (void)
4554 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4558 * gtk_icon_view_new_with_model:
4559 * @model: The model.
4561 * Creates a new #GtkIconView widget with the model @model.
4563 * Return value: A newly created #GtkIconView widget.
4568 gtk_icon_view_new_with_model (GtkTreeModel *model)
4570 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4574 * gtk_icon_view_convert_widget_to_bin_window_coords:
4575 * @icon_view: a #GtkIconView
4576 * @wx: X coordinate relative to the widget
4577 * @wy: Y coordinate relative to the widget
4578 * @bx: return location for bin_window X coordinate
4579 * @by: return location for bin_window Y coordinate
4581 * Converts widget coordinates to coordinates for the bin_window,
4582 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4587 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4595 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4597 if (icon_view->priv->bin_window)
4598 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4609 * gtk_icon_view_get_path_at_pos:
4610 * @icon_view: A #GtkIconView.
4611 * @x: The x position to be identified
4612 * @y: The y position to be identified
4614 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4615 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4616 * the cell at the specified position.
4617 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4618 * widget coordinates to bin_window coordinates.
4620 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4621 * if no icon exists at that position.
4626 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4630 GtkIconViewItem *item;
4633 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4635 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4640 path = gtk_tree_path_new_from_indices (item->index, -1);
4646 * gtk_icon_view_get_item_at_pos:
4647 * @icon_view: A #GtkIconView.
4648 * @x: The x position to be identified
4649 * @y: The y position to be identified
4650 * @path: Return location for the path, or %NULL
4651 * @cell: Return location for the renderer responsible for the cell
4652 * at (@x, @y), or %NULL
4654 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4655 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4656 * obtains the cell at the specified position. The returned path should
4657 * be freed with gtk_tree_path_free().
4658 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4659 * widget coordinates to bin_window coordinates.
4661 * Return value: %TRUE if an item exists at the specified position
4666 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4670 GtkCellRenderer **cell)
4672 GtkIconViewItem *item;
4673 GtkIconViewCellInfo *info;
4675 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4677 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4682 *path = gtk_tree_path_new_from_indices (item->index, -1);
4695 return (item != NULL);
4699 * gtk_icon_view_set_tooltip_item:
4700 * @icon_view: a #GtkIconView
4701 * @tooltip: a #GtkTooltip
4702 * @path: a #GtkTreePath
4704 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4705 * See also gtk_tooltip_set_tip_area().
4710 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4711 GtkTooltip *tooltip,
4714 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4715 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4717 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4721 * gtk_icon_view_set_tooltip_cell:
4722 * @icon_view: a #GtkIconView
4723 * @tooltip: a #GtkTooltip
4724 * @path: a #GtkTreePath
4725 * @cell: a #GtkCellRenderer or %NULL
4727 * Sets the tip area of @tooltip to the area which @cell occupies in
4728 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4733 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4734 GtkTooltip *tooltip,
4736 GtkCellRenderer *cell)
4739 GtkIconViewItem *item = NULL;
4740 GtkIconViewCellInfo *info = NULL;
4743 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4744 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4745 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4747 if (gtk_tree_path_get_depth (path) > 0)
4748 item = g_list_nth_data (icon_view->priv->items,
4749 gtk_tree_path_get_indices(path)[0]);
4756 info = gtk_icon_view_get_cell_info (icon_view, cell);
4757 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4763 rect.width = item->width;
4764 rect.height = item->height;
4767 if (icon_view->priv->bin_window)
4769 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4774 gtk_tooltip_set_tip_area (tooltip, &rect);
4779 * gtk_icon_view_get_tooltip_context:
4780 * @icon_view: an #GtkIconView
4781 * @x: the x coordinate (relative to widget coordinates)
4782 * @y: the y coordinate (relative to widget coordinates)
4783 * @keyboard_tip: whether this is a keyboard tooltip or not
4784 * @model: a pointer to receive a #GtkTreeModel or %NULL
4785 * @path: a pointer to receive a #GtkTreePath or %NULL
4786 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4788 * This function is supposed to be used in a #GtkWidget::query-tooltip
4789 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4790 * which are received in the signal handler, should be passed to this
4791 * function without modification.
4793 * The return value indicates whether there is an icon view item at the given
4794 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4795 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4796 * @model, @path and @iter which have been provided will be set to point to
4797 * that row and the corresponding model. @x and @y will always be converted
4798 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4800 * Return value: whether or not the given tooltip context points to a item
4805 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4808 gboolean keyboard_tip,
4809 GtkTreeModel **model,
4813 GtkTreePath *tmppath = NULL;
4815 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4816 g_return_val_if_fail (x != NULL, FALSE);
4817 g_return_val_if_fail (y != NULL, FALSE);
4821 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4828 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4831 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4836 *model = gtk_icon_view_get_model (icon_view);
4839 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4845 gtk_tree_path_free (tmppath);
4851 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4854 gboolean keyboard_tip,
4855 GtkTooltip *tooltip,
4861 GtkTreeModel *model;
4862 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4864 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4867 &model, &path, &iter))
4870 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4874 gtk_tree_path_free (path);
4878 gtk_tooltip_set_markup (tooltip, str);
4879 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4881 gtk_tree_path_free (path);
4889 * gtk_icon_view_set_tooltip_column:
4890 * @icon_view: a #GtkIconView
4891 * @column: an integer, which is a valid column number for @icon_view's model
4893 * If you only plan to have simple (text-only) tooltips on full items, you
4894 * can use this function to have #GtkIconView handle these automatically
4895 * for you. @column should be set to the column in @icon_view's model
4896 * containing the tooltip texts, or -1 to disable this feature.
4898 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4899 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4904 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4907 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4909 if (column == icon_view->priv->tooltip_column)
4914 g_signal_handlers_disconnect_by_func (icon_view,
4915 gtk_icon_view_set_tooltip_query_cb,
4917 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4921 if (icon_view->priv->tooltip_column == -1)
4923 g_signal_connect (icon_view, "query-tooltip",
4924 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4925 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4929 icon_view->priv->tooltip_column = column;
4930 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4934 * gtk_icon_view_get_tooltip_column:
4935 * @icon_view: a #GtkIconView
4937 * Returns the column of @icon_view's model which is being used for
4938 * displaying tooltips on @icon_view's rows.
4940 * Return value: the index of the tooltip column that is currently being
4941 * used, or -1 if this is disabled.
4946 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4948 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4950 return icon_view->priv->tooltip_column;
4954 * gtk_icon_view_get_visible_range:
4955 * @icon_view: A #GtkIconView
4956 * @start_path: Return location for start of region, or %NULL
4957 * @end_path: Return location for end of region, or %NULL
4959 * Sets @start_path and @end_path to be the first and last visible path.
4960 * Note that there may be invisible paths in between.
4962 * Both paths should be freed with gtk_tree_path_free() after use.
4964 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4969 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4970 GtkTreePath **start_path,
4971 GtkTreePath **end_path)
4973 gint start_index = -1;
4974 gint end_index = -1;
4977 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4979 if (icon_view->priv->hadjustment == NULL ||
4980 icon_view->priv->vadjustment == NULL)
4983 if (start_path == NULL && end_path == NULL)
4986 for (icons = icon_view->priv->items; icons; icons = icons->next)
4988 GtkIconViewItem *item = icons->data;
4990 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4991 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4992 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4993 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4995 if (start_index == -1)
4996 start_index = item->index;
4997 end_index = item->index;
5001 if (start_path && start_index != -1)
5002 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5003 if (end_path && end_index != -1)
5004 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5006 return start_index != -1;
5010 * gtk_icon_view_selected_foreach:
5011 * @icon_view: A #GtkIconView.
5012 * @func: The funcion to call for each selected icon.
5013 * @data: User data to pass to the function.
5015 * Calls a function for each selected icon. Note that the model or
5016 * selection cannot be modified from within this function.
5021 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5022 GtkIconViewForeachFunc func,
5027 for (list = icon_view->priv->items; list; list = list->next)
5029 GtkIconViewItem *item = list->data;
5030 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5033 (* func) (icon_view, path, data);
5035 gtk_tree_path_free (path);
5040 * gtk_icon_view_set_selection_mode:
5041 * @icon_view: A #GtkIconView.
5042 * @mode: The selection mode
5044 * Sets the selection mode of the @icon_view.
5049 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5050 GtkSelectionMode mode)
5052 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5054 if (mode == icon_view->priv->selection_mode)
5057 if (mode == GTK_SELECTION_NONE ||
5058 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5059 gtk_icon_view_unselect_all (icon_view);
5061 icon_view->priv->selection_mode = mode;
5063 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5067 * gtk_icon_view_get_selection_mode:
5068 * @icon_view: A #GtkIconView.
5070 * Gets the selection mode of the @icon_view.
5072 * Return value: the current selection mode
5077 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5079 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5081 return icon_view->priv->selection_mode;
5085 * gtk_icon_view_set_model:
5086 * @icon_view: A #GtkIconView.
5087 * @model: The model.
5089 * Sets the model for a #GtkIconView.
5090 * If the @icon_view already has a model set, it will remove
5091 * it before setting the new model. If @model is %NULL, then
5092 * it will unset the old model.
5097 gtk_icon_view_set_model (GtkIconView *icon_view,
5098 GtkTreeModel *model)
5100 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5101 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5103 if (icon_view->priv->model == model)
5106 if (icon_view->priv->scroll_to_path)
5108 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5109 icon_view->priv->scroll_to_path = NULL;
5112 gtk_icon_view_stop_editing (icon_view, TRUE);
5118 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5120 if (icon_view->priv->pixbuf_column != -1)
5122 column_type = gtk_tree_model_get_column_type (model,
5123 icon_view->priv->pixbuf_column);
5125 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5128 if (icon_view->priv->text_column != -1)
5130 column_type = gtk_tree_model_get_column_type (model,
5131 icon_view->priv->text_column);
5133 g_return_if_fail (column_type == G_TYPE_STRING);
5136 if (icon_view->priv->markup_column != -1)
5138 column_type = gtk_tree_model_get_column_type (model,
5139 icon_view->priv->markup_column);
5141 g_return_if_fail (column_type == G_TYPE_STRING);
5146 if (icon_view->priv->model)
5148 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5149 gtk_icon_view_row_changed,
5151 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5152 gtk_icon_view_row_inserted,
5154 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5155 gtk_icon_view_row_deleted,
5157 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5158 gtk_icon_view_rows_reordered,
5161 g_object_unref (icon_view->priv->model);
5163 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5164 g_list_free (icon_view->priv->items);
5165 icon_view->priv->items = NULL;
5166 icon_view->priv->anchor_item = NULL;
5167 icon_view->priv->cursor_item = NULL;
5168 icon_view->priv->last_single_clicked = NULL;
5169 icon_view->priv->width = 0;
5170 icon_view->priv->height = 0;
5173 icon_view->priv->model = model;
5175 if (icon_view->priv->model)
5177 g_object_ref (icon_view->priv->model);
5178 g_signal_connect (icon_view->priv->model,
5180 G_CALLBACK (gtk_icon_view_row_changed),
5182 g_signal_connect (icon_view->priv->model,
5184 G_CALLBACK (gtk_icon_view_row_inserted),
5186 g_signal_connect (icon_view->priv->model,
5188 G_CALLBACK (gtk_icon_view_row_deleted),
5190 g_signal_connect (icon_view->priv->model,
5192 G_CALLBACK (gtk_icon_view_rows_reordered),
5195 gtk_icon_view_build_items (icon_view);
5197 gtk_icon_view_queue_layout (icon_view);
5200 g_object_notify (G_OBJECT (icon_view), "model");
5202 if (GTK_WIDGET_REALIZED (icon_view))
5203 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5207 * gtk_icon_view_get_model:
5208 * @icon_view: a #GtkIconView
5210 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5213 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5218 gtk_icon_view_get_model (GtkIconView *icon_view)
5220 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5222 return icon_view->priv->model;
5226 update_text_cell (GtkIconView *icon_view)
5228 GtkIconViewCellInfo *info;
5232 if (icon_view->priv->text_column == -1 &&
5233 icon_view->priv->markup_column == -1)
5235 if (icon_view->priv->text_cell != -1)
5237 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5238 icon_view->priv->pixbuf_cell--;
5240 info = g_list_nth_data (icon_view->priv->cell_list,
5241 icon_view->priv->text_cell);
5243 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5245 free_cell_info (info);
5247 icon_view->priv->n_cells--;
5248 icon_view->priv->text_cell = -1;
5253 if (icon_view->priv->text_cell == -1)
5255 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5256 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5257 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5260 if (info->cell == cell)
5262 icon_view->priv->text_cell = i;
5268 info = g_list_nth_data (icon_view->priv->cell_list,
5269 icon_view->priv->text_cell);
5271 if (icon_view->priv->markup_column != -1)
5272 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5274 "markup", icon_view->priv->markup_column,
5277 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5279 "text", icon_view->priv->text_column,
5282 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5283 g_object_set (info->cell,
5284 "alignment", PANGO_ALIGN_CENTER,
5285 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5290 g_object_set (info->cell,
5291 "alignment", PANGO_ALIGN_LEFT,
5292 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5300 update_pixbuf_cell (GtkIconView *icon_view)
5302 GtkIconViewCellInfo *info;
5306 if (icon_view->priv->pixbuf_column == -1)
5308 if (icon_view->priv->pixbuf_cell != -1)
5310 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5311 icon_view->priv->text_cell--;
5313 info = g_list_nth_data (icon_view->priv->cell_list,
5314 icon_view->priv->pixbuf_cell);
5316 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5318 free_cell_info (info);
5320 icon_view->priv->n_cells--;
5321 icon_view->priv->pixbuf_cell = -1;
5326 if (icon_view->priv->pixbuf_cell == -1)
5328 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5330 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5331 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5334 if (info->cell == cell)
5336 icon_view->priv->pixbuf_cell = i;
5342 info = g_list_nth_data (icon_view->priv->cell_list,
5343 icon_view->priv->pixbuf_cell);
5345 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5347 "pixbuf", icon_view->priv->pixbuf_column,
5350 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5351 g_object_set (info->cell,
5352 "follow-state", TRUE,
5357 g_object_set (info->cell,
5358 "follow-state", TRUE,
5366 * gtk_icon_view_set_text_column:
5367 * @icon_view: A #GtkIconView.
5368 * @column: A column in the currently used model, or -1 to display no text
5370 * Sets the column with text for @icon_view to be @column. The text
5371 * column must be of type #G_TYPE_STRING.
5376 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5379 if (column == icon_view->priv->text_column)
5383 icon_view->priv->text_column = -1;
5386 if (icon_view->priv->model != NULL)
5390 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5392 g_return_if_fail (column_type == G_TYPE_STRING);
5395 icon_view->priv->text_column = column;
5398 gtk_icon_view_stop_editing (icon_view, TRUE);
5400 update_text_cell (icon_view);
5402 gtk_icon_view_invalidate_sizes (icon_view);
5403 gtk_icon_view_queue_layout (icon_view);
5405 g_object_notify (G_OBJECT (icon_view), "text-column");
5409 * gtk_icon_view_get_text_column:
5410 * @icon_view: A #GtkIconView.
5412 * Returns the column with text for @icon_view.
5414 * Returns: the text column, or -1 if it's unset.
5419 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5421 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5423 return icon_view->priv->text_column;
5427 * gtk_icon_view_set_markup_column:
5428 * @icon_view: A #GtkIconView.
5429 * @column: A column in the currently used model, or -1 to display no text
5431 * Sets the column with markup information for @icon_view to be
5432 * @column. The markup column must be of type #G_TYPE_STRING.
5433 * If the markup column is set to something, it overrides
5434 * the text column set by gtk_icon_view_set_text_column().
5439 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5442 if (column == icon_view->priv->markup_column)
5446 icon_view->priv->markup_column = -1;
5449 if (icon_view->priv->model != NULL)
5453 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5455 g_return_if_fail (column_type == G_TYPE_STRING);
5458 icon_view->priv->markup_column = column;
5461 gtk_icon_view_stop_editing (icon_view, TRUE);
5463 update_text_cell (icon_view);
5465 gtk_icon_view_invalidate_sizes (icon_view);
5466 gtk_icon_view_queue_layout (icon_view);
5468 g_object_notify (G_OBJECT (icon_view), "markup-column");
5472 * gtk_icon_view_get_markup_column:
5473 * @icon_view: A #GtkIconView.
5475 * Returns the column with markup text for @icon_view.
5477 * Returns: the markup column, or -1 if it's unset.
5482 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5484 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5486 return icon_view->priv->markup_column;
5490 * gtk_icon_view_set_pixbuf_column:
5491 * @icon_view: A #GtkIconView.
5492 * @column: A column in the currently used model, or -1 to disable
5494 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5495 * column must be of type #GDK_TYPE_PIXBUF
5500 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5503 if (column == icon_view->priv->pixbuf_column)
5507 icon_view->priv->pixbuf_column = -1;
5510 if (icon_view->priv->model != NULL)
5514 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5516 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5519 icon_view->priv->pixbuf_column = column;
5522 gtk_icon_view_stop_editing (icon_view, TRUE);
5524 update_pixbuf_cell (icon_view);
5526 gtk_icon_view_invalidate_sizes (icon_view);
5527 gtk_icon_view_queue_layout (icon_view);
5529 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5534 * gtk_icon_view_get_pixbuf_column:
5535 * @icon_view: A #GtkIconView.
5537 * Returns the column with pixbufs for @icon_view.
5539 * Returns: the pixbuf column, or -1 if it's unset.
5544 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5546 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5548 return icon_view->priv->pixbuf_column;
5552 * gtk_icon_view_select_path:
5553 * @icon_view: A #GtkIconView.
5554 * @path: The #GtkTreePath to be selected.
5556 * Selects the row at @path.
5561 gtk_icon_view_select_path (GtkIconView *icon_view,
5564 GtkIconViewItem *item = NULL;
5566 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5567 g_return_if_fail (icon_view->priv->model != NULL);
5568 g_return_if_fail (path != NULL);
5570 if (gtk_tree_path_get_depth (path) > 0)
5571 item = g_list_nth_data (icon_view->priv->items,
5572 gtk_tree_path_get_indices(path)[0]);
5575 gtk_icon_view_select_item (icon_view, item);
5579 * gtk_icon_view_unselect_path:
5580 * @icon_view: A #GtkIconView.
5581 * @path: The #GtkTreePath to be unselected.
5583 * Unselects the row at @path.
5588 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5591 GtkIconViewItem *item;
5593 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5594 g_return_if_fail (icon_view->priv->model != NULL);
5595 g_return_if_fail (path != NULL);
5597 item = g_list_nth_data (icon_view->priv->items,
5598 gtk_tree_path_get_indices(path)[0]);
5603 gtk_icon_view_unselect_item (icon_view, item);
5607 * gtk_icon_view_get_selected_items:
5608 * @icon_view: A #GtkIconView.
5610 * Creates a list of paths of all selected items. Additionally, if you are
5611 * planning on modifying the model after calling this function, you may
5612 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5613 * To do this, you can use gtk_tree_row_reference_new().
5615 * To free the return value, use:
5617 * g_list_foreach (list, gtk_tree_path_free, NULL);
5618 * g_list_free (list);
5621 * Return value: A #GList containing a #GtkTreePath for each selected row.
5626 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5629 GList *selected = NULL;
5631 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5633 for (list = icon_view->priv->items; list != NULL; list = list->next)
5635 GtkIconViewItem *item = list->data;
5639 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5641 selected = g_list_prepend (selected, path);
5649 * gtk_icon_view_select_all:
5650 * @icon_view: A #GtkIconView.
5652 * Selects all the icons. @icon_view must has its selection mode set
5653 * to #GTK_SELECTION_MULTIPLE.
5658 gtk_icon_view_select_all (GtkIconView *icon_view)
5661 gboolean dirty = FALSE;
5663 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5665 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5668 for (items = icon_view->priv->items; items; items = items->next)
5670 GtkIconViewItem *item = items->data;
5672 if (!item->selected)
5675 item->selected = TRUE;
5676 gtk_icon_view_queue_draw_item (icon_view, item);
5681 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5685 * gtk_icon_view_unselect_all:
5686 * @icon_view: A #GtkIconView.
5688 * Unselects all the icons.
5693 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5695 gboolean dirty = FALSE;
5697 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5699 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5702 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5705 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5709 * gtk_icon_view_path_is_selected:
5710 * @icon_view: A #GtkIconView.
5711 * @path: A #GtkTreePath to check selection on.
5713 * Returns %TRUE if the icon pointed to by @path is currently
5714 * selected. If @path does not point to a valid location, %FALSE is returned.
5716 * Return value: %TRUE if @path is selected.
5721 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5724 GtkIconViewItem *item;
5726 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5727 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5728 g_return_val_if_fail (path != NULL, FALSE);
5730 item = g_list_nth_data (icon_view->priv->items,
5731 gtk_tree_path_get_indices(path)[0]);
5736 return item->selected;
5740 * gtk_icon_view_item_activated:
5741 * @icon_view: A #GtkIconView
5742 * @path: The #GtkTreePath to be activated
5744 * Activates the item determined by @path.
5749 gtk_icon_view_item_activated (GtkIconView *icon_view,
5752 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5753 g_return_if_fail (path != NULL);
5755 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5759 * gtk_icon_view_set_orientation:
5760 * @icon_view: a #GtkIconView
5761 * @orientation: the relative position of texts and icons
5763 * Sets the ::orientation property which determines whether the labels
5764 * are drawn beside the icons instead of below.
5769 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5770 GtkOrientation orientation)
5772 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5774 if (icon_view->priv->orientation != orientation)
5776 icon_view->priv->orientation = orientation;
5778 gtk_icon_view_stop_editing (icon_view, TRUE);
5779 gtk_icon_view_invalidate_sizes (icon_view);
5780 gtk_icon_view_queue_layout (icon_view);
5782 update_text_cell (icon_view);
5783 update_pixbuf_cell (icon_view);
5785 g_object_notify (G_OBJECT (icon_view), "orientation");
5790 * gtk_icon_view_get_orientation:
5791 * @icon_view: a #GtkIconView
5793 * Returns the value of the ::orientation property which determines
5794 * whether the labels are drawn beside the icons instead of below.
5796 * Return value: the relative position of texts and icons
5801 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5803 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5804 GTK_ORIENTATION_VERTICAL);
5806 return icon_view->priv->orientation;
5810 * gtk_icon_view_set_columns:
5811 * @icon_view: a #GtkIconView
5812 * @columns: the number of columns
5814 * Sets the ::columns property which determines in how
5815 * many columns the icons are arranged. If @columns is
5816 * -1, the number of columns will be chosen automatically
5817 * to fill the available area.
5822 gtk_icon_view_set_columns (GtkIconView *icon_view,
5825 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5827 if (icon_view->priv->columns != columns)
5829 icon_view->priv->columns = columns;
5831 gtk_icon_view_stop_editing (icon_view, TRUE);
5832 gtk_icon_view_queue_layout (icon_view);
5834 g_object_notify (G_OBJECT (icon_view), "columns");
5839 * gtk_icon_view_get_columns:
5840 * @icon_view: a #GtkIconView
5842 * Returns the value of the ::columns property.
5844 * Return value: the number of columns, or -1
5849 gtk_icon_view_get_columns (GtkIconView *icon_view)
5851 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5853 return icon_view->priv->columns;
5857 * gtk_icon_view_set_item_width:
5858 * @icon_view: a #GtkIconView
5859 * @item_width: the width for each item
5861 * Sets the ::item-width property which specifies the width
5862 * to use for each item. If it is set to -1, the icon view will
5863 * automatically determine a suitable item size.
5868 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5871 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5873 if (icon_view->priv->item_width != item_width)
5875 icon_view->priv->item_width = item_width;
5877 gtk_icon_view_stop_editing (icon_view, TRUE);
5878 gtk_icon_view_invalidate_sizes (icon_view);
5879 gtk_icon_view_queue_layout (icon_view);
5881 update_text_cell (icon_view);
5883 g_object_notify (G_OBJECT (icon_view), "item-width");
5888 * gtk_icon_view_get_item_width:
5889 * @icon_view: a #GtkIconView
5891 * Returns the value of the ::item-width property.
5893 * Return value: the width of a single item, or -1
5898 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5900 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5902 return icon_view->priv->item_width;
5907 * gtk_icon_view_set_spacing:
5908 * @icon_view: a #GtkIconView
5909 * @spacing: the spacing
5911 * Sets the ::spacing property which specifies the space
5912 * which is inserted between the cells (i.e. the icon and
5913 * the text) of an item.
5918 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5921 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5923 if (icon_view->priv->spacing != spacing)
5925 icon_view->priv->spacing = spacing;
5927 gtk_icon_view_stop_editing (icon_view, TRUE);
5928 gtk_icon_view_invalidate_sizes (icon_view);
5929 gtk_icon_view_queue_layout (icon_view);
5931 g_object_notify (G_OBJECT (icon_view), "spacing");
5936 * gtk_icon_view_get_spacing:
5937 * @icon_view: a #GtkIconView
5939 * Returns the value of the ::spacing property.
5941 * Return value: the space between cells
5946 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5948 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5950 return icon_view->priv->spacing;
5954 * gtk_icon_view_set_row_spacing:
5955 * @icon_view: a #GtkIconView
5956 * @row_spacing: the row spacing
5958 * Sets the ::row-spacing property which specifies the space
5959 * which is inserted between the rows of the icon view.
5964 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5967 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5969 if (icon_view->priv->row_spacing != row_spacing)
5971 icon_view->priv->row_spacing = row_spacing;
5973 gtk_icon_view_stop_editing (icon_view, TRUE);
5974 gtk_icon_view_invalidate_sizes (icon_view);
5975 gtk_icon_view_queue_layout (icon_view);
5977 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5982 * gtk_icon_view_get_row_spacing:
5983 * @icon_view: a #GtkIconView
5985 * Returns the value of the ::row-spacing property.
5987 * Return value: the space between rows
5992 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5994 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5996 return icon_view->priv->row_spacing;
6000 * gtk_icon_view_set_column_spacing:
6001 * @icon_view: a #GtkIconView
6002 * @column_spacing: the column spacing
6004 * Sets the ::column-spacing property which specifies the space
6005 * which is inserted between the columns of the icon view.
6010 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6011 gint column_spacing)
6013 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6015 if (icon_view->priv->column_spacing != column_spacing)
6017 icon_view->priv->column_spacing = column_spacing;
6019 gtk_icon_view_stop_editing (icon_view, TRUE);
6020 gtk_icon_view_invalidate_sizes (icon_view);
6021 gtk_icon_view_queue_layout (icon_view);
6023 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6028 * gtk_icon_view_get_column_spacing:
6029 * @icon_view: a #GtkIconView
6031 * Returns the value of the ::column-spacing property.
6033 * Return value: the space between columns
6038 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6040 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6042 return icon_view->priv->column_spacing;
6046 * gtk_icon_view_set_margin:
6047 * @icon_view: a #GtkIconView
6048 * @margin: the margin
6050 * Sets the ::margin property which specifies the space
6051 * which is inserted at the top, bottom, left and right
6057 gtk_icon_view_set_margin (GtkIconView *icon_view,
6060 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6062 if (icon_view->priv->margin != margin)
6064 icon_view->priv->margin = margin;
6066 gtk_icon_view_stop_editing (icon_view, TRUE);
6067 gtk_icon_view_invalidate_sizes (icon_view);
6068 gtk_icon_view_queue_layout (icon_view);
6070 g_object_notify (G_OBJECT (icon_view), "margin");
6075 * gtk_icon_view_get_margin:
6076 * @icon_view: a #GtkIconView
6078 * Returns the value of the ::margin property.
6080 * Return value: the space at the borders
6085 gtk_icon_view_get_margin (GtkIconView *icon_view)
6087 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6089 return icon_view->priv->margin;
6093 /* Get/set whether drag_motion requested the drag data and
6094 * drag_data_received should thus not actually insert the data,
6095 * since the data doesn't result from a drop.
6098 set_status_pending (GdkDragContext *context,
6099 GdkDragAction suggested_action)
6101 g_object_set_data (G_OBJECT (context),
6102 I_("gtk-icon-view-status-pending"),
6103 GINT_TO_POINTER (suggested_action));
6106 static GdkDragAction
6107 get_status_pending (GdkDragContext *context)
6109 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6110 "gtk-icon-view-status-pending"));
6114 unset_reorderable (GtkIconView *icon_view)
6116 if (icon_view->priv->reorderable)
6118 icon_view->priv->reorderable = FALSE;
6119 g_object_notify (G_OBJECT (icon_view), "reorderable");
6124 clear_source_info (GtkIconView *icon_view)
6126 if (icon_view->priv->source_targets)
6127 gtk_target_list_unref (icon_view->priv->source_targets);
6128 icon_view->priv->source_targets = NULL;
6130 icon_view->priv->source_set = FALSE;
6134 clear_dest_info (GtkIconView *icon_view)
6136 if (icon_view->priv->dest_targets)
6137 gtk_target_list_unref (icon_view->priv->dest_targets);
6138 icon_view->priv->dest_targets = NULL;
6140 icon_view->priv->dest_set = FALSE;
6144 set_source_row (GdkDragContext *context,
6145 GtkTreeModel *model,
6146 GtkTreePath *source_row)
6149 g_object_set_data_full (G_OBJECT (context),
6150 I_("gtk-icon-view-source-row"),
6151 gtk_tree_row_reference_new (model, source_row),
6152 (GDestroyNotify) gtk_tree_row_reference_free);
6154 g_object_set_data_full (G_OBJECT (context),
6155 I_("gtk-icon-view-source-row"),
6160 get_source_row (GdkDragContext *context)
6162 GtkTreeRowReference *ref;
6164 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6167 return gtk_tree_row_reference_get_path (ref);
6174 GtkTreeRowReference *dest_row;
6175 gboolean empty_view_drop;
6176 gboolean drop_append_mode;
6180 dest_row_free (gpointer data)
6182 DestRow *dr = (DestRow *)data;
6184 gtk_tree_row_reference_free (dr->dest_row);
6189 set_dest_row (GdkDragContext *context,
6190 GtkTreeModel *model,
6191 GtkTreePath *dest_row,
6192 gboolean empty_view_drop,
6193 gboolean drop_append_mode)
6199 g_object_set_data_full (G_OBJECT (context),
6200 I_("gtk-icon-view-dest-row"),
6205 dr = g_new0 (DestRow, 1);
6207 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6208 dr->empty_view_drop = empty_view_drop;
6209 dr->drop_append_mode = drop_append_mode;
6210 g_object_set_data_full (G_OBJECT (context),
6211 I_("gtk-icon-view-dest-row"),
6212 dr, (GDestroyNotify) dest_row_free);
6216 get_dest_row (GdkDragContext *context)
6220 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6224 GtkTreePath *path = NULL;
6227 path = gtk_tree_row_reference_get_path (dr->dest_row);
6228 else if (dr->empty_view_drop)
6229 path = gtk_tree_path_new_from_indices (0, -1);
6233 if (path && dr->drop_append_mode)
6234 gtk_tree_path_next (path);
6243 check_model_dnd (GtkTreeModel *model,
6244 GType required_iface,
6245 const gchar *signal)
6247 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6249 g_warning ("You must override the default '%s' handler "
6250 "on GtkIconView when using models that don't support "
6251 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6252 "is to connect to '%s' and call "
6253 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6254 "the default handler from running. Look at the source code "
6255 "for the default handler in gtkiconview.c to get an idea what "
6256 "your handler should do. (gtkiconview.c is in the GTK+ source "
6257 "code.) If you're using GTK+ from a language other than C, "
6258 "there may be a more natural way to override default handlers, e.g. via derivation.",
6259 signal, g_type_name (required_iface), signal);
6267 remove_scroll_timeout (GtkIconView *icon_view)
6269 if (icon_view->priv->scroll_timeout_id != 0)
6271 g_source_remove (icon_view->priv->scroll_timeout_id);
6273 icon_view->priv->scroll_timeout_id = 0;
6278 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6280 gint px, py, x, y, width, height;
6281 gint hoffset, voffset;
6283 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6284 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6286 /* see if we are near the edge. */
6287 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6289 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6291 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6293 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6296 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6297 icon_view->priv->vadjustment->value + voffset);
6300 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6301 icon_view->priv->hadjustment->value + hoffset);
6306 drag_scroll_timeout (gpointer data)
6308 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6310 gtk_icon_view_autoscroll (icon_view);
6317 set_destination (GtkIconView *icon_view,
6318 GdkDragContext *context,
6321 GdkDragAction *suggested_action,
6325 GtkTreePath *path = NULL;
6326 GtkIconViewDropPosition pos;
6327 GtkIconViewDropPosition old_pos;
6328 GtkTreePath *old_dest_path = NULL;
6329 gboolean can_drop = FALSE;
6331 widget = GTK_WIDGET (icon_view);
6333 *suggested_action = 0;
6336 if (!icon_view->priv->dest_set)
6338 /* someone unset us as a drag dest, note that if
6339 * we return FALSE drag_leave isn't called
6342 gtk_icon_view_set_drag_dest_item (icon_view,
6344 GTK_ICON_VIEW_DROP_LEFT);
6346 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6348 return FALSE; /* no longer a drop site */
6351 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6352 if (*target == GDK_NONE)
6355 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6358 GtkTreeModel *model;
6360 /* the row got dropped on empty space, let's setup a special case
6364 gtk_tree_path_free (path);
6366 model = gtk_icon_view_get_model (icon_view);
6368 n_children = gtk_tree_model_iter_n_children (model, NULL);
6371 pos = GTK_ICON_VIEW_DROP_BELOW;
6372 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6376 pos = GTK_ICON_VIEW_DROP_ABOVE;
6377 path = gtk_tree_path_new_from_indices (0, -1);
6387 gtk_icon_view_get_drag_dest_item (icon_view,
6392 gtk_tree_path_free (old_dest_path);
6394 if (TRUE /* FIXME if the location droppable predicate */)
6402 GtkWidget *source_widget;
6404 *suggested_action = context->suggested_action;
6405 source_widget = gtk_drag_get_source_widget (context);
6407 if (source_widget == widget)
6409 /* Default to MOVE, unless the user has
6410 * pressed ctrl or shift to affect available actions
6412 if ((context->actions & GDK_ACTION_MOVE) != 0)
6413 *suggested_action = GDK_ACTION_MOVE;
6416 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6421 /* can't drop here */
6422 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6424 GTK_ICON_VIEW_DROP_LEFT);
6428 gtk_tree_path_free (path);
6434 get_logical_destination (GtkIconView *icon_view,
6435 gboolean *drop_append_mode)
6437 /* adjust path to point to the row the drop goes in front of */
6438 GtkTreePath *path = NULL;
6439 GtkIconViewDropPosition pos;
6441 *drop_append_mode = FALSE;
6443 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6448 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6449 pos == GTK_ICON_VIEW_DROP_BELOW)
6452 GtkTreeModel *model = icon_view->priv->model;
6454 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6455 !gtk_tree_model_iter_next (model, &iter))
6456 *drop_append_mode = TRUE;
6459 *drop_append_mode = FALSE;
6460 gtk_tree_path_next (path);
6468 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6469 GdkEventMotion *event)
6471 GdkDragContext *context;
6472 GtkTreePath *path = NULL;
6474 GtkTreeModel *model;
6475 gboolean retval = FALSE;
6477 if (!icon_view->priv->source_set)
6480 if (icon_view->priv->pressed_button < 0)
6483 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6484 icon_view->priv->press_start_x,
6485 icon_view->priv->press_start_y,
6486 event->x, event->y))
6489 model = gtk_icon_view_get_model (icon_view);
6494 button = icon_view->priv->pressed_button;
6495 icon_view->priv->pressed_button = -1;
6497 path = gtk_icon_view_get_path_at_pos (icon_view,
6498 icon_view->priv->press_start_x,
6499 icon_view->priv->press_start_y);
6504 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6505 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6509 /* FIXME Check whether we're a start button, if not return FALSE and
6513 /* Now we can begin the drag */
6517 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6518 icon_view->priv->source_targets,
6519 icon_view->priv->source_actions,
6523 set_source_row (context, model, path);
6527 gtk_tree_path_free (path);
6532 /* Source side drag signals */
6534 gtk_icon_view_drag_begin (GtkWidget *widget,
6535 GdkDragContext *context)
6537 GtkIconView *icon_view;
6538 GtkIconViewItem *item;
6543 icon_view = GTK_ICON_VIEW (widget);
6545 /* if the user uses a custom DnD impl, we don't set the icon here */
6546 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6549 item = gtk_icon_view_get_item_at_coords (icon_view,
6550 icon_view->priv->press_start_x,
6551 icon_view->priv->press_start_y,
6555 g_return_if_fail (item != NULL);
6557 x = icon_view->priv->press_start_x - item->x + 1;
6558 y = icon_view->priv->press_start_y - item->y + 1;
6560 path = gtk_tree_path_new_from_indices (item->index, -1);
6561 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6562 gtk_tree_path_free (path);
6564 gtk_drag_set_icon_pixmap (context,
6565 gdk_drawable_get_colormap (icon),
6570 g_object_unref (icon);
6574 gtk_icon_view_drag_end (GtkWidget *widget,
6575 GdkDragContext *context)
6581 gtk_icon_view_drag_data_get (GtkWidget *widget,
6582 GdkDragContext *context,
6583 GtkSelectionData *selection_data,
6587 GtkIconView *icon_view;
6588 GtkTreeModel *model;
6589 GtkTreePath *source_row;
6591 icon_view = GTK_ICON_VIEW (widget);
6592 model = gtk_icon_view_get_model (icon_view);
6597 if (!icon_view->priv->source_set)
6600 source_row = get_source_row (context);
6602 if (source_row == NULL)
6605 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6606 * any model; for DragSource models there are some other targets
6610 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6611 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6616 /* If drag_data_get does nothing, try providing row data. */
6617 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6618 gtk_tree_set_row_drag_data (selection_data,
6623 gtk_tree_path_free (source_row);
6627 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6628 GdkDragContext *context)
6630 GtkTreeModel *model;
6631 GtkIconView *icon_view;
6632 GtkTreePath *source_row;
6634 icon_view = GTK_ICON_VIEW (widget);
6635 model = gtk_icon_view_get_model (icon_view);
6637 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6640 if (!icon_view->priv->source_set)
6643 source_row = get_source_row (context);
6645 if (source_row == NULL)
6648 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6651 gtk_tree_path_free (source_row);
6653 set_source_row (context, NULL, NULL);
6656 /* Target side drag signals */
6658 gtk_icon_view_drag_leave (GtkWidget *widget,
6659 GdkDragContext *context,
6662 GtkIconView *icon_view;
6664 icon_view = GTK_ICON_VIEW (widget);
6666 /* unset any highlight row */
6667 gtk_icon_view_set_drag_dest_item (icon_view,
6669 GTK_ICON_VIEW_DROP_LEFT);
6671 remove_scroll_timeout (icon_view);
6675 gtk_icon_view_drag_motion (GtkWidget *widget,
6676 GdkDragContext *context,
6681 GtkTreePath *path = NULL;
6682 GtkIconViewDropPosition pos;
6683 GtkIconView *icon_view;
6684 GdkDragAction suggested_action = 0;
6688 icon_view = GTK_ICON_VIEW (widget);
6690 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6693 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6695 /* we only know this *after* set_desination_row */
6696 empty = icon_view->priv->empty_view_drop;
6698 if (path == NULL && !empty)
6700 /* Can't drop here. */
6701 gdk_drag_status (context, 0, time);
6705 if (icon_view->priv->scroll_timeout_id == 0)
6707 icon_view->priv->scroll_timeout_id =
6708 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6711 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6713 /* Request data so we can use the source row when
6714 * determining whether to accept the drop
6716 set_status_pending (context, suggested_action);
6717 gtk_drag_get_data (widget, context, target, time);
6721 set_status_pending (context, 0);
6722 gdk_drag_status (context, suggested_action, time);
6727 gtk_tree_path_free (path);
6733 gtk_icon_view_drag_drop (GtkWidget *widget,
6734 GdkDragContext *context,
6739 GtkIconView *icon_view;
6741 GdkDragAction suggested_action = 0;
6742 GdkAtom target = GDK_NONE;
6743 GtkTreeModel *model;
6744 gboolean drop_append_mode;
6746 icon_view = GTK_ICON_VIEW (widget);
6747 model = gtk_icon_view_get_model (icon_view);
6749 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6751 if (!icon_view->priv->dest_set)
6754 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6757 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6760 path = get_logical_destination (icon_view, &drop_append_mode);
6762 if (target != GDK_NONE && path != NULL)
6764 /* in case a motion had requested drag data, change things so we
6765 * treat drag data receives as a drop.
6767 set_status_pending (context, 0);
6768 set_dest_row (context, model, path,
6769 icon_view->priv->empty_view_drop, drop_append_mode);
6773 gtk_tree_path_free (path);
6775 /* Unset this thing */
6776 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6778 if (target != GDK_NONE)
6780 gtk_drag_get_data (widget, context, target, time);
6788 gtk_icon_view_drag_data_received (GtkWidget *widget,
6789 GdkDragContext *context,
6792 GtkSelectionData *selection_data,
6797 gboolean accepted = FALSE;
6798 GtkTreeModel *model;
6799 GtkIconView *icon_view;
6800 GtkTreePath *dest_row;
6801 GdkDragAction suggested_action;
6802 gboolean drop_append_mode;
6804 icon_view = GTK_ICON_VIEW (widget);
6805 model = gtk_icon_view_get_model (icon_view);
6807 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6810 if (!icon_view->priv->dest_set)
6813 suggested_action = get_status_pending (context);
6815 if (suggested_action)
6817 /* We are getting this data due to a request in drag_motion,
6818 * rather than due to a request in drag_drop, so we are just
6819 * supposed to call drag_status, not actually paste in the
6822 path = get_logical_destination (icon_view, &drop_append_mode);
6825 suggested_action = 0;
6827 if (suggested_action)
6829 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6832 suggested_action = 0;
6835 gdk_drag_status (context, suggested_action, time);
6838 gtk_tree_path_free (path);
6840 /* If you can't drop, remove user drop indicator until the next motion */
6841 if (suggested_action == 0)
6842 gtk_icon_view_set_drag_dest_item (icon_view,
6844 GTK_ICON_VIEW_DROP_LEFT);
6849 dest_row = get_dest_row (context);
6851 if (dest_row == NULL)
6854 if (selection_data->length >= 0)
6856 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6862 gtk_drag_finish (context,
6864 (context->action == GDK_ACTION_MOVE),
6867 gtk_tree_path_free (dest_row);
6870 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6873 /* Drag-and-Drop support */
6875 * gtk_icon_view_enable_model_drag_source:
6876 * @icon_view: a #GtkIconTreeView
6877 * @start_button_mask: Mask of allowed buttons to start drag
6878 * @targets: the table of targets that the drag will support
6879 * @n_targets: the number of items in @targets
6880 * @actions: the bitmask of possible actions for a drag from this
6883 * Turns @icon_view into a drag source for automatic DND.
6888 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6889 GdkModifierType start_button_mask,
6890 const GtkTargetEntry *targets,
6892 GdkDragAction actions)
6894 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6896 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6898 clear_source_info (icon_view);
6899 icon_view->priv->start_button_mask = start_button_mask;
6900 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6901 icon_view->priv->source_actions = actions;
6903 icon_view->priv->source_set = TRUE;
6905 unset_reorderable (icon_view);
6909 * gtk_icon_view_enable_model_drag_dest:
6910 * @icon_view: a #GtkIconView
6911 * @targets: the table of targets that the drag will support
6912 * @n_targets: the number of items in @targets
6913 * @actions: the bitmask of possible actions for a drag to this
6916 * Turns @icon_view into a drop destination for automatic DND.
6921 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6922 const GtkTargetEntry *targets,
6924 GdkDragAction actions)
6926 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6928 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6930 clear_dest_info (icon_view);
6932 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6933 icon_view->priv->dest_actions = actions;
6935 icon_view->priv->dest_set = TRUE;
6937 unset_reorderable (icon_view);
6941 * gtk_icon_view_unset_model_drag_source:
6942 * @icon_view: a #GtkIconView
6944 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6949 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6951 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6953 if (icon_view->priv->source_set)
6955 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6956 clear_source_info (icon_view);
6959 unset_reorderable (icon_view);
6963 * gtk_icon_view_unset_model_drag_dest:
6964 * @icon_view: a #GtkIconView
6966 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6971 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6973 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6975 if (icon_view->priv->dest_set)
6977 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6978 clear_dest_info (icon_view);
6981 unset_reorderable (icon_view);
6984 /* These are useful to implement your own custom stuff. */
6986 * gtk_icon_view_set_drag_dest_item:
6987 * @icon_view: a #GtkIconView
6988 * @path: The path of the item to highlight, or %NULL.
6989 * @pos: Specifies where to drop, relative to the item
6991 * Sets the item that is highlighted for feedback.
6996 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6998 GtkIconViewDropPosition pos)
7000 /* Note; this function is exported to allow a custom DND
7001 * implementation, so it can't touch TreeViewDragInfo
7004 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7006 if (icon_view->priv->dest_item)
7008 GtkTreePath *current_path;
7009 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7010 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7011 icon_view->priv->dest_item = NULL;
7013 gtk_icon_view_queue_draw_path (icon_view, current_path);
7014 gtk_tree_path_free (current_path);
7017 /* special case a drop on an empty model */
7018 icon_view->priv->empty_view_drop = FALSE;
7019 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7020 && gtk_tree_path_get_depth (path) == 1
7021 && gtk_tree_path_get_indices (path)[0] == 0)
7025 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7028 if (n_children == 0)
7029 icon_view->priv->empty_view_drop = TRUE;
7032 icon_view->priv->dest_pos = pos;
7036 icon_view->priv->dest_item =
7037 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7038 icon_view->priv->model, path);
7040 gtk_icon_view_queue_draw_path (icon_view, path);
7045 * gtk_icon_view_get_drag_dest_item:
7046 * @icon_view: a #GtkIconView
7047 * @path: Return location for the path of the highlighted item, or %NULL.
7048 * @pos: Return location for the drop position, or %NULL
7050 * Gets information about the item that is highlighted for feedback.
7055 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7057 GtkIconViewDropPosition *pos)
7059 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7063 if (icon_view->priv->dest_item)
7064 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7070 *pos = icon_view->priv->dest_pos;
7074 * gtk_icon_view_get_dest_item_at_pos:
7075 * @icon_view: a #GtkIconView
7076 * @drag_x: the position to determine the destination item for
7077 * @drag_y: the position to determine the destination item for
7078 * @path: Return location for the path of the item, or %NULL.
7079 * @pos: Return location for the drop position, or %NULL
7081 * Determines the destination item for a given position.
7083 * Return value: whether there is an item at the given position.
7088 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7092 GtkIconViewDropPosition *pos)
7094 GtkIconViewItem *item;
7096 /* Note; this function is exported to allow a custom DND
7097 * implementation, so it can't touch TreeViewDragInfo
7100 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7101 g_return_val_if_fail (drag_x >= 0, FALSE);
7102 g_return_val_if_fail (drag_y >= 0, FALSE);
7103 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7109 item = gtk_icon_view_get_item_at_coords (icon_view,
7110 drag_x + icon_view->priv->hadjustment->value,
7111 drag_y + icon_view->priv->vadjustment->value,
7118 *path = gtk_tree_path_new_from_indices (item->index, -1);
7122 if (drag_x < item->x + item->width / 4)
7123 *pos = GTK_ICON_VIEW_DROP_LEFT;
7124 else if (drag_x > item->x + item->width * 3 / 4)
7125 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7126 else if (drag_y < item->y + item->height / 4)
7127 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7128 else if (drag_y > item->y + item->height * 3 / 4)
7129 *pos = GTK_ICON_VIEW_DROP_BELOW;
7131 *pos = GTK_ICON_VIEW_DROP_INTO;
7138 * gtk_icon_view_create_drag_icon:
7139 * @icon_view: a #GtkIconView
7140 * @path: a #GtkTreePath in @icon_view
7142 * Creates a #GdkPixmap representation of the item at @path.
7143 * This image is used for a drag icon.
7145 * Return value: a newly-allocated pixmap of the drag icon.
7150 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7155 GdkPixmap *drawable;
7160 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7161 g_return_val_if_fail (path != NULL, NULL);
7163 widget = GTK_WIDGET (icon_view);
7165 if (!GTK_WIDGET_REALIZED (widget))
7168 index = gtk_tree_path_get_indices (path)[0];
7170 for (l = icon_view->priv->items; l; l = l->next)
7172 GtkIconViewItem *item = l->data;
7174 if (index == item->index)
7176 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7181 cr = gdk_cairo_create (drawable);
7182 cairo_set_line_width (cr, 1.);
7184 gdk_cairo_set_source_color
7185 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7186 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7191 area.width = item->width;
7192 area.height = item->height;
7194 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7195 drawable, 1, 1, FALSE);
7197 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7198 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7211 * gtk_icon_view_get_reorderable:
7212 * @icon_view: a #GtkIconView
7214 * Retrieves whether the user can reorder the list via drag-and-drop.
7215 * See gtk_icon_view_set_reorderable().
7217 * Return value: %TRUE if the list can be reordered.
7222 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7224 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7226 return icon_view->priv->reorderable;
7229 static const GtkTargetEntry item_targets[] = {
7230 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7235 * gtk_icon_view_set_reorderable:
7236 * @icon_view: A #GtkIconView.
7237 * @reorderable: %TRUE, if the list of items can be reordered.
7239 * This function is a convenience function to allow you to reorder models that
7240 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7241 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7242 * the user can reorder the model by dragging and dropping rows. The
7243 * developer can listen to these changes by connecting to the model's
7244 * row_inserted and row_deleted signals.
7246 * This function does not give you any degree of control over the order -- any
7247 * reordering is allowed. If more control is needed, you should probably
7248 * handle drag and drop manually.
7253 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7254 gboolean reorderable)
7256 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7258 reorderable = reorderable != FALSE;
7260 if (icon_view->priv->reorderable == reorderable)
7265 gtk_icon_view_enable_model_drag_source (icon_view,
7268 G_N_ELEMENTS (item_targets),
7270 gtk_icon_view_enable_model_drag_dest (icon_view,
7272 G_N_ELEMENTS (item_targets),
7277 gtk_icon_view_unset_model_drag_source (icon_view);
7278 gtk_icon_view_unset_model_drag_dest (icon_view);
7281 icon_view->priv->reorderable = reorderable;
7283 g_object_notify (G_OBJECT (icon_view), "reorderable");
7287 /* Accessibility Support */
7289 static gpointer accessible_parent_class;
7290 static gpointer accessible_item_parent_class;
7291 static GQuark accessible_private_data_quark = 0;
7293 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7294 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7295 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7297 static GType gtk_icon_view_item_accessible_get_type (void);
7308 GtkIconViewItem *item;
7312 AtkStateSet *state_set;
7316 GtkTextBuffer *text_buffer;
7318 gchar *action_descriptions[LAST_ACTION];
7319 gchar *image_description;
7320 guint action_idle_handler;
7321 } GtkIconViewItemAccessible;
7323 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7329 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7334 typedef struct _GtkIconViewItemAccessibleClass
7336 AtkObjectClass parent_class;
7338 } GtkIconViewItemAccessibleClass;
7340 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7343 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7345 GtkIconViewItemAccessible *item;
7346 GtkIconView *icon_view;
7349 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7350 item->action_idle_handler = 0;
7352 if (item->widget != NULL)
7354 icon_view = GTK_ICON_VIEW (item->widget);
7355 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7356 gtk_icon_view_item_activated (icon_view, path);
7357 gtk_tree_path_free (path);
7364 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7367 GtkIconViewItemAccessible *item;
7369 if (i < 0 || i >= LAST_ACTION)
7372 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7374 if (!GTK_IS_ICON_VIEW (item->widget))
7377 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7382 case ACTION_ACTIVATE:
7383 if (!item->action_idle_handler)
7384 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7387 g_assert_not_reached ();
7395 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7400 static const gchar *
7401 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7404 GtkIconViewItemAccessible *item;
7406 if (i < 0 || i >= LAST_ACTION)
7409 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7411 if (item->action_descriptions[i])
7412 return item->action_descriptions[i];
7414 return gtk_icon_view_item_accessible_action_descriptions[i];
7417 static const gchar *
7418 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7421 if (i < 0 || i >= LAST_ACTION)
7424 return gtk_icon_view_item_accessible_action_names[i];
7428 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7430 const gchar *description)
7432 GtkIconViewItemAccessible *item;
7434 if (i < 0 || i >= LAST_ACTION)
7437 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7439 g_free (item->action_descriptions[i]);
7441 item->action_descriptions[i] = g_strdup (description);
7447 atk_action_item_interface_init (AtkActionIface *iface)
7449 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7450 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7451 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7452 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7453 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7456 static const gchar *
7457 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7459 GtkIconViewItemAccessible *item;
7461 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7463 return item->image_description;
7467 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7468 const gchar *description)
7470 GtkIconViewItemAccessible *item;
7472 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7474 g_free (item->image_description);
7475 item->image_description = g_strdup (item->image_description);
7481 get_pixbuf_box (GtkIconView *icon_view,
7482 GtkIconViewItem *item,
7487 for (l = icon_view->priv->cell_list; l; l = l->next)
7489 GtkIconViewCellInfo *info = l->data;
7491 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7493 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7503 get_text (GtkIconView *icon_view,
7504 GtkIconViewItem *item)
7509 for (l = icon_view->priv->cell_list; l; l = l->next)
7511 GtkIconViewCellInfo *info = l->data;
7513 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7515 g_object_get (info->cell, "text", &text, NULL);
7525 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7529 GtkIconViewItemAccessible *item;
7532 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7534 if (!GTK_IS_ICON_VIEW (item->widget))
7537 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7540 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7543 *height = box.height;
7548 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7551 AtkCoordType coord_type)
7553 GtkIconViewItemAccessible *item;
7556 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7558 if (!GTK_IS_ICON_VIEW (item->widget))
7561 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7564 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7566 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7568 *x+= box.x - item->item->x;
7569 *y+= box.y - item->item->y;
7575 atk_image_item_interface_init (AtkImageIface *iface)
7577 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7578 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7579 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7580 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7584 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7588 GtkIconViewItemAccessible *item;
7589 GtkTextIter start, end;
7590 GtkTextBuffer *buffer;
7592 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7594 if (!GTK_IS_ICON_VIEW (item->widget))
7597 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7600 buffer = item->text_buffer;
7601 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7603 gtk_text_buffer_get_end_iter (buffer, &end);
7605 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7607 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7611 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7614 GtkIconViewItemAccessible *item;
7615 GtkTextIter start, end;
7616 GtkTextBuffer *buffer;
7620 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7622 if (!GTK_IS_ICON_VIEW (item->widget))
7625 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7628 buffer = item->text_buffer;
7629 if (offset >= gtk_text_buffer_get_char_count (buffer))
7632 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7634 gtk_text_iter_forward_char (&end);
7635 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7636 unichar = g_utf8_get_char (string);
7644 get_pango_text_offsets (PangoLayout *layout,
7645 GtkTextBuffer *buffer,
7647 AtkTextBoundary boundary_type,
7651 GtkTextIter *start_iter,
7652 GtkTextIter *end_iter)
7654 PangoLayoutIter *iter;
7655 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7656 gint index, start_index, end_index;
7658 gboolean found = FALSE;
7660 text = pango_layout_get_text (layout);
7661 index = g_utf8_offset_to_pointer (text, offset) - text;
7662 iter = pango_layout_get_iter (layout);
7665 line = pango_layout_iter_get_line_readonly (iter);
7666 start_index = line->start_index;
7667 end_index = start_index + line->length;
7669 if (index >= start_index && index <= end_index)
7672 * Found line for offset
7678 * We want the previous line
7682 switch (boundary_type)
7684 case ATK_TEXT_BOUNDARY_LINE_START:
7685 end_index = start_index;
7686 start_index = prev_line->start_index;
7688 case ATK_TEXT_BOUNDARY_LINE_END:
7690 start_index = prev_prev_line->start_index +
7691 prev_prev_line->length;
7692 end_index = prev_line->start_index + prev_line->length;
7695 g_assert_not_reached();
7699 start_index = end_index = 0;
7702 switch (boundary_type)
7704 case ATK_TEXT_BOUNDARY_LINE_START:
7705 if (pango_layout_iter_next_line (iter))
7706 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7708 case ATK_TEXT_BOUNDARY_LINE_END:
7710 start_index = prev_line->start_index +
7714 g_assert_not_reached();
7719 * We want the next line
7721 if (pango_layout_iter_next_line (iter))
7723 line = pango_layout_iter_get_line_readonly (iter);
7724 switch (boundary_type)
7726 case ATK_TEXT_BOUNDARY_LINE_START:
7727 start_index = line->start_index;
7728 if (pango_layout_iter_next_line (iter))
7729 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7731 end_index = start_index + line->length;
7733 case ATK_TEXT_BOUNDARY_LINE_END:
7734 start_index = end_index;
7735 end_index = line->start_index + line->length;
7738 g_assert_not_reached();
7742 start_index = end_index;
7748 prev_prev_line = prev_line;
7751 while (pango_layout_iter_next_line (iter));
7755 start_index = prev_line->start_index + prev_line->length;
7756 end_index = start_index;
7758 pango_layout_iter_free (iter);
7759 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7760 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7762 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7763 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7768 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7770 AtkTextBoundary boundary_type,
7774 GtkIconViewItemAccessible *item;
7775 GtkTextIter start, end;
7776 GtkTextBuffer *buffer;
7778 GtkIconView *icon_view;
7781 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7783 if (!GTK_IS_ICON_VIEW (item->widget))
7786 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7789 buffer = item->text_buffer;
7791 if (!gtk_text_buffer_get_char_count (buffer))
7795 return g_strdup ("");
7797 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7801 switch (boundary_type)
7803 case ATK_TEXT_BOUNDARY_CHAR:
7804 gtk_text_iter_backward_char(&start);
7806 case ATK_TEXT_BOUNDARY_WORD_START:
7807 if (!gtk_text_iter_starts_word (&start))
7808 gtk_text_iter_backward_word_start (&start);
7810 gtk_text_iter_backward_word_start(&start);
7812 case ATK_TEXT_BOUNDARY_WORD_END:
7813 if (gtk_text_iter_inside_word (&start) &&
7814 !gtk_text_iter_starts_word (&start))
7815 gtk_text_iter_backward_word_start (&start);
7816 while (!gtk_text_iter_ends_word (&start))
7818 if (!gtk_text_iter_backward_char (&start))
7822 gtk_text_iter_backward_word_start(&start);
7823 while (!gtk_text_iter_ends_word (&start))
7825 if (!gtk_text_iter_backward_char (&start))
7829 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7830 if (!gtk_text_iter_starts_sentence (&start))
7831 gtk_text_iter_backward_sentence_start (&start);
7833 gtk_text_iter_backward_sentence_start (&start);
7835 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7836 if (gtk_text_iter_inside_sentence (&start) &&
7837 !gtk_text_iter_starts_sentence (&start))
7838 gtk_text_iter_backward_sentence_start (&start);
7839 while (!gtk_text_iter_ends_sentence (&start))
7841 if (!gtk_text_iter_backward_char (&start))
7845 gtk_text_iter_backward_sentence_start (&start);
7846 while (!gtk_text_iter_ends_sentence (&start))
7848 if (!gtk_text_iter_backward_char (&start))
7852 case ATK_TEXT_BOUNDARY_LINE_START:
7853 case ATK_TEXT_BOUNDARY_LINE_END:
7855 icon_view = GTK_ICON_VIEW (item->widget);
7856 /* FIXME we probably have to use GailTextCell to salvage this */
7857 gtk_icon_view_update_item_text (icon_view, item->item);
7858 get_pango_text_offsets (icon_view->priv->layout,
7871 *start_offset = gtk_text_iter_get_offset (&start);
7872 *end_offset = gtk_text_iter_get_offset (&end);
7874 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7878 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7880 AtkTextBoundary boundary_type,
7884 GtkIconViewItemAccessible *item;
7885 GtkTextIter start, end;
7886 GtkTextBuffer *buffer;
7888 GtkIconView *icon_view;
7891 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7893 if (!GTK_IS_ICON_VIEW (item->widget))
7896 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7899 buffer = item->text_buffer;
7901 if (!gtk_text_buffer_get_char_count (buffer))
7905 return g_strdup ("");
7907 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7911 switch (boundary_type)
7913 case ATK_TEXT_BOUNDARY_CHAR:
7914 gtk_text_iter_forward_char (&end);
7916 case ATK_TEXT_BOUNDARY_WORD_START:
7917 if (!gtk_text_iter_starts_word (&start))
7918 gtk_text_iter_backward_word_start (&start);
7919 if (gtk_text_iter_inside_word (&end))
7920 gtk_text_iter_forward_word_end (&end);
7921 while (!gtk_text_iter_starts_word (&end))
7923 if (!gtk_text_iter_forward_char (&end))
7927 case ATK_TEXT_BOUNDARY_WORD_END:
7928 if (gtk_text_iter_inside_word (&start) &&
7929 !gtk_text_iter_starts_word (&start))
7930 gtk_text_iter_backward_word_start (&start);
7931 while (!gtk_text_iter_ends_word (&start))
7933 if (!gtk_text_iter_backward_char (&start))
7936 gtk_text_iter_forward_word_end (&end);
7938 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7939 if (!gtk_text_iter_starts_sentence (&start))
7940 gtk_text_iter_backward_sentence_start (&start);
7941 if (gtk_text_iter_inside_sentence (&end))
7942 gtk_text_iter_forward_sentence_end (&end);
7943 while (!gtk_text_iter_starts_sentence (&end))
7945 if (!gtk_text_iter_forward_char (&end))
7949 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7950 if (gtk_text_iter_inside_sentence (&start) &&
7951 !gtk_text_iter_starts_sentence (&start))
7952 gtk_text_iter_backward_sentence_start (&start);
7953 while (!gtk_text_iter_ends_sentence (&start))
7955 if (!gtk_text_iter_backward_char (&start))
7958 gtk_text_iter_forward_sentence_end (&end);
7960 case ATK_TEXT_BOUNDARY_LINE_START:
7961 case ATK_TEXT_BOUNDARY_LINE_END:
7963 icon_view = GTK_ICON_VIEW (item->widget);
7964 /* FIXME we probably have to use GailTextCell to salvage this */
7965 gtk_icon_view_update_item_text (icon_view, item->item);
7966 get_pango_text_offsets (icon_view->priv->layout,
7980 *start_offset = gtk_text_iter_get_offset (&start);
7981 *end_offset = gtk_text_iter_get_offset (&end);
7983 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7987 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7989 AtkTextBoundary boundary_type,
7993 GtkIconViewItemAccessible *item;
7994 GtkTextIter start, end;
7995 GtkTextBuffer *buffer;
7997 GtkIconView *icon_view;
8000 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8002 if (!GTK_IS_ICON_VIEW (item->widget))
8005 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8008 buffer = item->text_buffer;
8010 if (!gtk_text_buffer_get_char_count (buffer))
8014 return g_strdup ("");
8016 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8020 switch (boundary_type)
8022 case ATK_TEXT_BOUNDARY_CHAR:
8023 gtk_text_iter_forward_char(&start);
8024 gtk_text_iter_forward_chars(&end, 2);
8026 case ATK_TEXT_BOUNDARY_WORD_START:
8027 if (gtk_text_iter_inside_word (&end))
8028 gtk_text_iter_forward_word_end (&end);
8029 while (!gtk_text_iter_starts_word (&end))
8031 if (!gtk_text_iter_forward_char (&end))
8035 if (!gtk_text_iter_is_end (&end))
8037 gtk_text_iter_forward_word_end (&end);
8038 while (!gtk_text_iter_starts_word (&end))
8040 if (!gtk_text_iter_forward_char (&end))
8045 case ATK_TEXT_BOUNDARY_WORD_END:
8046 gtk_text_iter_forward_word_end (&end);
8048 if (!gtk_text_iter_is_end (&end))
8049 gtk_text_iter_forward_word_end (&end);
8051 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8052 if (gtk_text_iter_inside_sentence (&end))
8053 gtk_text_iter_forward_sentence_end (&end);
8054 while (!gtk_text_iter_starts_sentence (&end))
8056 if (!gtk_text_iter_forward_char (&end))
8060 if (!gtk_text_iter_is_end (&end))
8062 gtk_text_iter_forward_sentence_end (&end);
8063 while (!gtk_text_iter_starts_sentence (&end))
8065 if (!gtk_text_iter_forward_char (&end))
8070 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8071 gtk_text_iter_forward_sentence_end (&end);
8073 if (!gtk_text_iter_is_end (&end))
8074 gtk_text_iter_forward_sentence_end (&end);
8076 case ATK_TEXT_BOUNDARY_LINE_START:
8077 case ATK_TEXT_BOUNDARY_LINE_END:
8079 icon_view = GTK_ICON_VIEW (item->widget);
8080 /* FIXME we probably have to use GailTextCell to salvage this */
8081 gtk_icon_view_update_item_text (icon_view, item->item);
8082 get_pango_text_offsets (icon_view->priv->layout,
8094 *start_offset = gtk_text_iter_get_offset (&start);
8095 *end_offset = gtk_text_iter_get_offset (&end);
8097 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8101 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8103 GtkIconViewItemAccessible *item;
8105 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8107 if (!GTK_IS_ICON_VIEW (item->widget))
8110 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8113 return gtk_text_buffer_get_char_count (item->text_buffer);
8117 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8123 AtkCoordType coord_type)
8125 GtkIconViewItemAccessible *item;
8127 GtkIconView *icon_view;
8128 PangoRectangle char_rect;
8129 const gchar *item_text;
8133 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8135 if (!GTK_IS_ICON_VIEW (item->widget))
8138 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8142 icon_view = GTK_ICON_VIEW (item->widget);
8143 /* FIXME we probably have to use GailTextCell to salvage this */
8144 gtk_icon_view_update_item_text (icon_view, item->item);
8145 item_text = pango_layout_get_text (icon_view->priv->layout);
8146 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8147 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8149 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8150 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8151 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8152 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8153 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8154 *width = char_rect.width / PANGO_SCALE;
8155 *height = char_rect.height / PANGO_SCALE;
8160 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8163 AtkCoordType coord_type)
8165 GtkIconViewItemAccessible *item;
8168 GtkIconView *icon_view;
8169 const gchar *item_text;
8174 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8176 if (!GTK_IS_ICON_VIEW (item->widget))
8179 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8183 icon_view = GTK_ICON_VIEW (item->widget);
8184 /* FIXME we probably have to use GailTextCell to salvage this */
8185 gtk_icon_view_update_item_text (icon_view, item->item);
8186 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8187 x -= l_x + item->item->layout_x - item->item->x;
8188 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8189 y -= l_y + item->item->layout_y - item->item->y;
8190 item_text = pango_layout_get_text (icon_view->priv->layout);
8191 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8202 offset = g_utf8_strlen (item_text, -1);
8204 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8210 atk_text_item_interface_init (AtkTextIface *iface)
8212 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8213 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8214 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8215 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8216 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8217 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8218 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8219 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8223 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8228 AtkCoordType coord_type)
8230 GtkIconViewItemAccessible *item;
8231 AtkObject *parent_obj;
8234 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8236 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8237 if (!GTK_IS_WIDGET (item->widget))
8240 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8243 *width = item->item->width;
8244 *height = item->item->height;
8245 if (gtk_icon_view_item_accessible_is_showing (item))
8247 parent_obj = gtk_widget_get_accessible (item->widget);
8248 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8249 *x = l_x + item->item->x;
8250 *y = l_y + item->item->y;
8260 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8262 GtkIconViewItemAccessible *item;
8263 GtkWidget *toplevel;
8265 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8267 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8268 if (!GTK_IS_WIDGET (item->widget))
8271 gtk_widget_grab_focus (item->widget);
8272 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8273 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8274 if (GTK_WIDGET_TOPLEVEL (toplevel))
8275 gtk_window_present (GTK_WINDOW (toplevel));
8281 atk_component_item_interface_init (AtkComponentIface *iface)
8283 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8284 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8288 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8289 AtkStateType state_type,
8290 gboolean emit_signal)
8294 rc = atk_state_set_add_state (item->state_set, state_type);
8296 * The signal should only be generated if the value changed,
8297 * not when the item is set up. So states that are set
8298 * initially should pass FALSE as the emit_signal argument.
8303 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8304 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8305 if (state_type == ATK_STATE_VISIBLE)
8306 g_signal_emit_by_name (item, "visible-data-changed");
8313 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8314 AtkStateType state_type,
8315 gboolean emit_signal)
8317 if (atk_state_set_contains_state (item->state_set, state_type))
8321 rc = atk_state_set_remove_state (item->state_set, state_type);
8323 * The signal should only be generated if the value changed,
8324 * not when the item is set up. So states that are set
8325 * initially should pass FALSE as the emit_signal argument.
8330 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8331 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8332 if (state_type == ATK_STATE_VISIBLE)
8333 g_signal_emit_by_name (item, "visible-data-changed");
8343 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8345 GtkIconView *icon_view;
8346 GdkRectangle visible_rect;
8347 gboolean is_showing;
8350 * An item is considered "SHOWING" if any part of the item is in the
8351 * visible rectangle.
8354 if (!GTK_IS_ICON_VIEW (item->widget))
8357 if (item->item == NULL)
8360 icon_view = GTK_ICON_VIEW (item->widget);
8362 if (icon_view->priv->hadjustment)
8363 visible_rect.x += icon_view->priv->hadjustment->value;
8365 if (icon_view->priv->hadjustment)
8366 visible_rect.y += icon_view->priv->vadjustment->value;
8367 visible_rect.width = item->widget->allocation.width;
8368 visible_rect.height = item->widget->allocation.height;
8370 if (((item->item->x + item->item->width) < visible_rect.x) ||
8371 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8372 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8373 (item->item->y > (visible_rect.y + visible_rect.height)))
8382 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8383 gboolean emit_signal)
8385 if (gtk_icon_view_item_accessible_is_showing (item))
8386 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8389 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8394 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8398 item->state_set = atk_state_set_new ();
8400 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8401 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8402 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8403 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8404 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8406 for (i = 0; i < LAST_ACTION; i++)
8407 item->action_descriptions[i] = NULL;
8409 item->image_description = NULL;
8411 item->action_idle_handler = 0;
8415 gtk_icon_view_item_accessible_finalize (GObject *object)
8417 GtkIconViewItemAccessible *item;
8420 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8422 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8425 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8427 if (item->state_set)
8428 g_object_unref (item->state_set);
8430 if (item->text_buffer)
8431 g_object_unref (item->text_buffer);
8433 for (i = 0; i < LAST_ACTION; i++)
8434 g_free (item->action_descriptions[i]);
8436 g_free (item->image_description);
8438 if (item->action_idle_handler)
8440 g_source_remove (item->action_idle_handler);
8441 item->action_idle_handler = 0;
8444 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8447 static G_CONST_RETURN gchar*
8448 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8454 GtkIconViewItemAccessible *item;
8455 GtkTextIter start_iter;
8456 GtkTextIter end_iter;
8458 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8460 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8461 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8463 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8468 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8470 GtkIconViewItemAccessible *item;
8472 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8473 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8476 return gtk_widget_get_accessible (item->widget);
8482 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8484 GtkIconViewItemAccessible *item;
8486 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8487 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8489 return item->item->index;
8492 static AtkStateSet *
8493 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8495 GtkIconViewItemAccessible *item;
8496 GtkIconView *icon_view;
8498 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8499 g_return_val_if_fail (item->state_set, NULL);
8504 icon_view = GTK_ICON_VIEW (item->widget);
8505 if (icon_view->priv->cursor_item == item->item)
8506 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8508 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8509 if (item->item->selected)
8510 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8512 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8514 return g_object_ref (item->state_set);
8518 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8520 GObjectClass *gobject_class;
8522 accessible_item_parent_class = g_type_class_peek_parent (klass);
8524 gobject_class = (GObjectClass *)klass;
8526 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8528 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8529 klass->get_name = gtk_icon_view_item_accessible_get_name;
8530 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8531 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8535 gtk_icon_view_item_accessible_get_type (void)
8537 static GType type = 0;
8541 const GTypeInfo tinfo =
8543 sizeof (GtkIconViewItemAccessibleClass),
8544 (GBaseInitFunc) NULL, /* base init */
8545 (GBaseFinalizeFunc) NULL, /* base finalize */
8546 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8547 (GClassFinalizeFunc) NULL, /* class finalize */
8548 NULL, /* class data */
8549 sizeof (GtkIconViewItemAccessible), /* instance size */
8550 0, /* nb preallocs */
8551 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8552 NULL /* value table */
8555 static const GInterfaceInfo atk_component_info =
8557 (GInterfaceInitFunc) atk_component_item_interface_init,
8558 (GInterfaceFinalizeFunc) NULL,
8561 static const GInterfaceInfo atk_action_info =
8563 (GInterfaceInitFunc) atk_action_item_interface_init,
8564 (GInterfaceFinalizeFunc) NULL,
8567 static const GInterfaceInfo atk_image_info =
8569 (GInterfaceInitFunc) atk_image_item_interface_init,
8570 (GInterfaceFinalizeFunc) NULL,
8573 static const GInterfaceInfo atk_text_info =
8575 (GInterfaceInitFunc) atk_text_item_interface_init,
8576 (GInterfaceFinalizeFunc) NULL,
8580 type = g_type_register_static (ATK_TYPE_OBJECT,
8581 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8582 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8583 &atk_component_info);
8584 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8586 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8588 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8595 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8596 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8597 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8599 static GType gtk_icon_view_accessible_get_type (void);
8604 } GtkIconViewAccessible;
8610 } GtkIconViewItemAccessibleInfo;
8616 GtkAdjustment *old_hadj;
8617 GtkAdjustment *old_vadj;
8619 GtkTreeModel *model;
8621 } GtkIconViewAccessiblePrivate;
8623 static GtkIconViewAccessiblePrivate *
8624 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8626 return g_object_get_qdata (G_OBJECT (accessible),
8627 accessible_private_data_quark);
8631 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8635 GtkIconViewItemAccessibleInfo *info;
8636 GtkIconViewItemAccessibleInfo *tmp_info;
8637 GtkIconViewAccessiblePrivate *priv;
8640 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8642 info->index = index;
8644 priv = gtk_icon_view_accessible_get_priv (accessible);
8645 items = priv->items;
8648 tmp_info = items->data;
8649 if (tmp_info->index > index)
8651 items = items->next;
8653 priv->items = g_list_insert_before (priv->items, items, info);
8654 priv->old_hadj = NULL;
8655 priv->old_vadj = NULL;
8659 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8661 GtkIconView *icon_view;
8664 widget = GTK_ACCESSIBLE (accessible)->widget;
8668 icon_view = GTK_ICON_VIEW (widget);
8670 return g_list_length (icon_view->priv->items);
8674 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8677 GtkIconViewAccessiblePrivate *priv;
8678 GtkIconViewItemAccessibleInfo *info;
8681 priv = gtk_icon_view_accessible_get_priv (accessible);
8682 items = priv->items;
8687 if (info->index == index)
8689 items = items->next;
8695 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8698 GtkIconView *icon_view;
8702 GtkIconViewItemAccessible *a11y_item;
8704 widget = GTK_ACCESSIBLE (accessible)->widget;
8708 icon_view = GTK_ICON_VIEW (widget);
8709 icons = g_list_nth (icon_view->priv->items, index);
8713 GtkIconViewItem *item = icons->data;
8715 g_return_val_if_fail (item->index == index, NULL);
8716 obj = gtk_icon_view_accessible_find_child (accessible, index);
8721 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8722 gtk_icon_view_item_accessible_info_new (accessible,
8725 obj->role = ATK_ROLE_ICON;
8726 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8727 a11y_item->item = item;
8728 a11y_item->widget = widget;
8729 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8731 gtk_icon_view_set_cell_data (icon_view, item);
8732 text = get_text (icon_view, item);
8735 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8739 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8740 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8748 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8751 GtkIconViewAccessiblePrivate *priv;
8752 GtkIconViewItemAccessibleInfo *info;
8753 GtkIconViewItemAccessible *item;
8756 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8760 gboolean act_on_item;
8762 widget = GTK_ACCESSIBLE (view)->widget;
8766 items = priv->items;
8768 act_on_item = (list == NULL);
8773 info = (GtkIconViewItemAccessibleInfo *)items->data;
8774 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8776 if (act_on_item == FALSE && list == items)
8780 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8782 items = items->next;
8788 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8789 GtkIconView *icon_view)
8792 GtkIconViewAccessible *view;
8795 * The scrollbars have changed
8797 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8798 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8800 gtk_icon_view_accessible_traverse_items (view, NULL);
8804 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8805 GtkAdjustment *hadj,
8806 GtkAdjustment *vadj)
8809 GtkIconViewAccessiblePrivate *priv;
8811 atk_obj = gtk_widget_get_accessible (widget);
8812 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8814 if (priv->old_hadj != hadj)
8818 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8819 (gpointer *)&priv->old_hadj);
8821 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8822 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8825 priv->old_hadj = hadj;
8828 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8829 (gpointer *)&priv->old_hadj);
8830 g_signal_connect (hadj,
8832 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8836 if (priv->old_vadj != vadj)
8840 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8841 (gpointer *)&priv->old_vadj);
8843 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8844 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8847 priv->old_vadj = vadj;
8850 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8851 (gpointer *)&priv->old_vadj);
8852 g_signal_connect (vadj,
8854 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8861 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8868 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8869 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8875 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8880 GtkIconViewAccessiblePrivate *priv;
8881 GtkIconViewItemAccessibleInfo *info;
8882 GtkIconViewAccessible *view;
8883 GtkIconViewItemAccessible *item;
8889 index = gtk_tree_path_get_indices(path)[0];
8890 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8891 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8892 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8894 items = priv->items;
8899 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8900 if (info->index != item->item->index)
8902 if (info->index < index)
8903 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8905 if (tmp_list == NULL)
8908 info->index = item->item->index;
8911 items = items->next;
8913 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8914 g_signal_emit_by_name (atk_obj, "children-changed::add",
8920 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8924 GtkIconViewAccessiblePrivate *priv;
8925 GtkIconViewItemAccessibleInfo *info;
8926 GtkIconViewAccessible *view;
8927 GtkIconViewItemAccessible *item;
8930 GList *deleted_item;
8934 index = gtk_tree_path_get_indices(path)[0];
8935 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8936 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8937 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8939 items = priv->items;
8941 deleted_item = NULL;
8946 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8947 if (info->index == index)
8949 deleted_item = items;
8951 if (info->index != item->item->index)
8953 if (tmp_list == NULL)
8956 info->index = item->item->index;
8959 items = items->next;
8961 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8964 info = deleted_item->data;
8965 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8966 g_signal_emit_by_name (atk_obj, "children-changed::remove",
8968 priv->items = g_list_remove_link (priv->items, deleted_item);
8976 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8977 GtkIconViewItemAccessibleInfo *i2)
8979 return i1->index - i2->index;
8983 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8989 GtkIconViewAccessiblePrivate *priv;
8990 GtkIconViewItemAccessibleInfo *info;
8991 GtkIconView *icon_view;
8992 GtkIconViewItemAccessible *item;
8996 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8997 icon_view = GTK_ICON_VIEW (user_data);
8998 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9000 items = priv->items;
9004 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9005 info->index = new_order[info->index];
9006 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9007 items = items->next;
9009 priv->items = g_list_sort (priv->items,
9010 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9016 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9021 obj = G_OBJECT (model);
9022 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9023 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9024 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9025 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9029 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9033 obj = G_OBJECT (icon_view->priv->model);
9034 g_signal_connect_data (obj, "row-changed",
9035 (GCallback) gtk_icon_view_accessible_model_row_changed,
9036 icon_view, NULL, 0);
9037 g_signal_connect_data (obj, "row-inserted",
9038 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9039 icon_view, NULL, G_CONNECT_AFTER);
9040 g_signal_connect_data (obj, "row-deleted",
9041 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9042 icon_view, NULL, G_CONNECT_AFTER);
9043 g_signal_connect_data (obj, "rows-reordered",
9044 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9045 icon_view, NULL, G_CONNECT_AFTER);
9049 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9051 GtkIconViewItemAccessibleInfo *info;
9054 items = priv->items;
9057 info = (GtkIconViewItemAccessibleInfo *) items->data;
9058 g_object_unref (info->item);
9059 g_free (items->data);
9060 items = items->next;
9062 g_list_free (priv->items);
9067 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9070 GtkIconView *icon_view;
9073 GtkIconViewAccessiblePrivate *priv;
9075 if (strcmp (pspec->name, "model") == 0)
9077 widget = GTK_WIDGET (obj);
9078 atk_obj = gtk_widget_get_accessible (widget);
9079 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9082 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9083 (gpointer *)&priv->model);
9084 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9086 gtk_icon_view_accessible_clear_cache (priv);
9088 icon_view = GTK_ICON_VIEW (obj);
9089 priv->model = icon_view->priv->model;
9090 /* If there is no model the GtkIconView is probably being destroyed */
9093 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9094 gtk_icon_view_accessible_connect_model_signals (icon_view);
9102 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9105 GtkIconViewAccessiblePrivate *priv;
9106 GtkIconView *icon_view;
9108 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9109 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9111 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9112 g_object_set_qdata (G_OBJECT (accessible),
9113 accessible_private_data_quark,
9116 icon_view = GTK_ICON_VIEW (data);
9117 if (icon_view->priv->hadjustment)
9119 priv->old_hadj = icon_view->priv->hadjustment;
9120 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9121 g_signal_connect (icon_view->priv->hadjustment,
9123 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9126 if (icon_view->priv->vadjustment)
9128 priv->old_vadj = icon_view->priv->vadjustment;
9129 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9130 g_signal_connect (icon_view->priv->vadjustment,
9132 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9135 g_signal_connect_after (data,
9136 "set-scroll-adjustments",
9137 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9139 g_signal_connect (data,
9141 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9144 priv->model = icon_view->priv->model;
9147 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9148 gtk_icon_view_accessible_connect_model_signals (icon_view);
9151 accessible->role = ATK_ROLE_LAYERED_PANE;
9155 gtk_icon_view_accessible_finalize (GObject *object)
9157 GtkIconViewAccessiblePrivate *priv;
9159 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9160 gtk_icon_view_accessible_clear_cache (priv);
9164 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9168 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9169 GtkAccessible *accessible)
9172 GtkIconViewAccessiblePrivate *priv;
9174 atk_obj = ATK_OBJECT (accessible);
9175 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9178 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9179 (gpointer *)&priv->old_hadj);
9181 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9182 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9184 priv->old_hadj = NULL;
9188 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9189 (gpointer *)&priv->old_vadj);
9191 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9192 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9194 priv->old_vadj = NULL;
9199 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9201 if (accessible->widget)
9203 g_signal_connect_after (accessible->widget,
9205 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9208 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9212 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9214 GObjectClass *gobject_class;
9215 GtkAccessibleClass *accessible_class;
9217 accessible_parent_class = g_type_class_peek_parent (klass);
9219 gobject_class = (GObjectClass *)klass;
9220 accessible_class = (GtkAccessibleClass *)klass;
9222 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9224 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9225 klass->ref_child = gtk_icon_view_accessible_ref_child;
9226 klass->initialize = gtk_icon_view_accessible_initialize;
9228 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9230 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9234 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9237 AtkCoordType coord_type)
9240 GtkIconView *icon_view;
9241 GtkIconViewItem *item;
9244 widget = GTK_ACCESSIBLE (component)->widget;
9246 /* State is defunct */
9249 icon_view = GTK_ICON_VIEW (widget);
9250 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9251 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9253 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9259 atk_component_interface_init (AtkComponentIface *iface)
9261 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9265 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9269 GtkIconView *icon_view;
9270 GtkIconViewItem *item;
9272 widget = GTK_ACCESSIBLE (selection)->widget;
9276 icon_view = GTK_ICON_VIEW (widget);
9278 item = g_list_nth_data (icon_view->priv->items, i);
9283 gtk_icon_view_select_item (icon_view, item);
9289 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9292 GtkIconView *icon_view;
9294 widget = GTK_ACCESSIBLE (selection)->widget;
9298 icon_view = GTK_ICON_VIEW (widget);
9299 gtk_icon_view_unselect_all (icon_view);
9305 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9310 GtkIconView *icon_view;
9311 GtkIconViewItem *item;
9313 widget = GTK_ACCESSIBLE (selection)->widget;
9317 icon_view = GTK_ICON_VIEW (widget);
9319 l = icon_view->priv->items;
9326 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9337 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9340 GtkIconView *icon_view;
9341 GtkIconViewItem *item;
9345 widget = GTK_ACCESSIBLE (selection)->widget;
9349 icon_view = GTK_ICON_VIEW (widget);
9351 l = icon_view->priv->items;
9367 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9371 GtkIconView *icon_view;
9372 GtkIconViewItem *item;
9374 widget = GTK_ACCESSIBLE (selection)->widget;
9378 icon_view = GTK_ICON_VIEW (widget);
9380 item = g_list_nth_data (icon_view->priv->items, i);
9384 return item->selected;
9388 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9392 GtkIconView *icon_view;
9393 GtkIconViewItem *item;
9397 widget = GTK_ACCESSIBLE (selection)->widget;
9401 icon_view = GTK_ICON_VIEW (widget);
9402 l = icon_view->priv->items;
9411 gtk_icon_view_unselect_item (icon_view, item);
9423 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9426 GtkIconView *icon_view;
9428 widget = GTK_ACCESSIBLE (selection)->widget;
9432 icon_view = GTK_ICON_VIEW (widget);
9433 gtk_icon_view_select_all (icon_view);
9438 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9440 iface->add_selection = gtk_icon_view_accessible_add_selection;
9441 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9442 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9443 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9444 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9445 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9446 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9450 gtk_icon_view_accessible_get_type (void)
9452 static GType type = 0;
9456 static GTypeInfo tinfo =
9459 (GBaseInitFunc) NULL, /* base init */
9460 (GBaseFinalizeFunc) NULL, /* base finalize */
9461 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9462 (GClassFinalizeFunc) NULL, /* class finalize */
9463 NULL, /* class data */
9464 0, /* instance size */
9465 0, /* nb preallocs */
9466 (GInstanceInitFunc) NULL, /* instance init */
9467 NULL /* value table */
9469 static const GInterfaceInfo atk_component_info =
9471 (GInterfaceInitFunc) atk_component_interface_init,
9472 (GInterfaceFinalizeFunc) NULL,
9475 static const GInterfaceInfo atk_selection_info =
9477 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9478 (GInterfaceFinalizeFunc) NULL,
9483 * Figure out the size of the class and instance
9484 * we are deriving from
9486 AtkObjectFactory *factory;
9489 GType derived_atk_type;
9491 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9492 factory = atk_registry_get_factory (atk_get_default_registry (),
9494 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9495 g_type_query (derived_atk_type, &query);
9496 tinfo.class_size = query.class_size;
9497 tinfo.instance_size = query.instance_size;
9499 type = g_type_register_static (derived_atk_type,
9500 I_("GtkIconViewAccessible"),
9502 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9503 &atk_component_info);
9504 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9505 &atk_selection_info);
9511 gtk_icon_view_accessible_new (GObject *obj)
9513 AtkObject *accessible;
9515 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9517 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9518 atk_object_initialize (accessible, obj);
9524 gtk_icon_view_accessible_factory_get_accessible_type (void)
9526 return gtk_icon_view_accessible_get_type ();
9530 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9532 return gtk_icon_view_accessible_new (obj);
9536 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9538 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9539 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9543 gtk_icon_view_accessible_factory_get_type (void)
9545 static GType type = 0;
9549 const GTypeInfo tinfo =
9551 sizeof (AtkObjectFactoryClass),
9552 NULL, /* base_init */
9553 NULL, /* base_finalize */
9554 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9555 NULL, /* class_finalize */
9556 NULL, /* class_data */
9557 sizeof (AtkObjectFactory),
9558 0, /* n_preallocs */
9562 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9563 I_("GtkIconViewAccessibleFactory"),
9571 gtk_icon_view_get_accessible (GtkWidget *widget)
9573 static gboolean first_time = TRUE;
9577 AtkObjectFactory *factory;
9578 AtkRegistry *registry;
9580 GType derived_atk_type;
9583 * Figure out whether accessibility is enabled by looking at the
9584 * type of the accessible object which would be created for
9585 * the parent type of GtkIconView.
9587 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9589 registry = atk_get_default_registry ();
9590 factory = atk_registry_get_factory (registry,
9592 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9593 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9594 atk_registry_set_factory_type (registry,
9596 gtk_icon_view_accessible_factory_get_type ());
9599 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9603 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9604 GtkBuilder *builder,
9606 const gchar *tagname,
9607 GMarkupParser *parser,
9610 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9611 tagname, parser, data))
9614 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9615 tagname, parser, data);
9619 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9620 GtkBuilder *builder,
9622 const gchar *tagname,
9625 if (strcmp (tagname, "attributes") == 0)
9626 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9629 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9635 #define __GTK_ICON_VIEW_C__
9636 #include "gtkaliasdef.c"