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 gboolean gtk_icon_view_key_press (GtkWidget *widget,
260 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
262 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
265 /* GtkContainer vfuncs */
266 static void gtk_icon_view_remove (GtkContainer *container,
268 static void gtk_icon_view_forall (GtkContainer *container,
269 gboolean include_internals,
270 GtkCallback callback,
271 gpointer callback_data);
273 /* GtkIconView vfuncs */
274 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
276 GtkAdjustment *vadj);
277 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
278 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
279 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
280 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
281 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
283 /* Internal functions */
284 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
285 GtkIconView *icon_view);
286 static void gtk_icon_view_layout (GtkIconView *icon_view);
287 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
290 GtkIconViewItem *item,
292 GdkDrawable *drawable,
295 gboolean draw_focus);
296 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
299 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
302 GtkIconViewItem *item);
303 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
304 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
305 GtkIconViewItem *item,
307 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
310 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
311 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
312 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
313 GtkIconViewItem *item,
318 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
319 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
320 GtkIconViewItem *item);
321 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
322 GtkIconViewItem *item,
324 static void gtk_icon_view_update_rubberband (gpointer data);
325 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
326 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
327 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
330 GtkMovementStep step,
332 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
333 GtkMovementStep step,
335 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
337 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
343 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
344 GtkIconViewItem *item);
345 static void gtk_icon_view_select_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
350 GtkIconViewItem *anchor,
351 GtkIconViewItem *cursor);
352 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
355 gboolean only_in_cell,
356 GtkIconViewCellInfo **cell_at_pos);
357 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
358 GtkIconViewItem *item,
359 GtkIconViewCellInfo *cell_info,
360 GdkRectangle *cell_area);
361 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
362 GtkIconViewItem *item,
363 GtkIconViewCellInfo *info,
365 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
366 GtkCellRenderer *renderer);
367 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
368 GtkIconViewItem *item);
369 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
370 GtkCellRenderer *renderer,
372 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
377 const gchar *attribute,
379 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
380 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
381 GtkCellRenderer *renderer);
382 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
383 GtkCellRenderer *cell,
384 GtkCellLayoutDataFunc func,
386 GDestroyNotify destroy);
387 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
388 GtkCellRenderer *cell,
390 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
392 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
393 GtkIconViewItem *item,
394 GtkIconViewCellInfo *cell_info,
396 static void gtk_icon_view_put (GtkIconView *icon_view,
398 GtkIconViewItem *item,
400 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
401 GtkIconView *icon_view);
402 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
403 GtkIconViewItem *item,
404 GtkIconViewCellInfo *cell_info,
406 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
407 gboolean cancel_editing);
409 /* Source side drag signals */
410 static void gtk_icon_view_drag_begin (GtkWidget *widget,
411 GdkDragContext *context);
412 static void gtk_icon_view_drag_end (GtkWidget *widget,
413 GdkDragContext *context);
414 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
415 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
420 GdkDragContext *context);
422 /* Target side drag signals */
423 static void gtk_icon_view_drag_leave (GtkWidget *widget,
424 GdkDragContext *context,
426 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
427 GdkDragContext *context,
431 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
432 GdkDragContext *context,
436 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
437 GdkDragContext *context,
440 GtkSelectionData *selection_data,
443 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
444 GdkEventMotion *event);
446 static void remove_scroll_timeout (GtkIconView *icon_view);
447 static void clear_dest_info (GtkIconView *icon_view);
448 static void clear_source_info (GtkIconView *icon_view);
451 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
453 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
454 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
455 gtk_icon_view_cell_layout_init))
458 gtk_icon_view_class_init (GtkIconViewClass *klass)
460 GObjectClass *gobject_class;
461 GtkObjectClass *object_class;
462 GtkWidgetClass *widget_class;
463 GtkContainerClass *container_class;
464 GtkBindingSet *binding_set;
466 binding_set = gtk_binding_set_by_class (klass);
468 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
470 gobject_class = (GObjectClass *) klass;
471 object_class = (GtkObjectClass *) klass;
472 widget_class = (GtkWidgetClass *) klass;
473 container_class = (GtkContainerClass *) klass;
475 gobject_class->finalize = gtk_icon_view_finalize;
476 gobject_class->set_property = gtk_icon_view_set_property;
477 gobject_class->get_property = gtk_icon_view_get_property;
479 object_class->destroy = gtk_icon_view_destroy;
481 widget_class->realize = gtk_icon_view_realize;
482 widget_class->unrealize = gtk_icon_view_unrealize;
483 widget_class->style_set = gtk_icon_view_style_set;
484 widget_class->get_accessible = gtk_icon_view_get_accessible;
485 widget_class->size_request = gtk_icon_view_size_request;
486 widget_class->size_allocate = gtk_icon_view_size_allocate;
487 widget_class->expose_event = gtk_icon_view_expose;
488 widget_class->motion_notify_event = gtk_icon_view_motion;
489 widget_class->button_press_event = gtk_icon_view_button_press;
490 widget_class->button_release_event = gtk_icon_view_button_release;
491 widget_class->key_press_event = gtk_icon_view_key_press;
492 widget_class->key_release_event = gtk_icon_view_key_release;
493 widget_class->drag_begin = gtk_icon_view_drag_begin;
494 widget_class->drag_end = gtk_icon_view_drag_end;
495 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
496 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
497 widget_class->drag_leave = gtk_icon_view_drag_leave;
498 widget_class->drag_motion = gtk_icon_view_drag_motion;
499 widget_class->drag_drop = gtk_icon_view_drag_drop;
500 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
501 widget_class->state_changed = gtk_icon_view_state_changed;
503 container_class->remove = gtk_icon_view_remove;
504 container_class->forall = gtk_icon_view_forall;
506 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
507 klass->select_all = gtk_icon_view_real_select_all;
508 klass->unselect_all = gtk_icon_view_real_unselect_all;
509 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
510 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
511 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
512 klass->move_cursor = gtk_icon_view_real_move_cursor;
516 * GtkIconView:selection-mode:
518 * The ::selection-mode property specifies the selection mode of
519 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
520 * is enabled, for the other modes, only keyboard selection is possible.
524 g_object_class_install_property (gobject_class,
526 g_param_spec_enum ("selection-mode",
527 P_("Selection mode"),
528 P_("The selection mode"),
529 GTK_TYPE_SELECTION_MODE,
530 GTK_SELECTION_SINGLE,
531 GTK_PARAM_READWRITE));
534 * GtkIconView:pixbuf-column:
536 * The ::pixbuf-column property contains the number of the model column
537 * containing the pixbufs which are displayed. The pixbuf column must be
538 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
539 * display of pixbufs.
543 g_object_class_install_property (gobject_class,
545 g_param_spec_int ("pixbuf-column",
547 P_("Model column used to retrieve the icon pixbuf from"),
549 GTK_PARAM_READWRITE));
552 * GtkIconView:text-column:
554 * The ::text-column property contains the number of the model column
555 * containing the texts which are displayed. The text column must be
556 * of type #G_TYPE_STRING. If this property and the :markup-column
557 * property are both set to -1, no texts are displayed.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_int ("text-column",
565 P_("Model column used to retrieve the text from"),
567 GTK_PARAM_READWRITE));
571 * GtkIconView:markup-column:
573 * The ::markup-column property contains the number of the model column
574 * containing markup information to be displayed. The markup column must be
575 * of type #G_TYPE_STRING. If this property and the :text-column property
576 * are both set to column numbers, it overrides the text column.
577 * If both are set to -1, no texts are displayed.
581 g_object_class_install_property (gobject_class,
583 g_param_spec_int ("markup-column",
585 P_("Model column used to retrieve the text if using Pango markup"),
587 GTK_PARAM_READWRITE));
589 g_object_class_install_property (gobject_class,
591 g_param_spec_object ("model",
592 P_("Icon View Model"),
593 P_("The model for the icon view"),
595 GTK_PARAM_READWRITE));
598 * GtkIconView:columns:
600 * The columns property contains the number of the columns in which the
601 * items should be displayed. If it is -1, the number of columns will
602 * be chosen automatically to fill the available area.
606 g_object_class_install_property (gobject_class,
608 g_param_spec_int ("columns",
609 P_("Number of columns"),
610 P_("Number of columns to display"),
612 GTK_PARAM_READWRITE));
616 * GtkIconView:item-width:
618 * The item-width property specifies the width to use for each item.
619 * If it is set to -1, the icon view will automatically determine a
620 * suitable item size.
624 g_object_class_install_property (gobject_class,
626 g_param_spec_int ("item-width",
627 P_("Width for each item"),
628 P_("The width used for each item"),
630 GTK_PARAM_READWRITE));
633 * GtkIconView:spacing:
635 * The spacing property specifies the space which is inserted between
636 * the cells (i.e. the icon and the text) of an item.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("spacing",
644 P_("Space which is inserted between cells of an item"),
646 GTK_PARAM_READWRITE));
649 * GtkIconView:row-spacing:
651 * The row-spacing property specifies the space which is inserted between
652 * the rows of the icon view.
656 g_object_class_install_property (gobject_class,
658 g_param_spec_int ("row-spacing",
660 P_("Space which is inserted between grid rows"),
662 GTK_PARAM_READWRITE));
665 * GtkIconView:column-spacing:
667 * The column-spacing property specifies the space which is inserted between
668 * the columns of the icon view.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_int ("column-spacing",
675 P_("Column Spacing"),
676 P_("Space which is inserted between grid columns"),
678 GTK_PARAM_READWRITE));
681 * GtkIconView:margin:
683 * The margin property specifies the space which is inserted
684 * at the edges of the icon view.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_int ("margin",
692 P_("Space which is inserted at the edges of the icon view"),
694 GTK_PARAM_READWRITE));
698 * GtkIconView:orientation:
700 * The orientation property specifies how the cells (i.e. the icon and
701 * the text) of the item are positioned relative to each other.
705 g_object_class_install_property (gobject_class,
707 g_param_spec_enum ("orientation",
709 P_("How the text and icon of each item are positioned relative to each other"),
710 GTK_TYPE_ORIENTATION,
711 GTK_ORIENTATION_VERTICAL,
712 GTK_PARAM_READWRITE));
715 * GtkIconView:reorderable:
717 * The reorderable property specifies if the items can be reordered
722 g_object_class_install_property (gobject_class,
724 g_param_spec_boolean ("reorderable",
726 P_("View is reorderable"),
730 /* Style properties */
731 gtk_widget_class_install_style_property (widget_class,
732 g_param_spec_boxed ("selection-box-color",
733 P_("Selection Box Color"),
734 P_("Color of the selection box"),
736 GTK_PARAM_READABLE));
738 gtk_widget_class_install_style_property (widget_class,
739 g_param_spec_uchar ("selection-box-alpha",
740 P_("Selection Box Alpha"),
741 P_("Opacity of the selection box"),
744 GTK_PARAM_READABLE));
747 widget_class->set_scroll_adjustments_signal =
748 g_signal_new (I_("set_scroll_adjustments"),
749 G_TYPE_FROM_CLASS (gobject_class),
751 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
753 _gtk_marshal_VOID__OBJECT_OBJECT,
755 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
757 icon_view_signals[ITEM_ACTIVATED] =
758 g_signal_new (I_("item_activated"),
759 G_TYPE_FROM_CLASS (gobject_class),
761 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
763 g_cclosure_marshal_VOID__BOXED,
767 icon_view_signals[SELECTION_CHANGED] =
768 g_signal_new (I_("selection-changed"),
769 G_TYPE_FROM_CLASS (gobject_class),
771 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
773 g_cclosure_marshal_VOID__VOID,
776 icon_view_signals[SELECT_ALL] =
777 g_signal_new (I_("select_all"),
778 G_TYPE_FROM_CLASS (gobject_class),
779 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
780 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
782 g_cclosure_marshal_VOID__VOID,
785 icon_view_signals[UNSELECT_ALL] =
786 g_signal_new (I_("unselect_all"),
787 G_TYPE_FROM_CLASS (gobject_class),
788 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
789 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
791 g_cclosure_marshal_VOID__VOID,
794 icon_view_signals[SELECT_CURSOR_ITEM] =
795 g_signal_new (I_("select_cursor_item"),
796 G_TYPE_FROM_CLASS (gobject_class),
797 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
798 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
800 g_cclosure_marshal_VOID__VOID,
803 icon_view_signals[TOGGLE_CURSOR_ITEM] =
804 g_signal_new (I_("toggle_cursor_item"),
805 G_TYPE_FROM_CLASS (gobject_class),
806 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
807 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
809 g_cclosure_marshal_VOID__VOID,
812 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
813 g_signal_new (I_("activate_cursor_item"),
814 G_TYPE_FROM_CLASS (gobject_class),
815 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
816 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
818 _gtk_marshal_BOOLEAN__VOID,
821 icon_view_signals[MOVE_CURSOR] =
822 g_signal_new (I_("move_cursor"),
823 G_TYPE_FROM_CLASS (gobject_class),
824 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
825 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
827 _gtk_marshal_BOOLEAN__ENUM_INT,
829 GTK_TYPE_MOVEMENT_STEP,
833 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
835 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
837 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
838 "toggle_cursor_item", 0);
840 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
841 "activate_cursor_item", 0);
842 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
843 "activate_cursor_item", 0);
844 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
845 "activate_cursor_item", 0);
846 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
847 "activate_cursor_item", 0);
849 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
850 GTK_MOVEMENT_DISPLAY_LINES, -1);
851 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
852 GTK_MOVEMENT_DISPLAY_LINES, -1);
854 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
855 GTK_MOVEMENT_DISPLAY_LINES, 1);
856 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
857 GTK_MOVEMENT_DISPLAY_LINES, 1);
859 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
860 GTK_MOVEMENT_DISPLAY_LINES, -1);
862 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
863 GTK_MOVEMENT_DISPLAY_LINES, 1);
865 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
866 GTK_MOVEMENT_BUFFER_ENDS, -1);
867 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
868 GTK_MOVEMENT_BUFFER_ENDS, -1);
870 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
871 GTK_MOVEMENT_BUFFER_ENDS, 1);
872 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
873 GTK_MOVEMENT_BUFFER_ENDS, 1);
875 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
876 GTK_MOVEMENT_PAGES, -1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
878 GTK_MOVEMENT_PAGES, -1);
880 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
881 GTK_MOVEMENT_PAGES, 1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
883 GTK_MOVEMENT_PAGES, 1);
885 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
886 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
888 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
891 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
893 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
897 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
899 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
900 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
901 iface->clear = gtk_icon_view_cell_layout_clear;
902 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
903 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
904 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
905 iface->reorder = gtk_icon_view_cell_layout_reorder;
906 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
910 gtk_icon_view_init (GtkIconView *icon_view)
912 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
914 icon_view->priv->width = 0;
915 icon_view->priv->height = 0;
916 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
917 icon_view->priv->pressed_button = -1;
918 icon_view->priv->press_start_x = -1;
919 icon_view->priv->press_start_y = -1;
920 icon_view->priv->text_column = -1;
921 icon_view->priv->markup_column = -1;
922 icon_view->priv->pixbuf_column = -1;
923 icon_view->priv->text_cell = -1;
924 icon_view->priv->pixbuf_cell = -1;
926 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
928 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
930 icon_view->priv->cell_list = NULL;
931 icon_view->priv->n_cells = 0;
932 icon_view->priv->cursor_cell = -1;
934 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
936 icon_view->priv->columns = -1;
937 icon_view->priv->item_width = -1;
938 icon_view->priv->spacing = 0;
939 icon_view->priv->row_spacing = 6;
940 icon_view->priv->column_spacing = 6;
941 icon_view->priv->margin = 6;
945 gtk_icon_view_destroy (GtkObject *object)
947 GtkIconView *icon_view;
949 icon_view = GTK_ICON_VIEW (object);
951 gtk_icon_view_stop_editing (icon_view, TRUE);
953 gtk_icon_view_set_model (icon_view, NULL);
955 if (icon_view->priv->layout_idle_id != 0)
957 g_source_remove (icon_view->priv->layout_idle_id);
958 icon_view->priv->layout_idle_id = 0;
961 if (icon_view->priv->scroll_to_path != NULL)
963 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
964 icon_view->priv->scroll_to_path = NULL;
967 remove_scroll_timeout (icon_view);
969 if (icon_view->priv->hadjustment != NULL)
971 g_object_unref (icon_view->priv->hadjustment);
972 icon_view->priv->hadjustment = NULL;
975 if (icon_view->priv->vadjustment != NULL)
977 g_object_unref (icon_view->priv->vadjustment);
978 icon_view->priv->vadjustment = NULL;
981 clear_dest_info (icon_view);
982 clear_source_info (icon_view);
984 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
987 /* GObject methods */
989 gtk_icon_view_finalize (GObject *object)
991 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
993 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
998 gtk_icon_view_set_property (GObject *object,
1000 const GValue *value,
1003 GtkIconView *icon_view;
1005 icon_view = GTK_ICON_VIEW (object);
1009 case PROP_SELECTION_MODE:
1010 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1012 case PROP_PIXBUF_COLUMN:
1013 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1015 case PROP_TEXT_COLUMN:
1016 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1018 case PROP_MARKUP_COLUMN:
1019 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1022 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1024 case PROP_ORIENTATION:
1025 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1028 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1030 case PROP_ITEM_WIDTH:
1031 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1034 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1036 case PROP_ROW_SPACING:
1037 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1039 case PROP_COLUMN_SPACING:
1040 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1043 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1045 case PROP_REORDERABLE:
1046 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1050 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1056 gtk_icon_view_get_property (GObject *object,
1061 GtkIconView *icon_view;
1063 icon_view = GTK_ICON_VIEW (object);
1067 case PROP_SELECTION_MODE:
1068 g_value_set_enum (value, icon_view->priv->selection_mode);
1070 case PROP_PIXBUF_COLUMN:
1071 g_value_set_int (value, icon_view->priv->pixbuf_column);
1073 case PROP_TEXT_COLUMN:
1074 g_value_set_int (value, icon_view->priv->text_column);
1076 case PROP_MARKUP_COLUMN:
1077 g_value_set_int (value, icon_view->priv->markup_column);
1080 g_value_set_object (value, icon_view->priv->model);
1082 case PROP_ORIENTATION:
1083 g_value_set_enum (value, icon_view->priv->orientation);
1086 g_value_set_int (value, icon_view->priv->columns);
1088 case PROP_ITEM_WIDTH:
1089 g_value_set_int (value, icon_view->priv->item_width);
1092 g_value_set_int (value, icon_view->priv->spacing);
1094 case PROP_ROW_SPACING:
1095 g_value_set_int (value, icon_view->priv->row_spacing);
1097 case PROP_COLUMN_SPACING:
1098 g_value_set_int (value, icon_view->priv->column_spacing);
1101 g_value_set_int (value, icon_view->priv->margin);
1103 case PROP_REORDERABLE:
1104 g_value_set_boolean (value, icon_view->priv->reorderable);
1108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1113 /* GtkWidget signals */
1115 gtk_icon_view_realize (GtkWidget *widget)
1117 GtkIconView *icon_view;
1118 GdkWindowAttr attributes;
1119 gint attributes_mask;
1121 icon_view = GTK_ICON_VIEW (widget);
1123 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1125 /* Make the main, clipping window */
1126 attributes.window_type = GDK_WINDOW_CHILD;
1127 attributes.x = widget->allocation.x;
1128 attributes.y = widget->allocation.y;
1129 attributes.width = widget->allocation.width;
1130 attributes.height = widget->allocation.height;
1131 attributes.wclass = GDK_INPUT_OUTPUT;
1132 attributes.visual = gtk_widget_get_visual (widget);
1133 attributes.colormap = gtk_widget_get_colormap (widget);
1134 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1136 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1138 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1139 &attributes, attributes_mask);
1140 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1141 gdk_window_set_user_data (widget->window, widget);
1143 /* Make the window for the icon view */
1146 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1147 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1148 attributes.event_mask = (GDK_EXPOSURE_MASK |
1150 GDK_POINTER_MOTION_MASK |
1151 GDK_BUTTON_PRESS_MASK |
1152 GDK_BUTTON_RELEASE_MASK |
1153 GDK_KEY_PRESS_MASK |
1154 GDK_KEY_RELEASE_MASK) |
1155 gtk_widget_get_events (widget);
1157 icon_view->priv->bin_window = gdk_window_new (widget->window,
1158 &attributes, attributes_mask);
1159 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1161 widget->style = gtk_style_attach (widget->style, widget->window);
1162 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1164 gdk_window_show (icon_view->priv->bin_window);
1168 gtk_icon_view_unrealize (GtkWidget *widget)
1170 GtkIconView *icon_view;
1172 icon_view = GTK_ICON_VIEW (widget);
1174 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1175 gdk_window_destroy (icon_view->priv->bin_window);
1176 icon_view->priv->bin_window = NULL;
1178 /* GtkWidget::unrealize destroys children and widget->window */
1179 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1180 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1184 gtk_icon_view_state_changed (GtkWidget *widget,
1185 GtkStateType previous_state)
1187 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1189 if (GTK_WIDGET_REALIZED (widget))
1191 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1192 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1195 gtk_widget_queue_draw (widget);
1199 gtk_icon_view_style_set (GtkWidget *widget,
1200 GtkStyle *previous_style)
1202 GtkIconView *icon_view;
1204 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1206 icon_view = GTK_ICON_VIEW (widget);
1208 if (GTK_WIDGET_REALIZED (widget))
1210 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1211 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1214 gtk_widget_queue_resize (widget);
1218 gtk_icon_view_size_request (GtkWidget *widget,
1219 GtkRequisition *requisition)
1221 GtkIconView *icon_view;
1224 icon_view = GTK_ICON_VIEW (widget);
1226 requisition->width = icon_view->priv->width;
1227 requisition->height = icon_view->priv->height;
1229 tmp_list = icon_view->priv->children;
1233 GtkIconViewChild *child = tmp_list->data;
1234 GtkRequisition child_requisition;
1236 tmp_list = tmp_list->next;
1238 if (GTK_WIDGET_VISIBLE (child->widget))
1239 gtk_widget_size_request (child->widget, &child_requisition);
1244 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1248 for (list = icon_view->priv->children; list; list = list->next)
1250 GtkIconViewChild *child = list->data;
1251 GtkAllocation allocation;
1253 /* totally ignore our child's requisition */
1254 if (child->cell < 0)
1256 allocation.x = child->item->x;
1257 allocation.y = child->item->y;
1258 allocation.width = child->item->width;
1259 allocation.height = child->item->height;
1263 GdkRectangle *box = &child->item->box[child->cell];
1265 allocation.x = box->x;
1266 allocation.y = box->y;
1267 allocation.width = box->width;
1268 allocation.height = box->height;
1271 gtk_widget_size_allocate (child->widget, &allocation);
1276 gtk_icon_view_size_allocate (GtkWidget *widget,
1277 GtkAllocation *allocation)
1279 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1281 GtkAdjustment *hadjustment, *vadjustment;
1283 widget->allocation = *allocation;
1285 if (GTK_WIDGET_REALIZED (widget))
1287 gdk_window_move_resize (widget->window,
1288 allocation->x, allocation->y,
1289 allocation->width, allocation->height);
1290 gdk_window_resize (icon_view->priv->bin_window,
1291 MAX (icon_view->priv->width, allocation->width),
1292 MAX (icon_view->priv->height, allocation->height));
1295 gtk_icon_view_layout (icon_view);
1297 gtk_icon_view_allocate_children (icon_view);
1299 hadjustment = icon_view->priv->hadjustment;
1300 vadjustment = icon_view->priv->vadjustment;
1302 hadjustment->page_size = allocation->width;
1303 hadjustment->page_increment = allocation->width * 0.9;
1304 hadjustment->step_increment = allocation->width * 0.1;
1305 hadjustment->lower = 0;
1306 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1308 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1309 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1311 vadjustment->page_size = allocation->height;
1312 vadjustment->page_increment = allocation->height * 0.9;
1313 vadjustment->step_increment = allocation->height * 0.1;
1314 vadjustment->lower = 0;
1315 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1317 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1318 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1320 if (GTK_WIDGET_REALIZED (widget) &&
1321 icon_view->priv->scroll_to_path)
1324 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1325 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1326 icon_view->priv->scroll_to_path = NULL;
1328 gtk_icon_view_scroll_to_path (icon_view, path,
1329 icon_view->priv->scroll_to_use_align,
1330 icon_view->priv->scroll_to_row_align,
1331 icon_view->priv->scroll_to_col_align);
1332 gtk_tree_path_free (path);
1336 gtk_adjustment_changed (hadjustment);
1337 gtk_adjustment_changed (vadjustment);
1342 gtk_icon_view_expose (GtkWidget *widget,
1343 GdkEventExpose *expose)
1345 GtkIconView *icon_view;
1350 GtkIconViewDropPosition dest_pos;
1351 GtkIconViewItem *dest_item = NULL;
1353 icon_view = GTK_ICON_VIEW (widget);
1355 if (expose->window != icon_view->priv->bin_window)
1358 cr = gdk_cairo_create (icon_view->priv->bin_window);
1359 cairo_set_line_width (cr, 1.);
1361 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1365 dest_index = gtk_tree_path_get_indices (path)[0];
1366 gtk_tree_path_free (path);
1371 for (icons = icon_view->priv->items; icons; icons = icons->next)
1373 GtkIconViewItem *item = icons->data;
1378 area.width = item->width;
1379 area.height = item->height;
1381 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1384 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1385 icon_view->priv->bin_window,
1386 item->x, item->y, TRUE);
1388 if (dest_index == item->index)
1396 case GTK_ICON_VIEW_DROP_INTO:
1397 gtk_paint_focus (widget->style,
1398 icon_view->priv->bin_window,
1399 GTK_WIDGET_STATE (widget),
1402 "iconview-drop-indicator",
1403 dest_item->x, dest_item->y,
1404 dest_item->width, dest_item->height);
1406 case GTK_ICON_VIEW_DROP_ABOVE:
1407 gtk_paint_focus (widget->style,
1408 icon_view->priv->bin_window,
1409 GTK_WIDGET_STATE (widget),
1412 "iconview-drop-indicator",
1413 dest_item->x, dest_item->y - 1,
1414 dest_item->width, 2);
1416 case GTK_ICON_VIEW_DROP_LEFT:
1417 gtk_paint_focus (widget->style,
1418 icon_view->priv->bin_window,
1419 GTK_WIDGET_STATE (widget),
1422 "iconview-drop-indicator",
1423 dest_item->x - 1, dest_item->y,
1424 2, dest_item->height);
1426 case GTK_ICON_VIEW_DROP_BELOW:
1427 gtk_paint_focus (widget->style,
1428 icon_view->priv->bin_window,
1429 GTK_WIDGET_STATE (widget),
1432 "iconview-drop-indicator",
1433 dest_item->x, dest_item->y + dest_item->height - 1,
1434 dest_item->width, 2);
1436 case GTK_ICON_VIEW_DROP_RIGHT:
1437 gtk_paint_focus (widget->style,
1438 icon_view->priv->bin_window,
1439 GTK_WIDGET_STATE (widget),
1442 "iconview-drop-indicator",
1443 dest_item->x + dest_item->width - 1, dest_item->y,
1444 2, dest_item->height);
1445 case GTK_ICON_VIEW_NO_DROP: ;
1450 if (icon_view->priv->doing_rubberband)
1452 GdkRectangle *rectangles;
1455 gdk_region_get_rectangles (expose->region,
1459 while (n_rectangles--)
1460 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1462 g_free (rectangles);
1467 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1473 rubberband_scroll_timeout (gpointer data)
1475 GtkIconView *icon_view;
1480 value = MIN (icon_view->priv->vadjustment->value +
1481 icon_view->priv->scroll_value_diff,
1482 icon_view->priv->vadjustment->upper -
1483 icon_view->priv->vadjustment->page_size);
1485 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1487 gtk_icon_view_update_rubberband (icon_view);
1493 gtk_icon_view_motion (GtkWidget *widget,
1494 GdkEventMotion *event)
1496 GtkIconView *icon_view;
1499 icon_view = GTK_ICON_VIEW (widget);
1501 gtk_icon_view_maybe_begin_drag (icon_view, event);
1503 if (icon_view->priv->doing_rubberband)
1505 gtk_icon_view_update_rubberband (widget);
1507 abs_y = event->y - icon_view->priv->height *
1508 (icon_view->priv->vadjustment->value /
1509 (icon_view->priv->vadjustment->upper -
1510 icon_view->priv->vadjustment->lower));
1512 if (abs_y < 0 || abs_y > widget->allocation.height)
1515 icon_view->priv->scroll_value_diff = abs_y;
1517 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1519 icon_view->priv->event_last_x = event->x;
1520 icon_view->priv->event_last_y = event->y;
1522 if (icon_view->priv->scroll_timeout_id == 0)
1523 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1527 remove_scroll_timeout (icon_view);
1534 gtk_icon_view_remove (GtkContainer *container,
1537 GtkIconView *icon_view;
1538 GtkIconViewChild *child = NULL;
1541 icon_view = GTK_ICON_VIEW (container);
1543 tmp_list = icon_view->priv->children;
1546 child = tmp_list->data;
1547 if (child->widget == widget)
1549 gtk_widget_unparent (widget);
1551 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1552 g_list_free_1 (tmp_list);
1557 tmp_list = tmp_list->next;
1562 gtk_icon_view_forall (GtkContainer *container,
1563 gboolean include_internals,
1564 GtkCallback callback,
1565 gpointer callback_data)
1567 GtkIconView *icon_view;
1568 GtkIconViewChild *child = NULL;
1571 icon_view = GTK_ICON_VIEW (container);
1573 tmp_list = icon_view->priv->children;
1576 child = tmp_list->data;
1577 tmp_list = tmp_list->next;
1579 (* callback) (child->widget, callback_data);
1584 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1585 GtkIconViewItem *item,
1586 GtkIconViewCellInfo *info,
1591 GdkRectangle cell_area;
1592 gboolean visible, mode;
1594 gtk_icon_view_set_cell_data (icon_view, item);
1596 g_object_get (info->cell,
1597 "visible", &visible,
1601 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1603 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1605 path = gtk_tree_path_new_from_indices (item->index, -1);
1606 path_string = gtk_tree_path_to_string (path);
1607 gtk_tree_path_free (path);
1609 gtk_cell_renderer_activate (info->cell,
1611 GTK_WIDGET (icon_view),
1617 g_free (path_string);
1622 gtk_icon_view_put (GtkIconView *icon_view,
1624 GtkIconViewItem *item,
1627 GtkIconViewChild *child;
1629 child = g_new (GtkIconViewChild, 1);
1631 child->widget = widget;
1635 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1637 if (GTK_WIDGET_REALIZED (icon_view))
1638 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1640 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1644 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1645 GtkIconView *icon_view)
1648 GtkIconViewItem *item;
1650 if (icon_view->priv->edited_item == NULL)
1653 item = icon_view->priv->edited_item;
1654 icon_view->priv->edited_item = NULL;
1655 icon_view->priv->editable = NULL;
1656 for (l = icon_view->priv->cell_list; l; l = l->next)
1658 GtkIconViewCellInfo *info = l->data;
1660 info->editing = FALSE;
1663 if (GTK_WIDGET_HAS_FOCUS (editable))
1664 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1666 g_signal_handlers_disconnect_by_func (editable,
1667 gtk_icon_view_remove_widget,
1670 gtk_container_remove (GTK_CONTAINER (icon_view),
1671 GTK_WIDGET (editable));
1673 gtk_icon_view_queue_draw_item (icon_view, item);
1678 gtk_icon_view_start_editing (GtkIconView *icon_view,
1679 GtkIconViewItem *item,
1680 GtkIconViewCellInfo *info,
1685 GdkRectangle cell_area;
1686 gboolean visible, mode;
1687 GtkCellEditable *editable;
1689 gtk_icon_view_set_cell_data (icon_view, item);
1691 g_object_get (info->cell,
1692 "visible", &visible,
1695 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1697 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1699 path = gtk_tree_path_new_from_indices (item->index, -1);
1700 path_string = gtk_tree_path_to_string (path);
1701 gtk_tree_path_free (path);
1703 editable = gtk_cell_renderer_start_editing (info->cell,
1705 GTK_WIDGET (icon_view),
1710 g_free (path_string);
1712 /* FIXME ugly special case */
1713 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1714 g_object_set (editable, "has-frame", TRUE, NULL);
1716 /* the rest corresponds to tree_view_real_start_editing... */
1717 icon_view->priv->edited_item = item;
1718 icon_view->priv->editable = editable;
1719 info->editing = TRUE;
1721 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1723 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1725 gtk_widget_grab_focus (GTK_WIDGET (editable));
1726 g_signal_connect (editable, "remove_widget",
1727 G_CALLBACK (gtk_icon_view_remove_widget),
1734 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1735 gboolean cancel_editing)
1737 GtkCellRenderer *cell = NULL;
1738 GtkIconViewItem *item;
1741 if (icon_view->priv->edited_item == NULL)
1745 * This is very evil. We need to do this, because
1746 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1747 * later on. If gtk_icon_view_row_changed notices
1748 * icon_view->priv->edited_item != NULL, it'll call
1749 * gtk_icon_view_stop_editing again. Bad things will happen then.
1751 * Please read that again if you intend to modify anything here.
1754 item = icon_view->priv->edited_item;
1755 icon_view->priv->edited_item = NULL;
1757 for (l = icon_view->priv->cell_list; l; l = l->next)
1759 GtkIconViewCellInfo *info = l->data;
1771 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1772 if (!cancel_editing)
1773 gtk_cell_editable_editing_done (icon_view->priv->editable);
1775 icon_view->priv->edited_item = item;
1777 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1781 * gtk_icon_view_set_cursor:
1782 * @icon_view: A #GtkIconView
1783 * @path: A #GtkTreePath
1784 * @cell: One of the cell renderers of @icon_view, or %NULL
1785 * @start_editing: %TRUE if the specified cell should start being edited.
1787 * Sets the current keyboard focus to be at @path, and selects it. This is
1788 * useful when you want to focus the user's attention on a particular item.
1789 * If @cell is not %NULL, then focus is given to the cell specified by
1790 * it. Additionally, if @start_editing is %TRUE, then editing should be
1791 * started in the specified cell.
1793 * This function is often followed by <literal>gtk_widget_grab_focus
1794 * (icon_view)</literal> in order to give keyboard focus to the widget.
1795 * Please note that editing can only happen when the widget is realized.
1800 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1802 GtkCellRenderer *cell,
1803 gboolean start_editing)
1805 GtkIconViewItem *item = NULL;
1806 GtkIconViewCellInfo *info = NULL;
1810 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1811 g_return_if_fail (path != NULL);
1812 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1814 gtk_icon_view_stop_editing (icon_view, TRUE);
1816 if (gtk_tree_path_get_depth (path) == 1)
1817 item = g_list_nth_data (icon_view->priv->items,
1818 gtk_tree_path_get_indices(path)[0]);
1824 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1828 if (info->cell == cell)
1837 g_return_if_fail (cell == NULL || info != NULL);
1839 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1840 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1842 if (info && start_editing)
1843 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1847 * gtk_icon_view_get_cursor:
1848 * @icon_view: A #GtkIconView
1849 * @path: Return location for the current cursor path, or %NULL
1850 * @cell: Return location the current focus cell, or %NULL
1852 * Fills in @path and @cell with the current cursor path and cell.
1853 * If the cursor isn't currently set, then *@path will be %NULL.
1854 * If no cell currently has focus, then *@cell will be %NULL.
1856 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1858 * Return value: %TRUE if the cursor is set.
1863 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1865 GtkCellRenderer **cell)
1867 GtkIconViewItem *item;
1868 GtkIconViewCellInfo *info;
1870 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1872 item = icon_view->priv->cursor_item;
1873 if (icon_view->priv->cursor_cell < 0)
1876 info = g_list_nth_data (icon_view->priv->cell_list,
1877 icon_view->priv->cursor_cell);
1882 *path = gtk_tree_path_new_from_indices (item->index, -1);
1895 return (item != NULL);
1899 gtk_icon_view_button_press (GtkWidget *widget,
1900 GdkEventButton *event)
1902 GtkIconView *icon_view;
1903 GtkIconViewItem *item;
1904 GtkIconViewCellInfo *info = NULL;
1905 gboolean dirty = FALSE;
1906 GtkCellRendererMode mode;
1909 icon_view = GTK_ICON_VIEW (widget);
1911 if (event->window != icon_view->priv->bin_window)
1914 if (!GTK_WIDGET_HAS_FOCUS (widget))
1915 gtk_widget_grab_focus (widget);
1917 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1919 item = gtk_icon_view_get_item_at_coords (icon_view,
1925 g_object_get (info->cell, "mode", &mode, NULL);
1927 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1928 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1929 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1933 gtk_icon_view_scroll_to_item (icon_view, item);
1935 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1937 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1939 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1940 (event->state & GDK_SHIFT_MASK))
1942 gtk_icon_view_unselect_all_internal (icon_view);
1944 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1945 if (!icon_view->priv->anchor_item)
1946 icon_view->priv->anchor_item = item;
1948 gtk_icon_view_select_all_between (icon_view,
1949 icon_view->priv->anchor_item,
1955 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1956 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1957 (event->state & GDK_CONTROL_MASK))
1959 item->selected = !item->selected;
1960 gtk_icon_view_queue_draw_item (icon_view, item);
1965 if (!item->selected)
1967 gtk_icon_view_unselect_all_internal (icon_view);
1969 item->selected = TRUE;
1970 gtk_icon_view_queue_draw_item (icon_view, item);
1974 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1975 icon_view->priv->anchor_item = item;
1978 /* Save press to possibly begin a drag */
1979 if (icon_view->priv->pressed_button < 0)
1981 icon_view->priv->pressed_button = event->button;
1982 icon_view->priv->press_start_x = event->x;
1983 icon_view->priv->press_start_y = event->y;
1986 if (!icon_view->priv->last_single_clicked)
1987 icon_view->priv->last_single_clicked = item;
1989 /* cancel the current editing, if it exists */
1990 gtk_icon_view_stop_editing (icon_view, TRUE);
1992 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1993 gtk_icon_view_item_activate_cell (icon_view, item, info,
1995 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1996 gtk_icon_view_start_editing (icon_view, item, info,
2001 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2002 !(event->state & GDK_CONTROL_MASK))
2004 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2007 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2008 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2013 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2015 item = gtk_icon_view_get_item_at_coords (icon_view,
2020 if (item && item == icon_view->priv->last_single_clicked)
2024 path = gtk_tree_path_new_from_indices (item->index, -1);
2025 gtk_icon_view_item_activated (icon_view, path);
2026 gtk_tree_path_free (path);
2029 icon_view->priv->last_single_clicked = NULL;
2030 icon_view->priv->pressed_button = -1;
2034 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2036 return event->button == 1;
2040 gtk_icon_view_button_release (GtkWidget *widget,
2041 GdkEventButton *event)
2043 GtkIconView *icon_view;
2045 icon_view = GTK_ICON_VIEW (widget);
2047 if (icon_view->priv->pressed_button == event->button)
2048 icon_view->priv->pressed_button = -1;
2050 gtk_icon_view_stop_rubberbanding (icon_view);
2052 remove_scroll_timeout (icon_view);
2058 gtk_icon_view_key_press (GtkWidget *widget,
2061 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2063 if (icon_view->priv->doing_rubberband)
2065 if (event->keyval == GDK_Escape)
2066 gtk_icon_view_stop_rubberbanding (icon_view);
2071 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2075 gtk_icon_view_key_release (GtkWidget *widget,
2078 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2080 if (icon_view->priv->doing_rubberband)
2083 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2087 gtk_icon_view_update_rubberband (gpointer data)
2089 GtkIconView *icon_view;
2091 GdkRectangle old_area;
2092 GdkRectangle new_area;
2093 GdkRectangle common;
2094 GdkRegion *invalid_region;
2096 icon_view = GTK_ICON_VIEW (data);
2098 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2103 old_area.x = MIN (icon_view->priv->rubberband_x1,
2104 icon_view->priv->rubberband_x2);
2105 old_area.y = MIN (icon_view->priv->rubberband_y1,
2106 icon_view->priv->rubberband_y2);
2107 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2108 icon_view->priv->rubberband_x1) + 1;
2109 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2110 icon_view->priv->rubberband_y1) + 1;
2112 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2113 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2114 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2115 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2117 invalid_region = gdk_region_rectangle (&old_area);
2118 gdk_region_union_with_rect (invalid_region, &new_area);
2120 gdk_rectangle_intersect (&old_area, &new_area, &common);
2121 if (common.width > 2 && common.height > 2)
2123 GdkRegion *common_region;
2125 /* make sure the border is invalidated */
2131 common_region = gdk_region_rectangle (&common);
2133 gdk_region_subtract (invalid_region, common_region);
2134 gdk_region_destroy (common_region);
2137 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2139 gdk_region_destroy (invalid_region);
2141 icon_view->priv->rubberband_x2 = x;
2142 icon_view->priv->rubberband_y2 = y;
2144 gtk_icon_view_update_rubberband_selection (icon_view);
2148 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2154 g_assert (!icon_view->priv->doing_rubberband);
2156 for (items = icon_view->priv->items; items; items = items->next)
2158 GtkIconViewItem *item = items->data;
2160 item->selected_before_rubberbanding = item->selected;
2163 icon_view->priv->rubberband_x1 = x;
2164 icon_view->priv->rubberband_y1 = y;
2165 icon_view->priv->rubberband_x2 = x;
2166 icon_view->priv->rubberband_y2 = y;
2168 icon_view->priv->doing_rubberband = TRUE;
2170 gtk_grab_add (GTK_WIDGET (icon_view));
2174 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2176 if (!icon_view->priv->doing_rubberband)
2179 icon_view->priv->doing_rubberband = FALSE;
2181 gtk_grab_remove (GTK_WIDGET (icon_view));
2183 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2187 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2190 gint x, y, width, height;
2191 gboolean dirty = FALSE;
2193 x = MIN (icon_view->priv->rubberband_x1,
2194 icon_view->priv->rubberband_x2);
2195 y = MIN (icon_view->priv->rubberband_y1,
2196 icon_view->priv->rubberband_y2);
2197 width = ABS (icon_view->priv->rubberband_x1 -
2198 icon_view->priv->rubberband_x2);
2199 height = ABS (icon_view->priv->rubberband_y1 -
2200 icon_view->priv->rubberband_y2);
2202 for (items = icon_view->priv->items; items; items = items->next)
2204 GtkIconViewItem *item = items->data;
2208 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2209 x, y, width, height);
2211 selected = is_in ^ item->selected_before_rubberbanding;
2213 if (item->selected != selected)
2215 item->selected = selected;
2217 gtk_icon_view_queue_draw_item (icon_view, item);
2222 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2226 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2227 GtkIconViewItem *item,
2236 for (l = icon_view->priv->cell_list; l; l = l->next)
2238 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2240 if (!info->cell->visible)
2243 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2245 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2246 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2254 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2256 gboolean dirty = FALSE;
2259 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2262 for (items = icon_view->priv->items; items; items = items->next)
2264 GtkIconViewItem *item = items->data;
2268 item->selected = FALSE;
2270 gtk_icon_view_queue_draw_item (icon_view, item);
2278 /* GtkIconView signals */
2280 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2281 GtkAdjustment *hadj,
2282 GtkAdjustment *vadj)
2284 gboolean need_adjust = FALSE;
2287 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2289 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2291 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2293 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2295 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2297 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2298 0, 0, NULL, NULL, icon_view);
2299 g_object_unref (icon_view->priv->hadjustment);
2302 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2304 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2305 0, 0, NULL, NULL, icon_view);
2306 g_object_unref (icon_view->priv->vadjustment);
2309 if (icon_view->priv->hadjustment != hadj)
2311 icon_view->priv->hadjustment = hadj;
2312 g_object_ref_sink (icon_view->priv->hadjustment);
2314 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2315 G_CALLBACK (gtk_icon_view_adjustment_changed),
2320 if (icon_view->priv->vadjustment != vadj)
2322 icon_view->priv->vadjustment = vadj;
2323 g_object_ref_sink (icon_view->priv->vadjustment);
2325 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2326 G_CALLBACK (gtk_icon_view_adjustment_changed),
2332 gtk_icon_view_adjustment_changed (NULL, icon_view);
2336 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2338 gtk_icon_view_select_all (icon_view);
2342 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2344 gtk_icon_view_unselect_all (icon_view);
2348 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2350 gtk_icon_view_unselect_all (icon_view);
2352 if (icon_view->priv->cursor_item != NULL)
2353 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2357 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2360 GtkCellRendererMode mode;
2361 GtkIconViewCellInfo *info = NULL;
2363 if (!icon_view->priv->cursor_item)
2366 info = g_list_nth_data (icon_view->priv->cell_list,
2367 icon_view->priv->cursor_cell);
2371 g_object_get (info->cell, "mode", &mode, NULL);
2373 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2375 gtk_icon_view_item_activate_cell (icon_view,
2376 icon_view->priv->cursor_item,
2380 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2382 gtk_icon_view_start_editing (icon_view,
2383 icon_view->priv->cursor_item,
2389 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2390 gtk_icon_view_item_activated (icon_view, path);
2391 gtk_tree_path_free (path);
2397 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2399 if (!icon_view->priv->cursor_item)
2402 switch (icon_view->priv->selection_mode)
2404 case GTK_SELECTION_NONE:
2406 case GTK_SELECTION_BROWSE:
2407 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2409 case GTK_SELECTION_SINGLE:
2410 if (icon_view->priv->cursor_item->selected)
2411 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2413 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2415 case GTK_SELECTION_MULTIPLE:
2416 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2417 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2419 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2424 /* Internal functions */
2426 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2427 GtkIconView *icon_view)
2429 if (GTK_WIDGET_REALIZED (icon_view))
2431 gdk_window_move (icon_view->priv->bin_window,
2432 - icon_view->priv->hadjustment->value,
2433 - icon_view->priv->vadjustment->value);
2435 if (icon_view->priv->doing_rubberband)
2436 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2438 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2443 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2448 gint *maximum_width)
2451 gint x, current_width;
2452 GList *items, *last_item;
2459 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2460 max_height = g_new0 (gint, icon_view->priv->n_cells);
2467 gtk_widget_style_get (GTK_WIDGET (icon_view),
2468 "focus-line-width", &focus_width,
2471 x += icon_view->priv->margin + focus_width;
2472 current_width += 2 * (icon_view->priv->margin + focus_width);
2477 GtkIconViewItem *item = items->data;
2479 gtk_icon_view_calculate_item_size (icon_view, item);
2480 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2482 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2484 current_width += item->width;
2486 if (items != first_item)
2488 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2489 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2493 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2495 item->y = *y + focus_width;
2496 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2498 x = current_width - (icon_view->priv->margin + focus_width);
2500 for (i = 0; i < icon_view->priv->n_cells; i++)
2501 max_height[i] = MAX (max_height[i], item->box[i].height);
2503 if (current_width > *maximum_width)
2504 *maximum_width = current_width;
2510 items = items->next;
2515 /* Now go through the row again and align the icons */
2516 for (items = first_item; items != last_item; items = items->next)
2518 GtkIconViewItem *item = items->data;
2520 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2522 /* We may want to readjust the new y coordinate. */
2523 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2524 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2527 item->col = col - 1 - item->col;
2530 g_free (max_height);
2536 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2539 if (upper != adj->upper)
2541 gdouble min = MAX (0.0, upper - adj->page_size);
2542 gboolean value_changed = FALSE;
2546 if (adj->value > min)
2549 value_changed = TRUE;
2552 gtk_adjustment_changed (adj);
2555 gtk_adjustment_value_changed (adj);
2560 gtk_icon_view_layout (GtkIconView *icon_view)
2562 gint y = 0, maximum_width = 0;
2568 if (icon_view->priv->layout_idle_id != 0)
2570 g_source_remove (icon_view->priv->layout_idle_id);
2571 icon_view->priv->layout_idle_id = 0;
2574 if (icon_view->priv->model == NULL)
2577 widget = GTK_WIDGET (icon_view);
2579 item_width = icon_view->priv->item_width;
2583 for (icons = icon_view->priv->items; icons; icons = icons->next)
2585 GtkIconViewItem *item = icons->data;
2586 gtk_icon_view_calculate_item_size (icon_view, item);
2587 item_width = MAX (item_width, item->width);
2591 icons = icon_view->priv->items;
2592 y += icon_view->priv->margin;
2597 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2599 &y, &maximum_width);
2602 while (icons != NULL);
2604 if (maximum_width != icon_view->priv->width)
2605 icon_view->priv->width = maximum_width;
2607 y += icon_view->priv->margin;
2609 if (y != icon_view->priv->height)
2610 icon_view->priv->height = y;
2612 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2613 icon_view->priv->width);
2614 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2615 icon_view->priv->height);
2617 if (icon_view->priv->width != widget->requisition.width ||
2618 icon_view->priv->height != widget->requisition.height)
2619 gtk_widget_queue_resize_no_redraw (widget);
2621 if (GTK_WIDGET_REALIZED (icon_view))
2622 gdk_window_resize (icon_view->priv->bin_window,
2623 MAX (icon_view->priv->width, widget->allocation.width),
2624 MAX (icon_view->priv->height, widget->allocation.height));
2626 if (icon_view->priv->scroll_to_path)
2630 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2631 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2632 icon_view->priv->scroll_to_path = NULL;
2634 gtk_icon_view_scroll_to_path (icon_view, path,
2635 icon_view->priv->scroll_to_use_align,
2636 icon_view->priv->scroll_to_row_align,
2637 icon_view->priv->scroll_to_col_align);
2638 gtk_tree_path_free (path);
2641 gtk_widget_queue_draw (widget);
2645 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2646 GtkIconViewItem *item,
2647 GtkIconViewCellInfo *info,
2648 GdkRectangle *cell_area)
2650 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2652 cell_area->x = item->box[info->position].x - item->before[info->position];
2653 cell_area->y = item->y;
2654 cell_area->width = item->box[info->position].width +
2655 item->before[info->position] + item->after[info->position];
2656 cell_area->height = item->height;
2660 cell_area->x = item->x;
2661 cell_area->y = item->box[info->position].y - item->before[info->position];
2662 cell_area->width = item->width;
2663 cell_area->height = item->box[info->position].height +
2664 item->before[info->position] + item->after[info->position];
2669 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2670 GtkIconViewItem *item,
2671 GtkIconViewCellInfo *info,
2674 *box = item->box[info->position];
2677 /* try to guess a reasonable wrap width for an implicit text cell renderer
2680 adjust_wrap_width (GtkIconView *icon_view,
2681 GtkIconViewItem *item)
2683 GtkIconViewCellInfo *text_info;
2684 GtkIconViewCellInfo *pixbuf_info;
2685 gint pixbuf_width, wrap_width;
2687 if (icon_view->priv->text_cell != -1 &&
2688 icon_view->priv->pixbuf_cell != -1)
2690 text_info = g_list_nth_data (icon_view->priv->cell_list,
2691 icon_view->priv->text_cell);
2692 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2693 icon_view->priv->pixbuf_cell);
2695 gtk_cell_renderer_get_size (pixbuf_info->cell,
2696 GTK_WIDGET (icon_view),
2701 if (item->width == -1)
2702 wrap_width = MAX (2 * pixbuf_width, 50);
2703 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2704 wrap_width = item->width;
2706 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2708 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2709 g_object_set (text_info->cell, "width", wrap_width, NULL);
2714 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2715 GtkIconViewItem *item)
2720 if (item->width != -1 && item->height != -1)
2723 if (item->n_cells != icon_view->priv->n_cells)
2725 g_free (item->before);
2726 g_free (item->after);
2729 item->before = g_new0 (gint, icon_view->priv->n_cells);
2730 item->after = g_new0 (gint, icon_view->priv->n_cells);
2731 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2733 item->n_cells = icon_view->priv->n_cells;
2736 gtk_icon_view_set_cell_data (icon_view, item);
2738 spacing = icon_view->priv->spacing;
2742 for (l = icon_view->priv->cell_list; l; l = l->next)
2744 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2746 if (!info->cell->visible)
2749 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2751 &item->box[info->position].width,
2752 &item->box[info->position].height);
2754 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2756 item->width += item->box[info->position].width
2757 + (info->position > 0 ? spacing : 0);
2758 item->height = MAX (item->height, item->box[info->position].height);
2762 item->width = MAX (item->width, item->box[info->position].width);
2763 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2769 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2770 GtkIconViewItem *item,
2773 GdkRectangle cell_area;
2779 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2781 gtk_icon_view_set_cell_data (icon_view, item);
2783 spacing = icon_view->priv->spacing;
2786 for (i = 0; i < icon_view->priv->n_cells; i++)
2788 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2789 item->height = MAX (item->height, max_height[i]);
2791 item->height += max_height[i] + (i > 0 ? spacing : 0);
2794 cell_area.x = item->x;
2795 cell_area.y = item->y;
2797 for (k = 0; k < 2; k++)
2798 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2800 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2802 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2805 if (!info->cell->visible)
2808 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2810 cell_area.width = item->box[info->position].width;
2811 cell_area.height = item->height;
2815 cell_area.width = item->width;
2816 cell_area.height = max_height[i];
2819 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2821 &item->box[info->position].x, &item->box[info->position].y,
2822 &item->box[info->position].width, &item->box[info->position].height);
2824 item->box[info->position].x += cell_area.x;
2825 item->box[info->position].y += cell_area.y;
2826 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2828 item->before[info->position] = item->box[info->position].x - cell_area.x;
2829 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2830 cell_area.x += cell_area.width + spacing;
2834 if (item->box[info->position].width > item->width)
2836 item->width = item->box[info->position].width;
2837 cell_area.width = item->width;
2839 item->before[info->position] = item->box[info->position].y - cell_area.y;
2840 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2841 cell_area.y += cell_area.height + spacing;
2845 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2847 for (i = 0; i < icon_view->priv->n_cells; i++)
2849 item->box[i].x = item->x + item->width -
2850 (item->box[i].x + item->box[i].width - item->x);
2856 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2858 g_list_foreach (icon_view->priv->items,
2859 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2863 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2870 gtk_icon_view_paint_item (GtkIconView *icon_view,
2872 GtkIconViewItem *item,
2874 GdkDrawable *drawable,
2877 gboolean draw_focus)
2879 gint focus_width, focus_pad;
2881 GdkRectangle cell_area, box;
2885 GtkCellRendererState flags;
2887 if (icon_view->priv->model == NULL)
2890 gtk_icon_view_set_cell_data (icon_view, item);
2892 gtk_widget_style_get (GTK_WIDGET (icon_view),
2893 "focus-line-width", &focus_width,
2894 "focus-padding", &focus_pad,
2897 padding = focus_width;
2901 flags = GTK_CELL_RENDERER_SELECTED;
2902 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2903 state = GTK_STATE_SELECTED;
2905 state = GTK_STATE_ACTIVE;
2910 state = GTK_STATE_NORMAL;
2913 #ifdef DEBUG_ICON_VIEW
2914 gdk_draw_rectangle (drawable,
2915 GTK_WIDGET (icon_view)->style->black_gc,
2918 item->width, item->height);
2922 for (l = icon_view->priv->cell_list; l; l = l->next)
2924 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2926 if (!info->cell->visible)
2929 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2931 /* FIXME we hardwire background drawing behind text
2932 * cell renderers here
2934 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2936 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2937 cairo_rectangle (cr,
2938 x - item->x + box.x,
2939 y - item->y + box.y,
2940 box.width, box.height);
2945 for (l = icon_view->priv->cell_list; l; l = l->next)
2947 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2949 if (!info->cell->visible)
2952 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2954 #ifdef DEBUG_ICON_VIEW
2955 gdk_draw_rectangle (drawable,
2956 GTK_WIDGET (icon_view)->style->black_gc,
2958 x - item->x + cell_area.x,
2959 y - item->y + cell_area.y,
2960 cell_area.width, cell_area.height);
2962 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2964 gdk_draw_rectangle (drawable,
2965 GTK_WIDGET (icon_view)->style->black_gc,
2967 x - item->x + box.x,
2968 y - item->y + box.y,
2969 box.width, box.height);
2972 cell_area.x = x - item->x + cell_area.x;
2973 cell_area.y = y - item->y + cell_area.y;
2975 gtk_cell_renderer_render (info->cell,
2977 GTK_WIDGET (icon_view),
2978 &cell_area, &cell_area, area, flags);
2982 /* FIXME where to draw the focus with generic cell renderers ? */
2984 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2985 item == icon_view->priv->cursor_item)
2986 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2988 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2990 if (!info->cell->visible)
2993 if (icon_view->priv->cursor_cell < 0 &&
2994 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2995 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2996 icon_view->priv->cursor_cell = i;
2998 if (i == icon_view->priv->cursor_cell)
3000 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3002 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3006 GTK_WIDGET (icon_view),
3008 x - item->x + box.x - padding,
3009 y - item->y + box.y - padding,
3010 box.width + 2 * padding,
3011 box.height + 2 * padding);
3018 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3023 GdkRectangle rubber_rect;
3024 GdkColor *fill_color_gdk;
3025 guchar fill_color_alpha;
3027 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3028 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3029 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3030 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3032 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3035 gtk_widget_style_get (GTK_WIDGET (icon_view),
3036 "selection-box-color", &fill_color_gdk,
3037 "selection-box-alpha", &fill_color_alpha,
3040 if (!fill_color_gdk)
3041 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3043 cairo_set_source_rgba (cr,
3044 fill_color_gdk->red / 65535.,
3045 fill_color_gdk->green / 65535.,
3046 fill_color_gdk->blue / 65535.,
3047 fill_color_alpha / 255.);
3050 gdk_cairo_rectangle (cr, &rect);
3054 /* Draw the border without alpha */
3055 cairo_set_source_rgb (cr,
3056 fill_color_gdk->red / 65535.,
3057 fill_color_gdk->green / 65535.,
3058 fill_color_gdk->blue / 65535.);
3059 cairo_rectangle (cr,
3060 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3061 rubber_rect.width - 1, rubber_rect.height - 1);
3065 gdk_color_free (fill_color_gdk);
3069 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3075 index = gtk_tree_path_get_indices (path)[0];
3077 for (l = icon_view->priv->items; l; l = l->next)
3079 GtkIconViewItem *item = l->data;
3081 if (item->index == index)
3083 gtk_icon_view_queue_draw_item (icon_view, item);
3090 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3091 GtkIconViewItem *item)
3096 gtk_widget_style_get (GTK_WIDGET (icon_view),
3097 "focus-line-width", &focus_width,
3100 rect.x = item->x - focus_width;
3101 rect.y = item->y - focus_width;
3102 rect.width = item->width + 2 * focus_width;
3103 rect.height = item->height + 2 * focus_width;
3105 if (icon_view->priv->bin_window)
3106 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3110 layout_callback (gpointer user_data)
3112 GtkIconView *icon_view;
3114 icon_view = GTK_ICON_VIEW (user_data);
3116 icon_view->priv->layout_idle_id = 0;
3118 gtk_icon_view_layout (icon_view);
3124 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3126 if (icon_view->priv->layout_idle_id != 0)
3129 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3133 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3134 GtkIconViewItem *item,
3138 AtkObject *item_obj;
3140 if (icon_view->priv->cursor_item == item &&
3141 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3144 if (icon_view->priv->cursor_item != NULL)
3145 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3147 icon_view->priv->cursor_item = item;
3148 if (cursor_cell >= 0)
3149 icon_view->priv->cursor_cell = cursor_cell;
3151 gtk_icon_view_queue_draw_item (icon_view, item);
3153 /* Notify that accessible focus object has changed */
3154 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3155 item_obj = atk_object_ref_accessible_child (obj, item->index);
3157 if (item_obj != NULL)
3159 atk_focus_tracker_notify (item_obj);
3160 g_object_unref (item_obj);
3165 static GtkIconViewItem *
3166 gtk_icon_view_item_new (void)
3168 GtkIconViewItem *item;
3170 item = g_new0 (GtkIconViewItem, 1);
3179 gtk_icon_view_item_free (GtkIconViewItem *item)
3181 g_return_if_fail (item != NULL);
3183 g_free (item->before);
3184 g_free (item->after);
3191 static GtkIconViewItem *
3192 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3195 gboolean only_in_cell,
3196 GtkIconViewCellInfo **cell_at_pos)
3201 for (items = icon_view->priv->items; items; items = items->next)
3203 GtkIconViewItem *item = items->data;
3205 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3206 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3208 if (only_in_cell || cell_at_pos)
3210 gtk_icon_view_set_cell_data (icon_view, item);
3212 for (l = icon_view->priv->cell_list; l; l = l->next)
3214 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3216 if (!info->cell->visible)
3219 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3221 if ((x >= box.x && x <= box.x + box.width &&
3222 y >= box.y && y <= box.y + box.height) ||
3224 x <= box.x + box.width &&
3226 y <= box.y + box.height))
3229 *cell_at_pos = info;
3239 *cell_at_pos = NULL;
3250 gtk_icon_view_select_item (GtkIconView *icon_view,
3251 GtkIconViewItem *item)
3253 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3254 g_return_if_fail (item != NULL);
3259 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3261 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3262 gtk_icon_view_unselect_all_internal (icon_view);
3264 item->selected = TRUE;
3266 gtk_icon_view_queue_draw_item (icon_view, item);
3268 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3273 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3274 GtkIconViewItem *item)
3276 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3277 g_return_if_fail (item != NULL);
3279 if (!item->selected)
3282 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3283 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3286 item->selected = FALSE;
3288 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3290 gtk_icon_view_queue_draw_item (icon_view, item);
3294 verify_items (GtkIconView *icon_view)
3299 for (items = icon_view->priv->items; items; items = items->next)
3301 GtkIconViewItem *item = items->data;
3303 if (item->index != i)
3304 g_error ("List item does not match its index: "
3305 "item index %d and list index %d\n", item->index, i);
3312 gtk_icon_view_row_changed (GtkTreeModel *model,
3317 GtkIconViewItem *item;
3319 GtkIconView *icon_view;
3321 icon_view = GTK_ICON_VIEW (data);
3323 gtk_icon_view_stop_editing (icon_view, TRUE);
3325 index = gtk_tree_path_get_indices(path)[0];
3326 item = g_list_nth_data (icon_view->priv->items, index);
3328 gtk_icon_view_item_invalidate_size (item);
3329 gtk_icon_view_queue_layout (icon_view);
3331 verify_items (icon_view);
3335 gtk_icon_view_row_inserted (GtkTreeModel *model,
3341 GtkIconViewItem *item;
3342 gboolean iters_persist;
3343 GtkIconView *icon_view;
3346 icon_view = GTK_ICON_VIEW (data);
3348 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3350 index = gtk_tree_path_get_indices(path)[0];
3352 item = gtk_icon_view_item_new ();
3357 item->index = index;
3359 /* FIXME: We can be more efficient here,
3360 we can store a tail pointer and use that when
3361 appending (which is a rather common operation)
3363 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3366 list = g_list_nth (icon_view->priv->items, index + 1);
3367 for (; list; list = list->next)
3374 verify_items (icon_view);
3376 gtk_icon_view_queue_layout (icon_view);
3380 gtk_icon_view_row_deleted (GtkTreeModel *model,
3385 GtkIconView *icon_view;
3386 GtkIconViewItem *item;
3388 gboolean emit = FALSE;
3390 icon_view = GTK_ICON_VIEW (data);
3392 index = gtk_tree_path_get_indices(path)[0];
3394 list = g_list_nth (icon_view->priv->items, index);
3397 gtk_icon_view_stop_editing (icon_view, TRUE);
3399 if (item == icon_view->priv->anchor_item)
3400 icon_view->priv->anchor_item = NULL;
3402 if (item == icon_view->priv->cursor_item)
3403 icon_view->priv->cursor_item = NULL;
3408 gtk_icon_view_item_free (item);
3410 for (next = list->next; next; next = next->next)
3417 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3419 verify_items (icon_view);
3421 gtk_icon_view_queue_layout (icon_view);
3424 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3428 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3429 GtkTreePath *parent,
3436 GtkIconView *icon_view;
3437 GList *items = NULL, *list;
3438 GtkIconViewItem **item_array;
3441 icon_view = GTK_ICON_VIEW (data);
3443 gtk_icon_view_stop_editing (icon_view, TRUE);
3445 length = gtk_tree_model_iter_n_children (model, NULL);
3447 order = g_new (gint, length);
3448 for (i = 0; i < length; i++)
3449 order [new_order[i]] = i;
3451 item_array = g_new (GtkIconViewItem *, length);
3452 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3453 item_array[order[i]] = list->data;
3456 for (i = length - 1; i >= 0; i--)
3458 item_array[i]->index = i;
3459 items = g_list_prepend (items, item_array[i]);
3462 g_free (item_array);
3463 g_list_free (icon_view->priv->items);
3464 icon_view->priv->items = items;
3466 gtk_icon_view_queue_layout (icon_view);
3468 verify_items (icon_view);
3472 gtk_icon_view_build_items (GtkIconView *icon_view)
3476 gboolean iters_persist;
3477 GList *items = NULL;
3479 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3481 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3489 GtkIconViewItem *item = gtk_icon_view_item_new ();
3498 items = g_list_prepend (items, item);
3500 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3502 icon_view->priv->items = g_list_reverse (items);
3506 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3509 GtkMovementStep step,
3513 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3514 I_("move_cursor"), 2,
3518 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3523 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3526 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3531 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3538 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3539 GtkMovementStep step,
3542 GdkModifierType state;
3544 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3545 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3546 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3547 step == GTK_MOVEMENT_DISPLAY_LINES ||
3548 step == GTK_MOVEMENT_PAGES ||
3549 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3551 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3554 gtk_icon_view_stop_editing (icon_view, FALSE);
3555 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3557 if (gtk_get_current_event_state (&state))
3559 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3560 icon_view->priv->ctrl_pressed = TRUE;
3561 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3562 icon_view->priv->shift_pressed = TRUE;
3564 /* else we assume not pressed */
3568 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3569 case GTK_MOVEMENT_VISUAL_POSITIONS:
3570 gtk_icon_view_move_cursor_left_right (icon_view, count);
3572 case GTK_MOVEMENT_DISPLAY_LINES:
3573 gtk_icon_view_move_cursor_up_down (icon_view, count);
3575 case GTK_MOVEMENT_PAGES:
3576 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3578 case GTK_MOVEMENT_BUFFER_ENDS:
3579 gtk_icon_view_move_cursor_start_end (icon_view, count);
3582 g_assert_not_reached ();
3585 icon_view->priv->ctrl_pressed = FALSE;
3586 icon_view->priv->shift_pressed = FALSE;
3591 static GtkIconViewItem *
3592 find_item (GtkIconView *icon_view,
3593 GtkIconViewItem *current,
3599 GtkIconViewItem *item;
3601 /* FIXME: this could be more efficient
3603 row = current->row + row_ofs;
3604 col = current->col + col_ofs;
3606 for (items = icon_view->priv->items; items; items = items->next)
3609 if (item->row == row && item->col == col)
3617 find_cell (GtkIconView *icon_view,
3618 GtkIconViewItem *item,
3620 GtkOrientation orientation,
3631 if (icon_view->priv->orientation != orientation)
3634 gtk_icon_view_set_cell_data (icon_view, item);
3636 focusable = g_new0 (gint, icon_view->priv->n_cells);
3641 for (k = 0; k < 2; k++)
3642 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3644 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3646 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3649 if (!info->cell->visible)
3652 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3655 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3658 current = n_focusable;
3660 focusable[n_focusable] = i;
3666 if (n_focusable == 0)
3667 focusable[n_focusable++] = first_text;
3671 current = step > 0 ? 0 : n_focusable - 1;
3672 cell = focusable[current];
3675 if (current + *count < 0)
3678 *count = current + *count;
3680 else if (current + *count > n_focusable - 1)
3683 *count = current + *count - (n_focusable - 1);
3687 cell = focusable[current + *count];
3696 static GtkIconViewItem *
3697 find_item_page_up_down (GtkIconView *icon_view,
3698 GtkIconViewItem *current,
3705 y = current->y + count * icon_view->priv->vadjustment->page_size;
3707 item = g_list_find (icon_view->priv->items, current);
3712 for (next = item->next; next; next = next->next)
3714 if (((GtkIconViewItem *)next->data)->col == col)
3717 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3727 for (next = item->prev; next; next = next->prev)
3729 if (((GtkIconViewItem *)next->data)->col == col)
3732 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3746 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3747 GtkIconViewItem *anchor,
3748 GtkIconViewItem *cursor)
3751 GtkIconViewItem *item;
3752 gint row1, row2, col1, col2;
3753 gboolean dirty = FALSE;
3755 if (anchor->row < cursor->row)
3766 if (anchor->col < cursor->col)
3777 for (items = icon_view->priv->items; items; items = items->next)
3781 if (row1 <= item->row && item->row <= row2 &&
3782 col1 <= item->col && item->col <= col2)
3784 if (!item->selected)
3787 item->selected = TRUE;
3789 gtk_icon_view_queue_draw_item (icon_view, item);
3797 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3800 GtkIconViewItem *item;
3802 gboolean dirty = FALSE;
3805 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3808 if (!icon_view->priv->cursor_item)
3813 list = icon_view->priv->items;
3815 list = g_list_last (icon_view->priv->items);
3817 item = list ? list->data : NULL;
3822 item = icon_view->priv->cursor_item;
3823 cell = icon_view->priv->cursor_cell;
3824 step = count > 0 ? 1 : -1;
3827 cell = find_cell (icon_view, item, cell,
3828 GTK_ORIENTATION_VERTICAL,
3833 item = find_item (icon_view, item, step, 0);
3834 count = count - step;
3840 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3844 if (icon_view->priv->ctrl_pressed ||
3845 !icon_view->priv->shift_pressed ||
3846 !icon_view->priv->anchor_item ||
3847 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3848 icon_view->priv->anchor_item = item;
3850 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3852 if (!icon_view->priv->ctrl_pressed &&
3853 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3855 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3856 dirty = gtk_icon_view_select_all_between (icon_view,
3857 icon_view->priv->anchor_item,
3861 gtk_icon_view_scroll_to_item (icon_view, item);
3864 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3868 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3871 GtkIconViewItem *item;
3872 gboolean dirty = FALSE;
3874 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3877 if (!icon_view->priv->cursor_item)
3882 list = icon_view->priv->items;
3884 list = g_list_last (icon_view->priv->items);
3886 item = list ? list->data : NULL;
3889 item = find_item_page_up_down (icon_view,
3890 icon_view->priv->cursor_item,
3893 if (item == icon_view->priv->cursor_item)
3894 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3899 if (icon_view->priv->ctrl_pressed ||
3900 !icon_view->priv->shift_pressed ||
3901 !icon_view->priv->anchor_item ||
3902 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3903 icon_view->priv->anchor_item = item;
3905 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3907 if (!icon_view->priv->ctrl_pressed &&
3908 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3910 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3911 dirty = gtk_icon_view_select_all_between (icon_view,
3912 icon_view->priv->anchor_item,
3916 gtk_icon_view_scroll_to_item (icon_view, item);
3919 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3923 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3926 GtkIconViewItem *item;
3928 gboolean dirty = FALSE;
3931 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3934 if (!icon_view->priv->cursor_item)
3939 list = icon_view->priv->items;
3941 list = g_list_last (icon_view->priv->items);
3943 item = list ? list->data : NULL;
3947 item = icon_view->priv->cursor_item;
3948 cell = icon_view->priv->cursor_cell;
3949 step = count > 0 ? 1 : -1;
3952 cell = find_cell (icon_view, item, cell,
3953 GTK_ORIENTATION_HORIZONTAL,
3958 item = find_item (icon_view, item, 0, step);
3959 count = count - step;
3965 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3969 if (icon_view->priv->ctrl_pressed ||
3970 !icon_view->priv->shift_pressed ||
3971 !icon_view->priv->anchor_item ||
3972 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3973 icon_view->priv->anchor_item = item;
3975 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3977 if (!icon_view->priv->ctrl_pressed &&
3978 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3980 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3981 dirty = gtk_icon_view_select_all_between (icon_view,
3982 icon_view->priv->anchor_item,
3986 gtk_icon_view_scroll_to_item (icon_view, item);
3989 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3993 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3996 GtkIconViewItem *item;
3998 gboolean dirty = FALSE;
4000 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4004 list = icon_view->priv->items;
4006 list = g_list_last (icon_view->priv->items);
4008 item = list ? list->data : NULL;
4010 if (item == icon_view->priv->cursor_item)
4011 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4016 if (icon_view->priv->ctrl_pressed ||
4017 !icon_view->priv->shift_pressed ||
4018 !icon_view->priv->anchor_item ||
4019 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4020 icon_view->priv->anchor_item = item;
4022 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4024 if (!icon_view->priv->ctrl_pressed &&
4025 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4027 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4028 dirty = gtk_icon_view_select_all_between (icon_view,
4029 icon_view->priv->anchor_item,
4033 gtk_icon_view_scroll_to_item (icon_view, item);
4036 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4040 * gtk_icon_view_scroll_to_path:
4041 * @icon_view: A #GtkIconView.
4042 * @path: The path of the item to move to.
4043 * @use_align: whether to use alignment arguments, or %FALSE.
4044 * @row_align: The vertical alignment of the item specified by @path.
4045 * @col_align: The horizontal alignment of the item specified by @path.
4047 * Moves the alignments of @icon_view to the position specified by @path.
4048 * @row_align determines where the row is placed, and @col_align determines
4049 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4050 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4053 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4054 * tree does the minimum amount of work to scroll the item onto the screen.
4055 * This means that the item will be scrolled to the edge closest to its current
4056 * position. If the item is currently visible on the screen, nothing is done.
4058 * This function only works if the model is set, and @path is a valid row on
4059 * the model. If the model changes before the @icon_view is realized, the
4060 * centered path will be modified to reflect this change.
4065 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4071 GtkIconViewItem *item = NULL;
4073 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4074 g_return_if_fail (path != NULL);
4075 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4076 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4078 if (gtk_tree_path_get_depth (path) > 0)
4079 item = g_list_nth_data (icon_view->priv->items,
4080 gtk_tree_path_get_indices(path)[0]);
4082 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4084 if (icon_view->priv->scroll_to_path)
4085 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4087 icon_view->priv->scroll_to_path = NULL;
4090 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4092 icon_view->priv->scroll_to_use_align = use_align;
4093 icon_view->priv->scroll_to_row_align = row_align;
4094 icon_view->priv->scroll_to_col_align = col_align;
4103 gfloat offset, value;
4105 gtk_widget_style_get (GTK_WIDGET (icon_view),
4106 "focus-line-width", &focus_width,
4109 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4111 offset = y + item->y - focus_width -
4112 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4113 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4114 icon_view->priv->vadjustment->lower,
4115 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4116 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4118 offset = x + item->x - focus_width -
4119 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4120 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4121 icon_view->priv->hadjustment->lower,
4122 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4123 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4125 gtk_adjustment_changed (icon_view->priv->hadjustment);
4126 gtk_adjustment_changed (icon_view->priv->vadjustment);
4129 gtk_icon_view_scroll_to_item (icon_view, item);
4134 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4135 GtkIconViewItem *item)
4137 gint x, y, width, height;
4140 gtk_widget_style_get (GTK_WIDGET (icon_view),
4141 "focus-line-width", &focus_width,
4144 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4146 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4148 if (y + item->y - focus_width < 0)
4149 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4150 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4151 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4152 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4153 icon_view->priv->vadjustment->value + y + item->y + item->height
4154 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4156 if (x + item->x - focus_width < 0)
4157 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4158 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4159 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4160 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4161 icon_view->priv->hadjustment->value + x + item->x + item->width
4162 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4164 gtk_adjustment_changed (icon_view->priv->hadjustment);
4165 gtk_adjustment_changed (icon_view->priv->vadjustment);
4168 /* GtkCellLayout implementation */
4169 static GtkIconViewCellInfo *
4170 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4171 GtkCellRenderer *renderer)
4175 for (i = icon_view->priv->cell_list; i; i = i->next)
4177 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4179 if (info->cell == renderer)
4187 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4188 GtkIconViewItem *item)
4191 gboolean iters_persist;
4194 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4200 path = gtk_tree_path_new_from_indices (item->index, -1);
4201 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4203 gtk_tree_path_free (path);
4208 for (i = icon_view->priv->cell_list; i; i = i->next)
4211 GtkIconViewCellInfo *info = i->data;
4213 g_object_freeze_notify (G_OBJECT (info->cell));
4215 for (j = info->attributes; j && j->next; j = j->next->next)
4217 gchar *property = j->data;
4218 gint column = GPOINTER_TO_INT (j->next->data);
4219 GValue value = {0, };
4221 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4223 g_object_set_property (G_OBJECT (info->cell),
4225 g_value_unset (&value);
4229 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4231 icon_view->priv->model,
4235 g_object_thaw_notify (G_OBJECT (info->cell));
4238 adjust_wrap_width (icon_view, item);
4242 free_cell_attributes (GtkIconViewCellInfo *info)
4246 list = info->attributes;
4247 while (list && list->next)
4249 g_free (list->data);
4250 list = list->next->next;
4253 g_slist_free (info->attributes);
4254 info->attributes = NULL;
4258 free_cell_info (GtkIconViewCellInfo *info)
4260 free_cell_attributes (info);
4262 g_object_unref (info->cell);
4265 (* info->destroy) (info->func_data);
4271 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4272 GtkCellRenderer *renderer,
4275 GtkIconViewCellInfo *info;
4276 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4278 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4279 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4281 g_object_ref_sink (renderer);
4283 info = g_new0 (GtkIconViewCellInfo, 1);
4284 info->cell = renderer;
4285 info->expand = expand ? TRUE : FALSE;
4286 info->pack = GTK_PACK_START;
4287 info->position = icon_view->priv->n_cells;
4289 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4290 icon_view->priv->n_cells++;
4294 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4295 GtkCellRenderer *renderer,
4298 GtkIconViewCellInfo *info;
4299 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4301 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4302 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4304 g_object_ref_sink (renderer);
4306 info = g_new0 (GtkIconViewCellInfo, 1);
4307 info->cell = renderer;
4308 info->expand = expand ? TRUE : FALSE;
4309 info->pack = GTK_PACK_END;
4310 info->position = icon_view->priv->n_cells;
4312 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4313 icon_view->priv->n_cells++;
4317 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4318 GtkCellRenderer *renderer,
4319 const gchar *attribute,
4322 GtkIconViewCellInfo *info;
4323 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4325 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4326 g_return_if_fail (info != NULL);
4328 info->attributes = g_slist_prepend (info->attributes,
4329 GINT_TO_POINTER (column));
4330 info->attributes = g_slist_prepend (info->attributes,
4331 g_strdup (attribute));
4335 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4337 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4339 while (icon_view->priv->cell_list)
4341 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4342 free_cell_info (info);
4343 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4344 icon_view->priv->cell_list);
4347 icon_view->priv->n_cells = 0;
4351 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4352 GtkCellRenderer *cell,
4353 GtkCellLayoutDataFunc func,
4355 GDestroyNotify destroy)
4357 GtkIconViewCellInfo *info;
4358 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4360 info = gtk_icon_view_get_cell_info (icon_view, cell);
4361 g_return_if_fail (info != NULL);
4365 GDestroyNotify d = info->destroy;
4367 info->destroy = NULL;
4368 d (info->func_data);
4372 info->func_data = func_data;
4373 info->destroy = destroy;
4377 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4378 GtkCellRenderer *renderer)
4380 GtkIconViewCellInfo *info;
4382 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4384 free_cell_attributes (info);
4388 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4389 GtkCellRenderer *cell,
4392 GtkIconView *icon_view;
4394 GtkIconViewCellInfo *info;
4397 icon_view = GTK_ICON_VIEW (layout);
4399 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4401 info = gtk_icon_view_get_cell_info (icon_view, cell);
4403 g_return_if_fail (info != NULL);
4404 g_return_if_fail (position >= 0);
4406 link = g_list_find (icon_view->priv->cell_list, info);
4408 g_return_if_fail (link != NULL);
4410 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4412 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4415 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4422 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4426 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4428 GtkIconView *icon_view = (GtkIconView *)layout;
4429 GList *retval = NULL, *l;
4431 for (l = icon_view->priv->cell_list; l; l = l->next)
4433 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4435 retval = g_list_prepend (retval, info->cell);
4438 return g_list_reverse (retval);
4445 * gtk_icon_view_new:
4447 * Creates a new #GtkIconView widget
4449 * Return value: A newly created #GtkIconView widget
4454 gtk_icon_view_new (void)
4456 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4460 * gtk_icon_view_new_with_model:
4461 * @model: The model.
4463 * Creates a new #GtkIconView widget with the model @model.
4465 * Return value: A newly created #GtkIconView widget.
4470 gtk_icon_view_new_with_model (GtkTreeModel *model)
4472 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4477 * gtk_icon_view_get_path_at_pos:
4478 * @icon_view: A #GtkIconView.
4479 * @x: The x position to be identified
4480 * @y: The y position to be identified
4482 * Finds the path at the point (@x, @y), relative to widget coordinates.
4483 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4484 * the cell at the specified position.
4486 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4487 * if no icon exists at that position.
4492 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4496 GtkIconViewItem *item;
4499 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4501 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4506 path = gtk_tree_path_new_from_indices (item->index, -1);
4512 * gtk_icon_view_get_item_at_pos:
4513 * @icon_view: A #GtkIconView.
4514 * @x: The x position to be identified
4515 * @y: The y position to be identified
4516 * @path: Return location for the path, or %NULL
4517 * @cell: Return location for the renderer responsible for the cell
4518 * at (@x, @y), or %NULL
4520 * Finds the path at the point (@x, @y), relative to widget coordinates.
4521 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4522 * obtains the cell at the specified position. The returned path should
4523 * be freed with gtk_tree_path_free().
4525 * Return value: %TRUE if an item exists at the specified position
4530 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4534 GtkCellRenderer **cell)
4536 GtkIconViewItem *item;
4537 GtkIconViewCellInfo *info;
4539 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4541 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4546 *path = gtk_tree_path_new_from_indices (item->index, -1);
4559 return (item != NULL);
4564 * gtk_icon_view_get_visible_range:
4565 * @icon_view: A #GtkIconView
4566 * @start_path: Return location for start of region, or %NULL
4567 * @end_path: Return location for end of region, or %NULL
4569 * Sets @start_path and @end_path to be the first and last visible path.
4570 * Note that there may be invisible paths in between.
4572 * Both paths should be freed with gtk_tree_path_free() after use.
4574 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4579 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4580 GtkTreePath **start_path,
4581 GtkTreePath **end_path)
4583 gint start_index = -1;
4584 gint end_index = -1;
4587 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4589 if (icon_view->priv->hadjustment == NULL ||
4590 icon_view->priv->vadjustment == NULL)
4593 if (start_path == NULL && end_path == NULL)
4596 for (icons = icon_view->priv->items; icons; icons = icons->next)
4598 GtkIconViewItem *item = icons->data;
4600 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4601 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4602 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4603 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4605 if (start_index == -1)
4606 start_index = item->index;
4607 end_index = item->index;
4611 if (start_path && start_index != -1)
4612 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4613 if (end_path && end_index != -1)
4614 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4616 return start_index != -1;
4620 * gtk_icon_view_selected_foreach:
4621 * @icon_view: A #GtkIconView.
4622 * @func: The funcion to call for each selected icon.
4623 * @data: User data to pass to the function.
4625 * Calls a function for each selected icon. Note that the model or
4626 * selection cannot be modified from within this function.
4631 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4632 GtkIconViewForeachFunc func,
4637 for (list = icon_view->priv->items; list; list = list->next)
4639 GtkIconViewItem *item = list->data;
4640 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4643 (* func) (icon_view, path, data);
4645 gtk_tree_path_free (path);
4650 * gtk_icon_view_set_selection_mode:
4651 * @icon_view: A #GtkIconView.
4652 * @mode: The selection mode
4654 * Sets the selection mode of the @icon_view.
4659 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4660 GtkSelectionMode mode)
4662 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4664 if (mode == icon_view->priv->selection_mode)
4667 if (mode == GTK_SELECTION_NONE ||
4668 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4669 gtk_icon_view_unselect_all (icon_view);
4671 icon_view->priv->selection_mode = mode;
4673 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4677 * gtk_icon_view_get_selection_mode:
4678 * @icon_view: A #GtkIconView.
4680 * Gets the selection mode of the @icon_view.
4682 * Return value: the current selection mode
4687 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4689 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4691 return icon_view->priv->selection_mode;
4695 * gtk_icon_view_set_model:
4696 * @icon_view: A #GtkIconView.
4697 * @model: The model.
4699 * Sets the model for a #GtkIconView.
4700 * If the @icon_view already has a model set, it will remove
4701 * it before setting the new model. If @model is %NULL, then
4702 * it will unset the old model.
4707 gtk_icon_view_set_model (GtkIconView *icon_view,
4708 GtkTreeModel *model)
4710 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4711 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4713 if (icon_view->priv->model == model)
4716 if (icon_view->priv->scroll_to_path)
4718 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4719 icon_view->priv->scroll_to_path = NULL;
4722 gtk_icon_view_stop_editing (icon_view, TRUE);
4728 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4730 if (icon_view->priv->pixbuf_column != -1)
4732 column_type = gtk_tree_model_get_column_type (model,
4733 icon_view->priv->pixbuf_column);
4735 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4738 if (icon_view->priv->text_column != -1)
4740 column_type = gtk_tree_model_get_column_type (model,
4741 icon_view->priv->text_column);
4743 g_return_if_fail (column_type == G_TYPE_STRING);
4746 if (icon_view->priv->markup_column != -1)
4748 column_type = gtk_tree_model_get_column_type (model,
4749 icon_view->priv->markup_column);
4751 g_return_if_fail (column_type == G_TYPE_STRING);
4756 if (icon_view->priv->model)
4758 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4759 gtk_icon_view_row_changed,
4761 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4762 gtk_icon_view_row_inserted,
4764 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4765 gtk_icon_view_row_deleted,
4767 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4768 gtk_icon_view_rows_reordered,
4771 g_object_unref (icon_view->priv->model);
4773 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4774 g_list_free (icon_view->priv->items);
4775 icon_view->priv->items = NULL;
4776 icon_view->priv->anchor_item = NULL;
4777 icon_view->priv->cursor_item = NULL;
4778 icon_view->priv->last_single_clicked = NULL;
4779 icon_view->priv->width = 0;
4780 icon_view->priv->height = 0;
4783 icon_view->priv->model = model;
4785 if (icon_view->priv->model)
4787 g_object_ref (icon_view->priv->model);
4788 g_signal_connect (icon_view->priv->model,
4790 G_CALLBACK (gtk_icon_view_row_changed),
4792 g_signal_connect (icon_view->priv->model,
4794 G_CALLBACK (gtk_icon_view_row_inserted),
4796 g_signal_connect (icon_view->priv->model,
4798 G_CALLBACK (gtk_icon_view_row_deleted),
4800 g_signal_connect (icon_view->priv->model,
4802 G_CALLBACK (gtk_icon_view_rows_reordered),
4805 gtk_icon_view_build_items (icon_view);
4807 gtk_icon_view_queue_layout (icon_view);
4810 g_object_notify (G_OBJECT (icon_view), "model");
4812 if (GTK_WIDGET_REALIZED (icon_view))
4813 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4817 * gtk_icon_view_get_model:
4818 * @icon_view: a #GtkIconView
4820 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4823 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4828 gtk_icon_view_get_model (GtkIconView *icon_view)
4830 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4832 return icon_view->priv->model;
4836 update_text_cell (GtkIconView *icon_view)
4838 GtkIconViewCellInfo *info;
4842 if (icon_view->priv->text_column == -1 &&
4843 icon_view->priv->markup_column == -1)
4845 if (icon_view->priv->text_cell != -1)
4847 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4848 icon_view->priv->pixbuf_cell--;
4850 info = g_list_nth_data (icon_view->priv->cell_list,
4851 icon_view->priv->text_cell);
4853 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4855 free_cell_info (info);
4857 icon_view->priv->n_cells--;
4858 icon_view->priv->text_cell = -1;
4863 if (icon_view->priv->text_cell == -1)
4865 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4866 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4867 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4870 if (info->cell == cell)
4872 icon_view->priv->text_cell = i;
4878 info = g_list_nth_data (icon_view->priv->cell_list,
4879 icon_view->priv->text_cell);
4881 if (icon_view->priv->markup_column != -1)
4882 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4884 "markup", icon_view->priv->markup_column,
4887 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4889 "text", icon_view->priv->text_column,
4892 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4893 g_object_set (info->cell,
4894 "alignment", PANGO_ALIGN_CENTER,
4895 "wrap-mode", PANGO_WRAP_WORD,
4896 "wrap-width", icon_view->priv->item_width,
4901 g_object_set (info->cell,
4902 "alignment", PANGO_ALIGN_LEFT,
4903 "wrap-mode", PANGO_WRAP_WORD,
4904 "wrap-width", icon_view->priv->item_width,
4912 update_pixbuf_cell (GtkIconView *icon_view)
4914 GtkIconViewCellInfo *info;
4918 if (icon_view->priv->pixbuf_column == -1)
4920 if (icon_view->priv->pixbuf_cell != -1)
4922 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4923 icon_view->priv->text_cell--;
4925 info = g_list_nth_data (icon_view->priv->cell_list,
4926 icon_view->priv->pixbuf_cell);
4928 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4930 free_cell_info (info);
4932 icon_view->priv->n_cells--;
4933 icon_view->priv->pixbuf_cell = -1;
4938 if (icon_view->priv->pixbuf_cell == -1)
4940 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4942 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4943 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4946 if (info->cell == cell)
4948 icon_view->priv->pixbuf_cell = i;
4954 info = g_list_nth_data (icon_view->priv->cell_list,
4955 icon_view->priv->pixbuf_cell);
4957 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4959 "pixbuf", icon_view->priv->pixbuf_column,
4962 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4963 g_object_set (info->cell,
4964 "follow-state", TRUE,
4969 g_object_set (info->cell,
4970 "follow-state", TRUE,
4978 * gtk_icon_view_set_text_column:
4979 * @icon_view: A #GtkIconView.
4980 * @column: A column in the currently used model, or -1 to display no text
4982 * Sets the column with text for @icon_view to be @column. The text
4983 * column must be of type #G_TYPE_STRING.
4988 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4991 if (column == icon_view->priv->text_column)
4995 icon_view->priv->text_column = -1;
4998 if (icon_view->priv->model != NULL)
5002 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5004 g_return_if_fail (column_type == G_TYPE_STRING);
5007 icon_view->priv->text_column = column;
5010 gtk_icon_view_stop_editing (icon_view, TRUE);
5012 update_text_cell (icon_view);
5014 gtk_icon_view_invalidate_sizes (icon_view);
5015 gtk_icon_view_queue_layout (icon_view);
5017 g_object_notify (G_OBJECT (icon_view), "text-column");
5021 * gtk_icon_view_get_text_column:
5022 * @icon_view: A #GtkIconView.
5024 * Returns the column with text for @icon_view.
5026 * Returns: the text column, or -1 if it's unset.
5031 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5033 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5035 return icon_view->priv->text_column;
5039 * gtk_icon_view_set_markup_column:
5040 * @icon_view: A #GtkIconView.
5041 * @column: A column in the currently used model, or -1 to display no text
5043 * Sets the column with markup information for @icon_view to be
5044 * @column. The markup column must be of type #G_TYPE_STRING.
5045 * If the markup column is set to something, it overrides
5046 * the text column set by gtk_icon_view_set_text_column().
5051 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5054 if (column == icon_view->priv->markup_column)
5058 icon_view->priv->markup_column = -1;
5061 if (icon_view->priv->model != NULL)
5065 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5067 g_return_if_fail (column_type == G_TYPE_STRING);
5070 icon_view->priv->markup_column = column;
5073 gtk_icon_view_stop_editing (icon_view, TRUE);
5075 update_text_cell (icon_view);
5077 gtk_icon_view_invalidate_sizes (icon_view);
5078 gtk_icon_view_queue_layout (icon_view);
5080 g_object_notify (G_OBJECT (icon_view), "markup-column");
5084 * gtk_icon_view_get_markup_column:
5085 * @icon_view: A #GtkIconView.
5087 * Returns the column with markup text for @icon_view.
5089 * Returns: the markup column, or -1 if it's unset.
5094 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5096 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5098 return icon_view->priv->markup_column;
5102 * gtk_icon_view_set_pixbuf_column:
5103 * @icon_view: A #GtkIconView.
5104 * @column: A column in the currently used model, or -1 to disable
5106 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5107 * column must be of type #GDK_TYPE_PIXBUF
5112 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5115 if (column == icon_view->priv->pixbuf_column)
5119 icon_view->priv->pixbuf_column = -1;
5122 if (icon_view->priv->model != NULL)
5126 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5128 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5131 icon_view->priv->pixbuf_column = column;
5134 gtk_icon_view_stop_editing (icon_view, TRUE);
5136 update_pixbuf_cell (icon_view);
5138 gtk_icon_view_invalidate_sizes (icon_view);
5139 gtk_icon_view_queue_layout (icon_view);
5141 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5146 * gtk_icon_view_get_pixbuf_column:
5147 * @icon_view: A #GtkIconView.
5149 * Returns the column with pixbufs for @icon_view.
5151 * Returns: the pixbuf column, or -1 if it's unset.
5156 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5158 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5160 return icon_view->priv->pixbuf_column;
5164 * gtk_icon_view_select_path:
5165 * @icon_view: A #GtkIconView.
5166 * @path: The #GtkTreePath to be selected.
5168 * Selects the row at @path.
5173 gtk_icon_view_select_path (GtkIconView *icon_view,
5176 GtkIconViewItem *item = NULL;
5178 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5179 g_return_if_fail (icon_view->priv->model != NULL);
5180 g_return_if_fail (path != NULL);
5182 if (gtk_tree_path_get_depth (path) > 0)
5183 item = g_list_nth_data (icon_view->priv->items,
5184 gtk_tree_path_get_indices(path)[0]);
5187 gtk_icon_view_select_item (icon_view, item);
5191 * gtk_icon_view_unselect_path:
5192 * @icon_view: A #GtkIconView.
5193 * @path: The #GtkTreePath to be unselected.
5195 * Unselects the row at @path.
5200 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5203 GtkIconViewItem *item;
5205 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5206 g_return_if_fail (icon_view->priv->model != NULL);
5207 g_return_if_fail (path != NULL);
5209 item = g_list_nth_data (icon_view->priv->items,
5210 gtk_tree_path_get_indices(path)[0]);
5215 gtk_icon_view_unselect_item (icon_view, item);
5219 * gtk_icon_view_get_selected_items:
5220 * @icon_view: A #GtkIconView.
5222 * Creates a list of paths of all selected items. Additionally, if you are
5223 * planning on modifying the model after calling this function, you may
5224 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5225 * To do this, you can use gtk_tree_row_reference_new().
5227 * To free the return value, use:
5228 * <informalexample><programlisting>
5229 * g_list_foreach (list, gtk_tree_path_free, NULL);
5230 * g_list_free (list);
5231 * </programlisting></informalexample>
5233 * Return value: A #GList containing a #GtkTreePath for each selected row.
5238 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5241 GList *selected = NULL;
5243 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5245 for (list = icon_view->priv->items; list != NULL; list = list->next)
5247 GtkIconViewItem *item = list->data;
5251 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5253 selected = g_list_prepend (selected, path);
5261 * gtk_icon_view_select_all:
5262 * @icon_view: A #GtkIconView.
5264 * Selects all the icons. @icon_view must has its selection mode set
5265 * to #GTK_SELECTION_MULTIPLE.
5270 gtk_icon_view_select_all (GtkIconView *icon_view)
5273 gboolean dirty = FALSE;
5275 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5277 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5280 for (items = icon_view->priv->items; items; items = items->next)
5282 GtkIconViewItem *item = items->data;
5284 if (!item->selected)
5287 item->selected = TRUE;
5288 gtk_icon_view_queue_draw_item (icon_view, item);
5293 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5297 * gtk_icon_view_unselect_all:
5298 * @icon_view: A #GtkIconView.
5300 * Unselects all the icons.
5305 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5307 gboolean dirty = FALSE;
5309 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5311 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5314 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5317 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5321 * gtk_icon_view_path_is_selected:
5322 * @icon_view: A #GtkIconView.
5323 * @path: A #GtkTreePath to check selection on.
5325 * Returns %TRUE if the icon pointed to by @path is currently
5326 * selected. If @path does not point to a valid location, %FALSE is returned.
5328 * Return value: %TRUE if @path is selected.
5333 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5336 GtkIconViewItem *item;
5338 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5339 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5340 g_return_val_if_fail (path != NULL, FALSE);
5342 item = g_list_nth_data (icon_view->priv->items,
5343 gtk_tree_path_get_indices(path)[0]);
5348 return item->selected;
5352 * gtk_icon_view_item_activated:
5353 * @icon_view: A #GtkIconView
5354 * @path: The #GtkTreePath to be activated
5356 * Activates the item determined by @path.
5361 gtk_icon_view_item_activated (GtkIconView *icon_view,
5364 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5365 g_return_if_fail (path != NULL);
5367 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5371 * gtk_icon_view_set_orientation:
5372 * @icon_view: a #GtkIconView
5373 * @orientation: the relative position of texts and icons
5375 * Sets the ::orientation property which determines whether the labels
5376 * are drawn beside the icons instead of below.
5381 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5382 GtkOrientation orientation)
5384 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5386 if (icon_view->priv->orientation != orientation)
5388 icon_view->priv->orientation = orientation;
5390 gtk_icon_view_stop_editing (icon_view, TRUE);
5391 gtk_icon_view_invalidate_sizes (icon_view);
5392 gtk_icon_view_queue_layout (icon_view);
5394 update_text_cell (icon_view);
5395 update_pixbuf_cell (icon_view);
5397 g_object_notify (G_OBJECT (icon_view), "orientation");
5402 * gtk_icon_view_get_orientation:
5403 * @icon_view: a #GtkIconView
5405 * Returns the value of the ::orientation property which determines
5406 * whether the labels are drawn beside the icons instead of below.
5408 * Return value: the relative position of texts and icons
5413 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5415 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5416 GTK_ORIENTATION_VERTICAL);
5418 return icon_view->priv->orientation;
5422 * gtk_icon_view_set_columns:
5423 * @icon_view: a #GtkIconView
5424 * @columns: the number of columns
5426 * Sets the ::columns property which determines in how
5427 * many columns the icons are arranged. If @columns is
5428 * -1, the number of columns will be chosen automatically
5429 * to fill the available area.
5434 gtk_icon_view_set_columns (GtkIconView *icon_view,
5437 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5439 if (icon_view->priv->columns != columns)
5441 icon_view->priv->columns = columns;
5443 gtk_icon_view_stop_editing (icon_view, TRUE);
5444 gtk_icon_view_queue_layout (icon_view);
5446 g_object_notify (G_OBJECT (icon_view), "columns");
5451 * gtk_icon_view_get_columns:
5452 * @icon_view: a #GtkIconView
5454 * Returns the value of the ::columns property.
5456 * Return value: the number of columns, or -1
5461 gtk_icon_view_get_columns (GtkIconView *icon_view)
5463 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5465 return icon_view->priv->columns;
5469 * gtk_icon_view_set_item_width:
5470 * @icon_view: a #GtkIconView
5471 * @item_width: the width for each item
5473 * Sets the ::item-width property which specifies the width
5474 * to use for each item. If it is set to -1, the icon view will
5475 * automatically determine a suitable item size.
5480 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5483 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5485 if (icon_view->priv->item_width != item_width)
5487 icon_view->priv->item_width = item_width;
5489 gtk_icon_view_stop_editing (icon_view, TRUE);
5490 gtk_icon_view_invalidate_sizes (icon_view);
5491 gtk_icon_view_queue_layout (icon_view);
5493 update_text_cell (icon_view);
5495 g_object_notify (G_OBJECT (icon_view), "item-width");
5500 * gtk_icon_view_get_item_width:
5501 * @icon_view: a #GtkIconView
5503 * Returns the value of the ::item-width property.
5505 * Return value: the width of a single item, or -1
5510 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5512 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5514 return icon_view->priv->item_width;
5519 * gtk_icon_view_set_spacing:
5520 * @icon_view: a #GtkIconView
5521 * @spacing: the spacing
5523 * Sets the ::spacing property which specifies the space
5524 * which is inserted between the cells (i.e. the icon and
5525 * the text) of an item.
5530 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5533 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5535 if (icon_view->priv->spacing != spacing)
5537 icon_view->priv->spacing = spacing;
5539 gtk_icon_view_stop_editing (icon_view, TRUE);
5540 gtk_icon_view_invalidate_sizes (icon_view);
5541 gtk_icon_view_queue_layout (icon_view);
5543 g_object_notify (G_OBJECT (icon_view), "spacing");
5548 * gtk_icon_view_get_spacing:
5549 * @icon_view: a #GtkIconView
5551 * Returns the value of the ::spacing property.
5553 * Return value: the space between cells
5558 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5560 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5562 return icon_view->priv->spacing;
5566 * gtk_icon_view_set_row_spacing:
5567 * @icon_view: a #GtkIconView
5568 * @row_spacing: the row spacing
5570 * Sets the ::row-spacing property which specifies the space
5571 * which is inserted between the rows of the icon view.
5576 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5579 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5581 if (icon_view->priv->row_spacing != row_spacing)
5583 icon_view->priv->row_spacing = row_spacing;
5585 gtk_icon_view_stop_editing (icon_view, TRUE);
5586 gtk_icon_view_invalidate_sizes (icon_view);
5587 gtk_icon_view_queue_layout (icon_view);
5589 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5594 * gtk_icon_view_get_row_spacing:
5595 * @icon_view: a #GtkIconView
5597 * Returns the value of the ::row-spacing property.
5599 * Return value: the space between rows
5604 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5606 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5608 return icon_view->priv->row_spacing;
5612 * gtk_icon_view_set_column_spacing:
5613 * @icon_view: a #GtkIconView
5614 * @column_spacing: the column spacing
5616 * Sets the ::column-spacing property which specifies the space
5617 * which is inserted between the columns of the icon view.
5622 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5623 gint column_spacing)
5625 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5627 if (icon_view->priv->column_spacing != column_spacing)
5629 icon_view->priv->column_spacing = column_spacing;
5631 gtk_icon_view_stop_editing (icon_view, TRUE);
5632 gtk_icon_view_invalidate_sizes (icon_view);
5633 gtk_icon_view_queue_layout (icon_view);
5635 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5640 * gtk_icon_view_get_column_spacing:
5641 * @icon_view: a #GtkIconView
5643 * Returns the value of the ::column-spacing property.
5645 * Return value: the space between columns
5650 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5652 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5654 return icon_view->priv->column_spacing;
5658 * gtk_icon_view_set_margin:
5659 * @icon_view: a #GtkIconView
5660 * @margin: the margin
5662 * Sets the ::margin property which specifies the space
5663 * which is inserted at the top, bottom, left and right
5669 gtk_icon_view_set_margin (GtkIconView *icon_view,
5672 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5674 if (icon_view->priv->margin != margin)
5676 icon_view->priv->margin = margin;
5678 gtk_icon_view_stop_editing (icon_view, TRUE);
5679 gtk_icon_view_invalidate_sizes (icon_view);
5680 gtk_icon_view_queue_layout (icon_view);
5682 g_object_notify (G_OBJECT (icon_view), "margin");
5687 * gtk_icon_view_get_margin:
5688 * @icon_view: a #GtkIconView
5690 * Returns the value of the ::margin property.
5692 * Return value: the space at the borders
5697 gtk_icon_view_get_margin (GtkIconView *icon_view)
5699 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5701 return icon_view->priv->margin;
5705 /* Get/set whether drag_motion requested the drag data and
5706 * drag_data_received should thus not actually insert the data,
5707 * since the data doesn't result from a drop.
5710 set_status_pending (GdkDragContext *context,
5711 GdkDragAction suggested_action)
5713 g_object_set_data (G_OBJECT (context),
5714 I_("gtk-icon-view-status-pending"),
5715 GINT_TO_POINTER (suggested_action));
5718 static GdkDragAction
5719 get_status_pending (GdkDragContext *context)
5721 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5722 "gtk-icon-view-status-pending"));
5726 unset_reorderable (GtkIconView *icon_view)
5728 if (icon_view->priv->reorderable)
5730 icon_view->priv->reorderable = FALSE;
5731 g_object_notify (G_OBJECT (icon_view), "reorderable");
5736 clear_source_info (GtkIconView *icon_view)
5738 if (icon_view->priv->source_targets)
5739 gtk_target_list_unref (icon_view->priv->source_targets);
5740 icon_view->priv->source_targets = NULL;
5742 icon_view->priv->source_set = FALSE;
5746 clear_dest_info (GtkIconView *icon_view)
5748 if (icon_view->priv->dest_targets)
5749 gtk_target_list_unref (icon_view->priv->dest_targets);
5750 icon_view->priv->dest_targets = NULL;
5752 icon_view->priv->dest_set = FALSE;
5756 set_source_row (GdkDragContext *context,
5757 GtkTreeModel *model,
5758 GtkTreePath *source_row)
5761 g_object_set_data_full (G_OBJECT (context),
5762 I_("gtk-icon-view-source-row"),
5763 gtk_tree_row_reference_new (model, source_row),
5764 (GDestroyNotify) gtk_tree_row_reference_free);
5766 g_object_set_data_full (G_OBJECT (context),
5767 I_("gtk-icon-view-source-row"),
5772 get_source_row (GdkDragContext *context)
5774 GtkTreeRowReference *ref;
5776 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5779 return gtk_tree_row_reference_get_path (ref);
5786 GtkTreeRowReference *dest_row;
5787 gboolean empty_view_drop;
5788 gboolean drop_append_mode;
5792 dest_row_free (gpointer data)
5794 DestRow *dr = (DestRow *)data;
5796 gtk_tree_row_reference_free (dr->dest_row);
5801 set_dest_row (GdkDragContext *context,
5802 GtkTreeModel *model,
5803 GtkTreePath *dest_row,
5804 gboolean empty_view_drop,
5805 gboolean drop_append_mode)
5811 g_object_set_data_full (G_OBJECT (context),
5812 I_("gtk-icon-view-dest-row"),
5817 dr = g_new0 (DestRow, 1);
5819 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5820 dr->empty_view_drop = empty_view_drop;
5821 dr->drop_append_mode = drop_append_mode;
5822 g_object_set_data_full (G_OBJECT (context),
5823 I_("gtk-icon-view-dest-row"),
5824 dr, (GDestroyNotify) dest_row_free);
5828 get_dest_row (GdkDragContext *context)
5832 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5836 GtkTreePath *path = NULL;
5839 path = gtk_tree_row_reference_get_path (dr->dest_row);
5840 else if (dr->empty_view_drop)
5841 path = gtk_tree_path_new_from_indices (0, -1);
5845 if (path && dr->drop_append_mode)
5846 gtk_tree_path_next (path);
5855 check_model_dnd (GtkTreeModel *model,
5856 GType required_iface,
5857 const gchar *signal)
5859 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5861 g_warning ("You must override the default '%s' handler "
5862 "on GtkIconView when using models that don't support "
5863 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5864 "is to connect to '%s' and call "
5865 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5866 "the default handler from running. Look at the source code "
5867 "for the default handler in gtkiconview.c to get an idea what "
5868 "your handler should do. (gtkiconview.c is in the GTK+ source "
5869 "code.) If you're using GTK+ from a language other than C, "
5870 "there may be a more natural way to override default handlers, e.g. via derivation.",
5871 signal, g_type_name (required_iface), signal);
5879 remove_scroll_timeout (GtkIconView *icon_view)
5881 if (icon_view->priv->scroll_timeout_id != 0)
5883 g_source_remove (icon_view->priv->scroll_timeout_id);
5885 icon_view->priv->scroll_timeout_id = 0;
5890 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5892 gint px, py, x, y, width, height;
5893 gint hoffset, voffset;
5896 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5897 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5899 /* see if we are near the edge. */
5900 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5902 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5904 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5906 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5910 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5911 icon_view->priv->vadjustment->lower,
5912 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5913 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5917 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5918 icon_view->priv->hadjustment->lower,
5919 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5920 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5926 drag_scroll_timeout (gpointer data)
5928 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5930 gtk_icon_view_autoscroll (icon_view);
5937 set_destination (GtkIconView *icon_view,
5938 GdkDragContext *context,
5941 GdkDragAction *suggested_action,
5945 GtkTreePath *path = NULL;
5946 GtkIconViewDropPosition pos;
5947 GtkIconViewDropPosition old_pos;
5948 GtkTreePath *old_dest_path = NULL;
5949 gboolean can_drop = FALSE;
5951 widget = GTK_WIDGET (icon_view);
5953 *suggested_action = 0;
5956 if (!icon_view->priv->dest_set)
5958 /* someone unset us as a drag dest, note that if
5959 * we return FALSE drag_leave isn't called
5962 gtk_icon_view_set_drag_dest_item (icon_view,
5964 GTK_ICON_VIEW_DROP_LEFT);
5966 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5968 return FALSE; /* no longer a drop site */
5971 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5972 if (*target == GDK_NONE)
5975 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5978 GtkTreeModel *model;
5980 /* the row got dropped on empty space, let's setup a special case
5984 gtk_tree_path_free (path);
5986 model = gtk_icon_view_get_model (icon_view);
5988 n_children = gtk_tree_model_iter_n_children (model, NULL);
5991 pos = GTK_ICON_VIEW_DROP_BELOW;
5992 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5996 pos = GTK_ICON_VIEW_DROP_ABOVE;
5997 path = gtk_tree_path_new_from_indices (0, -1);
6007 gtk_icon_view_get_drag_dest_item (icon_view,
6012 gtk_tree_path_free (old_dest_path);
6014 if (TRUE /* FIXME if the location droppable predicate */)
6022 GtkWidget *source_widget;
6024 *suggested_action = context->suggested_action;
6025 source_widget = gtk_drag_get_source_widget (context);
6027 if (source_widget == widget)
6029 /* Default to MOVE, unless the user has
6030 * pressed ctrl or shift to affect available actions
6032 if ((context->actions & GDK_ACTION_MOVE) != 0)
6033 *suggested_action = GDK_ACTION_MOVE;
6036 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6041 /* can't drop here */
6042 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6044 GTK_ICON_VIEW_DROP_LEFT);
6048 gtk_tree_path_free (path);
6054 get_logical_destination (GtkIconView *icon_view,
6055 gboolean *drop_append_mode)
6057 /* adjust path to point to the row the drop goes in front of */
6058 GtkTreePath *path = NULL;
6059 GtkIconViewDropPosition pos;
6061 *drop_append_mode = FALSE;
6063 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6068 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6069 pos == GTK_ICON_VIEW_DROP_BELOW)
6072 GtkTreeModel *model = icon_view->priv->model;
6074 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6075 !gtk_tree_model_iter_next (model, &iter))
6076 *drop_append_mode = TRUE;
6079 *drop_append_mode = FALSE;
6080 gtk_tree_path_next (path);
6088 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6089 GdkEventMotion *event)
6091 GdkDragContext *context;
6092 GtkTreePath *path = NULL;
6094 GtkTreeModel *model;
6095 gboolean retval = FALSE;
6097 if (!icon_view->priv->source_set)
6100 if (icon_view->priv->pressed_button < 0)
6103 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6104 icon_view->priv->press_start_x,
6105 icon_view->priv->press_start_y,
6106 event->x, event->y))
6109 model = gtk_icon_view_get_model (icon_view);
6114 button = icon_view->priv->pressed_button;
6115 icon_view->priv->pressed_button = -1;
6117 path = gtk_icon_view_get_path_at_pos (icon_view,
6118 icon_view->priv->press_start_x,
6119 icon_view->priv->press_start_y);
6124 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6125 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6129 /* FIXME Check whether we're a start button, if not return FALSE and
6133 /* Now we can begin the drag */
6137 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6138 icon_view->priv->source_targets,
6139 icon_view->priv->source_actions,
6143 set_source_row (context, model, path);
6147 gtk_tree_path_free (path);
6152 /* Source side drag signals */
6154 gtk_icon_view_drag_begin (GtkWidget *widget,
6155 GdkDragContext *context)
6157 GtkIconView *icon_view;
6158 GtkIconViewItem *item;
6163 icon_view = GTK_ICON_VIEW (widget);
6165 /* if the user uses a custom DnD impl, we don't set the icon here */
6166 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6169 item = gtk_icon_view_get_item_at_coords (icon_view,
6170 icon_view->priv->press_start_x,
6171 icon_view->priv->press_start_y,
6175 g_return_if_fail (item != NULL);
6177 x = icon_view->priv->press_start_x - item->x + 1;
6178 y = icon_view->priv->press_start_y - item->y + 1;
6180 path = gtk_tree_path_new_from_indices (item->index, -1);
6181 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6182 gtk_tree_path_free (path);
6184 gtk_drag_set_icon_pixmap (context,
6185 gdk_drawable_get_colormap (icon),
6190 g_object_unref (icon);
6194 gtk_icon_view_drag_end (GtkWidget *widget,
6195 GdkDragContext *context)
6201 gtk_icon_view_drag_data_get (GtkWidget *widget,
6202 GdkDragContext *context,
6203 GtkSelectionData *selection_data,
6207 GtkIconView *icon_view;
6208 GtkTreeModel *model;
6209 GtkTreePath *source_row;
6211 icon_view = GTK_ICON_VIEW (widget);
6212 model = gtk_icon_view_get_model (icon_view);
6217 if (!icon_view->priv->dest_set)
6220 source_row = get_source_row (context);
6222 if (source_row == NULL)
6225 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6226 * any model; for DragSource models there are some other targets
6230 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6231 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6236 /* If drag_data_get does nothing, try providing row data. */
6237 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6238 gtk_tree_set_row_drag_data (selection_data,
6243 gtk_tree_path_free (source_row);
6247 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6248 GdkDragContext *context)
6250 GtkTreeModel *model;
6251 GtkIconView *icon_view;
6252 GtkTreePath *source_row;
6254 icon_view = GTK_ICON_VIEW (widget);
6255 model = gtk_icon_view_get_model (icon_view);
6257 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6260 if (!icon_view->priv->dest_set)
6263 source_row = get_source_row (context);
6265 if (source_row == NULL)
6268 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6271 gtk_tree_path_free (source_row);
6273 set_source_row (context, NULL, NULL);
6276 /* Target side drag signals */
6278 gtk_icon_view_drag_leave (GtkWidget *widget,
6279 GdkDragContext *context,
6282 GtkIconView *icon_view;
6284 icon_view = GTK_ICON_VIEW (widget);
6286 /* unset any highlight row */
6287 gtk_icon_view_set_drag_dest_item (icon_view,
6289 GTK_ICON_VIEW_DROP_LEFT);
6291 remove_scroll_timeout (icon_view);
6295 gtk_icon_view_drag_motion (GtkWidget *widget,
6296 GdkDragContext *context,
6301 GtkTreePath *path = NULL;
6302 GtkIconViewDropPosition pos;
6303 GtkIconView *icon_view;
6304 GdkDragAction suggested_action = 0;
6308 icon_view = GTK_ICON_VIEW (widget);
6310 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6313 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6315 /* we only know this *after* set_desination_row */
6316 empty = icon_view->priv->empty_view_drop;
6318 if (path == NULL && !empty)
6320 /* Can't drop here. */
6321 gdk_drag_status (context, 0, time);
6325 if (icon_view->priv->scroll_timeout_id == 0)
6327 icon_view->priv->scroll_timeout_id =
6328 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6331 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6333 /* Request data so we can use the source row when
6334 * determining whether to accept the drop
6336 set_status_pending (context, suggested_action);
6337 gtk_drag_get_data (widget, context, target, time);
6341 set_status_pending (context, 0);
6342 gdk_drag_status (context, suggested_action, time);
6347 gtk_tree_path_free (path);
6353 gtk_icon_view_drag_drop (GtkWidget *widget,
6354 GdkDragContext *context,
6359 GtkIconView *icon_view;
6361 GdkDragAction suggested_action = 0;
6362 GdkAtom target = GDK_NONE;
6363 GtkTreeModel *model;
6364 gboolean drop_append_mode;
6366 icon_view = GTK_ICON_VIEW (widget);
6367 model = gtk_icon_view_get_model (icon_view);
6369 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6371 if (!icon_view->priv->dest_set)
6374 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6377 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6380 path = get_logical_destination (icon_view, &drop_append_mode);
6382 if (target != GDK_NONE && path != NULL)
6384 /* in case a motion had requested drag data, change things so we
6385 * treat drag data receives as a drop.
6387 set_status_pending (context, 0);
6388 set_dest_row (context, model, path,
6389 icon_view->priv->empty_view_drop, drop_append_mode);
6393 gtk_tree_path_free (path);
6395 /* Unset this thing */
6396 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6398 if (target != GDK_NONE)
6400 gtk_drag_get_data (widget, context, target, time);
6408 gtk_icon_view_drag_data_received (GtkWidget *widget,
6409 GdkDragContext *context,
6412 GtkSelectionData *selection_data,
6417 gboolean accepted = FALSE;
6418 GtkTreeModel *model;
6419 GtkIconView *icon_view;
6420 GtkTreePath *dest_row;
6421 GdkDragAction suggested_action;
6422 gboolean drop_append_mode;
6424 icon_view = GTK_ICON_VIEW (widget);
6425 model = gtk_icon_view_get_model (icon_view);
6427 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6430 if (!icon_view->priv->dest_set)
6433 suggested_action = get_status_pending (context);
6435 if (suggested_action)
6437 /* We are getting this data due to a request in drag_motion,
6438 * rather than due to a request in drag_drop, so we are just
6439 * supposed to call drag_status, not actually paste in the
6442 path = get_logical_destination (icon_view, &drop_append_mode);
6445 suggested_action = 0;
6447 if (suggested_action)
6449 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6452 suggested_action = 0;
6455 gdk_drag_status (context, suggested_action, time);
6458 gtk_tree_path_free (path);
6460 /* If you can't drop, remove user drop indicator until the next motion */
6461 if (suggested_action == 0)
6462 gtk_icon_view_set_drag_dest_item (icon_view,
6464 GTK_ICON_VIEW_DROP_LEFT);
6469 dest_row = get_dest_row (context);
6471 if (dest_row == NULL)
6474 if (selection_data->length >= 0)
6476 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6482 gtk_drag_finish (context,
6484 (context->action == GDK_ACTION_MOVE),
6487 gtk_tree_path_free (dest_row);
6490 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6493 /* Drag-and-Drop support */
6495 * gtk_icon_view_enable_model_drag_source:
6496 * @icon_view: a #GtkIconTreeView
6497 * @start_button_mask: Mask of allowed buttons to start drag
6498 * @targets: the table of targets that the drag will support
6499 * @n_targets: the number of items in @targets
6500 * @actions: the bitmask of possible actions for a drag from this
6503 * Turns @icon_view into a drag source for automatic DND.
6508 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6509 GdkModifierType start_button_mask,
6510 const GtkTargetEntry *targets,
6512 GdkDragAction actions)
6514 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6516 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6518 clear_source_info (icon_view);
6519 icon_view->priv->start_button_mask = start_button_mask;
6520 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6521 icon_view->priv->source_actions = actions;
6523 icon_view->priv->source_set = TRUE;
6525 unset_reorderable (icon_view);
6529 * gtk_icon_view_enable_model_drag_dest:
6530 * @icon_view: a #GtkIconView
6531 * @targets: the table of targets that the drag will support
6532 * @n_targets: the number of items in @targets
6533 * @actions: the bitmask of possible actions for a drag to this
6536 * Turns @icon_view into a drop destination for automatic DND.
6541 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6542 const GtkTargetEntry *targets,
6544 GdkDragAction actions)
6546 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6548 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6550 clear_dest_info (icon_view);
6552 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6553 icon_view->priv->dest_actions = actions;
6555 icon_view->priv->dest_set = TRUE;
6557 unset_reorderable (icon_view);
6561 * gtk_icon_view_unset_model_drag_source:
6562 * @icon_view: a #GtkIconView
6564 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6569 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6571 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6573 if (icon_view->priv->source_set)
6575 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6576 clear_source_info (icon_view);
6579 unset_reorderable (icon_view);
6583 * gtk_icon_view_unset_model_drag_dest:
6584 * @icon_view: a #GtkIconView
6586 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6591 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6593 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6595 if (icon_view->priv->dest_set)
6597 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6598 clear_dest_info (icon_view);
6601 unset_reorderable (icon_view);
6604 /* These are useful to implement your own custom stuff. */
6606 * gtk_icon_view_set_drag_dest_item:
6607 * @icon_view: a #GtkIconView
6608 * @path: The path of the item to highlight, or %NULL.
6609 * @pos: Specifies where to drop, relative to the item
6611 * Sets the item that is highlighted for feedback.
6616 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6618 GtkIconViewDropPosition pos)
6620 /* Note; this function is exported to allow a custom DND
6621 * implementation, so it can't touch TreeViewDragInfo
6624 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6626 if (icon_view->priv->dest_item)
6628 GtkTreePath *current_path;
6629 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6630 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6631 icon_view->priv->dest_item = NULL;
6633 gtk_icon_view_queue_draw_path (icon_view, current_path);
6634 gtk_tree_path_free (current_path);
6637 /* special case a drop on an empty model */
6638 icon_view->priv->empty_view_drop = FALSE;
6639 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6640 && gtk_tree_path_get_depth (path) == 1
6641 && gtk_tree_path_get_indices (path)[0] == 0)
6645 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6648 if (n_children == 0)
6649 icon_view->priv->empty_view_drop = TRUE;
6652 icon_view->priv->dest_pos = pos;
6656 icon_view->priv->dest_item =
6657 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6658 icon_view->priv->model, path);
6660 gtk_icon_view_queue_draw_path (icon_view, path);
6665 * gtk_icon_view_get_drag_dest_item:
6666 * @icon_view: a #GtkIconView
6667 * @path: Return location for the path of the highlighted item, or %NULL.
6668 * @pos: Return location for the drop position, or %NULL
6670 * Gets information about the item that is highlighted for feedback.
6675 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6677 GtkIconViewDropPosition *pos)
6679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6683 if (icon_view->priv->dest_item)
6684 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6690 *pos = icon_view->priv->dest_pos;
6694 * gtk_icon_view_get_dest_item_at_pos:
6695 * @icon_view: a #GtkIconView
6696 * @drag_x: the position to determine the destination item for
6697 * @drag_y: the position to determine the destination item for
6698 * @path: Return location for the path of the item, or %NULL.
6699 * @pos: Return location for the drop position, or %NULL
6701 * Determines the destination item for a given position.
6703 * Return value: whether there is an item at the given position.
6708 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6712 GtkIconViewDropPosition *pos)
6714 GtkIconViewItem *item;
6716 /* Note; this function is exported to allow a custom DND
6717 * implementation, so it can't touch TreeViewDragInfo
6720 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6721 g_return_val_if_fail (drag_x >= 0, FALSE);
6722 g_return_val_if_fail (drag_y >= 0, FALSE);
6723 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6729 item = gtk_icon_view_get_item_at_coords (icon_view,
6730 drag_x + icon_view->priv->hadjustment->value,
6731 drag_y + icon_view->priv->vadjustment->value,
6738 *path = gtk_tree_path_new_from_indices (item->index, -1);
6742 if (drag_x < item->x + item->width / 4)
6743 *pos = GTK_ICON_VIEW_DROP_LEFT;
6744 else if (drag_x > item->x + item->width * 3 / 4)
6745 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6746 else if (drag_y < item->y + item->height / 4)
6747 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6748 else if (drag_y > item->y + item->height * 3 / 4)
6749 *pos = GTK_ICON_VIEW_DROP_BELOW;
6751 *pos = GTK_ICON_VIEW_DROP_INTO;
6758 * gtk_icon_view_create_drag_icon:
6759 * @icon_view: a #GtkIconView
6760 * @path: a #GtkTreePath in @icon_view
6762 * Creates a #GdkPixmap representation of the item at @path.
6763 * This image is used for a drag icon.
6765 * Return value: a newly-allocated pixmap of the drag icon.
6770 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6775 GdkPixmap *drawable;
6780 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6781 g_return_val_if_fail (path != NULL, NULL);
6783 widget = GTK_WIDGET (icon_view);
6785 if (!GTK_WIDGET_REALIZED (widget))
6788 index = gtk_tree_path_get_indices (path)[0];
6790 for (l = icon_view->priv->items; l; l = l->next)
6792 GtkIconViewItem *item = l->data;
6794 if (index == item->index)
6796 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6801 cr = gdk_cairo_create (drawable);
6802 cairo_set_line_width (cr, 1.);
6804 gdk_cairo_set_source_color
6805 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6806 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6811 area.width = item->width;
6812 area.height = item->height;
6814 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6815 drawable, 1, 1, FALSE);
6817 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6818 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6831 * gtk_icon_view_get_reorderable:
6832 * @icon_view: a #GtkIconView
6834 * Retrieves whether the user can reorder the list via drag-and-drop.
6835 * See gtk_icon_view_set_reorderable().
6837 * Return value: %TRUE if the list can be reordered.
6842 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6844 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6846 return icon_view->priv->reorderable;
6849 static const GtkTargetEntry item_targets[] = {
6850 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6855 * gtk_icon_view_set_reorderable:
6856 * @icon_view: A #GtkIconView.
6857 * @reorderable: %TRUE, if the list of items can be reordered.
6859 * This function is a convenience function to allow you to reorder models that
6860 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6861 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6862 * the user can reorder the model by dragging and dropping rows. The
6863 * developer can listen to these changes by connecting to the model's
6864 * row_inserted and row_deleted signals.
6866 * This function does not give you any degree of control over the order -- any
6867 * reordering is allowed. If more control is needed, you should probably
6868 * handle drag and drop manually.
6873 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6874 gboolean reorderable)
6876 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6878 reorderable = reorderable != FALSE;
6880 if (icon_view->priv->reorderable == reorderable)
6885 gtk_icon_view_enable_model_drag_source (icon_view,
6888 G_N_ELEMENTS (item_targets),
6890 gtk_icon_view_enable_model_drag_dest (icon_view,
6892 G_N_ELEMENTS (item_targets),
6897 gtk_icon_view_unset_model_drag_source (icon_view);
6898 gtk_icon_view_unset_model_drag_dest (icon_view);
6901 icon_view->priv->reorderable = reorderable;
6903 g_object_notify (G_OBJECT (icon_view), "reorderable");
6907 /* Accessibility Support */
6909 static gpointer accessible_parent_class;
6910 static gpointer accessible_item_parent_class;
6911 static GQuark accessible_private_data_quark = 0;
6913 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6914 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6915 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6917 static GType gtk_icon_view_item_accessible_get_type (void);
6928 GtkIconViewItem *item;
6932 AtkStateSet *state_set;
6936 GtkTextBuffer *text_buffer;
6938 gchar *action_descriptions[LAST_ACTION];
6939 gchar *image_description;
6940 guint action_idle_handler;
6941 } GtkIconViewItemAccessible;
6943 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6949 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6954 typedef struct _GtkIconViewItemAccessibleClass
6956 AtkObjectClass parent_class;
6958 } GtkIconViewItemAccessibleClass;
6960 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6963 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6965 GtkIconViewItemAccessible *item;
6966 GtkIconView *icon_view;
6969 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6970 item->action_idle_handler = 0;
6972 if (item->widget != NULL)
6974 icon_view = GTK_ICON_VIEW (item->widget);
6975 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6976 gtk_icon_view_item_activated (icon_view, path);
6977 gtk_tree_path_free (path);
6984 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6987 GtkIconViewItemAccessible *item;
6989 if (i < 0 || i >= LAST_ACTION)
6992 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6994 if (!GTK_IS_ICON_VIEW (item->widget))
6997 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7002 case ACTION_ACTIVATE:
7003 if (!item->action_idle_handler)
7004 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7007 g_assert_not_reached ();
7015 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7020 static const gchar *
7021 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7024 GtkIconViewItemAccessible *item;
7026 if (i < 0 || i >= LAST_ACTION)
7029 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7031 if (item->action_descriptions[i])
7032 return item->action_descriptions[i];
7034 return gtk_icon_view_item_accessible_action_descriptions[i];
7037 static const gchar *
7038 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7041 if (i < 0 || i >= LAST_ACTION)
7044 return gtk_icon_view_item_accessible_action_names[i];
7048 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7050 const gchar *description)
7052 GtkIconViewItemAccessible *item;
7054 if (i < 0 || i >= LAST_ACTION)
7057 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7059 g_free (item->action_descriptions[i]);
7061 item->action_descriptions[i] = g_strdup (description);
7067 atk_action_item_interface_init (AtkActionIface *iface)
7069 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7070 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7071 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7072 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7073 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7076 static const gchar *
7077 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7079 GtkIconViewItemAccessible *item;
7081 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7083 return item->image_description;
7087 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7088 const gchar *description)
7090 GtkIconViewItemAccessible *item;
7092 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7094 g_free (item->image_description);
7095 item->image_description = g_strdup (item->image_description);
7101 get_pixbuf_box (GtkIconView *icon_view,
7102 GtkIconViewItem *item,
7107 for (l = icon_view->priv->cell_list; l; l = l->next)
7109 GtkIconViewCellInfo *info = l->data;
7111 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7113 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7123 get_text (GtkIconView *icon_view,
7124 GtkIconViewItem *item)
7129 for (l = icon_view->priv->cell_list; l; l = l->next)
7131 GtkIconViewCellInfo *info = l->data;
7133 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7135 g_object_get (info->cell, "text", &text, NULL);
7145 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7149 GtkIconViewItemAccessible *item;
7152 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7154 if (!GTK_IS_ICON_VIEW (item->widget))
7157 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7160 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7163 *height = box.height;
7168 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7171 AtkCoordType coord_type)
7173 GtkIconViewItemAccessible *item;
7176 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7178 if (!GTK_IS_ICON_VIEW (item->widget))
7181 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7184 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7186 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7188 *x+= box.x - item->item->x;
7189 *y+= box.y - item->item->y;
7195 atk_image_item_interface_init (AtkImageIface *iface)
7197 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7198 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7199 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7200 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7204 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7208 GtkIconViewItemAccessible *item;
7209 GtkTextIter start, end;
7210 GtkTextBuffer *buffer;
7212 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7214 if (!GTK_IS_ICON_VIEW (item->widget))
7217 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7220 buffer = item->text_buffer;
7221 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7223 gtk_text_buffer_get_end_iter (buffer, &end);
7225 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7227 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7231 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7234 GtkIconViewItemAccessible *item;
7235 GtkTextIter start, end;
7236 GtkTextBuffer *buffer;
7240 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7242 if (!GTK_IS_ICON_VIEW (item->widget))
7245 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7248 buffer = item->text_buffer;
7249 if (offset >= gtk_text_buffer_get_char_count (buffer))
7252 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7254 gtk_text_iter_forward_char (&end);
7255 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7256 unichar = g_utf8_get_char (string);
7264 get_pango_text_offsets (PangoLayout *layout,
7265 GtkTextBuffer *buffer,
7267 AtkTextBoundary boundary_type,
7271 GtkTextIter *start_iter,
7272 GtkTextIter *end_iter)
7274 PangoLayoutIter *iter;
7275 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7276 gint index, start_index, end_index;
7278 gboolean found = FALSE;
7280 text = pango_layout_get_text (layout);
7281 index = g_utf8_offset_to_pointer (text, offset) - text;
7282 iter = pango_layout_get_iter (layout);
7285 line = pango_layout_iter_get_line_readonly (iter);
7286 start_index = line->start_index;
7287 end_index = start_index + line->length;
7289 if (index >= start_index && index <= end_index)
7292 * Found line for offset
7298 * We want the previous line
7302 switch (boundary_type)
7304 case ATK_TEXT_BOUNDARY_LINE_START:
7305 end_index = start_index;
7306 start_index = prev_line->start_index;
7308 case ATK_TEXT_BOUNDARY_LINE_END:
7310 start_index = prev_prev_line->start_index +
7311 prev_prev_line->length;
7312 end_index = prev_line->start_index + prev_line->length;
7315 g_assert_not_reached();
7319 start_index = end_index = 0;
7322 switch (boundary_type)
7324 case ATK_TEXT_BOUNDARY_LINE_START:
7325 if (pango_layout_iter_next_line (iter))
7326 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7328 case ATK_TEXT_BOUNDARY_LINE_END:
7330 start_index = prev_line->start_index +
7334 g_assert_not_reached();
7339 * We want the next line
7341 if (pango_layout_iter_next_line (iter))
7343 line = pango_layout_iter_get_line_readonly (iter);
7344 switch (boundary_type)
7346 case ATK_TEXT_BOUNDARY_LINE_START:
7347 start_index = line->start_index;
7348 if (pango_layout_iter_next_line (iter))
7349 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7351 end_index = start_index + line->length;
7353 case ATK_TEXT_BOUNDARY_LINE_END:
7354 start_index = end_index;
7355 end_index = line->start_index + line->length;
7358 g_assert_not_reached();
7362 start_index = end_index;
7368 prev_prev_line = prev_line;
7371 while (pango_layout_iter_next_line (iter));
7375 start_index = prev_line->start_index + prev_line->length;
7376 end_index = start_index;
7378 pango_layout_iter_free (iter);
7379 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7380 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7382 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7383 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7388 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7390 AtkTextBoundary boundary_type,
7394 GtkIconViewItemAccessible *item;
7395 GtkTextIter start, end;
7396 GtkTextBuffer *buffer;
7398 GtkIconView *icon_view;
7401 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7403 if (!GTK_IS_ICON_VIEW (item->widget))
7406 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7409 buffer = item->text_buffer;
7411 if (!gtk_text_buffer_get_char_count (buffer))
7415 return g_strdup ("");
7417 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7421 switch (boundary_type)
7423 case ATK_TEXT_BOUNDARY_CHAR:
7424 gtk_text_iter_backward_char(&start);
7426 case ATK_TEXT_BOUNDARY_WORD_START:
7427 if (!gtk_text_iter_starts_word (&start))
7428 gtk_text_iter_backward_word_start (&start);
7430 gtk_text_iter_backward_word_start(&start);
7432 case ATK_TEXT_BOUNDARY_WORD_END:
7433 if (gtk_text_iter_inside_word (&start) &&
7434 !gtk_text_iter_starts_word (&start))
7435 gtk_text_iter_backward_word_start (&start);
7436 while (!gtk_text_iter_ends_word (&start))
7438 if (!gtk_text_iter_backward_char (&start))
7442 gtk_text_iter_backward_word_start(&start);
7443 while (!gtk_text_iter_ends_word (&start))
7445 if (!gtk_text_iter_backward_char (&start))
7449 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7450 if (!gtk_text_iter_starts_sentence (&start))
7451 gtk_text_iter_backward_sentence_start (&start);
7453 gtk_text_iter_backward_sentence_start (&start);
7455 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7456 if (gtk_text_iter_inside_sentence (&start) &&
7457 !gtk_text_iter_starts_sentence (&start))
7458 gtk_text_iter_backward_sentence_start (&start);
7459 while (!gtk_text_iter_ends_sentence (&start))
7461 if (!gtk_text_iter_backward_char (&start))
7465 gtk_text_iter_backward_sentence_start (&start);
7466 while (!gtk_text_iter_ends_sentence (&start))
7468 if (!gtk_text_iter_backward_char (&start))
7472 case ATK_TEXT_BOUNDARY_LINE_START:
7473 case ATK_TEXT_BOUNDARY_LINE_END:
7475 icon_view = GTK_ICON_VIEW (item->widget);
7476 /* FIXME we probably have to use GailTextCell to salvage this */
7477 gtk_icon_view_update_item_text (icon_view, item->item);
7478 get_pango_text_offsets (icon_view->priv->layout,
7491 *start_offset = gtk_text_iter_get_offset (&start);
7492 *end_offset = gtk_text_iter_get_offset (&end);
7494 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7498 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7500 AtkTextBoundary boundary_type,
7504 GtkIconViewItemAccessible *item;
7505 GtkTextIter start, end;
7506 GtkTextBuffer *buffer;
7508 GtkIconView *icon_view;
7511 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7513 if (!GTK_IS_ICON_VIEW (item->widget))
7516 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7519 buffer = item->text_buffer;
7521 if (!gtk_text_buffer_get_char_count (buffer))
7525 return g_strdup ("");
7527 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7531 switch (boundary_type)
7533 case ATK_TEXT_BOUNDARY_CHAR:
7534 gtk_text_iter_forward_char (&end);
7536 case ATK_TEXT_BOUNDARY_WORD_START:
7537 if (!gtk_text_iter_starts_word (&start))
7538 gtk_text_iter_backward_word_start (&start);
7539 if (gtk_text_iter_inside_word (&end))
7540 gtk_text_iter_forward_word_end (&end);
7541 while (!gtk_text_iter_starts_word (&end))
7543 if (!gtk_text_iter_forward_char (&end))
7547 case ATK_TEXT_BOUNDARY_WORD_END:
7548 if (gtk_text_iter_inside_word (&start) &&
7549 !gtk_text_iter_starts_word (&start))
7550 gtk_text_iter_backward_word_start (&start);
7551 while (!gtk_text_iter_ends_word (&start))
7553 if (!gtk_text_iter_backward_char (&start))
7556 gtk_text_iter_forward_word_end (&end);
7558 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7559 if (!gtk_text_iter_starts_sentence (&start))
7560 gtk_text_iter_backward_sentence_start (&start);
7561 if (gtk_text_iter_inside_sentence (&end))
7562 gtk_text_iter_forward_sentence_end (&end);
7563 while (!gtk_text_iter_starts_sentence (&end))
7565 if (!gtk_text_iter_forward_char (&end))
7569 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7570 if (gtk_text_iter_inside_sentence (&start) &&
7571 !gtk_text_iter_starts_sentence (&start))
7572 gtk_text_iter_backward_sentence_start (&start);
7573 while (!gtk_text_iter_ends_sentence (&start))
7575 if (!gtk_text_iter_backward_char (&start))
7578 gtk_text_iter_forward_sentence_end (&end);
7580 case ATK_TEXT_BOUNDARY_LINE_START:
7581 case ATK_TEXT_BOUNDARY_LINE_END:
7583 icon_view = GTK_ICON_VIEW (item->widget);
7584 /* FIXME we probably have to use GailTextCell to salvage this */
7585 gtk_icon_view_update_item_text (icon_view, item->item);
7586 get_pango_text_offsets (icon_view->priv->layout,
7600 *start_offset = gtk_text_iter_get_offset (&start);
7601 *end_offset = gtk_text_iter_get_offset (&end);
7603 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7607 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7609 AtkTextBoundary boundary_type,
7613 GtkIconViewItemAccessible *item;
7614 GtkTextIter start, end;
7615 GtkTextBuffer *buffer;
7617 GtkIconView *icon_view;
7620 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7622 if (!GTK_IS_ICON_VIEW (item->widget))
7625 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7628 buffer = item->text_buffer;
7630 if (!gtk_text_buffer_get_char_count (buffer))
7634 return g_strdup ("");
7636 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7640 switch (boundary_type)
7642 case ATK_TEXT_BOUNDARY_CHAR:
7643 gtk_text_iter_forward_char(&start);
7644 gtk_text_iter_forward_chars(&end, 2);
7646 case ATK_TEXT_BOUNDARY_WORD_START:
7647 if (gtk_text_iter_inside_word (&end))
7648 gtk_text_iter_forward_word_end (&end);
7649 while (!gtk_text_iter_starts_word (&end))
7651 if (!gtk_text_iter_forward_char (&end))
7655 if (!gtk_text_iter_is_end (&end))
7657 gtk_text_iter_forward_word_end (&end);
7658 while (!gtk_text_iter_starts_word (&end))
7660 if (!gtk_text_iter_forward_char (&end))
7665 case ATK_TEXT_BOUNDARY_WORD_END:
7666 gtk_text_iter_forward_word_end (&end);
7668 if (!gtk_text_iter_is_end (&end))
7669 gtk_text_iter_forward_word_end (&end);
7671 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7672 if (gtk_text_iter_inside_sentence (&end))
7673 gtk_text_iter_forward_sentence_end (&end);
7674 while (!gtk_text_iter_starts_sentence (&end))
7676 if (!gtk_text_iter_forward_char (&end))
7680 if (!gtk_text_iter_is_end (&end))
7682 gtk_text_iter_forward_sentence_end (&end);
7683 while (!gtk_text_iter_starts_sentence (&end))
7685 if (!gtk_text_iter_forward_char (&end))
7690 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7691 gtk_text_iter_forward_sentence_end (&end);
7693 if (!gtk_text_iter_is_end (&end))
7694 gtk_text_iter_forward_sentence_end (&end);
7696 case ATK_TEXT_BOUNDARY_LINE_START:
7697 case ATK_TEXT_BOUNDARY_LINE_END:
7699 icon_view = GTK_ICON_VIEW (item->widget);
7700 /* FIXME we probably have to use GailTextCell to salvage this */
7701 gtk_icon_view_update_item_text (icon_view, item->item);
7702 get_pango_text_offsets (icon_view->priv->layout,
7714 *start_offset = gtk_text_iter_get_offset (&start);
7715 *end_offset = gtk_text_iter_get_offset (&end);
7717 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7721 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7723 GtkIconViewItemAccessible *item;
7725 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7727 if (!GTK_IS_ICON_VIEW (item->widget))
7730 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7733 return gtk_text_buffer_get_char_count (item->text_buffer);
7737 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7743 AtkCoordType coord_type)
7745 GtkIconViewItemAccessible *item;
7747 GtkIconView *icon_view;
7748 PangoRectangle char_rect;
7749 const gchar *item_text;
7753 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7755 if (!GTK_IS_ICON_VIEW (item->widget))
7758 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7762 icon_view = GTK_ICON_VIEW (item->widget);
7763 /* FIXME we probably have to use GailTextCell to salvage this */
7764 gtk_icon_view_update_item_text (icon_view, item->item);
7765 item_text = pango_layout_get_text (icon_view->priv->layout);
7766 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7767 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7769 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7770 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7771 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7772 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7773 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7774 *width = char_rect.width / PANGO_SCALE;
7775 *height = char_rect.height / PANGO_SCALE;
7780 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7783 AtkCoordType coord_type)
7785 GtkIconViewItemAccessible *item;
7788 GtkIconView *icon_view;
7789 const gchar *item_text;
7794 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7796 if (!GTK_IS_ICON_VIEW (item->widget))
7799 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7803 icon_view = GTK_ICON_VIEW (item->widget);
7804 /* FIXME we probably have to use GailTextCell to salvage this */
7805 gtk_icon_view_update_item_text (icon_view, item->item);
7806 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7807 x -= l_x + item->item->layout_x - item->item->x;
7808 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7809 y -= l_y + item->item->layout_y - item->item->y;
7810 item_text = pango_layout_get_text (icon_view->priv->layout);
7811 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7822 offset = g_utf8_strlen (item_text, -1);
7824 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7830 atk_text_item_interface_init (AtkTextIface *iface)
7832 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7833 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7834 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7835 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7836 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7837 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7838 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7839 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7843 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7848 AtkCoordType coord_type)
7850 GtkIconViewItemAccessible *item;
7851 AtkObject *parent_obj;
7854 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7856 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7857 if (!GTK_IS_WIDGET (item->widget))
7860 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7863 *width = item->item->width;
7864 *height = item->item->height;
7865 if (gtk_icon_view_item_accessible_is_showing (item))
7867 parent_obj = gtk_widget_get_accessible (item->widget);
7868 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7869 *x = l_x + item->item->x;
7870 *y = l_y + item->item->y;
7880 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7882 GtkIconViewItemAccessible *item;
7883 GtkWidget *toplevel;
7885 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7887 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7888 if (!GTK_IS_WIDGET (item->widget))
7891 gtk_widget_grab_focus (item->widget);
7892 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7893 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7894 if (GTK_WIDGET_TOPLEVEL (toplevel))
7895 gtk_window_present (GTK_WINDOW (toplevel));
7901 atk_component_item_interface_init (AtkComponentIface *iface)
7903 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7904 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7908 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7909 AtkStateType state_type,
7910 gboolean emit_signal)
7914 rc = atk_state_set_add_state (item->state_set, state_type);
7916 * The signal should only be generated if the value changed,
7917 * not when the item is set up. So states that are set
7918 * initially should pass FALSE as the emit_signal argument.
7923 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7924 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7925 if (state_type == ATK_STATE_VISIBLE)
7926 g_signal_emit_by_name (item, "visible_data_changed");
7933 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7934 AtkStateType state_type,
7935 gboolean emit_signal)
7937 if (atk_state_set_contains_state (item->state_set, state_type))
7941 rc = atk_state_set_remove_state (item->state_set, state_type);
7943 * The signal should only be generated if the value changed,
7944 * not when the item is set up. So states that are set
7945 * initially should pass FALSE as the emit_signal argument.
7950 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7951 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7952 if (state_type == ATK_STATE_VISIBLE)
7953 g_signal_emit_by_name (item, "visible_data_changed");
7963 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7965 GtkIconView *icon_view;
7966 GdkRectangle visible_rect;
7967 gboolean is_showing;
7970 * An item is considered "SHOWING" if any part of the item is in the
7971 * visible rectangle.
7974 if (!GTK_IS_ICON_VIEW (item->widget))
7977 if (item->item == NULL)
7980 icon_view = GTK_ICON_VIEW (item->widget);
7982 if (icon_view->priv->hadjustment)
7983 visible_rect.x += icon_view->priv->hadjustment->value;
7985 if (icon_view->priv->hadjustment)
7986 visible_rect.y += icon_view->priv->vadjustment->value;
7987 visible_rect.width = item->widget->allocation.width;
7988 visible_rect.height = item->widget->allocation.height;
7990 if (((item->item->x + item->item->width) < visible_rect.x) ||
7991 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7992 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7993 (item->item->y > (visible_rect.y + visible_rect.height)))
8002 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8003 gboolean emit_signal)
8005 if (gtk_icon_view_item_accessible_is_showing (item))
8006 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8009 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8014 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8018 item->state_set = atk_state_set_new ();
8020 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8021 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8022 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8023 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8024 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8026 for (i = 0; i < LAST_ACTION; i++)
8027 item->action_descriptions[i] = NULL;
8029 item->image_description = NULL;
8031 item->action_idle_handler = 0;
8035 gtk_icon_view_item_accessible_finalize (GObject *object)
8037 GtkIconViewItemAccessible *item;
8040 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8042 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8045 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8047 if (item->state_set)
8048 g_object_unref (item->state_set);
8050 if (item->text_buffer)
8051 g_object_unref (item->text_buffer);
8053 for (i = 0; i < LAST_ACTION; i++)
8054 g_free (item->action_descriptions[i]);
8056 g_free (item->image_description);
8058 if (item->action_idle_handler)
8060 g_source_remove (item->action_idle_handler);
8061 item->action_idle_handler = 0;
8064 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8067 static G_CONST_RETURN gchar*
8068 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8074 GtkIconViewItemAccessible *item;
8075 GtkTextIter start_iter;
8076 GtkTextIter end_iter;
8078 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8080 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8081 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8083 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8088 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8090 GtkIconViewItemAccessible *item;
8092 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8093 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8096 return gtk_widget_get_accessible (item->widget);
8102 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8104 GtkIconViewItemAccessible *item;
8106 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8107 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8109 return item->item->index;
8112 static AtkStateSet *
8113 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8115 GtkIconViewItemAccessible *item;
8116 GtkIconView *icon_view;
8118 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8119 g_return_val_if_fail (item->state_set, NULL);
8124 icon_view = GTK_ICON_VIEW (item->widget);
8125 if (icon_view->priv->cursor_item == item->item)
8126 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8128 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8130 return g_object_ref (item->state_set);
8134 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8136 GObjectClass *gobject_class;
8138 accessible_item_parent_class = g_type_class_peek_parent (klass);
8140 gobject_class = (GObjectClass *)klass;
8142 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8144 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8145 klass->get_name = gtk_icon_view_item_accessible_get_name;
8146 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8147 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8151 gtk_icon_view_item_accessible_get_type (void)
8153 static GType type = 0;
8157 const GTypeInfo tinfo =
8159 sizeof (GtkIconViewItemAccessibleClass),
8160 (GBaseInitFunc) NULL, /* base init */
8161 (GBaseFinalizeFunc) NULL, /* base finalize */
8162 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8163 (GClassFinalizeFunc) NULL, /* class finalize */
8164 NULL, /* class data */
8165 sizeof (GtkIconViewItemAccessible), /* instance size */
8166 0, /* nb preallocs */
8167 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8168 NULL /* value table */
8171 static const GInterfaceInfo atk_component_info =
8173 (GInterfaceInitFunc) atk_component_item_interface_init,
8174 (GInterfaceFinalizeFunc) NULL,
8177 static const GInterfaceInfo atk_action_info =
8179 (GInterfaceInitFunc) atk_action_item_interface_init,
8180 (GInterfaceFinalizeFunc) NULL,
8183 static const GInterfaceInfo atk_image_info =
8185 (GInterfaceInitFunc) atk_image_item_interface_init,
8186 (GInterfaceFinalizeFunc) NULL,
8189 static const GInterfaceInfo atk_text_info =
8191 (GInterfaceInitFunc) atk_text_item_interface_init,
8192 (GInterfaceFinalizeFunc) NULL,
8196 type = g_type_register_static (ATK_TYPE_OBJECT,
8197 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8198 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8199 &atk_component_info);
8200 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8202 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8204 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8211 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8212 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8213 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8215 static GType gtk_icon_view_accessible_get_type (void);
8220 } GtkIconViewAccessible;
8226 } GtkIconViewItemAccessibleInfo;
8232 GtkAdjustment *old_hadj;
8233 GtkAdjustment *old_vadj;
8235 GtkTreeModel *model;
8237 } GtkIconViewAccessiblePrivate;
8239 static GtkIconViewAccessiblePrivate *
8240 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8242 return g_object_get_qdata (G_OBJECT (accessible),
8243 accessible_private_data_quark);
8247 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8251 GtkIconViewItemAccessibleInfo *info;
8252 GtkIconViewItemAccessibleInfo *tmp_info;
8253 GtkIconViewAccessiblePrivate *priv;
8256 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8258 info->index = index;
8260 priv = gtk_icon_view_accessible_get_priv (accessible);
8261 items = priv->items;
8264 tmp_info = items->data;
8265 if (tmp_info->index > index)
8267 items = items->next;
8269 priv->items = g_list_insert_before (priv->items, items, info);
8270 priv->old_hadj = NULL;
8271 priv->old_vadj = NULL;
8275 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8277 GtkIconView *icon_view;
8280 widget = GTK_ACCESSIBLE (accessible)->widget;
8284 icon_view = GTK_ICON_VIEW (widget);
8286 return g_list_length (icon_view->priv->items);
8290 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8293 GtkIconViewAccessiblePrivate *priv;
8294 GtkIconViewItemAccessibleInfo *info;
8297 priv = gtk_icon_view_accessible_get_priv (accessible);
8298 items = priv->items;
8303 if (info->index == index)
8305 items = items->next;
8311 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8314 GtkIconView *icon_view;
8318 GtkIconViewItemAccessible *a11y_item;
8320 widget = GTK_ACCESSIBLE (accessible)->widget;
8324 icon_view = GTK_ICON_VIEW (widget);
8325 icons = g_list_nth (icon_view->priv->items, index);
8329 GtkIconViewItem *item = icons->data;
8331 g_return_val_if_fail (item->index == index, NULL);
8332 obj = gtk_icon_view_accessible_find_child (accessible, index);
8337 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8338 gtk_icon_view_item_accessible_info_new (accessible,
8341 obj->role = ATK_ROLE_ICON;
8342 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8343 a11y_item->item = item;
8344 a11y_item->widget = widget;
8345 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8347 gtk_icon_view_set_cell_data (icon_view, item);
8348 text = get_text (icon_view, item);
8351 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8355 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8356 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8364 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8367 GtkIconViewAccessiblePrivate *priv;
8368 GtkIconViewItemAccessibleInfo *info;
8369 GtkIconViewItemAccessible *item;
8372 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8376 gboolean act_on_item;
8378 widget = GTK_ACCESSIBLE (view)->widget;
8382 items = priv->items;
8384 act_on_item = (list == NULL);
8389 info = (GtkIconViewItemAccessibleInfo *)items->data;
8390 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8392 if (act_on_item == FALSE && list == items)
8396 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8398 items = items->next;
8404 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8405 GtkIconView *icon_view)
8408 GtkIconViewAccessible *view;
8411 * The scrollbars have changed
8413 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8414 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8416 gtk_icon_view_accessible_traverse_items (view, NULL);
8420 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8421 GtkAdjustment *hadj,
8422 GtkAdjustment *vadj)
8425 GtkIconViewAccessiblePrivate *priv;
8427 atk_obj = gtk_widget_get_accessible (widget);
8428 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8430 if (priv->old_hadj != hadj)
8434 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8435 (gpointer *)&priv->old_hadj);
8437 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8438 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8441 priv->old_hadj = hadj;
8444 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8445 (gpointer *)&priv->old_hadj);
8446 g_signal_connect (hadj,
8448 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8452 if (priv->old_vadj != vadj)
8456 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8457 (gpointer *)&priv->old_vadj);
8459 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8460 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8463 priv->old_vadj = vadj;
8466 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8467 (gpointer *)&priv->old_vadj);
8468 g_signal_connect (vadj,
8470 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8477 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8484 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8485 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8491 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8496 GtkIconViewAccessiblePrivate *priv;
8497 GtkIconViewItemAccessibleInfo *info;
8498 GtkIconViewAccessible *view;
8499 GtkIconViewItemAccessible *item;
8505 index = gtk_tree_path_get_indices(path)[0];
8506 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8507 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8508 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8510 items = priv->items;
8515 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8516 if (info->index != item->item->index)
8518 if (info->index < index)
8519 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8521 if (tmp_list == NULL)
8524 info->index = item->item->index;
8527 items = items->next;
8529 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8530 g_signal_emit_by_name (atk_obj, "children_changed::add",
8536 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8540 GtkIconViewAccessiblePrivate *priv;
8541 GtkIconViewItemAccessibleInfo *info;
8542 GtkIconViewAccessible *view;
8543 GtkIconViewItemAccessible *item;
8546 GList *deleted_item;
8550 index = gtk_tree_path_get_indices(path)[0];
8551 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8552 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8553 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8555 items = priv->items;
8557 deleted_item = NULL;
8562 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8563 if (info->index == index)
8565 deleted_item = items;
8567 if (info->index != item->item->index)
8569 if (tmp_list == NULL)
8572 info->index = item->item->index;
8575 items = items->next;
8577 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8580 info = deleted_item->data;
8581 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8583 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8587 priv->items = g_list_remove_link (priv->items, deleted_item);
8595 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8596 GtkIconViewItemAccessibleInfo *i2)
8598 return i1->index - i2->index;
8602 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8608 GtkIconViewAccessiblePrivate *priv;
8609 GtkIconViewItemAccessibleInfo *info;
8610 GtkIconView *icon_view;
8611 GtkIconViewItemAccessible *item;
8615 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8616 icon_view = GTK_ICON_VIEW (user_data);
8617 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8619 items = priv->items;
8623 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8624 info->index = new_order[info->index];
8625 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8626 items = items->next;
8628 priv->items = g_list_sort (priv->items,
8629 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8635 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8640 obj = G_OBJECT (model);
8641 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8642 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8643 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8644 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8648 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8652 obj = G_OBJECT (icon_view->priv->model);
8653 g_signal_connect_data (obj, "row_changed",
8654 (GCallback) gtk_icon_view_accessible_model_row_changed,
8655 icon_view, NULL, 0);
8656 g_signal_connect_data (obj, "row_inserted",
8657 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8658 icon_view, NULL, G_CONNECT_AFTER);
8659 g_signal_connect_data (obj, "row_deleted",
8660 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8661 icon_view, NULL, G_CONNECT_AFTER);
8662 g_signal_connect_data (obj, "rows_reordered",
8663 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8664 icon_view, NULL, G_CONNECT_AFTER);
8668 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8670 GtkIconViewItemAccessibleInfo *info;
8673 items = priv->items;
8676 info = (GtkIconViewItemAccessibleInfo *) items->data;
8677 g_object_unref (info->item);
8678 g_free (items->data);
8679 items = items->next;
8681 g_list_free (priv->items);
8686 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8689 GtkIconView *icon_view;
8692 GtkIconViewAccessiblePrivate *priv;
8694 if (strcmp (pspec->name, "model") == 0)
8696 widget = GTK_WIDGET (obj);
8697 atk_obj = gtk_widget_get_accessible (widget);
8698 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8701 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8702 (gpointer *)&priv->model);
8703 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8705 gtk_icon_view_accessible_clear_cache (priv);
8707 icon_view = GTK_ICON_VIEW (obj);
8708 priv->model = icon_view->priv->model;
8709 /* If there is no model the GtkIconView is probably being destroyed */
8712 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8713 gtk_icon_view_accessible_connect_model_signals (icon_view);
8721 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8724 GtkIconViewAccessiblePrivate *priv;
8725 GtkIconView *icon_view;
8727 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8728 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8730 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8731 g_object_set_qdata (G_OBJECT (accessible),
8732 accessible_private_data_quark,
8735 icon_view = GTK_ICON_VIEW (data);
8736 if (icon_view->priv->hadjustment)
8738 priv->old_hadj = icon_view->priv->hadjustment;
8739 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8740 g_signal_connect (icon_view->priv->hadjustment,
8742 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8745 if (icon_view->priv->vadjustment)
8747 priv->old_vadj = icon_view->priv->vadjustment;
8748 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8749 g_signal_connect (icon_view->priv->vadjustment,
8751 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8754 g_signal_connect_after (data,
8755 "set_scroll_adjustments",
8756 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8758 g_signal_connect (data,
8760 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8763 priv->model = icon_view->priv->model;
8766 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8767 gtk_icon_view_accessible_connect_model_signals (icon_view);
8770 accessible->role = ATK_ROLE_LAYERED_PANE;
8774 gtk_icon_view_accessible_finalize (GObject *object)
8776 GtkIconViewAccessiblePrivate *priv;
8778 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8779 gtk_icon_view_accessible_clear_cache (priv);
8783 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8787 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8788 GtkAccessible *accessible)
8791 GtkIconViewAccessiblePrivate *priv;
8793 atk_obj = ATK_OBJECT (accessible);
8794 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8797 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8798 (gpointer *)&priv->old_hadj);
8800 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8801 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8803 priv->old_hadj = NULL;
8807 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8808 (gpointer *)&priv->old_vadj);
8810 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8811 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8813 priv->old_vadj = NULL;
8818 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8820 if (accessible->widget)
8822 g_signal_connect_after (accessible->widget,
8824 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8827 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8831 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8833 GObjectClass *gobject_class;
8834 GtkAccessibleClass *accessible_class;
8836 accessible_parent_class = g_type_class_peek_parent (klass);
8838 gobject_class = (GObjectClass *)klass;
8839 accessible_class = (GtkAccessibleClass *)klass;
8841 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8843 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8844 klass->ref_child = gtk_icon_view_accessible_ref_child;
8845 klass->initialize = gtk_icon_view_accessible_initialize;
8847 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8849 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8853 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8856 AtkCoordType coord_type)
8859 GtkIconView *icon_view;
8860 GtkIconViewItem *item;
8863 widget = GTK_ACCESSIBLE (component)->widget;
8865 /* State is defunct */
8868 icon_view = GTK_ICON_VIEW (widget);
8869 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8870 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8872 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8878 atk_component_interface_init (AtkComponentIface *iface)
8880 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8884 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8888 GtkIconView *icon_view;
8889 GtkIconViewItem *item;
8891 widget = GTK_ACCESSIBLE (selection)->widget;
8895 icon_view = GTK_ICON_VIEW (widget);
8897 item = g_list_nth_data (icon_view->priv->items, i);
8902 gtk_icon_view_select_item (icon_view, item);
8908 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8911 GtkIconView *icon_view;
8913 widget = GTK_ACCESSIBLE (selection)->widget;
8917 icon_view = GTK_ICON_VIEW (widget);
8918 gtk_icon_view_unselect_all (icon_view);
8924 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8929 GtkIconView *icon_view;
8930 GtkIconViewItem *item;
8932 widget = GTK_ACCESSIBLE (selection)->widget;
8936 icon_view = GTK_ICON_VIEW (widget);
8938 l = icon_view->priv->items;
8945 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8956 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8959 GtkIconView *icon_view;
8960 GtkIconViewItem *item;
8964 widget = GTK_ACCESSIBLE (selection)->widget;
8968 icon_view = GTK_ICON_VIEW (widget);
8970 l = icon_view->priv->items;
8986 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8990 GtkIconView *icon_view;
8991 GtkIconViewItem *item;
8993 widget = GTK_ACCESSIBLE (selection)->widget;
8997 icon_view = GTK_ICON_VIEW (widget);
8999 item = g_list_nth_data (icon_view->priv->items, i);
9003 return item->selected;
9007 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9011 GtkIconView *icon_view;
9012 GtkIconViewItem *item;
9016 widget = GTK_ACCESSIBLE (selection)->widget;
9020 icon_view = GTK_ICON_VIEW (widget);
9021 l = icon_view->priv->items;
9030 gtk_icon_view_unselect_item (icon_view, item);
9042 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9045 GtkIconView *icon_view;
9047 widget = GTK_ACCESSIBLE (selection)->widget;
9051 icon_view = GTK_ICON_VIEW (widget);
9052 gtk_icon_view_select_all (icon_view);
9057 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9059 iface->add_selection = gtk_icon_view_accessible_add_selection;
9060 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9061 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9062 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9063 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9064 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9065 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9069 gtk_icon_view_accessible_get_type (void)
9071 static GType type = 0;
9075 static GTypeInfo tinfo =
9078 (GBaseInitFunc) NULL, /* base init */
9079 (GBaseFinalizeFunc) NULL, /* base finalize */
9080 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9081 (GClassFinalizeFunc) NULL, /* class finalize */
9082 NULL, /* class data */
9083 0, /* instance size */
9084 0, /* nb preallocs */
9085 (GInstanceInitFunc) NULL, /* instance init */
9086 NULL /* value table */
9088 static const GInterfaceInfo atk_component_info =
9090 (GInterfaceInitFunc) atk_component_interface_init,
9091 (GInterfaceFinalizeFunc) NULL,
9094 static const GInterfaceInfo atk_selection_info =
9096 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9097 (GInterfaceFinalizeFunc) NULL,
9102 * Figure out the size of the class and instance
9103 * we are deriving from
9105 AtkObjectFactory *factory;
9108 GType derived_atk_type;
9110 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9111 factory = atk_registry_get_factory (atk_get_default_registry (),
9113 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9114 g_type_query (derived_atk_type, &query);
9115 tinfo.class_size = query.class_size;
9116 tinfo.instance_size = query.instance_size;
9118 type = g_type_register_static (derived_atk_type,
9119 I_("GtkIconViewAccessible"),
9121 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9122 &atk_component_info);
9123 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9124 &atk_selection_info);
9130 gtk_icon_view_accessible_new (GObject *obj)
9132 AtkObject *accessible;
9134 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9136 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9137 atk_object_initialize (accessible, obj);
9143 gtk_icon_view_accessible_factory_get_accessible_type (void)
9145 return gtk_icon_view_accessible_get_type ();
9149 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9151 return gtk_icon_view_accessible_new (obj);
9155 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9157 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9158 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9162 gtk_icon_view_accessible_factory_get_type (void)
9164 static GType type = 0;
9168 const GTypeInfo tinfo =
9170 sizeof (AtkObjectFactoryClass),
9171 NULL, /* base_init */
9172 NULL, /* base_finalize */
9173 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9174 NULL, /* class_finalize */
9175 NULL, /* class_data */
9176 sizeof (AtkObjectFactory),
9177 0, /* n_preallocs */
9181 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9182 I_("GtkIconViewAccessibleFactory"),
9190 gtk_icon_view_get_accessible (GtkWidget *widget)
9192 static gboolean first_time = TRUE;
9196 AtkObjectFactory *factory;
9197 AtkRegistry *registry;
9199 GType derived_atk_type;
9202 * Figure out whether accessibility is enabled by looking at the
9203 * type of the accessible object which would be created for
9204 * the parent type of GtkIconView.
9206 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9208 registry = atk_get_default_registry ();
9209 factory = atk_registry_get_factory (registry,
9211 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9212 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9213 atk_registry_set_factory_type (registry,
9215 gtk_icon_view_accessible_factory_get_type ());
9218 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9221 #define __GTK_ICON_VIEW_C__
9222 #include "gtkaliasdef.c"