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"
37 #include "gtkaccessible.h"
38 #include "gtkwindow.h"
40 #include "gtkcombobox.h"
41 #include "gtktextbuffer.h"
42 #include "gtktreednd.h"
43 #include "gtkprivate.h"
48 * @short_description: A widget which displays a list of icons in a grid
50 * #GtkIconView provides an alternative view on a list model.
51 * It displays the model as a grid of icons with labels. Like
52 * #GtkTreeView, it allows to select one or multiple items
53 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
54 * In addition to selection with the arrow keys, #GtkIconView supports
55 * rubberband selection, which is controlled by dragging the pointer.
58 #undef DEBUG_ICON_VIEW
60 #define SCROLL_EDGE_SIZE 15
62 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
64 typedef struct _GtkIconViewItem GtkIconViewItem;
65 struct _GtkIconViewItem
73 gint x, y, width, height;
76 * box[i] is the actual area occupied by cell i,
77 * before, after are used to calculate the cell
78 * area relative to the box.
79 * See gtk_icon_view_get_cell_area().
87 guint selected_before_rubberbanding : 1;
91 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
92 struct _GtkIconViewCellInfo
94 GtkCellRenderer *cell;
104 GtkCellLayoutDataFunc func;
106 GDestroyNotify destroy;
109 typedef struct _GtkIconViewChild GtkIconViewChild;
110 struct _GtkIconViewChild
113 GtkIconViewItem *item;
117 struct _GtkIconViewPrivate
121 GtkSelectionMode selection_mode;
123 GdkWindow *bin_window;
131 GtkAdjustment *hadjustment;
132 GtkAdjustment *vadjustment;
134 guint layout_idle_id;
136 gboolean doing_rubberband;
137 gint rubberband_x1, rubberband_y1;
138 gint rubberband_x2, rubberband_y2;
139 GdkDevice *rubberband_device;
141 guint scroll_timeout_id;
142 gint scroll_value_diff;
143 gint event_last_x, event_last_y;
145 GtkIconViewItem *anchor_item;
146 GtkIconViewItem *cursor_item;
147 GtkIconViewItem *edited_item;
148 GtkCellEditable *editable;
150 GtkIconViewItem *last_single_clicked;
157 GtkOrientation orientation;
177 GdkModifierType start_button_mask;
182 GdkDragAction source_actions;
183 GdkDragAction dest_actions;
185 GtkTreeRowReference *dest_item;
186 GtkIconViewDropPosition dest_pos;
189 GtkTreeRowReference *scroll_to_path;
190 gfloat scroll_to_row_align;
191 gfloat scroll_to_col_align;
192 guint scroll_to_use_align : 1;
194 guint source_set : 1;
196 guint reorderable : 1;
197 guint empty_view_drop :1;
199 guint ctrl_pressed : 1;
200 guint shift_pressed : 1;
202 guint draw_focus : 1;
215 ACTIVATE_CURSOR_ITEM,
241 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
242 static void gtk_icon_view_finalize (GObject *object);
243 static void gtk_icon_view_set_property (GObject *object,
247 static void gtk_icon_view_get_property (GObject *object,
252 /* GtkObject vfuncs */
253 static void gtk_icon_view_destroy (GtkObject *object);
255 /* GtkWidget vfuncs */
256 static void gtk_icon_view_realize (GtkWidget *widget);
257 static void gtk_icon_view_unrealize (GtkWidget *widget);
258 static void gtk_icon_view_style_set (GtkWidget *widget,
259 GtkStyle *previous_style);
260 static void gtk_icon_view_state_changed (GtkWidget *widget,
261 GtkStateType previous_state);
262 static void gtk_icon_view_size_request (GtkWidget *widget,
263 GtkRequisition *requisition);
264 static void gtk_icon_view_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static gboolean gtk_icon_view_expose (GtkWidget *widget,
267 GdkEventExpose *expose);
268 static gboolean gtk_icon_view_motion (GtkWidget *widget,
269 GdkEventMotion *event);
270 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
273 GdkEventButton *event);
274 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
276 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
278 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
281 /* GtkContainer vfuncs */
282 static void gtk_icon_view_remove (GtkContainer *container,
284 static void gtk_icon_view_forall (GtkContainer *container,
285 gboolean include_internals,
286 GtkCallback callback,
287 gpointer callback_data);
289 /* GtkIconView vfuncs */
290 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
292 GtkAdjustment *vadj);
293 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
294 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
295 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
296 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
297 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
299 /* Internal functions */
300 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
301 GtkIconView *icon_view);
302 static void gtk_icon_view_layout (GtkIconView *icon_view);
303 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
306 GtkIconViewItem *item,
308 GdkDrawable *drawable,
311 gboolean draw_focus);
312 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
315 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
317 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
318 GtkIconViewItem *item);
319 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
320 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
321 GtkIconViewItem *item,
323 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
327 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
328 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
329 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
330 GtkIconViewItem *item,
335 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
336 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
337 GtkIconViewItem *item);
338 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
339 GtkIconViewItem *item,
341 static void gtk_icon_view_update_rubberband (gpointer data);
342 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
343 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
344 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
347 GtkMovementStep step,
349 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
350 GtkMovementStep step,
352 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
354 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
356 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
358 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
360 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static void gtk_icon_view_select_item (GtkIconView *icon_view,
363 GtkIconViewItem *item);
364 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
365 GtkIconViewItem *item);
366 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
367 GtkIconViewItem *anchor,
368 GtkIconViewItem *cursor);
369 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
372 gboolean only_in_cell,
373 GtkIconViewCellInfo **cell_at_pos);
374 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
375 GtkIconViewItem *item,
376 GtkIconViewCellInfo *cell_info,
377 GdkRectangle *cell_area);
378 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
379 GtkIconViewItem *item,
380 GtkIconViewCellInfo *info,
382 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
383 GtkCellRenderer *renderer);
384 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
385 GtkIconViewItem *item);
386 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
387 GtkCellRenderer *renderer,
389 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
390 GtkCellRenderer *renderer,
392 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
393 GtkCellRenderer *renderer,
394 const gchar *attribute,
396 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
397 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
398 GtkCellRenderer *renderer);
399 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
400 GtkCellRenderer *cell,
401 GtkCellLayoutDataFunc func,
403 GDestroyNotify destroy);
404 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
405 GtkCellRenderer *cell,
407 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
409 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
410 GtkIconViewItem *item,
411 GtkIconViewCellInfo *cell_info,
413 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
414 GtkIconViewItem *item);
415 static void gtk_icon_view_put (GtkIconView *icon_view,
417 GtkIconViewItem *item,
419 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
420 GtkIconView *icon_view);
421 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
422 GtkIconViewItem *item,
423 GtkIconViewCellInfo *cell_info,
425 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
426 gboolean cancel_editing);
428 /* Source side drag signals */
429 static void gtk_icon_view_drag_begin (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_icon_view_drag_end (GtkWidget *widget,
432 GdkDragContext *context);
433 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
434 GdkDragContext *context,
435 GtkSelectionData *selection_data,
438 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
439 GdkDragContext *context);
441 /* Target side drag signals */
442 static void gtk_icon_view_drag_leave (GtkWidget *widget,
443 GdkDragContext *context,
445 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
446 GdkDragContext *context,
450 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
451 GdkDragContext *context,
455 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
456 GdkDragContext *context,
459 GtkSelectionData *selection_data,
462 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
463 GdkEventMotion *event);
465 static void remove_scroll_timeout (GtkIconView *icon_view);
467 static void adjust_wrap_width (GtkIconView *icon_view,
468 GtkIconViewItem *item);
471 static GtkBuildableIface *parent_buildable_iface;
472 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
473 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
476 const gchar *tagname,
477 GMarkupParser *parser,
479 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
482 const gchar *tagname,
485 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
487 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
489 gtk_icon_view_cell_layout_init)
490 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
491 gtk_icon_view_buildable_init))
494 gtk_icon_view_class_init (GtkIconViewClass *klass)
496 GObjectClass *gobject_class;
497 GtkObjectClass *object_class;
498 GtkWidgetClass *widget_class;
499 GtkContainerClass *container_class;
500 GtkBindingSet *binding_set;
502 binding_set = gtk_binding_set_by_class (klass);
504 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
506 gobject_class = (GObjectClass *) klass;
507 object_class = (GtkObjectClass *) klass;
508 widget_class = (GtkWidgetClass *) klass;
509 container_class = (GtkContainerClass *) klass;
511 gobject_class->finalize = gtk_icon_view_finalize;
512 gobject_class->set_property = gtk_icon_view_set_property;
513 gobject_class->get_property = gtk_icon_view_get_property;
515 object_class->destroy = gtk_icon_view_destroy;
517 widget_class->realize = gtk_icon_view_realize;
518 widget_class->unrealize = gtk_icon_view_unrealize;
519 widget_class->style_set = gtk_icon_view_style_set;
520 widget_class->get_accessible = gtk_icon_view_get_accessible;
521 widget_class->size_request = gtk_icon_view_size_request;
522 widget_class->size_allocate = gtk_icon_view_size_allocate;
523 widget_class->expose_event = gtk_icon_view_expose;
524 widget_class->motion_notify_event = gtk_icon_view_motion;
525 widget_class->button_press_event = gtk_icon_view_button_press;
526 widget_class->button_release_event = gtk_icon_view_button_release;
527 widget_class->key_press_event = gtk_icon_view_key_press;
528 widget_class->key_release_event = gtk_icon_view_key_release;
529 widget_class->drag_begin = gtk_icon_view_drag_begin;
530 widget_class->drag_end = gtk_icon_view_drag_end;
531 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
532 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
533 widget_class->drag_leave = gtk_icon_view_drag_leave;
534 widget_class->drag_motion = gtk_icon_view_drag_motion;
535 widget_class->drag_drop = gtk_icon_view_drag_drop;
536 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
537 widget_class->state_changed = gtk_icon_view_state_changed;
539 container_class->remove = gtk_icon_view_remove;
540 container_class->forall = gtk_icon_view_forall;
542 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
543 klass->select_all = gtk_icon_view_real_select_all;
544 klass->unselect_all = gtk_icon_view_real_unselect_all;
545 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
546 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
547 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
548 klass->move_cursor = gtk_icon_view_real_move_cursor;
552 * GtkIconView:selection-mode:
554 * The ::selection-mode property specifies the selection mode of
555 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
556 * is enabled, for the other modes, only keyboard selection is possible.
560 g_object_class_install_property (gobject_class,
562 g_param_spec_enum ("selection-mode",
563 P_("Selection mode"),
564 P_("The selection mode"),
565 GTK_TYPE_SELECTION_MODE,
566 GTK_SELECTION_SINGLE,
567 GTK_PARAM_READWRITE));
570 * GtkIconView:pixbuf-column:
572 * The ::pixbuf-column property contains the number of the model column
573 * containing the pixbufs which are displayed. The pixbuf column must be
574 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
575 * display of pixbufs.
579 g_object_class_install_property (gobject_class,
581 g_param_spec_int ("pixbuf-column",
583 P_("Model column used to retrieve the icon pixbuf from"),
585 GTK_PARAM_READWRITE));
588 * GtkIconView:text-column:
590 * The ::text-column property contains the number of the model column
591 * containing the texts which are displayed. The text column must be
592 * of type #G_TYPE_STRING. If this property and the :markup-column
593 * property are both set to -1, no texts are displayed.
597 g_object_class_install_property (gobject_class,
599 g_param_spec_int ("text-column",
601 P_("Model column used to retrieve the text from"),
603 GTK_PARAM_READWRITE));
607 * GtkIconView:markup-column:
609 * The ::markup-column property contains the number of the model column
610 * containing markup information to be displayed. The markup column must be
611 * of type #G_TYPE_STRING. If this property and the :text-column property
612 * are both set to column numbers, it overrides the text column.
613 * If both are set to -1, no texts are displayed.
617 g_object_class_install_property (gobject_class,
619 g_param_spec_int ("markup-column",
621 P_("Model column used to retrieve the text if using Pango markup"),
623 GTK_PARAM_READWRITE));
625 g_object_class_install_property (gobject_class,
627 g_param_spec_object ("model",
628 P_("Icon View Model"),
629 P_("The model for the icon view"),
631 GTK_PARAM_READWRITE));
634 * GtkIconView:columns:
636 * The columns property contains the number of the columns in which the
637 * items should be displayed. If it is -1, the number of columns will
638 * be chosen automatically to fill the available area.
642 g_object_class_install_property (gobject_class,
644 g_param_spec_int ("columns",
645 P_("Number of columns"),
646 P_("Number of columns to display"),
648 GTK_PARAM_READWRITE));
652 * GtkIconView:item-width:
654 * The item-width property specifies the width to use for each item.
655 * If it is set to -1, the icon view will automatically determine a
656 * suitable item size.
660 g_object_class_install_property (gobject_class,
662 g_param_spec_int ("item-width",
663 P_("Width for each item"),
664 P_("The width used for each item"),
666 GTK_PARAM_READWRITE));
669 * GtkIconView:spacing:
671 * The spacing property specifies the space which is inserted between
672 * the cells (i.e. the icon and the text) of an item.
676 g_object_class_install_property (gobject_class,
678 g_param_spec_int ("spacing",
680 P_("Space which is inserted between cells of an item"),
682 GTK_PARAM_READWRITE));
685 * GtkIconView:row-spacing:
687 * The row-spacing property specifies the space which is inserted between
688 * the rows of the icon view.
692 g_object_class_install_property (gobject_class,
694 g_param_spec_int ("row-spacing",
696 P_("Space which is inserted between grid rows"),
698 GTK_PARAM_READWRITE));
701 * GtkIconView:column-spacing:
703 * The column-spacing property specifies the space which is inserted between
704 * the columns of the icon view.
708 g_object_class_install_property (gobject_class,
710 g_param_spec_int ("column-spacing",
711 P_("Column Spacing"),
712 P_("Space which is inserted between grid columns"),
714 GTK_PARAM_READWRITE));
717 * GtkIconView:margin:
719 * The margin property specifies the space which is inserted
720 * at the edges of the icon view.
724 g_object_class_install_property (gobject_class,
726 g_param_spec_int ("margin",
728 P_("Space which is inserted at the edges of the icon view"),
730 GTK_PARAM_READWRITE));
733 * GtkIconView:orientation:
735 * The orientation property specifies how the cells (i.e. the icon and
736 * the text) of the item are positioned relative to each other.
740 g_object_class_install_property (gobject_class,
742 g_param_spec_enum ("orientation",
744 P_("How the text and icon of each item are positioned relative to each other"),
745 GTK_TYPE_ORIENTATION,
746 GTK_ORIENTATION_VERTICAL,
747 GTK_PARAM_READWRITE));
750 * GtkIconView:reorderable:
752 * The reorderable property specifies if the items can be reordered
757 g_object_class_install_property (gobject_class,
759 g_param_spec_boolean ("reorderable",
761 P_("View is reorderable"),
765 g_object_class_install_property (gobject_class,
767 g_param_spec_int ("tooltip-column",
768 P_("Tooltip Column"),
769 P_("The column in the model containing the tooltip texts for the items"),
773 GTK_PARAM_READWRITE));
776 * GtkIconView:item-padding:
778 * The item-padding property specifies the padding around each
779 * of the icon view's item.
783 g_object_class_install_property (gobject_class,
785 g_param_spec_int ("item-padding",
787 P_("Padding around icon view items"),
789 GTK_PARAM_READWRITE));
793 /* Style properties */
794 gtk_widget_class_install_style_property (widget_class,
795 g_param_spec_boxed ("selection-box-color",
796 P_("Selection Box Color"),
797 P_("Color of the selection box"),
799 GTK_PARAM_READABLE));
801 gtk_widget_class_install_style_property (widget_class,
802 g_param_spec_uchar ("selection-box-alpha",
803 P_("Selection Box Alpha"),
804 P_("Opacity of the selection box"),
807 GTK_PARAM_READABLE));
811 * GtkIconView::set-scroll-adjustments
812 * @horizontal: the horizontal #GtkAdjustment
813 * @vertical: the vertical #GtkAdjustment
815 * Set the scroll adjustments for the icon view. Usually scrolled containers
816 * like #GtkScrolledWindow will emit this signal to connect two instances
817 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
819 widget_class->set_scroll_adjustments_signal =
820 g_signal_new (I_("set-scroll-adjustments"),
821 G_TYPE_FROM_CLASS (gobject_class),
823 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
825 _gtk_marshal_VOID__OBJECT_OBJECT,
827 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
830 * GtkIconView::item-activated:
831 * @iconview: the object on which the signal is emitted
832 * @path: the #GtkTreePath for the activated item
834 * The ::item-activated signal is emitted when the method
835 * gtk_icon_view_item_activated() is called or the user double
836 * clicks an item. It is also emitted when a non-editable item
837 * is selected and one of the keys: Space, Return or Enter is
840 icon_view_signals[ITEM_ACTIVATED] =
841 g_signal_new (I_("item-activated"),
842 G_TYPE_FROM_CLASS (gobject_class),
844 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
846 g_cclosure_marshal_VOID__BOXED,
851 * GtkIconView::selection-changed:
852 * @iconview: the object on which the signal is emitted
854 * The ::selection-changed signal is emitted when the selection
855 * (i.e. the set of selected items) changes.
857 icon_view_signals[SELECTION_CHANGED] =
858 g_signal_new (I_("selection-changed"),
859 G_TYPE_FROM_CLASS (gobject_class),
861 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
863 g_cclosure_marshal_VOID__VOID,
867 * GtkIconView::select-all:
868 * @iconview: the object on which the signal is emitted
870 * A <link linkend="keybinding-signals">keybinding signal</link>
871 * which gets emitted when the user selects all items.
873 * Applications should not connect to it, but may emit it with
874 * g_signal_emit_by_name() if they need to control selection
877 * The default binding for this signal is Ctrl-a.
879 icon_view_signals[SELECT_ALL] =
880 g_signal_new (I_("select-all"),
881 G_TYPE_FROM_CLASS (gobject_class),
882 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
883 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
885 g_cclosure_marshal_VOID__VOID,
889 * GtkIconView::unselect-all:
890 * @iconview: the object on which the signal is emitted
892 * A <link linkend="keybinding-signals">keybinding signal</link>
893 * which gets emitted when the user unselects all items.
895 * Applications should not connect to it, but may emit it with
896 * g_signal_emit_by_name() if they need to control selection
899 * The default binding for this signal is Ctrl-Shift-a.
901 icon_view_signals[UNSELECT_ALL] =
902 g_signal_new (I_("unselect-all"),
903 G_TYPE_FROM_CLASS (gobject_class),
904 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
905 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
907 g_cclosure_marshal_VOID__VOID,
911 * GtkIconView::select-cursor-item:
912 * @iconview: the object on which the signal is emitted
914 * A <link linkend="keybinding-signals">keybinding signal</link>
915 * which gets emitted when the user selects the item that is currently
918 * Applications should not connect to it, but may emit it with
919 * g_signal_emit_by_name() if they need to control selection
922 * There is no default binding for this signal.
924 icon_view_signals[SELECT_CURSOR_ITEM] =
925 g_signal_new (I_("select-cursor-item"),
926 G_TYPE_FROM_CLASS (gobject_class),
927 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
928 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
930 g_cclosure_marshal_VOID__VOID,
934 * GtkIconView::toggle-cursor-item:
935 * @iconview: the object on which the signal is emitted
937 * A <link linkend="keybinding-signals">keybinding signal</link>
938 * which gets emitted when the user toggles whether the currently
939 * focused item is selected or not. The exact effect of this
940 * depend on the selection mode.
942 * Applications should not connect to it, but may emit it with
943 * g_signal_emit_by_name() if they need to control selection
946 * There is no default binding for this signal is Ctrl-Space.
948 icon_view_signals[TOGGLE_CURSOR_ITEM] =
949 g_signal_new (I_("toggle-cursor-item"),
950 G_TYPE_FROM_CLASS (gobject_class),
951 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
952 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
954 g_cclosure_marshal_VOID__VOID,
958 * GtkIconView::activate-cursor-item:
959 * @iconview: the object on which the signal is emitted
961 * A <link linkend="keybinding-signals">keybinding signal</link>
962 * which gets emitted when the user activates the currently
965 * Applications should not connect to it, but may emit it with
966 * g_signal_emit_by_name() if they need to control activation
969 * The default bindings for this signal are Space, Return and Enter.
971 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
972 g_signal_new (I_("activate-cursor-item"),
973 G_TYPE_FROM_CLASS (gobject_class),
974 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
975 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
977 _gtk_marshal_BOOLEAN__VOID,
981 * GtkIconView::move-cursor:
982 * @iconview: the object which received the signal
983 * @step: the granularity of the move, as a #GtkMovementStep
984 * @count: the number of @step units to move
986 * The ::move-cursor signal is a
987 * <link linkend="keybinding-signals">keybinding signal</link>
988 * which gets emitted when the user initiates a cursor movement.
990 * Applications should not connect to it, but may emit it with
991 * g_signal_emit_by_name() if they need to control the cursor
994 * The default bindings for this signal include
996 * <listitem>Arrow keys which move by individual steps</listitem>
997 * <listitem>Home/End keys which move to the first/last item</listitem>
998 * <listitem>PageUp/PageDown which move by "pages"</listitem>
1001 * All of these will extend the selection when combined with
1002 * the Shift modifier.
1004 icon_view_signals[MOVE_CURSOR] =
1005 g_signal_new (I_("move-cursor"),
1006 G_TYPE_FROM_CLASS (gobject_class),
1007 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1008 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1010 _gtk_marshal_BOOLEAN__ENUM_INT,
1012 GTK_TYPE_MOVEMENT_STEP,
1016 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1018 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1020 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1021 "toggle-cursor-item", 0);
1022 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1023 "toggle-cursor-item", 0);
1025 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1026 "activate-cursor-item", 0);
1027 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1028 "activate-cursor-item", 0);
1029 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1030 "activate-cursor-item", 0);
1031 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1032 "activate-cursor-item", 0);
1033 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1034 "activate-cursor-item", 0);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1037 GTK_MOVEMENT_DISPLAY_LINES, -1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1039 GTK_MOVEMENT_DISPLAY_LINES, -1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1042 GTK_MOVEMENT_DISPLAY_LINES, 1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1044 GTK_MOVEMENT_DISPLAY_LINES, 1);
1046 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1047 GTK_MOVEMENT_DISPLAY_LINES, -1);
1049 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1050 GTK_MOVEMENT_DISPLAY_LINES, 1);
1052 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1053 GTK_MOVEMENT_BUFFER_ENDS, -1);
1054 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1055 GTK_MOVEMENT_BUFFER_ENDS, -1);
1057 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1058 GTK_MOVEMENT_BUFFER_ENDS, 1);
1059 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1060 GTK_MOVEMENT_BUFFER_ENDS, 1);
1062 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1063 GTK_MOVEMENT_PAGES, -1);
1064 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1065 GTK_MOVEMENT_PAGES, -1);
1067 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1068 GTK_MOVEMENT_PAGES, 1);
1069 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1070 GTK_MOVEMENT_PAGES, 1);
1072 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1073 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1074 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1075 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1077 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1078 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1079 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1080 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1084 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1086 parent_buildable_iface = g_type_interface_peek_parent (iface);
1087 iface->add_child = _gtk_cell_layout_buildable_add_child;
1088 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1089 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1093 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1095 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1096 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1097 iface->clear = gtk_icon_view_cell_layout_clear;
1098 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1099 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1100 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1101 iface->reorder = gtk_icon_view_cell_layout_reorder;
1102 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1106 gtk_icon_view_init (GtkIconView *icon_view)
1108 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1110 icon_view->priv->width = 0;
1111 icon_view->priv->height = 0;
1112 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1113 icon_view->priv->pressed_button = -1;
1114 icon_view->priv->press_start_x = -1;
1115 icon_view->priv->press_start_y = -1;
1116 icon_view->priv->text_column = -1;
1117 icon_view->priv->markup_column = -1;
1118 icon_view->priv->pixbuf_column = -1;
1119 icon_view->priv->text_cell = -1;
1120 icon_view->priv->pixbuf_cell = -1;
1121 icon_view->priv->tooltip_column = -1;
1123 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1125 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1127 icon_view->priv->cell_list = NULL;
1128 icon_view->priv->n_cells = 0;
1129 icon_view->priv->cursor_cell = -1;
1131 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1133 icon_view->priv->columns = -1;
1134 icon_view->priv->item_width = -1;
1135 icon_view->priv->spacing = 0;
1136 icon_view->priv->row_spacing = 6;
1137 icon_view->priv->column_spacing = 6;
1138 icon_view->priv->margin = 6;
1139 icon_view->priv->item_padding = 6;
1141 icon_view->priv->draw_focus = TRUE;
1145 gtk_icon_view_destroy (GtkObject *object)
1147 GtkIconView *icon_view;
1149 icon_view = GTK_ICON_VIEW (object);
1151 gtk_icon_view_stop_editing (icon_view, TRUE);
1153 gtk_icon_view_set_model (icon_view, NULL);
1155 if (icon_view->priv->layout_idle_id != 0)
1157 g_source_remove (icon_view->priv->layout_idle_id);
1158 icon_view->priv->layout_idle_id = 0;
1161 if (icon_view->priv->scroll_to_path != NULL)
1163 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1164 icon_view->priv->scroll_to_path = NULL;
1167 remove_scroll_timeout (icon_view);
1169 if (icon_view->priv->hadjustment != NULL)
1171 g_object_unref (icon_view->priv->hadjustment);
1172 icon_view->priv->hadjustment = NULL;
1175 if (icon_view->priv->vadjustment != NULL)
1177 g_object_unref (icon_view->priv->vadjustment);
1178 icon_view->priv->vadjustment = NULL;
1181 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1184 /* GObject methods */
1186 gtk_icon_view_finalize (GObject *object)
1188 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1190 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1195 gtk_icon_view_set_property (GObject *object,
1197 const GValue *value,
1200 GtkIconView *icon_view;
1202 icon_view = GTK_ICON_VIEW (object);
1206 case PROP_SELECTION_MODE:
1207 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1209 case PROP_PIXBUF_COLUMN:
1210 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1212 case PROP_TEXT_COLUMN:
1213 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1215 case PROP_MARKUP_COLUMN:
1216 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1219 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1221 case PROP_ORIENTATION:
1222 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1225 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1227 case PROP_ITEM_WIDTH:
1228 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1231 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1233 case PROP_ROW_SPACING:
1234 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1236 case PROP_COLUMN_SPACING:
1237 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1240 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1242 case PROP_REORDERABLE:
1243 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1246 case PROP_TOOLTIP_COLUMN:
1247 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1250 case PROP_ITEM_PADDING:
1251 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1255 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1261 gtk_icon_view_get_property (GObject *object,
1266 GtkIconView *icon_view;
1268 icon_view = GTK_ICON_VIEW (object);
1272 case PROP_SELECTION_MODE:
1273 g_value_set_enum (value, icon_view->priv->selection_mode);
1275 case PROP_PIXBUF_COLUMN:
1276 g_value_set_int (value, icon_view->priv->pixbuf_column);
1278 case PROP_TEXT_COLUMN:
1279 g_value_set_int (value, icon_view->priv->text_column);
1281 case PROP_MARKUP_COLUMN:
1282 g_value_set_int (value, icon_view->priv->markup_column);
1285 g_value_set_object (value, icon_view->priv->model);
1287 case PROP_ORIENTATION:
1288 g_value_set_enum (value, icon_view->priv->orientation);
1291 g_value_set_int (value, icon_view->priv->columns);
1293 case PROP_ITEM_WIDTH:
1294 g_value_set_int (value, icon_view->priv->item_width);
1297 g_value_set_int (value, icon_view->priv->spacing);
1299 case PROP_ROW_SPACING:
1300 g_value_set_int (value, icon_view->priv->row_spacing);
1302 case PROP_COLUMN_SPACING:
1303 g_value_set_int (value, icon_view->priv->column_spacing);
1306 g_value_set_int (value, icon_view->priv->margin);
1308 case PROP_REORDERABLE:
1309 g_value_set_boolean (value, icon_view->priv->reorderable);
1311 case PROP_TOOLTIP_COLUMN:
1312 g_value_set_int (value, icon_view->priv->tooltip_column);
1315 case PROP_ITEM_PADDING:
1316 g_value_set_int (value, icon_view->priv->item_padding);
1320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1325 /* GtkWidget signals */
1327 gtk_icon_view_realize (GtkWidget *widget)
1329 GtkIconView *icon_view;
1330 GdkWindowAttr attributes;
1331 gint attributes_mask;
1333 icon_view = GTK_ICON_VIEW (widget);
1335 gtk_widget_set_realized (widget, TRUE);
1337 /* Make the main, clipping window */
1338 attributes.window_type = GDK_WINDOW_CHILD;
1339 attributes.x = widget->allocation.x;
1340 attributes.y = widget->allocation.y;
1341 attributes.width = widget->allocation.width;
1342 attributes.height = widget->allocation.height;
1343 attributes.wclass = GDK_INPUT_OUTPUT;
1344 attributes.visual = gtk_widget_get_visual (widget);
1345 attributes.colormap = gtk_widget_get_colormap (widget);
1346 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1348 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1350 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1351 &attributes, attributes_mask);
1352 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1353 gdk_window_set_user_data (widget->window, widget);
1355 /* Make the window for the icon view */
1358 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1359 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1360 attributes.event_mask = (GDK_EXPOSURE_MASK |
1362 GDK_POINTER_MOTION_MASK |
1363 GDK_BUTTON_PRESS_MASK |
1364 GDK_BUTTON_RELEASE_MASK |
1365 GDK_KEY_PRESS_MASK |
1366 GDK_KEY_RELEASE_MASK) |
1367 gtk_widget_get_events (widget);
1369 icon_view->priv->bin_window = gdk_window_new (widget->window,
1370 &attributes, attributes_mask);
1371 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1373 widget->style = gtk_style_attach (widget->style, widget->window);
1374 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1376 gdk_window_show (icon_view->priv->bin_window);
1380 gtk_icon_view_unrealize (GtkWidget *widget)
1382 GtkIconView *icon_view;
1384 icon_view = GTK_ICON_VIEW (widget);
1386 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1387 gdk_window_destroy (icon_view->priv->bin_window);
1388 icon_view->priv->bin_window = NULL;
1390 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1394 gtk_icon_view_state_changed (GtkWidget *widget,
1395 GtkStateType previous_state)
1397 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1399 if (gtk_widget_get_realized (widget))
1401 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1402 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1405 gtk_widget_queue_draw (widget);
1409 gtk_icon_view_style_set (GtkWidget *widget,
1410 GtkStyle *previous_style)
1412 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1414 if (gtk_widget_get_realized (widget))
1416 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1417 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1420 gtk_widget_queue_resize (widget);
1424 gtk_icon_view_size_request (GtkWidget *widget,
1425 GtkRequisition *requisition)
1427 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1430 requisition->width = icon_view->priv->width;
1431 requisition->height = icon_view->priv->height;
1433 tmp_list = icon_view->priv->children;
1437 GtkIconViewChild *child = tmp_list->data;
1438 GtkRequisition child_requisition;
1440 tmp_list = tmp_list->next;
1442 if (gtk_widget_get_visible (child->widget))
1443 gtk_widget_size_request (child->widget, &child_requisition);
1448 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1452 for (list = icon_view->priv->children; list; list = list->next)
1454 GtkIconViewChild *child = list->data;
1455 GtkAllocation allocation;
1457 /* totally ignore our child's requisition */
1458 if (child->cell < 0)
1460 allocation.x = child->item->x + icon_view->priv->item_padding;
1461 allocation.y = child->item->y + icon_view->priv->item_padding;
1462 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1463 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1467 GdkRectangle *box = &child->item->box[child->cell];
1469 allocation.x = box->x;
1470 allocation.y = box->y;
1471 allocation.width = box->width;
1472 allocation.height = box->height;
1475 gtk_widget_size_allocate (child->widget, &allocation);
1480 gtk_icon_view_size_allocate (GtkWidget *widget,
1481 GtkAllocation *allocation)
1483 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1485 GtkAdjustment *hadjustment, *vadjustment;
1487 widget->allocation = *allocation;
1489 if (gtk_widget_get_realized (widget))
1491 gdk_window_move_resize (widget->window,
1492 allocation->x, allocation->y,
1493 allocation->width, allocation->height);
1494 gdk_window_resize (icon_view->priv->bin_window,
1495 MAX (icon_view->priv->width, allocation->width),
1496 MAX (icon_view->priv->height, allocation->height));
1499 gtk_icon_view_layout (icon_view);
1501 gtk_icon_view_allocate_children (icon_view);
1503 hadjustment = icon_view->priv->hadjustment;
1504 vadjustment = icon_view->priv->vadjustment;
1506 hadjustment->page_size = allocation->width;
1507 hadjustment->page_increment = allocation->width * 0.9;
1508 hadjustment->step_increment = allocation->width * 0.1;
1509 hadjustment->lower = 0;
1510 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1512 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1513 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1515 vadjustment->page_size = allocation->height;
1516 vadjustment->page_increment = allocation->height * 0.9;
1517 vadjustment->step_increment = allocation->height * 0.1;
1518 vadjustment->lower = 0;
1519 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1521 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1522 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1524 if (gtk_widget_get_realized (widget) &&
1525 icon_view->priv->scroll_to_path)
1528 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1529 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1530 icon_view->priv->scroll_to_path = NULL;
1532 gtk_icon_view_scroll_to_path (icon_view, path,
1533 icon_view->priv->scroll_to_use_align,
1534 icon_view->priv->scroll_to_row_align,
1535 icon_view->priv->scroll_to_col_align);
1536 gtk_tree_path_free (path);
1540 gtk_adjustment_changed (hadjustment);
1541 gtk_adjustment_changed (vadjustment);
1546 gtk_icon_view_expose (GtkWidget *widget,
1547 GdkEventExpose *expose)
1549 GtkIconView *icon_view;
1554 GtkIconViewDropPosition dest_pos;
1555 GtkIconViewItem *dest_item = NULL;
1557 icon_view = GTK_ICON_VIEW (widget);
1559 if (expose->window != icon_view->priv->bin_window)
1562 /* If a layout has been scheduled, do it now so that all
1563 * cell view items have valid sizes before we proceed. */
1564 if (icon_view->priv->layout_idle_id != 0)
1565 gtk_icon_view_layout (icon_view);
1567 cr = gdk_cairo_create (icon_view->priv->bin_window);
1568 cairo_set_line_width (cr, 1.);
1570 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1574 dest_index = gtk_tree_path_get_indices (path)[0];
1575 gtk_tree_path_free (path);
1580 for (icons = icon_view->priv->items; icons; icons = icons->next)
1582 GtkIconViewItem *item = icons->data;
1587 area.width = item->width;
1588 area.height = item->height;
1590 if (cairo_region_contains_rectangle (expose->region, &area) == CAIRO_REGION_OVERLAP_OUT)
1593 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1594 icon_view->priv->bin_window,
1596 icon_view->priv->draw_focus);
1598 if (dest_index == item->index)
1606 case GTK_ICON_VIEW_DROP_INTO:
1607 gtk_paint_focus (widget->style,
1608 icon_view->priv->bin_window,
1609 gtk_widget_get_state (widget),
1612 "iconview-drop-indicator",
1613 dest_item->x, dest_item->y,
1614 dest_item->width, dest_item->height);
1616 case GTK_ICON_VIEW_DROP_ABOVE:
1617 gtk_paint_focus (widget->style,
1618 icon_view->priv->bin_window,
1619 gtk_widget_get_state (widget),
1622 "iconview-drop-indicator",
1623 dest_item->x, dest_item->y - 1,
1624 dest_item->width, 2);
1626 case GTK_ICON_VIEW_DROP_LEFT:
1627 gtk_paint_focus (widget->style,
1628 icon_view->priv->bin_window,
1629 gtk_widget_get_state (widget),
1632 "iconview-drop-indicator",
1633 dest_item->x - 1, dest_item->y,
1634 2, dest_item->height);
1636 case GTK_ICON_VIEW_DROP_BELOW:
1637 gtk_paint_focus (widget->style,
1638 icon_view->priv->bin_window,
1639 gtk_widget_get_state (widget),
1642 "iconview-drop-indicator",
1643 dest_item->x, dest_item->y + dest_item->height - 1,
1644 dest_item->width, 2);
1646 case GTK_ICON_VIEW_DROP_RIGHT:
1647 gtk_paint_focus (widget->style,
1648 icon_view->priv->bin_window,
1649 gtk_widget_get_state (widget),
1652 "iconview-drop-indicator",
1653 dest_item->x + dest_item->width - 1, dest_item->y,
1654 2, dest_item->height);
1655 case GTK_ICON_VIEW_NO_DROP: ;
1660 if (icon_view->priv->doing_rubberband)
1662 cairo_rectangle_int_t rectangle;
1665 n_rectangles = cairo_region_num_rectangles (expose->region);
1667 while (n_rectangles--)
1669 cairo_region_get_rectangle (expose->region, n_rectangles, &rectangle);
1670 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangle);
1676 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1682 rubberband_scroll_timeout (gpointer data)
1684 GtkIconView *icon_view = data;
1686 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1687 icon_view->priv->vadjustment->value +
1688 icon_view->priv->scroll_value_diff);
1690 gtk_icon_view_update_rubberband (icon_view);
1696 gtk_icon_view_motion (GtkWidget *widget,
1697 GdkEventMotion *event)
1699 GtkIconView *icon_view;
1702 icon_view = GTK_ICON_VIEW (widget);
1704 gtk_icon_view_maybe_begin_drag (icon_view, event);
1706 if (icon_view->priv->doing_rubberband)
1708 gtk_icon_view_update_rubberband (widget);
1710 abs_y = event->y - icon_view->priv->height *
1711 (icon_view->priv->vadjustment->value /
1712 (icon_view->priv->vadjustment->upper -
1713 icon_view->priv->vadjustment->lower));
1715 if (abs_y < 0 || abs_y > widget->allocation.height)
1718 icon_view->priv->scroll_value_diff = abs_y;
1720 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1722 icon_view->priv->event_last_x = event->x;
1723 icon_view->priv->event_last_y = event->y;
1725 if (icon_view->priv->scroll_timeout_id == 0)
1726 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1730 remove_scroll_timeout (icon_view);
1737 gtk_icon_view_remove (GtkContainer *container,
1740 GtkIconView *icon_view;
1741 GtkIconViewChild *child = NULL;
1744 icon_view = GTK_ICON_VIEW (container);
1746 tmp_list = icon_view->priv->children;
1749 child = tmp_list->data;
1750 if (child->widget == widget)
1752 gtk_widget_unparent (widget);
1754 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1755 g_list_free_1 (tmp_list);
1760 tmp_list = tmp_list->next;
1765 gtk_icon_view_forall (GtkContainer *container,
1766 gboolean include_internals,
1767 GtkCallback callback,
1768 gpointer callback_data)
1770 GtkIconView *icon_view;
1771 GtkIconViewChild *child = NULL;
1774 icon_view = GTK_ICON_VIEW (container);
1776 tmp_list = icon_view->priv->children;
1779 child = tmp_list->data;
1780 tmp_list = tmp_list->next;
1782 (* callback) (child->widget, callback_data);
1787 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1788 GtkIconViewItem *item,
1789 GtkIconViewCellInfo *info,
1794 GdkRectangle cell_area;
1795 gboolean visible, mode;
1797 gtk_icon_view_set_cell_data (icon_view, item);
1799 g_object_get (info->cell,
1800 "visible", &visible,
1804 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1806 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1808 path = gtk_tree_path_new_from_indices (item->index, -1);
1809 path_string = gtk_tree_path_to_string (path);
1810 gtk_tree_path_free (path);
1812 gtk_cell_renderer_activate (info->cell,
1814 GTK_WIDGET (icon_view),
1820 g_free (path_string);
1825 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1826 GtkIconViewItem *item)
1829 AtkObject *item_obj;
1831 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1834 item_obj = atk_object_ref_accessible_child (obj, item->index);
1835 if (item_obj != NULL)
1837 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1838 g_object_unref (item_obj);
1844 gtk_icon_view_put (GtkIconView *icon_view,
1846 GtkIconViewItem *item,
1849 GtkIconViewChild *child;
1851 child = g_new (GtkIconViewChild, 1);
1853 child->widget = widget;
1857 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1859 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1860 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1862 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1866 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1867 GtkIconView *icon_view)
1870 GtkIconViewItem *item;
1872 if (icon_view->priv->edited_item == NULL)
1875 item = icon_view->priv->edited_item;
1876 icon_view->priv->edited_item = NULL;
1877 icon_view->priv->editable = NULL;
1878 for (l = icon_view->priv->cell_list; l; l = l->next)
1880 GtkIconViewCellInfo *info = l->data;
1882 info->editing = FALSE;
1885 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1886 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1888 g_signal_handlers_disconnect_by_func (editable,
1889 gtk_icon_view_remove_widget,
1892 gtk_container_remove (GTK_CONTAINER (icon_view),
1893 GTK_WIDGET (editable));
1895 gtk_icon_view_queue_draw_item (icon_view, item);
1900 gtk_icon_view_start_editing (GtkIconView *icon_view,
1901 GtkIconViewItem *item,
1902 GtkIconViewCellInfo *info,
1907 GdkRectangle cell_area;
1908 gboolean visible, mode;
1909 GtkCellEditable *editable;
1911 gtk_icon_view_set_cell_data (icon_view, item);
1913 g_object_get (info->cell,
1914 "visible", &visible,
1917 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1919 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1921 path = gtk_tree_path_new_from_indices (item->index, -1);
1922 path_string = gtk_tree_path_to_string (path);
1923 gtk_tree_path_free (path);
1925 editable = gtk_cell_renderer_start_editing (info->cell,
1927 GTK_WIDGET (icon_view),
1932 g_free (path_string);
1934 /* the rest corresponds to tree_view_real_start_editing... */
1935 icon_view->priv->edited_item = item;
1936 icon_view->priv->editable = editable;
1937 info->editing = TRUE;
1939 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1941 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1943 gtk_widget_grab_focus (GTK_WIDGET (editable));
1944 g_signal_connect (editable, "remove-widget",
1945 G_CALLBACK (gtk_icon_view_remove_widget),
1952 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1953 gboolean cancel_editing)
1955 GtkCellRenderer *cell = NULL;
1956 GtkIconViewItem *item;
1959 if (icon_view->priv->edited_item == NULL)
1963 * This is very evil. We need to do this, because
1964 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1965 * later on. If gtk_icon_view_row_changed notices
1966 * icon_view->priv->edited_item != NULL, it'll call
1967 * gtk_icon_view_stop_editing again. Bad things will happen then.
1969 * Please read that again if you intend to modify anything here.
1972 item = icon_view->priv->edited_item;
1973 icon_view->priv->edited_item = NULL;
1975 for (l = icon_view->priv->cell_list; l; l = l->next)
1977 GtkIconViewCellInfo *info = l->data;
1989 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1990 if (!cancel_editing)
1991 gtk_cell_editable_editing_done (icon_view->priv->editable);
1993 icon_view->priv->edited_item = item;
1995 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1999 * gtk_icon_view_set_cursor:
2000 * @icon_view: A #GtkIconView
2001 * @path: A #GtkTreePath
2002 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2003 * @start_editing: %TRUE if the specified cell should start being edited.
2005 * Sets the current keyboard focus to be at @path, and selects it. This is
2006 * useful when you want to focus the user's attention on a particular item.
2007 * If @cell is not %NULL, then focus is given to the cell specified by
2008 * it. Additionally, if @start_editing is %TRUE, then editing should be
2009 * started in the specified cell.
2011 * This function is often followed by <literal>gtk_widget_grab_focus
2012 * (icon_view)</literal> in order to give keyboard focus to the widget.
2013 * Please note that editing can only happen when the widget is realized.
2018 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2020 GtkCellRenderer *cell,
2021 gboolean start_editing)
2023 GtkIconViewItem *item = NULL;
2024 GtkIconViewCellInfo *info = NULL;
2028 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2029 g_return_if_fail (path != NULL);
2030 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2032 gtk_icon_view_stop_editing (icon_view, TRUE);
2034 if (gtk_tree_path_get_depth (path) == 1)
2035 item = g_list_nth_data (icon_view->priv->items,
2036 gtk_tree_path_get_indices(path)[0]);
2042 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2046 if (info->cell == cell)
2055 g_return_if_fail (cell == NULL || info != NULL);
2057 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2058 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2060 if (info && start_editing)
2061 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2065 * gtk_icon_view_get_cursor:
2066 * @icon_view: A #GtkIconView
2067 * @path: (allow-none): Return location for the current cursor path, or %NULL
2068 * @cell: (allow-none): Return location the current focus cell, or %NULL
2070 * Fills in @path and @cell with the current cursor path and cell.
2071 * If the cursor isn't currently set, then *@path will be %NULL.
2072 * If no cell currently has focus, then *@cell will be %NULL.
2074 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2076 * Return value: %TRUE if the cursor is set.
2081 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2083 GtkCellRenderer **cell)
2085 GtkIconViewItem *item;
2086 GtkIconViewCellInfo *info;
2088 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2090 item = icon_view->priv->cursor_item;
2091 if (icon_view->priv->cursor_cell < 0)
2094 info = g_list_nth_data (icon_view->priv->cell_list,
2095 icon_view->priv->cursor_cell);
2100 *path = gtk_tree_path_new_from_indices (item->index, -1);
2113 return (item != NULL);
2117 gtk_icon_view_button_press (GtkWidget *widget,
2118 GdkEventButton *event)
2120 GtkIconView *icon_view;
2121 GtkIconViewItem *item;
2122 GtkIconViewCellInfo *info = NULL;
2123 gboolean dirty = FALSE;
2124 GtkCellRendererMode mode;
2125 gint cursor_cell = -1;
2127 icon_view = GTK_ICON_VIEW (widget);
2129 if (event->window != icon_view->priv->bin_window)
2132 if (!gtk_widget_has_focus (widget))
2133 gtk_widget_grab_focus (widget);
2135 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2137 item = gtk_icon_view_get_item_at_coords (icon_view,
2143 * We consider only the the cells' area as the item area if the
2144 * item is not selected, but if it *is* selected, the complete
2145 * selection rectangle is considered to be part of the item.
2147 if (item != NULL && (info != NULL || item->selected))
2151 g_object_get (info->cell, "mode", &mode, NULL);
2153 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2154 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2155 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2158 gtk_icon_view_scroll_to_item (icon_view, item);
2160 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2162 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2164 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2165 (event->state & GDK_SHIFT_MASK))
2167 gtk_icon_view_unselect_all_internal (icon_view);
2169 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2170 if (!icon_view->priv->anchor_item)
2171 icon_view->priv->anchor_item = item;
2173 gtk_icon_view_select_all_between (icon_view,
2174 icon_view->priv->anchor_item,
2180 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2181 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2182 (event->state & GDK_CONTROL_MASK))
2184 item->selected = !item->selected;
2185 gtk_icon_view_queue_draw_item (icon_view, item);
2190 gtk_icon_view_unselect_all_internal (icon_view);
2192 item->selected = TRUE;
2193 gtk_icon_view_queue_draw_item (icon_view, item);
2196 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2197 icon_view->priv->anchor_item = item;
2200 /* Save press to possibly begin a drag */
2201 if (icon_view->priv->pressed_button < 0)
2203 icon_view->priv->pressed_button = event->button;
2204 icon_view->priv->press_start_x = event->x;
2205 icon_view->priv->press_start_y = event->y;
2208 if (!icon_view->priv->last_single_clicked)
2209 icon_view->priv->last_single_clicked = item;
2211 /* cancel the current editing, if it exists */
2212 gtk_icon_view_stop_editing (icon_view, TRUE);
2216 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2217 gtk_icon_view_item_activate_cell (icon_view, item, info,
2219 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2220 gtk_icon_view_start_editing (icon_view, item, info,
2226 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2227 !(event->state & GDK_CONTROL_MASK))
2229 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2232 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2233 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2236 /* don't draw keyboard focus around an clicked-on item */
2237 icon_view->priv->draw_focus = FALSE;
2240 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2242 item = gtk_icon_view_get_item_at_coords (icon_view,
2247 if (item && item == icon_view->priv->last_single_clicked)
2251 path = gtk_tree_path_new_from_indices (item->index, -1);
2252 gtk_icon_view_item_activated (icon_view, path);
2253 gtk_tree_path_free (path);
2256 icon_view->priv->last_single_clicked = NULL;
2257 icon_view->priv->pressed_button = -1;
2261 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2263 return event->button == 1;
2267 gtk_icon_view_button_release (GtkWidget *widget,
2268 GdkEventButton *event)
2270 GtkIconView *icon_view;
2272 icon_view = GTK_ICON_VIEW (widget);
2274 if (icon_view->priv->pressed_button == event->button)
2275 icon_view->priv->pressed_button = -1;
2277 gtk_icon_view_stop_rubberbanding (icon_view);
2279 remove_scroll_timeout (icon_view);
2285 gtk_icon_view_key_press (GtkWidget *widget,
2288 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2290 if (icon_view->priv->doing_rubberband)
2292 if (event->keyval == GDK_Escape)
2293 gtk_icon_view_stop_rubberbanding (icon_view);
2298 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2302 gtk_icon_view_key_release (GtkWidget *widget,
2305 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2307 if (icon_view->priv->doing_rubberband)
2310 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2314 gtk_icon_view_update_rubberband (gpointer data)
2316 GtkIconView *icon_view;
2318 GdkRectangle old_area;
2319 GdkRectangle new_area;
2320 GdkRectangle common;
2321 cairo_region_t *invalid_region;
2323 icon_view = GTK_ICON_VIEW (data);
2325 gdk_window_get_device_position (icon_view->priv->bin_window,
2326 icon_view->priv->rubberband_device,
2332 old_area.x = MIN (icon_view->priv->rubberband_x1,
2333 icon_view->priv->rubberband_x2);
2334 old_area.y = MIN (icon_view->priv->rubberband_y1,
2335 icon_view->priv->rubberband_y2);
2336 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2337 icon_view->priv->rubberband_x1) + 1;
2338 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2339 icon_view->priv->rubberband_y1) + 1;
2341 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2342 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2343 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2344 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2346 invalid_region = cairo_region_create_rectangle (&old_area);
2347 cairo_region_union_rectangle (invalid_region, &new_area);
2349 gdk_rectangle_intersect (&old_area, &new_area, &common);
2350 if (common.width > 2 && common.height > 2)
2352 cairo_region_t *common_region;
2354 /* make sure the border is invalidated */
2360 common_region = cairo_region_create_rectangle (&common);
2362 cairo_region_subtract (invalid_region, common_region);
2363 cairo_region_destroy (common_region);
2366 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2368 cairo_region_destroy (invalid_region);
2370 icon_view->priv->rubberband_x2 = x;
2371 icon_view->priv->rubberband_y2 = y;
2373 gtk_icon_view_update_rubberband_selection (icon_view);
2377 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2384 if (icon_view->priv->rubberband_device)
2387 for (items = icon_view->priv->items; items; items = items->next)
2389 GtkIconViewItem *item = items->data;
2391 item->selected_before_rubberbanding = item->selected;
2394 icon_view->priv->rubberband_x1 = x;
2395 icon_view->priv->rubberband_y1 = y;
2396 icon_view->priv->rubberband_x2 = x;
2397 icon_view->priv->rubberband_y2 = y;
2399 icon_view->priv->doing_rubberband = TRUE;
2400 icon_view->priv->rubberband_device = device;
2402 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2406 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2408 if (!icon_view->priv->doing_rubberband)
2411 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2412 icon_view->priv->rubberband_device);
2414 icon_view->priv->doing_rubberband = FALSE;
2415 icon_view->priv->rubberband_device = NULL;
2417 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2421 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2424 gint x, y, width, height;
2425 gboolean dirty = FALSE;
2427 x = MIN (icon_view->priv->rubberband_x1,
2428 icon_view->priv->rubberband_x2);
2429 y = MIN (icon_view->priv->rubberband_y1,
2430 icon_view->priv->rubberband_y2);
2431 width = ABS (icon_view->priv->rubberband_x1 -
2432 icon_view->priv->rubberband_x2);
2433 height = ABS (icon_view->priv->rubberband_y1 -
2434 icon_view->priv->rubberband_y2);
2436 for (items = icon_view->priv->items; items; items = items->next)
2438 GtkIconViewItem *item = items->data;
2442 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2443 x, y, width, height);
2445 selected = is_in ^ item->selected_before_rubberbanding;
2447 if (item->selected != selected)
2449 item->selected = selected;
2451 gtk_icon_view_queue_draw_item (icon_view, item);
2456 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2460 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2461 GtkIconViewItem *item,
2470 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2471 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2474 for (l = icon_view->priv->cell_list; l; l = l->next)
2476 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2478 if (!gtk_cell_renderer_get_visible (info->cell))
2481 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2483 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2484 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2492 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2494 gboolean dirty = FALSE;
2497 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2500 for (items = icon_view->priv->items; items; items = items->next)
2502 GtkIconViewItem *item = items->data;
2506 item->selected = FALSE;
2508 gtk_icon_view_queue_draw_item (icon_view, item);
2509 gtk_icon_view_item_selected_changed (icon_view, item);
2517 /* GtkIconView signals */
2519 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2520 GtkAdjustment *hadj,
2521 GtkAdjustment *vadj)
2523 gboolean need_adjust = FALSE;
2526 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2528 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2530 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2532 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2534 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2536 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2537 0, 0, NULL, NULL, icon_view);
2538 g_object_unref (icon_view->priv->hadjustment);
2541 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2543 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2544 0, 0, NULL, NULL, icon_view);
2545 g_object_unref (icon_view->priv->vadjustment);
2548 if (icon_view->priv->hadjustment != hadj)
2550 icon_view->priv->hadjustment = hadj;
2551 g_object_ref_sink (icon_view->priv->hadjustment);
2553 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2554 G_CALLBACK (gtk_icon_view_adjustment_changed),
2559 if (icon_view->priv->vadjustment != vadj)
2561 icon_view->priv->vadjustment = vadj;
2562 g_object_ref_sink (icon_view->priv->vadjustment);
2564 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2565 G_CALLBACK (gtk_icon_view_adjustment_changed),
2571 gtk_icon_view_adjustment_changed (NULL, icon_view);
2575 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2577 gtk_icon_view_select_all (icon_view);
2581 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2583 gtk_icon_view_unselect_all (icon_view);
2587 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2589 gtk_icon_view_unselect_all (icon_view);
2591 if (icon_view->priv->cursor_item != NULL)
2592 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2596 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2599 GtkCellRendererMode mode;
2600 GtkIconViewCellInfo *info = NULL;
2602 if (!icon_view->priv->cursor_item)
2605 info = g_list_nth_data (icon_view->priv->cell_list,
2606 icon_view->priv->cursor_cell);
2610 g_object_get (info->cell, "mode", &mode, NULL);
2612 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2614 gtk_icon_view_item_activate_cell (icon_view,
2615 icon_view->priv->cursor_item,
2619 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2621 gtk_icon_view_start_editing (icon_view,
2622 icon_view->priv->cursor_item,
2628 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2629 gtk_icon_view_item_activated (icon_view, path);
2630 gtk_tree_path_free (path);
2636 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2638 if (!icon_view->priv->cursor_item)
2641 switch (icon_view->priv->selection_mode)
2643 case GTK_SELECTION_NONE:
2645 case GTK_SELECTION_BROWSE:
2646 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2648 case GTK_SELECTION_SINGLE:
2649 if (icon_view->priv->cursor_item->selected)
2650 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2652 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2654 case GTK_SELECTION_MULTIPLE:
2655 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2656 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2658 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2659 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2664 /* Internal functions */
2666 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2667 GtkIconView *icon_view)
2669 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2671 gdk_window_move (icon_view->priv->bin_window,
2672 - icon_view->priv->hadjustment->value,
2673 - icon_view->priv->vadjustment->value);
2675 if (icon_view->priv->doing_rubberband)
2676 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2678 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2683 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2688 gint *maximum_width)
2691 gint x, current_width;
2692 GList *items, *last_item;
2699 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2700 max_height = g_new0 (gint, icon_view->priv->n_cells);
2707 gtk_widget_style_get (GTK_WIDGET (icon_view),
2708 "focus-line-width", &focus_width,
2711 x += icon_view->priv->margin + focus_width;
2712 current_width += 2 * (icon_view->priv->margin + focus_width);
2717 GtkIconViewItem *item = items->data;
2719 gtk_icon_view_calculate_item_size (icon_view, item);
2720 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2722 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2724 current_width += item->width;
2726 if (items != first_item)
2728 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2729 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2733 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2735 item->y = *y + focus_width;
2738 x = current_width - (icon_view->priv->margin + focus_width);
2740 for (i = 0; i < icon_view->priv->n_cells; i++)
2741 max_height[i] = MAX (max_height[i], item->box[i].height);
2743 if (current_width > *maximum_width)
2744 *maximum_width = current_width;
2750 items = items->next;
2755 /* Now go through the row again and align the icons */
2756 for (items = first_item; items != last_item; items = items->next)
2758 GtkIconViewItem *item = items->data;
2762 item->x = *maximum_width - item->width - item->x;
2763 item->col = col - 1 - item->col;
2766 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2768 /* We may want to readjust the new y coordinate. */
2769 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2770 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2773 g_free (max_height);
2779 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2782 if (upper != adj->upper)
2784 gdouble min = MAX (0.0, upper - adj->page_size);
2785 gboolean value_changed = FALSE;
2789 if (adj->value > min)
2792 value_changed = TRUE;
2795 gtk_adjustment_changed (adj);
2798 gtk_adjustment_value_changed (adj);
2803 gtk_icon_view_layout (GtkIconView *icon_view)
2805 gint y = 0, maximum_width = 0;
2811 if (icon_view->priv->layout_idle_id != 0)
2813 g_source_remove (icon_view->priv->layout_idle_id);
2814 icon_view->priv->layout_idle_id = 0;
2817 if (icon_view->priv->model == NULL)
2820 widget = GTK_WIDGET (icon_view);
2822 item_width = icon_view->priv->item_width;
2826 for (icons = icon_view->priv->items; icons; icons = icons->next)
2828 GtkIconViewItem *item = icons->data;
2829 gtk_icon_view_calculate_item_size (icon_view, item);
2830 item_width = MAX (item_width, item->width);
2835 icons = icon_view->priv->items;
2836 y += icon_view->priv->margin;
2841 gtk_icon_view_set_cell_data (icon_view, icons->data);
2842 adjust_wrap_width (icon_view, icons->data);
2847 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2849 &y, &maximum_width);
2852 while (icons != NULL);
2854 if (maximum_width != icon_view->priv->width)
2855 icon_view->priv->width = maximum_width;
2857 y += icon_view->priv->margin;
2859 if (y != icon_view->priv->height)
2860 icon_view->priv->height = y;
2862 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2863 icon_view->priv->width);
2864 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2865 icon_view->priv->height);
2867 if (icon_view->priv->width != widget->requisition.width ||
2868 icon_view->priv->height != widget->requisition.height)
2869 gtk_widget_queue_resize_no_redraw (widget);
2871 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2872 gdk_window_resize (icon_view->priv->bin_window,
2873 MAX (icon_view->priv->width, widget->allocation.width),
2874 MAX (icon_view->priv->height, widget->allocation.height));
2876 if (icon_view->priv->scroll_to_path)
2880 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2881 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2882 icon_view->priv->scroll_to_path = NULL;
2884 gtk_icon_view_scroll_to_path (icon_view, path,
2885 icon_view->priv->scroll_to_use_align,
2886 icon_view->priv->scroll_to_row_align,
2887 icon_view->priv->scroll_to_col_align);
2888 gtk_tree_path_free (path);
2891 gtk_widget_queue_draw (widget);
2895 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2896 GtkIconViewItem *item,
2897 GtkIconViewCellInfo *info,
2898 GdkRectangle *cell_area)
2900 g_return_if_fail (info->position < item->n_cells);
2902 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2904 cell_area->x = item->box[info->position].x - item->before[info->position];
2905 cell_area->y = item->y + icon_view->priv->item_padding;
2906 cell_area->width = item->box[info->position].width +
2907 item->before[info->position] + item->after[info->position];
2908 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2912 cell_area->x = item->x + icon_view->priv->item_padding;
2913 cell_area->y = item->box[info->position].y - item->before[info->position];
2914 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2915 cell_area->height = item->box[info->position].height +
2916 item->before[info->position] + item->after[info->position];
2921 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2922 GtkIconViewItem *item,
2923 GtkIconViewCellInfo *info,
2926 g_return_if_fail (info->position < item->n_cells);
2928 *box = item->box[info->position];
2931 /* try to guess a reasonable wrap width for an implicit text cell renderer
2934 adjust_wrap_width (GtkIconView *icon_view,
2935 GtkIconViewItem *item)
2937 GtkIconViewCellInfo *text_info;
2938 GtkIconViewCellInfo *pixbuf_info;
2939 gint pixbuf_width, wrap_width;
2941 if (icon_view->priv->text_cell != -1 &&
2942 icon_view->priv->pixbuf_cell != -1)
2946 text_info = g_list_nth_data (icon_view->priv->cell_list,
2947 icon_view->priv->text_cell);
2948 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2949 icon_view->priv->pixbuf_cell);
2951 gtk_cell_renderer_get_size (pixbuf_info->cell,
2952 GTK_WIDGET (icon_view),
2958 if (icon_view->priv->item_width > 0)
2959 item_width = icon_view->priv->item_width;
2961 item_width = item->width;
2963 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2964 wrap_width = item_width;
2966 if (item->width == -1 && item_width <= 0)
2967 wrap_width = MAX (2 * pixbuf_width, 50);
2969 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2972 wrap_width -= icon_view->priv->item_padding * 2;
2974 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2975 g_object_set (text_info->cell, "width", wrap_width, NULL);
2980 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2981 GtkIconViewItem *item)
2986 if (item->width != -1 && item->height != -1)
2989 if (item->n_cells != icon_view->priv->n_cells)
2991 g_free (item->before);
2992 g_free (item->after);
2995 item->before = g_new0 (gint, icon_view->priv->n_cells);
2996 item->after = g_new0 (gint, icon_view->priv->n_cells);
2997 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2999 item->n_cells = icon_view->priv->n_cells;
3002 gtk_icon_view_set_cell_data (icon_view, item);
3004 spacing = icon_view->priv->spacing;
3008 for (l = icon_view->priv->cell_list; l; l = l->next)
3010 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3012 if (!gtk_cell_renderer_get_visible (info->cell))
3015 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3017 &item->box[info->position].width,
3018 &item->box[info->position].height);
3020 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3022 item->width += item->box[info->position].width
3023 + (info->position > 0 ? spacing : 0);
3024 item->height = MAX (item->height, item->box[info->position].height);
3028 item->width = MAX (item->width, item->box[info->position].width);
3029 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3033 item->width += icon_view->priv->item_padding * 2;
3034 item->height += icon_view->priv->item_padding * 2;
3038 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3039 GtkIconViewItem *item,
3042 GdkRectangle cell_area;
3048 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3050 gtk_icon_view_set_cell_data (icon_view, item);
3052 spacing = icon_view->priv->spacing;
3055 for (i = 0; i < icon_view->priv->n_cells; i++)
3057 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3058 item->height = MAX (item->height, max_height[i]);
3060 item->height += max_height[i] + (i > 0 ? spacing : 0);
3063 cell_area.x = item->x + icon_view->priv->item_padding;
3064 cell_area.y = item->y + icon_view->priv->item_padding;
3066 for (k = 0; k < 2; k++)
3067 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3069 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3071 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3074 if (!gtk_cell_renderer_get_visible (info->cell))
3077 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3079 /* We should not subtract icon_view->priv->item_padding from item->height,
3080 * because item->height is recalculated above using
3081 * max_height which does not contain item padding.
3083 cell_area.width = item->box[info->position].width;
3084 cell_area.height = item->height;
3088 /* item->width is not recalculated and thus needs to be
3089 * corrected for the padding.
3091 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3092 cell_area.height = max_height[i];
3095 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3097 &item->box[info->position].x, &item->box[info->position].y,
3098 &item->box[info->position].width, &item->box[info->position].height);
3100 item->box[info->position].x += cell_area.x;
3101 item->box[info->position].y += cell_area.y;
3102 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3104 item->before[info->position] = item->box[info->position].x - cell_area.x;
3105 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3106 cell_area.x += cell_area.width + spacing;
3110 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3112 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3113 cell_area.width = item->width;
3115 item->before[info->position] = item->box[info->position].y - cell_area.y;
3116 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3117 cell_area.y += cell_area.height + spacing;
3121 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3123 for (i = 0; i < icon_view->priv->n_cells; i++)
3125 item->box[i].x = item->x + item->width -
3126 (item->box[i].x + item->box[i].width - item->x);
3130 item->height += icon_view->priv->item_padding * 2;
3134 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3136 g_list_foreach (icon_view->priv->items,
3137 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3141 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3148 gtk_icon_view_paint_item (GtkIconView *icon_view,
3150 GtkIconViewItem *item,
3152 GdkDrawable *drawable,
3155 gboolean draw_focus)
3159 GdkRectangle cell_area, box;
3163 GtkCellRendererState flags;
3165 if (icon_view->priv->model == NULL)
3168 gtk_icon_view_set_cell_data (icon_view, item);
3170 gtk_widget_style_get (GTK_WIDGET (icon_view),
3171 "focus-line-width", &focus_width,
3174 padding = focus_width;
3178 flags = GTK_CELL_RENDERER_SELECTED;
3179 if (gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3180 state = GTK_STATE_SELECTED;
3182 state = GTK_STATE_ACTIVE;
3187 state = GTK_STATE_NORMAL;
3190 #ifdef DEBUG_ICON_VIEW
3191 gdk_draw_rectangle (drawable,
3192 GTK_WIDGET (icon_view)->style->black_gc,
3195 item->width, item->height);
3200 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3201 (GdkWindow *) drawable,
3205 GTK_WIDGET (icon_view),
3208 item->width, item->height);
3211 for (l = icon_view->priv->cell_list; l; l = l->next)
3213 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3215 if (!gtk_cell_renderer_get_visible (info->cell))
3218 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3220 #ifdef DEBUG_ICON_VIEW
3221 gdk_draw_rectangle (drawable,
3222 GTK_WIDGET (icon_view)->style->black_gc,
3224 x - item->x + cell_area.x,
3225 y - item->y + cell_area.y,
3226 cell_area.width, cell_area.height);
3228 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3230 gdk_draw_rectangle (drawable,
3231 GTK_WIDGET (icon_view)->style->black_gc,
3233 x - item->x + box.x,
3234 y - item->y + box.y,
3235 box.width, box.height);
3238 cell_area.x = x - item->x + cell_area.x;
3239 cell_area.y = y - item->y + cell_area.y;
3241 gtk_cell_renderer_render (info->cell,
3243 GTK_WIDGET (icon_view),
3244 &cell_area, &cell_area, area, flags);
3248 gtk_widget_has_focus (GTK_WIDGET (icon_view)) &&
3249 item == icon_view->priv->cursor_item)
3251 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3253 GtkCellRendererMode mode;
3254 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3256 if (!gtk_cell_renderer_get_visible (info->cell))
3259 /* If found a editable/activatable cell, draw focus on it. */
3260 g_object_get (info->cell, "mode", &mode, NULL);
3261 if (icon_view->priv->cursor_cell < 0 &&
3262 mode != GTK_CELL_RENDERER_MODE_INERT)
3263 icon_view->priv->cursor_cell = i;
3265 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3267 if (i == icon_view->priv->cursor_cell)
3269 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3273 GTK_WIDGET (icon_view),
3275 x - item->x + box.x - padding,
3276 y - item->y + box.y - padding,
3277 box.width + 2 * padding,
3278 box.height + 2 * padding);
3283 /* If there are no editable/activatable cells, draw focus
3284 * around the whole item.
3286 if (icon_view->priv->cursor_cell < 0)
3287 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3291 GTK_WIDGET (icon_view),
3295 item->width + 2 * padding,
3296 item->height + 2 * padding);
3301 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3306 GdkRectangle rubber_rect;
3307 GdkColor *fill_color_gdk;
3308 guchar fill_color_alpha;
3310 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3311 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3312 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3313 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3315 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3318 gtk_widget_style_get (GTK_WIDGET (icon_view),
3319 "selection-box-color", &fill_color_gdk,
3320 "selection-box-alpha", &fill_color_alpha,
3323 if (!fill_color_gdk)
3324 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3326 cairo_set_source_rgba (cr,
3327 fill_color_gdk->red / 65535.,
3328 fill_color_gdk->green / 65535.,
3329 fill_color_gdk->blue / 65535.,
3330 fill_color_alpha / 255.);
3333 gdk_cairo_rectangle (cr, &rect);
3337 /* Draw the border without alpha */
3338 cairo_set_source_rgb (cr,
3339 fill_color_gdk->red / 65535.,
3340 fill_color_gdk->green / 65535.,
3341 fill_color_gdk->blue / 65535.);
3342 cairo_rectangle (cr,
3343 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3344 rubber_rect.width - 1, rubber_rect.height - 1);
3348 gdk_color_free (fill_color_gdk);
3352 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3358 index = gtk_tree_path_get_indices (path)[0];
3360 for (l = icon_view->priv->items; l; l = l->next)
3362 GtkIconViewItem *item = l->data;
3364 if (item->index == index)
3366 gtk_icon_view_queue_draw_item (icon_view, item);
3373 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3374 GtkIconViewItem *item)
3379 gtk_widget_style_get (GTK_WIDGET (icon_view),
3380 "focus-line-width", &focus_width,
3383 rect.x = item->x - focus_width;
3384 rect.y = item->y - focus_width;
3385 rect.width = item->width + 2 * focus_width;
3386 rect.height = item->height + 2 * focus_width;
3388 if (icon_view->priv->bin_window)
3389 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3393 layout_callback (gpointer user_data)
3395 GtkIconView *icon_view;
3397 icon_view = GTK_ICON_VIEW (user_data);
3399 icon_view->priv->layout_idle_id = 0;
3401 gtk_icon_view_layout (icon_view);
3407 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3409 if (icon_view->priv->layout_idle_id != 0)
3412 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3416 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3417 GtkIconViewItem *item,
3421 AtkObject *item_obj;
3422 AtkObject *cursor_item_obj;
3424 if (icon_view->priv->cursor_item == item &&
3425 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3428 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3429 if (icon_view->priv->cursor_item != NULL)
3431 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3434 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3435 if (cursor_item_obj != NULL)
3436 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3439 icon_view->priv->cursor_item = item;
3440 if (cursor_cell >= 0)
3441 icon_view->priv->cursor_cell = cursor_cell;
3443 gtk_icon_view_queue_draw_item (icon_view, item);
3445 /* Notify that accessible focus object has changed */
3446 item_obj = atk_object_ref_accessible_child (obj, item->index);
3448 if (item_obj != NULL)
3450 atk_focus_tracker_notify (item_obj);
3451 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3452 g_object_unref (item_obj);
3457 static GtkIconViewItem *
3458 gtk_icon_view_item_new (void)
3460 GtkIconViewItem *item;
3462 item = g_new0 (GtkIconViewItem, 1);
3471 gtk_icon_view_item_free (GtkIconViewItem *item)
3473 g_return_if_fail (item != NULL);
3475 g_free (item->before);
3476 g_free (item->after);
3483 static GtkIconViewItem *
3484 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3487 gboolean only_in_cell,
3488 GtkIconViewCellInfo **cell_at_pos)
3494 *cell_at_pos = NULL;
3496 for (items = icon_view->priv->items; items; items = items->next)
3498 GtkIconViewItem *item = items->data;
3500 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3501 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3503 if (only_in_cell || cell_at_pos)
3505 gtk_icon_view_set_cell_data (icon_view, item);
3507 for (l = icon_view->priv->cell_list; l; l = l->next)
3509 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3511 if (!gtk_cell_renderer_get_visible (info->cell))
3514 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3516 if ((x >= box.x && x <= box.x + box.width &&
3517 y >= box.y && y <= box.y + box.height) ||
3519 x <= box.x + box.width &&
3521 y <= box.y + box.height))
3524 *cell_at_pos = info;
3542 gtk_icon_view_select_item (GtkIconView *icon_view,
3543 GtkIconViewItem *item)
3545 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3546 g_return_if_fail (item != NULL);
3551 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3553 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3554 gtk_icon_view_unselect_all_internal (icon_view);
3556 item->selected = TRUE;
3558 gtk_icon_view_item_selected_changed (icon_view, item);
3559 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3561 gtk_icon_view_queue_draw_item (icon_view, item);
3566 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3567 GtkIconViewItem *item)
3569 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3570 g_return_if_fail (item != NULL);
3572 if (!item->selected)
3575 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3576 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3579 item->selected = FALSE;
3581 gtk_icon_view_item_selected_changed (icon_view, item);
3582 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3584 gtk_icon_view_queue_draw_item (icon_view, item);
3588 verify_items (GtkIconView *icon_view)
3593 for (items = icon_view->priv->items; items; items = items->next)
3595 GtkIconViewItem *item = items->data;
3597 if (item->index != i)
3598 g_error ("List item does not match its index: "
3599 "item index %d and list index %d\n", item->index, i);
3606 gtk_icon_view_row_changed (GtkTreeModel *model,
3611 GtkIconViewItem *item;
3613 GtkIconView *icon_view;
3615 icon_view = GTK_ICON_VIEW (data);
3617 gtk_icon_view_stop_editing (icon_view, TRUE);
3619 index = gtk_tree_path_get_indices(path)[0];
3620 item = g_list_nth_data (icon_view->priv->items, index);
3622 gtk_icon_view_item_invalidate_size (item);
3623 gtk_icon_view_queue_layout (icon_view);
3625 verify_items (icon_view);
3629 gtk_icon_view_row_inserted (GtkTreeModel *model,
3635 GtkIconViewItem *item;
3636 gboolean iters_persist;
3637 GtkIconView *icon_view;
3640 icon_view = GTK_ICON_VIEW (data);
3642 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3644 index = gtk_tree_path_get_indices(path)[0];
3646 item = gtk_icon_view_item_new ();
3651 item->index = index;
3653 /* FIXME: We can be more efficient here,
3654 we can store a tail pointer and use that when
3655 appending (which is a rather common operation)
3657 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3660 list = g_list_nth (icon_view->priv->items, index + 1);
3661 for (; list; list = list->next)
3668 verify_items (icon_view);
3670 gtk_icon_view_queue_layout (icon_view);
3674 gtk_icon_view_row_deleted (GtkTreeModel *model,
3679 GtkIconView *icon_view;
3680 GtkIconViewItem *item;
3682 gboolean emit = FALSE;
3684 icon_view = GTK_ICON_VIEW (data);
3686 index = gtk_tree_path_get_indices(path)[0];
3688 list = g_list_nth (icon_view->priv->items, index);
3691 gtk_icon_view_stop_editing (icon_view, TRUE);
3693 if (item == icon_view->priv->anchor_item)
3694 icon_view->priv->anchor_item = NULL;
3696 if (item == icon_view->priv->cursor_item)
3697 icon_view->priv->cursor_item = NULL;
3702 gtk_icon_view_item_free (item);
3704 for (next = list->next; next; next = next->next)
3711 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3713 verify_items (icon_view);
3715 gtk_icon_view_queue_layout (icon_view);
3718 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3722 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3723 GtkTreePath *parent,
3730 GtkIconView *icon_view;
3731 GList *items = NULL, *list;
3732 GtkIconViewItem **item_array;
3735 icon_view = GTK_ICON_VIEW (data);
3737 gtk_icon_view_stop_editing (icon_view, TRUE);
3739 length = gtk_tree_model_iter_n_children (model, NULL);
3741 order = g_new (gint, length);
3742 for (i = 0; i < length; i++)
3743 order [new_order[i]] = i;
3745 item_array = g_new (GtkIconViewItem *, length);
3746 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3747 item_array[order[i]] = list->data;
3750 for (i = length - 1; i >= 0; i--)
3752 item_array[i]->index = i;
3753 items = g_list_prepend (items, item_array[i]);
3756 g_free (item_array);
3757 g_list_free (icon_view->priv->items);
3758 icon_view->priv->items = items;
3760 gtk_icon_view_queue_layout (icon_view);
3762 verify_items (icon_view);
3766 gtk_icon_view_build_items (GtkIconView *icon_view)
3770 gboolean iters_persist;
3771 GList *items = NULL;
3773 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3775 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3783 GtkIconViewItem *item = gtk_icon_view_item_new ();
3792 items = g_list_prepend (items, item);
3794 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3796 icon_view->priv->items = g_list_reverse (items);
3800 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3803 GtkMovementStep step,
3807 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3808 I_("move-cursor"), 2,
3812 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3817 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3820 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3825 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3832 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3833 GtkMovementStep step,
3836 GdkModifierType state;
3838 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3839 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3840 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3841 step == GTK_MOVEMENT_DISPLAY_LINES ||
3842 step == GTK_MOVEMENT_PAGES ||
3843 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3845 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3848 gtk_icon_view_stop_editing (icon_view, FALSE);
3849 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3851 if (gtk_get_current_event_state (&state))
3853 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3854 icon_view->priv->ctrl_pressed = TRUE;
3855 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3856 icon_view->priv->shift_pressed = TRUE;
3858 /* else we assume not pressed */
3862 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3863 case GTK_MOVEMENT_VISUAL_POSITIONS:
3864 gtk_icon_view_move_cursor_left_right (icon_view, count);
3866 case GTK_MOVEMENT_DISPLAY_LINES:
3867 gtk_icon_view_move_cursor_up_down (icon_view, count);
3869 case GTK_MOVEMENT_PAGES:
3870 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3872 case GTK_MOVEMENT_BUFFER_ENDS:
3873 gtk_icon_view_move_cursor_start_end (icon_view, count);
3876 g_assert_not_reached ();
3879 icon_view->priv->ctrl_pressed = FALSE;
3880 icon_view->priv->shift_pressed = FALSE;
3882 icon_view->priv->draw_focus = TRUE;
3887 static GtkIconViewItem *
3888 find_item (GtkIconView *icon_view,
3889 GtkIconViewItem *current,
3895 GtkIconViewItem *item;
3897 /* FIXME: this could be more efficient
3899 row = current->row + row_ofs;
3900 col = current->col + col_ofs;
3902 for (items = icon_view->priv->items; items; items = items->next)
3905 if (item->row == row && item->col == col)
3913 find_cell (GtkIconView *icon_view,
3914 GtkIconViewItem *item,
3916 GtkOrientation orientation,
3926 if (icon_view->priv->orientation != orientation)
3929 gtk_icon_view_set_cell_data (icon_view, item);
3931 focusable = g_new0 (gint, icon_view->priv->n_cells);
3935 for (k = 0; k < 2; k++)
3936 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3938 GtkCellRendererMode mode;
3939 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3941 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3944 if (!gtk_cell_renderer_get_visible (info->cell))
3947 g_object_get (info->cell, "mode", &mode, NULL);
3948 if (mode != GTK_CELL_RENDERER_MODE_INERT)
3951 current = n_focusable;
3953 focusable[n_focusable] = i;
3959 if (n_focusable == 0)
3967 current = step > 0 ? 0 : n_focusable - 1;
3968 cell = focusable[current];
3971 if (current + *count < 0)
3974 *count = current + *count;
3976 else if (current + *count > n_focusable - 1)
3979 *count = current + *count - (n_focusable - 1);
3983 cell = focusable[current + *count];
3992 static GtkIconViewItem *
3993 find_item_page_up_down (GtkIconView *icon_view,
3994 GtkIconViewItem *current,
4001 y = current->y + count * icon_view->priv->vadjustment->page_size;
4003 item = g_list_find (icon_view->priv->items, current);
4008 for (next = item->next; next; next = next->next)
4010 if (((GtkIconViewItem *)next->data)->col == col)
4013 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4023 for (next = item->prev; next; next = next->prev)
4025 if (((GtkIconViewItem *)next->data)->col == col)
4028 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4042 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4043 GtkIconViewItem *anchor,
4044 GtkIconViewItem *cursor)
4047 GtkIconViewItem *item;
4048 gint row1, row2, col1, col2;
4049 gboolean dirty = FALSE;
4051 if (anchor->row < cursor->row)
4062 if (anchor->col < cursor->col)
4073 for (items = icon_view->priv->items; items; items = items->next)
4077 if (row1 <= item->row && item->row <= row2 &&
4078 col1 <= item->col && item->col <= col2)
4080 if (!item->selected)
4083 item->selected = TRUE;
4084 gtk_icon_view_item_selected_changed (icon_view, item);
4086 gtk_icon_view_queue_draw_item (icon_view, item);
4094 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4097 GtkIconViewItem *item;
4099 gboolean dirty = FALSE;
4101 GtkDirectionType direction;
4103 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4106 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4108 if (!icon_view->priv->cursor_item)
4113 list = icon_view->priv->items;
4115 list = g_list_last (icon_view->priv->items);
4117 item = list ? list->data : NULL;
4122 item = icon_view->priv->cursor_item;
4123 cell = icon_view->priv->cursor_cell;
4124 step = count > 0 ? 1 : -1;
4127 cell = find_cell (icon_view, item, cell,
4128 GTK_ORIENTATION_VERTICAL,
4133 item = find_item (icon_view, item, step, 0);
4134 count = count - step;
4140 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4142 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4144 gtk_widget_child_focus (toplevel,
4145 direction == GTK_DIR_UP ?
4146 GTK_DIR_TAB_BACKWARD :
4147 GTK_DIR_TAB_FORWARD);
4153 if (icon_view->priv->ctrl_pressed ||
4154 !icon_view->priv->shift_pressed ||
4155 !icon_view->priv->anchor_item ||
4156 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4157 icon_view->priv->anchor_item = item;
4159 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4161 if (!icon_view->priv->ctrl_pressed &&
4162 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4164 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4165 dirty = gtk_icon_view_select_all_between (icon_view,
4166 icon_view->priv->anchor_item,
4170 gtk_icon_view_scroll_to_item (icon_view, item);
4173 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4177 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4180 GtkIconViewItem *item;
4181 gboolean dirty = FALSE;
4183 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4186 if (!icon_view->priv->cursor_item)
4191 list = icon_view->priv->items;
4193 list = g_list_last (icon_view->priv->items);
4195 item = list ? list->data : NULL;
4198 item = find_item_page_up_down (icon_view,
4199 icon_view->priv->cursor_item,
4202 if (item == icon_view->priv->cursor_item)
4203 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4208 if (icon_view->priv->ctrl_pressed ||
4209 !icon_view->priv->shift_pressed ||
4210 !icon_view->priv->anchor_item ||
4211 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4212 icon_view->priv->anchor_item = item;
4214 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4216 if (!icon_view->priv->ctrl_pressed &&
4217 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4219 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4220 dirty = gtk_icon_view_select_all_between (icon_view,
4221 icon_view->priv->anchor_item,
4225 gtk_icon_view_scroll_to_item (icon_view, item);
4228 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4232 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4235 GtkIconViewItem *item;
4237 gboolean dirty = FALSE;
4239 GtkDirectionType direction;
4241 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4244 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4246 if (!icon_view->priv->cursor_item)
4251 list = icon_view->priv->items;
4253 list = g_list_last (icon_view->priv->items);
4255 item = list ? list->data : NULL;
4259 item = icon_view->priv->cursor_item;
4260 cell = icon_view->priv->cursor_cell;
4261 step = count > 0 ? 1 : -1;
4264 cell = find_cell (icon_view, item, cell,
4265 GTK_ORIENTATION_HORIZONTAL,
4270 item = find_item (icon_view, item, 0, step);
4271 count = count - step;
4277 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4279 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4281 gtk_widget_child_focus (toplevel,
4282 direction == GTK_DIR_LEFT ?
4283 GTK_DIR_TAB_BACKWARD :
4284 GTK_DIR_TAB_FORWARD);
4290 if (icon_view->priv->ctrl_pressed ||
4291 !icon_view->priv->shift_pressed ||
4292 !icon_view->priv->anchor_item ||
4293 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4294 icon_view->priv->anchor_item = item;
4296 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4298 if (!icon_view->priv->ctrl_pressed &&
4299 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4301 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4302 dirty = gtk_icon_view_select_all_between (icon_view,
4303 icon_view->priv->anchor_item,
4307 gtk_icon_view_scroll_to_item (icon_view, item);
4310 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4314 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4317 GtkIconViewItem *item;
4319 gboolean dirty = FALSE;
4321 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4325 list = icon_view->priv->items;
4327 list = g_list_last (icon_view->priv->items);
4329 item = list ? list->data : NULL;
4331 if (item == icon_view->priv->cursor_item)
4332 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4337 if (icon_view->priv->ctrl_pressed ||
4338 !icon_view->priv->shift_pressed ||
4339 !icon_view->priv->anchor_item ||
4340 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4341 icon_view->priv->anchor_item = item;
4343 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4345 if (!icon_view->priv->ctrl_pressed &&
4346 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4348 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4349 dirty = gtk_icon_view_select_all_between (icon_view,
4350 icon_view->priv->anchor_item,
4354 gtk_icon_view_scroll_to_item (icon_view, item);
4357 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4361 * gtk_icon_view_scroll_to_path:
4362 * @icon_view: A #GtkIconView.
4363 * @path: The path of the item to move to.
4364 * @use_align: whether to use alignment arguments, or %FALSE.
4365 * @row_align: The vertical alignment of the item specified by @path.
4366 * @col_align: The horizontal alignment of the item specified by @path.
4368 * Moves the alignments of @icon_view to the position specified by @path.
4369 * @row_align determines where the row is placed, and @col_align determines
4370 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4371 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4374 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4375 * tree does the minimum amount of work to scroll the item onto the screen.
4376 * This means that the item will be scrolled to the edge closest to its current
4377 * position. If the item is currently visible on the screen, nothing is done.
4379 * This function only works if the model is set, and @path is a valid row on
4380 * the model. If the model changes before the @icon_view is realized, the
4381 * centered path will be modified to reflect this change.
4386 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4392 GtkIconViewItem *item = NULL;
4394 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4395 g_return_if_fail (path != NULL);
4396 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4397 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4399 if (gtk_tree_path_get_depth (path) > 0)
4400 item = g_list_nth_data (icon_view->priv->items,
4401 gtk_tree_path_get_indices(path)[0]);
4403 if (!item || item->width < 0 ||
4404 !gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4406 if (icon_view->priv->scroll_to_path)
4407 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4409 icon_view->priv->scroll_to_path = NULL;
4412 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4414 icon_view->priv->scroll_to_use_align = use_align;
4415 icon_view->priv->scroll_to_row_align = row_align;
4416 icon_view->priv->scroll_to_col_align = col_align;
4427 gtk_widget_style_get (GTK_WIDGET (icon_view),
4428 "focus-line-width", &focus_width,
4431 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4433 offset = y + item->y - focus_width -
4434 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4436 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4437 icon_view->priv->vadjustment->value + offset);
4439 offset = x + item->x - focus_width -
4440 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4442 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4443 icon_view->priv->hadjustment->value + offset);
4445 gtk_adjustment_changed (icon_view->priv->hadjustment);
4446 gtk_adjustment_changed (icon_view->priv->vadjustment);
4449 gtk_icon_view_scroll_to_item (icon_view, item);
4454 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4455 GtkIconViewItem *item)
4457 gint x, y, width, height;
4460 gtk_widget_style_get (GTK_WIDGET (icon_view),
4461 "focus-line-width", &focus_width,
4464 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4466 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4468 if (y + item->y - focus_width < 0)
4469 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4470 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4471 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4472 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4473 icon_view->priv->vadjustment->value + y + item->y + item->height
4474 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4476 if (x + item->x - focus_width < 0)
4477 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4478 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4479 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4480 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4481 icon_view->priv->hadjustment->value + x + item->x + item->width
4482 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4484 gtk_adjustment_changed (icon_view->priv->hadjustment);
4485 gtk_adjustment_changed (icon_view->priv->vadjustment);
4488 /* GtkCellLayout implementation */
4489 static GtkIconViewCellInfo *
4490 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4491 GtkCellRenderer *renderer)
4495 for (i = icon_view->priv->cell_list; i; i = i->next)
4497 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4499 if (info->cell == renderer)
4507 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4508 GtkIconViewItem *item)
4511 gboolean iters_persist;
4514 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4520 path = gtk_tree_path_new_from_indices (item->index, -1);
4521 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4523 gtk_tree_path_free (path);
4528 for (i = icon_view->priv->cell_list; i; i = i->next)
4531 GtkIconViewCellInfo *info = i->data;
4533 g_object_freeze_notify (G_OBJECT (info->cell));
4535 for (j = info->attributes; j && j->next; j = j->next->next)
4537 gchar *property = j->data;
4538 gint column = GPOINTER_TO_INT (j->next->data);
4539 GValue value = {0, };
4541 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4543 g_object_set_property (G_OBJECT (info->cell),
4545 g_value_unset (&value);
4549 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4551 icon_view->priv->model,
4555 g_object_thaw_notify (G_OBJECT (info->cell));
4560 free_cell_attributes (GtkIconViewCellInfo *info)
4564 list = info->attributes;
4565 while (list && list->next)
4567 g_free (list->data);
4568 list = list->next->next;
4571 g_slist_free (info->attributes);
4572 info->attributes = NULL;
4576 free_cell_info (GtkIconViewCellInfo *info)
4578 free_cell_attributes (info);
4580 g_object_unref (info->cell);
4583 (* info->destroy) (info->func_data);
4589 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4590 GtkCellRenderer *renderer,
4593 GtkIconViewCellInfo *info;
4594 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4596 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4597 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4599 g_object_ref_sink (renderer);
4601 info = g_new0 (GtkIconViewCellInfo, 1);
4602 info->cell = renderer;
4603 info->expand = expand ? TRUE : FALSE;
4604 info->pack = GTK_PACK_START;
4605 info->position = icon_view->priv->n_cells;
4607 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4608 icon_view->priv->n_cells++;
4612 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4613 GtkCellRenderer *renderer,
4616 GtkIconViewCellInfo *info;
4617 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4619 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4620 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4622 g_object_ref_sink (renderer);
4624 info = g_new0 (GtkIconViewCellInfo, 1);
4625 info->cell = renderer;
4626 info->expand = expand ? TRUE : FALSE;
4627 info->pack = GTK_PACK_END;
4628 info->position = icon_view->priv->n_cells;
4630 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4631 icon_view->priv->n_cells++;
4635 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4636 GtkCellRenderer *renderer,
4637 const gchar *attribute,
4640 GtkIconViewCellInfo *info;
4641 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4643 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4644 g_return_if_fail (info != NULL);
4646 info->attributes = g_slist_prepend (info->attributes,
4647 GINT_TO_POINTER (column));
4648 info->attributes = g_slist_prepend (info->attributes,
4649 g_strdup (attribute));
4653 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4655 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4657 while (icon_view->priv->cell_list)
4659 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4660 free_cell_info (info);
4661 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4662 icon_view->priv->cell_list);
4665 icon_view->priv->n_cells = 0;
4669 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4670 GtkCellRenderer *cell,
4671 GtkCellLayoutDataFunc func,
4673 GDestroyNotify destroy)
4675 GtkIconViewCellInfo *info;
4676 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4678 info = gtk_icon_view_get_cell_info (icon_view, cell);
4679 g_return_if_fail (info != NULL);
4683 GDestroyNotify d = info->destroy;
4685 info->destroy = NULL;
4686 d (info->func_data);
4690 info->func_data = func_data;
4691 info->destroy = destroy;
4695 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4696 GtkCellRenderer *renderer)
4698 GtkIconViewCellInfo *info;
4700 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4702 free_cell_attributes (info);
4706 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4707 GtkCellRenderer *cell,
4710 GtkIconView *icon_view;
4712 GtkIconViewCellInfo *info;
4715 icon_view = GTK_ICON_VIEW (layout);
4717 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4719 info = gtk_icon_view_get_cell_info (icon_view, cell);
4721 g_return_if_fail (info != NULL);
4722 g_return_if_fail (position >= 0);
4724 link = g_list_find (icon_view->priv->cell_list, info);
4726 g_return_if_fail (link != NULL);
4728 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4730 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4733 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4740 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4744 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4746 GtkIconView *icon_view = (GtkIconView *)layout;
4747 GList *retval = NULL, *l;
4749 for (l = icon_view->priv->cell_list; l; l = l->next)
4751 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4753 retval = g_list_prepend (retval, info->cell);
4756 return g_list_reverse (retval);
4763 * gtk_icon_view_new:
4765 * Creates a new #GtkIconView widget
4767 * Return value: A newly created #GtkIconView widget
4772 gtk_icon_view_new (void)
4774 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4778 * gtk_icon_view_new_with_model:
4779 * @model: The model.
4781 * Creates a new #GtkIconView widget with the model @model.
4783 * Return value: A newly created #GtkIconView widget.
4788 gtk_icon_view_new_with_model (GtkTreeModel *model)
4790 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4794 * gtk_icon_view_convert_widget_to_bin_window_coords:
4795 * @icon_view: a #GtkIconView
4796 * @wx: X coordinate relative to the widget
4797 * @wy: Y coordinate relative to the widget
4798 * @bx: return location for bin_window X coordinate
4799 * @by: return location for bin_window Y coordinate
4801 * Converts widget coordinates to coordinates for the bin_window,
4802 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4807 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4815 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4817 if (icon_view->priv->bin_window)
4818 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4829 * gtk_icon_view_get_path_at_pos:
4830 * @icon_view: A #GtkIconView.
4831 * @x: The x position to be identified
4832 * @y: The y position to be identified
4834 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4835 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4836 * the cell at the specified position.
4837 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4838 * widget coordinates to bin_window coordinates.
4840 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4841 * if no icon exists at that position.
4846 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4850 GtkIconViewItem *item;
4853 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4855 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4860 path = gtk_tree_path_new_from_indices (item->index, -1);
4866 * gtk_icon_view_get_item_at_pos:
4867 * @icon_view: A #GtkIconView.
4868 * @x: The x position to be identified
4869 * @y: The y position to be identified
4870 * @path: (allow-none): Return location for the path, or %NULL
4871 * @cell: Return location for the renderer responsible for the cell
4872 * at (@x, @y), or %NULL
4874 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4875 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4876 * obtains the cell at the specified position. The returned path should
4877 * be freed with gtk_tree_path_free().
4878 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4879 * widget coordinates to bin_window coordinates.
4881 * Return value: %TRUE if an item exists at the specified position
4886 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4890 GtkCellRenderer **cell)
4892 GtkIconViewItem *item;
4893 GtkIconViewCellInfo *info;
4895 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4897 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4902 *path = gtk_tree_path_new_from_indices (item->index, -1);
4915 return (item != NULL);
4919 * gtk_icon_view_set_tooltip_item:
4920 * @icon_view: a #GtkIconView
4921 * @tooltip: a #GtkTooltip
4922 * @path: a #GtkTreePath
4924 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4925 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4926 * See also gtk_tooltip_set_tip_area().
4931 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4932 GtkTooltip *tooltip,
4935 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4936 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4938 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4942 * gtk_icon_view_set_tooltip_cell:
4943 * @icon_view: a #GtkIconView
4944 * @tooltip: a #GtkTooltip
4945 * @path: a #GtkTreePath
4946 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4948 * Sets the tip area of @tooltip to the area which @cell occupies in
4949 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4951 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4956 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4957 GtkTooltip *tooltip,
4959 GtkCellRenderer *cell)
4962 GtkIconViewItem *item = NULL;
4963 GtkIconViewCellInfo *info = NULL;
4966 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4967 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4968 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4970 if (gtk_tree_path_get_depth (path) > 0)
4971 item = g_list_nth_data (icon_view->priv->items,
4972 gtk_tree_path_get_indices(path)[0]);
4979 info = gtk_icon_view_get_cell_info (icon_view, cell);
4980 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4986 rect.width = item->width;
4987 rect.height = item->height;
4990 if (icon_view->priv->bin_window)
4992 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4997 gtk_tooltip_set_tip_area (tooltip, &rect);
5002 * gtk_icon_view_get_tooltip_context:
5003 * @icon_view: an #GtkIconView
5004 * @x: the x coordinate (relative to widget coordinates)
5005 * @y: the y coordinate (relative to widget coordinates)
5006 * @keyboard_tip: whether this is a keyboard tooltip or not
5007 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5008 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
5009 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5011 * This function is supposed to be used in a #GtkWidget::query-tooltip
5012 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5013 * which are received in the signal handler, should be passed to this
5014 * function without modification.
5016 * The return value indicates whether there is an icon view item at the given
5017 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5018 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5019 * @model, @path and @iter which have been provided will be set to point to
5020 * that row and the corresponding model. @x and @y will always be converted
5021 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5023 * Return value: whether or not the given tooltip context points to a item
5028 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5031 gboolean keyboard_tip,
5032 GtkTreeModel **model,
5036 GtkTreePath *tmppath = NULL;
5038 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5039 g_return_val_if_fail (x != NULL, FALSE);
5040 g_return_val_if_fail (y != NULL, FALSE);
5044 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5051 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5054 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5059 *model = gtk_icon_view_get_model (icon_view);
5062 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5068 gtk_tree_path_free (tmppath);
5074 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5077 gboolean keyboard_tip,
5078 GtkTooltip *tooltip,
5084 GtkTreeModel *model;
5085 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5087 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5090 &model, &path, &iter))
5093 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5097 gtk_tree_path_free (path);
5101 gtk_tooltip_set_markup (tooltip, str);
5102 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5104 gtk_tree_path_free (path);
5112 * gtk_icon_view_set_tooltip_column:
5113 * @icon_view: a #GtkIconView
5114 * @column: an integer, which is a valid column number for @icon_view's model
5116 * If you only plan to have simple (text-only) tooltips on full items, you
5117 * can use this function to have #GtkIconView handle these automatically
5118 * for you. @column should be set to the column in @icon_view's model
5119 * containing the tooltip texts, or -1 to disable this feature.
5121 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5122 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5127 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5130 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5132 if (column == icon_view->priv->tooltip_column)
5137 g_signal_handlers_disconnect_by_func (icon_view,
5138 gtk_icon_view_set_tooltip_query_cb,
5140 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5144 if (icon_view->priv->tooltip_column == -1)
5146 g_signal_connect (icon_view, "query-tooltip",
5147 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5148 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5152 icon_view->priv->tooltip_column = column;
5153 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5157 * gtk_icon_view_get_tooltip_column:
5158 * @icon_view: a #GtkIconView
5160 * Returns the column of @icon_view's model which is being used for
5161 * displaying tooltips on @icon_view's rows.
5163 * Return value: the index of the tooltip column that is currently being
5164 * used, or -1 if this is disabled.
5169 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5171 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5173 return icon_view->priv->tooltip_column;
5177 * gtk_icon_view_get_visible_range:
5178 * @icon_view: A #GtkIconView
5179 * @start_path: (allow-none): Return location for start of region, or %NULL
5180 * @end_path: (allow-none): Return location for end of region, or %NULL
5182 * Sets @start_path and @end_path to be the first and last visible path.
5183 * Note that there may be invisible paths in between.
5185 * Both paths should be freed with gtk_tree_path_free() after use.
5187 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5192 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5193 GtkTreePath **start_path,
5194 GtkTreePath **end_path)
5196 gint start_index = -1;
5197 gint end_index = -1;
5200 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5202 if (icon_view->priv->hadjustment == NULL ||
5203 icon_view->priv->vadjustment == NULL)
5206 if (start_path == NULL && end_path == NULL)
5209 for (icons = icon_view->priv->items; icons; icons = icons->next)
5211 GtkIconViewItem *item = icons->data;
5213 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5214 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5215 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5216 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5218 if (start_index == -1)
5219 start_index = item->index;
5220 end_index = item->index;
5224 if (start_path && start_index != -1)
5225 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5226 if (end_path && end_index != -1)
5227 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5229 return start_index != -1;
5233 * gtk_icon_view_selected_foreach:
5234 * @icon_view: A #GtkIconView.
5235 * @func: The function to call for each selected icon.
5236 * @data: User data to pass to the function.
5238 * Calls a function for each selected icon. Note that the model or
5239 * selection cannot be modified from within this function.
5244 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5245 GtkIconViewForeachFunc func,
5250 for (list = icon_view->priv->items; list; list = list->next)
5252 GtkIconViewItem *item = list->data;
5253 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5256 (* func) (icon_view, path, data);
5258 gtk_tree_path_free (path);
5263 * gtk_icon_view_set_selection_mode:
5264 * @icon_view: A #GtkIconView.
5265 * @mode: The selection mode
5267 * Sets the selection mode of the @icon_view.
5272 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5273 GtkSelectionMode mode)
5275 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5277 if (mode == icon_view->priv->selection_mode)
5280 if (mode == GTK_SELECTION_NONE ||
5281 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5282 gtk_icon_view_unselect_all (icon_view);
5284 icon_view->priv->selection_mode = mode;
5286 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5290 * gtk_icon_view_get_selection_mode:
5291 * @icon_view: A #GtkIconView.
5293 * Gets the selection mode of the @icon_view.
5295 * Return value: the current selection mode
5300 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5302 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5304 return icon_view->priv->selection_mode;
5308 * gtk_icon_view_set_model:
5309 * @icon_view: A #GtkIconView.
5310 * @model: (allow-none): The model.
5312 * Sets the model for a #GtkIconView.
5313 * If the @icon_view already has a model set, it will remove
5314 * it before setting the new model. If @model is %NULL, then
5315 * it will unset the old model.
5320 gtk_icon_view_set_model (GtkIconView *icon_view,
5321 GtkTreeModel *model)
5323 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5324 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5326 if (icon_view->priv->model == model)
5329 if (icon_view->priv->scroll_to_path)
5331 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5332 icon_view->priv->scroll_to_path = NULL;
5335 gtk_icon_view_stop_editing (icon_view, TRUE);
5341 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5343 if (icon_view->priv->pixbuf_column != -1)
5345 column_type = gtk_tree_model_get_column_type (model,
5346 icon_view->priv->pixbuf_column);
5348 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5351 if (icon_view->priv->text_column != -1)
5353 column_type = gtk_tree_model_get_column_type (model,
5354 icon_view->priv->text_column);
5356 g_return_if_fail (column_type == G_TYPE_STRING);
5359 if (icon_view->priv->markup_column != -1)
5361 column_type = gtk_tree_model_get_column_type (model,
5362 icon_view->priv->markup_column);
5364 g_return_if_fail (column_type == G_TYPE_STRING);
5369 if (icon_view->priv->model)
5371 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5372 gtk_icon_view_row_changed,
5374 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5375 gtk_icon_view_row_inserted,
5377 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5378 gtk_icon_view_row_deleted,
5380 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5381 gtk_icon_view_rows_reordered,
5384 g_object_unref (icon_view->priv->model);
5386 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5387 g_list_free (icon_view->priv->items);
5388 icon_view->priv->items = NULL;
5389 icon_view->priv->anchor_item = NULL;
5390 icon_view->priv->cursor_item = NULL;
5391 icon_view->priv->last_single_clicked = NULL;
5392 icon_view->priv->width = 0;
5393 icon_view->priv->height = 0;
5396 icon_view->priv->model = model;
5398 if (icon_view->priv->model)
5400 g_object_ref (icon_view->priv->model);
5401 g_signal_connect (icon_view->priv->model,
5403 G_CALLBACK (gtk_icon_view_row_changed),
5405 g_signal_connect (icon_view->priv->model,
5407 G_CALLBACK (gtk_icon_view_row_inserted),
5409 g_signal_connect (icon_view->priv->model,
5411 G_CALLBACK (gtk_icon_view_row_deleted),
5413 g_signal_connect (icon_view->priv->model,
5415 G_CALLBACK (gtk_icon_view_rows_reordered),
5418 gtk_icon_view_build_items (icon_view);
5420 gtk_icon_view_queue_layout (icon_view);
5423 g_object_notify (G_OBJECT (icon_view), "model");
5425 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5426 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5430 * gtk_icon_view_get_model:
5431 * @icon_view: a #GtkIconView
5433 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5436 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5441 gtk_icon_view_get_model (GtkIconView *icon_view)
5443 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5445 return icon_view->priv->model;
5449 update_text_cell (GtkIconView *icon_view)
5451 GtkIconViewCellInfo *info;
5455 if (icon_view->priv->text_column == -1 &&
5456 icon_view->priv->markup_column == -1)
5458 if (icon_view->priv->text_cell != -1)
5460 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5461 icon_view->priv->pixbuf_cell--;
5463 info = g_list_nth_data (icon_view->priv->cell_list,
5464 icon_view->priv->text_cell);
5466 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5468 free_cell_info (info);
5470 icon_view->priv->n_cells--;
5471 icon_view->priv->text_cell = -1;
5476 if (icon_view->priv->text_cell == -1)
5478 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5479 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5480 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5483 if (info->cell == cell)
5485 icon_view->priv->text_cell = i;
5491 info = g_list_nth_data (icon_view->priv->cell_list,
5492 icon_view->priv->text_cell);
5494 if (icon_view->priv->markup_column != -1)
5495 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5497 "markup", icon_view->priv->markup_column,
5500 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5502 "text", icon_view->priv->text_column,
5505 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5506 g_object_set (info->cell,
5507 "alignment", PANGO_ALIGN_CENTER,
5508 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5513 g_object_set (info->cell,
5514 "alignment", PANGO_ALIGN_LEFT,
5515 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5523 update_pixbuf_cell (GtkIconView *icon_view)
5525 GtkIconViewCellInfo *info;
5529 if (icon_view->priv->pixbuf_column == -1)
5531 if (icon_view->priv->pixbuf_cell != -1)
5533 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5534 icon_view->priv->text_cell--;
5536 info = g_list_nth_data (icon_view->priv->cell_list,
5537 icon_view->priv->pixbuf_cell);
5539 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5541 free_cell_info (info);
5543 icon_view->priv->n_cells--;
5544 icon_view->priv->pixbuf_cell = -1;
5549 if (icon_view->priv->pixbuf_cell == -1)
5551 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5553 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5554 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5557 if (info->cell == cell)
5559 icon_view->priv->pixbuf_cell = i;
5565 info = g_list_nth_data (icon_view->priv->cell_list,
5566 icon_view->priv->pixbuf_cell);
5568 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5570 "pixbuf", icon_view->priv->pixbuf_column,
5573 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5574 g_object_set (info->cell,
5579 g_object_set (info->cell,
5587 * gtk_icon_view_set_text_column:
5588 * @icon_view: A #GtkIconView.
5589 * @column: A column in the currently used model, or -1 to display no text
5591 * Sets the column with text for @icon_view to be @column. The text
5592 * column must be of type #G_TYPE_STRING.
5597 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5600 if (column == icon_view->priv->text_column)
5604 icon_view->priv->text_column = -1;
5607 if (icon_view->priv->model != NULL)
5611 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5613 g_return_if_fail (column_type == G_TYPE_STRING);
5616 icon_view->priv->text_column = column;
5619 gtk_icon_view_stop_editing (icon_view, TRUE);
5621 update_text_cell (icon_view);
5623 gtk_icon_view_invalidate_sizes (icon_view);
5624 gtk_icon_view_queue_layout (icon_view);
5626 g_object_notify (G_OBJECT (icon_view), "text-column");
5630 * gtk_icon_view_get_text_column:
5631 * @icon_view: A #GtkIconView.
5633 * Returns the column with text for @icon_view.
5635 * Returns: the text column, or -1 if it's unset.
5640 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5642 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5644 return icon_view->priv->text_column;
5648 * gtk_icon_view_set_markup_column:
5649 * @icon_view: A #GtkIconView.
5650 * @column: A column in the currently used model, or -1 to display no text
5652 * Sets the column with markup information for @icon_view to be
5653 * @column. The markup column must be of type #G_TYPE_STRING.
5654 * If the markup column is set to something, it overrides
5655 * the text column set by gtk_icon_view_set_text_column().
5660 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5663 if (column == icon_view->priv->markup_column)
5667 icon_view->priv->markup_column = -1;
5670 if (icon_view->priv->model != NULL)
5674 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5676 g_return_if_fail (column_type == G_TYPE_STRING);
5679 icon_view->priv->markup_column = column;
5682 gtk_icon_view_stop_editing (icon_view, TRUE);
5684 update_text_cell (icon_view);
5686 gtk_icon_view_invalidate_sizes (icon_view);
5687 gtk_icon_view_queue_layout (icon_view);
5689 g_object_notify (G_OBJECT (icon_view), "markup-column");
5693 * gtk_icon_view_get_markup_column:
5694 * @icon_view: A #GtkIconView.
5696 * Returns the column with markup text for @icon_view.
5698 * Returns: the markup column, or -1 if it's unset.
5703 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5705 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5707 return icon_view->priv->markup_column;
5711 * gtk_icon_view_set_pixbuf_column:
5712 * @icon_view: A #GtkIconView.
5713 * @column: A column in the currently used model, or -1 to disable
5715 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5716 * column must be of type #GDK_TYPE_PIXBUF
5721 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5724 if (column == icon_view->priv->pixbuf_column)
5728 icon_view->priv->pixbuf_column = -1;
5731 if (icon_view->priv->model != NULL)
5735 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5737 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5740 icon_view->priv->pixbuf_column = column;
5743 gtk_icon_view_stop_editing (icon_view, TRUE);
5745 update_pixbuf_cell (icon_view);
5747 gtk_icon_view_invalidate_sizes (icon_view);
5748 gtk_icon_view_queue_layout (icon_view);
5750 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5755 * gtk_icon_view_get_pixbuf_column:
5756 * @icon_view: A #GtkIconView.
5758 * Returns the column with pixbufs for @icon_view.
5760 * Returns: the pixbuf column, or -1 if it's unset.
5765 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5767 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5769 return icon_view->priv->pixbuf_column;
5773 * gtk_icon_view_select_path:
5774 * @icon_view: A #GtkIconView.
5775 * @path: The #GtkTreePath to be selected.
5777 * Selects the row at @path.
5782 gtk_icon_view_select_path (GtkIconView *icon_view,
5785 GtkIconViewItem *item = NULL;
5787 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5788 g_return_if_fail (icon_view->priv->model != NULL);
5789 g_return_if_fail (path != NULL);
5791 if (gtk_tree_path_get_depth (path) > 0)
5792 item = g_list_nth_data (icon_view->priv->items,
5793 gtk_tree_path_get_indices(path)[0]);
5796 gtk_icon_view_select_item (icon_view, item);
5800 * gtk_icon_view_unselect_path:
5801 * @icon_view: A #GtkIconView.
5802 * @path: The #GtkTreePath to be unselected.
5804 * Unselects the row at @path.
5809 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5812 GtkIconViewItem *item;
5814 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5815 g_return_if_fail (icon_view->priv->model != NULL);
5816 g_return_if_fail (path != NULL);
5818 item = g_list_nth_data (icon_view->priv->items,
5819 gtk_tree_path_get_indices(path)[0]);
5824 gtk_icon_view_unselect_item (icon_view, item);
5828 * gtk_icon_view_get_selected_items:
5829 * @icon_view: A #GtkIconView.
5831 * Creates a list of paths of all selected items. Additionally, if you are
5832 * planning on modifying the model after calling this function, you may
5833 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5834 * To do this, you can use gtk_tree_row_reference_new().
5836 * To free the return value, use:
5838 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5839 * g_list_free (list);
5842 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5847 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5850 GList *selected = NULL;
5852 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5854 for (list = icon_view->priv->items; list != NULL; list = list->next)
5856 GtkIconViewItem *item = list->data;
5860 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5862 selected = g_list_prepend (selected, path);
5870 * gtk_icon_view_select_all:
5871 * @icon_view: A #GtkIconView.
5873 * Selects all the icons. @icon_view must has its selection mode set
5874 * to #GTK_SELECTION_MULTIPLE.
5879 gtk_icon_view_select_all (GtkIconView *icon_view)
5882 gboolean dirty = FALSE;
5884 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5886 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5889 for (items = icon_view->priv->items; items; items = items->next)
5891 GtkIconViewItem *item = items->data;
5893 if (!item->selected)
5896 item->selected = TRUE;
5897 gtk_icon_view_queue_draw_item (icon_view, item);
5902 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5906 * gtk_icon_view_unselect_all:
5907 * @icon_view: A #GtkIconView.
5909 * Unselects all the icons.
5914 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5916 gboolean dirty = FALSE;
5918 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5920 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5923 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5926 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5930 * gtk_icon_view_path_is_selected:
5931 * @icon_view: A #GtkIconView.
5932 * @path: A #GtkTreePath to check selection on.
5934 * Returns %TRUE if the icon pointed to by @path is currently
5935 * selected. If @path does not point to a valid location, %FALSE is returned.
5937 * Return value: %TRUE if @path is selected.
5942 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5945 GtkIconViewItem *item;
5947 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5948 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5949 g_return_val_if_fail (path != NULL, FALSE);
5951 item = g_list_nth_data (icon_view->priv->items,
5952 gtk_tree_path_get_indices(path)[0]);
5957 return item->selected;
5961 * gtk_icon_view_get_item_row:
5962 * @icon_view: a #GtkIconView
5963 * @path: the #GtkTreePath of the item
5965 * Gets the row in which the item @path is currently
5966 * displayed. Row numbers start at 0.
5968 * Returns: The row in which the item is displayed
5973 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5976 GtkIconViewItem *item;
5978 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5979 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5980 g_return_val_if_fail (path != NULL, FALSE);
5982 item = g_list_nth_data (icon_view->priv->items,
5983 gtk_tree_path_get_indices(path)[0]);
5992 * gtk_icon_view_get_item_column:
5993 * @icon_view: a #GtkIconView
5994 * @path: the #GtkTreePath of the item
5996 * Gets the column in which the item @path is currently
5997 * displayed. Column numbers start at 0.
5999 * Returns: The column in which the item is displayed
6004 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6007 GtkIconViewItem *item;
6009 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6010 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
6011 g_return_val_if_fail (path != NULL, FALSE);
6013 item = g_list_nth_data (icon_view->priv->items,
6014 gtk_tree_path_get_indices(path)[0]);
6023 * gtk_icon_view_item_activated:
6024 * @icon_view: A #GtkIconView
6025 * @path: The #GtkTreePath to be activated
6027 * Activates the item determined by @path.
6032 gtk_icon_view_item_activated (GtkIconView *icon_view,
6035 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6036 g_return_if_fail (path != NULL);
6038 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6042 * gtk_icon_view_set_orientation:
6043 * @icon_view: a #GtkIconView
6044 * @orientation: the relative position of texts and icons
6046 * Sets the ::orientation property which determines whether the labels
6047 * are drawn beside the icons instead of below.
6052 gtk_icon_view_set_orientation (GtkIconView *icon_view,
6053 GtkOrientation orientation)
6055 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6057 if (icon_view->priv->orientation != orientation)
6059 icon_view->priv->orientation = orientation;
6061 gtk_icon_view_stop_editing (icon_view, TRUE);
6062 gtk_icon_view_invalidate_sizes (icon_view);
6063 gtk_icon_view_queue_layout (icon_view);
6065 update_text_cell (icon_view);
6066 update_pixbuf_cell (icon_view);
6068 g_object_notify (G_OBJECT (icon_view), "orientation");
6073 * gtk_icon_view_get_orientation:
6074 * @icon_view: a #GtkIconView
6076 * Returns the value of the ::orientation property which determines
6077 * whether the labels are drawn beside the icons instead of below.
6079 * Return value: the relative position of texts and icons
6084 gtk_icon_view_get_orientation (GtkIconView *icon_view)
6086 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6087 GTK_ORIENTATION_VERTICAL);
6089 return icon_view->priv->orientation;
6093 * gtk_icon_view_set_columns:
6094 * @icon_view: a #GtkIconView
6095 * @columns: the number of columns
6097 * Sets the ::columns property which determines in how
6098 * many columns the icons are arranged. If @columns is
6099 * -1, the number of columns will be chosen automatically
6100 * to fill the available area.
6105 gtk_icon_view_set_columns (GtkIconView *icon_view,
6108 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6110 if (icon_view->priv->columns != columns)
6112 icon_view->priv->columns = columns;
6114 gtk_icon_view_stop_editing (icon_view, TRUE);
6115 gtk_icon_view_queue_layout (icon_view);
6117 g_object_notify (G_OBJECT (icon_view), "columns");
6122 * gtk_icon_view_get_columns:
6123 * @icon_view: a #GtkIconView
6125 * Returns the value of the ::columns property.
6127 * Return value: the number of columns, or -1
6132 gtk_icon_view_get_columns (GtkIconView *icon_view)
6134 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6136 return icon_view->priv->columns;
6140 * gtk_icon_view_set_item_width:
6141 * @icon_view: a #GtkIconView
6142 * @item_width: the width for each item
6144 * Sets the ::item-width property which specifies the width
6145 * to use for each item. If it is set to -1, the icon view will
6146 * automatically determine a suitable item size.
6151 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6154 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6156 if (icon_view->priv->item_width != item_width)
6158 icon_view->priv->item_width = item_width;
6160 gtk_icon_view_stop_editing (icon_view, TRUE);
6161 gtk_icon_view_invalidate_sizes (icon_view);
6162 gtk_icon_view_queue_layout (icon_view);
6164 update_text_cell (icon_view);
6166 g_object_notify (G_OBJECT (icon_view), "item-width");
6171 * gtk_icon_view_get_item_width:
6172 * @icon_view: a #GtkIconView
6174 * Returns the value of the ::item-width property.
6176 * Return value: the width of a single item, or -1
6181 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6183 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6185 return icon_view->priv->item_width;
6190 * gtk_icon_view_set_spacing:
6191 * @icon_view: a #GtkIconView
6192 * @spacing: the spacing
6194 * Sets the ::spacing property which specifies the space
6195 * which is inserted between the cells (i.e. the icon and
6196 * the text) of an item.
6201 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6204 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6206 if (icon_view->priv->spacing != spacing)
6208 icon_view->priv->spacing = spacing;
6210 gtk_icon_view_stop_editing (icon_view, TRUE);
6211 gtk_icon_view_invalidate_sizes (icon_view);
6212 gtk_icon_view_queue_layout (icon_view);
6214 g_object_notify (G_OBJECT (icon_view), "spacing");
6219 * gtk_icon_view_get_spacing:
6220 * @icon_view: a #GtkIconView
6222 * Returns the value of the ::spacing property.
6224 * Return value: the space between cells
6229 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6231 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6233 return icon_view->priv->spacing;
6237 * gtk_icon_view_set_row_spacing:
6238 * @icon_view: a #GtkIconView
6239 * @row_spacing: the row spacing
6241 * Sets the ::row-spacing property which specifies the space
6242 * which is inserted between the rows of the icon view.
6247 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6250 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6252 if (icon_view->priv->row_spacing != row_spacing)
6254 icon_view->priv->row_spacing = row_spacing;
6256 gtk_icon_view_stop_editing (icon_view, TRUE);
6257 gtk_icon_view_invalidate_sizes (icon_view);
6258 gtk_icon_view_queue_layout (icon_view);
6260 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6265 * gtk_icon_view_get_row_spacing:
6266 * @icon_view: a #GtkIconView
6268 * Returns the value of the ::row-spacing property.
6270 * Return value: the space between rows
6275 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6277 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6279 return icon_view->priv->row_spacing;
6283 * gtk_icon_view_set_column_spacing:
6284 * @icon_view: a #GtkIconView
6285 * @column_spacing: the column spacing
6287 * Sets the ::column-spacing property which specifies the space
6288 * which is inserted between the columns of the icon view.
6293 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6294 gint column_spacing)
6296 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6298 if (icon_view->priv->column_spacing != column_spacing)
6300 icon_view->priv->column_spacing = column_spacing;
6302 gtk_icon_view_stop_editing (icon_view, TRUE);
6303 gtk_icon_view_invalidate_sizes (icon_view);
6304 gtk_icon_view_queue_layout (icon_view);
6306 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6311 * gtk_icon_view_get_column_spacing:
6312 * @icon_view: a #GtkIconView
6314 * Returns the value of the ::column-spacing property.
6316 * Return value: the space between columns
6321 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6323 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6325 return icon_view->priv->column_spacing;
6329 * gtk_icon_view_set_margin:
6330 * @icon_view: a #GtkIconView
6331 * @margin: the margin
6333 * Sets the ::margin property which specifies the space
6334 * which is inserted at the top, bottom, left and right
6340 gtk_icon_view_set_margin (GtkIconView *icon_view,
6343 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6345 if (icon_view->priv->margin != margin)
6347 icon_view->priv->margin = margin;
6349 gtk_icon_view_stop_editing (icon_view, TRUE);
6350 gtk_icon_view_invalidate_sizes (icon_view);
6351 gtk_icon_view_queue_layout (icon_view);
6353 g_object_notify (G_OBJECT (icon_view), "margin");
6358 * gtk_icon_view_get_margin:
6359 * @icon_view: a #GtkIconView
6361 * Returns the value of the ::margin property.
6363 * Return value: the space at the borders
6368 gtk_icon_view_get_margin (GtkIconView *icon_view)
6370 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6372 return icon_view->priv->margin;
6376 * gtk_icon_view_set_item_padding:
6377 * @icon_view: a #GtkIconView
6378 * @item_padding: the item padding
6380 * Sets the #GtkIconView:item-padding property which specifies the padding
6381 * around each of the icon view's items.
6386 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6389 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6391 if (icon_view->priv->item_padding != item_padding)
6393 icon_view->priv->item_padding = item_padding;
6395 gtk_icon_view_stop_editing (icon_view, TRUE);
6396 gtk_icon_view_invalidate_sizes (icon_view);
6397 gtk_icon_view_queue_layout (icon_view);
6399 g_object_notify (G_OBJECT (icon_view), "item-padding");
6404 * gtk_icon_view_get_item_padding:
6405 * @icon_view: a #GtkIconView
6407 * Returns the value of the ::item-padding property.
6409 * Return value: the padding around items
6414 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6416 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6418 return icon_view->priv->item_padding;
6421 /* Get/set whether drag_motion requested the drag data and
6422 * drag_data_received should thus not actually insert the data,
6423 * since the data doesn't result from a drop.
6426 set_status_pending (GdkDragContext *context,
6427 GdkDragAction suggested_action)
6429 g_object_set_data (G_OBJECT (context),
6430 I_("gtk-icon-view-status-pending"),
6431 GINT_TO_POINTER (suggested_action));
6434 static GdkDragAction
6435 get_status_pending (GdkDragContext *context)
6437 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6438 "gtk-icon-view-status-pending"));
6442 unset_reorderable (GtkIconView *icon_view)
6444 if (icon_view->priv->reorderable)
6446 icon_view->priv->reorderable = FALSE;
6447 g_object_notify (G_OBJECT (icon_view), "reorderable");
6452 set_source_row (GdkDragContext *context,
6453 GtkTreeModel *model,
6454 GtkTreePath *source_row)
6457 g_object_set_data_full (G_OBJECT (context),
6458 I_("gtk-icon-view-source-row"),
6459 gtk_tree_row_reference_new (model, source_row),
6460 (GDestroyNotify) gtk_tree_row_reference_free);
6462 g_object_set_data_full (G_OBJECT (context),
6463 I_("gtk-icon-view-source-row"),
6468 get_source_row (GdkDragContext *context)
6470 GtkTreeRowReference *ref;
6472 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6475 return gtk_tree_row_reference_get_path (ref);
6482 GtkTreeRowReference *dest_row;
6483 gboolean empty_view_drop;
6484 gboolean drop_append_mode;
6488 dest_row_free (gpointer data)
6490 DestRow *dr = (DestRow *)data;
6492 gtk_tree_row_reference_free (dr->dest_row);
6497 set_dest_row (GdkDragContext *context,
6498 GtkTreeModel *model,
6499 GtkTreePath *dest_row,
6500 gboolean empty_view_drop,
6501 gboolean drop_append_mode)
6507 g_object_set_data_full (G_OBJECT (context),
6508 I_("gtk-icon-view-dest-row"),
6513 dr = g_new0 (DestRow, 1);
6515 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6516 dr->empty_view_drop = empty_view_drop;
6517 dr->drop_append_mode = drop_append_mode;
6518 g_object_set_data_full (G_OBJECT (context),
6519 I_("gtk-icon-view-dest-row"),
6520 dr, (GDestroyNotify) dest_row_free);
6524 get_dest_row (GdkDragContext *context)
6528 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6532 GtkTreePath *path = NULL;
6535 path = gtk_tree_row_reference_get_path (dr->dest_row);
6536 else if (dr->empty_view_drop)
6537 path = gtk_tree_path_new_from_indices (0, -1);
6541 if (path && dr->drop_append_mode)
6542 gtk_tree_path_next (path);
6551 check_model_dnd (GtkTreeModel *model,
6552 GType required_iface,
6553 const gchar *signal)
6555 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6557 g_warning ("You must override the default '%s' handler "
6558 "on GtkIconView when using models that don't support "
6559 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6560 "is to connect to '%s' and call "
6561 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6562 "the default handler from running. Look at the source code "
6563 "for the default handler in gtkiconview.c to get an idea what "
6564 "your handler should do. (gtkiconview.c is in the GTK+ source "
6565 "code.) If you're using GTK+ from a language other than C, "
6566 "there may be a more natural way to override default handlers, e.g. via derivation.",
6567 signal, g_type_name (required_iface), signal);
6575 remove_scroll_timeout (GtkIconView *icon_view)
6577 if (icon_view->priv->scroll_timeout_id != 0)
6579 g_source_remove (icon_view->priv->scroll_timeout_id);
6581 icon_view->priv->scroll_timeout_id = 0;
6586 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6588 gint px, py, x, y, width, height;
6589 gint hoffset, voffset;
6591 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6592 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6594 /* see if we are near the edge. */
6595 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6597 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6599 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6601 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6604 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6605 icon_view->priv->vadjustment->value + voffset);
6608 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6609 icon_view->priv->hadjustment->value + hoffset);
6614 drag_scroll_timeout (gpointer data)
6616 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6618 gtk_icon_view_autoscroll (icon_view);
6625 set_destination (GtkIconView *icon_view,
6626 GdkDragContext *context,
6629 GdkDragAction *suggested_action,
6633 GtkTreePath *path = NULL;
6634 GtkIconViewDropPosition pos;
6635 GtkIconViewDropPosition old_pos;
6636 GtkTreePath *old_dest_path = NULL;
6637 gboolean can_drop = FALSE;
6639 widget = GTK_WIDGET (icon_view);
6641 *suggested_action = 0;
6644 if (!icon_view->priv->dest_set)
6646 /* someone unset us as a drag dest, note that if
6647 * we return FALSE drag_leave isn't called
6650 gtk_icon_view_set_drag_dest_item (icon_view,
6652 GTK_ICON_VIEW_DROP_LEFT);
6654 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6656 return FALSE; /* no longer a drop site */
6659 *target = gtk_drag_dest_find_target (widget, context,
6660 gtk_drag_dest_get_target_list (widget));
6661 if (*target == GDK_NONE)
6664 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6667 GtkTreeModel *model;
6669 /* the row got dropped on empty space, let's setup a special case
6673 gtk_tree_path_free (path);
6675 model = gtk_icon_view_get_model (icon_view);
6677 n_children = gtk_tree_model_iter_n_children (model, NULL);
6680 pos = GTK_ICON_VIEW_DROP_BELOW;
6681 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6685 pos = GTK_ICON_VIEW_DROP_ABOVE;
6686 path = gtk_tree_path_new_from_indices (0, -1);
6696 gtk_icon_view_get_drag_dest_item (icon_view,
6701 gtk_tree_path_free (old_dest_path);
6703 if (TRUE /* FIXME if the location droppable predicate */)
6711 GtkWidget *source_widget;
6713 *suggested_action = context->suggested_action;
6714 source_widget = gtk_drag_get_source_widget (context);
6716 if (source_widget == widget)
6718 /* Default to MOVE, unless the user has
6719 * pressed ctrl or shift to affect available actions
6721 if ((context->actions & GDK_ACTION_MOVE) != 0)
6722 *suggested_action = GDK_ACTION_MOVE;
6725 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6730 /* can't drop here */
6731 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6733 GTK_ICON_VIEW_DROP_LEFT);
6737 gtk_tree_path_free (path);
6743 get_logical_destination (GtkIconView *icon_view,
6744 gboolean *drop_append_mode)
6746 /* adjust path to point to the row the drop goes in front of */
6747 GtkTreePath *path = NULL;
6748 GtkIconViewDropPosition pos;
6750 *drop_append_mode = FALSE;
6752 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6757 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6758 pos == GTK_ICON_VIEW_DROP_BELOW)
6761 GtkTreeModel *model = icon_view->priv->model;
6763 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6764 !gtk_tree_model_iter_next (model, &iter))
6765 *drop_append_mode = TRUE;
6768 *drop_append_mode = FALSE;
6769 gtk_tree_path_next (path);
6777 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6778 GdkEventMotion *event)
6780 GtkWidget *widget = GTK_WIDGET (icon_view);
6781 GdkDragContext *context;
6782 GtkTreePath *path = NULL;
6784 GtkTreeModel *model;
6785 gboolean retval = FALSE;
6787 if (!icon_view->priv->source_set)
6790 if (icon_view->priv->pressed_button < 0)
6793 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6794 icon_view->priv->press_start_x,
6795 icon_view->priv->press_start_y,
6796 event->x, event->y))
6799 model = gtk_icon_view_get_model (icon_view);
6804 button = icon_view->priv->pressed_button;
6805 icon_view->priv->pressed_button = -1;
6807 path = gtk_icon_view_get_path_at_pos (icon_view,
6808 icon_view->priv->press_start_x,
6809 icon_view->priv->press_start_y);
6814 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6815 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6819 /* FIXME Check whether we're a start button, if not return FALSE and
6823 /* Now we can begin the drag */
6827 context = gtk_drag_begin (widget,
6828 gtk_drag_source_get_target_list (widget),
6829 icon_view->priv->source_actions,
6833 set_source_row (context, model, path);
6837 gtk_tree_path_free (path);
6842 /* Source side drag signals */
6844 gtk_icon_view_drag_begin (GtkWidget *widget,
6845 GdkDragContext *context)
6847 GtkIconView *icon_view;
6848 GtkIconViewItem *item;
6853 icon_view = GTK_ICON_VIEW (widget);
6855 /* if the user uses a custom DnD impl, we don't set the icon here */
6856 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6859 item = gtk_icon_view_get_item_at_coords (icon_view,
6860 icon_view->priv->press_start_x,
6861 icon_view->priv->press_start_y,
6865 g_return_if_fail (item != NULL);
6867 x = icon_view->priv->press_start_x - item->x + 1;
6868 y = icon_view->priv->press_start_y - item->y + 1;
6870 path = gtk_tree_path_new_from_indices (item->index, -1);
6871 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6872 gtk_tree_path_free (path);
6874 gtk_drag_set_icon_pixmap (context,
6875 gdk_drawable_get_colormap (icon),
6880 g_object_unref (icon);
6884 gtk_icon_view_drag_end (GtkWidget *widget,
6885 GdkDragContext *context)
6891 gtk_icon_view_drag_data_get (GtkWidget *widget,
6892 GdkDragContext *context,
6893 GtkSelectionData *selection_data,
6897 GtkIconView *icon_view;
6898 GtkTreeModel *model;
6899 GtkTreePath *source_row;
6901 icon_view = GTK_ICON_VIEW (widget);
6902 model = gtk_icon_view_get_model (icon_view);
6907 if (!icon_view->priv->source_set)
6910 source_row = get_source_row (context);
6912 if (source_row == NULL)
6915 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6916 * any model; for DragSource models there are some other targets
6920 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6921 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6926 /* If drag_data_get does nothing, try providing row data. */
6927 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6928 gtk_tree_set_row_drag_data (selection_data,
6933 gtk_tree_path_free (source_row);
6937 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6938 GdkDragContext *context)
6940 GtkTreeModel *model;
6941 GtkIconView *icon_view;
6942 GtkTreePath *source_row;
6944 icon_view = GTK_ICON_VIEW (widget);
6945 model = gtk_icon_view_get_model (icon_view);
6947 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6950 if (!icon_view->priv->source_set)
6953 source_row = get_source_row (context);
6955 if (source_row == NULL)
6958 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6961 gtk_tree_path_free (source_row);
6963 set_source_row (context, NULL, NULL);
6966 /* Target side drag signals */
6968 gtk_icon_view_drag_leave (GtkWidget *widget,
6969 GdkDragContext *context,
6972 GtkIconView *icon_view;
6974 icon_view = GTK_ICON_VIEW (widget);
6976 /* unset any highlight row */
6977 gtk_icon_view_set_drag_dest_item (icon_view,
6979 GTK_ICON_VIEW_DROP_LEFT);
6981 remove_scroll_timeout (icon_view);
6985 gtk_icon_view_drag_motion (GtkWidget *widget,
6986 GdkDragContext *context,
6991 GtkTreePath *path = NULL;
6992 GtkIconViewDropPosition pos;
6993 GtkIconView *icon_view;
6994 GdkDragAction suggested_action = 0;
6998 icon_view = GTK_ICON_VIEW (widget);
7000 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7003 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7005 /* we only know this *after* set_desination_row */
7006 empty = icon_view->priv->empty_view_drop;
7008 if (path == NULL && !empty)
7010 /* Can't drop here. */
7011 gdk_drag_status (context, 0, time);
7015 if (icon_view->priv->scroll_timeout_id == 0)
7017 icon_view->priv->scroll_timeout_id =
7018 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7021 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7023 /* Request data so we can use the source row when
7024 * determining whether to accept the drop
7026 set_status_pending (context, suggested_action);
7027 gtk_drag_get_data (widget, context, target, time);
7031 set_status_pending (context, 0);
7032 gdk_drag_status (context, suggested_action, time);
7037 gtk_tree_path_free (path);
7043 gtk_icon_view_drag_drop (GtkWidget *widget,
7044 GdkDragContext *context,
7049 GtkIconView *icon_view;
7051 GdkDragAction suggested_action = 0;
7052 GdkAtom target = GDK_NONE;
7053 GtkTreeModel *model;
7054 gboolean drop_append_mode;
7056 icon_view = GTK_ICON_VIEW (widget);
7057 model = gtk_icon_view_get_model (icon_view);
7059 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7061 if (!icon_view->priv->dest_set)
7064 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7067 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7070 path = get_logical_destination (icon_view, &drop_append_mode);
7072 if (target != GDK_NONE && path != NULL)
7074 /* in case a motion had requested drag data, change things so we
7075 * treat drag data receives as a drop.
7077 set_status_pending (context, 0);
7078 set_dest_row (context, model, path,
7079 icon_view->priv->empty_view_drop, drop_append_mode);
7083 gtk_tree_path_free (path);
7085 /* Unset this thing */
7086 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7088 if (target != GDK_NONE)
7090 gtk_drag_get_data (widget, context, target, time);
7098 gtk_icon_view_drag_data_received (GtkWidget *widget,
7099 GdkDragContext *context,
7102 GtkSelectionData *selection_data,
7107 gboolean accepted = FALSE;
7108 GtkTreeModel *model;
7109 GtkIconView *icon_view;
7110 GtkTreePath *dest_row;
7111 GdkDragAction suggested_action;
7112 gboolean drop_append_mode;
7114 icon_view = GTK_ICON_VIEW (widget);
7115 model = gtk_icon_view_get_model (icon_view);
7117 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7120 if (!icon_view->priv->dest_set)
7123 suggested_action = get_status_pending (context);
7125 if (suggested_action)
7127 /* We are getting this data due to a request in drag_motion,
7128 * rather than due to a request in drag_drop, so we are just
7129 * supposed to call drag_status, not actually paste in the
7132 path = get_logical_destination (icon_view, &drop_append_mode);
7135 suggested_action = 0;
7137 if (suggested_action)
7139 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7142 suggested_action = 0;
7145 gdk_drag_status (context, suggested_action, time);
7148 gtk_tree_path_free (path);
7150 /* If you can't drop, remove user drop indicator until the next motion */
7151 if (suggested_action == 0)
7152 gtk_icon_view_set_drag_dest_item (icon_view,
7154 GTK_ICON_VIEW_DROP_LEFT);
7159 dest_row = get_dest_row (context);
7161 if (dest_row == NULL)
7164 if (selection_data->length >= 0)
7166 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7172 gtk_drag_finish (context,
7174 (context->action == GDK_ACTION_MOVE),
7177 gtk_tree_path_free (dest_row);
7180 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7183 /* Drag-and-Drop support */
7185 * gtk_icon_view_enable_model_drag_source:
7186 * @icon_view: a #GtkIconTreeView
7187 * @start_button_mask: Mask of allowed buttons to start drag
7188 * @targets: the table of targets that the drag will support
7189 * @n_targets: the number of items in @targets
7190 * @actions: the bitmask of possible actions for a drag from this
7193 * Turns @icon_view into a drag source for automatic DND. Calling this
7194 * method sets #GtkIconView:reorderable to %FALSE.
7199 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7200 GdkModifierType start_button_mask,
7201 const GtkTargetEntry *targets,
7203 GdkDragAction actions)
7205 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7207 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7209 icon_view->priv->start_button_mask = start_button_mask;
7210 icon_view->priv->source_actions = actions;
7212 icon_view->priv->source_set = TRUE;
7214 unset_reorderable (icon_view);
7218 * gtk_icon_view_enable_model_drag_dest:
7219 * @icon_view: a #GtkIconView
7220 * @targets: the table of targets that the drag will support
7221 * @n_targets: the number of items in @targets
7222 * @actions: the bitmask of possible actions for a drag to this
7225 * Turns @icon_view into a drop destination for automatic DND. Calling this
7226 * method sets #GtkIconView:reorderable to %FALSE.
7231 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7232 const GtkTargetEntry *targets,
7234 GdkDragAction actions)
7236 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7238 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7240 icon_view->priv->dest_actions = actions;
7242 icon_view->priv->dest_set = TRUE;
7244 unset_reorderable (icon_view);
7248 * gtk_icon_view_unset_model_drag_source:
7249 * @icon_view: a #GtkIconView
7251 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7252 * method sets #GtkIconView:reorderable to %FALSE.
7257 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7259 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7261 if (icon_view->priv->source_set)
7263 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7264 icon_view->priv->source_set = FALSE;
7267 unset_reorderable (icon_view);
7271 * gtk_icon_view_unset_model_drag_dest:
7272 * @icon_view: a #GtkIconView
7274 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7275 * method sets #GtkIconView:reorderable to %FALSE.
7280 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7282 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7284 if (icon_view->priv->dest_set)
7286 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7287 icon_view->priv->dest_set = FALSE;
7290 unset_reorderable (icon_view);
7293 /* These are useful to implement your own custom stuff. */
7295 * gtk_icon_view_set_drag_dest_item:
7296 * @icon_view: a #GtkIconView
7297 * @path: (allow-none): The path of the item to highlight, or %NULL.
7298 * @pos: Specifies where to drop, relative to the item
7300 * Sets the item that is highlighted for feedback.
7305 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7307 GtkIconViewDropPosition pos)
7309 /* Note; this function is exported to allow a custom DND
7310 * implementation, so it can't touch TreeViewDragInfo
7313 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7315 if (icon_view->priv->dest_item)
7317 GtkTreePath *current_path;
7318 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7319 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7320 icon_view->priv->dest_item = NULL;
7322 gtk_icon_view_queue_draw_path (icon_view, current_path);
7323 gtk_tree_path_free (current_path);
7326 /* special case a drop on an empty model */
7327 icon_view->priv->empty_view_drop = FALSE;
7328 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7329 && gtk_tree_path_get_depth (path) == 1
7330 && gtk_tree_path_get_indices (path)[0] == 0)
7334 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7337 if (n_children == 0)
7338 icon_view->priv->empty_view_drop = TRUE;
7341 icon_view->priv->dest_pos = pos;
7345 icon_view->priv->dest_item =
7346 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7347 icon_view->priv->model, path);
7349 gtk_icon_view_queue_draw_path (icon_view, path);
7354 * gtk_icon_view_get_drag_dest_item:
7355 * @icon_view: a #GtkIconView
7356 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7357 * @pos: (allow-none): Return location for the drop position, or %NULL
7359 * Gets information about the item that is highlighted for feedback.
7364 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7366 GtkIconViewDropPosition *pos)
7368 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7372 if (icon_view->priv->dest_item)
7373 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7379 *pos = icon_view->priv->dest_pos;
7383 * gtk_icon_view_get_dest_item_at_pos:
7384 * @icon_view: a #GtkIconView
7385 * @drag_x: the position to determine the destination item for
7386 * @drag_y: the position to determine the destination item for
7387 * @path: (allow-none): Return location for the path of the item, or %NULL.
7388 * @pos: (allow-none): Return location for the drop position, or %NULL
7390 * Determines the destination item for a given position.
7392 * Return value: whether there is an item at the given position.
7397 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7401 GtkIconViewDropPosition *pos)
7403 GtkIconViewItem *item;
7405 /* Note; this function is exported to allow a custom DND
7406 * implementation, so it can't touch TreeViewDragInfo
7409 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7410 g_return_val_if_fail (drag_x >= 0, FALSE);
7411 g_return_val_if_fail (drag_y >= 0, FALSE);
7412 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7418 item = gtk_icon_view_get_item_at_coords (icon_view,
7419 drag_x + icon_view->priv->hadjustment->value,
7420 drag_y + icon_view->priv->vadjustment->value,
7427 *path = gtk_tree_path_new_from_indices (item->index, -1);
7431 if (drag_x < item->x + item->width / 4)
7432 *pos = GTK_ICON_VIEW_DROP_LEFT;
7433 else if (drag_x > item->x + item->width * 3 / 4)
7434 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7435 else if (drag_y < item->y + item->height / 4)
7436 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7437 else if (drag_y > item->y + item->height * 3 / 4)
7438 *pos = GTK_ICON_VIEW_DROP_BELOW;
7440 *pos = GTK_ICON_VIEW_DROP_INTO;
7447 * gtk_icon_view_create_drag_icon:
7448 * @icon_view: a #GtkIconView
7449 * @path: a #GtkTreePath in @icon_view
7451 * Creates a #GdkPixmap representation of the item at @path.
7452 * This image is used for a drag icon.
7454 * Return value: a newly-allocated pixmap of the drag icon.
7459 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7464 GdkPixmap *drawable;
7469 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7470 g_return_val_if_fail (path != NULL, NULL);
7472 widget = GTK_WIDGET (icon_view);
7474 if (!gtk_widget_get_realized (widget))
7477 index = gtk_tree_path_get_indices (path)[0];
7479 for (l = icon_view->priv->items; l; l = l->next)
7481 GtkIconViewItem *item = l->data;
7483 if (index == item->index)
7485 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7490 cr = gdk_cairo_create (drawable);
7491 cairo_set_line_width (cr, 1.);
7493 gdk_cairo_set_source_color
7494 (cr, &widget->style->base[gtk_widget_get_state (widget)]);
7495 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7500 area.width = item->width;
7501 area.height = item->height;
7503 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7504 drawable, 1, 1, FALSE);
7506 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7507 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7520 * gtk_icon_view_get_reorderable:
7521 * @icon_view: a #GtkIconView
7523 * Retrieves whether the user can reorder the list via drag-and-drop.
7524 * See gtk_icon_view_set_reorderable().
7526 * Return value: %TRUE if the list can be reordered.
7531 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7533 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7535 return icon_view->priv->reorderable;
7538 static const GtkTargetEntry item_targets[] = {
7539 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7544 * gtk_icon_view_set_reorderable:
7545 * @icon_view: A #GtkIconView.
7546 * @reorderable: %TRUE, if the list of items can be reordered.
7548 * This function is a convenience function to allow you to reorder models that
7549 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7550 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7551 * the user can reorder the model by dragging and dropping rows. The
7552 * developer can listen to these changes by connecting to the model's
7553 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7554 * the icon view as a drag source and destination. Therefore, drag and
7555 * drop can not be used in a reorderable view for any other purpose.
7557 * This function does not give you any degree of control over the order -- any
7558 * reordering is allowed. If more control is needed, you should probably
7559 * handle drag and drop manually.
7564 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7565 gboolean reorderable)
7567 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7569 reorderable = reorderable != FALSE;
7571 if (icon_view->priv->reorderable == reorderable)
7576 gtk_icon_view_enable_model_drag_source (icon_view,
7579 G_N_ELEMENTS (item_targets),
7581 gtk_icon_view_enable_model_drag_dest (icon_view,
7583 G_N_ELEMENTS (item_targets),
7588 gtk_icon_view_unset_model_drag_source (icon_view);
7589 gtk_icon_view_unset_model_drag_dest (icon_view);
7592 icon_view->priv->reorderable = reorderable;
7594 g_object_notify (G_OBJECT (icon_view), "reorderable");
7598 /* Accessibility Support */
7600 static gpointer accessible_parent_class;
7601 static gpointer accessible_item_parent_class;
7602 static GQuark accessible_private_data_quark = 0;
7604 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7605 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7606 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7608 static GType gtk_icon_view_item_accessible_get_type (void);
7619 GtkIconViewItem *item;
7623 AtkStateSet *state_set;
7627 GtkTextBuffer *text_buffer;
7629 gchar *action_descriptions[LAST_ACTION];
7630 gchar *image_description;
7631 guint action_idle_handler;
7632 } GtkIconViewItemAccessible;
7634 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7640 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7645 typedef struct _GtkIconViewItemAccessibleClass
7647 AtkObjectClass parent_class;
7649 } GtkIconViewItemAccessibleClass;
7651 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7654 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7656 GtkIconViewItemAccessible *item;
7657 GtkIconView *icon_view;
7660 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7661 item->action_idle_handler = 0;
7663 if (item->widget != NULL)
7665 icon_view = GTK_ICON_VIEW (item->widget);
7666 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7667 gtk_icon_view_item_activated (icon_view, path);
7668 gtk_tree_path_free (path);
7675 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7678 GtkIconViewItemAccessible *item;
7680 if (i < 0 || i >= LAST_ACTION)
7683 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7685 if (!GTK_IS_ICON_VIEW (item->widget))
7688 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7693 case ACTION_ACTIVATE:
7694 if (!item->action_idle_handler)
7695 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7698 g_assert_not_reached ();
7706 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7711 static const gchar *
7712 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7715 GtkIconViewItemAccessible *item;
7717 if (i < 0 || i >= LAST_ACTION)
7720 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7722 if (item->action_descriptions[i])
7723 return item->action_descriptions[i];
7725 return gtk_icon_view_item_accessible_action_descriptions[i];
7728 static const gchar *
7729 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7732 if (i < 0 || i >= LAST_ACTION)
7735 return gtk_icon_view_item_accessible_action_names[i];
7739 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7741 const gchar *description)
7743 GtkIconViewItemAccessible *item;
7745 if (i < 0 || i >= LAST_ACTION)
7748 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7750 g_free (item->action_descriptions[i]);
7752 item->action_descriptions[i] = g_strdup (description);
7758 atk_action_item_interface_init (AtkActionIface *iface)
7760 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7761 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7762 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7763 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7764 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7767 static const gchar *
7768 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7770 GtkIconViewItemAccessible *item;
7772 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7774 return item->image_description;
7778 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7779 const gchar *description)
7781 GtkIconViewItemAccessible *item;
7783 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7785 g_free (item->image_description);
7786 item->image_description = g_strdup (description);
7792 get_pixbuf_box (GtkIconView *icon_view,
7793 GtkIconViewItem *item,
7798 for (l = icon_view->priv->cell_list; l; l = l->next)
7800 GtkIconViewCellInfo *info = l->data;
7802 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7804 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7814 get_text (GtkIconView *icon_view,
7815 GtkIconViewItem *item)
7820 for (l = icon_view->priv->cell_list; l; l = l->next)
7822 GtkIconViewCellInfo *info = l->data;
7824 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7826 g_object_get (info->cell, "text", &text, NULL);
7836 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7840 GtkIconViewItemAccessible *item;
7843 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7845 if (!GTK_IS_ICON_VIEW (item->widget))
7848 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7851 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7854 *height = box.height;
7859 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7862 AtkCoordType coord_type)
7864 GtkIconViewItemAccessible *item;
7867 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7869 if (!GTK_IS_ICON_VIEW (item->widget))
7872 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7875 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7877 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7879 *x+= box.x - item->item->x;
7880 *y+= box.y - item->item->y;
7886 atk_image_item_interface_init (AtkImageIface *iface)
7888 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7889 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7890 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7891 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7895 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7899 GtkIconViewItemAccessible *item;
7900 GtkTextIter start, end;
7901 GtkTextBuffer *buffer;
7903 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7905 if (!GTK_IS_ICON_VIEW (item->widget))
7908 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7911 buffer = item->text_buffer;
7912 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7914 gtk_text_buffer_get_end_iter (buffer, &end);
7916 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7918 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7922 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7925 GtkIconViewItemAccessible *item;
7926 GtkTextIter start, end;
7927 GtkTextBuffer *buffer;
7931 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7933 if (!GTK_IS_ICON_VIEW (item->widget))
7936 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7939 buffer = item->text_buffer;
7940 if (offset >= gtk_text_buffer_get_char_count (buffer))
7943 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7945 gtk_text_iter_forward_char (&end);
7946 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7947 unichar = g_utf8_get_char (string);
7955 get_pango_text_offsets (PangoLayout *layout,
7956 GtkTextBuffer *buffer,
7958 AtkTextBoundary boundary_type,
7962 GtkTextIter *start_iter,
7963 GtkTextIter *end_iter)
7965 PangoLayoutIter *iter;
7966 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7967 gint index, start_index, end_index;
7969 gboolean found = FALSE;
7971 text = pango_layout_get_text (layout);
7972 index = g_utf8_offset_to_pointer (text, offset) - text;
7973 iter = pango_layout_get_iter (layout);
7976 line = pango_layout_iter_get_line_readonly (iter);
7977 start_index = line->start_index;
7978 end_index = start_index + line->length;
7980 if (index >= start_index && index <= end_index)
7983 * Found line for offset
7989 * We want the previous line
7993 switch (boundary_type)
7995 case ATK_TEXT_BOUNDARY_LINE_START:
7996 end_index = start_index;
7997 start_index = prev_line->start_index;
7999 case ATK_TEXT_BOUNDARY_LINE_END:
8001 start_index = prev_prev_line->start_index +
8002 prev_prev_line->length;
8003 end_index = prev_line->start_index + prev_line->length;
8006 g_assert_not_reached();
8010 start_index = end_index = 0;
8013 switch (boundary_type)
8015 case ATK_TEXT_BOUNDARY_LINE_START:
8016 if (pango_layout_iter_next_line (iter))
8017 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8019 case ATK_TEXT_BOUNDARY_LINE_END:
8021 start_index = prev_line->start_index +
8025 g_assert_not_reached();
8030 * We want the next line
8032 if (pango_layout_iter_next_line (iter))
8034 line = pango_layout_iter_get_line_readonly (iter);
8035 switch (boundary_type)
8037 case ATK_TEXT_BOUNDARY_LINE_START:
8038 start_index = line->start_index;
8039 if (pango_layout_iter_next_line (iter))
8040 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8042 end_index = start_index + line->length;
8044 case ATK_TEXT_BOUNDARY_LINE_END:
8045 start_index = end_index;
8046 end_index = line->start_index + line->length;
8049 g_assert_not_reached();
8053 start_index = end_index;
8059 prev_prev_line = prev_line;
8062 while (pango_layout_iter_next_line (iter));
8066 start_index = prev_line->start_index + prev_line->length;
8067 end_index = start_index;
8069 pango_layout_iter_free (iter);
8070 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8071 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8073 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8074 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8079 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8081 AtkTextBoundary boundary_type,
8085 GtkIconViewItemAccessible *item;
8086 GtkTextIter start, end;
8087 GtkTextBuffer *buffer;
8089 GtkIconView *icon_view;
8092 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8094 if (!GTK_IS_ICON_VIEW (item->widget))
8097 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8100 buffer = item->text_buffer;
8102 if (!gtk_text_buffer_get_char_count (buffer))
8106 return g_strdup ("");
8108 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8112 switch (boundary_type)
8114 case ATK_TEXT_BOUNDARY_CHAR:
8115 gtk_text_iter_backward_char(&start);
8117 case ATK_TEXT_BOUNDARY_WORD_START:
8118 if (!gtk_text_iter_starts_word (&start))
8119 gtk_text_iter_backward_word_start (&start);
8121 gtk_text_iter_backward_word_start(&start);
8123 case ATK_TEXT_BOUNDARY_WORD_END:
8124 if (gtk_text_iter_inside_word (&start) &&
8125 !gtk_text_iter_starts_word (&start))
8126 gtk_text_iter_backward_word_start (&start);
8127 while (!gtk_text_iter_ends_word (&start))
8129 if (!gtk_text_iter_backward_char (&start))
8133 gtk_text_iter_backward_word_start(&start);
8134 while (!gtk_text_iter_ends_word (&start))
8136 if (!gtk_text_iter_backward_char (&start))
8140 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8141 if (!gtk_text_iter_starts_sentence (&start))
8142 gtk_text_iter_backward_sentence_start (&start);
8144 gtk_text_iter_backward_sentence_start (&start);
8146 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8147 if (gtk_text_iter_inside_sentence (&start) &&
8148 !gtk_text_iter_starts_sentence (&start))
8149 gtk_text_iter_backward_sentence_start (&start);
8150 while (!gtk_text_iter_ends_sentence (&start))
8152 if (!gtk_text_iter_backward_char (&start))
8156 gtk_text_iter_backward_sentence_start (&start);
8157 while (!gtk_text_iter_ends_sentence (&start))
8159 if (!gtk_text_iter_backward_char (&start))
8163 case ATK_TEXT_BOUNDARY_LINE_START:
8164 case ATK_TEXT_BOUNDARY_LINE_END:
8166 icon_view = GTK_ICON_VIEW (item->widget);
8167 /* FIXME we probably have to use GailTextCell to salvage this */
8168 gtk_icon_view_update_item_text (icon_view, item->item);
8169 get_pango_text_offsets (icon_view->priv->layout,
8182 *start_offset = gtk_text_iter_get_offset (&start);
8183 *end_offset = gtk_text_iter_get_offset (&end);
8185 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8189 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8191 AtkTextBoundary boundary_type,
8195 GtkIconViewItemAccessible *item;
8196 GtkTextIter start, end;
8197 GtkTextBuffer *buffer;
8199 GtkIconView *icon_view;
8202 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8204 if (!GTK_IS_ICON_VIEW (item->widget))
8207 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8210 buffer = item->text_buffer;
8212 if (!gtk_text_buffer_get_char_count (buffer))
8216 return g_strdup ("");
8218 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8222 switch (boundary_type)
8224 case ATK_TEXT_BOUNDARY_CHAR:
8225 gtk_text_iter_forward_char (&end);
8227 case ATK_TEXT_BOUNDARY_WORD_START:
8228 if (!gtk_text_iter_starts_word (&start))
8229 gtk_text_iter_backward_word_start (&start);
8230 if (gtk_text_iter_inside_word (&end))
8231 gtk_text_iter_forward_word_end (&end);
8232 while (!gtk_text_iter_starts_word (&end))
8234 if (!gtk_text_iter_forward_char (&end))
8238 case ATK_TEXT_BOUNDARY_WORD_END:
8239 if (gtk_text_iter_inside_word (&start) &&
8240 !gtk_text_iter_starts_word (&start))
8241 gtk_text_iter_backward_word_start (&start);
8242 while (!gtk_text_iter_ends_word (&start))
8244 if (!gtk_text_iter_backward_char (&start))
8247 gtk_text_iter_forward_word_end (&end);
8249 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8250 if (!gtk_text_iter_starts_sentence (&start))
8251 gtk_text_iter_backward_sentence_start (&start);
8252 if (gtk_text_iter_inside_sentence (&end))
8253 gtk_text_iter_forward_sentence_end (&end);
8254 while (!gtk_text_iter_starts_sentence (&end))
8256 if (!gtk_text_iter_forward_char (&end))
8260 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8261 if (gtk_text_iter_inside_sentence (&start) &&
8262 !gtk_text_iter_starts_sentence (&start))
8263 gtk_text_iter_backward_sentence_start (&start);
8264 while (!gtk_text_iter_ends_sentence (&start))
8266 if (!gtk_text_iter_backward_char (&start))
8269 gtk_text_iter_forward_sentence_end (&end);
8271 case ATK_TEXT_BOUNDARY_LINE_START:
8272 case ATK_TEXT_BOUNDARY_LINE_END:
8274 icon_view = GTK_ICON_VIEW (item->widget);
8275 /* FIXME we probably have to use GailTextCell to salvage this */
8276 gtk_icon_view_update_item_text (icon_view, item->item);
8277 get_pango_text_offsets (icon_view->priv->layout,
8291 *start_offset = gtk_text_iter_get_offset (&start);
8292 *end_offset = gtk_text_iter_get_offset (&end);
8294 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8298 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8300 AtkTextBoundary boundary_type,
8304 GtkIconViewItemAccessible *item;
8305 GtkTextIter start, end;
8306 GtkTextBuffer *buffer;
8308 GtkIconView *icon_view;
8311 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8313 if (!GTK_IS_ICON_VIEW (item->widget))
8316 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8319 buffer = item->text_buffer;
8321 if (!gtk_text_buffer_get_char_count (buffer))
8325 return g_strdup ("");
8327 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8331 switch (boundary_type)
8333 case ATK_TEXT_BOUNDARY_CHAR:
8334 gtk_text_iter_forward_char(&start);
8335 gtk_text_iter_forward_chars(&end, 2);
8337 case ATK_TEXT_BOUNDARY_WORD_START:
8338 if (gtk_text_iter_inside_word (&end))
8339 gtk_text_iter_forward_word_end (&end);
8340 while (!gtk_text_iter_starts_word (&end))
8342 if (!gtk_text_iter_forward_char (&end))
8346 if (!gtk_text_iter_is_end (&end))
8348 gtk_text_iter_forward_word_end (&end);
8349 while (!gtk_text_iter_starts_word (&end))
8351 if (!gtk_text_iter_forward_char (&end))
8356 case ATK_TEXT_BOUNDARY_WORD_END:
8357 gtk_text_iter_forward_word_end (&end);
8359 if (!gtk_text_iter_is_end (&end))
8360 gtk_text_iter_forward_word_end (&end);
8362 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8363 if (gtk_text_iter_inside_sentence (&end))
8364 gtk_text_iter_forward_sentence_end (&end);
8365 while (!gtk_text_iter_starts_sentence (&end))
8367 if (!gtk_text_iter_forward_char (&end))
8371 if (!gtk_text_iter_is_end (&end))
8373 gtk_text_iter_forward_sentence_end (&end);
8374 while (!gtk_text_iter_starts_sentence (&end))
8376 if (!gtk_text_iter_forward_char (&end))
8381 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8382 gtk_text_iter_forward_sentence_end (&end);
8384 if (!gtk_text_iter_is_end (&end))
8385 gtk_text_iter_forward_sentence_end (&end);
8387 case ATK_TEXT_BOUNDARY_LINE_START:
8388 case ATK_TEXT_BOUNDARY_LINE_END:
8390 icon_view = GTK_ICON_VIEW (item->widget);
8391 /* FIXME we probably have to use GailTextCell to salvage this */
8392 gtk_icon_view_update_item_text (icon_view, item->item);
8393 get_pango_text_offsets (icon_view->priv->layout,
8405 *start_offset = gtk_text_iter_get_offset (&start);
8406 *end_offset = gtk_text_iter_get_offset (&end);
8408 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8412 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8414 GtkIconViewItemAccessible *item;
8416 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8418 if (!GTK_IS_ICON_VIEW (item->widget))
8421 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8424 return gtk_text_buffer_get_char_count (item->text_buffer);
8428 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8434 AtkCoordType coord_type)
8436 GtkIconViewItemAccessible *item;
8438 GtkIconView *icon_view;
8439 PangoRectangle char_rect;
8440 const gchar *item_text;
8444 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8446 if (!GTK_IS_ICON_VIEW (item->widget))
8449 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8453 icon_view = GTK_ICON_VIEW (item->widget);
8454 /* FIXME we probably have to use GailTextCell to salvage this */
8455 gtk_icon_view_update_item_text (icon_view, item->item);
8456 item_text = pango_layout_get_text (icon_view->priv->layout);
8457 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8458 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8460 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8461 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8462 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8463 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8464 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8465 *width = char_rect.width / PANGO_SCALE;
8466 *height = char_rect.height / PANGO_SCALE;
8471 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8474 AtkCoordType coord_type)
8476 GtkIconViewItemAccessible *item;
8479 GtkIconView *icon_view;
8480 const gchar *item_text;
8485 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8487 if (!GTK_IS_ICON_VIEW (item->widget))
8490 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8494 icon_view = GTK_ICON_VIEW (item->widget);
8495 /* FIXME we probably have to use GailTextCell to salvage this */
8496 gtk_icon_view_update_item_text (icon_view, item->item);
8497 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8498 x -= l_x + item->item->layout_x - item->item->x;
8499 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8500 y -= l_y + item->item->layout_y - item->item->y;
8501 item_text = pango_layout_get_text (icon_view->priv->layout);
8502 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8513 offset = g_utf8_strlen (item_text, -1);
8515 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8521 atk_text_item_interface_init (AtkTextIface *iface)
8523 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8524 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8525 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8526 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8527 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8528 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8529 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8530 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8534 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8539 AtkCoordType coord_type)
8541 GtkIconViewItemAccessible *item;
8542 AtkObject *parent_obj;
8545 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8547 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8548 if (!GTK_IS_WIDGET (item->widget))
8551 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8554 *width = item->item->width;
8555 *height = item->item->height;
8556 if (gtk_icon_view_item_accessible_is_showing (item))
8558 parent_obj = gtk_widget_get_accessible (item->widget);
8559 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8560 *x = l_x + item->item->x;
8561 *y = l_y + item->item->y;
8571 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8573 GtkIconViewItemAccessible *item;
8574 GtkWidget *toplevel;
8576 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8578 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8579 if (!GTK_IS_WIDGET (item->widget))
8582 gtk_widget_grab_focus (item->widget);
8583 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8584 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8585 if (gtk_widget_is_toplevel (toplevel))
8586 gtk_window_present (GTK_WINDOW (toplevel));
8592 atk_component_item_interface_init (AtkComponentIface *iface)
8594 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8595 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8599 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8600 AtkStateType state_type,
8601 gboolean emit_signal)
8605 rc = atk_state_set_add_state (item->state_set, state_type);
8607 * The signal should only be generated if the value changed,
8608 * not when the item is set up. So states that are set
8609 * initially should pass FALSE as the emit_signal argument.
8614 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8615 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8616 if (state_type == ATK_STATE_VISIBLE)
8617 g_signal_emit_by_name (item, "visible-data-changed");
8624 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8625 AtkStateType state_type,
8626 gboolean emit_signal)
8628 if (atk_state_set_contains_state (item->state_set, state_type))
8632 rc = atk_state_set_remove_state (item->state_set, state_type);
8634 * The signal should only be generated if the value changed,
8635 * not when the item is set up. So states that are set
8636 * initially should pass FALSE as the emit_signal argument.
8641 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8642 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8643 if (state_type == ATK_STATE_VISIBLE)
8644 g_signal_emit_by_name (item, "visible-data-changed");
8654 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8656 GtkIconView *icon_view;
8657 GdkRectangle visible_rect;
8658 gboolean is_showing;
8661 * An item is considered "SHOWING" if any part of the item is in the
8662 * visible rectangle.
8665 if (!GTK_IS_ICON_VIEW (item->widget))
8668 if (item->item == NULL)
8671 icon_view = GTK_ICON_VIEW (item->widget);
8673 if (icon_view->priv->hadjustment)
8674 visible_rect.x += icon_view->priv->hadjustment->value;
8676 if (icon_view->priv->hadjustment)
8677 visible_rect.y += icon_view->priv->vadjustment->value;
8678 visible_rect.width = item->widget->allocation.width;
8679 visible_rect.height = item->widget->allocation.height;
8681 if (((item->item->x + item->item->width) < visible_rect.x) ||
8682 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8683 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8684 (item->item->y > (visible_rect.y + visible_rect.height)))
8693 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8694 gboolean emit_signal)
8696 if (gtk_icon_view_item_accessible_is_showing (item))
8697 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8700 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8705 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8709 item->state_set = atk_state_set_new ();
8711 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8712 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8713 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8714 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8715 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8717 for (i = 0; i < LAST_ACTION; i++)
8718 item->action_descriptions[i] = NULL;
8720 item->image_description = NULL;
8722 item->action_idle_handler = 0;
8726 gtk_icon_view_item_accessible_finalize (GObject *object)
8728 GtkIconViewItemAccessible *item;
8731 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8733 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8736 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8738 if (item->state_set)
8739 g_object_unref (item->state_set);
8741 if (item->text_buffer)
8742 g_object_unref (item->text_buffer);
8744 for (i = 0; i < LAST_ACTION; i++)
8745 g_free (item->action_descriptions[i]);
8747 g_free (item->image_description);
8749 if (item->action_idle_handler)
8751 g_source_remove (item->action_idle_handler);
8752 item->action_idle_handler = 0;
8755 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8758 static G_CONST_RETURN gchar*
8759 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8765 GtkIconViewItemAccessible *item;
8766 GtkTextIter start_iter;
8767 GtkTextIter end_iter;
8769 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8771 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8772 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8774 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8779 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8781 GtkIconViewItemAccessible *item;
8783 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8784 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8787 return gtk_widget_get_accessible (item->widget);
8793 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8795 GtkIconViewItemAccessible *item;
8797 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8798 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8800 return item->item->index;
8803 static AtkStateSet *
8804 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8806 GtkIconViewItemAccessible *item;
8807 GtkIconView *icon_view;
8809 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8810 g_return_val_if_fail (item->state_set, NULL);
8815 icon_view = GTK_ICON_VIEW (item->widget);
8816 if (icon_view->priv->cursor_item == item->item)
8817 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8819 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8820 if (item->item->selected)
8821 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8823 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8825 return g_object_ref (item->state_set);
8829 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8831 GObjectClass *gobject_class;
8833 accessible_item_parent_class = g_type_class_peek_parent (klass);
8835 gobject_class = (GObjectClass *)klass;
8837 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8839 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8840 klass->get_name = gtk_icon_view_item_accessible_get_name;
8841 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8842 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8846 gtk_icon_view_item_accessible_get_type (void)
8848 static GType type = 0;
8852 const GTypeInfo tinfo =
8854 sizeof (GtkIconViewItemAccessibleClass),
8855 (GBaseInitFunc) NULL, /* base init */
8856 (GBaseFinalizeFunc) NULL, /* base finalize */
8857 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8858 (GClassFinalizeFunc) NULL, /* class finalize */
8859 NULL, /* class data */
8860 sizeof (GtkIconViewItemAccessible), /* instance size */
8861 0, /* nb preallocs */
8862 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8863 NULL /* value table */
8866 const GInterfaceInfo atk_component_info =
8868 (GInterfaceInitFunc) atk_component_item_interface_init,
8869 (GInterfaceFinalizeFunc) NULL,
8872 const GInterfaceInfo atk_action_info =
8874 (GInterfaceInitFunc) atk_action_item_interface_init,
8875 (GInterfaceFinalizeFunc) NULL,
8878 const GInterfaceInfo atk_image_info =
8880 (GInterfaceInitFunc) atk_image_item_interface_init,
8881 (GInterfaceFinalizeFunc) NULL,
8884 const GInterfaceInfo atk_text_info =
8886 (GInterfaceInitFunc) atk_text_item_interface_init,
8887 (GInterfaceFinalizeFunc) NULL,
8891 type = g_type_register_static (ATK_TYPE_OBJECT,
8892 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8893 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8894 &atk_component_info);
8895 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8897 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8899 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8906 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8907 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8908 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8910 static GType gtk_icon_view_accessible_get_type (void);
8915 } GtkIconViewAccessible;
8921 } GtkIconViewItemAccessibleInfo;
8927 GtkAdjustment *old_hadj;
8928 GtkAdjustment *old_vadj;
8930 GtkTreeModel *model;
8932 } GtkIconViewAccessiblePrivate;
8934 static GtkIconViewAccessiblePrivate *
8935 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8937 return g_object_get_qdata (G_OBJECT (accessible),
8938 accessible_private_data_quark);
8942 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8946 GtkIconViewItemAccessibleInfo *info;
8947 GtkIconViewItemAccessibleInfo *tmp_info;
8948 GtkIconViewAccessiblePrivate *priv;
8951 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8953 info->index = index;
8955 priv = gtk_icon_view_accessible_get_priv (accessible);
8956 items = priv->items;
8959 tmp_info = items->data;
8960 if (tmp_info->index > index)
8962 items = items->next;
8964 priv->items = g_list_insert_before (priv->items, items, info);
8965 priv->old_hadj = NULL;
8966 priv->old_vadj = NULL;
8970 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8972 GtkIconView *icon_view;
8975 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
8979 icon_view = GTK_ICON_VIEW (widget);
8981 return g_list_length (icon_view->priv->items);
8985 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8988 GtkIconViewAccessiblePrivate *priv;
8989 GtkIconViewItemAccessibleInfo *info;
8992 priv = gtk_icon_view_accessible_get_priv (accessible);
8993 items = priv->items;
8998 if (info->index == index)
9000 items = items->next;
9006 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9009 GtkIconView *icon_view;
9013 GtkIconViewItemAccessible *a11y_item;
9015 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9019 icon_view = GTK_ICON_VIEW (widget);
9020 icons = g_list_nth (icon_view->priv->items, index);
9024 GtkIconViewItem *item = icons->data;
9026 g_return_val_if_fail (item->index == index, NULL);
9027 obj = gtk_icon_view_accessible_find_child (accessible, index);
9032 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9033 gtk_icon_view_item_accessible_info_new (accessible,
9036 obj->role = ATK_ROLE_ICON;
9037 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9038 a11y_item->item = item;
9039 a11y_item->widget = widget;
9040 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9042 gtk_icon_view_set_cell_data (icon_view, item);
9043 text = get_text (icon_view, item);
9046 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9050 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9051 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9059 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9062 GtkIconViewAccessiblePrivate *priv;
9063 GtkIconViewItemAccessibleInfo *info;
9064 GtkIconViewItemAccessible *item;
9067 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9071 gboolean act_on_item;
9073 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9077 items = priv->items;
9079 act_on_item = (list == NULL);
9084 info = (GtkIconViewItemAccessibleInfo *)items->data;
9085 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9087 if (act_on_item == FALSE && list == items)
9091 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9093 items = items->next;
9099 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9100 GtkIconView *icon_view)
9103 GtkIconViewAccessible *view;
9106 * The scrollbars have changed
9108 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9109 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9111 gtk_icon_view_accessible_traverse_items (view, NULL);
9115 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9116 GtkAdjustment *hadj,
9117 GtkAdjustment *vadj)
9120 GtkIconViewAccessiblePrivate *priv;
9122 atk_obj = gtk_widget_get_accessible (widget);
9123 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9125 if (priv->old_hadj != hadj)
9129 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9130 (gpointer *)&priv->old_hadj);
9132 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9133 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9136 priv->old_hadj = hadj;
9139 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9140 (gpointer *)&priv->old_hadj);
9141 g_signal_connect (hadj,
9143 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9147 if (priv->old_vadj != vadj)
9151 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9152 (gpointer *)&priv->old_vadj);
9154 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9155 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9158 priv->old_vadj = vadj;
9161 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9162 (gpointer *)&priv->old_vadj);
9163 g_signal_connect (vadj,
9165 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9172 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9180 GtkIconView *icon_view;
9181 GtkIconViewItem *item;
9182 GtkIconViewAccessible *a11y_view;
9183 GtkIconViewItemAccessible *a11y_item;
9187 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9188 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9189 index = gtk_tree_path_get_indices(path)[0];
9190 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9191 gtk_icon_view_accessible_find_child (atk_obj, index));
9195 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9196 icon_view = GTK_ICON_VIEW (widget);
9197 item = a11y_item->item;
9199 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9201 if (!name || strcmp (name, "") == 0)
9203 gtk_icon_view_set_cell_data (icon_view, item);
9204 text = get_text (icon_view, item);
9207 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9213 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9219 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9224 GtkIconViewAccessiblePrivate *priv;
9225 GtkIconViewItemAccessibleInfo *info;
9226 GtkIconViewAccessible *view;
9227 GtkIconViewItemAccessible *item;
9233 index = gtk_tree_path_get_indices(path)[0];
9234 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9235 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9236 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9238 items = priv->items;
9243 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9244 if (info->index != item->item->index)
9246 if (info->index < index)
9247 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9249 if (tmp_list == NULL)
9252 info->index = item->item->index;
9255 items = items->next;
9257 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9258 g_signal_emit_by_name (atk_obj, "children-changed::add",
9264 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9268 GtkIconViewAccessiblePrivate *priv;
9269 GtkIconViewItemAccessibleInfo *info;
9270 GtkIconViewAccessible *view;
9271 GtkIconViewItemAccessible *item;
9274 GList *deleted_item;
9278 index = gtk_tree_path_get_indices(path)[0];
9279 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9280 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9281 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9283 items = priv->items;
9285 deleted_item = NULL;
9290 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9291 if (info->index == index)
9293 deleted_item = items;
9295 if (info->index != item->item->index)
9297 if (tmp_list == NULL)
9300 info->index = item->item->index;
9303 items = items->next;
9305 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9308 info = deleted_item->data;
9309 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9310 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9312 priv->items = g_list_remove_link (priv->items, deleted_item);
9320 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9321 GtkIconViewItemAccessibleInfo *i2)
9323 return i1->index - i2->index;
9327 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9333 GtkIconViewAccessiblePrivate *priv;
9334 GtkIconViewItemAccessibleInfo *info;
9335 GtkIconView *icon_view;
9336 GtkIconViewItemAccessible *item;
9342 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9343 icon_view = GTK_ICON_VIEW (user_data);
9344 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9346 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9348 order = g_new (gint, length);
9349 for (i = 0; i < length; i++)
9350 order [new_order[i]] = i;
9352 items = priv->items;
9356 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9357 info->index = order[info->index];
9358 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9359 items = items->next;
9362 priv->items = g_list_sort (priv->items,
9363 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9369 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9374 obj = G_OBJECT (model);
9375 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9376 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9377 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9378 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9382 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9386 obj = G_OBJECT (icon_view->priv->model);
9387 g_signal_connect_data (obj, "row-changed",
9388 (GCallback) gtk_icon_view_accessible_model_row_changed,
9389 icon_view, NULL, 0);
9390 g_signal_connect_data (obj, "row-inserted",
9391 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9392 icon_view, NULL, G_CONNECT_AFTER);
9393 g_signal_connect_data (obj, "row-deleted",
9394 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9395 icon_view, NULL, G_CONNECT_AFTER);
9396 g_signal_connect_data (obj, "rows-reordered",
9397 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9398 icon_view, NULL, G_CONNECT_AFTER);
9402 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9404 GtkIconViewItemAccessibleInfo *info;
9407 items = priv->items;
9410 info = (GtkIconViewItemAccessibleInfo *) items->data;
9411 g_object_unref (info->item);
9412 g_free (items->data);
9413 items = items->next;
9415 g_list_free (priv->items);
9420 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9423 GtkIconView *icon_view;
9426 GtkIconViewAccessiblePrivate *priv;
9428 if (strcmp (pspec->name, "model") == 0)
9430 widget = GTK_WIDGET (obj);
9431 atk_obj = gtk_widget_get_accessible (widget);
9432 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9435 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9436 (gpointer *)&priv->model);
9437 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9439 gtk_icon_view_accessible_clear_cache (priv);
9441 icon_view = GTK_ICON_VIEW (obj);
9442 priv->model = icon_view->priv->model;
9443 /* If there is no model the GtkIconView is probably being destroyed */
9446 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9447 gtk_icon_view_accessible_connect_model_signals (icon_view);
9455 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9458 GtkIconViewAccessiblePrivate *priv;
9459 GtkIconView *icon_view;
9461 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9462 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9464 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9465 g_object_set_qdata (G_OBJECT (accessible),
9466 accessible_private_data_quark,
9469 icon_view = GTK_ICON_VIEW (data);
9470 if (icon_view->priv->hadjustment)
9472 priv->old_hadj = icon_view->priv->hadjustment;
9473 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9474 g_signal_connect (icon_view->priv->hadjustment,
9476 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9479 if (icon_view->priv->vadjustment)
9481 priv->old_vadj = icon_view->priv->vadjustment;
9482 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9483 g_signal_connect (icon_view->priv->vadjustment,
9485 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9488 g_signal_connect_after (data,
9489 "set-scroll-adjustments",
9490 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9492 g_signal_connect (data,
9494 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9497 priv->model = icon_view->priv->model;
9500 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9501 gtk_icon_view_accessible_connect_model_signals (icon_view);
9504 accessible->role = ATK_ROLE_LAYERED_PANE;
9508 gtk_icon_view_accessible_finalize (GObject *object)
9510 GtkIconViewAccessiblePrivate *priv;
9512 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9513 gtk_icon_view_accessible_clear_cache (priv);
9517 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9521 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9522 GtkAccessible *accessible)
9525 GtkIconViewAccessiblePrivate *priv;
9527 atk_obj = ATK_OBJECT (accessible);
9528 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9531 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9532 (gpointer *)&priv->old_hadj);
9534 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9535 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9537 priv->old_hadj = NULL;
9541 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9542 (gpointer *)&priv->old_vadj);
9544 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9545 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9547 priv->old_vadj = NULL;
9552 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9556 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9559 g_signal_connect_after (widget,
9561 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9564 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9568 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9570 GObjectClass *gobject_class;
9571 GtkAccessibleClass *accessible_class;
9573 accessible_parent_class = g_type_class_peek_parent (klass);
9575 gobject_class = (GObjectClass *)klass;
9576 accessible_class = (GtkAccessibleClass *)klass;
9578 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9580 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9581 klass->ref_child = gtk_icon_view_accessible_ref_child;
9582 klass->initialize = gtk_icon_view_accessible_initialize;
9584 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9586 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9590 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9593 AtkCoordType coord_type)
9596 GtkIconView *icon_view;
9597 GtkIconViewItem *item;
9600 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9602 /* State is defunct */
9605 icon_view = GTK_ICON_VIEW (widget);
9606 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9607 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9609 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9615 atk_component_interface_init (AtkComponentIface *iface)
9617 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9621 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9625 GtkIconView *icon_view;
9626 GtkIconViewItem *item;
9628 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9632 icon_view = GTK_ICON_VIEW (widget);
9634 item = g_list_nth_data (icon_view->priv->items, i);
9639 gtk_icon_view_select_item (icon_view, item);
9645 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9648 GtkIconView *icon_view;
9650 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9654 icon_view = GTK_ICON_VIEW (widget);
9655 gtk_icon_view_unselect_all (icon_view);
9661 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9666 GtkIconView *icon_view;
9667 GtkIconViewItem *item;
9669 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9673 icon_view = GTK_ICON_VIEW (widget);
9675 l = icon_view->priv->items;
9682 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9693 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9696 GtkIconView *icon_view;
9697 GtkIconViewItem *item;
9701 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9705 icon_view = GTK_ICON_VIEW (widget);
9707 l = icon_view->priv->items;
9723 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9727 GtkIconView *icon_view;
9728 GtkIconViewItem *item;
9730 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9734 icon_view = GTK_ICON_VIEW (widget);
9736 item = g_list_nth_data (icon_view->priv->items, i);
9740 return item->selected;
9744 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9748 GtkIconView *icon_view;
9749 GtkIconViewItem *item;
9753 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9757 icon_view = GTK_ICON_VIEW (widget);
9758 l = icon_view->priv->items;
9767 gtk_icon_view_unselect_item (icon_view, item);
9779 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9782 GtkIconView *icon_view;
9784 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9788 icon_view = GTK_ICON_VIEW (widget);
9789 gtk_icon_view_select_all (icon_view);
9794 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9796 iface->add_selection = gtk_icon_view_accessible_add_selection;
9797 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9798 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9799 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9800 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9801 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9802 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9806 gtk_icon_view_accessible_get_type (void)
9808 static GType type = 0;
9815 (GBaseInitFunc) NULL, /* base init */
9816 (GBaseFinalizeFunc) NULL, /* base finalize */
9817 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9818 (GClassFinalizeFunc) NULL, /* class finalize */
9819 NULL, /* class data */
9820 0, /* instance size */
9821 0, /* nb preallocs */
9822 (GInstanceInitFunc) NULL, /* instance init */
9823 NULL /* value table */
9825 const GInterfaceInfo atk_component_info =
9827 (GInterfaceInitFunc) atk_component_interface_init,
9828 (GInterfaceFinalizeFunc) NULL,
9831 const GInterfaceInfo atk_selection_info =
9833 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9834 (GInterfaceFinalizeFunc) NULL,
9839 * Figure out the size of the class and instance
9840 * we are deriving from
9842 AtkObjectFactory *factory;
9845 GType derived_atk_type;
9847 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9848 factory = atk_registry_get_factory (atk_get_default_registry (),
9850 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9851 g_type_query (derived_atk_type, &query);
9852 tinfo.class_size = query.class_size;
9853 tinfo.instance_size = query.instance_size;
9855 type = g_type_register_static (derived_atk_type,
9856 I_("GtkIconViewAccessible"),
9858 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9859 &atk_component_info);
9860 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9861 &atk_selection_info);
9867 gtk_icon_view_accessible_new (GObject *obj)
9869 AtkObject *accessible;
9871 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9873 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9874 atk_object_initialize (accessible, obj);
9880 gtk_icon_view_accessible_factory_get_accessible_type (void)
9882 return gtk_icon_view_accessible_get_type ();
9886 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9888 return gtk_icon_view_accessible_new (obj);
9892 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9894 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9895 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9899 gtk_icon_view_accessible_factory_get_type (void)
9901 static GType type = 0;
9905 const GTypeInfo tinfo =
9907 sizeof (AtkObjectFactoryClass),
9908 NULL, /* base_init */
9909 NULL, /* base_finalize */
9910 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9911 NULL, /* class_finalize */
9912 NULL, /* class_data */
9913 sizeof (AtkObjectFactory),
9914 0, /* n_preallocs */
9918 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9919 I_("GtkIconViewAccessibleFactory"),
9927 gtk_icon_view_get_accessible (GtkWidget *widget)
9929 static gboolean first_time = TRUE;
9933 AtkObjectFactory *factory;
9934 AtkRegistry *registry;
9936 GType derived_atk_type;
9939 * Figure out whether accessibility is enabled by looking at the
9940 * type of the accessible object which would be created for
9941 * the parent type of GtkIconView.
9943 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9945 registry = atk_get_default_registry ();
9946 factory = atk_registry_get_factory (registry,
9948 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9949 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9950 atk_registry_set_factory_type (registry,
9952 gtk_icon_view_accessible_factory_get_type ());
9955 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9959 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9960 GtkBuilder *builder,
9962 const gchar *tagname,
9963 GMarkupParser *parser,
9966 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9967 tagname, parser, data))
9970 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9971 tagname, parser, data);
9975 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9976 GtkBuilder *builder,
9978 const gchar *tagname,
9981 if (strcmp (tagname, "attributes") == 0)
9982 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9985 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,