2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtktextbuffer.h"
42 #include "gtktreednd.h"
43 #include "gtkprivate.h"
46 #undef DEBUG_ICON_VIEW
48 #define SCROLL_EDGE_SIZE 15
50 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
52 typedef struct _GtkIconViewItem GtkIconViewItem;
53 struct _GtkIconViewItem
61 gint x, y, width, height;
64 * box[i] is the actual area occupied by cell i,
65 * before, after are used to calculate the cell
66 * area relative to the box.
67 * See gtk_icon_view_get_cell_area().
75 guint selected_before_rubberbanding : 1;
79 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
80 struct _GtkIconViewCellInfo
82 GtkCellRenderer *cell;
92 GtkCellLayoutDataFunc func;
94 GDestroyNotify destroy;
97 typedef struct _GtkIconViewChild GtkIconViewChild;
98 struct _GtkIconViewChild
101 GtkIconViewItem *item;
105 struct _GtkIconViewPrivate
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gboolean doing_rubberband;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
134 GtkIconViewItem *edited_item;
135 GtkCellEditable *editable;
137 GtkIconViewItem *last_single_clicked;
144 GtkOrientation orientation;
163 GdkModifierType start_button_mask;
168 GtkTargetList *source_targets;
169 GdkDragAction source_actions;
171 GtkTargetList *dest_targets;
172 GdkDragAction dest_actions;
174 GtkTreeRowReference *dest_item;
175 GtkIconViewDropPosition dest_pos;
178 GtkTreeRowReference *scroll_to_path;
179 gfloat scroll_to_row_align;
180 gfloat scroll_to_col_align;
181 guint scroll_to_use_align : 1;
183 guint source_set : 1;
185 guint reorderable : 1;
186 guint empty_view_drop :1;
188 guint ctrl_pressed : 1;
189 guint shift_pressed : 1;
202 ACTIVATE_CURSOR_ITEM,
227 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
228 static void gtk_icon_view_finalize (GObject *object);
229 static void gtk_icon_view_set_property (GObject *object,
233 static void gtk_icon_view_get_property (GObject *object,
238 /* GtkObject vfuncs */
239 static void gtk_icon_view_destroy (GtkObject *object);
241 /* GtkWidget vfuncs */
242 static void gtk_icon_view_realize (GtkWidget *widget);
243 static void gtk_icon_view_unrealize (GtkWidget *widget);
244 static void gtk_icon_view_style_set (GtkWidget *widget,
245 GtkStyle *previous_style);
246 static void gtk_icon_view_state_changed (GtkWidget *widget,
247 GtkStateType previous_state);
248 static void gtk_icon_view_size_request (GtkWidget *widget,
249 GtkRequisition *requisition);
250 static void gtk_icon_view_size_allocate (GtkWidget *widget,
251 GtkAllocation *allocation);
252 static gboolean gtk_icon_view_expose (GtkWidget *widget,
253 GdkEventExpose *expose);
254 static gboolean gtk_icon_view_motion (GtkWidget *widget,
255 GdkEventMotion *event);
256 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
257 GdkEventButton *event);
258 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
259 GdkEventButton *event);
260 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
262 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
264 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
267 /* GtkContainer vfuncs */
268 static void gtk_icon_view_remove (GtkContainer *container,
270 static void gtk_icon_view_forall (GtkContainer *container,
271 gboolean include_internals,
272 GtkCallback callback,
273 gpointer callback_data);
275 /* GtkIconView vfuncs */
276 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
278 GtkAdjustment *vadj);
279 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
280 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
282 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
283 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
285 /* Internal functions */
286 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
287 GtkIconView *icon_view);
288 static void gtk_icon_view_layout (GtkIconView *icon_view);
289 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
292 GtkIconViewItem *item,
294 GdkDrawable *drawable,
297 gboolean draw_focus);
298 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
303 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
304 GtkIconViewItem *item);
305 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
306 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
307 GtkIconViewItem *item,
309 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
312 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
313 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
314 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
315 GtkIconViewItem *item,
320 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
321 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
322 GtkIconViewItem *item);
323 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
324 GtkIconViewItem *item,
326 static void gtk_icon_view_update_rubberband (gpointer data);
327 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
328 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
329 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
332 GtkMovementStep step,
334 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
335 GtkMovementStep step,
337 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
343 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
345 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_select_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
350 GtkIconViewItem *item);
351 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
352 GtkIconViewItem *anchor,
353 GtkIconViewItem *cursor);
354 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
357 gboolean only_in_cell,
358 GtkIconViewCellInfo **cell_at_pos);
359 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
360 GtkIconViewItem *item,
361 GtkIconViewCellInfo *cell_info,
362 GdkRectangle *cell_area);
363 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
364 GtkIconViewItem *item,
365 GtkIconViewCellInfo *info,
367 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
368 GtkCellRenderer *renderer);
369 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
370 GtkIconViewItem *item);
371 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
372 GtkCellRenderer *renderer,
374 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
375 GtkCellRenderer *renderer,
377 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
378 GtkCellRenderer *renderer,
379 const gchar *attribute,
381 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
382 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
383 GtkCellRenderer *renderer);
384 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
385 GtkCellRenderer *cell,
386 GtkCellLayoutDataFunc func,
388 GDestroyNotify destroy);
389 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
390 GtkCellRenderer *cell,
392 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
394 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
395 GtkIconViewItem *item,
396 GtkIconViewCellInfo *cell_info,
398 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
399 GtkIconViewItem *item);
400 static void gtk_icon_view_put (GtkIconView *icon_view,
402 GtkIconViewItem *item,
404 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
405 GtkIconView *icon_view);
406 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
407 GtkIconViewItem *item,
408 GtkIconViewCellInfo *cell_info,
410 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
411 gboolean cancel_editing);
413 /* Source side drag signals */
414 static void gtk_icon_view_drag_begin (GtkWidget *widget,
415 GdkDragContext *context);
416 static void gtk_icon_view_drag_end (GtkWidget *widget,
417 GdkDragContext *context);
418 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
426 /* Target side drag signals */
427 static void gtk_icon_view_drag_leave (GtkWidget *widget,
428 GdkDragContext *context,
430 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
431 GdkDragContext *context,
435 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
436 GdkDragContext *context,
440 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
441 GdkDragContext *context,
444 GtkSelectionData *selection_data,
447 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
448 GdkEventMotion *event);
450 static void remove_scroll_timeout (GtkIconView *icon_view);
451 static void clear_dest_info (GtkIconView *icon_view);
452 static void clear_source_info (GtkIconView *icon_view);
454 static void adjust_wrap_width (GtkIconView *icon_view,
455 GtkIconViewItem *item);
458 static GtkBuildableIface *parent_buildable_iface;
459 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
460 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
463 const gchar *tagname,
464 GMarkupParser *parser,
466 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
469 const gchar *tagname,
472 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
474 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
475 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
476 gtk_icon_view_cell_layout_init)
477 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
478 gtk_icon_view_buildable_init))
481 gtk_icon_view_class_init (GtkIconViewClass *klass)
483 GObjectClass *gobject_class;
484 GtkObjectClass *object_class;
485 GtkWidgetClass *widget_class;
486 GtkContainerClass *container_class;
487 GtkBindingSet *binding_set;
489 binding_set = gtk_binding_set_by_class (klass);
491 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
493 gobject_class = (GObjectClass *) klass;
494 object_class = (GtkObjectClass *) klass;
495 widget_class = (GtkWidgetClass *) klass;
496 container_class = (GtkContainerClass *) klass;
498 gobject_class->finalize = gtk_icon_view_finalize;
499 gobject_class->set_property = gtk_icon_view_set_property;
500 gobject_class->get_property = gtk_icon_view_get_property;
502 object_class->destroy = gtk_icon_view_destroy;
504 widget_class->realize = gtk_icon_view_realize;
505 widget_class->unrealize = gtk_icon_view_unrealize;
506 widget_class->style_set = gtk_icon_view_style_set;
507 widget_class->get_accessible = gtk_icon_view_get_accessible;
508 widget_class->size_request = gtk_icon_view_size_request;
509 widget_class->size_allocate = gtk_icon_view_size_allocate;
510 widget_class->expose_event = gtk_icon_view_expose;
511 widget_class->motion_notify_event = gtk_icon_view_motion;
512 widget_class->button_press_event = gtk_icon_view_button_press;
513 widget_class->button_release_event = gtk_icon_view_button_release;
514 widget_class->key_press_event = gtk_icon_view_key_press;
515 widget_class->key_release_event = gtk_icon_view_key_release;
516 widget_class->drag_begin = gtk_icon_view_drag_begin;
517 widget_class->drag_end = gtk_icon_view_drag_end;
518 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
519 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
520 widget_class->drag_leave = gtk_icon_view_drag_leave;
521 widget_class->drag_motion = gtk_icon_view_drag_motion;
522 widget_class->drag_drop = gtk_icon_view_drag_drop;
523 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
524 widget_class->state_changed = gtk_icon_view_state_changed;
526 container_class->remove = gtk_icon_view_remove;
527 container_class->forall = gtk_icon_view_forall;
529 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
530 klass->select_all = gtk_icon_view_real_select_all;
531 klass->unselect_all = gtk_icon_view_real_unselect_all;
532 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
533 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
534 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
535 klass->move_cursor = gtk_icon_view_real_move_cursor;
539 * GtkIconView:selection-mode:
541 * The ::selection-mode property specifies the selection mode of
542 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
543 * is enabled, for the other modes, only keyboard selection is possible.
547 g_object_class_install_property (gobject_class,
549 g_param_spec_enum ("selection-mode",
550 P_("Selection mode"),
551 P_("The selection mode"),
552 GTK_TYPE_SELECTION_MODE,
553 GTK_SELECTION_SINGLE,
554 GTK_PARAM_READWRITE));
557 * GtkIconView:pixbuf-column:
559 * The ::pixbuf-column property contains the number of the model column
560 * containing the pixbufs which are displayed. The pixbuf column must be
561 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
562 * display of pixbufs.
566 g_object_class_install_property (gobject_class,
568 g_param_spec_int ("pixbuf-column",
570 P_("Model column used to retrieve the icon pixbuf from"),
572 GTK_PARAM_READWRITE));
575 * GtkIconView:text-column:
577 * The ::text-column property contains the number of the model column
578 * containing the texts which are displayed. The text column must be
579 * of type #G_TYPE_STRING. If this property and the :markup-column
580 * property are both set to -1, no texts are displayed.
584 g_object_class_install_property (gobject_class,
586 g_param_spec_int ("text-column",
588 P_("Model column used to retrieve the text from"),
590 GTK_PARAM_READWRITE));
594 * GtkIconView:markup-column:
596 * The ::markup-column property contains the number of the model column
597 * containing markup information to be displayed. The markup column must be
598 * of type #G_TYPE_STRING. If this property and the :text-column property
599 * are both set to column numbers, it overrides the text column.
600 * If both are set to -1, no texts are displayed.
604 g_object_class_install_property (gobject_class,
606 g_param_spec_int ("markup-column",
608 P_("Model column used to retrieve the text if using Pango markup"),
610 GTK_PARAM_READWRITE));
612 g_object_class_install_property (gobject_class,
614 g_param_spec_object ("model",
615 P_("Icon View Model"),
616 P_("The model for the icon view"),
618 GTK_PARAM_READWRITE));
621 * GtkIconView:columns:
623 * The columns property contains the number of the columns in which the
624 * items should be displayed. If it is -1, the number of columns will
625 * be chosen automatically to fill the available area.
629 g_object_class_install_property (gobject_class,
631 g_param_spec_int ("columns",
632 P_("Number of columns"),
633 P_("Number of columns to display"),
635 GTK_PARAM_READWRITE));
639 * GtkIconView:item-width:
641 * The item-width property specifies the width to use for each item.
642 * If it is set to -1, the icon view will automatically determine a
643 * suitable item size.
647 g_object_class_install_property (gobject_class,
649 g_param_spec_int ("item-width",
650 P_("Width for each item"),
651 P_("The width used for each item"),
653 GTK_PARAM_READWRITE));
656 * GtkIconView:spacing:
658 * The spacing property specifies the space which is inserted between
659 * the cells (i.e. the icon and the text) of an item.
663 g_object_class_install_property (gobject_class,
665 g_param_spec_int ("spacing",
667 P_("Space which is inserted between cells of an item"),
669 GTK_PARAM_READWRITE));
672 * GtkIconView:row-spacing:
674 * The row-spacing property specifies the space which is inserted between
675 * the rows of the icon view.
679 g_object_class_install_property (gobject_class,
681 g_param_spec_int ("row-spacing",
683 P_("Space which is inserted between grid rows"),
685 GTK_PARAM_READWRITE));
688 * GtkIconView:column-spacing:
690 * The column-spacing property specifies the space which is inserted between
691 * the columns of the icon view.
695 g_object_class_install_property (gobject_class,
697 g_param_spec_int ("column-spacing",
698 P_("Column Spacing"),
699 P_("Space which is inserted between grid columns"),
701 GTK_PARAM_READWRITE));
704 * GtkIconView:margin:
706 * The margin property specifies the space which is inserted
707 * at the edges of the icon view.
711 g_object_class_install_property (gobject_class,
713 g_param_spec_int ("margin",
715 P_("Space which is inserted at the edges of the icon view"),
717 GTK_PARAM_READWRITE));
721 * GtkIconView:orientation:
723 * The orientation property specifies how the cells (i.e. the icon and
724 * the text) of the item are positioned relative to each other.
728 g_object_class_install_property (gobject_class,
730 g_param_spec_enum ("orientation",
732 P_("How the text and icon of each item are positioned relative to each other"),
733 GTK_TYPE_ORIENTATION,
734 GTK_ORIENTATION_VERTICAL,
735 GTK_PARAM_READWRITE));
738 * GtkIconView:reorderable:
740 * The reorderable property specifies if the items can be reordered
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("reorderable",
749 P_("View is reorderable"),
753 g_object_class_install_property (gobject_class,
755 g_param_spec_int ("tooltip-column",
756 P_("Tooltip Column"),
757 P_("The column in the model containing the tooltip texts for the items"),
761 GTK_PARAM_READWRITE));
765 /* Style properties */
766 gtk_widget_class_install_style_property (widget_class,
767 g_param_spec_boxed ("selection-box-color",
768 P_("Selection Box Color"),
769 P_("Color of the selection box"),
771 GTK_PARAM_READABLE));
773 gtk_widget_class_install_style_property (widget_class,
774 g_param_spec_uchar ("selection-box-alpha",
775 P_("Selection Box Alpha"),
776 P_("Opacity of the selection box"),
779 GTK_PARAM_READABLE));
782 widget_class->set_scroll_adjustments_signal =
783 g_signal_new (I_("set_scroll_adjustments"),
784 G_TYPE_FROM_CLASS (gobject_class),
786 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
788 _gtk_marshal_VOID__OBJECT_OBJECT,
790 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
792 icon_view_signals[ITEM_ACTIVATED] =
793 g_signal_new (I_("item_activated"),
794 G_TYPE_FROM_CLASS (gobject_class),
796 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
798 g_cclosure_marshal_VOID__BOXED,
802 icon_view_signals[SELECTION_CHANGED] =
803 g_signal_new (I_("selection-changed"),
804 G_TYPE_FROM_CLASS (gobject_class),
806 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
808 g_cclosure_marshal_VOID__VOID,
811 icon_view_signals[SELECT_ALL] =
812 g_signal_new (I_("select_all"),
813 G_TYPE_FROM_CLASS (gobject_class),
814 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
815 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
817 g_cclosure_marshal_VOID__VOID,
820 icon_view_signals[UNSELECT_ALL] =
821 g_signal_new (I_("unselect_all"),
822 G_TYPE_FROM_CLASS (gobject_class),
823 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
824 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
826 g_cclosure_marshal_VOID__VOID,
829 icon_view_signals[SELECT_CURSOR_ITEM] =
830 g_signal_new (I_("select_cursor_item"),
831 G_TYPE_FROM_CLASS (gobject_class),
832 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
833 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
835 g_cclosure_marshal_VOID__VOID,
838 icon_view_signals[TOGGLE_CURSOR_ITEM] =
839 g_signal_new (I_("toggle_cursor_item"),
840 G_TYPE_FROM_CLASS (gobject_class),
841 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
842 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
844 g_cclosure_marshal_VOID__VOID,
847 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
848 g_signal_new (I_("activate_cursor_item"),
849 G_TYPE_FROM_CLASS (gobject_class),
850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
851 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
853 _gtk_marshal_BOOLEAN__VOID,
856 icon_view_signals[MOVE_CURSOR] =
857 g_signal_new (I_("move_cursor"),
858 G_TYPE_FROM_CLASS (gobject_class),
859 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
860 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
862 _gtk_marshal_BOOLEAN__ENUM_INT,
864 GTK_TYPE_MOVEMENT_STEP,
868 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
870 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
872 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
873 "toggle_cursor_item", 0);
874 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
875 "toggle_cursor_item", 0);
877 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
878 "activate_cursor_item", 0);
879 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
880 "activate_cursor_item", 0);
881 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
882 "activate_cursor_item", 0);
883 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
884 "activate_cursor_item", 0);
885 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
886 "activate_cursor_item", 0);
888 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
889 GTK_MOVEMENT_DISPLAY_LINES, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
891 GTK_MOVEMENT_DISPLAY_LINES, -1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
894 GTK_MOVEMENT_DISPLAY_LINES, 1);
895 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
896 GTK_MOVEMENT_DISPLAY_LINES, 1);
898 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
899 GTK_MOVEMENT_DISPLAY_LINES, -1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
902 GTK_MOVEMENT_DISPLAY_LINES, 1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
905 GTK_MOVEMENT_BUFFER_ENDS, -1);
906 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
907 GTK_MOVEMENT_BUFFER_ENDS, -1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
910 GTK_MOVEMENT_BUFFER_ENDS, 1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
912 GTK_MOVEMENT_BUFFER_ENDS, 1);
914 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
915 GTK_MOVEMENT_PAGES, -1);
916 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
917 GTK_MOVEMENT_PAGES, -1);
919 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
920 GTK_MOVEMENT_PAGES, 1);
921 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
922 GTK_MOVEMENT_PAGES, 1);
924 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
925 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
926 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
927 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
929 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
930 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
931 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
932 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
936 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
938 parent_buildable_iface = g_type_interface_peek_parent (iface);
939 iface->add_child = _gtk_cell_layout_buildable_add_child;
940 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
941 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
945 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
947 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
948 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
949 iface->clear = gtk_icon_view_cell_layout_clear;
950 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
951 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
952 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
953 iface->reorder = gtk_icon_view_cell_layout_reorder;
954 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
958 gtk_icon_view_init (GtkIconView *icon_view)
960 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
962 icon_view->priv->width = 0;
963 icon_view->priv->height = 0;
964 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
965 icon_view->priv->pressed_button = -1;
966 icon_view->priv->press_start_x = -1;
967 icon_view->priv->press_start_y = -1;
968 icon_view->priv->text_column = -1;
969 icon_view->priv->markup_column = -1;
970 icon_view->priv->pixbuf_column = -1;
971 icon_view->priv->text_cell = -1;
972 icon_view->priv->pixbuf_cell = -1;
973 icon_view->priv->tooltip_column = -1;
975 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
977 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
979 icon_view->priv->cell_list = NULL;
980 icon_view->priv->n_cells = 0;
981 icon_view->priv->cursor_cell = -1;
983 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
985 icon_view->priv->columns = -1;
986 icon_view->priv->item_width = -1;
987 icon_view->priv->spacing = 0;
988 icon_view->priv->row_spacing = 6;
989 icon_view->priv->column_spacing = 6;
990 icon_view->priv->margin = 6;
994 gtk_icon_view_destroy (GtkObject *object)
996 GtkIconView *icon_view;
998 icon_view = GTK_ICON_VIEW (object);
1000 gtk_icon_view_stop_editing (icon_view, TRUE);
1002 gtk_icon_view_set_model (icon_view, NULL);
1004 if (icon_view->priv->layout_idle_id != 0)
1006 g_source_remove (icon_view->priv->layout_idle_id);
1007 icon_view->priv->layout_idle_id = 0;
1010 if (icon_view->priv->scroll_to_path != NULL)
1012 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1013 icon_view->priv->scroll_to_path = NULL;
1016 remove_scroll_timeout (icon_view);
1018 if (icon_view->priv->hadjustment != NULL)
1020 g_object_unref (icon_view->priv->hadjustment);
1021 icon_view->priv->hadjustment = NULL;
1024 if (icon_view->priv->vadjustment != NULL)
1026 g_object_unref (icon_view->priv->vadjustment);
1027 icon_view->priv->vadjustment = NULL;
1030 clear_dest_info (icon_view);
1031 clear_source_info (icon_view);
1033 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1036 /* GObject methods */
1038 gtk_icon_view_finalize (GObject *object)
1040 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1042 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1047 gtk_icon_view_set_property (GObject *object,
1049 const GValue *value,
1052 GtkIconView *icon_view;
1054 icon_view = GTK_ICON_VIEW (object);
1058 case PROP_SELECTION_MODE:
1059 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1061 case PROP_PIXBUF_COLUMN:
1062 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1064 case PROP_TEXT_COLUMN:
1065 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1067 case PROP_MARKUP_COLUMN:
1068 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1071 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1073 case PROP_ORIENTATION:
1074 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1077 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1079 case PROP_ITEM_WIDTH:
1080 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1083 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1085 case PROP_ROW_SPACING:
1086 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1088 case PROP_COLUMN_SPACING:
1089 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1092 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1094 case PROP_REORDERABLE:
1095 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1098 case PROP_TOOLTIP_COLUMN:
1099 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1109 gtk_icon_view_get_property (GObject *object,
1114 GtkIconView *icon_view;
1116 icon_view = GTK_ICON_VIEW (object);
1120 case PROP_SELECTION_MODE:
1121 g_value_set_enum (value, icon_view->priv->selection_mode);
1123 case PROP_PIXBUF_COLUMN:
1124 g_value_set_int (value, icon_view->priv->pixbuf_column);
1126 case PROP_TEXT_COLUMN:
1127 g_value_set_int (value, icon_view->priv->text_column);
1129 case PROP_MARKUP_COLUMN:
1130 g_value_set_int (value, icon_view->priv->markup_column);
1133 g_value_set_object (value, icon_view->priv->model);
1135 case PROP_ORIENTATION:
1136 g_value_set_enum (value, icon_view->priv->orientation);
1139 g_value_set_int (value, icon_view->priv->columns);
1141 case PROP_ITEM_WIDTH:
1142 g_value_set_int (value, icon_view->priv->item_width);
1145 g_value_set_int (value, icon_view->priv->spacing);
1147 case PROP_ROW_SPACING:
1148 g_value_set_int (value, icon_view->priv->row_spacing);
1150 case PROP_COLUMN_SPACING:
1151 g_value_set_int (value, icon_view->priv->column_spacing);
1154 g_value_set_int (value, icon_view->priv->margin);
1156 case PROP_REORDERABLE:
1157 g_value_set_boolean (value, icon_view->priv->reorderable);
1159 case PROP_TOOLTIP_COLUMN:
1160 g_value_set_int (value, icon_view->priv->tooltip_column);
1164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1169 /* GtkWidget signals */
1171 gtk_icon_view_realize (GtkWidget *widget)
1173 GtkIconView *icon_view;
1174 GdkWindowAttr attributes;
1175 gint attributes_mask;
1177 icon_view = GTK_ICON_VIEW (widget);
1179 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1181 /* Make the main, clipping window */
1182 attributes.window_type = GDK_WINDOW_CHILD;
1183 attributes.x = widget->allocation.x;
1184 attributes.y = widget->allocation.y;
1185 attributes.width = widget->allocation.width;
1186 attributes.height = widget->allocation.height;
1187 attributes.wclass = GDK_INPUT_OUTPUT;
1188 attributes.visual = gtk_widget_get_visual (widget);
1189 attributes.colormap = gtk_widget_get_colormap (widget);
1190 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1192 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1194 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1195 &attributes, attributes_mask);
1196 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1197 gdk_window_set_user_data (widget->window, widget);
1199 /* Make the window for the icon view */
1202 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1203 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1204 attributes.event_mask = (GDK_EXPOSURE_MASK |
1206 GDK_POINTER_MOTION_MASK |
1207 GDK_BUTTON_PRESS_MASK |
1208 GDK_BUTTON_RELEASE_MASK |
1209 GDK_KEY_PRESS_MASK |
1210 GDK_KEY_RELEASE_MASK) |
1211 gtk_widget_get_events (widget);
1213 icon_view->priv->bin_window = gdk_window_new (widget->window,
1214 &attributes, attributes_mask);
1215 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1217 widget->style = gtk_style_attach (widget->style, widget->window);
1218 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1220 gdk_window_show (icon_view->priv->bin_window);
1224 gtk_icon_view_unrealize (GtkWidget *widget)
1226 GtkIconView *icon_view;
1228 icon_view = GTK_ICON_VIEW (widget);
1230 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1231 gdk_window_destroy (icon_view->priv->bin_window);
1232 icon_view->priv->bin_window = NULL;
1234 /* GtkWidget::unrealize destroys children and widget->window */
1235 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1236 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1240 gtk_icon_view_state_changed (GtkWidget *widget,
1241 GtkStateType previous_state)
1243 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1245 if (GTK_WIDGET_REALIZED (widget))
1247 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1248 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1251 gtk_widget_queue_draw (widget);
1255 gtk_icon_view_style_set (GtkWidget *widget,
1256 GtkStyle *previous_style)
1258 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1260 if (GTK_WIDGET_REALIZED (widget))
1262 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1263 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1266 gtk_widget_queue_resize (widget);
1270 gtk_icon_view_size_request (GtkWidget *widget,
1271 GtkRequisition *requisition)
1273 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1276 requisition->width = icon_view->priv->width;
1277 requisition->height = icon_view->priv->height;
1279 tmp_list = icon_view->priv->children;
1283 GtkIconViewChild *child = tmp_list->data;
1284 GtkRequisition child_requisition;
1286 tmp_list = tmp_list->next;
1288 if (GTK_WIDGET_VISIBLE (child->widget))
1289 gtk_widget_size_request (child->widget, &child_requisition);
1294 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1298 for (list = icon_view->priv->children; list; list = list->next)
1300 GtkIconViewChild *child = list->data;
1301 GtkAllocation allocation;
1303 /* totally ignore our child's requisition */
1304 if (child->cell < 0)
1306 allocation.x = child->item->x;
1307 allocation.y = child->item->y;
1308 allocation.width = child->item->width;
1309 allocation.height = child->item->height;
1313 GdkRectangle *box = &child->item->box[child->cell];
1315 allocation.x = box->x;
1316 allocation.y = box->y;
1317 allocation.width = box->width;
1318 allocation.height = box->height;
1321 gtk_widget_size_allocate (child->widget, &allocation);
1326 gtk_icon_view_size_allocate (GtkWidget *widget,
1327 GtkAllocation *allocation)
1329 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1331 GtkAdjustment *hadjustment, *vadjustment;
1333 widget->allocation = *allocation;
1335 if (GTK_WIDGET_REALIZED (widget))
1337 gdk_window_move_resize (widget->window,
1338 allocation->x, allocation->y,
1339 allocation->width, allocation->height);
1340 gdk_window_resize (icon_view->priv->bin_window,
1341 MAX (icon_view->priv->width, allocation->width),
1342 MAX (icon_view->priv->height, allocation->height));
1345 gtk_icon_view_layout (icon_view);
1347 gtk_icon_view_allocate_children (icon_view);
1349 hadjustment = icon_view->priv->hadjustment;
1350 vadjustment = icon_view->priv->vadjustment;
1352 hadjustment->page_size = allocation->width;
1353 hadjustment->page_increment = allocation->width * 0.9;
1354 hadjustment->step_increment = allocation->width * 0.1;
1355 hadjustment->lower = 0;
1356 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1358 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1359 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1361 vadjustment->page_size = allocation->height;
1362 vadjustment->page_increment = allocation->height * 0.9;
1363 vadjustment->step_increment = allocation->height * 0.1;
1364 vadjustment->lower = 0;
1365 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1367 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1368 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1370 if (GTK_WIDGET_REALIZED (widget) &&
1371 icon_view->priv->scroll_to_path)
1374 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1375 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1376 icon_view->priv->scroll_to_path = NULL;
1378 gtk_icon_view_scroll_to_path (icon_view, path,
1379 icon_view->priv->scroll_to_use_align,
1380 icon_view->priv->scroll_to_row_align,
1381 icon_view->priv->scroll_to_col_align);
1382 gtk_tree_path_free (path);
1386 gtk_adjustment_changed (hadjustment);
1387 gtk_adjustment_changed (vadjustment);
1392 gtk_icon_view_expose (GtkWidget *widget,
1393 GdkEventExpose *expose)
1395 GtkIconView *icon_view;
1400 GtkIconViewDropPosition dest_pos;
1401 GtkIconViewItem *dest_item = NULL;
1403 icon_view = GTK_ICON_VIEW (widget);
1405 if (expose->window != icon_view->priv->bin_window)
1408 cr = gdk_cairo_create (icon_view->priv->bin_window);
1409 cairo_set_line_width (cr, 1.);
1411 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1415 dest_index = gtk_tree_path_get_indices (path)[0];
1416 gtk_tree_path_free (path);
1421 for (icons = icon_view->priv->items; icons; icons = icons->next)
1423 GtkIconViewItem *item = icons->data;
1428 area.width = item->width;
1429 area.height = item->height;
1431 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1434 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1435 icon_view->priv->bin_window,
1436 item->x, item->y, TRUE);
1438 if (dest_index == item->index)
1446 case GTK_ICON_VIEW_DROP_INTO:
1447 gtk_paint_focus (widget->style,
1448 icon_view->priv->bin_window,
1449 GTK_WIDGET_STATE (widget),
1452 "iconview-drop-indicator",
1453 dest_item->x, dest_item->y,
1454 dest_item->width, dest_item->height);
1456 case GTK_ICON_VIEW_DROP_ABOVE:
1457 gtk_paint_focus (widget->style,
1458 icon_view->priv->bin_window,
1459 GTK_WIDGET_STATE (widget),
1462 "iconview-drop-indicator",
1463 dest_item->x, dest_item->y - 1,
1464 dest_item->width, 2);
1466 case GTK_ICON_VIEW_DROP_LEFT:
1467 gtk_paint_focus (widget->style,
1468 icon_view->priv->bin_window,
1469 GTK_WIDGET_STATE (widget),
1472 "iconview-drop-indicator",
1473 dest_item->x - 1, dest_item->y,
1474 2, dest_item->height);
1476 case GTK_ICON_VIEW_DROP_BELOW:
1477 gtk_paint_focus (widget->style,
1478 icon_view->priv->bin_window,
1479 GTK_WIDGET_STATE (widget),
1482 "iconview-drop-indicator",
1483 dest_item->x, dest_item->y + dest_item->height - 1,
1484 dest_item->width, 2);
1486 case GTK_ICON_VIEW_DROP_RIGHT:
1487 gtk_paint_focus (widget->style,
1488 icon_view->priv->bin_window,
1489 GTK_WIDGET_STATE (widget),
1492 "iconview-drop-indicator",
1493 dest_item->x + dest_item->width - 1, dest_item->y,
1494 2, dest_item->height);
1495 case GTK_ICON_VIEW_NO_DROP: ;
1500 if (icon_view->priv->doing_rubberband)
1502 GdkRectangle *rectangles;
1505 gdk_region_get_rectangles (expose->region,
1509 while (n_rectangles--)
1510 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1512 g_free (rectangles);
1517 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1523 rubberband_scroll_timeout (gpointer data)
1525 GtkIconView *icon_view;
1530 value = MIN (icon_view->priv->vadjustment->value +
1531 icon_view->priv->scroll_value_diff,
1532 icon_view->priv->vadjustment->upper -
1533 icon_view->priv->vadjustment->page_size);
1535 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1537 gtk_icon_view_update_rubberband (icon_view);
1543 gtk_icon_view_motion (GtkWidget *widget,
1544 GdkEventMotion *event)
1546 GtkIconView *icon_view;
1549 icon_view = GTK_ICON_VIEW (widget);
1551 gtk_icon_view_maybe_begin_drag (icon_view, event);
1553 if (icon_view->priv->doing_rubberband)
1555 gtk_icon_view_update_rubberband (widget);
1557 abs_y = event->y - icon_view->priv->height *
1558 (icon_view->priv->vadjustment->value /
1559 (icon_view->priv->vadjustment->upper -
1560 icon_view->priv->vadjustment->lower));
1562 if (abs_y < 0 || abs_y > widget->allocation.height)
1565 icon_view->priv->scroll_value_diff = abs_y;
1567 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1569 icon_view->priv->event_last_x = event->x;
1570 icon_view->priv->event_last_y = event->y;
1572 if (icon_view->priv->scroll_timeout_id == 0)
1573 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1577 remove_scroll_timeout (icon_view);
1584 gtk_icon_view_remove (GtkContainer *container,
1587 GtkIconView *icon_view;
1588 GtkIconViewChild *child = NULL;
1591 icon_view = GTK_ICON_VIEW (container);
1593 tmp_list = icon_view->priv->children;
1596 child = tmp_list->data;
1597 if (child->widget == widget)
1599 gtk_widget_unparent (widget);
1601 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1602 g_list_free_1 (tmp_list);
1607 tmp_list = tmp_list->next;
1612 gtk_icon_view_forall (GtkContainer *container,
1613 gboolean include_internals,
1614 GtkCallback callback,
1615 gpointer callback_data)
1617 GtkIconView *icon_view;
1618 GtkIconViewChild *child = NULL;
1621 icon_view = GTK_ICON_VIEW (container);
1623 tmp_list = icon_view->priv->children;
1626 child = tmp_list->data;
1627 tmp_list = tmp_list->next;
1629 (* callback) (child->widget, callback_data);
1634 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1635 GtkIconViewItem *item,
1636 GtkIconViewCellInfo *info,
1641 GdkRectangle cell_area;
1642 gboolean visible, mode;
1644 gtk_icon_view_set_cell_data (icon_view, item);
1646 g_object_get (info->cell,
1647 "visible", &visible,
1651 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1653 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1655 path = gtk_tree_path_new_from_indices (item->index, -1);
1656 path_string = gtk_tree_path_to_string (path);
1657 gtk_tree_path_free (path);
1659 gtk_cell_renderer_activate (info->cell,
1661 GTK_WIDGET (icon_view),
1667 g_free (path_string);
1672 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1673 GtkIconViewItem *item)
1676 AtkObject *item_obj;
1678 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1681 item_obj = atk_object_ref_accessible_child (obj, item->index);
1682 if (item_obj != NULL)
1684 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1685 g_object_unref (item_obj);
1691 gtk_icon_view_put (GtkIconView *icon_view,
1693 GtkIconViewItem *item,
1696 GtkIconViewChild *child;
1698 child = g_new (GtkIconViewChild, 1);
1700 child->widget = widget;
1704 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1706 if (GTK_WIDGET_REALIZED (icon_view))
1707 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1709 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1713 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1714 GtkIconView *icon_view)
1717 GtkIconViewItem *item;
1719 if (icon_view->priv->edited_item == NULL)
1722 item = icon_view->priv->edited_item;
1723 icon_view->priv->edited_item = NULL;
1724 icon_view->priv->editable = NULL;
1725 for (l = icon_view->priv->cell_list; l; l = l->next)
1727 GtkIconViewCellInfo *info = l->data;
1729 info->editing = FALSE;
1732 if (GTK_WIDGET_HAS_FOCUS (editable))
1733 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1735 g_signal_handlers_disconnect_by_func (editable,
1736 gtk_icon_view_remove_widget,
1739 gtk_container_remove (GTK_CONTAINER (icon_view),
1740 GTK_WIDGET (editable));
1742 gtk_icon_view_queue_draw_item (icon_view, item);
1747 gtk_icon_view_start_editing (GtkIconView *icon_view,
1748 GtkIconViewItem *item,
1749 GtkIconViewCellInfo *info,
1754 GdkRectangle cell_area;
1755 gboolean visible, mode;
1756 GtkCellEditable *editable;
1758 gtk_icon_view_set_cell_data (icon_view, item);
1760 g_object_get (info->cell,
1761 "visible", &visible,
1764 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1766 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1768 path = gtk_tree_path_new_from_indices (item->index, -1);
1769 path_string = gtk_tree_path_to_string (path);
1770 gtk_tree_path_free (path);
1772 editable = gtk_cell_renderer_start_editing (info->cell,
1774 GTK_WIDGET (icon_view),
1779 g_free (path_string);
1781 /* FIXME ugly special case */
1782 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1783 g_object_set (editable, "has-frame", TRUE, NULL);
1785 /* the rest corresponds to tree_view_real_start_editing... */
1786 icon_view->priv->edited_item = item;
1787 icon_view->priv->editable = editable;
1788 info->editing = TRUE;
1790 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1792 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1794 gtk_widget_grab_focus (GTK_WIDGET (editable));
1795 g_signal_connect (editable, "remove_widget",
1796 G_CALLBACK (gtk_icon_view_remove_widget),
1803 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1804 gboolean cancel_editing)
1806 GtkCellRenderer *cell = NULL;
1807 GtkIconViewItem *item;
1810 if (icon_view->priv->edited_item == NULL)
1814 * This is very evil. We need to do this, because
1815 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1816 * later on. If gtk_icon_view_row_changed notices
1817 * icon_view->priv->edited_item != NULL, it'll call
1818 * gtk_icon_view_stop_editing again. Bad things will happen then.
1820 * Please read that again if you intend to modify anything here.
1823 item = icon_view->priv->edited_item;
1824 icon_view->priv->edited_item = NULL;
1826 for (l = icon_view->priv->cell_list; l; l = l->next)
1828 GtkIconViewCellInfo *info = l->data;
1840 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1841 if (!cancel_editing)
1842 gtk_cell_editable_editing_done (icon_view->priv->editable);
1844 icon_view->priv->edited_item = item;
1846 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1850 * gtk_icon_view_set_cursor:
1851 * @icon_view: A #GtkIconView
1852 * @path: A #GtkTreePath
1853 * @cell: One of the cell renderers of @icon_view, or %NULL
1854 * @start_editing: %TRUE if the specified cell should start being edited.
1856 * Sets the current keyboard focus to be at @path, and selects it. This is
1857 * useful when you want to focus the user's attention on a particular item.
1858 * If @cell is not %NULL, then focus is given to the cell specified by
1859 * it. Additionally, if @start_editing is %TRUE, then editing should be
1860 * started in the specified cell.
1862 * This function is often followed by <literal>gtk_widget_grab_focus
1863 * (icon_view)</literal> in order to give keyboard focus to the widget.
1864 * Please note that editing can only happen when the widget is realized.
1869 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1871 GtkCellRenderer *cell,
1872 gboolean start_editing)
1874 GtkIconViewItem *item = NULL;
1875 GtkIconViewCellInfo *info = NULL;
1879 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1880 g_return_if_fail (path != NULL);
1881 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1883 gtk_icon_view_stop_editing (icon_view, TRUE);
1885 if (gtk_tree_path_get_depth (path) == 1)
1886 item = g_list_nth_data (icon_view->priv->items,
1887 gtk_tree_path_get_indices(path)[0]);
1893 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1897 if (info->cell == cell)
1906 g_return_if_fail (cell == NULL || info != NULL);
1908 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1909 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1911 if (info && start_editing)
1912 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1916 * gtk_icon_view_get_cursor:
1917 * @icon_view: A #GtkIconView
1918 * @path: Return location for the current cursor path, or %NULL
1919 * @cell: Return location the current focus cell, or %NULL
1921 * Fills in @path and @cell with the current cursor path and cell.
1922 * If the cursor isn't currently set, then *@path will be %NULL.
1923 * If no cell currently has focus, then *@cell will be %NULL.
1925 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1927 * Return value: %TRUE if the cursor is set.
1932 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1934 GtkCellRenderer **cell)
1936 GtkIconViewItem *item;
1937 GtkIconViewCellInfo *info;
1939 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1941 item = icon_view->priv->cursor_item;
1942 if (icon_view->priv->cursor_cell < 0)
1945 info = g_list_nth_data (icon_view->priv->cell_list,
1946 icon_view->priv->cursor_cell);
1951 *path = gtk_tree_path_new_from_indices (item->index, -1);
1964 return (item != NULL);
1968 gtk_icon_view_button_press (GtkWidget *widget,
1969 GdkEventButton *event)
1971 GtkIconView *icon_view;
1972 GtkIconViewItem *item;
1973 GtkIconViewCellInfo *info = NULL;
1974 gboolean dirty = FALSE;
1975 GtkCellRendererMode mode;
1978 icon_view = GTK_ICON_VIEW (widget);
1980 if (event->window != icon_view->priv->bin_window)
1983 if (!GTK_WIDGET_HAS_FOCUS (widget))
1984 gtk_widget_grab_focus (widget);
1986 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1988 item = gtk_icon_view_get_item_at_coords (icon_view,
1994 g_object_get (info->cell, "mode", &mode, NULL);
1996 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1997 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1998 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2002 gtk_icon_view_scroll_to_item (icon_view, item);
2004 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2006 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2008 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2009 (event->state & GDK_SHIFT_MASK))
2011 gtk_icon_view_unselect_all_internal (icon_view);
2013 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2014 if (!icon_view->priv->anchor_item)
2015 icon_view->priv->anchor_item = item;
2017 gtk_icon_view_select_all_between (icon_view,
2018 icon_view->priv->anchor_item,
2024 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2025 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2026 (event->state & GDK_CONTROL_MASK))
2028 item->selected = !item->selected;
2029 gtk_icon_view_queue_draw_item (icon_view, item);
2034 if (!item->selected)
2036 gtk_icon_view_unselect_all_internal (icon_view);
2038 item->selected = TRUE;
2039 gtk_icon_view_queue_draw_item (icon_view, item);
2043 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2044 icon_view->priv->anchor_item = item;
2047 /* Save press to possibly begin a drag */
2048 if (icon_view->priv->pressed_button < 0)
2050 icon_view->priv->pressed_button = event->button;
2051 icon_view->priv->press_start_x = event->x;
2052 icon_view->priv->press_start_y = event->y;
2055 if (!icon_view->priv->last_single_clicked)
2056 icon_view->priv->last_single_clicked = item;
2058 /* cancel the current editing, if it exists */
2059 gtk_icon_view_stop_editing (icon_view, TRUE);
2061 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2062 gtk_icon_view_item_activate_cell (icon_view, item, info,
2064 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2065 gtk_icon_view_start_editing (icon_view, item, info,
2070 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2071 !(event->state & GDK_CONTROL_MASK))
2073 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2076 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2077 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2082 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2084 item = gtk_icon_view_get_item_at_coords (icon_view,
2089 if (item && item == icon_view->priv->last_single_clicked)
2093 path = gtk_tree_path_new_from_indices (item->index, -1);
2094 gtk_icon_view_item_activated (icon_view, path);
2095 gtk_tree_path_free (path);
2098 icon_view->priv->last_single_clicked = NULL;
2099 icon_view->priv->pressed_button = -1;
2103 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2105 return event->button == 1;
2109 gtk_icon_view_button_release (GtkWidget *widget,
2110 GdkEventButton *event)
2112 GtkIconView *icon_view;
2114 icon_view = GTK_ICON_VIEW (widget);
2116 if (icon_view->priv->pressed_button == event->button)
2117 icon_view->priv->pressed_button = -1;
2119 gtk_icon_view_stop_rubberbanding (icon_view);
2121 remove_scroll_timeout (icon_view);
2127 gtk_icon_view_key_press (GtkWidget *widget,
2130 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2132 if (icon_view->priv->doing_rubberband)
2134 if (event->keyval == GDK_Escape)
2135 gtk_icon_view_stop_rubberbanding (icon_view);
2140 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2144 gtk_icon_view_key_release (GtkWidget *widget,
2147 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2149 if (icon_view->priv->doing_rubberband)
2152 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2156 gtk_icon_view_update_rubberband (gpointer data)
2158 GtkIconView *icon_view;
2160 GdkRectangle old_area;
2161 GdkRectangle new_area;
2162 GdkRectangle common;
2163 GdkRegion *invalid_region;
2165 icon_view = GTK_ICON_VIEW (data);
2167 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2172 old_area.x = MIN (icon_view->priv->rubberband_x1,
2173 icon_view->priv->rubberband_x2);
2174 old_area.y = MIN (icon_view->priv->rubberband_y1,
2175 icon_view->priv->rubberband_y2);
2176 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2177 icon_view->priv->rubberband_x1) + 1;
2178 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2179 icon_view->priv->rubberband_y1) + 1;
2181 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2182 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2183 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2184 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2186 invalid_region = gdk_region_rectangle (&old_area);
2187 gdk_region_union_with_rect (invalid_region, &new_area);
2189 gdk_rectangle_intersect (&old_area, &new_area, &common);
2190 if (common.width > 2 && common.height > 2)
2192 GdkRegion *common_region;
2194 /* make sure the border is invalidated */
2200 common_region = gdk_region_rectangle (&common);
2202 gdk_region_subtract (invalid_region, common_region);
2203 gdk_region_destroy (common_region);
2206 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2208 gdk_region_destroy (invalid_region);
2210 icon_view->priv->rubberband_x2 = x;
2211 icon_view->priv->rubberband_y2 = y;
2213 gtk_icon_view_update_rubberband_selection (icon_view);
2217 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2223 g_assert (!icon_view->priv->doing_rubberband);
2225 for (items = icon_view->priv->items; items; items = items->next)
2227 GtkIconViewItem *item = items->data;
2229 item->selected_before_rubberbanding = item->selected;
2232 icon_view->priv->rubberband_x1 = x;
2233 icon_view->priv->rubberband_y1 = y;
2234 icon_view->priv->rubberband_x2 = x;
2235 icon_view->priv->rubberband_y2 = y;
2237 icon_view->priv->doing_rubberband = TRUE;
2239 gtk_grab_add (GTK_WIDGET (icon_view));
2243 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2245 if (!icon_view->priv->doing_rubberband)
2248 icon_view->priv->doing_rubberband = FALSE;
2250 gtk_grab_remove (GTK_WIDGET (icon_view));
2252 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2256 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2259 gint x, y, width, height;
2260 gboolean dirty = FALSE;
2262 x = MIN (icon_view->priv->rubberband_x1,
2263 icon_view->priv->rubberband_x2);
2264 y = MIN (icon_view->priv->rubberband_y1,
2265 icon_view->priv->rubberband_y2);
2266 width = ABS (icon_view->priv->rubberband_x1 -
2267 icon_view->priv->rubberband_x2);
2268 height = ABS (icon_view->priv->rubberband_y1 -
2269 icon_view->priv->rubberband_y2);
2271 for (items = icon_view->priv->items; items; items = items->next)
2273 GtkIconViewItem *item = items->data;
2277 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2278 x, y, width, height);
2280 selected = is_in ^ item->selected_before_rubberbanding;
2282 if (item->selected != selected)
2284 item->selected = selected;
2286 gtk_icon_view_queue_draw_item (icon_view, item);
2291 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2295 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2296 GtkIconViewItem *item,
2305 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2306 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2309 for (l = icon_view->priv->cell_list; l; l = l->next)
2311 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2313 if (!info->cell->visible)
2316 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2318 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2319 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2327 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2329 gboolean dirty = FALSE;
2332 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2335 for (items = icon_view->priv->items; items; items = items->next)
2337 GtkIconViewItem *item = items->data;
2341 item->selected = FALSE;
2343 gtk_icon_view_queue_draw_item (icon_view, item);
2344 gtk_icon_view_item_selected_changed (icon_view, item);
2352 /* GtkIconView signals */
2354 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2355 GtkAdjustment *hadj,
2356 GtkAdjustment *vadj)
2358 gboolean need_adjust = FALSE;
2361 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2363 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2365 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2367 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2369 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2371 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2372 0, 0, NULL, NULL, icon_view);
2373 g_object_unref (icon_view->priv->hadjustment);
2376 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2378 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2379 0, 0, NULL, NULL, icon_view);
2380 g_object_unref (icon_view->priv->vadjustment);
2383 if (icon_view->priv->hadjustment != hadj)
2385 icon_view->priv->hadjustment = hadj;
2386 g_object_ref_sink (icon_view->priv->hadjustment);
2388 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2389 G_CALLBACK (gtk_icon_view_adjustment_changed),
2394 if (icon_view->priv->vadjustment != vadj)
2396 icon_view->priv->vadjustment = vadj;
2397 g_object_ref_sink (icon_view->priv->vadjustment);
2399 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2400 G_CALLBACK (gtk_icon_view_adjustment_changed),
2406 gtk_icon_view_adjustment_changed (NULL, icon_view);
2410 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2412 gtk_icon_view_select_all (icon_view);
2416 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2418 gtk_icon_view_unselect_all (icon_view);
2422 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2424 gtk_icon_view_unselect_all (icon_view);
2426 if (icon_view->priv->cursor_item != NULL)
2427 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2431 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2434 GtkCellRendererMode mode;
2435 GtkIconViewCellInfo *info = NULL;
2437 if (!icon_view->priv->cursor_item)
2440 info = g_list_nth_data (icon_view->priv->cell_list,
2441 icon_view->priv->cursor_cell);
2445 g_object_get (info->cell, "mode", &mode, NULL);
2447 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2449 gtk_icon_view_item_activate_cell (icon_view,
2450 icon_view->priv->cursor_item,
2454 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2456 gtk_icon_view_start_editing (icon_view,
2457 icon_view->priv->cursor_item,
2463 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2464 gtk_icon_view_item_activated (icon_view, path);
2465 gtk_tree_path_free (path);
2471 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2473 if (!icon_view->priv->cursor_item)
2476 switch (icon_view->priv->selection_mode)
2478 case GTK_SELECTION_NONE:
2480 case GTK_SELECTION_BROWSE:
2481 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2483 case GTK_SELECTION_SINGLE:
2484 if (icon_view->priv->cursor_item->selected)
2485 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2487 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2489 case GTK_SELECTION_MULTIPLE:
2490 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2491 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2493 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2494 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2499 /* Internal functions */
2501 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2502 GtkIconView *icon_view)
2504 if (GTK_WIDGET_REALIZED (icon_view))
2506 gdk_window_move (icon_view->priv->bin_window,
2507 - icon_view->priv->hadjustment->value,
2508 - icon_view->priv->vadjustment->value);
2510 if (icon_view->priv->doing_rubberband)
2511 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2513 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2518 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2523 gint *maximum_width)
2526 gint x, current_width;
2527 GList *items, *last_item;
2534 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2535 max_height = g_new0 (gint, icon_view->priv->n_cells);
2542 gtk_widget_style_get (GTK_WIDGET (icon_view),
2543 "focus-line-width", &focus_width,
2546 x += icon_view->priv->margin + focus_width;
2547 current_width += 2 * (icon_view->priv->margin + focus_width);
2552 GtkIconViewItem *item = items->data;
2554 gtk_icon_view_calculate_item_size (icon_view, item);
2555 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2557 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2559 current_width += item->width;
2561 if (items != first_item)
2563 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2564 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2568 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2570 item->y = *y + focus_width;
2571 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2573 x = current_width - (icon_view->priv->margin + focus_width);
2575 for (i = 0; i < icon_view->priv->n_cells; i++)
2576 max_height[i] = MAX (max_height[i], item->box[i].height);
2578 if (current_width > *maximum_width)
2579 *maximum_width = current_width;
2585 items = items->next;
2590 /* Now go through the row again and align the icons */
2591 for (items = first_item; items != last_item; items = items->next)
2593 GtkIconViewItem *item = items->data;
2595 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2597 /* We may want to readjust the new y coordinate. */
2598 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2599 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2602 item->col = col - 1 - item->col;
2605 g_free (max_height);
2611 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2614 if (upper != adj->upper)
2616 gdouble min = MAX (0.0, upper - adj->page_size);
2617 gboolean value_changed = FALSE;
2621 if (adj->value > min)
2624 value_changed = TRUE;
2627 gtk_adjustment_changed (adj);
2630 gtk_adjustment_value_changed (adj);
2635 gtk_icon_view_layout (GtkIconView *icon_view)
2637 gint y = 0, maximum_width = 0;
2643 if (icon_view->priv->layout_idle_id != 0)
2645 g_source_remove (icon_view->priv->layout_idle_id);
2646 icon_view->priv->layout_idle_id = 0;
2649 if (icon_view->priv->model == NULL)
2652 widget = GTK_WIDGET (icon_view);
2654 item_width = icon_view->priv->item_width;
2658 for (icons = icon_view->priv->items; icons; icons = icons->next)
2660 GtkIconViewItem *item = icons->data;
2661 gtk_icon_view_calculate_item_size (icon_view, item);
2662 item_width = MAX (item_width, item->width);
2667 icons = icon_view->priv->items;
2668 y += icon_view->priv->margin;
2673 gtk_icon_view_set_cell_data (icon_view, icons->data);
2674 adjust_wrap_width (icon_view, icons->data);
2679 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2681 &y, &maximum_width);
2684 while (icons != NULL);
2686 if (maximum_width != icon_view->priv->width)
2687 icon_view->priv->width = maximum_width;
2689 y += icon_view->priv->margin;
2691 if (y != icon_view->priv->height)
2692 icon_view->priv->height = y;
2694 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2695 icon_view->priv->width);
2696 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2697 icon_view->priv->height);
2699 if (icon_view->priv->width != widget->requisition.width ||
2700 icon_view->priv->height != widget->requisition.height)
2701 gtk_widget_queue_resize_no_redraw (widget);
2703 if (GTK_WIDGET_REALIZED (icon_view))
2704 gdk_window_resize (icon_view->priv->bin_window,
2705 MAX (icon_view->priv->width, widget->allocation.width),
2706 MAX (icon_view->priv->height, widget->allocation.height));
2708 if (icon_view->priv->scroll_to_path)
2712 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2713 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2714 icon_view->priv->scroll_to_path = NULL;
2716 gtk_icon_view_scroll_to_path (icon_view, path,
2717 icon_view->priv->scroll_to_use_align,
2718 icon_view->priv->scroll_to_row_align,
2719 icon_view->priv->scroll_to_col_align);
2720 gtk_tree_path_free (path);
2723 gtk_widget_queue_draw (widget);
2727 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2728 GtkIconViewItem *item,
2729 GtkIconViewCellInfo *info,
2730 GdkRectangle *cell_area)
2732 g_return_if_fail (info->position < item->n_cells);
2734 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2736 cell_area->x = item->box[info->position].x - item->before[info->position];
2737 cell_area->y = item->y;
2738 cell_area->width = item->box[info->position].width +
2739 item->before[info->position] + item->after[info->position];
2740 cell_area->height = item->height;
2744 cell_area->x = item->x;
2745 cell_area->y = item->box[info->position].y - item->before[info->position];
2746 cell_area->width = item->width;
2747 cell_area->height = item->box[info->position].height +
2748 item->before[info->position] + item->after[info->position];
2753 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2754 GtkIconViewItem *item,
2755 GtkIconViewCellInfo *info,
2758 g_return_if_fail (info->position < item->n_cells);
2760 *box = item->box[info->position];
2763 /* try to guess a reasonable wrap width for an implicit text cell renderer
2766 adjust_wrap_width (GtkIconView *icon_view,
2767 GtkIconViewItem *item)
2769 GtkIconViewCellInfo *text_info;
2770 GtkIconViewCellInfo *pixbuf_info;
2771 gint pixbuf_width, wrap_width;
2773 if (icon_view->priv->text_cell != -1 &&
2774 icon_view->priv->pixbuf_cell != -1)
2778 text_info = g_list_nth_data (icon_view->priv->cell_list,
2779 icon_view->priv->text_cell);
2780 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2781 icon_view->priv->pixbuf_cell);
2783 gtk_cell_renderer_get_size (pixbuf_info->cell,
2784 GTK_WIDGET (icon_view),
2790 if (icon_view->priv->item_width > 0)
2791 item_width = icon_view->priv->item_width;
2793 item_width = item->width;
2795 if (item->width == -1)
2798 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2800 wrap_width = MAX (2 * pixbuf_width, 50);
2802 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2803 wrap_width = item_width;
2805 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2807 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2808 g_object_set (text_info->cell, "width", wrap_width, NULL);
2813 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2814 GtkIconViewItem *item)
2819 if (item->width != -1 && item->height != -1)
2822 if (item->n_cells != icon_view->priv->n_cells)
2824 g_free (item->before);
2825 g_free (item->after);
2828 item->before = g_new0 (gint, icon_view->priv->n_cells);
2829 item->after = g_new0 (gint, icon_view->priv->n_cells);
2830 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2832 item->n_cells = icon_view->priv->n_cells;
2835 gtk_icon_view_set_cell_data (icon_view, item);
2837 spacing = icon_view->priv->spacing;
2841 for (l = icon_view->priv->cell_list; l; l = l->next)
2843 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2845 if (!info->cell->visible)
2848 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2850 &item->box[info->position].width,
2851 &item->box[info->position].height);
2853 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2855 item->width += item->box[info->position].width
2856 + (info->position > 0 ? spacing : 0);
2857 item->height = MAX (item->height, item->box[info->position].height);
2861 item->width = MAX (item->width, item->box[info->position].width);
2862 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2868 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2869 GtkIconViewItem *item,
2872 GdkRectangle cell_area;
2878 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2880 gtk_icon_view_set_cell_data (icon_view, item);
2882 spacing = icon_view->priv->spacing;
2885 for (i = 0; i < icon_view->priv->n_cells; i++)
2887 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2888 item->height = MAX (item->height, max_height[i]);
2890 item->height += max_height[i] + (i > 0 ? spacing : 0);
2893 cell_area.x = item->x;
2894 cell_area.y = item->y;
2896 for (k = 0; k < 2; k++)
2897 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2899 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2901 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2904 if (!info->cell->visible)
2907 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2909 cell_area.width = item->box[info->position].width;
2910 cell_area.height = item->height;
2914 cell_area.width = item->width;
2915 cell_area.height = max_height[i];
2918 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2920 &item->box[info->position].x, &item->box[info->position].y,
2921 &item->box[info->position].width, &item->box[info->position].height);
2923 item->box[info->position].x += cell_area.x;
2924 item->box[info->position].y += cell_area.y;
2925 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2927 item->before[info->position] = item->box[info->position].x - cell_area.x;
2928 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2929 cell_area.x += cell_area.width + spacing;
2933 if (item->box[info->position].width > item->width)
2935 item->width = item->box[info->position].width;
2936 cell_area.width = item->width;
2938 item->before[info->position] = item->box[info->position].y - cell_area.y;
2939 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2940 cell_area.y += cell_area.height + spacing;
2944 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2946 for (i = 0; i < icon_view->priv->n_cells; i++)
2948 item->box[i].x = item->x + item->width -
2949 (item->box[i].x + item->box[i].width - item->x);
2955 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2957 g_list_foreach (icon_view->priv->items,
2958 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2962 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2969 gtk_icon_view_paint_item (GtkIconView *icon_view,
2971 GtkIconViewItem *item,
2973 GdkDrawable *drawable,
2976 gboolean draw_focus)
2980 GdkRectangle cell_area, box;
2984 GtkCellRendererState flags;
2986 if (icon_view->priv->model == NULL)
2989 gtk_icon_view_set_cell_data (icon_view, item);
2991 gtk_widget_style_get (GTK_WIDGET (icon_view),
2992 "focus-line-width", &focus_width,
2995 padding = focus_width;
2999 flags = GTK_CELL_RENDERER_SELECTED;
3000 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3001 state = GTK_STATE_SELECTED;
3003 state = GTK_STATE_ACTIVE;
3008 state = GTK_STATE_NORMAL;
3011 #ifdef DEBUG_ICON_VIEW
3012 gdk_draw_rectangle (drawable,
3013 GTK_WIDGET (icon_view)->style->black_gc,
3016 item->width, item->height);
3020 for (l = icon_view->priv->cell_list; l; l = l->next)
3022 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3024 if (!info->cell->visible)
3027 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3029 /* FIXME we hardwire background drawing behind text
3030 * cell renderers here
3032 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3034 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
3035 cairo_rectangle (cr,
3036 x - item->x + box.x,
3037 y - item->y + box.y,
3038 box.width, box.height);
3043 for (l = icon_view->priv->cell_list; l; l = l->next)
3045 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3047 if (!info->cell->visible)
3050 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3052 #ifdef DEBUG_ICON_VIEW
3053 gdk_draw_rectangle (drawable,
3054 GTK_WIDGET (icon_view)->style->black_gc,
3056 x - item->x + cell_area.x,
3057 y - item->y + cell_area.y,
3058 cell_area.width, cell_area.height);
3060 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3062 gdk_draw_rectangle (drawable,
3063 GTK_WIDGET (icon_view)->style->black_gc,
3065 x - item->x + box.x,
3066 y - item->y + box.y,
3067 box.width, box.height);
3070 cell_area.x = x - item->x + cell_area.x;
3071 cell_area.y = y - item->y + cell_area.y;
3073 gtk_cell_renderer_render (info->cell,
3075 GTK_WIDGET (icon_view),
3076 &cell_area, &cell_area, area, flags);
3080 /* FIXME where to draw the focus with generic cell renderers ? */
3082 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3083 item == icon_view->priv->cursor_item)
3084 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3086 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3088 if (!info->cell->visible)
3091 if (icon_view->priv->cursor_cell < 0 &&
3092 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3093 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3094 icon_view->priv->cursor_cell = i;
3096 if (i == icon_view->priv->cursor_cell)
3098 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3100 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3104 GTK_WIDGET (icon_view),
3106 x - item->x + box.x - padding,
3107 y - item->y + box.y - padding,
3108 box.width + 2 * padding,
3109 box.height + 2 * padding);
3116 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3121 GdkRectangle rubber_rect;
3122 GdkColor *fill_color_gdk;
3123 guchar fill_color_alpha;
3125 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3126 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3127 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3128 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3130 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3133 gtk_widget_style_get (GTK_WIDGET (icon_view),
3134 "selection-box-color", &fill_color_gdk,
3135 "selection-box-alpha", &fill_color_alpha,
3138 if (!fill_color_gdk)
3139 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3141 cairo_set_source_rgba (cr,
3142 fill_color_gdk->red / 65535.,
3143 fill_color_gdk->green / 65535.,
3144 fill_color_gdk->blue / 65535.,
3145 fill_color_alpha / 255.);
3148 gdk_cairo_rectangle (cr, &rect);
3152 /* Draw the border without alpha */
3153 cairo_set_source_rgb (cr,
3154 fill_color_gdk->red / 65535.,
3155 fill_color_gdk->green / 65535.,
3156 fill_color_gdk->blue / 65535.);
3157 cairo_rectangle (cr,
3158 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3159 rubber_rect.width - 1, rubber_rect.height - 1);
3163 gdk_color_free (fill_color_gdk);
3167 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3173 index = gtk_tree_path_get_indices (path)[0];
3175 for (l = icon_view->priv->items; l; l = l->next)
3177 GtkIconViewItem *item = l->data;
3179 if (item->index == index)
3181 gtk_icon_view_queue_draw_item (icon_view, item);
3188 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3189 GtkIconViewItem *item)
3194 gtk_widget_style_get (GTK_WIDGET (icon_view),
3195 "focus-line-width", &focus_width,
3198 rect.x = item->x - focus_width;
3199 rect.y = item->y - focus_width;
3200 rect.width = item->width + 2 * focus_width;
3201 rect.height = item->height + 2 * focus_width;
3203 if (icon_view->priv->bin_window)
3204 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3208 layout_callback (gpointer user_data)
3210 GtkIconView *icon_view;
3212 icon_view = GTK_ICON_VIEW (user_data);
3214 icon_view->priv->layout_idle_id = 0;
3216 gtk_icon_view_layout (icon_view);
3222 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3224 if (icon_view->priv->layout_idle_id != 0)
3227 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3231 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3232 GtkIconViewItem *item,
3236 AtkObject *item_obj;
3237 AtkObject *cursor_item_obj;
3239 if (icon_view->priv->cursor_item == item &&
3240 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3243 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3244 if (icon_view->priv->cursor_item != NULL)
3246 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3249 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3250 if (cursor_item_obj != NULL)
3251 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3254 icon_view->priv->cursor_item = item;
3255 if (cursor_cell >= 0)
3256 icon_view->priv->cursor_cell = cursor_cell;
3258 gtk_icon_view_queue_draw_item (icon_view, item);
3260 /* Notify that accessible focus object has changed */
3261 item_obj = atk_object_ref_accessible_child (obj, item->index);
3263 if (item_obj != NULL)
3265 atk_focus_tracker_notify (item_obj);
3266 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3267 g_object_unref (item_obj);
3272 static GtkIconViewItem *
3273 gtk_icon_view_item_new (void)
3275 GtkIconViewItem *item;
3277 item = g_new0 (GtkIconViewItem, 1);
3286 gtk_icon_view_item_free (GtkIconViewItem *item)
3288 g_return_if_fail (item != NULL);
3290 g_free (item->before);
3291 g_free (item->after);
3298 static GtkIconViewItem *
3299 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3302 gboolean only_in_cell,
3303 GtkIconViewCellInfo **cell_at_pos)
3308 for (items = icon_view->priv->items; items; items = items->next)
3310 GtkIconViewItem *item = items->data;
3312 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3313 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3315 if (only_in_cell || cell_at_pos)
3317 gtk_icon_view_set_cell_data (icon_view, item);
3319 for (l = icon_view->priv->cell_list; l; l = l->next)
3321 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3323 if (!info->cell->visible)
3326 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3328 if ((x >= box.x && x <= box.x + box.width &&
3329 y >= box.y && y <= box.y + box.height) ||
3331 x <= box.x + box.width &&
3333 y <= box.y + box.height))
3336 *cell_at_pos = info;
3346 *cell_at_pos = NULL;
3357 gtk_icon_view_select_item (GtkIconView *icon_view,
3358 GtkIconViewItem *item)
3360 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3361 g_return_if_fail (item != NULL);
3366 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3368 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3369 gtk_icon_view_unselect_all_internal (icon_view);
3371 item->selected = TRUE;
3373 gtk_icon_view_item_selected_changed (icon_view, item);
3374 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3376 gtk_icon_view_queue_draw_item (icon_view, item);
3381 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3382 GtkIconViewItem *item)
3384 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3385 g_return_if_fail (item != NULL);
3387 if (!item->selected)
3390 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3391 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3394 item->selected = FALSE;
3396 gtk_icon_view_item_selected_changed (icon_view, item);
3397 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3399 gtk_icon_view_queue_draw_item (icon_view, item);
3403 verify_items (GtkIconView *icon_view)
3408 for (items = icon_view->priv->items; items; items = items->next)
3410 GtkIconViewItem *item = items->data;
3412 if (item->index != i)
3413 g_error ("List item does not match its index: "
3414 "item index %d and list index %d\n", item->index, i);
3421 gtk_icon_view_row_changed (GtkTreeModel *model,
3426 GtkIconViewItem *item;
3428 GtkIconView *icon_view;
3430 icon_view = GTK_ICON_VIEW (data);
3432 gtk_icon_view_stop_editing (icon_view, TRUE);
3434 index = gtk_tree_path_get_indices(path)[0];
3435 item = g_list_nth_data (icon_view->priv->items, index);
3437 gtk_icon_view_item_invalidate_size (item);
3438 gtk_icon_view_queue_layout (icon_view);
3440 verify_items (icon_view);
3444 gtk_icon_view_row_inserted (GtkTreeModel *model,
3450 GtkIconViewItem *item;
3451 gboolean iters_persist;
3452 GtkIconView *icon_view;
3455 icon_view = GTK_ICON_VIEW (data);
3457 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3459 index = gtk_tree_path_get_indices(path)[0];
3461 item = gtk_icon_view_item_new ();
3466 item->index = index;
3468 /* FIXME: We can be more efficient here,
3469 we can store a tail pointer and use that when
3470 appending (which is a rather common operation)
3472 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3475 list = g_list_nth (icon_view->priv->items, index + 1);
3476 for (; list; list = list->next)
3483 verify_items (icon_view);
3485 gtk_icon_view_queue_layout (icon_view);
3489 gtk_icon_view_row_deleted (GtkTreeModel *model,
3494 GtkIconView *icon_view;
3495 GtkIconViewItem *item;
3497 gboolean emit = FALSE;
3499 icon_view = GTK_ICON_VIEW (data);
3501 index = gtk_tree_path_get_indices(path)[0];
3503 list = g_list_nth (icon_view->priv->items, index);
3506 gtk_icon_view_stop_editing (icon_view, TRUE);
3508 if (item == icon_view->priv->anchor_item)
3509 icon_view->priv->anchor_item = NULL;
3511 if (item == icon_view->priv->cursor_item)
3512 icon_view->priv->cursor_item = NULL;
3517 gtk_icon_view_item_free (item);
3519 for (next = list->next; next; next = next->next)
3526 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3528 verify_items (icon_view);
3530 gtk_icon_view_queue_layout (icon_view);
3533 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3537 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3538 GtkTreePath *parent,
3545 GtkIconView *icon_view;
3546 GList *items = NULL, *list;
3547 GtkIconViewItem **item_array;
3550 icon_view = GTK_ICON_VIEW (data);
3552 gtk_icon_view_stop_editing (icon_view, TRUE);
3554 length = gtk_tree_model_iter_n_children (model, NULL);
3556 order = g_new (gint, length);
3557 for (i = 0; i < length; i++)
3558 order [new_order[i]] = i;
3560 item_array = g_new (GtkIconViewItem *, length);
3561 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3562 item_array[order[i]] = list->data;
3565 for (i = length - 1; i >= 0; i--)
3567 item_array[i]->index = i;
3568 items = g_list_prepend (items, item_array[i]);
3571 g_free (item_array);
3572 g_list_free (icon_view->priv->items);
3573 icon_view->priv->items = items;
3575 gtk_icon_view_queue_layout (icon_view);
3577 verify_items (icon_view);
3581 gtk_icon_view_build_items (GtkIconView *icon_view)
3585 gboolean iters_persist;
3586 GList *items = NULL;
3588 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3590 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3598 GtkIconViewItem *item = gtk_icon_view_item_new ();
3607 items = g_list_prepend (items, item);
3609 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3611 icon_view->priv->items = g_list_reverse (items);
3615 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3618 GtkMovementStep step,
3622 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3623 I_("move_cursor"), 2,
3627 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3632 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3635 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3640 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3647 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3648 GtkMovementStep step,
3651 GdkModifierType state;
3653 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3654 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3655 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3656 step == GTK_MOVEMENT_DISPLAY_LINES ||
3657 step == GTK_MOVEMENT_PAGES ||
3658 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3660 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3663 gtk_icon_view_stop_editing (icon_view, FALSE);
3664 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3666 if (gtk_get_current_event_state (&state))
3668 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3669 icon_view->priv->ctrl_pressed = TRUE;
3670 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3671 icon_view->priv->shift_pressed = TRUE;
3673 /* else we assume not pressed */
3677 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3678 case GTK_MOVEMENT_VISUAL_POSITIONS:
3679 gtk_icon_view_move_cursor_left_right (icon_view, count);
3681 case GTK_MOVEMENT_DISPLAY_LINES:
3682 gtk_icon_view_move_cursor_up_down (icon_view, count);
3684 case GTK_MOVEMENT_PAGES:
3685 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3687 case GTK_MOVEMENT_BUFFER_ENDS:
3688 gtk_icon_view_move_cursor_start_end (icon_view, count);
3691 g_assert_not_reached ();
3694 icon_view->priv->ctrl_pressed = FALSE;
3695 icon_view->priv->shift_pressed = FALSE;
3700 static GtkIconViewItem *
3701 find_item (GtkIconView *icon_view,
3702 GtkIconViewItem *current,
3708 GtkIconViewItem *item;
3710 /* FIXME: this could be more efficient
3712 row = current->row + row_ofs;
3713 col = current->col + col_ofs;
3715 for (items = icon_view->priv->items; items; items = items->next)
3718 if (item->row == row && item->col == col)
3726 find_cell (GtkIconView *icon_view,
3727 GtkIconViewItem *item,
3729 GtkOrientation orientation,
3740 if (icon_view->priv->orientation != orientation)
3743 gtk_icon_view_set_cell_data (icon_view, item);
3745 focusable = g_new0 (gint, icon_view->priv->n_cells);
3750 for (k = 0; k < 2; k++)
3751 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3753 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3755 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3758 if (!info->cell->visible)
3761 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3764 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3767 current = n_focusable;
3769 focusable[n_focusable] = i;
3775 if (n_focusable == 0)
3776 focusable[n_focusable++] = first_text;
3780 current = step > 0 ? 0 : n_focusable - 1;
3781 cell = focusable[current];
3784 if (current + *count < 0)
3787 *count = current + *count;
3789 else if (current + *count > n_focusable - 1)
3792 *count = current + *count - (n_focusable - 1);
3796 cell = focusable[current + *count];
3805 static GtkIconViewItem *
3806 find_item_page_up_down (GtkIconView *icon_view,
3807 GtkIconViewItem *current,
3814 y = current->y + count * icon_view->priv->vadjustment->page_size;
3816 item = g_list_find (icon_view->priv->items, current);
3821 for (next = item->next; next; next = next->next)
3823 if (((GtkIconViewItem *)next->data)->col == col)
3826 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3836 for (next = item->prev; next; next = next->prev)
3838 if (((GtkIconViewItem *)next->data)->col == col)
3841 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3855 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3856 GtkIconViewItem *anchor,
3857 GtkIconViewItem *cursor)
3860 GtkIconViewItem *item;
3861 gint row1, row2, col1, col2;
3862 gboolean dirty = FALSE;
3864 if (anchor->row < cursor->row)
3875 if (anchor->col < cursor->col)
3886 for (items = icon_view->priv->items; items; items = items->next)
3890 if (row1 <= item->row && item->row <= row2 &&
3891 col1 <= item->col && item->col <= col2)
3893 if (!item->selected)
3896 item->selected = TRUE;
3897 gtk_icon_view_item_selected_changed (icon_view, item);
3899 gtk_icon_view_queue_draw_item (icon_view, item);
3907 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3910 GtkIconViewItem *item;
3912 gboolean dirty = FALSE;
3915 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3918 if (!icon_view->priv->cursor_item)
3923 list = icon_view->priv->items;
3925 list = g_list_last (icon_view->priv->items);
3927 item = list ? list->data : NULL;
3932 item = icon_view->priv->cursor_item;
3933 cell = icon_view->priv->cursor_cell;
3934 step = count > 0 ? 1 : -1;
3937 cell = find_cell (icon_view, item, cell,
3938 GTK_ORIENTATION_VERTICAL,
3943 item = find_item (icon_view, item, step, 0);
3944 count = count - step;
3950 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3954 if (icon_view->priv->ctrl_pressed ||
3955 !icon_view->priv->shift_pressed ||
3956 !icon_view->priv->anchor_item ||
3957 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3958 icon_view->priv->anchor_item = item;
3960 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3962 if (!icon_view->priv->ctrl_pressed &&
3963 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3965 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3966 dirty = gtk_icon_view_select_all_between (icon_view,
3967 icon_view->priv->anchor_item,
3971 gtk_icon_view_scroll_to_item (icon_view, item);
3974 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3978 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3981 GtkIconViewItem *item;
3982 gboolean dirty = FALSE;
3984 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3987 if (!icon_view->priv->cursor_item)
3992 list = icon_view->priv->items;
3994 list = g_list_last (icon_view->priv->items);
3996 item = list ? list->data : NULL;
3999 item = find_item_page_up_down (icon_view,
4000 icon_view->priv->cursor_item,
4003 if (item == icon_view->priv->cursor_item)
4004 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4009 if (icon_view->priv->ctrl_pressed ||
4010 !icon_view->priv->shift_pressed ||
4011 !icon_view->priv->anchor_item ||
4012 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4013 icon_view->priv->anchor_item = item;
4015 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4017 if (!icon_view->priv->ctrl_pressed &&
4018 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4020 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4021 dirty = gtk_icon_view_select_all_between (icon_view,
4022 icon_view->priv->anchor_item,
4026 gtk_icon_view_scroll_to_item (icon_view, item);
4029 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4033 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4036 GtkIconViewItem *item;
4038 gboolean dirty = FALSE;
4041 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4044 if (!icon_view->priv->cursor_item)
4049 list = icon_view->priv->items;
4051 list = g_list_last (icon_view->priv->items);
4053 item = list ? list->data : NULL;
4057 item = icon_view->priv->cursor_item;
4058 cell = icon_view->priv->cursor_cell;
4059 step = count > 0 ? 1 : -1;
4062 cell = find_cell (icon_view, item, cell,
4063 GTK_ORIENTATION_HORIZONTAL,
4068 item = find_item (icon_view, item, 0, step);
4069 count = count - step;
4075 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4079 if (icon_view->priv->ctrl_pressed ||
4080 !icon_view->priv->shift_pressed ||
4081 !icon_view->priv->anchor_item ||
4082 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4083 icon_view->priv->anchor_item = item;
4085 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4087 if (!icon_view->priv->ctrl_pressed &&
4088 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4090 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4091 dirty = gtk_icon_view_select_all_between (icon_view,
4092 icon_view->priv->anchor_item,
4096 gtk_icon_view_scroll_to_item (icon_view, item);
4099 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4103 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4106 GtkIconViewItem *item;
4108 gboolean dirty = FALSE;
4110 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4114 list = icon_view->priv->items;
4116 list = g_list_last (icon_view->priv->items);
4118 item = list ? list->data : NULL;
4120 if (item == icon_view->priv->cursor_item)
4121 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4126 if (icon_view->priv->ctrl_pressed ||
4127 !icon_view->priv->shift_pressed ||
4128 !icon_view->priv->anchor_item ||
4129 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4130 icon_view->priv->anchor_item = item;
4132 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4134 if (!icon_view->priv->ctrl_pressed &&
4135 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4137 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4138 dirty = gtk_icon_view_select_all_between (icon_view,
4139 icon_view->priv->anchor_item,
4143 gtk_icon_view_scroll_to_item (icon_view, item);
4146 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4150 * gtk_icon_view_scroll_to_path:
4151 * @icon_view: A #GtkIconView.
4152 * @path: The path of the item to move to.
4153 * @use_align: whether to use alignment arguments, or %FALSE.
4154 * @row_align: The vertical alignment of the item specified by @path.
4155 * @col_align: The horizontal alignment of the item specified by @path.
4157 * Moves the alignments of @icon_view to the position specified by @path.
4158 * @row_align determines where the row is placed, and @col_align determines
4159 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4160 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4163 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4164 * tree does the minimum amount of work to scroll the item onto the screen.
4165 * This means that the item will be scrolled to the edge closest to its current
4166 * position. If the item is currently visible on the screen, nothing is done.
4168 * This function only works if the model is set, and @path is a valid row on
4169 * the model. If the model changes before the @icon_view is realized, the
4170 * centered path will be modified to reflect this change.
4175 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4181 GtkIconViewItem *item = NULL;
4183 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4184 g_return_if_fail (path != NULL);
4185 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4186 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4188 if (gtk_tree_path_get_depth (path) > 0)
4189 item = g_list_nth_data (icon_view->priv->items,
4190 gtk_tree_path_get_indices(path)[0]);
4192 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4194 if (icon_view->priv->scroll_to_path)
4195 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4197 icon_view->priv->scroll_to_path = NULL;
4200 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4202 icon_view->priv->scroll_to_use_align = use_align;
4203 icon_view->priv->scroll_to_row_align = row_align;
4204 icon_view->priv->scroll_to_col_align = col_align;
4213 gfloat offset, value;
4215 gtk_widget_style_get (GTK_WIDGET (icon_view),
4216 "focus-line-width", &focus_width,
4219 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4221 offset = y + item->y - focus_width -
4222 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4223 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4224 icon_view->priv->vadjustment->lower,
4225 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4226 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4228 offset = x + item->x - focus_width -
4229 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4230 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4231 icon_view->priv->hadjustment->lower,
4232 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4233 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4235 gtk_adjustment_changed (icon_view->priv->hadjustment);
4236 gtk_adjustment_changed (icon_view->priv->vadjustment);
4239 gtk_icon_view_scroll_to_item (icon_view, item);
4244 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4245 GtkIconViewItem *item)
4247 gint x, y, width, height;
4250 gtk_widget_style_get (GTK_WIDGET (icon_view),
4251 "focus-line-width", &focus_width,
4254 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4256 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4258 if (y + item->y - focus_width < 0)
4259 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4260 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4261 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4262 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4263 icon_view->priv->vadjustment->value + y + item->y + item->height
4264 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4266 if (x + item->x - focus_width < 0)
4267 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4268 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4269 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4270 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4271 icon_view->priv->hadjustment->value + x + item->x + item->width
4272 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4274 gtk_adjustment_changed (icon_view->priv->hadjustment);
4275 gtk_adjustment_changed (icon_view->priv->vadjustment);
4278 /* GtkCellLayout implementation */
4279 static GtkIconViewCellInfo *
4280 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4281 GtkCellRenderer *renderer)
4285 for (i = icon_view->priv->cell_list; i; i = i->next)
4287 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4289 if (info->cell == renderer)
4297 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4298 GtkIconViewItem *item)
4301 gboolean iters_persist;
4304 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4310 path = gtk_tree_path_new_from_indices (item->index, -1);
4311 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4313 gtk_tree_path_free (path);
4318 for (i = icon_view->priv->cell_list; i; i = i->next)
4321 GtkIconViewCellInfo *info = i->data;
4323 g_object_freeze_notify (G_OBJECT (info->cell));
4325 for (j = info->attributes; j && j->next; j = j->next->next)
4327 gchar *property = j->data;
4328 gint column = GPOINTER_TO_INT (j->next->data);
4329 GValue value = {0, };
4331 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4333 g_object_set_property (G_OBJECT (info->cell),
4335 g_value_unset (&value);
4339 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4341 icon_view->priv->model,
4345 g_object_thaw_notify (G_OBJECT (info->cell));
4350 free_cell_attributes (GtkIconViewCellInfo *info)
4354 list = info->attributes;
4355 while (list && list->next)
4357 g_free (list->data);
4358 list = list->next->next;
4361 g_slist_free (info->attributes);
4362 info->attributes = NULL;
4366 free_cell_info (GtkIconViewCellInfo *info)
4368 free_cell_attributes (info);
4370 g_object_unref (info->cell);
4373 (* info->destroy) (info->func_data);
4379 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4380 GtkCellRenderer *renderer,
4383 GtkIconViewCellInfo *info;
4384 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4386 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4387 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4389 g_object_ref_sink (renderer);
4391 info = g_new0 (GtkIconViewCellInfo, 1);
4392 info->cell = renderer;
4393 info->expand = expand ? TRUE : FALSE;
4394 info->pack = GTK_PACK_START;
4395 info->position = icon_view->priv->n_cells;
4397 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4398 icon_view->priv->n_cells++;
4402 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4403 GtkCellRenderer *renderer,
4406 GtkIconViewCellInfo *info;
4407 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4409 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4410 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4412 g_object_ref_sink (renderer);
4414 info = g_new0 (GtkIconViewCellInfo, 1);
4415 info->cell = renderer;
4416 info->expand = expand ? TRUE : FALSE;
4417 info->pack = GTK_PACK_END;
4418 info->position = icon_view->priv->n_cells;
4420 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4421 icon_view->priv->n_cells++;
4425 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4426 GtkCellRenderer *renderer,
4427 const gchar *attribute,
4430 GtkIconViewCellInfo *info;
4431 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4433 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4434 g_return_if_fail (info != NULL);
4436 info->attributes = g_slist_prepend (info->attributes,
4437 GINT_TO_POINTER (column));
4438 info->attributes = g_slist_prepend (info->attributes,
4439 g_strdup (attribute));
4443 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4445 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4447 while (icon_view->priv->cell_list)
4449 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4450 free_cell_info (info);
4451 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4452 icon_view->priv->cell_list);
4455 icon_view->priv->n_cells = 0;
4459 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4460 GtkCellRenderer *cell,
4461 GtkCellLayoutDataFunc func,
4463 GDestroyNotify destroy)
4465 GtkIconViewCellInfo *info;
4466 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4468 info = gtk_icon_view_get_cell_info (icon_view, cell);
4469 g_return_if_fail (info != NULL);
4473 GDestroyNotify d = info->destroy;
4475 info->destroy = NULL;
4476 d (info->func_data);
4480 info->func_data = func_data;
4481 info->destroy = destroy;
4485 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4486 GtkCellRenderer *renderer)
4488 GtkIconViewCellInfo *info;
4490 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4492 free_cell_attributes (info);
4496 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4497 GtkCellRenderer *cell,
4500 GtkIconView *icon_view;
4502 GtkIconViewCellInfo *info;
4505 icon_view = GTK_ICON_VIEW (layout);
4507 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4509 info = gtk_icon_view_get_cell_info (icon_view, cell);
4511 g_return_if_fail (info != NULL);
4512 g_return_if_fail (position >= 0);
4514 link = g_list_find (icon_view->priv->cell_list, info);
4516 g_return_if_fail (link != NULL);
4518 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4520 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4523 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4530 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4534 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4536 GtkIconView *icon_view = (GtkIconView *)layout;
4537 GList *retval = NULL, *l;
4539 for (l = icon_view->priv->cell_list; l; l = l->next)
4541 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4543 retval = g_list_prepend (retval, info->cell);
4546 return g_list_reverse (retval);
4553 * gtk_icon_view_new:
4555 * Creates a new #GtkIconView widget
4557 * Return value: A newly created #GtkIconView widget
4562 gtk_icon_view_new (void)
4564 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4568 * gtk_icon_view_new_with_model:
4569 * @model: The model.
4571 * Creates a new #GtkIconView widget with the model @model.
4573 * Return value: A newly created #GtkIconView widget.
4578 gtk_icon_view_new_with_model (GtkTreeModel *model)
4580 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4584 * gtk_icon_view_convert_widget_to_bin_window_coords:
4585 * @icon_view: a #GtkIconView
4586 * @wx: X coordinate relative to the widget
4587 * @wy: Y coordinate relative to the widget
4588 * @bx: return location for bin_window X coordinate
4589 * @by: return location for bin_window Y coordinate
4591 * Converts widget coordinates to coordinates for the bin_window,
4592 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4597 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4605 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4607 if (icon_view->priv->bin_window)
4608 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4619 * gtk_icon_view_get_path_at_pos:
4620 * @icon_view: A #GtkIconView.
4621 * @x: The x position to be identified
4622 * @y: The y position to be identified
4624 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4625 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4626 * the cell at the specified position.
4627 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4628 * widget coordinates to bin_window coordinates.
4630 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4631 * if no icon exists at that position.
4636 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4640 GtkIconViewItem *item;
4643 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4645 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4650 path = gtk_tree_path_new_from_indices (item->index, -1);
4656 * gtk_icon_view_get_item_at_pos:
4657 * @icon_view: A #GtkIconView.
4658 * @x: The x position to be identified
4659 * @y: The y position to be identified
4660 * @path: Return location for the path, or %NULL
4661 * @cell: Return location for the renderer responsible for the cell
4662 * at (@x, @y), or %NULL
4664 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4665 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4666 * obtains the cell at the specified position. The returned path should
4667 * be freed with gtk_tree_path_free().
4668 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4669 * widget coordinates to bin_window coordinates.
4671 * Return value: %TRUE if an item exists at the specified position
4676 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4680 GtkCellRenderer **cell)
4682 GtkIconViewItem *item;
4683 GtkIconViewCellInfo *info;
4685 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4687 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4692 *path = gtk_tree_path_new_from_indices (item->index, -1);
4705 return (item != NULL);
4709 * gtk_icon_view_set_tooltip_item:
4710 * @icon_view: a #GtkIconView
4711 * @tooltip: a #GtkTooltip
4712 * @path: a #GtkTreePath
4714 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4715 * See also gtk_tooltip_set_tip_area().
4720 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4721 GtkTooltip *tooltip,
4724 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4725 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4727 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4731 * gtk_icon_view_set_tooltip_cell:
4732 * @icon_view: a #GtkIconView
4733 * @tooltip: a #GtkTooltip
4734 * @path: a #GtkTreePath
4735 * @cell: a #GtkCellRenderer or %NULL
4737 * Sets the tip area of @tooltip to the area which @cell occupies in
4738 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4743 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4744 GtkTooltip *tooltip,
4746 GtkCellRenderer *cell)
4749 GtkIconViewItem *item = NULL;
4750 GtkIconViewCellInfo *info = NULL;
4753 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4754 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4755 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4757 if (gtk_tree_path_get_depth (path) > 0)
4758 item = g_list_nth_data (icon_view->priv->items,
4759 gtk_tree_path_get_indices(path)[0]);
4766 info = gtk_icon_view_get_cell_info (icon_view, cell);
4767 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4773 rect.width = item->width;
4774 rect.height = item->height;
4777 if (icon_view->priv->bin_window)
4779 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4784 gtk_tooltip_set_tip_area (tooltip, &rect);
4789 * gtk_icon_view_get_tooltip_context:
4790 * @icon_view: an #GtkIconView
4791 * @x: the x coordinate (relative to widget coordinates)
4792 * @y: the y coordinate (relative to widget coordinates)
4793 * @keyboard_tip: whether this is a keyboard tooltip or not
4794 * @model: a pointer to receive a #GtkTreeModel or %NULL
4795 * @path: a pointer to receive a #GtkTreePath or %NULL
4796 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4798 * This function is supposed to be used in a #GtkWidget::query-tooltip
4799 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4800 * which are received in the signal handler, should be passed to this
4801 * function without modification.
4803 * The return value indicates whether there is an icon view item at the given
4804 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4805 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4806 * @model, @path and @iter which have been provided will be set to point to
4807 * that row and the corresponding model. @x and @y will always be converted
4808 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4810 * Return value: whether or not the given tooltip context points to a item
4815 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4818 gboolean keyboard_tip,
4819 GtkTreeModel **model,
4823 GtkTreePath *tmppath = NULL;
4825 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4826 g_return_val_if_fail (x != NULL, FALSE);
4827 g_return_val_if_fail (y != NULL, FALSE);
4831 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4838 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4841 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4846 *model = gtk_icon_view_get_model (icon_view);
4849 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4855 gtk_tree_path_free (tmppath);
4861 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4864 gboolean keyboard_tip,
4865 GtkTooltip *tooltip,
4871 GtkTreeModel *model;
4872 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4874 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4877 &model, &path, &iter))
4880 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4884 gtk_tree_path_free (path);
4888 gtk_tooltip_set_markup (tooltip, str);
4889 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4891 gtk_tree_path_free (path);
4899 * gtk_icon_view_set_tooltip_column:
4900 * @icon_view: a #GtkIconView
4901 * @column: an integer, which is a valid column number for @icon_view's model
4903 * If you only plan to have simple (text-only) tooltips on full items, you
4904 * can use this function to have #GtkIconView handle these automatically
4905 * for you. @column should be set to the column in @icon_view's model
4906 * containing the tooltip texts, or -1 to disable this feature.
4908 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4909 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4914 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4917 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4919 if (column == icon_view->priv->tooltip_column)
4924 g_signal_handlers_disconnect_by_func (icon_view,
4925 gtk_icon_view_set_tooltip_query_cb,
4927 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4931 if (icon_view->priv->tooltip_column == -1)
4933 g_signal_connect (icon_view, "query-tooltip",
4934 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4935 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4939 icon_view->priv->tooltip_column = column;
4940 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4944 * gtk_icon_view_get_tooltip_column:
4945 * @icon_view: a #GtkIconView
4947 * Returns the column of @icon_view's model which is being used for
4948 * displaying tooltips on @icon_view's rows.
4950 * Return value: the index of the tooltip column that is currently being
4951 * used, or -1 if this is disabled.
4956 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4958 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4960 return icon_view->priv->tooltip_column;
4964 * gtk_icon_view_get_visible_range:
4965 * @icon_view: A #GtkIconView
4966 * @start_path: Return location for start of region, or %NULL
4967 * @end_path: Return location for end of region, or %NULL
4969 * Sets @start_path and @end_path to be the first and last visible path.
4970 * Note that there may be invisible paths in between.
4972 * Both paths should be freed with gtk_tree_path_free() after use.
4974 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4979 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4980 GtkTreePath **start_path,
4981 GtkTreePath **end_path)
4983 gint start_index = -1;
4984 gint end_index = -1;
4987 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4989 if (icon_view->priv->hadjustment == NULL ||
4990 icon_view->priv->vadjustment == NULL)
4993 if (start_path == NULL && end_path == NULL)
4996 for (icons = icon_view->priv->items; icons; icons = icons->next)
4998 GtkIconViewItem *item = icons->data;
5000 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5001 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5002 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5003 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5005 if (start_index == -1)
5006 start_index = item->index;
5007 end_index = item->index;
5011 if (start_path && start_index != -1)
5012 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5013 if (end_path && end_index != -1)
5014 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5016 return start_index != -1;
5020 * gtk_icon_view_selected_foreach:
5021 * @icon_view: A #GtkIconView.
5022 * @func: The funcion to call for each selected icon.
5023 * @data: User data to pass to the function.
5025 * Calls a function for each selected icon. Note that the model or
5026 * selection cannot be modified from within this function.
5031 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5032 GtkIconViewForeachFunc func,
5037 for (list = icon_view->priv->items; list; list = list->next)
5039 GtkIconViewItem *item = list->data;
5040 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5043 (* func) (icon_view, path, data);
5045 gtk_tree_path_free (path);
5050 * gtk_icon_view_set_selection_mode:
5051 * @icon_view: A #GtkIconView.
5052 * @mode: The selection mode
5054 * Sets the selection mode of the @icon_view.
5059 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5060 GtkSelectionMode mode)
5062 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5064 if (mode == icon_view->priv->selection_mode)
5067 if (mode == GTK_SELECTION_NONE ||
5068 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5069 gtk_icon_view_unselect_all (icon_view);
5071 icon_view->priv->selection_mode = mode;
5073 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5077 * gtk_icon_view_get_selection_mode:
5078 * @icon_view: A #GtkIconView.
5080 * Gets the selection mode of the @icon_view.
5082 * Return value: the current selection mode
5087 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5089 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5091 return icon_view->priv->selection_mode;
5095 * gtk_icon_view_set_model:
5096 * @icon_view: A #GtkIconView.
5097 * @model: The model.
5099 * Sets the model for a #GtkIconView.
5100 * If the @icon_view already has a model set, it will remove
5101 * it before setting the new model. If @model is %NULL, then
5102 * it will unset the old model.
5107 gtk_icon_view_set_model (GtkIconView *icon_view,
5108 GtkTreeModel *model)
5110 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5111 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5113 if (icon_view->priv->model == model)
5116 if (icon_view->priv->scroll_to_path)
5118 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5119 icon_view->priv->scroll_to_path = NULL;
5122 gtk_icon_view_stop_editing (icon_view, TRUE);
5128 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5130 if (icon_view->priv->pixbuf_column != -1)
5132 column_type = gtk_tree_model_get_column_type (model,
5133 icon_view->priv->pixbuf_column);
5135 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5138 if (icon_view->priv->text_column != -1)
5140 column_type = gtk_tree_model_get_column_type (model,
5141 icon_view->priv->text_column);
5143 g_return_if_fail (column_type == G_TYPE_STRING);
5146 if (icon_view->priv->markup_column != -1)
5148 column_type = gtk_tree_model_get_column_type (model,
5149 icon_view->priv->markup_column);
5151 g_return_if_fail (column_type == G_TYPE_STRING);
5156 if (icon_view->priv->model)
5158 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5159 gtk_icon_view_row_changed,
5161 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5162 gtk_icon_view_row_inserted,
5164 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5165 gtk_icon_view_row_deleted,
5167 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5168 gtk_icon_view_rows_reordered,
5171 g_object_unref (icon_view->priv->model);
5173 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5174 g_list_free (icon_view->priv->items);
5175 icon_view->priv->items = NULL;
5176 icon_view->priv->anchor_item = NULL;
5177 icon_view->priv->cursor_item = NULL;
5178 icon_view->priv->last_single_clicked = NULL;
5179 icon_view->priv->width = 0;
5180 icon_view->priv->height = 0;
5183 icon_view->priv->model = model;
5185 if (icon_view->priv->model)
5187 g_object_ref (icon_view->priv->model);
5188 g_signal_connect (icon_view->priv->model,
5190 G_CALLBACK (gtk_icon_view_row_changed),
5192 g_signal_connect (icon_view->priv->model,
5194 G_CALLBACK (gtk_icon_view_row_inserted),
5196 g_signal_connect (icon_view->priv->model,
5198 G_CALLBACK (gtk_icon_view_row_deleted),
5200 g_signal_connect (icon_view->priv->model,
5202 G_CALLBACK (gtk_icon_view_rows_reordered),
5205 gtk_icon_view_build_items (icon_view);
5207 gtk_icon_view_queue_layout (icon_view);
5210 g_object_notify (G_OBJECT (icon_view), "model");
5212 if (GTK_WIDGET_REALIZED (icon_view))
5213 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5217 * gtk_icon_view_get_model:
5218 * @icon_view: a #GtkIconView
5220 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5223 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5228 gtk_icon_view_get_model (GtkIconView *icon_view)
5230 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5232 return icon_view->priv->model;
5236 update_text_cell (GtkIconView *icon_view)
5238 GtkIconViewCellInfo *info;
5242 if (icon_view->priv->text_column == -1 &&
5243 icon_view->priv->markup_column == -1)
5245 if (icon_view->priv->text_cell != -1)
5247 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5248 icon_view->priv->pixbuf_cell--;
5250 info = g_list_nth_data (icon_view->priv->cell_list,
5251 icon_view->priv->text_cell);
5253 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5255 free_cell_info (info);
5257 icon_view->priv->n_cells--;
5258 icon_view->priv->text_cell = -1;
5263 if (icon_view->priv->text_cell == -1)
5265 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5266 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5267 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5270 if (info->cell == cell)
5272 icon_view->priv->text_cell = i;
5278 info = g_list_nth_data (icon_view->priv->cell_list,
5279 icon_view->priv->text_cell);
5281 if (icon_view->priv->markup_column != -1)
5282 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5284 "markup", icon_view->priv->markup_column,
5287 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5289 "text", icon_view->priv->text_column,
5292 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5293 g_object_set (info->cell,
5294 "alignment", PANGO_ALIGN_CENTER,
5295 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5300 g_object_set (info->cell,
5301 "alignment", PANGO_ALIGN_LEFT,
5302 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5310 update_pixbuf_cell (GtkIconView *icon_view)
5312 GtkIconViewCellInfo *info;
5316 if (icon_view->priv->pixbuf_column == -1)
5318 if (icon_view->priv->pixbuf_cell != -1)
5320 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5321 icon_view->priv->text_cell--;
5323 info = g_list_nth_data (icon_view->priv->cell_list,
5324 icon_view->priv->pixbuf_cell);
5326 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5328 free_cell_info (info);
5330 icon_view->priv->n_cells--;
5331 icon_view->priv->pixbuf_cell = -1;
5336 if (icon_view->priv->pixbuf_cell == -1)
5338 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5340 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5341 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5344 if (info->cell == cell)
5346 icon_view->priv->pixbuf_cell = i;
5352 info = g_list_nth_data (icon_view->priv->cell_list,
5353 icon_view->priv->pixbuf_cell);
5355 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5357 "pixbuf", icon_view->priv->pixbuf_column,
5360 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5361 g_object_set (info->cell,
5362 "follow-state", TRUE,
5367 g_object_set (info->cell,
5368 "follow-state", TRUE,
5376 * gtk_icon_view_set_text_column:
5377 * @icon_view: A #GtkIconView.
5378 * @column: A column in the currently used model, or -1 to display no text
5380 * Sets the column with text for @icon_view to be @column. The text
5381 * column must be of type #G_TYPE_STRING.
5386 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5389 if (column == icon_view->priv->text_column)
5393 icon_view->priv->text_column = -1;
5396 if (icon_view->priv->model != NULL)
5400 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5402 g_return_if_fail (column_type == G_TYPE_STRING);
5405 icon_view->priv->text_column = column;
5408 gtk_icon_view_stop_editing (icon_view, TRUE);
5410 update_text_cell (icon_view);
5412 gtk_icon_view_invalidate_sizes (icon_view);
5413 gtk_icon_view_queue_layout (icon_view);
5415 g_object_notify (G_OBJECT (icon_view), "text-column");
5419 * gtk_icon_view_get_text_column:
5420 * @icon_view: A #GtkIconView.
5422 * Returns the column with text for @icon_view.
5424 * Returns: the text column, or -1 if it's unset.
5429 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5431 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5433 return icon_view->priv->text_column;
5437 * gtk_icon_view_set_markup_column:
5438 * @icon_view: A #GtkIconView.
5439 * @column: A column in the currently used model, or -1 to display no text
5441 * Sets the column with markup information for @icon_view to be
5442 * @column. The markup column must be of type #G_TYPE_STRING.
5443 * If the markup column is set to something, it overrides
5444 * the text column set by gtk_icon_view_set_text_column().
5449 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5452 if (column == icon_view->priv->markup_column)
5456 icon_view->priv->markup_column = -1;
5459 if (icon_view->priv->model != NULL)
5463 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5465 g_return_if_fail (column_type == G_TYPE_STRING);
5468 icon_view->priv->markup_column = column;
5471 gtk_icon_view_stop_editing (icon_view, TRUE);
5473 update_text_cell (icon_view);
5475 gtk_icon_view_invalidate_sizes (icon_view);
5476 gtk_icon_view_queue_layout (icon_view);
5478 g_object_notify (G_OBJECT (icon_view), "markup-column");
5482 * gtk_icon_view_get_markup_column:
5483 * @icon_view: A #GtkIconView.
5485 * Returns the column with markup text for @icon_view.
5487 * Returns: the markup column, or -1 if it's unset.
5492 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5494 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5496 return icon_view->priv->markup_column;
5500 * gtk_icon_view_set_pixbuf_column:
5501 * @icon_view: A #GtkIconView.
5502 * @column: A column in the currently used model, or -1 to disable
5504 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5505 * column must be of type #GDK_TYPE_PIXBUF
5510 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5513 if (column == icon_view->priv->pixbuf_column)
5517 icon_view->priv->pixbuf_column = -1;
5520 if (icon_view->priv->model != NULL)
5524 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5526 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5529 icon_view->priv->pixbuf_column = column;
5532 gtk_icon_view_stop_editing (icon_view, TRUE);
5534 update_pixbuf_cell (icon_view);
5536 gtk_icon_view_invalidate_sizes (icon_view);
5537 gtk_icon_view_queue_layout (icon_view);
5539 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5544 * gtk_icon_view_get_pixbuf_column:
5545 * @icon_view: A #GtkIconView.
5547 * Returns the column with pixbufs for @icon_view.
5549 * Returns: the pixbuf column, or -1 if it's unset.
5554 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5556 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5558 return icon_view->priv->pixbuf_column;
5562 * gtk_icon_view_select_path:
5563 * @icon_view: A #GtkIconView.
5564 * @path: The #GtkTreePath to be selected.
5566 * Selects the row at @path.
5571 gtk_icon_view_select_path (GtkIconView *icon_view,
5574 GtkIconViewItem *item = NULL;
5576 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5577 g_return_if_fail (icon_view->priv->model != NULL);
5578 g_return_if_fail (path != NULL);
5580 if (gtk_tree_path_get_depth (path) > 0)
5581 item = g_list_nth_data (icon_view->priv->items,
5582 gtk_tree_path_get_indices(path)[0]);
5585 gtk_icon_view_select_item (icon_view, item);
5589 * gtk_icon_view_unselect_path:
5590 * @icon_view: A #GtkIconView.
5591 * @path: The #GtkTreePath to be unselected.
5593 * Unselects the row at @path.
5598 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5601 GtkIconViewItem *item;
5603 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5604 g_return_if_fail (icon_view->priv->model != NULL);
5605 g_return_if_fail (path != NULL);
5607 item = g_list_nth_data (icon_view->priv->items,
5608 gtk_tree_path_get_indices(path)[0]);
5613 gtk_icon_view_unselect_item (icon_view, item);
5617 * gtk_icon_view_get_selected_items:
5618 * @icon_view: A #GtkIconView.
5620 * Creates a list of paths of all selected items. Additionally, if you are
5621 * planning on modifying the model after calling this function, you may
5622 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5623 * To do this, you can use gtk_tree_row_reference_new().
5625 * To free the return value, use:
5627 * g_list_foreach (list, gtk_tree_path_free, NULL);
5628 * g_list_free (list);
5631 * Return value: A #GList containing a #GtkTreePath for each selected row.
5636 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5639 GList *selected = NULL;
5641 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5643 for (list = icon_view->priv->items; list != NULL; list = list->next)
5645 GtkIconViewItem *item = list->data;
5649 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5651 selected = g_list_prepend (selected, path);
5659 * gtk_icon_view_select_all:
5660 * @icon_view: A #GtkIconView.
5662 * Selects all the icons. @icon_view must has its selection mode set
5663 * to #GTK_SELECTION_MULTIPLE.
5668 gtk_icon_view_select_all (GtkIconView *icon_view)
5671 gboolean dirty = FALSE;
5673 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5675 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5678 for (items = icon_view->priv->items; items; items = items->next)
5680 GtkIconViewItem *item = items->data;
5682 if (!item->selected)
5685 item->selected = TRUE;
5686 gtk_icon_view_queue_draw_item (icon_view, item);
5691 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5695 * gtk_icon_view_unselect_all:
5696 * @icon_view: A #GtkIconView.
5698 * Unselects all the icons.
5703 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5705 gboolean dirty = FALSE;
5707 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5709 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5712 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5715 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5719 * gtk_icon_view_path_is_selected:
5720 * @icon_view: A #GtkIconView.
5721 * @path: A #GtkTreePath to check selection on.
5723 * Returns %TRUE if the icon pointed to by @path is currently
5724 * selected. If @path does not point to a valid location, %FALSE is returned.
5726 * Return value: %TRUE if @path is selected.
5731 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5734 GtkIconViewItem *item;
5736 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5737 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5738 g_return_val_if_fail (path != NULL, FALSE);
5740 item = g_list_nth_data (icon_view->priv->items,
5741 gtk_tree_path_get_indices(path)[0]);
5746 return item->selected;
5750 * gtk_icon_view_item_activated:
5751 * @icon_view: A #GtkIconView
5752 * @path: The #GtkTreePath to be activated
5754 * Activates the item determined by @path.
5759 gtk_icon_view_item_activated (GtkIconView *icon_view,
5762 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5763 g_return_if_fail (path != NULL);
5765 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5769 * gtk_icon_view_set_orientation:
5770 * @icon_view: a #GtkIconView
5771 * @orientation: the relative position of texts and icons
5773 * Sets the ::orientation property which determines whether the labels
5774 * are drawn beside the icons instead of below.
5779 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5780 GtkOrientation orientation)
5782 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5784 if (icon_view->priv->orientation != orientation)
5786 icon_view->priv->orientation = orientation;
5788 gtk_icon_view_stop_editing (icon_view, TRUE);
5789 gtk_icon_view_invalidate_sizes (icon_view);
5790 gtk_icon_view_queue_layout (icon_view);
5792 update_text_cell (icon_view);
5793 update_pixbuf_cell (icon_view);
5795 g_object_notify (G_OBJECT (icon_view), "orientation");
5800 * gtk_icon_view_get_orientation:
5801 * @icon_view: a #GtkIconView
5803 * Returns the value of the ::orientation property which determines
5804 * whether the labels are drawn beside the icons instead of below.
5806 * Return value: the relative position of texts and icons
5811 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5813 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5814 GTK_ORIENTATION_VERTICAL);
5816 return icon_view->priv->orientation;
5820 * gtk_icon_view_set_columns:
5821 * @icon_view: a #GtkIconView
5822 * @columns: the number of columns
5824 * Sets the ::columns property which determines in how
5825 * many columns the icons are arranged. If @columns is
5826 * -1, the number of columns will be chosen automatically
5827 * to fill the available area.
5832 gtk_icon_view_set_columns (GtkIconView *icon_view,
5835 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5837 if (icon_view->priv->columns != columns)
5839 icon_view->priv->columns = columns;
5841 gtk_icon_view_stop_editing (icon_view, TRUE);
5842 gtk_icon_view_queue_layout (icon_view);
5844 g_object_notify (G_OBJECT (icon_view), "columns");
5849 * gtk_icon_view_get_columns:
5850 * @icon_view: a #GtkIconView
5852 * Returns the value of the ::columns property.
5854 * Return value: the number of columns, or -1
5859 gtk_icon_view_get_columns (GtkIconView *icon_view)
5861 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5863 return icon_view->priv->columns;
5867 * gtk_icon_view_set_item_width:
5868 * @icon_view: a #GtkIconView
5869 * @item_width: the width for each item
5871 * Sets the ::item-width property which specifies the width
5872 * to use for each item. If it is set to -1, the icon view will
5873 * automatically determine a suitable item size.
5878 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5881 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5883 if (icon_view->priv->item_width != item_width)
5885 icon_view->priv->item_width = item_width;
5887 gtk_icon_view_stop_editing (icon_view, TRUE);
5888 gtk_icon_view_invalidate_sizes (icon_view);
5889 gtk_icon_view_queue_layout (icon_view);
5891 update_text_cell (icon_view);
5893 g_object_notify (G_OBJECT (icon_view), "item-width");
5898 * gtk_icon_view_get_item_width:
5899 * @icon_view: a #GtkIconView
5901 * Returns the value of the ::item-width property.
5903 * Return value: the width of a single item, or -1
5908 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5910 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5912 return icon_view->priv->item_width;
5917 * gtk_icon_view_set_spacing:
5918 * @icon_view: a #GtkIconView
5919 * @spacing: the spacing
5921 * Sets the ::spacing property which specifies the space
5922 * which is inserted between the cells (i.e. the icon and
5923 * the text) of an item.
5928 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5931 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5933 if (icon_view->priv->spacing != spacing)
5935 icon_view->priv->spacing = spacing;
5937 gtk_icon_view_stop_editing (icon_view, TRUE);
5938 gtk_icon_view_invalidate_sizes (icon_view);
5939 gtk_icon_view_queue_layout (icon_view);
5941 g_object_notify (G_OBJECT (icon_view), "spacing");
5946 * gtk_icon_view_get_spacing:
5947 * @icon_view: a #GtkIconView
5949 * Returns the value of the ::spacing property.
5951 * Return value: the space between cells
5956 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5958 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5960 return icon_view->priv->spacing;
5964 * gtk_icon_view_set_row_spacing:
5965 * @icon_view: a #GtkIconView
5966 * @row_spacing: the row spacing
5968 * Sets the ::row-spacing property which specifies the space
5969 * which is inserted between the rows of the icon view.
5974 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5977 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5979 if (icon_view->priv->row_spacing != row_spacing)
5981 icon_view->priv->row_spacing = row_spacing;
5983 gtk_icon_view_stop_editing (icon_view, TRUE);
5984 gtk_icon_view_invalidate_sizes (icon_view);
5985 gtk_icon_view_queue_layout (icon_view);
5987 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5992 * gtk_icon_view_get_row_spacing:
5993 * @icon_view: a #GtkIconView
5995 * Returns the value of the ::row-spacing property.
5997 * Return value: the space between rows
6002 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6004 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6006 return icon_view->priv->row_spacing;
6010 * gtk_icon_view_set_column_spacing:
6011 * @icon_view: a #GtkIconView
6012 * @column_spacing: the column spacing
6014 * Sets the ::column-spacing property which specifies the space
6015 * which is inserted between the columns of the icon view.
6020 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6021 gint column_spacing)
6023 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6025 if (icon_view->priv->column_spacing != column_spacing)
6027 icon_view->priv->column_spacing = column_spacing;
6029 gtk_icon_view_stop_editing (icon_view, TRUE);
6030 gtk_icon_view_invalidate_sizes (icon_view);
6031 gtk_icon_view_queue_layout (icon_view);
6033 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6038 * gtk_icon_view_get_column_spacing:
6039 * @icon_view: a #GtkIconView
6041 * Returns the value of the ::column-spacing property.
6043 * Return value: the space between columns
6048 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6050 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6052 return icon_view->priv->column_spacing;
6056 * gtk_icon_view_set_margin:
6057 * @icon_view: a #GtkIconView
6058 * @margin: the margin
6060 * Sets the ::margin property which specifies the space
6061 * which is inserted at the top, bottom, left and right
6067 gtk_icon_view_set_margin (GtkIconView *icon_view,
6070 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6072 if (icon_view->priv->margin != margin)
6074 icon_view->priv->margin = margin;
6076 gtk_icon_view_stop_editing (icon_view, TRUE);
6077 gtk_icon_view_invalidate_sizes (icon_view);
6078 gtk_icon_view_queue_layout (icon_view);
6080 g_object_notify (G_OBJECT (icon_view), "margin");
6085 * gtk_icon_view_get_margin:
6086 * @icon_view: a #GtkIconView
6088 * Returns the value of the ::margin property.
6090 * Return value: the space at the borders
6095 gtk_icon_view_get_margin (GtkIconView *icon_view)
6097 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6099 return icon_view->priv->margin;
6103 /* Get/set whether drag_motion requested the drag data and
6104 * drag_data_received should thus not actually insert the data,
6105 * since the data doesn't result from a drop.
6108 set_status_pending (GdkDragContext *context,
6109 GdkDragAction suggested_action)
6111 g_object_set_data (G_OBJECT (context),
6112 I_("gtk-icon-view-status-pending"),
6113 GINT_TO_POINTER (suggested_action));
6116 static GdkDragAction
6117 get_status_pending (GdkDragContext *context)
6119 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6120 "gtk-icon-view-status-pending"));
6124 unset_reorderable (GtkIconView *icon_view)
6126 if (icon_view->priv->reorderable)
6128 icon_view->priv->reorderable = FALSE;
6129 g_object_notify (G_OBJECT (icon_view), "reorderable");
6134 clear_source_info (GtkIconView *icon_view)
6136 if (icon_view->priv->source_targets)
6137 gtk_target_list_unref (icon_view->priv->source_targets);
6138 icon_view->priv->source_targets = NULL;
6140 icon_view->priv->source_set = FALSE;
6144 clear_dest_info (GtkIconView *icon_view)
6146 if (icon_view->priv->dest_targets)
6147 gtk_target_list_unref (icon_view->priv->dest_targets);
6148 icon_view->priv->dest_targets = NULL;
6150 icon_view->priv->dest_set = FALSE;
6154 set_source_row (GdkDragContext *context,
6155 GtkTreeModel *model,
6156 GtkTreePath *source_row)
6159 g_object_set_data_full (G_OBJECT (context),
6160 I_("gtk-icon-view-source-row"),
6161 gtk_tree_row_reference_new (model, source_row),
6162 (GDestroyNotify) gtk_tree_row_reference_free);
6164 g_object_set_data_full (G_OBJECT (context),
6165 I_("gtk-icon-view-source-row"),
6170 get_source_row (GdkDragContext *context)
6172 GtkTreeRowReference *ref;
6174 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6177 return gtk_tree_row_reference_get_path (ref);
6184 GtkTreeRowReference *dest_row;
6185 gboolean empty_view_drop;
6186 gboolean drop_append_mode;
6190 dest_row_free (gpointer data)
6192 DestRow *dr = (DestRow *)data;
6194 gtk_tree_row_reference_free (dr->dest_row);
6199 set_dest_row (GdkDragContext *context,
6200 GtkTreeModel *model,
6201 GtkTreePath *dest_row,
6202 gboolean empty_view_drop,
6203 gboolean drop_append_mode)
6209 g_object_set_data_full (G_OBJECT (context),
6210 I_("gtk-icon-view-dest-row"),
6215 dr = g_new0 (DestRow, 1);
6217 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6218 dr->empty_view_drop = empty_view_drop;
6219 dr->drop_append_mode = drop_append_mode;
6220 g_object_set_data_full (G_OBJECT (context),
6221 I_("gtk-icon-view-dest-row"),
6222 dr, (GDestroyNotify) dest_row_free);
6226 get_dest_row (GdkDragContext *context)
6230 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6234 GtkTreePath *path = NULL;
6237 path = gtk_tree_row_reference_get_path (dr->dest_row);
6238 else if (dr->empty_view_drop)
6239 path = gtk_tree_path_new_from_indices (0, -1);
6243 if (path && dr->drop_append_mode)
6244 gtk_tree_path_next (path);
6253 check_model_dnd (GtkTreeModel *model,
6254 GType required_iface,
6255 const gchar *signal)
6257 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6259 g_warning ("You must override the default '%s' handler "
6260 "on GtkIconView when using models that don't support "
6261 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6262 "is to connect to '%s' and call "
6263 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6264 "the default handler from running. Look at the source code "
6265 "for the default handler in gtkiconview.c to get an idea what "
6266 "your handler should do. (gtkiconview.c is in the GTK+ source "
6267 "code.) If you're using GTK+ from a language other than C, "
6268 "there may be a more natural way to override default handlers, e.g. via derivation.",
6269 signal, g_type_name (required_iface), signal);
6277 remove_scroll_timeout (GtkIconView *icon_view)
6279 if (icon_view->priv->scroll_timeout_id != 0)
6281 g_source_remove (icon_view->priv->scroll_timeout_id);
6283 icon_view->priv->scroll_timeout_id = 0;
6288 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6290 gint px, py, x, y, width, height;
6291 gint hoffset, voffset;
6294 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6295 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6297 /* see if we are near the edge. */
6298 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6300 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6302 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6304 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6308 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6309 icon_view->priv->vadjustment->lower,
6310 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6311 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6315 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6316 icon_view->priv->hadjustment->lower,
6317 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6318 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6324 drag_scroll_timeout (gpointer data)
6326 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6328 gtk_icon_view_autoscroll (icon_view);
6335 set_destination (GtkIconView *icon_view,
6336 GdkDragContext *context,
6339 GdkDragAction *suggested_action,
6343 GtkTreePath *path = NULL;
6344 GtkIconViewDropPosition pos;
6345 GtkIconViewDropPosition old_pos;
6346 GtkTreePath *old_dest_path = NULL;
6347 gboolean can_drop = FALSE;
6349 widget = GTK_WIDGET (icon_view);
6351 *suggested_action = 0;
6354 if (!icon_view->priv->dest_set)
6356 /* someone unset us as a drag dest, note that if
6357 * we return FALSE drag_leave isn't called
6360 gtk_icon_view_set_drag_dest_item (icon_view,
6362 GTK_ICON_VIEW_DROP_LEFT);
6364 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6366 return FALSE; /* no longer a drop site */
6369 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6370 if (*target == GDK_NONE)
6373 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6376 GtkTreeModel *model;
6378 /* the row got dropped on empty space, let's setup a special case
6382 gtk_tree_path_free (path);
6384 model = gtk_icon_view_get_model (icon_view);
6386 n_children = gtk_tree_model_iter_n_children (model, NULL);
6389 pos = GTK_ICON_VIEW_DROP_BELOW;
6390 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6394 pos = GTK_ICON_VIEW_DROP_ABOVE;
6395 path = gtk_tree_path_new_from_indices (0, -1);
6405 gtk_icon_view_get_drag_dest_item (icon_view,
6410 gtk_tree_path_free (old_dest_path);
6412 if (TRUE /* FIXME if the location droppable predicate */)
6420 GtkWidget *source_widget;
6422 *suggested_action = context->suggested_action;
6423 source_widget = gtk_drag_get_source_widget (context);
6425 if (source_widget == widget)
6427 /* Default to MOVE, unless the user has
6428 * pressed ctrl or shift to affect available actions
6430 if ((context->actions & GDK_ACTION_MOVE) != 0)
6431 *suggested_action = GDK_ACTION_MOVE;
6434 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6439 /* can't drop here */
6440 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6442 GTK_ICON_VIEW_DROP_LEFT);
6446 gtk_tree_path_free (path);
6452 get_logical_destination (GtkIconView *icon_view,
6453 gboolean *drop_append_mode)
6455 /* adjust path to point to the row the drop goes in front of */
6456 GtkTreePath *path = NULL;
6457 GtkIconViewDropPosition pos;
6459 *drop_append_mode = FALSE;
6461 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6466 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6467 pos == GTK_ICON_VIEW_DROP_BELOW)
6470 GtkTreeModel *model = icon_view->priv->model;
6472 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6473 !gtk_tree_model_iter_next (model, &iter))
6474 *drop_append_mode = TRUE;
6477 *drop_append_mode = FALSE;
6478 gtk_tree_path_next (path);
6486 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6487 GdkEventMotion *event)
6489 GdkDragContext *context;
6490 GtkTreePath *path = NULL;
6492 GtkTreeModel *model;
6493 gboolean retval = FALSE;
6495 if (!icon_view->priv->source_set)
6498 if (icon_view->priv->pressed_button < 0)
6501 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6502 icon_view->priv->press_start_x,
6503 icon_view->priv->press_start_y,
6504 event->x, event->y))
6507 model = gtk_icon_view_get_model (icon_view);
6512 button = icon_view->priv->pressed_button;
6513 icon_view->priv->pressed_button = -1;
6515 path = gtk_icon_view_get_path_at_pos (icon_view,
6516 icon_view->priv->press_start_x,
6517 icon_view->priv->press_start_y);
6522 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6523 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6527 /* FIXME Check whether we're a start button, if not return FALSE and
6531 /* Now we can begin the drag */
6535 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6536 icon_view->priv->source_targets,
6537 icon_view->priv->source_actions,
6541 set_source_row (context, model, path);
6545 gtk_tree_path_free (path);
6550 /* Source side drag signals */
6552 gtk_icon_view_drag_begin (GtkWidget *widget,
6553 GdkDragContext *context)
6555 GtkIconView *icon_view;
6556 GtkIconViewItem *item;
6561 icon_view = GTK_ICON_VIEW (widget);
6563 /* if the user uses a custom DnD impl, we don't set the icon here */
6564 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6567 item = gtk_icon_view_get_item_at_coords (icon_view,
6568 icon_view->priv->press_start_x,
6569 icon_view->priv->press_start_y,
6573 g_return_if_fail (item != NULL);
6575 x = icon_view->priv->press_start_x - item->x + 1;
6576 y = icon_view->priv->press_start_y - item->y + 1;
6578 path = gtk_tree_path_new_from_indices (item->index, -1);
6579 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6580 gtk_tree_path_free (path);
6582 gtk_drag_set_icon_pixmap (context,
6583 gdk_drawable_get_colormap (icon),
6588 g_object_unref (icon);
6592 gtk_icon_view_drag_end (GtkWidget *widget,
6593 GdkDragContext *context)
6599 gtk_icon_view_drag_data_get (GtkWidget *widget,
6600 GdkDragContext *context,
6601 GtkSelectionData *selection_data,
6605 GtkIconView *icon_view;
6606 GtkTreeModel *model;
6607 GtkTreePath *source_row;
6609 icon_view = GTK_ICON_VIEW (widget);
6610 model = gtk_icon_view_get_model (icon_view);
6615 if (!icon_view->priv->dest_set)
6618 source_row = get_source_row (context);
6620 if (source_row == NULL)
6623 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6624 * any model; for DragSource models there are some other targets
6628 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6629 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6634 /* If drag_data_get does nothing, try providing row data. */
6635 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6636 gtk_tree_set_row_drag_data (selection_data,
6641 gtk_tree_path_free (source_row);
6645 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6646 GdkDragContext *context)
6648 GtkTreeModel *model;
6649 GtkIconView *icon_view;
6650 GtkTreePath *source_row;
6652 icon_view = GTK_ICON_VIEW (widget);
6653 model = gtk_icon_view_get_model (icon_view);
6655 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6658 if (!icon_view->priv->dest_set)
6661 source_row = get_source_row (context);
6663 if (source_row == NULL)
6666 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6669 gtk_tree_path_free (source_row);
6671 set_source_row (context, NULL, NULL);
6674 /* Target side drag signals */
6676 gtk_icon_view_drag_leave (GtkWidget *widget,
6677 GdkDragContext *context,
6680 GtkIconView *icon_view;
6682 icon_view = GTK_ICON_VIEW (widget);
6684 /* unset any highlight row */
6685 gtk_icon_view_set_drag_dest_item (icon_view,
6687 GTK_ICON_VIEW_DROP_LEFT);
6689 remove_scroll_timeout (icon_view);
6693 gtk_icon_view_drag_motion (GtkWidget *widget,
6694 GdkDragContext *context,
6699 GtkTreePath *path = NULL;
6700 GtkIconViewDropPosition pos;
6701 GtkIconView *icon_view;
6702 GdkDragAction suggested_action = 0;
6706 icon_view = GTK_ICON_VIEW (widget);
6708 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6711 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6713 /* we only know this *after* set_desination_row */
6714 empty = icon_view->priv->empty_view_drop;
6716 if (path == NULL && !empty)
6718 /* Can't drop here. */
6719 gdk_drag_status (context, 0, time);
6723 if (icon_view->priv->scroll_timeout_id == 0)
6725 icon_view->priv->scroll_timeout_id =
6726 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6729 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6731 /* Request data so we can use the source row when
6732 * determining whether to accept the drop
6734 set_status_pending (context, suggested_action);
6735 gtk_drag_get_data (widget, context, target, time);
6739 set_status_pending (context, 0);
6740 gdk_drag_status (context, suggested_action, time);
6745 gtk_tree_path_free (path);
6751 gtk_icon_view_drag_drop (GtkWidget *widget,
6752 GdkDragContext *context,
6757 GtkIconView *icon_view;
6759 GdkDragAction suggested_action = 0;
6760 GdkAtom target = GDK_NONE;
6761 GtkTreeModel *model;
6762 gboolean drop_append_mode;
6764 icon_view = GTK_ICON_VIEW (widget);
6765 model = gtk_icon_view_get_model (icon_view);
6767 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6769 if (!icon_view->priv->dest_set)
6772 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6775 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6778 path = get_logical_destination (icon_view, &drop_append_mode);
6780 if (target != GDK_NONE && path != NULL)
6782 /* in case a motion had requested drag data, change things so we
6783 * treat drag data receives as a drop.
6785 set_status_pending (context, 0);
6786 set_dest_row (context, model, path,
6787 icon_view->priv->empty_view_drop, drop_append_mode);
6791 gtk_tree_path_free (path);
6793 /* Unset this thing */
6794 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6796 if (target != GDK_NONE)
6798 gtk_drag_get_data (widget, context, target, time);
6806 gtk_icon_view_drag_data_received (GtkWidget *widget,
6807 GdkDragContext *context,
6810 GtkSelectionData *selection_data,
6815 gboolean accepted = FALSE;
6816 GtkTreeModel *model;
6817 GtkIconView *icon_view;
6818 GtkTreePath *dest_row;
6819 GdkDragAction suggested_action;
6820 gboolean drop_append_mode;
6822 icon_view = GTK_ICON_VIEW (widget);
6823 model = gtk_icon_view_get_model (icon_view);
6825 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6828 if (!icon_view->priv->dest_set)
6831 suggested_action = get_status_pending (context);
6833 if (suggested_action)
6835 /* We are getting this data due to a request in drag_motion,
6836 * rather than due to a request in drag_drop, so we are just
6837 * supposed to call drag_status, not actually paste in the
6840 path = get_logical_destination (icon_view, &drop_append_mode);
6843 suggested_action = 0;
6845 if (suggested_action)
6847 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6850 suggested_action = 0;
6853 gdk_drag_status (context, suggested_action, time);
6856 gtk_tree_path_free (path);
6858 /* If you can't drop, remove user drop indicator until the next motion */
6859 if (suggested_action == 0)
6860 gtk_icon_view_set_drag_dest_item (icon_view,
6862 GTK_ICON_VIEW_DROP_LEFT);
6867 dest_row = get_dest_row (context);
6869 if (dest_row == NULL)
6872 if (selection_data->length >= 0)
6874 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6880 gtk_drag_finish (context,
6882 (context->action == GDK_ACTION_MOVE),
6885 gtk_tree_path_free (dest_row);
6888 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6891 /* Drag-and-Drop support */
6893 * gtk_icon_view_enable_model_drag_source:
6894 * @icon_view: a #GtkIconTreeView
6895 * @start_button_mask: Mask of allowed buttons to start drag
6896 * @targets: the table of targets that the drag will support
6897 * @n_targets: the number of items in @targets
6898 * @actions: the bitmask of possible actions for a drag from this
6901 * Turns @icon_view into a drag source for automatic DND.
6906 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6907 GdkModifierType start_button_mask,
6908 const GtkTargetEntry *targets,
6910 GdkDragAction actions)
6912 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6914 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6916 clear_source_info (icon_view);
6917 icon_view->priv->start_button_mask = start_button_mask;
6918 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6919 icon_view->priv->source_actions = actions;
6921 icon_view->priv->source_set = TRUE;
6923 unset_reorderable (icon_view);
6927 * gtk_icon_view_enable_model_drag_dest:
6928 * @icon_view: a #GtkIconView
6929 * @targets: the table of targets that the drag will support
6930 * @n_targets: the number of items in @targets
6931 * @actions: the bitmask of possible actions for a drag to this
6934 * Turns @icon_view into a drop destination for automatic DND.
6939 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6940 const GtkTargetEntry *targets,
6942 GdkDragAction actions)
6944 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6946 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6948 clear_dest_info (icon_view);
6950 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6951 icon_view->priv->dest_actions = actions;
6953 icon_view->priv->dest_set = TRUE;
6955 unset_reorderable (icon_view);
6959 * gtk_icon_view_unset_model_drag_source:
6960 * @icon_view: a #GtkIconView
6962 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6967 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6969 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6971 if (icon_view->priv->source_set)
6973 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6974 clear_source_info (icon_view);
6977 unset_reorderable (icon_view);
6981 * gtk_icon_view_unset_model_drag_dest:
6982 * @icon_view: a #GtkIconView
6984 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6989 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6991 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6993 if (icon_view->priv->dest_set)
6995 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6996 clear_dest_info (icon_view);
6999 unset_reorderable (icon_view);
7002 /* These are useful to implement your own custom stuff. */
7004 * gtk_icon_view_set_drag_dest_item:
7005 * @icon_view: a #GtkIconView
7006 * @path: The path of the item to highlight, or %NULL.
7007 * @pos: Specifies where to drop, relative to the item
7009 * Sets the item that is highlighted for feedback.
7014 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7016 GtkIconViewDropPosition pos)
7018 /* Note; this function is exported to allow a custom DND
7019 * implementation, so it can't touch TreeViewDragInfo
7022 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7024 if (icon_view->priv->dest_item)
7026 GtkTreePath *current_path;
7027 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7028 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7029 icon_view->priv->dest_item = NULL;
7031 gtk_icon_view_queue_draw_path (icon_view, current_path);
7032 gtk_tree_path_free (current_path);
7035 /* special case a drop on an empty model */
7036 icon_view->priv->empty_view_drop = FALSE;
7037 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7038 && gtk_tree_path_get_depth (path) == 1
7039 && gtk_tree_path_get_indices (path)[0] == 0)
7043 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7046 if (n_children == 0)
7047 icon_view->priv->empty_view_drop = TRUE;
7050 icon_view->priv->dest_pos = pos;
7054 icon_view->priv->dest_item =
7055 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7056 icon_view->priv->model, path);
7058 gtk_icon_view_queue_draw_path (icon_view, path);
7063 * gtk_icon_view_get_drag_dest_item:
7064 * @icon_view: a #GtkIconView
7065 * @path: Return location for the path of the highlighted item, or %NULL.
7066 * @pos: Return location for the drop position, or %NULL
7068 * Gets information about the item that is highlighted for feedback.
7073 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7075 GtkIconViewDropPosition *pos)
7077 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7081 if (icon_view->priv->dest_item)
7082 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7088 *pos = icon_view->priv->dest_pos;
7092 * gtk_icon_view_get_dest_item_at_pos:
7093 * @icon_view: a #GtkIconView
7094 * @drag_x: the position to determine the destination item for
7095 * @drag_y: the position to determine the destination item for
7096 * @path: Return location for the path of the item, or %NULL.
7097 * @pos: Return location for the drop position, or %NULL
7099 * Determines the destination item for a given position.
7101 * Return value: whether there is an item at the given position.
7106 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7110 GtkIconViewDropPosition *pos)
7112 GtkIconViewItem *item;
7114 /* Note; this function is exported to allow a custom DND
7115 * implementation, so it can't touch TreeViewDragInfo
7118 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7119 g_return_val_if_fail (drag_x >= 0, FALSE);
7120 g_return_val_if_fail (drag_y >= 0, FALSE);
7121 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7127 item = gtk_icon_view_get_item_at_coords (icon_view,
7128 drag_x + icon_view->priv->hadjustment->value,
7129 drag_y + icon_view->priv->vadjustment->value,
7136 *path = gtk_tree_path_new_from_indices (item->index, -1);
7140 if (drag_x < item->x + item->width / 4)
7141 *pos = GTK_ICON_VIEW_DROP_LEFT;
7142 else if (drag_x > item->x + item->width * 3 / 4)
7143 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7144 else if (drag_y < item->y + item->height / 4)
7145 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7146 else if (drag_y > item->y + item->height * 3 / 4)
7147 *pos = GTK_ICON_VIEW_DROP_BELOW;
7149 *pos = GTK_ICON_VIEW_DROP_INTO;
7156 * gtk_icon_view_create_drag_icon:
7157 * @icon_view: a #GtkIconView
7158 * @path: a #GtkTreePath in @icon_view
7160 * Creates a #GdkPixmap representation of the item at @path.
7161 * This image is used for a drag icon.
7163 * Return value: a newly-allocated pixmap of the drag icon.
7168 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7173 GdkPixmap *drawable;
7178 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7179 g_return_val_if_fail (path != NULL, NULL);
7181 widget = GTK_WIDGET (icon_view);
7183 if (!GTK_WIDGET_REALIZED (widget))
7186 index = gtk_tree_path_get_indices (path)[0];
7188 for (l = icon_view->priv->items; l; l = l->next)
7190 GtkIconViewItem *item = l->data;
7192 if (index == item->index)
7194 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7199 cr = gdk_cairo_create (drawable);
7200 cairo_set_line_width (cr, 1.);
7202 gdk_cairo_set_source_color
7203 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7204 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7209 area.width = item->width;
7210 area.height = item->height;
7212 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7213 drawable, 1, 1, FALSE);
7215 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7216 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7229 * gtk_icon_view_get_reorderable:
7230 * @icon_view: a #GtkIconView
7232 * Retrieves whether the user can reorder the list via drag-and-drop.
7233 * See gtk_icon_view_set_reorderable().
7235 * Return value: %TRUE if the list can be reordered.
7240 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7242 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7244 return icon_view->priv->reorderable;
7247 static const GtkTargetEntry item_targets[] = {
7248 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7253 * gtk_icon_view_set_reorderable:
7254 * @icon_view: A #GtkIconView.
7255 * @reorderable: %TRUE, if the list of items can be reordered.
7257 * This function is a convenience function to allow you to reorder models that
7258 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7259 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7260 * the user can reorder the model by dragging and dropping rows. The
7261 * developer can listen to these changes by connecting to the model's
7262 * row_inserted and row_deleted signals.
7264 * This function does not give you any degree of control over the order -- any
7265 * reordering is allowed. If more control is needed, you should probably
7266 * handle drag and drop manually.
7271 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7272 gboolean reorderable)
7274 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7276 reorderable = reorderable != FALSE;
7278 if (icon_view->priv->reorderable == reorderable)
7283 gtk_icon_view_enable_model_drag_source (icon_view,
7286 G_N_ELEMENTS (item_targets),
7288 gtk_icon_view_enable_model_drag_dest (icon_view,
7290 G_N_ELEMENTS (item_targets),
7295 gtk_icon_view_unset_model_drag_source (icon_view);
7296 gtk_icon_view_unset_model_drag_dest (icon_view);
7299 icon_view->priv->reorderable = reorderable;
7301 g_object_notify (G_OBJECT (icon_view), "reorderable");
7305 /* Accessibility Support */
7307 static gpointer accessible_parent_class;
7308 static gpointer accessible_item_parent_class;
7309 static GQuark accessible_private_data_quark = 0;
7311 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7312 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7313 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7315 static GType gtk_icon_view_item_accessible_get_type (void);
7326 GtkIconViewItem *item;
7330 AtkStateSet *state_set;
7334 GtkTextBuffer *text_buffer;
7336 gchar *action_descriptions[LAST_ACTION];
7337 gchar *image_description;
7338 guint action_idle_handler;
7339 } GtkIconViewItemAccessible;
7341 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7347 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7352 typedef struct _GtkIconViewItemAccessibleClass
7354 AtkObjectClass parent_class;
7356 } GtkIconViewItemAccessibleClass;
7358 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7361 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7363 GtkIconViewItemAccessible *item;
7364 GtkIconView *icon_view;
7367 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7368 item->action_idle_handler = 0;
7370 if (item->widget != NULL)
7372 icon_view = GTK_ICON_VIEW (item->widget);
7373 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7374 gtk_icon_view_item_activated (icon_view, path);
7375 gtk_tree_path_free (path);
7382 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7385 GtkIconViewItemAccessible *item;
7387 if (i < 0 || i >= LAST_ACTION)
7390 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7392 if (!GTK_IS_ICON_VIEW (item->widget))
7395 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7400 case ACTION_ACTIVATE:
7401 if (!item->action_idle_handler)
7402 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7405 g_assert_not_reached ();
7413 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7418 static const gchar *
7419 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7422 GtkIconViewItemAccessible *item;
7424 if (i < 0 || i >= LAST_ACTION)
7427 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7429 if (item->action_descriptions[i])
7430 return item->action_descriptions[i];
7432 return gtk_icon_view_item_accessible_action_descriptions[i];
7435 static const gchar *
7436 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7439 if (i < 0 || i >= LAST_ACTION)
7442 return gtk_icon_view_item_accessible_action_names[i];
7446 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7448 const gchar *description)
7450 GtkIconViewItemAccessible *item;
7452 if (i < 0 || i >= LAST_ACTION)
7455 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7457 g_free (item->action_descriptions[i]);
7459 item->action_descriptions[i] = g_strdup (description);
7465 atk_action_item_interface_init (AtkActionIface *iface)
7467 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7468 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7469 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7470 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7471 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7474 static const gchar *
7475 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7477 GtkIconViewItemAccessible *item;
7479 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7481 return item->image_description;
7485 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7486 const gchar *description)
7488 GtkIconViewItemAccessible *item;
7490 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7492 g_free (item->image_description);
7493 item->image_description = g_strdup (item->image_description);
7499 get_pixbuf_box (GtkIconView *icon_view,
7500 GtkIconViewItem *item,
7505 for (l = icon_view->priv->cell_list; l; l = l->next)
7507 GtkIconViewCellInfo *info = l->data;
7509 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7511 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7521 get_text (GtkIconView *icon_view,
7522 GtkIconViewItem *item)
7527 for (l = icon_view->priv->cell_list; l; l = l->next)
7529 GtkIconViewCellInfo *info = l->data;
7531 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7533 g_object_get (info->cell, "text", &text, NULL);
7543 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7547 GtkIconViewItemAccessible *item;
7550 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7552 if (!GTK_IS_ICON_VIEW (item->widget))
7555 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7558 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7561 *height = box.height;
7566 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7569 AtkCoordType coord_type)
7571 GtkIconViewItemAccessible *item;
7574 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7576 if (!GTK_IS_ICON_VIEW (item->widget))
7579 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7582 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7584 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7586 *x+= box.x - item->item->x;
7587 *y+= box.y - item->item->y;
7593 atk_image_item_interface_init (AtkImageIface *iface)
7595 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7596 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7597 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7598 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7602 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7606 GtkIconViewItemAccessible *item;
7607 GtkTextIter start, end;
7608 GtkTextBuffer *buffer;
7610 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7612 if (!GTK_IS_ICON_VIEW (item->widget))
7615 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7618 buffer = item->text_buffer;
7619 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7621 gtk_text_buffer_get_end_iter (buffer, &end);
7623 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7625 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7629 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7632 GtkIconViewItemAccessible *item;
7633 GtkTextIter start, end;
7634 GtkTextBuffer *buffer;
7638 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7640 if (!GTK_IS_ICON_VIEW (item->widget))
7643 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7646 buffer = item->text_buffer;
7647 if (offset >= gtk_text_buffer_get_char_count (buffer))
7650 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7652 gtk_text_iter_forward_char (&end);
7653 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7654 unichar = g_utf8_get_char (string);
7662 get_pango_text_offsets (PangoLayout *layout,
7663 GtkTextBuffer *buffer,
7665 AtkTextBoundary boundary_type,
7669 GtkTextIter *start_iter,
7670 GtkTextIter *end_iter)
7672 PangoLayoutIter *iter;
7673 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7674 gint index, start_index, end_index;
7676 gboolean found = FALSE;
7678 text = pango_layout_get_text (layout);
7679 index = g_utf8_offset_to_pointer (text, offset) - text;
7680 iter = pango_layout_get_iter (layout);
7683 line = pango_layout_iter_get_line_readonly (iter);
7684 start_index = line->start_index;
7685 end_index = start_index + line->length;
7687 if (index >= start_index && index <= end_index)
7690 * Found line for offset
7696 * We want the previous line
7700 switch (boundary_type)
7702 case ATK_TEXT_BOUNDARY_LINE_START:
7703 end_index = start_index;
7704 start_index = prev_line->start_index;
7706 case ATK_TEXT_BOUNDARY_LINE_END:
7708 start_index = prev_prev_line->start_index +
7709 prev_prev_line->length;
7710 end_index = prev_line->start_index + prev_line->length;
7713 g_assert_not_reached();
7717 start_index = end_index = 0;
7720 switch (boundary_type)
7722 case ATK_TEXT_BOUNDARY_LINE_START:
7723 if (pango_layout_iter_next_line (iter))
7724 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7726 case ATK_TEXT_BOUNDARY_LINE_END:
7728 start_index = prev_line->start_index +
7732 g_assert_not_reached();
7737 * We want the next line
7739 if (pango_layout_iter_next_line (iter))
7741 line = pango_layout_iter_get_line_readonly (iter);
7742 switch (boundary_type)
7744 case ATK_TEXT_BOUNDARY_LINE_START:
7745 start_index = line->start_index;
7746 if (pango_layout_iter_next_line (iter))
7747 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7749 end_index = start_index + line->length;
7751 case ATK_TEXT_BOUNDARY_LINE_END:
7752 start_index = end_index;
7753 end_index = line->start_index + line->length;
7756 g_assert_not_reached();
7760 start_index = end_index;
7766 prev_prev_line = prev_line;
7769 while (pango_layout_iter_next_line (iter));
7773 start_index = prev_line->start_index + prev_line->length;
7774 end_index = start_index;
7776 pango_layout_iter_free (iter);
7777 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7778 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7780 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7781 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7786 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7788 AtkTextBoundary boundary_type,
7792 GtkIconViewItemAccessible *item;
7793 GtkTextIter start, end;
7794 GtkTextBuffer *buffer;
7796 GtkIconView *icon_view;
7799 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7801 if (!GTK_IS_ICON_VIEW (item->widget))
7804 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7807 buffer = item->text_buffer;
7809 if (!gtk_text_buffer_get_char_count (buffer))
7813 return g_strdup ("");
7815 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7819 switch (boundary_type)
7821 case ATK_TEXT_BOUNDARY_CHAR:
7822 gtk_text_iter_backward_char(&start);
7824 case ATK_TEXT_BOUNDARY_WORD_START:
7825 if (!gtk_text_iter_starts_word (&start))
7826 gtk_text_iter_backward_word_start (&start);
7828 gtk_text_iter_backward_word_start(&start);
7830 case ATK_TEXT_BOUNDARY_WORD_END:
7831 if (gtk_text_iter_inside_word (&start) &&
7832 !gtk_text_iter_starts_word (&start))
7833 gtk_text_iter_backward_word_start (&start);
7834 while (!gtk_text_iter_ends_word (&start))
7836 if (!gtk_text_iter_backward_char (&start))
7840 gtk_text_iter_backward_word_start(&start);
7841 while (!gtk_text_iter_ends_word (&start))
7843 if (!gtk_text_iter_backward_char (&start))
7847 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7848 if (!gtk_text_iter_starts_sentence (&start))
7849 gtk_text_iter_backward_sentence_start (&start);
7851 gtk_text_iter_backward_sentence_start (&start);
7853 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7854 if (gtk_text_iter_inside_sentence (&start) &&
7855 !gtk_text_iter_starts_sentence (&start))
7856 gtk_text_iter_backward_sentence_start (&start);
7857 while (!gtk_text_iter_ends_sentence (&start))
7859 if (!gtk_text_iter_backward_char (&start))
7863 gtk_text_iter_backward_sentence_start (&start);
7864 while (!gtk_text_iter_ends_sentence (&start))
7866 if (!gtk_text_iter_backward_char (&start))
7870 case ATK_TEXT_BOUNDARY_LINE_START:
7871 case ATK_TEXT_BOUNDARY_LINE_END:
7873 icon_view = GTK_ICON_VIEW (item->widget);
7874 /* FIXME we probably have to use GailTextCell to salvage this */
7875 gtk_icon_view_update_item_text (icon_view, item->item);
7876 get_pango_text_offsets (icon_view->priv->layout,
7889 *start_offset = gtk_text_iter_get_offset (&start);
7890 *end_offset = gtk_text_iter_get_offset (&end);
7892 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7896 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7898 AtkTextBoundary boundary_type,
7902 GtkIconViewItemAccessible *item;
7903 GtkTextIter start, end;
7904 GtkTextBuffer *buffer;
7906 GtkIconView *icon_view;
7909 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7911 if (!GTK_IS_ICON_VIEW (item->widget))
7914 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7917 buffer = item->text_buffer;
7919 if (!gtk_text_buffer_get_char_count (buffer))
7923 return g_strdup ("");
7925 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7929 switch (boundary_type)
7931 case ATK_TEXT_BOUNDARY_CHAR:
7932 gtk_text_iter_forward_char (&end);
7934 case ATK_TEXT_BOUNDARY_WORD_START:
7935 if (!gtk_text_iter_starts_word (&start))
7936 gtk_text_iter_backward_word_start (&start);
7937 if (gtk_text_iter_inside_word (&end))
7938 gtk_text_iter_forward_word_end (&end);
7939 while (!gtk_text_iter_starts_word (&end))
7941 if (!gtk_text_iter_forward_char (&end))
7945 case ATK_TEXT_BOUNDARY_WORD_END:
7946 if (gtk_text_iter_inside_word (&start) &&
7947 !gtk_text_iter_starts_word (&start))
7948 gtk_text_iter_backward_word_start (&start);
7949 while (!gtk_text_iter_ends_word (&start))
7951 if (!gtk_text_iter_backward_char (&start))
7954 gtk_text_iter_forward_word_end (&end);
7956 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7957 if (!gtk_text_iter_starts_sentence (&start))
7958 gtk_text_iter_backward_sentence_start (&start);
7959 if (gtk_text_iter_inside_sentence (&end))
7960 gtk_text_iter_forward_sentence_end (&end);
7961 while (!gtk_text_iter_starts_sentence (&end))
7963 if (!gtk_text_iter_forward_char (&end))
7967 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7968 if (gtk_text_iter_inside_sentence (&start) &&
7969 !gtk_text_iter_starts_sentence (&start))
7970 gtk_text_iter_backward_sentence_start (&start);
7971 while (!gtk_text_iter_ends_sentence (&start))
7973 if (!gtk_text_iter_backward_char (&start))
7976 gtk_text_iter_forward_sentence_end (&end);
7978 case ATK_TEXT_BOUNDARY_LINE_START:
7979 case ATK_TEXT_BOUNDARY_LINE_END:
7981 icon_view = GTK_ICON_VIEW (item->widget);
7982 /* FIXME we probably have to use GailTextCell to salvage this */
7983 gtk_icon_view_update_item_text (icon_view, item->item);
7984 get_pango_text_offsets (icon_view->priv->layout,
7998 *start_offset = gtk_text_iter_get_offset (&start);
7999 *end_offset = gtk_text_iter_get_offset (&end);
8001 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8005 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8007 AtkTextBoundary boundary_type,
8011 GtkIconViewItemAccessible *item;
8012 GtkTextIter start, end;
8013 GtkTextBuffer *buffer;
8015 GtkIconView *icon_view;
8018 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8020 if (!GTK_IS_ICON_VIEW (item->widget))
8023 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8026 buffer = item->text_buffer;
8028 if (!gtk_text_buffer_get_char_count (buffer))
8032 return g_strdup ("");
8034 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8038 switch (boundary_type)
8040 case ATK_TEXT_BOUNDARY_CHAR:
8041 gtk_text_iter_forward_char(&start);
8042 gtk_text_iter_forward_chars(&end, 2);
8044 case ATK_TEXT_BOUNDARY_WORD_START:
8045 if (gtk_text_iter_inside_word (&end))
8046 gtk_text_iter_forward_word_end (&end);
8047 while (!gtk_text_iter_starts_word (&end))
8049 if (!gtk_text_iter_forward_char (&end))
8053 if (!gtk_text_iter_is_end (&end))
8055 gtk_text_iter_forward_word_end (&end);
8056 while (!gtk_text_iter_starts_word (&end))
8058 if (!gtk_text_iter_forward_char (&end))
8063 case ATK_TEXT_BOUNDARY_WORD_END:
8064 gtk_text_iter_forward_word_end (&end);
8066 if (!gtk_text_iter_is_end (&end))
8067 gtk_text_iter_forward_word_end (&end);
8069 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8070 if (gtk_text_iter_inside_sentence (&end))
8071 gtk_text_iter_forward_sentence_end (&end);
8072 while (!gtk_text_iter_starts_sentence (&end))
8074 if (!gtk_text_iter_forward_char (&end))
8078 if (!gtk_text_iter_is_end (&end))
8080 gtk_text_iter_forward_sentence_end (&end);
8081 while (!gtk_text_iter_starts_sentence (&end))
8083 if (!gtk_text_iter_forward_char (&end))
8088 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8089 gtk_text_iter_forward_sentence_end (&end);
8091 if (!gtk_text_iter_is_end (&end))
8092 gtk_text_iter_forward_sentence_end (&end);
8094 case ATK_TEXT_BOUNDARY_LINE_START:
8095 case ATK_TEXT_BOUNDARY_LINE_END:
8097 icon_view = GTK_ICON_VIEW (item->widget);
8098 /* FIXME we probably have to use GailTextCell to salvage this */
8099 gtk_icon_view_update_item_text (icon_view, item->item);
8100 get_pango_text_offsets (icon_view->priv->layout,
8112 *start_offset = gtk_text_iter_get_offset (&start);
8113 *end_offset = gtk_text_iter_get_offset (&end);
8115 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8119 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8121 GtkIconViewItemAccessible *item;
8123 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8125 if (!GTK_IS_ICON_VIEW (item->widget))
8128 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8131 return gtk_text_buffer_get_char_count (item->text_buffer);
8135 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8141 AtkCoordType coord_type)
8143 GtkIconViewItemAccessible *item;
8145 GtkIconView *icon_view;
8146 PangoRectangle char_rect;
8147 const gchar *item_text;
8151 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8153 if (!GTK_IS_ICON_VIEW (item->widget))
8156 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8160 icon_view = GTK_ICON_VIEW (item->widget);
8161 /* FIXME we probably have to use GailTextCell to salvage this */
8162 gtk_icon_view_update_item_text (icon_view, item->item);
8163 item_text = pango_layout_get_text (icon_view->priv->layout);
8164 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8165 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8167 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8168 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8169 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8170 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8171 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8172 *width = char_rect.width / PANGO_SCALE;
8173 *height = char_rect.height / PANGO_SCALE;
8178 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8181 AtkCoordType coord_type)
8183 GtkIconViewItemAccessible *item;
8186 GtkIconView *icon_view;
8187 const gchar *item_text;
8192 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8194 if (!GTK_IS_ICON_VIEW (item->widget))
8197 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8201 icon_view = GTK_ICON_VIEW (item->widget);
8202 /* FIXME we probably have to use GailTextCell to salvage this */
8203 gtk_icon_view_update_item_text (icon_view, item->item);
8204 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8205 x -= l_x + item->item->layout_x - item->item->x;
8206 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8207 y -= l_y + item->item->layout_y - item->item->y;
8208 item_text = pango_layout_get_text (icon_view->priv->layout);
8209 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8220 offset = g_utf8_strlen (item_text, -1);
8222 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8228 atk_text_item_interface_init (AtkTextIface *iface)
8230 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8231 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8232 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8233 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8234 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8235 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8236 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8237 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8241 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8246 AtkCoordType coord_type)
8248 GtkIconViewItemAccessible *item;
8249 AtkObject *parent_obj;
8252 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8254 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8255 if (!GTK_IS_WIDGET (item->widget))
8258 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8261 *width = item->item->width;
8262 *height = item->item->height;
8263 if (gtk_icon_view_item_accessible_is_showing (item))
8265 parent_obj = gtk_widget_get_accessible (item->widget);
8266 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8267 *x = l_x + item->item->x;
8268 *y = l_y + item->item->y;
8278 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8280 GtkIconViewItemAccessible *item;
8281 GtkWidget *toplevel;
8283 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8285 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8286 if (!GTK_IS_WIDGET (item->widget))
8289 gtk_widget_grab_focus (item->widget);
8290 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8291 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8292 if (GTK_WIDGET_TOPLEVEL (toplevel))
8293 gtk_window_present (GTK_WINDOW (toplevel));
8299 atk_component_item_interface_init (AtkComponentIface *iface)
8301 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8302 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8306 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8307 AtkStateType state_type,
8308 gboolean emit_signal)
8312 rc = atk_state_set_add_state (item->state_set, state_type);
8314 * The signal should only be generated if the value changed,
8315 * not when the item is set up. So states that are set
8316 * initially should pass FALSE as the emit_signal argument.
8321 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8322 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8323 if (state_type == ATK_STATE_VISIBLE)
8324 g_signal_emit_by_name (item, "visible_data_changed");
8331 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8332 AtkStateType state_type,
8333 gboolean emit_signal)
8335 if (atk_state_set_contains_state (item->state_set, state_type))
8339 rc = atk_state_set_remove_state (item->state_set, state_type);
8341 * The signal should only be generated if the value changed,
8342 * not when the item is set up. So states that are set
8343 * initially should pass FALSE as the emit_signal argument.
8348 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8349 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8350 if (state_type == ATK_STATE_VISIBLE)
8351 g_signal_emit_by_name (item, "visible_data_changed");
8361 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8363 GtkIconView *icon_view;
8364 GdkRectangle visible_rect;
8365 gboolean is_showing;
8368 * An item is considered "SHOWING" if any part of the item is in the
8369 * visible rectangle.
8372 if (!GTK_IS_ICON_VIEW (item->widget))
8375 if (item->item == NULL)
8378 icon_view = GTK_ICON_VIEW (item->widget);
8380 if (icon_view->priv->hadjustment)
8381 visible_rect.x += icon_view->priv->hadjustment->value;
8383 if (icon_view->priv->hadjustment)
8384 visible_rect.y += icon_view->priv->vadjustment->value;
8385 visible_rect.width = item->widget->allocation.width;
8386 visible_rect.height = item->widget->allocation.height;
8388 if (((item->item->x + item->item->width) < visible_rect.x) ||
8389 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8390 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8391 (item->item->y > (visible_rect.y + visible_rect.height)))
8400 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8401 gboolean emit_signal)
8403 if (gtk_icon_view_item_accessible_is_showing (item))
8404 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8407 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8412 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8416 item->state_set = atk_state_set_new ();
8418 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8419 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8420 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8421 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8422 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8424 for (i = 0; i < LAST_ACTION; i++)
8425 item->action_descriptions[i] = NULL;
8427 item->image_description = NULL;
8429 item->action_idle_handler = 0;
8433 gtk_icon_view_item_accessible_finalize (GObject *object)
8435 GtkIconViewItemAccessible *item;
8438 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8440 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8443 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8445 if (item->state_set)
8446 g_object_unref (item->state_set);
8448 if (item->text_buffer)
8449 g_object_unref (item->text_buffer);
8451 for (i = 0; i < LAST_ACTION; i++)
8452 g_free (item->action_descriptions[i]);
8454 g_free (item->image_description);
8456 if (item->action_idle_handler)
8458 g_source_remove (item->action_idle_handler);
8459 item->action_idle_handler = 0;
8462 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8465 static G_CONST_RETURN gchar*
8466 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8472 GtkIconViewItemAccessible *item;
8473 GtkTextIter start_iter;
8474 GtkTextIter end_iter;
8476 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8478 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8479 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8481 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8486 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8488 GtkIconViewItemAccessible *item;
8490 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8491 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8494 return gtk_widget_get_accessible (item->widget);
8500 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8502 GtkIconViewItemAccessible *item;
8504 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8505 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8507 return item->item->index;
8510 static AtkStateSet *
8511 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8513 GtkIconViewItemAccessible *item;
8514 GtkIconView *icon_view;
8516 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8517 g_return_val_if_fail (item->state_set, NULL);
8522 icon_view = GTK_ICON_VIEW (item->widget);
8523 if (icon_view->priv->cursor_item == item->item)
8524 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8526 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8527 if (item->item->selected)
8528 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8530 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8532 return g_object_ref (item->state_set);
8536 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8538 GObjectClass *gobject_class;
8540 accessible_item_parent_class = g_type_class_peek_parent (klass);
8542 gobject_class = (GObjectClass *)klass;
8544 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8546 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8547 klass->get_name = gtk_icon_view_item_accessible_get_name;
8548 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8549 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8553 gtk_icon_view_item_accessible_get_type (void)
8555 static GType type = 0;
8559 const GTypeInfo tinfo =
8561 sizeof (GtkIconViewItemAccessibleClass),
8562 (GBaseInitFunc) NULL, /* base init */
8563 (GBaseFinalizeFunc) NULL, /* base finalize */
8564 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8565 (GClassFinalizeFunc) NULL, /* class finalize */
8566 NULL, /* class data */
8567 sizeof (GtkIconViewItemAccessible), /* instance size */
8568 0, /* nb preallocs */
8569 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8570 NULL /* value table */
8573 static const GInterfaceInfo atk_component_info =
8575 (GInterfaceInitFunc) atk_component_item_interface_init,
8576 (GInterfaceFinalizeFunc) NULL,
8579 static const GInterfaceInfo atk_action_info =
8581 (GInterfaceInitFunc) atk_action_item_interface_init,
8582 (GInterfaceFinalizeFunc) NULL,
8585 static const GInterfaceInfo atk_image_info =
8587 (GInterfaceInitFunc) atk_image_item_interface_init,
8588 (GInterfaceFinalizeFunc) NULL,
8591 static const GInterfaceInfo atk_text_info =
8593 (GInterfaceInitFunc) atk_text_item_interface_init,
8594 (GInterfaceFinalizeFunc) NULL,
8598 type = g_type_register_static (ATK_TYPE_OBJECT,
8599 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8600 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8601 &atk_component_info);
8602 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8604 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8606 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8613 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8614 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8615 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8617 static GType gtk_icon_view_accessible_get_type (void);
8622 } GtkIconViewAccessible;
8628 } GtkIconViewItemAccessibleInfo;
8634 GtkAdjustment *old_hadj;
8635 GtkAdjustment *old_vadj;
8637 GtkTreeModel *model;
8639 } GtkIconViewAccessiblePrivate;
8641 static GtkIconViewAccessiblePrivate *
8642 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8644 return g_object_get_qdata (G_OBJECT (accessible),
8645 accessible_private_data_quark);
8649 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8653 GtkIconViewItemAccessibleInfo *info;
8654 GtkIconViewItemAccessibleInfo *tmp_info;
8655 GtkIconViewAccessiblePrivate *priv;
8658 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8660 info->index = index;
8662 priv = gtk_icon_view_accessible_get_priv (accessible);
8663 items = priv->items;
8666 tmp_info = items->data;
8667 if (tmp_info->index > index)
8669 items = items->next;
8671 priv->items = g_list_insert_before (priv->items, items, info);
8672 priv->old_hadj = NULL;
8673 priv->old_vadj = NULL;
8677 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8679 GtkIconView *icon_view;
8682 widget = GTK_ACCESSIBLE (accessible)->widget;
8686 icon_view = GTK_ICON_VIEW (widget);
8688 return g_list_length (icon_view->priv->items);
8692 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8695 GtkIconViewAccessiblePrivate *priv;
8696 GtkIconViewItemAccessibleInfo *info;
8699 priv = gtk_icon_view_accessible_get_priv (accessible);
8700 items = priv->items;
8705 if (info->index == index)
8707 items = items->next;
8713 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8716 GtkIconView *icon_view;
8720 GtkIconViewItemAccessible *a11y_item;
8722 widget = GTK_ACCESSIBLE (accessible)->widget;
8726 icon_view = GTK_ICON_VIEW (widget);
8727 icons = g_list_nth (icon_view->priv->items, index);
8731 GtkIconViewItem *item = icons->data;
8733 g_return_val_if_fail (item->index == index, NULL);
8734 obj = gtk_icon_view_accessible_find_child (accessible, index);
8739 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8740 gtk_icon_view_item_accessible_info_new (accessible,
8743 obj->role = ATK_ROLE_ICON;
8744 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8745 a11y_item->item = item;
8746 a11y_item->widget = widget;
8747 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8749 gtk_icon_view_set_cell_data (icon_view, item);
8750 text = get_text (icon_view, item);
8753 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8757 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8758 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8766 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8769 GtkIconViewAccessiblePrivate *priv;
8770 GtkIconViewItemAccessibleInfo *info;
8771 GtkIconViewItemAccessible *item;
8774 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8778 gboolean act_on_item;
8780 widget = GTK_ACCESSIBLE (view)->widget;
8784 items = priv->items;
8786 act_on_item = (list == NULL);
8791 info = (GtkIconViewItemAccessibleInfo *)items->data;
8792 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8794 if (act_on_item == FALSE && list == items)
8798 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8800 items = items->next;
8806 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8807 GtkIconView *icon_view)
8810 GtkIconViewAccessible *view;
8813 * The scrollbars have changed
8815 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8816 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8818 gtk_icon_view_accessible_traverse_items (view, NULL);
8822 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8823 GtkAdjustment *hadj,
8824 GtkAdjustment *vadj)
8827 GtkIconViewAccessiblePrivate *priv;
8829 atk_obj = gtk_widget_get_accessible (widget);
8830 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8832 if (priv->old_hadj != hadj)
8836 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8837 (gpointer *)&priv->old_hadj);
8839 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8840 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8843 priv->old_hadj = hadj;
8846 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8847 (gpointer *)&priv->old_hadj);
8848 g_signal_connect (hadj,
8850 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8854 if (priv->old_vadj != vadj)
8858 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8859 (gpointer *)&priv->old_vadj);
8861 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8862 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8865 priv->old_vadj = vadj;
8868 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8869 (gpointer *)&priv->old_vadj);
8870 g_signal_connect (vadj,
8872 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8879 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8886 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8887 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8893 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8898 GtkIconViewAccessiblePrivate *priv;
8899 GtkIconViewItemAccessibleInfo *info;
8900 GtkIconViewAccessible *view;
8901 GtkIconViewItemAccessible *item;
8907 index = gtk_tree_path_get_indices(path)[0];
8908 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8909 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8910 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8912 items = priv->items;
8917 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8918 if (info->index != item->item->index)
8920 if (info->index < index)
8921 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8923 if (tmp_list == NULL)
8926 info->index = item->item->index;
8929 items = items->next;
8931 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8932 g_signal_emit_by_name (atk_obj, "children_changed::add",
8938 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8942 GtkIconViewAccessiblePrivate *priv;
8943 GtkIconViewItemAccessibleInfo *info;
8944 GtkIconViewAccessible *view;
8945 GtkIconViewItemAccessible *item;
8948 GList *deleted_item;
8952 index = gtk_tree_path_get_indices(path)[0];
8953 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8954 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8955 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8957 items = priv->items;
8959 deleted_item = NULL;
8964 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8965 if (info->index == index)
8967 deleted_item = items;
8969 if (info->index != item->item->index)
8971 if (tmp_list == NULL)
8974 info->index = item->item->index;
8977 items = items->next;
8979 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8982 info = deleted_item->data;
8983 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8984 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8986 priv->items = g_list_remove_link (priv->items, deleted_item);
8994 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8995 GtkIconViewItemAccessibleInfo *i2)
8997 return i1->index - i2->index;
9001 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9007 GtkIconViewAccessiblePrivate *priv;
9008 GtkIconViewItemAccessibleInfo *info;
9009 GtkIconView *icon_view;
9010 GtkIconViewItemAccessible *item;
9014 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9015 icon_view = GTK_ICON_VIEW (user_data);
9016 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9018 items = priv->items;
9022 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9023 info->index = new_order[info->index];
9024 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9025 items = items->next;
9027 priv->items = g_list_sort (priv->items,
9028 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9034 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9039 obj = G_OBJECT (model);
9040 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9041 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9042 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9043 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9047 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9051 obj = G_OBJECT (icon_view->priv->model);
9052 g_signal_connect_data (obj, "row_changed",
9053 (GCallback) gtk_icon_view_accessible_model_row_changed,
9054 icon_view, NULL, 0);
9055 g_signal_connect_data (obj, "row_inserted",
9056 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9057 icon_view, NULL, G_CONNECT_AFTER);
9058 g_signal_connect_data (obj, "row_deleted",
9059 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9060 icon_view, NULL, G_CONNECT_AFTER);
9061 g_signal_connect_data (obj, "rows_reordered",
9062 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9063 icon_view, NULL, G_CONNECT_AFTER);
9067 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9069 GtkIconViewItemAccessibleInfo *info;
9072 items = priv->items;
9075 info = (GtkIconViewItemAccessibleInfo *) items->data;
9076 g_object_unref (info->item);
9077 g_free (items->data);
9078 items = items->next;
9080 g_list_free (priv->items);
9085 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9088 GtkIconView *icon_view;
9091 GtkIconViewAccessiblePrivate *priv;
9093 if (strcmp (pspec->name, "model") == 0)
9095 widget = GTK_WIDGET (obj);
9096 atk_obj = gtk_widget_get_accessible (widget);
9097 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9100 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9101 (gpointer *)&priv->model);
9102 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9104 gtk_icon_view_accessible_clear_cache (priv);
9106 icon_view = GTK_ICON_VIEW (obj);
9107 priv->model = icon_view->priv->model;
9108 /* If there is no model the GtkIconView is probably being destroyed */
9111 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9112 gtk_icon_view_accessible_connect_model_signals (icon_view);
9120 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9123 GtkIconViewAccessiblePrivate *priv;
9124 GtkIconView *icon_view;
9126 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9127 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9129 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9130 g_object_set_qdata (G_OBJECT (accessible),
9131 accessible_private_data_quark,
9134 icon_view = GTK_ICON_VIEW (data);
9135 if (icon_view->priv->hadjustment)
9137 priv->old_hadj = icon_view->priv->hadjustment;
9138 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9139 g_signal_connect (icon_view->priv->hadjustment,
9141 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9144 if (icon_view->priv->vadjustment)
9146 priv->old_vadj = icon_view->priv->vadjustment;
9147 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9148 g_signal_connect (icon_view->priv->vadjustment,
9150 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9153 g_signal_connect_after (data,
9154 "set_scroll_adjustments",
9155 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9157 g_signal_connect (data,
9159 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9162 priv->model = icon_view->priv->model;
9165 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9166 gtk_icon_view_accessible_connect_model_signals (icon_view);
9169 accessible->role = ATK_ROLE_LAYERED_PANE;
9173 gtk_icon_view_accessible_finalize (GObject *object)
9175 GtkIconViewAccessiblePrivate *priv;
9177 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9178 gtk_icon_view_accessible_clear_cache (priv);
9182 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9186 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9187 GtkAccessible *accessible)
9190 GtkIconViewAccessiblePrivate *priv;
9192 atk_obj = ATK_OBJECT (accessible);
9193 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9196 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9197 (gpointer *)&priv->old_hadj);
9199 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9200 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9202 priv->old_hadj = NULL;
9206 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9207 (gpointer *)&priv->old_vadj);
9209 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9210 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9212 priv->old_vadj = NULL;
9217 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9219 if (accessible->widget)
9221 g_signal_connect_after (accessible->widget,
9223 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9226 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9230 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9232 GObjectClass *gobject_class;
9233 GtkAccessibleClass *accessible_class;
9235 accessible_parent_class = g_type_class_peek_parent (klass);
9237 gobject_class = (GObjectClass *)klass;
9238 accessible_class = (GtkAccessibleClass *)klass;
9240 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9242 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9243 klass->ref_child = gtk_icon_view_accessible_ref_child;
9244 klass->initialize = gtk_icon_view_accessible_initialize;
9246 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9248 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9252 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9255 AtkCoordType coord_type)
9258 GtkIconView *icon_view;
9259 GtkIconViewItem *item;
9262 widget = GTK_ACCESSIBLE (component)->widget;
9264 /* State is defunct */
9267 icon_view = GTK_ICON_VIEW (widget);
9268 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9269 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9271 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9277 atk_component_interface_init (AtkComponentIface *iface)
9279 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9283 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9287 GtkIconView *icon_view;
9288 GtkIconViewItem *item;
9290 widget = GTK_ACCESSIBLE (selection)->widget;
9294 icon_view = GTK_ICON_VIEW (widget);
9296 item = g_list_nth_data (icon_view->priv->items, i);
9301 gtk_icon_view_select_item (icon_view, item);
9307 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9310 GtkIconView *icon_view;
9312 widget = GTK_ACCESSIBLE (selection)->widget;
9316 icon_view = GTK_ICON_VIEW (widget);
9317 gtk_icon_view_unselect_all (icon_view);
9323 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9328 GtkIconView *icon_view;
9329 GtkIconViewItem *item;
9331 widget = GTK_ACCESSIBLE (selection)->widget;
9335 icon_view = GTK_ICON_VIEW (widget);
9337 l = icon_view->priv->items;
9344 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9355 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9358 GtkIconView *icon_view;
9359 GtkIconViewItem *item;
9363 widget = GTK_ACCESSIBLE (selection)->widget;
9367 icon_view = GTK_ICON_VIEW (widget);
9369 l = icon_view->priv->items;
9385 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9389 GtkIconView *icon_view;
9390 GtkIconViewItem *item;
9392 widget = GTK_ACCESSIBLE (selection)->widget;
9396 icon_view = GTK_ICON_VIEW (widget);
9398 item = g_list_nth_data (icon_view->priv->items, i);
9402 return item->selected;
9406 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9410 GtkIconView *icon_view;
9411 GtkIconViewItem *item;
9415 widget = GTK_ACCESSIBLE (selection)->widget;
9419 icon_view = GTK_ICON_VIEW (widget);
9420 l = icon_view->priv->items;
9429 gtk_icon_view_unselect_item (icon_view, item);
9441 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9444 GtkIconView *icon_view;
9446 widget = GTK_ACCESSIBLE (selection)->widget;
9450 icon_view = GTK_ICON_VIEW (widget);
9451 gtk_icon_view_select_all (icon_view);
9456 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9458 iface->add_selection = gtk_icon_view_accessible_add_selection;
9459 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9460 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9461 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9462 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9463 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9464 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9468 gtk_icon_view_accessible_get_type (void)
9470 static GType type = 0;
9474 static GTypeInfo tinfo =
9477 (GBaseInitFunc) NULL, /* base init */
9478 (GBaseFinalizeFunc) NULL, /* base finalize */
9479 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9480 (GClassFinalizeFunc) NULL, /* class finalize */
9481 NULL, /* class data */
9482 0, /* instance size */
9483 0, /* nb preallocs */
9484 (GInstanceInitFunc) NULL, /* instance init */
9485 NULL /* value table */
9487 static const GInterfaceInfo atk_component_info =
9489 (GInterfaceInitFunc) atk_component_interface_init,
9490 (GInterfaceFinalizeFunc) NULL,
9493 static const GInterfaceInfo atk_selection_info =
9495 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9496 (GInterfaceFinalizeFunc) NULL,
9501 * Figure out the size of the class and instance
9502 * we are deriving from
9504 AtkObjectFactory *factory;
9507 GType derived_atk_type;
9509 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9510 factory = atk_registry_get_factory (atk_get_default_registry (),
9512 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9513 g_type_query (derived_atk_type, &query);
9514 tinfo.class_size = query.class_size;
9515 tinfo.instance_size = query.instance_size;
9517 type = g_type_register_static (derived_atk_type,
9518 I_("GtkIconViewAccessible"),
9520 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9521 &atk_component_info);
9522 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9523 &atk_selection_info);
9529 gtk_icon_view_accessible_new (GObject *obj)
9531 AtkObject *accessible;
9533 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9535 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9536 atk_object_initialize (accessible, obj);
9542 gtk_icon_view_accessible_factory_get_accessible_type (void)
9544 return gtk_icon_view_accessible_get_type ();
9548 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9550 return gtk_icon_view_accessible_new (obj);
9554 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9556 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9557 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9561 gtk_icon_view_accessible_factory_get_type (void)
9563 static GType type = 0;
9567 const GTypeInfo tinfo =
9569 sizeof (AtkObjectFactoryClass),
9570 NULL, /* base_init */
9571 NULL, /* base_finalize */
9572 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9573 NULL, /* class_finalize */
9574 NULL, /* class_data */
9575 sizeof (AtkObjectFactory),
9576 0, /* n_preallocs */
9580 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9581 I_("GtkIconViewAccessibleFactory"),
9589 gtk_icon_view_get_accessible (GtkWidget *widget)
9591 static gboolean first_time = TRUE;
9595 AtkObjectFactory *factory;
9596 AtkRegistry *registry;
9598 GType derived_atk_type;
9601 * Figure out whether accessibility is enabled by looking at the
9602 * type of the accessible object which would be created for
9603 * the parent type of GtkIconView.
9605 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9607 registry = atk_get_default_registry ();
9608 factory = atk_registry_get_factory (registry,
9610 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9611 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9612 atk_registry_set_factory_type (registry,
9614 gtk_icon_view_accessible_factory_get_type ());
9617 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9621 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9622 GtkBuilder *builder,
9624 const gchar *tagname,
9625 GMarkupParser *parser,
9628 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9629 tagname, parser, data))
9632 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9633 tagname, parser, data);
9637 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9638 GtkBuilder *builder,
9640 const gchar *tagname,
9643 if (strcmp (tagname, "attributes") == 0)
9644 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9647 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9653 #define __GTK_ICON_VIEW_C__
9654 #include "gtkaliasdef.c"