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 columns"),
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:reorderable:
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 = NULL;
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_data (icon_view->priv->items,
1757 gtk_tree_path_get_indices(path)[0]);
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;
1971 icon_view->priv->pressed_button = -1;
1975 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1977 return event->button == 1;
1981 gtk_icon_view_button_release (GtkWidget *widget,
1982 GdkEventButton *event)
1984 GtkIconView *icon_view;
1986 icon_view = GTK_ICON_VIEW (widget);
1988 if (icon_view->priv->pressed_button == event->button)
1989 icon_view->priv->pressed_button = -1;
1991 gtk_icon_view_stop_rubberbanding (icon_view);
1993 remove_scroll_timeout (icon_view);
1999 gtk_icon_view_update_rubberband (gpointer data)
2001 GtkIconView *icon_view;
2003 GdkRectangle old_area;
2004 GdkRectangle new_area;
2005 GdkRectangle common;
2006 GdkRegion *invalid_region;
2008 icon_view = GTK_ICON_VIEW (data);
2010 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2015 old_area.x = MIN (icon_view->priv->rubberband_x1,
2016 icon_view->priv->rubberband_x2);
2017 old_area.y = MIN (icon_view->priv->rubberband_y1,
2018 icon_view->priv->rubberband_y2);
2019 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2020 icon_view->priv->rubberband_x1) + 1;
2021 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2022 icon_view->priv->rubberband_y1) + 1;
2024 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2025 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2026 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2027 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2029 invalid_region = gdk_region_rectangle (&old_area);
2030 gdk_region_union_with_rect (invalid_region, &new_area);
2032 gdk_rectangle_intersect (&old_area, &new_area, &common);
2033 if (common.width > 2 && common.height > 2)
2035 GdkRegion *common_region;
2037 /* make sure the border is invalidated */
2043 common_region = gdk_region_rectangle (&common);
2045 gdk_region_subtract (invalid_region, common_region);
2046 gdk_region_destroy (common_region);
2049 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2051 gdk_region_destroy (invalid_region);
2053 icon_view->priv->rubberband_x2 = x;
2054 icon_view->priv->rubberband_y2 = y;
2056 gtk_icon_view_update_rubberband_selection (icon_view);
2060 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2066 g_assert (!icon_view->priv->doing_rubberband);
2068 for (items = icon_view->priv->items; items; items = items->next)
2070 GtkIconViewItem *item = items->data;
2072 item->selected_before_rubberbanding = item->selected;
2075 icon_view->priv->rubberband_x1 = x;
2076 icon_view->priv->rubberband_y1 = y;
2077 icon_view->priv->rubberband_x2 = x;
2078 icon_view->priv->rubberband_y2 = y;
2080 icon_view->priv->doing_rubberband = TRUE;
2082 gtk_grab_add (GTK_WIDGET (icon_view));
2086 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2088 if (!icon_view->priv->doing_rubberband)
2091 icon_view->priv->doing_rubberband = FALSE;
2093 gtk_grab_remove (GTK_WIDGET (icon_view));
2095 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2099 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2102 gint x, y, width, height;
2103 gboolean dirty = FALSE;
2105 x = MIN (icon_view->priv->rubberband_x1,
2106 icon_view->priv->rubberband_x2);
2107 y = MIN (icon_view->priv->rubberband_y1,
2108 icon_view->priv->rubberband_y2);
2109 width = ABS (icon_view->priv->rubberband_x1 -
2110 icon_view->priv->rubberband_x2);
2111 height = ABS (icon_view->priv->rubberband_y1 -
2112 icon_view->priv->rubberband_y2);
2114 for (items = icon_view->priv->items; items; items = items->next)
2116 GtkIconViewItem *item = items->data;
2120 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2121 x, y, width, height);
2123 selected = is_in ^ item->selected_before_rubberbanding;
2125 if (item->selected != selected)
2127 item->selected = selected;
2129 gtk_icon_view_queue_draw_item (icon_view, item);
2134 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2138 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2139 GtkIconViewItem *item,
2148 for (l = icon_view->priv->cell_list; l; l = l->next)
2150 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2152 if (!info->cell->visible)
2155 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2157 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2158 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2166 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2168 gboolean dirty = FALSE;
2171 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2174 for (items = icon_view->priv->items; items; items = items->next)
2176 GtkIconViewItem *item = items->data;
2180 item->selected = FALSE;
2182 gtk_icon_view_queue_draw_item (icon_view, item);
2190 /* GtkIconView signals */
2192 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2193 GtkAdjustment *hadj,
2194 GtkAdjustment *vadj)
2196 gboolean need_adjust = FALSE;
2199 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2201 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2203 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2205 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2207 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2209 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2210 0, 0, NULL, NULL, icon_view);
2211 g_object_unref (icon_view->priv->hadjustment);
2214 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2216 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2217 0, 0, NULL, NULL, icon_view);
2218 g_object_unref (icon_view->priv->vadjustment);
2221 if (icon_view->priv->hadjustment != hadj)
2223 icon_view->priv->hadjustment = hadj;
2224 g_object_ref_sink (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_sink (icon_view->priv->vadjustment);
2237 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2238 G_CALLBACK (gtk_icon_view_adjustment_changed),
2244 gtk_icon_view_adjustment_changed (NULL, icon_view);
2248 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2250 gtk_icon_view_select_all (icon_view);
2254 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2256 gtk_icon_view_unselect_all (icon_view);
2260 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2262 gtk_icon_view_unselect_all (icon_view);
2264 if (icon_view->priv->cursor_item != NULL)
2265 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2269 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2272 GtkCellRendererMode mode;
2273 GtkIconViewCellInfo *info = NULL;
2275 if (!icon_view->priv->cursor_item)
2278 info = g_list_nth_data (icon_view->priv->cell_list,
2279 icon_view->priv->cursor_cell);
2283 g_object_get (info->cell, "mode", &mode, NULL);
2285 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2287 gtk_icon_view_item_activate_cell (icon_view,
2288 icon_view->priv->cursor_item,
2292 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2294 gtk_icon_view_start_editing (icon_view,
2295 icon_view->priv->cursor_item,
2301 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2302 gtk_icon_view_item_activated (icon_view, path);
2303 gtk_tree_path_free (path);
2309 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2311 if (!icon_view->priv->cursor_item)
2314 switch (icon_view->priv->selection_mode)
2316 case GTK_SELECTION_NONE:
2318 case GTK_SELECTION_BROWSE:
2319 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2321 case GTK_SELECTION_SINGLE:
2322 if (icon_view->priv->cursor_item->selected)
2323 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2325 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2327 case GTK_SELECTION_MULTIPLE:
2328 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2329 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2331 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2336 /* Internal functions */
2338 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2339 GtkIconView *icon_view)
2341 if (GTK_WIDGET_REALIZED (icon_view))
2343 gdk_window_move (icon_view->priv->bin_window,
2344 - icon_view->priv->hadjustment->value,
2345 - icon_view->priv->vadjustment->value);
2347 if (icon_view->priv->doing_rubberband)
2348 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2350 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2355 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2360 gint *maximum_width)
2363 gint x, current_width;
2364 GList *items, *last_item;
2371 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2372 max_height = g_new0 (gint, icon_view->priv->n_cells);
2379 gtk_widget_style_get (GTK_WIDGET (icon_view),
2380 "focus-line-width", &focus_width,
2383 x += icon_view->priv->margin + focus_width;
2384 current_width += 2 * (icon_view->priv->margin + focus_width);
2389 GtkIconViewItem *item = items->data;
2391 gtk_icon_view_calculate_item_size (icon_view, item);
2392 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2394 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2396 current_width += item->width;
2398 if (items != first_item)
2400 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2401 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2405 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2407 item->y = *y + focus_width;
2408 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2410 x = current_width - (icon_view->priv->margin + focus_width);
2412 for (i = 0; i < icon_view->priv->n_cells; i++)
2413 max_height[i] = MAX (max_height[i], item->box[i].height);
2415 if (current_width > *maximum_width)
2416 *maximum_width = current_width;
2422 items = items->next;
2427 /* Now go through the row again and align the icons */
2428 for (items = first_item; items != last_item; items = items->next)
2430 GtkIconViewItem *item = items->data;
2432 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2434 /* We may want to readjust the new y coordinate. */
2435 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2436 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2439 item->col = col - 1 - item->col;
2442 g_free (max_height);
2448 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2451 if (upper != adj->upper)
2453 gdouble min = MAX (0.0, upper - adj->page_size);
2454 gboolean value_changed = FALSE;
2458 if (adj->value > min)
2461 value_changed = TRUE;
2464 gtk_adjustment_changed (adj);
2467 gtk_adjustment_value_changed (adj);
2472 gtk_icon_view_layout (GtkIconView *icon_view)
2474 gint y = 0, maximum_width = 0;
2480 if (icon_view->priv->model == NULL)
2483 widget = GTK_WIDGET (icon_view);
2485 item_width = icon_view->priv->item_width;
2489 for (icons = icon_view->priv->items; icons; icons = icons->next)
2491 GtkIconViewItem *item = icons->data;
2492 gtk_icon_view_calculate_item_size (icon_view, item);
2493 item_width = MAX (item_width, item->width);
2497 icons = icon_view->priv->items;
2498 y += icon_view->priv->margin;
2503 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2505 &y, &maximum_width);
2508 while (icons != NULL);
2510 if (maximum_width != icon_view->priv->width)
2512 icon_view->priv->width = maximum_width;
2514 y += icon_view->priv->margin;
2516 if (y != icon_view->priv->height)
2518 icon_view->priv->height = y;
2521 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width);
2522 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height);
2524 if (GTK_WIDGET_REALIZED (icon_view))
2526 gdk_window_resize (icon_view->priv->bin_window,
2527 MAX (icon_view->priv->width, widget->allocation.width),
2528 MAX (icon_view->priv->height, widget->allocation.height));
2531 if (icon_view->priv->layout_idle_id != 0)
2533 g_source_remove (icon_view->priv->layout_idle_id);
2534 icon_view->priv->layout_idle_id = 0;
2537 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2541 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2542 GtkIconViewItem *item,
2543 GtkIconViewCellInfo *info,
2544 GdkRectangle *cell_area)
2546 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2548 cell_area->x = item->box[info->position].x - item->before[info->position];
2549 cell_area->y = item->y;
2550 cell_area->width = item->box[info->position].width +
2551 item->before[info->position] + item->after[info->position];
2552 cell_area->height = item->height;
2556 cell_area->x = item->x;
2557 cell_area->y = item->box[info->position].y - item->before[info->position];
2558 cell_area->width = item->width;
2559 cell_area->height = item->box[info->position].height +
2560 item->before[info->position] + item->after[info->position];
2565 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2566 GtkIconViewItem *item,
2567 GtkIconViewCellInfo *info,
2570 *box = item->box[info->position];
2573 /* try to guess a reasonable wrap width for an implicit text cell renderer
2576 adjust_wrap_width (GtkIconView *icon_view,
2577 GtkIconViewItem *item)
2579 GtkIconViewCellInfo *text_info;
2580 GtkIconViewCellInfo *pixbuf_info;
2581 gint pixbuf_width, wrap_width;
2583 if (icon_view->priv->text_cell != -1 &&
2584 icon_view->priv->pixbuf_cell != -1)
2586 text_info = g_list_nth_data (icon_view->priv->cell_list,
2587 icon_view->priv->text_cell);
2588 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2589 icon_view->priv->pixbuf_cell);
2591 gtk_cell_renderer_get_size (pixbuf_info->cell,
2592 GTK_WIDGET (icon_view),
2597 if (item->width == -1)
2598 wrap_width = pixbuf_width;
2599 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2600 wrap_width = item->width;
2602 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2604 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2609 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2610 GtkIconViewItem *item)
2615 if (item->width != -1 && item->height != -1)
2618 if (item->n_cells != icon_view->priv->n_cells)
2620 g_free (item->before);
2621 g_free (item->after);
2624 item->before = g_new0 (gint, icon_view->priv->n_cells);
2625 item->after = g_new0 (gint, icon_view->priv->n_cells);
2626 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2628 item->n_cells = icon_view->priv->n_cells;
2631 gtk_icon_view_set_cell_data (icon_view, item);
2633 spacing = icon_view->priv->spacing;
2637 for (l = icon_view->priv->cell_list; l; l = l->next)
2639 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2641 if (!info->cell->visible)
2644 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2646 &item->box[info->position].width,
2647 &item->box[info->position].height);
2649 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2651 item->width += item->box[info->position].width
2652 + (info->position > 0 ? spacing : 0);
2653 item->height = MAX (item->height, item->box[info->position].height);
2657 item->width = MAX (item->width, item->box[info->position].width);
2658 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2664 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2665 GtkIconViewItem *item,
2668 GdkRectangle cell_area;
2674 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2676 gtk_icon_view_set_cell_data (icon_view, item);
2678 spacing = icon_view->priv->spacing;
2681 for (i = 0; i < icon_view->priv->n_cells; i++)
2683 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2684 item->height = MAX (item->height, max_height[i]);
2686 item->height += max_height[i] + (i > 0 ? spacing : 0);
2689 cell_area.x = item->x;
2690 cell_area.y = item->y;
2692 for (k = 0; k < 2; k++)
2693 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2695 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2697 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2700 if (!info->cell->visible)
2703 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2705 cell_area.width = item->box[info->position].width;
2706 cell_area.height = item->height;
2710 cell_area.width = item->width;
2711 cell_area.height = max_height[i];
2714 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2716 &item->box[info->position].x, &item->box[info->position].y,
2717 &item->box[info->position].width, &item->box[info->position].height);
2719 item->box[info->position].x += cell_area.x;
2720 item->box[info->position].y += cell_area.y;
2721 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2723 item->before[info->position] = item->box[info->position].x - cell_area.x;
2724 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2725 cell_area.x += cell_area.width + spacing;
2729 if (item->box[info->position].width > item->width)
2731 item->width = item->box[info->position].width;
2732 cell_area.width = item->width;
2734 item->before[info->position] = item->box[info->position].y - cell_area.y;
2735 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2736 cell_area.y += cell_area.height + spacing;
2740 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2742 for (i = 0; i < icon_view->priv->n_cells; i++)
2744 item->box[i].x = item->x + item->width -
2745 (item->box[i].x + item->box[i].width - item->x);
2751 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2753 g_list_foreach (icon_view->priv->items,
2754 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2758 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2765 gtk_icon_view_paint_item (GtkIconView *icon_view,
2767 GtkIconViewItem *item,
2769 GdkDrawable *drawable,
2772 gboolean draw_focus)
2774 gint focus_width, focus_pad;
2776 GdkRectangle cell_area, box;
2780 GtkCellRendererState flags;
2782 if (icon_view->priv->model == NULL)
2785 gtk_icon_view_set_cell_data (icon_view, item);
2787 gtk_widget_style_get (GTK_WIDGET (icon_view),
2788 "focus-line-width", &focus_width,
2789 "focus-padding", &focus_pad,
2792 padding = focus_width;
2796 flags = GTK_CELL_RENDERER_SELECTED;
2797 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2798 state = GTK_STATE_SELECTED;
2800 state = GTK_STATE_ACTIVE;
2805 state = GTK_STATE_NORMAL;
2808 #ifdef DEBUG_ICON_VIEW
2809 gdk_draw_rectangle (drawable,
2810 GTK_WIDGET (icon_view)->style->black_gc,
2813 item->width, item->height);
2817 for (l = icon_view->priv->cell_list; l; l = l->next)
2819 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2821 if (!info->cell->visible)
2824 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2826 /* FIXME we hardwire background drawing behind text
2827 * cell renderers here
2829 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2831 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2832 cairo_rectangle (cr,
2833 x - item->x + box.x,
2834 y - item->y + box.y,
2835 box.width, box.height);
2840 for (l = icon_view->priv->cell_list; l; l = l->next)
2842 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2844 if (!info->cell->visible)
2847 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2849 #ifdef DEBUG_ICON_VIEW
2850 gdk_draw_rectangle (drawable,
2851 GTK_WIDGET (icon_view)->style->black_gc,
2853 x - item->x + cell_area.x,
2854 y - item->y + cell_area.y,
2855 cell_area.width, cell_area.height);
2857 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2859 gdk_draw_rectangle (drawable,
2860 GTK_WIDGET (icon_view)->style->black_gc,
2862 x - item->x + box.x,
2863 y - item->y + box.y,
2864 box.width, box.height);
2867 cell_area.x = x - item->x + cell_area.x;
2868 cell_area.y = y - item->y + cell_area.y;
2870 gtk_cell_renderer_render (info->cell,
2872 GTK_WIDGET (icon_view),
2873 &cell_area, &cell_area, area, flags);
2877 /* FIXME where to draw the focus with generic cell renderers ? */
2879 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2880 item == icon_view->priv->cursor_item)
2881 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2883 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2885 if (!info->cell->visible)
2888 if (icon_view->priv->cursor_cell < 0 &&
2889 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2890 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2891 icon_view->priv->cursor_cell = i;
2893 if (i == icon_view->priv->cursor_cell)
2895 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2897 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2901 GTK_WIDGET (icon_view),
2903 x - item->x + box.x - padding,
2904 y - item->y + box.y - padding,
2905 box.width + 2 * padding,
2906 box.height + 2 * padding);
2913 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2918 GdkRectangle rubber_rect;
2919 GdkColor *fill_color_gdk;
2920 guchar fill_color_alpha;
2922 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2923 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2924 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2925 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2927 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2930 gtk_widget_style_get (GTK_WIDGET (icon_view),
2931 "selection-box-color", &fill_color_gdk,
2932 "selection-box-alpha", &fill_color_alpha,
2935 if (!fill_color_gdk)
2936 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2938 cairo_set_source_rgba (cr,
2939 fill_color_gdk->red / 65535.,
2940 fill_color_gdk->green / 65535.,
2941 fill_color_gdk->blue / 65535.,
2942 fill_color_alpha / 255.);
2945 gdk_cairo_rectangle (cr, &rect);
2949 /* Draw the border without alpha */
2950 cairo_set_source_rgb (cr,
2951 fill_color_gdk->red / 65535.,
2952 fill_color_gdk->green / 65535.,
2953 fill_color_gdk->blue / 65535.);
2954 cairo_rectangle (cr,
2955 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2956 rubber_rect.width - 1, rubber_rect.height - 1);
2960 gdk_color_free (fill_color_gdk);
2964 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2970 index = gtk_tree_path_get_indices (path)[0];
2972 for (l = icon_view->priv->items; l; l = l->next)
2974 GtkIconViewItem *item = l->data;
2976 if (item->index == index)
2978 gtk_icon_view_queue_draw_item (icon_view, item);
2985 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2986 GtkIconViewItem *item)
2991 gtk_widget_style_get (GTK_WIDGET (icon_view),
2992 "focus-line-width", &focus_width,
2995 rect.x = item->x - focus_width;
2996 rect.y = item->y - focus_width;
2997 rect.width = item->width + 2 * focus_width;
2998 rect.height = item->height + 2 * focus_width;
3000 if (icon_view->priv->bin_window)
3001 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3005 layout_callback (gpointer user_data)
3007 GtkIconView *icon_view;
3009 GDK_THREADS_ENTER ();
3011 icon_view = GTK_ICON_VIEW (user_data);
3013 icon_view->priv->layout_idle_id = 0;
3015 gtk_icon_view_layout (icon_view);
3017 GDK_THREADS_LEAVE();
3023 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3025 if (icon_view->priv->layout_idle_id != 0)
3028 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3032 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3033 GtkIconViewItem *item,
3037 AtkObject *item_obj;
3039 if (icon_view->priv->cursor_item == item &&
3040 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3043 if (icon_view->priv->cursor_item != NULL)
3044 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3046 icon_view->priv->cursor_item = item;
3047 if (cursor_cell >= 0)
3048 icon_view->priv->cursor_cell = cursor_cell;
3050 gtk_icon_view_queue_draw_item (icon_view, item);
3052 /* Notify that accessible focus object has changed */
3053 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3054 item_obj = atk_object_ref_accessible_child (obj, item->index);
3056 if (item_obj != NULL)
3058 atk_focus_tracker_notify (item_obj);
3059 g_object_unref (item_obj);
3064 static GtkIconViewItem *
3065 gtk_icon_view_item_new (void)
3067 GtkIconViewItem *item;
3069 item = g_new0 (GtkIconViewItem, 1);
3078 gtk_icon_view_item_free (GtkIconViewItem *item)
3080 g_return_if_fail (item != NULL);
3082 g_free (item->before);
3083 g_free (item->after);
3090 static GtkIconViewItem *
3091 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3094 gboolean only_in_cell,
3095 GtkIconViewCellInfo **cell_at_pos)
3100 for (items = icon_view->priv->items; items; items = items->next)
3102 GtkIconViewItem *item = items->data;
3104 if (x >= item->x - icon_view->priv->row_spacing/2 && x <= item->x + item->width + icon_view->priv->row_spacing/2 &&
3105 y >= item->y - icon_view->priv->column_spacing/2 && y <= item->y + item->height + icon_view->priv->column_spacing/2)
3107 if (only_in_cell || cell_at_pos)
3109 gtk_icon_view_set_cell_data (icon_view, item);
3111 for (l = icon_view->priv->cell_list; l; l = l->next)
3113 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3115 if (!info->cell->visible)
3118 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3120 if ((x >= box.x && x <= box.x + box.width &&
3121 y >= box.y && y <= box.y + box.height) ||
3123 x <= box.x + box.width &&
3125 y <= box.y + box.height))
3128 *cell_at_pos = info;
3138 *cell_at_pos = NULL;
3149 gtk_icon_view_select_item (GtkIconView *icon_view,
3150 GtkIconViewItem *item)
3152 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3153 g_return_if_fail (item != NULL);
3158 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3160 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3161 gtk_icon_view_unselect_all_internal (icon_view);
3163 item->selected = TRUE;
3165 gtk_icon_view_queue_draw_item (icon_view, item);
3167 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3172 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3173 GtkIconViewItem *item)
3175 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3176 g_return_if_fail (item != NULL);
3178 if (!item->selected)
3181 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3182 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3185 item->selected = FALSE;
3187 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3189 gtk_icon_view_queue_draw_item (icon_view, item);
3193 verify_items (GtkIconView *icon_view)
3198 for (items = icon_view->priv->items; items; items = items->next)
3200 GtkIconViewItem *item = items->data;
3202 if (item->index != i)
3203 g_error ("List item does not match its index: "
3204 "item index %d and list index %d\n", item->index, i);
3211 gtk_icon_view_row_changed (GtkTreeModel *model,
3216 GtkIconViewItem *item;
3218 GtkIconView *icon_view;
3220 icon_view = GTK_ICON_VIEW (data);
3222 gtk_icon_view_stop_editing (icon_view, TRUE);
3224 index = gtk_tree_path_get_indices(path)[0];
3225 item = g_list_nth_data (icon_view->priv->items, index);
3227 gtk_icon_view_item_invalidate_size (item);
3228 gtk_icon_view_queue_layout (icon_view);
3230 verify_items (icon_view);
3234 gtk_icon_view_row_inserted (GtkTreeModel *model,
3240 GtkIconViewItem *item;
3241 gboolean iters_persist;
3242 GtkIconView *icon_view;
3245 icon_view = GTK_ICON_VIEW (data);
3247 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3249 index = gtk_tree_path_get_indices(path)[0];
3251 item = gtk_icon_view_item_new ();
3256 item->index = index;
3258 /* FIXME: We can be more efficient here,
3259 we can store a tail pointer and use that when
3260 appending (which is a rather common operation)
3262 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3265 list = g_list_nth (icon_view->priv->items, index + 1);
3266 for (; list; list = list->next)
3273 verify_items (icon_view);
3277 gtk_icon_view_row_deleted (GtkTreeModel *model,
3282 GtkIconView *icon_view;
3283 GtkIconViewItem *item;
3285 gboolean emit = FALSE;
3287 icon_view = GTK_ICON_VIEW (data);
3289 index = gtk_tree_path_get_indices(path)[0];
3291 list = g_list_nth (icon_view->priv->items, index);
3294 gtk_icon_view_stop_editing (icon_view, TRUE);
3296 if (item == icon_view->priv->anchor_item)
3297 icon_view->priv->anchor_item = NULL;
3299 if (item == icon_view->priv->cursor_item)
3300 icon_view->priv->cursor_item = NULL;
3305 gtk_icon_view_item_free (item);
3307 for (next = list->next; next; next = next->next)
3314 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3316 gtk_icon_view_queue_layout (icon_view);
3318 verify_items (icon_view);
3321 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3325 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3326 GtkTreePath *parent,
3333 GtkIconView *icon_view;
3334 GList *items = NULL, *list;
3335 GtkIconViewItem **item_array;
3338 icon_view = GTK_ICON_VIEW (data);
3340 gtk_icon_view_stop_editing (icon_view, TRUE);
3342 length = gtk_tree_model_iter_n_children (model, NULL);
3344 order = g_new (gint, length);
3345 for (i = 0; i < length; i++)
3346 order [new_order[i]] = i;
3348 item_array = g_new (GtkIconViewItem *, length);
3349 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3350 item_array[order[i]] = list->data;
3353 for (i = length - 1; i >= 0; i--)
3355 item_array[i]->index = i;
3356 items = g_list_prepend (items, item_array[i]);
3359 g_free (item_array);
3360 g_list_free (icon_view->priv->items);
3361 icon_view->priv->items = items;
3363 gtk_icon_view_queue_layout (icon_view);
3365 verify_items (icon_view);
3369 gtk_icon_view_build_items (GtkIconView *icon_view)
3373 gboolean iters_persist;
3374 GList *items = NULL;
3376 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3378 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3386 GtkIconViewItem *item = gtk_icon_view_item_new ();
3395 items = g_list_prepend (items, item);
3397 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3399 icon_view->priv->items = g_list_reverse (items);
3403 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3406 GtkMovementStep step,
3410 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3411 I_("move_cursor"), 2,
3415 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3420 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3423 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3428 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3435 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3436 GtkMovementStep step,
3439 GdkModifierType state;
3441 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3442 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3443 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3444 step == GTK_MOVEMENT_DISPLAY_LINES ||
3445 step == GTK_MOVEMENT_PAGES ||
3446 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3448 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3451 gtk_icon_view_stop_editing (icon_view, FALSE);
3452 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3454 if (gtk_get_current_event_state (&state))
3456 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3457 icon_view->priv->ctrl_pressed = TRUE;
3458 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3459 icon_view->priv->shift_pressed = TRUE;
3461 /* else we assume not pressed */
3465 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3466 case GTK_MOVEMENT_VISUAL_POSITIONS:
3467 gtk_icon_view_move_cursor_left_right (icon_view, count);
3469 case GTK_MOVEMENT_DISPLAY_LINES:
3470 gtk_icon_view_move_cursor_up_down (icon_view, count);
3472 case GTK_MOVEMENT_PAGES:
3473 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3475 case GTK_MOVEMENT_BUFFER_ENDS:
3476 gtk_icon_view_move_cursor_start_end (icon_view, count);
3479 g_assert_not_reached ();
3482 icon_view->priv->ctrl_pressed = FALSE;
3483 icon_view->priv->shift_pressed = FALSE;
3488 static GtkIconViewItem *
3489 find_item (GtkIconView *icon_view,
3490 GtkIconViewItem *current,
3496 GtkIconViewItem *item;
3498 /* FIXME: this could be more efficient
3500 row = current->row + row_ofs;
3501 col = current->col + col_ofs;
3503 for (items = icon_view->priv->items; items; items = items->next)
3506 if (item->row == row && item->col == col)
3514 find_cell (GtkIconView *icon_view,
3515 GtkIconViewItem *item,
3517 GtkOrientation orientation,
3528 if (icon_view->priv->orientation != orientation)
3531 gtk_icon_view_set_cell_data (icon_view, item);
3533 focusable = g_new0 (gint, icon_view->priv->n_cells);
3538 for (k = 0; k < 2; k++)
3539 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3541 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3543 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3546 if (!info->cell->visible)
3549 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3552 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3555 current = n_focusable;
3557 focusable[n_focusable] = i;
3563 if (n_focusable == 0)
3564 focusable[n_focusable++] = first_text;
3568 current = step > 0 ? 0 : n_focusable - 1;
3569 cell = focusable[current];
3572 if (current + *count < 0)
3575 *count = current + *count;
3577 else if (current + *count > n_focusable - 1)
3580 *count = current + *count - (n_focusable - 1);
3584 cell = focusable[current + *count];
3593 static GtkIconViewItem *
3594 find_item_page_up_down (GtkIconView *icon_view,
3595 GtkIconViewItem *current,
3602 y = current->y + count * icon_view->priv->vadjustment->page_size;
3604 item = g_list_find (icon_view->priv->items, current);
3609 for (next = item->next; next; next = next->next)
3611 if (((GtkIconViewItem *)next->data)->col == col)
3614 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3624 for (next = item->prev; next; next = next->prev)
3626 if (((GtkIconViewItem *)next->data)->col == col)
3629 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3643 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3644 GtkIconViewItem *anchor,
3645 GtkIconViewItem *cursor)
3648 GtkIconViewItem *item;
3649 gint row1, row2, col1, col2;
3650 gboolean dirty = FALSE;
3652 if (anchor->row < cursor->row)
3663 if (anchor->col < cursor->col)
3674 for (items = icon_view->priv->items; items; items = items->next)
3678 if (row1 <= item->row && item->row <= row2 &&
3679 col1 <= item->col && item->col <= col2)
3681 if (!item->selected)
3684 item->selected = TRUE;
3686 gtk_icon_view_queue_draw_item (icon_view, item);
3694 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3697 GtkIconViewItem *item;
3699 gboolean dirty = FALSE;
3702 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3705 if (!icon_view->priv->cursor_item)
3710 list = icon_view->priv->items;
3712 list = g_list_last (icon_view->priv->items);
3714 item = list ? list->data : NULL;
3719 item = icon_view->priv->cursor_item;
3720 cell = icon_view->priv->cursor_cell;
3721 step = count > 0 ? 1 : -1;
3724 cell = find_cell (icon_view, item, cell,
3725 GTK_ORIENTATION_VERTICAL,
3730 item = find_item (icon_view, item, step, 0);
3731 count = count - step;
3738 if (icon_view->priv->ctrl_pressed ||
3739 !icon_view->priv->shift_pressed ||
3740 !icon_view->priv->anchor_item ||
3741 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3742 icon_view->priv->anchor_item = item;
3744 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3746 if (!icon_view->priv->ctrl_pressed &&
3747 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3749 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3750 dirty = gtk_icon_view_select_all_between (icon_view,
3751 icon_view->priv->anchor_item,
3755 gtk_icon_view_scroll_to_item (icon_view, item);
3758 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3762 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3765 GtkIconViewItem *item;
3766 gboolean dirty = FALSE;
3768 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3771 if (!icon_view->priv->cursor_item)
3776 list = icon_view->priv->items;
3778 list = g_list_last (icon_view->priv->items);
3780 item = list ? list->data : NULL;
3783 item = find_item_page_up_down (icon_view,
3784 icon_view->priv->cursor_item,
3790 if (icon_view->priv->ctrl_pressed ||
3791 !icon_view->priv->shift_pressed ||
3792 !icon_view->priv->anchor_item ||
3793 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3794 icon_view->priv->anchor_item = item;
3796 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3798 if (!icon_view->priv->ctrl_pressed &&
3799 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3801 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3802 dirty = gtk_icon_view_select_all_between (icon_view,
3803 icon_view->priv->anchor_item,
3807 gtk_icon_view_scroll_to_item (icon_view, item);
3810 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3814 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3817 GtkIconViewItem *item;
3819 gboolean dirty = FALSE;
3822 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3825 if (!icon_view->priv->cursor_item)
3830 list = icon_view->priv->items;
3832 list = g_list_last (icon_view->priv->items);
3834 item = list ? list->data : NULL;
3838 item = icon_view->priv->cursor_item;
3839 cell = icon_view->priv->cursor_cell;
3840 step = count > 0 ? 1 : -1;
3843 cell = find_cell (icon_view, item, cell,
3844 GTK_ORIENTATION_HORIZONTAL,
3849 item = find_item (icon_view, item, 0, step);
3850 count = count - step;
3857 if (icon_view->priv->ctrl_pressed ||
3858 !icon_view->priv->shift_pressed ||
3859 !icon_view->priv->anchor_item ||
3860 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3861 icon_view->priv->anchor_item = item;
3863 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3865 if (!icon_view->priv->ctrl_pressed &&
3866 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3868 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3869 dirty = gtk_icon_view_select_all_between (icon_view,
3870 icon_view->priv->anchor_item,
3874 gtk_icon_view_scroll_to_item (icon_view, item);
3877 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3881 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3884 GtkIconViewItem *item;
3886 gboolean dirty = FALSE;
3888 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3892 list = icon_view->priv->items;
3894 list = g_list_last (icon_view->priv->items);
3896 item = list ? list->data : NULL;
3901 if (icon_view->priv->ctrl_pressed ||
3902 !icon_view->priv->shift_pressed ||
3903 !icon_view->priv->anchor_item ||
3904 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3905 icon_view->priv->anchor_item = item;
3907 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3909 if (!icon_view->priv->ctrl_pressed &&
3910 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3912 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3913 dirty = gtk_icon_view_select_all_between (icon_view,
3914 icon_view->priv->anchor_item,
3918 gtk_icon_view_scroll_to_item (icon_view, item);
3921 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3925 * gtk_icon_view_scroll_to_path:
3926 * @icon_view: A #GtkIconView.
3927 * @path: The path of the item to move to.
3928 * @use_align: whether to use alignment arguments, or %FALSE.
3929 * @row_align: The vertical alignment of the item specified by @path.
3930 * @col_align: The horizontal alignment of the item specified by @path.
3932 * Moves the alignments of @icon_view to the position specified by @path.
3933 * @row_align determines where the row is placed, and @col_align determines where
3934 * @column is placed. Both are expected to be between 0.0 and 1.0.
3935 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
3937 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3938 * tree does the minimum amount of work to scroll the item onto the screen.
3939 * This means that the item will be scrolled to the edge closest to its current
3940 * position. If the item is currently visible on the screen, nothing is done.
3942 * This function only works if the model is set, and @path is a valid row on the
3943 * model. If the model changes before the @icon_view is realized, the centered
3944 * path will be modified to reflect this change.
3949 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3955 GtkIconViewItem *item = NULL;
3957 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3958 g_return_if_fail (path != NULL);
3959 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3960 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3962 if (! GTK_WIDGET_REALIZED (icon_view))
3964 if (icon_view->priv->scroll_to_path)
3965 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3967 icon_view->priv->scroll_to_path = NULL;
3970 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3972 icon_view->priv->scroll_to_use_align = use_align;
3973 icon_view->priv->scroll_to_row_align = row_align;
3974 icon_view->priv->scroll_to_col_align = col_align;
3979 if (gtk_tree_path_get_depth (path) > 0)
3980 item = g_list_nth_data (icon_view->priv->items,
3981 gtk_tree_path_get_indices(path)[0]);
3990 gfloat offset, value;
3992 gtk_widget_style_get (GTK_WIDGET (icon_view),
3993 "focus-line-width", &focus_width,
3996 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3998 offset = y + item->y - focus_width -
3999 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4000 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4001 icon_view->priv->vadjustment->lower,
4002 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4003 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4005 offset = x + item->x - focus_width -
4006 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4007 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4008 icon_view->priv->hadjustment->lower,
4009 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4010 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4012 gtk_adjustment_changed (icon_view->priv->hadjustment);
4013 gtk_adjustment_changed (icon_view->priv->vadjustment);
4016 gtk_icon_view_scroll_to_item (icon_view, item);
4021 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4022 GtkIconViewItem *item)
4024 gint x, y, width, height;
4027 gtk_widget_style_get (GTK_WIDGET (icon_view),
4028 "focus-line-width", &focus_width,
4031 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4033 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4035 if (y + item->y - focus_width < 0)
4036 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4037 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4038 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4039 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4040 icon_view->priv->vadjustment->value + y + item->y + item->height
4041 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4043 if (x + item->x - focus_width < 0)
4044 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4045 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4046 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4047 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4048 icon_view->priv->hadjustment->value + x + item->x + item->width
4049 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4051 gtk_adjustment_changed (icon_view->priv->hadjustment);
4052 gtk_adjustment_changed (icon_view->priv->vadjustment);
4055 /* GtkCellLayout implementation */
4056 static GtkIconViewCellInfo *
4057 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4058 GtkCellRenderer *renderer)
4062 for (i = icon_view->priv->cell_list; i; i = i->next)
4064 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4066 if (info->cell == renderer)
4074 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4075 GtkIconViewItem *item)
4078 gboolean iters_persist;
4081 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4087 path = gtk_tree_path_new_from_indices (item->index, -1);
4088 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4089 gtk_tree_path_free (path);
4094 for (i = icon_view->priv->cell_list; i; i = i->next)
4097 GtkIconViewCellInfo *info = i->data;
4099 g_object_freeze_notify (G_OBJECT (info->cell));
4101 for (j = info->attributes; j && j->next; j = j->next->next)
4103 gchar *property = j->data;
4104 gint column = GPOINTER_TO_INT (j->next->data);
4105 GValue value = {0, };
4107 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4109 g_object_set_property (G_OBJECT (info->cell),
4111 g_value_unset (&value);
4115 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4117 icon_view->priv->model,
4121 g_object_thaw_notify (G_OBJECT (info->cell));
4124 adjust_wrap_width (icon_view, item);
4128 free_cell_attributes (GtkIconViewCellInfo *info)
4132 list = info->attributes;
4133 while (list && list->next)
4135 g_free (list->data);
4136 list = list->next->next;
4139 g_slist_free (info->attributes);
4140 info->attributes = NULL;
4144 free_cell_info (GtkIconViewCellInfo *info)
4146 free_cell_attributes (info);
4148 g_object_unref (info->cell);
4151 (* info->destroy) (info->func_data);
4157 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4158 GtkCellRenderer *renderer,
4161 GtkIconViewCellInfo *info;
4162 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4164 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4165 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4167 g_object_ref_sink (renderer);
4169 info = g_new0 (GtkIconViewCellInfo, 1);
4170 info->cell = renderer;
4171 info->expand = expand ? TRUE : FALSE;
4172 info->pack = GTK_PACK_START;
4173 info->position = icon_view->priv->n_cells;
4175 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4176 icon_view->priv->n_cells++;
4180 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4181 GtkCellRenderer *renderer,
4184 GtkIconViewCellInfo *info;
4185 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4187 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4188 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4190 g_object_ref_sink (renderer);
4192 info = g_new0 (GtkIconViewCellInfo, 1);
4193 info->cell = renderer;
4194 info->expand = expand ? TRUE : FALSE;
4195 info->pack = GTK_PACK_END;
4196 info->position = icon_view->priv->n_cells;
4198 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4199 icon_view->priv->n_cells++;
4203 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4204 GtkCellRenderer *renderer,
4205 const gchar *attribute,
4208 GtkIconViewCellInfo *info;
4209 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4211 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4212 g_return_if_fail (info != NULL);
4214 info->attributes = g_slist_prepend (info->attributes,
4215 GINT_TO_POINTER (column));
4216 info->attributes = g_slist_prepend (info->attributes,
4217 g_strdup (attribute));
4221 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4223 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4225 while (icon_view->priv->cell_list)
4227 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4228 free_cell_info (info);
4229 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4230 icon_view->priv->cell_list);
4233 icon_view->priv->n_cells = 0;
4237 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4238 GtkCellRenderer *cell,
4239 GtkCellLayoutDataFunc func,
4241 GDestroyNotify destroy)
4243 GtkIconViewCellInfo *info;
4244 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4246 info = gtk_icon_view_get_cell_info (icon_view, cell);
4247 g_return_if_fail (info != NULL);
4251 GDestroyNotify d = info->destroy;
4253 info->destroy = NULL;
4254 d (info->func_data);
4258 info->func_data = func_data;
4259 info->destroy = destroy;
4263 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4264 GtkCellRenderer *renderer)
4266 GtkIconViewCellInfo *info;
4268 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4270 free_cell_attributes (info);
4274 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4275 GtkCellRenderer *cell,
4278 GtkIconView *icon_view;
4280 GtkIconViewCellInfo *info;
4283 icon_view = GTK_ICON_VIEW (layout);
4285 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4287 info = gtk_icon_view_get_cell_info (icon_view, cell);
4289 g_return_if_fail (info != NULL);
4290 g_return_if_fail (position >= 0);
4292 link = g_list_find (icon_view->priv->cell_list, info);
4294 g_return_if_fail (link != NULL);
4296 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4298 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4301 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4308 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4315 * gtk_icon_view_new:
4317 * Creates a new #GtkIconView widget
4319 * Return value: A newly created #GtkIconView widget
4324 gtk_icon_view_new (void)
4326 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4330 * gtk_icon_view_new_with_model:
4331 * @model: The model.
4333 * Creates a new #GtkIconView widget with the model @model.
4335 * Return value: A newly created #GtkIconView widget.
4340 gtk_icon_view_new_with_model (GtkTreeModel *model)
4342 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4347 * gtk_icon_view_get_path_at_pos:
4348 * @icon_view: A #GtkIconView.
4349 * @x: The x position to be identified
4350 * @y: The y position to be identified
4352 * Finds the path at the point (@x, @y), relative to widget coordinates.
4353 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4354 * the cell at the specified position.
4356 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4357 * if no icon exists at that position.
4362 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4366 GtkIconViewItem *item;
4369 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4371 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4376 path = gtk_tree_path_new_from_indices (item->index, -1);
4382 * gtk_icon_view_get_item_at_pos:
4383 * @icon_view: A #GtkIconView.
4384 * @x: The x position to be identified
4385 * @y: The y position to be identified
4386 * @path: Return location for the path, or %NULL
4387 * @cell: Return location for the renderer responsible for the cell
4388 * at (@x, @y), or %NULL
4390 * Finds the path at the point (@x, @y), relative to widget coordinates.
4391 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4392 * obtains the cell at the specified position. The returned path should
4393 * be freed with gtk_tree_path_free().
4395 * Return value: %TRUE if an item exists at the specified position
4400 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4404 GtkCellRenderer **cell)
4406 GtkIconViewItem *item;
4407 GtkIconViewCellInfo *info;
4409 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4411 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4416 *path = gtk_tree_path_new_from_indices (item->index, -1);
4429 return (item != NULL);
4434 * gtk_icon_view_get_visible_range:
4435 * @icon_view: A #GtkIconView
4436 * @start_path: Return location for start of region, or %NULL
4437 * @end_path: Return location for end of region, or %NULL
4439 * Sets @start_path and @end_path to be the first and last visible path.
4440 * Note that there may be invisible paths in between.
4442 * Both paths should be freed with gtk_tree_path_free() after use.
4444 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4449 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4450 GtkTreePath **start_path,
4451 GtkTreePath **end_path)
4453 gint start_index = -1;
4454 gint end_index = -1;
4457 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4459 if (icon_view->priv->hadjustment == NULL ||
4460 icon_view->priv->vadjustment == NULL)
4463 if (start_path == NULL && end_path == NULL)
4466 for (icons = icon_view->priv->items; icons; icons = icons->next)
4468 GtkIconViewItem *item = icons->data;
4470 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4471 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4472 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4473 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4475 if (start_index == -1)
4476 start_index = item->index;
4477 end_index = item->index;
4481 if (start_path && start_index != -1)
4482 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4483 if (end_path && end_index != -1)
4484 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4486 return start_index != -1;
4490 * gtk_icon_view_selected_foreach:
4491 * @icon_view: A #GtkIconView.
4492 * @func: The funcion to call for each selected icon.
4493 * @data: User data to pass to the function.
4495 * Calls a function for each selected icon. Note that the model or
4496 * selection cannot be modified from within this function.
4501 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4502 GtkIconViewForeachFunc func,
4507 for (list = icon_view->priv->items; list; list = list->next)
4509 GtkIconViewItem *item = list->data;
4510 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4513 (* func) (icon_view, path, data);
4515 gtk_tree_path_free (path);
4520 * gtk_icon_view_set_selection_mode:
4521 * @icon_view: A #GtkIconView.
4522 * @mode: The selection mode
4524 * Sets the selection mode of the @icon_view.
4529 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4530 GtkSelectionMode mode)
4532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4534 if (mode == icon_view->priv->selection_mode)
4537 if (mode == GTK_SELECTION_NONE ||
4538 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4539 gtk_icon_view_unselect_all (icon_view);
4541 icon_view->priv->selection_mode = mode;
4543 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4547 * gtk_icon_view_get_selection_mode:
4548 * @icon_view: A #GtkIconView.
4550 * Gets the selection mode of the @icon_view.
4552 * Return value: the current selection mode
4557 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4559 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4561 return icon_view->priv->selection_mode;
4565 * gtk_icon_view_set_model:
4566 * @icon_view: A #GtkIconView.
4567 * @model: The model.
4569 * Sets the model for a #GtkIconView.
4570 * If the @icon_view already has a model set, it will remove
4571 * it before setting the new model. If @model is %NULL, then
4572 * it will unset the old model.
4577 gtk_icon_view_set_model (GtkIconView *icon_view,
4578 GtkTreeModel *model)
4580 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4581 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4583 if (icon_view->priv->model == model)
4586 if (icon_view->priv->scroll_to_path)
4588 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4589 icon_view->priv->scroll_to_path = NULL;
4592 gtk_icon_view_stop_editing (icon_view, TRUE);
4598 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4600 if (icon_view->priv->pixbuf_column != -1)
4602 column_type = gtk_tree_model_get_column_type (model,
4603 icon_view->priv->pixbuf_column);
4605 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4608 if (icon_view->priv->text_column != -1)
4610 column_type = gtk_tree_model_get_column_type (model,
4611 icon_view->priv->text_column);
4613 g_return_if_fail (column_type == G_TYPE_STRING);
4616 if (icon_view->priv->markup_column != -1)
4618 column_type = gtk_tree_model_get_column_type (model,
4619 icon_view->priv->markup_column);
4621 g_return_if_fail (column_type == G_TYPE_STRING);
4626 if (icon_view->priv->model)
4628 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4629 gtk_icon_view_row_changed,
4631 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4632 gtk_icon_view_row_inserted,
4634 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4635 gtk_icon_view_row_deleted,
4637 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4638 gtk_icon_view_rows_reordered,
4641 g_object_unref (icon_view->priv->model);
4643 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4644 g_list_free (icon_view->priv->items);
4645 icon_view->priv->items = NULL;
4646 icon_view->priv->anchor_item = NULL;
4647 icon_view->priv->cursor_item = NULL;
4648 icon_view->priv->last_single_clicked = NULL;
4649 icon_view->priv->width = 0;
4650 icon_view->priv->height = 0;
4653 icon_view->priv->model = model;
4655 if (icon_view->priv->model)
4657 g_object_ref (icon_view->priv->model);
4658 g_signal_connect (icon_view->priv->model,
4660 G_CALLBACK (gtk_icon_view_row_changed),
4662 g_signal_connect (icon_view->priv->model,
4664 G_CALLBACK (gtk_icon_view_row_inserted),
4666 g_signal_connect (icon_view->priv->model,
4668 G_CALLBACK (gtk_icon_view_row_deleted),
4670 g_signal_connect (icon_view->priv->model,
4672 G_CALLBACK (gtk_icon_view_rows_reordered),
4675 gtk_icon_view_build_items (icon_view);
4677 gtk_icon_view_queue_layout (icon_view);
4680 g_object_notify (G_OBJECT (icon_view), "model");
4682 if (GTK_WIDGET_REALIZED (icon_view))
4683 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4687 * gtk_icon_view_get_model:
4688 * @icon_view: a #GtkIconView
4690 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4693 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4698 gtk_icon_view_get_model (GtkIconView *icon_view)
4700 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4702 return icon_view->priv->model;
4706 update_text_cell (GtkIconView *icon_view)
4708 GtkIconViewCellInfo *info;
4712 if (icon_view->priv->text_column == -1 &&
4713 icon_view->priv->markup_column == -1)
4715 if (icon_view->priv->text_cell != -1)
4717 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4718 icon_view->priv->pixbuf_cell--;
4720 info = g_list_nth_data (icon_view->priv->cell_list,
4721 icon_view->priv->text_cell);
4723 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4725 free_cell_info (info);
4727 icon_view->priv->n_cells--;
4728 icon_view->priv->text_cell = -1;
4733 if (icon_view->priv->text_cell == -1)
4735 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4736 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4737 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4740 if (info->cell == cell)
4742 icon_view->priv->text_cell = i;
4748 info = g_list_nth_data (icon_view->priv->cell_list,
4749 icon_view->priv->text_cell);
4751 if (icon_view->priv->markup_column != -1)
4752 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4754 "markup", icon_view->priv->markup_column,
4757 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4759 "text", icon_view->priv->text_column,
4762 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4763 g_object_set (info->cell,
4764 "wrap_mode", PANGO_WRAP_CHAR,
4765 "wrap_width", icon_view->priv->item_width,
4770 g_object_set (info->cell,
4771 "wrap_mode", PANGO_WRAP_CHAR,
4772 "wrap_width", icon_view->priv->item_width,
4780 update_pixbuf_cell (GtkIconView *icon_view)
4782 GtkIconViewCellInfo *info;
4786 if (icon_view->priv->pixbuf_column == -1)
4788 if (icon_view->priv->pixbuf_cell != -1)
4790 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4791 icon_view->priv->text_cell--;
4793 info = g_list_nth_data (icon_view->priv->cell_list,
4794 icon_view->priv->pixbuf_cell);
4796 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4798 free_cell_info (info);
4800 icon_view->priv->n_cells--;
4801 icon_view->priv->pixbuf_cell = -1;
4806 if (icon_view->priv->pixbuf_cell == -1)
4808 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4810 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4811 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4814 if (info->cell == cell)
4816 icon_view->priv->pixbuf_cell = i;
4822 info = g_list_nth_data (icon_view->priv->cell_list,
4823 icon_view->priv->pixbuf_cell);
4825 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4827 "pixbuf", icon_view->priv->pixbuf_column,
4830 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4831 g_object_set (info->cell,
4832 "follow_state", TRUE,
4837 g_object_set (info->cell,
4838 "follow_state", TRUE,
4846 * gtk_icon_view_set_text_column:
4847 * @icon_view: A #GtkIconView.
4848 * @column: A column in the currently used model.
4850 * Sets the column with text for @icon_view to be @column. The text
4851 * column must be of type #G_TYPE_STRING.
4856 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4859 if (column == icon_view->priv->text_column)
4863 icon_view->priv->text_column = -1;
4866 if (icon_view->priv->model != NULL)
4870 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4872 g_return_if_fail (column_type == G_TYPE_STRING);
4875 icon_view->priv->text_column = column;
4878 gtk_icon_view_stop_editing (icon_view, TRUE);
4880 update_text_cell (icon_view);
4882 gtk_icon_view_invalidate_sizes (icon_view);
4883 gtk_icon_view_queue_layout (icon_view);
4885 g_object_notify (G_OBJECT (icon_view), "text-column");
4889 * gtk_icon_view_get_text_column:
4890 * @icon_view: A #GtkIconView.
4892 * Returns the column with text for @icon_view.
4894 * Returns: the text column, or -1 if it's unset.
4899 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4901 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4903 return icon_view->priv->text_column;
4907 * gtk_icon_view_set_markup_column:
4908 * @icon_view: A #GtkIconView.
4909 * @column: A column in the currently used model.
4911 * Sets the column with markup information for @icon_view to be
4912 * @column. The markup column must be of type #G_TYPE_STRING.
4913 * If the markup column is set to something, it overrides
4914 * the text column set by gtk_icon_view_set_text_column().
4919 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4922 if (column == icon_view->priv->markup_column)
4926 icon_view->priv->markup_column = -1;
4929 if (icon_view->priv->model != NULL)
4933 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4935 g_return_if_fail (column_type == G_TYPE_STRING);
4938 icon_view->priv->markup_column = column;
4941 gtk_icon_view_stop_editing (icon_view, TRUE);
4943 update_text_cell (icon_view);
4945 gtk_icon_view_invalidate_sizes (icon_view);
4946 gtk_icon_view_queue_layout (icon_view);
4948 g_object_notify (G_OBJECT (icon_view), "markup-column");
4952 * gtk_icon_view_get_markup_column:
4953 * @icon_view: A #GtkIconView.
4955 * Returns the column with markup text for @icon_view.
4957 * Returns: the markup column, or -1 if it's unset.
4962 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4964 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4966 return icon_view->priv->markup_column;
4970 * gtk_icon_view_set_pixbuf_column:
4971 * @icon_view: A #GtkIconView.
4972 * @column: A column in the currently used model.
4974 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4975 * column must be of type #GDK_TYPE_PIXBUF
4980 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4983 if (column == icon_view->priv->pixbuf_column)
4987 icon_view->priv->pixbuf_column = -1;
4990 if (icon_view->priv->model != NULL)
4994 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4996 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4999 icon_view->priv->pixbuf_column = column;
5002 gtk_icon_view_stop_editing (icon_view, TRUE);
5004 update_pixbuf_cell (icon_view);
5006 gtk_icon_view_invalidate_sizes (icon_view);
5007 gtk_icon_view_queue_layout (icon_view);
5009 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5014 * gtk_icon_view_get_pixbuf_column:
5015 * @icon_view: A #GtkIconView.
5017 * Returns the column with pixbufs for @icon_view.
5019 * Returns: the pixbuf column, or -1 if it's unset.
5024 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5026 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5028 return icon_view->priv->pixbuf_column;
5032 * gtk_icon_view_select_path:
5033 * @icon_view: A #GtkIconView.
5034 * @path: The #GtkTreePath to be selected.
5036 * Selects the row at @path.
5041 gtk_icon_view_select_path (GtkIconView *icon_view,
5044 GtkIconViewItem *item = NULL;
5046 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5047 g_return_if_fail (icon_view->priv->model != NULL);
5048 g_return_if_fail (path != NULL);
5050 if (gtk_tree_path_get_depth (path) > 0)
5051 item = g_list_nth_data (icon_view->priv->items,
5052 gtk_tree_path_get_indices(path)[0]);
5055 gtk_icon_view_select_item (icon_view, item);
5059 * gtk_icon_view_unselect_path:
5060 * @icon_view: A #GtkIconView.
5061 * @path: The #GtkTreePath to be unselected.
5063 * Unselects the row at @path.
5068 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5071 GtkIconViewItem *item;
5073 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5074 g_return_if_fail (icon_view->priv->model != NULL);
5075 g_return_if_fail (path != NULL);
5077 item = g_list_nth_data (icon_view->priv->items,
5078 gtk_tree_path_get_indices(path)[0]);
5083 gtk_icon_view_unselect_item (icon_view, item);
5087 * gtk_icon_view_get_selected_items:
5088 * @icon_view: A #GtkIconView.
5090 * Creates a list of paths of all selected items. Additionally, if you are
5091 * planning on modifying the model after calling this function, you may
5092 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5093 * To do this, you can use gtk_tree_row_reference_new().
5095 * To free the return value, use:
5096 * <informalexample><programlisting>
5097 * g_list_foreach (list, gtk_tree_path_free, NULL);
5098 * g_list_free (list);
5099 * </programlisting></informalexample>
5101 * Return value: A #GList containing a #GtkTreePath for each selected row.
5106 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5109 GList *selected = NULL;
5111 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5113 for (list = icon_view->priv->items; list != NULL; list = list->next)
5115 GtkIconViewItem *item = list->data;
5119 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5121 selected = g_list_prepend (selected, path);
5129 * gtk_icon_view_select_all:
5130 * @icon_view: A #GtkIconView.
5132 * Selects all the icons. @icon_view must has its selection mode set
5133 * to #GTK_SELECTION_MULTIPLE.
5138 gtk_icon_view_select_all (GtkIconView *icon_view)
5141 gboolean dirty = FALSE;
5143 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5145 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5148 for (items = icon_view->priv->items; items; items = items->next)
5150 GtkIconViewItem *item = items->data;
5152 if (!item->selected)
5155 item->selected = TRUE;
5156 gtk_icon_view_queue_draw_item (icon_view, item);
5161 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5165 * gtk_icon_view_unselect_all:
5166 * @icon_view: A #GtkIconView.
5168 * Unselects all the icons.
5173 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5175 gboolean dirty = FALSE;
5177 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5179 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5182 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5185 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5189 * gtk_icon_view_path_is_selected:
5190 * @icon_view: A #GtkIconView.
5191 * @path: A #GtkTreePath to check selection on.
5193 * Returns %TRUE if the icon pointed to by @path is currently
5194 * selected. If @icon does not point to a valid location, %FALSE is returned.
5196 * Return value: %TRUE if @path is selected.
5201 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5204 GtkIconViewItem *item;
5206 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5207 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5208 g_return_val_if_fail (path != NULL, FALSE);
5210 item = g_list_nth_data (icon_view->priv->items,
5211 gtk_tree_path_get_indices(path)[0]);
5216 return item->selected;
5220 * gtk_icon_view_item_activated:
5221 * @icon_view: A #GtkIconView
5222 * @path: The #GtkTreePath to be activated
5224 * Activates the item determined by @path.
5229 gtk_icon_view_item_activated (GtkIconView *icon_view,
5232 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5233 g_return_if_fail (path != NULL);
5235 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5239 * gtk_icon_view_set_orientation:
5240 * @icon_view: a #GtkIconView
5241 * @orientation: the relative position of texts and icons
5243 * Sets the ::orientation property which determines whether the labels
5244 * are drawn beside the icons instead of below.
5249 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5250 GtkOrientation orientation)
5252 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5254 if (icon_view->priv->orientation != orientation)
5256 icon_view->priv->orientation = orientation;
5258 gtk_icon_view_stop_editing (icon_view, TRUE);
5259 gtk_icon_view_invalidate_sizes (icon_view);
5260 gtk_icon_view_queue_layout (icon_view);
5262 update_text_cell (icon_view);
5263 update_pixbuf_cell (icon_view);
5265 g_object_notify (G_OBJECT (icon_view), "orientation");
5270 * gtk_icon_view_get_orientation:
5271 * @icon_view: a #GtkIconView
5273 * Returns the value of the ::orientation property which determines
5274 * whether the labels are drawn beside the icons instead of below.
5276 * Return value: the relative position of texts and icons
5281 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5283 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5284 GTK_ORIENTATION_VERTICAL);
5286 return icon_view->priv->orientation;
5290 * gtk_icon_view_set_columns:
5291 * @icon_view: a #GtkIconView
5292 * @columns: the number of columns
5294 * Sets the ::columns property which determines in how
5295 * many columns the icons are arranged. If @columns is
5296 * -1, the number of columns will be chosen automatically
5297 * to fill the available area.
5302 gtk_icon_view_set_columns (GtkIconView *icon_view,
5305 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5307 if (icon_view->priv->columns != columns)
5309 icon_view->priv->columns = columns;
5311 gtk_icon_view_stop_editing (icon_view, TRUE);
5312 gtk_icon_view_queue_layout (icon_view);
5314 g_object_notify (G_OBJECT (icon_view), "columns");
5319 * gtk_icon_view_get_columns:
5320 * @icon_view: a #GtkIconView
5322 * Returns the value of the ::columns property.
5324 * Return value: the number of columns, or -1
5329 gtk_icon_view_get_columns (GtkIconView *icon_view)
5331 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5333 return icon_view->priv->columns;
5337 * gtk_icon_view_set_item_width:
5338 * @icon_view: a #GtkIconView
5339 * @item_width: the width for each item
5341 * Sets the ::item-width property which specifies the width
5342 * to use for each item. If it is set to -1, the icon view will
5343 * automatically determine a suitable item size.
5348 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5351 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5353 if (icon_view->priv->item_width != item_width)
5355 icon_view->priv->item_width = item_width;
5357 gtk_icon_view_stop_editing (icon_view, TRUE);
5358 gtk_icon_view_invalidate_sizes (icon_view);
5359 gtk_icon_view_queue_layout (icon_view);
5361 update_text_cell (icon_view);
5363 g_object_notify (G_OBJECT (icon_view), "item-width");
5368 * gtk_icon_view_get_item_width:
5369 * @icon_view: a #GtkIconView
5371 * Returns the value of the ::item-width property.
5373 * Return value: the width of a single item, or -1
5378 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5380 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5382 return icon_view->priv->item_width;
5387 * gtk_icon_view_set_spacing:
5388 * @icon_view: a #GtkIconView
5389 * @spacing: the spacing
5391 * Sets the ::spacing property which specifies the space
5392 * which is inserted between the cells (i.e. the icon and
5393 * the text) of an item.
5398 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5401 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5403 if (icon_view->priv->spacing != spacing)
5405 icon_view->priv->spacing = spacing;
5407 gtk_icon_view_stop_editing (icon_view, TRUE);
5408 gtk_icon_view_invalidate_sizes (icon_view);
5409 gtk_icon_view_queue_layout (icon_view);
5411 g_object_notify (G_OBJECT (icon_view), "spacing");
5416 * gtk_icon_view_get_spacing:
5417 * @icon_view: a #GtkIconView
5419 * Returns the value of the ::spacing property.
5421 * Return value: the space between cells
5426 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5428 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5430 return icon_view->priv->spacing;
5434 * gtk_icon_view_set_row_spacing:
5435 * @icon_view: a #GtkIconView
5436 * @row_spacing: the row spacing
5438 * Sets the ::row-spacing property which specifies the space
5439 * which is inserted between the rows of the icon view.
5444 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5447 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5449 if (icon_view->priv->row_spacing != row_spacing)
5451 icon_view->priv->row_spacing = row_spacing;
5453 gtk_icon_view_stop_editing (icon_view, TRUE);
5454 gtk_icon_view_invalidate_sizes (icon_view);
5455 gtk_icon_view_queue_layout (icon_view);
5457 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5462 * gtk_icon_view_get_row_spacing:
5463 * @icon_view: a #GtkIconView
5465 * Returns the value of the ::row-spacing property.
5467 * Return value: the space between rows
5472 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5474 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5476 return icon_view->priv->row_spacing;
5480 * gtk_icon_view_set_column_spacing:
5481 * @icon_view: a #GtkIconView
5482 * @column_spacing: the column spacing
5484 * Sets the ::column-spacing property which specifies the space
5485 * which is inserted between the columns of the icon view.
5490 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5491 gint column_spacing)
5493 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5495 if (icon_view->priv->column_spacing != column_spacing)
5497 icon_view->priv->column_spacing = column_spacing;
5499 gtk_icon_view_stop_editing (icon_view, TRUE);
5500 gtk_icon_view_invalidate_sizes (icon_view);
5501 gtk_icon_view_queue_layout (icon_view);
5503 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5508 * gtk_icon_view_get_column_spacing:
5509 * @icon_view: a #GtkIconView
5511 * Returns the value of the ::column-spacing property.
5513 * Return value: the space between columns
5518 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5520 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5522 return icon_view->priv->column_spacing;
5526 * gtk_icon_view_set_margin:
5527 * @icon_view: a #GtkIconView
5528 * @margin: the margin
5530 * Sets the ::margin property which specifies the space
5531 * which is inserted at the top, bottom, left and right
5537 gtk_icon_view_set_margin (GtkIconView *icon_view,
5540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5542 if (icon_view->priv->margin != margin)
5544 icon_view->priv->margin = margin;
5546 gtk_icon_view_stop_editing (icon_view, TRUE);
5547 gtk_icon_view_invalidate_sizes (icon_view);
5548 gtk_icon_view_queue_layout (icon_view);
5550 g_object_notify (G_OBJECT (icon_view), "margin");
5555 * gtk_icon_view_get_margin:
5556 * @icon_view: a #GtkIconView
5558 * Returns the value of the ::margin property.
5560 * Return value: the space at the borders
5565 gtk_icon_view_get_margin (GtkIconView *icon_view)
5567 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5569 return icon_view->priv->margin;
5573 /* Get/set whether drag_motion requested the drag data and
5574 * drag_data_received should thus not actually insert the data,
5575 * since the data doesn't result from a drop.
5578 set_status_pending (GdkDragContext *context,
5579 GdkDragAction suggested_action)
5581 g_object_set_data (G_OBJECT (context),
5582 I_("gtk-icon-view-status-pending"),
5583 GINT_TO_POINTER (suggested_action));
5586 static GdkDragAction
5587 get_status_pending (GdkDragContext *context)
5589 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5590 "gtk-icon-view-status-pending"));
5594 unset_reorderable (GtkIconView *icon_view)
5596 if (icon_view->priv->reorderable)
5598 icon_view->priv->reorderable = FALSE;
5599 g_object_notify (G_OBJECT (icon_view), "reorderable");
5604 clear_source_info (GtkIconView *icon_view)
5606 if (icon_view->priv->source_targets)
5607 gtk_target_list_unref (icon_view->priv->source_targets);
5608 icon_view->priv->source_targets = NULL;
5610 icon_view->priv->source_set = FALSE;
5614 clear_dest_info (GtkIconView *icon_view)
5616 if (icon_view->priv->dest_targets)
5617 gtk_target_list_unref (icon_view->priv->dest_targets);
5618 icon_view->priv->dest_targets = NULL;
5620 icon_view->priv->dest_set = FALSE;
5624 set_source_row (GdkDragContext *context,
5625 GtkTreeModel *model,
5626 GtkTreePath *source_row)
5629 g_object_set_data_full (G_OBJECT (context),
5630 I_("gtk-icon-view-source-row"),
5631 gtk_tree_row_reference_new (model, source_row),
5632 (GDestroyNotify) gtk_tree_row_reference_free);
5634 g_object_set_data_full (G_OBJECT (context),
5635 I_("gtk-icon-view-source-row"),
5640 get_source_row (GdkDragContext *context)
5642 GtkTreeRowReference *ref;
5644 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5647 return gtk_tree_row_reference_get_path (ref);
5654 GtkTreeRowReference *dest_row;
5655 gboolean empty_view_drop;
5656 gboolean drop_append_mode;
5660 dest_row_free (gpointer data)
5662 DestRow *dr = (DestRow *)data;
5664 gtk_tree_row_reference_free (dr->dest_row);
5669 set_dest_row (GdkDragContext *context,
5670 GtkTreeModel *model,
5671 GtkTreePath *dest_row,
5672 gboolean empty_view_drop,
5673 gboolean drop_append_mode)
5679 g_object_set_data_full (G_OBJECT (context),
5680 I_("gtk-icon-view-dest-row"),
5685 dr = g_new0 (DestRow, 1);
5687 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5688 dr->empty_view_drop = empty_view_drop;
5689 dr->drop_append_mode = drop_append_mode;
5690 g_object_set_data_full (G_OBJECT (context),
5691 I_("gtk-icon-view-dest-row"),
5692 dr, (GDestroyNotify) dest_row_free);
5696 get_dest_row (GdkDragContext *context)
5700 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5704 GtkTreePath *path = NULL;
5707 path = gtk_tree_row_reference_get_path (dr->dest_row);
5708 else if (dr->empty_view_drop)
5709 path = gtk_tree_path_new_from_indices (0, -1);
5713 if (path && dr->drop_append_mode)
5714 gtk_tree_path_next (path);
5723 check_model_dnd (GtkTreeModel *model,
5724 GType required_iface,
5725 const gchar *signal)
5727 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5729 g_warning ("You must override the default '%s' handler "
5730 "on GtkIconView when using models that don't support "
5731 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5732 "is to connect to '%s' and call "
5733 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5734 "the default handler from running. Look at the source code "
5735 "for the default handler in gtkiconview.c to get an idea what "
5736 "your handler should do. (gtkiconview.c is in the GTK+ source "
5737 "code.) If you're using GTK+ from a language other than C, "
5738 "there may be a more natural way to override default handlers, e.g. via derivation.",
5739 signal, g_type_name (required_iface), signal);
5747 remove_scroll_timeout (GtkIconView *icon_view)
5749 if (icon_view->priv->scroll_timeout_id != 0)
5751 g_source_remove (icon_view->priv->scroll_timeout_id);
5753 icon_view->priv->scroll_timeout_id = 0;
5758 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5760 gint px, py, x, y, width, height;
5761 gint hoffset, voffset;
5764 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5765 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5767 /* see if we are near the edge. */
5768 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5770 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5772 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5774 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5778 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5779 icon_view->priv->vadjustment->lower,
5780 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5781 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5785 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5786 icon_view->priv->hadjustment->lower,
5787 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5788 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5794 drag_scroll_timeout (gpointer data)
5796 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5798 GDK_THREADS_ENTER ();
5800 gtk_icon_view_autoscroll (icon_view);
5802 GDK_THREADS_LEAVE ();
5809 set_destination (GtkIconView *icon_view,
5810 GdkDragContext *context,
5813 GdkDragAction *suggested_action,
5817 GtkTreePath *path = NULL;
5818 GtkIconViewDropPosition pos;
5819 GtkIconViewDropPosition old_pos;
5820 GtkTreePath *old_dest_path = NULL;
5821 gboolean can_drop = FALSE;
5823 widget = GTK_WIDGET (icon_view);
5825 *suggested_action = 0;
5828 if (!icon_view->priv->dest_set)
5830 /* someone unset us as a drag dest, note that if
5831 * we return FALSE drag_leave isn't called
5834 gtk_icon_view_set_drag_dest_item (icon_view,
5836 GTK_ICON_VIEW_DROP_LEFT);
5838 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5840 return FALSE; /* no longer a drop site */
5843 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5844 if (*target == GDK_NONE)
5847 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5850 GtkTreeModel *model;
5852 /* the row got dropped on empty space, let's setup a special case
5856 gtk_tree_path_free (path);
5858 model = gtk_icon_view_get_model (icon_view);
5860 n_children = gtk_tree_model_iter_n_children (model, NULL);
5863 pos = GTK_ICON_VIEW_DROP_BELOW;
5864 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5868 pos = GTK_ICON_VIEW_DROP_ABOVE;
5869 path = gtk_tree_path_new_from_indices (0, -1);
5879 gtk_icon_view_get_drag_dest_item (icon_view,
5884 gtk_tree_path_free (old_dest_path);
5886 if (TRUE /* FIXME if the location droppable predicate */)
5894 GtkWidget *source_widget;
5896 *suggested_action = context->suggested_action;
5897 source_widget = gtk_drag_get_source_widget (context);
5899 if (source_widget == widget)
5901 /* Default to MOVE, unless the user has
5902 * pressed ctrl or shift to affect available actions
5904 if ((context->actions & GDK_ACTION_MOVE) != 0)
5905 *suggested_action = GDK_ACTION_MOVE;
5908 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5913 /* can't drop here */
5914 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5916 GTK_ICON_VIEW_DROP_LEFT);
5920 gtk_tree_path_free (path);
5926 get_logical_destination (GtkIconView *icon_view,
5927 gboolean *drop_append_mode)
5929 /* adjust path to point to the row the drop goes in front of */
5930 GtkTreePath *path = NULL;
5931 GtkIconViewDropPosition pos;
5933 *drop_append_mode = FALSE;
5935 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5940 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5941 pos == GTK_ICON_VIEW_DROP_BELOW)
5944 GtkTreeModel *model = icon_view->priv->model;
5946 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5947 !gtk_tree_model_iter_next (model, &iter))
5948 *drop_append_mode = TRUE;
5951 *drop_append_mode = FALSE;
5952 gtk_tree_path_next (path);
5960 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5961 GdkEventMotion *event)
5963 GdkDragContext *context;
5964 GtkTreePath *path = NULL;
5966 GtkTreeModel *model;
5967 gboolean retval = FALSE;
5969 if (!icon_view->priv->source_set)
5972 if (icon_view->priv->pressed_button < 0)
5975 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5976 icon_view->priv->press_start_x,
5977 icon_view->priv->press_start_y,
5978 event->x, event->y))
5981 model = gtk_icon_view_get_model (icon_view);
5986 button = icon_view->priv->pressed_button;
5987 icon_view->priv->pressed_button = -1;
5989 path = gtk_icon_view_get_path_at_pos (icon_view,
5990 icon_view->priv->press_start_x,
5991 icon_view->priv->press_start_y);
5996 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5997 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6001 /* FIXME Check whether we're a start button, if not return FALSE and
6005 /* Now we can begin the drag */
6009 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6010 icon_view->priv->source_targets,
6011 icon_view->priv->source_actions,
6015 set_source_row (context, model, path);
6019 gtk_tree_path_free (path);
6024 /* Source side drag signals */
6026 gtk_icon_view_drag_begin (GtkWidget *widget,
6027 GdkDragContext *context)
6029 GtkIconView *icon_view;
6030 GtkIconViewItem *item;
6035 icon_view = GTK_ICON_VIEW (widget);
6037 /* if the user uses a custom DnD impl, we don't set the icon here */
6038 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6041 item = gtk_icon_view_get_item_at_coords (icon_view,
6042 icon_view->priv->press_start_x,
6043 icon_view->priv->press_start_y,
6047 g_return_if_fail (item != NULL);
6049 x = icon_view->priv->press_start_x - item->x + 1;
6050 y = icon_view->priv->press_start_y - item->y + 1;
6052 path = gtk_tree_path_new_from_indices (item->index, -1);
6053 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6054 gtk_tree_path_free (path);
6056 gtk_drag_set_icon_pixmap (context,
6057 gdk_drawable_get_colormap (icon),
6062 g_object_unref (icon);
6066 gtk_icon_view_drag_end (GtkWidget *widget,
6067 GdkDragContext *context)
6073 gtk_icon_view_drag_data_get (GtkWidget *widget,
6074 GdkDragContext *context,
6075 GtkSelectionData *selection_data,
6079 GtkIconView *icon_view;
6080 GtkTreeModel *model;
6081 GtkTreePath *source_row;
6083 icon_view = GTK_ICON_VIEW (widget);
6084 model = gtk_icon_view_get_model (icon_view);
6089 if (!icon_view->priv->dest_set)
6092 source_row = get_source_row (context);
6094 if (source_row == NULL)
6097 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6098 * any model; for DragSource models there are some other targets
6102 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6103 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6108 /* If drag_data_get does nothing, try providing row data. */
6109 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6110 gtk_tree_set_row_drag_data (selection_data,
6115 gtk_tree_path_free (source_row);
6119 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6120 GdkDragContext *context)
6122 GtkTreeModel *model;
6123 GtkIconView *icon_view;
6124 GtkTreePath *source_row;
6126 icon_view = GTK_ICON_VIEW (widget);
6127 model = gtk_icon_view_get_model (icon_view);
6129 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6132 if (!icon_view->priv->dest_set)
6135 source_row = get_source_row (context);
6137 if (source_row == NULL)
6140 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6143 gtk_tree_path_free (source_row);
6145 set_source_row (context, NULL, NULL);
6148 /* Target side drag signals */
6150 gtk_icon_view_drag_leave (GtkWidget *widget,
6151 GdkDragContext *context,
6154 GtkIconView *icon_view;
6156 icon_view = GTK_ICON_VIEW (widget);
6158 /* unset any highlight row */
6159 gtk_icon_view_set_drag_dest_item (icon_view,
6161 GTK_ICON_VIEW_DROP_LEFT);
6163 remove_scroll_timeout (icon_view);
6167 gtk_icon_view_drag_motion (GtkWidget *widget,
6168 GdkDragContext *context,
6173 GtkTreePath *path = NULL;
6174 GtkIconViewDropPosition pos;
6175 GtkIconView *icon_view;
6176 GdkDragAction suggested_action = 0;
6180 icon_view = GTK_ICON_VIEW (widget);
6182 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6185 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6187 /* we only know this *after* set_desination_row */
6188 empty = icon_view->priv->empty_view_drop;
6190 if (path == NULL && !empty)
6192 /* Can't drop here. */
6193 gdk_drag_status (context, 0, time);
6197 if (icon_view->priv->scroll_timeout_id == 0)
6199 icon_view->priv->scroll_timeout_id =
6200 g_timeout_add (50, drag_scroll_timeout, icon_view);
6203 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6205 /* Request data so we can use the source row when
6206 * determining whether to accept the drop
6208 set_status_pending (context, suggested_action);
6209 gtk_drag_get_data (widget, context, target, time);
6213 set_status_pending (context, 0);
6214 gdk_drag_status (context, suggested_action, time);
6219 gtk_tree_path_free (path);
6225 gtk_icon_view_drag_drop (GtkWidget *widget,
6226 GdkDragContext *context,
6231 GtkIconView *icon_view;
6233 GdkDragAction suggested_action = 0;
6234 GdkAtom target = GDK_NONE;
6235 GtkTreeModel *model;
6236 gboolean drop_append_mode;
6238 icon_view = GTK_ICON_VIEW (widget);
6239 model = gtk_icon_view_get_model (icon_view);
6241 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6243 if (!icon_view->priv->dest_set)
6246 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6249 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6252 path = get_logical_destination (icon_view, &drop_append_mode);
6254 if (target != GDK_NONE && path != NULL)
6256 /* in case a motion had requested drag data, change things so we
6257 * treat drag data receives as a drop.
6259 set_status_pending (context, 0);
6260 set_dest_row (context, model, path,
6261 icon_view->priv->empty_view_drop, drop_append_mode);
6265 gtk_tree_path_free (path);
6267 /* Unset this thing */
6268 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6270 if (target != GDK_NONE)
6272 gtk_drag_get_data (widget, context, target, time);
6280 gtk_icon_view_drag_data_received (GtkWidget *widget,
6281 GdkDragContext *context,
6284 GtkSelectionData *selection_data,
6289 gboolean accepted = FALSE;
6290 GtkTreeModel *model;
6291 GtkIconView *icon_view;
6292 GtkTreePath *dest_row;
6293 GdkDragAction suggested_action;
6294 gboolean drop_append_mode;
6296 icon_view = GTK_ICON_VIEW (widget);
6297 model = gtk_icon_view_get_model (icon_view);
6299 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6302 if (!icon_view->priv->dest_set)
6305 suggested_action = get_status_pending (context);
6307 if (suggested_action)
6309 /* We are getting this data due to a request in drag_motion,
6310 * rather than due to a request in drag_drop, so we are just
6311 * supposed to call drag_status, not actually paste in the
6314 path = get_logical_destination (icon_view, &drop_append_mode);
6317 suggested_action = 0;
6319 if (suggested_action)
6321 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6324 suggested_action = 0;
6327 gdk_drag_status (context, suggested_action, time);
6330 gtk_tree_path_free (path);
6332 /* If you can't drop, remove user drop indicator until the next motion */
6333 if (suggested_action == 0)
6334 gtk_icon_view_set_drag_dest_item (icon_view,
6336 GTK_ICON_VIEW_DROP_LEFT);
6341 dest_row = get_dest_row (context);
6343 if (dest_row == NULL)
6346 if (selection_data->length >= 0)
6348 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6354 gtk_drag_finish (context,
6356 (context->action == GDK_ACTION_MOVE),
6359 gtk_tree_path_free (dest_row);
6362 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6365 /* Drag-and-Drop support */
6367 * gtk_icon_view_enable_model_drag_source:
6368 * @icon_view: a #GtkIconTreeView
6369 * @start_button_mask: Mask of allowed buttons to start drag
6370 * @targets: the table of targets that the drag will support
6371 * @n_targets: the number of items in @targets
6372 * @actions: the bitmask of possible actions for a drag from this
6375 * Turns @icon_view into a drag source for automatic DND.
6380 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6381 GdkModifierType start_button_mask,
6382 const GtkTargetEntry *targets,
6384 GdkDragAction actions)
6386 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6388 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6390 clear_source_info (icon_view);
6391 icon_view->priv->start_button_mask = start_button_mask;
6392 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6393 icon_view->priv->source_actions = actions;
6395 icon_view->priv->source_set = TRUE;
6397 unset_reorderable (icon_view);
6401 * gtk_icon_view_enable_model_drag_dest:
6402 * @icon_view: a #GtkIconView
6403 * @targets: the table of targets that the drag will support
6404 * @n_targets: the number of items in @targets
6405 * @actions: the bitmask of possible actions for a drag from this
6408 * Turns @icon_view into a drop destination for automatic DND.
6413 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6414 const GtkTargetEntry *targets,
6416 GdkDragAction actions)
6418 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6420 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6422 clear_dest_info (icon_view);
6424 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6425 icon_view->priv->dest_actions = actions;
6427 icon_view->priv->dest_set = TRUE;
6429 unset_reorderable (icon_view);
6433 * gtk_icon_view_unset_model_drag_source:
6434 * @icon_view: a #GtkIconView
6436 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6441 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6443 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6445 if (icon_view->priv->source_set)
6447 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6448 clear_source_info (icon_view);
6451 unset_reorderable (icon_view);
6455 * gtk_icon_view_unset_model_drag_dest:
6456 * @icon_view: a #GtkIconView
6458 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6463 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6465 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6467 if (icon_view->priv->dest_set)
6469 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6470 clear_dest_info (icon_view);
6473 unset_reorderable (icon_view);
6476 /* These are useful to implement your own custom stuff. */
6478 * gtk_icon_view_set_drag_dest_item:
6479 * @icon_view: a #GtkIconView
6480 * @path: The path of the item to highlight, or %NULL.
6481 * @pos: Specifies where to drop, relative to the item
6483 * Sets the item that is highlighted for feedback.
6488 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6490 GtkIconViewDropPosition pos)
6492 /* Note; this function is exported to allow a custom DND
6493 * implementation, so it can't touch TreeViewDragInfo
6496 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6498 if (icon_view->priv->dest_item)
6500 GtkTreePath *current_path;
6501 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6502 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6503 icon_view->priv->dest_item = NULL;
6505 gtk_icon_view_queue_draw_path (icon_view, current_path);
6506 gtk_tree_path_free (current_path);
6509 /* special case a drop on an empty model */
6510 icon_view->priv->empty_view_drop = FALSE;
6511 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6512 && gtk_tree_path_get_depth (path) == 1
6513 && gtk_tree_path_get_indices (path)[0] == 0)
6517 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6520 if (n_children == 0)
6521 icon_view->priv->empty_view_drop = TRUE;
6524 icon_view->priv->dest_pos = pos;
6528 icon_view->priv->dest_item =
6529 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6530 icon_view->priv->model, path);
6532 gtk_icon_view_queue_draw_path (icon_view, path);
6537 * gtk_icon_view_get_drag_dest_item:
6538 * @icon_view: a #GtkIconView
6539 * @path: Return location for the path of the highlighted item, or %NULL.
6540 * @pos: Return location for the drop position, or %NULL
6542 * Gets information about the item that is highlighted for feedback.
6547 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6549 GtkIconViewDropPosition *pos)
6551 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6555 if (icon_view->priv->dest_item)
6556 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6562 *pos = icon_view->priv->dest_pos;
6566 * gtk_icon_view_get_dest_item_at_pos:
6567 * @icon_view: a #GtkIconView
6568 * @drag_x: the position to determine the destination item for
6569 * @drag_y: the position to determine the destination item for
6570 * @path: Return location for the path of the item, or %NULL.
6571 * @pos: Return location for the drop position, or %NULL
6573 * Determines the destination item for a given position.
6575 * Return value: whether there is an item at the given position.
6580 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6584 GtkIconViewDropPosition *pos)
6586 GtkIconViewItem *item;
6588 /* Note; this function is exported to allow a custom DND
6589 * implementation, so it can't touch TreeViewDragInfo
6592 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6593 g_return_val_if_fail (drag_x >= 0, FALSE);
6594 g_return_val_if_fail (drag_y >= 0, FALSE);
6595 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6601 item = gtk_icon_view_get_item_at_coords (icon_view,
6602 drag_x + icon_view->priv->hadjustment->value,
6603 drag_y + icon_view->priv->vadjustment->value,
6610 *path = gtk_tree_path_new_from_indices (item->index, -1);
6614 if (drag_x < item->x + item->width / 4)
6615 *pos = GTK_ICON_VIEW_DROP_LEFT;
6616 else if (drag_x > item->x + item->width * 3 / 4)
6617 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6618 else if (drag_y < item->y + item->height / 4)
6619 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6620 else if (drag_y > item->y + item->height * 3 / 4)
6621 *pos = GTK_ICON_VIEW_DROP_BELOW;
6623 *pos = GTK_ICON_VIEW_DROP_INTO;
6630 * gtk_icon_view_create_drag_icon:
6631 * @icon_view: a #GtkIconView
6632 * @path: a #GtkTreePath in @icon_view
6634 * Creates a #GdkPixmap representation of the item at @path.
6635 * This image is used for a drag icon.
6637 * Return value: a newly-allocated pixmap of the drag icon.
6642 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6647 GdkPixmap *drawable;
6652 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6653 g_return_val_if_fail (path != NULL, NULL);
6655 widget = GTK_WIDGET (icon_view);
6657 if (!GTK_WIDGET_REALIZED (widget))
6660 index = gtk_tree_path_get_indices (path)[0];
6662 for (l = icon_view->priv->items; l; l = l->next)
6664 GtkIconViewItem *item = l->data;
6666 if (index == item->index)
6668 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6673 cr = gdk_cairo_create (drawable);
6674 cairo_set_line_width (cr, 1.);
6676 gdk_cairo_set_source_color
6677 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6678 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6683 area.width = item->width;
6684 area.height = item->height;
6686 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6687 drawable, 1, 1, FALSE);
6689 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6690 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6703 * gtk_icon_view_get_reorderable:
6704 * @icon_view: a #GtkIconView
6706 * Retrieves whether the user can reorder the list via drag-and-drop.
6707 * See gtk_icon_view_set_reorderable().
6709 * Return value: %TRUE if the list can be reordered.
6714 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6716 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6718 return icon_view->priv->reorderable;
6721 static const GtkTargetEntry item_targets[] = {
6722 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6727 * gtk_icon_view_set_reorderable:
6728 * @icon_view: A #GtkIconView.
6729 * @reorderable: %TRUE, if the list of items can be reordered.
6731 * This function is a convenience function to allow you to reorder models that
6732 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6733 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6734 * the user can reorder the model by dragging and dropping rows. The
6735 * developer can listen to these changes by connecting to the model's
6736 * row_inserted and row_deleted signals.
6738 * This function does not give you any degree of control over the order -- any
6739 * reordering is allowed. If more control is needed, you should probably
6740 * handle drag and drop manually.
6745 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6746 gboolean reorderable)
6748 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6750 reorderable = reorderable != FALSE;
6752 if (icon_view->priv->reorderable == reorderable)
6757 gtk_icon_view_enable_model_drag_source (icon_view,
6760 G_N_ELEMENTS (item_targets),
6762 gtk_icon_view_enable_model_drag_dest (icon_view,
6764 G_N_ELEMENTS (item_targets),
6769 gtk_icon_view_unset_model_drag_source (icon_view);
6770 gtk_icon_view_unset_model_drag_dest (icon_view);
6773 icon_view->priv->reorderable = reorderable;
6775 g_object_notify (G_OBJECT (icon_view), "reorderable");
6779 /* Accessibility Support */
6781 static gpointer accessible_parent_class;
6782 static gpointer accessible_item_parent_class;
6783 static GQuark accessible_private_data_quark = 0;
6785 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6786 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6787 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6789 static GType gtk_icon_view_item_accessible_get_type (void);
6800 GtkIconViewItem *item;
6804 AtkStateSet *state_set;
6808 GtkTextBuffer *text_buffer;
6810 gchar *action_descriptions[LAST_ACTION];
6811 gchar *image_description;
6812 guint action_idle_handler;
6813 } GtkIconViewItemAccessible;
6815 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6821 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6826 typedef struct _GtkIconViewItemAccessibleClass
6828 AtkObjectClass parent_class;
6830 } GtkIconViewItemAccessibleClass;
6832 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6835 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6837 GtkIconViewItemAccessible *item;
6838 GtkIconView *icon_view;
6841 GDK_THREADS_ENTER ();
6843 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6844 item->action_idle_handler = 0;
6846 if (item->widget != NULL)
6848 icon_view = GTK_ICON_VIEW (item->widget);
6849 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6850 gtk_icon_view_item_activated (icon_view, path);
6851 gtk_tree_path_free (path);
6854 GDK_THREADS_LEAVE ();
6860 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6863 GtkIconViewItemAccessible *item;
6865 if (i < 0 || i >= LAST_ACTION)
6868 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6870 if (!GTK_IS_ICON_VIEW (item->widget))
6873 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6878 case ACTION_ACTIVATE:
6879 if (!item->action_idle_handler)
6880 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6883 g_assert_not_reached ();
6891 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6896 static const gchar *
6897 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6900 GtkIconViewItemAccessible *item;
6902 if (i < 0 || i >= LAST_ACTION)
6905 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6907 if (item->action_descriptions[i])
6908 return item->action_descriptions[i];
6910 return gtk_icon_view_item_accessible_action_descriptions[i];
6913 static const gchar *
6914 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6917 if (i < 0 || i >= LAST_ACTION)
6920 return gtk_icon_view_item_accessible_action_names[i];
6924 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6926 const gchar *description)
6928 GtkIconViewItemAccessible *item;
6930 if (i < 0 || i >= LAST_ACTION)
6933 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6935 if (item->action_descriptions[i])
6936 g_free (item->action_descriptions[i]);
6938 item->action_descriptions[i] = g_strdup (description);
6944 atk_action_item_interface_init (AtkActionIface *iface)
6946 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6947 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6948 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6949 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6950 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6953 static const gchar *
6954 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6956 GtkIconViewItemAccessible *item;
6958 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6960 return item->image_description;
6964 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6965 const gchar *description)
6967 GtkIconViewItemAccessible *item;
6969 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6971 g_free (item->image_description);
6972 item->image_description = g_strdup (item->image_description);
6978 get_pixbuf_box (GtkIconView *icon_view,
6979 GtkIconViewItem *item,
6984 for (l = icon_view->priv->cell_list; l; l = l->next)
6986 GtkIconViewCellInfo *info = l->data;
6988 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6990 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7000 get_text (GtkIconView *icon_view,
7001 GtkIconViewItem *item)
7006 for (l = icon_view->priv->cell_list; l; l = l->next)
7008 GtkIconViewCellInfo *info = l->data;
7010 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7012 g_object_get (info->cell, "text", &text, NULL);
7022 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7026 GtkIconViewItemAccessible *item;
7029 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7031 if (!GTK_IS_ICON_VIEW (item->widget))
7034 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7037 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7040 *height = box.height;
7045 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7048 AtkCoordType coord_type)
7050 GtkIconViewItemAccessible *item;
7053 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7055 if (!GTK_IS_ICON_VIEW (item->widget))
7058 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7061 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7063 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7065 *x+= box.x - item->item->x;
7066 *y+= box.y - item->item->y;
7072 atk_image_item_interface_init (AtkImageIface *iface)
7074 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7075 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7076 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7077 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7081 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7085 GtkIconViewItemAccessible *item;
7086 GtkTextIter start, end;
7087 GtkTextBuffer *buffer;
7089 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7091 if (!GTK_IS_ICON_VIEW (item->widget))
7094 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7097 buffer = item->text_buffer;
7098 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7100 gtk_text_buffer_get_end_iter (buffer, &end);
7102 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7104 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7108 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7111 GtkIconViewItemAccessible *item;
7112 GtkTextIter start, end;
7113 GtkTextBuffer *buffer;
7117 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7119 if (!GTK_IS_ICON_VIEW (item->widget))
7122 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7125 buffer = item->text_buffer;
7126 if (offset >= gtk_text_buffer_get_char_count (buffer))
7129 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7131 gtk_text_iter_forward_char (&end);
7132 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7133 unichar = g_utf8_get_char (string);
7141 get_pango_text_offsets (PangoLayout *layout,
7142 GtkTextBuffer *buffer,
7144 AtkTextBoundary boundary_type,
7148 GtkTextIter *start_iter,
7149 GtkTextIter *end_iter)
7151 PangoLayoutIter *iter;
7152 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7153 gint index, start_index, end_index;
7155 gboolean found = FALSE;
7157 text = pango_layout_get_text (layout);
7158 index = g_utf8_offset_to_pointer (text, offset) - text;
7159 iter = pango_layout_get_iter (layout);
7162 line = pango_layout_iter_get_line (iter);
7163 start_index = line->start_index;
7164 end_index = start_index + line->length;
7166 if (index >= start_index && index <= end_index)
7169 * Found line for offset
7175 * We want the previous line
7179 switch (boundary_type)
7181 case ATK_TEXT_BOUNDARY_LINE_START:
7182 end_index = start_index;
7183 start_index = prev_line->start_index;
7185 case ATK_TEXT_BOUNDARY_LINE_END:
7187 start_index = prev_prev_line->start_index +
7188 prev_prev_line->length;
7189 end_index = prev_line->start_index + prev_line->length;
7192 g_assert_not_reached();
7196 start_index = end_index = 0;
7199 switch (boundary_type)
7201 case ATK_TEXT_BOUNDARY_LINE_START:
7202 if (pango_layout_iter_next_line (iter))
7203 end_index = pango_layout_iter_get_line (iter)->start_index;
7205 case ATK_TEXT_BOUNDARY_LINE_END:
7207 start_index = prev_line->start_index +
7211 g_assert_not_reached();
7216 * We want the next line
7218 if (pango_layout_iter_next_line (iter))
7220 line = pango_layout_iter_get_line (iter);
7221 switch (boundary_type)
7223 case ATK_TEXT_BOUNDARY_LINE_START:
7224 start_index = line->start_index;
7225 if (pango_layout_iter_next_line (iter))
7226 end_index = pango_layout_iter_get_line (iter)->start_index;
7228 end_index = start_index + line->length;
7230 case ATK_TEXT_BOUNDARY_LINE_END:
7231 start_index = end_index;
7232 end_index = line->start_index + line->length;
7235 g_assert_not_reached();
7239 start_index = end_index;
7245 prev_prev_line = prev_line;
7248 while (pango_layout_iter_next_line (iter));
7252 start_index = prev_line->start_index + prev_line->length;
7253 end_index = start_index;
7255 pango_layout_iter_free (iter);
7256 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7257 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7259 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7260 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7265 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7267 AtkTextBoundary boundary_type,
7271 GtkIconViewItemAccessible *item;
7272 GtkTextIter start, end;
7273 GtkTextBuffer *buffer;
7275 GtkIconView *icon_view;
7278 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7280 if (!GTK_IS_ICON_VIEW (item->widget))
7283 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7286 buffer = item->text_buffer;
7288 if (!gtk_text_buffer_get_char_count (buffer))
7292 return g_strdup ("");
7294 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7298 switch (boundary_type)
7300 case ATK_TEXT_BOUNDARY_CHAR:
7301 gtk_text_iter_backward_char(&start);
7303 case ATK_TEXT_BOUNDARY_WORD_START:
7304 if (!gtk_text_iter_starts_word (&start))
7305 gtk_text_iter_backward_word_start (&start);
7307 gtk_text_iter_backward_word_start(&start);
7309 case ATK_TEXT_BOUNDARY_WORD_END:
7310 if (gtk_text_iter_inside_word (&start) &&
7311 !gtk_text_iter_starts_word (&start))
7312 gtk_text_iter_backward_word_start (&start);
7313 while (!gtk_text_iter_ends_word (&start))
7315 if (!gtk_text_iter_backward_char (&start))
7319 gtk_text_iter_backward_word_start(&start);
7320 while (!gtk_text_iter_ends_word (&start))
7322 if (!gtk_text_iter_backward_char (&start))
7326 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7327 if (!gtk_text_iter_starts_sentence (&start))
7328 gtk_text_iter_backward_sentence_start (&start);
7330 gtk_text_iter_backward_sentence_start (&start);
7332 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7333 if (gtk_text_iter_inside_sentence (&start) &&
7334 !gtk_text_iter_starts_sentence (&start))
7335 gtk_text_iter_backward_sentence_start (&start);
7336 while (!gtk_text_iter_ends_sentence (&start))
7338 if (!gtk_text_iter_backward_char (&start))
7342 gtk_text_iter_backward_sentence_start (&start);
7343 while (!gtk_text_iter_ends_sentence (&start))
7345 if (!gtk_text_iter_backward_char (&start))
7349 case ATK_TEXT_BOUNDARY_LINE_START:
7350 case ATK_TEXT_BOUNDARY_LINE_END:
7352 icon_view = GTK_ICON_VIEW (item->widget);
7353 /* FIXME we probably have to use GailTextCell to salvage this */
7354 gtk_icon_view_update_item_text (icon_view, item->item);
7355 get_pango_text_offsets (icon_view->priv->layout,
7368 *start_offset = gtk_text_iter_get_offset (&start);
7369 *end_offset = gtk_text_iter_get_offset (&end);
7371 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7375 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7377 AtkTextBoundary boundary_type,
7381 GtkIconViewItemAccessible *item;
7382 GtkTextIter start, end;
7383 GtkTextBuffer *buffer;
7385 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:
7460 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;
7494 GtkIconView *icon_view;
7497 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7499 if (!GTK_IS_ICON_VIEW (item->widget))
7502 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7505 buffer = item->text_buffer;
7507 if (!gtk_text_buffer_get_char_count (buffer))
7511 return g_strdup ("");
7513 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7517 switch (boundary_type)
7519 case ATK_TEXT_BOUNDARY_CHAR:
7520 gtk_text_iter_forward_char(&start);
7521 gtk_text_iter_forward_chars(&end, 2);
7523 case ATK_TEXT_BOUNDARY_WORD_START:
7524 if (gtk_text_iter_inside_word (&end))
7525 gtk_text_iter_forward_word_end (&end);
7526 while (!gtk_text_iter_starts_word (&end))
7528 if (!gtk_text_iter_forward_char (&end))
7532 if (!gtk_text_iter_is_end (&end))
7534 gtk_text_iter_forward_word_end (&end);
7535 while (!gtk_text_iter_starts_word (&end))
7537 if (!gtk_text_iter_forward_char (&end))
7542 case ATK_TEXT_BOUNDARY_WORD_END:
7543 gtk_text_iter_forward_word_end (&end);
7545 if (!gtk_text_iter_is_end (&end))
7546 gtk_text_iter_forward_word_end (&end);
7548 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7549 if (gtk_text_iter_inside_sentence (&end))
7550 gtk_text_iter_forward_sentence_end (&end);
7551 while (!gtk_text_iter_starts_sentence (&end))
7553 if (!gtk_text_iter_forward_char (&end))
7557 if (!gtk_text_iter_is_end (&end))
7559 gtk_text_iter_forward_sentence_end (&end);
7560 while (!gtk_text_iter_starts_sentence (&end))
7562 if (!gtk_text_iter_forward_char (&end))
7567 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7568 gtk_text_iter_forward_sentence_end (&end);
7570 if (!gtk_text_iter_is_end (&end))
7571 gtk_text_iter_forward_sentence_end (&end);
7573 case ATK_TEXT_BOUNDARY_LINE_START:
7574 case ATK_TEXT_BOUNDARY_LINE_END:
7576 icon_view = GTK_ICON_VIEW (item->widget);
7577 /* FIXME we probably have to use GailTextCell to salvage this */
7578 gtk_icon_view_update_item_text (icon_view, item->item);
7579 get_pango_text_offsets (icon_view->priv->layout,
7591 *start_offset = gtk_text_iter_get_offset (&start);
7592 *end_offset = gtk_text_iter_get_offset (&end);
7594 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7598 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7600 GtkIconViewItemAccessible *item;
7602 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7604 if (!GTK_IS_ICON_VIEW (item->widget))
7607 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7610 return gtk_text_buffer_get_char_count (item->text_buffer);
7614 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7620 AtkCoordType coord_type)
7622 GtkIconViewItemAccessible *item;
7624 GtkIconView *icon_view;
7625 PangoRectangle char_rect;
7626 const gchar *item_text;
7630 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7632 if (!GTK_IS_ICON_VIEW (item->widget))
7635 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7639 icon_view = GTK_ICON_VIEW (item->widget);
7640 /* FIXME we probably have to use GailTextCell to salvage this */
7641 gtk_icon_view_update_item_text (icon_view, item->item);
7642 item_text = pango_layout_get_text (icon_view->priv->layout);
7643 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7644 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7646 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7647 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7648 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7649 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7650 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7651 *width = char_rect.width / PANGO_SCALE;
7652 *height = char_rect.height / PANGO_SCALE;
7657 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7660 AtkCoordType coord_type)
7662 GtkIconViewItemAccessible *item;
7665 GtkIconView *icon_view;
7666 const gchar *item_text;
7671 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7673 if (!GTK_IS_ICON_VIEW (item->widget))
7676 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7680 icon_view = GTK_ICON_VIEW (item->widget);
7681 /* FIXME we probably have to use GailTextCell to salvage this */
7682 gtk_icon_view_update_item_text (icon_view, item->item);
7683 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7684 x -= l_x + item->item->layout_x - item->item->x;
7685 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7686 y -= l_y + item->item->layout_y - item->item->y;
7687 item_text = pango_layout_get_text (icon_view->priv->layout);
7688 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7699 offset = g_utf8_strlen (item_text, -1);
7701 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7707 atk_text_item_interface_init (AtkTextIface *iface)
7709 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7710 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7711 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7712 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7713 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7714 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7715 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7716 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7720 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7725 AtkCoordType coord_type)
7727 GtkIconViewItemAccessible *item;
7728 AtkObject *parent_obj;
7731 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7733 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7734 if (!GTK_IS_WIDGET (item->widget))
7737 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7740 *width = item->item->width;
7741 *height = item->item->height;
7742 if (gtk_icon_view_item_accessible_is_showing (item))
7744 parent_obj = gtk_widget_get_accessible (item->widget);
7745 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7746 *x = l_x + item->item->x;
7747 *y = l_y + item->item->y;
7757 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7759 GtkIconViewItemAccessible *item;
7760 GtkWidget *toplevel;
7762 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7764 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7765 if (!GTK_IS_WIDGET (item->widget))
7768 gtk_widget_grab_focus (item->widget);
7769 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7770 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7771 if (GTK_WIDGET_TOPLEVEL (toplevel))
7772 gtk_window_present (GTK_WINDOW (toplevel));
7778 atk_component_item_interface_init (AtkComponentIface *iface)
7780 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7781 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7785 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7786 AtkStateType state_type,
7787 gboolean emit_signal)
7791 rc = atk_state_set_add_state (item->state_set, state_type);
7793 * The signal should only be generated if the value changed,
7794 * not when the item is set up. So states that are set
7795 * initially should pass FALSE as the emit_signal argument.
7800 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7801 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7802 if (state_type == ATK_STATE_VISIBLE)
7803 g_signal_emit_by_name (item, "visible_data_changed");
7810 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7811 AtkStateType state_type,
7812 gboolean emit_signal)
7814 if (atk_state_set_contains_state (item->state_set, state_type))
7818 rc = atk_state_set_remove_state (item->state_set, state_type);
7820 * The signal should only be generated if the value changed,
7821 * not when the item is set up. So states that are set
7822 * initially should pass FALSE as the emit_signal argument.
7827 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7828 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7829 if (state_type == ATK_STATE_VISIBLE)
7830 g_signal_emit_by_name (item, "visible_data_changed");
7840 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7842 GtkIconView *icon_view;
7843 GdkRectangle visible_rect;
7844 gboolean is_showing;
7847 * An item is considered "SHOWING" if any part of the item is in the
7848 * visible rectangle.
7851 if (!GTK_IS_ICON_VIEW (item->widget))
7854 if (item->item == NULL)
7857 icon_view = GTK_ICON_VIEW (item->widget);
7859 if (icon_view->priv->hadjustment)
7860 visible_rect.x += icon_view->priv->hadjustment->value;
7862 if (icon_view->priv->hadjustment)
7863 visible_rect.y += icon_view->priv->vadjustment->value;
7864 visible_rect.width = item->widget->allocation.width;
7865 visible_rect.height = item->widget->allocation.height;
7867 if (((item->item->x + item->item->width) < visible_rect.x) ||
7868 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7869 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7870 (item->item->y > (visible_rect.y + visible_rect.height)))
7879 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7880 gboolean emit_signal)
7882 if (gtk_icon_view_item_accessible_is_showing (item))
7883 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7886 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7891 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7895 item->state_set = atk_state_set_new ();
7897 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7898 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7899 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7900 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7901 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7903 for (i = 0; i < LAST_ACTION; i++)
7904 item->action_descriptions[i] = NULL;
7906 item->image_description = NULL;
7908 item->action_idle_handler = 0;
7912 gtk_icon_view_item_accessible_finalize (GObject *object)
7914 GtkIconViewItemAccessible *item;
7917 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7919 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7922 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7924 if (item->state_set)
7925 g_object_unref (item->state_set);
7927 if (item->text_buffer)
7928 g_object_unref (item->text_buffer);
7930 for (i = 0; i < LAST_ACTION; i++)
7931 g_free (item->action_descriptions[i]);
7933 g_free (item->image_description);
7935 if (item->action_idle_handler)
7937 g_source_remove (item->action_idle_handler);
7938 item->action_idle_handler = 0;
7941 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7944 static G_CONST_RETURN gchar*
7945 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7951 GtkIconViewItemAccessible *item;
7952 GtkTextIter start_iter;
7953 GtkTextIter end_iter;
7955 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7957 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7958 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7960 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7965 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7967 GtkIconViewItemAccessible *item;
7969 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7970 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7973 return gtk_widget_get_accessible (item->widget);
7979 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7981 GtkIconViewItemAccessible *item;
7983 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7984 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7986 return item->item->index;
7989 static AtkStateSet *
7990 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7992 GtkIconViewItemAccessible *item;
7993 GtkIconView *icon_view;
7995 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7996 g_return_val_if_fail (item->state_set, NULL);
8001 icon_view = GTK_ICON_VIEW (item->widget);
8002 if (icon_view->priv->cursor_item == item->item)
8003 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8005 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8007 return g_object_ref (item->state_set);
8011 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8013 GObjectClass *gobject_class;
8015 accessible_item_parent_class = g_type_class_peek_parent (klass);
8017 gobject_class = (GObjectClass *)klass;
8019 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8021 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8022 klass->get_name = gtk_icon_view_item_accessible_get_name;
8023 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8024 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8028 gtk_icon_view_item_accessible_get_type (void)
8030 static GType type = 0;
8034 static const GTypeInfo tinfo =
8036 sizeof (GtkIconViewItemAccessibleClass),
8037 (GBaseInitFunc) NULL, /* base init */
8038 (GBaseFinalizeFunc) NULL, /* base finalize */
8039 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8040 (GClassFinalizeFunc) NULL, /* class finalize */
8041 NULL, /* class data */
8042 sizeof (GtkIconViewItemAccessible), /* instance size */
8043 0, /* nb preallocs */
8044 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8045 NULL /* value table */
8048 static const GInterfaceInfo atk_component_info =
8050 (GInterfaceInitFunc) atk_component_item_interface_init,
8051 (GInterfaceFinalizeFunc) NULL,
8054 static const GInterfaceInfo atk_action_info =
8056 (GInterfaceInitFunc) atk_action_item_interface_init,
8057 (GInterfaceFinalizeFunc) NULL,
8060 static const GInterfaceInfo atk_image_info =
8062 (GInterfaceInitFunc) atk_image_item_interface_init,
8063 (GInterfaceFinalizeFunc) NULL,
8066 static const GInterfaceInfo atk_text_info =
8068 (GInterfaceInitFunc) atk_text_item_interface_init,
8069 (GInterfaceFinalizeFunc) NULL,
8073 type = g_type_register_static (ATK_TYPE_OBJECT,
8074 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8075 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8076 &atk_component_info);
8077 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8079 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8081 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8088 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8089 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8090 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8092 static GType gtk_icon_view_accessible_get_type (void);
8097 } GtkIconViewAccessible;
8103 } GtkIconViewItemAccessibleInfo;
8109 GtkAdjustment *old_hadj;
8110 GtkAdjustment *old_vadj;
8112 GtkTreeModel *model;
8114 } GtkIconViewAccessiblePrivate;
8116 static GtkIconViewAccessiblePrivate *
8117 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8119 return g_object_get_qdata (G_OBJECT (accessible),
8120 accessible_private_data_quark);
8124 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8128 GtkIconViewItemAccessibleInfo *info;
8129 GtkIconViewItemAccessibleInfo *tmp_info;
8130 GtkIconViewAccessiblePrivate *priv;
8133 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8135 info->index = index;
8137 priv = gtk_icon_view_accessible_get_priv (accessible);
8138 items = priv->items;
8141 tmp_info = items->data;
8142 if (tmp_info->index > index)
8144 items = items->next;
8146 priv->items = g_list_insert_before (priv->items, items, info);
8147 priv->old_hadj = NULL;
8148 priv->old_vadj = NULL;
8152 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8154 GtkIconView *icon_view;
8157 widget = GTK_ACCESSIBLE (accessible)->widget;
8161 icon_view = GTK_ICON_VIEW (widget);
8163 return g_list_length (icon_view->priv->items);
8167 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8170 GtkIconViewAccessiblePrivate *priv;
8171 GtkIconViewItemAccessibleInfo *info;
8174 priv = gtk_icon_view_accessible_get_priv (accessible);
8175 items = priv->items;
8180 if (info->index == index)
8182 items = items->next;
8188 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8191 GtkIconView *icon_view;
8195 GtkIconViewItemAccessible *a11y_item;
8197 widget = GTK_ACCESSIBLE (accessible)->widget;
8201 icon_view = GTK_ICON_VIEW (widget);
8202 icons = g_list_nth (icon_view->priv->items, index);
8206 GtkIconViewItem *item = icons->data;
8208 g_return_val_if_fail (item->index == index, NULL);
8209 obj = gtk_icon_view_accessible_find_child (accessible, index);
8212 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8213 gtk_icon_view_item_accessible_info_new (accessible,
8216 obj->role = ATK_ROLE_ICON;
8217 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8218 a11y_item->item = item;
8219 a11y_item->widget = widget;
8220 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8222 gtk_icon_view_set_cell_data (icon_view, item);
8223 gtk_text_buffer_set_text (a11y_item->text_buffer,
8224 get_text (icon_view, item), -1);
8226 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8227 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8235 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8238 GtkIconViewAccessiblePrivate *priv;
8239 GtkIconViewItemAccessibleInfo *info;
8240 GtkIconViewItemAccessible *item;
8243 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8247 gboolean act_on_item;
8249 widget = GTK_ACCESSIBLE (view)->widget;
8253 items = priv->items;
8255 act_on_item = (list == NULL);
8260 info = (GtkIconViewItemAccessibleInfo *)items->data;
8261 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8263 if (act_on_item == FALSE && list == items)
8267 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8269 items = items->next;
8275 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8276 GtkIconView *icon_view)
8279 GtkIconViewAccessible *view;
8282 * The scrollbars have changed
8284 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8285 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8287 gtk_icon_view_accessible_traverse_items (view, NULL);
8291 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8292 GtkAdjustment *hadj,
8293 GtkAdjustment *vadj)
8296 GtkIconViewAccessiblePrivate *priv;
8298 atk_obj = gtk_widget_get_accessible (widget);
8299 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8301 if (priv->old_hadj != hadj)
8305 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8306 (gpointer *)&priv->old_hadj);
8308 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8309 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8312 priv->old_hadj = hadj;
8315 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8316 (gpointer *)&priv->old_hadj);
8317 g_signal_connect (hadj,
8319 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8323 if (priv->old_vadj != vadj)
8327 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8328 (gpointer *)&priv->old_vadj);
8330 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8331 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8334 priv->old_vadj = vadj;
8337 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8338 (gpointer *)&priv->old_vadj);
8339 g_signal_connect (vadj,
8341 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8348 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8355 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8356 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8362 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8367 GtkIconViewAccessiblePrivate *priv;
8368 GtkIconViewItemAccessibleInfo *info;
8369 GtkIconViewAccessible *view;
8370 GtkIconViewItemAccessible *item;
8376 index = gtk_tree_path_get_indices(path)[0];
8377 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8378 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8379 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8381 items = priv->items;
8386 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8387 if (info->index != item->item->index)
8389 if (info->index < index)
8390 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8392 if (tmp_list == NULL)
8395 info->index = item->item->index;
8398 items = items->next;
8400 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8401 g_signal_emit_by_name (atk_obj, "children_changed::add",
8407 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8411 GtkIconViewAccessiblePrivate *priv;
8412 GtkIconViewItemAccessibleInfo *info;
8413 GtkIconViewAccessible *view;
8414 GtkIconViewItemAccessible *item;
8417 GList *deleted_item;
8421 index = gtk_tree_path_get_indices(path)[0];
8422 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8423 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8424 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8426 items = priv->items;
8428 deleted_item = NULL;
8433 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8434 if (info->index == index)
8436 deleted_item = items;
8438 if (info->index != item->item->index)
8440 if (tmp_list == NULL)
8443 info->index = item->item->index;
8446 items = items->next;
8448 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8451 info = deleted_item->data;
8452 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8454 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8458 priv->items = g_list_remove_link (priv->items, deleted_item);
8466 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8467 GtkIconViewItemAccessibleInfo *i2)
8469 return i1->index - i2->index;
8473 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8479 GtkIconViewAccessiblePrivate *priv;
8480 GtkIconViewItemAccessibleInfo *info;
8481 GtkIconViewAccessible *view;
8482 GtkIconView *icon_view;
8483 GtkIconViewItemAccessible *item;
8487 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8488 icon_view = GTK_ICON_VIEW (user_data);
8489 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8490 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8492 items = priv->items;
8496 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8497 info->index = new_order[info->index];
8498 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8499 items = items->next;
8501 priv->items = g_list_sort (priv->items,
8502 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8508 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8513 obj = G_OBJECT (model);
8514 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8515 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8516 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8517 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8521 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8525 obj = G_OBJECT (icon_view->priv->model);
8526 g_signal_connect_data (obj, "row-changed",
8527 (GCallback) gtk_icon_view_accessible_model_row_changed,
8528 icon_view, NULL, 0);
8529 g_signal_connect_data (obj, "row-inserted",
8530 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8531 icon_view, NULL, G_CONNECT_AFTER);
8532 g_signal_connect_data (obj, "row-deleted",
8533 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8534 icon_view, NULL, G_CONNECT_AFTER);
8535 g_signal_connect_data (obj, "rows-reordered",
8536 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8537 icon_view, NULL, G_CONNECT_AFTER);
8541 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8543 GtkIconViewItemAccessibleInfo *info;
8546 items = priv->items;
8549 info = (GtkIconViewItemAccessibleInfo *) items->data;
8550 g_object_unref (info->item);
8551 g_free (items->data);
8552 items = items->next;
8554 g_list_free (priv->items);
8559 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8562 GtkIconView *icon_view;
8565 GtkIconViewAccessiblePrivate *priv;
8567 if (strcmp (pspec->name, "model") == 0)
8569 widget = GTK_WIDGET (obj);
8570 atk_obj = gtk_widget_get_accessible (widget);
8571 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8574 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8575 (gpointer *)&priv->model);
8576 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8578 gtk_icon_view_accessible_clear_cache (priv);
8580 icon_view = GTK_ICON_VIEW (obj);
8581 priv->model = icon_view->priv->model;
8582 /* If there is no model the GtkIconView is probably being destroyed */
8585 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8586 gtk_icon_view_accessible_connect_model_signals (icon_view);
8594 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8597 GtkIconViewAccessiblePrivate *priv;
8598 GtkIconView *icon_view;
8600 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8601 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8603 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8604 g_object_set_qdata (G_OBJECT (accessible),
8605 accessible_private_data_quark,
8608 icon_view = GTK_ICON_VIEW (data);
8609 if (icon_view->priv->hadjustment)
8611 priv->old_hadj = icon_view->priv->hadjustment;
8612 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8613 g_signal_connect (icon_view->priv->hadjustment,
8615 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8618 if (icon_view->priv->vadjustment)
8620 priv->old_vadj = icon_view->priv->vadjustment;
8621 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8622 g_signal_connect (icon_view->priv->vadjustment,
8624 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8627 g_signal_connect_after (data,
8628 "set_scroll_adjustments",
8629 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8631 g_signal_connect (data,
8633 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8636 priv->model = icon_view->priv->model;
8639 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8640 gtk_icon_view_accessible_connect_model_signals (icon_view);
8643 accessible->role = ATK_ROLE_LAYERED_PANE;
8647 gtk_icon_view_accessible_finalize (GObject *object)
8649 GtkIconViewAccessiblePrivate *priv;
8651 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8652 gtk_icon_view_accessible_clear_cache (priv);
8656 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8660 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8661 GtkAccessible *accessible)
8664 GtkIconViewAccessiblePrivate *priv;
8666 atk_obj = ATK_OBJECT (accessible);
8667 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8670 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8671 (gpointer *)&priv->old_hadj);
8673 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8674 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8676 priv->old_hadj = NULL;
8680 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8681 (gpointer *)&priv->old_vadj);
8683 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8684 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8686 priv->old_vadj = NULL;
8691 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8693 if (accessible->widget)
8695 g_signal_connect_after (accessible->widget,
8697 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8700 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8704 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8706 GObjectClass *gobject_class;
8707 GtkAccessibleClass *accessible_class;
8709 accessible_parent_class = g_type_class_peek_parent (klass);
8711 gobject_class = (GObjectClass *)klass;
8712 accessible_class = (GtkAccessibleClass *)klass;
8714 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8716 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8717 klass->ref_child = gtk_icon_view_accessible_ref_child;
8718 klass->initialize = gtk_icon_view_accessible_initialize;
8720 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8722 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8726 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8729 AtkCoordType coord_type)
8732 GtkIconView *icon_view;
8733 GtkIconViewItem *item;
8736 widget = GTK_ACCESSIBLE (component)->widget;
8738 /* State is defunct */
8741 icon_view = GTK_ICON_VIEW (widget);
8742 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8743 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8745 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8751 atk_component_interface_init (AtkComponentIface *iface)
8753 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8757 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8761 GtkIconView *icon_view;
8762 GtkIconViewItem *item;
8764 widget = GTK_ACCESSIBLE (selection)->widget;
8768 icon_view = GTK_ICON_VIEW (widget);
8770 item = g_list_nth_data (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);
8873 item = g_list_nth_data (icon_view->priv->items, i);
8877 return item->selected;
8881 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8885 GtkIconView *icon_view;
8886 GtkIconViewItem *item;
8890 widget = GTK_ACCESSIBLE (selection)->widget;
8894 icon_view = GTK_ICON_VIEW (widget);
8895 l = icon_view->priv->items;
8904 gtk_icon_view_unselect_item (icon_view, item);
8916 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8919 GtkIconView *icon_view;
8921 widget = GTK_ACCESSIBLE (selection)->widget;
8925 icon_view = GTK_ICON_VIEW (widget);
8926 gtk_icon_view_select_all (icon_view);
8931 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8933 iface->add_selection = gtk_icon_view_accessible_add_selection;
8934 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8935 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8936 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8937 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8938 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8939 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8943 gtk_icon_view_accessible_get_type (void)
8945 static GType type = 0;
8949 static GTypeInfo tinfo =
8952 (GBaseInitFunc) NULL, /* base init */
8953 (GBaseFinalizeFunc) NULL, /* base finalize */
8954 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8955 (GClassFinalizeFunc) NULL, /* class finalize */
8956 NULL, /* class data */
8957 0, /* instance size */
8958 0, /* nb preallocs */
8959 (GInstanceInitFunc) NULL, /* instance init */
8960 NULL /* value table */
8962 static const GInterfaceInfo atk_component_info =
8964 (GInterfaceInitFunc) atk_component_interface_init,
8965 (GInterfaceFinalizeFunc) NULL,
8968 static const GInterfaceInfo atk_selection_info =
8970 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8971 (GInterfaceFinalizeFunc) NULL,
8976 * Figure out the size of the class and instance
8977 * we are deriving from
8979 AtkObjectFactory *factory;
8982 GType derived_atk_type;
8984 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8985 factory = atk_registry_get_factory (atk_get_default_registry (),
8987 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8988 g_type_query (derived_atk_type, &query);
8989 tinfo.class_size = query.class_size;
8990 tinfo.instance_size = query.instance_size;
8992 type = g_type_register_static (derived_atk_type,
8993 "GtkIconViewAccessible",
8995 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8996 &atk_component_info);
8997 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8998 &atk_selection_info);
9004 gtk_icon_view_accessible_new (GObject *obj)
9006 AtkObject *accessible;
9008 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9010 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9011 atk_object_initialize (accessible, obj);
9017 gtk_icon_view_accessible_factory_get_accessible_type (void)
9019 return gtk_icon_view_accessible_get_type ();
9023 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9025 return gtk_icon_view_accessible_new (obj);
9029 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9031 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9032 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9036 gtk_icon_view_accessible_factory_get_type (void)
9038 static GType type = 0;
9042 static const GTypeInfo tinfo =
9044 sizeof (AtkObjectFactoryClass),
9045 NULL, /* base_init */
9046 NULL, /* base_finalize */
9047 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9048 NULL, /* class_finalize */
9049 NULL, /* class_data */
9050 sizeof (AtkObjectFactory),
9051 0, /* n_preallocs */
9055 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9056 "GtkIconViewAccessibleFactory",
9064 gtk_icon_view_get_accessible (GtkWidget *widget)
9066 static gboolean first_time = TRUE;
9070 AtkObjectFactory *factory;
9071 AtkRegistry *registry;
9073 GType derived_atk_type;
9076 * Figure out whether accessibility is enabled by looking at the
9077 * type of the accessible object which would be created for
9078 * the parent type of GtkIconView.
9080 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9082 registry = atk_get_default_registry ();
9083 factory = atk_registry_get_factory (registry,
9085 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9086 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9087 atk_registry_set_factory_type (registry,
9089 gtk_icon_view_accessible_factory_get_type ());
9092 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9095 #define __GTK_ICON_VIEW_C__
9096 #include "gtkaliasdef.c"