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_class_init (GtkIconViewClass *klass);
226 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
227 static void gtk_icon_view_finalize (GObject *object);
228 static void gtk_icon_view_set_property (GObject *object,
232 static void gtk_icon_view_get_property (GObject *object,
237 /* GtkObject vfuncs */
238 static void gtk_icon_view_destroy (GtkObject *object);
240 /* GtkWidget vfuncs */
241 static void gtk_icon_view_realize (GtkWidget *widget);
242 static void gtk_icon_view_unrealize (GtkWidget *widget);
243 static void gtk_icon_view_size_request (GtkWidget *widget,
244 GtkRequisition *requisition);
245 static void gtk_icon_view_size_allocate (GtkWidget *widget,
246 GtkAllocation *allocation);
247 static gboolean gtk_icon_view_expose (GtkWidget *widget,
248 GdkEventExpose *expose);
249 static gboolean gtk_icon_view_motion (GtkWidget *widget,
250 GdkEventMotion *event);
251 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
252 GdkEventButton *event);
253 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
254 GdkEventButton *event);
255 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
258 /* GtkContainer vfuncs */
259 static void gtk_icon_view_remove (GtkContainer *container,
261 static void gtk_icon_view_forall (GtkContainer *container,
262 gboolean include_internals,
263 GtkCallback callback,
264 gpointer callback_data);
266 /* GtkIconView vfuncs */
267 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
269 GtkAdjustment *vadj);
270 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
271 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
272 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
273 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
274 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
276 /* Internal functions */
277 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
278 GtkIconView *icon_view);
279 static void gtk_icon_view_layout (GtkIconView *icon_view);
280 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
283 GtkIconViewItem *item,
285 GdkDrawable *drawable,
288 gboolean draw_focus);
289 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
292 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
294 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
295 GtkIconViewItem *item);
296 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
297 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
298 GtkIconViewItem *item,
300 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
303 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
304 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
305 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
306 GtkIconViewItem *item,
311 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
312 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
313 GtkIconViewItem *item);
314 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
315 GtkIconViewItem *item,
317 static void gtk_icon_view_update_rubberband (gpointer data);
318 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
319 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
320 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
323 GtkMovementStep step,
325 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
326 GtkMovementStep step,
328 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
330 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
332 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
334 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
336 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
337 GtkIconViewItem *item);
338 static void gtk_icon_view_select_item (GtkIconView *icon_view,
339 GtkIconViewItem *item);
340 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
341 GtkIconViewItem *item);
342 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
343 GtkIconViewItem *anchor,
344 GtkIconViewItem *cursor);
345 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
348 gboolean only_in_cell,
349 GtkIconViewCellInfo **cell_at_pos);
350 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
351 GtkIconViewItem *item,
352 GtkIconViewCellInfo *cell_info,
353 GdkRectangle *cell_area);
354 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
355 GtkIconViewItem *item,
356 GtkIconViewCellInfo *info,
358 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
359 GtkCellRenderer *renderer);
360 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
363 GtkCellRenderer *renderer,
365 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
366 GtkCellRenderer *renderer,
368 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
369 GtkCellRenderer *renderer,
370 const gchar *attribute,
372 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
373 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
374 GtkCellRenderer *renderer);
375 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
376 GtkCellRenderer *cell,
377 GtkCellLayoutDataFunc func,
379 GDestroyNotify destroy);
380 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
381 GtkCellRenderer *cell,
383 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
384 GtkIconViewItem *item,
385 GtkIconViewCellInfo *cell_info,
387 static void gtk_icon_view_put (GtkIconView *icon_view,
389 GtkIconViewItem *item,
391 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
392 GtkIconView *icon_view);
393 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
394 GtkIconViewItem *item,
395 GtkIconViewCellInfo *cell_info,
397 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
398 gboolean cancel_editing);
400 /* Source side drag signals */
401 static void gtk_icon_view_drag_begin (GtkWidget *widget,
402 GdkDragContext *context);
403 static void gtk_icon_view_drag_end (GtkWidget *widget,
404 GdkDragContext *context);
405 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
406 GdkDragContext *context,
407 GtkSelectionData *selection_data,
410 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
411 GdkDragContext *context);
413 /* Target side drag signals */
414 static void gtk_icon_view_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
418 GdkDragContext *context,
422 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
423 GdkDragContext *context,
427 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
428 GdkDragContext *context,
431 GtkSelectionData *selection_data,
434 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
435 GdkEventMotion *event);
437 static void remove_scroll_timeout (GtkIconView *icon_view);
440 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
442 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
443 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
444 gtk_icon_view_cell_layout_init));
447 gtk_icon_view_class_init (GtkIconViewClass *klass)
449 GObjectClass *gobject_class;
450 GtkObjectClass *object_class;
451 GtkWidgetClass *widget_class;
452 GtkContainerClass *container_class;
453 GtkBindingSet *binding_set;
455 binding_set = gtk_binding_set_by_class (klass);
457 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
459 gobject_class = (GObjectClass *) klass;
460 object_class = (GtkObjectClass *) klass;
461 widget_class = (GtkWidgetClass *) klass;
462 container_class = (GtkContainerClass *) klass;
464 gobject_class->finalize = gtk_icon_view_finalize;
465 gobject_class->set_property = gtk_icon_view_set_property;
466 gobject_class->get_property = gtk_icon_view_get_property;
468 object_class->destroy = gtk_icon_view_destroy;
470 widget_class->realize = gtk_icon_view_realize;
471 widget_class->unrealize = gtk_icon_view_unrealize;
472 widget_class->size_request = gtk_icon_view_size_request;
473 widget_class->size_allocate = gtk_icon_view_size_allocate;
474 widget_class->expose_event = gtk_icon_view_expose;
475 widget_class->motion_notify_event = gtk_icon_view_motion;
476 widget_class->button_press_event = gtk_icon_view_button_press;
477 widget_class->button_release_event = gtk_icon_view_button_release;
478 widget_class->drag_begin = gtk_icon_view_drag_begin;
479 widget_class->drag_end = gtk_icon_view_drag_end;
480 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
481 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
482 widget_class->drag_leave = gtk_icon_view_drag_leave;
483 widget_class->drag_motion = gtk_icon_view_drag_motion;
484 widget_class->drag_drop = gtk_icon_view_drag_drop;
485 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
486 widget_class->get_accessible = gtk_icon_view_get_accessible;
488 container_class->remove = gtk_icon_view_remove;
489 container_class->forall = gtk_icon_view_forall;
491 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
492 klass->select_all = gtk_icon_view_real_select_all;
493 klass->unselect_all = gtk_icon_view_real_unselect_all;
494 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
495 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
496 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
497 klass->move_cursor = gtk_icon_view_real_move_cursor;
501 * GtkIconView:selection-mode:
503 * The ::selection-mode property specifies the selection mode of
504 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
505 * is enabled, for the other modes, only keyboard selection is possible.
509 g_object_class_install_property (gobject_class,
511 g_param_spec_enum ("selection-mode",
512 P_("Selection mode"),
513 P_("The selection mode"),
514 GTK_TYPE_SELECTION_MODE,
515 GTK_SELECTION_SINGLE,
516 GTK_PARAM_READWRITE));
519 * GtkIconView:pixbuf-column:
521 * The ::pixbuf-column property contains the number of the model column
522 * containing the pixbufs which are displayed. The pixbuf column must be
523 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
524 * display of pixbufs.
528 g_object_class_install_property (gobject_class,
530 g_param_spec_int ("pixbuf-column",
532 P_("Model column used to retrieve the icon pixbuf from"),
534 GTK_PARAM_READWRITE));
537 * GtkIconView:text-column:
539 * The ::text-column property contains the number of the model column
540 * containing the texts which are displayed. The text column must be
541 * of type #G_TYPE_STRING. If this property and the :markup-column
542 * property are both set to -1, no texts are displayed.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_int ("text-column",
550 P_("Model column used to retrieve the text from"),
552 GTK_PARAM_READWRITE));
556 * GtkIconView:markup-column:
558 * The ::markup-column property contains the number of the model column
559 * containing markup information to be displayed. The markup column must be
560 * of type #G_TYPE_STRING. If this property and the :text-column property
561 * are both set to column numbers, it overrides the text column.
562 * If both are set to -1, no texts are displayed.
566 g_object_class_install_property (gobject_class,
568 g_param_spec_int ("markup-column",
570 P_("Model column used to retrieve the text if using Pango markup"),
572 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
576 g_param_spec_object ("model",
577 P_("Icon View Model"),
578 P_("The model for the icon view"),
580 GTK_PARAM_READWRITE));
583 * GtkIconView:columns:
585 * The columns property contains the number of the columns in which the
586 * items should be displayed. If it is -1, the number of columns will
587 * be chosen automatically to fill the available area.
591 g_object_class_install_property (gobject_class,
593 g_param_spec_int ("columns",
594 P_("Number of columns"),
595 P_("Number of columns to display"),
597 GTK_PARAM_READWRITE));
601 * GtkIconView::item-width:
603 * The item-width property specifies the width to use for each item.
604 * If it is set to -1, the icon view will automatically determine a
605 * suitable item size.
609 g_object_class_install_property (gobject_class,
611 g_param_spec_int ("item-width",
612 P_("Width for each item"),
613 P_("The width used for each item"),
615 GTK_PARAM_READWRITE));
618 * GtkIconView::spacing:
620 * The spacing property specifies the space which is inserted between
621 * the cells (i.e. the icon and the text) of an item.
625 g_object_class_install_property (gobject_class,
627 g_param_spec_int ("spacing",
629 P_("Space which is inserted between cells of an item"),
631 GTK_PARAM_READWRITE));
634 * GtkIconView::row-spacing:
636 * The row-spacing property specifies the space which is inserted between
637 * the rows of the icon view.
641 g_object_class_install_property (gobject_class,
643 g_param_spec_int ("row-spacing",
645 P_("Space which is inserted between grid rows"),
647 GTK_PARAM_READWRITE));
650 * GtkIconView::column-spacing:
652 * The column-spacing property specifies the space which is inserted between
653 * the columns of the icon view.
657 g_object_class_install_property (gobject_class,
659 g_param_spec_int ("column-spacing",
660 P_("Column Spacing"),
661 P_("Space which is inserted between grid column"),
663 GTK_PARAM_READWRITE));
666 * GtkIconView::margin:
668 * The margin property specifies the space which is inserted
669 * at the edges of the icon view.
673 g_object_class_install_property (gobject_class,
675 g_param_spec_int ("margin",
677 P_("Space which is inserted at the edges of the icon view"),
679 GTK_PARAM_READWRITE));
683 * GtkIconView::orientation:
685 * The orientation property specifies how the cells (i.e. the icon and
686 * the text) of the item are positioned relative to each other.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_enum ("orientation",
694 P_("How the text and icon of each item are positioned relative to each other"),
695 GTK_TYPE_ORIENTATION,
696 GTK_ORIENTATION_VERTICAL,
697 GTK_PARAM_READWRITE));
700 * GtkIconView:orientation:
702 * The reorderable property specifies if the items can be reordered
707 g_object_class_install_property (gobject_class,
709 g_param_spec_boolean ("reorderable",
711 P_("View is reorderable"),
715 /* Style properties */
716 gtk_widget_class_install_style_property (widget_class,
717 g_param_spec_boxed ("selection-box-color",
718 P_("Selection Box Color"),
719 P_("Color of the selection box"),
721 GTK_PARAM_READABLE));
723 gtk_widget_class_install_style_property (widget_class,
724 g_param_spec_uchar ("selection-box-alpha",
725 P_("Selection Box Alpha"),
726 P_("Opacity of the selection box"),
729 GTK_PARAM_READABLE));
732 widget_class->set_scroll_adjustments_signal =
733 g_signal_new (I_("set_scroll_adjustments"),
734 G_TYPE_FROM_CLASS (gobject_class),
736 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
738 _gtk_marshal_VOID__OBJECT_OBJECT,
740 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
742 icon_view_signals[ITEM_ACTIVATED] =
743 g_signal_new (I_("item_activated"),
744 G_TYPE_FROM_CLASS (gobject_class),
746 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
748 g_cclosure_marshal_VOID__BOXED,
752 icon_view_signals[SELECTION_CHANGED] =
753 g_signal_new (I_("selection_changed"),
754 G_TYPE_FROM_CLASS (gobject_class),
756 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
758 g_cclosure_marshal_VOID__VOID,
761 icon_view_signals[SELECT_ALL] =
762 g_signal_new (I_("select_all"),
763 G_TYPE_FROM_CLASS (gobject_class),
764 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
765 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
767 g_cclosure_marshal_VOID__VOID,
770 icon_view_signals[UNSELECT_ALL] =
771 g_signal_new (I_("unselect_all"),
772 G_TYPE_FROM_CLASS (gobject_class),
773 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
774 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
776 g_cclosure_marshal_VOID__VOID,
779 icon_view_signals[SELECT_CURSOR_ITEM] =
780 g_signal_new (I_("select_cursor_item"),
781 G_TYPE_FROM_CLASS (gobject_class),
782 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
783 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
785 g_cclosure_marshal_VOID__VOID,
788 icon_view_signals[TOGGLE_CURSOR_ITEM] =
789 g_signal_new (I_("toggle_cursor_item"),
790 G_TYPE_FROM_CLASS (gobject_class),
791 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
792 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
794 g_cclosure_marshal_VOID__VOID,
797 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
798 g_signal_new (I_("activate_cursor_item"),
799 G_TYPE_FROM_CLASS (gobject_class),
800 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
801 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
803 _gtk_marshal_BOOLEAN__VOID,
806 icon_view_signals[MOVE_CURSOR] =
807 g_signal_new (I_("move_cursor"),
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
812 _gtk_marshal_BOOLEAN__ENUM_INT,
814 GTK_TYPE_MOVEMENT_STEP,
818 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
820 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
822 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
823 "toggle_cursor_item", 0);
825 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
826 "activate_cursor_item", 0);
827 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
828 "activate_cursor_item", 0);
829 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
830 "activate_cursor_item", 0);
831 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
832 "activate_cursor_item", 0);
834 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
835 GTK_MOVEMENT_DISPLAY_LINES, -1);
836 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
837 GTK_MOVEMENT_DISPLAY_LINES, -1);
839 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
840 GTK_MOVEMENT_DISPLAY_LINES, 1);
841 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
842 GTK_MOVEMENT_DISPLAY_LINES, 1);
844 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
845 GTK_MOVEMENT_DISPLAY_LINES, -1);
847 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
848 GTK_MOVEMENT_DISPLAY_LINES, 1);
850 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
851 GTK_MOVEMENT_BUFFER_ENDS, -1);
852 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
853 GTK_MOVEMENT_BUFFER_ENDS, -1);
855 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
856 GTK_MOVEMENT_BUFFER_ENDS, 1);
857 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
858 GTK_MOVEMENT_BUFFER_ENDS, 1);
860 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
861 GTK_MOVEMENT_PAGES, -1);
862 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
863 GTK_MOVEMENT_PAGES, -1);
865 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
866 GTK_MOVEMENT_PAGES, 1);
867 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
868 GTK_MOVEMENT_PAGES, 1);
870 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
871 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
872 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
873 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
875 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
876 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
878 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
882 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
884 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
885 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
886 iface->clear = gtk_icon_view_cell_layout_clear;
887 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
888 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
889 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
890 iface->reorder = gtk_icon_view_cell_layout_reorder;
894 gtk_icon_view_init (GtkIconView *icon_view)
896 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
898 icon_view->priv->width = 0;
899 icon_view->priv->height = 0;
900 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
901 icon_view->priv->pressed_button = -1;
902 icon_view->priv->press_start_x = -1;
903 icon_view->priv->press_start_y = -1;
904 icon_view->priv->text_column = -1;
905 icon_view->priv->markup_column = -1;
906 icon_view->priv->pixbuf_column = -1;
907 icon_view->priv->text_cell = -1;
908 icon_view->priv->pixbuf_cell = -1;
910 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
912 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
914 icon_view->priv->cell_list = NULL;
915 icon_view->priv->n_cells = 0;
916 icon_view->priv->cursor_cell = -1;
918 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
920 icon_view->priv->columns = -1;
921 icon_view->priv->item_width = -1;
922 icon_view->priv->spacing = 0;
923 icon_view->priv->row_spacing = 6;
924 icon_view->priv->column_spacing = 6;
925 icon_view->priv->margin = 6;
929 gtk_icon_view_destroy (GtkObject *object)
931 GtkIconView *icon_view;
933 icon_view = GTK_ICON_VIEW (object);
935 gtk_icon_view_stop_editing (icon_view, TRUE);
937 gtk_icon_view_set_model (icon_view, NULL);
939 if (icon_view->priv->layout_idle_id != 0)
941 g_source_remove (icon_view->priv->layout_idle_id);
942 icon_view->priv->layout_idle_id = 0;
945 if (icon_view->priv->scroll_to_path != NULL)
947 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
948 icon_view->priv->scroll_to_path = NULL;
951 remove_scroll_timeout (icon_view);
953 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
956 /* GObject methods */
958 gtk_icon_view_finalize (GObject *object)
960 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
962 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
967 gtk_icon_view_set_property (GObject *object,
972 GtkIconView *icon_view;
974 icon_view = GTK_ICON_VIEW (object);
978 case PROP_SELECTION_MODE:
979 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
981 case PROP_PIXBUF_COLUMN:
982 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
984 case PROP_TEXT_COLUMN:
985 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
987 case PROP_MARKUP_COLUMN:
988 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
991 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
993 case PROP_ORIENTATION:
994 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
997 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
999 case PROP_ITEM_WIDTH:
1000 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1003 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1005 case PROP_ROW_SPACING:
1006 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1008 case PROP_COLUMN_SPACING:
1009 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1012 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1014 case PROP_REORDERABLE:
1015 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1019 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1025 gtk_icon_view_get_property (GObject *object,
1030 GtkIconView *icon_view;
1032 icon_view = GTK_ICON_VIEW (object);
1036 case PROP_SELECTION_MODE:
1037 g_value_set_enum (value, icon_view->priv->selection_mode);
1039 case PROP_PIXBUF_COLUMN:
1040 g_value_set_int (value, icon_view->priv->pixbuf_column);
1042 case PROP_TEXT_COLUMN:
1043 g_value_set_int (value, icon_view->priv->text_column);
1045 case PROP_MARKUP_COLUMN:
1046 g_value_set_int (value, icon_view->priv->markup_column);
1049 g_value_set_object (value, icon_view->priv->model);
1051 case PROP_ORIENTATION:
1052 g_value_set_enum (value, icon_view->priv->orientation);
1055 g_value_set_int (value, icon_view->priv->columns);
1057 case PROP_ITEM_WIDTH:
1058 g_value_set_int (value, icon_view->priv->item_width);
1061 g_value_set_int (value, icon_view->priv->spacing);
1063 case PROP_ROW_SPACING:
1064 g_value_set_int (value, icon_view->priv->row_spacing);
1066 case PROP_COLUMN_SPACING:
1067 g_value_set_int (value, icon_view->priv->column_spacing);
1070 g_value_set_int (value, icon_view->priv->margin);
1072 case PROP_REORDERABLE:
1073 g_value_set_boolean (value, icon_view->priv->reorderable);
1077 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1082 /* GtkWidget signals */
1084 gtk_icon_view_realize (GtkWidget *widget)
1086 GtkIconView *icon_view;
1087 GdkWindowAttr attributes;
1088 gint attributes_mask;
1090 icon_view = GTK_ICON_VIEW (widget);
1092 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1094 /* Make the main, clipping window */
1095 attributes.window_type = GDK_WINDOW_CHILD;
1096 attributes.x = widget->allocation.x;
1097 attributes.y = widget->allocation.y;
1098 attributes.width = widget->allocation.width;
1099 attributes.height = widget->allocation.height;
1100 attributes.wclass = GDK_INPUT_OUTPUT;
1101 attributes.visual = gtk_widget_get_visual (widget);
1102 attributes.colormap = gtk_widget_get_colormap (widget);
1103 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1105 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1107 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1108 &attributes, attributes_mask);
1109 gdk_window_set_user_data (widget->window, widget);
1111 /* Make the window for the icon view */
1114 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1115 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1116 attributes.event_mask = (GDK_EXPOSURE_MASK |
1118 GDK_POINTER_MOTION_MASK |
1119 GDK_BUTTON_PRESS_MASK |
1120 GDK_BUTTON_RELEASE_MASK |
1121 GDK_KEY_PRESS_MASK |
1122 GDK_KEY_RELEASE_MASK) |
1123 gtk_widget_get_events (widget);
1125 icon_view->priv->bin_window = gdk_window_new (widget->window,
1126 &attributes, attributes_mask);
1127 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1129 widget->style = gtk_style_attach (widget->style, widget->window);
1130 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1131 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1133 gdk_window_show (icon_view->priv->bin_window);
1137 gtk_icon_view_unrealize (GtkWidget *widget)
1139 GtkIconView *icon_view;
1141 icon_view = GTK_ICON_VIEW (widget);
1143 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1144 gdk_window_destroy (icon_view->priv->bin_window);
1145 icon_view->priv->bin_window = NULL;
1147 /* GtkWidget::unrealize destroys children and widget->window */
1148 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1149 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1153 gtk_icon_view_size_request (GtkWidget *widget,
1154 GtkRequisition *requisition)
1156 GtkIconView *icon_view;
1159 icon_view = GTK_ICON_VIEW (widget);
1161 requisition->width = icon_view->priv->width;
1162 requisition->height = icon_view->priv->height;
1164 tmp_list = icon_view->priv->children;
1168 GtkIconViewChild *child = tmp_list->data;
1169 GtkRequisition child_requisition;
1171 tmp_list = tmp_list->next;
1173 if (GTK_WIDGET_VISIBLE (child->widget))
1174 gtk_widget_size_request (child->widget, &child_requisition);
1179 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1183 for (list = icon_view->priv->children; list; list = list->next)
1185 GtkIconViewChild *child = list->data;
1186 GtkAllocation allocation;
1188 /* totally ignore our child's requisition */
1189 if (child->cell < 0)
1191 allocation.x = child->item->x;
1192 allocation.y = child->item->y;
1193 allocation.width = child->item->width;
1194 allocation.height = child->item->height;
1198 GdkRectangle *box = &child->item->box[child->cell];
1200 allocation.x = box->x;
1201 allocation.y = box->y;
1202 allocation.width = box->width;
1203 allocation.height = box->height;
1206 gtk_widget_size_allocate (child->widget, &allocation);
1211 gtk_icon_view_size_allocate (GtkWidget *widget,
1212 GtkAllocation *allocation)
1214 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1216 GtkAdjustment *hadjustment, *vadjustment;
1218 widget->allocation = *allocation;
1220 if (GTK_WIDGET_REALIZED (widget))
1222 gdk_window_move_resize (widget->window,
1223 allocation->x, allocation->y,
1224 allocation->width, allocation->height);
1225 gdk_window_resize (icon_view->priv->bin_window,
1226 MAX (icon_view->priv->width, allocation->width),
1227 MAX (icon_view->priv->height, allocation->height));
1230 gtk_icon_view_layout (icon_view);
1232 gtk_icon_view_allocate_children (icon_view);
1234 hadjustment = icon_view->priv->hadjustment;
1235 vadjustment = icon_view->priv->vadjustment;
1237 hadjustment->page_size = allocation->width;
1238 hadjustment->page_increment = allocation->width * 0.9;
1239 hadjustment->step_increment = allocation->width * 0.1;
1240 hadjustment->lower = 0;
1241 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1243 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1244 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1246 vadjustment->page_size = allocation->height;
1247 vadjustment->page_increment = allocation->height * 0.9;
1248 vadjustment->step_increment = allocation->height * 0.1;
1249 vadjustment->lower = 0;
1250 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1252 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1253 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1255 if (GTK_WIDGET_REALIZED (widget) &&
1256 icon_view->priv->scroll_to_path)
1259 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1260 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1261 icon_view->priv->scroll_to_path = NULL;
1263 gtk_icon_view_scroll_to_path (icon_view, path,
1264 icon_view->priv->scroll_to_use_align,
1265 icon_view->priv->scroll_to_row_align,
1266 icon_view->priv->scroll_to_col_align);
1267 gtk_tree_path_free (path);
1271 gtk_adjustment_changed (hadjustment);
1272 gtk_adjustment_changed (vadjustment);
1277 gtk_icon_view_expose (GtkWidget *widget,
1278 GdkEventExpose *expose)
1280 GtkIconView *icon_view;
1285 GtkIconViewDropPosition dest_pos;
1286 GtkIconViewItem *dest_item = NULL;
1288 icon_view = GTK_ICON_VIEW (widget);
1290 if (expose->window != icon_view->priv->bin_window)
1293 cr = gdk_cairo_create (icon_view->priv->bin_window);
1294 cairo_set_line_width (cr, 1.);
1296 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1300 dest_index = gtk_tree_path_get_indices (path)[0];
1301 gtk_tree_path_free (path);
1306 for (icons = icon_view->priv->items; icons; icons = icons->next)
1308 GtkIconViewItem *item = icons->data;
1313 area.width = item->width;
1314 area.height = item->height;
1316 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1319 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1320 icon_view->priv->bin_window,
1321 item->x, item->y, TRUE);
1323 if (dest_index == item->index)
1331 case GTK_ICON_VIEW_DROP_INTO:
1332 gtk_paint_focus (widget->style,
1333 icon_view->priv->bin_window,
1334 GTK_WIDGET_STATE (widget),
1337 "iconview-drop-indicator",
1338 dest_item->x, dest_item->y,
1339 dest_item->width, dest_item->height);
1341 case GTK_ICON_VIEW_DROP_ABOVE:
1342 gtk_paint_focus (widget->style,
1343 icon_view->priv->bin_window,
1344 GTK_WIDGET_STATE (widget),
1347 "iconview-drop-indicator",
1348 dest_item->x, dest_item->y - 1,
1349 dest_item->width, 2);
1351 case GTK_ICON_VIEW_DROP_LEFT:
1352 gtk_paint_focus (widget->style,
1353 icon_view->priv->bin_window,
1354 GTK_WIDGET_STATE (widget),
1357 "iconview-drop-indicator",
1358 dest_item->x - 1, dest_item->y,
1359 2, dest_item->height);
1361 case GTK_ICON_VIEW_DROP_BELOW:
1362 gtk_paint_focus (widget->style,
1363 icon_view->priv->bin_window,
1364 GTK_WIDGET_STATE (widget),
1367 "iconview-drop-indicator",
1368 dest_item->x, dest_item->y + dest_item->height - 1,
1369 dest_item->width, 2);
1371 case GTK_ICON_VIEW_DROP_RIGHT:
1372 gtk_paint_focus (widget->style,
1373 icon_view->priv->bin_window,
1374 GTK_WIDGET_STATE (widget),
1377 "iconview-drop-indicator",
1378 dest_item->x + dest_item->width - 1, dest_item->y,
1379 2, dest_item->height);
1380 case GTK_ICON_VIEW_NO_DROP: ;
1385 if (icon_view->priv->doing_rubberband)
1387 GdkRectangle *rectangles;
1390 gdk_region_get_rectangles (expose->region,
1394 while (n_rectangles--)
1395 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1397 g_free (rectangles);
1402 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1408 rubberband_scroll_timeout (gpointer data)
1410 GtkIconView *icon_view;
1413 GDK_THREADS_ENTER ();
1417 value = MIN (icon_view->priv->vadjustment->value +
1418 icon_view->priv->scroll_value_diff,
1419 icon_view->priv->vadjustment->upper -
1420 icon_view->priv->vadjustment->page_size);
1422 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1424 gtk_icon_view_update_rubberband (icon_view);
1426 GDK_THREADS_LEAVE ();
1432 gtk_icon_view_motion (GtkWidget *widget,
1433 GdkEventMotion *event)
1435 GtkIconView *icon_view;
1438 icon_view = GTK_ICON_VIEW (widget);
1440 gtk_icon_view_maybe_begin_drag (icon_view, event);
1442 if (icon_view->priv->doing_rubberband)
1444 gtk_icon_view_update_rubberband (widget);
1446 abs_y = event->y - icon_view->priv->height *
1447 (icon_view->priv->vadjustment->value /
1448 (icon_view->priv->vadjustment->upper -
1449 icon_view->priv->vadjustment->lower));
1451 if (abs_y < 0 || abs_y > widget->allocation.height)
1454 icon_view->priv->scroll_value_diff = abs_y;
1456 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1458 icon_view->priv->event_last_x = event->x;
1459 icon_view->priv->event_last_y = event->y;
1461 if (icon_view->priv->scroll_timeout_id == 0)
1462 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1466 remove_scroll_timeout (icon_view);
1473 gtk_icon_view_remove (GtkContainer *container,
1476 GtkIconView *icon_view;
1477 GtkIconViewChild *child = NULL;
1480 icon_view = GTK_ICON_VIEW (container);
1482 tmp_list = icon_view->priv->children;
1485 child = tmp_list->data;
1486 if (child->widget == widget)
1488 gtk_widget_unparent (widget);
1490 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1491 g_list_free_1 (tmp_list);
1496 tmp_list = tmp_list->next;
1501 gtk_icon_view_forall (GtkContainer *container,
1502 gboolean include_internals,
1503 GtkCallback callback,
1504 gpointer callback_data)
1506 GtkIconView *icon_view;
1507 GtkIconViewChild *child = NULL;
1510 icon_view = GTK_ICON_VIEW (container);
1512 tmp_list = icon_view->priv->children;
1515 child = tmp_list->data;
1516 tmp_list = tmp_list->next;
1518 (* callback) (child->widget, callback_data);
1523 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1524 GtkIconViewItem *item,
1525 GtkIconViewCellInfo *info,
1530 GdkRectangle cell_area;
1531 gboolean visible, mode;
1533 gtk_icon_view_set_cell_data (icon_view, item);
1535 g_object_get (info->cell,
1536 "visible", &visible,
1540 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1542 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1544 path = gtk_tree_path_new_from_indices (item->index, -1);
1545 path_string = gtk_tree_path_to_string (path);
1546 gtk_tree_path_free (path);
1548 gtk_cell_renderer_activate (info->cell,
1550 GTK_WIDGET (icon_view),
1556 g_free (path_string);
1561 gtk_icon_view_put (GtkIconView *icon_view,
1563 GtkIconViewItem *item,
1566 GtkIconViewChild *child;
1568 child = g_new (GtkIconViewChild, 1);
1570 child->widget = widget;
1574 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1576 if (GTK_WIDGET_REALIZED (icon_view))
1577 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1579 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1583 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1584 GtkIconView *icon_view)
1587 GtkIconViewItem *item;
1589 if (icon_view->priv->edited_item == NULL)
1592 item = icon_view->priv->edited_item;
1593 icon_view->priv->edited_item = NULL;
1594 icon_view->priv->editable = NULL;
1595 for (l = icon_view->priv->cell_list; l; l = l->next)
1597 GtkIconViewCellInfo *info = l->data;
1599 info->editing = FALSE;
1602 if (GTK_WIDGET_HAS_FOCUS (editable))
1603 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1605 g_signal_handlers_disconnect_by_func (editable,
1606 gtk_icon_view_remove_widget,
1609 gtk_container_remove (GTK_CONTAINER (icon_view),
1610 GTK_WIDGET (editable));
1612 gtk_icon_view_queue_draw_item (icon_view, item);
1617 gtk_icon_view_start_editing (GtkIconView *icon_view,
1618 GtkIconViewItem *item,
1619 GtkIconViewCellInfo *info,
1624 GdkRectangle cell_area;
1625 gboolean visible, mode;
1626 GtkCellEditable *editable;
1628 gtk_icon_view_set_cell_data (icon_view, item);
1630 g_object_get (info->cell,
1631 "visible", &visible,
1634 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1636 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1638 path = gtk_tree_path_new_from_indices (item->index, -1);
1639 path_string = gtk_tree_path_to_string (path);
1640 gtk_tree_path_free (path);
1642 editable = gtk_cell_renderer_start_editing (info->cell,
1644 GTK_WIDGET (icon_view),
1649 g_free (path_string);
1651 /* FIXME ugly special case */
1652 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1653 g_object_set (editable, "has_frame", TRUE, NULL);
1655 /* the rest corresponds to tree_view_real_start_editing... */
1656 icon_view->priv->edited_item = item;
1657 icon_view->priv->editable = editable;
1658 info->editing = TRUE;
1660 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1662 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1664 gtk_widget_grab_focus (GTK_WIDGET (editable));
1665 g_signal_connect (editable, "remove_widget",
1666 G_CALLBACK (gtk_icon_view_remove_widget),
1673 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1674 gboolean cancel_editing)
1676 GtkCellRenderer *cell = NULL;
1677 GtkIconViewItem *item;
1680 if (icon_view->priv->edited_item == NULL)
1684 * This is very evil. We need to do this, because
1685 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1686 * later on. If gtk_icon_view_row_changed notices
1687 * icon_view->priv->edited_item != NULL, it'll call
1688 * gtk_icon_view_stop_editing again. Bad things will happen then.
1690 * Please read that again if you intend to modify anything here.
1693 item = icon_view->priv->edited_item;
1694 icon_view->priv->edited_item = NULL;
1696 for (l = icon_view->priv->cell_list; l; l = l->next)
1698 GtkIconViewCellInfo *info = l->data;
1710 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1711 if (!cancel_editing)
1712 gtk_cell_editable_editing_done (icon_view->priv->editable);
1714 icon_view->priv->edited_item = item;
1716 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1720 * gtk_icon_view_set_cursor:
1721 * @icon_view: A #GtkIconView
1722 * @path: A #GtkTreePath
1723 * @cell: A #GtkCellRenderer or %NULL
1724 * @start_editing: %TRUE if the specified cell should start being edited.
1726 * Sets the current keyboard focus to be at @path, and selects it. This is
1727 * useful when you want to focus the user's attention on a particular item.
1728 * If @cell is not %NULL, then focus is given to the cell specified by
1729 * it. Additionally, if @start_editing is %TRUE, then editing should be
1730 * started in the specified cell.
1732 * This function is often followed by <literal>gtk_widget_grab_focus
1733 * (icon_view)</literal> in order to give keyboard focus to the widget.
1734 * Please note that editing can only happen when the widget is realized.
1739 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1741 GtkCellRenderer *cell,
1742 gboolean start_editing)
1744 GtkIconViewItem *item;
1745 GtkIconViewCellInfo *info = NULL;
1749 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1750 g_return_if_fail (path != NULL);
1751 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1753 gtk_icon_view_stop_editing (icon_view, TRUE);
1755 if (gtk_tree_path_get_depth (path) == 1)
1756 item = g_list_nth (icon_view->priv->items,
1757 gtk_tree_path_get_indices(path)[0])->data;
1763 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1767 if (info->cell == cell)
1776 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1777 if (FALSE && GTK_WIDGET_REALIZED (icon_view))
1778 gtk_icon_view_scroll_to_item (icon_view, item);
1780 gtk_icon_view_scroll_to_path (icon_view, path,
1784 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1788 * gtk_icon_view_get_cursor:
1789 * @icon_view: A #GtkIconView
1790 * @path: Return location for the current cursor path, or %NULL
1791 * @cell: Return location the current focus cell, or %NULL
1793 * Fills in @path and @cell with the current cursor path and cell.
1794 * If the cursor isn't currently set, then *@path will be %NULL.
1795 * If no cell currently has focus, then *@cell will be %NULL.
1797 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1799 * Return value: %TRUE if the cursor is set.
1804 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1806 GtkCellRenderer **cell)
1808 GtkIconViewItem *item;
1809 GtkIconViewCellInfo *info;
1811 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1813 item = icon_view->priv->cursor_item;
1814 if (icon_view->priv->cursor_cell < 0)
1817 info = g_list_nth_data (icon_view->priv->cell_list,
1818 icon_view->priv->cursor_cell);
1823 *path = gtk_tree_path_new_from_indices (item->index, -1);
1836 return (item != NULL);
1840 gtk_icon_view_button_press (GtkWidget *widget,
1841 GdkEventButton *event)
1843 GtkIconView *icon_view;
1844 GtkIconViewItem *item;
1845 GtkIconViewCellInfo *info = NULL;
1846 gboolean dirty = FALSE;
1847 GtkCellRendererMode mode;
1850 icon_view = GTK_ICON_VIEW (widget);
1852 if (event->window != icon_view->priv->bin_window)
1855 if (!GTK_WIDGET_HAS_FOCUS (widget))
1856 gtk_widget_grab_focus (widget);
1858 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1860 item = gtk_icon_view_get_item_at_coords (icon_view,
1866 g_object_get (info->cell, "mode", &mode, NULL);
1868 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1869 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1870 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1874 gtk_icon_view_scroll_to_item (icon_view, item);
1876 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1878 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1880 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1881 (event->state & GDK_SHIFT_MASK))
1883 gtk_icon_view_unselect_all_internal (icon_view);
1885 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1886 if (!icon_view->priv->anchor_item)
1887 icon_view->priv->anchor_item = item;
1889 gtk_icon_view_select_all_between (icon_view,
1890 icon_view->priv->anchor_item,
1896 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1897 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1898 (event->state & GDK_CONTROL_MASK))
1900 item->selected = !item->selected;
1901 gtk_icon_view_queue_draw_item (icon_view, item);
1906 if (!item->selected)
1908 gtk_icon_view_unselect_all_internal (icon_view);
1910 item->selected = TRUE;
1911 gtk_icon_view_queue_draw_item (icon_view, item);
1915 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1916 icon_view->priv->anchor_item = item;
1919 /* Save press to possibly begin a drag */
1920 if (icon_view->priv->pressed_button < 0)
1922 icon_view->priv->pressed_button = event->button;
1923 icon_view->priv->press_start_x = event->x;
1924 icon_view->priv->press_start_y = event->y;
1927 if (!icon_view->priv->last_single_clicked)
1928 icon_view->priv->last_single_clicked = item;
1930 /* cancel the current editing, if it exists */
1931 gtk_icon_view_stop_editing (icon_view, TRUE);
1933 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1934 gtk_icon_view_item_activate_cell (icon_view, item, info,
1936 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1937 gtk_icon_view_start_editing (icon_view, item, info,
1942 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1943 !(event->state & GDK_CONTROL_MASK))
1945 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1948 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1949 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
1954 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1956 item = gtk_icon_view_get_item_at_coords (icon_view,
1961 if (item && item == icon_view->priv->last_single_clicked)
1965 path = gtk_tree_path_new_from_indices (item->index, -1);
1966 gtk_icon_view_item_activated (icon_view, path);
1967 gtk_tree_path_free (path);
1970 icon_view->priv->last_single_clicked = NULL;
1974 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1976 return event->button == 1;
1980 gtk_icon_view_button_release (GtkWidget *widget,
1981 GdkEventButton *event)
1983 GtkIconView *icon_view;
1985 icon_view = GTK_ICON_VIEW (widget);
1987 if (icon_view->priv->pressed_button == event->button)
1988 icon_view->priv->pressed_button = -1;
1990 gtk_icon_view_stop_rubberbanding (icon_view);
1992 remove_scroll_timeout (icon_view);
1998 gtk_icon_view_update_rubberband (gpointer data)
2000 GtkIconView *icon_view;
2002 GdkRectangle old_area;
2003 GdkRectangle new_area;
2004 GdkRectangle common;
2005 GdkRegion *invalid_region;
2007 icon_view = GTK_ICON_VIEW (data);
2009 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2014 old_area.x = MIN (icon_view->priv->rubberband_x1,
2015 icon_view->priv->rubberband_x2);
2016 old_area.y = MIN (icon_view->priv->rubberband_y1,
2017 icon_view->priv->rubberband_y2);
2018 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2019 icon_view->priv->rubberband_x1) + 1;
2020 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2021 icon_view->priv->rubberband_y1) + 1;
2023 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2024 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2025 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2026 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2028 invalid_region = gdk_region_rectangle (&old_area);
2029 gdk_region_union_with_rect (invalid_region, &new_area);
2031 gdk_rectangle_intersect (&old_area, &new_area, &common);
2032 if (common.width > 2 && common.height > 2)
2034 GdkRegion *common_region;
2036 /* make sure the border is invalidated */
2042 common_region = gdk_region_rectangle (&common);
2044 gdk_region_subtract (invalid_region, common_region);
2045 gdk_region_destroy (common_region);
2048 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2050 gdk_region_destroy (invalid_region);
2052 icon_view->priv->rubberband_x2 = x;
2053 icon_view->priv->rubberband_y2 = y;
2055 gtk_icon_view_update_rubberband_selection (icon_view);
2059 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2065 g_assert (!icon_view->priv->doing_rubberband);
2067 for (items = icon_view->priv->items; items; items = items->next)
2069 GtkIconViewItem *item = items->data;
2071 item->selected_before_rubberbanding = item->selected;
2074 icon_view->priv->rubberband_x1 = x;
2075 icon_view->priv->rubberband_y1 = y;
2076 icon_view->priv->rubberband_x2 = x;
2077 icon_view->priv->rubberband_y2 = y;
2079 icon_view->priv->doing_rubberband = TRUE;
2081 gtk_grab_add (GTK_WIDGET (icon_view));
2085 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2087 if (!icon_view->priv->doing_rubberband)
2090 icon_view->priv->doing_rubberband = FALSE;
2092 gtk_grab_remove (GTK_WIDGET (icon_view));
2094 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2098 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2101 gint x, y, width, height;
2102 gboolean dirty = FALSE;
2104 x = MIN (icon_view->priv->rubberband_x1,
2105 icon_view->priv->rubberband_x2);
2106 y = MIN (icon_view->priv->rubberband_y1,
2107 icon_view->priv->rubberband_y2);
2108 width = ABS (icon_view->priv->rubberband_x1 -
2109 icon_view->priv->rubberband_x2);
2110 height = ABS (icon_view->priv->rubberband_y1 -
2111 icon_view->priv->rubberband_y2);
2113 for (items = icon_view->priv->items; items; items = items->next)
2115 GtkIconViewItem *item = items->data;
2119 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2120 x, y, width, height);
2122 selected = is_in ^ item->selected_before_rubberbanding;
2124 if (item->selected != selected)
2126 item->selected = selected;
2128 gtk_icon_view_queue_draw_item (icon_view, item);
2133 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2137 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2138 GtkIconViewItem *item,
2147 for (l = icon_view->priv->cell_list; l; l = l->next)
2149 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2151 if (!info->cell->visible)
2154 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2156 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2157 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2165 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2167 gboolean dirty = FALSE;
2170 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2173 for (items = icon_view->priv->items; items; items = items->next)
2175 GtkIconViewItem *item = items->data;
2179 item->selected = FALSE;
2181 gtk_icon_view_queue_draw_item (icon_view, item);
2189 /* GtkIconView signals */
2191 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2192 GtkAdjustment *hadj,
2193 GtkAdjustment *vadj)
2195 gboolean need_adjust = FALSE;
2198 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2200 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2202 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2204 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2206 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2208 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2209 0, 0, NULL, NULL, icon_view);
2210 g_object_unref (icon_view->priv->hadjustment);
2213 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2215 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2216 0, 0, NULL, NULL, icon_view);
2217 g_object_unref (icon_view->priv->vadjustment);
2220 if (icon_view->priv->hadjustment != hadj)
2222 icon_view->priv->hadjustment = hadj;
2223 g_object_ref (icon_view->priv->hadjustment);
2224 gtk_object_sink (GTK_OBJECT (icon_view->priv->hadjustment));
2226 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2227 G_CALLBACK (gtk_icon_view_adjustment_changed),
2232 if (icon_view->priv->vadjustment != vadj)
2234 icon_view->priv->vadjustment = vadj;
2235 g_object_ref (icon_view->priv->vadjustment);
2236 gtk_object_sink (GTK_OBJECT (icon_view->priv->vadjustment));
2238 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2239 G_CALLBACK (gtk_icon_view_adjustment_changed),
2245 gtk_icon_view_adjustment_changed (NULL, icon_view);
2249 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2251 gtk_icon_view_select_all (icon_view);
2255 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2257 gtk_icon_view_unselect_all (icon_view);
2261 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2263 gtk_icon_view_unselect_all (icon_view);
2265 if (icon_view->priv->cursor_item != NULL)
2266 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2270 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2273 GtkCellRendererMode mode;
2274 GtkIconViewCellInfo *info = NULL;
2276 if (!icon_view->priv->cursor_item)
2279 info = g_list_nth_data (icon_view->priv->cell_list,
2280 icon_view->priv->cursor_cell);
2284 g_object_get (info->cell, "mode", &mode, NULL);
2286 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2288 gtk_icon_view_item_activate_cell (icon_view,
2289 icon_view->priv->cursor_item,
2293 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2295 gtk_icon_view_start_editing (icon_view,
2296 icon_view->priv->cursor_item,
2302 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2303 gtk_icon_view_item_activated (icon_view, path);
2304 gtk_tree_path_free (path);
2310 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2312 if (!icon_view->priv->cursor_item)
2315 switch (icon_view->priv->selection_mode)
2317 case GTK_SELECTION_NONE:
2319 case GTK_SELECTION_BROWSE:
2320 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2322 case GTK_SELECTION_SINGLE:
2323 if (icon_view->priv->cursor_item->selected)
2324 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2326 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2328 case GTK_SELECTION_MULTIPLE:
2329 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2330 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2332 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2337 /* Internal functions */
2339 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2340 GtkIconView *icon_view)
2342 if (GTK_WIDGET_REALIZED (icon_view))
2344 gdk_window_move (icon_view->priv->bin_window,
2345 - icon_view->priv->hadjustment->value,
2346 - icon_view->priv->vadjustment->value);
2348 if (icon_view->priv->doing_rubberband)
2349 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2351 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2356 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2361 gint *maximum_width)
2365 gint x, current_width;
2366 GList *items, *last_item;
2373 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2374 max_height = g_new0 (gint, icon_view->priv->n_cells);
2381 gtk_widget_style_get (GTK_WIDGET (icon_view),
2382 "focus-line-width", &focus_width,
2385 spacing = icon_view->priv->spacing;
2387 x += icon_view->priv->margin + focus_width;
2388 current_width += 2 * (icon_view->priv->margin + focus_width);
2393 GtkIconViewItem *item = items->data;
2395 gtk_icon_view_calculate_item_size (icon_view, item);
2396 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2398 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2400 current_width += item->width;
2402 if (items != first_item)
2404 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2405 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2409 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2411 item->y = *y + focus_width;
2412 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2414 x = current_width - (icon_view->priv->margin + focus_width);
2416 for (i = 0; i < icon_view->priv->n_cells; i++)
2417 max_height[i] = MAX (max_height[i], item->box[i].height);
2419 if (current_width > *maximum_width)
2420 *maximum_width = current_width;
2426 items = items->next;
2431 /* Now go through the row again and align the icons */
2432 for (items = first_item; items != last_item; items = items->next)
2434 GtkIconViewItem *item = items->data;
2436 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2438 /* We may want to readjust the new y coordinate. */
2439 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2440 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2443 item->col = col - 1 - item->col;
2446 g_free (max_height);
2452 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2455 if (upper != adj->upper)
2457 gdouble min = MAX (0.0, upper - adj->page_size);
2458 gboolean value_changed = FALSE;
2462 if (adj->value > min)
2465 value_changed = TRUE;
2468 gtk_adjustment_changed (adj);
2471 gtk_adjustment_value_changed (adj);
2476 gtk_icon_view_layout (GtkIconView *icon_view)
2478 gint y = 0, maximum_width = 0;
2484 if (icon_view->priv->model == NULL)
2487 widget = GTK_WIDGET (icon_view);
2489 item_width = icon_view->priv->item_width;
2493 for (icons = icon_view->priv->items; icons; icons = icons->next)
2495 GtkIconViewItem *item = icons->data;
2496 gtk_icon_view_calculate_item_size (icon_view, item);
2497 item_width = MAX (item_width, item->width);
2501 icons = icon_view->priv->items;
2502 y += icon_view->priv->margin;
2507 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2509 &y, &maximum_width);
2512 while (icons != NULL);
2514 if (maximum_width != icon_view->priv->width)
2516 icon_view->priv->width = maximum_width;
2518 y += icon_view->priv->margin;
2520 if (y != icon_view->priv->height)
2522 icon_view->priv->height = y;
2525 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width);
2526 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height);
2528 if (GTK_WIDGET_REALIZED (icon_view))
2530 gdk_window_resize (icon_view->priv->bin_window,
2531 MAX (icon_view->priv->width, widget->allocation.width),
2532 MAX (icon_view->priv->height, widget->allocation.height));
2535 if (icon_view->priv->layout_idle_id != 0)
2537 g_source_remove (icon_view->priv->layout_idle_id);
2538 icon_view->priv->layout_idle_id = 0;
2541 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2545 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2546 GtkIconViewItem *item,
2547 GtkIconViewCellInfo *info,
2548 GdkRectangle *cell_area)
2550 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2552 cell_area->x = item->box[info->position].x - item->before[info->position];
2553 cell_area->y = item->y;
2554 cell_area->width = item->box[info->position].width +
2555 item->before[info->position] + item->after[info->position];
2556 cell_area->height = item->height;
2560 cell_area->x = item->x;
2561 cell_area->y = item->box[info->position].y - item->before[info->position];
2562 cell_area->width = item->width;
2563 cell_area->height = item->box[info->position].height +
2564 item->before[info->position] + item->after[info->position];
2569 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2570 GtkIconViewItem *item,
2571 GtkIconViewCellInfo *info,
2574 *box = item->box[info->position];
2577 /* try to guess a reasonable wrap width for an implicit text cell renderer
2580 adjust_wrap_width (GtkIconView *icon_view,
2581 GtkIconViewItem *item)
2583 GtkIconViewCellInfo *text_info;
2584 GtkIconViewCellInfo *pixbuf_info;
2585 gint pixbuf_width, wrap_width;
2587 if (icon_view->priv->item_width < 0 &&
2588 icon_view->priv->text_cell != -1 &&
2589 icon_view->priv->pixbuf_cell != -1)
2591 text_info = g_list_nth_data (icon_view->priv->cell_list,
2592 icon_view->priv->text_cell);
2593 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2594 icon_view->priv->pixbuf_cell);
2596 gtk_cell_renderer_get_size (pixbuf_info->cell,
2597 GTK_WIDGET (icon_view),
2602 if (item->width == -1)
2603 wrap_width = pixbuf_width;
2604 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2605 wrap_width = item->width;
2607 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2609 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2614 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2615 GtkIconViewItem *item)
2620 if (item->width != -1 && item->height != -1)
2623 if (item->n_cells != icon_view->priv->n_cells)
2625 g_free (item->before);
2626 g_free (item->after);
2629 item->before = g_new0 (gint, icon_view->priv->n_cells);
2630 item->after = g_new0 (gint, icon_view->priv->n_cells);
2631 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2633 item->n_cells = icon_view->priv->n_cells;
2636 gtk_icon_view_set_cell_data (icon_view, item);
2638 spacing = icon_view->priv->spacing;
2642 for (l = icon_view->priv->cell_list; l; l = l->next)
2644 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2646 if (!info->cell->visible)
2649 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2651 &item->box[info->position].width,
2652 &item->box[info->position].height);
2654 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2656 item->width += item->box[info->position].width
2657 + (info->position > 0 ? spacing : 0);
2658 item->height = MAX (item->height, item->box[info->position].height);
2662 item->width = MAX (item->width, item->box[info->position].width);
2663 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2669 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2670 GtkIconViewItem *item,
2673 GdkRectangle cell_area;
2679 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2681 gtk_icon_view_set_cell_data (icon_view, item);
2683 spacing = icon_view->priv->spacing;
2686 for (i = 0; i < icon_view->priv->n_cells; i++)
2688 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2689 item->height = MAX (item->height, max_height[i]);
2691 item->height += max_height[i] + (i > 0 ? spacing : 0);
2694 cell_area.x = item->x;
2695 cell_area.y = item->y;
2697 for (k = 0; k < 2; k++)
2698 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2700 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2702 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2705 if (!info->cell->visible)
2708 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2710 cell_area.width = item->box[info->position].width;
2711 cell_area.height = item->height;
2715 cell_area.width = item->width;
2716 cell_area.height = max_height[i];
2719 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2721 &item->box[info->position].x, &item->box[info->position].y,
2722 &item->box[info->position].width, &item->box[info->position].height);
2724 item->box[info->position].x += cell_area.x;
2725 item->box[info->position].y += cell_area.y;
2726 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2728 item->before[info->position] = item->box[info->position].x - cell_area.x;
2729 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2730 cell_area.x += cell_area.width + spacing;
2734 if (item->box[info->position].width > item->width)
2736 item->width = item->box[info->position].width;
2737 cell_area.width = item->width;
2739 item->before[info->position] = item->box[info->position].y - cell_area.y;
2740 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2741 cell_area.y += cell_area.height + spacing;
2745 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2747 for (i = 0; i < icon_view->priv->n_cells; i++)
2749 item->box[i].x = item->x + item->width -
2750 (item->box[i].x + item->box[i].width - item->x);
2756 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2758 g_list_foreach (icon_view->priv->items,
2759 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2763 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2770 gtk_icon_view_paint_item (GtkIconView *icon_view,
2772 GtkIconViewItem *item,
2774 GdkDrawable *drawable,
2777 gboolean draw_focus)
2779 gint focus_width, focus_pad;
2780 gint spacing, padding;
2781 GdkRectangle cell_area, box;
2786 GtkCellRendererState flags;
2788 if (icon_view->priv->model == NULL)
2791 gtk_icon_view_set_cell_data (icon_view, item);
2793 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2795 gtk_widget_style_get (GTK_WIDGET (icon_view),
2796 "focus-line-width", &focus_width,
2797 "focus-padding", &focus_pad,
2800 spacing = icon_view->priv->spacing;
2801 padding = focus_width;
2805 flags = GTK_CELL_RENDERER_SELECTED;
2806 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2807 state = GTK_STATE_SELECTED;
2809 state = GTK_STATE_ACTIVE;
2814 state = GTK_STATE_NORMAL;
2817 #ifdef DEBUG_ICON_VIEW
2818 gdk_draw_rectangle (drawable,
2819 GTK_WIDGET (icon_view)->style->black_gc,
2822 item->width, item->height);
2826 for (l = icon_view->priv->cell_list; l; l = l->next)
2828 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2830 if (!info->cell->visible)
2833 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2835 /* FIXME we hardwire background drawing behind text
2836 * cell renderers here
2838 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2840 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2841 cairo_rectangle (cr,
2842 x - item->x + box.x,
2843 y - item->y + box.y,
2844 box.width, box.height);
2849 for (l = icon_view->priv->cell_list; l; l = l->next)
2851 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2853 if (!info->cell->visible)
2856 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2858 #ifdef DEBUG_ICON_VIEW
2859 gdk_draw_rectangle (drawable,
2860 GTK_WIDGET (icon_view)->style->black_gc,
2862 x - item->x + cell_area.x,
2863 y - item->y + cell_area.y,
2864 cell_area.width, cell_area.height);
2866 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2868 gdk_draw_rectangle (drawable,
2869 GTK_WIDGET (icon_view)->style->black_gc,
2871 x - item->x + box.x,
2872 y - item->y + box.y,
2873 box.width, box.height);
2876 cell_area.x = x - item->x + cell_area.x;
2877 cell_area.y = y - item->y + cell_area.y;
2879 gtk_cell_renderer_render (info->cell,
2881 GTK_WIDGET (icon_view),
2882 &cell_area, &cell_area, area, flags);
2886 /* FIXME where to draw the focus with generic cell renderers ? */
2888 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2889 item == icon_view->priv->cursor_item)
2890 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2892 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2894 if (!info->cell->visible)
2897 if (icon_view->priv->cursor_cell < 0 &&
2898 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2899 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2900 icon_view->priv->cursor_cell = i;
2902 if (i == icon_view->priv->cursor_cell)
2904 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2906 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2910 GTK_WIDGET (icon_view),
2912 x - item->x + box.x - padding,
2913 y - item->y + box.y - padding,
2914 box.width + 2 * padding,
2915 box.height + 2 * padding);
2922 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2927 GdkRectangle rubber_rect;
2928 GdkColor *fill_color_gdk;
2929 guchar fill_color_alpha;
2931 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2932 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2933 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2934 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2936 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2939 gtk_widget_style_get (GTK_WIDGET (icon_view),
2940 "selection-box-color", &fill_color_gdk,
2941 "selection-box-alpha", &fill_color_alpha,
2944 if (!fill_color_gdk)
2945 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2947 cairo_set_source_rgba (cr,
2948 fill_color_gdk->red / 65535.,
2949 fill_color_gdk->green / 65535.,
2950 fill_color_gdk->blue / 65535.,
2951 fill_color_alpha / 255.);
2954 gdk_cairo_rectangle (cr, &rect);
2958 /* Draw the border without alpha */
2959 cairo_set_source_rgb (cr,
2960 fill_color_gdk->red / 65535.,
2961 fill_color_gdk->green / 65535.,
2962 fill_color_gdk->blue / 65535.);
2963 cairo_rectangle (cr,
2964 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2965 rubber_rect.width - 1, rubber_rect.height - 1);
2969 gdk_color_free (fill_color_gdk);
2973 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2979 index = gtk_tree_path_get_indices (path)[0];
2981 for (l = icon_view->priv->items; l; l = l->next)
2983 GtkIconViewItem *item = l->data;
2985 if (item->index == index)
2987 gtk_icon_view_queue_draw_item (icon_view, item);
2994 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2995 GtkIconViewItem *item)
3000 gtk_widget_style_get (GTK_WIDGET (icon_view),
3001 "focus-line-width", &focus_width,
3004 rect.x = item->x - focus_width;
3005 rect.y = item->y - focus_width;
3006 rect.width = item->width + 2 * focus_width;
3007 rect.height = item->height + 2 * focus_width;
3009 if (icon_view->priv->bin_window)
3010 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3014 layout_callback (gpointer user_data)
3016 GtkIconView *icon_view;
3018 GDK_THREADS_ENTER ();
3020 icon_view = GTK_ICON_VIEW (user_data);
3022 icon_view->priv->layout_idle_id = 0;
3024 gtk_icon_view_layout (icon_view);
3026 GDK_THREADS_LEAVE();
3032 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3034 if (icon_view->priv->layout_idle_id != 0)
3037 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3041 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3042 GtkIconViewItem *item,
3046 AtkObject *item_obj;
3048 if (icon_view->priv->cursor_item == item &&
3049 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3052 if (icon_view->priv->cursor_item != NULL)
3053 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3055 icon_view->priv->cursor_item = item;
3056 if (cursor_cell >= 0)
3057 icon_view->priv->cursor_cell = cursor_cell;
3059 gtk_icon_view_queue_draw_item (icon_view, item);
3061 /* Notify that accessible focus object has changed */
3062 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3063 item_obj = atk_object_ref_accessible_child (obj, item->index);
3065 if (item_obj != NULL)
3067 atk_focus_tracker_notify (item_obj);
3068 g_object_unref (item_obj);
3073 static GtkIconViewItem *
3074 gtk_icon_view_item_new (void)
3076 GtkIconViewItem *item;
3078 item = g_new0 (GtkIconViewItem, 1);
3087 gtk_icon_view_item_free (GtkIconViewItem *item)
3089 g_return_if_fail (item != NULL);
3091 g_free (item->before);
3092 g_free (item->after);
3099 static GtkIconViewItem *
3100 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3103 gboolean only_in_cell,
3104 GtkIconViewCellInfo **cell_at_pos)
3109 for (items = icon_view->priv->items; items; items = items->next)
3111 GtkIconViewItem *item = items->data;
3113 if (x >= item->x - icon_view->priv->row_spacing/2 && x <= item->x + item->width + icon_view->priv->row_spacing/2 &&
3114 y >= item->y - icon_view->priv->column_spacing/2 && y <= item->y + item->height + icon_view->priv->column_spacing/2)
3116 if (only_in_cell || cell_at_pos)
3118 gtk_icon_view_set_cell_data (icon_view, item);
3120 for (l = icon_view->priv->cell_list; l; l = l->next)
3122 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3124 if (!info->cell->visible)
3127 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3129 if ((x >= box.x && x <= box.x + box.width &&
3130 y >= box.y && y <= box.y + box.height) ||
3132 x <= box.x + box.width &&
3134 y <= box.y + box.height))
3137 *cell_at_pos = info;
3147 *cell_at_pos = NULL;
3158 gtk_icon_view_select_item (GtkIconView *icon_view,
3159 GtkIconViewItem *item)
3161 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3162 g_return_if_fail (item != NULL);
3167 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3169 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3170 gtk_icon_view_unselect_all_internal (icon_view);
3172 item->selected = TRUE;
3174 gtk_icon_view_queue_draw_item (icon_view, item);
3176 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3181 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3182 GtkIconViewItem *item)
3184 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3185 g_return_if_fail (item != NULL);
3187 if (!item->selected)
3190 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3191 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3194 item->selected = FALSE;
3196 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3198 gtk_icon_view_queue_draw_item (icon_view, item);
3202 verify_items (GtkIconView *icon_view)
3207 for (items = icon_view->priv->items; items; items = items->next)
3209 GtkIconViewItem *item = items->data;
3211 if (item->index != i)
3212 g_error ("List item does not match its index: "
3213 "item index %d and list index %d\n", item->index, i);
3220 gtk_icon_view_row_changed (GtkTreeModel *model,
3225 GtkIconViewItem *item;
3227 GtkIconView *icon_view;
3229 icon_view = GTK_ICON_VIEW (data);
3231 gtk_icon_view_stop_editing (icon_view, TRUE);
3233 index = gtk_tree_path_get_indices(path)[0];
3234 item = g_list_nth_data (icon_view->priv->items, index);
3236 gtk_icon_view_item_invalidate_size (item);
3237 gtk_icon_view_queue_layout (icon_view);
3239 verify_items (icon_view);
3243 gtk_icon_view_row_inserted (GtkTreeModel *model,
3249 GtkIconViewItem *item;
3250 gboolean iters_persist;
3251 GtkIconView *icon_view;
3254 icon_view = GTK_ICON_VIEW (data);
3256 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3258 length = gtk_tree_model_iter_n_children (model, NULL);
3259 index = gtk_tree_path_get_indices(path)[0];
3261 item = gtk_icon_view_item_new ();
3266 item->index = index;
3268 /* FIXME: We can be more efficient here,
3269 we can store a tail pointer and use that when
3270 appending (which is a rather common operation)
3272 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3275 list = g_list_nth (icon_view->priv->items, index + 1);
3276 for (; list; list = list->next)
3283 verify_items (icon_view);
3287 gtk_icon_view_row_deleted (GtkTreeModel *model,
3292 GtkIconView *icon_view;
3293 GtkIconViewItem *item;
3295 gboolean emit = FALSE;
3297 icon_view = GTK_ICON_VIEW (data);
3299 index = gtk_tree_path_get_indices(path)[0];
3301 list = g_list_nth (icon_view->priv->items, index);
3304 gtk_icon_view_stop_editing (icon_view, TRUE);
3306 if (item == icon_view->priv->anchor_item)
3307 icon_view->priv->anchor_item = NULL;
3309 if (item == icon_view->priv->cursor_item)
3310 icon_view->priv->cursor_item = NULL;
3315 gtk_icon_view_item_free (item);
3317 for (next = list->next; next; next = next->next)
3324 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3326 gtk_icon_view_queue_layout (icon_view);
3328 verify_items (icon_view);
3331 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3335 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3336 GtkTreePath *parent,
3343 GtkIconView *icon_view;
3344 GList *items = NULL, *list;
3345 GtkIconViewItem **item_array;
3348 icon_view = GTK_ICON_VIEW (data);
3350 gtk_icon_view_stop_editing (icon_view, TRUE);
3352 length = gtk_tree_model_iter_n_children (model, NULL);
3354 order = g_new (gint, length);
3355 for (i = 0; i < length; i++)
3356 order [new_order[i]] = i;
3358 item_array = g_new (GtkIconViewItem *, length);
3359 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3360 item_array[order[i]] = list->data;
3363 for (i = length - 1; i >= 0; i--)
3365 item_array[i]->index = i;
3366 items = g_list_prepend (items, item_array[i]);
3369 g_free (item_array);
3370 g_list_free (icon_view->priv->items);
3371 icon_view->priv->items = items;
3373 gtk_icon_view_queue_layout (icon_view);
3375 verify_items (icon_view);
3379 gtk_icon_view_build_items (GtkIconView *icon_view)
3383 gboolean iters_persist;
3384 GList *items = NULL;
3386 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3388 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3396 GtkIconViewItem *item = gtk_icon_view_item_new ();
3405 items = g_list_prepend (items, item);
3407 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3409 icon_view->priv->items = g_list_reverse (items);
3413 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3416 GtkMovementStep step,
3420 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3421 I_("move_cursor"), 2,
3425 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3430 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3433 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3438 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3445 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3446 GtkMovementStep step,
3449 GdkModifierType state;
3451 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3452 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3453 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3454 step == GTK_MOVEMENT_DISPLAY_LINES ||
3455 step == GTK_MOVEMENT_PAGES ||
3456 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3458 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3461 gtk_icon_view_stop_editing (icon_view, FALSE);
3462 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3464 if (gtk_get_current_event_state (&state))
3466 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3467 icon_view->priv->ctrl_pressed = TRUE;
3468 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3469 icon_view->priv->shift_pressed = TRUE;
3471 /* else we assume not pressed */
3475 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3476 case GTK_MOVEMENT_VISUAL_POSITIONS:
3477 gtk_icon_view_move_cursor_left_right (icon_view, count);
3479 case GTK_MOVEMENT_DISPLAY_LINES:
3480 gtk_icon_view_move_cursor_up_down (icon_view, count);
3482 case GTK_MOVEMENT_PAGES:
3483 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3485 case GTK_MOVEMENT_BUFFER_ENDS:
3486 gtk_icon_view_move_cursor_start_end (icon_view, count);
3489 g_assert_not_reached ();
3492 icon_view->priv->ctrl_pressed = FALSE;
3493 icon_view->priv->shift_pressed = FALSE;
3498 static GtkIconViewItem *
3499 find_item (GtkIconView *icon_view,
3500 GtkIconViewItem *current,
3506 GtkIconViewItem *item;
3508 /* FIXME: this could be more efficient
3510 row = current->row + row_ofs;
3511 col = current->col + col_ofs;
3513 for (items = icon_view->priv->items; items; items = items->next)
3516 if (item->row == row && item->col == col)
3524 find_cell (GtkIconView *icon_view,
3525 GtkIconViewItem *item,
3527 GtkOrientation orientation,
3538 if (icon_view->priv->orientation != orientation)
3541 gtk_icon_view_set_cell_data (icon_view, item);
3543 focusable = g_new0 (gint, icon_view->priv->n_cells);
3548 for (k = 0; k < 2; k++)
3549 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3551 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3553 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3556 if (!info->cell->visible)
3559 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3562 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3565 current = n_focusable;
3567 focusable[n_focusable] = i;
3573 if (n_focusable == 0)
3574 focusable[n_focusable++] = first_text;
3578 current = step > 0 ? 0 : n_focusable - 1;
3579 cell = focusable[current];
3582 if (current + *count < 0)
3585 *count = current + *count;
3587 else if (current + *count > n_focusable - 1)
3590 *count = current + *count - (n_focusable - 1);
3594 cell = focusable[current + *count];
3603 static GtkIconViewItem *
3604 find_item_page_up_down (GtkIconView *icon_view,
3605 GtkIconViewItem *current,
3612 y = current->y + count * icon_view->priv->vadjustment->page_size;
3614 item = g_list_find (icon_view->priv->items, current);
3619 for (next = item->next; next; next = next->next)
3621 if (((GtkIconViewItem *)next->data)->col == col)
3624 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3634 for (next = item->prev; next; next = next->prev)
3636 if (((GtkIconViewItem *)next->data)->col == col)
3639 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3653 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3654 GtkIconViewItem *anchor,
3655 GtkIconViewItem *cursor)
3658 GtkIconViewItem *item;
3659 gint row1, row2, col1, col2;
3660 gboolean dirty = FALSE;
3662 if (anchor->row < cursor->row)
3673 if (anchor->col < cursor->col)
3684 for (items = icon_view->priv->items; items; items = items->next)
3688 if (row1 <= item->row && item->row <= row2 &&
3689 col1 <= item->col && item->col <= col2)
3691 if (!item->selected)
3694 item->selected = TRUE;
3696 gtk_icon_view_queue_draw_item (icon_view, item);
3704 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3707 GtkIconViewItem *item;
3709 gboolean dirty = FALSE;
3712 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3715 if (!icon_view->priv->cursor_item)
3720 list = icon_view->priv->items;
3722 list = g_list_last (icon_view->priv->items);
3724 item = list ? list->data : NULL;
3729 item = icon_view->priv->cursor_item;
3730 cell = icon_view->priv->cursor_cell;
3731 step = count > 0 ? 1 : -1;
3734 cell = find_cell (icon_view, item, cell,
3735 GTK_ORIENTATION_VERTICAL,
3740 item = find_item (icon_view, item, step, 0);
3741 count = count - step;
3748 if (icon_view->priv->ctrl_pressed ||
3749 !icon_view->priv->shift_pressed ||
3750 !icon_view->priv->anchor_item ||
3751 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3752 icon_view->priv->anchor_item = item;
3754 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3756 if (!icon_view->priv->ctrl_pressed &&
3757 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3759 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3760 dirty = gtk_icon_view_select_all_between (icon_view,
3761 icon_view->priv->anchor_item,
3765 gtk_icon_view_scroll_to_item (icon_view, item);
3768 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3772 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3775 GtkIconViewItem *item;
3776 gboolean dirty = FALSE;
3778 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3781 if (!icon_view->priv->cursor_item)
3786 list = icon_view->priv->items;
3788 list = g_list_last (icon_view->priv->items);
3790 item = list ? list->data : NULL;
3793 item = find_item_page_up_down (icon_view,
3794 icon_view->priv->cursor_item,
3800 if (icon_view->priv->ctrl_pressed ||
3801 !icon_view->priv->shift_pressed ||
3802 !icon_view->priv->anchor_item ||
3803 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3804 icon_view->priv->anchor_item = item;
3806 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3808 if (!icon_view->priv->ctrl_pressed &&
3809 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3811 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3812 dirty = gtk_icon_view_select_all_between (icon_view,
3813 icon_view->priv->anchor_item,
3817 gtk_icon_view_scroll_to_item (icon_view, item);
3820 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3824 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3827 GtkIconViewItem *item;
3829 gboolean dirty = FALSE;
3832 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3835 if (!icon_view->priv->cursor_item)
3840 list = icon_view->priv->items;
3842 list = g_list_last (icon_view->priv->items);
3844 item = list ? list->data : NULL;
3848 item = icon_view->priv->cursor_item;
3849 cell = icon_view->priv->cursor_cell;
3850 step = count > 0 ? 1 : -1;
3853 cell = find_cell (icon_view, item, cell,
3854 GTK_ORIENTATION_HORIZONTAL,
3859 item = find_item (icon_view, item, 0, step);
3860 count = count - step;
3867 if (icon_view->priv->ctrl_pressed ||
3868 !icon_view->priv->shift_pressed ||
3869 !icon_view->priv->anchor_item ||
3870 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3871 icon_view->priv->anchor_item = item;
3873 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3875 if (!icon_view->priv->ctrl_pressed &&
3876 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3878 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3879 dirty = gtk_icon_view_select_all_between (icon_view,
3880 icon_view->priv->anchor_item,
3884 gtk_icon_view_scroll_to_item (icon_view, item);
3887 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3891 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3894 GtkIconViewItem *item;
3896 gboolean dirty = FALSE;
3898 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3902 list = icon_view->priv->items;
3904 list = g_list_last (icon_view->priv->items);
3906 item = list ? list->data : NULL;
3911 if (icon_view->priv->ctrl_pressed ||
3912 !icon_view->priv->shift_pressed ||
3913 !icon_view->priv->anchor_item ||
3914 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3915 icon_view->priv->anchor_item = item;
3917 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3919 if (!icon_view->priv->ctrl_pressed &&
3920 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3922 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3923 dirty = gtk_icon_view_select_all_between (icon_view,
3924 icon_view->priv->anchor_item,
3928 gtk_icon_view_scroll_to_item (icon_view, item);
3931 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3935 * gtk_icon_view_scroll_to_path:
3936 * @icon_view: A #GtkIconView.
3937 * @path: The path of the item to move to.
3938 * @use_align: whether to use alignment arguments, or %FALSE.
3939 * @row_align: The vertical alignment of the item specified by @path.
3940 * @col_align: The horizontal alignment of the item specified by @column.
3942 * Moves the alignments of @icon_view to the position specified by @path.
3943 * @row_align determines where the row is placed, and @col_align determines where
3944 * @column is placed. Both are expected to be between 0.0 and 1.0.
3945 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
3947 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3948 * tree does the minimum amount of work to scroll the item onto the screen.
3949 * This means that the item will be scrolled to the edge closest to its current
3950 * position. If the item is currently visible on the screen, nothing is done.
3952 * This function only works if the model is set, and @path is a valid row on the
3953 * model. If the model changes before the @icon_view is realized, the centered
3954 * path will be modified to reflect this change.
3959 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3965 GtkIconViewItem *item = NULL;
3967 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3968 g_return_if_fail (path != NULL);
3969 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3970 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3972 if (! GTK_WIDGET_REALIZED (icon_view))
3974 if (icon_view->priv->scroll_to_path)
3975 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3977 icon_view->priv->scroll_to_path = NULL;
3980 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3982 icon_view->priv->scroll_to_use_align = use_align;
3983 icon_view->priv->scroll_to_row_align = row_align;
3984 icon_view->priv->scroll_to_col_align = col_align;
3989 if (gtk_tree_path_get_depth (path) > 0)
3990 item = g_list_nth_data (icon_view->priv->items,
3991 gtk_tree_path_get_indices(path)[0]);
3998 gint x, y, width, height;
4000 gfloat offset, value;
4002 gtk_widget_style_get (GTK_WIDGET (icon_view),
4003 "focus-line-width", &focus_width,
4006 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4008 offset = y + item->y - focus_width -
4009 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4010 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4011 icon_view->priv->vadjustment->lower,
4012 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4013 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4015 offset = x + item->x - focus_width -
4016 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4017 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4018 icon_view->priv->hadjustment->lower,
4019 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4020 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4022 gtk_adjustment_changed (icon_view->priv->hadjustment);
4023 gtk_adjustment_changed (icon_view->priv->vadjustment);
4026 gtk_icon_view_scroll_to_item (icon_view, item);
4031 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4032 GtkIconViewItem *item)
4034 gint x, y, width, height;
4037 gtk_widget_style_get (GTK_WIDGET (icon_view),
4038 "focus-line-width", &focus_width,
4041 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4043 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4045 if (y + item->y - focus_width < 0)
4046 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4047 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4048 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4049 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4050 icon_view->priv->vadjustment->value + y + item->y + item->height
4051 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4053 if (x + item->x - focus_width < 0)
4054 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4055 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4056 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4057 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4058 icon_view->priv->hadjustment->value + x + item->x + item->width
4059 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4061 gtk_adjustment_changed (icon_view->priv->hadjustment);
4062 gtk_adjustment_changed (icon_view->priv->vadjustment);
4065 /* GtkCellLayout implementation */
4066 static GtkIconViewCellInfo *
4067 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4068 GtkCellRenderer *renderer)
4072 for (i = icon_view->priv->cell_list; i; i = i->next)
4074 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4076 if (info->cell == renderer)
4084 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4085 GtkIconViewItem *item)
4088 gboolean iters_persist;
4091 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4097 path = gtk_tree_path_new_from_indices (item->index, -1);
4098 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4099 gtk_tree_path_free (path);
4104 for (i = icon_view->priv->cell_list; i; i = i->next)
4107 GtkIconViewCellInfo *info = i->data;
4109 g_object_freeze_notify (G_OBJECT (info->cell));
4111 for (j = info->attributes; j && j->next; j = j->next->next)
4113 gchar *property = j->data;
4114 gint column = GPOINTER_TO_INT (j->next->data);
4115 GValue value = {0, };
4117 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4119 g_object_set_property (G_OBJECT (info->cell),
4121 g_value_unset (&value);
4125 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4127 icon_view->priv->model,
4131 g_object_thaw_notify (G_OBJECT (info->cell));
4134 adjust_wrap_width (icon_view, item);
4138 free_cell_attributes (GtkIconViewCellInfo *info)
4142 list = info->attributes;
4143 while (list && list->next)
4145 g_free (list->data);
4146 list = list->next->next;
4149 g_slist_free (info->attributes);
4150 info->attributes = NULL;
4154 free_cell_info (GtkIconViewCellInfo *info)
4156 free_cell_attributes (info);
4158 g_object_unref (info->cell);
4161 (* info->destroy) (info->func_data);
4167 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4168 GtkCellRenderer *renderer,
4171 GtkIconViewCellInfo *info;
4172 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4174 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4175 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4177 g_object_ref (renderer);
4178 gtk_object_sink (GTK_OBJECT (renderer));
4180 info = g_new0 (GtkIconViewCellInfo, 1);
4181 info->cell = renderer;
4182 info->expand = expand ? TRUE : FALSE;
4183 info->pack = GTK_PACK_START;
4184 info->position = icon_view->priv->n_cells;
4186 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4187 icon_view->priv->n_cells++;
4191 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4192 GtkCellRenderer *renderer,
4195 GtkIconViewCellInfo *info;
4196 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4198 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4199 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4201 g_object_ref (renderer);
4202 gtk_object_sink (GTK_OBJECT (renderer));
4204 info = g_new0 (GtkIconViewCellInfo, 1);
4205 info->cell = renderer;
4206 info->expand = expand ? TRUE : FALSE;
4207 info->pack = GTK_PACK_END;
4208 info->position = icon_view->priv->n_cells;
4210 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4211 icon_view->priv->n_cells++;
4215 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4216 GtkCellRenderer *renderer,
4217 const gchar *attribute,
4220 GtkIconViewCellInfo *info;
4221 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4223 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4224 g_return_if_fail (info != NULL);
4226 info->attributes = g_slist_prepend (info->attributes,
4227 GINT_TO_POINTER (column));
4228 info->attributes = g_slist_prepend (info->attributes,
4229 g_strdup (attribute));
4233 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4235 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4237 while (icon_view->priv->cell_list)
4239 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4240 free_cell_info (info);
4241 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4242 icon_view->priv->cell_list);
4245 icon_view->priv->n_cells = 0;
4249 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4250 GtkCellRenderer *cell,
4251 GtkCellLayoutDataFunc func,
4253 GDestroyNotify destroy)
4255 GtkIconViewCellInfo *info;
4256 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4258 info = gtk_icon_view_get_cell_info (icon_view, cell);
4259 g_return_if_fail (info != NULL);
4263 GDestroyNotify d = info->destroy;
4265 info->destroy = NULL;
4266 d (info->func_data);
4270 info->func_data = func_data;
4271 info->destroy = destroy;
4275 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4276 GtkCellRenderer *renderer)
4278 GtkIconViewCellInfo *info;
4280 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4282 free_cell_attributes (info);
4286 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4287 GtkCellRenderer *cell,
4290 GtkIconView *icon_view;
4292 GtkIconViewCellInfo *info;
4295 icon_view = GTK_ICON_VIEW (layout);
4297 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4299 info = gtk_icon_view_get_cell_info (icon_view, cell);
4301 g_return_if_fail (info != NULL);
4302 g_return_if_fail (position >= 0);
4304 link = g_list_find (icon_view->priv->cell_list, info);
4306 g_return_if_fail (link != NULL);
4308 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4310 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4313 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4320 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4327 * gtk_icon_view_new:
4329 * Creates a new #GtkIconView widget
4331 * Return value: A newly created #GtkIconView widget
4336 gtk_icon_view_new (void)
4338 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4342 * gtk_icon_view_new_with_model:
4343 * @model: The model.
4345 * Creates a new #GtkIconView widget with the model @model.
4347 * Return value: A newly created #GtkIconView widget.
4352 gtk_icon_view_new_with_model (GtkTreeModel *model)
4354 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4359 * gtk_icon_view_get_path_at_pos:
4360 * @icon_view: A #GtkIconView.
4361 * @x: The x position to be identified
4362 * @y: The y position to be identified
4364 * Finds the path at the point (@x, @y), relative to widget coordinates.
4365 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4366 * the cell at the specified position.
4368 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4369 * if no icon exists at that position.
4374 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4378 GtkIconViewItem *item;
4381 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4383 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4388 path = gtk_tree_path_new_from_indices (item->index, -1);
4394 * gtk_icon_view_get_item_at_pos:
4395 * @icon_view: A #GtkIconView.
4396 * @x: The x position to be identified
4397 * @y: The y position to be identified
4398 * @path: Return location for the path, or %NULL
4399 * @cell: Return location for the renderer responsible for the cell
4400 * at (@x, @y), or %NULL
4402 * Finds the path at the point (@x, @y), relative to widget coordinates.
4403 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4404 * obtains the cell at the specified position. The returned path should
4405 * be freed with gtk_tree_path_free().
4407 * Return value: %TRUE if an item exists at the specified position
4412 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4416 GtkCellRenderer **cell)
4418 GtkIconViewItem *item;
4419 GtkIconViewCellInfo *info;
4421 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4423 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4428 *path = gtk_tree_path_new_from_indices (item->index, -1);
4441 return (item != NULL);
4446 * gtk_icon_view_get_visible_range:
4447 * @icon_view: A #GtkIconView
4448 * @start_path: Return location for start of region, or %NULL
4449 * @end_path: Return location for end of region, or %NULL
4451 * Sets @start_path and @end_path to be the first and last visible path.
4452 * Note that there may be invisible paths in between.
4454 * Both paths should be freed with gtk_tree_path_free() after use.
4456 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4461 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4462 GtkTreePath **start_path,
4463 GtkTreePath **end_path)
4465 gint start_index = -1;
4466 gint end_index = -1;
4467 GtkIconViewItem *item;
4470 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4472 if (icon_view->priv->hadjustment == NULL ||
4473 icon_view->priv->vadjustment == NULL)
4476 if (start_path == NULL && end_path == NULL)
4479 for (icons = icon_view->priv->items; icons; icons = icons->next)
4481 GtkIconViewItem *item = icons->data;
4483 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4484 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4485 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4486 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4488 if (start_index == -1)
4489 start_index = item->index;
4490 end_index = item->index;
4494 if (start_path && start_index != -1)
4495 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4496 if (end_path && end_index != -1)
4497 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4499 return start_index != -1;
4503 * gtk_icon_view_selected_foreach:
4504 * @icon_view: A #GtkIconView.
4505 * @func: The funcion to call for each selected icon.
4506 * @data: User data to pass to the function.
4508 * Calls a function for each selected icon. Note that the model or
4509 * selection cannot be modified from within this function.
4514 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4515 GtkIconViewForeachFunc func,
4520 for (list = icon_view->priv->items; list; list = list->next)
4522 GtkIconViewItem *item = list->data;
4523 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4526 (* func) (icon_view, path, data);
4528 gtk_tree_path_free (path);
4533 * gtk_icon_view_set_selection_mode:
4534 * @icon_view: A #GtkIconView.
4535 * @mode: The selection mode
4537 * Sets the selection mode of the @icon_view.
4542 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4543 GtkSelectionMode mode)
4545 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4547 if (mode == icon_view->priv->selection_mode)
4550 if (mode == GTK_SELECTION_NONE ||
4551 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4552 gtk_icon_view_unselect_all (icon_view);
4554 icon_view->priv->selection_mode = mode;
4556 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4560 * gtk_icon_view_get_selection_mode:
4561 * @icon_view: A #GtkIconView.
4563 * Gets the selection mode of the @icon_view.
4565 * Return value: the current selection mode
4570 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4572 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4574 return icon_view->priv->selection_mode;
4578 * gtk_icon_view_set_model:
4579 * @icon_view: A #GtkIconView.
4580 * @model: The model.
4582 * Sets the model for a #GtkIconView.
4583 * If the @icon_view already has a model set, it will remove
4584 * it before setting the new model. If @model is %NULL, then
4585 * it will unset the old model.
4590 gtk_icon_view_set_model (GtkIconView *icon_view,
4591 GtkTreeModel *model)
4593 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4594 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4596 if (icon_view->priv->model == model)
4599 if (icon_view->priv->scroll_to_path)
4601 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4602 icon_view->priv->scroll_to_path = NULL;
4605 gtk_icon_view_stop_editing (icon_view, TRUE);
4611 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4613 if (icon_view->priv->pixbuf_column != -1)
4615 column_type = gtk_tree_model_get_column_type (model,
4616 icon_view->priv->pixbuf_column);
4618 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4621 if (icon_view->priv->text_column != -1)
4623 column_type = gtk_tree_model_get_column_type (model,
4624 icon_view->priv->text_column);
4626 g_return_if_fail (column_type == G_TYPE_STRING);
4629 if (icon_view->priv->markup_column != -1)
4631 column_type = gtk_tree_model_get_column_type (model,
4632 icon_view->priv->markup_column);
4634 g_return_if_fail (column_type == G_TYPE_STRING);
4639 if (icon_view->priv->model)
4641 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4642 gtk_icon_view_row_changed,
4644 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4645 gtk_icon_view_row_inserted,
4647 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4648 gtk_icon_view_row_deleted,
4650 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4651 gtk_icon_view_rows_reordered,
4654 g_object_unref (icon_view->priv->model);
4656 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4657 g_list_free (icon_view->priv->items);
4658 icon_view->priv->items = NULL;
4659 icon_view->priv->anchor_item = NULL;
4660 icon_view->priv->cursor_item = NULL;
4661 icon_view->priv->last_single_clicked = NULL;
4662 icon_view->priv->width = 0;
4663 icon_view->priv->height = 0;
4666 icon_view->priv->model = model;
4668 if (icon_view->priv->model)
4670 g_object_ref (icon_view->priv->model);
4671 g_signal_connect (icon_view->priv->model,
4673 G_CALLBACK (gtk_icon_view_row_changed),
4675 g_signal_connect (icon_view->priv->model,
4677 G_CALLBACK (gtk_icon_view_row_inserted),
4679 g_signal_connect (icon_view->priv->model,
4681 G_CALLBACK (gtk_icon_view_row_deleted),
4683 g_signal_connect (icon_view->priv->model,
4685 G_CALLBACK (gtk_icon_view_rows_reordered),
4688 gtk_icon_view_build_items (icon_view);
4690 gtk_icon_view_queue_layout (icon_view);
4693 g_object_notify (G_OBJECT (icon_view), "model");
4695 if (GTK_WIDGET_REALIZED (icon_view))
4696 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4700 * gtk_icon_view_get_model:
4701 * @icon_view: a #GtkIconView
4703 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4706 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4711 gtk_icon_view_get_model (GtkIconView *icon_view)
4713 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4715 return icon_view->priv->model;
4719 update_text_cell (GtkIconView *icon_view)
4721 GtkIconViewCellInfo *info;
4725 if (icon_view->priv->text_column == -1 &&
4726 icon_view->priv->markup_column == -1)
4728 if (icon_view->priv->text_cell != -1)
4730 info = g_list_nth_data (icon_view->priv->cell_list,
4731 icon_view->priv->text_cell);
4733 g_list_remove (icon_view->priv->cell_list, info);
4735 free_cell_info (info);
4737 icon_view->priv->n_cells--;
4738 icon_view->priv->text_cell = -1;
4743 if (icon_view->priv->text_cell == -1)
4745 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4746 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4747 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4750 if (info->cell == cell)
4752 icon_view->priv->text_cell = i;
4758 info = g_list_nth_data (icon_view->priv->cell_list,
4759 icon_view->priv->text_cell);
4761 if (icon_view->priv->markup_column != -1)
4762 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4764 "markup", icon_view->priv->markup_column,
4767 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4769 "text", icon_view->priv->text_column,
4772 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4773 g_object_set (info->cell,
4774 "wrap_mode", PANGO_WRAP_CHAR,
4775 "wrap_width", icon_view->priv->item_width,
4780 g_object_set (info->cell,
4781 "wrap_mode", PANGO_WRAP_CHAR,
4782 "wrap_width", icon_view->priv->item_width,
4790 update_pixbuf_cell (GtkIconView *icon_view)
4792 GtkIconViewCellInfo *info;
4796 if (icon_view->priv->pixbuf_column == -1)
4798 if (icon_view->priv->pixbuf_cell != -1)
4800 info = g_list_nth_data (icon_view->priv->cell_list,
4801 icon_view->priv->pixbuf_cell);
4803 g_list_remove (icon_view->priv->cell_list, info);
4805 free_cell_info (info);
4807 icon_view->priv->n_cells--;
4808 icon_view->priv->pixbuf_cell = -1;
4813 if (icon_view->priv->pixbuf_cell == -1)
4815 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4817 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4818 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4821 if (info->cell == cell)
4823 icon_view->priv->pixbuf_cell = i;
4829 info = g_list_nth_data (icon_view->priv->cell_list,
4830 icon_view->priv->pixbuf_cell);
4832 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4834 "pixbuf", icon_view->priv->pixbuf_column,
4837 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4838 g_object_set (info->cell,
4839 "follow_state", TRUE,
4844 g_object_set (info->cell,
4845 "follow_state", TRUE,
4853 * gtk_icon_view_set_text_column:
4854 * @icon_view: A #GtkIconView.
4855 * @column: A column in the currently used model.
4857 * Sets the column with text for @icon_view to be @column. The text
4858 * column must be of type #G_TYPE_STRING.
4863 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4866 if (column == icon_view->priv->text_column)
4870 icon_view->priv->text_column = -1;
4873 if (icon_view->priv->model != NULL)
4877 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4879 g_return_if_fail (column_type == G_TYPE_STRING);
4882 icon_view->priv->text_column = column;
4885 gtk_icon_view_stop_editing (icon_view, TRUE);
4887 update_text_cell (icon_view);
4889 gtk_icon_view_invalidate_sizes (icon_view);
4890 gtk_icon_view_queue_layout (icon_view);
4892 g_object_notify (G_OBJECT (icon_view), "text-column");
4896 * gtk_icon_view_get_text_column:
4897 * @icon_view: A #GtkIconView.
4899 * Returns the column with text for @icon_view.
4901 * Returns: the text column, or -1 if it's unset.
4906 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4908 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4910 return icon_view->priv->text_column;
4914 * gtk_icon_view_set_markup_column:
4915 * @icon_view: A #GtkIconView.
4916 * @column: A column in the currently used model.
4918 * Sets the column with markup information for @icon_view to be
4919 * @column. The markup column must be of type #G_TYPE_STRING.
4920 * If the markup column is set to something, it overrides
4921 * the text column set by gtk_icon_view_set_text_column().
4926 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4929 if (column == icon_view->priv->markup_column)
4933 icon_view->priv->markup_column = -1;
4936 if (icon_view->priv->model != NULL)
4940 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4942 g_return_if_fail (column_type == G_TYPE_STRING);
4945 icon_view->priv->markup_column = column;
4948 gtk_icon_view_stop_editing (icon_view, TRUE);
4950 update_text_cell (icon_view);
4952 gtk_icon_view_invalidate_sizes (icon_view);
4953 gtk_icon_view_queue_layout (icon_view);
4955 g_object_notify (G_OBJECT (icon_view), "markup-column");
4959 * gtk_icon_view_get_markup_column:
4960 * @icon_view: A #GtkIconView.
4962 * Returns the column with markup text for @icon_view.
4964 * Returns: the markup column, or -1 if it's unset.
4969 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4971 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4973 return icon_view->priv->markup_column;
4977 * gtk_icon_view_set_pixbuf_column:
4978 * @icon_view: A #GtkIconView.
4979 * @column: A column in the currently used model.
4981 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4982 * column must be of type #GDK_TYPE_PIXBUF
4987 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4990 if (column == icon_view->priv->pixbuf_column)
4994 icon_view->priv->pixbuf_column = -1;
4997 if (icon_view->priv->model != NULL)
5001 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5003 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5006 icon_view->priv->pixbuf_column = column;
5009 gtk_icon_view_stop_editing (icon_view, TRUE);
5011 update_pixbuf_cell (icon_view);
5013 gtk_icon_view_invalidate_sizes (icon_view);
5014 gtk_icon_view_queue_layout (icon_view);
5016 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5021 * gtk_icon_view_get_pixbuf_column:
5022 * @icon_view: A #GtkIconView.
5024 * Returns the column with pixbufs for @icon_view.
5026 * Returns: the pixbuf column, or -1 if it's unset.
5031 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5033 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5035 return icon_view->priv->pixbuf_column;
5039 * gtk_icon_view_select_path:
5040 * @icon_view: A #GtkIconView.
5041 * @path: The #GtkTreePath to be selected.
5043 * Selects the row at @path.
5048 gtk_icon_view_select_path (GtkIconView *icon_view,
5051 GtkIconViewItem *item = NULL;
5053 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5054 g_return_if_fail (icon_view->priv->model != NULL);
5055 g_return_if_fail (path != NULL);
5057 if (gtk_tree_path_get_depth (path) > 0)
5058 item = g_list_nth_data (icon_view->priv->items,
5059 gtk_tree_path_get_indices(path)[0]);
5062 gtk_icon_view_select_item (icon_view, item);
5066 * gtk_icon_view_unselect_path:
5067 * @icon_view: A #GtkIconView.
5068 * @path: The #GtkTreePath to be unselected.
5070 * Unselects the row at @path.
5075 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5078 GtkIconViewItem *item;
5080 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5081 g_return_if_fail (icon_view->priv->model != NULL);
5082 g_return_if_fail (path != NULL);
5084 item = g_list_nth (icon_view->priv->items,
5085 gtk_tree_path_get_indices(path)[0])->data;
5090 gtk_icon_view_unselect_item (icon_view, item);
5094 * gtk_icon_view_get_selected_items:
5095 * @icon_view: A #GtkIconView.
5097 * Creates a list of paths of all selected items. Additionally, if you are
5098 * planning on modifying the model after calling this function, you may
5099 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5100 * To do this, you can use gtk_tree_row_reference_new().
5102 * To free the return value, use:
5103 * <informalexample><programlisting>
5104 * g_list_foreach (list, gtk_tree_path_free, NULL);
5105 * g_list_free (list);
5106 * </programlisting></informalexample>
5108 * Return value: A #GList containing a #GtkTreePath for each selected row.
5113 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5116 GList *selected = NULL;
5118 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5120 for (list = icon_view->priv->items; list != NULL; list = list->next)
5122 GtkIconViewItem *item = list->data;
5126 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5128 selected = g_list_prepend (selected, path);
5136 * gtk_icon_view_select_all:
5137 * @icon_view: A #GtkIconView.
5139 * Selects all the icons. @icon_view must has its selection mode set
5140 * to #GTK_SELECTION_MULTIPLE.
5145 gtk_icon_view_select_all (GtkIconView *icon_view)
5148 gboolean dirty = FALSE;
5150 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5152 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5155 for (items = icon_view->priv->items; items; items = items->next)
5157 GtkIconViewItem *item = items->data;
5159 if (!item->selected)
5162 item->selected = TRUE;
5163 gtk_icon_view_queue_draw_item (icon_view, item);
5168 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5172 * gtk_icon_view_unselect_all:
5173 * @icon_view: A #GtkIconView.
5175 * Unselects all the icons.
5180 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5182 gboolean dirty = FALSE;
5184 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5186 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5189 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5192 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5196 * gtk_icon_view_path_is_selected:
5197 * @icon_view: A #GtkIconView.
5198 * @path: A #GtkTreePath to check selection on.
5200 * Returns %TRUE if the icon pointed to by @path is currently
5201 * selected. If @icon does not point to a valid location, %FALSE is returned.
5203 * Return value: %TRUE if @path is selected.
5208 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5211 GtkIconViewItem *item;
5213 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5214 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5215 g_return_val_if_fail (path != NULL, FALSE);
5217 item = g_list_nth (icon_view->priv->items,
5218 gtk_tree_path_get_indices(path)[0])->data;
5223 return item->selected;
5227 * gtk_icon_view_item_activated:
5228 * @icon_view: A #GtkIconView
5229 * @path: The #GtkTreePath to be activated
5231 * Activates the item determined by @path.
5236 gtk_icon_view_item_activated (GtkIconView *icon_view,
5239 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5240 g_return_if_fail (path != NULL);
5242 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5246 * gtk_icon_view_set_orientation:
5247 * @icon_view: a #GtkIconView
5248 * @orientation: the relative position of texts and icons
5250 * Sets the ::orientation property which determines whether the labels
5251 * are drawn beside the icons instead of below.
5256 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5257 GtkOrientation orientation)
5259 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5261 if (icon_view->priv->orientation != orientation)
5263 icon_view->priv->orientation = orientation;
5265 gtk_icon_view_stop_editing (icon_view, TRUE);
5266 gtk_icon_view_invalidate_sizes (icon_view);
5267 gtk_icon_view_queue_layout (icon_view);
5269 update_text_cell (icon_view);
5270 update_pixbuf_cell (icon_view);
5272 g_object_notify (G_OBJECT (icon_view), "orientation");
5277 * gtk_icon_view_get_orientation:
5278 * @icon_view: a #GtkIconView
5280 * Returns the value of the ::orientation property which determines
5281 * whether the labels are drawn beside the icons instead of below.
5283 * Return value: the relative position of texts and icons
5288 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5290 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5291 GTK_ORIENTATION_VERTICAL);
5293 return icon_view->priv->orientation;
5297 * gtk_icon_view_set_columns:
5298 * @icon_view: a #GtkIconView
5299 * @columns: the number of columns
5301 * Sets the ::columns property which determines in how
5302 * many columns the icons are arranged. If @columns is
5303 * -1, the number of columns will be chosen automatically
5304 * to fill the available area.
5309 gtk_icon_view_set_columns (GtkIconView *icon_view,
5312 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5314 if (icon_view->priv->columns != columns)
5316 icon_view->priv->columns = columns;
5318 gtk_icon_view_stop_editing (icon_view, TRUE);
5319 gtk_icon_view_queue_layout (icon_view);
5321 g_object_notify (G_OBJECT (icon_view), "columns");
5326 * gtk_icon_view_get_columns:
5327 * @icon_view: a #GtkIconView
5329 * Returns the value of the ::columns property.
5331 * Return value: the number of columns, or -1
5336 gtk_icon_view_get_columns (GtkIconView *icon_view)
5338 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5340 return icon_view->priv->columns;
5344 * gtk_icon_view_set_item_width:
5345 * @icon_view: a #GtkIconView
5346 * @item_width: the width for each item
5348 * Sets the ::item-width property which specifies the width
5349 * to use for each item. If it is set to -1, the icon view will
5350 * automatically determine a suitable item size.
5355 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5358 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5360 if (icon_view->priv->item_width != item_width)
5362 icon_view->priv->item_width = item_width;
5364 gtk_icon_view_stop_editing (icon_view, TRUE);
5365 gtk_icon_view_invalidate_sizes (icon_view);
5366 gtk_icon_view_queue_layout (icon_view);
5368 update_text_cell (icon_view);
5370 g_object_notify (G_OBJECT (icon_view), "item-width");
5375 * gtk_icon_view_get_item_width:
5376 * @icon_view: a #GtkIconView
5378 * Returns the value of the ::item-width property.
5380 * Return value: the width of a single item, or -1
5385 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5387 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5389 return icon_view->priv->item_width;
5394 * gtk_icon_view_set_spacing:
5395 * @icon_view: a #GtkIconView
5396 * @spacing: the spacing
5398 * Sets the ::spacing property which specifies the space
5399 * which is inserted between the cells (i.e. the icon and
5400 * the text) of an item.
5405 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5408 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5410 if (icon_view->priv->spacing != spacing)
5412 icon_view->priv->spacing = spacing;
5414 gtk_icon_view_stop_editing (icon_view, TRUE);
5415 gtk_icon_view_invalidate_sizes (icon_view);
5416 gtk_icon_view_queue_layout (icon_view);
5418 g_object_notify (G_OBJECT (icon_view), "spacing");
5423 * gtk_icon_view_get_spacing:
5424 * @icon_view: a #GtkIconView
5426 * Returns the value of the ::spacing property.
5428 * Return value: the space between cells
5433 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5435 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5437 return icon_view->priv->spacing;
5441 * gtk_icon_view_set_row_spacing:
5442 * @icon_view: a #GtkIconView
5443 * @row_spacing: the row spacing
5445 * Sets the ::row-spacing property which specifies the space
5446 * which is inserted between the rows of the icon view.
5451 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5454 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5456 if (icon_view->priv->row_spacing != row_spacing)
5458 icon_view->priv->row_spacing = row_spacing;
5460 gtk_icon_view_stop_editing (icon_view, TRUE);
5461 gtk_icon_view_invalidate_sizes (icon_view);
5462 gtk_icon_view_queue_layout (icon_view);
5464 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5469 * gtk_icon_view_get_row_spacing:
5470 * @icon_view: a #GtkIconView
5472 * Returns the value of the ::row-spacing property.
5474 * Return value: the space between rows
5479 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5481 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5483 return icon_view->priv->row_spacing;
5487 * gtk_icon_view_set_column_spacing:
5488 * @icon_view: a #GtkIconView
5489 * @column_spacing: the column spacing
5491 * Sets the ::column-spacing property which specifies the space
5492 * which is inserted between the columns of the icon view.
5497 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5498 gint column_spacing)
5500 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5502 if (icon_view->priv->column_spacing != column_spacing)
5504 icon_view->priv->column_spacing = column_spacing;
5506 gtk_icon_view_stop_editing (icon_view, TRUE);
5507 gtk_icon_view_invalidate_sizes (icon_view);
5508 gtk_icon_view_queue_layout (icon_view);
5510 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5515 * gtk_icon_view_get_column_spacing:
5516 * @icon_view: a #GtkIconView
5518 * Returns the value of the ::column-spacing property.
5520 * Return value: the space between columns
5525 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5527 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5529 return icon_view->priv->column_spacing;
5533 * gtk_icon_view_set_margin:
5534 * @icon_view: a #GtkIconView
5535 * @margin: the margin
5537 * Sets the ::margin property which specifies the space
5538 * which is inserted at the top, bottom, left and right
5544 gtk_icon_view_set_margin (GtkIconView *icon_view,
5547 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5549 if (icon_view->priv->margin != margin)
5551 icon_view->priv->margin = margin;
5553 gtk_icon_view_stop_editing (icon_view, TRUE);
5554 gtk_icon_view_invalidate_sizes (icon_view);
5555 gtk_icon_view_queue_layout (icon_view);
5557 g_object_notify (G_OBJECT (icon_view), "margin");
5562 * gtk_icon_view_get_margin:
5563 * @icon_view: a #GtkIconView
5565 * Returns the value of the ::margin property.
5567 * Return value: the space at the borders
5572 gtk_icon_view_get_margin (GtkIconView *icon_view)
5574 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5576 return icon_view->priv->margin;
5580 /* Get/set whether drag_motion requested the drag data and
5581 * drag_data_received should thus not actually insert the data,
5582 * since the data doesn't result from a drop.
5585 set_status_pending (GdkDragContext *context,
5586 GdkDragAction suggested_action)
5588 g_object_set_data (G_OBJECT (context),
5589 I_("gtk-icon-view-status-pending"),
5590 GINT_TO_POINTER (suggested_action));
5593 static GdkDragAction
5594 get_status_pending (GdkDragContext *context)
5596 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5597 "gtk-icon-view-status-pending"));
5601 unset_reorderable (GtkIconView *icon_view)
5603 if (icon_view->priv->reorderable)
5605 icon_view->priv->reorderable = FALSE;
5606 g_object_notify (G_OBJECT (icon_view), "reorderable");
5611 clear_source_info (GtkIconView *icon_view)
5613 if (icon_view->priv->source_targets)
5614 gtk_target_list_unref (icon_view->priv->source_targets);
5615 icon_view->priv->source_targets = NULL;
5617 icon_view->priv->source_set = FALSE;
5621 clear_dest_info (GtkIconView *icon_view)
5623 if (icon_view->priv->dest_targets)
5624 gtk_target_list_unref (icon_view->priv->dest_targets);
5625 icon_view->priv->dest_targets = NULL;
5627 icon_view->priv->dest_set = FALSE;
5631 set_source_row (GdkDragContext *context,
5632 GtkTreeModel *model,
5633 GtkTreePath *source_row)
5636 g_object_set_data_full (G_OBJECT (context),
5637 I_("gtk-icon-view-source-row"),
5638 gtk_tree_row_reference_new (model, source_row),
5639 (GDestroyNotify) gtk_tree_row_reference_free);
5641 g_object_set_data_full (G_OBJECT (context),
5642 I_("gtk-icon-view-source-row"),
5647 get_source_row (GdkDragContext *context)
5649 GtkTreeRowReference *ref;
5651 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5654 return gtk_tree_row_reference_get_path (ref);
5661 GtkTreeRowReference *dest_row;
5662 gboolean empty_view_drop;
5663 gboolean drop_append_mode;
5667 dest_row_free (gpointer data)
5669 DestRow *dr = (DestRow *)data;
5671 gtk_tree_row_reference_free (dr->dest_row);
5676 set_dest_row (GdkDragContext *context,
5677 GtkTreeModel *model,
5678 GtkTreePath *dest_row,
5679 gboolean empty_view_drop,
5680 gboolean drop_append_mode)
5686 g_object_set_data_full (G_OBJECT (context),
5687 I_("gtk-icon-view-dest-row"),
5692 dr = g_new0 (DestRow, 1);
5694 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5695 dr->empty_view_drop = empty_view_drop;
5696 dr->drop_append_mode = drop_append_mode;
5697 g_object_set_data_full (G_OBJECT (context),
5698 I_("gtk-icon-view-dest-row"),
5699 dr, (GDestroyNotify) dest_row_free);
5703 get_dest_row (GdkDragContext *context)
5707 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5711 GtkTreePath *path = NULL;
5714 path = gtk_tree_row_reference_get_path (dr->dest_row);
5715 else if (dr->empty_view_drop)
5716 path = gtk_tree_path_new_from_indices (0, -1);
5720 if (path && dr->drop_append_mode)
5721 gtk_tree_path_next (path);
5730 check_model_dnd (GtkTreeModel *model,
5731 GType required_iface,
5732 const gchar *signal)
5734 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5736 g_warning ("You must override the default '%s' handler "
5737 "on GtkIconView when using models that don't support "
5738 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5739 "is to connect to '%s' and call "
5740 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5741 "the default handler from running. Look at the source code "
5742 "for the default handler in gtkiconview.c to get an idea what "
5743 "your handler should do. (gtkiconview.c is in the GTK+ source "
5744 "code.) If you're using GTK+ from a language other than C, "
5745 "there may be a more natural way to override default handlers, e.g. via derivation.",
5746 signal, g_type_name (required_iface), signal);
5754 remove_scroll_timeout (GtkIconView *icon_view)
5756 if (icon_view->priv->scroll_timeout_id != 0)
5758 g_source_remove (icon_view->priv->scroll_timeout_id);
5760 icon_view->priv->scroll_timeout_id = 0;
5765 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5767 gint px, py, x, y, width, height;
5768 gint hoffset, voffset;
5771 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5772 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5774 /* see if we are near the edge. */
5775 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5777 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5779 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5781 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5785 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5786 icon_view->priv->vadjustment->lower,
5787 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5788 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5792 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5793 icon_view->priv->hadjustment->lower,
5794 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5795 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5801 drag_scroll_timeout (gpointer data)
5803 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5805 GDK_THREADS_ENTER ();
5807 gtk_icon_view_autoscroll (icon_view);
5809 GDK_THREADS_LEAVE ();
5816 set_destination (GtkIconView *icon_view,
5817 GdkDragContext *context,
5820 GdkDragAction *suggested_action,
5824 GtkTreePath *path = NULL;
5825 GtkIconViewDropPosition pos;
5826 GtkIconViewDropPosition old_pos;
5827 GtkTreePath *old_dest_path = NULL;
5828 gboolean can_drop = FALSE;
5830 widget = GTK_WIDGET (icon_view);
5832 *suggested_action = 0;
5835 if (!icon_view->priv->dest_set)
5837 /* someone unset us as a drag dest, note that if
5838 * we return FALSE drag_leave isn't called
5841 gtk_icon_view_set_drag_dest_item (icon_view,
5843 GTK_ICON_VIEW_DROP_LEFT);
5845 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5847 return FALSE; /* no longer a drop site */
5850 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5851 if (*target == GDK_NONE)
5854 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5857 GtkTreeModel *model;
5859 /* the row got dropped on empty space, let's setup a special case
5863 gtk_tree_path_free (path);
5865 model = gtk_icon_view_get_model (icon_view);
5867 n_children = gtk_tree_model_iter_n_children (model, NULL);
5870 pos = GTK_ICON_VIEW_DROP_BELOW;
5871 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5875 pos = GTK_ICON_VIEW_DROP_ABOVE;
5876 path = gtk_tree_path_new_from_indices (0, -1);
5886 gtk_icon_view_get_drag_dest_item (icon_view,
5891 gtk_tree_path_free (old_dest_path);
5893 if (TRUE /* FIXME if the location droppable predicate */)
5901 GtkWidget *source_widget;
5903 *suggested_action = context->suggested_action;
5904 source_widget = gtk_drag_get_source_widget (context);
5906 if (source_widget == widget)
5908 /* Default to MOVE, unless the user has
5909 * pressed ctrl or shift to affect available actions
5911 if ((context->actions & GDK_ACTION_MOVE) != 0)
5912 *suggested_action = GDK_ACTION_MOVE;
5915 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5920 /* can't drop here */
5921 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5923 GTK_ICON_VIEW_DROP_LEFT);
5927 gtk_tree_path_free (path);
5933 get_logical_destination (GtkIconView *icon_view,
5934 gboolean *drop_append_mode)
5936 /* adjust path to point to the row the drop goes in front of */
5937 GtkTreePath *path = NULL;
5938 GtkIconViewDropPosition pos;
5940 *drop_append_mode = FALSE;
5942 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5947 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5948 pos == GTK_ICON_VIEW_DROP_BELOW)
5951 GtkTreeModel *model = icon_view->priv->model;
5953 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5954 !gtk_tree_model_iter_next (model, &iter))
5955 *drop_append_mode = TRUE;
5958 *drop_append_mode = FALSE;
5959 gtk_tree_path_next (path);
5967 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5968 GdkEventMotion *event)
5970 GdkDragContext *context;
5971 GtkTreePath *path = NULL;
5973 GtkTreeModel *model;
5974 gboolean retval = FALSE;
5976 if (!icon_view->priv->source_set)
5979 if (icon_view->priv->pressed_button < 0)
5982 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5983 icon_view->priv->press_start_x,
5984 icon_view->priv->press_start_y,
5985 event->x, event->y))
5988 model = gtk_icon_view_get_model (icon_view);
5993 button = icon_view->priv->pressed_button;
5994 icon_view->priv->pressed_button = -1;
5996 path = gtk_icon_view_get_path_at_pos (icon_view,
5997 icon_view->priv->press_start_x,
5998 icon_view->priv->press_start_y);
6003 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6004 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6008 /* FIXME Check whether we're a start button, if not return FALSE and
6012 /* Now we can begin the drag */
6016 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6017 icon_view->priv->source_targets,
6018 icon_view->priv->source_actions,
6022 set_source_row (context, model, path);
6026 gtk_tree_path_free (path);
6031 /* Source side drag signals */
6033 gtk_icon_view_drag_begin (GtkWidget *widget,
6034 GdkDragContext *context)
6036 GtkIconView *icon_view;
6037 GtkIconViewItem *item;
6042 icon_view = GTK_ICON_VIEW (widget);
6044 /* if the user uses a custom DnD impl, we don't set the icon here */
6045 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6048 item = gtk_icon_view_get_item_at_coords (icon_view,
6049 icon_view->priv->press_start_x,
6050 icon_view->priv->press_start_y,
6054 g_return_if_fail (item != NULL);
6056 x = icon_view->priv->press_start_x - item->x + 1;
6057 y = icon_view->priv->press_start_y - item->y + 1;
6059 path = gtk_tree_path_new_from_indices (item->index, -1);
6060 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6061 gtk_tree_path_free (path);
6063 gtk_drag_set_icon_pixmap (context,
6064 gdk_drawable_get_colormap (icon),
6069 g_object_unref (icon);
6073 gtk_icon_view_drag_end (GtkWidget *widget,
6074 GdkDragContext *context)
6080 gtk_icon_view_drag_data_get (GtkWidget *widget,
6081 GdkDragContext *context,
6082 GtkSelectionData *selection_data,
6086 GtkIconView *icon_view;
6087 GtkTreeModel *model;
6088 GtkTreePath *source_row;
6090 icon_view = GTK_ICON_VIEW (widget);
6091 model = gtk_icon_view_get_model (icon_view);
6096 if (!icon_view->priv->dest_set)
6099 source_row = get_source_row (context);
6101 if (source_row == NULL)
6104 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6105 * any model; for DragSource models there are some other targets
6109 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6110 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6115 /* If drag_data_get does nothing, try providing row data. */
6116 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6117 gtk_tree_set_row_drag_data (selection_data,
6122 gtk_tree_path_free (source_row);
6126 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6127 GdkDragContext *context)
6129 GtkTreeModel *model;
6130 GtkIconView *icon_view;
6131 GtkTreePath *source_row;
6133 icon_view = GTK_ICON_VIEW (widget);
6134 model = gtk_icon_view_get_model (icon_view);
6136 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6139 if (!icon_view->priv->dest_set)
6142 source_row = get_source_row (context);
6144 if (source_row == NULL)
6147 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6150 gtk_tree_path_free (source_row);
6152 set_source_row (context, NULL, NULL);
6155 /* Target side drag signals */
6157 gtk_icon_view_drag_leave (GtkWidget *widget,
6158 GdkDragContext *context,
6161 GtkIconView *icon_view;
6163 icon_view = GTK_ICON_VIEW (widget);
6165 /* unset any highlight row */
6166 gtk_icon_view_set_drag_dest_item (icon_view,
6168 GTK_ICON_VIEW_DROP_LEFT);
6170 remove_scroll_timeout (icon_view);
6174 gtk_icon_view_drag_motion (GtkWidget *widget,
6175 GdkDragContext *context,
6180 GtkTreePath *path = NULL;
6181 GtkTreeModel *model;
6182 GtkIconViewDropPosition pos;
6183 GtkIconView *icon_view;
6184 GdkDragAction suggested_action = 0;
6188 icon_view = GTK_ICON_VIEW (widget);
6190 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6193 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6195 /* we only know this *after* set_desination_row */
6196 model = gtk_icon_view_get_model (icon_view);
6197 empty = icon_view->priv->empty_view_drop;
6199 if (path == NULL && !empty)
6201 /* Can't drop here. */
6202 gdk_drag_status (context, 0, time);
6206 if (icon_view->priv->scroll_timeout_id == 0)
6208 icon_view->priv->scroll_timeout_id =
6209 g_timeout_add (50, drag_scroll_timeout, icon_view);
6212 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6214 /* Request data so we can use the source row when
6215 * determining whether to accept the drop
6217 set_status_pending (context, suggested_action);
6218 gtk_drag_get_data (widget, context, target, time);
6222 set_status_pending (context, 0);
6223 gdk_drag_status (context, suggested_action, time);
6228 gtk_tree_path_free (path);
6234 gtk_icon_view_drag_drop (GtkWidget *widget,
6235 GdkDragContext *context,
6240 GtkIconView *icon_view;
6242 GdkDragAction suggested_action = 0;
6243 GdkAtom target = GDK_NONE;
6244 GtkTreeModel *model;
6245 gboolean drop_append_mode;
6247 icon_view = GTK_ICON_VIEW (widget);
6248 model = gtk_icon_view_get_model (icon_view);
6250 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6252 if (!icon_view->priv->dest_set)
6255 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6258 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6261 path = get_logical_destination (icon_view, &drop_append_mode);
6263 if (target != GDK_NONE && path != NULL)
6265 /* in case a motion had requested drag data, change things so we
6266 * treat drag data receives as a drop.
6268 set_status_pending (context, 0);
6269 set_dest_row (context, model, path,
6270 icon_view->priv->empty_view_drop, drop_append_mode);
6274 gtk_tree_path_free (path);
6276 /* Unset this thing */
6277 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6279 if (target != GDK_NONE)
6281 gtk_drag_get_data (widget, context, target, time);
6289 gtk_icon_view_drag_data_received (GtkWidget *widget,
6290 GdkDragContext *context,
6293 GtkSelectionData *selection_data,
6298 gboolean accepted = FALSE;
6299 GtkTreeModel *model;
6300 GtkIconView *icon_view;
6301 GtkTreePath *dest_row;
6302 GdkDragAction suggested_action;
6303 gboolean drop_append_mode;
6305 icon_view = GTK_ICON_VIEW (widget);
6306 model = gtk_icon_view_get_model (icon_view);
6308 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6311 if (!icon_view->priv->dest_set)
6314 suggested_action = get_status_pending (context);
6316 if (suggested_action)
6318 /* We are getting this data due to a request in drag_motion,
6319 * rather than due to a request in drag_drop, so we are just
6320 * supposed to call drag_status, not actually paste in the
6323 path = get_logical_destination (icon_view, &drop_append_mode);
6326 suggested_action = 0;
6328 if (suggested_action)
6330 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6333 suggested_action = 0;
6336 gdk_drag_status (context, suggested_action, time);
6339 gtk_tree_path_free (path);
6341 /* If you can't drop, remove user drop indicator until the next motion */
6342 if (suggested_action == 0)
6343 gtk_icon_view_set_drag_dest_item (icon_view,
6345 GTK_ICON_VIEW_DROP_LEFT);
6350 dest_row = get_dest_row (context);
6352 if (dest_row == NULL)
6355 if (selection_data->length >= 0)
6357 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6363 gtk_drag_finish (context,
6365 (context->action == GDK_ACTION_MOVE),
6368 gtk_tree_path_free (dest_row);
6371 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6374 /* Drag-and-Drop support */
6376 * gtk_icon_view_enable_model_drag_source:
6377 * @icon_view: a #GtkIconTreeView
6378 * @start_button_mask: Mask of allowed buttons to start drag
6379 * @targets: the table of targets that the drag will support
6380 * @n_targets: the number of items in @targets
6381 * @actions: the bitmask of possible actions for a drag from this
6384 * Turns @icon_view into a drag source for automatic DND.
6389 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6390 GdkModifierType start_button_mask,
6391 const GtkTargetEntry *targets,
6393 GdkDragAction actions)
6395 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6397 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6399 clear_source_info (icon_view);
6400 icon_view->priv->start_button_mask = start_button_mask;
6401 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6402 icon_view->priv->source_actions = actions;
6404 icon_view->priv->source_set = TRUE;
6406 unset_reorderable (icon_view);
6410 * gtk_icon_view_enable_model_drag_dest:
6411 * @icon_view: a #GtkIconView
6412 * @targets: the table of targets that the drag will support
6413 * @n_targets: the number of items in @targets
6414 * @actions: the bitmask of possible actions for a drag from this
6417 * Turns @icon_view into a drop destination for automatic DND.
6422 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6423 const GtkTargetEntry *targets,
6425 GdkDragAction actions)
6427 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6429 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6431 clear_dest_info (icon_view);
6433 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6434 icon_view->priv->dest_actions = actions;
6436 icon_view->priv->dest_set = TRUE;
6438 unset_reorderable (icon_view);
6442 * gtk_icon_view_unset_model_drag_source:
6443 * @icon_view: a #GtkIconView
6445 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6450 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6452 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6454 if (icon_view->priv->source_set)
6456 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6457 clear_source_info (icon_view);
6460 unset_reorderable (icon_view);
6464 * gtk_icon_view_unset_model_drag_dest:
6465 * @icon_view: a #GtkIconView
6467 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6472 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6474 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6476 if (icon_view->priv->dest_set)
6478 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6479 clear_dest_info (icon_view);
6482 unset_reorderable (icon_view);
6485 /* These are useful to implement your own custom stuff. */
6487 * gtk_icon_view_set_drag_dest_item:
6488 * @icon_view: a #GtkIconView
6489 * @path: The path of the item to highlight, or %NULL.
6490 * @pos: Specifies whether to drop, relative to the item
6492 * Sets the item that is highlighted for feedback.
6497 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6499 GtkIconViewDropPosition pos)
6501 /* Note; this function is exported to allow a custom DND
6502 * implementation, so it can't touch TreeViewDragInfo
6505 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6507 if (icon_view->priv->dest_item)
6509 GtkTreePath *current_path;
6510 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6511 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6512 icon_view->priv->dest_item = NULL;
6514 gtk_icon_view_queue_draw_path (icon_view, current_path);
6515 gtk_tree_path_free (current_path);
6518 /* special case a drop on an empty model */
6519 icon_view->priv->empty_view_drop = FALSE;
6520 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6521 && gtk_tree_path_get_depth (path) == 1
6522 && gtk_tree_path_get_indices (path)[0] == 0)
6526 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6529 if (n_children == 0)
6530 icon_view->priv->empty_view_drop = TRUE;
6533 icon_view->priv->dest_pos = pos;
6537 icon_view->priv->dest_item =
6538 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6539 icon_view->priv->model, path);
6541 gtk_icon_view_queue_draw_path (icon_view, path);
6546 * gtk_icon_view_get_drag_dest_item:
6547 * @icon_view: a #GtkIconView
6548 * @path: Return location for the path of the highlighted item, or %NULL.
6549 * @pos: Return location for the drop position, or %NULL
6551 * Gets information about the item that is highlighted for feedback.
6556 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6558 GtkIconViewDropPosition *pos)
6560 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6564 if (icon_view->priv->dest_item)
6565 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6571 *pos = icon_view->priv->dest_pos;
6575 * gtk_icon_view_get_dest_item_at_pos:
6576 * @icon_view: a #GtkIconView
6577 * @drag_x: the position to determine the destination item for
6578 * @drag_y: the position to determine the destination item for
6579 * @path: Return location for the path of the highlighted item, or %NULL.
6580 * @pos: Return location for the drop position, or %NULL
6582 * Determines the destination item for a given position.
6584 * Return value: whether there is an item at the given position.
6589 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6593 GtkIconViewDropPosition *pos)
6595 GtkIconViewItem *item;
6597 /* Note; this function is exported to allow a custom DND
6598 * implementation, so it can't touch TreeViewDragInfo
6601 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6602 g_return_val_if_fail (drag_x >= 0, FALSE);
6603 g_return_val_if_fail (drag_y >= 0, FALSE);
6604 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6610 item = gtk_icon_view_get_item_at_coords (icon_view,
6611 drag_x + icon_view->priv->hadjustment->value,
6612 drag_y + icon_view->priv->vadjustment->value,
6619 *path = gtk_tree_path_new_from_indices (item->index, -1);
6623 if (drag_x < item->x + item->width / 4)
6624 *pos = GTK_ICON_VIEW_DROP_LEFT;
6625 else if (drag_x > item->x + item->width * 3 / 4)
6626 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6627 else if (drag_y < item->y + item->height / 4)
6628 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6629 else if (drag_y > item->y + item->height * 3 / 4)
6630 *pos = GTK_ICON_VIEW_DROP_BELOW;
6632 *pos = GTK_ICON_VIEW_DROP_INTO;
6639 * gtk_icon_view_create_drag_icon:
6640 * @icon_view: a #GtkIconView
6641 * @path: a #GtkTreePath in @icon_view
6643 * Creates a #GdkPixmap representation of the item at @path.
6644 * This image is used for a drag icon.
6646 * Return value: a newly-allocated pixmap of the drag icon.
6651 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6656 GdkPixmap *drawable;
6661 widget = GTK_WIDGET (icon_view);
6663 index = gtk_tree_path_get_indices (path)[0];
6665 for (l = icon_view->priv->items; l; l = l->next)
6667 GtkIconViewItem *item = l->data;
6669 if (index == item->index)
6671 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6676 cr = gdk_cairo_create (drawable);
6677 cairo_set_line_width (cr, 1.);
6679 gdk_cairo_set_source_color
6680 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6681 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6686 area.width = item->width;
6687 area.height = item->height;
6689 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6690 drawable, 1, 1, FALSE);
6692 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6693 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6706 * gtk_icon_view_get_reorderable:
6707 * @icon_view: a #GtkIconView
6709 * Retrieves whether the user can reorder the list via drag-and-drop.
6710 * See gtk_icon_view_set_reorderable().
6712 * Return value: %TRUE if the list can be reordered.
6717 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6719 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6721 return icon_view->priv->reorderable;
6724 static const GtkTargetEntry item_targets[] = {
6725 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6730 * gtk_icon_view_set_reorderable:
6731 * @icon_view: A #GtkIconView.
6732 * @reorderable: %TRUE, if the list of items can be reordered.
6734 * This function is a convenience function to allow you to reorder models that
6735 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6736 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6737 * the user can reorder the model by dragging and dropping rows. The
6738 * developer can listen to these changes by connecting to the model's
6739 * row_inserted and row_deleted signals.
6741 * This function does not give you any degree of control over the order -- any
6742 * reordering is allowed. If more control is needed, you should probably
6743 * handle drag and drop manually.
6748 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6749 gboolean reorderable)
6751 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6753 reorderable = reorderable != FALSE;
6755 if (icon_view->priv->reorderable == reorderable)
6760 gtk_icon_view_enable_model_drag_source (icon_view,
6763 G_N_ELEMENTS (item_targets),
6765 gtk_icon_view_enable_model_drag_dest (icon_view,
6767 G_N_ELEMENTS (item_targets),
6772 gtk_icon_view_unset_model_drag_source (icon_view);
6773 gtk_icon_view_unset_model_drag_dest (icon_view);
6776 icon_view->priv->reorderable = reorderable;
6778 g_object_notify (G_OBJECT (icon_view), "reorderable");
6782 /* Accessibility Support */
6784 static gpointer accessible_parent_class;
6785 static gpointer accessible_item_parent_class;
6786 static GQuark accessible_private_data_quark = 0;
6788 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6789 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6790 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6792 static GType gtk_icon_view_item_accessible_get_type (void);
6803 GtkIconViewItem *item;
6807 AtkStateSet *state_set;
6811 GtkTextBuffer *text_buffer;
6813 gchar *action_descriptions[LAST_ACTION];
6814 gchar *image_description;
6815 guint action_idle_handler;
6816 } GtkIconViewItemAccessible;
6818 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6824 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6829 typedef struct _GtkIconViewItemAccessibleClass
6831 AtkObjectClass parent_class;
6833 } GtkIconViewItemAccessibleClass;
6835 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6838 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6840 GtkIconViewItemAccessible *item;
6841 GtkIconView *icon_view;
6844 GDK_THREADS_ENTER ();
6846 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6847 item->action_idle_handler = 0;
6849 if (item->widget != NULL)
6851 icon_view = GTK_ICON_VIEW (item->widget);
6852 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6853 gtk_icon_view_item_activated (icon_view, path);
6854 gtk_tree_path_free (path);
6857 GDK_THREADS_LEAVE ();
6863 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6866 GtkIconViewItemAccessible *item;
6867 GtkIconView *icon_view;
6869 if (i < 0 || i >= LAST_ACTION)
6872 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6874 if (!GTK_IS_ICON_VIEW (item->widget))
6877 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6880 icon_view = GTK_ICON_VIEW (item->widget);
6884 case ACTION_ACTIVATE:
6885 if (!item->action_idle_handler)
6886 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6889 g_assert_not_reached ();
6897 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6902 static const gchar *
6903 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6906 GtkIconViewItemAccessible *item;
6908 if (i < 0 || i >= LAST_ACTION)
6911 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6913 if (item->action_descriptions[i])
6914 return item->action_descriptions[i];
6916 return gtk_icon_view_item_accessible_action_descriptions[i];
6919 static const gchar *
6920 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6923 if (i < 0 || i >= LAST_ACTION)
6926 return gtk_icon_view_item_accessible_action_names[i];
6930 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6932 const gchar *description)
6934 GtkIconViewItemAccessible *item;
6936 if (i < 0 || i >= LAST_ACTION)
6939 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6941 if (item->action_descriptions[i])
6942 g_free (item->action_descriptions[i]);
6944 item->action_descriptions[i] = g_strdup (description);
6950 atk_action_item_interface_init (AtkActionIface *iface)
6952 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6953 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6954 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6955 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6956 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6959 static const gchar *
6960 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6962 GtkIconViewItemAccessible *item;
6964 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6966 return item->image_description;
6970 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6971 const gchar *description)
6973 GtkIconViewItemAccessible *item;
6975 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6977 g_free (item->image_description);
6978 item->image_description = g_strdup (item->image_description);
6984 get_pixbuf_box (GtkIconView *icon_view,
6985 GtkIconViewItem *item,
6990 for (l = icon_view->priv->cell_list; l; l = l->next)
6992 GtkIconViewCellInfo *info = l->data;
6994 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6996 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7006 get_text (GtkIconView *icon_view,
7007 GtkIconViewItem *item)
7012 for (l = icon_view->priv->cell_list; l; l = l->next)
7014 GtkIconViewCellInfo *info = l->data;
7016 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7018 g_object_get (info->cell, "text", &text, NULL);
7028 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7032 GtkIconViewItemAccessible *item;
7035 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7037 if (!GTK_IS_ICON_VIEW (item->widget))
7040 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7043 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7046 *height = box.height;
7051 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7054 AtkCoordType coord_type)
7056 GtkIconViewItemAccessible *item;
7059 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7061 if (!GTK_IS_ICON_VIEW (item->widget))
7064 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7067 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7069 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7071 *x+= box.x - item->item->x;
7072 *y+= box.y - item->item->y;
7078 atk_image_item_interface_init (AtkImageIface *iface)
7080 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7081 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7082 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7083 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7087 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7091 GtkIconViewItemAccessible *item;
7092 GtkTextIter start, end;
7093 GtkTextBuffer *buffer;
7095 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7097 if (!GTK_IS_ICON_VIEW (item->widget))
7100 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7103 buffer = item->text_buffer;
7104 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7106 gtk_text_buffer_get_end_iter (buffer, &end);
7108 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7110 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7114 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7117 GtkIconViewItemAccessible *item;
7118 GtkTextIter start, end;
7119 GtkTextBuffer *buffer;
7123 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7125 if (!GTK_IS_ICON_VIEW (item->widget))
7128 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7131 buffer = item->text_buffer;
7132 if (offset >= gtk_text_buffer_get_char_count (buffer))
7135 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7137 gtk_text_iter_forward_char (&end);
7138 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7139 unichar = g_utf8_get_char (string);
7146 get_pango_text_offsets (PangoLayout *layout,
7147 GtkTextBuffer *buffer,
7149 AtkTextBoundary boundary_type,
7153 GtkTextIter *start_iter,
7154 GtkTextIter *end_iter)
7156 PangoLayoutIter *iter;
7157 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7158 gint index, start_index, end_index;
7160 gboolean found = FALSE;
7162 text = pango_layout_get_text (layout);
7163 index = g_utf8_offset_to_pointer (text, offset) - text;
7164 iter = pango_layout_get_iter (layout);
7167 line = pango_layout_iter_get_line (iter);
7168 start_index = line->start_index;
7169 end_index = start_index + line->length;
7171 if (index >= start_index && index <= end_index)
7174 * Found line for offset
7180 * We want the previous line
7184 switch (boundary_type)
7186 case ATK_TEXT_BOUNDARY_LINE_START:
7187 end_index = start_index;
7188 start_index = prev_line->start_index;
7190 case ATK_TEXT_BOUNDARY_LINE_END:
7192 start_index = prev_prev_line->start_index +
7193 prev_prev_line->length;
7194 end_index = prev_line->start_index + prev_line->length;
7197 g_assert_not_reached();
7201 start_index = end_index = 0;
7204 switch (boundary_type)
7206 case ATK_TEXT_BOUNDARY_LINE_START:
7207 if (pango_layout_iter_next_line (iter))
7208 end_index = pango_layout_iter_get_line (iter)->start_index;
7210 case ATK_TEXT_BOUNDARY_LINE_END:
7212 start_index = prev_line->start_index +
7216 g_assert_not_reached();
7221 * We want the next line
7223 if (pango_layout_iter_next_line (iter))
7225 line = pango_layout_iter_get_line (iter);
7226 switch (boundary_type)
7228 case ATK_TEXT_BOUNDARY_LINE_START:
7229 start_index = line->start_index;
7230 if (pango_layout_iter_next_line (iter))
7231 end_index = pango_layout_iter_get_line (iter)->start_index;
7233 end_index = start_index + line->length;
7235 case ATK_TEXT_BOUNDARY_LINE_END:
7236 start_index = end_index;
7237 end_index = line->start_index + line->length;
7240 g_assert_not_reached();
7244 start_index = end_index;
7250 prev_prev_line = prev_line;
7253 while (pango_layout_iter_next_line (iter));
7257 start_index = prev_line->start_index + prev_line->length;
7258 end_index = start_index;
7260 pango_layout_iter_free (iter);
7261 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7262 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7264 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7265 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7269 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7271 AtkTextBoundary boundary_type,
7275 GtkIconViewItemAccessible *item;
7276 GtkTextIter start, end;
7277 GtkTextBuffer *buffer;
7278 GtkIconView *icon_view;
7280 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7282 if (!GTK_IS_ICON_VIEW (item->widget))
7285 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7288 buffer = item->text_buffer;
7290 if (!gtk_text_buffer_get_char_count (buffer))
7294 return g_strdup ("");
7296 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7300 switch (boundary_type)
7302 case ATK_TEXT_BOUNDARY_CHAR:
7303 gtk_text_iter_backward_char(&start);
7305 case ATK_TEXT_BOUNDARY_WORD_START:
7306 if (!gtk_text_iter_starts_word (&start))
7307 gtk_text_iter_backward_word_start (&start);
7309 gtk_text_iter_backward_word_start(&start);
7311 case ATK_TEXT_BOUNDARY_WORD_END:
7312 if (gtk_text_iter_inside_word (&start) &&
7313 !gtk_text_iter_starts_word (&start))
7314 gtk_text_iter_backward_word_start (&start);
7315 while (!gtk_text_iter_ends_word (&start))
7317 if (!gtk_text_iter_backward_char (&start))
7321 gtk_text_iter_backward_word_start(&start);
7322 while (!gtk_text_iter_ends_word (&start))
7324 if (!gtk_text_iter_backward_char (&start))
7328 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7329 if (!gtk_text_iter_starts_sentence (&start))
7330 gtk_text_iter_backward_sentence_start (&start);
7332 gtk_text_iter_backward_sentence_start (&start);
7334 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7335 if (gtk_text_iter_inside_sentence (&start) &&
7336 !gtk_text_iter_starts_sentence (&start))
7337 gtk_text_iter_backward_sentence_start (&start);
7338 while (!gtk_text_iter_ends_sentence (&start))
7340 if (!gtk_text_iter_backward_char (&start))
7344 gtk_text_iter_backward_sentence_start (&start);
7345 while (!gtk_text_iter_ends_sentence (&start))
7347 if (!gtk_text_iter_backward_char (&start))
7351 case ATK_TEXT_BOUNDARY_LINE_START:
7352 case ATK_TEXT_BOUNDARY_LINE_END:
7353 icon_view = GTK_ICON_VIEW (item->widget);
7355 /* FIXME we probably have to use GailTextCell to salvage this */
7356 gtk_icon_view_update_item_text (icon_view, item->item);
7357 get_pango_text_offsets (icon_view->priv->layout,
7370 *start_offset = gtk_text_iter_get_offset (&start);
7371 *end_offset = gtk_text_iter_get_offset (&end);
7373 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7377 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7379 AtkTextBoundary boundary_type,
7383 GtkIconViewItemAccessible *item;
7384 GtkTextIter start, end;
7385 GtkTextBuffer *buffer;
7386 GtkIconView *icon_view;
7388 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7390 if (!GTK_IS_ICON_VIEW (item->widget))
7393 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7396 buffer = item->text_buffer;
7398 if (!gtk_text_buffer_get_char_count (buffer))
7402 return g_strdup ("");
7404 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7408 switch (boundary_type)
7410 case ATK_TEXT_BOUNDARY_CHAR:
7411 gtk_text_iter_forward_char (&end);
7413 case ATK_TEXT_BOUNDARY_WORD_START:
7414 if (!gtk_text_iter_starts_word (&start))
7415 gtk_text_iter_backward_word_start (&start);
7416 if (gtk_text_iter_inside_word (&end))
7417 gtk_text_iter_forward_word_end (&end);
7418 while (!gtk_text_iter_starts_word (&end))
7420 if (!gtk_text_iter_forward_char (&end))
7424 case ATK_TEXT_BOUNDARY_WORD_END:
7425 if (gtk_text_iter_inside_word (&start) &&
7426 !gtk_text_iter_starts_word (&start))
7427 gtk_text_iter_backward_word_start (&start);
7428 while (!gtk_text_iter_ends_word (&start))
7430 if (!gtk_text_iter_backward_char (&start))
7433 gtk_text_iter_forward_word_end (&end);
7435 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7436 if (!gtk_text_iter_starts_sentence (&start))
7437 gtk_text_iter_backward_sentence_start (&start);
7438 if (gtk_text_iter_inside_sentence (&end))
7439 gtk_text_iter_forward_sentence_end (&end);
7440 while (!gtk_text_iter_starts_sentence (&end))
7442 if (!gtk_text_iter_forward_char (&end))
7446 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7447 if (gtk_text_iter_inside_sentence (&start) &&
7448 !gtk_text_iter_starts_sentence (&start))
7449 gtk_text_iter_backward_sentence_start (&start);
7450 while (!gtk_text_iter_ends_sentence (&start))
7452 if (!gtk_text_iter_backward_char (&start))
7455 gtk_text_iter_forward_sentence_end (&end);
7457 case ATK_TEXT_BOUNDARY_LINE_START:
7458 case ATK_TEXT_BOUNDARY_LINE_END:
7459 icon_view = GTK_ICON_VIEW (item->widget);
7461 /* FIXME we probably have to use GailTextCell to salvage this */
7462 gtk_icon_view_update_item_text (icon_view, item->item);
7463 get_pango_text_offsets (icon_view->priv->layout,
7477 *start_offset = gtk_text_iter_get_offset (&start);
7478 *end_offset = gtk_text_iter_get_offset (&end);
7480 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7484 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7486 AtkTextBoundary boundary_type,
7490 GtkIconViewItemAccessible *item;
7491 GtkTextIter start, end;
7492 GtkTextBuffer *buffer;
7493 GtkIconView *icon_view;
7495 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7497 if (!GTK_IS_ICON_VIEW (item->widget))
7500 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7503 buffer = item->text_buffer;
7505 if (!gtk_text_buffer_get_char_count (buffer))
7509 return g_strdup ("");
7511 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7515 switch (boundary_type)
7517 case ATK_TEXT_BOUNDARY_CHAR:
7518 gtk_text_iter_forward_char(&start);
7519 gtk_text_iter_forward_chars(&end, 2);
7521 case ATK_TEXT_BOUNDARY_WORD_START:
7522 if (gtk_text_iter_inside_word (&end))
7523 gtk_text_iter_forward_word_end (&end);
7524 while (!gtk_text_iter_starts_word (&end))
7526 if (!gtk_text_iter_forward_char (&end))
7530 if (!gtk_text_iter_is_end (&end))
7532 gtk_text_iter_forward_word_end (&end);
7533 while (!gtk_text_iter_starts_word (&end))
7535 if (!gtk_text_iter_forward_char (&end))
7540 case ATK_TEXT_BOUNDARY_WORD_END:
7541 gtk_text_iter_forward_word_end (&end);
7543 if (!gtk_text_iter_is_end (&end))
7544 gtk_text_iter_forward_word_end (&end);
7546 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7547 if (gtk_text_iter_inside_sentence (&end))
7548 gtk_text_iter_forward_sentence_end (&end);
7549 while (!gtk_text_iter_starts_sentence (&end))
7551 if (!gtk_text_iter_forward_char (&end))
7555 if (!gtk_text_iter_is_end (&end))
7557 gtk_text_iter_forward_sentence_end (&end);
7558 while (!gtk_text_iter_starts_sentence (&end))
7560 if (!gtk_text_iter_forward_char (&end))
7565 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7566 gtk_text_iter_forward_sentence_end (&end);
7568 if (!gtk_text_iter_is_end (&end))
7569 gtk_text_iter_forward_sentence_end (&end);
7571 case ATK_TEXT_BOUNDARY_LINE_START:
7572 case ATK_TEXT_BOUNDARY_LINE_END:
7573 icon_view = GTK_ICON_VIEW (item->widget);
7575 /* FIXME we probably have to use GailTextCell to salvage this */
7576 gtk_icon_view_update_item_text (icon_view, item->item);
7577 get_pango_text_offsets (icon_view->priv->layout,
7589 *start_offset = gtk_text_iter_get_offset (&start);
7590 *end_offset = gtk_text_iter_get_offset (&end);
7592 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7596 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7598 GtkIconViewItemAccessible *item;
7600 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7602 if (!GTK_IS_ICON_VIEW (item->widget))
7605 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7608 return gtk_text_buffer_get_char_count (item->text_buffer);
7612 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7618 AtkCoordType coord_type)
7620 GtkIconViewItemAccessible *item;
7621 GtkIconView *icon_view;
7622 PangoRectangle char_rect;
7623 const gchar *item_text;
7626 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7628 if (!GTK_IS_ICON_VIEW (item->widget))
7631 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7634 icon_view = GTK_ICON_VIEW (item->widget);
7636 /* FIXME we probably have to use GailTextCell to salvage this */
7637 gtk_icon_view_update_item_text (icon_view, item->item);
7638 item_text = pango_layout_get_text (icon_view->priv->layout);
7639 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7640 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7642 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7643 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7644 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7645 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7646 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7647 *width = char_rect.width / PANGO_SCALE;
7648 *height = char_rect.height / PANGO_SCALE;
7653 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7656 AtkCoordType coord_type)
7658 GtkIconViewItemAccessible *item;
7659 GtkIconView *icon_view;
7660 const gchar *item_text;
7665 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7667 if (!GTK_IS_ICON_VIEW (item->widget))
7670 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7673 icon_view = GTK_ICON_VIEW (item->widget);
7675 /* FIXME we probably have to use GailTextCell to salvage this */
7676 gtk_icon_view_update_item_text (icon_view, item->item);
7677 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7678 x -= l_x + item->item->layout_x - item->item->x;
7679 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7680 y -= l_y + item->item->layout_y - item->item->y;
7681 item_text = pango_layout_get_text (icon_view->priv->layout);
7682 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7693 offset = g_utf8_strlen (item_text, -1);
7695 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7701 atk_text_item_interface_init (AtkTextIface *iface)
7703 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7704 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7705 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7706 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7707 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7708 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7709 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7710 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7714 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7719 AtkCoordType coord_type)
7721 GtkIconViewItemAccessible *item;
7722 AtkObject *parent_obj;
7725 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7727 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7728 if (!GTK_IS_WIDGET (item->widget))
7731 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7734 *width = item->item->width;
7735 *height = item->item->height;
7736 if (gtk_icon_view_item_accessible_is_showing (item))
7738 parent_obj = gtk_widget_get_accessible (item->widget);
7739 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7740 *x = l_x + item->item->x;
7741 *y = l_y + item->item->y;
7751 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7753 GtkIconViewItemAccessible *item;
7754 GtkWidget *toplevel;
7756 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7758 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7759 if (!GTK_IS_WIDGET (item->widget))
7762 gtk_widget_grab_focus (item->widget);
7763 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7764 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7765 if (GTK_WIDGET_TOPLEVEL (toplevel))
7766 gtk_window_present (GTK_WINDOW (toplevel));
7772 atk_component_item_interface_init (AtkComponentIface *iface)
7774 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7775 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7779 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7780 AtkStateType state_type,
7781 gboolean emit_signal)
7785 rc = atk_state_set_add_state (item->state_set, state_type);
7787 * The signal should only be generated if the value changed,
7788 * not when the item is set up. So states that are set
7789 * initially should pass FALSE as the emit_signal argument.
7794 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7795 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7796 if (state_type == ATK_STATE_VISIBLE)
7797 g_signal_emit_by_name (item, "visible_data_changed");
7804 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7805 AtkStateType state_type,
7806 gboolean emit_signal)
7808 if (atk_state_set_contains_state (item->state_set, state_type))
7812 rc = atk_state_set_remove_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, FALSE);
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");
7834 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7836 GtkIconView *icon_view;
7837 GdkRectangle visible_rect;
7838 gboolean is_showing;
7841 * An item is considered "SHOWING" if any part of the item is in the
7842 * visible rectangle.
7845 if (!GTK_IS_ICON_VIEW (item->widget))
7848 if (item->item == NULL)
7851 icon_view = GTK_ICON_VIEW (item->widget);
7853 if (icon_view->priv->hadjustment)
7854 visible_rect.x += icon_view->priv->hadjustment->value;
7856 if (icon_view->priv->hadjustment)
7857 visible_rect.y += icon_view->priv->vadjustment->value;
7858 visible_rect.width = item->widget->allocation.width;
7859 visible_rect.height = item->widget->allocation.height;
7861 if (((item->item->x + item->item->width) < visible_rect.x) ||
7862 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7863 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7864 (item->item->y > (visible_rect.y + visible_rect.height)))
7873 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7874 gboolean emit_signal)
7876 if (gtk_icon_view_item_accessible_is_showing (item))
7877 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7880 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7885 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7889 item->state_set = atk_state_set_new ();
7891 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7892 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7893 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7894 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7895 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7897 for (i = 0; i < LAST_ACTION; i++)
7898 item->action_descriptions[i] = NULL;
7900 item->image_description = NULL;
7902 item->action_idle_handler = 0;
7906 gtk_icon_view_item_accessible_finalize (GObject *object)
7908 GtkIconViewItemAccessible *item;
7911 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7913 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7916 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7918 if (item->state_set)
7919 g_object_unref (item->state_set);
7921 if (item->text_buffer)
7922 g_object_unref (item->text_buffer);
7924 for (i = 0; i < LAST_ACTION; i++)
7925 g_free (item->action_descriptions[i]);
7927 g_free (item->image_description);
7929 if (item->action_idle_handler)
7931 g_source_remove (item->action_idle_handler);
7932 item->action_idle_handler = 0;
7935 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7938 static G_CONST_RETURN gchar*
7939 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7945 GtkIconViewItemAccessible *item;
7946 GtkTextIter start_iter;
7947 GtkTextIter end_iter;
7949 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7951 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7952 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7954 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7959 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7961 GtkIconViewItemAccessible *item;
7963 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7964 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7967 return gtk_widget_get_accessible (item->widget);
7973 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7975 GtkIconViewItemAccessible *item;
7977 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7978 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7980 return item->item->index;
7983 static AtkStateSet *
7984 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7986 GtkIconViewItemAccessible *item;
7987 GtkIconView *icon_view;
7989 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7990 g_return_val_if_fail (item->state_set, NULL);
7995 icon_view = GTK_ICON_VIEW (item->widget);
7996 if (icon_view->priv->cursor_item == item->item)
7997 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7999 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8001 return g_object_ref (item->state_set);
8005 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8007 GObjectClass *gobject_class;
8009 accessible_item_parent_class = g_type_class_peek_parent (klass);
8011 gobject_class = (GObjectClass *)klass;
8013 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8015 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8016 klass->get_name = gtk_icon_view_item_accessible_get_name;
8017 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8018 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8022 gtk_icon_view_item_accessible_get_type (void)
8024 static GType type = 0;
8028 static const GTypeInfo tinfo =
8030 sizeof (GtkIconViewItemAccessibleClass),
8031 (GBaseInitFunc) NULL, /* base init */
8032 (GBaseFinalizeFunc) NULL, /* base finalize */
8033 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8034 (GClassFinalizeFunc) NULL, /* class finalize */
8035 NULL, /* class data */
8036 sizeof (GtkIconViewItemAccessible), /* instance size */
8037 0, /* nb preallocs */
8038 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8039 NULL /* value table */
8042 static const GInterfaceInfo atk_component_info =
8044 (GInterfaceInitFunc) atk_component_item_interface_init,
8045 (GInterfaceFinalizeFunc) NULL,
8048 static const GInterfaceInfo atk_action_info =
8050 (GInterfaceInitFunc) atk_action_item_interface_init,
8051 (GInterfaceFinalizeFunc) NULL,
8054 static const GInterfaceInfo atk_image_info =
8056 (GInterfaceInitFunc) atk_image_item_interface_init,
8057 (GInterfaceFinalizeFunc) NULL,
8060 static const GInterfaceInfo atk_text_info =
8062 (GInterfaceInitFunc) atk_text_item_interface_init,
8063 (GInterfaceFinalizeFunc) NULL,
8067 type = g_type_register_static (ATK_TYPE_OBJECT,
8068 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8069 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8070 &atk_component_info);
8071 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8073 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8075 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8082 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8083 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8084 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8086 static GType gtk_icon_view_accessible_get_type (void);
8091 } GtkIconViewAccessible;
8097 } GtkIconViewItemAccessibleInfo;
8103 GtkAdjustment *old_hadj;
8104 GtkAdjustment *old_vadj;
8106 GtkTreeModel *model;
8108 } GtkIconViewAccessiblePrivate;
8110 static GtkIconViewAccessiblePrivate *
8111 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8113 return g_object_get_qdata (G_OBJECT (accessible),
8114 accessible_private_data_quark);
8118 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8122 GtkIconViewItemAccessibleInfo *info;
8123 GtkIconViewItemAccessibleInfo *tmp_info;
8124 GtkIconViewAccessiblePrivate *priv;
8127 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8129 info->index = index;
8131 priv = gtk_icon_view_accessible_get_priv (accessible);
8132 items = priv->items;
8135 tmp_info = items->data;
8136 if (tmp_info->index > index)
8138 items = items->next;
8140 priv->items = g_list_insert_before (priv->items, items, info);
8141 priv->old_hadj = NULL;
8142 priv->old_vadj = NULL;
8146 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8148 GtkIconView *icon_view;
8151 widget = GTK_ACCESSIBLE (accessible)->widget;
8155 icon_view = GTK_ICON_VIEW (widget);
8157 return g_list_length (icon_view->priv->items);
8161 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8164 GtkIconViewAccessiblePrivate *priv;
8165 GtkIconViewItemAccessibleInfo *info;
8168 priv = gtk_icon_view_accessible_get_priv (accessible);
8169 items = priv->items;
8174 if (info->index == index)
8176 items = items->next;
8182 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8185 GtkIconView *icon_view;
8189 GtkIconViewItemAccessible *a11y_item;
8191 widget = GTK_ACCESSIBLE (accessible)->widget;
8195 icon_view = GTK_ICON_VIEW (widget);
8196 icons = g_list_nth (icon_view->priv->items, index);
8200 GtkIconViewItem *item = icons->data;
8202 g_return_val_if_fail (item->index == index, NULL);
8203 obj = gtk_icon_view_accessible_find_child (accessible, index);
8206 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8207 gtk_icon_view_item_accessible_info_new (accessible,
8210 obj->role = ATK_ROLE_ICON;
8211 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8212 a11y_item->item = item;
8213 a11y_item->widget = widget;
8214 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8216 gtk_icon_view_set_cell_data (icon_view, item);
8217 gtk_text_buffer_set_text (a11y_item->text_buffer,
8218 get_text (icon_view, item), -1);
8220 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8221 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8229 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8232 GtkIconViewAccessiblePrivate *priv;
8233 GtkIconViewItemAccessibleInfo *info;
8234 GtkIconViewItemAccessible *item;
8237 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8241 gboolean act_on_item;
8243 widget = GTK_ACCESSIBLE (view)->widget;
8247 items = priv->items;
8249 act_on_item = (list == NULL);
8254 info = (GtkIconViewItemAccessibleInfo *)items->data;
8255 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8257 if (act_on_item == FALSE && list == items)
8261 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8263 items = items->next;
8269 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8270 GtkIconView *icon_view)
8273 GtkIconViewAccessible *view;
8276 * The scrollbars have changed
8278 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8279 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8281 gtk_icon_view_accessible_traverse_items (view, NULL);
8285 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8286 GtkAdjustment *hadj,
8287 GtkAdjustment *vadj)
8290 GtkIconViewAccessiblePrivate *priv;
8292 atk_obj = gtk_widget_get_accessible (widget);
8293 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8295 if (priv->old_hadj != hadj)
8299 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8300 (gpointer *)&priv->old_hadj);
8302 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8303 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8306 priv->old_hadj = hadj;
8309 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8310 (gpointer *)&priv->old_hadj);
8311 g_signal_connect (hadj,
8313 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8317 if (priv->old_vadj != vadj)
8321 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8322 (gpointer *)&priv->old_vadj);
8324 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8325 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8328 priv->old_vadj = vadj;
8331 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8332 (gpointer *)&priv->old_vadj);
8333 g_signal_connect (vadj,
8335 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8342 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8349 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8350 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8356 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8361 GtkIconViewAccessiblePrivate *priv;
8362 GtkIconViewItemAccessibleInfo *info;
8363 GtkIconViewAccessible *view;
8364 GtkIconViewItemAccessible *item;
8370 index = gtk_tree_path_get_indices(path)[0];
8371 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8372 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8373 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8375 items = priv->items;
8380 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8381 if (info->index != item->item->index)
8383 if (info->index < index)
8384 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8386 if (tmp_list == NULL)
8389 info->index = item->item->index;
8392 items = items->next;
8394 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8395 g_signal_emit_by_name (atk_obj, "children_changed::add",
8401 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8405 GtkIconViewAccessiblePrivate *priv;
8406 GtkIconViewItemAccessibleInfo *info;
8407 GtkIconViewAccessible *view;
8408 GtkIconViewItemAccessible *item;
8411 GList *deleted_item;
8415 index = gtk_tree_path_get_indices(path)[0];
8416 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8417 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8418 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8420 items = priv->items;
8422 deleted_item = NULL;
8427 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8428 if (info->index == index)
8430 deleted_item = items;
8432 if (info->index != item->item->index)
8434 if (tmp_list == NULL)
8437 info->index = item->item->index;
8440 items = items->next;
8442 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8445 info = deleted_item->data;
8446 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8448 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8452 priv->items = g_list_remove_link (priv->items, deleted_item);
8460 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8461 GtkIconViewItemAccessibleInfo *i2)
8463 return i1->index - i2->index;
8467 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8473 GtkIconViewAccessiblePrivate *priv;
8474 GtkIconViewItemAccessibleInfo *info;
8475 GtkIconViewAccessible *view;
8476 GtkIconView *icon_view;
8477 GtkIconViewItemAccessible *item;
8482 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8483 icon_view = GTK_ICON_VIEW (user_data);
8484 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8485 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8487 items = priv->items;
8492 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8493 info->index = new_order[info->index];
8494 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8495 item->item = tmp_list->data;
8496 items = items->next;
8498 priv->items = g_list_sort (priv->items,
8499 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8505 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8510 obj = G_OBJECT (model);
8511 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8512 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8513 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8514 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8518 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8522 obj = G_OBJECT (icon_view->priv->model);
8523 g_signal_connect_data (obj, "row-changed",
8524 (GCallback) gtk_icon_view_accessible_model_row_changed,
8525 icon_view, NULL, 0);
8526 g_signal_connect_data (obj, "row-inserted",
8527 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8528 icon_view, NULL, G_CONNECT_AFTER);
8529 g_signal_connect_data (obj, "row-deleted",
8530 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8531 icon_view, NULL, G_CONNECT_AFTER);
8532 g_signal_connect_data (obj, "rows-reordered",
8533 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8534 icon_view, NULL, G_CONNECT_AFTER);
8538 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8540 GtkIconViewItemAccessibleInfo *info;
8543 items = priv->items;
8546 info = (GtkIconViewItemAccessibleInfo *) items->data;
8547 g_object_unref (info->item);
8548 g_free (items->data);
8549 items = items->next;
8551 g_list_free (priv->items);
8556 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8559 GtkIconView *icon_view;
8562 GtkIconViewAccessible *view;
8563 GtkIconViewAccessiblePrivate *priv;
8565 if (strcmp (pspec->name, "model") == 0)
8567 widget = GTK_WIDGET (obj);
8568 atk_obj = gtk_widget_get_accessible (widget);
8569 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8570 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8573 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8574 (gpointer *)&priv->model);
8575 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8577 gtk_icon_view_accessible_clear_cache (priv);
8579 icon_view = GTK_ICON_VIEW (obj);
8580 priv->model = icon_view->priv->model;
8581 /* If there is no model the GtkIconView is probably being destroyed */
8584 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8585 gtk_icon_view_accessible_connect_model_signals (icon_view);
8593 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8596 GtkIconViewAccessiblePrivate *priv;
8597 GtkIconView *icon_view;
8599 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8600 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8602 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8603 g_object_set_qdata (G_OBJECT (accessible),
8604 accessible_private_data_quark,
8607 icon_view = GTK_ICON_VIEW (data);
8608 if (icon_view->priv->hadjustment)
8610 priv->old_hadj = icon_view->priv->hadjustment;
8611 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8612 g_signal_connect (icon_view->priv->hadjustment,
8614 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8617 if (icon_view->priv->vadjustment)
8619 priv->old_vadj = icon_view->priv->vadjustment;
8620 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8621 g_signal_connect (icon_view->priv->vadjustment,
8623 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8626 g_signal_connect_after (data,
8627 "set_scroll_adjustments",
8628 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8630 g_signal_connect (data,
8632 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8635 priv->model = icon_view->priv->model;
8638 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8639 gtk_icon_view_accessible_connect_model_signals (icon_view);
8642 accessible->role = ATK_ROLE_LAYERED_PANE;
8646 gtk_icon_view_accessible_finalize (GObject *object)
8648 GtkIconViewAccessiblePrivate *priv;
8650 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8651 gtk_icon_view_accessible_clear_cache (priv);
8655 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8659 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8660 GtkAccessible *accessible)
8663 GtkIconViewAccessiblePrivate *priv;
8665 atk_obj = ATK_OBJECT (accessible);
8666 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8669 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8670 (gpointer *)&priv->old_hadj);
8672 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8673 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8675 priv->old_hadj = NULL;
8679 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8680 (gpointer *)&priv->old_vadj);
8682 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8683 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8685 priv->old_vadj = NULL;
8690 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8692 if (accessible->widget)
8694 g_signal_connect_after (accessible->widget,
8696 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8699 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8703 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8705 GObjectClass *gobject_class;
8706 GtkAccessibleClass *accessible_class;
8708 accessible_parent_class = g_type_class_peek_parent (klass);
8710 gobject_class = (GObjectClass *)klass;
8711 accessible_class = (GtkAccessibleClass *)klass;
8713 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8715 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8716 klass->ref_child = gtk_icon_view_accessible_ref_child;
8717 klass->initialize = gtk_icon_view_accessible_initialize;
8719 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8721 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8725 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8728 AtkCoordType coord_type)
8731 GtkIconView *icon_view;
8732 GtkIconViewItem *item;
8735 widget = GTK_ACCESSIBLE (component)->widget;
8737 /* State is defunct */
8740 icon_view = GTK_ICON_VIEW (widget);
8741 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8742 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8744 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8750 atk_component_interface_init (AtkComponentIface *iface)
8752 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8756 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8760 GtkIconView *icon_view;
8761 GtkIconViewItem *item;
8764 widget = GTK_ACCESSIBLE (selection)->widget;
8768 icon_view = GTK_ICON_VIEW (widget);
8770 l = g_list_nth (icon_view->priv->items, i);
8775 gtk_icon_view_select_item (icon_view, item);
8781 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8784 GtkIconView *icon_view;
8786 widget = GTK_ACCESSIBLE (selection)->widget;
8790 icon_view = GTK_ICON_VIEW (widget);
8791 gtk_icon_view_unselect_all (icon_view);
8797 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8801 GtkIconView *icon_view;
8802 GtkIconViewItem *item;
8805 widget = GTK_ACCESSIBLE (selection)->widget;
8809 icon_view = GTK_ICON_VIEW (widget);
8811 l = icon_view->priv->items;
8818 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8829 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8832 GtkIconView *icon_view;
8833 GtkIconViewItem *item;
8837 widget = GTK_ACCESSIBLE (selection)->widget;
8841 icon_view = GTK_ICON_VIEW (widget);
8843 l = icon_view->priv->items;
8859 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8863 GtkIconView *icon_view;
8864 GtkIconViewItem *item;
8867 widget = GTK_ACCESSIBLE (selection)->widget;
8871 icon_view = GTK_ICON_VIEW (widget);
8872 l = g_list_nth (icon_view->priv->items, i);
8878 return item->selected;
8882 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8886 GtkIconView *icon_view;
8887 GtkIconViewItem *item;
8891 widget = GTK_ACCESSIBLE (selection)->widget;
8895 icon_view = GTK_ICON_VIEW (widget);
8896 l = icon_view->priv->items;
8905 gtk_icon_view_unselect_item (icon_view, item);
8917 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8920 GtkIconView *icon_view;
8922 widget = GTK_ACCESSIBLE (selection)->widget;
8926 icon_view = GTK_ICON_VIEW (widget);
8927 gtk_icon_view_select_all (icon_view);
8932 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8934 iface->add_selection = gtk_icon_view_accessible_add_selection;
8935 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8936 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8937 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8938 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8939 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8940 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8944 gtk_icon_view_accessible_get_type (void)
8946 static GType type = 0;
8950 static GTypeInfo tinfo =
8953 (GBaseInitFunc) NULL, /* base init */
8954 (GBaseFinalizeFunc) NULL, /* base finalize */
8955 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8956 (GClassFinalizeFunc) NULL, /* class finalize */
8957 NULL, /* class data */
8958 0, /* instance size */
8959 0, /* nb preallocs */
8960 (GInstanceInitFunc) NULL, /* instance init */
8961 NULL /* value table */
8963 static const GInterfaceInfo atk_component_info =
8965 (GInterfaceInitFunc) atk_component_interface_init,
8966 (GInterfaceFinalizeFunc) NULL,
8969 static const GInterfaceInfo atk_selection_info =
8971 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8972 (GInterfaceFinalizeFunc) NULL,
8977 * Figure out the size of the class and instance
8978 * we are deriving from
8980 AtkObjectFactory *factory;
8983 GType derived_atk_type;
8985 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8986 factory = atk_registry_get_factory (atk_get_default_registry (),
8988 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8989 g_type_query (derived_atk_type, &query);
8990 tinfo.class_size = query.class_size;
8991 tinfo.instance_size = query.instance_size;
8993 type = g_type_register_static (derived_atk_type,
8994 "GtkIconViewAccessible",
8996 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8997 &atk_component_info);
8998 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8999 &atk_selection_info);
9005 gtk_icon_view_accessible_new (GObject *obj)
9007 AtkObject *accessible;
9009 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9011 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9012 atk_object_initialize (accessible, obj);
9018 gtk_icon_view_accessible_factory_get_accessible_type (void)
9020 return gtk_icon_view_accessible_get_type ();
9024 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9026 return gtk_icon_view_accessible_new (obj);
9030 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9032 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9033 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9037 gtk_icon_view_accessible_factory_get_type (void)
9039 static GType type = 0;
9043 static const GTypeInfo tinfo =
9045 sizeof (AtkObjectFactoryClass),
9046 NULL, /* base_init */
9047 NULL, /* base_finalize */
9048 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9049 NULL, /* class_finalize */
9050 NULL, /* class_data */
9051 sizeof (AtkObjectFactory),
9052 0, /* n_preallocs */
9056 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9057 "GtkIconViewAccessibleFactory",
9065 gtk_icon_view_get_accessible (GtkWidget *widget)
9067 static gboolean first_time = TRUE;
9071 AtkObjectFactory *factory;
9072 AtkRegistry *registry;
9074 GType derived_atk_type;
9077 * Figure out whether accessibility is enabled by looking at the
9078 * type of the accessible object which would be created for
9079 * the parent type of GtkIconView.
9081 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9083 registry = atk_get_default_registry ();
9084 factory = atk_registry_get_factory (registry,
9086 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9087 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9088 atk_registry_set_factory_type (registry,
9090 gtk_icon_view_accessible_factory_get_type ());
9093 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9096 #define __GTK_ICON_VIEW_C__
9097 #include "gtkaliasdef.c"