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 if (icon_view->priv->hadjustment != NULL)
954 g_object_unref (icon_view->priv->hadjustment);
955 icon_view->priv->hadjustment = NULL;
958 if (icon_view->priv->vadjustment != NULL)
960 g_object_unref (icon_view->priv->vadjustment);
961 icon_view->priv->vadjustment = NULL;
964 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
967 /* GObject methods */
969 gtk_icon_view_finalize (GObject *object)
971 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
973 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
978 gtk_icon_view_set_property (GObject *object,
983 GtkIconView *icon_view;
985 icon_view = GTK_ICON_VIEW (object);
989 case PROP_SELECTION_MODE:
990 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
992 case PROP_PIXBUF_COLUMN:
993 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
995 case PROP_TEXT_COLUMN:
996 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
998 case PROP_MARKUP_COLUMN:
999 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1002 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1004 case PROP_ORIENTATION:
1005 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1008 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1010 case PROP_ITEM_WIDTH:
1011 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1014 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1016 case PROP_ROW_SPACING:
1017 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1019 case PROP_COLUMN_SPACING:
1020 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1023 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1025 case PROP_REORDERABLE:
1026 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1030 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1036 gtk_icon_view_get_property (GObject *object,
1041 GtkIconView *icon_view;
1043 icon_view = GTK_ICON_VIEW (object);
1047 case PROP_SELECTION_MODE:
1048 g_value_set_enum (value, icon_view->priv->selection_mode);
1050 case PROP_PIXBUF_COLUMN:
1051 g_value_set_int (value, icon_view->priv->pixbuf_column);
1053 case PROP_TEXT_COLUMN:
1054 g_value_set_int (value, icon_view->priv->text_column);
1056 case PROP_MARKUP_COLUMN:
1057 g_value_set_int (value, icon_view->priv->markup_column);
1060 g_value_set_object (value, icon_view->priv->model);
1062 case PROP_ORIENTATION:
1063 g_value_set_enum (value, icon_view->priv->orientation);
1066 g_value_set_int (value, icon_view->priv->columns);
1068 case PROP_ITEM_WIDTH:
1069 g_value_set_int (value, icon_view->priv->item_width);
1072 g_value_set_int (value, icon_view->priv->spacing);
1074 case PROP_ROW_SPACING:
1075 g_value_set_int (value, icon_view->priv->row_spacing);
1077 case PROP_COLUMN_SPACING:
1078 g_value_set_int (value, icon_view->priv->column_spacing);
1081 g_value_set_int (value, icon_view->priv->margin);
1083 case PROP_REORDERABLE:
1084 g_value_set_boolean (value, icon_view->priv->reorderable);
1088 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1093 /* GtkWidget signals */
1095 gtk_icon_view_realize (GtkWidget *widget)
1097 GtkIconView *icon_view;
1098 GdkWindowAttr attributes;
1099 gint attributes_mask;
1101 icon_view = GTK_ICON_VIEW (widget);
1103 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1105 /* Make the main, clipping window */
1106 attributes.window_type = GDK_WINDOW_CHILD;
1107 attributes.x = widget->allocation.x;
1108 attributes.y = widget->allocation.y;
1109 attributes.width = widget->allocation.width;
1110 attributes.height = widget->allocation.height;
1111 attributes.wclass = GDK_INPUT_OUTPUT;
1112 attributes.visual = gtk_widget_get_visual (widget);
1113 attributes.colormap = gtk_widget_get_colormap (widget);
1114 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1116 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1118 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1119 &attributes, attributes_mask);
1120 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1121 gdk_window_set_user_data (widget->window, widget);
1123 /* Make the window for the icon view */
1126 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1127 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1128 attributes.event_mask = (GDK_EXPOSURE_MASK |
1130 GDK_POINTER_MOTION_MASK |
1131 GDK_BUTTON_PRESS_MASK |
1132 GDK_BUTTON_RELEASE_MASK |
1133 GDK_KEY_PRESS_MASK |
1134 GDK_KEY_RELEASE_MASK) |
1135 gtk_widget_get_events (widget);
1137 icon_view->priv->bin_window = gdk_window_new (widget->window,
1138 &attributes, attributes_mask);
1139 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1141 widget->style = gtk_style_attach (widget->style, widget->window);
1142 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1144 gdk_window_show (icon_view->priv->bin_window);
1148 gtk_icon_view_unrealize (GtkWidget *widget)
1150 GtkIconView *icon_view;
1152 icon_view = GTK_ICON_VIEW (widget);
1154 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1155 gdk_window_destroy (icon_view->priv->bin_window);
1156 icon_view->priv->bin_window = NULL;
1158 /* GtkWidget::unrealize destroys children and widget->window */
1159 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1160 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1164 gtk_icon_view_size_request (GtkWidget *widget,
1165 GtkRequisition *requisition)
1167 GtkIconView *icon_view;
1170 icon_view = GTK_ICON_VIEW (widget);
1172 requisition->width = icon_view->priv->width;
1173 requisition->height = icon_view->priv->height;
1175 tmp_list = icon_view->priv->children;
1179 GtkIconViewChild *child = tmp_list->data;
1180 GtkRequisition child_requisition;
1182 tmp_list = tmp_list->next;
1184 if (GTK_WIDGET_VISIBLE (child->widget))
1185 gtk_widget_size_request (child->widget, &child_requisition);
1190 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1194 for (list = icon_view->priv->children; list; list = list->next)
1196 GtkIconViewChild *child = list->data;
1197 GtkAllocation allocation;
1199 /* totally ignore our child's requisition */
1200 if (child->cell < 0)
1202 allocation.x = child->item->x;
1203 allocation.y = child->item->y;
1204 allocation.width = child->item->width;
1205 allocation.height = child->item->height;
1209 GdkRectangle *box = &child->item->box[child->cell];
1211 allocation.x = box->x;
1212 allocation.y = box->y;
1213 allocation.width = box->width;
1214 allocation.height = box->height;
1217 gtk_widget_size_allocate (child->widget, &allocation);
1222 gtk_icon_view_size_allocate (GtkWidget *widget,
1223 GtkAllocation *allocation)
1225 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1227 GtkAdjustment *hadjustment, *vadjustment;
1229 widget->allocation = *allocation;
1231 if (GTK_WIDGET_REALIZED (widget))
1233 gdk_window_move_resize (widget->window,
1234 allocation->x, allocation->y,
1235 allocation->width, allocation->height);
1236 gdk_window_resize (icon_view->priv->bin_window,
1237 MAX (icon_view->priv->width, allocation->width),
1238 MAX (icon_view->priv->height, allocation->height));
1241 gtk_icon_view_layout (icon_view);
1243 gtk_icon_view_allocate_children (icon_view);
1245 hadjustment = icon_view->priv->hadjustment;
1246 vadjustment = icon_view->priv->vadjustment;
1248 hadjustment->page_size = allocation->width;
1249 hadjustment->page_increment = allocation->width * 0.9;
1250 hadjustment->step_increment = allocation->width * 0.1;
1251 hadjustment->lower = 0;
1252 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1254 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1255 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1257 vadjustment->page_size = allocation->height;
1258 vadjustment->page_increment = allocation->height * 0.9;
1259 vadjustment->step_increment = allocation->height * 0.1;
1260 vadjustment->lower = 0;
1261 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1263 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1264 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1266 if (GTK_WIDGET_REALIZED (widget) &&
1267 icon_view->priv->scroll_to_path)
1270 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1271 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1272 icon_view->priv->scroll_to_path = NULL;
1274 gtk_icon_view_scroll_to_path (icon_view, path,
1275 icon_view->priv->scroll_to_use_align,
1276 icon_view->priv->scroll_to_row_align,
1277 icon_view->priv->scroll_to_col_align);
1278 gtk_tree_path_free (path);
1282 gtk_adjustment_changed (hadjustment);
1283 gtk_adjustment_changed (vadjustment);
1288 gtk_icon_view_expose (GtkWidget *widget,
1289 GdkEventExpose *expose)
1291 GtkIconView *icon_view;
1296 GtkIconViewDropPosition dest_pos;
1297 GtkIconViewItem *dest_item = NULL;
1299 icon_view = GTK_ICON_VIEW (widget);
1301 if (expose->window != icon_view->priv->bin_window)
1304 cr = gdk_cairo_create (icon_view->priv->bin_window);
1305 cairo_set_line_width (cr, 1.);
1307 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1311 dest_index = gtk_tree_path_get_indices (path)[0];
1312 gtk_tree_path_free (path);
1317 for (icons = icon_view->priv->items; icons; icons = icons->next)
1319 GtkIconViewItem *item = icons->data;
1324 area.width = item->width;
1325 area.height = item->height;
1327 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1330 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1331 icon_view->priv->bin_window,
1332 item->x, item->y, TRUE);
1334 if (dest_index == item->index)
1342 case GTK_ICON_VIEW_DROP_INTO:
1343 gtk_paint_focus (widget->style,
1344 icon_view->priv->bin_window,
1345 GTK_WIDGET_STATE (widget),
1348 "iconview-drop-indicator",
1349 dest_item->x, dest_item->y,
1350 dest_item->width, dest_item->height);
1352 case GTK_ICON_VIEW_DROP_ABOVE:
1353 gtk_paint_focus (widget->style,
1354 icon_view->priv->bin_window,
1355 GTK_WIDGET_STATE (widget),
1358 "iconview-drop-indicator",
1359 dest_item->x, dest_item->y - 1,
1360 dest_item->width, 2);
1362 case GTK_ICON_VIEW_DROP_LEFT:
1363 gtk_paint_focus (widget->style,
1364 icon_view->priv->bin_window,
1365 GTK_WIDGET_STATE (widget),
1368 "iconview-drop-indicator",
1369 dest_item->x - 1, dest_item->y,
1370 2, dest_item->height);
1372 case GTK_ICON_VIEW_DROP_BELOW:
1373 gtk_paint_focus (widget->style,
1374 icon_view->priv->bin_window,
1375 GTK_WIDGET_STATE (widget),
1378 "iconview-drop-indicator",
1379 dest_item->x, dest_item->y + dest_item->height - 1,
1380 dest_item->width, 2);
1382 case GTK_ICON_VIEW_DROP_RIGHT:
1383 gtk_paint_focus (widget->style,
1384 icon_view->priv->bin_window,
1385 GTK_WIDGET_STATE (widget),
1388 "iconview-drop-indicator",
1389 dest_item->x + dest_item->width - 1, dest_item->y,
1390 2, dest_item->height);
1391 case GTK_ICON_VIEW_NO_DROP: ;
1396 if (icon_view->priv->doing_rubberband)
1398 GdkRectangle *rectangles;
1401 gdk_region_get_rectangles (expose->region,
1405 while (n_rectangles--)
1406 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1408 g_free (rectangles);
1413 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1419 rubberband_scroll_timeout (gpointer data)
1421 GtkIconView *icon_view;
1424 GDK_THREADS_ENTER ();
1428 value = MIN (icon_view->priv->vadjustment->value +
1429 icon_view->priv->scroll_value_diff,
1430 icon_view->priv->vadjustment->upper -
1431 icon_view->priv->vadjustment->page_size);
1433 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1435 gtk_icon_view_update_rubberband (icon_view);
1437 GDK_THREADS_LEAVE ();
1443 gtk_icon_view_motion (GtkWidget *widget,
1444 GdkEventMotion *event)
1446 GtkIconView *icon_view;
1449 icon_view = GTK_ICON_VIEW (widget);
1451 gtk_icon_view_maybe_begin_drag (icon_view, event);
1453 if (icon_view->priv->doing_rubberband)
1455 gtk_icon_view_update_rubberband (widget);
1457 abs_y = event->y - icon_view->priv->height *
1458 (icon_view->priv->vadjustment->value /
1459 (icon_view->priv->vadjustment->upper -
1460 icon_view->priv->vadjustment->lower));
1462 if (abs_y < 0 || abs_y > widget->allocation.height)
1465 icon_view->priv->scroll_value_diff = abs_y;
1467 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1469 icon_view->priv->event_last_x = event->x;
1470 icon_view->priv->event_last_y = event->y;
1472 if (icon_view->priv->scroll_timeout_id == 0)
1473 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1477 remove_scroll_timeout (icon_view);
1484 gtk_icon_view_remove (GtkContainer *container,
1487 GtkIconView *icon_view;
1488 GtkIconViewChild *child = NULL;
1491 icon_view = GTK_ICON_VIEW (container);
1493 tmp_list = icon_view->priv->children;
1496 child = tmp_list->data;
1497 if (child->widget == widget)
1499 gtk_widget_unparent (widget);
1501 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1502 g_list_free_1 (tmp_list);
1507 tmp_list = tmp_list->next;
1512 gtk_icon_view_forall (GtkContainer *container,
1513 gboolean include_internals,
1514 GtkCallback callback,
1515 gpointer callback_data)
1517 GtkIconView *icon_view;
1518 GtkIconViewChild *child = NULL;
1521 icon_view = GTK_ICON_VIEW (container);
1523 tmp_list = icon_view->priv->children;
1526 child = tmp_list->data;
1527 tmp_list = tmp_list->next;
1529 (* callback) (child->widget, callback_data);
1534 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1535 GtkIconViewItem *item,
1536 GtkIconViewCellInfo *info,
1541 GdkRectangle cell_area;
1542 gboolean visible, mode;
1544 gtk_icon_view_set_cell_data (icon_view, item);
1546 g_object_get (info->cell,
1547 "visible", &visible,
1551 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1553 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1555 path = gtk_tree_path_new_from_indices (item->index, -1);
1556 path_string = gtk_tree_path_to_string (path);
1557 gtk_tree_path_free (path);
1559 gtk_cell_renderer_activate (info->cell,
1561 GTK_WIDGET (icon_view),
1567 g_free (path_string);
1572 gtk_icon_view_put (GtkIconView *icon_view,
1574 GtkIconViewItem *item,
1577 GtkIconViewChild *child;
1579 child = g_new (GtkIconViewChild, 1);
1581 child->widget = widget;
1585 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1587 if (GTK_WIDGET_REALIZED (icon_view))
1588 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1590 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1594 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1595 GtkIconView *icon_view)
1598 GtkIconViewItem *item;
1600 if (icon_view->priv->edited_item == NULL)
1603 item = icon_view->priv->edited_item;
1604 icon_view->priv->edited_item = NULL;
1605 icon_view->priv->editable = NULL;
1606 for (l = icon_view->priv->cell_list; l; l = l->next)
1608 GtkIconViewCellInfo *info = l->data;
1610 info->editing = FALSE;
1613 if (GTK_WIDGET_HAS_FOCUS (editable))
1614 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1616 g_signal_handlers_disconnect_by_func (editable,
1617 gtk_icon_view_remove_widget,
1620 gtk_container_remove (GTK_CONTAINER (icon_view),
1621 GTK_WIDGET (editable));
1623 gtk_icon_view_queue_draw_item (icon_view, item);
1628 gtk_icon_view_start_editing (GtkIconView *icon_view,
1629 GtkIconViewItem *item,
1630 GtkIconViewCellInfo *info,
1635 GdkRectangle cell_area;
1636 gboolean visible, mode;
1637 GtkCellEditable *editable;
1639 gtk_icon_view_set_cell_data (icon_view, item);
1641 g_object_get (info->cell,
1642 "visible", &visible,
1645 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1647 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1649 path = gtk_tree_path_new_from_indices (item->index, -1);
1650 path_string = gtk_tree_path_to_string (path);
1651 gtk_tree_path_free (path);
1653 editable = gtk_cell_renderer_start_editing (info->cell,
1655 GTK_WIDGET (icon_view),
1660 g_free (path_string);
1662 /* FIXME ugly special case */
1663 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1664 g_object_set (editable, "has-frame", TRUE, NULL);
1666 /* the rest corresponds to tree_view_real_start_editing... */
1667 icon_view->priv->edited_item = item;
1668 icon_view->priv->editable = editable;
1669 info->editing = TRUE;
1671 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1673 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1675 gtk_widget_grab_focus (GTK_WIDGET (editable));
1676 g_signal_connect (editable, "remove_widget",
1677 G_CALLBACK (gtk_icon_view_remove_widget),
1684 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1685 gboolean cancel_editing)
1687 GtkCellRenderer *cell = NULL;
1688 GtkIconViewItem *item;
1691 if (icon_view->priv->edited_item == NULL)
1695 * This is very evil. We need to do this, because
1696 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1697 * later on. If gtk_icon_view_row_changed notices
1698 * icon_view->priv->edited_item != NULL, it'll call
1699 * gtk_icon_view_stop_editing again. Bad things will happen then.
1701 * Please read that again if you intend to modify anything here.
1704 item = icon_view->priv->edited_item;
1705 icon_view->priv->edited_item = NULL;
1707 for (l = icon_view->priv->cell_list; l; l = l->next)
1709 GtkIconViewCellInfo *info = l->data;
1721 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1722 if (!cancel_editing)
1723 gtk_cell_editable_editing_done (icon_view->priv->editable);
1725 icon_view->priv->edited_item = item;
1727 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1731 * gtk_icon_view_set_cursor:
1732 * @icon_view: A #GtkIconView
1733 * @path: A #GtkTreePath
1734 * @cell: One of the cell renderers of @icon_view, or %NULL
1735 * @start_editing: %TRUE if the specified cell should start being edited.
1737 * Sets the current keyboard focus to be at @path, and selects it. This is
1738 * useful when you want to focus the user's attention on a particular item.
1739 * If @cell is not %NULL, then focus is given to the cell specified by
1740 * it. Additionally, if @start_editing is %TRUE, then editing should be
1741 * started in the specified cell.
1743 * This function is often followed by <literal>gtk_widget_grab_focus
1744 * (icon_view)</literal> in order to give keyboard focus to the widget.
1745 * Please note that editing can only happen when the widget is realized.
1750 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1752 GtkCellRenderer *cell,
1753 gboolean start_editing)
1755 GtkIconViewItem *item = NULL;
1756 GtkIconViewCellInfo *info = NULL;
1760 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1761 g_return_if_fail (path != NULL);
1762 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1764 gtk_icon_view_stop_editing (icon_view, TRUE);
1766 if (gtk_tree_path_get_depth (path) == 1)
1767 item = g_list_nth_data (icon_view->priv->items,
1768 gtk_tree_path_get_indices(path)[0]);
1774 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1778 if (info->cell == cell)
1787 g_return_if_fail (cell == NULL || info != NULL);
1789 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1790 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1792 if (info && start_editing)
1793 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1797 * gtk_icon_view_get_cursor:
1798 * @icon_view: A #GtkIconView
1799 * @path: Return location for the current cursor path, or %NULL
1800 * @cell: Return location the current focus cell, or %NULL
1802 * Fills in @path and @cell with the current cursor path and cell.
1803 * If the cursor isn't currently set, then *@path will be %NULL.
1804 * If no cell currently has focus, then *@cell will be %NULL.
1806 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1808 * Return value: %TRUE if the cursor is set.
1813 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1815 GtkCellRenderer **cell)
1817 GtkIconViewItem *item;
1818 GtkIconViewCellInfo *info;
1820 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1822 item = icon_view->priv->cursor_item;
1823 if (icon_view->priv->cursor_cell < 0)
1826 info = g_list_nth_data (icon_view->priv->cell_list,
1827 icon_view->priv->cursor_cell);
1832 *path = gtk_tree_path_new_from_indices (item->index, -1);
1845 return (item != NULL);
1849 gtk_icon_view_button_press (GtkWidget *widget,
1850 GdkEventButton *event)
1852 GtkIconView *icon_view;
1853 GtkIconViewItem *item;
1854 GtkIconViewCellInfo *info = NULL;
1855 gboolean dirty = FALSE;
1856 GtkCellRendererMode mode;
1859 icon_view = GTK_ICON_VIEW (widget);
1861 if (event->window != icon_view->priv->bin_window)
1864 if (!GTK_WIDGET_HAS_FOCUS (widget))
1865 gtk_widget_grab_focus (widget);
1867 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1869 item = gtk_icon_view_get_item_at_coords (icon_view,
1875 g_object_get (info->cell, "mode", &mode, NULL);
1877 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1878 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1879 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1883 gtk_icon_view_scroll_to_item (icon_view, item);
1885 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1887 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1889 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1890 (event->state & GDK_SHIFT_MASK))
1892 gtk_icon_view_unselect_all_internal (icon_view);
1894 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1895 if (!icon_view->priv->anchor_item)
1896 icon_view->priv->anchor_item = item;
1898 gtk_icon_view_select_all_between (icon_view,
1899 icon_view->priv->anchor_item,
1905 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1906 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1907 (event->state & GDK_CONTROL_MASK))
1909 item->selected = !item->selected;
1910 gtk_icon_view_queue_draw_item (icon_view, item);
1915 if (!item->selected)
1917 gtk_icon_view_unselect_all_internal (icon_view);
1919 item->selected = TRUE;
1920 gtk_icon_view_queue_draw_item (icon_view, item);
1924 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1925 icon_view->priv->anchor_item = item;
1928 /* Save press to possibly begin a drag */
1929 if (icon_view->priv->pressed_button < 0)
1931 icon_view->priv->pressed_button = event->button;
1932 icon_view->priv->press_start_x = event->x;
1933 icon_view->priv->press_start_y = event->y;
1936 if (!icon_view->priv->last_single_clicked)
1937 icon_view->priv->last_single_clicked = item;
1939 /* cancel the current editing, if it exists */
1940 gtk_icon_view_stop_editing (icon_view, TRUE);
1942 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1943 gtk_icon_view_item_activate_cell (icon_view, item, info,
1945 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1946 gtk_icon_view_start_editing (icon_view, item, info,
1951 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1952 !(event->state & GDK_CONTROL_MASK))
1954 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1957 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1958 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
1963 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1965 item = gtk_icon_view_get_item_at_coords (icon_view,
1970 if (item && item == icon_view->priv->last_single_clicked)
1974 path = gtk_tree_path_new_from_indices (item->index, -1);
1975 gtk_icon_view_item_activated (icon_view, path);
1976 gtk_tree_path_free (path);
1979 icon_view->priv->last_single_clicked = NULL;
1980 icon_view->priv->pressed_button = -1;
1984 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1986 return event->button == 1;
1990 gtk_icon_view_button_release (GtkWidget *widget,
1991 GdkEventButton *event)
1993 GtkIconView *icon_view;
1995 icon_view = GTK_ICON_VIEW (widget);
1997 if (icon_view->priv->pressed_button == event->button)
1998 icon_view->priv->pressed_button = -1;
2000 gtk_icon_view_stop_rubberbanding (icon_view);
2002 remove_scroll_timeout (icon_view);
2008 gtk_icon_view_update_rubberband (gpointer data)
2010 GtkIconView *icon_view;
2012 GdkRectangle old_area;
2013 GdkRectangle new_area;
2014 GdkRectangle common;
2015 GdkRegion *invalid_region;
2017 icon_view = GTK_ICON_VIEW (data);
2019 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2024 old_area.x = MIN (icon_view->priv->rubberband_x1,
2025 icon_view->priv->rubberband_x2);
2026 old_area.y = MIN (icon_view->priv->rubberband_y1,
2027 icon_view->priv->rubberband_y2);
2028 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2029 icon_view->priv->rubberband_x1) + 1;
2030 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2031 icon_view->priv->rubberband_y1) + 1;
2033 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2034 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2035 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2036 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2038 invalid_region = gdk_region_rectangle (&old_area);
2039 gdk_region_union_with_rect (invalid_region, &new_area);
2041 gdk_rectangle_intersect (&old_area, &new_area, &common);
2042 if (common.width > 2 && common.height > 2)
2044 GdkRegion *common_region;
2046 /* make sure the border is invalidated */
2052 common_region = gdk_region_rectangle (&common);
2054 gdk_region_subtract (invalid_region, common_region);
2055 gdk_region_destroy (common_region);
2058 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2060 gdk_region_destroy (invalid_region);
2062 icon_view->priv->rubberband_x2 = x;
2063 icon_view->priv->rubberband_y2 = y;
2065 gtk_icon_view_update_rubberband_selection (icon_view);
2069 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2075 g_assert (!icon_view->priv->doing_rubberband);
2077 for (items = icon_view->priv->items; items; items = items->next)
2079 GtkIconViewItem *item = items->data;
2081 item->selected_before_rubberbanding = item->selected;
2084 icon_view->priv->rubberband_x1 = x;
2085 icon_view->priv->rubberband_y1 = y;
2086 icon_view->priv->rubberband_x2 = x;
2087 icon_view->priv->rubberband_y2 = y;
2089 icon_view->priv->doing_rubberband = TRUE;
2091 gtk_grab_add (GTK_WIDGET (icon_view));
2095 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2097 if (!icon_view->priv->doing_rubberband)
2100 icon_view->priv->doing_rubberband = FALSE;
2102 gtk_grab_remove (GTK_WIDGET (icon_view));
2104 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2108 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2111 gint x, y, width, height;
2112 gboolean dirty = FALSE;
2114 x = MIN (icon_view->priv->rubberband_x1,
2115 icon_view->priv->rubberband_x2);
2116 y = MIN (icon_view->priv->rubberband_y1,
2117 icon_view->priv->rubberband_y2);
2118 width = ABS (icon_view->priv->rubberband_x1 -
2119 icon_view->priv->rubberband_x2);
2120 height = ABS (icon_view->priv->rubberband_y1 -
2121 icon_view->priv->rubberband_y2);
2123 for (items = icon_view->priv->items; items; items = items->next)
2125 GtkIconViewItem *item = items->data;
2129 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2130 x, y, width, height);
2132 selected = is_in ^ item->selected_before_rubberbanding;
2134 if (item->selected != selected)
2136 item->selected = selected;
2138 gtk_icon_view_queue_draw_item (icon_view, item);
2143 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2147 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2148 GtkIconViewItem *item,
2157 for (l = icon_view->priv->cell_list; l; l = l->next)
2159 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2161 if (!info->cell->visible)
2164 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2166 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2167 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2175 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2177 gboolean dirty = FALSE;
2180 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2183 for (items = icon_view->priv->items; items; items = items->next)
2185 GtkIconViewItem *item = items->data;
2189 item->selected = FALSE;
2191 gtk_icon_view_queue_draw_item (icon_view, item);
2199 /* GtkIconView signals */
2201 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2202 GtkAdjustment *hadj,
2203 GtkAdjustment *vadj)
2205 gboolean need_adjust = FALSE;
2208 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2210 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2212 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2214 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2216 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2218 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2219 0, 0, NULL, NULL, icon_view);
2220 g_object_unref (icon_view->priv->hadjustment);
2223 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2225 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2226 0, 0, NULL, NULL, icon_view);
2227 g_object_unref (icon_view->priv->vadjustment);
2230 if (icon_view->priv->hadjustment != hadj)
2232 icon_view->priv->hadjustment = hadj;
2233 g_object_ref_sink (icon_view->priv->hadjustment);
2235 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2236 G_CALLBACK (gtk_icon_view_adjustment_changed),
2241 if (icon_view->priv->vadjustment != vadj)
2243 icon_view->priv->vadjustment = vadj;
2244 g_object_ref_sink (icon_view->priv->vadjustment);
2246 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2247 G_CALLBACK (gtk_icon_view_adjustment_changed),
2253 gtk_icon_view_adjustment_changed (NULL, icon_view);
2257 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2259 gtk_icon_view_select_all (icon_view);
2263 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2265 gtk_icon_view_unselect_all (icon_view);
2269 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2271 gtk_icon_view_unselect_all (icon_view);
2273 if (icon_view->priv->cursor_item != NULL)
2274 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2278 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2281 GtkCellRendererMode mode;
2282 GtkIconViewCellInfo *info = NULL;
2284 if (!icon_view->priv->cursor_item)
2287 info = g_list_nth_data (icon_view->priv->cell_list,
2288 icon_view->priv->cursor_cell);
2292 g_object_get (info->cell, "mode", &mode, NULL);
2294 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2296 gtk_icon_view_item_activate_cell (icon_view,
2297 icon_view->priv->cursor_item,
2301 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2303 gtk_icon_view_start_editing (icon_view,
2304 icon_view->priv->cursor_item,
2310 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2311 gtk_icon_view_item_activated (icon_view, path);
2312 gtk_tree_path_free (path);
2318 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2320 if (!icon_view->priv->cursor_item)
2323 switch (icon_view->priv->selection_mode)
2325 case GTK_SELECTION_NONE:
2327 case GTK_SELECTION_BROWSE:
2328 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2330 case GTK_SELECTION_SINGLE:
2331 if (icon_view->priv->cursor_item->selected)
2332 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2334 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2336 case GTK_SELECTION_MULTIPLE:
2337 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2338 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2340 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2345 /* Internal functions */
2347 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2348 GtkIconView *icon_view)
2350 if (GTK_WIDGET_REALIZED (icon_view))
2352 gdk_window_move (icon_view->priv->bin_window,
2353 - icon_view->priv->hadjustment->value,
2354 - icon_view->priv->vadjustment->value);
2356 if (icon_view->priv->doing_rubberband)
2357 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2359 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2364 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2369 gint *maximum_width)
2372 gint x, current_width;
2373 GList *items, *last_item;
2380 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2381 max_height = g_new0 (gint, icon_view->priv->n_cells);
2388 gtk_widget_style_get (GTK_WIDGET (icon_view),
2389 "focus-line-width", &focus_width,
2392 x += icon_view->priv->margin + focus_width;
2393 current_width += 2 * (icon_view->priv->margin + focus_width);
2398 GtkIconViewItem *item = items->data;
2400 gtk_icon_view_calculate_item_size (icon_view, item);
2401 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2403 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2405 current_width += item->width;
2407 if (items != first_item)
2409 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2410 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2414 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2416 item->y = *y + focus_width;
2417 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2419 x = current_width - (icon_view->priv->margin + focus_width);
2421 for (i = 0; i < icon_view->priv->n_cells; i++)
2422 max_height[i] = MAX (max_height[i], item->box[i].height);
2424 if (current_width > *maximum_width)
2425 *maximum_width = current_width;
2431 items = items->next;
2436 /* Now go through the row again and align the icons */
2437 for (items = first_item; items != last_item; items = items->next)
2439 GtkIconViewItem *item = items->data;
2441 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2443 /* We may want to readjust the new y coordinate. */
2444 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2445 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2448 item->col = col - 1 - item->col;
2451 g_free (max_height);
2457 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2460 if (upper != adj->upper)
2462 gdouble min = MAX (0.0, upper - adj->page_size);
2463 gboolean value_changed = FALSE;
2467 if (adj->value > min)
2470 value_changed = TRUE;
2473 gtk_adjustment_changed (adj);
2476 gtk_adjustment_value_changed (adj);
2481 gtk_icon_view_layout (GtkIconView *icon_view)
2483 gint y = 0, maximum_width = 0;
2489 if (icon_view->priv->layout_idle_id != 0)
2491 g_source_remove (icon_view->priv->layout_idle_id);
2492 icon_view->priv->layout_idle_id = 0;
2495 if (icon_view->priv->model == NULL)
2498 widget = GTK_WIDGET (icon_view);
2500 item_width = icon_view->priv->item_width;
2504 for (icons = icon_view->priv->items; icons; icons = icons->next)
2506 GtkIconViewItem *item = icons->data;
2507 gtk_icon_view_calculate_item_size (icon_view, item);
2508 item_width = MAX (item_width, item->width);
2512 icons = icon_view->priv->items;
2513 y += icon_view->priv->margin;
2518 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2520 &y, &maximum_width);
2523 while (icons != NULL);
2525 if (maximum_width != icon_view->priv->width)
2526 icon_view->priv->width = maximum_width;
2528 y += icon_view->priv->margin;
2530 if (y != icon_view->priv->height)
2531 icon_view->priv->height = y;
2533 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2534 icon_view->priv->width);
2535 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2536 icon_view->priv->height);
2538 if (GTK_WIDGET_REALIZED (icon_view))
2539 gdk_window_resize (icon_view->priv->bin_window,
2540 MAX (icon_view->priv->width, widget->allocation.width),
2541 MAX (icon_view->priv->height, widget->allocation.height));
2543 if (icon_view->priv->scroll_to_path)
2547 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2548 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2549 icon_view->priv->scroll_to_path = NULL;
2551 gtk_icon_view_scroll_to_path (icon_view, path,
2552 icon_view->priv->scroll_to_use_align,
2553 icon_view->priv->scroll_to_row_align,
2554 icon_view->priv->scroll_to_col_align);
2555 gtk_tree_path_free (path);
2558 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2562 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2563 GtkIconViewItem *item,
2564 GtkIconViewCellInfo *info,
2565 GdkRectangle *cell_area)
2567 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2569 cell_area->x = item->box[info->position].x - item->before[info->position];
2570 cell_area->y = item->y;
2571 cell_area->width = item->box[info->position].width +
2572 item->before[info->position] + item->after[info->position];
2573 cell_area->height = item->height;
2577 cell_area->x = item->x;
2578 cell_area->y = item->box[info->position].y - item->before[info->position];
2579 cell_area->width = item->width;
2580 cell_area->height = item->box[info->position].height +
2581 item->before[info->position] + item->after[info->position];
2586 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2587 GtkIconViewItem *item,
2588 GtkIconViewCellInfo *info,
2591 *box = item->box[info->position];
2594 /* try to guess a reasonable wrap width for an implicit text cell renderer
2597 adjust_wrap_width (GtkIconView *icon_view,
2598 GtkIconViewItem *item)
2600 GtkIconViewCellInfo *text_info;
2601 GtkIconViewCellInfo *pixbuf_info;
2602 gint pixbuf_width, wrap_width;
2604 if (icon_view->priv->text_cell != -1 &&
2605 icon_view->priv->pixbuf_cell != -1)
2607 text_info = g_list_nth_data (icon_view->priv->cell_list,
2608 icon_view->priv->text_cell);
2609 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2610 icon_view->priv->pixbuf_cell);
2612 gtk_cell_renderer_get_size (pixbuf_info->cell,
2613 GTK_WIDGET (icon_view),
2618 if (item->width == -1)
2619 wrap_width = MAX (2 * pixbuf_width, 50);
2620 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2621 wrap_width = item->width;
2623 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2625 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2630 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2631 GtkIconViewItem *item)
2636 if (item->width != -1 && item->height != -1)
2639 if (item->n_cells != icon_view->priv->n_cells)
2641 g_free (item->before);
2642 g_free (item->after);
2645 item->before = g_new0 (gint, icon_view->priv->n_cells);
2646 item->after = g_new0 (gint, icon_view->priv->n_cells);
2647 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2649 item->n_cells = icon_view->priv->n_cells;
2652 gtk_icon_view_set_cell_data (icon_view, item);
2654 spacing = icon_view->priv->spacing;
2658 for (l = icon_view->priv->cell_list; l; l = l->next)
2660 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2662 if (!info->cell->visible)
2665 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2667 &item->box[info->position].width,
2668 &item->box[info->position].height);
2670 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2672 item->width += item->box[info->position].width
2673 + (info->position > 0 ? spacing : 0);
2674 item->height = MAX (item->height, item->box[info->position].height);
2678 item->width = MAX (item->width, item->box[info->position].width);
2679 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2685 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2686 GtkIconViewItem *item,
2689 GdkRectangle cell_area;
2695 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2697 gtk_icon_view_set_cell_data (icon_view, item);
2699 spacing = icon_view->priv->spacing;
2702 for (i = 0; i < icon_view->priv->n_cells; i++)
2704 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2705 item->height = MAX (item->height, max_height[i]);
2707 item->height += max_height[i] + (i > 0 ? spacing : 0);
2710 cell_area.x = item->x;
2711 cell_area.y = item->y;
2713 for (k = 0; k < 2; k++)
2714 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2716 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2718 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2721 if (!info->cell->visible)
2724 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2726 cell_area.width = item->box[info->position].width;
2727 cell_area.height = item->height;
2731 cell_area.width = item->width;
2732 cell_area.height = max_height[i];
2735 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2737 &item->box[info->position].x, &item->box[info->position].y,
2738 &item->box[info->position].width, &item->box[info->position].height);
2740 item->box[info->position].x += cell_area.x;
2741 item->box[info->position].y += cell_area.y;
2742 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2744 item->before[info->position] = item->box[info->position].x - cell_area.x;
2745 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2746 cell_area.x += cell_area.width + spacing;
2750 if (item->box[info->position].width > item->width)
2752 item->width = item->box[info->position].width;
2753 cell_area.width = item->width;
2755 item->before[info->position] = item->box[info->position].y - cell_area.y;
2756 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2757 cell_area.y += cell_area.height + spacing;
2761 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2763 for (i = 0; i < icon_view->priv->n_cells; i++)
2765 item->box[i].x = item->x + item->width -
2766 (item->box[i].x + item->box[i].width - item->x);
2772 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2774 g_list_foreach (icon_view->priv->items,
2775 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2779 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2786 gtk_icon_view_paint_item (GtkIconView *icon_view,
2788 GtkIconViewItem *item,
2790 GdkDrawable *drawable,
2793 gboolean draw_focus)
2795 gint focus_width, focus_pad;
2797 GdkRectangle cell_area, box;
2801 GtkCellRendererState flags;
2803 if (icon_view->priv->model == NULL)
2806 gtk_icon_view_set_cell_data (icon_view, item);
2808 gtk_widget_style_get (GTK_WIDGET (icon_view),
2809 "focus-line-width", &focus_width,
2810 "focus-padding", &focus_pad,
2813 padding = focus_width;
2817 flags = GTK_CELL_RENDERER_SELECTED;
2818 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2819 state = GTK_STATE_SELECTED;
2821 state = GTK_STATE_ACTIVE;
2826 state = GTK_STATE_NORMAL;
2829 #ifdef DEBUG_ICON_VIEW
2830 gdk_draw_rectangle (drawable,
2831 GTK_WIDGET (icon_view)->style->black_gc,
2834 item->width, item->height);
2838 for (l = icon_view->priv->cell_list; l; l = l->next)
2840 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2842 if (!info->cell->visible)
2845 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2847 /* FIXME we hardwire background drawing behind text
2848 * cell renderers here
2850 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2852 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2853 cairo_rectangle (cr,
2854 x - item->x + box.x,
2855 y - item->y + box.y,
2856 box.width, box.height);
2861 for (l = icon_view->priv->cell_list; l; l = l->next)
2863 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2865 if (!info->cell->visible)
2868 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2870 #ifdef DEBUG_ICON_VIEW
2871 gdk_draw_rectangle (drawable,
2872 GTK_WIDGET (icon_view)->style->black_gc,
2874 x - item->x + cell_area.x,
2875 y - item->y + cell_area.y,
2876 cell_area.width, cell_area.height);
2878 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2880 gdk_draw_rectangle (drawable,
2881 GTK_WIDGET (icon_view)->style->black_gc,
2883 x - item->x + box.x,
2884 y - item->y + box.y,
2885 box.width, box.height);
2888 cell_area.x = x - item->x + cell_area.x;
2889 cell_area.y = y - item->y + cell_area.y;
2891 gtk_cell_renderer_render (info->cell,
2893 GTK_WIDGET (icon_view),
2894 &cell_area, &cell_area, area, flags);
2898 /* FIXME where to draw the focus with generic cell renderers ? */
2900 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2901 item == icon_view->priv->cursor_item)
2902 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2904 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2906 if (!info->cell->visible)
2909 if (icon_view->priv->cursor_cell < 0 &&
2910 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2911 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2912 icon_view->priv->cursor_cell = i;
2914 if (i == icon_view->priv->cursor_cell)
2916 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2918 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2922 GTK_WIDGET (icon_view),
2924 x - item->x + box.x - padding,
2925 y - item->y + box.y - padding,
2926 box.width + 2 * padding,
2927 box.height + 2 * padding);
2934 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2939 GdkRectangle rubber_rect;
2940 GdkColor *fill_color_gdk;
2941 guchar fill_color_alpha;
2943 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2944 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2945 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2946 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2948 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2951 gtk_widget_style_get (GTK_WIDGET (icon_view),
2952 "selection-box-color", &fill_color_gdk,
2953 "selection-box-alpha", &fill_color_alpha,
2956 if (!fill_color_gdk)
2957 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2959 cairo_set_source_rgba (cr,
2960 fill_color_gdk->red / 65535.,
2961 fill_color_gdk->green / 65535.,
2962 fill_color_gdk->blue / 65535.,
2963 fill_color_alpha / 255.);
2966 gdk_cairo_rectangle (cr, &rect);
2970 /* Draw the border without alpha */
2971 cairo_set_source_rgb (cr,
2972 fill_color_gdk->red / 65535.,
2973 fill_color_gdk->green / 65535.,
2974 fill_color_gdk->blue / 65535.);
2975 cairo_rectangle (cr,
2976 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2977 rubber_rect.width - 1, rubber_rect.height - 1);
2981 gdk_color_free (fill_color_gdk);
2985 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2991 index = gtk_tree_path_get_indices (path)[0];
2993 for (l = icon_view->priv->items; l; l = l->next)
2995 GtkIconViewItem *item = l->data;
2997 if (item->index == index)
2999 gtk_icon_view_queue_draw_item (icon_view, item);
3006 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3007 GtkIconViewItem *item)
3012 gtk_widget_style_get (GTK_WIDGET (icon_view),
3013 "focus-line-width", &focus_width,
3016 rect.x = item->x - focus_width;
3017 rect.y = item->y - focus_width;
3018 rect.width = item->width + 2 * focus_width;
3019 rect.height = item->height + 2 * focus_width;
3021 if (icon_view->priv->bin_window)
3022 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3026 layout_callback (gpointer user_data)
3028 GtkIconView *icon_view;
3030 GDK_THREADS_ENTER ();
3032 icon_view = GTK_ICON_VIEW (user_data);
3034 icon_view->priv->layout_idle_id = 0;
3036 gtk_icon_view_layout (icon_view);
3038 GDK_THREADS_LEAVE();
3044 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3046 if (icon_view->priv->layout_idle_id != 0)
3049 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3053 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3054 GtkIconViewItem *item,
3058 AtkObject *item_obj;
3060 if (icon_view->priv->cursor_item == item &&
3061 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3064 if (icon_view->priv->cursor_item != NULL)
3065 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3067 icon_view->priv->cursor_item = item;
3068 if (cursor_cell >= 0)
3069 icon_view->priv->cursor_cell = cursor_cell;
3071 gtk_icon_view_queue_draw_item (icon_view, item);
3073 /* Notify that accessible focus object has changed */
3074 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3075 item_obj = atk_object_ref_accessible_child (obj, item->index);
3077 if (item_obj != NULL)
3079 atk_focus_tracker_notify (item_obj);
3080 g_object_unref (item_obj);
3085 static GtkIconViewItem *
3086 gtk_icon_view_item_new (void)
3088 GtkIconViewItem *item;
3090 item = g_new0 (GtkIconViewItem, 1);
3099 gtk_icon_view_item_free (GtkIconViewItem *item)
3101 g_return_if_fail (item != NULL);
3103 g_free (item->before);
3104 g_free (item->after);
3111 static GtkIconViewItem *
3112 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3115 gboolean only_in_cell,
3116 GtkIconViewCellInfo **cell_at_pos)
3121 for (items = icon_view->priv->items; items; items = items->next)
3123 GtkIconViewItem *item = items->data;
3125 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3126 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3128 if (only_in_cell || cell_at_pos)
3130 gtk_icon_view_set_cell_data (icon_view, item);
3132 for (l = icon_view->priv->cell_list; l; l = l->next)
3134 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3136 if (!info->cell->visible)
3139 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3141 if ((x >= box.x && x <= box.x + box.width &&
3142 y >= box.y && y <= box.y + box.height) ||
3144 x <= box.x + box.width &&
3146 y <= box.y + box.height))
3149 *cell_at_pos = info;
3159 *cell_at_pos = NULL;
3170 gtk_icon_view_select_item (GtkIconView *icon_view,
3171 GtkIconViewItem *item)
3173 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3174 g_return_if_fail (item != NULL);
3179 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3181 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3182 gtk_icon_view_unselect_all_internal (icon_view);
3184 item->selected = TRUE;
3186 gtk_icon_view_queue_draw_item (icon_view, item);
3188 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3193 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3194 GtkIconViewItem *item)
3196 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3197 g_return_if_fail (item != NULL);
3199 if (!item->selected)
3202 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3203 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3206 item->selected = FALSE;
3208 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3210 gtk_icon_view_queue_draw_item (icon_view, item);
3214 verify_items (GtkIconView *icon_view)
3219 for (items = icon_view->priv->items; items; items = items->next)
3221 GtkIconViewItem *item = items->data;
3223 if (item->index != i)
3224 g_error ("List item does not match its index: "
3225 "item index %d and list index %d\n", item->index, i);
3232 gtk_icon_view_row_changed (GtkTreeModel *model,
3237 GtkIconViewItem *item;
3239 GtkIconView *icon_view;
3241 icon_view = GTK_ICON_VIEW (data);
3243 gtk_icon_view_stop_editing (icon_view, TRUE);
3245 index = gtk_tree_path_get_indices(path)[0];
3246 item = g_list_nth_data (icon_view->priv->items, index);
3248 gtk_icon_view_item_invalidate_size (item);
3249 gtk_icon_view_queue_layout (icon_view);
3251 verify_items (icon_view);
3255 gtk_icon_view_row_inserted (GtkTreeModel *model,
3261 GtkIconViewItem *item;
3262 gboolean iters_persist;
3263 GtkIconView *icon_view;
3266 icon_view = GTK_ICON_VIEW (data);
3268 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3270 index = gtk_tree_path_get_indices(path)[0];
3272 item = gtk_icon_view_item_new ();
3277 item->index = index;
3279 /* FIXME: We can be more efficient here,
3280 we can store a tail pointer and use that when
3281 appending (which is a rather common operation)
3283 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3286 list = g_list_nth (icon_view->priv->items, index + 1);
3287 for (; list; list = list->next)
3294 verify_items (icon_view);
3296 gtk_icon_view_queue_layout (icon_view);
3300 gtk_icon_view_row_deleted (GtkTreeModel *model,
3305 GtkIconView *icon_view;
3306 GtkIconViewItem *item;
3308 gboolean emit = FALSE;
3310 icon_view = GTK_ICON_VIEW (data);
3312 index = gtk_tree_path_get_indices(path)[0];
3314 list = g_list_nth (icon_view->priv->items, index);
3317 gtk_icon_view_stop_editing (icon_view, TRUE);
3319 if (item == icon_view->priv->anchor_item)
3320 icon_view->priv->anchor_item = NULL;
3322 if (item == icon_view->priv->cursor_item)
3323 icon_view->priv->cursor_item = NULL;
3328 gtk_icon_view_item_free (item);
3330 for (next = list->next; next; next = next->next)
3337 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3339 verify_items (icon_view);
3341 gtk_icon_view_queue_layout (icon_view);
3344 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3348 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3349 GtkTreePath *parent,
3356 GtkIconView *icon_view;
3357 GList *items = NULL, *list;
3358 GtkIconViewItem **item_array;
3361 icon_view = GTK_ICON_VIEW (data);
3363 gtk_icon_view_stop_editing (icon_view, TRUE);
3365 length = gtk_tree_model_iter_n_children (model, NULL);
3367 order = g_new (gint, length);
3368 for (i = 0; i < length; i++)
3369 order [new_order[i]] = i;
3371 item_array = g_new (GtkIconViewItem *, length);
3372 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3373 item_array[order[i]] = list->data;
3376 for (i = length - 1; i >= 0; i--)
3378 item_array[i]->index = i;
3379 items = g_list_prepend (items, item_array[i]);
3382 g_free (item_array);
3383 g_list_free (icon_view->priv->items);
3384 icon_view->priv->items = items;
3386 gtk_icon_view_queue_layout (icon_view);
3388 verify_items (icon_view);
3392 gtk_icon_view_build_items (GtkIconView *icon_view)
3396 gboolean iters_persist;
3397 GList *items = NULL;
3399 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3401 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3409 GtkIconViewItem *item = gtk_icon_view_item_new ();
3418 items = g_list_prepend (items, item);
3420 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3422 icon_view->priv->items = g_list_reverse (items);
3426 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3429 GtkMovementStep step,
3433 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3434 I_("move_cursor"), 2,
3438 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3443 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3446 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3451 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3458 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3459 GtkMovementStep step,
3462 GdkModifierType state;
3464 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3465 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3466 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3467 step == GTK_MOVEMENT_DISPLAY_LINES ||
3468 step == GTK_MOVEMENT_PAGES ||
3469 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3471 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3474 gtk_icon_view_stop_editing (icon_view, FALSE);
3475 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3477 if (gtk_get_current_event_state (&state))
3479 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3480 icon_view->priv->ctrl_pressed = TRUE;
3481 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3482 icon_view->priv->shift_pressed = TRUE;
3484 /* else we assume not pressed */
3488 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3489 case GTK_MOVEMENT_VISUAL_POSITIONS:
3490 gtk_icon_view_move_cursor_left_right (icon_view, count);
3492 case GTK_MOVEMENT_DISPLAY_LINES:
3493 gtk_icon_view_move_cursor_up_down (icon_view, count);
3495 case GTK_MOVEMENT_PAGES:
3496 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3498 case GTK_MOVEMENT_BUFFER_ENDS:
3499 gtk_icon_view_move_cursor_start_end (icon_view, count);
3502 g_assert_not_reached ();
3505 icon_view->priv->ctrl_pressed = FALSE;
3506 icon_view->priv->shift_pressed = FALSE;
3511 static GtkIconViewItem *
3512 find_item (GtkIconView *icon_view,
3513 GtkIconViewItem *current,
3519 GtkIconViewItem *item;
3521 /* FIXME: this could be more efficient
3523 row = current->row + row_ofs;
3524 col = current->col + col_ofs;
3526 for (items = icon_view->priv->items; items; items = items->next)
3529 if (item->row == row && item->col == col)
3537 find_cell (GtkIconView *icon_view,
3538 GtkIconViewItem *item,
3540 GtkOrientation orientation,
3551 if (icon_view->priv->orientation != orientation)
3554 gtk_icon_view_set_cell_data (icon_view, item);
3556 focusable = g_new0 (gint, icon_view->priv->n_cells);
3561 for (k = 0; k < 2; k++)
3562 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3564 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3566 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3569 if (!info->cell->visible)
3572 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3575 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3578 current = n_focusable;
3580 focusable[n_focusable] = i;
3586 if (n_focusable == 0)
3587 focusable[n_focusable++] = first_text;
3591 current = step > 0 ? 0 : n_focusable - 1;
3592 cell = focusable[current];
3595 if (current + *count < 0)
3598 *count = current + *count;
3600 else if (current + *count > n_focusable - 1)
3603 *count = current + *count - (n_focusable - 1);
3607 cell = focusable[current + *count];
3616 static GtkIconViewItem *
3617 find_item_page_up_down (GtkIconView *icon_view,
3618 GtkIconViewItem *current,
3625 y = current->y + count * icon_view->priv->vadjustment->page_size;
3627 item = g_list_find (icon_view->priv->items, current);
3632 for (next = item->next; next; next = next->next)
3634 if (((GtkIconViewItem *)next->data)->col == col)
3637 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3647 for (next = item->prev; next; next = next->prev)
3649 if (((GtkIconViewItem *)next->data)->col == col)
3652 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3666 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3667 GtkIconViewItem *anchor,
3668 GtkIconViewItem *cursor)
3671 GtkIconViewItem *item;
3672 gint row1, row2, col1, col2;
3673 gboolean dirty = FALSE;
3675 if (anchor->row < cursor->row)
3686 if (anchor->col < cursor->col)
3697 for (items = icon_view->priv->items; items; items = items->next)
3701 if (row1 <= item->row && item->row <= row2 &&
3702 col1 <= item->col && item->col <= col2)
3704 if (!item->selected)
3707 item->selected = TRUE;
3709 gtk_icon_view_queue_draw_item (icon_view, item);
3717 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3720 GtkIconViewItem *item;
3722 gboolean dirty = FALSE;
3725 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3728 if (!icon_view->priv->cursor_item)
3733 list = icon_view->priv->items;
3735 list = g_list_last (icon_view->priv->items);
3737 item = list ? list->data : NULL;
3742 item = icon_view->priv->cursor_item;
3743 cell = icon_view->priv->cursor_cell;
3744 step = count > 0 ? 1 : -1;
3747 cell = find_cell (icon_view, item, cell,
3748 GTK_ORIENTATION_VERTICAL,
3753 item = find_item (icon_view, item, step, 0);
3754 count = count - step;
3761 if (icon_view->priv->ctrl_pressed ||
3762 !icon_view->priv->shift_pressed ||
3763 !icon_view->priv->anchor_item ||
3764 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3765 icon_view->priv->anchor_item = item;
3767 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3769 if (!icon_view->priv->ctrl_pressed &&
3770 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3772 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3773 dirty = gtk_icon_view_select_all_between (icon_view,
3774 icon_view->priv->anchor_item,
3778 gtk_icon_view_scroll_to_item (icon_view, item);
3781 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3785 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3788 GtkIconViewItem *item;
3789 gboolean dirty = FALSE;
3791 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3794 if (!icon_view->priv->cursor_item)
3799 list = icon_view->priv->items;
3801 list = g_list_last (icon_view->priv->items);
3803 item = list ? list->data : NULL;
3806 item = find_item_page_up_down (icon_view,
3807 icon_view->priv->cursor_item,
3813 if (icon_view->priv->ctrl_pressed ||
3814 !icon_view->priv->shift_pressed ||
3815 !icon_view->priv->anchor_item ||
3816 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3817 icon_view->priv->anchor_item = item;
3819 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3821 if (!icon_view->priv->ctrl_pressed &&
3822 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3824 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3825 dirty = gtk_icon_view_select_all_between (icon_view,
3826 icon_view->priv->anchor_item,
3830 gtk_icon_view_scroll_to_item (icon_view, item);
3833 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3837 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3840 GtkIconViewItem *item;
3842 gboolean dirty = FALSE;
3845 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3848 if (!icon_view->priv->cursor_item)
3853 list = icon_view->priv->items;
3855 list = g_list_last (icon_view->priv->items);
3857 item = list ? list->data : NULL;
3861 item = icon_view->priv->cursor_item;
3862 cell = icon_view->priv->cursor_cell;
3863 step = count > 0 ? 1 : -1;
3866 cell = find_cell (icon_view, item, cell,
3867 GTK_ORIENTATION_HORIZONTAL,
3872 item = find_item (icon_view, item, 0, step);
3873 count = count - step;
3880 if (icon_view->priv->ctrl_pressed ||
3881 !icon_view->priv->shift_pressed ||
3882 !icon_view->priv->anchor_item ||
3883 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3884 icon_view->priv->anchor_item = item;
3886 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3888 if (!icon_view->priv->ctrl_pressed &&
3889 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3891 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3892 dirty = gtk_icon_view_select_all_between (icon_view,
3893 icon_view->priv->anchor_item,
3897 gtk_icon_view_scroll_to_item (icon_view, item);
3900 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3904 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3907 GtkIconViewItem *item;
3909 gboolean dirty = FALSE;
3911 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3915 list = icon_view->priv->items;
3917 list = g_list_last (icon_view->priv->items);
3919 item = list ? list->data : NULL;
3924 if (icon_view->priv->ctrl_pressed ||
3925 !icon_view->priv->shift_pressed ||
3926 !icon_view->priv->anchor_item ||
3927 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3928 icon_view->priv->anchor_item = item;
3930 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3932 if (!icon_view->priv->ctrl_pressed &&
3933 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3935 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3936 dirty = gtk_icon_view_select_all_between (icon_view,
3937 icon_view->priv->anchor_item,
3941 gtk_icon_view_scroll_to_item (icon_view, item);
3944 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3948 * gtk_icon_view_scroll_to_path:
3949 * @icon_view: A #GtkIconView.
3950 * @path: The path of the item to move to.
3951 * @use_align: whether to use alignment arguments, or %FALSE.
3952 * @row_align: The vertical alignment of the item specified by @path.
3953 * @col_align: The horizontal alignment of the item specified by @path.
3955 * Moves the alignments of @icon_view to the position specified by @path.
3956 * @row_align determines where the row is placed, and @col_align determines
3957 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3958 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
3961 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3962 * tree does the minimum amount of work to scroll the item onto the screen.
3963 * This means that the item will be scrolled to the edge closest to its current
3964 * position. If the item is currently visible on the screen, nothing is done.
3966 * This function only works if the model is set, and @path is a valid row on
3967 * the model. If the model changes before the @icon_view is realized, the
3968 * centered path will be modified to reflect this change.
3973 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3979 GtkIconViewItem *item = NULL;
3981 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3982 g_return_if_fail (path != NULL);
3983 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3984 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3986 if (gtk_tree_path_get_depth (path) > 0)
3987 item = g_list_nth_data (icon_view->priv->items,
3988 gtk_tree_path_get_indices(path)[0]);
3990 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
3992 if (icon_view->priv->scroll_to_path)
3993 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3995 icon_view->priv->scroll_to_path = NULL;
3998 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4000 icon_view->priv->scroll_to_use_align = use_align;
4001 icon_view->priv->scroll_to_row_align = row_align;
4002 icon_view->priv->scroll_to_col_align = col_align;
4011 gfloat offset, value;
4013 gtk_widget_style_get (GTK_WIDGET (icon_view),
4014 "focus-line-width", &focus_width,
4017 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4019 offset = y + item->y - focus_width -
4020 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4021 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4022 icon_view->priv->vadjustment->lower,
4023 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4024 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4026 offset = x + item->x - focus_width -
4027 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4028 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4029 icon_view->priv->hadjustment->lower,
4030 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4031 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4033 gtk_adjustment_changed (icon_view->priv->hadjustment);
4034 gtk_adjustment_changed (icon_view->priv->vadjustment);
4037 gtk_icon_view_scroll_to_item (icon_view, item);
4042 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4043 GtkIconViewItem *item)
4045 gint x, y, width, height;
4048 gtk_widget_style_get (GTK_WIDGET (icon_view),
4049 "focus-line-width", &focus_width,
4052 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4054 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4056 if (y + item->y - focus_width < 0)
4057 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4058 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4059 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4060 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4061 icon_view->priv->vadjustment->value + y + item->y + item->height
4062 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4064 if (x + item->x - focus_width < 0)
4065 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4066 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4067 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4068 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4069 icon_view->priv->hadjustment->value + x + item->x + item->width
4070 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4072 gtk_adjustment_changed (icon_view->priv->hadjustment);
4073 gtk_adjustment_changed (icon_view->priv->vadjustment);
4076 /* GtkCellLayout implementation */
4077 static GtkIconViewCellInfo *
4078 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4079 GtkCellRenderer *renderer)
4083 for (i = icon_view->priv->cell_list; i; i = i->next)
4085 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4087 if (info->cell == renderer)
4095 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4096 GtkIconViewItem *item)
4099 gboolean iters_persist;
4102 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4108 path = gtk_tree_path_new_from_indices (item->index, -1);
4109 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4110 gtk_tree_path_free (path);
4115 for (i = icon_view->priv->cell_list; i; i = i->next)
4118 GtkIconViewCellInfo *info = i->data;
4120 g_object_freeze_notify (G_OBJECT (info->cell));
4122 for (j = info->attributes; j && j->next; j = j->next->next)
4124 gchar *property = j->data;
4125 gint column = GPOINTER_TO_INT (j->next->data);
4126 GValue value = {0, };
4128 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4130 g_object_set_property (G_OBJECT (info->cell),
4132 g_value_unset (&value);
4136 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4138 icon_view->priv->model,
4142 g_object_thaw_notify (G_OBJECT (info->cell));
4145 adjust_wrap_width (icon_view, item);
4149 free_cell_attributes (GtkIconViewCellInfo *info)
4153 list = info->attributes;
4154 while (list && list->next)
4156 g_free (list->data);
4157 list = list->next->next;
4160 g_slist_free (info->attributes);
4161 info->attributes = NULL;
4165 free_cell_info (GtkIconViewCellInfo *info)
4167 free_cell_attributes (info);
4169 g_object_unref (info->cell);
4172 (* info->destroy) (info->func_data);
4178 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4179 GtkCellRenderer *renderer,
4182 GtkIconViewCellInfo *info;
4183 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4185 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4186 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4188 g_object_ref_sink (renderer);
4190 info = g_new0 (GtkIconViewCellInfo, 1);
4191 info->cell = renderer;
4192 info->expand = expand ? TRUE : FALSE;
4193 info->pack = GTK_PACK_START;
4194 info->position = icon_view->priv->n_cells;
4196 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4197 icon_view->priv->n_cells++;
4201 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4202 GtkCellRenderer *renderer,
4205 GtkIconViewCellInfo *info;
4206 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4208 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4209 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4211 g_object_ref_sink (renderer);
4213 info = g_new0 (GtkIconViewCellInfo, 1);
4214 info->cell = renderer;
4215 info->expand = expand ? TRUE : FALSE;
4216 info->pack = GTK_PACK_END;
4217 info->position = icon_view->priv->n_cells;
4219 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4220 icon_view->priv->n_cells++;
4224 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4225 GtkCellRenderer *renderer,
4226 const gchar *attribute,
4229 GtkIconViewCellInfo *info;
4230 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4232 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4233 g_return_if_fail (info != NULL);
4235 info->attributes = g_slist_prepend (info->attributes,
4236 GINT_TO_POINTER (column));
4237 info->attributes = g_slist_prepend (info->attributes,
4238 g_strdup (attribute));
4242 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4244 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4246 while (icon_view->priv->cell_list)
4248 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4249 free_cell_info (info);
4250 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4251 icon_view->priv->cell_list);
4254 icon_view->priv->n_cells = 0;
4258 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4259 GtkCellRenderer *cell,
4260 GtkCellLayoutDataFunc func,
4262 GDestroyNotify destroy)
4264 GtkIconViewCellInfo *info;
4265 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4267 info = gtk_icon_view_get_cell_info (icon_view, cell);
4268 g_return_if_fail (info != NULL);
4272 GDestroyNotify d = info->destroy;
4274 info->destroy = NULL;
4275 d (info->func_data);
4279 info->func_data = func_data;
4280 info->destroy = destroy;
4284 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4285 GtkCellRenderer *renderer)
4287 GtkIconViewCellInfo *info;
4289 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4291 free_cell_attributes (info);
4295 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4296 GtkCellRenderer *cell,
4299 GtkIconView *icon_view;
4301 GtkIconViewCellInfo *info;
4304 icon_view = GTK_ICON_VIEW (layout);
4306 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4308 info = gtk_icon_view_get_cell_info (icon_view, cell);
4310 g_return_if_fail (info != NULL);
4311 g_return_if_fail (position >= 0);
4313 link = g_list_find (icon_view->priv->cell_list, info);
4315 g_return_if_fail (link != NULL);
4317 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4319 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4322 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4329 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4336 * gtk_icon_view_new:
4338 * Creates a new #GtkIconView widget
4340 * Return value: A newly created #GtkIconView widget
4345 gtk_icon_view_new (void)
4347 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4351 * gtk_icon_view_new_with_model:
4352 * @model: The model.
4354 * Creates a new #GtkIconView widget with the model @model.
4356 * Return value: A newly created #GtkIconView widget.
4361 gtk_icon_view_new_with_model (GtkTreeModel *model)
4363 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4368 * gtk_icon_view_get_path_at_pos:
4369 * @icon_view: A #GtkIconView.
4370 * @x: The x position to be identified
4371 * @y: The y position to be identified
4373 * Finds the path at the point (@x, @y), relative to widget coordinates.
4374 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4375 * the cell at the specified position.
4377 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4378 * if no icon exists at that position.
4383 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4387 GtkIconViewItem *item;
4390 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4392 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4397 path = gtk_tree_path_new_from_indices (item->index, -1);
4403 * gtk_icon_view_get_item_at_pos:
4404 * @icon_view: A #GtkIconView.
4405 * @x: The x position to be identified
4406 * @y: The y position to be identified
4407 * @path: Return location for the path, or %NULL
4408 * @cell: Return location for the renderer responsible for the cell
4409 * at (@x, @y), or %NULL
4411 * Finds the path at the point (@x, @y), relative to widget coordinates.
4412 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4413 * obtains the cell at the specified position. The returned path should
4414 * be freed with gtk_tree_path_free().
4416 * Return value: %TRUE if an item exists at the specified position
4421 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4425 GtkCellRenderer **cell)
4427 GtkIconViewItem *item;
4428 GtkIconViewCellInfo *info;
4430 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4432 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4437 *path = gtk_tree_path_new_from_indices (item->index, -1);
4450 return (item != NULL);
4455 * gtk_icon_view_get_visible_range:
4456 * @icon_view: A #GtkIconView
4457 * @start_path: Return location for start of region, or %NULL
4458 * @end_path: Return location for end of region, or %NULL
4460 * Sets @start_path and @end_path to be the first and last visible path.
4461 * Note that there may be invisible paths in between.
4463 * Both paths should be freed with gtk_tree_path_free() after use.
4465 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4470 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4471 GtkTreePath **start_path,
4472 GtkTreePath **end_path)
4474 gint start_index = -1;
4475 gint end_index = -1;
4478 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4480 if (icon_view->priv->hadjustment == NULL ||
4481 icon_view->priv->vadjustment == NULL)
4484 if (start_path == NULL && end_path == NULL)
4487 for (icons = icon_view->priv->items; icons; icons = icons->next)
4489 GtkIconViewItem *item = icons->data;
4491 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4492 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4493 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4494 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4496 if (start_index == -1)
4497 start_index = item->index;
4498 end_index = item->index;
4502 if (start_path && start_index != -1)
4503 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4504 if (end_path && end_index != -1)
4505 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4507 return start_index != -1;
4511 * gtk_icon_view_selected_foreach:
4512 * @icon_view: A #GtkIconView.
4513 * @func: The funcion to call for each selected icon.
4514 * @data: User data to pass to the function.
4516 * Calls a function for each selected icon. Note that the model or
4517 * selection cannot be modified from within this function.
4522 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4523 GtkIconViewForeachFunc func,
4528 for (list = icon_view->priv->items; list; list = list->next)
4530 GtkIconViewItem *item = list->data;
4531 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4534 (* func) (icon_view, path, data);
4536 gtk_tree_path_free (path);
4541 * gtk_icon_view_set_selection_mode:
4542 * @icon_view: A #GtkIconView.
4543 * @mode: The selection mode
4545 * Sets the selection mode of the @icon_view.
4550 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4551 GtkSelectionMode mode)
4553 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4555 if (mode == icon_view->priv->selection_mode)
4558 if (mode == GTK_SELECTION_NONE ||
4559 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4560 gtk_icon_view_unselect_all (icon_view);
4562 icon_view->priv->selection_mode = mode;
4564 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4568 * gtk_icon_view_get_selection_mode:
4569 * @icon_view: A #GtkIconView.
4571 * Gets the selection mode of the @icon_view.
4573 * Return value: the current selection mode
4578 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4580 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4582 return icon_view->priv->selection_mode;
4586 * gtk_icon_view_set_model:
4587 * @icon_view: A #GtkIconView.
4588 * @model: The model.
4590 * Sets the model for a #GtkIconView.
4591 * If the @icon_view already has a model set, it will remove
4592 * it before setting the new model. If @model is %NULL, then
4593 * it will unset the old model.
4598 gtk_icon_view_set_model (GtkIconView *icon_view,
4599 GtkTreeModel *model)
4601 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4602 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4604 if (icon_view->priv->model == model)
4607 if (icon_view->priv->scroll_to_path)
4609 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4610 icon_view->priv->scroll_to_path = NULL;
4613 gtk_icon_view_stop_editing (icon_view, TRUE);
4619 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4621 if (icon_view->priv->pixbuf_column != -1)
4623 column_type = gtk_tree_model_get_column_type (model,
4624 icon_view->priv->pixbuf_column);
4626 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4629 if (icon_view->priv->text_column != -1)
4631 column_type = gtk_tree_model_get_column_type (model,
4632 icon_view->priv->text_column);
4634 g_return_if_fail (column_type == G_TYPE_STRING);
4637 if (icon_view->priv->markup_column != -1)
4639 column_type = gtk_tree_model_get_column_type (model,
4640 icon_view->priv->markup_column);
4642 g_return_if_fail (column_type == G_TYPE_STRING);
4647 if (icon_view->priv->model)
4649 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4650 gtk_icon_view_row_changed,
4652 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4653 gtk_icon_view_row_inserted,
4655 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4656 gtk_icon_view_row_deleted,
4658 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4659 gtk_icon_view_rows_reordered,
4662 g_object_unref (icon_view->priv->model);
4664 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4665 g_list_free (icon_view->priv->items);
4666 icon_view->priv->items = NULL;
4667 icon_view->priv->anchor_item = NULL;
4668 icon_view->priv->cursor_item = NULL;
4669 icon_view->priv->last_single_clicked = NULL;
4670 icon_view->priv->width = 0;
4671 icon_view->priv->height = 0;
4674 icon_view->priv->model = model;
4676 if (icon_view->priv->model)
4678 g_object_ref (icon_view->priv->model);
4679 g_signal_connect (icon_view->priv->model,
4681 G_CALLBACK (gtk_icon_view_row_changed),
4683 g_signal_connect (icon_view->priv->model,
4685 G_CALLBACK (gtk_icon_view_row_inserted),
4687 g_signal_connect (icon_view->priv->model,
4689 G_CALLBACK (gtk_icon_view_row_deleted),
4691 g_signal_connect (icon_view->priv->model,
4693 G_CALLBACK (gtk_icon_view_rows_reordered),
4696 gtk_icon_view_build_items (icon_view);
4698 gtk_icon_view_queue_layout (icon_view);
4701 g_object_notify (G_OBJECT (icon_view), "model");
4703 if (GTK_WIDGET_REALIZED (icon_view))
4704 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4708 * gtk_icon_view_get_model:
4709 * @icon_view: a #GtkIconView
4711 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4714 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4719 gtk_icon_view_get_model (GtkIconView *icon_view)
4721 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4723 return icon_view->priv->model;
4727 update_text_cell (GtkIconView *icon_view)
4729 GtkIconViewCellInfo *info;
4733 if (icon_view->priv->text_column == -1 &&
4734 icon_view->priv->markup_column == -1)
4736 if (icon_view->priv->text_cell != -1)
4738 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4739 icon_view->priv->pixbuf_cell--;
4741 info = g_list_nth_data (icon_view->priv->cell_list,
4742 icon_view->priv->text_cell);
4744 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4746 free_cell_info (info);
4748 icon_view->priv->n_cells--;
4749 icon_view->priv->text_cell = -1;
4754 if (icon_view->priv->text_cell == -1)
4756 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4757 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4758 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4761 if (info->cell == cell)
4763 icon_view->priv->text_cell = i;
4769 info = g_list_nth_data (icon_view->priv->cell_list,
4770 icon_view->priv->text_cell);
4772 if (icon_view->priv->markup_column != -1)
4773 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4775 "markup", icon_view->priv->markup_column,
4778 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4780 "text", icon_view->priv->text_column,
4783 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4784 g_object_set (info->cell,
4785 "wrap-mode", PANGO_WRAP_CHAR,
4786 "wrap-width", icon_view->priv->item_width,
4791 g_object_set (info->cell,
4792 "wrap-mode", PANGO_WRAP_CHAR,
4793 "wrap-width", icon_view->priv->item_width,
4801 update_pixbuf_cell (GtkIconView *icon_view)
4803 GtkIconViewCellInfo *info;
4807 if (icon_view->priv->pixbuf_column == -1)
4809 if (icon_view->priv->pixbuf_cell != -1)
4811 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4812 icon_view->priv->text_cell--;
4814 info = g_list_nth_data (icon_view->priv->cell_list,
4815 icon_view->priv->pixbuf_cell);
4817 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4819 free_cell_info (info);
4821 icon_view->priv->n_cells--;
4822 icon_view->priv->pixbuf_cell = -1;
4827 if (icon_view->priv->pixbuf_cell == -1)
4829 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4831 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4832 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4835 if (info->cell == cell)
4837 icon_view->priv->pixbuf_cell = i;
4843 info = g_list_nth_data (icon_view->priv->cell_list,
4844 icon_view->priv->pixbuf_cell);
4846 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4848 "pixbuf", icon_view->priv->pixbuf_column,
4851 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4852 g_object_set (info->cell,
4853 "follow-state", TRUE,
4858 g_object_set (info->cell,
4859 "follow-state", TRUE,
4867 * gtk_icon_view_set_text_column:
4868 * @icon_view: A #GtkIconView.
4869 * @column: A column in the currently used model.
4871 * Sets the column with text for @icon_view to be @column. The text
4872 * column must be of type #G_TYPE_STRING.
4877 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4880 if (column == icon_view->priv->text_column)
4884 icon_view->priv->text_column = -1;
4887 if (icon_view->priv->model != NULL)
4891 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4893 g_return_if_fail (column_type == G_TYPE_STRING);
4896 icon_view->priv->text_column = column;
4899 gtk_icon_view_stop_editing (icon_view, TRUE);
4901 update_text_cell (icon_view);
4903 gtk_icon_view_invalidate_sizes (icon_view);
4904 gtk_icon_view_queue_layout (icon_view);
4906 g_object_notify (G_OBJECT (icon_view), "text-column");
4910 * gtk_icon_view_get_text_column:
4911 * @icon_view: A #GtkIconView.
4913 * Returns the column with text for @icon_view.
4915 * Returns: the text column, or -1 if it's unset.
4920 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4922 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4924 return icon_view->priv->text_column;
4928 * gtk_icon_view_set_markup_column:
4929 * @icon_view: A #GtkIconView.
4930 * @column: A column in the currently used model.
4932 * Sets the column with markup information for @icon_view to be
4933 * @column. The markup column must be of type #G_TYPE_STRING.
4934 * If the markup column is set to something, it overrides
4935 * the text column set by gtk_icon_view_set_text_column().
4940 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4943 if (column == icon_view->priv->markup_column)
4947 icon_view->priv->markup_column = -1;
4950 if (icon_view->priv->model != NULL)
4954 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4956 g_return_if_fail (column_type == G_TYPE_STRING);
4959 icon_view->priv->markup_column = column;
4962 gtk_icon_view_stop_editing (icon_view, TRUE);
4964 update_text_cell (icon_view);
4966 gtk_icon_view_invalidate_sizes (icon_view);
4967 gtk_icon_view_queue_layout (icon_view);
4969 g_object_notify (G_OBJECT (icon_view), "markup-column");
4973 * gtk_icon_view_get_markup_column:
4974 * @icon_view: A #GtkIconView.
4976 * Returns the column with markup text for @icon_view.
4978 * Returns: the markup column, or -1 if it's unset.
4983 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4985 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4987 return icon_view->priv->markup_column;
4991 * gtk_icon_view_set_pixbuf_column:
4992 * @icon_view: A #GtkIconView.
4993 * @column: A column in the currently used model.
4995 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4996 * column must be of type #GDK_TYPE_PIXBUF
5001 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5004 if (column == icon_view->priv->pixbuf_column)
5008 icon_view->priv->pixbuf_column = -1;
5011 if (icon_view->priv->model != NULL)
5015 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5017 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5020 icon_view->priv->pixbuf_column = column;
5023 gtk_icon_view_stop_editing (icon_view, TRUE);
5025 update_pixbuf_cell (icon_view);
5027 gtk_icon_view_invalidate_sizes (icon_view);
5028 gtk_icon_view_queue_layout (icon_view);
5030 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5035 * gtk_icon_view_get_pixbuf_column:
5036 * @icon_view: A #GtkIconView.
5038 * Returns the column with pixbufs for @icon_view.
5040 * Returns: the pixbuf column, or -1 if it's unset.
5045 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5047 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5049 return icon_view->priv->pixbuf_column;
5053 * gtk_icon_view_select_path:
5054 * @icon_view: A #GtkIconView.
5055 * @path: The #GtkTreePath to be selected.
5057 * Selects the row at @path.
5062 gtk_icon_view_select_path (GtkIconView *icon_view,
5065 GtkIconViewItem *item = NULL;
5067 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5068 g_return_if_fail (icon_view->priv->model != NULL);
5069 g_return_if_fail (path != NULL);
5071 if (gtk_tree_path_get_depth (path) > 0)
5072 item = g_list_nth_data (icon_view->priv->items,
5073 gtk_tree_path_get_indices(path)[0]);
5076 gtk_icon_view_select_item (icon_view, item);
5080 * gtk_icon_view_unselect_path:
5081 * @icon_view: A #GtkIconView.
5082 * @path: The #GtkTreePath to be unselected.
5084 * Unselects the row at @path.
5089 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5092 GtkIconViewItem *item;
5094 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5095 g_return_if_fail (icon_view->priv->model != NULL);
5096 g_return_if_fail (path != NULL);
5098 item = g_list_nth_data (icon_view->priv->items,
5099 gtk_tree_path_get_indices(path)[0]);
5104 gtk_icon_view_unselect_item (icon_view, item);
5108 * gtk_icon_view_get_selected_items:
5109 * @icon_view: A #GtkIconView.
5111 * Creates a list of paths of all selected items. Additionally, if you are
5112 * planning on modifying the model after calling this function, you may
5113 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5114 * To do this, you can use gtk_tree_row_reference_new().
5116 * To free the return value, use:
5117 * <informalexample><programlisting>
5118 * g_list_foreach (list, gtk_tree_path_free, NULL);
5119 * g_list_free (list);
5120 * </programlisting></informalexample>
5122 * Return value: A #GList containing a #GtkTreePath for each selected row.
5127 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5130 GList *selected = NULL;
5132 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5134 for (list = icon_view->priv->items; list != NULL; list = list->next)
5136 GtkIconViewItem *item = list->data;
5140 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5142 selected = g_list_prepend (selected, path);
5150 * gtk_icon_view_select_all:
5151 * @icon_view: A #GtkIconView.
5153 * Selects all the icons. @icon_view must has its selection mode set
5154 * to #GTK_SELECTION_MULTIPLE.
5159 gtk_icon_view_select_all (GtkIconView *icon_view)
5162 gboolean dirty = FALSE;
5164 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5166 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5169 for (items = icon_view->priv->items; items; items = items->next)
5171 GtkIconViewItem *item = items->data;
5173 if (!item->selected)
5176 item->selected = TRUE;
5177 gtk_icon_view_queue_draw_item (icon_view, item);
5182 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5186 * gtk_icon_view_unselect_all:
5187 * @icon_view: A #GtkIconView.
5189 * Unselects all the icons.
5194 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5196 gboolean dirty = FALSE;
5198 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5200 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5203 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5206 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5210 * gtk_icon_view_path_is_selected:
5211 * @icon_view: A #GtkIconView.
5212 * @path: A #GtkTreePath to check selection on.
5214 * Returns %TRUE if the icon pointed to by @path is currently
5215 * selected. If @icon does not point to a valid location, %FALSE is returned.
5217 * Return value: %TRUE if @path is selected.
5222 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5225 GtkIconViewItem *item;
5227 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5228 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5229 g_return_val_if_fail (path != NULL, FALSE);
5231 item = g_list_nth_data (icon_view->priv->items,
5232 gtk_tree_path_get_indices(path)[0]);
5237 return item->selected;
5241 * gtk_icon_view_item_activated:
5242 * @icon_view: A #GtkIconView
5243 * @path: The #GtkTreePath to be activated
5245 * Activates the item determined by @path.
5250 gtk_icon_view_item_activated (GtkIconView *icon_view,
5253 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5254 g_return_if_fail (path != NULL);
5256 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5260 * gtk_icon_view_set_orientation:
5261 * @icon_view: a #GtkIconView
5262 * @orientation: the relative position of texts and icons
5264 * Sets the ::orientation property which determines whether the labels
5265 * are drawn beside the icons instead of below.
5270 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5271 GtkOrientation orientation)
5273 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5275 if (icon_view->priv->orientation != orientation)
5277 icon_view->priv->orientation = orientation;
5279 gtk_icon_view_stop_editing (icon_view, TRUE);
5280 gtk_icon_view_invalidate_sizes (icon_view);
5281 gtk_icon_view_queue_layout (icon_view);
5283 update_text_cell (icon_view);
5284 update_pixbuf_cell (icon_view);
5286 g_object_notify (G_OBJECT (icon_view), "orientation");
5291 * gtk_icon_view_get_orientation:
5292 * @icon_view: a #GtkIconView
5294 * Returns the value of the ::orientation property which determines
5295 * whether the labels are drawn beside the icons instead of below.
5297 * Return value: the relative position of texts and icons
5302 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5304 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5305 GTK_ORIENTATION_VERTICAL);
5307 return icon_view->priv->orientation;
5311 * gtk_icon_view_set_columns:
5312 * @icon_view: a #GtkIconView
5313 * @columns: the number of columns
5315 * Sets the ::columns property which determines in how
5316 * many columns the icons are arranged. If @columns is
5317 * -1, the number of columns will be chosen automatically
5318 * to fill the available area.
5323 gtk_icon_view_set_columns (GtkIconView *icon_view,
5326 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5328 if (icon_view->priv->columns != columns)
5330 icon_view->priv->columns = columns;
5332 gtk_icon_view_stop_editing (icon_view, TRUE);
5333 gtk_icon_view_queue_layout (icon_view);
5335 g_object_notify (G_OBJECT (icon_view), "columns");
5340 * gtk_icon_view_get_columns:
5341 * @icon_view: a #GtkIconView
5343 * Returns the value of the ::columns property.
5345 * Return value: the number of columns, or -1
5350 gtk_icon_view_get_columns (GtkIconView *icon_view)
5352 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5354 return icon_view->priv->columns;
5358 * gtk_icon_view_set_item_width:
5359 * @icon_view: a #GtkIconView
5360 * @item_width: the width for each item
5362 * Sets the ::item-width property which specifies the width
5363 * to use for each item. If it is set to -1, the icon view will
5364 * automatically determine a suitable item size.
5369 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5372 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5374 if (icon_view->priv->item_width != item_width)
5376 icon_view->priv->item_width = item_width;
5378 gtk_icon_view_stop_editing (icon_view, TRUE);
5379 gtk_icon_view_invalidate_sizes (icon_view);
5380 gtk_icon_view_queue_layout (icon_view);
5382 update_text_cell (icon_view);
5384 g_object_notify (G_OBJECT (icon_view), "item-width");
5389 * gtk_icon_view_get_item_width:
5390 * @icon_view: a #GtkIconView
5392 * Returns the value of the ::item-width property.
5394 * Return value: the width of a single item, or -1
5399 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5401 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5403 return icon_view->priv->item_width;
5408 * gtk_icon_view_set_spacing:
5409 * @icon_view: a #GtkIconView
5410 * @spacing: the spacing
5412 * Sets the ::spacing property which specifies the space
5413 * which is inserted between the cells (i.e. the icon and
5414 * the text) of an item.
5419 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5422 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5424 if (icon_view->priv->spacing != spacing)
5426 icon_view->priv->spacing = spacing;
5428 gtk_icon_view_stop_editing (icon_view, TRUE);
5429 gtk_icon_view_invalidate_sizes (icon_view);
5430 gtk_icon_view_queue_layout (icon_view);
5432 g_object_notify (G_OBJECT (icon_view), "spacing");
5437 * gtk_icon_view_get_spacing:
5438 * @icon_view: a #GtkIconView
5440 * Returns the value of the ::spacing property.
5442 * Return value: the space between cells
5447 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5449 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5451 return icon_view->priv->spacing;
5455 * gtk_icon_view_set_row_spacing:
5456 * @icon_view: a #GtkIconView
5457 * @row_spacing: the row spacing
5459 * Sets the ::row-spacing property which specifies the space
5460 * which is inserted between the rows of the icon view.
5465 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5468 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5470 if (icon_view->priv->row_spacing != row_spacing)
5472 icon_view->priv->row_spacing = row_spacing;
5474 gtk_icon_view_stop_editing (icon_view, TRUE);
5475 gtk_icon_view_invalidate_sizes (icon_view);
5476 gtk_icon_view_queue_layout (icon_view);
5478 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5483 * gtk_icon_view_get_row_spacing:
5484 * @icon_view: a #GtkIconView
5486 * Returns the value of the ::row-spacing property.
5488 * Return value: the space between rows
5493 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5495 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5497 return icon_view->priv->row_spacing;
5501 * gtk_icon_view_set_column_spacing:
5502 * @icon_view: a #GtkIconView
5503 * @column_spacing: the column spacing
5505 * Sets the ::column-spacing property which specifies the space
5506 * which is inserted between the columns of the icon view.
5511 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5512 gint column_spacing)
5514 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5516 if (icon_view->priv->column_spacing != column_spacing)
5518 icon_view->priv->column_spacing = column_spacing;
5520 gtk_icon_view_stop_editing (icon_view, TRUE);
5521 gtk_icon_view_invalidate_sizes (icon_view);
5522 gtk_icon_view_queue_layout (icon_view);
5524 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5529 * gtk_icon_view_get_column_spacing:
5530 * @icon_view: a #GtkIconView
5532 * Returns the value of the ::column-spacing property.
5534 * Return value: the space between columns
5539 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5541 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5543 return icon_view->priv->column_spacing;
5547 * gtk_icon_view_set_margin:
5548 * @icon_view: a #GtkIconView
5549 * @margin: the margin
5551 * Sets the ::margin property which specifies the space
5552 * which is inserted at the top, bottom, left and right
5558 gtk_icon_view_set_margin (GtkIconView *icon_view,
5561 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5563 if (icon_view->priv->margin != margin)
5565 icon_view->priv->margin = margin;
5567 gtk_icon_view_stop_editing (icon_view, TRUE);
5568 gtk_icon_view_invalidate_sizes (icon_view);
5569 gtk_icon_view_queue_layout (icon_view);
5571 g_object_notify (G_OBJECT (icon_view), "margin");
5576 * gtk_icon_view_get_margin:
5577 * @icon_view: a #GtkIconView
5579 * Returns the value of the ::margin property.
5581 * Return value: the space at the borders
5586 gtk_icon_view_get_margin (GtkIconView *icon_view)
5588 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5590 return icon_view->priv->margin;
5594 /* Get/set whether drag_motion requested the drag data and
5595 * drag_data_received should thus not actually insert the data,
5596 * since the data doesn't result from a drop.
5599 set_status_pending (GdkDragContext *context,
5600 GdkDragAction suggested_action)
5602 g_object_set_data (G_OBJECT (context),
5603 I_("gtk-icon-view-status-pending"),
5604 GINT_TO_POINTER (suggested_action));
5607 static GdkDragAction
5608 get_status_pending (GdkDragContext *context)
5610 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5611 "gtk-icon-view-status-pending"));
5615 unset_reorderable (GtkIconView *icon_view)
5617 if (icon_view->priv->reorderable)
5619 icon_view->priv->reorderable = FALSE;
5620 g_object_notify (G_OBJECT (icon_view), "reorderable");
5625 clear_source_info (GtkIconView *icon_view)
5627 if (icon_view->priv->source_targets)
5628 gtk_target_list_unref (icon_view->priv->source_targets);
5629 icon_view->priv->source_targets = NULL;
5631 icon_view->priv->source_set = FALSE;
5635 clear_dest_info (GtkIconView *icon_view)
5637 if (icon_view->priv->dest_targets)
5638 gtk_target_list_unref (icon_view->priv->dest_targets);
5639 icon_view->priv->dest_targets = NULL;
5641 icon_view->priv->dest_set = FALSE;
5645 set_source_row (GdkDragContext *context,
5646 GtkTreeModel *model,
5647 GtkTreePath *source_row)
5650 g_object_set_data_full (G_OBJECT (context),
5651 I_("gtk-icon-view-source-row"),
5652 gtk_tree_row_reference_new (model, source_row),
5653 (GDestroyNotify) gtk_tree_row_reference_free);
5655 g_object_set_data_full (G_OBJECT (context),
5656 I_("gtk-icon-view-source-row"),
5661 get_source_row (GdkDragContext *context)
5663 GtkTreeRowReference *ref;
5665 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5668 return gtk_tree_row_reference_get_path (ref);
5675 GtkTreeRowReference *dest_row;
5676 gboolean empty_view_drop;
5677 gboolean drop_append_mode;
5681 dest_row_free (gpointer data)
5683 DestRow *dr = (DestRow *)data;
5685 gtk_tree_row_reference_free (dr->dest_row);
5690 set_dest_row (GdkDragContext *context,
5691 GtkTreeModel *model,
5692 GtkTreePath *dest_row,
5693 gboolean empty_view_drop,
5694 gboolean drop_append_mode)
5700 g_object_set_data_full (G_OBJECT (context),
5701 I_("gtk-icon-view-dest-row"),
5706 dr = g_new0 (DestRow, 1);
5708 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5709 dr->empty_view_drop = empty_view_drop;
5710 dr->drop_append_mode = drop_append_mode;
5711 g_object_set_data_full (G_OBJECT (context),
5712 I_("gtk-icon-view-dest-row"),
5713 dr, (GDestroyNotify) dest_row_free);
5717 get_dest_row (GdkDragContext *context)
5721 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5725 GtkTreePath *path = NULL;
5728 path = gtk_tree_row_reference_get_path (dr->dest_row);
5729 else if (dr->empty_view_drop)
5730 path = gtk_tree_path_new_from_indices (0, -1);
5734 if (path && dr->drop_append_mode)
5735 gtk_tree_path_next (path);
5744 check_model_dnd (GtkTreeModel *model,
5745 GType required_iface,
5746 const gchar *signal)
5748 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5750 g_warning ("You must override the default '%s' handler "
5751 "on GtkIconView when using models that don't support "
5752 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5753 "is to connect to '%s' and call "
5754 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5755 "the default handler from running. Look at the source code "
5756 "for the default handler in gtkiconview.c to get an idea what "
5757 "your handler should do. (gtkiconview.c is in the GTK+ source "
5758 "code.) If you're using GTK+ from a language other than C, "
5759 "there may be a more natural way to override default handlers, e.g. via derivation.",
5760 signal, g_type_name (required_iface), signal);
5768 remove_scroll_timeout (GtkIconView *icon_view)
5770 if (icon_view->priv->scroll_timeout_id != 0)
5772 g_source_remove (icon_view->priv->scroll_timeout_id);
5774 icon_view->priv->scroll_timeout_id = 0;
5779 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5781 gint px, py, x, y, width, height;
5782 gint hoffset, voffset;
5785 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5786 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5788 /* see if we are near the edge. */
5789 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5791 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5793 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5795 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5799 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5800 icon_view->priv->vadjustment->lower,
5801 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5802 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5806 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5807 icon_view->priv->hadjustment->lower,
5808 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5809 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5815 drag_scroll_timeout (gpointer data)
5817 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5819 GDK_THREADS_ENTER ();
5821 gtk_icon_view_autoscroll (icon_view);
5823 GDK_THREADS_LEAVE ();
5830 set_destination (GtkIconView *icon_view,
5831 GdkDragContext *context,
5834 GdkDragAction *suggested_action,
5838 GtkTreePath *path = NULL;
5839 GtkIconViewDropPosition pos;
5840 GtkIconViewDropPosition old_pos;
5841 GtkTreePath *old_dest_path = NULL;
5842 gboolean can_drop = FALSE;
5844 widget = GTK_WIDGET (icon_view);
5846 *suggested_action = 0;
5849 if (!icon_view->priv->dest_set)
5851 /* someone unset us as a drag dest, note that if
5852 * we return FALSE drag_leave isn't called
5855 gtk_icon_view_set_drag_dest_item (icon_view,
5857 GTK_ICON_VIEW_DROP_LEFT);
5859 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5861 return FALSE; /* no longer a drop site */
5864 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5865 if (*target == GDK_NONE)
5868 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5871 GtkTreeModel *model;
5873 /* the row got dropped on empty space, let's setup a special case
5877 gtk_tree_path_free (path);
5879 model = gtk_icon_view_get_model (icon_view);
5881 n_children = gtk_tree_model_iter_n_children (model, NULL);
5884 pos = GTK_ICON_VIEW_DROP_BELOW;
5885 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5889 pos = GTK_ICON_VIEW_DROP_ABOVE;
5890 path = gtk_tree_path_new_from_indices (0, -1);
5900 gtk_icon_view_get_drag_dest_item (icon_view,
5905 gtk_tree_path_free (old_dest_path);
5907 if (TRUE /* FIXME if the location droppable predicate */)
5915 GtkWidget *source_widget;
5917 *suggested_action = context->suggested_action;
5918 source_widget = gtk_drag_get_source_widget (context);
5920 if (source_widget == widget)
5922 /* Default to MOVE, unless the user has
5923 * pressed ctrl or shift to affect available actions
5925 if ((context->actions & GDK_ACTION_MOVE) != 0)
5926 *suggested_action = GDK_ACTION_MOVE;
5929 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5934 /* can't drop here */
5935 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5937 GTK_ICON_VIEW_DROP_LEFT);
5941 gtk_tree_path_free (path);
5947 get_logical_destination (GtkIconView *icon_view,
5948 gboolean *drop_append_mode)
5950 /* adjust path to point to the row the drop goes in front of */
5951 GtkTreePath *path = NULL;
5952 GtkIconViewDropPosition pos;
5954 *drop_append_mode = FALSE;
5956 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5961 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5962 pos == GTK_ICON_VIEW_DROP_BELOW)
5965 GtkTreeModel *model = icon_view->priv->model;
5967 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5968 !gtk_tree_model_iter_next (model, &iter))
5969 *drop_append_mode = TRUE;
5972 *drop_append_mode = FALSE;
5973 gtk_tree_path_next (path);
5981 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5982 GdkEventMotion *event)
5984 GdkDragContext *context;
5985 GtkTreePath *path = NULL;
5987 GtkTreeModel *model;
5988 gboolean retval = FALSE;
5990 if (!icon_view->priv->source_set)
5993 if (icon_view->priv->pressed_button < 0)
5996 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5997 icon_view->priv->press_start_x,
5998 icon_view->priv->press_start_y,
5999 event->x, event->y))
6002 model = gtk_icon_view_get_model (icon_view);
6007 button = icon_view->priv->pressed_button;
6008 icon_view->priv->pressed_button = -1;
6010 path = gtk_icon_view_get_path_at_pos (icon_view,
6011 icon_view->priv->press_start_x,
6012 icon_view->priv->press_start_y);
6017 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6018 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6022 /* FIXME Check whether we're a start button, if not return FALSE and
6026 /* Now we can begin the drag */
6030 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6031 icon_view->priv->source_targets,
6032 icon_view->priv->source_actions,
6036 set_source_row (context, model, path);
6040 gtk_tree_path_free (path);
6045 /* Source side drag signals */
6047 gtk_icon_view_drag_begin (GtkWidget *widget,
6048 GdkDragContext *context)
6050 GtkIconView *icon_view;
6051 GtkIconViewItem *item;
6056 icon_view = GTK_ICON_VIEW (widget);
6058 /* if the user uses a custom DnD impl, we don't set the icon here */
6059 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6062 item = gtk_icon_view_get_item_at_coords (icon_view,
6063 icon_view->priv->press_start_x,
6064 icon_view->priv->press_start_y,
6068 g_return_if_fail (item != NULL);
6070 x = icon_view->priv->press_start_x - item->x + 1;
6071 y = icon_view->priv->press_start_y - item->y + 1;
6073 path = gtk_tree_path_new_from_indices (item->index, -1);
6074 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6075 gtk_tree_path_free (path);
6077 gtk_drag_set_icon_pixmap (context,
6078 gdk_drawable_get_colormap (icon),
6083 g_object_unref (icon);
6087 gtk_icon_view_drag_end (GtkWidget *widget,
6088 GdkDragContext *context)
6094 gtk_icon_view_drag_data_get (GtkWidget *widget,
6095 GdkDragContext *context,
6096 GtkSelectionData *selection_data,
6100 GtkIconView *icon_view;
6101 GtkTreeModel *model;
6102 GtkTreePath *source_row;
6104 icon_view = GTK_ICON_VIEW (widget);
6105 model = gtk_icon_view_get_model (icon_view);
6110 if (!icon_view->priv->dest_set)
6113 source_row = get_source_row (context);
6115 if (source_row == NULL)
6118 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6119 * any model; for DragSource models there are some other targets
6123 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6124 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6129 /* If drag_data_get does nothing, try providing row data. */
6130 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6131 gtk_tree_set_row_drag_data (selection_data,
6136 gtk_tree_path_free (source_row);
6140 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6141 GdkDragContext *context)
6143 GtkTreeModel *model;
6144 GtkIconView *icon_view;
6145 GtkTreePath *source_row;
6147 icon_view = GTK_ICON_VIEW (widget);
6148 model = gtk_icon_view_get_model (icon_view);
6150 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6153 if (!icon_view->priv->dest_set)
6156 source_row = get_source_row (context);
6158 if (source_row == NULL)
6161 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6164 gtk_tree_path_free (source_row);
6166 set_source_row (context, NULL, NULL);
6169 /* Target side drag signals */
6171 gtk_icon_view_drag_leave (GtkWidget *widget,
6172 GdkDragContext *context,
6175 GtkIconView *icon_view;
6177 icon_view = GTK_ICON_VIEW (widget);
6179 /* unset any highlight row */
6180 gtk_icon_view_set_drag_dest_item (icon_view,
6182 GTK_ICON_VIEW_DROP_LEFT);
6184 remove_scroll_timeout (icon_view);
6188 gtk_icon_view_drag_motion (GtkWidget *widget,
6189 GdkDragContext *context,
6194 GtkTreePath *path = NULL;
6195 GtkIconViewDropPosition pos;
6196 GtkIconView *icon_view;
6197 GdkDragAction suggested_action = 0;
6201 icon_view = GTK_ICON_VIEW (widget);
6203 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6206 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6208 /* we only know this *after* set_desination_row */
6209 empty = icon_view->priv->empty_view_drop;
6211 if (path == NULL && !empty)
6213 /* Can't drop here. */
6214 gdk_drag_status (context, 0, time);
6218 if (icon_view->priv->scroll_timeout_id == 0)
6220 icon_view->priv->scroll_timeout_id =
6221 g_timeout_add (50, drag_scroll_timeout, icon_view);
6224 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6226 /* Request data so we can use the source row when
6227 * determining whether to accept the drop
6229 set_status_pending (context, suggested_action);
6230 gtk_drag_get_data (widget, context, target, time);
6234 set_status_pending (context, 0);
6235 gdk_drag_status (context, suggested_action, time);
6240 gtk_tree_path_free (path);
6246 gtk_icon_view_drag_drop (GtkWidget *widget,
6247 GdkDragContext *context,
6252 GtkIconView *icon_view;
6254 GdkDragAction suggested_action = 0;
6255 GdkAtom target = GDK_NONE;
6256 GtkTreeModel *model;
6257 gboolean drop_append_mode;
6259 icon_view = GTK_ICON_VIEW (widget);
6260 model = gtk_icon_view_get_model (icon_view);
6262 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6264 if (!icon_view->priv->dest_set)
6267 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6270 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6273 path = get_logical_destination (icon_view, &drop_append_mode);
6275 if (target != GDK_NONE && path != NULL)
6277 /* in case a motion had requested drag data, change things so we
6278 * treat drag data receives as a drop.
6280 set_status_pending (context, 0);
6281 set_dest_row (context, model, path,
6282 icon_view->priv->empty_view_drop, drop_append_mode);
6286 gtk_tree_path_free (path);
6288 /* Unset this thing */
6289 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6291 if (target != GDK_NONE)
6293 gtk_drag_get_data (widget, context, target, time);
6301 gtk_icon_view_drag_data_received (GtkWidget *widget,
6302 GdkDragContext *context,
6305 GtkSelectionData *selection_data,
6310 gboolean accepted = FALSE;
6311 GtkTreeModel *model;
6312 GtkIconView *icon_view;
6313 GtkTreePath *dest_row;
6314 GdkDragAction suggested_action;
6315 gboolean drop_append_mode;
6317 icon_view = GTK_ICON_VIEW (widget);
6318 model = gtk_icon_view_get_model (icon_view);
6320 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6323 if (!icon_view->priv->dest_set)
6326 suggested_action = get_status_pending (context);
6328 if (suggested_action)
6330 /* We are getting this data due to a request in drag_motion,
6331 * rather than due to a request in drag_drop, so we are just
6332 * supposed to call drag_status, not actually paste in the
6335 path = get_logical_destination (icon_view, &drop_append_mode);
6338 suggested_action = 0;
6340 if (suggested_action)
6342 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6345 suggested_action = 0;
6348 gdk_drag_status (context, suggested_action, time);
6351 gtk_tree_path_free (path);
6353 /* If you can't drop, remove user drop indicator until the next motion */
6354 if (suggested_action == 0)
6355 gtk_icon_view_set_drag_dest_item (icon_view,
6357 GTK_ICON_VIEW_DROP_LEFT);
6362 dest_row = get_dest_row (context);
6364 if (dest_row == NULL)
6367 if (selection_data->length >= 0)
6369 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6375 gtk_drag_finish (context,
6377 (context->action == GDK_ACTION_MOVE),
6380 gtk_tree_path_free (dest_row);
6383 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6386 /* Drag-and-Drop support */
6388 * gtk_icon_view_enable_model_drag_source:
6389 * @icon_view: a #GtkIconTreeView
6390 * @start_button_mask: Mask of allowed buttons to start drag
6391 * @targets: the table of targets that the drag will support
6392 * @n_targets: the number of items in @targets
6393 * @actions: the bitmask of possible actions for a drag from this
6396 * Turns @icon_view into a drag source for automatic DND.
6401 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6402 GdkModifierType start_button_mask,
6403 const GtkTargetEntry *targets,
6405 GdkDragAction actions)
6407 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6409 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6411 clear_source_info (icon_view);
6412 icon_view->priv->start_button_mask = start_button_mask;
6413 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6414 icon_view->priv->source_actions = actions;
6416 icon_view->priv->source_set = TRUE;
6418 unset_reorderable (icon_view);
6422 * gtk_icon_view_enable_model_drag_dest:
6423 * @icon_view: a #GtkIconView
6424 * @targets: the table of targets that the drag will support
6425 * @n_targets: the number of items in @targets
6426 * @actions: the bitmask of possible actions for a drag to this
6429 * Turns @icon_view into a drop destination for automatic DND.
6434 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6435 const GtkTargetEntry *targets,
6437 GdkDragAction actions)
6439 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6441 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6443 clear_dest_info (icon_view);
6445 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6446 icon_view->priv->dest_actions = actions;
6448 icon_view->priv->dest_set = TRUE;
6450 unset_reorderable (icon_view);
6454 * gtk_icon_view_unset_model_drag_source:
6455 * @icon_view: a #GtkIconView
6457 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6462 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6464 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6466 if (icon_view->priv->source_set)
6468 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6469 clear_source_info (icon_view);
6472 unset_reorderable (icon_view);
6476 * gtk_icon_view_unset_model_drag_dest:
6477 * @icon_view: a #GtkIconView
6479 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6484 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6486 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6488 if (icon_view->priv->dest_set)
6490 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6491 clear_dest_info (icon_view);
6494 unset_reorderable (icon_view);
6497 /* These are useful to implement your own custom stuff. */
6499 * gtk_icon_view_set_drag_dest_item:
6500 * @icon_view: a #GtkIconView
6501 * @path: The path of the item to highlight, or %NULL.
6502 * @pos: Specifies where to drop, relative to the item
6504 * Sets the item that is highlighted for feedback.
6509 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6511 GtkIconViewDropPosition pos)
6513 /* Note; this function is exported to allow a custom DND
6514 * implementation, so it can't touch TreeViewDragInfo
6517 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6519 if (icon_view->priv->dest_item)
6521 GtkTreePath *current_path;
6522 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6523 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6524 icon_view->priv->dest_item = NULL;
6526 gtk_icon_view_queue_draw_path (icon_view, current_path);
6527 gtk_tree_path_free (current_path);
6530 /* special case a drop on an empty model */
6531 icon_view->priv->empty_view_drop = FALSE;
6532 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6533 && gtk_tree_path_get_depth (path) == 1
6534 && gtk_tree_path_get_indices (path)[0] == 0)
6538 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6541 if (n_children == 0)
6542 icon_view->priv->empty_view_drop = TRUE;
6545 icon_view->priv->dest_pos = pos;
6549 icon_view->priv->dest_item =
6550 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6551 icon_view->priv->model, path);
6553 gtk_icon_view_queue_draw_path (icon_view, path);
6558 * gtk_icon_view_get_drag_dest_item:
6559 * @icon_view: a #GtkIconView
6560 * @path: Return location for the path of the highlighted item, or %NULL.
6561 * @pos: Return location for the drop position, or %NULL
6563 * Gets information about the item that is highlighted for feedback.
6568 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6570 GtkIconViewDropPosition *pos)
6572 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6576 if (icon_view->priv->dest_item)
6577 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6583 *pos = icon_view->priv->dest_pos;
6587 * gtk_icon_view_get_dest_item_at_pos:
6588 * @icon_view: a #GtkIconView
6589 * @drag_x: the position to determine the destination item for
6590 * @drag_y: the position to determine the destination item for
6591 * @path: Return location for the path of the item, or %NULL.
6592 * @pos: Return location for the drop position, or %NULL
6594 * Determines the destination item for a given position.
6596 * Return value: whether there is an item at the given position.
6601 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6605 GtkIconViewDropPosition *pos)
6607 GtkIconViewItem *item;
6609 /* Note; this function is exported to allow a custom DND
6610 * implementation, so it can't touch TreeViewDragInfo
6613 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6614 g_return_val_if_fail (drag_x >= 0, FALSE);
6615 g_return_val_if_fail (drag_y >= 0, FALSE);
6616 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6622 item = gtk_icon_view_get_item_at_coords (icon_view,
6623 drag_x + icon_view->priv->hadjustment->value,
6624 drag_y + icon_view->priv->vadjustment->value,
6631 *path = gtk_tree_path_new_from_indices (item->index, -1);
6635 if (drag_x < item->x + item->width / 4)
6636 *pos = GTK_ICON_VIEW_DROP_LEFT;
6637 else if (drag_x > item->x + item->width * 3 / 4)
6638 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6639 else if (drag_y < item->y + item->height / 4)
6640 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6641 else if (drag_y > item->y + item->height * 3 / 4)
6642 *pos = GTK_ICON_VIEW_DROP_BELOW;
6644 *pos = GTK_ICON_VIEW_DROP_INTO;
6651 * gtk_icon_view_create_drag_icon:
6652 * @icon_view: a #GtkIconView
6653 * @path: a #GtkTreePath in @icon_view
6655 * Creates a #GdkPixmap representation of the item at @path.
6656 * This image is used for a drag icon.
6658 * Return value: a newly-allocated pixmap of the drag icon.
6663 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6668 GdkPixmap *drawable;
6673 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6674 g_return_val_if_fail (path != NULL, NULL);
6676 widget = GTK_WIDGET (icon_view);
6678 if (!GTK_WIDGET_REALIZED (widget))
6681 index = gtk_tree_path_get_indices (path)[0];
6683 for (l = icon_view->priv->items; l; l = l->next)
6685 GtkIconViewItem *item = l->data;
6687 if (index == item->index)
6689 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6694 cr = gdk_cairo_create (drawable);
6695 cairo_set_line_width (cr, 1.);
6697 gdk_cairo_set_source_color
6698 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6699 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6704 area.width = item->width;
6705 area.height = item->height;
6707 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6708 drawable, 1, 1, FALSE);
6710 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6711 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6724 * gtk_icon_view_get_reorderable:
6725 * @icon_view: a #GtkIconView
6727 * Retrieves whether the user can reorder the list via drag-and-drop.
6728 * See gtk_icon_view_set_reorderable().
6730 * Return value: %TRUE if the list can be reordered.
6735 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6737 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6739 return icon_view->priv->reorderable;
6742 static const GtkTargetEntry item_targets[] = {
6743 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6748 * gtk_icon_view_set_reorderable:
6749 * @icon_view: A #GtkIconView.
6750 * @reorderable: %TRUE, if the list of items can be reordered.
6752 * This function is a convenience function to allow you to reorder models that
6753 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6754 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6755 * the user can reorder the model by dragging and dropping rows. The
6756 * developer can listen to these changes by connecting to the model's
6757 * row_inserted and row_deleted signals.
6759 * This function does not give you any degree of control over the order -- any
6760 * reordering is allowed. If more control is needed, you should probably
6761 * handle drag and drop manually.
6766 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6767 gboolean reorderable)
6769 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6771 reorderable = reorderable != FALSE;
6773 if (icon_view->priv->reorderable == reorderable)
6778 gtk_icon_view_enable_model_drag_source (icon_view,
6781 G_N_ELEMENTS (item_targets),
6783 gtk_icon_view_enable_model_drag_dest (icon_view,
6785 G_N_ELEMENTS (item_targets),
6790 gtk_icon_view_unset_model_drag_source (icon_view);
6791 gtk_icon_view_unset_model_drag_dest (icon_view);
6794 icon_view->priv->reorderable = reorderable;
6796 g_object_notify (G_OBJECT (icon_view), "reorderable");
6800 /* Accessibility Support */
6802 static gpointer accessible_parent_class;
6803 static gpointer accessible_item_parent_class;
6804 static GQuark accessible_private_data_quark = 0;
6806 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6807 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6808 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6810 static GType gtk_icon_view_item_accessible_get_type (void);
6821 GtkIconViewItem *item;
6825 AtkStateSet *state_set;
6829 GtkTextBuffer *text_buffer;
6831 gchar *action_descriptions[LAST_ACTION];
6832 gchar *image_description;
6833 guint action_idle_handler;
6834 } GtkIconViewItemAccessible;
6836 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6842 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6847 typedef struct _GtkIconViewItemAccessibleClass
6849 AtkObjectClass parent_class;
6851 } GtkIconViewItemAccessibleClass;
6853 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6856 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6858 GtkIconViewItemAccessible *item;
6859 GtkIconView *icon_view;
6862 GDK_THREADS_ENTER ();
6864 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6865 item->action_idle_handler = 0;
6867 if (item->widget != NULL)
6869 icon_view = GTK_ICON_VIEW (item->widget);
6870 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6871 gtk_icon_view_item_activated (icon_view, path);
6872 gtk_tree_path_free (path);
6875 GDK_THREADS_LEAVE ();
6881 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6884 GtkIconViewItemAccessible *item;
6886 if (i < 0 || i >= LAST_ACTION)
6889 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6891 if (!GTK_IS_ICON_VIEW (item->widget))
6894 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6899 case ACTION_ACTIVATE:
6900 if (!item->action_idle_handler)
6901 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6904 g_assert_not_reached ();
6912 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6917 static const gchar *
6918 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6921 GtkIconViewItemAccessible *item;
6923 if (i < 0 || i >= LAST_ACTION)
6926 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6928 if (item->action_descriptions[i])
6929 return item->action_descriptions[i];
6931 return gtk_icon_view_item_accessible_action_descriptions[i];
6934 static const gchar *
6935 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6938 if (i < 0 || i >= LAST_ACTION)
6941 return gtk_icon_view_item_accessible_action_names[i];
6945 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6947 const gchar *description)
6949 GtkIconViewItemAccessible *item;
6951 if (i < 0 || i >= LAST_ACTION)
6954 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6956 if (item->action_descriptions[i])
6957 g_free (item->action_descriptions[i]);
6959 item->action_descriptions[i] = g_strdup (description);
6965 atk_action_item_interface_init (AtkActionIface *iface)
6967 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6968 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6969 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6970 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6971 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6974 static const gchar *
6975 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6977 GtkIconViewItemAccessible *item;
6979 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6981 return item->image_description;
6985 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6986 const gchar *description)
6988 GtkIconViewItemAccessible *item;
6990 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6992 g_free (item->image_description);
6993 item->image_description = g_strdup (item->image_description);
6999 get_pixbuf_box (GtkIconView *icon_view,
7000 GtkIconViewItem *item,
7005 for (l = icon_view->priv->cell_list; l; l = l->next)
7007 GtkIconViewCellInfo *info = l->data;
7009 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7011 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7021 get_text (GtkIconView *icon_view,
7022 GtkIconViewItem *item)
7027 for (l = icon_view->priv->cell_list; l; l = l->next)
7029 GtkIconViewCellInfo *info = l->data;
7031 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7033 g_object_get (info->cell, "text", &text, NULL);
7043 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7047 GtkIconViewItemAccessible *item;
7050 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7052 if (!GTK_IS_ICON_VIEW (item->widget))
7055 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7058 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7061 *height = box.height;
7066 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7069 AtkCoordType coord_type)
7071 GtkIconViewItemAccessible *item;
7074 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7076 if (!GTK_IS_ICON_VIEW (item->widget))
7079 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7082 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7084 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7086 *x+= box.x - item->item->x;
7087 *y+= box.y - item->item->y;
7093 atk_image_item_interface_init (AtkImageIface *iface)
7095 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7096 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7097 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7098 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7102 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7106 GtkIconViewItemAccessible *item;
7107 GtkTextIter start, end;
7108 GtkTextBuffer *buffer;
7110 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7112 if (!GTK_IS_ICON_VIEW (item->widget))
7115 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7118 buffer = item->text_buffer;
7119 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7121 gtk_text_buffer_get_end_iter (buffer, &end);
7123 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7125 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7129 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7132 GtkIconViewItemAccessible *item;
7133 GtkTextIter start, end;
7134 GtkTextBuffer *buffer;
7138 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7140 if (!GTK_IS_ICON_VIEW (item->widget))
7143 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7146 buffer = item->text_buffer;
7147 if (offset >= gtk_text_buffer_get_char_count (buffer))
7150 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7152 gtk_text_iter_forward_char (&end);
7153 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7154 unichar = g_utf8_get_char (string);
7162 get_pango_text_offsets (PangoLayout *layout,
7163 GtkTextBuffer *buffer,
7165 AtkTextBoundary boundary_type,
7169 GtkTextIter *start_iter,
7170 GtkTextIter *end_iter)
7172 PangoLayoutIter *iter;
7173 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7174 gint index, start_index, end_index;
7176 gboolean found = FALSE;
7178 text = pango_layout_get_text (layout);
7179 index = g_utf8_offset_to_pointer (text, offset) - text;
7180 iter = pango_layout_get_iter (layout);
7183 line = pango_layout_iter_get_line (iter);
7184 start_index = line->start_index;
7185 end_index = start_index + line->length;
7187 if (index >= start_index && index <= end_index)
7190 * Found line for offset
7196 * We want the previous line
7200 switch (boundary_type)
7202 case ATK_TEXT_BOUNDARY_LINE_START:
7203 end_index = start_index;
7204 start_index = prev_line->start_index;
7206 case ATK_TEXT_BOUNDARY_LINE_END:
7208 start_index = prev_prev_line->start_index +
7209 prev_prev_line->length;
7210 end_index = prev_line->start_index + prev_line->length;
7213 g_assert_not_reached();
7217 start_index = end_index = 0;
7220 switch (boundary_type)
7222 case ATK_TEXT_BOUNDARY_LINE_START:
7223 if (pango_layout_iter_next_line (iter))
7224 end_index = pango_layout_iter_get_line (iter)->start_index;
7226 case ATK_TEXT_BOUNDARY_LINE_END:
7228 start_index = prev_line->start_index +
7232 g_assert_not_reached();
7237 * We want the next line
7239 if (pango_layout_iter_next_line (iter))
7241 line = pango_layout_iter_get_line (iter);
7242 switch (boundary_type)
7244 case ATK_TEXT_BOUNDARY_LINE_START:
7245 start_index = line->start_index;
7246 if (pango_layout_iter_next_line (iter))
7247 end_index = pango_layout_iter_get_line (iter)->start_index;
7249 end_index = start_index + line->length;
7251 case ATK_TEXT_BOUNDARY_LINE_END:
7252 start_index = end_index;
7253 end_index = line->start_index + line->length;
7256 g_assert_not_reached();
7260 start_index = end_index;
7266 prev_prev_line = prev_line;
7269 while (pango_layout_iter_next_line (iter));
7273 start_index = prev_line->start_index + prev_line->length;
7274 end_index = start_index;
7276 pango_layout_iter_free (iter);
7277 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7278 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7280 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7281 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7286 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7288 AtkTextBoundary boundary_type,
7292 GtkIconViewItemAccessible *item;
7293 GtkTextIter start, end;
7294 GtkTextBuffer *buffer;
7296 GtkIconView *icon_view;
7299 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7301 if (!GTK_IS_ICON_VIEW (item->widget))
7304 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7307 buffer = item->text_buffer;
7309 if (!gtk_text_buffer_get_char_count (buffer))
7313 return g_strdup ("");
7315 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7319 switch (boundary_type)
7321 case ATK_TEXT_BOUNDARY_CHAR:
7322 gtk_text_iter_backward_char(&start);
7324 case ATK_TEXT_BOUNDARY_WORD_START:
7325 if (!gtk_text_iter_starts_word (&start))
7326 gtk_text_iter_backward_word_start (&start);
7328 gtk_text_iter_backward_word_start(&start);
7330 case ATK_TEXT_BOUNDARY_WORD_END:
7331 if (gtk_text_iter_inside_word (&start) &&
7332 !gtk_text_iter_starts_word (&start))
7333 gtk_text_iter_backward_word_start (&start);
7334 while (!gtk_text_iter_ends_word (&start))
7336 if (!gtk_text_iter_backward_char (&start))
7340 gtk_text_iter_backward_word_start(&start);
7341 while (!gtk_text_iter_ends_word (&start))
7343 if (!gtk_text_iter_backward_char (&start))
7347 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7348 if (!gtk_text_iter_starts_sentence (&start))
7349 gtk_text_iter_backward_sentence_start (&start);
7351 gtk_text_iter_backward_sentence_start (&start);
7353 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7354 if (gtk_text_iter_inside_sentence (&start) &&
7355 !gtk_text_iter_starts_sentence (&start))
7356 gtk_text_iter_backward_sentence_start (&start);
7357 while (!gtk_text_iter_ends_sentence (&start))
7359 if (!gtk_text_iter_backward_char (&start))
7363 gtk_text_iter_backward_sentence_start (&start);
7364 while (!gtk_text_iter_ends_sentence (&start))
7366 if (!gtk_text_iter_backward_char (&start))
7370 case ATK_TEXT_BOUNDARY_LINE_START:
7371 case ATK_TEXT_BOUNDARY_LINE_END:
7373 icon_view = GTK_ICON_VIEW (item->widget);
7374 /* FIXME we probably have to use GailTextCell to salvage this */
7375 gtk_icon_view_update_item_text (icon_view, item->item);
7376 get_pango_text_offsets (icon_view->priv->layout,
7389 *start_offset = gtk_text_iter_get_offset (&start);
7390 *end_offset = gtk_text_iter_get_offset (&end);
7392 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7396 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7398 AtkTextBoundary boundary_type,
7402 GtkIconViewItemAccessible *item;
7403 GtkTextIter start, end;
7404 GtkTextBuffer *buffer;
7406 GtkIconView *icon_view;
7409 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7411 if (!GTK_IS_ICON_VIEW (item->widget))
7414 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7417 buffer = item->text_buffer;
7419 if (!gtk_text_buffer_get_char_count (buffer))
7423 return g_strdup ("");
7425 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7429 switch (boundary_type)
7431 case ATK_TEXT_BOUNDARY_CHAR:
7432 gtk_text_iter_forward_char (&end);
7434 case ATK_TEXT_BOUNDARY_WORD_START:
7435 if (!gtk_text_iter_starts_word (&start))
7436 gtk_text_iter_backward_word_start (&start);
7437 if (gtk_text_iter_inside_word (&end))
7438 gtk_text_iter_forward_word_end (&end);
7439 while (!gtk_text_iter_starts_word (&end))
7441 if (!gtk_text_iter_forward_char (&end))
7445 case ATK_TEXT_BOUNDARY_WORD_END:
7446 if (gtk_text_iter_inside_word (&start) &&
7447 !gtk_text_iter_starts_word (&start))
7448 gtk_text_iter_backward_word_start (&start);
7449 while (!gtk_text_iter_ends_word (&start))
7451 if (!gtk_text_iter_backward_char (&start))
7454 gtk_text_iter_forward_word_end (&end);
7456 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7457 if (!gtk_text_iter_starts_sentence (&start))
7458 gtk_text_iter_backward_sentence_start (&start);
7459 if (gtk_text_iter_inside_sentence (&end))
7460 gtk_text_iter_forward_sentence_end (&end);
7461 while (!gtk_text_iter_starts_sentence (&end))
7463 if (!gtk_text_iter_forward_char (&end))
7467 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7468 if (gtk_text_iter_inside_sentence (&start) &&
7469 !gtk_text_iter_starts_sentence (&start))
7470 gtk_text_iter_backward_sentence_start (&start);
7471 while (!gtk_text_iter_ends_sentence (&start))
7473 if (!gtk_text_iter_backward_char (&start))
7476 gtk_text_iter_forward_sentence_end (&end);
7478 case ATK_TEXT_BOUNDARY_LINE_START:
7479 case ATK_TEXT_BOUNDARY_LINE_END:
7481 icon_view = GTK_ICON_VIEW (item->widget);
7482 /* FIXME we probably have to use GailTextCell to salvage this */
7483 gtk_icon_view_update_item_text (icon_view, item->item);
7484 get_pango_text_offsets (icon_view->priv->layout,
7498 *start_offset = gtk_text_iter_get_offset (&start);
7499 *end_offset = gtk_text_iter_get_offset (&end);
7501 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7505 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7507 AtkTextBoundary boundary_type,
7511 GtkIconViewItemAccessible *item;
7512 GtkTextIter start, end;
7513 GtkTextBuffer *buffer;
7515 GtkIconView *icon_view;
7518 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7520 if (!GTK_IS_ICON_VIEW (item->widget))
7523 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7526 buffer = item->text_buffer;
7528 if (!gtk_text_buffer_get_char_count (buffer))
7532 return g_strdup ("");
7534 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7538 switch (boundary_type)
7540 case ATK_TEXT_BOUNDARY_CHAR:
7541 gtk_text_iter_forward_char(&start);
7542 gtk_text_iter_forward_chars(&end, 2);
7544 case ATK_TEXT_BOUNDARY_WORD_START:
7545 if (gtk_text_iter_inside_word (&end))
7546 gtk_text_iter_forward_word_end (&end);
7547 while (!gtk_text_iter_starts_word (&end))
7549 if (!gtk_text_iter_forward_char (&end))
7553 if (!gtk_text_iter_is_end (&end))
7555 gtk_text_iter_forward_word_end (&end);
7556 while (!gtk_text_iter_starts_word (&end))
7558 if (!gtk_text_iter_forward_char (&end))
7563 case ATK_TEXT_BOUNDARY_WORD_END:
7564 gtk_text_iter_forward_word_end (&end);
7566 if (!gtk_text_iter_is_end (&end))
7567 gtk_text_iter_forward_word_end (&end);
7569 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7570 if (gtk_text_iter_inside_sentence (&end))
7571 gtk_text_iter_forward_sentence_end (&end);
7572 while (!gtk_text_iter_starts_sentence (&end))
7574 if (!gtk_text_iter_forward_char (&end))
7578 if (!gtk_text_iter_is_end (&end))
7580 gtk_text_iter_forward_sentence_end (&end);
7581 while (!gtk_text_iter_starts_sentence (&end))
7583 if (!gtk_text_iter_forward_char (&end))
7588 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7589 gtk_text_iter_forward_sentence_end (&end);
7591 if (!gtk_text_iter_is_end (&end))
7592 gtk_text_iter_forward_sentence_end (&end);
7594 case ATK_TEXT_BOUNDARY_LINE_START:
7595 case ATK_TEXT_BOUNDARY_LINE_END:
7597 icon_view = GTK_ICON_VIEW (item->widget);
7598 /* FIXME we probably have to use GailTextCell to salvage this */
7599 gtk_icon_view_update_item_text (icon_view, item->item);
7600 get_pango_text_offsets (icon_view->priv->layout,
7612 *start_offset = gtk_text_iter_get_offset (&start);
7613 *end_offset = gtk_text_iter_get_offset (&end);
7615 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7619 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7621 GtkIconViewItemAccessible *item;
7623 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7625 if (!GTK_IS_ICON_VIEW (item->widget))
7628 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7631 return gtk_text_buffer_get_char_count (item->text_buffer);
7635 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7641 AtkCoordType coord_type)
7643 GtkIconViewItemAccessible *item;
7645 GtkIconView *icon_view;
7646 PangoRectangle char_rect;
7647 const gchar *item_text;
7651 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7653 if (!GTK_IS_ICON_VIEW (item->widget))
7656 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7660 icon_view = GTK_ICON_VIEW (item->widget);
7661 /* FIXME we probably have to use GailTextCell to salvage this */
7662 gtk_icon_view_update_item_text (icon_view, item->item);
7663 item_text = pango_layout_get_text (icon_view->priv->layout);
7664 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7665 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7667 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7668 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7669 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7670 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7671 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7672 *width = char_rect.width / PANGO_SCALE;
7673 *height = char_rect.height / PANGO_SCALE;
7678 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7681 AtkCoordType coord_type)
7683 GtkIconViewItemAccessible *item;
7686 GtkIconView *icon_view;
7687 const gchar *item_text;
7692 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7694 if (!GTK_IS_ICON_VIEW (item->widget))
7697 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7701 icon_view = GTK_ICON_VIEW (item->widget);
7702 /* FIXME we probably have to use GailTextCell to salvage this */
7703 gtk_icon_view_update_item_text (icon_view, item->item);
7704 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7705 x -= l_x + item->item->layout_x - item->item->x;
7706 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7707 y -= l_y + item->item->layout_y - item->item->y;
7708 item_text = pango_layout_get_text (icon_view->priv->layout);
7709 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7720 offset = g_utf8_strlen (item_text, -1);
7722 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7728 atk_text_item_interface_init (AtkTextIface *iface)
7730 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7731 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7732 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7733 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7734 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7735 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7736 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7737 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7741 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7746 AtkCoordType coord_type)
7748 GtkIconViewItemAccessible *item;
7749 AtkObject *parent_obj;
7752 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7754 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7755 if (!GTK_IS_WIDGET (item->widget))
7758 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7761 *width = item->item->width;
7762 *height = item->item->height;
7763 if (gtk_icon_view_item_accessible_is_showing (item))
7765 parent_obj = gtk_widget_get_accessible (item->widget);
7766 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7767 *x = l_x + item->item->x;
7768 *y = l_y + item->item->y;
7778 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7780 GtkIconViewItemAccessible *item;
7781 GtkWidget *toplevel;
7783 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7785 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7786 if (!GTK_IS_WIDGET (item->widget))
7789 gtk_widget_grab_focus (item->widget);
7790 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7791 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7792 if (GTK_WIDGET_TOPLEVEL (toplevel))
7793 gtk_window_present (GTK_WINDOW (toplevel));
7799 atk_component_item_interface_init (AtkComponentIface *iface)
7801 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7802 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7806 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7807 AtkStateType state_type,
7808 gboolean emit_signal)
7812 rc = atk_state_set_add_state (item->state_set, state_type);
7814 * The signal should only be generated if the value changed,
7815 * not when the item is set up. So states that are set
7816 * initially should pass FALSE as the emit_signal argument.
7821 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7822 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7823 if (state_type == ATK_STATE_VISIBLE)
7824 g_signal_emit_by_name (item, "visible_data_changed");
7831 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7832 AtkStateType state_type,
7833 gboolean emit_signal)
7835 if (atk_state_set_contains_state (item->state_set, state_type))
7839 rc = atk_state_set_remove_state (item->state_set, state_type);
7841 * The signal should only be generated if the value changed,
7842 * not when the item is set up. So states that are set
7843 * initially should pass FALSE as the emit_signal argument.
7848 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7849 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7850 if (state_type == ATK_STATE_VISIBLE)
7851 g_signal_emit_by_name (item, "visible_data_changed");
7861 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7863 GtkIconView *icon_view;
7864 GdkRectangle visible_rect;
7865 gboolean is_showing;
7868 * An item is considered "SHOWING" if any part of the item is in the
7869 * visible rectangle.
7872 if (!GTK_IS_ICON_VIEW (item->widget))
7875 if (item->item == NULL)
7878 icon_view = GTK_ICON_VIEW (item->widget);
7880 if (icon_view->priv->hadjustment)
7881 visible_rect.x += icon_view->priv->hadjustment->value;
7883 if (icon_view->priv->hadjustment)
7884 visible_rect.y += icon_view->priv->vadjustment->value;
7885 visible_rect.width = item->widget->allocation.width;
7886 visible_rect.height = item->widget->allocation.height;
7888 if (((item->item->x + item->item->width) < visible_rect.x) ||
7889 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7890 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7891 (item->item->y > (visible_rect.y + visible_rect.height)))
7900 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7901 gboolean emit_signal)
7903 if (gtk_icon_view_item_accessible_is_showing (item))
7904 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7907 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7912 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7916 item->state_set = atk_state_set_new ();
7918 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7919 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7920 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7921 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7922 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7924 for (i = 0; i < LAST_ACTION; i++)
7925 item->action_descriptions[i] = NULL;
7927 item->image_description = NULL;
7929 item->action_idle_handler = 0;
7933 gtk_icon_view_item_accessible_finalize (GObject *object)
7935 GtkIconViewItemAccessible *item;
7938 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7940 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7943 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7945 if (item->state_set)
7946 g_object_unref (item->state_set);
7948 if (item->text_buffer)
7949 g_object_unref (item->text_buffer);
7951 for (i = 0; i < LAST_ACTION; i++)
7952 g_free (item->action_descriptions[i]);
7954 g_free (item->image_description);
7956 if (item->action_idle_handler)
7958 g_source_remove (item->action_idle_handler);
7959 item->action_idle_handler = 0;
7962 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7965 static G_CONST_RETURN gchar*
7966 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7972 GtkIconViewItemAccessible *item;
7973 GtkTextIter start_iter;
7974 GtkTextIter end_iter;
7976 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7978 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7979 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7981 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7986 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7988 GtkIconViewItemAccessible *item;
7990 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7991 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7994 return gtk_widget_get_accessible (item->widget);
8000 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8002 GtkIconViewItemAccessible *item;
8004 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8005 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8007 return item->item->index;
8010 static AtkStateSet *
8011 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8013 GtkIconViewItemAccessible *item;
8014 GtkIconView *icon_view;
8016 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8017 g_return_val_if_fail (item->state_set, NULL);
8022 icon_view = GTK_ICON_VIEW (item->widget);
8023 if (icon_view->priv->cursor_item == item->item)
8024 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8026 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8028 return g_object_ref (item->state_set);
8032 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8034 GObjectClass *gobject_class;
8036 accessible_item_parent_class = g_type_class_peek_parent (klass);
8038 gobject_class = (GObjectClass *)klass;
8040 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8042 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8043 klass->get_name = gtk_icon_view_item_accessible_get_name;
8044 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8045 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8049 gtk_icon_view_item_accessible_get_type (void)
8051 static GType type = 0;
8055 static const GTypeInfo tinfo =
8057 sizeof (GtkIconViewItemAccessibleClass),
8058 (GBaseInitFunc) NULL, /* base init */
8059 (GBaseFinalizeFunc) NULL, /* base finalize */
8060 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8061 (GClassFinalizeFunc) NULL, /* class finalize */
8062 NULL, /* class data */
8063 sizeof (GtkIconViewItemAccessible), /* instance size */
8064 0, /* nb preallocs */
8065 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8066 NULL /* value table */
8069 static const GInterfaceInfo atk_component_info =
8071 (GInterfaceInitFunc) atk_component_item_interface_init,
8072 (GInterfaceFinalizeFunc) NULL,
8075 static const GInterfaceInfo atk_action_info =
8077 (GInterfaceInitFunc) atk_action_item_interface_init,
8078 (GInterfaceFinalizeFunc) NULL,
8081 static const GInterfaceInfo atk_image_info =
8083 (GInterfaceInitFunc) atk_image_item_interface_init,
8084 (GInterfaceFinalizeFunc) NULL,
8087 static const GInterfaceInfo atk_text_info =
8089 (GInterfaceInitFunc) atk_text_item_interface_init,
8090 (GInterfaceFinalizeFunc) NULL,
8094 type = g_type_register_static (ATK_TYPE_OBJECT,
8095 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8096 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8097 &atk_component_info);
8098 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8100 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8102 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8109 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8110 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8111 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8113 static GType gtk_icon_view_accessible_get_type (void);
8118 } GtkIconViewAccessible;
8124 } GtkIconViewItemAccessibleInfo;
8130 GtkAdjustment *old_hadj;
8131 GtkAdjustment *old_vadj;
8133 GtkTreeModel *model;
8135 } GtkIconViewAccessiblePrivate;
8137 static GtkIconViewAccessiblePrivate *
8138 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8140 return g_object_get_qdata (G_OBJECT (accessible),
8141 accessible_private_data_quark);
8145 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8149 GtkIconViewItemAccessibleInfo *info;
8150 GtkIconViewItemAccessibleInfo *tmp_info;
8151 GtkIconViewAccessiblePrivate *priv;
8154 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8156 info->index = index;
8158 priv = gtk_icon_view_accessible_get_priv (accessible);
8159 items = priv->items;
8162 tmp_info = items->data;
8163 if (tmp_info->index > index)
8165 items = items->next;
8167 priv->items = g_list_insert_before (priv->items, items, info);
8168 priv->old_hadj = NULL;
8169 priv->old_vadj = NULL;
8173 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8175 GtkIconView *icon_view;
8178 widget = GTK_ACCESSIBLE (accessible)->widget;
8182 icon_view = GTK_ICON_VIEW (widget);
8184 return g_list_length (icon_view->priv->items);
8188 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8191 GtkIconViewAccessiblePrivate *priv;
8192 GtkIconViewItemAccessibleInfo *info;
8195 priv = gtk_icon_view_accessible_get_priv (accessible);
8196 items = priv->items;
8201 if (info->index == index)
8203 items = items->next;
8209 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8212 GtkIconView *icon_view;
8216 GtkIconViewItemAccessible *a11y_item;
8218 widget = GTK_ACCESSIBLE (accessible)->widget;
8222 icon_view = GTK_ICON_VIEW (widget);
8223 icons = g_list_nth (icon_view->priv->items, index);
8227 GtkIconViewItem *item = icons->data;
8229 g_return_val_if_fail (item->index == index, NULL);
8230 obj = gtk_icon_view_accessible_find_child (accessible, index);
8233 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8234 gtk_icon_view_item_accessible_info_new (accessible,
8237 obj->role = ATK_ROLE_ICON;
8238 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8239 a11y_item->item = item;
8240 a11y_item->widget = widget;
8241 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8243 gtk_icon_view_set_cell_data (icon_view, item);
8244 gtk_text_buffer_set_text (a11y_item->text_buffer,
8245 get_text (icon_view, item), -1);
8247 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8248 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8256 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8259 GtkIconViewAccessiblePrivate *priv;
8260 GtkIconViewItemAccessibleInfo *info;
8261 GtkIconViewItemAccessible *item;
8264 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8268 gboolean act_on_item;
8270 widget = GTK_ACCESSIBLE (view)->widget;
8274 items = priv->items;
8276 act_on_item = (list == NULL);
8281 info = (GtkIconViewItemAccessibleInfo *)items->data;
8282 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8284 if (act_on_item == FALSE && list == items)
8288 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8290 items = items->next;
8296 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8297 GtkIconView *icon_view)
8300 GtkIconViewAccessible *view;
8303 * The scrollbars have changed
8305 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8306 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8308 gtk_icon_view_accessible_traverse_items (view, NULL);
8312 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8313 GtkAdjustment *hadj,
8314 GtkAdjustment *vadj)
8317 GtkIconViewAccessiblePrivate *priv;
8319 atk_obj = gtk_widget_get_accessible (widget);
8320 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8322 if (priv->old_hadj != hadj)
8326 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8327 (gpointer *)&priv->old_hadj);
8329 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8330 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8333 priv->old_hadj = hadj;
8336 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8337 (gpointer *)&priv->old_hadj);
8338 g_signal_connect (hadj,
8340 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8344 if (priv->old_vadj != vadj)
8348 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8349 (gpointer *)&priv->old_vadj);
8351 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8352 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8355 priv->old_vadj = vadj;
8358 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8359 (gpointer *)&priv->old_vadj);
8360 g_signal_connect (vadj,
8362 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8369 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8376 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8377 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8383 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8388 GtkIconViewAccessiblePrivate *priv;
8389 GtkIconViewItemAccessibleInfo *info;
8390 GtkIconViewAccessible *view;
8391 GtkIconViewItemAccessible *item;
8397 index = gtk_tree_path_get_indices(path)[0];
8398 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8399 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8400 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8402 items = priv->items;
8407 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8408 if (info->index != item->item->index)
8410 if (info->index < index)
8411 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8413 if (tmp_list == NULL)
8416 info->index = item->item->index;
8419 items = items->next;
8421 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8422 g_signal_emit_by_name (atk_obj, "children_changed::add",
8428 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8432 GtkIconViewAccessiblePrivate *priv;
8433 GtkIconViewItemAccessibleInfo *info;
8434 GtkIconViewAccessible *view;
8435 GtkIconViewItemAccessible *item;
8438 GList *deleted_item;
8442 index = gtk_tree_path_get_indices(path)[0];
8443 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8444 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8445 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8447 items = priv->items;
8449 deleted_item = NULL;
8454 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8455 if (info->index == index)
8457 deleted_item = items;
8459 if (info->index != item->item->index)
8461 if (tmp_list == NULL)
8464 info->index = item->item->index;
8467 items = items->next;
8469 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8472 info = deleted_item->data;
8473 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8475 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8479 priv->items = g_list_remove_link (priv->items, deleted_item);
8487 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8488 GtkIconViewItemAccessibleInfo *i2)
8490 return i1->index - i2->index;
8494 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8500 GtkIconViewAccessiblePrivate *priv;
8501 GtkIconViewItemAccessibleInfo *info;
8502 GtkIconViewAccessible *view;
8503 GtkIconView *icon_view;
8504 GtkIconViewItemAccessible *item;
8508 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8509 icon_view = GTK_ICON_VIEW (user_data);
8510 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8511 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8513 items = priv->items;
8517 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8518 info->index = new_order[info->index];
8519 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8520 items = items->next;
8522 priv->items = g_list_sort (priv->items,
8523 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8529 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8534 obj = G_OBJECT (model);
8535 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8536 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8537 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8538 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8542 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8546 obj = G_OBJECT (icon_view->priv->model);
8547 g_signal_connect_data (obj, "row_changed",
8548 (GCallback) gtk_icon_view_accessible_model_row_changed,
8549 icon_view, NULL, 0);
8550 g_signal_connect_data (obj, "row_inserted",
8551 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8552 icon_view, NULL, G_CONNECT_AFTER);
8553 g_signal_connect_data (obj, "row_deleted",
8554 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8555 icon_view, NULL, G_CONNECT_AFTER);
8556 g_signal_connect_data (obj, "rows_reordered",
8557 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8558 icon_view, NULL, G_CONNECT_AFTER);
8562 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8564 GtkIconViewItemAccessibleInfo *info;
8567 items = priv->items;
8570 info = (GtkIconViewItemAccessibleInfo *) items->data;
8571 g_object_unref (info->item);
8572 g_free (items->data);
8573 items = items->next;
8575 g_list_free (priv->items);
8580 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8583 GtkIconView *icon_view;
8586 GtkIconViewAccessiblePrivate *priv;
8588 if (strcmp (pspec->name, "model") == 0)
8590 widget = GTK_WIDGET (obj);
8591 atk_obj = gtk_widget_get_accessible (widget);
8592 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8595 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8596 (gpointer *)&priv->model);
8597 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8599 gtk_icon_view_accessible_clear_cache (priv);
8601 icon_view = GTK_ICON_VIEW (obj);
8602 priv->model = icon_view->priv->model;
8603 /* If there is no model the GtkIconView is probably being destroyed */
8606 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8607 gtk_icon_view_accessible_connect_model_signals (icon_view);
8615 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8618 GtkIconViewAccessiblePrivate *priv;
8619 GtkIconView *icon_view;
8621 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8622 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8624 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8625 g_object_set_qdata (G_OBJECT (accessible),
8626 accessible_private_data_quark,
8629 icon_view = GTK_ICON_VIEW (data);
8630 if (icon_view->priv->hadjustment)
8632 priv->old_hadj = icon_view->priv->hadjustment;
8633 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8634 g_signal_connect (icon_view->priv->hadjustment,
8636 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8639 if (icon_view->priv->vadjustment)
8641 priv->old_vadj = icon_view->priv->vadjustment;
8642 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8643 g_signal_connect (icon_view->priv->vadjustment,
8645 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8648 g_signal_connect_after (data,
8649 "set_scroll_adjustments",
8650 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8652 g_signal_connect (data,
8654 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8657 priv->model = icon_view->priv->model;
8660 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8661 gtk_icon_view_accessible_connect_model_signals (icon_view);
8664 accessible->role = ATK_ROLE_LAYERED_PANE;
8668 gtk_icon_view_accessible_finalize (GObject *object)
8670 GtkIconViewAccessiblePrivate *priv;
8672 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8673 gtk_icon_view_accessible_clear_cache (priv);
8677 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8681 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8682 GtkAccessible *accessible)
8685 GtkIconViewAccessiblePrivate *priv;
8687 atk_obj = ATK_OBJECT (accessible);
8688 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8691 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8692 (gpointer *)&priv->old_hadj);
8694 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8695 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8697 priv->old_hadj = NULL;
8701 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8702 (gpointer *)&priv->old_vadj);
8704 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8705 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8707 priv->old_vadj = NULL;
8712 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8714 if (accessible->widget)
8716 g_signal_connect_after (accessible->widget,
8718 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8721 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8725 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8727 GObjectClass *gobject_class;
8728 GtkAccessibleClass *accessible_class;
8730 accessible_parent_class = g_type_class_peek_parent (klass);
8732 gobject_class = (GObjectClass *)klass;
8733 accessible_class = (GtkAccessibleClass *)klass;
8735 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8737 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8738 klass->ref_child = gtk_icon_view_accessible_ref_child;
8739 klass->initialize = gtk_icon_view_accessible_initialize;
8741 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8743 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8747 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8750 AtkCoordType coord_type)
8753 GtkIconView *icon_view;
8754 GtkIconViewItem *item;
8757 widget = GTK_ACCESSIBLE (component)->widget;
8759 /* State is defunct */
8762 icon_view = GTK_ICON_VIEW (widget);
8763 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8764 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8766 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8772 atk_component_interface_init (AtkComponentIface *iface)
8774 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8778 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8782 GtkIconView *icon_view;
8783 GtkIconViewItem *item;
8785 widget = GTK_ACCESSIBLE (selection)->widget;
8789 icon_view = GTK_ICON_VIEW (widget);
8791 item = g_list_nth_data (icon_view->priv->items, i);
8796 gtk_icon_view_select_item (icon_view, item);
8802 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8805 GtkIconView *icon_view;
8807 widget = GTK_ACCESSIBLE (selection)->widget;
8811 icon_view = GTK_ICON_VIEW (widget);
8812 gtk_icon_view_unselect_all (icon_view);
8818 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8822 GtkIconView *icon_view;
8823 GtkIconViewItem *item;
8826 widget = GTK_ACCESSIBLE (selection)->widget;
8830 icon_view = GTK_ICON_VIEW (widget);
8832 l = icon_view->priv->items;
8839 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8850 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8853 GtkIconView *icon_view;
8854 GtkIconViewItem *item;
8858 widget = GTK_ACCESSIBLE (selection)->widget;
8862 icon_view = GTK_ICON_VIEW (widget);
8864 l = icon_view->priv->items;
8880 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8884 GtkIconView *icon_view;
8885 GtkIconViewItem *item;
8888 widget = GTK_ACCESSIBLE (selection)->widget;
8892 icon_view = GTK_ICON_VIEW (widget);
8894 item = g_list_nth_data (icon_view->priv->items, i);
8898 return item->selected;
8902 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8906 GtkIconView *icon_view;
8907 GtkIconViewItem *item;
8911 widget = GTK_ACCESSIBLE (selection)->widget;
8915 icon_view = GTK_ICON_VIEW (widget);
8916 l = icon_view->priv->items;
8925 gtk_icon_view_unselect_item (icon_view, item);
8937 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8940 GtkIconView *icon_view;
8942 widget = GTK_ACCESSIBLE (selection)->widget;
8946 icon_view = GTK_ICON_VIEW (widget);
8947 gtk_icon_view_select_all (icon_view);
8952 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8954 iface->add_selection = gtk_icon_view_accessible_add_selection;
8955 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8956 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8957 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8958 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8959 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8960 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8964 gtk_icon_view_accessible_get_type (void)
8966 static GType type = 0;
8970 static GTypeInfo tinfo =
8973 (GBaseInitFunc) NULL, /* base init */
8974 (GBaseFinalizeFunc) NULL, /* base finalize */
8975 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8976 (GClassFinalizeFunc) NULL, /* class finalize */
8977 NULL, /* class data */
8978 0, /* instance size */
8979 0, /* nb preallocs */
8980 (GInstanceInitFunc) NULL, /* instance init */
8981 NULL /* value table */
8983 static const GInterfaceInfo atk_component_info =
8985 (GInterfaceInitFunc) atk_component_interface_init,
8986 (GInterfaceFinalizeFunc) NULL,
8989 static const GInterfaceInfo atk_selection_info =
8991 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8992 (GInterfaceFinalizeFunc) NULL,
8997 * Figure out the size of the class and instance
8998 * we are deriving from
9000 AtkObjectFactory *factory;
9003 GType derived_atk_type;
9005 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9006 factory = atk_registry_get_factory (atk_get_default_registry (),
9008 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9009 g_type_query (derived_atk_type, &query);
9010 tinfo.class_size = query.class_size;
9011 tinfo.instance_size = query.instance_size;
9013 type = g_type_register_static (derived_atk_type,
9014 "GtkIconViewAccessible",
9016 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9017 &atk_component_info);
9018 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9019 &atk_selection_info);
9025 gtk_icon_view_accessible_new (GObject *obj)
9027 AtkObject *accessible;
9029 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9031 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9032 atk_object_initialize (accessible, obj);
9038 gtk_icon_view_accessible_factory_get_accessible_type (void)
9040 return gtk_icon_view_accessible_get_type ();
9044 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9046 return gtk_icon_view_accessible_new (obj);
9050 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9052 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9053 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9057 gtk_icon_view_accessible_factory_get_type (void)
9059 static GType type = 0;
9063 static const GTypeInfo tinfo =
9065 sizeof (AtkObjectFactoryClass),
9066 NULL, /* base_init */
9067 NULL, /* base_finalize */
9068 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9069 NULL, /* class_finalize */
9070 NULL, /* class_data */
9071 sizeof (AtkObjectFactory),
9072 0, /* n_preallocs */
9076 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9077 "GtkIconViewAccessibleFactory",
9085 gtk_icon_view_get_accessible (GtkWidget *widget)
9087 static gboolean first_time = TRUE;
9091 AtkObjectFactory *factory;
9092 AtkRegistry *registry;
9094 GType derived_atk_type;
9097 * Figure out whether accessibility is enabled by looking at the
9098 * type of the accessible object which would be created for
9099 * the parent type of GtkIconView.
9101 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9103 registry = atk_get_default_registry ();
9104 factory = atk_registry_get_factory (registry,
9106 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9107 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9108 atk_registry_set_factory_type (registry,
9110 gtk_icon_view_accessible_factory_get_type ());
9113 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9116 #define __GTK_ICON_VIEW_C__
9117 #include "gtkaliasdef.c"