2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
36 #include "gtksignal.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.h"
43 #include "gtktreednd.h"
44 #include "gtkprivate.h"
47 #undef DEBUG_ICON_VIEW
49 #define SCROLL_EDGE_SIZE 15
51 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
53 typedef struct _GtkIconViewItem GtkIconViewItem;
54 struct _GtkIconViewItem
62 gint x, y, width, height;
65 * box[i] is the actual area occupied by cell i,
66 * before, after are used to calculate the cell
67 * area relative to the box.
68 * See gtk_icon_view_get_cell_area().
76 guint selected_before_rubberbanding : 1;
80 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
81 struct _GtkIconViewCellInfo
83 GtkCellRenderer *cell;
93 GtkCellLayoutDataFunc func;
95 GDestroyNotify destroy;
98 typedef struct _GtkIconViewChild GtkIconViewChild;
99 struct _GtkIconViewChild
102 GtkIconViewItem *item;
106 struct _GtkIconViewPrivate
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gboolean doing_rubberband;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
162 GdkModifierType start_button_mask;
167 GtkTargetList *source_targets;
168 GdkDragAction source_actions;
170 GtkTargetList *dest_targets;
171 GdkDragAction dest_actions;
173 GtkTreeRowReference *dest_item;
174 GtkIconViewDropPosition dest_pos;
177 GtkTreeRowReference *scroll_to_path;
178 gfloat scroll_to_row_align;
179 gfloat scroll_to_col_align;
180 guint scroll_to_use_align : 1;
182 guint source_set : 1;
184 guint reorderable : 1;
185 guint empty_view_drop :1;
187 guint ctrl_pressed : 1;
188 guint shift_pressed : 1;
201 ACTIVATE_CURSOR_ITEM,
225 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
226 static void gtk_icon_view_finalize (GObject *object);
227 static void gtk_icon_view_set_property (GObject *object,
231 static void gtk_icon_view_get_property (GObject *object,
236 /* GtkObject vfuncs */
237 static void gtk_icon_view_destroy (GtkObject *object);
239 /* GtkWidget vfuncs */
240 static void gtk_icon_view_realize (GtkWidget *widget);
241 static void gtk_icon_view_unrealize (GtkWidget *widget);
242 static void gtk_icon_view_size_request (GtkWidget *widget,
243 GtkRequisition *requisition);
244 static void gtk_icon_view_size_allocate (GtkWidget *widget,
245 GtkAllocation *allocation);
246 static gboolean gtk_icon_view_expose (GtkWidget *widget,
247 GdkEventExpose *expose);
248 static gboolean gtk_icon_view_motion (GtkWidget *widget,
249 GdkEventMotion *event);
250 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
251 GdkEventButton *event);
252 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
253 GdkEventButton *event);
254 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
257 /* GtkContainer vfuncs */
258 static void gtk_icon_view_remove (GtkContainer *container,
260 static void gtk_icon_view_forall (GtkContainer *container,
261 gboolean include_internals,
262 GtkCallback callback,
263 gpointer callback_data);
265 /* GtkIconView vfuncs */
266 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
268 GtkAdjustment *vadj);
269 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
270 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
271 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
272 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
273 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
275 /* Internal functions */
276 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
277 GtkIconView *icon_view);
278 static void gtk_icon_view_layout (GtkIconView *icon_view);
279 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
282 GtkIconViewItem *item,
284 GdkDrawable *drawable,
287 gboolean draw_focus);
288 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
291 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
293 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
294 GtkIconViewItem *item);
295 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
296 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
297 GtkIconViewItem *item,
299 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
302 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
303 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
304 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
305 GtkIconViewItem *item,
310 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
311 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
312 GtkIconViewItem *item);
313 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
314 GtkIconViewItem *item,
316 static void gtk_icon_view_update_rubberband (gpointer data);
317 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
318 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
319 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
322 GtkMovementStep step,
324 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
325 GtkMovementStep step,
327 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
329 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
331 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
333 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
335 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
336 GtkIconViewItem *item);
337 static void gtk_icon_view_select_item (GtkIconView *icon_view,
338 GtkIconViewItem *item);
339 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
340 GtkIconViewItem *item);
341 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
342 GtkIconViewItem *anchor,
343 GtkIconViewItem *cursor);
344 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
347 gboolean only_in_cell,
348 GtkIconViewCellInfo **cell_at_pos);
349 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
350 GtkIconViewItem *item,
351 GtkIconViewCellInfo *cell_info,
352 GdkRectangle *cell_area);
353 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
354 GtkIconViewItem *item,
355 GtkIconViewCellInfo *info,
357 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
358 GtkCellRenderer *renderer);
359 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
360 GtkIconViewItem *item);
361 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
362 GtkCellRenderer *renderer,
364 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
365 GtkCellRenderer *renderer,
367 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
368 GtkCellRenderer *renderer,
369 const gchar *attribute,
371 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
372 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
373 GtkCellRenderer *renderer);
374 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
375 GtkCellRenderer *cell,
376 GtkCellLayoutDataFunc func,
378 GDestroyNotify destroy);
379 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
380 GtkCellRenderer *cell,
382 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
383 GtkIconViewItem *item,
384 GtkIconViewCellInfo *cell_info,
386 static void gtk_icon_view_put (GtkIconView *icon_view,
388 GtkIconViewItem *item,
390 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
391 GtkIconView *icon_view);
392 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
393 GtkIconViewItem *item,
394 GtkIconViewCellInfo *cell_info,
396 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
397 gboolean cancel_editing);
399 /* Source side drag signals */
400 static void gtk_icon_view_drag_begin (GtkWidget *widget,
401 GdkDragContext *context);
402 static void gtk_icon_view_drag_end (GtkWidget *widget,
403 GdkDragContext *context);
404 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
405 GdkDragContext *context,
406 GtkSelectionData *selection_data,
409 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
410 GdkDragContext *context);
412 /* Target side drag signals */
413 static void gtk_icon_view_drag_leave (GtkWidget *widget,
414 GdkDragContext *context,
416 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
417 GdkDragContext *context,
421 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
422 GdkDragContext *context,
426 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
427 GdkDragContext *context,
430 GtkSelectionData *selection_data,
433 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
434 GdkEventMotion *event);
436 static void remove_scroll_timeout (GtkIconView *icon_view);
439 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
441 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
442 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
443 gtk_icon_view_cell_layout_init))
446 gtk_icon_view_class_init (GtkIconViewClass *klass)
448 GObjectClass *gobject_class;
449 GtkObjectClass *object_class;
450 GtkWidgetClass *widget_class;
451 GtkContainerClass *container_class;
452 GtkBindingSet *binding_set;
454 binding_set = gtk_binding_set_by_class (klass);
456 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
458 gobject_class = (GObjectClass *) klass;
459 object_class = (GtkObjectClass *) klass;
460 widget_class = (GtkWidgetClass *) klass;
461 container_class = (GtkContainerClass *) klass;
463 gobject_class->finalize = gtk_icon_view_finalize;
464 gobject_class->set_property = gtk_icon_view_set_property;
465 gobject_class->get_property = gtk_icon_view_get_property;
467 object_class->destroy = gtk_icon_view_destroy;
469 widget_class->realize = gtk_icon_view_realize;
470 widget_class->unrealize = gtk_icon_view_unrealize;
471 widget_class->size_request = gtk_icon_view_size_request;
472 widget_class->size_allocate = gtk_icon_view_size_allocate;
473 widget_class->expose_event = gtk_icon_view_expose;
474 widget_class->motion_notify_event = gtk_icon_view_motion;
475 widget_class->button_press_event = gtk_icon_view_button_press;
476 widget_class->button_release_event = gtk_icon_view_button_release;
477 widget_class->drag_begin = gtk_icon_view_drag_begin;
478 widget_class->drag_end = gtk_icon_view_drag_end;
479 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
480 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
481 widget_class->drag_leave = gtk_icon_view_drag_leave;
482 widget_class->drag_motion = gtk_icon_view_drag_motion;
483 widget_class->drag_drop = gtk_icon_view_drag_drop;
484 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
485 widget_class->get_accessible = gtk_icon_view_get_accessible;
487 container_class->remove = gtk_icon_view_remove;
488 container_class->forall = gtk_icon_view_forall;
490 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
491 klass->select_all = gtk_icon_view_real_select_all;
492 klass->unselect_all = gtk_icon_view_real_unselect_all;
493 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
494 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
495 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
496 klass->move_cursor = gtk_icon_view_real_move_cursor;
500 * GtkIconView:selection-mode:
502 * The ::selection-mode property specifies the selection mode of
503 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
504 * is enabled, for the other modes, only keyboard selection is possible.
508 g_object_class_install_property (gobject_class,
510 g_param_spec_enum ("selection-mode",
511 P_("Selection mode"),
512 P_("The selection mode"),
513 GTK_TYPE_SELECTION_MODE,
514 GTK_SELECTION_SINGLE,
515 GTK_PARAM_READWRITE));
518 * GtkIconView:pixbuf-column:
520 * The ::pixbuf-column property contains the number of the model column
521 * containing the pixbufs which are displayed. The pixbuf column must be
522 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
523 * display of pixbufs.
527 g_object_class_install_property (gobject_class,
529 g_param_spec_int ("pixbuf-column",
531 P_("Model column used to retrieve the icon pixbuf from"),
533 GTK_PARAM_READWRITE));
536 * GtkIconView:text-column:
538 * The ::text-column property contains the number of the model column
539 * containing the texts which are displayed. The text column must be
540 * of type #G_TYPE_STRING. If this property and the :markup-column
541 * property are both set to -1, no texts are displayed.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_int ("text-column",
549 P_("Model column used to retrieve the text from"),
551 GTK_PARAM_READWRITE));
555 * GtkIconView:markup-column:
557 * The ::markup-column property contains the number of the model column
558 * containing markup information to be displayed. The markup column must be
559 * of type #G_TYPE_STRING. If this property and the :text-column property
560 * are both set to column numbers, it overrides the text column.
561 * If both are set to -1, no texts are displayed.
565 g_object_class_install_property (gobject_class,
567 g_param_spec_int ("markup-column",
569 P_("Model column used to retrieve the text if using Pango markup"),
571 GTK_PARAM_READWRITE));
573 g_object_class_install_property (gobject_class,
575 g_param_spec_object ("model",
576 P_("Icon View Model"),
577 P_("The model for the icon view"),
579 GTK_PARAM_READWRITE));
582 * GtkIconView:columns:
584 * The columns property contains the number of the columns in which the
585 * items should be displayed. If it is -1, the number of columns will
586 * be chosen automatically to fill the available area.
590 g_object_class_install_property (gobject_class,
592 g_param_spec_int ("columns",
593 P_("Number of columns"),
594 P_("Number of columns to display"),
596 GTK_PARAM_READWRITE));
600 * GtkIconView::item-width:
602 * The item-width property specifies the width to use for each item.
603 * If it is set to -1, the icon view will automatically determine a
604 * suitable item size.
608 g_object_class_install_property (gobject_class,
610 g_param_spec_int ("item-width",
611 P_("Width for each item"),
612 P_("The width used for each item"),
614 GTK_PARAM_READWRITE));
617 * GtkIconView::spacing:
619 * The spacing property specifies the space which is inserted between
620 * the cells (i.e. the icon and the text) of an item.
624 g_object_class_install_property (gobject_class,
626 g_param_spec_int ("spacing",
628 P_("Space which is inserted between cells of an item"),
630 GTK_PARAM_READWRITE));
633 * GtkIconView::row-spacing:
635 * The row-spacing property specifies the space which is inserted between
636 * the rows of the icon view.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("row-spacing",
644 P_("Space which is inserted between grid rows"),
646 GTK_PARAM_READWRITE));
649 * GtkIconView::column-spacing:
651 * The column-spacing property specifies the space which is inserted between
652 * the columns of the icon view.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("column-spacing",
659 P_("Column Spacing"),
660 P_("Space which is inserted between grid columns"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView::margin:
667 * The margin property specifies the space which is inserted
668 * at the edges of the icon view.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("margin",
676 P_("Space which is inserted at the edges of the icon view"),
678 GTK_PARAM_READWRITE));
682 * GtkIconView::orientation:
684 * The orientation property specifies how the cells (i.e. the icon and
685 * the text) of the item are positioned relative to each other.
689 g_object_class_install_property (gobject_class,
691 g_param_spec_enum ("orientation",
693 P_("How the text and icon of each item are positioned relative to each other"),
694 GTK_TYPE_ORIENTATION,
695 GTK_ORIENTATION_VERTICAL,
696 GTK_PARAM_READWRITE));
699 * GtkIconView:reorderable:
701 * The reorderable property specifies if the items can be reordered
706 g_object_class_install_property (gobject_class,
708 g_param_spec_boolean ("reorderable",
710 P_("View is reorderable"),
714 /* Style properties */
715 gtk_widget_class_install_style_property (widget_class,
716 g_param_spec_boxed ("selection-box-color",
717 P_("Selection Box Color"),
718 P_("Color of the selection box"),
720 GTK_PARAM_READABLE));
722 gtk_widget_class_install_style_property (widget_class,
723 g_param_spec_uchar ("selection-box-alpha",
724 P_("Selection Box Alpha"),
725 P_("Opacity of the selection box"),
728 GTK_PARAM_READABLE));
731 widget_class->set_scroll_adjustments_signal =
732 g_signal_new (I_("set_scroll_adjustments"),
733 G_TYPE_FROM_CLASS (gobject_class),
735 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
737 _gtk_marshal_VOID__OBJECT_OBJECT,
739 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
741 icon_view_signals[ITEM_ACTIVATED] =
742 g_signal_new (I_("item_activated"),
743 G_TYPE_FROM_CLASS (gobject_class),
745 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
747 g_cclosure_marshal_VOID__BOXED,
751 icon_view_signals[SELECTION_CHANGED] =
752 g_signal_new (I_("selection_changed"),
753 G_TYPE_FROM_CLASS (gobject_class),
755 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
757 g_cclosure_marshal_VOID__VOID,
760 icon_view_signals[SELECT_ALL] =
761 g_signal_new (I_("select_all"),
762 G_TYPE_FROM_CLASS (gobject_class),
763 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
764 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
766 g_cclosure_marshal_VOID__VOID,
769 icon_view_signals[UNSELECT_ALL] =
770 g_signal_new (I_("unselect_all"),
771 G_TYPE_FROM_CLASS (gobject_class),
772 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
773 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
775 g_cclosure_marshal_VOID__VOID,
778 icon_view_signals[SELECT_CURSOR_ITEM] =
779 g_signal_new (I_("select_cursor_item"),
780 G_TYPE_FROM_CLASS (gobject_class),
781 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
784 g_cclosure_marshal_VOID__VOID,
787 icon_view_signals[TOGGLE_CURSOR_ITEM] =
788 g_signal_new (I_("toggle_cursor_item"),
789 G_TYPE_FROM_CLASS (gobject_class),
790 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
791 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
793 g_cclosure_marshal_VOID__VOID,
796 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
797 g_signal_new (I_("activate_cursor_item"),
798 G_TYPE_FROM_CLASS (gobject_class),
799 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
800 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
802 _gtk_marshal_BOOLEAN__VOID,
805 icon_view_signals[MOVE_CURSOR] =
806 g_signal_new (I_("move_cursor"),
807 G_TYPE_FROM_CLASS (gobject_class),
808 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
809 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
811 _gtk_marshal_BOOLEAN__ENUM_INT,
813 GTK_TYPE_MOVEMENT_STEP,
817 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
819 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
821 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
822 "toggle_cursor_item", 0);
824 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
825 "activate_cursor_item", 0);
826 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
827 "activate_cursor_item", 0);
828 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
829 "activate_cursor_item", 0);
830 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
831 "activate_cursor_item", 0);
833 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
834 GTK_MOVEMENT_DISPLAY_LINES, -1);
835 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
836 GTK_MOVEMENT_DISPLAY_LINES, -1);
838 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
839 GTK_MOVEMENT_DISPLAY_LINES, 1);
840 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
841 GTK_MOVEMENT_DISPLAY_LINES, 1);
843 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
844 GTK_MOVEMENT_DISPLAY_LINES, -1);
846 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
847 GTK_MOVEMENT_DISPLAY_LINES, 1);
849 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
850 GTK_MOVEMENT_BUFFER_ENDS, -1);
851 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
852 GTK_MOVEMENT_BUFFER_ENDS, -1);
854 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
855 GTK_MOVEMENT_BUFFER_ENDS, 1);
856 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
857 GTK_MOVEMENT_BUFFER_ENDS, 1);
859 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
860 GTK_MOVEMENT_PAGES, -1);
861 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
862 GTK_MOVEMENT_PAGES, -1);
864 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
865 GTK_MOVEMENT_PAGES, 1);
866 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
867 GTK_MOVEMENT_PAGES, 1);
869 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
870 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
871 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
872 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
874 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
875 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
876 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
877 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
881 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
883 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
884 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
885 iface->clear = gtk_icon_view_cell_layout_clear;
886 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
887 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
888 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
889 iface->reorder = gtk_icon_view_cell_layout_reorder;
893 gtk_icon_view_init (GtkIconView *icon_view)
895 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
897 icon_view->priv->width = 0;
898 icon_view->priv->height = 0;
899 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
900 icon_view->priv->pressed_button = -1;
901 icon_view->priv->press_start_x = -1;
902 icon_view->priv->press_start_y = -1;
903 icon_view->priv->text_column = -1;
904 icon_view->priv->markup_column = -1;
905 icon_view->priv->pixbuf_column = -1;
906 icon_view->priv->text_cell = -1;
907 icon_view->priv->pixbuf_cell = -1;
909 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
911 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
913 icon_view->priv->cell_list = NULL;
914 icon_view->priv->n_cells = 0;
915 icon_view->priv->cursor_cell = -1;
917 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
919 icon_view->priv->columns = -1;
920 icon_view->priv->item_width = -1;
921 icon_view->priv->spacing = 0;
922 icon_view->priv->row_spacing = 6;
923 icon_view->priv->column_spacing = 6;
924 icon_view->priv->margin = 6;
928 gtk_icon_view_destroy (GtkObject *object)
930 GtkIconView *icon_view;
932 icon_view = GTK_ICON_VIEW (object);
934 gtk_icon_view_stop_editing (icon_view, TRUE);
936 gtk_icon_view_set_model (icon_view, NULL);
938 if (icon_view->priv->layout_idle_id != 0)
940 g_source_remove (icon_view->priv->layout_idle_id);
941 icon_view->priv->layout_idle_id = 0;
944 if (icon_view->priv->scroll_to_path != NULL)
946 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
947 icon_view->priv->scroll_to_path = NULL;
950 remove_scroll_timeout (icon_view);
952 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
955 /* GObject methods */
957 gtk_icon_view_finalize (GObject *object)
959 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
961 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
966 gtk_icon_view_set_property (GObject *object,
971 GtkIconView *icon_view;
973 icon_view = GTK_ICON_VIEW (object);
977 case PROP_SELECTION_MODE:
978 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
980 case PROP_PIXBUF_COLUMN:
981 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
983 case PROP_TEXT_COLUMN:
984 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
986 case PROP_MARKUP_COLUMN:
987 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
990 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
992 case PROP_ORIENTATION:
993 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
996 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
998 case PROP_ITEM_WIDTH:
999 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1002 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1004 case PROP_ROW_SPACING:
1005 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1007 case PROP_COLUMN_SPACING:
1008 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1011 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1013 case PROP_REORDERABLE:
1014 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1018 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1024 gtk_icon_view_get_property (GObject *object,
1029 GtkIconView *icon_view;
1031 icon_view = GTK_ICON_VIEW (object);
1035 case PROP_SELECTION_MODE:
1036 g_value_set_enum (value, icon_view->priv->selection_mode);
1038 case PROP_PIXBUF_COLUMN:
1039 g_value_set_int (value, icon_view->priv->pixbuf_column);
1041 case PROP_TEXT_COLUMN:
1042 g_value_set_int (value, icon_view->priv->text_column);
1044 case PROP_MARKUP_COLUMN:
1045 g_value_set_int (value, icon_view->priv->markup_column);
1048 g_value_set_object (value, icon_view->priv->model);
1050 case PROP_ORIENTATION:
1051 g_value_set_enum (value, icon_view->priv->orientation);
1054 g_value_set_int (value, icon_view->priv->columns);
1056 case PROP_ITEM_WIDTH:
1057 g_value_set_int (value, icon_view->priv->item_width);
1060 g_value_set_int (value, icon_view->priv->spacing);
1062 case PROP_ROW_SPACING:
1063 g_value_set_int (value, icon_view->priv->row_spacing);
1065 case PROP_COLUMN_SPACING:
1066 g_value_set_int (value, icon_view->priv->column_spacing);
1069 g_value_set_int (value, icon_view->priv->margin);
1071 case PROP_REORDERABLE:
1072 g_value_set_boolean (value, icon_view->priv->reorderable);
1076 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1081 /* GtkWidget signals */
1083 gtk_icon_view_realize (GtkWidget *widget)
1085 GtkIconView *icon_view;
1086 GdkWindowAttr attributes;
1087 gint attributes_mask;
1089 icon_view = GTK_ICON_VIEW (widget);
1091 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1093 /* Make the main, clipping window */
1094 attributes.window_type = GDK_WINDOW_CHILD;
1095 attributes.x = widget->allocation.x;
1096 attributes.y = widget->allocation.y;
1097 attributes.width = widget->allocation.width;
1098 attributes.height = widget->allocation.height;
1099 attributes.wclass = GDK_INPUT_OUTPUT;
1100 attributes.visual = gtk_widget_get_visual (widget);
1101 attributes.colormap = gtk_widget_get_colormap (widget);
1102 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1104 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1106 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1107 &attributes, attributes_mask);
1108 gdk_window_set_user_data (widget->window, widget);
1110 /* Make the window for the icon view */
1113 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1114 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1115 attributes.event_mask = (GDK_EXPOSURE_MASK |
1117 GDK_POINTER_MOTION_MASK |
1118 GDK_BUTTON_PRESS_MASK |
1119 GDK_BUTTON_RELEASE_MASK |
1120 GDK_KEY_PRESS_MASK |
1121 GDK_KEY_RELEASE_MASK) |
1122 gtk_widget_get_events (widget);
1124 icon_view->priv->bin_window = gdk_window_new (widget->window,
1125 &attributes, attributes_mask);
1126 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1128 widget->style = gtk_style_attach (widget->style, widget->window);
1129 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1130 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1132 gdk_window_show (icon_view->priv->bin_window);
1136 gtk_icon_view_unrealize (GtkWidget *widget)
1138 GtkIconView *icon_view;
1140 icon_view = GTK_ICON_VIEW (widget);
1142 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1143 gdk_window_destroy (icon_view->priv->bin_window);
1144 icon_view->priv->bin_window = NULL;
1146 /* GtkWidget::unrealize destroys children and widget->window */
1147 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1148 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1152 gtk_icon_view_size_request (GtkWidget *widget,
1153 GtkRequisition *requisition)
1155 GtkIconView *icon_view;
1158 icon_view = GTK_ICON_VIEW (widget);
1160 requisition->width = icon_view->priv->width;
1161 requisition->height = icon_view->priv->height;
1163 tmp_list = icon_view->priv->children;
1167 GtkIconViewChild *child = tmp_list->data;
1168 GtkRequisition child_requisition;
1170 tmp_list = tmp_list->next;
1172 if (GTK_WIDGET_VISIBLE (child->widget))
1173 gtk_widget_size_request (child->widget, &child_requisition);
1178 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1182 for (list = icon_view->priv->children; list; list = list->next)
1184 GtkIconViewChild *child = list->data;
1185 GtkAllocation allocation;
1187 /* totally ignore our child's requisition */
1188 if (child->cell < 0)
1190 allocation.x = child->item->x;
1191 allocation.y = child->item->y;
1192 allocation.width = child->item->width;
1193 allocation.height = child->item->height;
1197 GdkRectangle *box = &child->item->box[child->cell];
1199 allocation.x = box->x;
1200 allocation.y = box->y;
1201 allocation.width = box->width;
1202 allocation.height = box->height;
1205 gtk_widget_size_allocate (child->widget, &allocation);
1210 gtk_icon_view_size_allocate (GtkWidget *widget,
1211 GtkAllocation *allocation)
1213 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1215 GtkAdjustment *hadjustment, *vadjustment;
1217 widget->allocation = *allocation;
1219 if (GTK_WIDGET_REALIZED (widget))
1221 gdk_window_move_resize (widget->window,
1222 allocation->x, allocation->y,
1223 allocation->width, allocation->height);
1224 gdk_window_resize (icon_view->priv->bin_window,
1225 MAX (icon_view->priv->width, allocation->width),
1226 MAX (icon_view->priv->height, allocation->height));
1229 gtk_icon_view_layout (icon_view);
1231 gtk_icon_view_allocate_children (icon_view);
1233 hadjustment = icon_view->priv->hadjustment;
1234 vadjustment = icon_view->priv->vadjustment;
1236 hadjustment->page_size = allocation->width;
1237 hadjustment->page_increment = allocation->width * 0.9;
1238 hadjustment->step_increment = allocation->width * 0.1;
1239 hadjustment->lower = 0;
1240 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1242 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1243 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1245 vadjustment->page_size = allocation->height;
1246 vadjustment->page_increment = allocation->height * 0.9;
1247 vadjustment->step_increment = allocation->height * 0.1;
1248 vadjustment->lower = 0;
1249 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1251 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1252 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1254 if (GTK_WIDGET_REALIZED (widget) &&
1255 icon_view->priv->scroll_to_path)
1258 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1259 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1260 icon_view->priv->scroll_to_path = NULL;
1262 gtk_icon_view_scroll_to_path (icon_view, path,
1263 icon_view->priv->scroll_to_use_align,
1264 icon_view->priv->scroll_to_row_align,
1265 icon_view->priv->scroll_to_col_align);
1266 gtk_tree_path_free (path);
1270 gtk_adjustment_changed (hadjustment);
1271 gtk_adjustment_changed (vadjustment);
1276 gtk_icon_view_expose (GtkWidget *widget,
1277 GdkEventExpose *expose)
1279 GtkIconView *icon_view;
1284 GtkIconViewDropPosition dest_pos;
1285 GtkIconViewItem *dest_item = NULL;
1287 icon_view = GTK_ICON_VIEW (widget);
1289 if (expose->window != icon_view->priv->bin_window)
1292 cr = gdk_cairo_create (icon_view->priv->bin_window);
1293 cairo_set_line_width (cr, 1.);
1295 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1299 dest_index = gtk_tree_path_get_indices (path)[0];
1300 gtk_tree_path_free (path);
1305 for (icons = icon_view->priv->items; icons; icons = icons->next)
1307 GtkIconViewItem *item = icons->data;
1312 area.width = item->width;
1313 area.height = item->height;
1315 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1318 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1319 icon_view->priv->bin_window,
1320 item->x, item->y, TRUE);
1322 if (dest_index == item->index)
1330 case GTK_ICON_VIEW_DROP_INTO:
1331 gtk_paint_focus (widget->style,
1332 icon_view->priv->bin_window,
1333 GTK_WIDGET_STATE (widget),
1336 "iconview-drop-indicator",
1337 dest_item->x, dest_item->y,
1338 dest_item->width, dest_item->height);
1340 case GTK_ICON_VIEW_DROP_ABOVE:
1341 gtk_paint_focus (widget->style,
1342 icon_view->priv->bin_window,
1343 GTK_WIDGET_STATE (widget),
1346 "iconview-drop-indicator",
1347 dest_item->x, dest_item->y - 1,
1348 dest_item->width, 2);
1350 case GTK_ICON_VIEW_DROP_LEFT:
1351 gtk_paint_focus (widget->style,
1352 icon_view->priv->bin_window,
1353 GTK_WIDGET_STATE (widget),
1356 "iconview-drop-indicator",
1357 dest_item->x - 1, dest_item->y,
1358 2, dest_item->height);
1360 case GTK_ICON_VIEW_DROP_BELOW:
1361 gtk_paint_focus (widget->style,
1362 icon_view->priv->bin_window,
1363 GTK_WIDGET_STATE (widget),
1366 "iconview-drop-indicator",
1367 dest_item->x, dest_item->y + dest_item->height - 1,
1368 dest_item->width, 2);
1370 case GTK_ICON_VIEW_DROP_RIGHT:
1371 gtk_paint_focus (widget->style,
1372 icon_view->priv->bin_window,
1373 GTK_WIDGET_STATE (widget),
1376 "iconview-drop-indicator",
1377 dest_item->x + dest_item->width - 1, dest_item->y,
1378 2, dest_item->height);
1379 case GTK_ICON_VIEW_NO_DROP: ;
1384 if (icon_view->priv->doing_rubberband)
1386 GdkRectangle *rectangles;
1389 gdk_region_get_rectangles (expose->region,
1393 while (n_rectangles--)
1394 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1396 g_free (rectangles);
1401 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1407 rubberband_scroll_timeout (gpointer data)
1409 GtkIconView *icon_view;
1412 GDK_THREADS_ENTER ();
1416 value = MIN (icon_view->priv->vadjustment->value +
1417 icon_view->priv->scroll_value_diff,
1418 icon_view->priv->vadjustment->upper -
1419 icon_view->priv->vadjustment->page_size);
1421 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1423 gtk_icon_view_update_rubberband (icon_view);
1425 GDK_THREADS_LEAVE ();
1431 gtk_icon_view_motion (GtkWidget *widget,
1432 GdkEventMotion *event)
1434 GtkIconView *icon_view;
1437 icon_view = GTK_ICON_VIEW (widget);
1439 gtk_icon_view_maybe_begin_drag (icon_view, event);
1441 if (icon_view->priv->doing_rubberband)
1443 gtk_icon_view_update_rubberband (widget);
1445 abs_y = event->y - icon_view->priv->height *
1446 (icon_view->priv->vadjustment->value /
1447 (icon_view->priv->vadjustment->upper -
1448 icon_view->priv->vadjustment->lower));
1450 if (abs_y < 0 || abs_y > widget->allocation.height)
1453 icon_view->priv->scroll_value_diff = abs_y;
1455 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1457 icon_view->priv->event_last_x = event->x;
1458 icon_view->priv->event_last_y = event->y;
1460 if (icon_view->priv->scroll_timeout_id == 0)
1461 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1465 remove_scroll_timeout (icon_view);
1472 gtk_icon_view_remove (GtkContainer *container,
1475 GtkIconView *icon_view;
1476 GtkIconViewChild *child = NULL;
1479 icon_view = GTK_ICON_VIEW (container);
1481 tmp_list = icon_view->priv->children;
1484 child = tmp_list->data;
1485 if (child->widget == widget)
1487 gtk_widget_unparent (widget);
1489 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1490 g_list_free_1 (tmp_list);
1495 tmp_list = tmp_list->next;
1500 gtk_icon_view_forall (GtkContainer *container,
1501 gboolean include_internals,
1502 GtkCallback callback,
1503 gpointer callback_data)
1505 GtkIconView *icon_view;
1506 GtkIconViewChild *child = NULL;
1509 icon_view = GTK_ICON_VIEW (container);
1511 tmp_list = icon_view->priv->children;
1514 child = tmp_list->data;
1515 tmp_list = tmp_list->next;
1517 (* callback) (child->widget, callback_data);
1522 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1523 GtkIconViewItem *item,
1524 GtkIconViewCellInfo *info,
1529 GdkRectangle cell_area;
1530 gboolean visible, mode;
1532 gtk_icon_view_set_cell_data (icon_view, item);
1534 g_object_get (info->cell,
1535 "visible", &visible,
1539 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1541 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1543 path = gtk_tree_path_new_from_indices (item->index, -1);
1544 path_string = gtk_tree_path_to_string (path);
1545 gtk_tree_path_free (path);
1547 gtk_cell_renderer_activate (info->cell,
1549 GTK_WIDGET (icon_view),
1555 g_free (path_string);
1560 gtk_icon_view_put (GtkIconView *icon_view,
1562 GtkIconViewItem *item,
1565 GtkIconViewChild *child;
1567 child = g_new (GtkIconViewChild, 1);
1569 child->widget = widget;
1573 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1575 if (GTK_WIDGET_REALIZED (icon_view))
1576 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1578 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1582 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1583 GtkIconView *icon_view)
1586 GtkIconViewItem *item;
1588 if (icon_view->priv->edited_item == NULL)
1591 item = icon_view->priv->edited_item;
1592 icon_view->priv->edited_item = NULL;
1593 icon_view->priv->editable = NULL;
1594 for (l = icon_view->priv->cell_list; l; l = l->next)
1596 GtkIconViewCellInfo *info = l->data;
1598 info->editing = FALSE;
1601 if (GTK_WIDGET_HAS_FOCUS (editable))
1602 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1604 g_signal_handlers_disconnect_by_func (editable,
1605 gtk_icon_view_remove_widget,
1608 gtk_container_remove (GTK_CONTAINER (icon_view),
1609 GTK_WIDGET (editable));
1611 gtk_icon_view_queue_draw_item (icon_view, item);
1616 gtk_icon_view_start_editing (GtkIconView *icon_view,
1617 GtkIconViewItem *item,
1618 GtkIconViewCellInfo *info,
1623 GdkRectangle cell_area;
1624 gboolean visible, mode;
1625 GtkCellEditable *editable;
1627 gtk_icon_view_set_cell_data (icon_view, item);
1629 g_object_get (info->cell,
1630 "visible", &visible,
1633 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1635 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1637 path = gtk_tree_path_new_from_indices (item->index, -1);
1638 path_string = gtk_tree_path_to_string (path);
1639 gtk_tree_path_free (path);
1641 editable = gtk_cell_renderer_start_editing (info->cell,
1643 GTK_WIDGET (icon_view),
1648 g_free (path_string);
1650 /* FIXME ugly special case */
1651 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1652 g_object_set (editable, "has_frame", TRUE, NULL);
1654 /* the rest corresponds to tree_view_real_start_editing... */
1655 icon_view->priv->edited_item = item;
1656 icon_view->priv->editable = editable;
1657 info->editing = TRUE;
1659 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1661 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1663 gtk_widget_grab_focus (GTK_WIDGET (editable));
1664 g_signal_connect (editable, "remove_widget",
1665 G_CALLBACK (gtk_icon_view_remove_widget),
1672 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1673 gboolean cancel_editing)
1675 GtkCellRenderer *cell = NULL;
1676 GtkIconViewItem *item;
1679 if (icon_view->priv->edited_item == NULL)
1683 * This is very evil. We need to do this, because
1684 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1685 * later on. If gtk_icon_view_row_changed notices
1686 * icon_view->priv->edited_item != NULL, it'll call
1687 * gtk_icon_view_stop_editing again. Bad things will happen then.
1689 * Please read that again if you intend to modify anything here.
1692 item = icon_view->priv->edited_item;
1693 icon_view->priv->edited_item = NULL;
1695 for (l = icon_view->priv->cell_list; l; l = l->next)
1697 GtkIconViewCellInfo *info = l->data;
1709 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1710 if (!cancel_editing)
1711 gtk_cell_editable_editing_done (icon_view->priv->editable);
1713 icon_view->priv->edited_item = item;
1715 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1719 * gtk_icon_view_set_cursor:
1720 * @icon_view: A #GtkIconView
1721 * @path: A #GtkTreePath
1722 * @cell: One of the cell renderers of @icon_view, or %NULL
1723 * @start_editing: %TRUE if the specified cell should start being edited.
1725 * Sets the current keyboard focus to be at @path, and selects it. This is
1726 * useful when you want to focus the user's attention on a particular item.
1727 * If @cell is not %NULL, then focus is given to the cell specified by
1728 * it. Additionally, if @start_editing is %TRUE, then editing should be
1729 * started in the specified cell.
1731 * This function is often followed by <literal>gtk_widget_grab_focus
1732 * (icon_view)</literal> in order to give keyboard focus to the widget.
1733 * Please note that editing can only happen when the widget is realized.
1738 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1740 GtkCellRenderer *cell,
1741 gboolean start_editing)
1743 GtkIconViewItem *item = NULL;
1744 GtkIconViewCellInfo *info = NULL;
1748 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1749 g_return_if_fail (path != NULL);
1750 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1752 gtk_icon_view_stop_editing (icon_view, TRUE);
1754 if (gtk_tree_path_get_depth (path) == 1)
1755 item = g_list_nth_data (icon_view->priv->items,
1756 gtk_tree_path_get_indices(path)[0]);
1762 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1766 if (info->cell == cell)
1775 g_return_if_fail (cell == NULL || info != NULL);
1777 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1778 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1780 if (info && start_editing)
1781 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1785 * gtk_icon_view_get_cursor:
1786 * @icon_view: A #GtkIconView
1787 * @path: Return location for the current cursor path, or %NULL
1788 * @cell: Return location the current focus cell, or %NULL
1790 * Fills in @path and @cell with the current cursor path and cell.
1791 * If the cursor isn't currently set, then *@path will be %NULL.
1792 * If no cell currently has focus, then *@cell will be %NULL.
1794 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1796 * Return value: %TRUE if the cursor is set.
1801 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1803 GtkCellRenderer **cell)
1805 GtkIconViewItem *item;
1806 GtkIconViewCellInfo *info;
1808 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1810 item = icon_view->priv->cursor_item;
1811 if (icon_view->priv->cursor_cell < 0)
1814 info = g_list_nth_data (icon_view->priv->cell_list,
1815 icon_view->priv->cursor_cell);
1820 *path = gtk_tree_path_new_from_indices (item->index, -1);
1833 return (item != NULL);
1837 gtk_icon_view_button_press (GtkWidget *widget,
1838 GdkEventButton *event)
1840 GtkIconView *icon_view;
1841 GtkIconViewItem *item;
1842 GtkIconViewCellInfo *info = NULL;
1843 gboolean dirty = FALSE;
1844 GtkCellRendererMode mode;
1847 icon_view = GTK_ICON_VIEW (widget);
1849 if (event->window != icon_view->priv->bin_window)
1852 if (!GTK_WIDGET_HAS_FOCUS (widget))
1853 gtk_widget_grab_focus (widget);
1855 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1857 item = gtk_icon_view_get_item_at_coords (icon_view,
1863 g_object_get (info->cell, "mode", &mode, NULL);
1865 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1866 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1867 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1871 gtk_icon_view_scroll_to_item (icon_view, item);
1873 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1875 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1877 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1878 (event->state & GDK_SHIFT_MASK))
1880 gtk_icon_view_unselect_all_internal (icon_view);
1882 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1883 if (!icon_view->priv->anchor_item)
1884 icon_view->priv->anchor_item = item;
1886 gtk_icon_view_select_all_between (icon_view,
1887 icon_view->priv->anchor_item,
1893 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1894 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1895 (event->state & GDK_CONTROL_MASK))
1897 item->selected = !item->selected;
1898 gtk_icon_view_queue_draw_item (icon_view, item);
1903 if (!item->selected)
1905 gtk_icon_view_unselect_all_internal (icon_view);
1907 item->selected = TRUE;
1908 gtk_icon_view_queue_draw_item (icon_view, item);
1912 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1913 icon_view->priv->anchor_item = item;
1916 /* Save press to possibly begin a drag */
1917 if (icon_view->priv->pressed_button < 0)
1919 icon_view->priv->pressed_button = event->button;
1920 icon_view->priv->press_start_x = event->x;
1921 icon_view->priv->press_start_y = event->y;
1924 if (!icon_view->priv->last_single_clicked)
1925 icon_view->priv->last_single_clicked = item;
1927 /* cancel the current editing, if it exists */
1928 gtk_icon_view_stop_editing (icon_view, TRUE);
1930 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1931 gtk_icon_view_item_activate_cell (icon_view, item, info,
1933 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1934 gtk_icon_view_start_editing (icon_view, item, info,
1939 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1940 !(event->state & GDK_CONTROL_MASK))
1942 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1945 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1946 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
1951 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1953 item = gtk_icon_view_get_item_at_coords (icon_view,
1958 if (item && item == icon_view->priv->last_single_clicked)
1962 path = gtk_tree_path_new_from_indices (item->index, -1);
1963 gtk_icon_view_item_activated (icon_view, path);
1964 gtk_tree_path_free (path);
1967 icon_view->priv->last_single_clicked = NULL;
1968 icon_view->priv->pressed_button = -1;
1972 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1974 return event->button == 1;
1978 gtk_icon_view_button_release (GtkWidget *widget,
1979 GdkEventButton *event)
1981 GtkIconView *icon_view;
1983 icon_view = GTK_ICON_VIEW (widget);
1985 if (icon_view->priv->pressed_button == event->button)
1986 icon_view->priv->pressed_button = -1;
1988 gtk_icon_view_stop_rubberbanding (icon_view);
1990 remove_scroll_timeout (icon_view);
1996 gtk_icon_view_update_rubberband (gpointer data)
1998 GtkIconView *icon_view;
2000 GdkRectangle old_area;
2001 GdkRectangle new_area;
2002 GdkRectangle common;
2003 GdkRegion *invalid_region;
2005 icon_view = GTK_ICON_VIEW (data);
2007 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2012 old_area.x = MIN (icon_view->priv->rubberband_x1,
2013 icon_view->priv->rubberband_x2);
2014 old_area.y = MIN (icon_view->priv->rubberband_y1,
2015 icon_view->priv->rubberband_y2);
2016 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2017 icon_view->priv->rubberband_x1) + 1;
2018 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2019 icon_view->priv->rubberband_y1) + 1;
2021 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2022 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2023 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2024 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2026 invalid_region = gdk_region_rectangle (&old_area);
2027 gdk_region_union_with_rect (invalid_region, &new_area);
2029 gdk_rectangle_intersect (&old_area, &new_area, &common);
2030 if (common.width > 2 && common.height > 2)
2032 GdkRegion *common_region;
2034 /* make sure the border is invalidated */
2040 common_region = gdk_region_rectangle (&common);
2042 gdk_region_subtract (invalid_region, common_region);
2043 gdk_region_destroy (common_region);
2046 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2048 gdk_region_destroy (invalid_region);
2050 icon_view->priv->rubberband_x2 = x;
2051 icon_view->priv->rubberband_y2 = y;
2053 gtk_icon_view_update_rubberband_selection (icon_view);
2057 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2063 g_assert (!icon_view->priv->doing_rubberband);
2065 for (items = icon_view->priv->items; items; items = items->next)
2067 GtkIconViewItem *item = items->data;
2069 item->selected_before_rubberbanding = item->selected;
2072 icon_view->priv->rubberband_x1 = x;
2073 icon_view->priv->rubberband_y1 = y;
2074 icon_view->priv->rubberband_x2 = x;
2075 icon_view->priv->rubberband_y2 = y;
2077 icon_view->priv->doing_rubberband = TRUE;
2079 gtk_grab_add (GTK_WIDGET (icon_view));
2083 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2085 if (!icon_view->priv->doing_rubberband)
2088 icon_view->priv->doing_rubberband = FALSE;
2090 gtk_grab_remove (GTK_WIDGET (icon_view));
2092 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2096 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2099 gint x, y, width, height;
2100 gboolean dirty = FALSE;
2102 x = MIN (icon_view->priv->rubberband_x1,
2103 icon_view->priv->rubberband_x2);
2104 y = MIN (icon_view->priv->rubberband_y1,
2105 icon_view->priv->rubberband_y2);
2106 width = ABS (icon_view->priv->rubberband_x1 -
2107 icon_view->priv->rubberband_x2);
2108 height = ABS (icon_view->priv->rubberband_y1 -
2109 icon_view->priv->rubberband_y2);
2111 for (items = icon_view->priv->items; items; items = items->next)
2113 GtkIconViewItem *item = items->data;
2117 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2118 x, y, width, height);
2120 selected = is_in ^ item->selected_before_rubberbanding;
2122 if (item->selected != selected)
2124 item->selected = selected;
2126 gtk_icon_view_queue_draw_item (icon_view, item);
2131 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2135 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2136 GtkIconViewItem *item,
2145 for (l = icon_view->priv->cell_list; l; l = l->next)
2147 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2149 if (!info->cell->visible)
2152 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2154 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2155 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2163 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2165 gboolean dirty = FALSE;
2168 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2171 for (items = icon_view->priv->items; items; items = items->next)
2173 GtkIconViewItem *item = items->data;
2177 item->selected = FALSE;
2179 gtk_icon_view_queue_draw_item (icon_view, item);
2187 /* GtkIconView signals */
2189 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2190 GtkAdjustment *hadj,
2191 GtkAdjustment *vadj)
2193 gboolean need_adjust = FALSE;
2196 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2198 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2200 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2202 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2204 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2206 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2207 0, 0, NULL, NULL, icon_view);
2208 g_object_unref (icon_view->priv->hadjustment);
2211 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2213 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2214 0, 0, NULL, NULL, icon_view);
2215 g_object_unref (icon_view->priv->vadjustment);
2218 if (icon_view->priv->hadjustment != hadj)
2220 icon_view->priv->hadjustment = hadj;
2221 g_object_ref_sink (icon_view->priv->hadjustment);
2223 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2224 G_CALLBACK (gtk_icon_view_adjustment_changed),
2229 if (icon_view->priv->vadjustment != vadj)
2231 icon_view->priv->vadjustment = vadj;
2232 g_object_ref_sink (icon_view->priv->vadjustment);
2234 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2235 G_CALLBACK (gtk_icon_view_adjustment_changed),
2241 gtk_icon_view_adjustment_changed (NULL, icon_view);
2245 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2247 gtk_icon_view_select_all (icon_view);
2251 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2253 gtk_icon_view_unselect_all (icon_view);
2257 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2259 gtk_icon_view_unselect_all (icon_view);
2261 if (icon_view->priv->cursor_item != NULL)
2262 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2266 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2269 GtkCellRendererMode mode;
2270 GtkIconViewCellInfo *info = NULL;
2272 if (!icon_view->priv->cursor_item)
2275 info = g_list_nth_data (icon_view->priv->cell_list,
2276 icon_view->priv->cursor_cell);
2280 g_object_get (info->cell, "mode", &mode, NULL);
2282 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2284 gtk_icon_view_item_activate_cell (icon_view,
2285 icon_view->priv->cursor_item,
2289 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2291 gtk_icon_view_start_editing (icon_view,
2292 icon_view->priv->cursor_item,
2298 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2299 gtk_icon_view_item_activated (icon_view, path);
2300 gtk_tree_path_free (path);
2306 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2308 if (!icon_view->priv->cursor_item)
2311 switch (icon_view->priv->selection_mode)
2313 case GTK_SELECTION_NONE:
2315 case GTK_SELECTION_BROWSE:
2316 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2318 case GTK_SELECTION_SINGLE:
2319 if (icon_view->priv->cursor_item->selected)
2320 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2322 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2324 case GTK_SELECTION_MULTIPLE:
2325 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2326 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2328 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2333 /* Internal functions */
2335 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2336 GtkIconView *icon_view)
2338 if (GTK_WIDGET_REALIZED (icon_view))
2340 gdk_window_move (icon_view->priv->bin_window,
2341 - icon_view->priv->hadjustment->value,
2342 - icon_view->priv->vadjustment->value);
2344 if (icon_view->priv->doing_rubberband)
2345 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2347 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2352 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2357 gint *maximum_width)
2360 gint x, current_width;
2361 GList *items, *last_item;
2368 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2369 max_height = g_new0 (gint, icon_view->priv->n_cells);
2376 gtk_widget_style_get (GTK_WIDGET (icon_view),
2377 "focus-line-width", &focus_width,
2380 x += icon_view->priv->margin + focus_width;
2381 current_width += 2 * (icon_view->priv->margin + focus_width);
2386 GtkIconViewItem *item = items->data;
2388 gtk_icon_view_calculate_item_size (icon_view, item);
2389 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2391 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2393 current_width += item->width;
2395 if (items != first_item)
2397 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2398 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2402 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2404 item->y = *y + focus_width;
2405 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2407 x = current_width - (icon_view->priv->margin + focus_width);
2409 for (i = 0; i < icon_view->priv->n_cells; i++)
2410 max_height[i] = MAX (max_height[i], item->box[i].height);
2412 if (current_width > *maximum_width)
2413 *maximum_width = current_width;
2419 items = items->next;
2424 /* Now go through the row again and align the icons */
2425 for (items = first_item; items != last_item; items = items->next)
2427 GtkIconViewItem *item = items->data;
2429 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2431 /* We may want to readjust the new y coordinate. */
2432 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2433 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2436 item->col = col - 1 - item->col;
2439 g_free (max_height);
2445 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2448 if (upper != adj->upper)
2450 gdouble min = MAX (0.0, upper - adj->page_size);
2451 gboolean value_changed = FALSE;
2455 if (adj->value > min)
2458 value_changed = TRUE;
2461 gtk_adjustment_changed (adj);
2464 gtk_adjustment_value_changed (adj);
2469 gtk_icon_view_layout (GtkIconView *icon_view)
2471 gint y = 0, maximum_width = 0;
2477 if (icon_view->priv->layout_idle_id != 0)
2479 g_source_remove (icon_view->priv->layout_idle_id);
2480 icon_view->priv->layout_idle_id = 0;
2483 if (icon_view->priv->model == NULL)
2486 widget = GTK_WIDGET (icon_view);
2488 item_width = icon_view->priv->item_width;
2492 for (icons = icon_view->priv->items; icons; icons = icons->next)
2494 GtkIconViewItem *item = icons->data;
2495 gtk_icon_view_calculate_item_size (icon_view, item);
2496 item_width = MAX (item_width, item->width);
2500 icons = icon_view->priv->items;
2501 y += icon_view->priv->margin;
2506 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2508 &y, &maximum_width);
2511 while (icons != NULL);
2513 if (maximum_width != icon_view->priv->width)
2514 icon_view->priv->width = maximum_width;
2516 y += icon_view->priv->margin;
2518 if (y != icon_view->priv->height)
2519 icon_view->priv->height = y;
2521 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2522 icon_view->priv->width);
2523 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2524 icon_view->priv->height);
2526 if (GTK_WIDGET_REALIZED (icon_view))
2527 gdk_window_resize (icon_view->priv->bin_window,
2528 MAX (icon_view->priv->width, widget->allocation.width),
2529 MAX (icon_view->priv->height, widget->allocation.height));
2531 if (icon_view->priv->scroll_to_path)
2535 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2536 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2537 icon_view->priv->scroll_to_path = NULL;
2539 gtk_icon_view_scroll_to_path (icon_view, path,
2540 icon_view->priv->scroll_to_use_align,
2541 icon_view->priv->scroll_to_row_align,
2542 icon_view->priv->scroll_to_col_align);
2543 gtk_tree_path_free (path);
2546 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2550 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2551 GtkIconViewItem *item,
2552 GtkIconViewCellInfo *info,
2553 GdkRectangle *cell_area)
2555 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2557 cell_area->x = item->box[info->position].x - item->before[info->position];
2558 cell_area->y = item->y;
2559 cell_area->width = item->box[info->position].width +
2560 item->before[info->position] + item->after[info->position];
2561 cell_area->height = item->height;
2565 cell_area->x = item->x;
2566 cell_area->y = item->box[info->position].y - item->before[info->position];
2567 cell_area->width = item->width;
2568 cell_area->height = item->box[info->position].height +
2569 item->before[info->position] + item->after[info->position];
2574 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2575 GtkIconViewItem *item,
2576 GtkIconViewCellInfo *info,
2579 *box = item->box[info->position];
2582 /* try to guess a reasonable wrap width for an implicit text cell renderer
2585 adjust_wrap_width (GtkIconView *icon_view,
2586 GtkIconViewItem *item)
2588 GtkIconViewCellInfo *text_info;
2589 GtkIconViewCellInfo *pixbuf_info;
2590 gint pixbuf_width, wrap_width;
2592 if (icon_view->priv->text_cell != -1 &&
2593 icon_view->priv->pixbuf_cell != -1)
2595 text_info = g_list_nth_data (icon_view->priv->cell_list,
2596 icon_view->priv->text_cell);
2597 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2598 icon_view->priv->pixbuf_cell);
2600 gtk_cell_renderer_get_size (pixbuf_info->cell,
2601 GTK_WIDGET (icon_view),
2606 if (item->width == -1)
2607 wrap_width = MAX (2 * pixbuf_width, 50);
2608 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2609 wrap_width = item->width;
2611 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2613 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2618 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2619 GtkIconViewItem *item)
2624 if (item->width != -1 && item->height != -1)
2627 if (item->n_cells != icon_view->priv->n_cells)
2629 g_free (item->before);
2630 g_free (item->after);
2633 item->before = g_new0 (gint, icon_view->priv->n_cells);
2634 item->after = g_new0 (gint, icon_view->priv->n_cells);
2635 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2637 item->n_cells = icon_view->priv->n_cells;
2640 gtk_icon_view_set_cell_data (icon_view, item);
2642 spacing = icon_view->priv->spacing;
2646 for (l = icon_view->priv->cell_list; l; l = l->next)
2648 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2650 if (!info->cell->visible)
2653 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2655 &item->box[info->position].width,
2656 &item->box[info->position].height);
2658 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2660 item->width += item->box[info->position].width
2661 + (info->position > 0 ? spacing : 0);
2662 item->height = MAX (item->height, item->box[info->position].height);
2666 item->width = MAX (item->width, item->box[info->position].width);
2667 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2673 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2674 GtkIconViewItem *item,
2677 GdkRectangle cell_area;
2683 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2685 gtk_icon_view_set_cell_data (icon_view, item);
2687 spacing = icon_view->priv->spacing;
2690 for (i = 0; i < icon_view->priv->n_cells; i++)
2692 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2693 item->height = MAX (item->height, max_height[i]);
2695 item->height += max_height[i] + (i > 0 ? spacing : 0);
2698 cell_area.x = item->x;
2699 cell_area.y = item->y;
2701 for (k = 0; k < 2; k++)
2702 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2704 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2706 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2709 if (!info->cell->visible)
2712 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2714 cell_area.width = item->box[info->position].width;
2715 cell_area.height = item->height;
2719 cell_area.width = item->width;
2720 cell_area.height = max_height[i];
2723 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2725 &item->box[info->position].x, &item->box[info->position].y,
2726 &item->box[info->position].width, &item->box[info->position].height);
2728 item->box[info->position].x += cell_area.x;
2729 item->box[info->position].y += cell_area.y;
2730 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2732 item->before[info->position] = item->box[info->position].x - cell_area.x;
2733 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2734 cell_area.x += cell_area.width + spacing;
2738 if (item->box[info->position].width > item->width)
2740 item->width = item->box[info->position].width;
2741 cell_area.width = item->width;
2743 item->before[info->position] = item->box[info->position].y - cell_area.y;
2744 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2745 cell_area.y += cell_area.height + spacing;
2749 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2751 for (i = 0; i < icon_view->priv->n_cells; i++)
2753 item->box[i].x = item->x + item->width -
2754 (item->box[i].x + item->box[i].width - item->x);
2760 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2762 g_list_foreach (icon_view->priv->items,
2763 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2767 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2774 gtk_icon_view_paint_item (GtkIconView *icon_view,
2776 GtkIconViewItem *item,
2778 GdkDrawable *drawable,
2781 gboolean draw_focus)
2783 gint focus_width, focus_pad;
2785 GdkRectangle cell_area, box;
2789 GtkCellRendererState flags;
2791 if (icon_view->priv->model == NULL)
2794 gtk_icon_view_set_cell_data (icon_view, item);
2796 gtk_widget_style_get (GTK_WIDGET (icon_view),
2797 "focus-line-width", &focus_width,
2798 "focus-padding", &focus_pad,
2801 padding = focus_width;
2805 flags = GTK_CELL_RENDERER_SELECTED;
2806 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2807 state = GTK_STATE_SELECTED;
2809 state = GTK_STATE_ACTIVE;
2814 state = GTK_STATE_NORMAL;
2817 #ifdef DEBUG_ICON_VIEW
2818 gdk_draw_rectangle (drawable,
2819 GTK_WIDGET (icon_view)->style->black_gc,
2822 item->width, item->height);
2826 for (l = icon_view->priv->cell_list; l; l = l->next)
2828 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2830 if (!info->cell->visible)
2833 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2835 /* FIXME we hardwire background drawing behind text
2836 * cell renderers here
2838 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2840 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2841 cairo_rectangle (cr,
2842 x - item->x + box.x,
2843 y - item->y + box.y,
2844 box.width, box.height);
2849 for (l = icon_view->priv->cell_list; l; l = l->next)
2851 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2853 if (!info->cell->visible)
2856 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2858 #ifdef DEBUG_ICON_VIEW
2859 gdk_draw_rectangle (drawable,
2860 GTK_WIDGET (icon_view)->style->black_gc,
2862 x - item->x + cell_area.x,
2863 y - item->y + cell_area.y,
2864 cell_area.width, cell_area.height);
2866 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2868 gdk_draw_rectangle (drawable,
2869 GTK_WIDGET (icon_view)->style->black_gc,
2871 x - item->x + box.x,
2872 y - item->y + box.y,
2873 box.width, box.height);
2876 cell_area.x = x - item->x + cell_area.x;
2877 cell_area.y = y - item->y + cell_area.y;
2879 gtk_cell_renderer_render (info->cell,
2881 GTK_WIDGET (icon_view),
2882 &cell_area, &cell_area, area, flags);
2886 /* FIXME where to draw the focus with generic cell renderers ? */
2888 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2889 item == icon_view->priv->cursor_item)
2890 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2892 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2894 if (!info->cell->visible)
2897 if (icon_view->priv->cursor_cell < 0 &&
2898 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2899 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2900 icon_view->priv->cursor_cell = i;
2902 if (i == icon_view->priv->cursor_cell)
2904 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2906 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2910 GTK_WIDGET (icon_view),
2912 x - item->x + box.x - padding,
2913 y - item->y + box.y - padding,
2914 box.width + 2 * padding,
2915 box.height + 2 * padding);
2922 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2927 GdkRectangle rubber_rect;
2928 GdkColor *fill_color_gdk;
2929 guchar fill_color_alpha;
2931 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2932 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2933 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2934 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2936 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2939 gtk_widget_style_get (GTK_WIDGET (icon_view),
2940 "selection-box-color", &fill_color_gdk,
2941 "selection-box-alpha", &fill_color_alpha,
2944 if (!fill_color_gdk)
2945 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2947 cairo_set_source_rgba (cr,
2948 fill_color_gdk->red / 65535.,
2949 fill_color_gdk->green / 65535.,
2950 fill_color_gdk->blue / 65535.,
2951 fill_color_alpha / 255.);
2954 gdk_cairo_rectangle (cr, &rect);
2958 /* Draw the border without alpha */
2959 cairo_set_source_rgb (cr,
2960 fill_color_gdk->red / 65535.,
2961 fill_color_gdk->green / 65535.,
2962 fill_color_gdk->blue / 65535.);
2963 cairo_rectangle (cr,
2964 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2965 rubber_rect.width - 1, rubber_rect.height - 1);
2969 gdk_color_free (fill_color_gdk);
2973 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2979 index = gtk_tree_path_get_indices (path)[0];
2981 for (l = icon_view->priv->items; l; l = l->next)
2983 GtkIconViewItem *item = l->data;
2985 if (item->index == index)
2987 gtk_icon_view_queue_draw_item (icon_view, item);
2994 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2995 GtkIconViewItem *item)
3000 gtk_widget_style_get (GTK_WIDGET (icon_view),
3001 "focus-line-width", &focus_width,
3004 rect.x = item->x - focus_width;
3005 rect.y = item->y - focus_width;
3006 rect.width = item->width + 2 * focus_width;
3007 rect.height = item->height + 2 * focus_width;
3009 if (icon_view->priv->bin_window)
3010 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3014 layout_callback (gpointer user_data)
3016 GtkIconView *icon_view;
3018 GDK_THREADS_ENTER ();
3020 icon_view = GTK_ICON_VIEW (user_data);
3022 icon_view->priv->layout_idle_id = 0;
3024 gtk_icon_view_layout (icon_view);
3026 GDK_THREADS_LEAVE();
3032 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3034 if (icon_view->priv->layout_idle_id != 0)
3037 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3041 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3042 GtkIconViewItem *item,
3046 AtkObject *item_obj;
3048 if (icon_view->priv->cursor_item == item &&
3049 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3052 if (icon_view->priv->cursor_item != NULL)
3053 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3055 icon_view->priv->cursor_item = item;
3056 if (cursor_cell >= 0)
3057 icon_view->priv->cursor_cell = cursor_cell;
3059 gtk_icon_view_queue_draw_item (icon_view, item);
3061 /* Notify that accessible focus object has changed */
3062 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3063 item_obj = atk_object_ref_accessible_child (obj, item->index);
3065 if (item_obj != NULL)
3067 atk_focus_tracker_notify (item_obj);
3068 g_object_unref (item_obj);
3073 static GtkIconViewItem *
3074 gtk_icon_view_item_new (void)
3076 GtkIconViewItem *item;
3078 item = g_new0 (GtkIconViewItem, 1);
3087 gtk_icon_view_item_free (GtkIconViewItem *item)
3089 g_return_if_fail (item != NULL);
3091 g_free (item->before);
3092 g_free (item->after);
3099 static GtkIconViewItem *
3100 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3103 gboolean only_in_cell,
3104 GtkIconViewCellInfo **cell_at_pos)
3109 for (items = icon_view->priv->items; items; items = items->next)
3111 GtkIconViewItem *item = items->data;
3113 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3114 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3116 if (only_in_cell || cell_at_pos)
3118 gtk_icon_view_set_cell_data (icon_view, item);
3120 for (l = icon_view->priv->cell_list; l; l = l->next)
3122 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3124 if (!info->cell->visible)
3127 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3129 if ((x >= box.x && x <= box.x + box.width &&
3130 y >= box.y && y <= box.y + box.height) ||
3132 x <= box.x + box.width &&
3134 y <= box.y + box.height))
3137 *cell_at_pos = info;
3147 *cell_at_pos = NULL;
3158 gtk_icon_view_select_item (GtkIconView *icon_view,
3159 GtkIconViewItem *item)
3161 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3162 g_return_if_fail (item != NULL);
3167 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3169 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3170 gtk_icon_view_unselect_all_internal (icon_view);
3172 item->selected = TRUE;
3174 gtk_icon_view_queue_draw_item (icon_view, item);
3176 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3181 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3182 GtkIconViewItem *item)
3184 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3185 g_return_if_fail (item != NULL);
3187 if (!item->selected)
3190 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3191 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3194 item->selected = FALSE;
3196 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3198 gtk_icon_view_queue_draw_item (icon_view, item);
3202 verify_items (GtkIconView *icon_view)
3207 for (items = icon_view->priv->items; items; items = items->next)
3209 GtkIconViewItem *item = items->data;
3211 if (item->index != i)
3212 g_error ("List item does not match its index: "
3213 "item index %d and list index %d\n", item->index, i);
3220 gtk_icon_view_row_changed (GtkTreeModel *model,
3225 GtkIconViewItem *item;
3227 GtkIconView *icon_view;
3229 icon_view = GTK_ICON_VIEW (data);
3231 gtk_icon_view_stop_editing (icon_view, TRUE);
3233 index = gtk_tree_path_get_indices(path)[0];
3234 item = g_list_nth_data (icon_view->priv->items, index);
3236 gtk_icon_view_item_invalidate_size (item);
3237 gtk_icon_view_queue_layout (icon_view);
3239 verify_items (icon_view);
3243 gtk_icon_view_row_inserted (GtkTreeModel *model,
3249 GtkIconViewItem *item;
3250 gboolean iters_persist;
3251 GtkIconView *icon_view;
3254 icon_view = GTK_ICON_VIEW (data);
3256 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3258 index = gtk_tree_path_get_indices(path)[0];
3260 item = gtk_icon_view_item_new ();
3265 item->index = index;
3267 /* FIXME: We can be more efficient here,
3268 we can store a tail pointer and use that when
3269 appending (which is a rather common operation)
3271 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3274 list = g_list_nth (icon_view->priv->items, index + 1);
3275 for (; list; list = list->next)
3282 verify_items (icon_view);
3284 gtk_icon_view_queue_layout (icon_view);
3288 gtk_icon_view_row_deleted (GtkTreeModel *model,
3293 GtkIconView *icon_view;
3294 GtkIconViewItem *item;
3296 gboolean emit = FALSE;
3298 icon_view = GTK_ICON_VIEW (data);
3300 index = gtk_tree_path_get_indices(path)[0];
3302 list = g_list_nth (icon_view->priv->items, index);
3305 gtk_icon_view_stop_editing (icon_view, TRUE);
3307 if (item == icon_view->priv->anchor_item)
3308 icon_view->priv->anchor_item = NULL;
3310 if (item == icon_view->priv->cursor_item)
3311 icon_view->priv->cursor_item = NULL;
3316 gtk_icon_view_item_free (item);
3318 for (next = list->next; next; next = next->next)
3325 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3327 verify_items (icon_view);
3329 gtk_icon_view_queue_layout (icon_view);
3332 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3336 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3337 GtkTreePath *parent,
3344 GtkIconView *icon_view;
3345 GList *items = NULL, *list;
3346 GtkIconViewItem **item_array;
3349 icon_view = GTK_ICON_VIEW (data);
3351 gtk_icon_view_stop_editing (icon_view, TRUE);
3353 length = gtk_tree_model_iter_n_children (model, NULL);
3355 order = g_new (gint, length);
3356 for (i = 0; i < length; i++)
3357 order [new_order[i]] = i;
3359 item_array = g_new (GtkIconViewItem *, length);
3360 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3361 item_array[order[i]] = list->data;
3364 for (i = length - 1; i >= 0; i--)
3366 item_array[i]->index = i;
3367 items = g_list_prepend (items, item_array[i]);
3370 g_free (item_array);
3371 g_list_free (icon_view->priv->items);
3372 icon_view->priv->items = items;
3374 gtk_icon_view_queue_layout (icon_view);
3376 verify_items (icon_view);
3380 gtk_icon_view_build_items (GtkIconView *icon_view)
3384 gboolean iters_persist;
3385 GList *items = NULL;
3387 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3389 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3397 GtkIconViewItem *item = gtk_icon_view_item_new ();
3406 items = g_list_prepend (items, item);
3408 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3410 icon_view->priv->items = g_list_reverse (items);
3414 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3417 GtkMovementStep step,
3421 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3422 I_("move_cursor"), 2,
3426 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3431 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3434 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3439 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3446 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3447 GtkMovementStep step,
3450 GdkModifierType state;
3452 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3453 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3454 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3455 step == GTK_MOVEMENT_DISPLAY_LINES ||
3456 step == GTK_MOVEMENT_PAGES ||
3457 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3459 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3462 gtk_icon_view_stop_editing (icon_view, FALSE);
3463 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3465 if (gtk_get_current_event_state (&state))
3467 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3468 icon_view->priv->ctrl_pressed = TRUE;
3469 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3470 icon_view->priv->shift_pressed = TRUE;
3472 /* else we assume not pressed */
3476 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3477 case GTK_MOVEMENT_VISUAL_POSITIONS:
3478 gtk_icon_view_move_cursor_left_right (icon_view, count);
3480 case GTK_MOVEMENT_DISPLAY_LINES:
3481 gtk_icon_view_move_cursor_up_down (icon_view, count);
3483 case GTK_MOVEMENT_PAGES:
3484 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3486 case GTK_MOVEMENT_BUFFER_ENDS:
3487 gtk_icon_view_move_cursor_start_end (icon_view, count);
3490 g_assert_not_reached ();
3493 icon_view->priv->ctrl_pressed = FALSE;
3494 icon_view->priv->shift_pressed = FALSE;
3499 static GtkIconViewItem *
3500 find_item (GtkIconView *icon_view,
3501 GtkIconViewItem *current,
3507 GtkIconViewItem *item;
3509 /* FIXME: this could be more efficient
3511 row = current->row + row_ofs;
3512 col = current->col + col_ofs;
3514 for (items = icon_view->priv->items; items; items = items->next)
3517 if (item->row == row && item->col == col)
3525 find_cell (GtkIconView *icon_view,
3526 GtkIconViewItem *item,
3528 GtkOrientation orientation,
3539 if (icon_view->priv->orientation != orientation)
3542 gtk_icon_view_set_cell_data (icon_view, item);
3544 focusable = g_new0 (gint, icon_view->priv->n_cells);
3549 for (k = 0; k < 2; k++)
3550 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3552 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3554 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3557 if (!info->cell->visible)
3560 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3563 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3566 current = n_focusable;
3568 focusable[n_focusable] = i;
3574 if (n_focusable == 0)
3575 focusable[n_focusable++] = first_text;
3579 current = step > 0 ? 0 : n_focusable - 1;
3580 cell = focusable[current];
3583 if (current + *count < 0)
3586 *count = current + *count;
3588 else if (current + *count > n_focusable - 1)
3591 *count = current + *count - (n_focusable - 1);
3595 cell = focusable[current + *count];
3604 static GtkIconViewItem *
3605 find_item_page_up_down (GtkIconView *icon_view,
3606 GtkIconViewItem *current,
3613 y = current->y + count * icon_view->priv->vadjustment->page_size;
3615 item = g_list_find (icon_view->priv->items, current);
3620 for (next = item->next; next; next = next->next)
3622 if (((GtkIconViewItem *)next->data)->col == col)
3625 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3635 for (next = item->prev; next; next = next->prev)
3637 if (((GtkIconViewItem *)next->data)->col == col)
3640 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3654 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3655 GtkIconViewItem *anchor,
3656 GtkIconViewItem *cursor)
3659 GtkIconViewItem *item;
3660 gint row1, row2, col1, col2;
3661 gboolean dirty = FALSE;
3663 if (anchor->row < cursor->row)
3674 if (anchor->col < cursor->col)
3685 for (items = icon_view->priv->items; items; items = items->next)
3689 if (row1 <= item->row && item->row <= row2 &&
3690 col1 <= item->col && item->col <= col2)
3692 if (!item->selected)
3695 item->selected = TRUE;
3697 gtk_icon_view_queue_draw_item (icon_view, item);
3705 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3708 GtkIconViewItem *item;
3710 gboolean dirty = FALSE;
3713 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3716 if (!icon_view->priv->cursor_item)
3721 list = icon_view->priv->items;
3723 list = g_list_last (icon_view->priv->items);
3725 item = list ? list->data : NULL;
3730 item = icon_view->priv->cursor_item;
3731 cell = icon_view->priv->cursor_cell;
3732 step = count > 0 ? 1 : -1;
3735 cell = find_cell (icon_view, item, cell,
3736 GTK_ORIENTATION_VERTICAL,
3741 item = find_item (icon_view, item, step, 0);
3742 count = count - step;
3749 if (icon_view->priv->ctrl_pressed ||
3750 !icon_view->priv->shift_pressed ||
3751 !icon_view->priv->anchor_item ||
3752 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3753 icon_view->priv->anchor_item = item;
3755 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3757 if (!icon_view->priv->ctrl_pressed &&
3758 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3760 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3761 dirty = gtk_icon_view_select_all_between (icon_view,
3762 icon_view->priv->anchor_item,
3766 gtk_icon_view_scroll_to_item (icon_view, item);
3769 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3773 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3776 GtkIconViewItem *item;
3777 gboolean dirty = FALSE;
3779 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3782 if (!icon_view->priv->cursor_item)
3787 list = icon_view->priv->items;
3789 list = g_list_last (icon_view->priv->items);
3791 item = list ? list->data : NULL;
3794 item = find_item_page_up_down (icon_view,
3795 icon_view->priv->cursor_item,
3801 if (icon_view->priv->ctrl_pressed ||
3802 !icon_view->priv->shift_pressed ||
3803 !icon_view->priv->anchor_item ||
3804 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3805 icon_view->priv->anchor_item = item;
3807 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3809 if (!icon_view->priv->ctrl_pressed &&
3810 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3812 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3813 dirty = gtk_icon_view_select_all_between (icon_view,
3814 icon_view->priv->anchor_item,
3818 gtk_icon_view_scroll_to_item (icon_view, item);
3821 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3825 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3828 GtkIconViewItem *item;
3830 gboolean dirty = FALSE;
3833 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3836 if (!icon_view->priv->cursor_item)
3841 list = icon_view->priv->items;
3843 list = g_list_last (icon_view->priv->items);
3845 item = list ? list->data : NULL;
3849 item = icon_view->priv->cursor_item;
3850 cell = icon_view->priv->cursor_cell;
3851 step = count > 0 ? 1 : -1;
3854 cell = find_cell (icon_view, item, cell,
3855 GTK_ORIENTATION_HORIZONTAL,
3860 item = find_item (icon_view, item, 0, step);
3861 count = count - step;
3868 if (icon_view->priv->ctrl_pressed ||
3869 !icon_view->priv->shift_pressed ||
3870 !icon_view->priv->anchor_item ||
3871 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3872 icon_view->priv->anchor_item = item;
3874 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3876 if (!icon_view->priv->ctrl_pressed &&
3877 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3879 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3880 dirty = gtk_icon_view_select_all_between (icon_view,
3881 icon_view->priv->anchor_item,
3885 gtk_icon_view_scroll_to_item (icon_view, item);
3888 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3892 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3895 GtkIconViewItem *item;
3897 gboolean dirty = FALSE;
3899 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3903 list = icon_view->priv->items;
3905 list = g_list_last (icon_view->priv->items);
3907 item = list ? list->data : NULL;
3912 if (icon_view->priv->ctrl_pressed ||
3913 !icon_view->priv->shift_pressed ||
3914 !icon_view->priv->anchor_item ||
3915 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3916 icon_view->priv->anchor_item = item;
3918 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3920 if (!icon_view->priv->ctrl_pressed &&
3921 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3923 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3924 dirty = gtk_icon_view_select_all_between (icon_view,
3925 icon_view->priv->anchor_item,
3929 gtk_icon_view_scroll_to_item (icon_view, item);
3932 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3936 * gtk_icon_view_scroll_to_path:
3937 * @icon_view: A #GtkIconView.
3938 * @path: The path of the item to move to.
3939 * @use_align: whether to use alignment arguments, or %FALSE.
3940 * @row_align: The vertical alignment of the item specified by @path.
3941 * @col_align: The horizontal alignment of the item specified by @path.
3943 * Moves the alignments of @icon_view to the position specified by @path.
3944 * @row_align determines where the row is placed, and @col_align determines
3945 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3946 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3949 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3950 * tree does the minimum amount of work to scroll the item onto the screen.
3951 * This means that the item will be scrolled to the edge closest to its current
3952 * position. If the item is currently visible on the screen, nothing is done.
3954 * This function only works if the model is set, and @path is a valid row on
3955 * the model. If the model changes before the @icon_view is realized, the
3956 * centered path will be modified to reflect this change.
3961 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3967 GtkIconViewItem *item = NULL;
3969 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3970 g_return_if_fail (path != NULL);
3971 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3972 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3974 if (gtk_tree_path_get_depth (path) > 0)
3975 item = g_list_nth_data (icon_view->priv->items,
3976 gtk_tree_path_get_indices(path)[0]);
3978 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
3980 if (icon_view->priv->scroll_to_path)
3981 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3983 icon_view->priv->scroll_to_path = NULL;
3986 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3988 icon_view->priv->scroll_to_use_align = use_align;
3989 icon_view->priv->scroll_to_row_align = row_align;
3990 icon_view->priv->scroll_to_col_align = col_align;
3999 gfloat offset, value;
4001 gtk_widget_style_get (GTK_WIDGET (icon_view),
4002 "focus-line-width", &focus_width,
4005 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4007 offset = y + item->y - focus_width -
4008 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4009 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4010 icon_view->priv->vadjustment->lower,
4011 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4012 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4014 offset = x + item->x - focus_width -
4015 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4016 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4017 icon_view->priv->hadjustment->lower,
4018 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4019 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4021 gtk_adjustment_changed (icon_view->priv->hadjustment);
4022 gtk_adjustment_changed (icon_view->priv->vadjustment);
4025 gtk_icon_view_scroll_to_item (icon_view, item);
4030 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4031 GtkIconViewItem *item)
4033 gint x, y, width, height;
4036 gtk_widget_style_get (GTK_WIDGET (icon_view),
4037 "focus-line-width", &focus_width,
4040 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4042 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4044 if (y + item->y - focus_width < 0)
4045 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4046 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4047 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4048 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4049 icon_view->priv->vadjustment->value + y + item->y + item->height
4050 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4052 if (x + item->x - focus_width < 0)
4053 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4054 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4055 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4056 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4057 icon_view->priv->hadjustment->value + x + item->x + item->width
4058 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4060 gtk_adjustment_changed (icon_view->priv->hadjustment);
4061 gtk_adjustment_changed (icon_view->priv->vadjustment);
4064 /* GtkCellLayout implementation */
4065 static GtkIconViewCellInfo *
4066 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4067 GtkCellRenderer *renderer)
4071 for (i = icon_view->priv->cell_list; i; i = i->next)
4073 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4075 if (info->cell == renderer)
4083 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4084 GtkIconViewItem *item)
4087 gboolean iters_persist;
4090 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4096 path = gtk_tree_path_new_from_indices (item->index, -1);
4097 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4098 gtk_tree_path_free (path);
4103 for (i = icon_view->priv->cell_list; i; i = i->next)
4106 GtkIconViewCellInfo *info = i->data;
4108 g_object_freeze_notify (G_OBJECT (info->cell));
4110 for (j = info->attributes; j && j->next; j = j->next->next)
4112 gchar *property = j->data;
4113 gint column = GPOINTER_TO_INT (j->next->data);
4114 GValue value = {0, };
4116 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4118 g_object_set_property (G_OBJECT (info->cell),
4120 g_value_unset (&value);
4124 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4126 icon_view->priv->model,
4130 g_object_thaw_notify (G_OBJECT (info->cell));
4133 adjust_wrap_width (icon_view, item);
4137 free_cell_attributes (GtkIconViewCellInfo *info)
4141 list = info->attributes;
4142 while (list && list->next)
4144 g_free (list->data);
4145 list = list->next->next;
4148 g_slist_free (info->attributes);
4149 info->attributes = NULL;
4153 free_cell_info (GtkIconViewCellInfo *info)
4155 free_cell_attributes (info);
4157 g_object_unref (info->cell);
4160 (* info->destroy) (info->func_data);
4166 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4167 GtkCellRenderer *renderer,
4170 GtkIconViewCellInfo *info;
4171 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4173 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4174 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4176 g_object_ref_sink (renderer);
4178 info = g_new0 (GtkIconViewCellInfo, 1);
4179 info->cell = renderer;
4180 info->expand = expand ? TRUE : FALSE;
4181 info->pack = GTK_PACK_START;
4182 info->position = icon_view->priv->n_cells;
4184 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4185 icon_view->priv->n_cells++;
4189 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4190 GtkCellRenderer *renderer,
4193 GtkIconViewCellInfo *info;
4194 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4196 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4197 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4199 g_object_ref_sink (renderer);
4201 info = g_new0 (GtkIconViewCellInfo, 1);
4202 info->cell = renderer;
4203 info->expand = expand ? TRUE : FALSE;
4204 info->pack = GTK_PACK_END;
4205 info->position = icon_view->priv->n_cells;
4207 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4208 icon_view->priv->n_cells++;
4212 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4213 GtkCellRenderer *renderer,
4214 const gchar *attribute,
4217 GtkIconViewCellInfo *info;
4218 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4220 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4221 g_return_if_fail (info != NULL);
4223 info->attributes = g_slist_prepend (info->attributes,
4224 GINT_TO_POINTER (column));
4225 info->attributes = g_slist_prepend (info->attributes,
4226 g_strdup (attribute));
4230 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4232 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4234 while (icon_view->priv->cell_list)
4236 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4237 free_cell_info (info);
4238 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4239 icon_view->priv->cell_list);
4242 icon_view->priv->n_cells = 0;
4246 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4247 GtkCellRenderer *cell,
4248 GtkCellLayoutDataFunc func,
4250 GDestroyNotify destroy)
4252 GtkIconViewCellInfo *info;
4253 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4255 info = gtk_icon_view_get_cell_info (icon_view, cell);
4256 g_return_if_fail (info != NULL);
4260 GDestroyNotify d = info->destroy;
4262 info->destroy = NULL;
4263 d (info->func_data);
4267 info->func_data = func_data;
4268 info->destroy = destroy;
4272 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4273 GtkCellRenderer *renderer)
4275 GtkIconViewCellInfo *info;
4277 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4279 free_cell_attributes (info);
4283 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4284 GtkCellRenderer *cell,
4287 GtkIconView *icon_view;
4289 GtkIconViewCellInfo *info;
4292 icon_view = GTK_ICON_VIEW (layout);
4294 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4296 info = gtk_icon_view_get_cell_info (icon_view, cell);
4298 g_return_if_fail (info != NULL);
4299 g_return_if_fail (position >= 0);
4301 link = g_list_find (icon_view->priv->cell_list, info);
4303 g_return_if_fail (link != NULL);
4305 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4307 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4310 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4317 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4324 * gtk_icon_view_new:
4326 * Creates a new #GtkIconView widget
4328 * Return value: A newly created #GtkIconView widget
4333 gtk_icon_view_new (void)
4335 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4339 * gtk_icon_view_new_with_model:
4340 * @model: The model.
4342 * Creates a new #GtkIconView widget with the model @model.
4344 * Return value: A newly created #GtkIconView widget.
4349 gtk_icon_view_new_with_model (GtkTreeModel *model)
4351 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4356 * gtk_icon_view_get_path_at_pos:
4357 * @icon_view: A #GtkIconView.
4358 * @x: The x position to be identified
4359 * @y: The y position to be identified
4361 * Finds the path at the point (@x, @y), relative to widget coordinates.
4362 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4363 * the cell at the specified position.
4365 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4366 * if no icon exists at that position.
4371 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4375 GtkIconViewItem *item;
4378 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4380 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4385 path = gtk_tree_path_new_from_indices (item->index, -1);
4391 * gtk_icon_view_get_item_at_pos:
4392 * @icon_view: A #GtkIconView.
4393 * @x: The x position to be identified
4394 * @y: The y position to be identified
4395 * @path: Return location for the path, or %NULL
4396 * @cell: Return location for the renderer responsible for the cell
4397 * at (@x, @y), or %NULL
4399 * Finds the path at the point (@x, @y), relative to widget coordinates.
4400 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4401 * obtains the cell at the specified position. The returned path should
4402 * be freed with gtk_tree_path_free().
4404 * Return value: %TRUE if an item exists at the specified position
4409 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4413 GtkCellRenderer **cell)
4415 GtkIconViewItem *item;
4416 GtkIconViewCellInfo *info;
4418 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4420 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4425 *path = gtk_tree_path_new_from_indices (item->index, -1);
4438 return (item != NULL);
4443 * gtk_icon_view_get_visible_range:
4444 * @icon_view: A #GtkIconView
4445 * @start_path: Return location for start of region, or %NULL
4446 * @end_path: Return location for end of region, or %NULL
4448 * Sets @start_path and @end_path to be the first and last visible path.
4449 * Note that there may be invisible paths in between.
4451 * Both paths should be freed with gtk_tree_path_free() after use.
4453 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4458 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4459 GtkTreePath **start_path,
4460 GtkTreePath **end_path)
4462 gint start_index = -1;
4463 gint end_index = -1;
4466 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4468 if (icon_view->priv->hadjustment == NULL ||
4469 icon_view->priv->vadjustment == NULL)
4472 if (start_path == NULL && end_path == NULL)
4475 for (icons = icon_view->priv->items; icons; icons = icons->next)
4477 GtkIconViewItem *item = icons->data;
4479 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4480 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4481 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4482 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4484 if (start_index == -1)
4485 start_index = item->index;
4486 end_index = item->index;
4490 if (start_path && start_index != -1)
4491 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4492 if (end_path && end_index != -1)
4493 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4495 return start_index != -1;
4499 * gtk_icon_view_selected_foreach:
4500 * @icon_view: A #GtkIconView.
4501 * @func: The funcion to call for each selected icon.
4502 * @data: User data to pass to the function.
4504 * Calls a function for each selected icon. Note that the model or
4505 * selection cannot be modified from within this function.
4510 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4511 GtkIconViewForeachFunc func,
4516 for (list = icon_view->priv->items; list; list = list->next)
4518 GtkIconViewItem *item = list->data;
4519 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4522 (* func) (icon_view, path, data);
4524 gtk_tree_path_free (path);
4529 * gtk_icon_view_set_selection_mode:
4530 * @icon_view: A #GtkIconView.
4531 * @mode: The selection mode
4533 * Sets the selection mode of the @icon_view.
4538 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4539 GtkSelectionMode mode)
4541 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4543 if (mode == icon_view->priv->selection_mode)
4546 if (mode == GTK_SELECTION_NONE ||
4547 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4548 gtk_icon_view_unselect_all (icon_view);
4550 icon_view->priv->selection_mode = mode;
4552 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4556 * gtk_icon_view_get_selection_mode:
4557 * @icon_view: A #GtkIconView.
4559 * Gets the selection mode of the @icon_view.
4561 * Return value: the current selection mode
4566 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4568 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4570 return icon_view->priv->selection_mode;
4574 * gtk_icon_view_set_model:
4575 * @icon_view: A #GtkIconView.
4576 * @model: The model.
4578 * Sets the model for a #GtkIconView.
4579 * If the @icon_view already has a model set, it will remove
4580 * it before setting the new model. If @model is %NULL, then
4581 * it will unset the old model.
4586 gtk_icon_view_set_model (GtkIconView *icon_view,
4587 GtkTreeModel *model)
4589 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4590 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4592 if (icon_view->priv->model == model)
4595 if (icon_view->priv->scroll_to_path)
4597 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4598 icon_view->priv->scroll_to_path = NULL;
4601 gtk_icon_view_stop_editing (icon_view, TRUE);
4607 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4609 if (icon_view->priv->pixbuf_column != -1)
4611 column_type = gtk_tree_model_get_column_type (model,
4612 icon_view->priv->pixbuf_column);
4614 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4617 if (icon_view->priv->text_column != -1)
4619 column_type = gtk_tree_model_get_column_type (model,
4620 icon_view->priv->text_column);
4622 g_return_if_fail (column_type == G_TYPE_STRING);
4625 if (icon_view->priv->markup_column != -1)
4627 column_type = gtk_tree_model_get_column_type (model,
4628 icon_view->priv->markup_column);
4630 g_return_if_fail (column_type == G_TYPE_STRING);
4635 if (icon_view->priv->model)
4637 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4638 gtk_icon_view_row_changed,
4640 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4641 gtk_icon_view_row_inserted,
4643 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4644 gtk_icon_view_row_deleted,
4646 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4647 gtk_icon_view_rows_reordered,
4650 g_object_unref (icon_view->priv->model);
4652 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4653 g_list_free (icon_view->priv->items);
4654 icon_view->priv->items = NULL;
4655 icon_view->priv->anchor_item = NULL;
4656 icon_view->priv->cursor_item = NULL;
4657 icon_view->priv->last_single_clicked = NULL;
4658 icon_view->priv->width = 0;
4659 icon_view->priv->height = 0;
4662 icon_view->priv->model = model;
4664 if (icon_view->priv->model)
4666 g_object_ref (icon_view->priv->model);
4667 g_signal_connect (icon_view->priv->model,
4669 G_CALLBACK (gtk_icon_view_row_changed),
4671 g_signal_connect (icon_view->priv->model,
4673 G_CALLBACK (gtk_icon_view_row_inserted),
4675 g_signal_connect (icon_view->priv->model,
4677 G_CALLBACK (gtk_icon_view_row_deleted),
4679 g_signal_connect (icon_view->priv->model,
4681 G_CALLBACK (gtk_icon_view_rows_reordered),
4684 gtk_icon_view_build_items (icon_view);
4686 gtk_icon_view_queue_layout (icon_view);
4689 g_object_notify (G_OBJECT (icon_view), "model");
4691 if (GTK_WIDGET_REALIZED (icon_view))
4692 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4696 * gtk_icon_view_get_model:
4697 * @icon_view: a #GtkIconView
4699 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4702 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4707 gtk_icon_view_get_model (GtkIconView *icon_view)
4709 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4711 return icon_view->priv->model;
4715 update_text_cell (GtkIconView *icon_view)
4717 GtkIconViewCellInfo *info;
4721 if (icon_view->priv->text_column == -1 &&
4722 icon_view->priv->markup_column == -1)
4724 if (icon_view->priv->text_cell != -1)
4726 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4727 icon_view->priv->pixbuf_cell--;
4729 info = g_list_nth_data (icon_view->priv->cell_list,
4730 icon_view->priv->text_cell);
4732 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4734 free_cell_info (info);
4736 icon_view->priv->n_cells--;
4737 icon_view->priv->text_cell = -1;
4742 if (icon_view->priv->text_cell == -1)
4744 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4745 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4746 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4749 if (info->cell == cell)
4751 icon_view->priv->text_cell = i;
4757 info = g_list_nth_data (icon_view->priv->cell_list,
4758 icon_view->priv->text_cell);
4760 if (icon_view->priv->markup_column != -1)
4761 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4763 "markup", icon_view->priv->markup_column,
4766 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4768 "text", icon_view->priv->text_column,
4771 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4772 g_object_set (info->cell,
4773 "wrap_mode", PANGO_WRAP_CHAR,
4774 "wrap_width", icon_view->priv->item_width,
4779 g_object_set (info->cell,
4780 "wrap_mode", PANGO_WRAP_CHAR,
4781 "wrap_width", icon_view->priv->item_width,
4789 update_pixbuf_cell (GtkIconView *icon_view)
4791 GtkIconViewCellInfo *info;
4795 if (icon_view->priv->pixbuf_column == -1)
4797 if (icon_view->priv->pixbuf_cell != -1)
4799 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4800 icon_view->priv->text_cell--;
4802 info = g_list_nth_data (icon_view->priv->cell_list,
4803 icon_view->priv->pixbuf_cell);
4805 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4807 free_cell_info (info);
4809 icon_view->priv->n_cells--;
4810 icon_view->priv->pixbuf_cell = -1;
4815 if (icon_view->priv->pixbuf_cell == -1)
4817 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4819 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4820 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4823 if (info->cell == cell)
4825 icon_view->priv->pixbuf_cell = i;
4831 info = g_list_nth_data (icon_view->priv->cell_list,
4832 icon_view->priv->pixbuf_cell);
4834 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4836 "pixbuf", icon_view->priv->pixbuf_column,
4839 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4840 g_object_set (info->cell,
4841 "follow_state", TRUE,
4846 g_object_set (info->cell,
4847 "follow_state", TRUE,
4855 * gtk_icon_view_set_text_column:
4856 * @icon_view: A #GtkIconView.
4857 * @column: A column in the currently used model.
4859 * Sets the column with text for @icon_view to be @column. The text
4860 * column must be of type #G_TYPE_STRING.
4865 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4868 if (column == icon_view->priv->text_column)
4872 icon_view->priv->text_column = -1;
4875 if (icon_view->priv->model != NULL)
4879 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4881 g_return_if_fail (column_type == G_TYPE_STRING);
4884 icon_view->priv->text_column = column;
4887 gtk_icon_view_stop_editing (icon_view, TRUE);
4889 update_text_cell (icon_view);
4891 gtk_icon_view_invalidate_sizes (icon_view);
4892 gtk_icon_view_queue_layout (icon_view);
4894 g_object_notify (G_OBJECT (icon_view), "text-column");
4898 * gtk_icon_view_get_text_column:
4899 * @icon_view: A #GtkIconView.
4901 * Returns the column with text for @icon_view.
4903 * Returns: the text column, or -1 if it's unset.
4908 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4910 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4912 return icon_view->priv->text_column;
4916 * gtk_icon_view_set_markup_column:
4917 * @icon_view: A #GtkIconView.
4918 * @column: A column in the currently used model.
4920 * Sets the column with markup information for @icon_view to be
4921 * @column. The markup column must be of type #G_TYPE_STRING.
4922 * If the markup column is set to something, it overrides
4923 * the text column set by gtk_icon_view_set_text_column().
4928 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4931 if (column == icon_view->priv->markup_column)
4935 icon_view->priv->markup_column = -1;
4938 if (icon_view->priv->model != NULL)
4942 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4944 g_return_if_fail (column_type == G_TYPE_STRING);
4947 icon_view->priv->markup_column = column;
4950 gtk_icon_view_stop_editing (icon_view, TRUE);
4952 update_text_cell (icon_view);
4954 gtk_icon_view_invalidate_sizes (icon_view);
4955 gtk_icon_view_queue_layout (icon_view);
4957 g_object_notify (G_OBJECT (icon_view), "markup-column");
4961 * gtk_icon_view_get_markup_column:
4962 * @icon_view: A #GtkIconView.
4964 * Returns the column with markup text for @icon_view.
4966 * Returns: the markup column, or -1 if it's unset.
4971 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4973 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4975 return icon_view->priv->markup_column;
4979 * gtk_icon_view_set_pixbuf_column:
4980 * @icon_view: A #GtkIconView.
4981 * @column: A column in the currently used model.
4983 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4984 * column must be of type #GDK_TYPE_PIXBUF
4989 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4992 if (column == icon_view->priv->pixbuf_column)
4996 icon_view->priv->pixbuf_column = -1;
4999 if (icon_view->priv->model != NULL)
5003 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5005 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5008 icon_view->priv->pixbuf_column = column;
5011 gtk_icon_view_stop_editing (icon_view, TRUE);
5013 update_pixbuf_cell (icon_view);
5015 gtk_icon_view_invalidate_sizes (icon_view);
5016 gtk_icon_view_queue_layout (icon_view);
5018 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5023 * gtk_icon_view_get_pixbuf_column:
5024 * @icon_view: A #GtkIconView.
5026 * Returns the column with pixbufs for @icon_view.
5028 * Returns: the pixbuf column, or -1 if it's unset.
5033 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5035 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5037 return icon_view->priv->pixbuf_column;
5041 * gtk_icon_view_select_path:
5042 * @icon_view: A #GtkIconView.
5043 * @path: The #GtkTreePath to be selected.
5045 * Selects the row at @path.
5050 gtk_icon_view_select_path (GtkIconView *icon_view,
5053 GtkIconViewItem *item = NULL;
5055 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5056 g_return_if_fail (icon_view->priv->model != NULL);
5057 g_return_if_fail (path != NULL);
5059 if (gtk_tree_path_get_depth (path) > 0)
5060 item = g_list_nth_data (icon_view->priv->items,
5061 gtk_tree_path_get_indices(path)[0]);
5064 gtk_icon_view_select_item (icon_view, item);
5068 * gtk_icon_view_unselect_path:
5069 * @icon_view: A #GtkIconView.
5070 * @path: The #GtkTreePath to be unselected.
5072 * Unselects the row at @path.
5077 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5080 GtkIconViewItem *item;
5082 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5083 g_return_if_fail (icon_view->priv->model != NULL);
5084 g_return_if_fail (path != NULL);
5086 item = g_list_nth_data (icon_view->priv->items,
5087 gtk_tree_path_get_indices(path)[0]);
5092 gtk_icon_view_unselect_item (icon_view, item);
5096 * gtk_icon_view_get_selected_items:
5097 * @icon_view: A #GtkIconView.
5099 * Creates a list of paths of all selected items. Additionally, if you are
5100 * planning on modifying the model after calling this function, you may
5101 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5102 * To do this, you can use gtk_tree_row_reference_new().
5104 * To free the return value, use:
5105 * <informalexample><programlisting>
5106 * g_list_foreach (list, gtk_tree_path_free, NULL);
5107 * g_list_free (list);
5108 * </programlisting></informalexample>
5110 * Return value: A #GList containing a #GtkTreePath for each selected row.
5115 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5118 GList *selected = NULL;
5120 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5122 for (list = icon_view->priv->items; list != NULL; list = list->next)
5124 GtkIconViewItem *item = list->data;
5128 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5130 selected = g_list_prepend (selected, path);
5138 * gtk_icon_view_select_all:
5139 * @icon_view: A #GtkIconView.
5141 * Selects all the icons. @icon_view must has its selection mode set
5142 * to #GTK_SELECTION_MULTIPLE.
5147 gtk_icon_view_select_all (GtkIconView *icon_view)
5150 gboolean dirty = FALSE;
5152 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5154 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5157 for (items = icon_view->priv->items; items; items = items->next)
5159 GtkIconViewItem *item = items->data;
5161 if (!item->selected)
5164 item->selected = TRUE;
5165 gtk_icon_view_queue_draw_item (icon_view, item);
5170 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5174 * gtk_icon_view_unselect_all:
5175 * @icon_view: A #GtkIconView.
5177 * Unselects all the icons.
5182 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5184 gboolean dirty = FALSE;
5186 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5188 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5191 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5194 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5198 * gtk_icon_view_path_is_selected:
5199 * @icon_view: A #GtkIconView.
5200 * @path: A #GtkTreePath to check selection on.
5202 * Returns %TRUE if the icon pointed to by @path is currently
5203 * selected. If @icon does not point to a valid location, %FALSE is returned.
5205 * Return value: %TRUE if @path is selected.
5210 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5213 GtkIconViewItem *item;
5215 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5216 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5217 g_return_val_if_fail (path != NULL, FALSE);
5219 item = g_list_nth_data (icon_view->priv->items,
5220 gtk_tree_path_get_indices(path)[0]);
5225 return item->selected;
5229 * gtk_icon_view_item_activated:
5230 * @icon_view: A #GtkIconView
5231 * @path: The #GtkTreePath to be activated
5233 * Activates the item determined by @path.
5238 gtk_icon_view_item_activated (GtkIconView *icon_view,
5241 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5242 g_return_if_fail (path != NULL);
5244 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5248 * gtk_icon_view_set_orientation:
5249 * @icon_view: a #GtkIconView
5250 * @orientation: the relative position of texts and icons
5252 * Sets the ::orientation property which determines whether the labels
5253 * are drawn beside the icons instead of below.
5258 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5259 GtkOrientation orientation)
5261 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5263 if (icon_view->priv->orientation != orientation)
5265 icon_view->priv->orientation = orientation;
5267 gtk_icon_view_stop_editing (icon_view, TRUE);
5268 gtk_icon_view_invalidate_sizes (icon_view);
5269 gtk_icon_view_queue_layout (icon_view);
5271 update_text_cell (icon_view);
5272 update_pixbuf_cell (icon_view);
5274 g_object_notify (G_OBJECT (icon_view), "orientation");
5279 * gtk_icon_view_get_orientation:
5280 * @icon_view: a #GtkIconView
5282 * Returns the value of the ::orientation property which determines
5283 * whether the labels are drawn beside the icons instead of below.
5285 * Return value: the relative position of texts and icons
5290 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5292 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5293 GTK_ORIENTATION_VERTICAL);
5295 return icon_view->priv->orientation;
5299 * gtk_icon_view_set_columns:
5300 * @icon_view: a #GtkIconView
5301 * @columns: the number of columns
5303 * Sets the ::columns property which determines in how
5304 * many columns the icons are arranged. If @columns is
5305 * -1, the number of columns will be chosen automatically
5306 * to fill the available area.
5311 gtk_icon_view_set_columns (GtkIconView *icon_view,
5314 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5316 if (icon_view->priv->columns != columns)
5318 icon_view->priv->columns = columns;
5320 gtk_icon_view_stop_editing (icon_view, TRUE);
5321 gtk_icon_view_queue_layout (icon_view);
5323 g_object_notify (G_OBJECT (icon_view), "columns");
5328 * gtk_icon_view_get_columns:
5329 * @icon_view: a #GtkIconView
5331 * Returns the value of the ::columns property.
5333 * Return value: the number of columns, or -1
5338 gtk_icon_view_get_columns (GtkIconView *icon_view)
5340 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5342 return icon_view->priv->columns;
5346 * gtk_icon_view_set_item_width:
5347 * @icon_view: a #GtkIconView
5348 * @item_width: the width for each item
5350 * Sets the ::item-width property which specifies the width
5351 * to use for each item. If it is set to -1, the icon view will
5352 * automatically determine a suitable item size.
5357 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5360 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5362 if (icon_view->priv->item_width != item_width)
5364 icon_view->priv->item_width = item_width;
5366 gtk_icon_view_stop_editing (icon_view, TRUE);
5367 gtk_icon_view_invalidate_sizes (icon_view);
5368 gtk_icon_view_queue_layout (icon_view);
5370 update_text_cell (icon_view);
5372 g_object_notify (G_OBJECT (icon_view), "item-width");
5377 * gtk_icon_view_get_item_width:
5378 * @icon_view: a #GtkIconView
5380 * Returns the value of the ::item-width property.
5382 * Return value: the width of a single item, or -1
5387 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5389 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5391 return icon_view->priv->item_width;
5396 * gtk_icon_view_set_spacing:
5397 * @icon_view: a #GtkIconView
5398 * @spacing: the spacing
5400 * Sets the ::spacing property which specifies the space
5401 * which is inserted between the cells (i.e. the icon and
5402 * the text) of an item.
5407 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5410 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5412 if (icon_view->priv->spacing != spacing)
5414 icon_view->priv->spacing = spacing;
5416 gtk_icon_view_stop_editing (icon_view, TRUE);
5417 gtk_icon_view_invalidate_sizes (icon_view);
5418 gtk_icon_view_queue_layout (icon_view);
5420 g_object_notify (G_OBJECT (icon_view), "spacing");
5425 * gtk_icon_view_get_spacing:
5426 * @icon_view: a #GtkIconView
5428 * Returns the value of the ::spacing property.
5430 * Return value: the space between cells
5435 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5437 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5439 return icon_view->priv->spacing;
5443 * gtk_icon_view_set_row_spacing:
5444 * @icon_view: a #GtkIconView
5445 * @row_spacing: the row spacing
5447 * Sets the ::row-spacing property which specifies the space
5448 * which is inserted between the rows of the icon view.
5453 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5456 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5458 if (icon_view->priv->row_spacing != row_spacing)
5460 icon_view->priv->row_spacing = row_spacing;
5462 gtk_icon_view_stop_editing (icon_view, TRUE);
5463 gtk_icon_view_invalidate_sizes (icon_view);
5464 gtk_icon_view_queue_layout (icon_view);
5466 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5471 * gtk_icon_view_get_row_spacing:
5472 * @icon_view: a #GtkIconView
5474 * Returns the value of the ::row-spacing property.
5476 * Return value: the space between rows
5481 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5483 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5485 return icon_view->priv->row_spacing;
5489 * gtk_icon_view_set_column_spacing:
5490 * @icon_view: a #GtkIconView
5491 * @column_spacing: the column spacing
5493 * Sets the ::column-spacing property which specifies the space
5494 * which is inserted between the columns of the icon view.
5499 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5500 gint column_spacing)
5502 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5504 if (icon_view->priv->column_spacing != column_spacing)
5506 icon_view->priv->column_spacing = column_spacing;
5508 gtk_icon_view_stop_editing (icon_view, TRUE);
5509 gtk_icon_view_invalidate_sizes (icon_view);
5510 gtk_icon_view_queue_layout (icon_view);
5512 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5517 * gtk_icon_view_get_column_spacing:
5518 * @icon_view: a #GtkIconView
5520 * Returns the value of the ::column-spacing property.
5522 * Return value: the space between columns
5527 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5529 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5531 return icon_view->priv->column_spacing;
5535 * gtk_icon_view_set_margin:
5536 * @icon_view: a #GtkIconView
5537 * @margin: the margin
5539 * Sets the ::margin property which specifies the space
5540 * which is inserted at the top, bottom, left and right
5546 gtk_icon_view_set_margin (GtkIconView *icon_view,
5549 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5551 if (icon_view->priv->margin != margin)
5553 icon_view->priv->margin = margin;
5555 gtk_icon_view_stop_editing (icon_view, TRUE);
5556 gtk_icon_view_invalidate_sizes (icon_view);
5557 gtk_icon_view_queue_layout (icon_view);
5559 g_object_notify (G_OBJECT (icon_view), "margin");
5564 * gtk_icon_view_get_margin:
5565 * @icon_view: a #GtkIconView
5567 * Returns the value of the ::margin property.
5569 * Return value: the space at the borders
5574 gtk_icon_view_get_margin (GtkIconView *icon_view)
5576 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5578 return icon_view->priv->margin;
5582 /* Get/set whether drag_motion requested the drag data and
5583 * drag_data_received should thus not actually insert the data,
5584 * since the data doesn't result from a drop.
5587 set_status_pending (GdkDragContext *context,
5588 GdkDragAction suggested_action)
5590 g_object_set_data (G_OBJECT (context),
5591 I_("gtk-icon-view-status-pending"),
5592 GINT_TO_POINTER (suggested_action));
5595 static GdkDragAction
5596 get_status_pending (GdkDragContext *context)
5598 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5599 "gtk-icon-view-status-pending"));
5603 unset_reorderable (GtkIconView *icon_view)
5605 if (icon_view->priv->reorderable)
5607 icon_view->priv->reorderable = FALSE;
5608 g_object_notify (G_OBJECT (icon_view), "reorderable");
5613 clear_source_info (GtkIconView *icon_view)
5615 if (icon_view->priv->source_targets)
5616 gtk_target_list_unref (icon_view->priv->source_targets);
5617 icon_view->priv->source_targets = NULL;
5619 icon_view->priv->source_set = FALSE;
5623 clear_dest_info (GtkIconView *icon_view)
5625 if (icon_view->priv->dest_targets)
5626 gtk_target_list_unref (icon_view->priv->dest_targets);
5627 icon_view->priv->dest_targets = NULL;
5629 icon_view->priv->dest_set = FALSE;
5633 set_source_row (GdkDragContext *context,
5634 GtkTreeModel *model,
5635 GtkTreePath *source_row)
5638 g_object_set_data_full (G_OBJECT (context),
5639 I_("gtk-icon-view-source-row"),
5640 gtk_tree_row_reference_new (model, source_row),
5641 (GDestroyNotify) gtk_tree_row_reference_free);
5643 g_object_set_data_full (G_OBJECT (context),
5644 I_("gtk-icon-view-source-row"),
5649 get_source_row (GdkDragContext *context)
5651 GtkTreeRowReference *ref;
5653 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5656 return gtk_tree_row_reference_get_path (ref);
5663 GtkTreeRowReference *dest_row;
5664 gboolean empty_view_drop;
5665 gboolean drop_append_mode;
5669 dest_row_free (gpointer data)
5671 DestRow *dr = (DestRow *)data;
5673 gtk_tree_row_reference_free (dr->dest_row);
5678 set_dest_row (GdkDragContext *context,
5679 GtkTreeModel *model,
5680 GtkTreePath *dest_row,
5681 gboolean empty_view_drop,
5682 gboolean drop_append_mode)
5688 g_object_set_data_full (G_OBJECT (context),
5689 I_("gtk-icon-view-dest-row"),
5694 dr = g_new0 (DestRow, 1);
5696 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5697 dr->empty_view_drop = empty_view_drop;
5698 dr->drop_append_mode = drop_append_mode;
5699 g_object_set_data_full (G_OBJECT (context),
5700 I_("gtk-icon-view-dest-row"),
5701 dr, (GDestroyNotify) dest_row_free);
5705 get_dest_row (GdkDragContext *context)
5709 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5713 GtkTreePath *path = NULL;
5716 path = gtk_tree_row_reference_get_path (dr->dest_row);
5717 else if (dr->empty_view_drop)
5718 path = gtk_tree_path_new_from_indices (0, -1);
5722 if (path && dr->drop_append_mode)
5723 gtk_tree_path_next (path);
5732 check_model_dnd (GtkTreeModel *model,
5733 GType required_iface,
5734 const gchar *signal)
5736 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5738 g_warning ("You must override the default '%s' handler "
5739 "on GtkIconView when using models that don't support "
5740 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5741 "is to connect to '%s' and call "
5742 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5743 "the default handler from running. Look at the source code "
5744 "for the default handler in gtkiconview.c to get an idea what "
5745 "your handler should do. (gtkiconview.c is in the GTK+ source "
5746 "code.) If you're using GTK+ from a language other than C, "
5747 "there may be a more natural way to override default handlers, e.g. via derivation.",
5748 signal, g_type_name (required_iface), signal);
5756 remove_scroll_timeout (GtkIconView *icon_view)
5758 if (icon_view->priv->scroll_timeout_id != 0)
5760 g_source_remove (icon_view->priv->scroll_timeout_id);
5762 icon_view->priv->scroll_timeout_id = 0;
5767 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5769 gint px, py, x, y, width, height;
5770 gint hoffset, voffset;
5773 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5774 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5776 /* see if we are near the edge. */
5777 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5779 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5781 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5783 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5787 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5788 icon_view->priv->vadjustment->lower,
5789 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5790 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5794 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5795 icon_view->priv->hadjustment->lower,
5796 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5797 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5803 drag_scroll_timeout (gpointer data)
5805 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5807 GDK_THREADS_ENTER ();
5809 gtk_icon_view_autoscroll (icon_view);
5811 GDK_THREADS_LEAVE ();
5818 set_destination (GtkIconView *icon_view,
5819 GdkDragContext *context,
5822 GdkDragAction *suggested_action,
5826 GtkTreePath *path = NULL;
5827 GtkIconViewDropPosition pos;
5828 GtkIconViewDropPosition old_pos;
5829 GtkTreePath *old_dest_path = NULL;
5830 gboolean can_drop = FALSE;
5832 widget = GTK_WIDGET (icon_view);
5834 *suggested_action = 0;
5837 if (!icon_view->priv->dest_set)
5839 /* someone unset us as a drag dest, note that if
5840 * we return FALSE drag_leave isn't called
5843 gtk_icon_view_set_drag_dest_item (icon_view,
5845 GTK_ICON_VIEW_DROP_LEFT);
5847 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5849 return FALSE; /* no longer a drop site */
5852 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5853 if (*target == GDK_NONE)
5856 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5859 GtkTreeModel *model;
5861 /* the row got dropped on empty space, let's setup a special case
5865 gtk_tree_path_free (path);
5867 model = gtk_icon_view_get_model (icon_view);
5869 n_children = gtk_tree_model_iter_n_children (model, NULL);
5872 pos = GTK_ICON_VIEW_DROP_BELOW;
5873 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5877 pos = GTK_ICON_VIEW_DROP_ABOVE;
5878 path = gtk_tree_path_new_from_indices (0, -1);
5888 gtk_icon_view_get_drag_dest_item (icon_view,
5893 gtk_tree_path_free (old_dest_path);
5895 if (TRUE /* FIXME if the location droppable predicate */)
5903 GtkWidget *source_widget;
5905 *suggested_action = context->suggested_action;
5906 source_widget = gtk_drag_get_source_widget (context);
5908 if (source_widget == widget)
5910 /* Default to MOVE, unless the user has
5911 * pressed ctrl or shift to affect available actions
5913 if ((context->actions & GDK_ACTION_MOVE) != 0)
5914 *suggested_action = GDK_ACTION_MOVE;
5917 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5922 /* can't drop here */
5923 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5925 GTK_ICON_VIEW_DROP_LEFT);
5929 gtk_tree_path_free (path);
5935 get_logical_destination (GtkIconView *icon_view,
5936 gboolean *drop_append_mode)
5938 /* adjust path to point to the row the drop goes in front of */
5939 GtkTreePath *path = NULL;
5940 GtkIconViewDropPosition pos;
5942 *drop_append_mode = FALSE;
5944 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5949 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5950 pos == GTK_ICON_VIEW_DROP_BELOW)
5953 GtkTreeModel *model = icon_view->priv->model;
5955 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5956 !gtk_tree_model_iter_next (model, &iter))
5957 *drop_append_mode = TRUE;
5960 *drop_append_mode = FALSE;
5961 gtk_tree_path_next (path);
5969 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5970 GdkEventMotion *event)
5972 GdkDragContext *context;
5973 GtkTreePath *path = NULL;
5975 GtkTreeModel *model;
5976 gboolean retval = FALSE;
5978 if (!icon_view->priv->source_set)
5981 if (icon_view->priv->pressed_button < 0)
5984 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5985 icon_view->priv->press_start_x,
5986 icon_view->priv->press_start_y,
5987 event->x, event->y))
5990 model = gtk_icon_view_get_model (icon_view);
5995 button = icon_view->priv->pressed_button;
5996 icon_view->priv->pressed_button = -1;
5998 path = gtk_icon_view_get_path_at_pos (icon_view,
5999 icon_view->priv->press_start_x,
6000 icon_view->priv->press_start_y);
6005 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6006 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6010 /* FIXME Check whether we're a start button, if not return FALSE and
6014 /* Now we can begin the drag */
6018 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6019 icon_view->priv->source_targets,
6020 icon_view->priv->source_actions,
6024 set_source_row (context, model, path);
6028 gtk_tree_path_free (path);
6033 /* Source side drag signals */
6035 gtk_icon_view_drag_begin (GtkWidget *widget,
6036 GdkDragContext *context)
6038 GtkIconView *icon_view;
6039 GtkIconViewItem *item;
6044 icon_view = GTK_ICON_VIEW (widget);
6046 /* if the user uses a custom DnD impl, we don't set the icon here */
6047 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6050 item = gtk_icon_view_get_item_at_coords (icon_view,
6051 icon_view->priv->press_start_x,
6052 icon_view->priv->press_start_y,
6056 g_return_if_fail (item != NULL);
6058 x = icon_view->priv->press_start_x - item->x + 1;
6059 y = icon_view->priv->press_start_y - item->y + 1;
6061 path = gtk_tree_path_new_from_indices (item->index, -1);
6062 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6063 gtk_tree_path_free (path);
6065 gtk_drag_set_icon_pixmap (context,
6066 gdk_drawable_get_colormap (icon),
6071 g_object_unref (icon);
6075 gtk_icon_view_drag_end (GtkWidget *widget,
6076 GdkDragContext *context)
6082 gtk_icon_view_drag_data_get (GtkWidget *widget,
6083 GdkDragContext *context,
6084 GtkSelectionData *selection_data,
6088 GtkIconView *icon_view;
6089 GtkTreeModel *model;
6090 GtkTreePath *source_row;
6092 icon_view = GTK_ICON_VIEW (widget);
6093 model = gtk_icon_view_get_model (icon_view);
6098 if (!icon_view->priv->dest_set)
6101 source_row = get_source_row (context);
6103 if (source_row == NULL)
6106 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6107 * any model; for DragSource models there are some other targets
6111 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6112 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6117 /* If drag_data_get does nothing, try providing row data. */
6118 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6119 gtk_tree_set_row_drag_data (selection_data,
6124 gtk_tree_path_free (source_row);
6128 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6129 GdkDragContext *context)
6131 GtkTreeModel *model;
6132 GtkIconView *icon_view;
6133 GtkTreePath *source_row;
6135 icon_view = GTK_ICON_VIEW (widget);
6136 model = gtk_icon_view_get_model (icon_view);
6138 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6141 if (!icon_view->priv->dest_set)
6144 source_row = get_source_row (context);
6146 if (source_row == NULL)
6149 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6152 gtk_tree_path_free (source_row);
6154 set_source_row (context, NULL, NULL);
6157 /* Target side drag signals */
6159 gtk_icon_view_drag_leave (GtkWidget *widget,
6160 GdkDragContext *context,
6163 GtkIconView *icon_view;
6165 icon_view = GTK_ICON_VIEW (widget);
6167 /* unset any highlight row */
6168 gtk_icon_view_set_drag_dest_item (icon_view,
6170 GTK_ICON_VIEW_DROP_LEFT);
6172 remove_scroll_timeout (icon_view);
6176 gtk_icon_view_drag_motion (GtkWidget *widget,
6177 GdkDragContext *context,
6182 GtkTreePath *path = NULL;
6183 GtkIconViewDropPosition pos;
6184 GtkIconView *icon_view;
6185 GdkDragAction suggested_action = 0;
6189 icon_view = GTK_ICON_VIEW (widget);
6191 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6194 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6196 /* we only know this *after* set_desination_row */
6197 empty = icon_view->priv->empty_view_drop;
6199 if (path == NULL && !empty)
6201 /* Can't drop here. */
6202 gdk_drag_status (context, 0, time);
6206 if (icon_view->priv->scroll_timeout_id == 0)
6208 icon_view->priv->scroll_timeout_id =
6209 g_timeout_add (50, drag_scroll_timeout, icon_view);
6212 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6214 /* Request data so we can use the source row when
6215 * determining whether to accept the drop
6217 set_status_pending (context, suggested_action);
6218 gtk_drag_get_data (widget, context, target, time);
6222 set_status_pending (context, 0);
6223 gdk_drag_status (context, suggested_action, time);
6228 gtk_tree_path_free (path);
6234 gtk_icon_view_drag_drop (GtkWidget *widget,
6235 GdkDragContext *context,
6240 GtkIconView *icon_view;
6242 GdkDragAction suggested_action = 0;
6243 GdkAtom target = GDK_NONE;
6244 GtkTreeModel *model;
6245 gboolean drop_append_mode;
6247 icon_view = GTK_ICON_VIEW (widget);
6248 model = gtk_icon_view_get_model (icon_view);
6250 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6252 if (!icon_view->priv->dest_set)
6255 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6258 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6261 path = get_logical_destination (icon_view, &drop_append_mode);
6263 if (target != GDK_NONE && path != NULL)
6265 /* in case a motion had requested drag data, change things so we
6266 * treat drag data receives as a drop.
6268 set_status_pending (context, 0);
6269 set_dest_row (context, model, path,
6270 icon_view->priv->empty_view_drop, drop_append_mode);
6274 gtk_tree_path_free (path);
6276 /* Unset this thing */
6277 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6279 if (target != GDK_NONE)
6281 gtk_drag_get_data (widget, context, target, time);
6289 gtk_icon_view_drag_data_received (GtkWidget *widget,
6290 GdkDragContext *context,
6293 GtkSelectionData *selection_data,
6298 gboolean accepted = FALSE;
6299 GtkTreeModel *model;
6300 GtkIconView *icon_view;
6301 GtkTreePath *dest_row;
6302 GdkDragAction suggested_action;
6303 gboolean drop_append_mode;
6305 icon_view = GTK_ICON_VIEW (widget);
6306 model = gtk_icon_view_get_model (icon_view);
6308 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6311 if (!icon_view->priv->dest_set)
6314 suggested_action = get_status_pending (context);
6316 if (suggested_action)
6318 /* We are getting this data due to a request in drag_motion,
6319 * rather than due to a request in drag_drop, so we are just
6320 * supposed to call drag_status, not actually paste in the
6323 path = get_logical_destination (icon_view, &drop_append_mode);
6326 suggested_action = 0;
6328 if (suggested_action)
6330 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6333 suggested_action = 0;
6336 gdk_drag_status (context, suggested_action, time);
6339 gtk_tree_path_free (path);
6341 /* If you can't drop, remove user drop indicator until the next motion */
6342 if (suggested_action == 0)
6343 gtk_icon_view_set_drag_dest_item (icon_view,
6345 GTK_ICON_VIEW_DROP_LEFT);
6350 dest_row = get_dest_row (context);
6352 if (dest_row == NULL)
6355 if (selection_data->length >= 0)
6357 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6363 gtk_drag_finish (context,
6365 (context->action == GDK_ACTION_MOVE),
6368 gtk_tree_path_free (dest_row);
6371 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6374 /* Drag-and-Drop support */
6376 * gtk_icon_view_enable_model_drag_source:
6377 * @icon_view: a #GtkIconTreeView
6378 * @start_button_mask: Mask of allowed buttons to start drag
6379 * @targets: the table of targets that the drag will support
6380 * @n_targets: the number of items in @targets
6381 * @actions: the bitmask of possible actions for a drag from this
6384 * Turns @icon_view into a drag source for automatic DND.
6389 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6390 GdkModifierType start_button_mask,
6391 const GtkTargetEntry *targets,
6393 GdkDragAction actions)
6395 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6397 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6399 clear_source_info (icon_view);
6400 icon_view->priv->start_button_mask = start_button_mask;
6401 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6402 icon_view->priv->source_actions = actions;
6404 icon_view->priv->source_set = TRUE;
6406 unset_reorderable (icon_view);
6410 * gtk_icon_view_enable_model_drag_dest:
6411 * @icon_view: a #GtkIconView
6412 * @targets: the table of targets that the drag will support
6413 * @n_targets: the number of items in @targets
6414 * @actions: the bitmask of possible actions for a drag from this
6417 * Turns @icon_view into a drop destination for automatic DND.
6422 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6423 const GtkTargetEntry *targets,
6425 GdkDragAction actions)
6427 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6429 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6431 clear_dest_info (icon_view);
6433 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6434 icon_view->priv->dest_actions = actions;
6436 icon_view->priv->dest_set = TRUE;
6438 unset_reorderable (icon_view);
6442 * gtk_icon_view_unset_model_drag_source:
6443 * @icon_view: a #GtkIconView
6445 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6450 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6452 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6454 if (icon_view->priv->source_set)
6456 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6457 clear_source_info (icon_view);
6460 unset_reorderable (icon_view);
6464 * gtk_icon_view_unset_model_drag_dest:
6465 * @icon_view: a #GtkIconView
6467 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6472 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6474 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6476 if (icon_view->priv->dest_set)
6478 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6479 clear_dest_info (icon_view);
6482 unset_reorderable (icon_view);
6485 /* These are useful to implement your own custom stuff. */
6487 * gtk_icon_view_set_drag_dest_item:
6488 * @icon_view: a #GtkIconView
6489 * @path: The path of the item to highlight, or %NULL.
6490 * @pos: Specifies where to drop, relative to the item
6492 * Sets the item that is highlighted for feedback.
6497 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6499 GtkIconViewDropPosition pos)
6501 /* Note; this function is exported to allow a custom DND
6502 * implementation, so it can't touch TreeViewDragInfo
6505 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6507 if (icon_view->priv->dest_item)
6509 GtkTreePath *current_path;
6510 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6511 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6512 icon_view->priv->dest_item = NULL;
6514 gtk_icon_view_queue_draw_path (icon_view, current_path);
6515 gtk_tree_path_free (current_path);
6518 /* special case a drop on an empty model */
6519 icon_view->priv->empty_view_drop = FALSE;
6520 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6521 && gtk_tree_path_get_depth (path) == 1
6522 && gtk_tree_path_get_indices (path)[0] == 0)
6526 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6529 if (n_children == 0)
6530 icon_view->priv->empty_view_drop = TRUE;
6533 icon_view->priv->dest_pos = pos;
6537 icon_view->priv->dest_item =
6538 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6539 icon_view->priv->model, path);
6541 gtk_icon_view_queue_draw_path (icon_view, path);
6546 * gtk_icon_view_get_drag_dest_item:
6547 * @icon_view: a #GtkIconView
6548 * @path: Return location for the path of the highlighted item, or %NULL.
6549 * @pos: Return location for the drop position, or %NULL
6551 * Gets information about the item that is highlighted for feedback.
6556 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6558 GtkIconViewDropPosition *pos)
6560 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6564 if (icon_view->priv->dest_item)
6565 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6571 *pos = icon_view->priv->dest_pos;
6575 * gtk_icon_view_get_dest_item_at_pos:
6576 * @icon_view: a #GtkIconView
6577 * @drag_x: the position to determine the destination item for
6578 * @drag_y: the position to determine the destination item for
6579 * @path: Return location for the path of the item, or %NULL.
6580 * @pos: Return location for the drop position, or %NULL
6582 * Determines the destination item for a given position.
6584 * Return value: whether there is an item at the given position.
6589 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6593 GtkIconViewDropPosition *pos)
6595 GtkIconViewItem *item;
6597 /* Note; this function is exported to allow a custom DND
6598 * implementation, so it can't touch TreeViewDragInfo
6601 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6602 g_return_val_if_fail (drag_x >= 0, FALSE);
6603 g_return_val_if_fail (drag_y >= 0, FALSE);
6604 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6610 item = gtk_icon_view_get_item_at_coords (icon_view,
6611 drag_x + icon_view->priv->hadjustment->value,
6612 drag_y + icon_view->priv->vadjustment->value,
6619 *path = gtk_tree_path_new_from_indices (item->index, -1);
6623 if (drag_x < item->x + item->width / 4)
6624 *pos = GTK_ICON_VIEW_DROP_LEFT;
6625 else if (drag_x > item->x + item->width * 3 / 4)
6626 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6627 else if (drag_y < item->y + item->height / 4)
6628 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6629 else if (drag_y > item->y + item->height * 3 / 4)
6630 *pos = GTK_ICON_VIEW_DROP_BELOW;
6632 *pos = GTK_ICON_VIEW_DROP_INTO;
6639 * gtk_icon_view_create_drag_icon:
6640 * @icon_view: a #GtkIconView
6641 * @path: a #GtkTreePath in @icon_view
6643 * Creates a #GdkPixmap representation of the item at @path.
6644 * This image is used for a drag icon.
6646 * Return value: a newly-allocated pixmap of the drag icon.
6651 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6656 GdkPixmap *drawable;
6661 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6662 g_return_val_if_fail (path != NULL, NULL);
6664 widget = GTK_WIDGET (icon_view);
6666 if (!GTK_WIDGET_REALIZED (widget))
6669 index = gtk_tree_path_get_indices (path)[0];
6671 for (l = icon_view->priv->items; l; l = l->next)
6673 GtkIconViewItem *item = l->data;
6675 if (index == item->index)
6677 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6682 cr = gdk_cairo_create (drawable);
6683 cairo_set_line_width (cr, 1.);
6685 gdk_cairo_set_source_color
6686 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6687 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6692 area.width = item->width;
6693 area.height = item->height;
6695 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6696 drawable, 1, 1, FALSE);
6698 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6699 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6712 * gtk_icon_view_get_reorderable:
6713 * @icon_view: a #GtkIconView
6715 * Retrieves whether the user can reorder the list via drag-and-drop.
6716 * See gtk_icon_view_set_reorderable().
6718 * Return value: %TRUE if the list can be reordered.
6723 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6725 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6727 return icon_view->priv->reorderable;
6730 static const GtkTargetEntry item_targets[] = {
6731 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6736 * gtk_icon_view_set_reorderable:
6737 * @icon_view: A #GtkIconView.
6738 * @reorderable: %TRUE, if the list of items can be reordered.
6740 * This function is a convenience function to allow you to reorder models that
6741 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6742 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6743 * the user can reorder the model by dragging and dropping rows. The
6744 * developer can listen to these changes by connecting to the model's
6745 * row_inserted and row_deleted signals.
6747 * This function does not give you any degree of control over the order -- any
6748 * reordering is allowed. If more control is needed, you should probably
6749 * handle drag and drop manually.
6754 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6755 gboolean reorderable)
6757 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6759 reorderable = reorderable != FALSE;
6761 if (icon_view->priv->reorderable == reorderable)
6766 gtk_icon_view_enable_model_drag_source (icon_view,
6769 G_N_ELEMENTS (item_targets),
6771 gtk_icon_view_enable_model_drag_dest (icon_view,
6773 G_N_ELEMENTS (item_targets),
6778 gtk_icon_view_unset_model_drag_source (icon_view);
6779 gtk_icon_view_unset_model_drag_dest (icon_view);
6782 icon_view->priv->reorderable = reorderable;
6784 g_object_notify (G_OBJECT (icon_view), "reorderable");
6788 /* Accessibility Support */
6790 static gpointer accessible_parent_class;
6791 static gpointer accessible_item_parent_class;
6792 static GQuark accessible_private_data_quark = 0;
6794 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6795 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6796 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6798 static GType gtk_icon_view_item_accessible_get_type (void);
6809 GtkIconViewItem *item;
6813 AtkStateSet *state_set;
6817 GtkTextBuffer *text_buffer;
6819 gchar *action_descriptions[LAST_ACTION];
6820 gchar *image_description;
6821 guint action_idle_handler;
6822 } GtkIconViewItemAccessible;
6824 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6830 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6835 typedef struct _GtkIconViewItemAccessibleClass
6837 AtkObjectClass parent_class;
6839 } GtkIconViewItemAccessibleClass;
6841 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6844 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6846 GtkIconViewItemAccessible *item;
6847 GtkIconView *icon_view;
6850 GDK_THREADS_ENTER ();
6852 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6853 item->action_idle_handler = 0;
6855 if (item->widget != NULL)
6857 icon_view = GTK_ICON_VIEW (item->widget);
6858 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6859 gtk_icon_view_item_activated (icon_view, path);
6860 gtk_tree_path_free (path);
6863 GDK_THREADS_LEAVE ();
6869 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6872 GtkIconViewItemAccessible *item;
6874 if (i < 0 || i >= LAST_ACTION)
6877 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6879 if (!GTK_IS_ICON_VIEW (item->widget))
6882 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6887 case ACTION_ACTIVATE:
6888 if (!item->action_idle_handler)
6889 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6892 g_assert_not_reached ();
6900 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6905 static const gchar *
6906 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6909 GtkIconViewItemAccessible *item;
6911 if (i < 0 || i >= LAST_ACTION)
6914 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6916 if (item->action_descriptions[i])
6917 return item->action_descriptions[i];
6919 return gtk_icon_view_item_accessible_action_descriptions[i];
6922 static const gchar *
6923 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6926 if (i < 0 || i >= LAST_ACTION)
6929 return gtk_icon_view_item_accessible_action_names[i];
6933 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6935 const gchar *description)
6937 GtkIconViewItemAccessible *item;
6939 if (i < 0 || i >= LAST_ACTION)
6942 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6944 if (item->action_descriptions[i])
6945 g_free (item->action_descriptions[i]);
6947 item->action_descriptions[i] = g_strdup (description);
6953 atk_action_item_interface_init (AtkActionIface *iface)
6955 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6956 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6957 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6958 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6959 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6962 static const gchar *
6963 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6965 GtkIconViewItemAccessible *item;
6967 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6969 return item->image_description;
6973 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6974 const gchar *description)
6976 GtkIconViewItemAccessible *item;
6978 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6980 g_free (item->image_description);
6981 item->image_description = g_strdup (item->image_description);
6987 get_pixbuf_box (GtkIconView *icon_view,
6988 GtkIconViewItem *item,
6993 for (l = icon_view->priv->cell_list; l; l = l->next)
6995 GtkIconViewCellInfo *info = l->data;
6997 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6999 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7009 get_text (GtkIconView *icon_view,
7010 GtkIconViewItem *item)
7015 for (l = icon_view->priv->cell_list; l; l = l->next)
7017 GtkIconViewCellInfo *info = l->data;
7019 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7021 g_object_get (info->cell, "text", &text, NULL);
7031 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7035 GtkIconViewItemAccessible *item;
7038 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7040 if (!GTK_IS_ICON_VIEW (item->widget))
7043 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7046 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7049 *height = box.height;
7054 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7057 AtkCoordType coord_type)
7059 GtkIconViewItemAccessible *item;
7062 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7064 if (!GTK_IS_ICON_VIEW (item->widget))
7067 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7070 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7072 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7074 *x+= box.x - item->item->x;
7075 *y+= box.y - item->item->y;
7081 atk_image_item_interface_init (AtkImageIface *iface)
7083 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7084 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7085 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7086 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7090 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7094 GtkIconViewItemAccessible *item;
7095 GtkTextIter start, end;
7096 GtkTextBuffer *buffer;
7098 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7100 if (!GTK_IS_ICON_VIEW (item->widget))
7103 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7106 buffer = item->text_buffer;
7107 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7109 gtk_text_buffer_get_end_iter (buffer, &end);
7111 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7113 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7117 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7120 GtkIconViewItemAccessible *item;
7121 GtkTextIter start, end;
7122 GtkTextBuffer *buffer;
7126 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7128 if (!GTK_IS_ICON_VIEW (item->widget))
7131 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7134 buffer = item->text_buffer;
7135 if (offset >= gtk_text_buffer_get_char_count (buffer))
7138 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7140 gtk_text_iter_forward_char (&end);
7141 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7142 unichar = g_utf8_get_char (string);
7150 get_pango_text_offsets (PangoLayout *layout,
7151 GtkTextBuffer *buffer,
7153 AtkTextBoundary boundary_type,
7157 GtkTextIter *start_iter,
7158 GtkTextIter *end_iter)
7160 PangoLayoutIter *iter;
7161 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7162 gint index, start_index, end_index;
7164 gboolean found = FALSE;
7166 text = pango_layout_get_text (layout);
7167 index = g_utf8_offset_to_pointer (text, offset) - text;
7168 iter = pango_layout_get_iter (layout);
7171 line = pango_layout_iter_get_line (iter);
7172 start_index = line->start_index;
7173 end_index = start_index + line->length;
7175 if (index >= start_index && index <= end_index)
7178 * Found line for offset
7184 * We want the previous line
7188 switch (boundary_type)
7190 case ATK_TEXT_BOUNDARY_LINE_START:
7191 end_index = start_index;
7192 start_index = prev_line->start_index;
7194 case ATK_TEXT_BOUNDARY_LINE_END:
7196 start_index = prev_prev_line->start_index +
7197 prev_prev_line->length;
7198 end_index = prev_line->start_index + prev_line->length;
7201 g_assert_not_reached();
7205 start_index = end_index = 0;
7208 switch (boundary_type)
7210 case ATK_TEXT_BOUNDARY_LINE_START:
7211 if (pango_layout_iter_next_line (iter))
7212 end_index = pango_layout_iter_get_line (iter)->start_index;
7214 case ATK_TEXT_BOUNDARY_LINE_END:
7216 start_index = prev_line->start_index +
7220 g_assert_not_reached();
7225 * We want the next line
7227 if (pango_layout_iter_next_line (iter))
7229 line = pango_layout_iter_get_line (iter);
7230 switch (boundary_type)
7232 case ATK_TEXT_BOUNDARY_LINE_START:
7233 start_index = line->start_index;
7234 if (pango_layout_iter_next_line (iter))
7235 end_index = pango_layout_iter_get_line (iter)->start_index;
7237 end_index = start_index + line->length;
7239 case ATK_TEXT_BOUNDARY_LINE_END:
7240 start_index = end_index;
7241 end_index = line->start_index + line->length;
7244 g_assert_not_reached();
7248 start_index = end_index;
7254 prev_prev_line = prev_line;
7257 while (pango_layout_iter_next_line (iter));
7261 start_index = prev_line->start_index + prev_line->length;
7262 end_index = start_index;
7264 pango_layout_iter_free (iter);
7265 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7266 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7268 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7269 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7274 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7276 AtkTextBoundary boundary_type,
7280 GtkIconViewItemAccessible *item;
7281 GtkTextIter start, end;
7282 GtkTextBuffer *buffer;
7284 GtkIconView *icon_view;
7287 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7289 if (!GTK_IS_ICON_VIEW (item->widget))
7292 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7295 buffer = item->text_buffer;
7297 if (!gtk_text_buffer_get_char_count (buffer))
7301 return g_strdup ("");
7303 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7307 switch (boundary_type)
7309 case ATK_TEXT_BOUNDARY_CHAR:
7310 gtk_text_iter_backward_char(&start);
7312 case ATK_TEXT_BOUNDARY_WORD_START:
7313 if (!gtk_text_iter_starts_word (&start))
7314 gtk_text_iter_backward_word_start (&start);
7316 gtk_text_iter_backward_word_start(&start);
7318 case ATK_TEXT_BOUNDARY_WORD_END:
7319 if (gtk_text_iter_inside_word (&start) &&
7320 !gtk_text_iter_starts_word (&start))
7321 gtk_text_iter_backward_word_start (&start);
7322 while (!gtk_text_iter_ends_word (&start))
7324 if (!gtk_text_iter_backward_char (&start))
7328 gtk_text_iter_backward_word_start(&start);
7329 while (!gtk_text_iter_ends_word (&start))
7331 if (!gtk_text_iter_backward_char (&start))
7335 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7336 if (!gtk_text_iter_starts_sentence (&start))
7337 gtk_text_iter_backward_sentence_start (&start);
7339 gtk_text_iter_backward_sentence_start (&start);
7341 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7342 if (gtk_text_iter_inside_sentence (&start) &&
7343 !gtk_text_iter_starts_sentence (&start))
7344 gtk_text_iter_backward_sentence_start (&start);
7345 while (!gtk_text_iter_ends_sentence (&start))
7347 if (!gtk_text_iter_backward_char (&start))
7351 gtk_text_iter_backward_sentence_start (&start);
7352 while (!gtk_text_iter_ends_sentence (&start))
7354 if (!gtk_text_iter_backward_char (&start))
7358 case ATK_TEXT_BOUNDARY_LINE_START:
7359 case ATK_TEXT_BOUNDARY_LINE_END:
7361 icon_view = GTK_ICON_VIEW (item->widget);
7362 /* FIXME we probably have to use GailTextCell to salvage this */
7363 gtk_icon_view_update_item_text (icon_view, item->item);
7364 get_pango_text_offsets (icon_view->priv->layout,
7377 *start_offset = gtk_text_iter_get_offset (&start);
7378 *end_offset = gtk_text_iter_get_offset (&end);
7380 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7384 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7386 AtkTextBoundary boundary_type,
7390 GtkIconViewItemAccessible *item;
7391 GtkTextIter start, end;
7392 GtkTextBuffer *buffer;
7394 GtkIconView *icon_view;
7397 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7399 if (!GTK_IS_ICON_VIEW (item->widget))
7402 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7405 buffer = item->text_buffer;
7407 if (!gtk_text_buffer_get_char_count (buffer))
7411 return g_strdup ("");
7413 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7417 switch (boundary_type)
7419 case ATK_TEXT_BOUNDARY_CHAR:
7420 gtk_text_iter_forward_char (&end);
7422 case ATK_TEXT_BOUNDARY_WORD_START:
7423 if (!gtk_text_iter_starts_word (&start))
7424 gtk_text_iter_backward_word_start (&start);
7425 if (gtk_text_iter_inside_word (&end))
7426 gtk_text_iter_forward_word_end (&end);
7427 while (!gtk_text_iter_starts_word (&end))
7429 if (!gtk_text_iter_forward_char (&end))
7433 case ATK_TEXT_BOUNDARY_WORD_END:
7434 if (gtk_text_iter_inside_word (&start) &&
7435 !gtk_text_iter_starts_word (&start))
7436 gtk_text_iter_backward_word_start (&start);
7437 while (!gtk_text_iter_ends_word (&start))
7439 if (!gtk_text_iter_backward_char (&start))
7442 gtk_text_iter_forward_word_end (&end);
7444 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7445 if (!gtk_text_iter_starts_sentence (&start))
7446 gtk_text_iter_backward_sentence_start (&start);
7447 if (gtk_text_iter_inside_sentence (&end))
7448 gtk_text_iter_forward_sentence_end (&end);
7449 while (!gtk_text_iter_starts_sentence (&end))
7451 if (!gtk_text_iter_forward_char (&end))
7455 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7456 if (gtk_text_iter_inside_sentence (&start) &&
7457 !gtk_text_iter_starts_sentence (&start))
7458 gtk_text_iter_backward_sentence_start (&start);
7459 while (!gtk_text_iter_ends_sentence (&start))
7461 if (!gtk_text_iter_backward_char (&start))
7464 gtk_text_iter_forward_sentence_end (&end);
7466 case ATK_TEXT_BOUNDARY_LINE_START:
7467 case ATK_TEXT_BOUNDARY_LINE_END:
7469 icon_view = GTK_ICON_VIEW (item->widget);
7470 /* FIXME we probably have to use GailTextCell to salvage this */
7471 gtk_icon_view_update_item_text (icon_view, item->item);
7472 get_pango_text_offsets (icon_view->priv->layout,
7486 *start_offset = gtk_text_iter_get_offset (&start);
7487 *end_offset = gtk_text_iter_get_offset (&end);
7489 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7493 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7495 AtkTextBoundary boundary_type,
7499 GtkIconViewItemAccessible *item;
7500 GtkTextIter start, end;
7501 GtkTextBuffer *buffer;
7503 GtkIconView *icon_view;
7506 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7508 if (!GTK_IS_ICON_VIEW (item->widget))
7511 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7514 buffer = item->text_buffer;
7516 if (!gtk_text_buffer_get_char_count (buffer))
7520 return g_strdup ("");
7522 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7526 switch (boundary_type)
7528 case ATK_TEXT_BOUNDARY_CHAR:
7529 gtk_text_iter_forward_char(&start);
7530 gtk_text_iter_forward_chars(&end, 2);
7532 case ATK_TEXT_BOUNDARY_WORD_START:
7533 if (gtk_text_iter_inside_word (&end))
7534 gtk_text_iter_forward_word_end (&end);
7535 while (!gtk_text_iter_starts_word (&end))
7537 if (!gtk_text_iter_forward_char (&end))
7541 if (!gtk_text_iter_is_end (&end))
7543 gtk_text_iter_forward_word_end (&end);
7544 while (!gtk_text_iter_starts_word (&end))
7546 if (!gtk_text_iter_forward_char (&end))
7551 case ATK_TEXT_BOUNDARY_WORD_END:
7552 gtk_text_iter_forward_word_end (&end);
7554 if (!gtk_text_iter_is_end (&end))
7555 gtk_text_iter_forward_word_end (&end);
7557 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7558 if (gtk_text_iter_inside_sentence (&end))
7559 gtk_text_iter_forward_sentence_end (&end);
7560 while (!gtk_text_iter_starts_sentence (&end))
7562 if (!gtk_text_iter_forward_char (&end))
7566 if (!gtk_text_iter_is_end (&end))
7568 gtk_text_iter_forward_sentence_end (&end);
7569 while (!gtk_text_iter_starts_sentence (&end))
7571 if (!gtk_text_iter_forward_char (&end))
7576 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7577 gtk_text_iter_forward_sentence_end (&end);
7579 if (!gtk_text_iter_is_end (&end))
7580 gtk_text_iter_forward_sentence_end (&end);
7582 case ATK_TEXT_BOUNDARY_LINE_START:
7583 case ATK_TEXT_BOUNDARY_LINE_END:
7585 icon_view = GTK_ICON_VIEW (item->widget);
7586 /* FIXME we probably have to use GailTextCell to salvage this */
7587 gtk_icon_view_update_item_text (icon_view, item->item);
7588 get_pango_text_offsets (icon_view->priv->layout,
7600 *start_offset = gtk_text_iter_get_offset (&start);
7601 *end_offset = gtk_text_iter_get_offset (&end);
7603 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7607 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7609 GtkIconViewItemAccessible *item;
7611 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7613 if (!GTK_IS_ICON_VIEW (item->widget))
7616 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7619 return gtk_text_buffer_get_char_count (item->text_buffer);
7623 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7629 AtkCoordType coord_type)
7631 GtkIconViewItemAccessible *item;
7633 GtkIconView *icon_view;
7634 PangoRectangle char_rect;
7635 const gchar *item_text;
7639 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7641 if (!GTK_IS_ICON_VIEW (item->widget))
7644 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7648 icon_view = GTK_ICON_VIEW (item->widget);
7649 /* FIXME we probably have to use GailTextCell to salvage this */
7650 gtk_icon_view_update_item_text (icon_view, item->item);
7651 item_text = pango_layout_get_text (icon_view->priv->layout);
7652 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7653 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7655 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7656 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7657 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7658 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7659 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7660 *width = char_rect.width / PANGO_SCALE;
7661 *height = char_rect.height / PANGO_SCALE;
7666 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7669 AtkCoordType coord_type)
7671 GtkIconViewItemAccessible *item;
7674 GtkIconView *icon_view;
7675 const gchar *item_text;
7680 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7682 if (!GTK_IS_ICON_VIEW (item->widget))
7685 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7689 icon_view = GTK_ICON_VIEW (item->widget);
7690 /* FIXME we probably have to use GailTextCell to salvage this */
7691 gtk_icon_view_update_item_text (icon_view, item->item);
7692 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7693 x -= l_x + item->item->layout_x - item->item->x;
7694 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7695 y -= l_y + item->item->layout_y - item->item->y;
7696 item_text = pango_layout_get_text (icon_view->priv->layout);
7697 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7708 offset = g_utf8_strlen (item_text, -1);
7710 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7716 atk_text_item_interface_init (AtkTextIface *iface)
7718 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7719 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7720 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7721 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7722 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7723 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7724 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7725 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7729 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7734 AtkCoordType coord_type)
7736 GtkIconViewItemAccessible *item;
7737 AtkObject *parent_obj;
7740 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7742 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7743 if (!GTK_IS_WIDGET (item->widget))
7746 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7749 *width = item->item->width;
7750 *height = item->item->height;
7751 if (gtk_icon_view_item_accessible_is_showing (item))
7753 parent_obj = gtk_widget_get_accessible (item->widget);
7754 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7755 *x = l_x + item->item->x;
7756 *y = l_y + item->item->y;
7766 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7768 GtkIconViewItemAccessible *item;
7769 GtkWidget *toplevel;
7771 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7773 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7774 if (!GTK_IS_WIDGET (item->widget))
7777 gtk_widget_grab_focus (item->widget);
7778 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7779 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7780 if (GTK_WIDGET_TOPLEVEL (toplevel))
7781 gtk_window_present (GTK_WINDOW (toplevel));
7787 atk_component_item_interface_init (AtkComponentIface *iface)
7789 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7790 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7794 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7795 AtkStateType state_type,
7796 gboolean emit_signal)
7800 rc = atk_state_set_add_state (item->state_set, state_type);
7802 * The signal should only be generated if the value changed,
7803 * not when the item is set up. So states that are set
7804 * initially should pass FALSE as the emit_signal argument.
7809 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7810 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7811 if (state_type == ATK_STATE_VISIBLE)
7812 g_signal_emit_by_name (item, "visible_data_changed");
7819 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7820 AtkStateType state_type,
7821 gboolean emit_signal)
7823 if (atk_state_set_contains_state (item->state_set, state_type))
7827 rc = atk_state_set_remove_state (item->state_set, state_type);
7829 * The signal should only be generated if the value changed,
7830 * not when the item is set up. So states that are set
7831 * initially should pass FALSE as the emit_signal argument.
7836 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7837 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7838 if (state_type == ATK_STATE_VISIBLE)
7839 g_signal_emit_by_name (item, "visible_data_changed");
7849 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7851 GtkIconView *icon_view;
7852 GdkRectangle visible_rect;
7853 gboolean is_showing;
7856 * An item is considered "SHOWING" if any part of the item is in the
7857 * visible rectangle.
7860 if (!GTK_IS_ICON_VIEW (item->widget))
7863 if (item->item == NULL)
7866 icon_view = GTK_ICON_VIEW (item->widget);
7868 if (icon_view->priv->hadjustment)
7869 visible_rect.x += icon_view->priv->hadjustment->value;
7871 if (icon_view->priv->hadjustment)
7872 visible_rect.y += icon_view->priv->vadjustment->value;
7873 visible_rect.width = item->widget->allocation.width;
7874 visible_rect.height = item->widget->allocation.height;
7876 if (((item->item->x + item->item->width) < visible_rect.x) ||
7877 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7878 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7879 (item->item->y > (visible_rect.y + visible_rect.height)))
7888 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7889 gboolean emit_signal)
7891 if (gtk_icon_view_item_accessible_is_showing (item))
7892 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7895 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7900 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7904 item->state_set = atk_state_set_new ();
7906 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7907 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7908 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7909 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7910 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7912 for (i = 0; i < LAST_ACTION; i++)
7913 item->action_descriptions[i] = NULL;
7915 item->image_description = NULL;
7917 item->action_idle_handler = 0;
7921 gtk_icon_view_item_accessible_finalize (GObject *object)
7923 GtkIconViewItemAccessible *item;
7926 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7928 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7931 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7933 if (item->state_set)
7934 g_object_unref (item->state_set);
7936 if (item->text_buffer)
7937 g_object_unref (item->text_buffer);
7939 for (i = 0; i < LAST_ACTION; i++)
7940 g_free (item->action_descriptions[i]);
7942 g_free (item->image_description);
7944 if (item->action_idle_handler)
7946 g_source_remove (item->action_idle_handler);
7947 item->action_idle_handler = 0;
7950 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7953 static G_CONST_RETURN gchar*
7954 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7960 GtkIconViewItemAccessible *item;
7961 GtkTextIter start_iter;
7962 GtkTextIter end_iter;
7964 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7966 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7967 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7969 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7974 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7976 GtkIconViewItemAccessible *item;
7978 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7979 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7982 return gtk_widget_get_accessible (item->widget);
7988 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7990 GtkIconViewItemAccessible *item;
7992 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7993 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7995 return item->item->index;
7998 static AtkStateSet *
7999 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8001 GtkIconViewItemAccessible *item;
8002 GtkIconView *icon_view;
8004 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8005 g_return_val_if_fail (item->state_set, NULL);
8010 icon_view = GTK_ICON_VIEW (item->widget);
8011 if (icon_view->priv->cursor_item == item->item)
8012 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8014 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8016 return g_object_ref (item->state_set);
8020 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8022 GObjectClass *gobject_class;
8024 accessible_item_parent_class = g_type_class_peek_parent (klass);
8026 gobject_class = (GObjectClass *)klass;
8028 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8030 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8031 klass->get_name = gtk_icon_view_item_accessible_get_name;
8032 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8033 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8037 gtk_icon_view_item_accessible_get_type (void)
8039 static GType type = 0;
8043 static const GTypeInfo tinfo =
8045 sizeof (GtkIconViewItemAccessibleClass),
8046 (GBaseInitFunc) NULL, /* base init */
8047 (GBaseFinalizeFunc) NULL, /* base finalize */
8048 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8049 (GClassFinalizeFunc) NULL, /* class finalize */
8050 NULL, /* class data */
8051 sizeof (GtkIconViewItemAccessible), /* instance size */
8052 0, /* nb preallocs */
8053 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8054 NULL /* value table */
8057 static const GInterfaceInfo atk_component_info =
8059 (GInterfaceInitFunc) atk_component_item_interface_init,
8060 (GInterfaceFinalizeFunc) NULL,
8063 static const GInterfaceInfo atk_action_info =
8065 (GInterfaceInitFunc) atk_action_item_interface_init,
8066 (GInterfaceFinalizeFunc) NULL,
8069 static const GInterfaceInfo atk_image_info =
8071 (GInterfaceInitFunc) atk_image_item_interface_init,
8072 (GInterfaceFinalizeFunc) NULL,
8075 static const GInterfaceInfo atk_text_info =
8077 (GInterfaceInitFunc) atk_text_item_interface_init,
8078 (GInterfaceFinalizeFunc) NULL,
8082 type = g_type_register_static (ATK_TYPE_OBJECT,
8083 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8084 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8085 &atk_component_info);
8086 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8088 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8090 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8097 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8098 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8099 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8101 static GType gtk_icon_view_accessible_get_type (void);
8106 } GtkIconViewAccessible;
8112 } GtkIconViewItemAccessibleInfo;
8118 GtkAdjustment *old_hadj;
8119 GtkAdjustment *old_vadj;
8121 GtkTreeModel *model;
8123 } GtkIconViewAccessiblePrivate;
8125 static GtkIconViewAccessiblePrivate *
8126 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8128 return g_object_get_qdata (G_OBJECT (accessible),
8129 accessible_private_data_quark);
8133 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8137 GtkIconViewItemAccessibleInfo *info;
8138 GtkIconViewItemAccessibleInfo *tmp_info;
8139 GtkIconViewAccessiblePrivate *priv;
8142 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8144 info->index = index;
8146 priv = gtk_icon_view_accessible_get_priv (accessible);
8147 items = priv->items;
8150 tmp_info = items->data;
8151 if (tmp_info->index > index)
8153 items = items->next;
8155 priv->items = g_list_insert_before (priv->items, items, info);
8156 priv->old_hadj = NULL;
8157 priv->old_vadj = NULL;
8161 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8163 GtkIconView *icon_view;
8166 widget = GTK_ACCESSIBLE (accessible)->widget;
8170 icon_view = GTK_ICON_VIEW (widget);
8172 return g_list_length (icon_view->priv->items);
8176 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8179 GtkIconViewAccessiblePrivate *priv;
8180 GtkIconViewItemAccessibleInfo *info;
8183 priv = gtk_icon_view_accessible_get_priv (accessible);
8184 items = priv->items;
8189 if (info->index == index)
8191 items = items->next;
8197 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8200 GtkIconView *icon_view;
8204 GtkIconViewItemAccessible *a11y_item;
8206 widget = GTK_ACCESSIBLE (accessible)->widget;
8210 icon_view = GTK_ICON_VIEW (widget);
8211 icons = g_list_nth (icon_view->priv->items, index);
8215 GtkIconViewItem *item = icons->data;
8217 g_return_val_if_fail (item->index == index, NULL);
8218 obj = gtk_icon_view_accessible_find_child (accessible, index);
8221 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8222 gtk_icon_view_item_accessible_info_new (accessible,
8225 obj->role = ATK_ROLE_ICON;
8226 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8227 a11y_item->item = item;
8228 a11y_item->widget = widget;
8229 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8231 gtk_icon_view_set_cell_data (icon_view, item);
8232 gtk_text_buffer_set_text (a11y_item->text_buffer,
8233 get_text (icon_view, item), -1);
8235 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8236 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8244 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8247 GtkIconViewAccessiblePrivate *priv;
8248 GtkIconViewItemAccessibleInfo *info;
8249 GtkIconViewItemAccessible *item;
8252 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8256 gboolean act_on_item;
8258 widget = GTK_ACCESSIBLE (view)->widget;
8262 items = priv->items;
8264 act_on_item = (list == NULL);
8269 info = (GtkIconViewItemAccessibleInfo *)items->data;
8270 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8272 if (act_on_item == FALSE && list == items)
8276 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8278 items = items->next;
8284 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8285 GtkIconView *icon_view)
8288 GtkIconViewAccessible *view;
8291 * The scrollbars have changed
8293 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8294 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8296 gtk_icon_view_accessible_traverse_items (view, NULL);
8300 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8301 GtkAdjustment *hadj,
8302 GtkAdjustment *vadj)
8305 GtkIconViewAccessiblePrivate *priv;
8307 atk_obj = gtk_widget_get_accessible (widget);
8308 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8310 if (priv->old_hadj != hadj)
8314 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8315 (gpointer *)&priv->old_hadj);
8317 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8318 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8321 priv->old_hadj = hadj;
8324 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8325 (gpointer *)&priv->old_hadj);
8326 g_signal_connect (hadj,
8328 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8332 if (priv->old_vadj != vadj)
8336 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8337 (gpointer *)&priv->old_vadj);
8339 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8340 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8343 priv->old_vadj = vadj;
8346 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8347 (gpointer *)&priv->old_vadj);
8348 g_signal_connect (vadj,
8350 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8357 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8364 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8365 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8371 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8376 GtkIconViewAccessiblePrivate *priv;
8377 GtkIconViewItemAccessibleInfo *info;
8378 GtkIconViewAccessible *view;
8379 GtkIconViewItemAccessible *item;
8385 index = gtk_tree_path_get_indices(path)[0];
8386 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8387 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8388 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8390 items = priv->items;
8395 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8396 if (info->index != item->item->index)
8398 if (info->index < index)
8399 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8401 if (tmp_list == NULL)
8404 info->index = item->item->index;
8407 items = items->next;
8409 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8410 g_signal_emit_by_name (atk_obj, "children_changed::add",
8416 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8420 GtkIconViewAccessiblePrivate *priv;
8421 GtkIconViewItemAccessibleInfo *info;
8422 GtkIconViewAccessible *view;
8423 GtkIconViewItemAccessible *item;
8426 GList *deleted_item;
8430 index = gtk_tree_path_get_indices(path)[0];
8431 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8432 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8433 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8435 items = priv->items;
8437 deleted_item = NULL;
8442 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8443 if (info->index == index)
8445 deleted_item = items;
8447 if (info->index != item->item->index)
8449 if (tmp_list == NULL)
8452 info->index = item->item->index;
8455 items = items->next;
8457 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8460 info = deleted_item->data;
8461 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8463 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8467 priv->items = g_list_remove_link (priv->items, deleted_item);
8475 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8476 GtkIconViewItemAccessibleInfo *i2)
8478 return i1->index - i2->index;
8482 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8488 GtkIconViewAccessiblePrivate *priv;
8489 GtkIconViewItemAccessibleInfo *info;
8490 GtkIconViewAccessible *view;
8491 GtkIconView *icon_view;
8492 GtkIconViewItemAccessible *item;
8496 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8497 icon_view = GTK_ICON_VIEW (user_data);
8498 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8499 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8501 items = priv->items;
8505 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8506 info->index = new_order[info->index];
8507 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8508 items = items->next;
8510 priv->items = g_list_sort (priv->items,
8511 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8517 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8522 obj = G_OBJECT (model);
8523 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8524 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8525 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8526 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8530 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8534 obj = G_OBJECT (icon_view->priv->model);
8535 g_signal_connect_data (obj, "row-changed",
8536 (GCallback) gtk_icon_view_accessible_model_row_changed,
8537 icon_view, NULL, 0);
8538 g_signal_connect_data (obj, "row-inserted",
8539 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8540 icon_view, NULL, G_CONNECT_AFTER);
8541 g_signal_connect_data (obj, "row-deleted",
8542 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8543 icon_view, NULL, G_CONNECT_AFTER);
8544 g_signal_connect_data (obj, "rows-reordered",
8545 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8546 icon_view, NULL, G_CONNECT_AFTER);
8550 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8552 GtkIconViewItemAccessibleInfo *info;
8555 items = priv->items;
8558 info = (GtkIconViewItemAccessibleInfo *) items->data;
8559 g_object_unref (info->item);
8560 g_free (items->data);
8561 items = items->next;
8563 g_list_free (priv->items);
8568 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8571 GtkIconView *icon_view;
8574 GtkIconViewAccessiblePrivate *priv;
8576 if (strcmp (pspec->name, "model") == 0)
8578 widget = GTK_WIDGET (obj);
8579 atk_obj = gtk_widget_get_accessible (widget);
8580 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8583 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8584 (gpointer *)&priv->model);
8585 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8587 gtk_icon_view_accessible_clear_cache (priv);
8589 icon_view = GTK_ICON_VIEW (obj);
8590 priv->model = icon_view->priv->model;
8591 /* If there is no model the GtkIconView is probably being destroyed */
8594 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8595 gtk_icon_view_accessible_connect_model_signals (icon_view);
8603 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8606 GtkIconViewAccessiblePrivate *priv;
8607 GtkIconView *icon_view;
8609 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8610 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8612 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8613 g_object_set_qdata (G_OBJECT (accessible),
8614 accessible_private_data_quark,
8617 icon_view = GTK_ICON_VIEW (data);
8618 if (icon_view->priv->hadjustment)
8620 priv->old_hadj = icon_view->priv->hadjustment;
8621 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8622 g_signal_connect (icon_view->priv->hadjustment,
8624 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8627 if (icon_view->priv->vadjustment)
8629 priv->old_vadj = icon_view->priv->vadjustment;
8630 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8631 g_signal_connect (icon_view->priv->vadjustment,
8633 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8636 g_signal_connect_after (data,
8637 "set_scroll_adjustments",
8638 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8640 g_signal_connect (data,
8642 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8645 priv->model = icon_view->priv->model;
8648 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8649 gtk_icon_view_accessible_connect_model_signals (icon_view);
8652 accessible->role = ATK_ROLE_LAYERED_PANE;
8656 gtk_icon_view_accessible_finalize (GObject *object)
8658 GtkIconViewAccessiblePrivate *priv;
8660 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8661 gtk_icon_view_accessible_clear_cache (priv);
8665 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8669 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8670 GtkAccessible *accessible)
8673 GtkIconViewAccessiblePrivate *priv;
8675 atk_obj = ATK_OBJECT (accessible);
8676 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8679 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8680 (gpointer *)&priv->old_hadj);
8682 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8683 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8685 priv->old_hadj = NULL;
8689 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8690 (gpointer *)&priv->old_vadj);
8692 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8693 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8695 priv->old_vadj = NULL;
8700 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8702 if (accessible->widget)
8704 g_signal_connect_after (accessible->widget,
8706 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8709 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8713 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8715 GObjectClass *gobject_class;
8716 GtkAccessibleClass *accessible_class;
8718 accessible_parent_class = g_type_class_peek_parent (klass);
8720 gobject_class = (GObjectClass *)klass;
8721 accessible_class = (GtkAccessibleClass *)klass;
8723 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8725 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8726 klass->ref_child = gtk_icon_view_accessible_ref_child;
8727 klass->initialize = gtk_icon_view_accessible_initialize;
8729 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8731 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8735 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8738 AtkCoordType coord_type)
8741 GtkIconView *icon_view;
8742 GtkIconViewItem *item;
8745 widget = GTK_ACCESSIBLE (component)->widget;
8747 /* State is defunct */
8750 icon_view = GTK_ICON_VIEW (widget);
8751 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8752 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8754 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8760 atk_component_interface_init (AtkComponentIface *iface)
8762 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8766 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8770 GtkIconView *icon_view;
8771 GtkIconViewItem *item;
8773 widget = GTK_ACCESSIBLE (selection)->widget;
8777 icon_view = GTK_ICON_VIEW (widget);
8779 item = g_list_nth_data (icon_view->priv->items, i);
8784 gtk_icon_view_select_item (icon_view, item);
8790 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8793 GtkIconView *icon_view;
8795 widget = GTK_ACCESSIBLE (selection)->widget;
8799 icon_view = GTK_ICON_VIEW (widget);
8800 gtk_icon_view_unselect_all (icon_view);
8806 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8810 GtkIconView *icon_view;
8811 GtkIconViewItem *item;
8814 widget = GTK_ACCESSIBLE (selection)->widget;
8818 icon_view = GTK_ICON_VIEW (widget);
8820 l = icon_view->priv->items;
8827 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8838 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8841 GtkIconView *icon_view;
8842 GtkIconViewItem *item;
8846 widget = GTK_ACCESSIBLE (selection)->widget;
8850 icon_view = GTK_ICON_VIEW (widget);
8852 l = icon_view->priv->items;
8868 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8872 GtkIconView *icon_view;
8873 GtkIconViewItem *item;
8876 widget = GTK_ACCESSIBLE (selection)->widget;
8880 icon_view = GTK_ICON_VIEW (widget);
8882 item = g_list_nth_data (icon_view->priv->items, i);
8886 return item->selected;
8890 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8894 GtkIconView *icon_view;
8895 GtkIconViewItem *item;
8899 widget = GTK_ACCESSIBLE (selection)->widget;
8903 icon_view = GTK_ICON_VIEW (widget);
8904 l = icon_view->priv->items;
8913 gtk_icon_view_unselect_item (icon_view, item);
8925 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8928 GtkIconView *icon_view;
8930 widget = GTK_ACCESSIBLE (selection)->widget;
8934 icon_view = GTK_ICON_VIEW (widget);
8935 gtk_icon_view_select_all (icon_view);
8940 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8942 iface->add_selection = gtk_icon_view_accessible_add_selection;
8943 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8944 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8945 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8946 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8947 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8948 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8952 gtk_icon_view_accessible_get_type (void)
8954 static GType type = 0;
8958 static GTypeInfo tinfo =
8961 (GBaseInitFunc) NULL, /* base init */
8962 (GBaseFinalizeFunc) NULL, /* base finalize */
8963 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8964 (GClassFinalizeFunc) NULL, /* class finalize */
8965 NULL, /* class data */
8966 0, /* instance size */
8967 0, /* nb preallocs */
8968 (GInstanceInitFunc) NULL, /* instance init */
8969 NULL /* value table */
8971 static const GInterfaceInfo atk_component_info =
8973 (GInterfaceInitFunc) atk_component_interface_init,
8974 (GInterfaceFinalizeFunc) NULL,
8977 static const GInterfaceInfo atk_selection_info =
8979 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8980 (GInterfaceFinalizeFunc) NULL,
8985 * Figure out the size of the class and instance
8986 * we are deriving from
8988 AtkObjectFactory *factory;
8991 GType derived_atk_type;
8993 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8994 factory = atk_registry_get_factory (atk_get_default_registry (),
8996 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8997 g_type_query (derived_atk_type, &query);
8998 tinfo.class_size = query.class_size;
8999 tinfo.instance_size = query.instance_size;
9001 type = g_type_register_static (derived_atk_type,
9002 "GtkIconViewAccessible",
9004 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9005 &atk_component_info);
9006 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9007 &atk_selection_info);
9013 gtk_icon_view_accessible_new (GObject *obj)
9015 AtkObject *accessible;
9017 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9019 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9020 atk_object_initialize (accessible, obj);
9026 gtk_icon_view_accessible_factory_get_accessible_type (void)
9028 return gtk_icon_view_accessible_get_type ();
9032 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9034 return gtk_icon_view_accessible_new (obj);
9038 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9040 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9041 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9045 gtk_icon_view_accessible_factory_get_type (void)
9047 static GType type = 0;
9051 static const GTypeInfo tinfo =
9053 sizeof (AtkObjectFactoryClass),
9054 NULL, /* base_init */
9055 NULL, /* base_finalize */
9056 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9057 NULL, /* class_finalize */
9058 NULL, /* class_data */
9059 sizeof (AtkObjectFactory),
9060 0, /* n_preallocs */
9064 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9065 "GtkIconViewAccessibleFactory",
9073 gtk_icon_view_get_accessible (GtkWidget *widget)
9075 static gboolean first_time = TRUE;
9079 AtkObjectFactory *factory;
9080 AtkRegistry *registry;
9082 GType derived_atk_type;
9085 * Figure out whether accessibility is enabled by looking at the
9086 * type of the accessible object which would be created for
9087 * the parent type of GtkIconView.
9089 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9091 registry = atk_get_default_registry ();
9092 factory = atk_registry_get_factory (registry,
9094 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9095 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9096 atk_registry_set_factory_type (registry,
9098 gtk_icon_view_accessible_factory_get_type ());
9101 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9104 #define __GTK_ICON_VIEW_C__
9105 #include "gtkaliasdef.c"