2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
36 #include "gtksignal.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.h"
43 #include "gtktreednd.h"
44 #include "gtkprivate.h"
47 #undef DEBUG_ICON_VIEW
49 #define SCROLL_EDGE_SIZE 15
51 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
53 typedef struct _GtkIconViewItem GtkIconViewItem;
54 struct _GtkIconViewItem
62 gint x, y, width, height;
65 * box[i] is the actual area occupied by cell i,
66 * before, after are used to calculate the cell
67 * area relative to the box.
68 * See gtk_icon_view_get_cell_area().
76 guint selected_before_rubberbanding : 1;
80 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
81 struct _GtkIconViewCellInfo
83 GtkCellRenderer *cell;
93 GtkCellLayoutDataFunc func;
95 GDestroyNotify destroy;
98 typedef struct _GtkIconViewChild GtkIconViewChild;
99 struct _GtkIconViewChild
102 GtkIconViewItem *item;
106 struct _GtkIconViewPrivate
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gboolean doing_rubberband;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
162 GdkModifierType start_button_mask;
167 GtkTargetList *source_targets;
168 GdkDragAction source_actions;
170 GtkTargetList *dest_targets;
171 GdkDragAction dest_actions;
173 GtkTreeRowReference *dest_item;
174 GtkIconViewDropPosition dest_pos;
177 GtkTreeRowReference *scroll_to_path;
178 gfloat scroll_to_row_align;
179 gfloat scroll_to_col_align;
180 guint scroll_to_use_align : 1;
182 guint source_set : 1;
184 guint reorderable : 1;
185 guint empty_view_drop :1;
187 guint ctrl_pressed : 1;
188 guint shift_pressed : 1;
201 ACTIVATE_CURSOR_ITEM,
225 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
226 static void gtk_icon_view_finalize (GObject *object);
227 static void gtk_icon_view_set_property (GObject *object,
231 static void gtk_icon_view_get_property (GObject *object,
236 /* GtkObject vfuncs */
237 static void gtk_icon_view_destroy (GtkObject *object);
239 /* GtkWidget vfuncs */
240 static void gtk_icon_view_realize (GtkWidget *widget);
241 static void gtk_icon_view_unrealize (GtkWidget *widget);
242 static void gtk_icon_view_style_set (GtkWidget *widget,
243 GtkStyle *previous_style);
244 static void gtk_icon_view_state_changed (GtkWidget *widget,
245 GtkStateType previous_state);
246 static void gtk_icon_view_size_request (GtkWidget *widget,
247 GtkRequisition *requisition);
248 static void gtk_icon_view_size_allocate (GtkWidget *widget,
249 GtkAllocation *allocation);
250 static gboolean gtk_icon_view_expose (GtkWidget *widget,
251 GdkEventExpose *expose);
252 static gboolean gtk_icon_view_motion (GtkWidget *widget,
253 GdkEventMotion *event);
254 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
255 GdkEventButton *event);
256 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
257 GdkEventButton *event);
258 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
261 /* GtkContainer vfuncs */
262 static void gtk_icon_view_remove (GtkContainer *container,
264 static void gtk_icon_view_forall (GtkContainer *container,
265 gboolean include_internals,
266 GtkCallback callback,
267 gpointer callback_data);
269 /* GtkIconView vfuncs */
270 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
272 GtkAdjustment *vadj);
273 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
274 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
275 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
276 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
277 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
279 /* Internal functions */
280 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
281 GtkIconView *icon_view);
282 static void gtk_icon_view_layout (GtkIconView *icon_view);
283 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
286 GtkIconViewItem *item,
288 GdkDrawable *drawable,
291 gboolean draw_focus);
292 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
295 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
297 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
298 GtkIconViewItem *item);
299 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
300 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
301 GtkIconViewItem *item,
303 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
306 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
307 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
308 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
309 GtkIconViewItem *item,
314 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
315 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
316 GtkIconViewItem *item);
317 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
318 GtkIconViewItem *item,
320 static void gtk_icon_view_update_rubberband (gpointer data);
321 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
322 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
323 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
326 GtkMovementStep step,
328 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
329 GtkMovementStep step,
331 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
333 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
335 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
337 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
339 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
340 GtkIconViewItem *item);
341 static void gtk_icon_view_select_item (GtkIconView *icon_view,
342 GtkIconViewItem *item);
343 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
344 GtkIconViewItem *item);
345 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
346 GtkIconViewItem *anchor,
347 GtkIconViewItem *cursor);
348 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
351 gboolean only_in_cell,
352 GtkIconViewCellInfo **cell_at_pos);
353 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
354 GtkIconViewItem *item,
355 GtkIconViewCellInfo *cell_info,
356 GdkRectangle *cell_area);
357 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
358 GtkIconViewItem *item,
359 GtkIconViewCellInfo *info,
361 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
362 GtkCellRenderer *renderer);
363 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
364 GtkIconViewItem *item);
365 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
366 GtkCellRenderer *renderer,
368 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
369 GtkCellRenderer *renderer,
371 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
372 GtkCellRenderer *renderer,
373 const gchar *attribute,
375 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
376 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
377 GtkCellRenderer *renderer);
378 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
379 GtkCellRenderer *cell,
380 GtkCellLayoutDataFunc func,
382 GDestroyNotify destroy);
383 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
384 GtkCellRenderer *cell,
386 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
387 GtkIconViewItem *item,
388 GtkIconViewCellInfo *cell_info,
390 static void gtk_icon_view_put (GtkIconView *icon_view,
392 GtkIconViewItem *item,
394 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
395 GtkIconView *icon_view);
396 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
397 GtkIconViewItem *item,
398 GtkIconViewCellInfo *cell_info,
400 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
401 gboolean cancel_editing);
403 /* Source side drag signals */
404 static void gtk_icon_view_drag_begin (GtkWidget *widget,
405 GdkDragContext *context);
406 static void gtk_icon_view_drag_end (GtkWidget *widget,
407 GdkDragContext *context);
408 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
409 GdkDragContext *context,
410 GtkSelectionData *selection_data,
413 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
414 GdkDragContext *context);
416 /* Target side drag signals */
417 static void gtk_icon_view_drag_leave (GtkWidget *widget,
418 GdkDragContext *context,
420 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
421 GdkDragContext *context,
425 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
426 GdkDragContext *context,
430 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
431 GdkDragContext *context,
434 GtkSelectionData *selection_data,
437 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
438 GdkEventMotion *event);
440 static void remove_scroll_timeout (GtkIconView *icon_view);
443 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
445 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
446 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
447 gtk_icon_view_cell_layout_init))
450 gtk_icon_view_class_init (GtkIconViewClass *klass)
452 GObjectClass *gobject_class;
453 GtkObjectClass *object_class;
454 GtkWidgetClass *widget_class;
455 GtkContainerClass *container_class;
456 GtkBindingSet *binding_set;
458 binding_set = gtk_binding_set_by_class (klass);
460 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
462 gobject_class = (GObjectClass *) klass;
463 object_class = (GtkObjectClass *) klass;
464 widget_class = (GtkWidgetClass *) klass;
465 container_class = (GtkContainerClass *) klass;
467 gobject_class->finalize = gtk_icon_view_finalize;
468 gobject_class->set_property = gtk_icon_view_set_property;
469 gobject_class->get_property = gtk_icon_view_get_property;
471 object_class->destroy = gtk_icon_view_destroy;
473 widget_class->realize = gtk_icon_view_realize;
474 widget_class->unrealize = gtk_icon_view_unrealize;
475 widget_class->style_set = gtk_icon_view_style_set;
476 widget_class->get_accessible = gtk_icon_view_get_accessible;
477 widget_class->size_request = gtk_icon_view_size_request;
478 widget_class->size_allocate = gtk_icon_view_size_allocate;
479 widget_class->expose_event = gtk_icon_view_expose;
480 widget_class->motion_notify_event = gtk_icon_view_motion;
481 widget_class->button_press_event = gtk_icon_view_button_press;
482 widget_class->button_release_event = gtk_icon_view_button_release;
483 widget_class->drag_begin = gtk_icon_view_drag_begin;
484 widget_class->drag_end = gtk_icon_view_drag_end;
485 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
486 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
487 widget_class->drag_leave = gtk_icon_view_drag_leave;
488 widget_class->drag_motion = gtk_icon_view_drag_motion;
489 widget_class->drag_drop = gtk_icon_view_drag_drop;
490 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
491 widget_class->state_changed = gtk_icon_view_state_changed;
493 container_class->remove = gtk_icon_view_remove;
494 container_class->forall = gtk_icon_view_forall;
496 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
497 klass->select_all = gtk_icon_view_real_select_all;
498 klass->unselect_all = gtk_icon_view_real_unselect_all;
499 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
500 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
501 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
502 klass->move_cursor = gtk_icon_view_real_move_cursor;
506 * GtkIconView:selection-mode:
508 * The ::selection-mode property specifies the selection mode of
509 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
510 * is enabled, for the other modes, only keyboard selection is possible.
514 g_object_class_install_property (gobject_class,
516 g_param_spec_enum ("selection-mode",
517 P_("Selection mode"),
518 P_("The selection mode"),
519 GTK_TYPE_SELECTION_MODE,
520 GTK_SELECTION_SINGLE,
521 GTK_PARAM_READWRITE));
524 * GtkIconView:pixbuf-column:
526 * The ::pixbuf-column property contains the number of the model column
527 * containing the pixbufs which are displayed. The pixbuf column must be
528 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
529 * display of pixbufs.
533 g_object_class_install_property (gobject_class,
535 g_param_spec_int ("pixbuf-column",
537 P_("Model column used to retrieve the icon pixbuf from"),
539 GTK_PARAM_READWRITE));
542 * GtkIconView:text-column:
544 * The ::text-column property contains the number of the model column
545 * containing the texts which are displayed. The text column must be
546 * of type #G_TYPE_STRING. If this property and the :markup-column
547 * property are both set to -1, no texts are displayed.
551 g_object_class_install_property (gobject_class,
553 g_param_spec_int ("text-column",
555 P_("Model column used to retrieve the text from"),
557 GTK_PARAM_READWRITE));
561 * GtkIconView:markup-column:
563 * The ::markup-column property contains the number of the model column
564 * containing markup information to be displayed. The markup column must be
565 * of type #G_TYPE_STRING. If this property and the :text-column property
566 * are both set to column numbers, it overrides the text column.
567 * If both are set to -1, no texts are displayed.
571 g_object_class_install_property (gobject_class,
573 g_param_spec_int ("markup-column",
575 P_("Model column used to retrieve the text if using Pango markup"),
577 GTK_PARAM_READWRITE));
579 g_object_class_install_property (gobject_class,
581 g_param_spec_object ("model",
582 P_("Icon View Model"),
583 P_("The model for the icon view"),
585 GTK_PARAM_READWRITE));
588 * GtkIconView:columns:
590 * The columns property contains the number of the columns in which the
591 * items should be displayed. If it is -1, the number of columns will
592 * be chosen automatically to fill the available area.
596 g_object_class_install_property (gobject_class,
598 g_param_spec_int ("columns",
599 P_("Number of columns"),
600 P_("Number of columns to display"),
602 GTK_PARAM_READWRITE));
606 * GtkIconView:item-width:
608 * The item-width property specifies the width to use for each item.
609 * If it is set to -1, the icon view will automatically determine a
610 * suitable item size.
614 g_object_class_install_property (gobject_class,
616 g_param_spec_int ("item-width",
617 P_("Width for each item"),
618 P_("The width used for each item"),
620 GTK_PARAM_READWRITE));
623 * GtkIconView:spacing:
625 * The spacing property specifies the space which is inserted between
626 * the cells (i.e. the icon and the text) of an item.
630 g_object_class_install_property (gobject_class,
632 g_param_spec_int ("spacing",
634 P_("Space which is inserted between cells of an item"),
636 GTK_PARAM_READWRITE));
639 * GtkIconView:row-spacing:
641 * The row-spacing property specifies the space which is inserted between
642 * the rows of the icon view.
646 g_object_class_install_property (gobject_class,
648 g_param_spec_int ("row-spacing",
650 P_("Space which is inserted between grid rows"),
652 GTK_PARAM_READWRITE));
655 * GtkIconView:column-spacing:
657 * The column-spacing property specifies the space which is inserted between
658 * the columns of the icon view.
662 g_object_class_install_property (gobject_class,
664 g_param_spec_int ("column-spacing",
665 P_("Column Spacing"),
666 P_("Space which is inserted between grid columns"),
668 GTK_PARAM_READWRITE));
671 * GtkIconView:margin:
673 * The margin property specifies the space which is inserted
674 * at the edges of the icon view.
678 g_object_class_install_property (gobject_class,
680 g_param_spec_int ("margin",
682 P_("Space which is inserted at the edges of the icon view"),
684 GTK_PARAM_READWRITE));
688 * GtkIconView:orientation:
690 * The orientation property specifies how the cells (i.e. the icon and
691 * the text) of the item are positioned relative to each other.
695 g_object_class_install_property (gobject_class,
697 g_param_spec_enum ("orientation",
699 P_("How the text and icon of each item are positioned relative to each other"),
700 GTK_TYPE_ORIENTATION,
701 GTK_ORIENTATION_VERTICAL,
702 GTK_PARAM_READWRITE));
705 * GtkIconView:reorderable:
707 * The reorderable property specifies if the items can be reordered
712 g_object_class_install_property (gobject_class,
714 g_param_spec_boolean ("reorderable",
716 P_("View is reorderable"),
720 /* Style properties */
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_boxed ("selection-box-color",
723 P_("Selection Box Color"),
724 P_("Color of the selection box"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_uchar ("selection-box-alpha",
730 P_("Selection Box Alpha"),
731 P_("Opacity of the selection box"),
734 GTK_PARAM_READABLE));
737 widget_class->set_scroll_adjustments_signal =
738 g_signal_new (I_("set_scroll_adjustments"),
739 G_TYPE_FROM_CLASS (gobject_class),
741 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
743 _gtk_marshal_VOID__OBJECT_OBJECT,
745 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
747 icon_view_signals[ITEM_ACTIVATED] =
748 g_signal_new (I_("item_activated"),
749 G_TYPE_FROM_CLASS (gobject_class),
751 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
753 g_cclosure_marshal_VOID__BOXED,
757 icon_view_signals[SELECTION_CHANGED] =
758 g_signal_new (I_("selection-changed"),
759 G_TYPE_FROM_CLASS (gobject_class),
761 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
763 g_cclosure_marshal_VOID__VOID,
766 icon_view_signals[SELECT_ALL] =
767 g_signal_new (I_("select_all"),
768 G_TYPE_FROM_CLASS (gobject_class),
769 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
770 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
772 g_cclosure_marshal_VOID__VOID,
775 icon_view_signals[UNSELECT_ALL] =
776 g_signal_new (I_("unselect_all"),
777 G_TYPE_FROM_CLASS (gobject_class),
778 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
779 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
781 g_cclosure_marshal_VOID__VOID,
784 icon_view_signals[SELECT_CURSOR_ITEM] =
785 g_signal_new (I_("select_cursor_item"),
786 G_TYPE_FROM_CLASS (gobject_class),
787 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
788 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
790 g_cclosure_marshal_VOID__VOID,
793 icon_view_signals[TOGGLE_CURSOR_ITEM] =
794 g_signal_new (I_("toggle_cursor_item"),
795 G_TYPE_FROM_CLASS (gobject_class),
796 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
797 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
799 g_cclosure_marshal_VOID__VOID,
802 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
803 g_signal_new (I_("activate_cursor_item"),
804 G_TYPE_FROM_CLASS (gobject_class),
805 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
806 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
808 _gtk_marshal_BOOLEAN__VOID,
811 icon_view_signals[MOVE_CURSOR] =
812 g_signal_new (I_("move_cursor"),
813 G_TYPE_FROM_CLASS (gobject_class),
814 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
815 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
817 _gtk_marshal_BOOLEAN__ENUM_INT,
819 GTK_TYPE_MOVEMENT_STEP,
823 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
825 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
827 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
828 "toggle_cursor_item", 0);
830 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
831 "activate_cursor_item", 0);
832 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
833 "activate_cursor_item", 0);
834 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
835 "activate_cursor_item", 0);
836 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
837 "activate_cursor_item", 0);
839 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
840 GTK_MOVEMENT_DISPLAY_LINES, -1);
841 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
842 GTK_MOVEMENT_DISPLAY_LINES, -1);
844 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
845 GTK_MOVEMENT_DISPLAY_LINES, 1);
846 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
847 GTK_MOVEMENT_DISPLAY_LINES, 1);
849 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
850 GTK_MOVEMENT_DISPLAY_LINES, -1);
852 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
853 GTK_MOVEMENT_DISPLAY_LINES, 1);
855 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
856 GTK_MOVEMENT_BUFFER_ENDS, -1);
857 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
858 GTK_MOVEMENT_BUFFER_ENDS, -1);
860 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
861 GTK_MOVEMENT_BUFFER_ENDS, 1);
862 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
863 GTK_MOVEMENT_BUFFER_ENDS, 1);
865 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
866 GTK_MOVEMENT_PAGES, -1);
867 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
868 GTK_MOVEMENT_PAGES, -1);
870 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
871 GTK_MOVEMENT_PAGES, 1);
872 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
873 GTK_MOVEMENT_PAGES, 1);
875 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
876 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
878 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
880 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
881 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
883 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
887 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
889 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
890 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
891 iface->clear = gtk_icon_view_cell_layout_clear;
892 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
893 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
894 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
895 iface->reorder = gtk_icon_view_cell_layout_reorder;
899 gtk_icon_view_init (GtkIconView *icon_view)
901 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
903 icon_view->priv->width = 0;
904 icon_view->priv->height = 0;
905 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
906 icon_view->priv->pressed_button = -1;
907 icon_view->priv->press_start_x = -1;
908 icon_view->priv->press_start_y = -1;
909 icon_view->priv->text_column = -1;
910 icon_view->priv->markup_column = -1;
911 icon_view->priv->pixbuf_column = -1;
912 icon_view->priv->text_cell = -1;
913 icon_view->priv->pixbuf_cell = -1;
915 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
917 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
919 icon_view->priv->cell_list = NULL;
920 icon_view->priv->n_cells = 0;
921 icon_view->priv->cursor_cell = -1;
923 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
925 icon_view->priv->columns = -1;
926 icon_view->priv->item_width = -1;
927 icon_view->priv->spacing = 0;
928 icon_view->priv->row_spacing = 6;
929 icon_view->priv->column_spacing = 6;
930 icon_view->priv->margin = 6;
934 gtk_icon_view_destroy (GtkObject *object)
936 GtkIconView *icon_view;
938 icon_view = GTK_ICON_VIEW (object);
940 gtk_icon_view_stop_editing (icon_view, TRUE);
942 gtk_icon_view_set_model (icon_view, NULL);
944 if (icon_view->priv->layout_idle_id != 0)
946 g_source_remove (icon_view->priv->layout_idle_id);
947 icon_view->priv->layout_idle_id = 0;
950 if (icon_view->priv->scroll_to_path != NULL)
952 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
953 icon_view->priv->scroll_to_path = NULL;
956 remove_scroll_timeout (icon_view);
958 if (icon_view->priv->hadjustment != NULL)
960 g_object_unref (icon_view->priv->hadjustment);
961 icon_view->priv->hadjustment = NULL;
964 if (icon_view->priv->vadjustment != NULL)
966 g_object_unref (icon_view->priv->vadjustment);
967 icon_view->priv->vadjustment = NULL;
970 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
973 /* GObject methods */
975 gtk_icon_view_finalize (GObject *object)
977 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
979 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
984 gtk_icon_view_set_property (GObject *object,
989 GtkIconView *icon_view;
991 icon_view = GTK_ICON_VIEW (object);
995 case PROP_SELECTION_MODE:
996 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
998 case PROP_PIXBUF_COLUMN:
999 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1001 case PROP_TEXT_COLUMN:
1002 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1004 case PROP_MARKUP_COLUMN:
1005 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1008 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1010 case PROP_ORIENTATION:
1011 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1014 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1016 case PROP_ITEM_WIDTH:
1017 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1020 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1022 case PROP_ROW_SPACING:
1023 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1025 case PROP_COLUMN_SPACING:
1026 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1029 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1031 case PROP_REORDERABLE:
1032 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1036 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1042 gtk_icon_view_get_property (GObject *object,
1047 GtkIconView *icon_view;
1049 icon_view = GTK_ICON_VIEW (object);
1053 case PROP_SELECTION_MODE:
1054 g_value_set_enum (value, icon_view->priv->selection_mode);
1056 case PROP_PIXBUF_COLUMN:
1057 g_value_set_int (value, icon_view->priv->pixbuf_column);
1059 case PROP_TEXT_COLUMN:
1060 g_value_set_int (value, icon_view->priv->text_column);
1062 case PROP_MARKUP_COLUMN:
1063 g_value_set_int (value, icon_view->priv->markup_column);
1066 g_value_set_object (value, icon_view->priv->model);
1068 case PROP_ORIENTATION:
1069 g_value_set_enum (value, icon_view->priv->orientation);
1072 g_value_set_int (value, icon_view->priv->columns);
1074 case PROP_ITEM_WIDTH:
1075 g_value_set_int (value, icon_view->priv->item_width);
1078 g_value_set_int (value, icon_view->priv->spacing);
1080 case PROP_ROW_SPACING:
1081 g_value_set_int (value, icon_view->priv->row_spacing);
1083 case PROP_COLUMN_SPACING:
1084 g_value_set_int (value, icon_view->priv->column_spacing);
1087 g_value_set_int (value, icon_view->priv->margin);
1089 case PROP_REORDERABLE:
1090 g_value_set_boolean (value, icon_view->priv->reorderable);
1094 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1099 /* GtkWidget signals */
1101 gtk_icon_view_realize (GtkWidget *widget)
1103 GtkIconView *icon_view;
1104 GdkWindowAttr attributes;
1105 gint attributes_mask;
1107 icon_view = GTK_ICON_VIEW (widget);
1109 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1111 /* Make the main, clipping window */
1112 attributes.window_type = GDK_WINDOW_CHILD;
1113 attributes.x = widget->allocation.x;
1114 attributes.y = widget->allocation.y;
1115 attributes.width = widget->allocation.width;
1116 attributes.height = widget->allocation.height;
1117 attributes.wclass = GDK_INPUT_OUTPUT;
1118 attributes.visual = gtk_widget_get_visual (widget);
1119 attributes.colormap = gtk_widget_get_colormap (widget);
1120 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1122 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1124 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1125 &attributes, attributes_mask);
1126 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1127 gdk_window_set_user_data (widget->window, widget);
1129 /* Make the window for the icon view */
1132 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1133 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1134 attributes.event_mask = (GDK_EXPOSURE_MASK |
1136 GDK_POINTER_MOTION_MASK |
1137 GDK_BUTTON_PRESS_MASK |
1138 GDK_BUTTON_RELEASE_MASK |
1139 GDK_KEY_PRESS_MASK |
1140 GDK_KEY_RELEASE_MASK) |
1141 gtk_widget_get_events (widget);
1143 icon_view->priv->bin_window = gdk_window_new (widget->window,
1144 &attributes, attributes_mask);
1145 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1147 widget->style = gtk_style_attach (widget->style, widget->window);
1148 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1150 gdk_window_show (icon_view->priv->bin_window);
1154 gtk_icon_view_unrealize (GtkWidget *widget)
1156 GtkIconView *icon_view;
1158 icon_view = GTK_ICON_VIEW (widget);
1160 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1161 gdk_window_destroy (icon_view->priv->bin_window);
1162 icon_view->priv->bin_window = NULL;
1164 /* GtkWidget::unrealize destroys children and widget->window */
1165 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1166 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1170 gtk_icon_view_state_changed (GtkWidget *widget,
1171 GtkStateType previous_state)
1173 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1175 if (GTK_WIDGET_REALIZED (widget))
1177 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1178 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1181 gtk_widget_queue_draw (widget);
1185 gtk_icon_view_style_set (GtkWidget *widget,
1186 GtkStyle *previous_style)
1188 GtkIconView *icon_view;
1190 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1192 icon_view = GTK_ICON_VIEW (widget);
1194 if (GTK_WIDGET_REALIZED (widget))
1196 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1197 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1200 gtk_widget_queue_resize (widget);
1204 gtk_icon_view_size_request (GtkWidget *widget,
1205 GtkRequisition *requisition)
1207 GtkIconView *icon_view;
1210 icon_view = GTK_ICON_VIEW (widget);
1212 requisition->width = icon_view->priv->width;
1213 requisition->height = icon_view->priv->height;
1215 tmp_list = icon_view->priv->children;
1219 GtkIconViewChild *child = tmp_list->data;
1220 GtkRequisition child_requisition;
1222 tmp_list = tmp_list->next;
1224 if (GTK_WIDGET_VISIBLE (child->widget))
1225 gtk_widget_size_request (child->widget, &child_requisition);
1230 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1234 for (list = icon_view->priv->children; list; list = list->next)
1236 GtkIconViewChild *child = list->data;
1237 GtkAllocation allocation;
1239 /* totally ignore our child's requisition */
1240 if (child->cell < 0)
1242 allocation.x = child->item->x;
1243 allocation.y = child->item->y;
1244 allocation.width = child->item->width;
1245 allocation.height = child->item->height;
1249 GdkRectangle *box = &child->item->box[child->cell];
1251 allocation.x = box->x;
1252 allocation.y = box->y;
1253 allocation.width = box->width;
1254 allocation.height = box->height;
1257 gtk_widget_size_allocate (child->widget, &allocation);
1262 gtk_icon_view_size_allocate (GtkWidget *widget,
1263 GtkAllocation *allocation)
1265 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1267 GtkAdjustment *hadjustment, *vadjustment;
1269 widget->allocation = *allocation;
1271 if (GTK_WIDGET_REALIZED (widget))
1273 gdk_window_move_resize (widget->window,
1274 allocation->x, allocation->y,
1275 allocation->width, allocation->height);
1276 gdk_window_resize (icon_view->priv->bin_window,
1277 MAX (icon_view->priv->width, allocation->width),
1278 MAX (icon_view->priv->height, allocation->height));
1281 gtk_icon_view_layout (icon_view);
1283 gtk_icon_view_allocate_children (icon_view);
1285 hadjustment = icon_view->priv->hadjustment;
1286 vadjustment = icon_view->priv->vadjustment;
1288 hadjustment->page_size = allocation->width;
1289 hadjustment->page_increment = allocation->width * 0.9;
1290 hadjustment->step_increment = allocation->width * 0.1;
1291 hadjustment->lower = 0;
1292 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1294 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1295 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1297 vadjustment->page_size = allocation->height;
1298 vadjustment->page_increment = allocation->height * 0.9;
1299 vadjustment->step_increment = allocation->height * 0.1;
1300 vadjustment->lower = 0;
1301 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1303 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1304 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1306 if (GTK_WIDGET_REALIZED (widget) &&
1307 icon_view->priv->scroll_to_path)
1310 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1311 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1312 icon_view->priv->scroll_to_path = NULL;
1314 gtk_icon_view_scroll_to_path (icon_view, path,
1315 icon_view->priv->scroll_to_use_align,
1316 icon_view->priv->scroll_to_row_align,
1317 icon_view->priv->scroll_to_col_align);
1318 gtk_tree_path_free (path);
1322 gtk_adjustment_changed (hadjustment);
1323 gtk_adjustment_changed (vadjustment);
1328 gtk_icon_view_expose (GtkWidget *widget,
1329 GdkEventExpose *expose)
1331 GtkIconView *icon_view;
1336 GtkIconViewDropPosition dest_pos;
1337 GtkIconViewItem *dest_item = NULL;
1339 icon_view = GTK_ICON_VIEW (widget);
1341 if (expose->window != icon_view->priv->bin_window)
1344 cr = gdk_cairo_create (icon_view->priv->bin_window);
1345 cairo_set_line_width (cr, 1.);
1347 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1351 dest_index = gtk_tree_path_get_indices (path)[0];
1352 gtk_tree_path_free (path);
1357 for (icons = icon_view->priv->items; icons; icons = icons->next)
1359 GtkIconViewItem *item = icons->data;
1364 area.width = item->width;
1365 area.height = item->height;
1367 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1370 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1371 icon_view->priv->bin_window,
1372 item->x, item->y, TRUE);
1374 if (dest_index == item->index)
1382 case GTK_ICON_VIEW_DROP_INTO:
1383 gtk_paint_focus (widget->style,
1384 icon_view->priv->bin_window,
1385 GTK_WIDGET_STATE (widget),
1388 "iconview-drop-indicator",
1389 dest_item->x, dest_item->y,
1390 dest_item->width, dest_item->height);
1392 case GTK_ICON_VIEW_DROP_ABOVE:
1393 gtk_paint_focus (widget->style,
1394 icon_view->priv->bin_window,
1395 GTK_WIDGET_STATE (widget),
1398 "iconview-drop-indicator",
1399 dest_item->x, dest_item->y - 1,
1400 dest_item->width, 2);
1402 case GTK_ICON_VIEW_DROP_LEFT:
1403 gtk_paint_focus (widget->style,
1404 icon_view->priv->bin_window,
1405 GTK_WIDGET_STATE (widget),
1408 "iconview-drop-indicator",
1409 dest_item->x - 1, dest_item->y,
1410 2, dest_item->height);
1412 case GTK_ICON_VIEW_DROP_BELOW:
1413 gtk_paint_focus (widget->style,
1414 icon_view->priv->bin_window,
1415 GTK_WIDGET_STATE (widget),
1418 "iconview-drop-indicator",
1419 dest_item->x, dest_item->y + dest_item->height - 1,
1420 dest_item->width, 2);
1422 case GTK_ICON_VIEW_DROP_RIGHT:
1423 gtk_paint_focus (widget->style,
1424 icon_view->priv->bin_window,
1425 GTK_WIDGET_STATE (widget),
1428 "iconview-drop-indicator",
1429 dest_item->x + dest_item->width - 1, dest_item->y,
1430 2, dest_item->height);
1431 case GTK_ICON_VIEW_NO_DROP: ;
1436 if (icon_view->priv->doing_rubberband)
1438 GdkRectangle *rectangles;
1441 gdk_region_get_rectangles (expose->region,
1445 while (n_rectangles--)
1446 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1448 g_free (rectangles);
1453 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1459 rubberband_scroll_timeout (gpointer data)
1461 GtkIconView *icon_view;
1464 GDK_THREADS_ENTER ();
1468 value = MIN (icon_view->priv->vadjustment->value +
1469 icon_view->priv->scroll_value_diff,
1470 icon_view->priv->vadjustment->upper -
1471 icon_view->priv->vadjustment->page_size);
1473 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1475 gtk_icon_view_update_rubberband (icon_view);
1477 GDK_THREADS_LEAVE ();
1483 gtk_icon_view_motion (GtkWidget *widget,
1484 GdkEventMotion *event)
1486 GtkIconView *icon_view;
1489 icon_view = GTK_ICON_VIEW (widget);
1491 gtk_icon_view_maybe_begin_drag (icon_view, event);
1493 if (icon_view->priv->doing_rubberband)
1495 gtk_icon_view_update_rubberband (widget);
1497 abs_y = event->y - icon_view->priv->height *
1498 (icon_view->priv->vadjustment->value /
1499 (icon_view->priv->vadjustment->upper -
1500 icon_view->priv->vadjustment->lower));
1502 if (abs_y < 0 || abs_y > widget->allocation.height)
1505 icon_view->priv->scroll_value_diff = abs_y;
1507 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1509 icon_view->priv->event_last_x = event->x;
1510 icon_view->priv->event_last_y = event->y;
1512 if (icon_view->priv->scroll_timeout_id == 0)
1513 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1517 remove_scroll_timeout (icon_view);
1524 gtk_icon_view_remove (GtkContainer *container,
1527 GtkIconView *icon_view;
1528 GtkIconViewChild *child = NULL;
1531 icon_view = GTK_ICON_VIEW (container);
1533 tmp_list = icon_view->priv->children;
1536 child = tmp_list->data;
1537 if (child->widget == widget)
1539 gtk_widget_unparent (widget);
1541 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1542 g_list_free_1 (tmp_list);
1547 tmp_list = tmp_list->next;
1552 gtk_icon_view_forall (GtkContainer *container,
1553 gboolean include_internals,
1554 GtkCallback callback,
1555 gpointer callback_data)
1557 GtkIconView *icon_view;
1558 GtkIconViewChild *child = NULL;
1561 icon_view = GTK_ICON_VIEW (container);
1563 tmp_list = icon_view->priv->children;
1566 child = tmp_list->data;
1567 tmp_list = tmp_list->next;
1569 (* callback) (child->widget, callback_data);
1574 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1575 GtkIconViewItem *item,
1576 GtkIconViewCellInfo *info,
1581 GdkRectangle cell_area;
1582 gboolean visible, mode;
1584 gtk_icon_view_set_cell_data (icon_view, item);
1586 g_object_get (info->cell,
1587 "visible", &visible,
1591 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1593 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1595 path = gtk_tree_path_new_from_indices (item->index, -1);
1596 path_string = gtk_tree_path_to_string (path);
1597 gtk_tree_path_free (path);
1599 gtk_cell_renderer_activate (info->cell,
1601 GTK_WIDGET (icon_view),
1607 g_free (path_string);
1612 gtk_icon_view_put (GtkIconView *icon_view,
1614 GtkIconViewItem *item,
1617 GtkIconViewChild *child;
1619 child = g_new (GtkIconViewChild, 1);
1621 child->widget = widget;
1625 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1627 if (GTK_WIDGET_REALIZED (icon_view))
1628 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1630 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1634 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1635 GtkIconView *icon_view)
1638 GtkIconViewItem *item;
1640 if (icon_view->priv->edited_item == NULL)
1643 item = icon_view->priv->edited_item;
1644 icon_view->priv->edited_item = NULL;
1645 icon_view->priv->editable = NULL;
1646 for (l = icon_view->priv->cell_list; l; l = l->next)
1648 GtkIconViewCellInfo *info = l->data;
1650 info->editing = FALSE;
1653 if (GTK_WIDGET_HAS_FOCUS (editable))
1654 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1656 g_signal_handlers_disconnect_by_func (editable,
1657 gtk_icon_view_remove_widget,
1660 gtk_container_remove (GTK_CONTAINER (icon_view),
1661 GTK_WIDGET (editable));
1663 gtk_icon_view_queue_draw_item (icon_view, item);
1668 gtk_icon_view_start_editing (GtkIconView *icon_view,
1669 GtkIconViewItem *item,
1670 GtkIconViewCellInfo *info,
1675 GdkRectangle cell_area;
1676 gboolean visible, mode;
1677 GtkCellEditable *editable;
1679 gtk_icon_view_set_cell_data (icon_view, item);
1681 g_object_get (info->cell,
1682 "visible", &visible,
1685 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1687 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1689 path = gtk_tree_path_new_from_indices (item->index, -1);
1690 path_string = gtk_tree_path_to_string (path);
1691 gtk_tree_path_free (path);
1693 editable = gtk_cell_renderer_start_editing (info->cell,
1695 GTK_WIDGET (icon_view),
1700 g_free (path_string);
1702 /* FIXME ugly special case */
1703 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1704 g_object_set (editable, "has-frame", TRUE, NULL);
1706 /* the rest corresponds to tree_view_real_start_editing... */
1707 icon_view->priv->edited_item = item;
1708 icon_view->priv->editable = editable;
1709 info->editing = TRUE;
1711 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1713 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1715 gtk_widget_grab_focus (GTK_WIDGET (editable));
1716 g_signal_connect (editable, "remove_widget",
1717 G_CALLBACK (gtk_icon_view_remove_widget),
1724 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1725 gboolean cancel_editing)
1727 GtkCellRenderer *cell = NULL;
1728 GtkIconViewItem *item;
1731 if (icon_view->priv->edited_item == NULL)
1735 * This is very evil. We need to do this, because
1736 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1737 * later on. If gtk_icon_view_row_changed notices
1738 * icon_view->priv->edited_item != NULL, it'll call
1739 * gtk_icon_view_stop_editing again. Bad things will happen then.
1741 * Please read that again if you intend to modify anything here.
1744 item = icon_view->priv->edited_item;
1745 icon_view->priv->edited_item = NULL;
1747 for (l = icon_view->priv->cell_list; l; l = l->next)
1749 GtkIconViewCellInfo *info = l->data;
1761 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1762 if (!cancel_editing)
1763 gtk_cell_editable_editing_done (icon_view->priv->editable);
1765 icon_view->priv->edited_item = item;
1767 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1771 * gtk_icon_view_set_cursor:
1772 * @icon_view: A #GtkIconView
1773 * @path: A #GtkTreePath
1774 * @cell: One of the cell renderers of @icon_view, or %NULL
1775 * @start_editing: %TRUE if the specified cell should start being edited.
1777 * Sets the current keyboard focus to be at @path, and selects it. This is
1778 * useful when you want to focus the user's attention on a particular item.
1779 * If @cell is not %NULL, then focus is given to the cell specified by
1780 * it. Additionally, if @start_editing is %TRUE, then editing should be
1781 * started in the specified cell.
1783 * This function is often followed by <literal>gtk_widget_grab_focus
1784 * (icon_view)</literal> in order to give keyboard focus to the widget.
1785 * Please note that editing can only happen when the widget is realized.
1790 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1792 GtkCellRenderer *cell,
1793 gboolean start_editing)
1795 GtkIconViewItem *item = NULL;
1796 GtkIconViewCellInfo *info = NULL;
1800 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1801 g_return_if_fail (path != NULL);
1802 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1804 gtk_icon_view_stop_editing (icon_view, TRUE);
1806 if (gtk_tree_path_get_depth (path) == 1)
1807 item = g_list_nth_data (icon_view->priv->items,
1808 gtk_tree_path_get_indices(path)[0]);
1814 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1818 if (info->cell == cell)
1827 g_return_if_fail (cell == NULL || info != NULL);
1829 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1830 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1832 if (info && start_editing)
1833 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1837 * gtk_icon_view_get_cursor:
1838 * @icon_view: A #GtkIconView
1839 * @path: Return location for the current cursor path, or %NULL
1840 * @cell: Return location the current focus cell, or %NULL
1842 * Fills in @path and @cell with the current cursor path and cell.
1843 * If the cursor isn't currently set, then *@path will be %NULL.
1844 * If no cell currently has focus, then *@cell will be %NULL.
1846 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1848 * Return value: %TRUE if the cursor is set.
1853 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1855 GtkCellRenderer **cell)
1857 GtkIconViewItem *item;
1858 GtkIconViewCellInfo *info;
1860 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1862 item = icon_view->priv->cursor_item;
1863 if (icon_view->priv->cursor_cell < 0)
1866 info = g_list_nth_data (icon_view->priv->cell_list,
1867 icon_view->priv->cursor_cell);
1872 *path = gtk_tree_path_new_from_indices (item->index, -1);
1885 return (item != NULL);
1889 gtk_icon_view_button_press (GtkWidget *widget,
1890 GdkEventButton *event)
1892 GtkIconView *icon_view;
1893 GtkIconViewItem *item;
1894 GtkIconViewCellInfo *info = NULL;
1895 gboolean dirty = FALSE;
1896 GtkCellRendererMode mode;
1899 icon_view = GTK_ICON_VIEW (widget);
1901 if (event->window != icon_view->priv->bin_window)
1904 if (!GTK_WIDGET_HAS_FOCUS (widget))
1905 gtk_widget_grab_focus (widget);
1907 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1909 item = gtk_icon_view_get_item_at_coords (icon_view,
1915 g_object_get (info->cell, "mode", &mode, NULL);
1917 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1918 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1919 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1923 gtk_icon_view_scroll_to_item (icon_view, item);
1925 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1927 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1929 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1930 (event->state & GDK_SHIFT_MASK))
1932 gtk_icon_view_unselect_all_internal (icon_view);
1934 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1935 if (!icon_view->priv->anchor_item)
1936 icon_view->priv->anchor_item = item;
1938 gtk_icon_view_select_all_between (icon_view,
1939 icon_view->priv->anchor_item,
1945 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1946 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1947 (event->state & GDK_CONTROL_MASK))
1949 item->selected = !item->selected;
1950 gtk_icon_view_queue_draw_item (icon_view, item);
1955 if (!item->selected)
1957 gtk_icon_view_unselect_all_internal (icon_view);
1959 item->selected = TRUE;
1960 gtk_icon_view_queue_draw_item (icon_view, item);
1964 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1965 icon_view->priv->anchor_item = item;
1968 /* Save press to possibly begin a drag */
1969 if (icon_view->priv->pressed_button < 0)
1971 icon_view->priv->pressed_button = event->button;
1972 icon_view->priv->press_start_x = event->x;
1973 icon_view->priv->press_start_y = event->y;
1976 if (!icon_view->priv->last_single_clicked)
1977 icon_view->priv->last_single_clicked = item;
1979 /* cancel the current editing, if it exists */
1980 gtk_icon_view_stop_editing (icon_view, TRUE);
1982 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1983 gtk_icon_view_item_activate_cell (icon_view, item, info,
1985 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1986 gtk_icon_view_start_editing (icon_view, item, info,
1991 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1992 !(event->state & GDK_CONTROL_MASK))
1994 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1997 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1998 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2003 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2005 item = gtk_icon_view_get_item_at_coords (icon_view,
2010 if (item && item == icon_view->priv->last_single_clicked)
2014 path = gtk_tree_path_new_from_indices (item->index, -1);
2015 gtk_icon_view_item_activated (icon_view, path);
2016 gtk_tree_path_free (path);
2019 icon_view->priv->last_single_clicked = NULL;
2020 icon_view->priv->pressed_button = -1;
2024 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2026 return event->button == 1;
2030 gtk_icon_view_button_release (GtkWidget *widget,
2031 GdkEventButton *event)
2033 GtkIconView *icon_view;
2035 icon_view = GTK_ICON_VIEW (widget);
2037 if (icon_view->priv->pressed_button == event->button)
2038 icon_view->priv->pressed_button = -1;
2040 gtk_icon_view_stop_rubberbanding (icon_view);
2042 remove_scroll_timeout (icon_view);
2048 gtk_icon_view_update_rubberband (gpointer data)
2050 GtkIconView *icon_view;
2052 GdkRectangle old_area;
2053 GdkRectangle new_area;
2054 GdkRectangle common;
2055 GdkRegion *invalid_region;
2057 icon_view = GTK_ICON_VIEW (data);
2059 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2064 old_area.x = MIN (icon_view->priv->rubberband_x1,
2065 icon_view->priv->rubberband_x2);
2066 old_area.y = MIN (icon_view->priv->rubberband_y1,
2067 icon_view->priv->rubberband_y2);
2068 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2069 icon_view->priv->rubberband_x1) + 1;
2070 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2071 icon_view->priv->rubberband_y1) + 1;
2073 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2074 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2075 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2076 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2078 invalid_region = gdk_region_rectangle (&old_area);
2079 gdk_region_union_with_rect (invalid_region, &new_area);
2081 gdk_rectangle_intersect (&old_area, &new_area, &common);
2082 if (common.width > 2 && common.height > 2)
2084 GdkRegion *common_region;
2086 /* make sure the border is invalidated */
2092 common_region = gdk_region_rectangle (&common);
2094 gdk_region_subtract (invalid_region, common_region);
2095 gdk_region_destroy (common_region);
2098 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2100 gdk_region_destroy (invalid_region);
2102 icon_view->priv->rubberband_x2 = x;
2103 icon_view->priv->rubberband_y2 = y;
2105 gtk_icon_view_update_rubberband_selection (icon_view);
2109 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2115 g_assert (!icon_view->priv->doing_rubberband);
2117 for (items = icon_view->priv->items; items; items = items->next)
2119 GtkIconViewItem *item = items->data;
2121 item->selected_before_rubberbanding = item->selected;
2124 icon_view->priv->rubberband_x1 = x;
2125 icon_view->priv->rubberband_y1 = y;
2126 icon_view->priv->rubberband_x2 = x;
2127 icon_view->priv->rubberband_y2 = y;
2129 icon_view->priv->doing_rubberband = TRUE;
2131 gtk_grab_add (GTK_WIDGET (icon_view));
2135 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2137 if (!icon_view->priv->doing_rubberband)
2140 icon_view->priv->doing_rubberband = FALSE;
2142 gtk_grab_remove (GTK_WIDGET (icon_view));
2144 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2148 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2151 gint x, y, width, height;
2152 gboolean dirty = FALSE;
2154 x = MIN (icon_view->priv->rubberband_x1,
2155 icon_view->priv->rubberband_x2);
2156 y = MIN (icon_view->priv->rubberband_y1,
2157 icon_view->priv->rubberband_y2);
2158 width = ABS (icon_view->priv->rubberband_x1 -
2159 icon_view->priv->rubberband_x2);
2160 height = ABS (icon_view->priv->rubberband_y1 -
2161 icon_view->priv->rubberband_y2);
2163 for (items = icon_view->priv->items; items; items = items->next)
2165 GtkIconViewItem *item = items->data;
2169 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2170 x, y, width, height);
2172 selected = is_in ^ item->selected_before_rubberbanding;
2174 if (item->selected != selected)
2176 item->selected = selected;
2178 gtk_icon_view_queue_draw_item (icon_view, item);
2183 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2187 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2188 GtkIconViewItem *item,
2197 for (l = icon_view->priv->cell_list; l; l = l->next)
2199 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2201 if (!info->cell->visible)
2204 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2206 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2207 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2215 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2217 gboolean dirty = FALSE;
2220 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2223 for (items = icon_view->priv->items; items; items = items->next)
2225 GtkIconViewItem *item = items->data;
2229 item->selected = FALSE;
2231 gtk_icon_view_queue_draw_item (icon_view, item);
2239 /* GtkIconView signals */
2241 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2242 GtkAdjustment *hadj,
2243 GtkAdjustment *vadj)
2245 gboolean need_adjust = FALSE;
2248 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2250 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2252 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2254 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2256 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2258 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2259 0, 0, NULL, NULL, icon_view);
2260 g_object_unref (icon_view->priv->hadjustment);
2263 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2265 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2266 0, 0, NULL, NULL, icon_view);
2267 g_object_unref (icon_view->priv->vadjustment);
2270 if (icon_view->priv->hadjustment != hadj)
2272 icon_view->priv->hadjustment = hadj;
2273 g_object_ref_sink (icon_view->priv->hadjustment);
2275 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2276 G_CALLBACK (gtk_icon_view_adjustment_changed),
2281 if (icon_view->priv->vadjustment != vadj)
2283 icon_view->priv->vadjustment = vadj;
2284 g_object_ref_sink (icon_view->priv->vadjustment);
2286 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2287 G_CALLBACK (gtk_icon_view_adjustment_changed),
2293 gtk_icon_view_adjustment_changed (NULL, icon_view);
2297 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2299 gtk_icon_view_select_all (icon_view);
2303 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2305 gtk_icon_view_unselect_all (icon_view);
2309 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2311 gtk_icon_view_unselect_all (icon_view);
2313 if (icon_view->priv->cursor_item != NULL)
2314 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2318 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2321 GtkCellRendererMode mode;
2322 GtkIconViewCellInfo *info = NULL;
2324 if (!icon_view->priv->cursor_item)
2327 info = g_list_nth_data (icon_view->priv->cell_list,
2328 icon_view->priv->cursor_cell);
2332 g_object_get (info->cell, "mode", &mode, NULL);
2334 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2336 gtk_icon_view_item_activate_cell (icon_view,
2337 icon_view->priv->cursor_item,
2341 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2343 gtk_icon_view_start_editing (icon_view,
2344 icon_view->priv->cursor_item,
2350 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2351 gtk_icon_view_item_activated (icon_view, path);
2352 gtk_tree_path_free (path);
2358 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2360 if (!icon_view->priv->cursor_item)
2363 switch (icon_view->priv->selection_mode)
2365 case GTK_SELECTION_NONE:
2367 case GTK_SELECTION_BROWSE:
2368 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2370 case GTK_SELECTION_SINGLE:
2371 if (icon_view->priv->cursor_item->selected)
2372 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2374 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2376 case GTK_SELECTION_MULTIPLE:
2377 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2378 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2380 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2385 /* Internal functions */
2387 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2388 GtkIconView *icon_view)
2390 if (GTK_WIDGET_REALIZED (icon_view))
2392 gdk_window_move (icon_view->priv->bin_window,
2393 - icon_view->priv->hadjustment->value,
2394 - icon_view->priv->vadjustment->value);
2396 if (icon_view->priv->doing_rubberband)
2397 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2399 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2404 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2409 gint *maximum_width)
2412 gint x, current_width;
2413 GList *items, *last_item;
2420 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2421 max_height = g_new0 (gint, icon_view->priv->n_cells);
2428 gtk_widget_style_get (GTK_WIDGET (icon_view),
2429 "focus-line-width", &focus_width,
2432 x += icon_view->priv->margin + focus_width;
2433 current_width += 2 * (icon_view->priv->margin + focus_width);
2438 GtkIconViewItem *item = items->data;
2440 gtk_icon_view_calculate_item_size (icon_view, item);
2441 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2443 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2445 current_width += item->width;
2447 if (items != first_item)
2449 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2450 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2454 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2456 item->y = *y + focus_width;
2457 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2459 x = current_width - (icon_view->priv->margin + focus_width);
2461 for (i = 0; i < icon_view->priv->n_cells; i++)
2462 max_height[i] = MAX (max_height[i], item->box[i].height);
2464 if (current_width > *maximum_width)
2465 *maximum_width = current_width;
2471 items = items->next;
2476 /* Now go through the row again and align the icons */
2477 for (items = first_item; items != last_item; items = items->next)
2479 GtkIconViewItem *item = items->data;
2481 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2483 /* We may want to readjust the new y coordinate. */
2484 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2485 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2488 item->col = col - 1 - item->col;
2491 g_free (max_height);
2497 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2500 if (upper != adj->upper)
2502 gdouble min = MAX (0.0, upper - adj->page_size);
2503 gboolean value_changed = FALSE;
2507 if (adj->value > min)
2510 value_changed = TRUE;
2513 gtk_adjustment_changed (adj);
2516 gtk_adjustment_value_changed (adj);
2521 gtk_icon_view_layout (GtkIconView *icon_view)
2523 gint y = 0, maximum_width = 0;
2529 if (icon_view->priv->layout_idle_id != 0)
2531 g_source_remove (icon_view->priv->layout_idle_id);
2532 icon_view->priv->layout_idle_id = 0;
2535 if (icon_view->priv->model == NULL)
2538 widget = GTK_WIDGET (icon_view);
2540 item_width = icon_view->priv->item_width;
2544 for (icons = icon_view->priv->items; icons; icons = icons->next)
2546 GtkIconViewItem *item = icons->data;
2547 gtk_icon_view_calculate_item_size (icon_view, item);
2548 item_width = MAX (item_width, item->width);
2552 icons = icon_view->priv->items;
2553 y += icon_view->priv->margin;
2558 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2560 &y, &maximum_width);
2563 while (icons != NULL);
2565 if (maximum_width != icon_view->priv->width)
2566 icon_view->priv->width = maximum_width;
2568 y += icon_view->priv->margin;
2570 if (y != icon_view->priv->height)
2571 icon_view->priv->height = y;
2573 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2574 icon_view->priv->width);
2575 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2576 icon_view->priv->height);
2578 if (GTK_WIDGET_REALIZED (icon_view))
2579 gdk_window_resize (icon_view->priv->bin_window,
2580 MAX (icon_view->priv->width, widget->allocation.width),
2581 MAX (icon_view->priv->height, widget->allocation.height));
2583 if (icon_view->priv->scroll_to_path)
2587 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2588 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2589 icon_view->priv->scroll_to_path = NULL;
2591 gtk_icon_view_scroll_to_path (icon_view, path,
2592 icon_view->priv->scroll_to_use_align,
2593 icon_view->priv->scroll_to_row_align,
2594 icon_view->priv->scroll_to_col_align);
2595 gtk_tree_path_free (path);
2598 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2602 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2603 GtkIconViewItem *item,
2604 GtkIconViewCellInfo *info,
2605 GdkRectangle *cell_area)
2607 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2609 cell_area->x = item->box[info->position].x - item->before[info->position];
2610 cell_area->y = item->y;
2611 cell_area->width = item->box[info->position].width +
2612 item->before[info->position] + item->after[info->position];
2613 cell_area->height = item->height;
2617 cell_area->x = item->x;
2618 cell_area->y = item->box[info->position].y - item->before[info->position];
2619 cell_area->width = item->width;
2620 cell_area->height = item->box[info->position].height +
2621 item->before[info->position] + item->after[info->position];
2626 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2627 GtkIconViewItem *item,
2628 GtkIconViewCellInfo *info,
2631 *box = item->box[info->position];
2634 /* try to guess a reasonable wrap width for an implicit text cell renderer
2637 adjust_wrap_width (GtkIconView *icon_view,
2638 GtkIconViewItem *item)
2640 GtkIconViewCellInfo *text_info;
2641 GtkIconViewCellInfo *pixbuf_info;
2642 gint pixbuf_width, wrap_width;
2644 if (icon_view->priv->text_cell != -1 &&
2645 icon_view->priv->pixbuf_cell != -1)
2647 text_info = g_list_nth_data (icon_view->priv->cell_list,
2648 icon_view->priv->text_cell);
2649 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2650 icon_view->priv->pixbuf_cell);
2652 gtk_cell_renderer_get_size (pixbuf_info->cell,
2653 GTK_WIDGET (icon_view),
2658 if (item->width == -1)
2659 wrap_width = MAX (2 * pixbuf_width, 50);
2660 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2661 wrap_width = item->width;
2663 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2665 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2670 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2671 GtkIconViewItem *item)
2676 if (item->width != -1 && item->height != -1)
2679 if (item->n_cells != icon_view->priv->n_cells)
2681 g_free (item->before);
2682 g_free (item->after);
2685 item->before = g_new0 (gint, icon_view->priv->n_cells);
2686 item->after = g_new0 (gint, icon_view->priv->n_cells);
2687 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2689 item->n_cells = icon_view->priv->n_cells;
2692 gtk_icon_view_set_cell_data (icon_view, item);
2694 spacing = icon_view->priv->spacing;
2698 for (l = icon_view->priv->cell_list; l; l = l->next)
2700 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2702 if (!info->cell->visible)
2705 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2707 &item->box[info->position].width,
2708 &item->box[info->position].height);
2710 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2712 item->width += item->box[info->position].width
2713 + (info->position > 0 ? spacing : 0);
2714 item->height = MAX (item->height, item->box[info->position].height);
2718 item->width = MAX (item->width, item->box[info->position].width);
2719 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2725 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2726 GtkIconViewItem *item,
2729 GdkRectangle cell_area;
2735 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2737 gtk_icon_view_set_cell_data (icon_view, item);
2739 spacing = icon_view->priv->spacing;
2742 for (i = 0; i < icon_view->priv->n_cells; i++)
2744 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2745 item->height = MAX (item->height, max_height[i]);
2747 item->height += max_height[i] + (i > 0 ? spacing : 0);
2750 cell_area.x = item->x;
2751 cell_area.y = item->y;
2753 for (k = 0; k < 2; k++)
2754 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2756 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2758 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2761 if (!info->cell->visible)
2764 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2766 cell_area.width = item->box[info->position].width;
2767 cell_area.height = item->height;
2771 cell_area.width = item->width;
2772 cell_area.height = max_height[i];
2775 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2777 &item->box[info->position].x, &item->box[info->position].y,
2778 &item->box[info->position].width, &item->box[info->position].height);
2780 item->box[info->position].x += cell_area.x;
2781 item->box[info->position].y += cell_area.y;
2782 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2784 item->before[info->position] = item->box[info->position].x - cell_area.x;
2785 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2786 cell_area.x += cell_area.width + spacing;
2790 if (item->box[info->position].width > item->width)
2792 item->width = item->box[info->position].width;
2793 cell_area.width = item->width;
2795 item->before[info->position] = item->box[info->position].y - cell_area.y;
2796 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2797 cell_area.y += cell_area.height + spacing;
2801 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2803 for (i = 0; i < icon_view->priv->n_cells; i++)
2805 item->box[i].x = item->x + item->width -
2806 (item->box[i].x + item->box[i].width - item->x);
2812 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2814 g_list_foreach (icon_view->priv->items,
2815 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2819 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2826 gtk_icon_view_paint_item (GtkIconView *icon_view,
2828 GtkIconViewItem *item,
2830 GdkDrawable *drawable,
2833 gboolean draw_focus)
2835 gint focus_width, focus_pad;
2837 GdkRectangle cell_area, box;
2841 GtkCellRendererState flags;
2843 if (icon_view->priv->model == NULL)
2846 gtk_icon_view_set_cell_data (icon_view, item);
2848 gtk_widget_style_get (GTK_WIDGET (icon_view),
2849 "focus-line-width", &focus_width,
2850 "focus-padding", &focus_pad,
2853 padding = focus_width;
2857 flags = GTK_CELL_RENDERER_SELECTED;
2858 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2859 state = GTK_STATE_SELECTED;
2861 state = GTK_STATE_ACTIVE;
2866 state = GTK_STATE_NORMAL;
2869 #ifdef DEBUG_ICON_VIEW
2870 gdk_draw_rectangle (drawable,
2871 GTK_WIDGET (icon_view)->style->black_gc,
2874 item->width, item->height);
2878 for (l = icon_view->priv->cell_list; l; l = l->next)
2880 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2882 if (!info->cell->visible)
2885 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2887 /* FIXME we hardwire background drawing behind text
2888 * cell renderers here
2890 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2892 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2893 cairo_rectangle (cr,
2894 x - item->x + box.x,
2895 y - item->y + box.y,
2896 box.width, box.height);
2901 for (l = icon_view->priv->cell_list; l; l = l->next)
2903 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2905 if (!info->cell->visible)
2908 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2910 #ifdef DEBUG_ICON_VIEW
2911 gdk_draw_rectangle (drawable,
2912 GTK_WIDGET (icon_view)->style->black_gc,
2914 x - item->x + cell_area.x,
2915 y - item->y + cell_area.y,
2916 cell_area.width, cell_area.height);
2918 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2920 gdk_draw_rectangle (drawable,
2921 GTK_WIDGET (icon_view)->style->black_gc,
2923 x - item->x + box.x,
2924 y - item->y + box.y,
2925 box.width, box.height);
2928 cell_area.x = x - item->x + cell_area.x;
2929 cell_area.y = y - item->y + cell_area.y;
2931 gtk_cell_renderer_render (info->cell,
2933 GTK_WIDGET (icon_view),
2934 &cell_area, &cell_area, area, flags);
2938 /* FIXME where to draw the focus with generic cell renderers ? */
2940 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2941 item == icon_view->priv->cursor_item)
2942 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2944 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2946 if (!info->cell->visible)
2949 if (icon_view->priv->cursor_cell < 0 &&
2950 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2951 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2952 icon_view->priv->cursor_cell = i;
2954 if (i == icon_view->priv->cursor_cell)
2956 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2958 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2962 GTK_WIDGET (icon_view),
2964 x - item->x + box.x - padding,
2965 y - item->y + box.y - padding,
2966 box.width + 2 * padding,
2967 box.height + 2 * padding);
2974 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2979 GdkRectangle rubber_rect;
2980 GdkColor *fill_color_gdk;
2981 guchar fill_color_alpha;
2983 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2984 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2985 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2986 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2988 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2991 gtk_widget_style_get (GTK_WIDGET (icon_view),
2992 "selection-box-color", &fill_color_gdk,
2993 "selection-box-alpha", &fill_color_alpha,
2996 if (!fill_color_gdk)
2997 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2999 cairo_set_source_rgba (cr,
3000 fill_color_gdk->red / 65535.,
3001 fill_color_gdk->green / 65535.,
3002 fill_color_gdk->blue / 65535.,
3003 fill_color_alpha / 255.);
3006 gdk_cairo_rectangle (cr, &rect);
3010 /* Draw the border without alpha */
3011 cairo_set_source_rgb (cr,
3012 fill_color_gdk->red / 65535.,
3013 fill_color_gdk->green / 65535.,
3014 fill_color_gdk->blue / 65535.);
3015 cairo_rectangle (cr,
3016 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3017 rubber_rect.width - 1, rubber_rect.height - 1);
3021 gdk_color_free (fill_color_gdk);
3025 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3031 index = gtk_tree_path_get_indices (path)[0];
3033 for (l = icon_view->priv->items; l; l = l->next)
3035 GtkIconViewItem *item = l->data;
3037 if (item->index == index)
3039 gtk_icon_view_queue_draw_item (icon_view, item);
3046 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3047 GtkIconViewItem *item)
3052 gtk_widget_style_get (GTK_WIDGET (icon_view),
3053 "focus-line-width", &focus_width,
3056 rect.x = item->x - focus_width;
3057 rect.y = item->y - focus_width;
3058 rect.width = item->width + 2 * focus_width;
3059 rect.height = item->height + 2 * focus_width;
3061 if (icon_view->priv->bin_window)
3062 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3066 layout_callback (gpointer user_data)
3068 GtkIconView *icon_view;
3070 GDK_THREADS_ENTER ();
3072 icon_view = GTK_ICON_VIEW (user_data);
3074 icon_view->priv->layout_idle_id = 0;
3076 gtk_icon_view_layout (icon_view);
3078 GDK_THREADS_LEAVE();
3084 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3086 if (icon_view->priv->layout_idle_id != 0)
3089 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3093 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3094 GtkIconViewItem *item,
3098 AtkObject *item_obj;
3100 if (icon_view->priv->cursor_item == item &&
3101 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3104 if (icon_view->priv->cursor_item != NULL)
3105 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3107 icon_view->priv->cursor_item = item;
3108 if (cursor_cell >= 0)
3109 icon_view->priv->cursor_cell = cursor_cell;
3111 gtk_icon_view_queue_draw_item (icon_view, item);
3113 /* Notify that accessible focus object has changed */
3114 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3115 item_obj = atk_object_ref_accessible_child (obj, item->index);
3117 if (item_obj != NULL)
3119 atk_focus_tracker_notify (item_obj);
3120 g_object_unref (item_obj);
3125 static GtkIconViewItem *
3126 gtk_icon_view_item_new (void)
3128 GtkIconViewItem *item;
3130 item = g_new0 (GtkIconViewItem, 1);
3139 gtk_icon_view_item_free (GtkIconViewItem *item)
3141 g_return_if_fail (item != NULL);
3143 g_free (item->before);
3144 g_free (item->after);
3151 static GtkIconViewItem *
3152 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3155 gboolean only_in_cell,
3156 GtkIconViewCellInfo **cell_at_pos)
3161 for (items = icon_view->priv->items; items; items = items->next)
3163 GtkIconViewItem *item = items->data;
3165 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3166 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3168 if (only_in_cell || cell_at_pos)
3170 gtk_icon_view_set_cell_data (icon_view, item);
3172 for (l = icon_view->priv->cell_list; l; l = l->next)
3174 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3176 if (!info->cell->visible)
3179 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3181 if ((x >= box.x && x <= box.x + box.width &&
3182 y >= box.y && y <= box.y + box.height) ||
3184 x <= box.x + box.width &&
3186 y <= box.y + box.height))
3189 *cell_at_pos = info;
3199 *cell_at_pos = NULL;
3210 gtk_icon_view_select_item (GtkIconView *icon_view,
3211 GtkIconViewItem *item)
3213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3214 g_return_if_fail (item != NULL);
3219 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3221 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3222 gtk_icon_view_unselect_all_internal (icon_view);
3224 item->selected = TRUE;
3226 gtk_icon_view_queue_draw_item (icon_view, item);
3228 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3233 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3234 GtkIconViewItem *item)
3236 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3237 g_return_if_fail (item != NULL);
3239 if (!item->selected)
3242 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3243 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3246 item->selected = FALSE;
3248 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3250 gtk_icon_view_queue_draw_item (icon_view, item);
3254 verify_items (GtkIconView *icon_view)
3259 for (items = icon_view->priv->items; items; items = items->next)
3261 GtkIconViewItem *item = items->data;
3263 if (item->index != i)
3264 g_error ("List item does not match its index: "
3265 "item index %d and list index %d\n", item->index, i);
3272 gtk_icon_view_row_changed (GtkTreeModel *model,
3277 GtkIconViewItem *item;
3279 GtkIconView *icon_view;
3281 icon_view = GTK_ICON_VIEW (data);
3283 gtk_icon_view_stop_editing (icon_view, TRUE);
3285 index = gtk_tree_path_get_indices(path)[0];
3286 item = g_list_nth_data (icon_view->priv->items, index);
3288 gtk_icon_view_item_invalidate_size (item);
3289 gtk_icon_view_queue_layout (icon_view);
3291 verify_items (icon_view);
3295 gtk_icon_view_row_inserted (GtkTreeModel *model,
3301 GtkIconViewItem *item;
3302 gboolean iters_persist;
3303 GtkIconView *icon_view;
3306 icon_view = GTK_ICON_VIEW (data);
3308 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3310 index = gtk_tree_path_get_indices(path)[0];
3312 item = gtk_icon_view_item_new ();
3317 item->index = index;
3319 /* FIXME: We can be more efficient here,
3320 we can store a tail pointer and use that when
3321 appending (which is a rather common operation)
3323 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3326 list = g_list_nth (icon_view->priv->items, index + 1);
3327 for (; list; list = list->next)
3334 verify_items (icon_view);
3336 gtk_icon_view_queue_layout (icon_view);
3340 gtk_icon_view_row_deleted (GtkTreeModel *model,
3345 GtkIconView *icon_view;
3346 GtkIconViewItem *item;
3348 gboolean emit = FALSE;
3350 icon_view = GTK_ICON_VIEW (data);
3352 index = gtk_tree_path_get_indices(path)[0];
3354 list = g_list_nth (icon_view->priv->items, index);
3357 gtk_icon_view_stop_editing (icon_view, TRUE);
3359 if (item == icon_view->priv->anchor_item)
3360 icon_view->priv->anchor_item = NULL;
3362 if (item == icon_view->priv->cursor_item)
3363 icon_view->priv->cursor_item = NULL;
3368 gtk_icon_view_item_free (item);
3370 for (next = list->next; next; next = next->next)
3377 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3379 verify_items (icon_view);
3381 gtk_icon_view_queue_layout (icon_view);
3384 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3388 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3389 GtkTreePath *parent,
3396 GtkIconView *icon_view;
3397 GList *items = NULL, *list;
3398 GtkIconViewItem **item_array;
3401 icon_view = GTK_ICON_VIEW (data);
3403 gtk_icon_view_stop_editing (icon_view, TRUE);
3405 length = gtk_tree_model_iter_n_children (model, NULL);
3407 order = g_new (gint, length);
3408 for (i = 0; i < length; i++)
3409 order [new_order[i]] = i;
3411 item_array = g_new (GtkIconViewItem *, length);
3412 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3413 item_array[order[i]] = list->data;
3416 for (i = length - 1; i >= 0; i--)
3418 item_array[i]->index = i;
3419 items = g_list_prepend (items, item_array[i]);
3422 g_free (item_array);
3423 g_list_free (icon_view->priv->items);
3424 icon_view->priv->items = items;
3426 gtk_icon_view_queue_layout (icon_view);
3428 verify_items (icon_view);
3432 gtk_icon_view_build_items (GtkIconView *icon_view)
3436 gboolean iters_persist;
3437 GList *items = NULL;
3439 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3441 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3449 GtkIconViewItem *item = gtk_icon_view_item_new ();
3458 items = g_list_prepend (items, item);
3460 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3462 icon_view->priv->items = g_list_reverse (items);
3466 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3469 GtkMovementStep step,
3473 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3474 I_("move_cursor"), 2,
3478 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3483 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3486 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3491 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3498 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3499 GtkMovementStep step,
3502 GdkModifierType state;
3504 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3505 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3506 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3507 step == GTK_MOVEMENT_DISPLAY_LINES ||
3508 step == GTK_MOVEMENT_PAGES ||
3509 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3511 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3514 gtk_icon_view_stop_editing (icon_view, FALSE);
3515 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3517 if (gtk_get_current_event_state (&state))
3519 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3520 icon_view->priv->ctrl_pressed = TRUE;
3521 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3522 icon_view->priv->shift_pressed = TRUE;
3524 /* else we assume not pressed */
3528 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3529 case GTK_MOVEMENT_VISUAL_POSITIONS:
3530 gtk_icon_view_move_cursor_left_right (icon_view, count);
3532 case GTK_MOVEMENT_DISPLAY_LINES:
3533 gtk_icon_view_move_cursor_up_down (icon_view, count);
3535 case GTK_MOVEMENT_PAGES:
3536 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3538 case GTK_MOVEMENT_BUFFER_ENDS:
3539 gtk_icon_view_move_cursor_start_end (icon_view, count);
3542 g_assert_not_reached ();
3545 icon_view->priv->ctrl_pressed = FALSE;
3546 icon_view->priv->shift_pressed = FALSE;
3551 static GtkIconViewItem *
3552 find_item (GtkIconView *icon_view,
3553 GtkIconViewItem *current,
3559 GtkIconViewItem *item;
3561 /* FIXME: this could be more efficient
3563 row = current->row + row_ofs;
3564 col = current->col + col_ofs;
3566 for (items = icon_view->priv->items; items; items = items->next)
3569 if (item->row == row && item->col == col)
3577 find_cell (GtkIconView *icon_view,
3578 GtkIconViewItem *item,
3580 GtkOrientation orientation,
3591 if (icon_view->priv->orientation != orientation)
3594 gtk_icon_view_set_cell_data (icon_view, item);
3596 focusable = g_new0 (gint, icon_view->priv->n_cells);
3601 for (k = 0; k < 2; k++)
3602 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3604 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3606 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3609 if (!info->cell->visible)
3612 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3615 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3618 current = n_focusable;
3620 focusable[n_focusable] = i;
3626 if (n_focusable == 0)
3627 focusable[n_focusable++] = first_text;
3631 current = step > 0 ? 0 : n_focusable - 1;
3632 cell = focusable[current];
3635 if (current + *count < 0)
3638 *count = current + *count;
3640 else if (current + *count > n_focusable - 1)
3643 *count = current + *count - (n_focusable - 1);
3647 cell = focusable[current + *count];
3656 static GtkIconViewItem *
3657 find_item_page_up_down (GtkIconView *icon_view,
3658 GtkIconViewItem *current,
3665 y = current->y + count * icon_view->priv->vadjustment->page_size;
3667 item = g_list_find (icon_view->priv->items, current);
3672 for (next = item->next; next; next = next->next)
3674 if (((GtkIconViewItem *)next->data)->col == col)
3677 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3687 for (next = item->prev; next; next = next->prev)
3689 if (((GtkIconViewItem *)next->data)->col == col)
3692 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3706 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3707 GtkIconViewItem *anchor,
3708 GtkIconViewItem *cursor)
3711 GtkIconViewItem *item;
3712 gint row1, row2, col1, col2;
3713 gboolean dirty = FALSE;
3715 if (anchor->row < cursor->row)
3726 if (anchor->col < cursor->col)
3737 for (items = icon_view->priv->items; items; items = items->next)
3741 if (row1 <= item->row && item->row <= row2 &&
3742 col1 <= item->col && item->col <= col2)
3744 if (!item->selected)
3747 item->selected = TRUE;
3749 gtk_icon_view_queue_draw_item (icon_view, item);
3757 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3760 GtkIconViewItem *item;
3762 gboolean dirty = FALSE;
3765 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3768 if (!icon_view->priv->cursor_item)
3773 list = icon_view->priv->items;
3775 list = g_list_last (icon_view->priv->items);
3777 item = list ? list->data : NULL;
3782 item = icon_view->priv->cursor_item;
3783 cell = icon_view->priv->cursor_cell;
3784 step = count > 0 ? 1 : -1;
3787 cell = find_cell (icon_view, item, cell,
3788 GTK_ORIENTATION_VERTICAL,
3793 item = find_item (icon_view, item, step, 0);
3794 count = count - step;
3801 if (icon_view->priv->ctrl_pressed ||
3802 !icon_view->priv->shift_pressed ||
3803 !icon_view->priv->anchor_item ||
3804 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3805 icon_view->priv->anchor_item = item;
3807 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3809 if (!icon_view->priv->ctrl_pressed &&
3810 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3812 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3813 dirty = gtk_icon_view_select_all_between (icon_view,
3814 icon_view->priv->anchor_item,
3818 gtk_icon_view_scroll_to_item (icon_view, item);
3821 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3825 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3828 GtkIconViewItem *item;
3829 gboolean dirty = FALSE;
3831 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3834 if (!icon_view->priv->cursor_item)
3839 list = icon_view->priv->items;
3841 list = g_list_last (icon_view->priv->items);
3843 item = list ? list->data : NULL;
3846 item = find_item_page_up_down (icon_view,
3847 icon_view->priv->cursor_item,
3853 if (icon_view->priv->ctrl_pressed ||
3854 !icon_view->priv->shift_pressed ||
3855 !icon_view->priv->anchor_item ||
3856 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3857 icon_view->priv->anchor_item = item;
3859 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3861 if (!icon_view->priv->ctrl_pressed &&
3862 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3864 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3865 dirty = gtk_icon_view_select_all_between (icon_view,
3866 icon_view->priv->anchor_item,
3870 gtk_icon_view_scroll_to_item (icon_view, item);
3873 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3877 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3880 GtkIconViewItem *item;
3882 gboolean dirty = FALSE;
3885 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3888 if (!icon_view->priv->cursor_item)
3893 list = icon_view->priv->items;
3895 list = g_list_last (icon_view->priv->items);
3897 item = list ? list->data : NULL;
3901 item = icon_view->priv->cursor_item;
3902 cell = icon_view->priv->cursor_cell;
3903 step = count > 0 ? 1 : -1;
3906 cell = find_cell (icon_view, item, cell,
3907 GTK_ORIENTATION_HORIZONTAL,
3912 item = find_item (icon_view, item, 0, step);
3913 count = count - step;
3920 if (icon_view->priv->ctrl_pressed ||
3921 !icon_view->priv->shift_pressed ||
3922 !icon_view->priv->anchor_item ||
3923 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3924 icon_view->priv->anchor_item = item;
3926 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3928 if (!icon_view->priv->ctrl_pressed &&
3929 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3931 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3932 dirty = gtk_icon_view_select_all_between (icon_view,
3933 icon_view->priv->anchor_item,
3937 gtk_icon_view_scroll_to_item (icon_view, item);
3940 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3944 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3947 GtkIconViewItem *item;
3949 gboolean dirty = FALSE;
3951 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3955 list = icon_view->priv->items;
3957 list = g_list_last (icon_view->priv->items);
3959 item = list ? list->data : NULL;
3964 if (icon_view->priv->ctrl_pressed ||
3965 !icon_view->priv->shift_pressed ||
3966 !icon_view->priv->anchor_item ||
3967 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3968 icon_view->priv->anchor_item = item;
3970 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3972 if (!icon_view->priv->ctrl_pressed &&
3973 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3975 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3976 dirty = gtk_icon_view_select_all_between (icon_view,
3977 icon_view->priv->anchor_item,
3981 gtk_icon_view_scroll_to_item (icon_view, item);
3984 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3988 * gtk_icon_view_scroll_to_path:
3989 * @icon_view: A #GtkIconView.
3990 * @path: The path of the item to move to.
3991 * @use_align: whether to use alignment arguments, or %FALSE.
3992 * @row_align: The vertical alignment of the item specified by @path.
3993 * @col_align: The horizontal alignment of the item specified by @path.
3995 * Moves the alignments of @icon_view to the position specified by @path.
3996 * @row_align determines where the row is placed, and @col_align determines
3997 * where @column is placed. Both are expected to be between 0.0 and 1.0.
3998 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4001 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4002 * tree does the minimum amount of work to scroll the item onto the screen.
4003 * This means that the item will be scrolled to the edge closest to its current
4004 * position. If the item is currently visible on the screen, nothing is done.
4006 * This function only works if the model is set, and @path is a valid row on
4007 * the model. If the model changes before the @icon_view is realized, the
4008 * centered path will be modified to reflect this change.
4013 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4019 GtkIconViewItem *item = NULL;
4021 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4022 g_return_if_fail (path != NULL);
4023 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4024 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4026 if (gtk_tree_path_get_depth (path) > 0)
4027 item = g_list_nth_data (icon_view->priv->items,
4028 gtk_tree_path_get_indices(path)[0]);
4030 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4032 if (icon_view->priv->scroll_to_path)
4033 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4035 icon_view->priv->scroll_to_path = NULL;
4038 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4040 icon_view->priv->scroll_to_use_align = use_align;
4041 icon_view->priv->scroll_to_row_align = row_align;
4042 icon_view->priv->scroll_to_col_align = col_align;
4051 gfloat offset, value;
4053 gtk_widget_style_get (GTK_WIDGET (icon_view),
4054 "focus-line-width", &focus_width,
4057 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4059 offset = y + item->y - focus_width -
4060 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4061 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4062 icon_view->priv->vadjustment->lower,
4063 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4064 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4066 offset = x + item->x - focus_width -
4067 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4068 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4069 icon_view->priv->hadjustment->lower,
4070 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4071 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4073 gtk_adjustment_changed (icon_view->priv->hadjustment);
4074 gtk_adjustment_changed (icon_view->priv->vadjustment);
4077 gtk_icon_view_scroll_to_item (icon_view, item);
4082 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4083 GtkIconViewItem *item)
4085 gint x, y, width, height;
4088 gtk_widget_style_get (GTK_WIDGET (icon_view),
4089 "focus-line-width", &focus_width,
4092 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4094 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4096 if (y + item->y - focus_width < 0)
4097 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4098 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4099 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4100 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4101 icon_view->priv->vadjustment->value + y + item->y + item->height
4102 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4104 if (x + item->x - focus_width < 0)
4105 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4106 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4107 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4108 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4109 icon_view->priv->hadjustment->value + x + item->x + item->width
4110 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4112 gtk_adjustment_changed (icon_view->priv->hadjustment);
4113 gtk_adjustment_changed (icon_view->priv->vadjustment);
4116 /* GtkCellLayout implementation */
4117 static GtkIconViewCellInfo *
4118 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4119 GtkCellRenderer *renderer)
4123 for (i = icon_view->priv->cell_list; i; i = i->next)
4125 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4127 if (info->cell == renderer)
4135 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4136 GtkIconViewItem *item)
4139 gboolean iters_persist;
4142 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4148 path = gtk_tree_path_new_from_indices (item->index, -1);
4149 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4150 gtk_tree_path_free (path);
4155 for (i = icon_view->priv->cell_list; i; i = i->next)
4158 GtkIconViewCellInfo *info = i->data;
4160 g_object_freeze_notify (G_OBJECT (info->cell));
4162 for (j = info->attributes; j && j->next; j = j->next->next)
4164 gchar *property = j->data;
4165 gint column = GPOINTER_TO_INT (j->next->data);
4166 GValue value = {0, };
4168 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4170 g_object_set_property (G_OBJECT (info->cell),
4172 g_value_unset (&value);
4176 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4178 icon_view->priv->model,
4182 g_object_thaw_notify (G_OBJECT (info->cell));
4185 adjust_wrap_width (icon_view, item);
4189 free_cell_attributes (GtkIconViewCellInfo *info)
4193 list = info->attributes;
4194 while (list && list->next)
4196 g_free (list->data);
4197 list = list->next->next;
4200 g_slist_free (info->attributes);
4201 info->attributes = NULL;
4205 free_cell_info (GtkIconViewCellInfo *info)
4207 free_cell_attributes (info);
4209 g_object_unref (info->cell);
4212 (* info->destroy) (info->func_data);
4218 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4219 GtkCellRenderer *renderer,
4222 GtkIconViewCellInfo *info;
4223 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4225 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4226 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4228 g_object_ref_sink (renderer);
4230 info = g_new0 (GtkIconViewCellInfo, 1);
4231 info->cell = renderer;
4232 info->expand = expand ? TRUE : FALSE;
4233 info->pack = GTK_PACK_START;
4234 info->position = icon_view->priv->n_cells;
4236 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4237 icon_view->priv->n_cells++;
4241 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4242 GtkCellRenderer *renderer,
4245 GtkIconViewCellInfo *info;
4246 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4248 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4249 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4251 g_object_ref_sink (renderer);
4253 info = g_new0 (GtkIconViewCellInfo, 1);
4254 info->cell = renderer;
4255 info->expand = expand ? TRUE : FALSE;
4256 info->pack = GTK_PACK_END;
4257 info->position = icon_view->priv->n_cells;
4259 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4260 icon_view->priv->n_cells++;
4264 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4265 GtkCellRenderer *renderer,
4266 const gchar *attribute,
4269 GtkIconViewCellInfo *info;
4270 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4272 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4273 g_return_if_fail (info != NULL);
4275 info->attributes = g_slist_prepend (info->attributes,
4276 GINT_TO_POINTER (column));
4277 info->attributes = g_slist_prepend (info->attributes,
4278 g_strdup (attribute));
4282 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4284 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4286 while (icon_view->priv->cell_list)
4288 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4289 free_cell_info (info);
4290 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4291 icon_view->priv->cell_list);
4294 icon_view->priv->n_cells = 0;
4298 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4299 GtkCellRenderer *cell,
4300 GtkCellLayoutDataFunc func,
4302 GDestroyNotify destroy)
4304 GtkIconViewCellInfo *info;
4305 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4307 info = gtk_icon_view_get_cell_info (icon_view, cell);
4308 g_return_if_fail (info != NULL);
4312 GDestroyNotify d = info->destroy;
4314 info->destroy = NULL;
4315 d (info->func_data);
4319 info->func_data = func_data;
4320 info->destroy = destroy;
4324 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4325 GtkCellRenderer *renderer)
4327 GtkIconViewCellInfo *info;
4329 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4331 free_cell_attributes (info);
4335 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4336 GtkCellRenderer *cell,
4339 GtkIconView *icon_view;
4341 GtkIconViewCellInfo *info;
4344 icon_view = GTK_ICON_VIEW (layout);
4346 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4348 info = gtk_icon_view_get_cell_info (icon_view, cell);
4350 g_return_if_fail (info != NULL);
4351 g_return_if_fail (position >= 0);
4353 link = g_list_find (icon_view->priv->cell_list, info);
4355 g_return_if_fail (link != NULL);
4357 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4359 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4362 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4369 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4376 * gtk_icon_view_new:
4378 * Creates a new #GtkIconView widget
4380 * Return value: A newly created #GtkIconView widget
4385 gtk_icon_view_new (void)
4387 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4391 * gtk_icon_view_new_with_model:
4392 * @model: The model.
4394 * Creates a new #GtkIconView widget with the model @model.
4396 * Return value: A newly created #GtkIconView widget.
4401 gtk_icon_view_new_with_model (GtkTreeModel *model)
4403 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4408 * gtk_icon_view_get_path_at_pos:
4409 * @icon_view: A #GtkIconView.
4410 * @x: The x position to be identified
4411 * @y: The y position to be identified
4413 * Finds the path at the point (@x, @y), relative to widget coordinates.
4414 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4415 * the cell at the specified position.
4417 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4418 * if no icon exists at that position.
4423 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4427 GtkIconViewItem *item;
4430 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4432 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4437 path = gtk_tree_path_new_from_indices (item->index, -1);
4443 * gtk_icon_view_get_item_at_pos:
4444 * @icon_view: A #GtkIconView.
4445 * @x: The x position to be identified
4446 * @y: The y position to be identified
4447 * @path: Return location for the path, or %NULL
4448 * @cell: Return location for the renderer responsible for the cell
4449 * at (@x, @y), or %NULL
4451 * Finds the path at the point (@x, @y), relative to widget coordinates.
4452 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4453 * obtains the cell at the specified position. The returned path should
4454 * be freed with gtk_tree_path_free().
4456 * Return value: %TRUE if an item exists at the specified position
4461 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4465 GtkCellRenderer **cell)
4467 GtkIconViewItem *item;
4468 GtkIconViewCellInfo *info;
4470 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4472 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4477 *path = gtk_tree_path_new_from_indices (item->index, -1);
4490 return (item != NULL);
4495 * gtk_icon_view_get_visible_range:
4496 * @icon_view: A #GtkIconView
4497 * @start_path: Return location for start of region, or %NULL
4498 * @end_path: Return location for end of region, or %NULL
4500 * Sets @start_path and @end_path to be the first and last visible path.
4501 * Note that there may be invisible paths in between.
4503 * Both paths should be freed with gtk_tree_path_free() after use.
4505 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4510 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4511 GtkTreePath **start_path,
4512 GtkTreePath **end_path)
4514 gint start_index = -1;
4515 gint end_index = -1;
4518 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4520 if (icon_view->priv->hadjustment == NULL ||
4521 icon_view->priv->vadjustment == NULL)
4524 if (start_path == NULL && end_path == NULL)
4527 for (icons = icon_view->priv->items; icons; icons = icons->next)
4529 GtkIconViewItem *item = icons->data;
4531 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4532 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4533 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4534 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4536 if (start_index == -1)
4537 start_index = item->index;
4538 end_index = item->index;
4542 if (start_path && start_index != -1)
4543 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4544 if (end_path && end_index != -1)
4545 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4547 return start_index != -1;
4551 * gtk_icon_view_selected_foreach:
4552 * @icon_view: A #GtkIconView.
4553 * @func: The funcion to call for each selected icon.
4554 * @data: User data to pass to the function.
4556 * Calls a function for each selected icon. Note that the model or
4557 * selection cannot be modified from within this function.
4562 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4563 GtkIconViewForeachFunc func,
4568 for (list = icon_view->priv->items; list; list = list->next)
4570 GtkIconViewItem *item = list->data;
4571 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4574 (* func) (icon_view, path, data);
4576 gtk_tree_path_free (path);
4581 * gtk_icon_view_set_selection_mode:
4582 * @icon_view: A #GtkIconView.
4583 * @mode: The selection mode
4585 * Sets the selection mode of the @icon_view.
4590 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4591 GtkSelectionMode mode)
4593 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4595 if (mode == icon_view->priv->selection_mode)
4598 if (mode == GTK_SELECTION_NONE ||
4599 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4600 gtk_icon_view_unselect_all (icon_view);
4602 icon_view->priv->selection_mode = mode;
4604 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4608 * gtk_icon_view_get_selection_mode:
4609 * @icon_view: A #GtkIconView.
4611 * Gets the selection mode of the @icon_view.
4613 * Return value: the current selection mode
4618 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4620 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4622 return icon_view->priv->selection_mode;
4626 * gtk_icon_view_set_model:
4627 * @icon_view: A #GtkIconView.
4628 * @model: The model.
4630 * Sets the model for a #GtkIconView.
4631 * If the @icon_view already has a model set, it will remove
4632 * it before setting the new model. If @model is %NULL, then
4633 * it will unset the old model.
4638 gtk_icon_view_set_model (GtkIconView *icon_view,
4639 GtkTreeModel *model)
4641 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4642 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4644 if (icon_view->priv->model == model)
4647 if (icon_view->priv->scroll_to_path)
4649 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4650 icon_view->priv->scroll_to_path = NULL;
4653 gtk_icon_view_stop_editing (icon_view, TRUE);
4659 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4661 if (icon_view->priv->pixbuf_column != -1)
4663 column_type = gtk_tree_model_get_column_type (model,
4664 icon_view->priv->pixbuf_column);
4666 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4669 if (icon_view->priv->text_column != -1)
4671 column_type = gtk_tree_model_get_column_type (model,
4672 icon_view->priv->text_column);
4674 g_return_if_fail (column_type == G_TYPE_STRING);
4677 if (icon_view->priv->markup_column != -1)
4679 column_type = gtk_tree_model_get_column_type (model,
4680 icon_view->priv->markup_column);
4682 g_return_if_fail (column_type == G_TYPE_STRING);
4687 if (icon_view->priv->model)
4689 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4690 gtk_icon_view_row_changed,
4692 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4693 gtk_icon_view_row_inserted,
4695 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4696 gtk_icon_view_row_deleted,
4698 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4699 gtk_icon_view_rows_reordered,
4702 g_object_unref (icon_view->priv->model);
4704 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4705 g_list_free (icon_view->priv->items);
4706 icon_view->priv->items = NULL;
4707 icon_view->priv->anchor_item = NULL;
4708 icon_view->priv->cursor_item = NULL;
4709 icon_view->priv->last_single_clicked = NULL;
4710 icon_view->priv->width = 0;
4711 icon_view->priv->height = 0;
4714 icon_view->priv->model = model;
4716 if (icon_view->priv->model)
4718 g_object_ref (icon_view->priv->model);
4719 g_signal_connect (icon_view->priv->model,
4721 G_CALLBACK (gtk_icon_view_row_changed),
4723 g_signal_connect (icon_view->priv->model,
4725 G_CALLBACK (gtk_icon_view_row_inserted),
4727 g_signal_connect (icon_view->priv->model,
4729 G_CALLBACK (gtk_icon_view_row_deleted),
4731 g_signal_connect (icon_view->priv->model,
4733 G_CALLBACK (gtk_icon_view_rows_reordered),
4736 gtk_icon_view_build_items (icon_view);
4738 gtk_icon_view_queue_layout (icon_view);
4741 g_object_notify (G_OBJECT (icon_view), "model");
4743 if (GTK_WIDGET_REALIZED (icon_view))
4744 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4748 * gtk_icon_view_get_model:
4749 * @icon_view: a #GtkIconView
4751 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4754 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4759 gtk_icon_view_get_model (GtkIconView *icon_view)
4761 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4763 return icon_view->priv->model;
4767 update_text_cell (GtkIconView *icon_view)
4769 GtkIconViewCellInfo *info;
4773 if (icon_view->priv->text_column == -1 &&
4774 icon_view->priv->markup_column == -1)
4776 if (icon_view->priv->text_cell != -1)
4778 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4779 icon_view->priv->pixbuf_cell--;
4781 info = g_list_nth_data (icon_view->priv->cell_list,
4782 icon_view->priv->text_cell);
4784 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4786 free_cell_info (info);
4788 icon_view->priv->n_cells--;
4789 icon_view->priv->text_cell = -1;
4794 if (icon_view->priv->text_cell == -1)
4796 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4797 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4798 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4801 if (info->cell == cell)
4803 icon_view->priv->text_cell = i;
4809 info = g_list_nth_data (icon_view->priv->cell_list,
4810 icon_view->priv->text_cell);
4812 if (icon_view->priv->markup_column != -1)
4813 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4815 "markup", icon_view->priv->markup_column,
4818 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4820 "text", icon_view->priv->text_column,
4823 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4824 g_object_set (info->cell,
4825 "wrap-mode", PANGO_WRAP_CHAR,
4826 "wrap-width", icon_view->priv->item_width,
4831 g_object_set (info->cell,
4832 "wrap-mode", PANGO_WRAP_CHAR,
4833 "wrap-width", icon_view->priv->item_width,
4841 update_pixbuf_cell (GtkIconView *icon_view)
4843 GtkIconViewCellInfo *info;
4847 if (icon_view->priv->pixbuf_column == -1)
4849 if (icon_view->priv->pixbuf_cell != -1)
4851 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4852 icon_view->priv->text_cell--;
4854 info = g_list_nth_data (icon_view->priv->cell_list,
4855 icon_view->priv->pixbuf_cell);
4857 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4859 free_cell_info (info);
4861 icon_view->priv->n_cells--;
4862 icon_view->priv->pixbuf_cell = -1;
4867 if (icon_view->priv->pixbuf_cell == -1)
4869 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4871 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4872 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4875 if (info->cell == cell)
4877 icon_view->priv->pixbuf_cell = i;
4883 info = g_list_nth_data (icon_view->priv->cell_list,
4884 icon_view->priv->pixbuf_cell);
4886 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4888 "pixbuf", icon_view->priv->pixbuf_column,
4891 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4892 g_object_set (info->cell,
4893 "follow-state", TRUE,
4898 g_object_set (info->cell,
4899 "follow-state", TRUE,
4907 * gtk_icon_view_set_text_column:
4908 * @icon_view: A #GtkIconView.
4909 * @column: A column in the currently used model.
4911 * Sets the column with text for @icon_view to be @column. The text
4912 * column must be of type #G_TYPE_STRING.
4917 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4920 if (column == icon_view->priv->text_column)
4924 icon_view->priv->text_column = -1;
4927 if (icon_view->priv->model != NULL)
4931 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4933 g_return_if_fail (column_type == G_TYPE_STRING);
4936 icon_view->priv->text_column = column;
4939 gtk_icon_view_stop_editing (icon_view, TRUE);
4941 update_text_cell (icon_view);
4943 gtk_icon_view_invalidate_sizes (icon_view);
4944 gtk_icon_view_queue_layout (icon_view);
4946 g_object_notify (G_OBJECT (icon_view), "text-column");
4950 * gtk_icon_view_get_text_column:
4951 * @icon_view: A #GtkIconView.
4953 * Returns the column with text for @icon_view.
4955 * Returns: the text column, or -1 if it's unset.
4960 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4962 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4964 return icon_view->priv->text_column;
4968 * gtk_icon_view_set_markup_column:
4969 * @icon_view: A #GtkIconView.
4970 * @column: A column in the currently used model.
4972 * Sets the column with markup information for @icon_view to be
4973 * @column. The markup column must be of type #G_TYPE_STRING.
4974 * If the markup column is set to something, it overrides
4975 * the text column set by gtk_icon_view_set_text_column().
4980 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4983 if (column == icon_view->priv->markup_column)
4987 icon_view->priv->markup_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 == G_TYPE_STRING);
4999 icon_view->priv->markup_column = column;
5002 gtk_icon_view_stop_editing (icon_view, TRUE);
5004 update_text_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), "markup-column");
5013 * gtk_icon_view_get_markup_column:
5014 * @icon_view: A #GtkIconView.
5016 * Returns the column with markup text for @icon_view.
5018 * Returns: the markup column, or -1 if it's unset.
5023 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5025 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5027 return icon_view->priv->markup_column;
5031 * gtk_icon_view_set_pixbuf_column:
5032 * @icon_view: A #GtkIconView.
5033 * @column: A column in the currently used model.
5035 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5036 * column must be of type #GDK_TYPE_PIXBUF
5041 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5044 if (column == icon_view->priv->pixbuf_column)
5048 icon_view->priv->pixbuf_column = -1;
5051 if (icon_view->priv->model != NULL)
5055 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5057 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5060 icon_view->priv->pixbuf_column = column;
5063 gtk_icon_view_stop_editing (icon_view, TRUE);
5065 update_pixbuf_cell (icon_view);
5067 gtk_icon_view_invalidate_sizes (icon_view);
5068 gtk_icon_view_queue_layout (icon_view);
5070 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5075 * gtk_icon_view_get_pixbuf_column:
5076 * @icon_view: A #GtkIconView.
5078 * Returns the column with pixbufs for @icon_view.
5080 * Returns: the pixbuf column, or -1 if it's unset.
5085 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5087 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5089 return icon_view->priv->pixbuf_column;
5093 * gtk_icon_view_select_path:
5094 * @icon_view: A #GtkIconView.
5095 * @path: The #GtkTreePath to be selected.
5097 * Selects the row at @path.
5102 gtk_icon_view_select_path (GtkIconView *icon_view,
5105 GtkIconViewItem *item = NULL;
5107 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5108 g_return_if_fail (icon_view->priv->model != NULL);
5109 g_return_if_fail (path != NULL);
5111 if (gtk_tree_path_get_depth (path) > 0)
5112 item = g_list_nth_data (icon_view->priv->items,
5113 gtk_tree_path_get_indices(path)[0]);
5116 gtk_icon_view_select_item (icon_view, item);
5120 * gtk_icon_view_unselect_path:
5121 * @icon_view: A #GtkIconView.
5122 * @path: The #GtkTreePath to be unselected.
5124 * Unselects the row at @path.
5129 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5132 GtkIconViewItem *item;
5134 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5135 g_return_if_fail (icon_view->priv->model != NULL);
5136 g_return_if_fail (path != NULL);
5138 item = g_list_nth_data (icon_view->priv->items,
5139 gtk_tree_path_get_indices(path)[0]);
5144 gtk_icon_view_unselect_item (icon_view, item);
5148 * gtk_icon_view_get_selected_items:
5149 * @icon_view: A #GtkIconView.
5151 * Creates a list of paths of all selected items. Additionally, if you are
5152 * planning on modifying the model after calling this function, you may
5153 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5154 * To do this, you can use gtk_tree_row_reference_new().
5156 * To free the return value, use:
5157 * <informalexample><programlisting>
5158 * g_list_foreach (list, gtk_tree_path_free, NULL);
5159 * g_list_free (list);
5160 * </programlisting></informalexample>
5162 * Return value: A #GList containing a #GtkTreePath for each selected row.
5167 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5170 GList *selected = NULL;
5172 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5174 for (list = icon_view->priv->items; list != NULL; list = list->next)
5176 GtkIconViewItem *item = list->data;
5180 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5182 selected = g_list_prepend (selected, path);
5190 * gtk_icon_view_select_all:
5191 * @icon_view: A #GtkIconView.
5193 * Selects all the icons. @icon_view must has its selection mode set
5194 * to #GTK_SELECTION_MULTIPLE.
5199 gtk_icon_view_select_all (GtkIconView *icon_view)
5202 gboolean dirty = FALSE;
5204 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5206 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5209 for (items = icon_view->priv->items; items; items = items->next)
5211 GtkIconViewItem *item = items->data;
5213 if (!item->selected)
5216 item->selected = TRUE;
5217 gtk_icon_view_queue_draw_item (icon_view, item);
5222 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5226 * gtk_icon_view_unselect_all:
5227 * @icon_view: A #GtkIconView.
5229 * Unselects all the icons.
5234 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5236 gboolean dirty = FALSE;
5238 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5240 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5243 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5246 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5250 * gtk_icon_view_path_is_selected:
5251 * @icon_view: A #GtkIconView.
5252 * @path: A #GtkTreePath to check selection on.
5254 * Returns %TRUE if the icon pointed to by @path is currently
5255 * selected. If @icon does not point to a valid location, %FALSE is returned.
5257 * Return value: %TRUE if @path is selected.
5262 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5265 GtkIconViewItem *item;
5267 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5268 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5269 g_return_val_if_fail (path != NULL, FALSE);
5271 item = g_list_nth_data (icon_view->priv->items,
5272 gtk_tree_path_get_indices(path)[0]);
5277 return item->selected;
5281 * gtk_icon_view_item_activated:
5282 * @icon_view: A #GtkIconView
5283 * @path: The #GtkTreePath to be activated
5285 * Activates the item determined by @path.
5290 gtk_icon_view_item_activated (GtkIconView *icon_view,
5293 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5294 g_return_if_fail (path != NULL);
5296 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5300 * gtk_icon_view_set_orientation:
5301 * @icon_view: a #GtkIconView
5302 * @orientation: the relative position of texts and icons
5304 * Sets the ::orientation property which determines whether the labels
5305 * are drawn beside the icons instead of below.
5310 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5311 GtkOrientation orientation)
5313 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5315 if (icon_view->priv->orientation != orientation)
5317 icon_view->priv->orientation = orientation;
5319 gtk_icon_view_stop_editing (icon_view, TRUE);
5320 gtk_icon_view_invalidate_sizes (icon_view);
5321 gtk_icon_view_queue_layout (icon_view);
5323 update_text_cell (icon_view);
5324 update_pixbuf_cell (icon_view);
5326 g_object_notify (G_OBJECT (icon_view), "orientation");
5331 * gtk_icon_view_get_orientation:
5332 * @icon_view: a #GtkIconView
5334 * Returns the value of the ::orientation property which determines
5335 * whether the labels are drawn beside the icons instead of below.
5337 * Return value: the relative position of texts and icons
5342 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5344 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5345 GTK_ORIENTATION_VERTICAL);
5347 return icon_view->priv->orientation;
5351 * gtk_icon_view_set_columns:
5352 * @icon_view: a #GtkIconView
5353 * @columns: the number of columns
5355 * Sets the ::columns property which determines in how
5356 * many columns the icons are arranged. If @columns is
5357 * -1, the number of columns will be chosen automatically
5358 * to fill the available area.
5363 gtk_icon_view_set_columns (GtkIconView *icon_view,
5366 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5368 if (icon_view->priv->columns != columns)
5370 icon_view->priv->columns = columns;
5372 gtk_icon_view_stop_editing (icon_view, TRUE);
5373 gtk_icon_view_queue_layout (icon_view);
5375 g_object_notify (G_OBJECT (icon_view), "columns");
5380 * gtk_icon_view_get_columns:
5381 * @icon_view: a #GtkIconView
5383 * Returns the value of the ::columns property.
5385 * Return value: the number of columns, or -1
5390 gtk_icon_view_get_columns (GtkIconView *icon_view)
5392 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5394 return icon_view->priv->columns;
5398 * gtk_icon_view_set_item_width:
5399 * @icon_view: a #GtkIconView
5400 * @item_width: the width for each item
5402 * Sets the ::item-width property which specifies the width
5403 * to use for each item. If it is set to -1, the icon view will
5404 * automatically determine a suitable item size.
5409 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5412 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5414 if (icon_view->priv->item_width != item_width)
5416 icon_view->priv->item_width = item_width;
5418 gtk_icon_view_stop_editing (icon_view, TRUE);
5419 gtk_icon_view_invalidate_sizes (icon_view);
5420 gtk_icon_view_queue_layout (icon_view);
5422 update_text_cell (icon_view);
5424 g_object_notify (G_OBJECT (icon_view), "item-width");
5429 * gtk_icon_view_get_item_width:
5430 * @icon_view: a #GtkIconView
5432 * Returns the value of the ::item-width property.
5434 * Return value: the width of a single item, or -1
5439 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5441 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5443 return icon_view->priv->item_width;
5448 * gtk_icon_view_set_spacing:
5449 * @icon_view: a #GtkIconView
5450 * @spacing: the spacing
5452 * Sets the ::spacing property which specifies the space
5453 * which is inserted between the cells (i.e. the icon and
5454 * the text) of an item.
5459 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5462 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5464 if (icon_view->priv->spacing != spacing)
5466 icon_view->priv->spacing = spacing;
5468 gtk_icon_view_stop_editing (icon_view, TRUE);
5469 gtk_icon_view_invalidate_sizes (icon_view);
5470 gtk_icon_view_queue_layout (icon_view);
5472 g_object_notify (G_OBJECT (icon_view), "spacing");
5477 * gtk_icon_view_get_spacing:
5478 * @icon_view: a #GtkIconView
5480 * Returns the value of the ::spacing property.
5482 * Return value: the space between cells
5487 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5489 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5491 return icon_view->priv->spacing;
5495 * gtk_icon_view_set_row_spacing:
5496 * @icon_view: a #GtkIconView
5497 * @row_spacing: the row spacing
5499 * Sets the ::row-spacing property which specifies the space
5500 * which is inserted between the rows of the icon view.
5505 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5508 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5510 if (icon_view->priv->row_spacing != row_spacing)
5512 icon_view->priv->row_spacing = row_spacing;
5514 gtk_icon_view_stop_editing (icon_view, TRUE);
5515 gtk_icon_view_invalidate_sizes (icon_view);
5516 gtk_icon_view_queue_layout (icon_view);
5518 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5523 * gtk_icon_view_get_row_spacing:
5524 * @icon_view: a #GtkIconView
5526 * Returns the value of the ::row-spacing property.
5528 * Return value: the space between rows
5533 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5535 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5537 return icon_view->priv->row_spacing;
5541 * gtk_icon_view_set_column_spacing:
5542 * @icon_view: a #GtkIconView
5543 * @column_spacing: the column spacing
5545 * Sets the ::column-spacing property which specifies the space
5546 * which is inserted between the columns of the icon view.
5551 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5552 gint column_spacing)
5554 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5556 if (icon_view->priv->column_spacing != column_spacing)
5558 icon_view->priv->column_spacing = column_spacing;
5560 gtk_icon_view_stop_editing (icon_view, TRUE);
5561 gtk_icon_view_invalidate_sizes (icon_view);
5562 gtk_icon_view_queue_layout (icon_view);
5564 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5569 * gtk_icon_view_get_column_spacing:
5570 * @icon_view: a #GtkIconView
5572 * Returns the value of the ::column-spacing property.
5574 * Return value: the space between columns
5579 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5581 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5583 return icon_view->priv->column_spacing;
5587 * gtk_icon_view_set_margin:
5588 * @icon_view: a #GtkIconView
5589 * @margin: the margin
5591 * Sets the ::margin property which specifies the space
5592 * which is inserted at the top, bottom, left and right
5598 gtk_icon_view_set_margin (GtkIconView *icon_view,
5601 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5603 if (icon_view->priv->margin != margin)
5605 icon_view->priv->margin = margin;
5607 gtk_icon_view_stop_editing (icon_view, TRUE);
5608 gtk_icon_view_invalidate_sizes (icon_view);
5609 gtk_icon_view_queue_layout (icon_view);
5611 g_object_notify (G_OBJECT (icon_view), "margin");
5616 * gtk_icon_view_get_margin:
5617 * @icon_view: a #GtkIconView
5619 * Returns the value of the ::margin property.
5621 * Return value: the space at the borders
5626 gtk_icon_view_get_margin (GtkIconView *icon_view)
5628 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5630 return icon_view->priv->margin;
5634 /* Get/set whether drag_motion requested the drag data and
5635 * drag_data_received should thus not actually insert the data,
5636 * since the data doesn't result from a drop.
5639 set_status_pending (GdkDragContext *context,
5640 GdkDragAction suggested_action)
5642 g_object_set_data (G_OBJECT (context),
5643 I_("gtk-icon-view-status-pending"),
5644 GINT_TO_POINTER (suggested_action));
5647 static GdkDragAction
5648 get_status_pending (GdkDragContext *context)
5650 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5651 "gtk-icon-view-status-pending"));
5655 unset_reorderable (GtkIconView *icon_view)
5657 if (icon_view->priv->reorderable)
5659 icon_view->priv->reorderable = FALSE;
5660 g_object_notify (G_OBJECT (icon_view), "reorderable");
5665 clear_source_info (GtkIconView *icon_view)
5667 if (icon_view->priv->source_targets)
5668 gtk_target_list_unref (icon_view->priv->source_targets);
5669 icon_view->priv->source_targets = NULL;
5671 icon_view->priv->source_set = FALSE;
5675 clear_dest_info (GtkIconView *icon_view)
5677 if (icon_view->priv->dest_targets)
5678 gtk_target_list_unref (icon_view->priv->dest_targets);
5679 icon_view->priv->dest_targets = NULL;
5681 icon_view->priv->dest_set = FALSE;
5685 set_source_row (GdkDragContext *context,
5686 GtkTreeModel *model,
5687 GtkTreePath *source_row)
5690 g_object_set_data_full (G_OBJECT (context),
5691 I_("gtk-icon-view-source-row"),
5692 gtk_tree_row_reference_new (model, source_row),
5693 (GDestroyNotify) gtk_tree_row_reference_free);
5695 g_object_set_data_full (G_OBJECT (context),
5696 I_("gtk-icon-view-source-row"),
5701 get_source_row (GdkDragContext *context)
5703 GtkTreeRowReference *ref;
5705 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5708 return gtk_tree_row_reference_get_path (ref);
5715 GtkTreeRowReference *dest_row;
5716 gboolean empty_view_drop;
5717 gboolean drop_append_mode;
5721 dest_row_free (gpointer data)
5723 DestRow *dr = (DestRow *)data;
5725 gtk_tree_row_reference_free (dr->dest_row);
5730 set_dest_row (GdkDragContext *context,
5731 GtkTreeModel *model,
5732 GtkTreePath *dest_row,
5733 gboolean empty_view_drop,
5734 gboolean drop_append_mode)
5740 g_object_set_data_full (G_OBJECT (context),
5741 I_("gtk-icon-view-dest-row"),
5746 dr = g_new0 (DestRow, 1);
5748 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5749 dr->empty_view_drop = empty_view_drop;
5750 dr->drop_append_mode = drop_append_mode;
5751 g_object_set_data_full (G_OBJECT (context),
5752 I_("gtk-icon-view-dest-row"),
5753 dr, (GDestroyNotify) dest_row_free);
5757 get_dest_row (GdkDragContext *context)
5761 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5765 GtkTreePath *path = NULL;
5768 path = gtk_tree_row_reference_get_path (dr->dest_row);
5769 else if (dr->empty_view_drop)
5770 path = gtk_tree_path_new_from_indices (0, -1);
5774 if (path && dr->drop_append_mode)
5775 gtk_tree_path_next (path);
5784 check_model_dnd (GtkTreeModel *model,
5785 GType required_iface,
5786 const gchar *signal)
5788 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5790 g_warning ("You must override the default '%s' handler "
5791 "on GtkIconView when using models that don't support "
5792 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5793 "is to connect to '%s' and call "
5794 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5795 "the default handler from running. Look at the source code "
5796 "for the default handler in gtkiconview.c to get an idea what "
5797 "your handler should do. (gtkiconview.c is in the GTK+ source "
5798 "code.) If you're using GTK+ from a language other than C, "
5799 "there may be a more natural way to override default handlers, e.g. via derivation.",
5800 signal, g_type_name (required_iface), signal);
5808 remove_scroll_timeout (GtkIconView *icon_view)
5810 if (icon_view->priv->scroll_timeout_id != 0)
5812 g_source_remove (icon_view->priv->scroll_timeout_id);
5814 icon_view->priv->scroll_timeout_id = 0;
5819 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5821 gint px, py, x, y, width, height;
5822 gint hoffset, voffset;
5825 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5826 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5828 /* see if we are near the edge. */
5829 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5831 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5833 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5835 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5839 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5840 icon_view->priv->vadjustment->lower,
5841 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5842 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5846 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5847 icon_view->priv->hadjustment->lower,
5848 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5849 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5855 drag_scroll_timeout (gpointer data)
5857 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5859 GDK_THREADS_ENTER ();
5861 gtk_icon_view_autoscroll (icon_view);
5863 GDK_THREADS_LEAVE ();
5870 set_destination (GtkIconView *icon_view,
5871 GdkDragContext *context,
5874 GdkDragAction *suggested_action,
5878 GtkTreePath *path = NULL;
5879 GtkIconViewDropPosition pos;
5880 GtkIconViewDropPosition old_pos;
5881 GtkTreePath *old_dest_path = NULL;
5882 gboolean can_drop = FALSE;
5884 widget = GTK_WIDGET (icon_view);
5886 *suggested_action = 0;
5889 if (!icon_view->priv->dest_set)
5891 /* someone unset us as a drag dest, note that if
5892 * we return FALSE drag_leave isn't called
5895 gtk_icon_view_set_drag_dest_item (icon_view,
5897 GTK_ICON_VIEW_DROP_LEFT);
5899 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5901 return FALSE; /* no longer a drop site */
5904 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5905 if (*target == GDK_NONE)
5908 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5911 GtkTreeModel *model;
5913 /* the row got dropped on empty space, let's setup a special case
5917 gtk_tree_path_free (path);
5919 model = gtk_icon_view_get_model (icon_view);
5921 n_children = gtk_tree_model_iter_n_children (model, NULL);
5924 pos = GTK_ICON_VIEW_DROP_BELOW;
5925 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5929 pos = GTK_ICON_VIEW_DROP_ABOVE;
5930 path = gtk_tree_path_new_from_indices (0, -1);
5940 gtk_icon_view_get_drag_dest_item (icon_view,
5945 gtk_tree_path_free (old_dest_path);
5947 if (TRUE /* FIXME if the location droppable predicate */)
5955 GtkWidget *source_widget;
5957 *suggested_action = context->suggested_action;
5958 source_widget = gtk_drag_get_source_widget (context);
5960 if (source_widget == widget)
5962 /* Default to MOVE, unless the user has
5963 * pressed ctrl or shift to affect available actions
5965 if ((context->actions & GDK_ACTION_MOVE) != 0)
5966 *suggested_action = GDK_ACTION_MOVE;
5969 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5974 /* can't drop here */
5975 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5977 GTK_ICON_VIEW_DROP_LEFT);
5981 gtk_tree_path_free (path);
5987 get_logical_destination (GtkIconView *icon_view,
5988 gboolean *drop_append_mode)
5990 /* adjust path to point to the row the drop goes in front of */
5991 GtkTreePath *path = NULL;
5992 GtkIconViewDropPosition pos;
5994 *drop_append_mode = FALSE;
5996 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6001 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6002 pos == GTK_ICON_VIEW_DROP_BELOW)
6005 GtkTreeModel *model = icon_view->priv->model;
6007 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6008 !gtk_tree_model_iter_next (model, &iter))
6009 *drop_append_mode = TRUE;
6012 *drop_append_mode = FALSE;
6013 gtk_tree_path_next (path);
6021 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6022 GdkEventMotion *event)
6024 GdkDragContext *context;
6025 GtkTreePath *path = NULL;
6027 GtkTreeModel *model;
6028 gboolean retval = FALSE;
6030 if (!icon_view->priv->source_set)
6033 if (icon_view->priv->pressed_button < 0)
6036 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6037 icon_view->priv->press_start_x,
6038 icon_view->priv->press_start_y,
6039 event->x, event->y))
6042 model = gtk_icon_view_get_model (icon_view);
6047 button = icon_view->priv->pressed_button;
6048 icon_view->priv->pressed_button = -1;
6050 path = gtk_icon_view_get_path_at_pos (icon_view,
6051 icon_view->priv->press_start_x,
6052 icon_view->priv->press_start_y);
6057 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6058 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6062 /* FIXME Check whether we're a start button, if not return FALSE and
6066 /* Now we can begin the drag */
6070 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6071 icon_view->priv->source_targets,
6072 icon_view->priv->source_actions,
6076 set_source_row (context, model, path);
6080 gtk_tree_path_free (path);
6085 /* Source side drag signals */
6087 gtk_icon_view_drag_begin (GtkWidget *widget,
6088 GdkDragContext *context)
6090 GtkIconView *icon_view;
6091 GtkIconViewItem *item;
6096 icon_view = GTK_ICON_VIEW (widget);
6098 /* if the user uses a custom DnD impl, we don't set the icon here */
6099 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6102 item = gtk_icon_view_get_item_at_coords (icon_view,
6103 icon_view->priv->press_start_x,
6104 icon_view->priv->press_start_y,
6108 g_return_if_fail (item != NULL);
6110 x = icon_view->priv->press_start_x - item->x + 1;
6111 y = icon_view->priv->press_start_y - item->y + 1;
6113 path = gtk_tree_path_new_from_indices (item->index, -1);
6114 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6115 gtk_tree_path_free (path);
6117 gtk_drag_set_icon_pixmap (context,
6118 gdk_drawable_get_colormap (icon),
6123 g_object_unref (icon);
6127 gtk_icon_view_drag_end (GtkWidget *widget,
6128 GdkDragContext *context)
6134 gtk_icon_view_drag_data_get (GtkWidget *widget,
6135 GdkDragContext *context,
6136 GtkSelectionData *selection_data,
6140 GtkIconView *icon_view;
6141 GtkTreeModel *model;
6142 GtkTreePath *source_row;
6144 icon_view = GTK_ICON_VIEW (widget);
6145 model = gtk_icon_view_get_model (icon_view);
6150 if (!icon_view->priv->dest_set)
6153 source_row = get_source_row (context);
6155 if (source_row == NULL)
6158 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6159 * any model; for DragSource models there are some other targets
6163 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6164 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6169 /* If drag_data_get does nothing, try providing row data. */
6170 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6171 gtk_tree_set_row_drag_data (selection_data,
6176 gtk_tree_path_free (source_row);
6180 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6181 GdkDragContext *context)
6183 GtkTreeModel *model;
6184 GtkIconView *icon_view;
6185 GtkTreePath *source_row;
6187 icon_view = GTK_ICON_VIEW (widget);
6188 model = gtk_icon_view_get_model (icon_view);
6190 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6193 if (!icon_view->priv->dest_set)
6196 source_row = get_source_row (context);
6198 if (source_row == NULL)
6201 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6204 gtk_tree_path_free (source_row);
6206 set_source_row (context, NULL, NULL);
6209 /* Target side drag signals */
6211 gtk_icon_view_drag_leave (GtkWidget *widget,
6212 GdkDragContext *context,
6215 GtkIconView *icon_view;
6217 icon_view = GTK_ICON_VIEW (widget);
6219 /* unset any highlight row */
6220 gtk_icon_view_set_drag_dest_item (icon_view,
6222 GTK_ICON_VIEW_DROP_LEFT);
6224 remove_scroll_timeout (icon_view);
6228 gtk_icon_view_drag_motion (GtkWidget *widget,
6229 GdkDragContext *context,
6234 GtkTreePath *path = NULL;
6235 GtkIconViewDropPosition pos;
6236 GtkIconView *icon_view;
6237 GdkDragAction suggested_action = 0;
6241 icon_view = GTK_ICON_VIEW (widget);
6243 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6246 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6248 /* we only know this *after* set_desination_row */
6249 empty = icon_view->priv->empty_view_drop;
6251 if (path == NULL && !empty)
6253 /* Can't drop here. */
6254 gdk_drag_status (context, 0, time);
6258 if (icon_view->priv->scroll_timeout_id == 0)
6260 icon_view->priv->scroll_timeout_id =
6261 g_timeout_add (50, drag_scroll_timeout, icon_view);
6264 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6266 /* Request data so we can use the source row when
6267 * determining whether to accept the drop
6269 set_status_pending (context, suggested_action);
6270 gtk_drag_get_data (widget, context, target, time);
6274 set_status_pending (context, 0);
6275 gdk_drag_status (context, suggested_action, time);
6280 gtk_tree_path_free (path);
6286 gtk_icon_view_drag_drop (GtkWidget *widget,
6287 GdkDragContext *context,
6292 GtkIconView *icon_view;
6294 GdkDragAction suggested_action = 0;
6295 GdkAtom target = GDK_NONE;
6296 GtkTreeModel *model;
6297 gboolean drop_append_mode;
6299 icon_view = GTK_ICON_VIEW (widget);
6300 model = gtk_icon_view_get_model (icon_view);
6302 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6304 if (!icon_view->priv->dest_set)
6307 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6310 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6313 path = get_logical_destination (icon_view, &drop_append_mode);
6315 if (target != GDK_NONE && path != NULL)
6317 /* in case a motion had requested drag data, change things so we
6318 * treat drag data receives as a drop.
6320 set_status_pending (context, 0);
6321 set_dest_row (context, model, path,
6322 icon_view->priv->empty_view_drop, drop_append_mode);
6326 gtk_tree_path_free (path);
6328 /* Unset this thing */
6329 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6331 if (target != GDK_NONE)
6333 gtk_drag_get_data (widget, context, target, time);
6341 gtk_icon_view_drag_data_received (GtkWidget *widget,
6342 GdkDragContext *context,
6345 GtkSelectionData *selection_data,
6350 gboolean accepted = FALSE;
6351 GtkTreeModel *model;
6352 GtkIconView *icon_view;
6353 GtkTreePath *dest_row;
6354 GdkDragAction suggested_action;
6355 gboolean drop_append_mode;
6357 icon_view = GTK_ICON_VIEW (widget);
6358 model = gtk_icon_view_get_model (icon_view);
6360 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6363 if (!icon_view->priv->dest_set)
6366 suggested_action = get_status_pending (context);
6368 if (suggested_action)
6370 /* We are getting this data due to a request in drag_motion,
6371 * rather than due to a request in drag_drop, so we are just
6372 * supposed to call drag_status, not actually paste in the
6375 path = get_logical_destination (icon_view, &drop_append_mode);
6378 suggested_action = 0;
6380 if (suggested_action)
6382 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6385 suggested_action = 0;
6388 gdk_drag_status (context, suggested_action, time);
6391 gtk_tree_path_free (path);
6393 /* If you can't drop, remove user drop indicator until the next motion */
6394 if (suggested_action == 0)
6395 gtk_icon_view_set_drag_dest_item (icon_view,
6397 GTK_ICON_VIEW_DROP_LEFT);
6402 dest_row = get_dest_row (context);
6404 if (dest_row == NULL)
6407 if (selection_data->length >= 0)
6409 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6415 gtk_drag_finish (context,
6417 (context->action == GDK_ACTION_MOVE),
6420 gtk_tree_path_free (dest_row);
6423 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6426 /* Drag-and-Drop support */
6428 * gtk_icon_view_enable_model_drag_source:
6429 * @icon_view: a #GtkIconTreeView
6430 * @start_button_mask: Mask of allowed buttons to start drag
6431 * @targets: the table of targets that the drag will support
6432 * @n_targets: the number of items in @targets
6433 * @actions: the bitmask of possible actions for a drag from this
6436 * Turns @icon_view into a drag source for automatic DND.
6441 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6442 GdkModifierType start_button_mask,
6443 const GtkTargetEntry *targets,
6445 GdkDragAction actions)
6447 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6449 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6451 clear_source_info (icon_view);
6452 icon_view->priv->start_button_mask = start_button_mask;
6453 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6454 icon_view->priv->source_actions = actions;
6456 icon_view->priv->source_set = TRUE;
6458 unset_reorderable (icon_view);
6462 * gtk_icon_view_enable_model_drag_dest:
6463 * @icon_view: a #GtkIconView
6464 * @targets: the table of targets that the drag will support
6465 * @n_targets: the number of items in @targets
6466 * @actions: the bitmask of possible actions for a drag to this
6469 * Turns @icon_view into a drop destination for automatic DND.
6474 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6475 const GtkTargetEntry *targets,
6477 GdkDragAction actions)
6479 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6481 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6483 clear_dest_info (icon_view);
6485 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6486 icon_view->priv->dest_actions = actions;
6488 icon_view->priv->dest_set = TRUE;
6490 unset_reorderable (icon_view);
6494 * gtk_icon_view_unset_model_drag_source:
6495 * @icon_view: a #GtkIconView
6497 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6502 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6504 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6506 if (icon_view->priv->source_set)
6508 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6509 clear_source_info (icon_view);
6512 unset_reorderable (icon_view);
6516 * gtk_icon_view_unset_model_drag_dest:
6517 * @icon_view: a #GtkIconView
6519 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6524 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6526 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6528 if (icon_view->priv->dest_set)
6530 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6531 clear_dest_info (icon_view);
6534 unset_reorderable (icon_view);
6537 /* These are useful to implement your own custom stuff. */
6539 * gtk_icon_view_set_drag_dest_item:
6540 * @icon_view: a #GtkIconView
6541 * @path: The path of the item to highlight, or %NULL.
6542 * @pos: Specifies where to drop, relative to the item
6544 * Sets the item that is highlighted for feedback.
6549 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6551 GtkIconViewDropPosition pos)
6553 /* Note; this function is exported to allow a custom DND
6554 * implementation, so it can't touch TreeViewDragInfo
6557 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6559 if (icon_view->priv->dest_item)
6561 GtkTreePath *current_path;
6562 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6563 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6564 icon_view->priv->dest_item = NULL;
6566 gtk_icon_view_queue_draw_path (icon_view, current_path);
6567 gtk_tree_path_free (current_path);
6570 /* special case a drop on an empty model */
6571 icon_view->priv->empty_view_drop = FALSE;
6572 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6573 && gtk_tree_path_get_depth (path) == 1
6574 && gtk_tree_path_get_indices (path)[0] == 0)
6578 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6581 if (n_children == 0)
6582 icon_view->priv->empty_view_drop = TRUE;
6585 icon_view->priv->dest_pos = pos;
6589 icon_view->priv->dest_item =
6590 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6591 icon_view->priv->model, path);
6593 gtk_icon_view_queue_draw_path (icon_view, path);
6598 * gtk_icon_view_get_drag_dest_item:
6599 * @icon_view: a #GtkIconView
6600 * @path: Return location for the path of the highlighted item, or %NULL.
6601 * @pos: Return location for the drop position, or %NULL
6603 * Gets information about the item that is highlighted for feedback.
6608 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6610 GtkIconViewDropPosition *pos)
6612 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6616 if (icon_view->priv->dest_item)
6617 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6623 *pos = icon_view->priv->dest_pos;
6627 * gtk_icon_view_get_dest_item_at_pos:
6628 * @icon_view: a #GtkIconView
6629 * @drag_x: the position to determine the destination item for
6630 * @drag_y: the position to determine the destination item for
6631 * @path: Return location for the path of the item, or %NULL.
6632 * @pos: Return location for the drop position, or %NULL
6634 * Determines the destination item for a given position.
6636 * Return value: whether there is an item at the given position.
6641 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6645 GtkIconViewDropPosition *pos)
6647 GtkIconViewItem *item;
6649 /* Note; this function is exported to allow a custom DND
6650 * implementation, so it can't touch TreeViewDragInfo
6653 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6654 g_return_val_if_fail (drag_x >= 0, FALSE);
6655 g_return_val_if_fail (drag_y >= 0, FALSE);
6656 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6662 item = gtk_icon_view_get_item_at_coords (icon_view,
6663 drag_x + icon_view->priv->hadjustment->value,
6664 drag_y + icon_view->priv->vadjustment->value,
6671 *path = gtk_tree_path_new_from_indices (item->index, -1);
6675 if (drag_x < item->x + item->width / 4)
6676 *pos = GTK_ICON_VIEW_DROP_LEFT;
6677 else if (drag_x > item->x + item->width * 3 / 4)
6678 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6679 else if (drag_y < item->y + item->height / 4)
6680 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6681 else if (drag_y > item->y + item->height * 3 / 4)
6682 *pos = GTK_ICON_VIEW_DROP_BELOW;
6684 *pos = GTK_ICON_VIEW_DROP_INTO;
6691 * gtk_icon_view_create_drag_icon:
6692 * @icon_view: a #GtkIconView
6693 * @path: a #GtkTreePath in @icon_view
6695 * Creates a #GdkPixmap representation of the item at @path.
6696 * This image is used for a drag icon.
6698 * Return value: a newly-allocated pixmap of the drag icon.
6703 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6708 GdkPixmap *drawable;
6713 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6714 g_return_val_if_fail (path != NULL, NULL);
6716 widget = GTK_WIDGET (icon_view);
6718 if (!GTK_WIDGET_REALIZED (widget))
6721 index = gtk_tree_path_get_indices (path)[0];
6723 for (l = icon_view->priv->items; l; l = l->next)
6725 GtkIconViewItem *item = l->data;
6727 if (index == item->index)
6729 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6734 cr = gdk_cairo_create (drawable);
6735 cairo_set_line_width (cr, 1.);
6737 gdk_cairo_set_source_color
6738 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6739 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6744 area.width = item->width;
6745 area.height = item->height;
6747 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6748 drawable, 1, 1, FALSE);
6750 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6751 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6764 * gtk_icon_view_get_reorderable:
6765 * @icon_view: a #GtkIconView
6767 * Retrieves whether the user can reorder the list via drag-and-drop.
6768 * See gtk_icon_view_set_reorderable().
6770 * Return value: %TRUE if the list can be reordered.
6775 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6777 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6779 return icon_view->priv->reorderable;
6782 static const GtkTargetEntry item_targets[] = {
6783 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6788 * gtk_icon_view_set_reorderable:
6789 * @icon_view: A #GtkIconView.
6790 * @reorderable: %TRUE, if the list of items can be reordered.
6792 * This function is a convenience function to allow you to reorder models that
6793 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6794 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6795 * the user can reorder the model by dragging and dropping rows. The
6796 * developer can listen to these changes by connecting to the model's
6797 * row_inserted and row_deleted signals.
6799 * This function does not give you any degree of control over the order -- any
6800 * reordering is allowed. If more control is needed, you should probably
6801 * handle drag and drop manually.
6806 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6807 gboolean reorderable)
6809 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6811 reorderable = reorderable != FALSE;
6813 if (icon_view->priv->reorderable == reorderable)
6818 gtk_icon_view_enable_model_drag_source (icon_view,
6821 G_N_ELEMENTS (item_targets),
6823 gtk_icon_view_enable_model_drag_dest (icon_view,
6825 G_N_ELEMENTS (item_targets),
6830 gtk_icon_view_unset_model_drag_source (icon_view);
6831 gtk_icon_view_unset_model_drag_dest (icon_view);
6834 icon_view->priv->reorderable = reorderable;
6836 g_object_notify (G_OBJECT (icon_view), "reorderable");
6840 /* Accessibility Support */
6842 static gpointer accessible_parent_class;
6843 static gpointer accessible_item_parent_class;
6844 static GQuark accessible_private_data_quark = 0;
6846 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6847 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6848 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6850 static GType gtk_icon_view_item_accessible_get_type (void);
6861 GtkIconViewItem *item;
6865 AtkStateSet *state_set;
6869 GtkTextBuffer *text_buffer;
6871 gchar *action_descriptions[LAST_ACTION];
6872 gchar *image_description;
6873 guint action_idle_handler;
6874 } GtkIconViewItemAccessible;
6876 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6882 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6887 typedef struct _GtkIconViewItemAccessibleClass
6889 AtkObjectClass parent_class;
6891 } GtkIconViewItemAccessibleClass;
6893 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6896 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6898 GtkIconViewItemAccessible *item;
6899 GtkIconView *icon_view;
6902 GDK_THREADS_ENTER ();
6904 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6905 item->action_idle_handler = 0;
6907 if (item->widget != NULL)
6909 icon_view = GTK_ICON_VIEW (item->widget);
6910 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6911 gtk_icon_view_item_activated (icon_view, path);
6912 gtk_tree_path_free (path);
6915 GDK_THREADS_LEAVE ();
6921 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6924 GtkIconViewItemAccessible *item;
6926 if (i < 0 || i >= LAST_ACTION)
6929 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6931 if (!GTK_IS_ICON_VIEW (item->widget))
6934 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6939 case ACTION_ACTIVATE:
6940 if (!item->action_idle_handler)
6941 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6944 g_assert_not_reached ();
6952 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6957 static const gchar *
6958 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6961 GtkIconViewItemAccessible *item;
6963 if (i < 0 || i >= LAST_ACTION)
6966 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6968 if (item->action_descriptions[i])
6969 return item->action_descriptions[i];
6971 return gtk_icon_view_item_accessible_action_descriptions[i];
6974 static const gchar *
6975 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6978 if (i < 0 || i >= LAST_ACTION)
6981 return gtk_icon_view_item_accessible_action_names[i];
6985 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6987 const gchar *description)
6989 GtkIconViewItemAccessible *item;
6991 if (i < 0 || i >= LAST_ACTION)
6994 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6996 if (item->action_descriptions[i])
6997 g_free (item->action_descriptions[i]);
6999 item->action_descriptions[i] = g_strdup (description);
7005 atk_action_item_interface_init (AtkActionIface *iface)
7007 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7008 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7009 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7010 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7011 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7014 static const gchar *
7015 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7017 GtkIconViewItemAccessible *item;
7019 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7021 return item->image_description;
7025 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7026 const gchar *description)
7028 GtkIconViewItemAccessible *item;
7030 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7032 g_free (item->image_description);
7033 item->image_description = g_strdup (item->image_description);
7039 get_pixbuf_box (GtkIconView *icon_view,
7040 GtkIconViewItem *item,
7045 for (l = icon_view->priv->cell_list; l; l = l->next)
7047 GtkIconViewCellInfo *info = l->data;
7049 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7051 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7061 get_text (GtkIconView *icon_view,
7062 GtkIconViewItem *item)
7067 for (l = icon_view->priv->cell_list; l; l = l->next)
7069 GtkIconViewCellInfo *info = l->data;
7071 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7073 g_object_get (info->cell, "text", &text, NULL);
7083 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7087 GtkIconViewItemAccessible *item;
7090 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7092 if (!GTK_IS_ICON_VIEW (item->widget))
7095 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7098 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7101 *height = box.height;
7106 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7109 AtkCoordType coord_type)
7111 GtkIconViewItemAccessible *item;
7114 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7116 if (!GTK_IS_ICON_VIEW (item->widget))
7119 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7122 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7124 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7126 *x+= box.x - item->item->x;
7127 *y+= box.y - item->item->y;
7133 atk_image_item_interface_init (AtkImageIface *iface)
7135 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7136 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7137 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7138 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7142 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7146 GtkIconViewItemAccessible *item;
7147 GtkTextIter start, end;
7148 GtkTextBuffer *buffer;
7150 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7152 if (!GTK_IS_ICON_VIEW (item->widget))
7155 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7158 buffer = item->text_buffer;
7159 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7161 gtk_text_buffer_get_end_iter (buffer, &end);
7163 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7165 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7169 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7172 GtkIconViewItemAccessible *item;
7173 GtkTextIter start, end;
7174 GtkTextBuffer *buffer;
7178 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7180 if (!GTK_IS_ICON_VIEW (item->widget))
7183 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7186 buffer = item->text_buffer;
7187 if (offset >= gtk_text_buffer_get_char_count (buffer))
7190 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7192 gtk_text_iter_forward_char (&end);
7193 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7194 unichar = g_utf8_get_char (string);
7202 get_pango_text_offsets (PangoLayout *layout,
7203 GtkTextBuffer *buffer,
7205 AtkTextBoundary boundary_type,
7209 GtkTextIter *start_iter,
7210 GtkTextIter *end_iter)
7212 PangoLayoutIter *iter;
7213 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7214 gint index, start_index, end_index;
7216 gboolean found = FALSE;
7218 text = pango_layout_get_text (layout);
7219 index = g_utf8_offset_to_pointer (text, offset) - text;
7220 iter = pango_layout_get_iter (layout);
7223 line = pango_layout_iter_get_line (iter);
7224 start_index = line->start_index;
7225 end_index = start_index + line->length;
7227 if (index >= start_index && index <= end_index)
7230 * Found line for offset
7236 * We want the previous line
7240 switch (boundary_type)
7242 case ATK_TEXT_BOUNDARY_LINE_START:
7243 end_index = start_index;
7244 start_index = prev_line->start_index;
7246 case ATK_TEXT_BOUNDARY_LINE_END:
7248 start_index = prev_prev_line->start_index +
7249 prev_prev_line->length;
7250 end_index = prev_line->start_index + prev_line->length;
7253 g_assert_not_reached();
7257 start_index = end_index = 0;
7260 switch (boundary_type)
7262 case ATK_TEXT_BOUNDARY_LINE_START:
7263 if (pango_layout_iter_next_line (iter))
7264 end_index = pango_layout_iter_get_line (iter)->start_index;
7266 case ATK_TEXT_BOUNDARY_LINE_END:
7268 start_index = prev_line->start_index +
7272 g_assert_not_reached();
7277 * We want the next line
7279 if (pango_layout_iter_next_line (iter))
7281 line = pango_layout_iter_get_line (iter);
7282 switch (boundary_type)
7284 case ATK_TEXT_BOUNDARY_LINE_START:
7285 start_index = line->start_index;
7286 if (pango_layout_iter_next_line (iter))
7287 end_index = pango_layout_iter_get_line (iter)->start_index;
7289 end_index = start_index + line->length;
7291 case ATK_TEXT_BOUNDARY_LINE_END:
7292 start_index = end_index;
7293 end_index = line->start_index + line->length;
7296 g_assert_not_reached();
7300 start_index = end_index;
7306 prev_prev_line = prev_line;
7309 while (pango_layout_iter_next_line (iter));
7313 start_index = prev_line->start_index + prev_line->length;
7314 end_index = start_index;
7316 pango_layout_iter_free (iter);
7317 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7318 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7320 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7321 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7326 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7328 AtkTextBoundary boundary_type,
7332 GtkIconViewItemAccessible *item;
7333 GtkTextIter start, end;
7334 GtkTextBuffer *buffer;
7336 GtkIconView *icon_view;
7339 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7341 if (!GTK_IS_ICON_VIEW (item->widget))
7344 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7347 buffer = item->text_buffer;
7349 if (!gtk_text_buffer_get_char_count (buffer))
7353 return g_strdup ("");
7355 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7359 switch (boundary_type)
7361 case ATK_TEXT_BOUNDARY_CHAR:
7362 gtk_text_iter_backward_char(&start);
7364 case ATK_TEXT_BOUNDARY_WORD_START:
7365 if (!gtk_text_iter_starts_word (&start))
7366 gtk_text_iter_backward_word_start (&start);
7368 gtk_text_iter_backward_word_start(&start);
7370 case ATK_TEXT_BOUNDARY_WORD_END:
7371 if (gtk_text_iter_inside_word (&start) &&
7372 !gtk_text_iter_starts_word (&start))
7373 gtk_text_iter_backward_word_start (&start);
7374 while (!gtk_text_iter_ends_word (&start))
7376 if (!gtk_text_iter_backward_char (&start))
7380 gtk_text_iter_backward_word_start(&start);
7381 while (!gtk_text_iter_ends_word (&start))
7383 if (!gtk_text_iter_backward_char (&start))
7387 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7388 if (!gtk_text_iter_starts_sentence (&start))
7389 gtk_text_iter_backward_sentence_start (&start);
7391 gtk_text_iter_backward_sentence_start (&start);
7393 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7394 if (gtk_text_iter_inside_sentence (&start) &&
7395 !gtk_text_iter_starts_sentence (&start))
7396 gtk_text_iter_backward_sentence_start (&start);
7397 while (!gtk_text_iter_ends_sentence (&start))
7399 if (!gtk_text_iter_backward_char (&start))
7403 gtk_text_iter_backward_sentence_start (&start);
7404 while (!gtk_text_iter_ends_sentence (&start))
7406 if (!gtk_text_iter_backward_char (&start))
7410 case ATK_TEXT_BOUNDARY_LINE_START:
7411 case ATK_TEXT_BOUNDARY_LINE_END:
7413 icon_view = GTK_ICON_VIEW (item->widget);
7414 /* FIXME we probably have to use GailTextCell to salvage this */
7415 gtk_icon_view_update_item_text (icon_view, item->item);
7416 get_pango_text_offsets (icon_view->priv->layout,
7429 *start_offset = gtk_text_iter_get_offset (&start);
7430 *end_offset = gtk_text_iter_get_offset (&end);
7432 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7436 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7438 AtkTextBoundary boundary_type,
7442 GtkIconViewItemAccessible *item;
7443 GtkTextIter start, end;
7444 GtkTextBuffer *buffer;
7446 GtkIconView *icon_view;
7449 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7451 if (!GTK_IS_ICON_VIEW (item->widget))
7454 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7457 buffer = item->text_buffer;
7459 if (!gtk_text_buffer_get_char_count (buffer))
7463 return g_strdup ("");
7465 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7469 switch (boundary_type)
7471 case ATK_TEXT_BOUNDARY_CHAR:
7472 gtk_text_iter_forward_char (&end);
7474 case ATK_TEXT_BOUNDARY_WORD_START:
7475 if (!gtk_text_iter_starts_word (&start))
7476 gtk_text_iter_backward_word_start (&start);
7477 if (gtk_text_iter_inside_word (&end))
7478 gtk_text_iter_forward_word_end (&end);
7479 while (!gtk_text_iter_starts_word (&end))
7481 if (!gtk_text_iter_forward_char (&end))
7485 case ATK_TEXT_BOUNDARY_WORD_END:
7486 if (gtk_text_iter_inside_word (&start) &&
7487 !gtk_text_iter_starts_word (&start))
7488 gtk_text_iter_backward_word_start (&start);
7489 while (!gtk_text_iter_ends_word (&start))
7491 if (!gtk_text_iter_backward_char (&start))
7494 gtk_text_iter_forward_word_end (&end);
7496 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7497 if (!gtk_text_iter_starts_sentence (&start))
7498 gtk_text_iter_backward_sentence_start (&start);
7499 if (gtk_text_iter_inside_sentence (&end))
7500 gtk_text_iter_forward_sentence_end (&end);
7501 while (!gtk_text_iter_starts_sentence (&end))
7503 if (!gtk_text_iter_forward_char (&end))
7507 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7508 if (gtk_text_iter_inside_sentence (&start) &&
7509 !gtk_text_iter_starts_sentence (&start))
7510 gtk_text_iter_backward_sentence_start (&start);
7511 while (!gtk_text_iter_ends_sentence (&start))
7513 if (!gtk_text_iter_backward_char (&start))
7516 gtk_text_iter_forward_sentence_end (&end);
7518 case ATK_TEXT_BOUNDARY_LINE_START:
7519 case ATK_TEXT_BOUNDARY_LINE_END:
7521 icon_view = GTK_ICON_VIEW (item->widget);
7522 /* FIXME we probably have to use GailTextCell to salvage this */
7523 gtk_icon_view_update_item_text (icon_view, item->item);
7524 get_pango_text_offsets (icon_view->priv->layout,
7538 *start_offset = gtk_text_iter_get_offset (&start);
7539 *end_offset = gtk_text_iter_get_offset (&end);
7541 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7545 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7547 AtkTextBoundary boundary_type,
7551 GtkIconViewItemAccessible *item;
7552 GtkTextIter start, end;
7553 GtkTextBuffer *buffer;
7555 GtkIconView *icon_view;
7558 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7560 if (!GTK_IS_ICON_VIEW (item->widget))
7563 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7566 buffer = item->text_buffer;
7568 if (!gtk_text_buffer_get_char_count (buffer))
7572 return g_strdup ("");
7574 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7578 switch (boundary_type)
7580 case ATK_TEXT_BOUNDARY_CHAR:
7581 gtk_text_iter_forward_char(&start);
7582 gtk_text_iter_forward_chars(&end, 2);
7584 case ATK_TEXT_BOUNDARY_WORD_START:
7585 if (gtk_text_iter_inside_word (&end))
7586 gtk_text_iter_forward_word_end (&end);
7587 while (!gtk_text_iter_starts_word (&end))
7589 if (!gtk_text_iter_forward_char (&end))
7593 if (!gtk_text_iter_is_end (&end))
7595 gtk_text_iter_forward_word_end (&end);
7596 while (!gtk_text_iter_starts_word (&end))
7598 if (!gtk_text_iter_forward_char (&end))
7603 case ATK_TEXT_BOUNDARY_WORD_END:
7604 gtk_text_iter_forward_word_end (&end);
7606 if (!gtk_text_iter_is_end (&end))
7607 gtk_text_iter_forward_word_end (&end);
7609 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7610 if (gtk_text_iter_inside_sentence (&end))
7611 gtk_text_iter_forward_sentence_end (&end);
7612 while (!gtk_text_iter_starts_sentence (&end))
7614 if (!gtk_text_iter_forward_char (&end))
7618 if (!gtk_text_iter_is_end (&end))
7620 gtk_text_iter_forward_sentence_end (&end);
7621 while (!gtk_text_iter_starts_sentence (&end))
7623 if (!gtk_text_iter_forward_char (&end))
7628 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7629 gtk_text_iter_forward_sentence_end (&end);
7631 if (!gtk_text_iter_is_end (&end))
7632 gtk_text_iter_forward_sentence_end (&end);
7634 case ATK_TEXT_BOUNDARY_LINE_START:
7635 case ATK_TEXT_BOUNDARY_LINE_END:
7637 icon_view = GTK_ICON_VIEW (item->widget);
7638 /* FIXME we probably have to use GailTextCell to salvage this */
7639 gtk_icon_view_update_item_text (icon_view, item->item);
7640 get_pango_text_offsets (icon_view->priv->layout,
7652 *start_offset = gtk_text_iter_get_offset (&start);
7653 *end_offset = gtk_text_iter_get_offset (&end);
7655 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7659 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7661 GtkIconViewItemAccessible *item;
7663 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7665 if (!GTK_IS_ICON_VIEW (item->widget))
7668 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7671 return gtk_text_buffer_get_char_count (item->text_buffer);
7675 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7681 AtkCoordType coord_type)
7683 GtkIconViewItemAccessible *item;
7685 GtkIconView *icon_view;
7686 PangoRectangle char_rect;
7687 const gchar *item_text;
7691 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7693 if (!GTK_IS_ICON_VIEW (item->widget))
7696 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7700 icon_view = GTK_ICON_VIEW (item->widget);
7701 /* FIXME we probably have to use GailTextCell to salvage this */
7702 gtk_icon_view_update_item_text (icon_view, item->item);
7703 item_text = pango_layout_get_text (icon_view->priv->layout);
7704 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7705 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7707 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7708 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7709 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7710 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7711 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7712 *width = char_rect.width / PANGO_SCALE;
7713 *height = char_rect.height / PANGO_SCALE;
7718 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7721 AtkCoordType coord_type)
7723 GtkIconViewItemAccessible *item;
7726 GtkIconView *icon_view;
7727 const gchar *item_text;
7732 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7734 if (!GTK_IS_ICON_VIEW (item->widget))
7737 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7741 icon_view = GTK_ICON_VIEW (item->widget);
7742 /* FIXME we probably have to use GailTextCell to salvage this */
7743 gtk_icon_view_update_item_text (icon_view, item->item);
7744 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7745 x -= l_x + item->item->layout_x - item->item->x;
7746 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7747 y -= l_y + item->item->layout_y - item->item->y;
7748 item_text = pango_layout_get_text (icon_view->priv->layout);
7749 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7760 offset = g_utf8_strlen (item_text, -1);
7762 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7768 atk_text_item_interface_init (AtkTextIface *iface)
7770 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7771 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7772 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7773 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7774 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7775 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7776 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7777 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7781 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7786 AtkCoordType coord_type)
7788 GtkIconViewItemAccessible *item;
7789 AtkObject *parent_obj;
7792 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7794 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7795 if (!GTK_IS_WIDGET (item->widget))
7798 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7801 *width = item->item->width;
7802 *height = item->item->height;
7803 if (gtk_icon_view_item_accessible_is_showing (item))
7805 parent_obj = gtk_widget_get_accessible (item->widget);
7806 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7807 *x = l_x + item->item->x;
7808 *y = l_y + item->item->y;
7818 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7820 GtkIconViewItemAccessible *item;
7821 GtkWidget *toplevel;
7823 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7825 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7826 if (!GTK_IS_WIDGET (item->widget))
7829 gtk_widget_grab_focus (item->widget);
7830 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7831 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7832 if (GTK_WIDGET_TOPLEVEL (toplevel))
7833 gtk_window_present (GTK_WINDOW (toplevel));
7839 atk_component_item_interface_init (AtkComponentIface *iface)
7841 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7842 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7846 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7847 AtkStateType state_type,
7848 gboolean emit_signal)
7852 rc = atk_state_set_add_state (item->state_set, state_type);
7854 * The signal should only be generated if the value changed,
7855 * not when the item is set up. So states that are set
7856 * initially should pass FALSE as the emit_signal argument.
7861 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7862 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7863 if (state_type == ATK_STATE_VISIBLE)
7864 g_signal_emit_by_name (item, "visible_data_changed");
7871 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7872 AtkStateType state_type,
7873 gboolean emit_signal)
7875 if (atk_state_set_contains_state (item->state_set, state_type))
7879 rc = atk_state_set_remove_state (item->state_set, state_type);
7881 * The signal should only be generated if the value changed,
7882 * not when the item is set up. So states that are set
7883 * initially should pass FALSE as the emit_signal argument.
7888 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7889 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7890 if (state_type == ATK_STATE_VISIBLE)
7891 g_signal_emit_by_name (item, "visible_data_changed");
7901 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7903 GtkIconView *icon_view;
7904 GdkRectangle visible_rect;
7905 gboolean is_showing;
7908 * An item is considered "SHOWING" if any part of the item is in the
7909 * visible rectangle.
7912 if (!GTK_IS_ICON_VIEW (item->widget))
7915 if (item->item == NULL)
7918 icon_view = GTK_ICON_VIEW (item->widget);
7920 if (icon_view->priv->hadjustment)
7921 visible_rect.x += icon_view->priv->hadjustment->value;
7923 if (icon_view->priv->hadjustment)
7924 visible_rect.y += icon_view->priv->vadjustment->value;
7925 visible_rect.width = item->widget->allocation.width;
7926 visible_rect.height = item->widget->allocation.height;
7928 if (((item->item->x + item->item->width) < visible_rect.x) ||
7929 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7930 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7931 (item->item->y > (visible_rect.y + visible_rect.height)))
7940 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7941 gboolean emit_signal)
7943 if (gtk_icon_view_item_accessible_is_showing (item))
7944 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7947 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7952 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7956 item->state_set = atk_state_set_new ();
7958 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7959 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7960 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7961 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7962 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7964 for (i = 0; i < LAST_ACTION; i++)
7965 item->action_descriptions[i] = NULL;
7967 item->image_description = NULL;
7969 item->action_idle_handler = 0;
7973 gtk_icon_view_item_accessible_finalize (GObject *object)
7975 GtkIconViewItemAccessible *item;
7978 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7980 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7983 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7985 if (item->state_set)
7986 g_object_unref (item->state_set);
7988 if (item->text_buffer)
7989 g_object_unref (item->text_buffer);
7991 for (i = 0; i < LAST_ACTION; i++)
7992 g_free (item->action_descriptions[i]);
7994 g_free (item->image_description);
7996 if (item->action_idle_handler)
7998 g_source_remove (item->action_idle_handler);
7999 item->action_idle_handler = 0;
8002 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8005 static G_CONST_RETURN gchar*
8006 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8012 GtkIconViewItemAccessible *item;
8013 GtkTextIter start_iter;
8014 GtkTextIter end_iter;
8016 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8018 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8019 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8021 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8026 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8028 GtkIconViewItemAccessible *item;
8030 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8031 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8034 return gtk_widget_get_accessible (item->widget);
8040 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8042 GtkIconViewItemAccessible *item;
8044 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8045 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8047 return item->item->index;
8050 static AtkStateSet *
8051 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8053 GtkIconViewItemAccessible *item;
8054 GtkIconView *icon_view;
8056 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8057 g_return_val_if_fail (item->state_set, NULL);
8062 icon_view = GTK_ICON_VIEW (item->widget);
8063 if (icon_view->priv->cursor_item == item->item)
8064 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8066 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8068 return g_object_ref (item->state_set);
8072 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8074 GObjectClass *gobject_class;
8076 accessible_item_parent_class = g_type_class_peek_parent (klass);
8078 gobject_class = (GObjectClass *)klass;
8080 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8082 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8083 klass->get_name = gtk_icon_view_item_accessible_get_name;
8084 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8085 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8089 gtk_icon_view_item_accessible_get_type (void)
8091 static GType type = 0;
8095 const GTypeInfo tinfo =
8097 sizeof (GtkIconViewItemAccessibleClass),
8098 (GBaseInitFunc) NULL, /* base init */
8099 (GBaseFinalizeFunc) NULL, /* base finalize */
8100 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8101 (GClassFinalizeFunc) NULL, /* class finalize */
8102 NULL, /* class data */
8103 sizeof (GtkIconViewItemAccessible), /* instance size */
8104 0, /* nb preallocs */
8105 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8106 NULL /* value table */
8109 static const GInterfaceInfo atk_component_info =
8111 (GInterfaceInitFunc) atk_component_item_interface_init,
8112 (GInterfaceFinalizeFunc) NULL,
8115 static const GInterfaceInfo atk_action_info =
8117 (GInterfaceInitFunc) atk_action_item_interface_init,
8118 (GInterfaceFinalizeFunc) NULL,
8121 static const GInterfaceInfo atk_image_info =
8123 (GInterfaceInitFunc) atk_image_item_interface_init,
8124 (GInterfaceFinalizeFunc) NULL,
8127 static const GInterfaceInfo atk_text_info =
8129 (GInterfaceInitFunc) atk_text_item_interface_init,
8130 (GInterfaceFinalizeFunc) NULL,
8134 type = g_type_register_static (ATK_TYPE_OBJECT,
8135 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8136 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8137 &atk_component_info);
8138 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8140 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8142 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8149 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8150 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8151 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8153 static GType gtk_icon_view_accessible_get_type (void);
8158 } GtkIconViewAccessible;
8164 } GtkIconViewItemAccessibleInfo;
8170 GtkAdjustment *old_hadj;
8171 GtkAdjustment *old_vadj;
8173 GtkTreeModel *model;
8175 } GtkIconViewAccessiblePrivate;
8177 static GtkIconViewAccessiblePrivate *
8178 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8180 return g_object_get_qdata (G_OBJECT (accessible),
8181 accessible_private_data_quark);
8185 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8189 GtkIconViewItemAccessibleInfo *info;
8190 GtkIconViewItemAccessibleInfo *tmp_info;
8191 GtkIconViewAccessiblePrivate *priv;
8194 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8196 info->index = index;
8198 priv = gtk_icon_view_accessible_get_priv (accessible);
8199 items = priv->items;
8202 tmp_info = items->data;
8203 if (tmp_info->index > index)
8205 items = items->next;
8207 priv->items = g_list_insert_before (priv->items, items, info);
8208 priv->old_hadj = NULL;
8209 priv->old_vadj = NULL;
8213 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8215 GtkIconView *icon_view;
8218 widget = GTK_ACCESSIBLE (accessible)->widget;
8222 icon_view = GTK_ICON_VIEW (widget);
8224 return g_list_length (icon_view->priv->items);
8228 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8231 GtkIconViewAccessiblePrivate *priv;
8232 GtkIconViewItemAccessibleInfo *info;
8235 priv = gtk_icon_view_accessible_get_priv (accessible);
8236 items = priv->items;
8241 if (info->index == index)
8243 items = items->next;
8249 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8252 GtkIconView *icon_view;
8256 GtkIconViewItemAccessible *a11y_item;
8258 widget = GTK_ACCESSIBLE (accessible)->widget;
8262 icon_view = GTK_ICON_VIEW (widget);
8263 icons = g_list_nth (icon_view->priv->items, index);
8267 GtkIconViewItem *item = icons->data;
8269 g_return_val_if_fail (item->index == index, NULL);
8270 obj = gtk_icon_view_accessible_find_child (accessible, index);
8273 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8274 gtk_icon_view_item_accessible_info_new (accessible,
8277 obj->role = ATK_ROLE_ICON;
8278 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8279 a11y_item->item = item;
8280 a11y_item->widget = widget;
8281 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8283 gtk_icon_view_set_cell_data (icon_view, item);
8284 gtk_text_buffer_set_text (a11y_item->text_buffer,
8285 get_text (icon_view, item), -1);
8287 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8288 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8296 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8299 GtkIconViewAccessiblePrivate *priv;
8300 GtkIconViewItemAccessibleInfo *info;
8301 GtkIconViewItemAccessible *item;
8304 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8308 gboolean act_on_item;
8310 widget = GTK_ACCESSIBLE (view)->widget;
8314 items = priv->items;
8316 act_on_item = (list == NULL);
8321 info = (GtkIconViewItemAccessibleInfo *)items->data;
8322 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8324 if (act_on_item == FALSE && list == items)
8328 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8330 items = items->next;
8336 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8337 GtkIconView *icon_view)
8340 GtkIconViewAccessible *view;
8343 * The scrollbars have changed
8345 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8346 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8348 gtk_icon_view_accessible_traverse_items (view, NULL);
8352 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8353 GtkAdjustment *hadj,
8354 GtkAdjustment *vadj)
8357 GtkIconViewAccessiblePrivate *priv;
8359 atk_obj = gtk_widget_get_accessible (widget);
8360 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8362 if (priv->old_hadj != hadj)
8366 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8367 (gpointer *)&priv->old_hadj);
8369 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8370 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8373 priv->old_hadj = hadj;
8376 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8377 (gpointer *)&priv->old_hadj);
8378 g_signal_connect (hadj,
8380 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8384 if (priv->old_vadj != vadj)
8388 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8389 (gpointer *)&priv->old_vadj);
8391 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8392 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8395 priv->old_vadj = vadj;
8398 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8399 (gpointer *)&priv->old_vadj);
8400 g_signal_connect (vadj,
8402 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8409 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8416 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8417 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8423 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8428 GtkIconViewAccessiblePrivate *priv;
8429 GtkIconViewItemAccessibleInfo *info;
8430 GtkIconViewAccessible *view;
8431 GtkIconViewItemAccessible *item;
8437 index = gtk_tree_path_get_indices(path)[0];
8438 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8439 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8440 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8442 items = priv->items;
8447 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8448 if (info->index != item->item->index)
8450 if (info->index < index)
8451 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8453 if (tmp_list == NULL)
8456 info->index = item->item->index;
8459 items = items->next;
8461 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8462 g_signal_emit_by_name (atk_obj, "children_changed::add",
8468 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8472 GtkIconViewAccessiblePrivate *priv;
8473 GtkIconViewItemAccessibleInfo *info;
8474 GtkIconViewAccessible *view;
8475 GtkIconViewItemAccessible *item;
8478 GList *deleted_item;
8482 index = gtk_tree_path_get_indices(path)[0];
8483 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8484 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8485 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8487 items = priv->items;
8489 deleted_item = NULL;
8494 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8495 if (info->index == index)
8497 deleted_item = items;
8499 if (info->index != item->item->index)
8501 if (tmp_list == NULL)
8504 info->index = item->item->index;
8507 items = items->next;
8509 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8512 info = deleted_item->data;
8513 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8515 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8519 priv->items = g_list_remove_link (priv->items, deleted_item);
8527 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8528 GtkIconViewItemAccessibleInfo *i2)
8530 return i1->index - i2->index;
8534 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8540 GtkIconViewAccessiblePrivate *priv;
8541 GtkIconViewItemAccessibleInfo *info;
8542 GtkIconView *icon_view;
8543 GtkIconViewItemAccessible *item;
8547 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8548 icon_view = GTK_ICON_VIEW (user_data);
8549 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8551 items = priv->items;
8555 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8556 info->index = new_order[info->index];
8557 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8558 items = items->next;
8560 priv->items = g_list_sort (priv->items,
8561 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8567 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8572 obj = G_OBJECT (model);
8573 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8574 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8575 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8576 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8580 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8584 obj = G_OBJECT (icon_view->priv->model);
8585 g_signal_connect_data (obj, "row_changed",
8586 (GCallback) gtk_icon_view_accessible_model_row_changed,
8587 icon_view, NULL, 0);
8588 g_signal_connect_data (obj, "row_inserted",
8589 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8590 icon_view, NULL, G_CONNECT_AFTER);
8591 g_signal_connect_data (obj, "row_deleted",
8592 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8593 icon_view, NULL, G_CONNECT_AFTER);
8594 g_signal_connect_data (obj, "rows_reordered",
8595 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8596 icon_view, NULL, G_CONNECT_AFTER);
8600 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8602 GtkIconViewItemAccessibleInfo *info;
8605 items = priv->items;
8608 info = (GtkIconViewItemAccessibleInfo *) items->data;
8609 g_object_unref (info->item);
8610 g_free (items->data);
8611 items = items->next;
8613 g_list_free (priv->items);
8618 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8621 GtkIconView *icon_view;
8624 GtkIconViewAccessiblePrivate *priv;
8626 if (strcmp (pspec->name, "model") == 0)
8628 widget = GTK_WIDGET (obj);
8629 atk_obj = gtk_widget_get_accessible (widget);
8630 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8633 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8634 (gpointer *)&priv->model);
8635 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8637 gtk_icon_view_accessible_clear_cache (priv);
8639 icon_view = GTK_ICON_VIEW (obj);
8640 priv->model = icon_view->priv->model;
8641 /* If there is no model the GtkIconView is probably being destroyed */
8644 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8645 gtk_icon_view_accessible_connect_model_signals (icon_view);
8653 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8656 GtkIconViewAccessiblePrivate *priv;
8657 GtkIconView *icon_view;
8659 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8660 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8662 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8663 g_object_set_qdata (G_OBJECT (accessible),
8664 accessible_private_data_quark,
8667 icon_view = GTK_ICON_VIEW (data);
8668 if (icon_view->priv->hadjustment)
8670 priv->old_hadj = icon_view->priv->hadjustment;
8671 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8672 g_signal_connect (icon_view->priv->hadjustment,
8674 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8677 if (icon_view->priv->vadjustment)
8679 priv->old_vadj = icon_view->priv->vadjustment;
8680 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8681 g_signal_connect (icon_view->priv->vadjustment,
8683 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8686 g_signal_connect_after (data,
8687 "set_scroll_adjustments",
8688 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8690 g_signal_connect (data,
8692 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8695 priv->model = icon_view->priv->model;
8698 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8699 gtk_icon_view_accessible_connect_model_signals (icon_view);
8702 accessible->role = ATK_ROLE_LAYERED_PANE;
8706 gtk_icon_view_accessible_finalize (GObject *object)
8708 GtkIconViewAccessiblePrivate *priv;
8710 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8711 gtk_icon_view_accessible_clear_cache (priv);
8715 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8719 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8720 GtkAccessible *accessible)
8723 GtkIconViewAccessiblePrivate *priv;
8725 atk_obj = ATK_OBJECT (accessible);
8726 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8729 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8730 (gpointer *)&priv->old_hadj);
8732 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8733 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8735 priv->old_hadj = NULL;
8739 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8740 (gpointer *)&priv->old_vadj);
8742 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8743 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8745 priv->old_vadj = NULL;
8750 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8752 if (accessible->widget)
8754 g_signal_connect_after (accessible->widget,
8756 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8759 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8763 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8765 GObjectClass *gobject_class;
8766 GtkAccessibleClass *accessible_class;
8768 accessible_parent_class = g_type_class_peek_parent (klass);
8770 gobject_class = (GObjectClass *)klass;
8771 accessible_class = (GtkAccessibleClass *)klass;
8773 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8775 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8776 klass->ref_child = gtk_icon_view_accessible_ref_child;
8777 klass->initialize = gtk_icon_view_accessible_initialize;
8779 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8781 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8785 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8788 AtkCoordType coord_type)
8791 GtkIconView *icon_view;
8792 GtkIconViewItem *item;
8795 widget = GTK_ACCESSIBLE (component)->widget;
8797 /* State is defunct */
8800 icon_view = GTK_ICON_VIEW (widget);
8801 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8802 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8804 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8810 atk_component_interface_init (AtkComponentIface *iface)
8812 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8816 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8820 GtkIconView *icon_view;
8821 GtkIconViewItem *item;
8823 widget = GTK_ACCESSIBLE (selection)->widget;
8827 icon_view = GTK_ICON_VIEW (widget);
8829 item = g_list_nth_data (icon_view->priv->items, i);
8834 gtk_icon_view_select_item (icon_view, item);
8840 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8843 GtkIconView *icon_view;
8845 widget = GTK_ACCESSIBLE (selection)->widget;
8849 icon_view = GTK_ICON_VIEW (widget);
8850 gtk_icon_view_unselect_all (icon_view);
8856 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8860 GtkIconView *icon_view;
8861 GtkIconViewItem *item;
8864 widget = GTK_ACCESSIBLE (selection)->widget;
8868 icon_view = GTK_ICON_VIEW (widget);
8870 l = icon_view->priv->items;
8877 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8888 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8891 GtkIconView *icon_view;
8892 GtkIconViewItem *item;
8896 widget = GTK_ACCESSIBLE (selection)->widget;
8900 icon_view = GTK_ICON_VIEW (widget);
8902 l = icon_view->priv->items;
8918 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8922 GtkIconView *icon_view;
8923 GtkIconViewItem *item;
8925 widget = GTK_ACCESSIBLE (selection)->widget;
8929 icon_view = GTK_ICON_VIEW (widget);
8931 item = g_list_nth_data (icon_view->priv->items, i);
8935 return item->selected;
8939 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8943 GtkIconView *icon_view;
8944 GtkIconViewItem *item;
8948 widget = GTK_ACCESSIBLE (selection)->widget;
8952 icon_view = GTK_ICON_VIEW (widget);
8953 l = icon_view->priv->items;
8962 gtk_icon_view_unselect_item (icon_view, item);
8974 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8977 GtkIconView *icon_view;
8979 widget = GTK_ACCESSIBLE (selection)->widget;
8983 icon_view = GTK_ICON_VIEW (widget);
8984 gtk_icon_view_select_all (icon_view);
8989 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8991 iface->add_selection = gtk_icon_view_accessible_add_selection;
8992 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8993 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8994 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8995 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8996 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8997 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9001 gtk_icon_view_accessible_get_type (void)
9003 static GType type = 0;
9007 static GTypeInfo tinfo =
9010 (GBaseInitFunc) NULL, /* base init */
9011 (GBaseFinalizeFunc) NULL, /* base finalize */
9012 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9013 (GClassFinalizeFunc) NULL, /* class finalize */
9014 NULL, /* class data */
9015 0, /* instance size */
9016 0, /* nb preallocs */
9017 (GInstanceInitFunc) NULL, /* instance init */
9018 NULL /* value table */
9020 static const GInterfaceInfo atk_component_info =
9022 (GInterfaceInitFunc) atk_component_interface_init,
9023 (GInterfaceFinalizeFunc) NULL,
9026 static const GInterfaceInfo atk_selection_info =
9028 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9029 (GInterfaceFinalizeFunc) NULL,
9034 * Figure out the size of the class and instance
9035 * we are deriving from
9037 AtkObjectFactory *factory;
9040 GType derived_atk_type;
9042 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9043 factory = atk_registry_get_factory (atk_get_default_registry (),
9045 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9046 g_type_query (derived_atk_type, &query);
9047 tinfo.class_size = query.class_size;
9048 tinfo.instance_size = query.instance_size;
9050 type = g_type_register_static (derived_atk_type,
9051 "GtkIconViewAccessible",
9053 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9054 &atk_component_info);
9055 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9056 &atk_selection_info);
9062 gtk_icon_view_accessible_new (GObject *obj)
9064 AtkObject *accessible;
9066 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9068 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9069 atk_object_initialize (accessible, obj);
9075 gtk_icon_view_accessible_factory_get_accessible_type (void)
9077 return gtk_icon_view_accessible_get_type ();
9081 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9083 return gtk_icon_view_accessible_new (obj);
9087 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9089 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9090 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9094 gtk_icon_view_accessible_factory_get_type (void)
9096 static GType type = 0;
9100 const GTypeInfo tinfo =
9102 sizeof (AtkObjectFactoryClass),
9103 NULL, /* base_init */
9104 NULL, /* base_finalize */
9105 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9106 NULL, /* class_finalize */
9107 NULL, /* class_data */
9108 sizeof (AtkObjectFactory),
9109 0, /* n_preallocs */
9113 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9114 "GtkIconViewAccessibleFactory",
9122 gtk_icon_view_get_accessible (GtkWidget *widget)
9124 static gboolean first_time = TRUE;
9128 AtkObjectFactory *factory;
9129 AtkRegistry *registry;
9131 GType derived_atk_type;
9134 * Figure out whether accessibility is enabled by looking at the
9135 * type of the accessible object which would be created for
9136 * the parent type of GtkIconView.
9138 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9140 registry = atk_get_default_registry ();
9141 factory = atk_registry_get_factory (registry,
9143 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9144 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9145 atk_registry_set_factory_type (registry,
9147 gtk_icon_view_accessible_factory_get_type ());
9150 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9153 #define __GTK_ICON_VIEW_C__
9154 #include "gtkaliasdef.c"