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"
46 #undef DEBUG_ICON_VIEW
48 #define SCROLL_EDGE_SIZE 15
49 #define ITEM_PADDING 6
51 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
53 typedef struct _GtkIconViewItem GtkIconViewItem;
54 struct _GtkIconViewItem
62 gint x, y, width, height;
65 * box[i] is the actual area occupied by cell i,
66 * before, after are used to calculate the cell
67 * area relative to the box.
68 * See gtk_icon_view_get_cell_area().
76 guint selected_before_rubberbanding : 1;
80 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
81 struct _GtkIconViewCellInfo
83 GtkCellRenderer *cell;
93 GtkCellLayoutDataFunc func;
95 GDestroyNotify destroy;
98 typedef struct _GtkIconViewChild GtkIconViewChild;
99 struct _GtkIconViewChild
102 GtkIconViewItem *item;
106 struct _GtkIconViewPrivate
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gboolean doing_rubberband;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
163 guint draw_focus : 1;
166 GdkModifierType start_button_mask;
171 GdkDragAction source_actions;
172 GdkDragAction dest_actions;
174 GtkTreeRowReference *dest_item;
175 GtkIconViewDropPosition dest_pos;
178 GtkTreeRowReference *scroll_to_path;
179 gfloat scroll_to_row_align;
180 gfloat scroll_to_col_align;
181 guint scroll_to_use_align : 1;
183 guint source_set : 1;
185 guint reorderable : 1;
186 guint empty_view_drop :1;
188 guint ctrl_pressed : 1;
189 guint shift_pressed : 1;
202 ACTIVATE_CURSOR_ITEM,
227 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
228 static void gtk_icon_view_finalize (GObject *object);
229 static void gtk_icon_view_set_property (GObject *object,
233 static void gtk_icon_view_get_property (GObject *object,
238 /* GtkObject vfuncs */
239 static void gtk_icon_view_destroy (GtkObject *object);
241 /* GtkWidget vfuncs */
242 static void gtk_icon_view_realize (GtkWidget *widget);
243 static void gtk_icon_view_unrealize (GtkWidget *widget);
244 static void gtk_icon_view_style_set (GtkWidget *widget,
245 GtkStyle *previous_style);
246 static void gtk_icon_view_state_changed (GtkWidget *widget,
247 GtkStateType previous_state);
248 static void gtk_icon_view_size_request (GtkWidget *widget,
249 GtkRequisition *requisition);
250 static void gtk_icon_view_size_allocate (GtkWidget *widget,
251 GtkAllocation *allocation);
252 static gboolean gtk_icon_view_expose (GtkWidget *widget,
253 GdkEventExpose *expose);
254 static gboolean gtk_icon_view_motion (GtkWidget *widget,
255 GdkEventMotion *event);
256 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
257 GdkEventButton *event);
258 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
259 GdkEventButton *event);
260 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
262 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
264 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
267 /* GtkContainer vfuncs */
268 static void gtk_icon_view_remove (GtkContainer *container,
270 static void gtk_icon_view_forall (GtkContainer *container,
271 gboolean include_internals,
272 GtkCallback callback,
273 gpointer callback_data);
275 /* GtkIconView vfuncs */
276 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
278 GtkAdjustment *vadj);
279 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
280 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
282 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
283 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
285 /* Internal functions */
286 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
287 GtkIconView *icon_view);
288 static void gtk_icon_view_layout (GtkIconView *icon_view);
289 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
292 GtkIconViewItem *item,
294 GdkDrawable *drawable,
297 gboolean draw_focus);
298 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
303 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
304 GtkIconViewItem *item);
305 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
306 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
307 GtkIconViewItem *item,
309 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
312 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
313 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
314 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
315 GtkIconViewItem *item,
320 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
321 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
322 GtkIconViewItem *item);
323 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
324 GtkIconViewItem *item,
326 static void gtk_icon_view_update_rubberband (gpointer data);
327 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
328 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
329 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
332 GtkMovementStep step,
334 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
335 GtkMovementStep step,
337 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
343 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
345 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_select_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
350 GtkIconViewItem *item);
351 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
352 GtkIconViewItem *anchor,
353 GtkIconViewItem *cursor);
354 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
357 gboolean only_in_cell,
358 GtkIconViewCellInfo **cell_at_pos);
359 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
360 GtkIconViewItem *item,
361 GtkIconViewCellInfo *cell_info,
362 GdkRectangle *cell_area);
363 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
364 GtkIconViewItem *item,
365 GtkIconViewCellInfo *info,
367 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
368 GtkCellRenderer *renderer);
369 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
370 GtkIconViewItem *item);
371 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
372 GtkCellRenderer *renderer,
374 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
375 GtkCellRenderer *renderer,
377 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
378 GtkCellRenderer *renderer,
379 const gchar *attribute,
381 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
382 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
383 GtkCellRenderer *renderer);
384 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
385 GtkCellRenderer *cell,
386 GtkCellLayoutDataFunc func,
388 GDestroyNotify destroy);
389 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
390 GtkCellRenderer *cell,
392 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
394 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
395 GtkIconViewItem *item,
396 GtkIconViewCellInfo *cell_info,
398 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
399 GtkIconViewItem *item);
400 static void gtk_icon_view_put (GtkIconView *icon_view,
402 GtkIconViewItem *item,
404 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
405 GtkIconView *icon_view);
406 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
407 GtkIconViewItem *item,
408 GtkIconViewCellInfo *cell_info,
410 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
411 gboolean cancel_editing);
413 /* Source side drag signals */
414 static void gtk_icon_view_drag_begin (GtkWidget *widget,
415 GdkDragContext *context);
416 static void gtk_icon_view_drag_end (GtkWidget *widget,
417 GdkDragContext *context);
418 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
419 GdkDragContext *context,
420 GtkSelectionData *selection_data,
423 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
424 GdkDragContext *context);
426 /* Target side drag signals */
427 static void gtk_icon_view_drag_leave (GtkWidget *widget,
428 GdkDragContext *context,
430 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
431 GdkDragContext *context,
435 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
436 GdkDragContext *context,
440 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
441 GdkDragContext *context,
444 GtkSelectionData *selection_data,
447 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
448 GdkEventMotion *event);
450 static void remove_scroll_timeout (GtkIconView *icon_view);
452 static void adjust_wrap_width (GtkIconView *icon_view,
453 GtkIconViewItem *item);
456 static GtkBuildableIface *parent_buildable_iface;
457 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
458 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
461 const gchar *tagname,
462 GMarkupParser *parser,
464 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
467 const gchar *tagname,
470 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
472 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
473 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
474 gtk_icon_view_cell_layout_init)
475 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
476 gtk_icon_view_buildable_init))
479 gtk_icon_view_class_init (GtkIconViewClass *klass)
481 GObjectClass *gobject_class;
482 GtkObjectClass *object_class;
483 GtkWidgetClass *widget_class;
484 GtkContainerClass *container_class;
485 GtkBindingSet *binding_set;
487 binding_set = gtk_binding_set_by_class (klass);
489 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
491 gobject_class = (GObjectClass *) klass;
492 object_class = (GtkObjectClass *) klass;
493 widget_class = (GtkWidgetClass *) klass;
494 container_class = (GtkContainerClass *) klass;
496 gobject_class->finalize = gtk_icon_view_finalize;
497 gobject_class->set_property = gtk_icon_view_set_property;
498 gobject_class->get_property = gtk_icon_view_get_property;
500 object_class->destroy = gtk_icon_view_destroy;
502 widget_class->realize = gtk_icon_view_realize;
503 widget_class->unrealize = gtk_icon_view_unrealize;
504 widget_class->style_set = gtk_icon_view_style_set;
505 widget_class->get_accessible = gtk_icon_view_get_accessible;
506 widget_class->size_request = gtk_icon_view_size_request;
507 widget_class->size_allocate = gtk_icon_view_size_allocate;
508 widget_class->expose_event = gtk_icon_view_expose;
509 widget_class->motion_notify_event = gtk_icon_view_motion;
510 widget_class->button_press_event = gtk_icon_view_button_press;
511 widget_class->button_release_event = gtk_icon_view_button_release;
512 widget_class->key_press_event = gtk_icon_view_key_press;
513 widget_class->key_release_event = gtk_icon_view_key_release;
514 widget_class->drag_begin = gtk_icon_view_drag_begin;
515 widget_class->drag_end = gtk_icon_view_drag_end;
516 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
517 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
518 widget_class->drag_leave = gtk_icon_view_drag_leave;
519 widget_class->drag_motion = gtk_icon_view_drag_motion;
520 widget_class->drag_drop = gtk_icon_view_drag_drop;
521 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
522 widget_class->state_changed = gtk_icon_view_state_changed;
524 container_class->remove = gtk_icon_view_remove;
525 container_class->forall = gtk_icon_view_forall;
527 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
528 klass->select_all = gtk_icon_view_real_select_all;
529 klass->unselect_all = gtk_icon_view_real_unselect_all;
530 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
531 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
532 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
533 klass->move_cursor = gtk_icon_view_real_move_cursor;
537 * GtkIconView:selection-mode:
539 * The ::selection-mode property specifies the selection mode of
540 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
541 * is enabled, for the other modes, only keyboard selection is possible.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_enum ("selection-mode",
548 P_("Selection mode"),
549 P_("The selection mode"),
550 GTK_TYPE_SELECTION_MODE,
551 GTK_SELECTION_SINGLE,
552 GTK_PARAM_READWRITE));
555 * GtkIconView:pixbuf-column:
557 * The ::pixbuf-column property contains the number of the model column
558 * containing the pixbufs which are displayed. The pixbuf column must be
559 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
560 * display of pixbufs.
564 g_object_class_install_property (gobject_class,
566 g_param_spec_int ("pixbuf-column",
568 P_("Model column used to retrieve the icon pixbuf from"),
570 GTK_PARAM_READWRITE));
573 * GtkIconView:text-column:
575 * The ::text-column property contains the number of the model column
576 * containing the texts which are displayed. The text column must be
577 * of type #G_TYPE_STRING. If this property and the :markup-column
578 * property are both set to -1, no texts are displayed.
582 g_object_class_install_property (gobject_class,
584 g_param_spec_int ("text-column",
586 P_("Model column used to retrieve the text from"),
588 GTK_PARAM_READWRITE));
592 * GtkIconView:markup-column:
594 * The ::markup-column property contains the number of the model column
595 * containing markup information to be displayed. The markup column must be
596 * of type #G_TYPE_STRING. If this property and the :text-column property
597 * are both set to column numbers, it overrides the text column.
598 * If both are set to -1, no texts are displayed.
602 g_object_class_install_property (gobject_class,
604 g_param_spec_int ("markup-column",
606 P_("Model column used to retrieve the text if using Pango markup"),
608 GTK_PARAM_READWRITE));
610 g_object_class_install_property (gobject_class,
612 g_param_spec_object ("model",
613 P_("Icon View Model"),
614 P_("The model for the icon view"),
616 GTK_PARAM_READWRITE));
619 * GtkIconView:columns:
621 * The columns property contains the number of the columns in which the
622 * items should be displayed. If it is -1, the number of columns will
623 * be chosen automatically to fill the available area.
627 g_object_class_install_property (gobject_class,
629 g_param_spec_int ("columns",
630 P_("Number of columns"),
631 P_("Number of columns to display"),
633 GTK_PARAM_READWRITE));
637 * GtkIconView:item-width:
639 * The item-width property specifies the width to use for each item.
640 * If it is set to -1, the icon view will automatically determine a
641 * suitable item size.
645 g_object_class_install_property (gobject_class,
647 g_param_spec_int ("item-width",
648 P_("Width for each item"),
649 P_("The width used for each item"),
651 GTK_PARAM_READWRITE));
654 * GtkIconView:spacing:
656 * The spacing property specifies the space which is inserted between
657 * the cells (i.e. the icon and the text) of an item.
661 g_object_class_install_property (gobject_class,
663 g_param_spec_int ("spacing",
665 P_("Space which is inserted between cells of an item"),
667 GTK_PARAM_READWRITE));
670 * GtkIconView:row-spacing:
672 * The row-spacing property specifies the space which is inserted between
673 * the rows of the icon view.
677 g_object_class_install_property (gobject_class,
679 g_param_spec_int ("row-spacing",
681 P_("Space which is inserted between grid rows"),
683 GTK_PARAM_READWRITE));
686 * GtkIconView:column-spacing:
688 * The column-spacing property specifies the space which is inserted between
689 * the columns of the icon view.
693 g_object_class_install_property (gobject_class,
695 g_param_spec_int ("column-spacing",
696 P_("Column Spacing"),
697 P_("Space which is inserted between grid columns"),
699 GTK_PARAM_READWRITE));
702 * GtkIconView:margin:
704 * The margin property specifies the space which is inserted
705 * at the edges of the icon view.
709 g_object_class_install_property (gobject_class,
711 g_param_spec_int ("margin",
713 P_("Space which is inserted at the edges of the icon view"),
715 GTK_PARAM_READWRITE));
719 * GtkIconView:orientation:
721 * The orientation property specifies how the cells (i.e. the icon and
722 * the text) of the item are positioned relative to each other.
726 g_object_class_install_property (gobject_class,
728 g_param_spec_enum ("orientation",
730 P_("How the text and icon of each item are positioned relative to each other"),
731 GTK_TYPE_ORIENTATION,
732 GTK_ORIENTATION_VERTICAL,
733 GTK_PARAM_READWRITE));
736 * GtkIconView:reorderable:
738 * The reorderable property specifies if the items can be reordered
743 g_object_class_install_property (gobject_class,
745 g_param_spec_boolean ("reorderable",
747 P_("View is reorderable"),
751 g_object_class_install_property (gobject_class,
753 g_param_spec_int ("tooltip-column",
754 P_("Tooltip Column"),
755 P_("The column in the model containing the tooltip texts for the items"),
759 GTK_PARAM_READWRITE));
763 /* Style properties */
764 gtk_widget_class_install_style_property (widget_class,
765 g_param_spec_boxed ("selection-box-color",
766 P_("Selection Box Color"),
767 P_("Color of the selection box"),
769 GTK_PARAM_READABLE));
771 gtk_widget_class_install_style_property (widget_class,
772 g_param_spec_uchar ("selection-box-alpha",
773 P_("Selection Box Alpha"),
774 P_("Opacity of the selection box"),
777 GTK_PARAM_READABLE));
781 * GtkIconView::set-scroll-adjustments
782 * @horizontal: the horizontal #GtkAdjustment
783 * @vertical: the vertical #GtkAdjustment
785 * Set the scroll adjustments for the icon view. Usually scrolled containers
786 * like #GtkScrolledWindow will emit this signal to connect two instances
787 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
789 widget_class->set_scroll_adjustments_signal =
790 g_signal_new (I_("set-scroll-adjustments"),
791 G_TYPE_FROM_CLASS (gobject_class),
793 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
795 _gtk_marshal_VOID__OBJECT_OBJECT,
797 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
800 * GtkIconView::item-activated:
801 * @iconview: the object on which the signal is emitted
802 * @path: the #GtkTreePath for the activated item
804 * The ::item-activated signal is emitted when the method
805 * gtk_icon_view_item_activated() is called or the user double
806 * clicks an item. It is also emitted when a non-editable item
807 * is selected and one of the keys: Space, Return or Enter is
810 icon_view_signals[ITEM_ACTIVATED] =
811 g_signal_new (I_("item-activated"),
812 G_TYPE_FROM_CLASS (gobject_class),
814 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
816 g_cclosure_marshal_VOID__BOXED,
821 * GtkIconView::selection-changed:
822 * @iconview: the object on which the signal is emitted
824 * The ::selection-changed signal is emitted when the selection
825 * (i.e. the set of selected items) changes.
827 icon_view_signals[SELECTION_CHANGED] =
828 g_signal_new (I_("selection-changed"),
829 G_TYPE_FROM_CLASS (gobject_class),
831 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
833 g_cclosure_marshal_VOID__VOID,
837 * GtkIconView::select-all:
838 * @iconview: the object on which the signal is emitted
840 * A <link linkend="keybinding-signals">keybinding signal</link>
841 * which gets emitted when the user selects all items.
843 * Applications should not connect to it, but may emit it with
844 * g_signal_emit_by_name() if they need to control selection
847 * The default binding for this signal is Ctrl-a.
849 icon_view_signals[SELECT_ALL] =
850 g_signal_new (I_("select-all"),
851 G_TYPE_FROM_CLASS (gobject_class),
852 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
853 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
855 g_cclosure_marshal_VOID__VOID,
859 * GtkIconView::unselect-all:
860 * @iconview: the object on which the signal is emitted
862 * A <link linkend="keybinding-signals">keybinding signal</link>
863 * which gets emitted when the user unselects all items.
865 * Applications should not connect to it, but may emit it with
866 * g_signal_emit_by_name() if they need to control selection
869 * The default binding for this signal is Ctrl-Shift-a.
871 icon_view_signals[UNSELECT_ALL] =
872 g_signal_new (I_("unselect-all"),
873 G_TYPE_FROM_CLASS (gobject_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
877 g_cclosure_marshal_VOID__VOID,
881 * GtkIconView::select-cursor-item:
882 * @iconview: the object on which the signal is emitted
884 * A <link linkend="keybinding-signals">keybinding signal</link>
885 * which gets emitted when the user selects the item that is currently
888 * Applications should not connect to it, but may emit it with
889 * g_signal_emit_by_name() if they need to control selection
892 * There is no default binding for this signal.
894 icon_view_signals[SELECT_CURSOR_ITEM] =
895 g_signal_new (I_("select-cursor-item"),
896 G_TYPE_FROM_CLASS (gobject_class),
897 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
898 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
900 g_cclosure_marshal_VOID__VOID,
904 * GtkIconView::toggle-cursor-item:
905 * @iconview: the object on which the signal is emitted
907 * A <link linkend="keybinding-signals">keybinding signal</link>
908 * which gets emitted when the user toggles whether the currently
909 * focused item is selected or not. The exact effect of this
910 * depend on the selection mode.
912 * Applications should not connect to it, but may emit it with
913 * g_signal_emit_by_name() if they need to control selection
916 * There is no default binding for this signal is Ctrl-Space.
918 icon_view_signals[TOGGLE_CURSOR_ITEM] =
919 g_signal_new (I_("toggle-cursor-item"),
920 G_TYPE_FROM_CLASS (gobject_class),
921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
924 g_cclosure_marshal_VOID__VOID,
928 * GtkIconView::activate-cursor-item:
929 * @iconview: the object on which the signal is emitted
931 * A <link linkend="keybinding-signals">keybinding signal</link>
932 * which gets emitted when the user activates the currently
935 * Applications should not connect to it, but may emit it with
936 * g_signal_emit_by_name() if they need to control activation
939 * The default bindings for this signal are Space, Return and Enter.
941 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
942 g_signal_new (I_("activate-cursor-item"),
943 G_TYPE_FROM_CLASS (gobject_class),
944 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
945 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
947 _gtk_marshal_BOOLEAN__VOID,
951 * GtkIconView::move-cursor:
952 * @iconview: the object which received the signal
953 * @step: the granularity of the move, as a #GtkMovementStep
954 * @count: the number of @step units to move
956 * The ::move-cursor signal is a
957 * <link linkend="keybinding-signals">keybinding signal</link>
958 * which gets emitted when the user initiates a cursor movement.
960 * Applications should not connect to it, but may emit it with
961 * g_signal_emit_by_name() if they need to control the cursor
964 * The default bindings for this signal include
966 * <listitem>Arrow keys which move by individual steps</listitem>
967 * <listitem>Home/End keys which move to the first/last item</listitem>
968 * <listitem>PageUp/PageDown which move by "pages"</listitem>
971 * All of these will extend the selection when combined with
972 * the Shift modifier.
974 icon_view_signals[MOVE_CURSOR] =
975 g_signal_new (I_("move-cursor"),
976 G_TYPE_FROM_CLASS (gobject_class),
977 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
978 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
980 _gtk_marshal_BOOLEAN__ENUM_INT,
982 GTK_TYPE_MOVEMENT_STEP,
986 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
988 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
990 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
991 "toggle-cursor-item", 0);
992 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
993 "toggle-cursor-item", 0);
995 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
996 "activate-cursor-item", 0);
997 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
998 "activate-cursor-item", 0);
999 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1000 "activate-cursor-item", 0);
1001 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1002 "activate-cursor-item", 0);
1003 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1004 "activate-cursor-item", 0);
1006 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1007 GTK_MOVEMENT_DISPLAY_LINES, -1);
1008 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1009 GTK_MOVEMENT_DISPLAY_LINES, -1);
1011 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1012 GTK_MOVEMENT_DISPLAY_LINES, 1);
1013 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1014 GTK_MOVEMENT_DISPLAY_LINES, 1);
1016 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1017 GTK_MOVEMENT_DISPLAY_LINES, -1);
1019 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1020 GTK_MOVEMENT_DISPLAY_LINES, 1);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1023 GTK_MOVEMENT_BUFFER_ENDS, -1);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1025 GTK_MOVEMENT_BUFFER_ENDS, -1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1028 GTK_MOVEMENT_BUFFER_ENDS, 1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1030 GTK_MOVEMENT_BUFFER_ENDS, 1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1033 GTK_MOVEMENT_PAGES, -1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1035 GTK_MOVEMENT_PAGES, -1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1038 GTK_MOVEMENT_PAGES, 1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1040 GTK_MOVEMENT_PAGES, 1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1043 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1044 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1045 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1048 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1049 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1050 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1054 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1056 parent_buildable_iface = g_type_interface_peek_parent (iface);
1057 iface->add_child = _gtk_cell_layout_buildable_add_child;
1058 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1059 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1063 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1065 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1066 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1067 iface->clear = gtk_icon_view_cell_layout_clear;
1068 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1069 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1070 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1071 iface->reorder = gtk_icon_view_cell_layout_reorder;
1072 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1076 gtk_icon_view_init (GtkIconView *icon_view)
1078 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1080 icon_view->priv->width = 0;
1081 icon_view->priv->height = 0;
1082 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1083 icon_view->priv->pressed_button = -1;
1084 icon_view->priv->press_start_x = -1;
1085 icon_view->priv->press_start_y = -1;
1086 icon_view->priv->text_column = -1;
1087 icon_view->priv->markup_column = -1;
1088 icon_view->priv->pixbuf_column = -1;
1089 icon_view->priv->text_cell = -1;
1090 icon_view->priv->pixbuf_cell = -1;
1091 icon_view->priv->tooltip_column = -1;
1093 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
1095 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1097 icon_view->priv->cell_list = NULL;
1098 icon_view->priv->n_cells = 0;
1099 icon_view->priv->cursor_cell = -1;
1101 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1103 icon_view->priv->columns = -1;
1104 icon_view->priv->item_width = -1;
1105 icon_view->priv->spacing = 0;
1106 icon_view->priv->row_spacing = 6;
1107 icon_view->priv->column_spacing = 6;
1108 icon_view->priv->margin = 6;
1110 icon_view->priv->draw_focus = TRUE;
1114 gtk_icon_view_destroy (GtkObject *object)
1116 GtkIconView *icon_view;
1118 icon_view = GTK_ICON_VIEW (object);
1120 gtk_icon_view_stop_editing (icon_view, TRUE);
1122 gtk_icon_view_set_model (icon_view, NULL);
1124 if (icon_view->priv->layout_idle_id != 0)
1126 g_source_remove (icon_view->priv->layout_idle_id);
1127 icon_view->priv->layout_idle_id = 0;
1130 if (icon_view->priv->scroll_to_path != NULL)
1132 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1133 icon_view->priv->scroll_to_path = NULL;
1136 remove_scroll_timeout (icon_view);
1138 if (icon_view->priv->hadjustment != NULL)
1140 g_object_unref (icon_view->priv->hadjustment);
1141 icon_view->priv->hadjustment = NULL;
1144 if (icon_view->priv->vadjustment != NULL)
1146 g_object_unref (icon_view->priv->vadjustment);
1147 icon_view->priv->vadjustment = NULL;
1150 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1153 /* GObject methods */
1155 gtk_icon_view_finalize (GObject *object)
1157 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1159 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1164 gtk_icon_view_set_property (GObject *object,
1166 const GValue *value,
1169 GtkIconView *icon_view;
1171 icon_view = GTK_ICON_VIEW (object);
1175 case PROP_SELECTION_MODE:
1176 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1178 case PROP_PIXBUF_COLUMN:
1179 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1181 case PROP_TEXT_COLUMN:
1182 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1184 case PROP_MARKUP_COLUMN:
1185 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1188 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1190 case PROP_ORIENTATION:
1191 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1194 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1196 case PROP_ITEM_WIDTH:
1197 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1200 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1202 case PROP_ROW_SPACING:
1203 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1205 case PROP_COLUMN_SPACING:
1206 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1209 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1211 case PROP_REORDERABLE:
1212 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1215 case PROP_TOOLTIP_COLUMN:
1216 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1226 gtk_icon_view_get_property (GObject *object,
1231 GtkIconView *icon_view;
1233 icon_view = GTK_ICON_VIEW (object);
1237 case PROP_SELECTION_MODE:
1238 g_value_set_enum (value, icon_view->priv->selection_mode);
1240 case PROP_PIXBUF_COLUMN:
1241 g_value_set_int (value, icon_view->priv->pixbuf_column);
1243 case PROP_TEXT_COLUMN:
1244 g_value_set_int (value, icon_view->priv->text_column);
1246 case PROP_MARKUP_COLUMN:
1247 g_value_set_int (value, icon_view->priv->markup_column);
1250 g_value_set_object (value, icon_view->priv->model);
1252 case PROP_ORIENTATION:
1253 g_value_set_enum (value, icon_view->priv->orientation);
1256 g_value_set_int (value, icon_view->priv->columns);
1258 case PROP_ITEM_WIDTH:
1259 g_value_set_int (value, icon_view->priv->item_width);
1262 g_value_set_int (value, icon_view->priv->spacing);
1264 case PROP_ROW_SPACING:
1265 g_value_set_int (value, icon_view->priv->row_spacing);
1267 case PROP_COLUMN_SPACING:
1268 g_value_set_int (value, icon_view->priv->column_spacing);
1271 g_value_set_int (value, icon_view->priv->margin);
1273 case PROP_REORDERABLE:
1274 g_value_set_boolean (value, icon_view->priv->reorderable);
1276 case PROP_TOOLTIP_COLUMN:
1277 g_value_set_int (value, icon_view->priv->tooltip_column);
1281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1286 /* GtkWidget signals */
1288 gtk_icon_view_realize (GtkWidget *widget)
1290 GtkIconView *icon_view;
1291 GdkWindowAttr attributes;
1292 gint attributes_mask;
1294 icon_view = GTK_ICON_VIEW (widget);
1296 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1298 /* Make the main, clipping window */
1299 attributes.window_type = GDK_WINDOW_CHILD;
1300 attributes.x = widget->allocation.x;
1301 attributes.y = widget->allocation.y;
1302 attributes.width = widget->allocation.width;
1303 attributes.height = widget->allocation.height;
1304 attributes.wclass = GDK_INPUT_OUTPUT;
1305 attributes.visual = gtk_widget_get_visual (widget);
1306 attributes.colormap = gtk_widget_get_colormap (widget);
1307 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1309 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1311 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1312 &attributes, attributes_mask);
1313 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1314 gdk_window_set_user_data (widget->window, widget);
1316 /* Make the window for the icon view */
1319 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1320 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1321 attributes.event_mask = (GDK_EXPOSURE_MASK |
1323 GDK_POINTER_MOTION_MASK |
1324 GDK_BUTTON_PRESS_MASK |
1325 GDK_BUTTON_RELEASE_MASK |
1326 GDK_KEY_PRESS_MASK |
1327 GDK_KEY_RELEASE_MASK) |
1328 gtk_widget_get_events (widget);
1330 icon_view->priv->bin_window = gdk_window_new (widget->window,
1331 &attributes, attributes_mask);
1332 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1334 widget->style = gtk_style_attach (widget->style, widget->window);
1335 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1337 gdk_window_show (icon_view->priv->bin_window);
1341 gtk_icon_view_unrealize (GtkWidget *widget)
1343 GtkIconView *icon_view;
1345 icon_view = GTK_ICON_VIEW (widget);
1347 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1348 gdk_window_destroy (icon_view->priv->bin_window);
1349 icon_view->priv->bin_window = NULL;
1351 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1355 gtk_icon_view_state_changed (GtkWidget *widget,
1356 GtkStateType previous_state)
1358 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1360 if (GTK_WIDGET_REALIZED (widget))
1362 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1363 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1366 gtk_widget_queue_draw (widget);
1370 gtk_icon_view_style_set (GtkWidget *widget,
1371 GtkStyle *previous_style)
1373 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1375 if (GTK_WIDGET_REALIZED (widget))
1377 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1378 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1381 gtk_widget_queue_resize (widget);
1385 gtk_icon_view_size_request (GtkWidget *widget,
1386 GtkRequisition *requisition)
1388 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1391 requisition->width = icon_view->priv->width;
1392 requisition->height = icon_view->priv->height;
1394 tmp_list = icon_view->priv->children;
1398 GtkIconViewChild *child = tmp_list->data;
1399 GtkRequisition child_requisition;
1401 tmp_list = tmp_list->next;
1403 if (GTK_WIDGET_VISIBLE (child->widget))
1404 gtk_widget_size_request (child->widget, &child_requisition);
1409 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1413 for (list = icon_view->priv->children; list; list = list->next)
1415 GtkIconViewChild *child = list->data;
1416 GtkAllocation allocation;
1418 /* totally ignore our child's requisition */
1419 if (child->cell < 0)
1421 allocation.x = child->item->x + ITEM_PADDING;
1422 allocation.y = child->item->y + ITEM_PADDING;
1423 allocation.width = child->item->width - ITEM_PADDING * 2;
1424 allocation.height = child->item->height - ITEM_PADDING * 2;
1428 GdkRectangle *box = &child->item->box[child->cell];
1430 allocation.x = box->x;
1431 allocation.y = box->y;
1432 allocation.width = box->width;
1433 allocation.height = box->height;
1436 gtk_widget_size_allocate (child->widget, &allocation);
1441 gtk_icon_view_size_allocate (GtkWidget *widget,
1442 GtkAllocation *allocation)
1444 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1446 GtkAdjustment *hadjustment, *vadjustment;
1448 widget->allocation = *allocation;
1450 if (GTK_WIDGET_REALIZED (widget))
1452 gdk_window_move_resize (widget->window,
1453 allocation->x, allocation->y,
1454 allocation->width, allocation->height);
1455 gdk_window_resize (icon_view->priv->bin_window,
1456 MAX (icon_view->priv->width, allocation->width),
1457 MAX (icon_view->priv->height, allocation->height));
1460 gtk_icon_view_layout (icon_view);
1462 gtk_icon_view_allocate_children (icon_view);
1464 hadjustment = icon_view->priv->hadjustment;
1465 vadjustment = icon_view->priv->vadjustment;
1467 hadjustment->page_size = allocation->width;
1468 hadjustment->page_increment = allocation->width * 0.9;
1469 hadjustment->step_increment = allocation->width * 0.1;
1470 hadjustment->lower = 0;
1471 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1473 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1474 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1476 vadjustment->page_size = allocation->height;
1477 vadjustment->page_increment = allocation->height * 0.9;
1478 vadjustment->step_increment = allocation->height * 0.1;
1479 vadjustment->lower = 0;
1480 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1482 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1483 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1485 if (GTK_WIDGET_REALIZED (widget) &&
1486 icon_view->priv->scroll_to_path)
1489 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1490 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1491 icon_view->priv->scroll_to_path = NULL;
1493 gtk_icon_view_scroll_to_path (icon_view, path,
1494 icon_view->priv->scroll_to_use_align,
1495 icon_view->priv->scroll_to_row_align,
1496 icon_view->priv->scroll_to_col_align);
1497 gtk_tree_path_free (path);
1501 gtk_adjustment_changed (hadjustment);
1502 gtk_adjustment_changed (vadjustment);
1507 gtk_icon_view_expose (GtkWidget *widget,
1508 GdkEventExpose *expose)
1510 GtkIconView *icon_view;
1515 GtkIconViewDropPosition dest_pos;
1516 GtkIconViewItem *dest_item = NULL;
1518 icon_view = GTK_ICON_VIEW (widget);
1520 if (expose->window != icon_view->priv->bin_window)
1523 cr = gdk_cairo_create (icon_view->priv->bin_window);
1524 cairo_set_line_width (cr, 1.);
1526 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1530 dest_index = gtk_tree_path_get_indices (path)[0];
1531 gtk_tree_path_free (path);
1536 for (icons = icon_view->priv->items; icons; icons = icons->next)
1538 GtkIconViewItem *item = icons->data;
1543 area.width = item->width;
1544 area.height = item->height;
1546 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1549 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1550 icon_view->priv->bin_window,
1552 icon_view->priv->draw_focus);
1554 if (dest_index == item->index)
1562 case GTK_ICON_VIEW_DROP_INTO:
1563 gtk_paint_focus (widget->style,
1564 icon_view->priv->bin_window,
1565 GTK_WIDGET_STATE (widget),
1568 "iconview-drop-indicator",
1569 dest_item->x, dest_item->y,
1570 dest_item->width, dest_item->height);
1572 case GTK_ICON_VIEW_DROP_ABOVE:
1573 gtk_paint_focus (widget->style,
1574 icon_view->priv->bin_window,
1575 GTK_WIDGET_STATE (widget),
1578 "iconview-drop-indicator",
1579 dest_item->x, dest_item->y - 1,
1580 dest_item->width, 2);
1582 case GTK_ICON_VIEW_DROP_LEFT:
1583 gtk_paint_focus (widget->style,
1584 icon_view->priv->bin_window,
1585 GTK_WIDGET_STATE (widget),
1588 "iconview-drop-indicator",
1589 dest_item->x - 1, dest_item->y,
1590 2, dest_item->height);
1592 case GTK_ICON_VIEW_DROP_BELOW:
1593 gtk_paint_focus (widget->style,
1594 icon_view->priv->bin_window,
1595 GTK_WIDGET_STATE (widget),
1598 "iconview-drop-indicator",
1599 dest_item->x, dest_item->y + dest_item->height - 1,
1600 dest_item->width, 2);
1602 case GTK_ICON_VIEW_DROP_RIGHT:
1603 gtk_paint_focus (widget->style,
1604 icon_view->priv->bin_window,
1605 GTK_WIDGET_STATE (widget),
1608 "iconview-drop-indicator",
1609 dest_item->x + dest_item->width - 1, dest_item->y,
1610 2, dest_item->height);
1611 case GTK_ICON_VIEW_NO_DROP: ;
1616 if (icon_view->priv->doing_rubberband)
1618 GdkRectangle *rectangles;
1621 gdk_region_get_rectangles (expose->region,
1625 while (n_rectangles--)
1626 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1628 g_free (rectangles);
1633 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1639 rubberband_scroll_timeout (gpointer data)
1641 GtkIconView *icon_view = data;
1643 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1644 icon_view->priv->vadjustment->value +
1645 icon_view->priv->scroll_value_diff);
1647 gtk_icon_view_update_rubberband (icon_view);
1653 gtk_icon_view_motion (GtkWidget *widget,
1654 GdkEventMotion *event)
1656 GtkIconView *icon_view;
1659 icon_view = GTK_ICON_VIEW (widget);
1661 gtk_icon_view_maybe_begin_drag (icon_view, event);
1663 if (icon_view->priv->doing_rubberband)
1665 gtk_icon_view_update_rubberband (widget);
1667 abs_y = event->y - icon_view->priv->height *
1668 (icon_view->priv->vadjustment->value /
1669 (icon_view->priv->vadjustment->upper -
1670 icon_view->priv->vadjustment->lower));
1672 if (abs_y < 0 || abs_y > widget->allocation.height)
1675 icon_view->priv->scroll_value_diff = abs_y;
1677 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1679 icon_view->priv->event_last_x = event->x;
1680 icon_view->priv->event_last_y = event->y;
1682 if (icon_view->priv->scroll_timeout_id == 0)
1683 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1687 remove_scroll_timeout (icon_view);
1694 gtk_icon_view_remove (GtkContainer *container,
1697 GtkIconView *icon_view;
1698 GtkIconViewChild *child = NULL;
1701 icon_view = GTK_ICON_VIEW (container);
1703 tmp_list = icon_view->priv->children;
1706 child = tmp_list->data;
1707 if (child->widget == widget)
1709 gtk_widget_unparent (widget);
1711 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1712 g_list_free_1 (tmp_list);
1717 tmp_list = tmp_list->next;
1722 gtk_icon_view_forall (GtkContainer *container,
1723 gboolean include_internals,
1724 GtkCallback callback,
1725 gpointer callback_data)
1727 GtkIconView *icon_view;
1728 GtkIconViewChild *child = NULL;
1731 icon_view = GTK_ICON_VIEW (container);
1733 tmp_list = icon_view->priv->children;
1736 child = tmp_list->data;
1737 tmp_list = tmp_list->next;
1739 (* callback) (child->widget, callback_data);
1744 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1745 GtkIconViewItem *item,
1746 GtkIconViewCellInfo *info,
1751 GdkRectangle cell_area;
1752 gboolean visible, mode;
1754 gtk_icon_view_set_cell_data (icon_view, item);
1756 g_object_get (info->cell,
1757 "visible", &visible,
1761 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1763 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1765 path = gtk_tree_path_new_from_indices (item->index, -1);
1766 path_string = gtk_tree_path_to_string (path);
1767 gtk_tree_path_free (path);
1769 gtk_cell_renderer_activate (info->cell,
1771 GTK_WIDGET (icon_view),
1777 g_free (path_string);
1782 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1783 GtkIconViewItem *item)
1786 AtkObject *item_obj;
1788 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1791 item_obj = atk_object_ref_accessible_child (obj, item->index);
1792 if (item_obj != NULL)
1794 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1795 g_object_unref (item_obj);
1801 gtk_icon_view_put (GtkIconView *icon_view,
1803 GtkIconViewItem *item,
1806 GtkIconViewChild *child;
1808 child = g_new (GtkIconViewChild, 1);
1810 child->widget = widget;
1814 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1816 if (GTK_WIDGET_REALIZED (icon_view))
1817 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1819 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1823 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1824 GtkIconView *icon_view)
1827 GtkIconViewItem *item;
1829 if (icon_view->priv->edited_item == NULL)
1832 item = icon_view->priv->edited_item;
1833 icon_view->priv->edited_item = NULL;
1834 icon_view->priv->editable = NULL;
1835 for (l = icon_view->priv->cell_list; l; l = l->next)
1837 GtkIconViewCellInfo *info = l->data;
1839 info->editing = FALSE;
1842 if (GTK_WIDGET_HAS_FOCUS (editable))
1843 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1845 g_signal_handlers_disconnect_by_func (editable,
1846 gtk_icon_view_remove_widget,
1849 gtk_container_remove (GTK_CONTAINER (icon_view),
1850 GTK_WIDGET (editable));
1852 gtk_icon_view_queue_draw_item (icon_view, item);
1857 gtk_icon_view_start_editing (GtkIconView *icon_view,
1858 GtkIconViewItem *item,
1859 GtkIconViewCellInfo *info,
1864 GdkRectangle cell_area;
1865 gboolean visible, mode;
1866 GtkCellEditable *editable;
1868 gtk_icon_view_set_cell_data (icon_view, item);
1870 g_object_get (info->cell,
1871 "visible", &visible,
1874 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1876 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1878 path = gtk_tree_path_new_from_indices (item->index, -1);
1879 path_string = gtk_tree_path_to_string (path);
1880 gtk_tree_path_free (path);
1882 editable = gtk_cell_renderer_start_editing (info->cell,
1884 GTK_WIDGET (icon_view),
1889 g_free (path_string);
1891 /* the rest corresponds to tree_view_real_start_editing... */
1892 icon_view->priv->edited_item = item;
1893 icon_view->priv->editable = editable;
1894 info->editing = TRUE;
1896 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1898 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1900 gtk_widget_grab_focus (GTK_WIDGET (editable));
1901 g_signal_connect (editable, "remove-widget",
1902 G_CALLBACK (gtk_icon_view_remove_widget),
1909 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1910 gboolean cancel_editing)
1912 GtkCellRenderer *cell = NULL;
1913 GtkIconViewItem *item;
1916 if (icon_view->priv->edited_item == NULL)
1920 * This is very evil. We need to do this, because
1921 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1922 * later on. If gtk_icon_view_row_changed notices
1923 * icon_view->priv->edited_item != NULL, it'll call
1924 * gtk_icon_view_stop_editing again. Bad things will happen then.
1926 * Please read that again if you intend to modify anything here.
1929 item = icon_view->priv->edited_item;
1930 icon_view->priv->edited_item = NULL;
1932 for (l = icon_view->priv->cell_list; l; l = l->next)
1934 GtkIconViewCellInfo *info = l->data;
1946 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1947 if (!cancel_editing)
1948 gtk_cell_editable_editing_done (icon_view->priv->editable);
1950 icon_view->priv->edited_item = item;
1952 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1956 * gtk_icon_view_set_cursor:
1957 * @icon_view: A #GtkIconView
1958 * @path: A #GtkTreePath
1959 * @cell: One of the cell renderers of @icon_view, or %NULL
1960 * @start_editing: %TRUE if the specified cell should start being edited.
1962 * Sets the current keyboard focus to be at @path, and selects it. This is
1963 * useful when you want to focus the user's attention on a particular item.
1964 * If @cell is not %NULL, then focus is given to the cell specified by
1965 * it. Additionally, if @start_editing is %TRUE, then editing should be
1966 * started in the specified cell.
1968 * This function is often followed by <literal>gtk_widget_grab_focus
1969 * (icon_view)</literal> in order to give keyboard focus to the widget.
1970 * Please note that editing can only happen when the widget is realized.
1975 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1977 GtkCellRenderer *cell,
1978 gboolean start_editing)
1980 GtkIconViewItem *item = NULL;
1981 GtkIconViewCellInfo *info = NULL;
1985 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1986 g_return_if_fail (path != NULL);
1987 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1989 gtk_icon_view_stop_editing (icon_view, TRUE);
1991 if (gtk_tree_path_get_depth (path) == 1)
1992 item = g_list_nth_data (icon_view->priv->items,
1993 gtk_tree_path_get_indices(path)[0]);
1999 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2003 if (info->cell == cell)
2012 g_return_if_fail (cell == NULL || info != NULL);
2014 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2015 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2017 if (info && start_editing)
2018 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2022 * gtk_icon_view_get_cursor:
2023 * @icon_view: A #GtkIconView
2024 * @path: Return location for the current cursor path, or %NULL
2025 * @cell: Return location the current focus cell, or %NULL
2027 * Fills in @path and @cell with the current cursor path and cell.
2028 * If the cursor isn't currently set, then *@path will be %NULL.
2029 * If no cell currently has focus, then *@cell will be %NULL.
2031 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2033 * Return value: %TRUE if the cursor is set.
2038 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2040 GtkCellRenderer **cell)
2042 GtkIconViewItem *item;
2043 GtkIconViewCellInfo *info;
2045 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2047 item = icon_view->priv->cursor_item;
2048 if (icon_view->priv->cursor_cell < 0)
2051 info = g_list_nth_data (icon_view->priv->cell_list,
2052 icon_view->priv->cursor_cell);
2057 *path = gtk_tree_path_new_from_indices (item->index, -1);
2070 return (item != NULL);
2074 gtk_icon_view_button_press (GtkWidget *widget,
2075 GdkEventButton *event)
2077 GtkIconView *icon_view;
2078 GtkIconViewItem *item;
2079 GtkIconViewCellInfo *info = NULL;
2080 gboolean dirty = FALSE;
2081 GtkCellRendererMode mode;
2082 gint cursor_cell = -1;
2084 icon_view = GTK_ICON_VIEW (widget);
2086 if (event->window != icon_view->priv->bin_window)
2089 if (!GTK_WIDGET_HAS_FOCUS (widget))
2090 gtk_widget_grab_focus (widget);
2092 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2094 item = gtk_icon_view_get_item_at_coords (icon_view,
2100 * We consider only the the cells' area as the item area if the
2101 * item is not selected, but if it *is* selected, the complete
2102 * selection rectangle is considered to be part of the item.
2104 if (item != NULL && (info != NULL || item->selected))
2108 g_object_get (info->cell, "mode", &mode, NULL);
2110 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2111 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2112 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2115 gtk_icon_view_scroll_to_item (icon_view, item);
2117 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2119 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2121 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2122 (event->state & GDK_SHIFT_MASK))
2124 gtk_icon_view_unselect_all_internal (icon_view);
2126 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2127 if (!icon_view->priv->anchor_item)
2128 icon_view->priv->anchor_item = item;
2130 gtk_icon_view_select_all_between (icon_view,
2131 icon_view->priv->anchor_item,
2137 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2138 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2139 (event->state & GDK_CONTROL_MASK))
2141 item->selected = !item->selected;
2142 gtk_icon_view_queue_draw_item (icon_view, item);
2147 if (!item->selected)
2149 gtk_icon_view_unselect_all_internal (icon_view);
2151 item->selected = TRUE;
2152 gtk_icon_view_queue_draw_item (icon_view, item);
2156 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2157 icon_view->priv->anchor_item = item;
2160 /* Save press to possibly begin a drag */
2161 if (icon_view->priv->pressed_button < 0)
2163 icon_view->priv->pressed_button = event->button;
2164 icon_view->priv->press_start_x = event->x;
2165 icon_view->priv->press_start_y = event->y;
2168 if (!icon_view->priv->last_single_clicked)
2169 icon_view->priv->last_single_clicked = item;
2171 /* cancel the current editing, if it exists */
2172 gtk_icon_view_stop_editing (icon_view, TRUE);
2176 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2177 gtk_icon_view_item_activate_cell (icon_view, item, info,
2179 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2180 gtk_icon_view_start_editing (icon_view, item, info,
2186 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2187 !(event->state & GDK_CONTROL_MASK))
2189 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2192 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2193 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2196 /* don't draw keyboard focus around an clicked-on item */
2197 icon_view->priv->draw_focus = FALSE;
2200 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2202 item = gtk_icon_view_get_item_at_coords (icon_view,
2207 if (item && item == icon_view->priv->last_single_clicked)
2211 path = gtk_tree_path_new_from_indices (item->index, -1);
2212 gtk_icon_view_item_activated (icon_view, path);
2213 gtk_tree_path_free (path);
2216 icon_view->priv->last_single_clicked = NULL;
2217 icon_view->priv->pressed_button = -1;
2221 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2223 return event->button == 1;
2227 gtk_icon_view_button_release (GtkWidget *widget,
2228 GdkEventButton *event)
2230 GtkIconView *icon_view;
2232 icon_view = GTK_ICON_VIEW (widget);
2234 if (icon_view->priv->pressed_button == event->button)
2235 icon_view->priv->pressed_button = -1;
2237 gtk_icon_view_stop_rubberbanding (icon_view);
2239 remove_scroll_timeout (icon_view);
2245 gtk_icon_view_key_press (GtkWidget *widget,
2248 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2250 if (icon_view->priv->doing_rubberband)
2252 if (event->keyval == GDK_Escape)
2253 gtk_icon_view_stop_rubberbanding (icon_view);
2258 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2262 gtk_icon_view_key_release (GtkWidget *widget,
2265 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2267 if (icon_view->priv->doing_rubberband)
2270 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2274 gtk_icon_view_update_rubberband (gpointer data)
2276 GtkIconView *icon_view;
2278 GdkRectangle old_area;
2279 GdkRectangle new_area;
2280 GdkRectangle common;
2281 GdkRegion *invalid_region;
2283 icon_view = GTK_ICON_VIEW (data);
2285 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2290 old_area.x = MIN (icon_view->priv->rubberband_x1,
2291 icon_view->priv->rubberband_x2);
2292 old_area.y = MIN (icon_view->priv->rubberband_y1,
2293 icon_view->priv->rubberband_y2);
2294 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2295 icon_view->priv->rubberband_x1) + 1;
2296 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2297 icon_view->priv->rubberband_y1) + 1;
2299 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2300 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2301 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2302 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2304 invalid_region = gdk_region_rectangle (&old_area);
2305 gdk_region_union_with_rect (invalid_region, &new_area);
2307 gdk_rectangle_intersect (&old_area, &new_area, &common);
2308 if (common.width > 2 && common.height > 2)
2310 GdkRegion *common_region;
2312 /* make sure the border is invalidated */
2318 common_region = gdk_region_rectangle (&common);
2320 gdk_region_subtract (invalid_region, common_region);
2321 gdk_region_destroy (common_region);
2324 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2326 gdk_region_destroy (invalid_region);
2328 icon_view->priv->rubberband_x2 = x;
2329 icon_view->priv->rubberband_y2 = y;
2331 gtk_icon_view_update_rubberband_selection (icon_view);
2335 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2341 g_assert (!icon_view->priv->doing_rubberband);
2343 for (items = icon_view->priv->items; items; items = items->next)
2345 GtkIconViewItem *item = items->data;
2347 item->selected_before_rubberbanding = item->selected;
2350 icon_view->priv->rubberband_x1 = x;
2351 icon_view->priv->rubberband_y1 = y;
2352 icon_view->priv->rubberband_x2 = x;
2353 icon_view->priv->rubberband_y2 = y;
2355 icon_view->priv->doing_rubberband = TRUE;
2357 gtk_grab_add (GTK_WIDGET (icon_view));
2361 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2363 if (!icon_view->priv->doing_rubberband)
2366 icon_view->priv->doing_rubberband = FALSE;
2368 gtk_grab_remove (GTK_WIDGET (icon_view));
2370 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2374 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2377 gint x, y, width, height;
2378 gboolean dirty = FALSE;
2380 x = MIN (icon_view->priv->rubberband_x1,
2381 icon_view->priv->rubberband_x2);
2382 y = MIN (icon_view->priv->rubberband_y1,
2383 icon_view->priv->rubberband_y2);
2384 width = ABS (icon_view->priv->rubberband_x1 -
2385 icon_view->priv->rubberband_x2);
2386 height = ABS (icon_view->priv->rubberband_y1 -
2387 icon_view->priv->rubberband_y2);
2389 for (items = icon_view->priv->items; items; items = items->next)
2391 GtkIconViewItem *item = items->data;
2395 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2396 x, y, width, height);
2398 selected = is_in ^ item->selected_before_rubberbanding;
2400 if (item->selected != selected)
2402 item->selected = selected;
2404 gtk_icon_view_queue_draw_item (icon_view, item);
2409 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2413 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2414 GtkIconViewItem *item,
2423 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2424 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2427 for (l = icon_view->priv->cell_list; l; l = l->next)
2429 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2431 if (!info->cell->visible)
2434 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2436 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2437 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2445 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2447 gboolean dirty = FALSE;
2450 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2453 for (items = icon_view->priv->items; items; items = items->next)
2455 GtkIconViewItem *item = items->data;
2459 item->selected = FALSE;
2461 gtk_icon_view_queue_draw_item (icon_view, item);
2462 gtk_icon_view_item_selected_changed (icon_view, item);
2470 /* GtkIconView signals */
2472 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2473 GtkAdjustment *hadj,
2474 GtkAdjustment *vadj)
2476 gboolean need_adjust = FALSE;
2479 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2481 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2483 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2485 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2487 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2489 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2490 0, 0, NULL, NULL, icon_view);
2491 g_object_unref (icon_view->priv->hadjustment);
2494 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2496 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2497 0, 0, NULL, NULL, icon_view);
2498 g_object_unref (icon_view->priv->vadjustment);
2501 if (icon_view->priv->hadjustment != hadj)
2503 icon_view->priv->hadjustment = hadj;
2504 g_object_ref_sink (icon_view->priv->hadjustment);
2506 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2507 G_CALLBACK (gtk_icon_view_adjustment_changed),
2512 if (icon_view->priv->vadjustment != vadj)
2514 icon_view->priv->vadjustment = vadj;
2515 g_object_ref_sink (icon_view->priv->vadjustment);
2517 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2518 G_CALLBACK (gtk_icon_view_adjustment_changed),
2524 gtk_icon_view_adjustment_changed (NULL, icon_view);
2528 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2530 gtk_icon_view_select_all (icon_view);
2534 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2536 gtk_icon_view_unselect_all (icon_view);
2540 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2542 gtk_icon_view_unselect_all (icon_view);
2544 if (icon_view->priv->cursor_item != NULL)
2545 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2549 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2552 GtkCellRendererMode mode;
2553 GtkIconViewCellInfo *info = NULL;
2555 if (!icon_view->priv->cursor_item)
2558 info = g_list_nth_data (icon_view->priv->cell_list,
2559 icon_view->priv->cursor_cell);
2563 g_object_get (info->cell, "mode", &mode, NULL);
2565 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2567 gtk_icon_view_item_activate_cell (icon_view,
2568 icon_view->priv->cursor_item,
2572 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2574 gtk_icon_view_start_editing (icon_view,
2575 icon_view->priv->cursor_item,
2581 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2582 gtk_icon_view_item_activated (icon_view, path);
2583 gtk_tree_path_free (path);
2589 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2591 if (!icon_view->priv->cursor_item)
2594 switch (icon_view->priv->selection_mode)
2596 case GTK_SELECTION_NONE:
2598 case GTK_SELECTION_BROWSE:
2599 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2601 case GTK_SELECTION_SINGLE:
2602 if (icon_view->priv->cursor_item->selected)
2603 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2605 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2607 case GTK_SELECTION_MULTIPLE:
2608 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2609 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2611 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2612 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2617 /* Internal functions */
2619 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2620 GtkIconView *icon_view)
2622 if (GTK_WIDGET_REALIZED (icon_view))
2624 gdk_window_move (icon_view->priv->bin_window,
2625 - icon_view->priv->hadjustment->value,
2626 - icon_view->priv->vadjustment->value);
2628 if (icon_view->priv->doing_rubberband)
2629 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2631 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2636 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2641 gint *maximum_width)
2644 gint x, current_width;
2645 GList *items, *last_item;
2652 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2653 max_height = g_new0 (gint, icon_view->priv->n_cells);
2660 gtk_widget_style_get (GTK_WIDGET (icon_view),
2661 "focus-line-width", &focus_width,
2664 x += icon_view->priv->margin + focus_width;
2665 current_width += 2 * (icon_view->priv->margin + focus_width);
2670 GtkIconViewItem *item = items->data;
2672 gtk_icon_view_calculate_item_size (icon_view, item);
2673 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2675 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2677 current_width += item->width;
2679 if (items != first_item)
2681 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2682 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2686 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2688 item->y = *y + focus_width;
2691 x = current_width - (icon_view->priv->margin + focus_width);
2693 for (i = 0; i < icon_view->priv->n_cells; i++)
2694 max_height[i] = MAX (max_height[i], item->box[i].height);
2696 if (current_width > *maximum_width)
2697 *maximum_width = current_width;
2703 items = items->next;
2708 /* Now go through the row again and align the icons */
2709 for (items = first_item; items != last_item; items = items->next)
2711 GtkIconViewItem *item = items->data;
2715 item->x = *maximum_width - item->width - item->x;
2716 item->col = col - 1 - item->col;
2719 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2721 /* We may want to readjust the new y coordinate. */
2722 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2723 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2726 g_free (max_height);
2732 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2735 if (upper != adj->upper)
2737 gdouble min = MAX (0.0, upper - adj->page_size);
2738 gboolean value_changed = FALSE;
2742 if (adj->value > min)
2745 value_changed = TRUE;
2748 gtk_adjustment_changed (adj);
2751 gtk_adjustment_value_changed (adj);
2756 gtk_icon_view_layout (GtkIconView *icon_view)
2758 gint y = 0, maximum_width = 0;
2764 if (icon_view->priv->layout_idle_id != 0)
2766 g_source_remove (icon_view->priv->layout_idle_id);
2767 icon_view->priv->layout_idle_id = 0;
2770 if (icon_view->priv->model == NULL)
2773 widget = GTK_WIDGET (icon_view);
2775 item_width = icon_view->priv->item_width;
2779 for (icons = icon_view->priv->items; icons; icons = icons->next)
2781 GtkIconViewItem *item = icons->data;
2782 gtk_icon_view_calculate_item_size (icon_view, item);
2783 item_width = MAX (item_width, item->width);
2788 icons = icon_view->priv->items;
2789 y += icon_view->priv->margin;
2794 gtk_icon_view_set_cell_data (icon_view, icons->data);
2795 adjust_wrap_width (icon_view, icons->data);
2800 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2802 &y, &maximum_width);
2805 while (icons != NULL);
2807 if (maximum_width != icon_view->priv->width)
2808 icon_view->priv->width = maximum_width;
2810 y += icon_view->priv->margin;
2812 if (y != icon_view->priv->height)
2813 icon_view->priv->height = y;
2815 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2816 icon_view->priv->width);
2817 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2818 icon_view->priv->height);
2820 if (icon_view->priv->width != widget->requisition.width ||
2821 icon_view->priv->height != widget->requisition.height)
2822 gtk_widget_queue_resize_no_redraw (widget);
2824 if (GTK_WIDGET_REALIZED (icon_view))
2825 gdk_window_resize (icon_view->priv->bin_window,
2826 MAX (icon_view->priv->width, widget->allocation.width),
2827 MAX (icon_view->priv->height, widget->allocation.height));
2829 if (icon_view->priv->scroll_to_path)
2833 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2834 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2835 icon_view->priv->scroll_to_path = NULL;
2837 gtk_icon_view_scroll_to_path (icon_view, path,
2838 icon_view->priv->scroll_to_use_align,
2839 icon_view->priv->scroll_to_row_align,
2840 icon_view->priv->scroll_to_col_align);
2841 gtk_tree_path_free (path);
2844 gtk_widget_queue_draw (widget);
2848 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2849 GtkIconViewItem *item,
2850 GtkIconViewCellInfo *info,
2851 GdkRectangle *cell_area)
2853 g_return_if_fail (info->position < item->n_cells);
2855 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2857 cell_area->x = item->box[info->position].x - item->before[info->position];
2858 cell_area->y = item->y + ITEM_PADDING;
2859 cell_area->width = item->box[info->position].width +
2860 item->before[info->position] + item->after[info->position];
2861 cell_area->height = item->height - ITEM_PADDING * 2;
2865 cell_area->x = item->x + ITEM_PADDING;
2866 cell_area->y = item->box[info->position].y - item->before[info->position];
2867 cell_area->width = item->width - ITEM_PADDING * 2;
2868 cell_area->height = item->box[info->position].height +
2869 item->before[info->position] + item->after[info->position];
2874 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2875 GtkIconViewItem *item,
2876 GtkIconViewCellInfo *info,
2879 g_return_if_fail (info->position < item->n_cells);
2881 *box = item->box[info->position];
2884 /* try to guess a reasonable wrap width for an implicit text cell renderer
2887 adjust_wrap_width (GtkIconView *icon_view,
2888 GtkIconViewItem *item)
2890 GtkIconViewCellInfo *text_info;
2891 GtkIconViewCellInfo *pixbuf_info;
2892 gint pixbuf_width, wrap_width;
2894 if (icon_view->priv->text_cell != -1 &&
2895 icon_view->priv->pixbuf_cell != -1)
2899 text_info = g_list_nth_data (icon_view->priv->cell_list,
2900 icon_view->priv->text_cell);
2901 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2902 icon_view->priv->pixbuf_cell);
2904 gtk_cell_renderer_get_size (pixbuf_info->cell,
2905 GTK_WIDGET (icon_view),
2911 if (icon_view->priv->item_width > 0)
2912 item_width = icon_view->priv->item_width;
2914 item_width = item->width;
2916 if (item->width == -1)
2919 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2921 wrap_width = MAX (2 * pixbuf_width, 50);
2923 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2924 wrap_width = item_width;
2926 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2928 wrap_width -= ITEM_PADDING * 2;
2930 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2931 g_object_set (text_info->cell, "width", wrap_width, NULL);
2936 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2937 GtkIconViewItem *item)
2942 if (item->width != -1 && item->height != -1)
2945 if (item->n_cells != icon_view->priv->n_cells)
2947 g_free (item->before);
2948 g_free (item->after);
2951 item->before = g_new0 (gint, icon_view->priv->n_cells);
2952 item->after = g_new0 (gint, icon_view->priv->n_cells);
2953 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2955 item->n_cells = icon_view->priv->n_cells;
2958 gtk_icon_view_set_cell_data (icon_view, item);
2960 spacing = icon_view->priv->spacing;
2964 for (l = icon_view->priv->cell_list; l; l = l->next)
2966 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2968 if (!info->cell->visible)
2971 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2973 &item->box[info->position].width,
2974 &item->box[info->position].height);
2976 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2978 item->width += item->box[info->position].width
2979 + (info->position > 0 ? spacing : 0);
2980 item->height = MAX (item->height, item->box[info->position].height);
2984 item->width = MAX (item->width, item->box[info->position].width);
2985 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2989 item->width += ITEM_PADDING * 2;
2990 item->height += ITEM_PADDING * 2;
2994 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2995 GtkIconViewItem *item,
2998 GdkRectangle cell_area;
3004 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3006 gtk_icon_view_set_cell_data (icon_view, item);
3008 spacing = icon_view->priv->spacing;
3011 for (i = 0; i < icon_view->priv->n_cells; i++)
3013 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3014 item->height = MAX (item->height, max_height[i]);
3016 item->height += max_height[i] + (i > 0 ? spacing : 0);
3019 cell_area.x = item->x + ITEM_PADDING;
3020 cell_area.y = item->y + ITEM_PADDING;
3022 for (k = 0; k < 2; k++)
3023 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3025 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3027 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3030 if (!info->cell->visible)
3033 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3035 /* We should not subtract ITEM_PADDING from item->height,
3036 * because item->height is recalculated above using
3037 * max_height which does not contain item padding.
3039 cell_area.width = item->box[info->position].width;
3040 cell_area.height = item->height;
3044 /* item->width is not recalculated and thus needs to be
3045 * corrected for the padding.
3047 cell_area.width = item->width - 2 * ITEM_PADDING;
3048 cell_area.height = max_height[i];
3051 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3053 &item->box[info->position].x, &item->box[info->position].y,
3054 &item->box[info->position].width, &item->box[info->position].height);
3056 item->box[info->position].x += cell_area.x;
3057 item->box[info->position].y += cell_area.y;
3058 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3060 item->before[info->position] = item->box[info->position].x - cell_area.x;
3061 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3062 cell_area.x += cell_area.width + spacing;
3066 if (item->box[info->position].width > item->width - ITEM_PADDING * 2)
3068 item->width = item->box[info->position].width + ITEM_PADDING * 2;
3069 cell_area.width = item->width;
3071 item->before[info->position] = item->box[info->position].y - cell_area.y;
3072 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3073 cell_area.y += cell_area.height + spacing;
3077 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3079 for (i = 0; i < icon_view->priv->n_cells; i++)
3081 item->box[i].x = item->x + item->width -
3082 (item->box[i].x + item->box[i].width - item->x);
3086 item->height += ITEM_PADDING * 2;
3090 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3092 g_list_foreach (icon_view->priv->items,
3093 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3097 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3104 gtk_icon_view_paint_item (GtkIconView *icon_view,
3106 GtkIconViewItem *item,
3108 GdkDrawable *drawable,
3111 gboolean draw_focus)
3115 GdkRectangle cell_area, box;
3119 GtkCellRendererState flags;
3121 if (icon_view->priv->model == NULL)
3124 gtk_icon_view_set_cell_data (icon_view, item);
3126 gtk_widget_style_get (GTK_WIDGET (icon_view),
3127 "focus-line-width", &focus_width,
3130 padding = focus_width;
3134 flags = GTK_CELL_RENDERER_SELECTED;
3135 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3136 state = GTK_STATE_SELECTED;
3138 state = GTK_STATE_ACTIVE;
3143 state = GTK_STATE_NORMAL;
3146 #ifdef DEBUG_ICON_VIEW
3147 gdk_draw_rectangle (drawable,
3148 GTK_WIDGET (icon_view)->style->black_gc,
3151 item->width, item->height);
3156 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3157 (GdkWindow *) drawable,
3161 GTK_WIDGET (icon_view),
3164 item->width, item->height);
3167 for (l = icon_view->priv->cell_list; l; l = l->next)
3169 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3171 if (!info->cell->visible)
3174 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3176 #ifdef DEBUG_ICON_VIEW
3177 gdk_draw_rectangle (drawable,
3178 GTK_WIDGET (icon_view)->style->black_gc,
3180 x - item->x + cell_area.x,
3181 y - item->y + cell_area.y,
3182 cell_area.width, cell_area.height);
3184 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3186 gdk_draw_rectangle (drawable,
3187 GTK_WIDGET (icon_view)->style->black_gc,
3189 x - item->x + box.x,
3190 y - item->y + box.y,
3191 box.width, box.height);
3194 cell_area.x = x - item->x + cell_area.x;
3195 cell_area.y = y - item->y + cell_area.y;
3197 gtk_cell_renderer_render (info->cell,
3199 GTK_WIDGET (icon_view),
3200 &cell_area, &cell_area, area, flags);
3204 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3205 item == icon_view->priv->cursor_item)
3207 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3209 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3211 if (!info->cell->visible)
3214 /* If found a editable/activatable cell, draw focus on it. */
3215 if (icon_view->priv->cursor_cell < 0 &&
3216 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3217 icon_view->priv->cursor_cell = i;
3219 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3221 if (i == icon_view->priv->cursor_cell)
3223 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3227 GTK_WIDGET (icon_view),
3229 x - item->x + box.x - padding,
3230 y - item->y + box.y - padding,
3231 box.width + 2 * padding,
3232 box.height + 2 * padding);
3237 /* If there are no editable/activatable cells, draw focus
3238 * around the whole item.
3240 if (icon_view->priv->cursor_cell < 0)
3241 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3245 GTK_WIDGET (icon_view),
3249 item->width + 2 * padding,
3250 item->height + 2 * padding);
3255 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3260 GdkRectangle rubber_rect;
3261 GdkColor *fill_color_gdk;
3262 guchar fill_color_alpha;
3264 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3265 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3266 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3267 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3269 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3272 gtk_widget_style_get (GTK_WIDGET (icon_view),
3273 "selection-box-color", &fill_color_gdk,
3274 "selection-box-alpha", &fill_color_alpha,
3277 if (!fill_color_gdk)
3278 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3280 cairo_set_source_rgba (cr,
3281 fill_color_gdk->red / 65535.,
3282 fill_color_gdk->green / 65535.,
3283 fill_color_gdk->blue / 65535.,
3284 fill_color_alpha / 255.);
3287 gdk_cairo_rectangle (cr, &rect);
3291 /* Draw the border without alpha */
3292 cairo_set_source_rgb (cr,
3293 fill_color_gdk->red / 65535.,
3294 fill_color_gdk->green / 65535.,
3295 fill_color_gdk->blue / 65535.);
3296 cairo_rectangle (cr,
3297 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3298 rubber_rect.width - 1, rubber_rect.height - 1);
3302 gdk_color_free (fill_color_gdk);
3306 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3312 index = gtk_tree_path_get_indices (path)[0];
3314 for (l = icon_view->priv->items; l; l = l->next)
3316 GtkIconViewItem *item = l->data;
3318 if (item->index == index)
3320 gtk_icon_view_queue_draw_item (icon_view, item);
3327 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3328 GtkIconViewItem *item)
3333 gtk_widget_style_get (GTK_WIDGET (icon_view),
3334 "focus-line-width", &focus_width,
3337 rect.x = item->x - focus_width;
3338 rect.y = item->y - focus_width;
3339 rect.width = item->width + 2 * focus_width;
3340 rect.height = item->height + 2 * focus_width;
3342 if (icon_view->priv->bin_window)
3343 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3347 layout_callback (gpointer user_data)
3349 GtkIconView *icon_view;
3351 icon_view = GTK_ICON_VIEW (user_data);
3353 icon_view->priv->layout_idle_id = 0;
3355 gtk_icon_view_layout (icon_view);
3361 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3363 if (icon_view->priv->layout_idle_id != 0)
3366 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3370 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3371 GtkIconViewItem *item,
3375 AtkObject *item_obj;
3376 AtkObject *cursor_item_obj;
3378 if (icon_view->priv->cursor_item == item &&
3379 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3382 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3383 if (icon_view->priv->cursor_item != NULL)
3385 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3388 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3389 if (cursor_item_obj != NULL)
3390 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3393 icon_view->priv->cursor_item = item;
3394 if (cursor_cell >= 0)
3395 icon_view->priv->cursor_cell = cursor_cell;
3397 gtk_icon_view_queue_draw_item (icon_view, item);
3399 /* Notify that accessible focus object has changed */
3400 item_obj = atk_object_ref_accessible_child (obj, item->index);
3402 if (item_obj != NULL)
3404 atk_focus_tracker_notify (item_obj);
3405 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3406 g_object_unref (item_obj);
3411 static GtkIconViewItem *
3412 gtk_icon_view_item_new (void)
3414 GtkIconViewItem *item;
3416 item = g_new0 (GtkIconViewItem, 1);
3425 gtk_icon_view_item_free (GtkIconViewItem *item)
3427 g_return_if_fail (item != NULL);
3429 g_free (item->before);
3430 g_free (item->after);
3437 static GtkIconViewItem *
3438 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3441 gboolean only_in_cell,
3442 GtkIconViewCellInfo **cell_at_pos)
3447 for (items = icon_view->priv->items; items; items = items->next)
3449 GtkIconViewItem *item = items->data;
3451 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3452 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3454 if (only_in_cell || cell_at_pos)
3456 gtk_icon_view_set_cell_data (icon_view, item);
3458 for (l = icon_view->priv->cell_list; l; l = l->next)
3460 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3462 if (!info->cell->visible)
3465 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3467 if ((x >= box.x && x <= box.x + box.width &&
3468 y >= box.y && y <= box.y + box.height) ||
3470 x <= box.x + box.width &&
3472 y <= box.y + box.height))
3475 *cell_at_pos = info;
3485 *cell_at_pos = NULL;
3496 gtk_icon_view_select_item (GtkIconView *icon_view,
3497 GtkIconViewItem *item)
3499 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3500 g_return_if_fail (item != NULL);
3505 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3507 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3508 gtk_icon_view_unselect_all_internal (icon_view);
3510 item->selected = TRUE;
3512 gtk_icon_view_item_selected_changed (icon_view, item);
3513 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3515 gtk_icon_view_queue_draw_item (icon_view, item);
3520 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3521 GtkIconViewItem *item)
3523 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3524 g_return_if_fail (item != NULL);
3526 if (!item->selected)
3529 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3530 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3533 item->selected = FALSE;
3535 gtk_icon_view_item_selected_changed (icon_view, item);
3536 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3538 gtk_icon_view_queue_draw_item (icon_view, item);
3542 verify_items (GtkIconView *icon_view)
3547 for (items = icon_view->priv->items; items; items = items->next)
3549 GtkIconViewItem *item = items->data;
3551 if (item->index != i)
3552 g_error ("List item does not match its index: "
3553 "item index %d and list index %d\n", item->index, i);
3560 gtk_icon_view_row_changed (GtkTreeModel *model,
3565 GtkIconViewItem *item;
3567 GtkIconView *icon_view;
3569 icon_view = GTK_ICON_VIEW (data);
3571 gtk_icon_view_stop_editing (icon_view, TRUE);
3573 index = gtk_tree_path_get_indices(path)[0];
3574 item = g_list_nth_data (icon_view->priv->items, index);
3576 gtk_icon_view_item_invalidate_size (item);
3577 gtk_icon_view_queue_layout (icon_view);
3579 verify_items (icon_view);
3583 gtk_icon_view_row_inserted (GtkTreeModel *model,
3589 GtkIconViewItem *item;
3590 gboolean iters_persist;
3591 GtkIconView *icon_view;
3594 icon_view = GTK_ICON_VIEW (data);
3596 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3598 index = gtk_tree_path_get_indices(path)[0];
3600 item = gtk_icon_view_item_new ();
3605 item->index = index;
3607 /* FIXME: We can be more efficient here,
3608 we can store a tail pointer and use that when
3609 appending (which is a rather common operation)
3611 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3614 list = g_list_nth (icon_view->priv->items, index + 1);
3615 for (; list; list = list->next)
3622 verify_items (icon_view);
3624 gtk_icon_view_queue_layout (icon_view);
3628 gtk_icon_view_row_deleted (GtkTreeModel *model,
3633 GtkIconView *icon_view;
3634 GtkIconViewItem *item;
3636 gboolean emit = FALSE;
3638 icon_view = GTK_ICON_VIEW (data);
3640 index = gtk_tree_path_get_indices(path)[0];
3642 list = g_list_nth (icon_view->priv->items, index);
3645 gtk_icon_view_stop_editing (icon_view, TRUE);
3647 if (item == icon_view->priv->anchor_item)
3648 icon_view->priv->anchor_item = NULL;
3650 if (item == icon_view->priv->cursor_item)
3651 icon_view->priv->cursor_item = NULL;
3656 gtk_icon_view_item_free (item);
3658 for (next = list->next; next; next = next->next)
3665 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3667 verify_items (icon_view);
3669 gtk_icon_view_queue_layout (icon_view);
3672 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3676 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3677 GtkTreePath *parent,
3684 GtkIconView *icon_view;
3685 GList *items = NULL, *list;
3686 GtkIconViewItem **item_array;
3689 icon_view = GTK_ICON_VIEW (data);
3691 gtk_icon_view_stop_editing (icon_view, TRUE);
3693 length = gtk_tree_model_iter_n_children (model, NULL);
3695 order = g_new (gint, length);
3696 for (i = 0; i < length; i++)
3697 order [new_order[i]] = i;
3699 item_array = g_new (GtkIconViewItem *, length);
3700 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3701 item_array[order[i]] = list->data;
3704 for (i = length - 1; i >= 0; i--)
3706 item_array[i]->index = i;
3707 items = g_list_prepend (items, item_array[i]);
3710 g_free (item_array);
3711 g_list_free (icon_view->priv->items);
3712 icon_view->priv->items = items;
3714 gtk_icon_view_queue_layout (icon_view);
3716 verify_items (icon_view);
3720 gtk_icon_view_build_items (GtkIconView *icon_view)
3724 gboolean iters_persist;
3725 GList *items = NULL;
3727 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3729 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3737 GtkIconViewItem *item = gtk_icon_view_item_new ();
3746 items = g_list_prepend (items, item);
3748 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3750 icon_view->priv->items = g_list_reverse (items);
3754 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3757 GtkMovementStep step,
3761 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3762 I_("move-cursor"), 2,
3766 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3771 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3774 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3779 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3786 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3787 GtkMovementStep step,
3790 GdkModifierType state;
3792 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3793 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3794 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3795 step == GTK_MOVEMENT_DISPLAY_LINES ||
3796 step == GTK_MOVEMENT_PAGES ||
3797 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3799 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3802 gtk_icon_view_stop_editing (icon_view, FALSE);
3803 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3805 if (gtk_get_current_event_state (&state))
3807 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3808 icon_view->priv->ctrl_pressed = TRUE;
3809 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3810 icon_view->priv->shift_pressed = TRUE;
3812 /* else we assume not pressed */
3816 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3817 case GTK_MOVEMENT_VISUAL_POSITIONS:
3818 gtk_icon_view_move_cursor_left_right (icon_view, count);
3820 case GTK_MOVEMENT_DISPLAY_LINES:
3821 gtk_icon_view_move_cursor_up_down (icon_view, count);
3823 case GTK_MOVEMENT_PAGES:
3824 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3826 case GTK_MOVEMENT_BUFFER_ENDS:
3827 gtk_icon_view_move_cursor_start_end (icon_view, count);
3830 g_assert_not_reached ();
3833 icon_view->priv->ctrl_pressed = FALSE;
3834 icon_view->priv->shift_pressed = FALSE;
3836 icon_view->priv->draw_focus = TRUE;
3841 static GtkIconViewItem *
3842 find_item (GtkIconView *icon_view,
3843 GtkIconViewItem *current,
3849 GtkIconViewItem *item;
3851 /* FIXME: this could be more efficient
3853 row = current->row + row_ofs;
3854 col = current->col + col_ofs;
3856 for (items = icon_view->priv->items; items; items = items->next)
3859 if (item->row == row && item->col == col)
3867 find_cell (GtkIconView *icon_view,
3868 GtkIconViewItem *item,
3870 GtkOrientation orientation,
3880 if (icon_view->priv->orientation != orientation)
3883 gtk_icon_view_set_cell_data (icon_view, item);
3885 focusable = g_new0 (gint, icon_view->priv->n_cells);
3889 for (k = 0; k < 2; k++)
3890 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3892 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3894 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3897 if (!info->cell->visible)
3900 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3903 current = n_focusable;
3905 focusable[n_focusable] = i;
3911 if (n_focusable == 0)
3919 current = step > 0 ? 0 : n_focusable - 1;
3920 cell = focusable[current];
3923 if (current + *count < 0)
3926 *count = current + *count;
3928 else if (current + *count > n_focusable - 1)
3931 *count = current + *count - (n_focusable - 1);
3935 cell = focusable[current + *count];
3944 static GtkIconViewItem *
3945 find_item_page_up_down (GtkIconView *icon_view,
3946 GtkIconViewItem *current,
3953 y = current->y + count * icon_view->priv->vadjustment->page_size;
3955 item = g_list_find (icon_view->priv->items, current);
3960 for (next = item->next; next; next = next->next)
3962 if (((GtkIconViewItem *)next->data)->col == col)
3965 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3975 for (next = item->prev; next; next = next->prev)
3977 if (((GtkIconViewItem *)next->data)->col == col)
3980 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3994 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3995 GtkIconViewItem *anchor,
3996 GtkIconViewItem *cursor)
3999 GtkIconViewItem *item;
4000 gint row1, row2, col1, col2;
4001 gboolean dirty = FALSE;
4003 if (anchor->row < cursor->row)
4014 if (anchor->col < cursor->col)
4025 for (items = icon_view->priv->items; items; items = items->next)
4029 if (row1 <= item->row && item->row <= row2 &&
4030 col1 <= item->col && item->col <= col2)
4032 if (!item->selected)
4035 item->selected = TRUE;
4036 gtk_icon_view_item_selected_changed (icon_view, item);
4038 gtk_icon_view_queue_draw_item (icon_view, item);
4046 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4049 GtkIconViewItem *item;
4051 gboolean dirty = FALSE;
4054 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4057 if (!icon_view->priv->cursor_item)
4062 list = icon_view->priv->items;
4064 list = g_list_last (icon_view->priv->items);
4066 item = list ? list->data : NULL;
4071 item = icon_view->priv->cursor_item;
4072 cell = icon_view->priv->cursor_cell;
4073 step = count > 0 ? 1 : -1;
4076 cell = find_cell (icon_view, item, cell,
4077 GTK_ORIENTATION_VERTICAL,
4082 item = find_item (icon_view, item, step, 0);
4083 count = count - step;
4089 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4093 if (icon_view->priv->ctrl_pressed ||
4094 !icon_view->priv->shift_pressed ||
4095 !icon_view->priv->anchor_item ||
4096 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4097 icon_view->priv->anchor_item = item;
4099 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4101 if (!icon_view->priv->ctrl_pressed &&
4102 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4104 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4105 dirty = gtk_icon_view_select_all_between (icon_view,
4106 icon_view->priv->anchor_item,
4110 gtk_icon_view_scroll_to_item (icon_view, item);
4113 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4117 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4120 GtkIconViewItem *item;
4121 gboolean dirty = FALSE;
4123 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4126 if (!icon_view->priv->cursor_item)
4131 list = icon_view->priv->items;
4133 list = g_list_last (icon_view->priv->items);
4135 item = list ? list->data : NULL;
4138 item = find_item_page_up_down (icon_view,
4139 icon_view->priv->cursor_item,
4142 if (item == icon_view->priv->cursor_item)
4143 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4148 if (icon_view->priv->ctrl_pressed ||
4149 !icon_view->priv->shift_pressed ||
4150 !icon_view->priv->anchor_item ||
4151 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4152 icon_view->priv->anchor_item = item;
4154 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4156 if (!icon_view->priv->ctrl_pressed &&
4157 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4159 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4160 dirty = gtk_icon_view_select_all_between (icon_view,
4161 icon_view->priv->anchor_item,
4165 gtk_icon_view_scroll_to_item (icon_view, item);
4168 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4172 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4175 GtkIconViewItem *item;
4177 gboolean dirty = FALSE;
4180 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4183 if (!icon_view->priv->cursor_item)
4188 list = icon_view->priv->items;
4190 list = g_list_last (icon_view->priv->items);
4192 item = list ? list->data : NULL;
4196 item = icon_view->priv->cursor_item;
4197 cell = icon_view->priv->cursor_cell;
4198 step = count > 0 ? 1 : -1;
4201 cell = find_cell (icon_view, item, cell,
4202 GTK_ORIENTATION_HORIZONTAL,
4207 item = find_item (icon_view, item, 0, step);
4208 count = count - step;
4214 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4218 if (icon_view->priv->ctrl_pressed ||
4219 !icon_view->priv->shift_pressed ||
4220 !icon_view->priv->anchor_item ||
4221 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4222 icon_view->priv->anchor_item = item;
4224 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4226 if (!icon_view->priv->ctrl_pressed &&
4227 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4229 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4230 dirty = gtk_icon_view_select_all_between (icon_view,
4231 icon_view->priv->anchor_item,
4235 gtk_icon_view_scroll_to_item (icon_view, item);
4238 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4242 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4245 GtkIconViewItem *item;
4247 gboolean dirty = FALSE;
4249 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4253 list = icon_view->priv->items;
4255 list = g_list_last (icon_view->priv->items);
4257 item = list ? list->data : NULL;
4259 if (item == icon_view->priv->cursor_item)
4260 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4265 if (icon_view->priv->ctrl_pressed ||
4266 !icon_view->priv->shift_pressed ||
4267 !icon_view->priv->anchor_item ||
4268 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4269 icon_view->priv->anchor_item = item;
4271 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4273 if (!icon_view->priv->ctrl_pressed &&
4274 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4276 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4277 dirty = gtk_icon_view_select_all_between (icon_view,
4278 icon_view->priv->anchor_item,
4282 gtk_icon_view_scroll_to_item (icon_view, item);
4285 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4289 * gtk_icon_view_scroll_to_path:
4290 * @icon_view: A #GtkIconView.
4291 * @path: The path of the item to move to.
4292 * @use_align: whether to use alignment arguments, or %FALSE.
4293 * @row_align: The vertical alignment of the item specified by @path.
4294 * @col_align: The horizontal alignment of the item specified by @path.
4296 * Moves the alignments of @icon_view to the position specified by @path.
4297 * @row_align determines where the row is placed, and @col_align determines
4298 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4299 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4302 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4303 * tree does the minimum amount of work to scroll the item onto the screen.
4304 * This means that the item will be scrolled to the edge closest to its current
4305 * position. If the item is currently visible on the screen, nothing is done.
4307 * This function only works if the model is set, and @path is a valid row on
4308 * the model. If the model changes before the @icon_view is realized, the
4309 * centered path will be modified to reflect this change.
4314 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4320 GtkIconViewItem *item = NULL;
4322 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4323 g_return_if_fail (path != NULL);
4324 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4325 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4327 if (gtk_tree_path_get_depth (path) > 0)
4328 item = g_list_nth_data (icon_view->priv->items,
4329 gtk_tree_path_get_indices(path)[0]);
4331 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4333 if (icon_view->priv->scroll_to_path)
4334 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4336 icon_view->priv->scroll_to_path = NULL;
4339 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4341 icon_view->priv->scroll_to_use_align = use_align;
4342 icon_view->priv->scroll_to_row_align = row_align;
4343 icon_view->priv->scroll_to_col_align = col_align;
4354 gtk_widget_style_get (GTK_WIDGET (icon_view),
4355 "focus-line-width", &focus_width,
4358 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4360 offset = y + item->y - focus_width -
4361 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4363 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4364 icon_view->priv->vadjustment->value + offset);
4366 offset = x + item->x - focus_width -
4367 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4369 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4370 icon_view->priv->hadjustment->value + offset);
4372 gtk_adjustment_changed (icon_view->priv->hadjustment);
4373 gtk_adjustment_changed (icon_view->priv->vadjustment);
4376 gtk_icon_view_scroll_to_item (icon_view, item);
4381 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4382 GtkIconViewItem *item)
4384 gint x, y, width, height;
4387 gtk_widget_style_get (GTK_WIDGET (icon_view),
4388 "focus-line-width", &focus_width,
4391 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4393 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4395 if (y + item->y - focus_width < 0)
4396 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4397 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4398 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4399 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4400 icon_view->priv->vadjustment->value + y + item->y + item->height
4401 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4403 if (x + item->x - focus_width < 0)
4404 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4405 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4406 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4407 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4408 icon_view->priv->hadjustment->value + x + item->x + item->width
4409 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4411 gtk_adjustment_changed (icon_view->priv->hadjustment);
4412 gtk_adjustment_changed (icon_view->priv->vadjustment);
4415 /* GtkCellLayout implementation */
4416 static GtkIconViewCellInfo *
4417 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4418 GtkCellRenderer *renderer)
4422 for (i = icon_view->priv->cell_list; i; i = i->next)
4424 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4426 if (info->cell == renderer)
4434 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4435 GtkIconViewItem *item)
4438 gboolean iters_persist;
4441 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4447 path = gtk_tree_path_new_from_indices (item->index, -1);
4448 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4450 gtk_tree_path_free (path);
4455 for (i = icon_view->priv->cell_list; i; i = i->next)
4458 GtkIconViewCellInfo *info = i->data;
4460 g_object_freeze_notify (G_OBJECT (info->cell));
4462 for (j = info->attributes; j && j->next; j = j->next->next)
4464 gchar *property = j->data;
4465 gint column = GPOINTER_TO_INT (j->next->data);
4466 GValue value = {0, };
4468 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4470 g_object_set_property (G_OBJECT (info->cell),
4472 g_value_unset (&value);
4476 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4478 icon_view->priv->model,
4482 g_object_thaw_notify (G_OBJECT (info->cell));
4487 free_cell_attributes (GtkIconViewCellInfo *info)
4491 list = info->attributes;
4492 while (list && list->next)
4494 g_free (list->data);
4495 list = list->next->next;
4498 g_slist_free (info->attributes);
4499 info->attributes = NULL;
4503 free_cell_info (GtkIconViewCellInfo *info)
4505 free_cell_attributes (info);
4507 g_object_unref (info->cell);
4510 (* info->destroy) (info->func_data);
4516 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4517 GtkCellRenderer *renderer,
4520 GtkIconViewCellInfo *info;
4521 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4523 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4524 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4526 g_object_ref_sink (renderer);
4528 info = g_new0 (GtkIconViewCellInfo, 1);
4529 info->cell = renderer;
4530 info->expand = expand ? TRUE : FALSE;
4531 info->pack = GTK_PACK_START;
4532 info->position = icon_view->priv->n_cells;
4534 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4535 icon_view->priv->n_cells++;
4539 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4540 GtkCellRenderer *renderer,
4543 GtkIconViewCellInfo *info;
4544 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4546 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4547 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4549 g_object_ref_sink (renderer);
4551 info = g_new0 (GtkIconViewCellInfo, 1);
4552 info->cell = renderer;
4553 info->expand = expand ? TRUE : FALSE;
4554 info->pack = GTK_PACK_END;
4555 info->position = icon_view->priv->n_cells;
4557 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4558 icon_view->priv->n_cells++;
4562 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4563 GtkCellRenderer *renderer,
4564 const gchar *attribute,
4567 GtkIconViewCellInfo *info;
4568 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4570 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4571 g_return_if_fail (info != NULL);
4573 info->attributes = g_slist_prepend (info->attributes,
4574 GINT_TO_POINTER (column));
4575 info->attributes = g_slist_prepend (info->attributes,
4576 g_strdup (attribute));
4580 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4582 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4584 while (icon_view->priv->cell_list)
4586 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4587 free_cell_info (info);
4588 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4589 icon_view->priv->cell_list);
4592 icon_view->priv->n_cells = 0;
4596 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4597 GtkCellRenderer *cell,
4598 GtkCellLayoutDataFunc func,
4600 GDestroyNotify destroy)
4602 GtkIconViewCellInfo *info;
4603 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4605 info = gtk_icon_view_get_cell_info (icon_view, cell);
4606 g_return_if_fail (info != NULL);
4610 GDestroyNotify d = info->destroy;
4612 info->destroy = NULL;
4613 d (info->func_data);
4617 info->func_data = func_data;
4618 info->destroy = destroy;
4622 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4623 GtkCellRenderer *renderer)
4625 GtkIconViewCellInfo *info;
4627 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4629 free_cell_attributes (info);
4633 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4634 GtkCellRenderer *cell,
4637 GtkIconView *icon_view;
4639 GtkIconViewCellInfo *info;
4642 icon_view = GTK_ICON_VIEW (layout);
4644 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4646 info = gtk_icon_view_get_cell_info (icon_view, cell);
4648 g_return_if_fail (info != NULL);
4649 g_return_if_fail (position >= 0);
4651 link = g_list_find (icon_view->priv->cell_list, info);
4653 g_return_if_fail (link != NULL);
4655 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4657 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4660 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4667 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4671 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4673 GtkIconView *icon_view = (GtkIconView *)layout;
4674 GList *retval = NULL, *l;
4676 for (l = icon_view->priv->cell_list; l; l = l->next)
4678 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4680 retval = g_list_prepend (retval, info->cell);
4683 return g_list_reverse (retval);
4690 * gtk_icon_view_new:
4692 * Creates a new #GtkIconView widget
4694 * Return value: A newly created #GtkIconView widget
4699 gtk_icon_view_new (void)
4701 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4705 * gtk_icon_view_new_with_model:
4706 * @model: The model.
4708 * Creates a new #GtkIconView widget with the model @model.
4710 * Return value: A newly created #GtkIconView widget.
4715 gtk_icon_view_new_with_model (GtkTreeModel *model)
4717 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4721 * gtk_icon_view_convert_widget_to_bin_window_coords:
4722 * @icon_view: a #GtkIconView
4723 * @wx: X coordinate relative to the widget
4724 * @wy: Y coordinate relative to the widget
4725 * @bx: return location for bin_window X coordinate
4726 * @by: return location for bin_window Y coordinate
4728 * Converts widget coordinates to coordinates for the bin_window,
4729 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4734 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4742 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4744 if (icon_view->priv->bin_window)
4745 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4756 * gtk_icon_view_get_path_at_pos:
4757 * @icon_view: A #GtkIconView.
4758 * @x: The x position to be identified
4759 * @y: The y position to be identified
4761 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4762 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4763 * the cell at the specified position.
4764 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4765 * widget coordinates to bin_window coordinates.
4767 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4768 * if no icon exists at that position.
4773 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4777 GtkIconViewItem *item;
4780 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4782 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4787 path = gtk_tree_path_new_from_indices (item->index, -1);
4793 * gtk_icon_view_get_item_at_pos:
4794 * @icon_view: A #GtkIconView.
4795 * @x: The x position to be identified
4796 * @y: The y position to be identified
4797 * @path: Return location for the path, or %NULL
4798 * @cell: Return location for the renderer responsible for the cell
4799 * at (@x, @y), or %NULL
4801 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4802 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4803 * obtains the cell at the specified position. The returned path should
4804 * be freed with gtk_tree_path_free().
4805 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4806 * widget coordinates to bin_window coordinates.
4808 * Return value: %TRUE if an item exists at the specified position
4813 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4817 GtkCellRenderer **cell)
4819 GtkIconViewItem *item;
4820 GtkIconViewCellInfo *info;
4822 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4824 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4829 *path = gtk_tree_path_new_from_indices (item->index, -1);
4842 return (item != NULL);
4846 * gtk_icon_view_set_tooltip_item:
4847 * @icon_view: a #GtkIconView
4848 * @tooltip: a #GtkTooltip
4849 * @path: a #GtkTreePath
4851 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4852 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4853 * See also gtk_tooltip_set_tip_area().
4858 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4859 GtkTooltip *tooltip,
4862 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4863 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4865 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4869 * gtk_icon_view_set_tooltip_cell:
4870 * @icon_view: a #GtkIconView
4871 * @tooltip: a #GtkTooltip
4872 * @path: a #GtkTreePath
4873 * @cell: a #GtkCellRenderer or %NULL
4875 * Sets the tip area of @tooltip to the area which @cell occupies in
4876 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4878 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4883 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4884 GtkTooltip *tooltip,
4886 GtkCellRenderer *cell)
4889 GtkIconViewItem *item = NULL;
4890 GtkIconViewCellInfo *info = NULL;
4893 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4894 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4895 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4897 if (gtk_tree_path_get_depth (path) > 0)
4898 item = g_list_nth_data (icon_view->priv->items,
4899 gtk_tree_path_get_indices(path)[0]);
4906 info = gtk_icon_view_get_cell_info (icon_view, cell);
4907 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4913 rect.width = item->width;
4914 rect.height = item->height;
4917 if (icon_view->priv->bin_window)
4919 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4924 gtk_tooltip_set_tip_area (tooltip, &rect);
4929 * gtk_icon_view_get_tooltip_context:
4930 * @icon_view: an #GtkIconView
4931 * @x: the x coordinate (relative to widget coordinates)
4932 * @y: the y coordinate (relative to widget coordinates)
4933 * @keyboard_tip: whether this is a keyboard tooltip or not
4934 * @model: a pointer to receive a #GtkTreeModel or %NULL
4935 * @path: a pointer to receive a #GtkTreePath or %NULL
4936 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4938 * This function is supposed to be used in a #GtkWidget::query-tooltip
4939 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4940 * which are received in the signal handler, should be passed to this
4941 * function without modification.
4943 * The return value indicates whether there is an icon view item at the given
4944 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4945 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4946 * @model, @path and @iter which have been provided will be set to point to
4947 * that row and the corresponding model. @x and @y will always be converted
4948 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4950 * Return value: whether or not the given tooltip context points to a item
4955 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4958 gboolean keyboard_tip,
4959 GtkTreeModel **model,
4963 GtkTreePath *tmppath = NULL;
4965 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4966 g_return_val_if_fail (x != NULL, FALSE);
4967 g_return_val_if_fail (y != NULL, FALSE);
4971 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4978 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4981 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4986 *model = gtk_icon_view_get_model (icon_view);
4989 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4995 gtk_tree_path_free (tmppath);
5001 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5004 gboolean keyboard_tip,
5005 GtkTooltip *tooltip,
5011 GtkTreeModel *model;
5012 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5014 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5017 &model, &path, &iter))
5020 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5024 gtk_tree_path_free (path);
5028 gtk_tooltip_set_markup (tooltip, str);
5029 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5031 gtk_tree_path_free (path);
5039 * gtk_icon_view_set_tooltip_column:
5040 * @icon_view: a #GtkIconView
5041 * @column: an integer, which is a valid column number for @icon_view's model
5043 * If you only plan to have simple (text-only) tooltips on full items, you
5044 * can use this function to have #GtkIconView handle these automatically
5045 * for you. @column should be set to the column in @icon_view's model
5046 * containing the tooltip texts, or -1 to disable this feature.
5048 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5049 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5054 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5057 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5059 if (column == icon_view->priv->tooltip_column)
5064 g_signal_handlers_disconnect_by_func (icon_view,
5065 gtk_icon_view_set_tooltip_query_cb,
5067 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5071 if (icon_view->priv->tooltip_column == -1)
5073 g_signal_connect (icon_view, "query-tooltip",
5074 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5075 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5079 icon_view->priv->tooltip_column = column;
5080 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5084 * gtk_icon_view_get_tooltip_column:
5085 * @icon_view: a #GtkIconView
5087 * Returns the column of @icon_view's model which is being used for
5088 * displaying tooltips on @icon_view's rows.
5090 * Return value: the index of the tooltip column that is currently being
5091 * used, or -1 if this is disabled.
5096 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5098 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5100 return icon_view->priv->tooltip_column;
5104 * gtk_icon_view_get_visible_range:
5105 * @icon_view: A #GtkIconView
5106 * @start_path: Return location for start of region, or %NULL
5107 * @end_path: Return location for end of region, or %NULL
5109 * Sets @start_path and @end_path to be the first and last visible path.
5110 * Note that there may be invisible paths in between.
5112 * Both paths should be freed with gtk_tree_path_free() after use.
5114 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5119 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5120 GtkTreePath **start_path,
5121 GtkTreePath **end_path)
5123 gint start_index = -1;
5124 gint end_index = -1;
5127 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5129 if (icon_view->priv->hadjustment == NULL ||
5130 icon_view->priv->vadjustment == NULL)
5133 if (start_path == NULL && end_path == NULL)
5136 for (icons = icon_view->priv->items; icons; icons = icons->next)
5138 GtkIconViewItem *item = icons->data;
5140 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5141 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5142 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5143 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5145 if (start_index == -1)
5146 start_index = item->index;
5147 end_index = item->index;
5151 if (start_path && start_index != -1)
5152 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5153 if (end_path && end_index != -1)
5154 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5156 return start_index != -1;
5160 * gtk_icon_view_selected_foreach:
5161 * @icon_view: A #GtkIconView.
5162 * @func: The funcion to call for each selected icon.
5163 * @data: User data to pass to the function.
5165 * Calls a function for each selected icon. Note that the model or
5166 * selection cannot be modified from within this function.
5171 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5172 GtkIconViewForeachFunc func,
5177 for (list = icon_view->priv->items; list; list = list->next)
5179 GtkIconViewItem *item = list->data;
5180 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5183 (* func) (icon_view, path, data);
5185 gtk_tree_path_free (path);
5190 * gtk_icon_view_set_selection_mode:
5191 * @icon_view: A #GtkIconView.
5192 * @mode: The selection mode
5194 * Sets the selection mode of the @icon_view.
5199 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5200 GtkSelectionMode mode)
5202 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5204 if (mode == icon_view->priv->selection_mode)
5207 if (mode == GTK_SELECTION_NONE ||
5208 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5209 gtk_icon_view_unselect_all (icon_view);
5211 icon_view->priv->selection_mode = mode;
5213 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5217 * gtk_icon_view_get_selection_mode:
5218 * @icon_view: A #GtkIconView.
5220 * Gets the selection mode of the @icon_view.
5222 * Return value: the current selection mode
5227 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5229 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5231 return icon_view->priv->selection_mode;
5235 * gtk_icon_view_set_model:
5236 * @icon_view: A #GtkIconView.
5237 * @model: The model.
5239 * Sets the model for a #GtkIconView.
5240 * If the @icon_view already has a model set, it will remove
5241 * it before setting the new model. If @model is %NULL, then
5242 * it will unset the old model.
5247 gtk_icon_view_set_model (GtkIconView *icon_view,
5248 GtkTreeModel *model)
5250 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5251 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5253 if (icon_view->priv->model == model)
5256 if (icon_view->priv->scroll_to_path)
5258 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5259 icon_view->priv->scroll_to_path = NULL;
5262 gtk_icon_view_stop_editing (icon_view, TRUE);
5268 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5270 if (icon_view->priv->pixbuf_column != -1)
5272 column_type = gtk_tree_model_get_column_type (model,
5273 icon_view->priv->pixbuf_column);
5275 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5278 if (icon_view->priv->text_column != -1)
5280 column_type = gtk_tree_model_get_column_type (model,
5281 icon_view->priv->text_column);
5283 g_return_if_fail (column_type == G_TYPE_STRING);
5286 if (icon_view->priv->markup_column != -1)
5288 column_type = gtk_tree_model_get_column_type (model,
5289 icon_view->priv->markup_column);
5291 g_return_if_fail (column_type == G_TYPE_STRING);
5296 if (icon_view->priv->model)
5298 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5299 gtk_icon_view_row_changed,
5301 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5302 gtk_icon_view_row_inserted,
5304 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5305 gtk_icon_view_row_deleted,
5307 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5308 gtk_icon_view_rows_reordered,
5311 g_object_unref (icon_view->priv->model);
5313 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5314 g_list_free (icon_view->priv->items);
5315 icon_view->priv->items = NULL;
5316 icon_view->priv->anchor_item = NULL;
5317 icon_view->priv->cursor_item = NULL;
5318 icon_view->priv->last_single_clicked = NULL;
5319 icon_view->priv->width = 0;
5320 icon_view->priv->height = 0;
5323 icon_view->priv->model = model;
5325 if (icon_view->priv->model)
5327 g_object_ref (icon_view->priv->model);
5328 g_signal_connect (icon_view->priv->model,
5330 G_CALLBACK (gtk_icon_view_row_changed),
5332 g_signal_connect (icon_view->priv->model,
5334 G_CALLBACK (gtk_icon_view_row_inserted),
5336 g_signal_connect (icon_view->priv->model,
5338 G_CALLBACK (gtk_icon_view_row_deleted),
5340 g_signal_connect (icon_view->priv->model,
5342 G_CALLBACK (gtk_icon_view_rows_reordered),
5345 gtk_icon_view_build_items (icon_view);
5347 gtk_icon_view_queue_layout (icon_view);
5350 g_object_notify (G_OBJECT (icon_view), "model");
5352 if (GTK_WIDGET_REALIZED (icon_view))
5353 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5357 * gtk_icon_view_get_model:
5358 * @icon_view: a #GtkIconView
5360 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5363 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5368 gtk_icon_view_get_model (GtkIconView *icon_view)
5370 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5372 return icon_view->priv->model;
5376 update_text_cell (GtkIconView *icon_view)
5378 GtkIconViewCellInfo *info;
5382 if (icon_view->priv->text_column == -1 &&
5383 icon_view->priv->markup_column == -1)
5385 if (icon_view->priv->text_cell != -1)
5387 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5388 icon_view->priv->pixbuf_cell--;
5390 info = g_list_nth_data (icon_view->priv->cell_list,
5391 icon_view->priv->text_cell);
5393 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5395 free_cell_info (info);
5397 icon_view->priv->n_cells--;
5398 icon_view->priv->text_cell = -1;
5403 if (icon_view->priv->text_cell == -1)
5405 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5406 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5407 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5410 if (info->cell == cell)
5412 icon_view->priv->text_cell = i;
5418 info = g_list_nth_data (icon_view->priv->cell_list,
5419 icon_view->priv->text_cell);
5421 if (icon_view->priv->markup_column != -1)
5422 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5424 "markup", icon_view->priv->markup_column,
5427 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5429 "text", icon_view->priv->text_column,
5432 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5433 g_object_set (info->cell,
5434 "alignment", PANGO_ALIGN_CENTER,
5435 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5440 g_object_set (info->cell,
5441 "alignment", PANGO_ALIGN_LEFT,
5442 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5450 update_pixbuf_cell (GtkIconView *icon_view)
5452 GtkIconViewCellInfo *info;
5456 if (icon_view->priv->pixbuf_column == -1)
5458 if (icon_view->priv->pixbuf_cell != -1)
5460 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5461 icon_view->priv->text_cell--;
5463 info = g_list_nth_data (icon_view->priv->cell_list,
5464 icon_view->priv->pixbuf_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->pixbuf_cell = -1;
5476 if (icon_view->priv->pixbuf_cell == -1)
5478 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5480 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5481 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5484 if (info->cell == cell)
5486 icon_view->priv->pixbuf_cell = i;
5492 info = g_list_nth_data (icon_view->priv->cell_list,
5493 icon_view->priv->pixbuf_cell);
5495 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5497 "pixbuf", icon_view->priv->pixbuf_column,
5500 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5501 g_object_set (info->cell,
5506 g_object_set (info->cell,
5514 * gtk_icon_view_set_text_column:
5515 * @icon_view: A #GtkIconView.
5516 * @column: A column in the currently used model, or -1 to display no text
5518 * Sets the column with text for @icon_view to be @column. The text
5519 * column must be of type #G_TYPE_STRING.
5524 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5527 if (column == icon_view->priv->text_column)
5531 icon_view->priv->text_column = -1;
5534 if (icon_view->priv->model != NULL)
5538 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5540 g_return_if_fail (column_type == G_TYPE_STRING);
5543 icon_view->priv->text_column = column;
5546 gtk_icon_view_stop_editing (icon_view, TRUE);
5548 update_text_cell (icon_view);
5550 gtk_icon_view_invalidate_sizes (icon_view);
5551 gtk_icon_view_queue_layout (icon_view);
5553 g_object_notify (G_OBJECT (icon_view), "text-column");
5557 * gtk_icon_view_get_text_column:
5558 * @icon_view: A #GtkIconView.
5560 * Returns the column with text for @icon_view.
5562 * Returns: the text column, or -1 if it's unset.
5567 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5569 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5571 return icon_view->priv->text_column;
5575 * gtk_icon_view_set_markup_column:
5576 * @icon_view: A #GtkIconView.
5577 * @column: A column in the currently used model, or -1 to display no text
5579 * Sets the column with markup information for @icon_view to be
5580 * @column. The markup column must be of type #G_TYPE_STRING.
5581 * If the markup column is set to something, it overrides
5582 * the text column set by gtk_icon_view_set_text_column().
5587 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5590 if (column == icon_view->priv->markup_column)
5594 icon_view->priv->markup_column = -1;
5597 if (icon_view->priv->model != NULL)
5601 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5603 g_return_if_fail (column_type == G_TYPE_STRING);
5606 icon_view->priv->markup_column = column;
5609 gtk_icon_view_stop_editing (icon_view, TRUE);
5611 update_text_cell (icon_view);
5613 gtk_icon_view_invalidate_sizes (icon_view);
5614 gtk_icon_view_queue_layout (icon_view);
5616 g_object_notify (G_OBJECT (icon_view), "markup-column");
5620 * gtk_icon_view_get_markup_column:
5621 * @icon_view: A #GtkIconView.
5623 * Returns the column with markup text for @icon_view.
5625 * Returns: the markup column, or -1 if it's unset.
5630 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5632 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5634 return icon_view->priv->markup_column;
5638 * gtk_icon_view_set_pixbuf_column:
5639 * @icon_view: A #GtkIconView.
5640 * @column: A column in the currently used model, or -1 to disable
5642 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5643 * column must be of type #GDK_TYPE_PIXBUF
5648 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5651 if (column == icon_view->priv->pixbuf_column)
5655 icon_view->priv->pixbuf_column = -1;
5658 if (icon_view->priv->model != NULL)
5662 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5664 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5667 icon_view->priv->pixbuf_column = column;
5670 gtk_icon_view_stop_editing (icon_view, TRUE);
5672 update_pixbuf_cell (icon_view);
5674 gtk_icon_view_invalidate_sizes (icon_view);
5675 gtk_icon_view_queue_layout (icon_view);
5677 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5682 * gtk_icon_view_get_pixbuf_column:
5683 * @icon_view: A #GtkIconView.
5685 * Returns the column with pixbufs for @icon_view.
5687 * Returns: the pixbuf column, or -1 if it's unset.
5692 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5694 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5696 return icon_view->priv->pixbuf_column;
5700 * gtk_icon_view_select_path:
5701 * @icon_view: A #GtkIconView.
5702 * @path: The #GtkTreePath to be selected.
5704 * Selects the row at @path.
5709 gtk_icon_view_select_path (GtkIconView *icon_view,
5712 GtkIconViewItem *item = NULL;
5714 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5715 g_return_if_fail (icon_view->priv->model != NULL);
5716 g_return_if_fail (path != NULL);
5718 if (gtk_tree_path_get_depth (path) > 0)
5719 item = g_list_nth_data (icon_view->priv->items,
5720 gtk_tree_path_get_indices(path)[0]);
5723 gtk_icon_view_select_item (icon_view, item);
5727 * gtk_icon_view_unselect_path:
5728 * @icon_view: A #GtkIconView.
5729 * @path: The #GtkTreePath to be unselected.
5731 * Unselects the row at @path.
5736 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5739 GtkIconViewItem *item;
5741 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5742 g_return_if_fail (icon_view->priv->model != NULL);
5743 g_return_if_fail (path != NULL);
5745 item = g_list_nth_data (icon_view->priv->items,
5746 gtk_tree_path_get_indices(path)[0]);
5751 gtk_icon_view_unselect_item (icon_view, item);
5755 * gtk_icon_view_get_selected_items:
5756 * @icon_view: A #GtkIconView.
5758 * Creates a list of paths of all selected items. Additionally, if you are
5759 * planning on modifying the model after calling this function, you may
5760 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5761 * To do this, you can use gtk_tree_row_reference_new().
5763 * To free the return value, use:
5765 * g_list_foreach (list, gtk_tree_path_free, NULL);
5766 * g_list_free (list);
5769 * Return value: A #GList containing a #GtkTreePath for each selected row.
5774 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5777 GList *selected = NULL;
5779 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5781 for (list = icon_view->priv->items; list != NULL; list = list->next)
5783 GtkIconViewItem *item = list->data;
5787 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5789 selected = g_list_prepend (selected, path);
5797 * gtk_icon_view_select_all:
5798 * @icon_view: A #GtkIconView.
5800 * Selects all the icons. @icon_view must has its selection mode set
5801 * to #GTK_SELECTION_MULTIPLE.
5806 gtk_icon_view_select_all (GtkIconView *icon_view)
5809 gboolean dirty = FALSE;
5811 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5813 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5816 for (items = icon_view->priv->items; items; items = items->next)
5818 GtkIconViewItem *item = items->data;
5820 if (!item->selected)
5823 item->selected = TRUE;
5824 gtk_icon_view_queue_draw_item (icon_view, item);
5829 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5833 * gtk_icon_view_unselect_all:
5834 * @icon_view: A #GtkIconView.
5836 * Unselects all the icons.
5841 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5843 gboolean dirty = FALSE;
5845 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5847 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5850 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5853 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5857 * gtk_icon_view_path_is_selected:
5858 * @icon_view: A #GtkIconView.
5859 * @path: A #GtkTreePath to check selection on.
5861 * Returns %TRUE if the icon pointed to by @path is currently
5862 * selected. If @path does not point to a valid location, %FALSE is returned.
5864 * Return value: %TRUE if @path is selected.
5869 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5872 GtkIconViewItem *item;
5874 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5875 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5876 g_return_val_if_fail (path != NULL, FALSE);
5878 item = g_list_nth_data (icon_view->priv->items,
5879 gtk_tree_path_get_indices(path)[0]);
5884 return item->selected;
5888 * gtk_icon_view_item_activated:
5889 * @icon_view: A #GtkIconView
5890 * @path: The #GtkTreePath to be activated
5892 * Activates the item determined by @path.
5897 gtk_icon_view_item_activated (GtkIconView *icon_view,
5900 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5901 g_return_if_fail (path != NULL);
5903 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5907 * gtk_icon_view_set_orientation:
5908 * @icon_view: a #GtkIconView
5909 * @orientation: the relative position of texts and icons
5911 * Sets the ::orientation property which determines whether the labels
5912 * are drawn beside the icons instead of below.
5917 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5918 GtkOrientation orientation)
5920 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5922 if (icon_view->priv->orientation != orientation)
5924 icon_view->priv->orientation = orientation;
5926 gtk_icon_view_stop_editing (icon_view, TRUE);
5927 gtk_icon_view_invalidate_sizes (icon_view);
5928 gtk_icon_view_queue_layout (icon_view);
5930 update_text_cell (icon_view);
5931 update_pixbuf_cell (icon_view);
5933 g_object_notify (G_OBJECT (icon_view), "orientation");
5938 * gtk_icon_view_get_orientation:
5939 * @icon_view: a #GtkIconView
5941 * Returns the value of the ::orientation property which determines
5942 * whether the labels are drawn beside the icons instead of below.
5944 * Return value: the relative position of texts and icons
5949 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5951 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5952 GTK_ORIENTATION_VERTICAL);
5954 return icon_view->priv->orientation;
5958 * gtk_icon_view_set_columns:
5959 * @icon_view: a #GtkIconView
5960 * @columns: the number of columns
5962 * Sets the ::columns property which determines in how
5963 * many columns the icons are arranged. If @columns is
5964 * -1, the number of columns will be chosen automatically
5965 * to fill the available area.
5970 gtk_icon_view_set_columns (GtkIconView *icon_view,
5973 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5975 if (icon_view->priv->columns != columns)
5977 icon_view->priv->columns = columns;
5979 gtk_icon_view_stop_editing (icon_view, TRUE);
5980 gtk_icon_view_queue_layout (icon_view);
5982 g_object_notify (G_OBJECT (icon_view), "columns");
5987 * gtk_icon_view_get_columns:
5988 * @icon_view: a #GtkIconView
5990 * Returns the value of the ::columns property.
5992 * Return value: the number of columns, or -1
5997 gtk_icon_view_get_columns (GtkIconView *icon_view)
5999 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6001 return icon_view->priv->columns;
6005 * gtk_icon_view_set_item_width:
6006 * @icon_view: a #GtkIconView
6007 * @item_width: the width for each item
6009 * Sets the ::item-width property which specifies the width
6010 * to use for each item. If it is set to -1, the icon view will
6011 * automatically determine a suitable item size.
6016 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6019 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6021 if (icon_view->priv->item_width != item_width)
6023 icon_view->priv->item_width = item_width;
6025 gtk_icon_view_stop_editing (icon_view, TRUE);
6026 gtk_icon_view_invalidate_sizes (icon_view);
6027 gtk_icon_view_queue_layout (icon_view);
6029 update_text_cell (icon_view);
6031 g_object_notify (G_OBJECT (icon_view), "item-width");
6036 * gtk_icon_view_get_item_width:
6037 * @icon_view: a #GtkIconView
6039 * Returns the value of the ::item-width property.
6041 * Return value: the width of a single item, or -1
6046 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6048 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6050 return icon_view->priv->item_width;
6055 * gtk_icon_view_set_spacing:
6056 * @icon_view: a #GtkIconView
6057 * @spacing: the spacing
6059 * Sets the ::spacing property which specifies the space
6060 * which is inserted between the cells (i.e. the icon and
6061 * the text) of an item.
6066 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6069 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6071 if (icon_view->priv->spacing != spacing)
6073 icon_view->priv->spacing = spacing;
6075 gtk_icon_view_stop_editing (icon_view, TRUE);
6076 gtk_icon_view_invalidate_sizes (icon_view);
6077 gtk_icon_view_queue_layout (icon_view);
6079 g_object_notify (G_OBJECT (icon_view), "spacing");
6084 * gtk_icon_view_get_spacing:
6085 * @icon_view: a #GtkIconView
6087 * Returns the value of the ::spacing property.
6089 * Return value: the space between cells
6094 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6096 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6098 return icon_view->priv->spacing;
6102 * gtk_icon_view_set_row_spacing:
6103 * @icon_view: a #GtkIconView
6104 * @row_spacing: the row spacing
6106 * Sets the ::row-spacing property which specifies the space
6107 * which is inserted between the rows of the icon view.
6112 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6115 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6117 if (icon_view->priv->row_spacing != row_spacing)
6119 icon_view->priv->row_spacing = row_spacing;
6121 gtk_icon_view_stop_editing (icon_view, TRUE);
6122 gtk_icon_view_invalidate_sizes (icon_view);
6123 gtk_icon_view_queue_layout (icon_view);
6125 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6130 * gtk_icon_view_get_row_spacing:
6131 * @icon_view: a #GtkIconView
6133 * Returns the value of the ::row-spacing property.
6135 * Return value: the space between rows
6140 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6142 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6144 return icon_view->priv->row_spacing;
6148 * gtk_icon_view_set_column_spacing:
6149 * @icon_view: a #GtkIconView
6150 * @column_spacing: the column spacing
6152 * Sets the ::column-spacing property which specifies the space
6153 * which is inserted between the columns of the icon view.
6158 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6159 gint column_spacing)
6161 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6163 if (icon_view->priv->column_spacing != column_spacing)
6165 icon_view->priv->column_spacing = column_spacing;
6167 gtk_icon_view_stop_editing (icon_view, TRUE);
6168 gtk_icon_view_invalidate_sizes (icon_view);
6169 gtk_icon_view_queue_layout (icon_view);
6171 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6176 * gtk_icon_view_get_column_spacing:
6177 * @icon_view: a #GtkIconView
6179 * Returns the value of the ::column-spacing property.
6181 * Return value: the space between columns
6186 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6188 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6190 return icon_view->priv->column_spacing;
6194 * gtk_icon_view_set_margin:
6195 * @icon_view: a #GtkIconView
6196 * @margin: the margin
6198 * Sets the ::margin property which specifies the space
6199 * which is inserted at the top, bottom, left and right
6205 gtk_icon_view_set_margin (GtkIconView *icon_view,
6208 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6210 if (icon_view->priv->margin != margin)
6212 icon_view->priv->margin = margin;
6214 gtk_icon_view_stop_editing (icon_view, TRUE);
6215 gtk_icon_view_invalidate_sizes (icon_view);
6216 gtk_icon_view_queue_layout (icon_view);
6218 g_object_notify (G_OBJECT (icon_view), "margin");
6223 * gtk_icon_view_get_margin:
6224 * @icon_view: a #GtkIconView
6226 * Returns the value of the ::margin property.
6228 * Return value: the space at the borders
6233 gtk_icon_view_get_margin (GtkIconView *icon_view)
6235 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6237 return icon_view->priv->margin;
6241 /* Get/set whether drag_motion requested the drag data and
6242 * drag_data_received should thus not actually insert the data,
6243 * since the data doesn't result from a drop.
6246 set_status_pending (GdkDragContext *context,
6247 GdkDragAction suggested_action)
6249 g_object_set_data (G_OBJECT (context),
6250 I_("gtk-icon-view-status-pending"),
6251 GINT_TO_POINTER (suggested_action));
6254 static GdkDragAction
6255 get_status_pending (GdkDragContext *context)
6257 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6258 "gtk-icon-view-status-pending"));
6262 unset_reorderable (GtkIconView *icon_view)
6264 if (icon_view->priv->reorderable)
6266 icon_view->priv->reorderable = FALSE;
6267 g_object_notify (G_OBJECT (icon_view), "reorderable");
6272 set_source_row (GdkDragContext *context,
6273 GtkTreeModel *model,
6274 GtkTreePath *source_row)
6277 g_object_set_data_full (G_OBJECT (context),
6278 I_("gtk-icon-view-source-row"),
6279 gtk_tree_row_reference_new (model, source_row),
6280 (GDestroyNotify) gtk_tree_row_reference_free);
6282 g_object_set_data_full (G_OBJECT (context),
6283 I_("gtk-icon-view-source-row"),
6288 get_source_row (GdkDragContext *context)
6290 GtkTreeRowReference *ref;
6292 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6295 return gtk_tree_row_reference_get_path (ref);
6302 GtkTreeRowReference *dest_row;
6303 gboolean empty_view_drop;
6304 gboolean drop_append_mode;
6308 dest_row_free (gpointer data)
6310 DestRow *dr = (DestRow *)data;
6312 gtk_tree_row_reference_free (dr->dest_row);
6317 set_dest_row (GdkDragContext *context,
6318 GtkTreeModel *model,
6319 GtkTreePath *dest_row,
6320 gboolean empty_view_drop,
6321 gboolean drop_append_mode)
6327 g_object_set_data_full (G_OBJECT (context),
6328 I_("gtk-icon-view-dest-row"),
6333 dr = g_new0 (DestRow, 1);
6335 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6336 dr->empty_view_drop = empty_view_drop;
6337 dr->drop_append_mode = drop_append_mode;
6338 g_object_set_data_full (G_OBJECT (context),
6339 I_("gtk-icon-view-dest-row"),
6340 dr, (GDestroyNotify) dest_row_free);
6344 get_dest_row (GdkDragContext *context)
6348 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6352 GtkTreePath *path = NULL;
6355 path = gtk_tree_row_reference_get_path (dr->dest_row);
6356 else if (dr->empty_view_drop)
6357 path = gtk_tree_path_new_from_indices (0, -1);
6361 if (path && dr->drop_append_mode)
6362 gtk_tree_path_next (path);
6371 check_model_dnd (GtkTreeModel *model,
6372 GType required_iface,
6373 const gchar *signal)
6375 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6377 g_warning ("You must override the default '%s' handler "
6378 "on GtkIconView when using models that don't support "
6379 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6380 "is to connect to '%s' and call "
6381 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6382 "the default handler from running. Look at the source code "
6383 "for the default handler in gtkiconview.c to get an idea what "
6384 "your handler should do. (gtkiconview.c is in the GTK+ source "
6385 "code.) If you're using GTK+ from a language other than C, "
6386 "there may be a more natural way to override default handlers, e.g. via derivation.",
6387 signal, g_type_name (required_iface), signal);
6395 remove_scroll_timeout (GtkIconView *icon_view)
6397 if (icon_view->priv->scroll_timeout_id != 0)
6399 g_source_remove (icon_view->priv->scroll_timeout_id);
6401 icon_view->priv->scroll_timeout_id = 0;
6406 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6408 gint px, py, x, y, width, height;
6409 gint hoffset, voffset;
6411 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6412 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6414 /* see if we are near the edge. */
6415 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6417 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6419 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6421 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6424 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6425 icon_view->priv->vadjustment->value + voffset);
6428 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6429 icon_view->priv->hadjustment->value + hoffset);
6434 drag_scroll_timeout (gpointer data)
6436 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6438 gtk_icon_view_autoscroll (icon_view);
6445 set_destination (GtkIconView *icon_view,
6446 GdkDragContext *context,
6449 GdkDragAction *suggested_action,
6453 GtkTreePath *path = NULL;
6454 GtkIconViewDropPosition pos;
6455 GtkIconViewDropPosition old_pos;
6456 GtkTreePath *old_dest_path = NULL;
6457 gboolean can_drop = FALSE;
6459 widget = GTK_WIDGET (icon_view);
6461 *suggested_action = 0;
6464 if (!icon_view->priv->dest_set)
6466 /* someone unset us as a drag dest, note that if
6467 * we return FALSE drag_leave isn't called
6470 gtk_icon_view_set_drag_dest_item (icon_view,
6472 GTK_ICON_VIEW_DROP_LEFT);
6474 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6476 return FALSE; /* no longer a drop site */
6479 *target = gtk_drag_dest_find_target (widget, context,
6480 gtk_drag_dest_get_target_list (widget));
6481 if (*target == GDK_NONE)
6484 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6487 GtkTreeModel *model;
6489 /* the row got dropped on empty space, let's setup a special case
6493 gtk_tree_path_free (path);
6495 model = gtk_icon_view_get_model (icon_view);
6497 n_children = gtk_tree_model_iter_n_children (model, NULL);
6500 pos = GTK_ICON_VIEW_DROP_BELOW;
6501 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6505 pos = GTK_ICON_VIEW_DROP_ABOVE;
6506 path = gtk_tree_path_new_from_indices (0, -1);
6516 gtk_icon_view_get_drag_dest_item (icon_view,
6521 gtk_tree_path_free (old_dest_path);
6523 if (TRUE /* FIXME if the location droppable predicate */)
6531 GtkWidget *source_widget;
6533 *suggested_action = context->suggested_action;
6534 source_widget = gtk_drag_get_source_widget (context);
6536 if (source_widget == widget)
6538 /* Default to MOVE, unless the user has
6539 * pressed ctrl or shift to affect available actions
6541 if ((context->actions & GDK_ACTION_MOVE) != 0)
6542 *suggested_action = GDK_ACTION_MOVE;
6545 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6550 /* can't drop here */
6551 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6553 GTK_ICON_VIEW_DROP_LEFT);
6557 gtk_tree_path_free (path);
6563 get_logical_destination (GtkIconView *icon_view,
6564 gboolean *drop_append_mode)
6566 /* adjust path to point to the row the drop goes in front of */
6567 GtkTreePath *path = NULL;
6568 GtkIconViewDropPosition pos;
6570 *drop_append_mode = FALSE;
6572 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6577 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6578 pos == GTK_ICON_VIEW_DROP_BELOW)
6581 GtkTreeModel *model = icon_view->priv->model;
6583 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6584 !gtk_tree_model_iter_next (model, &iter))
6585 *drop_append_mode = TRUE;
6588 *drop_append_mode = FALSE;
6589 gtk_tree_path_next (path);
6597 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6598 GdkEventMotion *event)
6600 GtkWidget *widget = GTK_WIDGET (icon_view);
6601 GdkDragContext *context;
6602 GtkTreePath *path = NULL;
6604 GtkTreeModel *model;
6605 gboolean retval = FALSE;
6607 if (!icon_view->priv->source_set)
6610 if (icon_view->priv->pressed_button < 0)
6613 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6614 icon_view->priv->press_start_x,
6615 icon_view->priv->press_start_y,
6616 event->x, event->y))
6619 model = gtk_icon_view_get_model (icon_view);
6624 button = icon_view->priv->pressed_button;
6625 icon_view->priv->pressed_button = -1;
6627 path = gtk_icon_view_get_path_at_pos (icon_view,
6628 icon_view->priv->press_start_x,
6629 icon_view->priv->press_start_y);
6634 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6635 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6639 /* FIXME Check whether we're a start button, if not return FALSE and
6643 /* Now we can begin the drag */
6647 context = gtk_drag_begin (widget,
6648 gtk_drag_source_get_target_list (widget),
6649 icon_view->priv->source_actions,
6653 set_source_row (context, model, path);
6657 gtk_tree_path_free (path);
6662 /* Source side drag signals */
6664 gtk_icon_view_drag_begin (GtkWidget *widget,
6665 GdkDragContext *context)
6667 GtkIconView *icon_view;
6668 GtkIconViewItem *item;
6673 icon_view = GTK_ICON_VIEW (widget);
6675 /* if the user uses a custom DnD impl, we don't set the icon here */
6676 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6679 item = gtk_icon_view_get_item_at_coords (icon_view,
6680 icon_view->priv->press_start_x,
6681 icon_view->priv->press_start_y,
6685 g_return_if_fail (item != NULL);
6687 x = icon_view->priv->press_start_x - item->x + 1;
6688 y = icon_view->priv->press_start_y - item->y + 1;
6690 path = gtk_tree_path_new_from_indices (item->index, -1);
6691 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6692 gtk_tree_path_free (path);
6694 gtk_drag_set_icon_pixmap (context,
6695 gdk_drawable_get_colormap (icon),
6700 g_object_unref (icon);
6704 gtk_icon_view_drag_end (GtkWidget *widget,
6705 GdkDragContext *context)
6711 gtk_icon_view_drag_data_get (GtkWidget *widget,
6712 GdkDragContext *context,
6713 GtkSelectionData *selection_data,
6717 GtkIconView *icon_view;
6718 GtkTreeModel *model;
6719 GtkTreePath *source_row;
6721 icon_view = GTK_ICON_VIEW (widget);
6722 model = gtk_icon_view_get_model (icon_view);
6727 if (!icon_view->priv->source_set)
6730 source_row = get_source_row (context);
6732 if (source_row == NULL)
6735 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6736 * any model; for DragSource models there are some other targets
6740 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6741 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6746 /* If drag_data_get does nothing, try providing row data. */
6747 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6748 gtk_tree_set_row_drag_data (selection_data,
6753 gtk_tree_path_free (source_row);
6757 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6758 GdkDragContext *context)
6760 GtkTreeModel *model;
6761 GtkIconView *icon_view;
6762 GtkTreePath *source_row;
6764 icon_view = GTK_ICON_VIEW (widget);
6765 model = gtk_icon_view_get_model (icon_view);
6767 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6770 if (!icon_view->priv->source_set)
6773 source_row = get_source_row (context);
6775 if (source_row == NULL)
6778 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6781 gtk_tree_path_free (source_row);
6783 set_source_row (context, NULL, NULL);
6786 /* Target side drag signals */
6788 gtk_icon_view_drag_leave (GtkWidget *widget,
6789 GdkDragContext *context,
6792 GtkIconView *icon_view;
6794 icon_view = GTK_ICON_VIEW (widget);
6796 /* unset any highlight row */
6797 gtk_icon_view_set_drag_dest_item (icon_view,
6799 GTK_ICON_VIEW_DROP_LEFT);
6801 remove_scroll_timeout (icon_view);
6805 gtk_icon_view_drag_motion (GtkWidget *widget,
6806 GdkDragContext *context,
6811 GtkTreePath *path = NULL;
6812 GtkIconViewDropPosition pos;
6813 GtkIconView *icon_view;
6814 GdkDragAction suggested_action = 0;
6818 icon_view = GTK_ICON_VIEW (widget);
6820 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6823 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6825 /* we only know this *after* set_desination_row */
6826 empty = icon_view->priv->empty_view_drop;
6828 if (path == NULL && !empty)
6830 /* Can't drop here. */
6831 gdk_drag_status (context, 0, time);
6835 if (icon_view->priv->scroll_timeout_id == 0)
6837 icon_view->priv->scroll_timeout_id =
6838 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6841 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6843 /* Request data so we can use the source row when
6844 * determining whether to accept the drop
6846 set_status_pending (context, suggested_action);
6847 gtk_drag_get_data (widget, context, target, time);
6851 set_status_pending (context, 0);
6852 gdk_drag_status (context, suggested_action, time);
6857 gtk_tree_path_free (path);
6863 gtk_icon_view_drag_drop (GtkWidget *widget,
6864 GdkDragContext *context,
6869 GtkIconView *icon_view;
6871 GdkDragAction suggested_action = 0;
6872 GdkAtom target = GDK_NONE;
6873 GtkTreeModel *model;
6874 gboolean drop_append_mode;
6876 icon_view = GTK_ICON_VIEW (widget);
6877 model = gtk_icon_view_get_model (icon_view);
6879 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6881 if (!icon_view->priv->dest_set)
6884 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6887 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6890 path = get_logical_destination (icon_view, &drop_append_mode);
6892 if (target != GDK_NONE && path != NULL)
6894 /* in case a motion had requested drag data, change things so we
6895 * treat drag data receives as a drop.
6897 set_status_pending (context, 0);
6898 set_dest_row (context, model, path,
6899 icon_view->priv->empty_view_drop, drop_append_mode);
6903 gtk_tree_path_free (path);
6905 /* Unset this thing */
6906 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6908 if (target != GDK_NONE)
6910 gtk_drag_get_data (widget, context, target, time);
6918 gtk_icon_view_drag_data_received (GtkWidget *widget,
6919 GdkDragContext *context,
6922 GtkSelectionData *selection_data,
6927 gboolean accepted = FALSE;
6928 GtkTreeModel *model;
6929 GtkIconView *icon_view;
6930 GtkTreePath *dest_row;
6931 GdkDragAction suggested_action;
6932 gboolean drop_append_mode;
6934 icon_view = GTK_ICON_VIEW (widget);
6935 model = gtk_icon_view_get_model (icon_view);
6937 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6940 if (!icon_view->priv->dest_set)
6943 suggested_action = get_status_pending (context);
6945 if (suggested_action)
6947 /* We are getting this data due to a request in drag_motion,
6948 * rather than due to a request in drag_drop, so we are just
6949 * supposed to call drag_status, not actually paste in the
6952 path = get_logical_destination (icon_view, &drop_append_mode);
6955 suggested_action = 0;
6957 if (suggested_action)
6959 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6962 suggested_action = 0;
6965 gdk_drag_status (context, suggested_action, time);
6968 gtk_tree_path_free (path);
6970 /* If you can't drop, remove user drop indicator until the next motion */
6971 if (suggested_action == 0)
6972 gtk_icon_view_set_drag_dest_item (icon_view,
6974 GTK_ICON_VIEW_DROP_LEFT);
6979 dest_row = get_dest_row (context);
6981 if (dest_row == NULL)
6984 if (selection_data->length >= 0)
6986 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6992 gtk_drag_finish (context,
6994 (context->action == GDK_ACTION_MOVE),
6997 gtk_tree_path_free (dest_row);
7000 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7003 /* Drag-and-Drop support */
7005 * gtk_icon_view_enable_model_drag_source:
7006 * @icon_view: a #GtkIconTreeView
7007 * @start_button_mask: Mask of allowed buttons to start drag
7008 * @targets: the table of targets that the drag will support
7009 * @n_targets: the number of items in @targets
7010 * @actions: the bitmask of possible actions for a drag from this
7013 * Turns @icon_view into a drag source for automatic DND. Calling this
7014 * method sets #GtkIconView:reorderable to %FALSE.
7019 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7020 GdkModifierType start_button_mask,
7021 const GtkTargetEntry *targets,
7023 GdkDragAction actions)
7025 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7027 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7029 icon_view->priv->start_button_mask = start_button_mask;
7030 icon_view->priv->source_actions = actions;
7032 icon_view->priv->source_set = TRUE;
7034 unset_reorderable (icon_view);
7038 * gtk_icon_view_enable_model_drag_dest:
7039 * @icon_view: a #GtkIconView
7040 * @targets: the table of targets that the drag will support
7041 * @n_targets: the number of items in @targets
7042 * @actions: the bitmask of possible actions for a drag to this
7045 * Turns @icon_view into a drop destination for automatic DND. Calling this
7046 * method sets #GtkIconView:reorderable to %FALSE.
7051 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7052 const GtkTargetEntry *targets,
7054 GdkDragAction actions)
7056 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7058 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7060 icon_view->priv->dest_actions = actions;
7062 icon_view->priv->dest_set = TRUE;
7064 unset_reorderable (icon_view);
7068 * gtk_icon_view_unset_model_drag_source:
7069 * @icon_view: a #GtkIconView
7071 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7072 * method sets #GtkIconView:reorderable to %FALSE.
7077 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7079 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7081 if (icon_view->priv->source_set)
7083 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7084 icon_view->priv->source_set = FALSE;
7087 unset_reorderable (icon_view);
7091 * gtk_icon_view_unset_model_drag_dest:
7092 * @icon_view: a #GtkIconView
7094 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7095 * method sets #GtkIconView:reorderable to %FALSE.
7100 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7102 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7104 if (icon_view->priv->dest_set)
7106 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7107 icon_view->priv->dest_set = FALSE;
7110 unset_reorderable (icon_view);
7113 /* These are useful to implement your own custom stuff. */
7115 * gtk_icon_view_set_drag_dest_item:
7116 * @icon_view: a #GtkIconView
7117 * @path: The path of the item to highlight, or %NULL.
7118 * @pos: Specifies where to drop, relative to the item
7120 * Sets the item that is highlighted for feedback.
7125 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7127 GtkIconViewDropPosition pos)
7129 /* Note; this function is exported to allow a custom DND
7130 * implementation, so it can't touch TreeViewDragInfo
7133 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7135 if (icon_view->priv->dest_item)
7137 GtkTreePath *current_path;
7138 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7139 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7140 icon_view->priv->dest_item = NULL;
7142 gtk_icon_view_queue_draw_path (icon_view, current_path);
7143 gtk_tree_path_free (current_path);
7146 /* special case a drop on an empty model */
7147 icon_view->priv->empty_view_drop = FALSE;
7148 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7149 && gtk_tree_path_get_depth (path) == 1
7150 && gtk_tree_path_get_indices (path)[0] == 0)
7154 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7157 if (n_children == 0)
7158 icon_view->priv->empty_view_drop = TRUE;
7161 icon_view->priv->dest_pos = pos;
7165 icon_view->priv->dest_item =
7166 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7167 icon_view->priv->model, path);
7169 gtk_icon_view_queue_draw_path (icon_view, path);
7174 * gtk_icon_view_get_drag_dest_item:
7175 * @icon_view: a #GtkIconView
7176 * @path: Return location for the path of the highlighted item, or %NULL.
7177 * @pos: Return location for the drop position, or %NULL
7179 * Gets information about the item that is highlighted for feedback.
7184 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7186 GtkIconViewDropPosition *pos)
7188 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7192 if (icon_view->priv->dest_item)
7193 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7199 *pos = icon_view->priv->dest_pos;
7203 * gtk_icon_view_get_dest_item_at_pos:
7204 * @icon_view: a #GtkIconView
7205 * @drag_x: the position to determine the destination item for
7206 * @drag_y: the position to determine the destination item for
7207 * @path: Return location for the path of the item, or %NULL.
7208 * @pos: Return location for the drop position, or %NULL
7210 * Determines the destination item for a given position.
7212 * Return value: whether there is an item at the given position.
7217 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7221 GtkIconViewDropPosition *pos)
7223 GtkIconViewItem *item;
7225 /* Note; this function is exported to allow a custom DND
7226 * implementation, so it can't touch TreeViewDragInfo
7229 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7230 g_return_val_if_fail (drag_x >= 0, FALSE);
7231 g_return_val_if_fail (drag_y >= 0, FALSE);
7232 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7238 item = gtk_icon_view_get_item_at_coords (icon_view,
7239 drag_x + icon_view->priv->hadjustment->value,
7240 drag_y + icon_view->priv->vadjustment->value,
7247 *path = gtk_tree_path_new_from_indices (item->index, -1);
7251 if (drag_x < item->x + item->width / 4)
7252 *pos = GTK_ICON_VIEW_DROP_LEFT;
7253 else if (drag_x > item->x + item->width * 3 / 4)
7254 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7255 else if (drag_y < item->y + item->height / 4)
7256 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7257 else if (drag_y > item->y + item->height * 3 / 4)
7258 *pos = GTK_ICON_VIEW_DROP_BELOW;
7260 *pos = GTK_ICON_VIEW_DROP_INTO;
7267 * gtk_icon_view_create_drag_icon:
7268 * @icon_view: a #GtkIconView
7269 * @path: a #GtkTreePath in @icon_view
7271 * Creates a #GdkPixmap representation of the item at @path.
7272 * This image is used for a drag icon.
7274 * Return value: a newly-allocated pixmap of the drag icon.
7279 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7284 GdkPixmap *drawable;
7289 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7290 g_return_val_if_fail (path != NULL, NULL);
7292 widget = GTK_WIDGET (icon_view);
7294 if (!GTK_WIDGET_REALIZED (widget))
7297 index = gtk_tree_path_get_indices (path)[0];
7299 for (l = icon_view->priv->items; l; l = l->next)
7301 GtkIconViewItem *item = l->data;
7303 if (index == item->index)
7305 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7310 cr = gdk_cairo_create (drawable);
7311 cairo_set_line_width (cr, 1.);
7313 gdk_cairo_set_source_color
7314 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7315 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7320 area.width = item->width;
7321 area.height = item->height;
7323 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7324 drawable, 1, 1, FALSE);
7326 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7327 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7340 * gtk_icon_view_get_reorderable:
7341 * @icon_view: a #GtkIconView
7343 * Retrieves whether the user can reorder the list via drag-and-drop.
7344 * See gtk_icon_view_set_reorderable().
7346 * Return value: %TRUE if the list can be reordered.
7351 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7353 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7355 return icon_view->priv->reorderable;
7358 static const GtkTargetEntry item_targets[] = {
7359 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7364 * gtk_icon_view_set_reorderable:
7365 * @icon_view: A #GtkIconView.
7366 * @reorderable: %TRUE, if the list of items can be reordered.
7368 * This function is a convenience function to allow you to reorder models that
7369 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7370 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7371 * the user can reorder the model by dragging and dropping rows. The
7372 * developer can listen to these changes by connecting to the model's
7373 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7374 * the icon view as a drag source and destination. Therefore, drag and
7375 * drop can not be used in a reorderable view for any other purpose.
7377 * This function does not give you any degree of control over the order -- any
7378 * reordering is allowed. If more control is needed, you should probably
7379 * handle drag and drop manually.
7384 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7385 gboolean reorderable)
7387 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7389 reorderable = reorderable != FALSE;
7391 if (icon_view->priv->reorderable == reorderable)
7396 gtk_icon_view_enable_model_drag_source (icon_view,
7399 G_N_ELEMENTS (item_targets),
7401 gtk_icon_view_enable_model_drag_dest (icon_view,
7403 G_N_ELEMENTS (item_targets),
7408 gtk_icon_view_unset_model_drag_source (icon_view);
7409 gtk_icon_view_unset_model_drag_dest (icon_view);
7412 icon_view->priv->reorderable = reorderable;
7414 g_object_notify (G_OBJECT (icon_view), "reorderable");
7418 /* Accessibility Support */
7420 static gpointer accessible_parent_class;
7421 static gpointer accessible_item_parent_class;
7422 static GQuark accessible_private_data_quark = 0;
7424 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7425 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7426 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7428 static GType gtk_icon_view_item_accessible_get_type (void);
7439 GtkIconViewItem *item;
7443 AtkStateSet *state_set;
7447 GtkTextBuffer *text_buffer;
7449 gchar *action_descriptions[LAST_ACTION];
7450 gchar *image_description;
7451 guint action_idle_handler;
7452 } GtkIconViewItemAccessible;
7454 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7460 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7465 typedef struct _GtkIconViewItemAccessibleClass
7467 AtkObjectClass parent_class;
7469 } GtkIconViewItemAccessibleClass;
7471 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7474 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7476 GtkIconViewItemAccessible *item;
7477 GtkIconView *icon_view;
7480 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7481 item->action_idle_handler = 0;
7483 if (item->widget != NULL)
7485 icon_view = GTK_ICON_VIEW (item->widget);
7486 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7487 gtk_icon_view_item_activated (icon_view, path);
7488 gtk_tree_path_free (path);
7495 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7498 GtkIconViewItemAccessible *item;
7500 if (i < 0 || i >= LAST_ACTION)
7503 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7505 if (!GTK_IS_ICON_VIEW (item->widget))
7508 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7513 case ACTION_ACTIVATE:
7514 if (!item->action_idle_handler)
7515 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7518 g_assert_not_reached ();
7526 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7531 static const gchar *
7532 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7535 GtkIconViewItemAccessible *item;
7537 if (i < 0 || i >= LAST_ACTION)
7540 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7542 if (item->action_descriptions[i])
7543 return item->action_descriptions[i];
7545 return gtk_icon_view_item_accessible_action_descriptions[i];
7548 static const gchar *
7549 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7552 if (i < 0 || i >= LAST_ACTION)
7555 return gtk_icon_view_item_accessible_action_names[i];
7559 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7561 const gchar *description)
7563 GtkIconViewItemAccessible *item;
7565 if (i < 0 || i >= LAST_ACTION)
7568 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7570 g_free (item->action_descriptions[i]);
7572 item->action_descriptions[i] = g_strdup (description);
7578 atk_action_item_interface_init (AtkActionIface *iface)
7580 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7581 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7582 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7583 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7584 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7587 static const gchar *
7588 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7590 GtkIconViewItemAccessible *item;
7592 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7594 return item->image_description;
7598 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7599 const gchar *description)
7601 GtkIconViewItemAccessible *item;
7603 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7605 g_free (item->image_description);
7606 item->image_description = g_strdup (item->image_description);
7612 get_pixbuf_box (GtkIconView *icon_view,
7613 GtkIconViewItem *item,
7618 for (l = icon_view->priv->cell_list; l; l = l->next)
7620 GtkIconViewCellInfo *info = l->data;
7622 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7624 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7634 get_text (GtkIconView *icon_view,
7635 GtkIconViewItem *item)
7640 for (l = icon_view->priv->cell_list; l; l = l->next)
7642 GtkIconViewCellInfo *info = l->data;
7644 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7646 g_object_get (info->cell, "text", &text, NULL);
7656 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7660 GtkIconViewItemAccessible *item;
7663 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7665 if (!GTK_IS_ICON_VIEW (item->widget))
7668 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7671 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7674 *height = box.height;
7679 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7682 AtkCoordType coord_type)
7684 GtkIconViewItemAccessible *item;
7687 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7689 if (!GTK_IS_ICON_VIEW (item->widget))
7692 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7695 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7697 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7699 *x+= box.x - item->item->x;
7700 *y+= box.y - item->item->y;
7706 atk_image_item_interface_init (AtkImageIface *iface)
7708 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7709 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7710 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7711 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7715 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7719 GtkIconViewItemAccessible *item;
7720 GtkTextIter start, end;
7721 GtkTextBuffer *buffer;
7723 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7725 if (!GTK_IS_ICON_VIEW (item->widget))
7728 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7731 buffer = item->text_buffer;
7732 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7734 gtk_text_buffer_get_end_iter (buffer, &end);
7736 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7738 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7742 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7745 GtkIconViewItemAccessible *item;
7746 GtkTextIter start, end;
7747 GtkTextBuffer *buffer;
7751 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7753 if (!GTK_IS_ICON_VIEW (item->widget))
7756 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7759 buffer = item->text_buffer;
7760 if (offset >= gtk_text_buffer_get_char_count (buffer))
7763 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7765 gtk_text_iter_forward_char (&end);
7766 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7767 unichar = g_utf8_get_char (string);
7775 get_pango_text_offsets (PangoLayout *layout,
7776 GtkTextBuffer *buffer,
7778 AtkTextBoundary boundary_type,
7782 GtkTextIter *start_iter,
7783 GtkTextIter *end_iter)
7785 PangoLayoutIter *iter;
7786 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7787 gint index, start_index, end_index;
7789 gboolean found = FALSE;
7791 text = pango_layout_get_text (layout);
7792 index = g_utf8_offset_to_pointer (text, offset) - text;
7793 iter = pango_layout_get_iter (layout);
7796 line = pango_layout_iter_get_line_readonly (iter);
7797 start_index = line->start_index;
7798 end_index = start_index + line->length;
7800 if (index >= start_index && index <= end_index)
7803 * Found line for offset
7809 * We want the previous line
7813 switch (boundary_type)
7815 case ATK_TEXT_BOUNDARY_LINE_START:
7816 end_index = start_index;
7817 start_index = prev_line->start_index;
7819 case ATK_TEXT_BOUNDARY_LINE_END:
7821 start_index = prev_prev_line->start_index +
7822 prev_prev_line->length;
7823 end_index = prev_line->start_index + prev_line->length;
7826 g_assert_not_reached();
7830 start_index = end_index = 0;
7833 switch (boundary_type)
7835 case ATK_TEXT_BOUNDARY_LINE_START:
7836 if (pango_layout_iter_next_line (iter))
7837 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7839 case ATK_TEXT_BOUNDARY_LINE_END:
7841 start_index = prev_line->start_index +
7845 g_assert_not_reached();
7850 * We want the next line
7852 if (pango_layout_iter_next_line (iter))
7854 line = pango_layout_iter_get_line_readonly (iter);
7855 switch (boundary_type)
7857 case ATK_TEXT_BOUNDARY_LINE_START:
7858 start_index = line->start_index;
7859 if (pango_layout_iter_next_line (iter))
7860 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7862 end_index = start_index + line->length;
7864 case ATK_TEXT_BOUNDARY_LINE_END:
7865 start_index = end_index;
7866 end_index = line->start_index + line->length;
7869 g_assert_not_reached();
7873 start_index = end_index;
7879 prev_prev_line = prev_line;
7882 while (pango_layout_iter_next_line (iter));
7886 start_index = prev_line->start_index + prev_line->length;
7887 end_index = start_index;
7889 pango_layout_iter_free (iter);
7890 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7891 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7893 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7894 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7899 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7901 AtkTextBoundary boundary_type,
7905 GtkIconViewItemAccessible *item;
7906 GtkTextIter start, end;
7907 GtkTextBuffer *buffer;
7909 GtkIconView *icon_view;
7912 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7914 if (!GTK_IS_ICON_VIEW (item->widget))
7917 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7920 buffer = item->text_buffer;
7922 if (!gtk_text_buffer_get_char_count (buffer))
7926 return g_strdup ("");
7928 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7932 switch (boundary_type)
7934 case ATK_TEXT_BOUNDARY_CHAR:
7935 gtk_text_iter_backward_char(&start);
7937 case ATK_TEXT_BOUNDARY_WORD_START:
7938 if (!gtk_text_iter_starts_word (&start))
7939 gtk_text_iter_backward_word_start (&start);
7941 gtk_text_iter_backward_word_start(&start);
7943 case ATK_TEXT_BOUNDARY_WORD_END:
7944 if (gtk_text_iter_inside_word (&start) &&
7945 !gtk_text_iter_starts_word (&start))
7946 gtk_text_iter_backward_word_start (&start);
7947 while (!gtk_text_iter_ends_word (&start))
7949 if (!gtk_text_iter_backward_char (&start))
7953 gtk_text_iter_backward_word_start(&start);
7954 while (!gtk_text_iter_ends_word (&start))
7956 if (!gtk_text_iter_backward_char (&start))
7960 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7961 if (!gtk_text_iter_starts_sentence (&start))
7962 gtk_text_iter_backward_sentence_start (&start);
7964 gtk_text_iter_backward_sentence_start (&start);
7966 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7967 if (gtk_text_iter_inside_sentence (&start) &&
7968 !gtk_text_iter_starts_sentence (&start))
7969 gtk_text_iter_backward_sentence_start (&start);
7970 while (!gtk_text_iter_ends_sentence (&start))
7972 if (!gtk_text_iter_backward_char (&start))
7976 gtk_text_iter_backward_sentence_start (&start);
7977 while (!gtk_text_iter_ends_sentence (&start))
7979 if (!gtk_text_iter_backward_char (&start))
7983 case ATK_TEXT_BOUNDARY_LINE_START:
7984 case ATK_TEXT_BOUNDARY_LINE_END:
7986 icon_view = GTK_ICON_VIEW (item->widget);
7987 /* FIXME we probably have to use GailTextCell to salvage this */
7988 gtk_icon_view_update_item_text (icon_view, item->item);
7989 get_pango_text_offsets (icon_view->priv->layout,
8002 *start_offset = gtk_text_iter_get_offset (&start);
8003 *end_offset = gtk_text_iter_get_offset (&end);
8005 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8009 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8011 AtkTextBoundary boundary_type,
8015 GtkIconViewItemAccessible *item;
8016 GtkTextIter start, end;
8017 GtkTextBuffer *buffer;
8019 GtkIconView *icon_view;
8022 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8024 if (!GTK_IS_ICON_VIEW (item->widget))
8027 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8030 buffer = item->text_buffer;
8032 if (!gtk_text_buffer_get_char_count (buffer))
8036 return g_strdup ("");
8038 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8042 switch (boundary_type)
8044 case ATK_TEXT_BOUNDARY_CHAR:
8045 gtk_text_iter_forward_char (&end);
8047 case ATK_TEXT_BOUNDARY_WORD_START:
8048 if (!gtk_text_iter_starts_word (&start))
8049 gtk_text_iter_backward_word_start (&start);
8050 if (gtk_text_iter_inside_word (&end))
8051 gtk_text_iter_forward_word_end (&end);
8052 while (!gtk_text_iter_starts_word (&end))
8054 if (!gtk_text_iter_forward_char (&end))
8058 case ATK_TEXT_BOUNDARY_WORD_END:
8059 if (gtk_text_iter_inside_word (&start) &&
8060 !gtk_text_iter_starts_word (&start))
8061 gtk_text_iter_backward_word_start (&start);
8062 while (!gtk_text_iter_ends_word (&start))
8064 if (!gtk_text_iter_backward_char (&start))
8067 gtk_text_iter_forward_word_end (&end);
8069 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8070 if (!gtk_text_iter_starts_sentence (&start))
8071 gtk_text_iter_backward_sentence_start (&start);
8072 if (gtk_text_iter_inside_sentence (&end))
8073 gtk_text_iter_forward_sentence_end (&end);
8074 while (!gtk_text_iter_starts_sentence (&end))
8076 if (!gtk_text_iter_forward_char (&end))
8080 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8081 if (gtk_text_iter_inside_sentence (&start) &&
8082 !gtk_text_iter_starts_sentence (&start))
8083 gtk_text_iter_backward_sentence_start (&start);
8084 while (!gtk_text_iter_ends_sentence (&start))
8086 if (!gtk_text_iter_backward_char (&start))
8089 gtk_text_iter_forward_sentence_end (&end);
8091 case ATK_TEXT_BOUNDARY_LINE_START:
8092 case ATK_TEXT_BOUNDARY_LINE_END:
8094 icon_view = GTK_ICON_VIEW (item->widget);
8095 /* FIXME we probably have to use GailTextCell to salvage this */
8096 gtk_icon_view_update_item_text (icon_view, item->item);
8097 get_pango_text_offsets (icon_view->priv->layout,
8111 *start_offset = gtk_text_iter_get_offset (&start);
8112 *end_offset = gtk_text_iter_get_offset (&end);
8114 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8118 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8120 AtkTextBoundary boundary_type,
8124 GtkIconViewItemAccessible *item;
8125 GtkTextIter start, end;
8126 GtkTextBuffer *buffer;
8128 GtkIconView *icon_view;
8131 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8133 if (!GTK_IS_ICON_VIEW (item->widget))
8136 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8139 buffer = item->text_buffer;
8141 if (!gtk_text_buffer_get_char_count (buffer))
8145 return g_strdup ("");
8147 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8151 switch (boundary_type)
8153 case ATK_TEXT_BOUNDARY_CHAR:
8154 gtk_text_iter_forward_char(&start);
8155 gtk_text_iter_forward_chars(&end, 2);
8157 case ATK_TEXT_BOUNDARY_WORD_START:
8158 if (gtk_text_iter_inside_word (&end))
8159 gtk_text_iter_forward_word_end (&end);
8160 while (!gtk_text_iter_starts_word (&end))
8162 if (!gtk_text_iter_forward_char (&end))
8166 if (!gtk_text_iter_is_end (&end))
8168 gtk_text_iter_forward_word_end (&end);
8169 while (!gtk_text_iter_starts_word (&end))
8171 if (!gtk_text_iter_forward_char (&end))
8176 case ATK_TEXT_BOUNDARY_WORD_END:
8177 gtk_text_iter_forward_word_end (&end);
8179 if (!gtk_text_iter_is_end (&end))
8180 gtk_text_iter_forward_word_end (&end);
8182 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8183 if (gtk_text_iter_inside_sentence (&end))
8184 gtk_text_iter_forward_sentence_end (&end);
8185 while (!gtk_text_iter_starts_sentence (&end))
8187 if (!gtk_text_iter_forward_char (&end))
8191 if (!gtk_text_iter_is_end (&end))
8193 gtk_text_iter_forward_sentence_end (&end);
8194 while (!gtk_text_iter_starts_sentence (&end))
8196 if (!gtk_text_iter_forward_char (&end))
8201 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8202 gtk_text_iter_forward_sentence_end (&end);
8204 if (!gtk_text_iter_is_end (&end))
8205 gtk_text_iter_forward_sentence_end (&end);
8207 case ATK_TEXT_BOUNDARY_LINE_START:
8208 case ATK_TEXT_BOUNDARY_LINE_END:
8210 icon_view = GTK_ICON_VIEW (item->widget);
8211 /* FIXME we probably have to use GailTextCell to salvage this */
8212 gtk_icon_view_update_item_text (icon_view, item->item);
8213 get_pango_text_offsets (icon_view->priv->layout,
8225 *start_offset = gtk_text_iter_get_offset (&start);
8226 *end_offset = gtk_text_iter_get_offset (&end);
8228 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8232 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8234 GtkIconViewItemAccessible *item;
8236 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8238 if (!GTK_IS_ICON_VIEW (item->widget))
8241 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8244 return gtk_text_buffer_get_char_count (item->text_buffer);
8248 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8254 AtkCoordType coord_type)
8256 GtkIconViewItemAccessible *item;
8258 GtkIconView *icon_view;
8259 PangoRectangle char_rect;
8260 const gchar *item_text;
8264 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8266 if (!GTK_IS_ICON_VIEW (item->widget))
8269 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8273 icon_view = GTK_ICON_VIEW (item->widget);
8274 /* FIXME we probably have to use GailTextCell to salvage this */
8275 gtk_icon_view_update_item_text (icon_view, item->item);
8276 item_text = pango_layout_get_text (icon_view->priv->layout);
8277 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8278 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8280 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8281 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8282 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8283 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8284 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8285 *width = char_rect.width / PANGO_SCALE;
8286 *height = char_rect.height / PANGO_SCALE;
8291 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8294 AtkCoordType coord_type)
8296 GtkIconViewItemAccessible *item;
8299 GtkIconView *icon_view;
8300 const gchar *item_text;
8305 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8307 if (!GTK_IS_ICON_VIEW (item->widget))
8310 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8314 icon_view = GTK_ICON_VIEW (item->widget);
8315 /* FIXME we probably have to use GailTextCell to salvage this */
8316 gtk_icon_view_update_item_text (icon_view, item->item);
8317 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8318 x -= l_x + item->item->layout_x - item->item->x;
8319 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8320 y -= l_y + item->item->layout_y - item->item->y;
8321 item_text = pango_layout_get_text (icon_view->priv->layout);
8322 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8333 offset = g_utf8_strlen (item_text, -1);
8335 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8341 atk_text_item_interface_init (AtkTextIface *iface)
8343 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8344 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8345 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8346 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8347 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8348 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8349 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8350 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8354 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8359 AtkCoordType coord_type)
8361 GtkIconViewItemAccessible *item;
8362 AtkObject *parent_obj;
8365 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8367 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8368 if (!GTK_IS_WIDGET (item->widget))
8371 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8374 *width = item->item->width;
8375 *height = item->item->height;
8376 if (gtk_icon_view_item_accessible_is_showing (item))
8378 parent_obj = gtk_widget_get_accessible (item->widget);
8379 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8380 *x = l_x + item->item->x;
8381 *y = l_y + item->item->y;
8391 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8393 GtkIconViewItemAccessible *item;
8394 GtkWidget *toplevel;
8396 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8398 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8399 if (!GTK_IS_WIDGET (item->widget))
8402 gtk_widget_grab_focus (item->widget);
8403 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8404 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8405 if (GTK_WIDGET_TOPLEVEL (toplevel))
8406 gtk_window_present (GTK_WINDOW (toplevel));
8412 atk_component_item_interface_init (AtkComponentIface *iface)
8414 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8415 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8419 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8420 AtkStateType state_type,
8421 gboolean emit_signal)
8425 rc = atk_state_set_add_state (item->state_set, state_type);
8427 * The signal should only be generated if the value changed,
8428 * not when the item is set up. So states that are set
8429 * initially should pass FALSE as the emit_signal argument.
8434 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8435 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8436 if (state_type == ATK_STATE_VISIBLE)
8437 g_signal_emit_by_name (item, "visible-data-changed");
8444 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8445 AtkStateType state_type,
8446 gboolean emit_signal)
8448 if (atk_state_set_contains_state (item->state_set, state_type))
8452 rc = atk_state_set_remove_state (item->state_set, state_type);
8454 * The signal should only be generated if the value changed,
8455 * not when the item is set up. So states that are set
8456 * initially should pass FALSE as the emit_signal argument.
8461 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8462 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8463 if (state_type == ATK_STATE_VISIBLE)
8464 g_signal_emit_by_name (item, "visible-data-changed");
8474 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8476 GtkIconView *icon_view;
8477 GdkRectangle visible_rect;
8478 gboolean is_showing;
8481 * An item is considered "SHOWING" if any part of the item is in the
8482 * visible rectangle.
8485 if (!GTK_IS_ICON_VIEW (item->widget))
8488 if (item->item == NULL)
8491 icon_view = GTK_ICON_VIEW (item->widget);
8493 if (icon_view->priv->hadjustment)
8494 visible_rect.x += icon_view->priv->hadjustment->value;
8496 if (icon_view->priv->hadjustment)
8497 visible_rect.y += icon_view->priv->vadjustment->value;
8498 visible_rect.width = item->widget->allocation.width;
8499 visible_rect.height = item->widget->allocation.height;
8501 if (((item->item->x + item->item->width) < visible_rect.x) ||
8502 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8503 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8504 (item->item->y > (visible_rect.y + visible_rect.height)))
8513 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8514 gboolean emit_signal)
8516 if (gtk_icon_view_item_accessible_is_showing (item))
8517 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8520 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8525 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8529 item->state_set = atk_state_set_new ();
8531 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8532 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8533 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8534 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8535 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8537 for (i = 0; i < LAST_ACTION; i++)
8538 item->action_descriptions[i] = NULL;
8540 item->image_description = NULL;
8542 item->action_idle_handler = 0;
8546 gtk_icon_view_item_accessible_finalize (GObject *object)
8548 GtkIconViewItemAccessible *item;
8551 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8553 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8556 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8558 if (item->state_set)
8559 g_object_unref (item->state_set);
8561 if (item->text_buffer)
8562 g_object_unref (item->text_buffer);
8564 for (i = 0; i < LAST_ACTION; i++)
8565 g_free (item->action_descriptions[i]);
8567 g_free (item->image_description);
8569 if (item->action_idle_handler)
8571 g_source_remove (item->action_idle_handler);
8572 item->action_idle_handler = 0;
8575 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8578 static G_CONST_RETURN gchar*
8579 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8585 GtkIconViewItemAccessible *item;
8586 GtkTextIter start_iter;
8587 GtkTextIter end_iter;
8589 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8591 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8592 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8594 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8599 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8601 GtkIconViewItemAccessible *item;
8603 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8604 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8607 return gtk_widget_get_accessible (item->widget);
8613 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8615 GtkIconViewItemAccessible *item;
8617 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8618 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8620 return item->item->index;
8623 static AtkStateSet *
8624 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8626 GtkIconViewItemAccessible *item;
8627 GtkIconView *icon_view;
8629 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8630 g_return_val_if_fail (item->state_set, NULL);
8635 icon_view = GTK_ICON_VIEW (item->widget);
8636 if (icon_view->priv->cursor_item == item->item)
8637 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8639 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8640 if (item->item->selected)
8641 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8643 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8645 return g_object_ref (item->state_set);
8649 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8651 GObjectClass *gobject_class;
8653 accessible_item_parent_class = g_type_class_peek_parent (klass);
8655 gobject_class = (GObjectClass *)klass;
8657 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8659 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8660 klass->get_name = gtk_icon_view_item_accessible_get_name;
8661 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8662 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8666 gtk_icon_view_item_accessible_get_type (void)
8668 static GType type = 0;
8672 const GTypeInfo tinfo =
8674 sizeof (GtkIconViewItemAccessibleClass),
8675 (GBaseInitFunc) NULL, /* base init */
8676 (GBaseFinalizeFunc) NULL, /* base finalize */
8677 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8678 (GClassFinalizeFunc) NULL, /* class finalize */
8679 NULL, /* class data */
8680 sizeof (GtkIconViewItemAccessible), /* instance size */
8681 0, /* nb preallocs */
8682 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8683 NULL /* value table */
8686 static const GInterfaceInfo atk_component_info =
8688 (GInterfaceInitFunc) atk_component_item_interface_init,
8689 (GInterfaceFinalizeFunc) NULL,
8692 static const GInterfaceInfo atk_action_info =
8694 (GInterfaceInitFunc) atk_action_item_interface_init,
8695 (GInterfaceFinalizeFunc) NULL,
8698 static const GInterfaceInfo atk_image_info =
8700 (GInterfaceInitFunc) atk_image_item_interface_init,
8701 (GInterfaceFinalizeFunc) NULL,
8704 static const GInterfaceInfo atk_text_info =
8706 (GInterfaceInitFunc) atk_text_item_interface_init,
8707 (GInterfaceFinalizeFunc) NULL,
8711 type = g_type_register_static (ATK_TYPE_OBJECT,
8712 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8713 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8714 &atk_component_info);
8715 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8717 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8719 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8726 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8727 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8728 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8730 static GType gtk_icon_view_accessible_get_type (void);
8735 } GtkIconViewAccessible;
8741 } GtkIconViewItemAccessibleInfo;
8747 GtkAdjustment *old_hadj;
8748 GtkAdjustment *old_vadj;
8750 GtkTreeModel *model;
8752 } GtkIconViewAccessiblePrivate;
8754 static GtkIconViewAccessiblePrivate *
8755 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8757 return g_object_get_qdata (G_OBJECT (accessible),
8758 accessible_private_data_quark);
8762 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8766 GtkIconViewItemAccessibleInfo *info;
8767 GtkIconViewItemAccessibleInfo *tmp_info;
8768 GtkIconViewAccessiblePrivate *priv;
8771 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8773 info->index = index;
8775 priv = gtk_icon_view_accessible_get_priv (accessible);
8776 items = priv->items;
8779 tmp_info = items->data;
8780 if (tmp_info->index > index)
8782 items = items->next;
8784 priv->items = g_list_insert_before (priv->items, items, info);
8785 priv->old_hadj = NULL;
8786 priv->old_vadj = NULL;
8790 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8792 GtkIconView *icon_view;
8795 widget = GTK_ACCESSIBLE (accessible)->widget;
8799 icon_view = GTK_ICON_VIEW (widget);
8801 return g_list_length (icon_view->priv->items);
8805 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8808 GtkIconViewAccessiblePrivate *priv;
8809 GtkIconViewItemAccessibleInfo *info;
8812 priv = gtk_icon_view_accessible_get_priv (accessible);
8813 items = priv->items;
8818 if (info->index == index)
8820 items = items->next;
8826 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8829 GtkIconView *icon_view;
8833 GtkIconViewItemAccessible *a11y_item;
8835 widget = GTK_ACCESSIBLE (accessible)->widget;
8839 icon_view = GTK_ICON_VIEW (widget);
8840 icons = g_list_nth (icon_view->priv->items, index);
8844 GtkIconViewItem *item = icons->data;
8846 g_return_val_if_fail (item->index == index, NULL);
8847 obj = gtk_icon_view_accessible_find_child (accessible, index);
8852 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8853 gtk_icon_view_item_accessible_info_new (accessible,
8856 obj->role = ATK_ROLE_ICON;
8857 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8858 a11y_item->item = item;
8859 a11y_item->widget = widget;
8860 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8862 gtk_icon_view_set_cell_data (icon_view, item);
8863 text = get_text (icon_view, item);
8866 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8870 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8871 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8879 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8882 GtkIconViewAccessiblePrivate *priv;
8883 GtkIconViewItemAccessibleInfo *info;
8884 GtkIconViewItemAccessible *item;
8887 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8891 gboolean act_on_item;
8893 widget = GTK_ACCESSIBLE (view)->widget;
8897 items = priv->items;
8899 act_on_item = (list == NULL);
8904 info = (GtkIconViewItemAccessibleInfo *)items->data;
8905 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8907 if (act_on_item == FALSE && list == items)
8911 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8913 items = items->next;
8919 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8920 GtkIconView *icon_view)
8923 GtkIconViewAccessible *view;
8926 * The scrollbars have changed
8928 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8929 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8931 gtk_icon_view_accessible_traverse_items (view, NULL);
8935 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8936 GtkAdjustment *hadj,
8937 GtkAdjustment *vadj)
8940 GtkIconViewAccessiblePrivate *priv;
8942 atk_obj = gtk_widget_get_accessible (widget);
8943 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8945 if (priv->old_hadj != hadj)
8949 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8950 (gpointer *)&priv->old_hadj);
8952 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8953 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8956 priv->old_hadj = hadj;
8959 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8960 (gpointer *)&priv->old_hadj);
8961 g_signal_connect (hadj,
8963 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8967 if (priv->old_vadj != vadj)
8971 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8972 (gpointer *)&priv->old_vadj);
8974 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8975 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8978 priv->old_vadj = vadj;
8981 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8982 (gpointer *)&priv->old_vadj);
8983 g_signal_connect (vadj,
8985 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8992 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9000 GtkIconView *icon_view;
9001 GtkIconViewItem *item;
9002 GtkIconViewAccessible *a11y_view;
9003 GtkIconViewItemAccessible *a11y_item;
9006 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9007 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9008 index = gtk_tree_path_get_indices(path)[0];
9009 a11y_item = gtk_icon_view_accessible_find_child (atk_obj, index);
9013 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9014 icon_view = GTK_ICON_VIEW (widget);
9015 item = a11y_item->item;
9017 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9019 if (!name || strcmp (name, "") == 0)
9021 gtk_icon_view_set_cell_data (icon_view, item);
9022 text = get_text (icon_view, item);
9025 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9031 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9037 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9042 GtkIconViewAccessiblePrivate *priv;
9043 GtkIconViewItemAccessibleInfo *info;
9044 GtkIconViewAccessible *view;
9045 GtkIconViewItemAccessible *item;
9051 index = gtk_tree_path_get_indices(path)[0];
9052 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9053 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9054 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9056 items = priv->items;
9061 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9062 if (info->index != item->item->index)
9064 if (info->index < index)
9065 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9067 if (tmp_list == NULL)
9070 info->index = item->item->index;
9073 items = items->next;
9075 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9076 g_signal_emit_by_name (atk_obj, "children-changed::add",
9082 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9086 GtkIconViewAccessiblePrivate *priv;
9087 GtkIconViewItemAccessibleInfo *info;
9088 GtkIconViewAccessible *view;
9089 GtkIconViewItemAccessible *item;
9092 GList *deleted_item;
9096 index = gtk_tree_path_get_indices(path)[0];
9097 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9098 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9099 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9101 items = priv->items;
9103 deleted_item = NULL;
9108 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9109 if (info->index == index)
9111 deleted_item = items;
9113 if (info->index != item->item->index)
9115 if (tmp_list == NULL)
9118 info->index = item->item->index;
9121 items = items->next;
9123 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9126 info = deleted_item->data;
9127 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9128 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9130 priv->items = g_list_remove_link (priv->items, deleted_item);
9138 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9139 GtkIconViewItemAccessibleInfo *i2)
9141 return i1->index - i2->index;
9145 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9151 GtkIconViewAccessiblePrivate *priv;
9152 GtkIconViewItemAccessibleInfo *info;
9153 GtkIconView *icon_view;
9154 GtkIconViewItemAccessible *item;
9160 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9161 icon_view = GTK_ICON_VIEW (user_data);
9162 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9164 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9166 order = g_new (gint, length);
9167 for (i = 0; i < length; i++)
9168 order [new_order[i]] = i;
9170 items = priv->items;
9174 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9175 info->index = order[info->index];
9176 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9177 items = items->next;
9180 priv->items = g_list_sort (priv->items,
9181 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9187 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9192 obj = G_OBJECT (model);
9193 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9194 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9195 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9196 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9200 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9204 obj = G_OBJECT (icon_view->priv->model);
9205 g_signal_connect_data (obj, "row-changed",
9206 (GCallback) gtk_icon_view_accessible_model_row_changed,
9207 icon_view, NULL, 0);
9208 g_signal_connect_data (obj, "row-inserted",
9209 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9210 icon_view, NULL, G_CONNECT_AFTER);
9211 g_signal_connect_data (obj, "row-deleted",
9212 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9213 icon_view, NULL, G_CONNECT_AFTER);
9214 g_signal_connect_data (obj, "rows-reordered",
9215 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9216 icon_view, NULL, G_CONNECT_AFTER);
9220 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9222 GtkIconViewItemAccessibleInfo *info;
9225 items = priv->items;
9228 info = (GtkIconViewItemAccessibleInfo *) items->data;
9229 g_object_unref (info->item);
9230 g_free (items->data);
9231 items = items->next;
9233 g_list_free (priv->items);
9238 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9241 GtkIconView *icon_view;
9244 GtkIconViewAccessiblePrivate *priv;
9246 if (strcmp (pspec->name, "model") == 0)
9248 widget = GTK_WIDGET (obj);
9249 atk_obj = gtk_widget_get_accessible (widget);
9250 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9253 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9254 (gpointer *)&priv->model);
9255 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9257 gtk_icon_view_accessible_clear_cache (priv);
9259 icon_view = GTK_ICON_VIEW (obj);
9260 priv->model = icon_view->priv->model;
9261 /* If there is no model the GtkIconView is probably being destroyed */
9264 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9265 gtk_icon_view_accessible_connect_model_signals (icon_view);
9273 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9276 GtkIconViewAccessiblePrivate *priv;
9277 GtkIconView *icon_view;
9279 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9280 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9282 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9283 g_object_set_qdata (G_OBJECT (accessible),
9284 accessible_private_data_quark,
9287 icon_view = GTK_ICON_VIEW (data);
9288 if (icon_view->priv->hadjustment)
9290 priv->old_hadj = icon_view->priv->hadjustment;
9291 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9292 g_signal_connect (icon_view->priv->hadjustment,
9294 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9297 if (icon_view->priv->vadjustment)
9299 priv->old_vadj = icon_view->priv->vadjustment;
9300 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9301 g_signal_connect (icon_view->priv->vadjustment,
9303 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9306 g_signal_connect_after (data,
9307 "set-scroll-adjustments",
9308 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9310 g_signal_connect (data,
9312 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9315 priv->model = icon_view->priv->model;
9318 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9319 gtk_icon_view_accessible_connect_model_signals (icon_view);
9322 accessible->role = ATK_ROLE_LAYERED_PANE;
9326 gtk_icon_view_accessible_finalize (GObject *object)
9328 GtkIconViewAccessiblePrivate *priv;
9330 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9331 gtk_icon_view_accessible_clear_cache (priv);
9335 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9339 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9340 GtkAccessible *accessible)
9343 GtkIconViewAccessiblePrivate *priv;
9345 atk_obj = ATK_OBJECT (accessible);
9346 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9349 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9350 (gpointer *)&priv->old_hadj);
9352 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9353 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9355 priv->old_hadj = NULL;
9359 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9360 (gpointer *)&priv->old_vadj);
9362 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9363 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9365 priv->old_vadj = NULL;
9370 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9372 if (accessible->widget)
9374 g_signal_connect_after (accessible->widget,
9376 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9379 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9383 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9385 GObjectClass *gobject_class;
9386 GtkAccessibleClass *accessible_class;
9388 accessible_parent_class = g_type_class_peek_parent (klass);
9390 gobject_class = (GObjectClass *)klass;
9391 accessible_class = (GtkAccessibleClass *)klass;
9393 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9395 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9396 klass->ref_child = gtk_icon_view_accessible_ref_child;
9397 klass->initialize = gtk_icon_view_accessible_initialize;
9399 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9401 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9405 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9408 AtkCoordType coord_type)
9411 GtkIconView *icon_view;
9412 GtkIconViewItem *item;
9415 widget = GTK_ACCESSIBLE (component)->widget;
9417 /* State is defunct */
9420 icon_view = GTK_ICON_VIEW (widget);
9421 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9422 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9424 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9430 atk_component_interface_init (AtkComponentIface *iface)
9432 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9436 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9440 GtkIconView *icon_view;
9441 GtkIconViewItem *item;
9443 widget = GTK_ACCESSIBLE (selection)->widget;
9447 icon_view = GTK_ICON_VIEW (widget);
9449 item = g_list_nth_data (icon_view->priv->items, i);
9454 gtk_icon_view_select_item (icon_view, item);
9460 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9463 GtkIconView *icon_view;
9465 widget = GTK_ACCESSIBLE (selection)->widget;
9469 icon_view = GTK_ICON_VIEW (widget);
9470 gtk_icon_view_unselect_all (icon_view);
9476 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9481 GtkIconView *icon_view;
9482 GtkIconViewItem *item;
9484 widget = GTK_ACCESSIBLE (selection)->widget;
9488 icon_view = GTK_ICON_VIEW (widget);
9490 l = icon_view->priv->items;
9497 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9508 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9511 GtkIconView *icon_view;
9512 GtkIconViewItem *item;
9516 widget = GTK_ACCESSIBLE (selection)->widget;
9520 icon_view = GTK_ICON_VIEW (widget);
9522 l = icon_view->priv->items;
9538 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9542 GtkIconView *icon_view;
9543 GtkIconViewItem *item;
9545 widget = GTK_ACCESSIBLE (selection)->widget;
9549 icon_view = GTK_ICON_VIEW (widget);
9551 item = g_list_nth_data (icon_view->priv->items, i);
9555 return item->selected;
9559 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9563 GtkIconView *icon_view;
9564 GtkIconViewItem *item;
9568 widget = GTK_ACCESSIBLE (selection)->widget;
9572 icon_view = GTK_ICON_VIEW (widget);
9573 l = icon_view->priv->items;
9582 gtk_icon_view_unselect_item (icon_view, item);
9594 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9597 GtkIconView *icon_view;
9599 widget = GTK_ACCESSIBLE (selection)->widget;
9603 icon_view = GTK_ICON_VIEW (widget);
9604 gtk_icon_view_select_all (icon_view);
9609 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9611 iface->add_selection = gtk_icon_view_accessible_add_selection;
9612 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9613 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9614 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9615 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9616 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9617 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9621 gtk_icon_view_accessible_get_type (void)
9623 static GType type = 0;
9627 static GTypeInfo tinfo =
9630 (GBaseInitFunc) NULL, /* base init */
9631 (GBaseFinalizeFunc) NULL, /* base finalize */
9632 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9633 (GClassFinalizeFunc) NULL, /* class finalize */
9634 NULL, /* class data */
9635 0, /* instance size */
9636 0, /* nb preallocs */
9637 (GInstanceInitFunc) NULL, /* instance init */
9638 NULL /* value table */
9640 static const GInterfaceInfo atk_component_info =
9642 (GInterfaceInitFunc) atk_component_interface_init,
9643 (GInterfaceFinalizeFunc) NULL,
9646 static const GInterfaceInfo atk_selection_info =
9648 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9649 (GInterfaceFinalizeFunc) NULL,
9654 * Figure out the size of the class and instance
9655 * we are deriving from
9657 AtkObjectFactory *factory;
9660 GType derived_atk_type;
9662 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9663 factory = atk_registry_get_factory (atk_get_default_registry (),
9665 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9666 g_type_query (derived_atk_type, &query);
9667 tinfo.class_size = query.class_size;
9668 tinfo.instance_size = query.instance_size;
9670 type = g_type_register_static (derived_atk_type,
9671 I_("GtkIconViewAccessible"),
9673 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9674 &atk_component_info);
9675 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9676 &atk_selection_info);
9682 gtk_icon_view_accessible_new (GObject *obj)
9684 AtkObject *accessible;
9686 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9688 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9689 atk_object_initialize (accessible, obj);
9695 gtk_icon_view_accessible_factory_get_accessible_type (void)
9697 return gtk_icon_view_accessible_get_type ();
9701 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9703 return gtk_icon_view_accessible_new (obj);
9707 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9709 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9710 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9714 gtk_icon_view_accessible_factory_get_type (void)
9716 static GType type = 0;
9720 const GTypeInfo tinfo =
9722 sizeof (AtkObjectFactoryClass),
9723 NULL, /* base_init */
9724 NULL, /* base_finalize */
9725 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9726 NULL, /* class_finalize */
9727 NULL, /* class_data */
9728 sizeof (AtkObjectFactory),
9729 0, /* n_preallocs */
9733 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9734 I_("GtkIconViewAccessibleFactory"),
9742 gtk_icon_view_get_accessible (GtkWidget *widget)
9744 static gboolean first_time = TRUE;
9748 AtkObjectFactory *factory;
9749 AtkRegistry *registry;
9751 GType derived_atk_type;
9754 * Figure out whether accessibility is enabled by looking at the
9755 * type of the accessible object which would be created for
9756 * the parent type of GtkIconView.
9758 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9760 registry = atk_get_default_registry ();
9761 factory = atk_registry_get_factory (registry,
9763 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9764 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9765 atk_registry_set_factory_type (registry,
9767 gtk_icon_view_accessible_factory_get_type ());
9770 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9774 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9775 GtkBuilder *builder,
9777 const gchar *tagname,
9778 GMarkupParser *parser,
9781 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9782 tagname, parser, data))
9785 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9786 tagname, parser, data);
9790 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9791 GtkBuilder *builder,
9793 const gchar *tagname,
9796 if (strcmp (tagname, "attributes") == 0)
9797 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9800 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9806 #define __GTK_ICON_VIEW_C__
9807 #include "gtkaliasdef.c"