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, MAX (0, 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, MAX (0, 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;
1646 value = MIN (icon_view->priv->vadjustment->value +
1647 icon_view->priv->scroll_value_diff,
1648 icon_view->priv->vadjustment->upper -
1649 icon_view->priv->vadjustment->page_size);
1651 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1653 gtk_icon_view_update_rubberband (icon_view);
1659 gtk_icon_view_motion (GtkWidget *widget,
1660 GdkEventMotion *event)
1662 GtkIconView *icon_view;
1665 icon_view = GTK_ICON_VIEW (widget);
1667 gtk_icon_view_maybe_begin_drag (icon_view, event);
1669 if (icon_view->priv->doing_rubberband)
1671 gtk_icon_view_update_rubberband (widget);
1673 abs_y = event->y - icon_view->priv->height *
1674 (icon_view->priv->vadjustment->value /
1675 (icon_view->priv->vadjustment->upper -
1676 icon_view->priv->vadjustment->lower));
1678 if (abs_y < 0 || abs_y > widget->allocation.height)
1681 icon_view->priv->scroll_value_diff = abs_y;
1683 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1685 icon_view->priv->event_last_x = event->x;
1686 icon_view->priv->event_last_y = event->y;
1688 if (icon_view->priv->scroll_timeout_id == 0)
1689 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1693 remove_scroll_timeout (icon_view);
1700 gtk_icon_view_remove (GtkContainer *container,
1703 GtkIconView *icon_view;
1704 GtkIconViewChild *child = NULL;
1707 icon_view = GTK_ICON_VIEW (container);
1709 tmp_list = icon_view->priv->children;
1712 child = tmp_list->data;
1713 if (child->widget == widget)
1715 gtk_widget_unparent (widget);
1717 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1718 g_list_free_1 (tmp_list);
1723 tmp_list = tmp_list->next;
1728 gtk_icon_view_forall (GtkContainer *container,
1729 gboolean include_internals,
1730 GtkCallback callback,
1731 gpointer callback_data)
1733 GtkIconView *icon_view;
1734 GtkIconViewChild *child = NULL;
1737 icon_view = GTK_ICON_VIEW (container);
1739 tmp_list = icon_view->priv->children;
1742 child = tmp_list->data;
1743 tmp_list = tmp_list->next;
1745 (* callback) (child->widget, callback_data);
1750 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1751 GtkIconViewItem *item,
1752 GtkIconViewCellInfo *info,
1757 GdkRectangle cell_area;
1758 gboolean visible, mode;
1760 gtk_icon_view_set_cell_data (icon_view, item);
1762 g_object_get (info->cell,
1763 "visible", &visible,
1767 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1769 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1771 path = gtk_tree_path_new_from_indices (item->index, -1);
1772 path_string = gtk_tree_path_to_string (path);
1773 gtk_tree_path_free (path);
1775 gtk_cell_renderer_activate (info->cell,
1777 GTK_WIDGET (icon_view),
1783 g_free (path_string);
1788 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1789 GtkIconViewItem *item)
1792 AtkObject *item_obj;
1794 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1797 item_obj = atk_object_ref_accessible_child (obj, item->index);
1798 if (item_obj != NULL)
1800 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1801 g_object_unref (item_obj);
1807 gtk_icon_view_put (GtkIconView *icon_view,
1809 GtkIconViewItem *item,
1812 GtkIconViewChild *child;
1814 child = g_new (GtkIconViewChild, 1);
1816 child->widget = widget;
1820 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1822 if (GTK_WIDGET_REALIZED (icon_view))
1823 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1825 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1829 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1830 GtkIconView *icon_view)
1833 GtkIconViewItem *item;
1835 if (icon_view->priv->edited_item == NULL)
1838 item = icon_view->priv->edited_item;
1839 icon_view->priv->edited_item = NULL;
1840 icon_view->priv->editable = NULL;
1841 for (l = icon_view->priv->cell_list; l; l = l->next)
1843 GtkIconViewCellInfo *info = l->data;
1845 info->editing = FALSE;
1848 if (GTK_WIDGET_HAS_FOCUS (editable))
1849 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1851 g_signal_handlers_disconnect_by_func (editable,
1852 gtk_icon_view_remove_widget,
1855 gtk_container_remove (GTK_CONTAINER (icon_view),
1856 GTK_WIDGET (editable));
1858 gtk_icon_view_queue_draw_item (icon_view, item);
1863 gtk_icon_view_start_editing (GtkIconView *icon_view,
1864 GtkIconViewItem *item,
1865 GtkIconViewCellInfo *info,
1870 GdkRectangle cell_area;
1871 gboolean visible, mode;
1872 GtkCellEditable *editable;
1874 gtk_icon_view_set_cell_data (icon_view, item);
1876 g_object_get (info->cell,
1877 "visible", &visible,
1880 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1882 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1884 path = gtk_tree_path_new_from_indices (item->index, -1);
1885 path_string = gtk_tree_path_to_string (path);
1886 gtk_tree_path_free (path);
1888 editable = gtk_cell_renderer_start_editing (info->cell,
1890 GTK_WIDGET (icon_view),
1895 g_free (path_string);
1897 /* the rest corresponds to tree_view_real_start_editing... */
1898 icon_view->priv->edited_item = item;
1899 icon_view->priv->editable = editable;
1900 info->editing = TRUE;
1902 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1904 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1906 gtk_widget_grab_focus (GTK_WIDGET (editable));
1907 g_signal_connect (editable, "remove-widget",
1908 G_CALLBACK (gtk_icon_view_remove_widget),
1915 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1916 gboolean cancel_editing)
1918 GtkCellRenderer *cell = NULL;
1919 GtkIconViewItem *item;
1922 if (icon_view->priv->edited_item == NULL)
1926 * This is very evil. We need to do this, because
1927 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1928 * later on. If gtk_icon_view_row_changed notices
1929 * icon_view->priv->edited_item != NULL, it'll call
1930 * gtk_icon_view_stop_editing again. Bad things will happen then.
1932 * Please read that again if you intend to modify anything here.
1935 item = icon_view->priv->edited_item;
1936 icon_view->priv->edited_item = NULL;
1938 for (l = icon_view->priv->cell_list; l; l = l->next)
1940 GtkIconViewCellInfo *info = l->data;
1952 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1953 if (!cancel_editing)
1954 gtk_cell_editable_editing_done (icon_view->priv->editable);
1956 icon_view->priv->edited_item = item;
1958 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1962 * gtk_icon_view_set_cursor:
1963 * @icon_view: A #GtkIconView
1964 * @path: A #GtkTreePath
1965 * @cell: One of the cell renderers of @icon_view, or %NULL
1966 * @start_editing: %TRUE if the specified cell should start being edited.
1968 * Sets the current keyboard focus to be at @path, and selects it. This is
1969 * useful when you want to focus the user's attention on a particular item.
1970 * If @cell is not %NULL, then focus is given to the cell specified by
1971 * it. Additionally, if @start_editing is %TRUE, then editing should be
1972 * started in the specified cell.
1974 * This function is often followed by <literal>gtk_widget_grab_focus
1975 * (icon_view)</literal> in order to give keyboard focus to the widget.
1976 * Please note that editing can only happen when the widget is realized.
1981 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1983 GtkCellRenderer *cell,
1984 gboolean start_editing)
1986 GtkIconViewItem *item = NULL;
1987 GtkIconViewCellInfo *info = NULL;
1991 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1992 g_return_if_fail (path != NULL);
1993 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1995 gtk_icon_view_stop_editing (icon_view, TRUE);
1997 if (gtk_tree_path_get_depth (path) == 1)
1998 item = g_list_nth_data (icon_view->priv->items,
1999 gtk_tree_path_get_indices(path)[0]);
2005 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2009 if (info->cell == cell)
2018 g_return_if_fail (cell == NULL || info != NULL);
2020 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2021 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2023 if (info && start_editing)
2024 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2028 * gtk_icon_view_get_cursor:
2029 * @icon_view: A #GtkIconView
2030 * @path: Return location for the current cursor path, or %NULL
2031 * @cell: Return location the current focus cell, or %NULL
2033 * Fills in @path and @cell with the current cursor path and cell.
2034 * If the cursor isn't currently set, then *@path will be %NULL.
2035 * If no cell currently has focus, then *@cell will be %NULL.
2037 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2039 * Return value: %TRUE if the cursor is set.
2044 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2046 GtkCellRenderer **cell)
2048 GtkIconViewItem *item;
2049 GtkIconViewCellInfo *info;
2051 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2053 item = icon_view->priv->cursor_item;
2054 if (icon_view->priv->cursor_cell < 0)
2057 info = g_list_nth_data (icon_view->priv->cell_list,
2058 icon_view->priv->cursor_cell);
2063 *path = gtk_tree_path_new_from_indices (item->index, -1);
2076 return (item != NULL);
2080 gtk_icon_view_button_press (GtkWidget *widget,
2081 GdkEventButton *event)
2083 GtkIconView *icon_view;
2084 GtkIconViewItem *item;
2085 GtkIconViewCellInfo *info = NULL;
2086 gboolean dirty = FALSE;
2087 GtkCellRendererMode mode;
2088 gint cursor_cell = -1;
2090 icon_view = GTK_ICON_VIEW (widget);
2092 if (event->window != icon_view->priv->bin_window)
2095 if (!GTK_WIDGET_HAS_FOCUS (widget))
2096 gtk_widget_grab_focus (widget);
2098 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2100 item = gtk_icon_view_get_item_at_coords (icon_view,
2106 * We consider only the the cells' area as the item area if the
2107 * item is not selected, but if it *is* selected, the complete
2108 * selection rectangle is considered to be part of the item.
2110 if (item != NULL && (info != NULL || item->selected))
2114 g_object_get (info->cell, "mode", &mode, NULL);
2116 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2117 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2118 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2121 gtk_icon_view_scroll_to_item (icon_view, item);
2123 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2125 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2127 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2128 (event->state & GDK_SHIFT_MASK))
2130 gtk_icon_view_unselect_all_internal (icon_view);
2132 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2133 if (!icon_view->priv->anchor_item)
2134 icon_view->priv->anchor_item = item;
2136 gtk_icon_view_select_all_between (icon_view,
2137 icon_view->priv->anchor_item,
2143 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2144 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2145 (event->state & GDK_CONTROL_MASK))
2147 item->selected = !item->selected;
2148 gtk_icon_view_queue_draw_item (icon_view, item);
2153 gtk_icon_view_unselect_all_internal (icon_view);
2155 item->selected = TRUE;
2156 gtk_icon_view_queue_draw_item (icon_view, item);
2159 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2160 icon_view->priv->anchor_item = item;
2163 /* Save press to possibly begin a drag */
2164 if (icon_view->priv->pressed_button < 0)
2166 icon_view->priv->pressed_button = event->button;
2167 icon_view->priv->press_start_x = event->x;
2168 icon_view->priv->press_start_y = event->y;
2171 if (!icon_view->priv->last_single_clicked)
2172 icon_view->priv->last_single_clicked = item;
2174 /* cancel the current editing, if it exists */
2175 gtk_icon_view_stop_editing (icon_view, TRUE);
2179 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2180 gtk_icon_view_item_activate_cell (icon_view, item, info,
2182 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2183 gtk_icon_view_start_editing (icon_view, item, info,
2189 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2190 !(event->state & GDK_CONTROL_MASK))
2192 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2195 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2196 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2199 /* don't draw keyboard focus around an clicked-on item */
2200 icon_view->priv->draw_focus = FALSE;
2203 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2205 item = gtk_icon_view_get_item_at_coords (icon_view,
2210 if (item && item == icon_view->priv->last_single_clicked)
2214 path = gtk_tree_path_new_from_indices (item->index, -1);
2215 gtk_icon_view_item_activated (icon_view, path);
2216 gtk_tree_path_free (path);
2219 icon_view->priv->last_single_clicked = NULL;
2220 icon_view->priv->pressed_button = -1;
2224 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2226 return event->button == 1;
2230 gtk_icon_view_button_release (GtkWidget *widget,
2231 GdkEventButton *event)
2233 GtkIconView *icon_view;
2235 icon_view = GTK_ICON_VIEW (widget);
2237 if (icon_view->priv->pressed_button == event->button)
2238 icon_view->priv->pressed_button = -1;
2240 gtk_icon_view_stop_rubberbanding (icon_view);
2242 remove_scroll_timeout (icon_view);
2248 gtk_icon_view_key_press (GtkWidget *widget,
2251 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2253 if (icon_view->priv->doing_rubberband)
2255 if (event->keyval == GDK_Escape)
2256 gtk_icon_view_stop_rubberbanding (icon_view);
2261 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2265 gtk_icon_view_key_release (GtkWidget *widget,
2268 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2270 if (icon_view->priv->doing_rubberband)
2273 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2277 gtk_icon_view_update_rubberband (gpointer data)
2279 GtkIconView *icon_view;
2281 GdkRectangle old_area;
2282 GdkRectangle new_area;
2283 GdkRectangle common;
2284 GdkRegion *invalid_region;
2286 icon_view = GTK_ICON_VIEW (data);
2288 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2293 old_area.x = MIN (icon_view->priv->rubberband_x1,
2294 icon_view->priv->rubberband_x2);
2295 old_area.y = MIN (icon_view->priv->rubberband_y1,
2296 icon_view->priv->rubberband_y2);
2297 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2298 icon_view->priv->rubberband_x1) + 1;
2299 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2300 icon_view->priv->rubberband_y1) + 1;
2302 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2303 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2304 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2305 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2307 invalid_region = gdk_region_rectangle (&old_area);
2308 gdk_region_union_with_rect (invalid_region, &new_area);
2310 gdk_rectangle_intersect (&old_area, &new_area, &common);
2311 if (common.width > 2 && common.height > 2)
2313 GdkRegion *common_region;
2315 /* make sure the border is invalidated */
2321 common_region = gdk_region_rectangle (&common);
2323 gdk_region_subtract (invalid_region, common_region);
2324 gdk_region_destroy (common_region);
2327 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2329 gdk_region_destroy (invalid_region);
2331 icon_view->priv->rubberband_x2 = x;
2332 icon_view->priv->rubberband_y2 = y;
2334 gtk_icon_view_update_rubberband_selection (icon_view);
2338 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2344 g_assert (!icon_view->priv->doing_rubberband);
2346 for (items = icon_view->priv->items; items; items = items->next)
2348 GtkIconViewItem *item = items->data;
2350 item->selected_before_rubberbanding = item->selected;
2353 icon_view->priv->rubberband_x1 = x;
2354 icon_view->priv->rubberband_y1 = y;
2355 icon_view->priv->rubberband_x2 = x;
2356 icon_view->priv->rubberband_y2 = y;
2358 icon_view->priv->doing_rubberband = TRUE;
2360 gtk_grab_add (GTK_WIDGET (icon_view));
2364 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2366 if (!icon_view->priv->doing_rubberband)
2369 icon_view->priv->doing_rubberband = FALSE;
2371 gtk_grab_remove (GTK_WIDGET (icon_view));
2373 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2377 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2380 gint x, y, width, height;
2381 gboolean dirty = FALSE;
2383 x = MIN (icon_view->priv->rubberband_x1,
2384 icon_view->priv->rubberband_x2);
2385 y = MIN (icon_view->priv->rubberband_y1,
2386 icon_view->priv->rubberband_y2);
2387 width = ABS (icon_view->priv->rubberband_x1 -
2388 icon_view->priv->rubberband_x2);
2389 height = ABS (icon_view->priv->rubberband_y1 -
2390 icon_view->priv->rubberband_y2);
2392 for (items = icon_view->priv->items; items; items = items->next)
2394 GtkIconViewItem *item = items->data;
2398 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2399 x, y, width, height);
2401 selected = is_in ^ item->selected_before_rubberbanding;
2403 if (item->selected != selected)
2405 item->selected = selected;
2407 gtk_icon_view_queue_draw_item (icon_view, item);
2412 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2416 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2417 GtkIconViewItem *item,
2426 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2427 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2430 for (l = icon_view->priv->cell_list; l; l = l->next)
2432 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2434 if (!info->cell->visible)
2437 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2439 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2440 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2448 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2450 gboolean dirty = FALSE;
2453 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2456 for (items = icon_view->priv->items; items; items = items->next)
2458 GtkIconViewItem *item = items->data;
2462 item->selected = FALSE;
2464 gtk_icon_view_queue_draw_item (icon_view, item);
2465 gtk_icon_view_item_selected_changed (icon_view, item);
2473 /* GtkIconView signals */
2475 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2476 GtkAdjustment *hadj,
2477 GtkAdjustment *vadj)
2479 gboolean need_adjust = FALSE;
2482 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2484 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2486 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2488 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2490 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2492 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2493 0, 0, NULL, NULL, icon_view);
2494 g_object_unref (icon_view->priv->hadjustment);
2497 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2499 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2500 0, 0, NULL, NULL, icon_view);
2501 g_object_unref (icon_view->priv->vadjustment);
2504 if (icon_view->priv->hadjustment != hadj)
2506 icon_view->priv->hadjustment = hadj;
2507 g_object_ref_sink (icon_view->priv->hadjustment);
2509 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2510 G_CALLBACK (gtk_icon_view_adjustment_changed),
2515 if (icon_view->priv->vadjustment != vadj)
2517 icon_view->priv->vadjustment = vadj;
2518 g_object_ref_sink (icon_view->priv->vadjustment);
2520 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2521 G_CALLBACK (gtk_icon_view_adjustment_changed),
2527 gtk_icon_view_adjustment_changed (NULL, icon_view);
2531 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2533 gtk_icon_view_select_all (icon_view);
2537 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2539 gtk_icon_view_unselect_all (icon_view);
2543 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2545 gtk_icon_view_unselect_all (icon_view);
2547 if (icon_view->priv->cursor_item != NULL)
2548 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2552 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2555 GtkCellRendererMode mode;
2556 GtkIconViewCellInfo *info = NULL;
2558 if (!icon_view->priv->cursor_item)
2561 info = g_list_nth_data (icon_view->priv->cell_list,
2562 icon_view->priv->cursor_cell);
2566 g_object_get (info->cell, "mode", &mode, NULL);
2568 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2570 gtk_icon_view_item_activate_cell (icon_view,
2571 icon_view->priv->cursor_item,
2575 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2577 gtk_icon_view_start_editing (icon_view,
2578 icon_view->priv->cursor_item,
2584 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2585 gtk_icon_view_item_activated (icon_view, path);
2586 gtk_tree_path_free (path);
2592 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2594 if (!icon_view->priv->cursor_item)
2597 switch (icon_view->priv->selection_mode)
2599 case GTK_SELECTION_NONE:
2601 case GTK_SELECTION_BROWSE:
2602 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2604 case GTK_SELECTION_SINGLE:
2605 if (icon_view->priv->cursor_item->selected)
2606 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2608 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2610 case GTK_SELECTION_MULTIPLE:
2611 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2612 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2614 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2615 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2620 /* Internal functions */
2622 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2623 GtkIconView *icon_view)
2625 if (GTK_WIDGET_REALIZED (icon_view))
2627 gdk_window_move (icon_view->priv->bin_window,
2628 - icon_view->priv->hadjustment->value,
2629 - icon_view->priv->vadjustment->value);
2631 if (icon_view->priv->doing_rubberband)
2632 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2634 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2639 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2644 gint *maximum_width)
2647 gint x, current_width;
2648 GList *items, *last_item;
2655 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2656 max_height = g_new0 (gint, icon_view->priv->n_cells);
2663 gtk_widget_style_get (GTK_WIDGET (icon_view),
2664 "focus-line-width", &focus_width,
2667 x += icon_view->priv->margin + focus_width;
2668 current_width += 2 * (icon_view->priv->margin + focus_width);
2673 GtkIconViewItem *item = items->data;
2675 gtk_icon_view_calculate_item_size (icon_view, item);
2676 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2678 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2680 current_width += item->width;
2682 if (items != first_item)
2684 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2685 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2689 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2691 item->y = *y + focus_width;
2694 x = current_width - (icon_view->priv->margin + focus_width);
2696 for (i = 0; i < icon_view->priv->n_cells; i++)
2697 max_height[i] = MAX (max_height[i], item->box[i].height);
2699 if (current_width > *maximum_width)
2700 *maximum_width = current_width;
2706 items = items->next;
2711 /* Now go through the row again and align the icons */
2712 for (items = first_item; items != last_item; items = items->next)
2714 GtkIconViewItem *item = items->data;
2718 item->x = *maximum_width - item->width - item->x;
2719 item->col = col - 1 - item->col;
2722 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2724 /* We may want to readjust the new y coordinate. */
2725 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2726 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2729 g_free (max_height);
2735 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2738 if (upper != adj->upper)
2740 gdouble min = MAX (0.0, upper - adj->page_size);
2741 gboolean value_changed = FALSE;
2745 if (adj->value > min)
2748 value_changed = TRUE;
2751 gtk_adjustment_changed (adj);
2754 gtk_adjustment_value_changed (adj);
2759 gtk_icon_view_layout (GtkIconView *icon_view)
2761 gint y = 0, maximum_width = 0;
2767 if (icon_view->priv->layout_idle_id != 0)
2769 g_source_remove (icon_view->priv->layout_idle_id);
2770 icon_view->priv->layout_idle_id = 0;
2773 if (icon_view->priv->model == NULL)
2776 widget = GTK_WIDGET (icon_view);
2778 item_width = icon_view->priv->item_width;
2782 for (icons = icon_view->priv->items; icons; icons = icons->next)
2784 GtkIconViewItem *item = icons->data;
2785 gtk_icon_view_calculate_item_size (icon_view, item);
2786 item_width = MAX (item_width, item->width);
2791 icons = icon_view->priv->items;
2792 y += icon_view->priv->margin;
2797 gtk_icon_view_set_cell_data (icon_view, icons->data);
2798 adjust_wrap_width (icon_view, icons->data);
2803 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2805 &y, &maximum_width);
2808 while (icons != NULL);
2810 if (maximum_width != icon_view->priv->width)
2811 icon_view->priv->width = maximum_width;
2813 y += icon_view->priv->margin;
2815 if (y != icon_view->priv->height)
2816 icon_view->priv->height = y;
2818 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2819 icon_view->priv->width);
2820 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2821 icon_view->priv->height);
2823 if (icon_view->priv->width != widget->requisition.width ||
2824 icon_view->priv->height != widget->requisition.height)
2825 gtk_widget_queue_resize_no_redraw (widget);
2827 if (GTK_WIDGET_REALIZED (icon_view))
2828 gdk_window_resize (icon_view->priv->bin_window,
2829 MAX (icon_view->priv->width, widget->allocation.width),
2830 MAX (icon_view->priv->height, widget->allocation.height));
2832 if (icon_view->priv->scroll_to_path)
2836 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2837 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2838 icon_view->priv->scroll_to_path = NULL;
2840 gtk_icon_view_scroll_to_path (icon_view, path,
2841 icon_view->priv->scroll_to_use_align,
2842 icon_view->priv->scroll_to_row_align,
2843 icon_view->priv->scroll_to_col_align);
2844 gtk_tree_path_free (path);
2847 gtk_widget_queue_draw (widget);
2851 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2852 GtkIconViewItem *item,
2853 GtkIconViewCellInfo *info,
2854 GdkRectangle *cell_area)
2856 g_return_if_fail (info->position < item->n_cells);
2858 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2860 cell_area->x = item->box[info->position].x - item->before[info->position];
2861 cell_area->y = item->y + ITEM_PADDING;
2862 cell_area->width = item->box[info->position].width +
2863 item->before[info->position] + item->after[info->position];
2864 cell_area->height = item->height - ITEM_PADDING * 2;
2868 cell_area->x = item->x + ITEM_PADDING;
2869 cell_area->y = item->box[info->position].y - item->before[info->position];
2870 cell_area->width = item->width - ITEM_PADDING * 2;
2871 cell_area->height = item->box[info->position].height +
2872 item->before[info->position] + item->after[info->position];
2877 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2878 GtkIconViewItem *item,
2879 GtkIconViewCellInfo *info,
2882 g_return_if_fail (info->position < item->n_cells);
2884 *box = item->box[info->position];
2887 /* try to guess a reasonable wrap width for an implicit text cell renderer
2890 adjust_wrap_width (GtkIconView *icon_view,
2891 GtkIconViewItem *item)
2893 GtkIconViewCellInfo *text_info;
2894 GtkIconViewCellInfo *pixbuf_info;
2895 gint pixbuf_width, wrap_width;
2897 if (icon_view->priv->text_cell != -1 &&
2898 icon_view->priv->pixbuf_cell != -1)
2902 text_info = g_list_nth_data (icon_view->priv->cell_list,
2903 icon_view->priv->text_cell);
2904 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2905 icon_view->priv->pixbuf_cell);
2907 gtk_cell_renderer_get_size (pixbuf_info->cell,
2908 GTK_WIDGET (icon_view),
2914 if (icon_view->priv->item_width > 0)
2915 item_width = icon_view->priv->item_width;
2917 item_width = item->width;
2919 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2920 wrap_width = item_width;
2922 if (item->width == -1 && item_width <= 0)
2923 wrap_width = MAX (2 * pixbuf_width, 50);
2925 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;
4352 gfloat offset, value;
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);
4362 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4363 icon_view->priv->vadjustment->lower,
4364 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4365 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4367 offset = x + item->x - focus_width -
4368 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4369 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4370 icon_view->priv->hadjustment->lower,
4371 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4372 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4374 gtk_adjustment_changed (icon_view->priv->hadjustment);
4375 gtk_adjustment_changed (icon_view->priv->vadjustment);
4378 gtk_icon_view_scroll_to_item (icon_view, item);
4383 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4384 GtkIconViewItem *item)
4386 gint x, y, width, height;
4389 gtk_widget_style_get (GTK_WIDGET (icon_view),
4390 "focus-line-width", &focus_width,
4393 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4395 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4397 if (y + item->y - focus_width < 0)
4398 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4399 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4400 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4401 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4402 icon_view->priv->vadjustment->value + y + item->y + item->height
4403 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4405 if (x + item->x - focus_width < 0)
4406 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4407 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4408 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4409 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4410 icon_view->priv->hadjustment->value + x + item->x + item->width
4411 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4413 gtk_adjustment_changed (icon_view->priv->hadjustment);
4414 gtk_adjustment_changed (icon_view->priv->vadjustment);
4417 /* GtkCellLayout implementation */
4418 static GtkIconViewCellInfo *
4419 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4420 GtkCellRenderer *renderer)
4424 for (i = icon_view->priv->cell_list; i; i = i->next)
4426 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4428 if (info->cell == renderer)
4436 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4437 GtkIconViewItem *item)
4440 gboolean iters_persist;
4443 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4449 path = gtk_tree_path_new_from_indices (item->index, -1);
4450 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4452 gtk_tree_path_free (path);
4457 for (i = icon_view->priv->cell_list; i; i = i->next)
4460 GtkIconViewCellInfo *info = i->data;
4462 g_object_freeze_notify (G_OBJECT (info->cell));
4464 for (j = info->attributes; j && j->next; j = j->next->next)
4466 gchar *property = j->data;
4467 gint column = GPOINTER_TO_INT (j->next->data);
4468 GValue value = {0, };
4470 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4472 g_object_set_property (G_OBJECT (info->cell),
4474 g_value_unset (&value);
4478 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4480 icon_view->priv->model,
4484 g_object_thaw_notify (G_OBJECT (info->cell));
4489 free_cell_attributes (GtkIconViewCellInfo *info)
4493 list = info->attributes;
4494 while (list && list->next)
4496 g_free (list->data);
4497 list = list->next->next;
4500 g_slist_free (info->attributes);
4501 info->attributes = NULL;
4505 free_cell_info (GtkIconViewCellInfo *info)
4507 free_cell_attributes (info);
4509 g_object_unref (info->cell);
4512 (* info->destroy) (info->func_data);
4518 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4519 GtkCellRenderer *renderer,
4522 GtkIconViewCellInfo *info;
4523 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4525 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4526 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4528 g_object_ref_sink (renderer);
4530 info = g_new0 (GtkIconViewCellInfo, 1);
4531 info->cell = renderer;
4532 info->expand = expand ? TRUE : FALSE;
4533 info->pack = GTK_PACK_START;
4534 info->position = icon_view->priv->n_cells;
4536 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4537 icon_view->priv->n_cells++;
4541 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4542 GtkCellRenderer *renderer,
4545 GtkIconViewCellInfo *info;
4546 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4548 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4549 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4551 g_object_ref_sink (renderer);
4553 info = g_new0 (GtkIconViewCellInfo, 1);
4554 info->cell = renderer;
4555 info->expand = expand ? TRUE : FALSE;
4556 info->pack = GTK_PACK_END;
4557 info->position = icon_view->priv->n_cells;
4559 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4560 icon_view->priv->n_cells++;
4564 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4565 GtkCellRenderer *renderer,
4566 const gchar *attribute,
4569 GtkIconViewCellInfo *info;
4570 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4572 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4573 g_return_if_fail (info != NULL);
4575 info->attributes = g_slist_prepend (info->attributes,
4576 GINT_TO_POINTER (column));
4577 info->attributes = g_slist_prepend (info->attributes,
4578 g_strdup (attribute));
4582 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4584 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4586 while (icon_view->priv->cell_list)
4588 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4589 free_cell_info (info);
4590 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4591 icon_view->priv->cell_list);
4594 icon_view->priv->n_cells = 0;
4598 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4599 GtkCellRenderer *cell,
4600 GtkCellLayoutDataFunc func,
4602 GDestroyNotify destroy)
4604 GtkIconViewCellInfo *info;
4605 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4607 info = gtk_icon_view_get_cell_info (icon_view, cell);
4608 g_return_if_fail (info != NULL);
4612 GDestroyNotify d = info->destroy;
4614 info->destroy = NULL;
4615 d (info->func_data);
4619 info->func_data = func_data;
4620 info->destroy = destroy;
4624 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4625 GtkCellRenderer *renderer)
4627 GtkIconViewCellInfo *info;
4629 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4631 free_cell_attributes (info);
4635 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4636 GtkCellRenderer *cell,
4639 GtkIconView *icon_view;
4641 GtkIconViewCellInfo *info;
4644 icon_view = GTK_ICON_VIEW (layout);
4646 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4648 info = gtk_icon_view_get_cell_info (icon_view, cell);
4650 g_return_if_fail (info != NULL);
4651 g_return_if_fail (position >= 0);
4653 link = g_list_find (icon_view->priv->cell_list, info);
4655 g_return_if_fail (link != NULL);
4657 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4659 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4662 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4669 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4673 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4675 GtkIconView *icon_view = (GtkIconView *)layout;
4676 GList *retval = NULL, *l;
4678 for (l = icon_view->priv->cell_list; l; l = l->next)
4680 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4682 retval = g_list_prepend (retval, info->cell);
4685 return g_list_reverse (retval);
4692 * gtk_icon_view_new:
4694 * Creates a new #GtkIconView widget
4696 * Return value: A newly created #GtkIconView widget
4701 gtk_icon_view_new (void)
4703 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4707 * gtk_icon_view_new_with_model:
4708 * @model: The model.
4710 * Creates a new #GtkIconView widget with the model @model.
4712 * Return value: A newly created #GtkIconView widget.
4717 gtk_icon_view_new_with_model (GtkTreeModel *model)
4719 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4723 * gtk_icon_view_convert_widget_to_bin_window_coords:
4724 * @icon_view: a #GtkIconView
4725 * @wx: X coordinate relative to the widget
4726 * @wy: Y coordinate relative to the widget
4727 * @bx: return location for bin_window X coordinate
4728 * @by: return location for bin_window Y coordinate
4730 * Converts widget coordinates to coordinates for the bin_window,
4731 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4736 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4744 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4746 if (icon_view->priv->bin_window)
4747 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4758 * gtk_icon_view_get_path_at_pos:
4759 * @icon_view: A #GtkIconView.
4760 * @x: The x position to be identified
4761 * @y: The y position to be identified
4763 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4764 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4765 * the cell at the specified position.
4766 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4767 * widget coordinates to bin_window coordinates.
4769 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4770 * if no icon exists at that position.
4775 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4779 GtkIconViewItem *item;
4782 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4784 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4789 path = gtk_tree_path_new_from_indices (item->index, -1);
4795 * gtk_icon_view_get_item_at_pos:
4796 * @icon_view: A #GtkIconView.
4797 * @x: The x position to be identified
4798 * @y: The y position to be identified
4799 * @path: Return location for the path, or %NULL
4800 * @cell: Return location for the renderer responsible for the cell
4801 * at (@x, @y), or %NULL
4803 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4804 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4805 * obtains the cell at the specified position. The returned path should
4806 * be freed with gtk_tree_path_free().
4807 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4808 * widget coordinates to bin_window coordinates.
4810 * Return value: %TRUE if an item exists at the specified position
4815 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4819 GtkCellRenderer **cell)
4821 GtkIconViewItem *item;
4822 GtkIconViewCellInfo *info;
4824 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4826 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4831 *path = gtk_tree_path_new_from_indices (item->index, -1);
4844 return (item != NULL);
4848 * gtk_icon_view_set_tooltip_item:
4849 * @icon_view: a #GtkIconView
4850 * @tooltip: a #GtkTooltip
4851 * @path: a #GtkTreePath
4853 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4854 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4855 * See also gtk_tooltip_set_tip_area().
4860 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4861 GtkTooltip *tooltip,
4864 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4865 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4867 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4871 * gtk_icon_view_set_tooltip_cell:
4872 * @icon_view: a #GtkIconView
4873 * @tooltip: a #GtkTooltip
4874 * @path: a #GtkTreePath
4875 * @cell: a #GtkCellRenderer or %NULL
4877 * Sets the tip area of @tooltip to the area which @cell occupies in
4878 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4880 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4885 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4886 GtkTooltip *tooltip,
4888 GtkCellRenderer *cell)
4891 GtkIconViewItem *item = NULL;
4892 GtkIconViewCellInfo *info = NULL;
4895 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4896 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4897 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4899 if (gtk_tree_path_get_depth (path) > 0)
4900 item = g_list_nth_data (icon_view->priv->items,
4901 gtk_tree_path_get_indices(path)[0]);
4908 info = gtk_icon_view_get_cell_info (icon_view, cell);
4909 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4915 rect.width = item->width;
4916 rect.height = item->height;
4919 if (icon_view->priv->bin_window)
4921 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4926 gtk_tooltip_set_tip_area (tooltip, &rect);
4931 * gtk_icon_view_get_tooltip_context:
4932 * @icon_view: an #GtkIconView
4933 * @x: the x coordinate (relative to widget coordinates)
4934 * @y: the y coordinate (relative to widget coordinates)
4935 * @keyboard_tip: whether this is a keyboard tooltip or not
4936 * @model: a pointer to receive a #GtkTreeModel or %NULL
4937 * @path: a pointer to receive a #GtkTreePath or %NULL
4938 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4940 * This function is supposed to be used in a #GtkWidget::query-tooltip
4941 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4942 * which are received in the signal handler, should be passed to this
4943 * function without modification.
4945 * The return value indicates whether there is an icon view item at the given
4946 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4947 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4948 * @model, @path and @iter which have been provided will be set to point to
4949 * that row and the corresponding model. @x and @y will always be converted
4950 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4952 * Return value: whether or not the given tooltip context points to a item
4957 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4960 gboolean keyboard_tip,
4961 GtkTreeModel **model,
4965 GtkTreePath *tmppath = NULL;
4967 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4968 g_return_val_if_fail (x != NULL, FALSE);
4969 g_return_val_if_fail (y != NULL, FALSE);
4973 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4980 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4983 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4988 *model = gtk_icon_view_get_model (icon_view);
4991 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4997 gtk_tree_path_free (tmppath);
5003 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5006 gboolean keyboard_tip,
5007 GtkTooltip *tooltip,
5013 GtkTreeModel *model;
5014 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5016 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5019 &model, &path, &iter))
5022 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5026 gtk_tree_path_free (path);
5030 gtk_tooltip_set_markup (tooltip, str);
5031 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5033 gtk_tree_path_free (path);
5041 * gtk_icon_view_set_tooltip_column:
5042 * @icon_view: a #GtkIconView
5043 * @column: an integer, which is a valid column number for @icon_view's model
5045 * If you only plan to have simple (text-only) tooltips on full items, you
5046 * can use this function to have #GtkIconView handle these automatically
5047 * for you. @column should be set to the column in @icon_view's model
5048 * containing the tooltip texts, or -1 to disable this feature.
5050 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5051 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5056 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5059 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5061 if (column == icon_view->priv->tooltip_column)
5066 g_signal_handlers_disconnect_by_func (icon_view,
5067 gtk_icon_view_set_tooltip_query_cb,
5069 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5073 if (icon_view->priv->tooltip_column == -1)
5075 g_signal_connect (icon_view, "query-tooltip",
5076 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5077 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5081 icon_view->priv->tooltip_column = column;
5082 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5086 * gtk_icon_view_get_tooltip_column:
5087 * @icon_view: a #GtkIconView
5089 * Returns the column of @icon_view's model which is being used for
5090 * displaying tooltips on @icon_view's rows.
5092 * Return value: the index of the tooltip column that is currently being
5093 * used, or -1 if this is disabled.
5098 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5100 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5102 return icon_view->priv->tooltip_column;
5106 * gtk_icon_view_get_visible_range:
5107 * @icon_view: A #GtkIconView
5108 * @start_path: Return location for start of region, or %NULL
5109 * @end_path: Return location for end of region, or %NULL
5111 * Sets @start_path and @end_path to be the first and last visible path.
5112 * Note that there may be invisible paths in between.
5114 * Both paths should be freed with gtk_tree_path_free() after use.
5116 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5121 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5122 GtkTreePath **start_path,
5123 GtkTreePath **end_path)
5125 gint start_index = -1;
5126 gint end_index = -1;
5129 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5131 if (icon_view->priv->hadjustment == NULL ||
5132 icon_view->priv->vadjustment == NULL)
5135 if (start_path == NULL && end_path == NULL)
5138 for (icons = icon_view->priv->items; icons; icons = icons->next)
5140 GtkIconViewItem *item = icons->data;
5142 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5143 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5144 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5145 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5147 if (start_index == -1)
5148 start_index = item->index;
5149 end_index = item->index;
5153 if (start_path && start_index != -1)
5154 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5155 if (end_path && end_index != -1)
5156 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5158 return start_index != -1;
5162 * gtk_icon_view_selected_foreach:
5163 * @icon_view: A #GtkIconView.
5164 * @func: The funcion to call for each selected icon.
5165 * @data: User data to pass to the function.
5167 * Calls a function for each selected icon. Note that the model or
5168 * selection cannot be modified from within this function.
5173 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5174 GtkIconViewForeachFunc func,
5179 for (list = icon_view->priv->items; list; list = list->next)
5181 GtkIconViewItem *item = list->data;
5182 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5185 (* func) (icon_view, path, data);
5187 gtk_tree_path_free (path);
5192 * gtk_icon_view_set_selection_mode:
5193 * @icon_view: A #GtkIconView.
5194 * @mode: The selection mode
5196 * Sets the selection mode of the @icon_view.
5201 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5202 GtkSelectionMode mode)
5204 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5206 if (mode == icon_view->priv->selection_mode)
5209 if (mode == GTK_SELECTION_NONE ||
5210 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5211 gtk_icon_view_unselect_all (icon_view);
5213 icon_view->priv->selection_mode = mode;
5215 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5219 * gtk_icon_view_get_selection_mode:
5220 * @icon_view: A #GtkIconView.
5222 * Gets the selection mode of the @icon_view.
5224 * Return value: the current selection mode
5229 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5231 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5233 return icon_view->priv->selection_mode;
5237 * gtk_icon_view_set_model:
5238 * @icon_view: A #GtkIconView.
5239 * @model: The model.
5241 * Sets the model for a #GtkIconView.
5242 * If the @icon_view already has a model set, it will remove
5243 * it before setting the new model. If @model is %NULL, then
5244 * it will unset the old model.
5249 gtk_icon_view_set_model (GtkIconView *icon_view,
5250 GtkTreeModel *model)
5252 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5253 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5255 if (icon_view->priv->model == model)
5258 if (icon_view->priv->scroll_to_path)
5260 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5261 icon_view->priv->scroll_to_path = NULL;
5264 gtk_icon_view_stop_editing (icon_view, TRUE);
5270 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5272 if (icon_view->priv->pixbuf_column != -1)
5274 column_type = gtk_tree_model_get_column_type (model,
5275 icon_view->priv->pixbuf_column);
5277 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5280 if (icon_view->priv->text_column != -1)
5282 column_type = gtk_tree_model_get_column_type (model,
5283 icon_view->priv->text_column);
5285 g_return_if_fail (column_type == G_TYPE_STRING);
5288 if (icon_view->priv->markup_column != -1)
5290 column_type = gtk_tree_model_get_column_type (model,
5291 icon_view->priv->markup_column);
5293 g_return_if_fail (column_type == G_TYPE_STRING);
5298 if (icon_view->priv->model)
5300 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5301 gtk_icon_view_row_changed,
5303 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5304 gtk_icon_view_row_inserted,
5306 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5307 gtk_icon_view_row_deleted,
5309 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5310 gtk_icon_view_rows_reordered,
5313 g_object_unref (icon_view->priv->model);
5315 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5316 g_list_free (icon_view->priv->items);
5317 icon_view->priv->items = NULL;
5318 icon_view->priv->anchor_item = NULL;
5319 icon_view->priv->cursor_item = NULL;
5320 icon_view->priv->last_single_clicked = NULL;
5321 icon_view->priv->width = 0;
5322 icon_view->priv->height = 0;
5325 icon_view->priv->model = model;
5327 if (icon_view->priv->model)
5329 g_object_ref (icon_view->priv->model);
5330 g_signal_connect (icon_view->priv->model,
5332 G_CALLBACK (gtk_icon_view_row_changed),
5334 g_signal_connect (icon_view->priv->model,
5336 G_CALLBACK (gtk_icon_view_row_inserted),
5338 g_signal_connect (icon_view->priv->model,
5340 G_CALLBACK (gtk_icon_view_row_deleted),
5342 g_signal_connect (icon_view->priv->model,
5344 G_CALLBACK (gtk_icon_view_rows_reordered),
5347 gtk_icon_view_build_items (icon_view);
5349 gtk_icon_view_queue_layout (icon_view);
5352 g_object_notify (G_OBJECT (icon_view), "model");
5354 if (GTK_WIDGET_REALIZED (icon_view))
5355 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5359 * gtk_icon_view_get_model:
5360 * @icon_view: a #GtkIconView
5362 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5365 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5370 gtk_icon_view_get_model (GtkIconView *icon_view)
5372 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5374 return icon_view->priv->model;
5378 update_text_cell (GtkIconView *icon_view)
5380 GtkIconViewCellInfo *info;
5384 if (icon_view->priv->text_column == -1 &&
5385 icon_view->priv->markup_column == -1)
5387 if (icon_view->priv->text_cell != -1)
5389 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5390 icon_view->priv->pixbuf_cell--;
5392 info = g_list_nth_data (icon_view->priv->cell_list,
5393 icon_view->priv->text_cell);
5395 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5397 free_cell_info (info);
5399 icon_view->priv->n_cells--;
5400 icon_view->priv->text_cell = -1;
5405 if (icon_view->priv->text_cell == -1)
5407 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5408 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5409 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5412 if (info->cell == cell)
5414 icon_view->priv->text_cell = i;
5420 info = g_list_nth_data (icon_view->priv->cell_list,
5421 icon_view->priv->text_cell);
5423 if (icon_view->priv->markup_column != -1)
5424 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5426 "markup", icon_view->priv->markup_column,
5429 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5431 "text", icon_view->priv->text_column,
5434 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5435 g_object_set (info->cell,
5436 "alignment", PANGO_ALIGN_CENTER,
5437 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5442 g_object_set (info->cell,
5443 "alignment", PANGO_ALIGN_LEFT,
5444 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5452 update_pixbuf_cell (GtkIconView *icon_view)
5454 GtkIconViewCellInfo *info;
5458 if (icon_view->priv->pixbuf_column == -1)
5460 if (icon_view->priv->pixbuf_cell != -1)
5462 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5463 icon_view->priv->text_cell--;
5465 info = g_list_nth_data (icon_view->priv->cell_list,
5466 icon_view->priv->pixbuf_cell);
5468 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5470 free_cell_info (info);
5472 icon_view->priv->n_cells--;
5473 icon_view->priv->pixbuf_cell = -1;
5478 if (icon_view->priv->pixbuf_cell == -1)
5480 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5482 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5483 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5486 if (info->cell == cell)
5488 icon_view->priv->pixbuf_cell = i;
5494 info = g_list_nth_data (icon_view->priv->cell_list,
5495 icon_view->priv->pixbuf_cell);
5497 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5499 "pixbuf", icon_view->priv->pixbuf_column,
5502 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5503 g_object_set (info->cell,
5508 g_object_set (info->cell,
5516 * gtk_icon_view_set_text_column:
5517 * @icon_view: A #GtkIconView.
5518 * @column: A column in the currently used model, or -1 to display no text
5520 * Sets the column with text for @icon_view to be @column. The text
5521 * column must be of type #G_TYPE_STRING.
5526 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5529 if (column == icon_view->priv->text_column)
5533 icon_view->priv->text_column = -1;
5536 if (icon_view->priv->model != NULL)
5540 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5542 g_return_if_fail (column_type == G_TYPE_STRING);
5545 icon_view->priv->text_column = column;
5548 gtk_icon_view_stop_editing (icon_view, TRUE);
5550 update_text_cell (icon_view);
5552 gtk_icon_view_invalidate_sizes (icon_view);
5553 gtk_icon_view_queue_layout (icon_view);
5555 g_object_notify (G_OBJECT (icon_view), "text-column");
5559 * gtk_icon_view_get_text_column:
5560 * @icon_view: A #GtkIconView.
5562 * Returns the column with text for @icon_view.
5564 * Returns: the text column, or -1 if it's unset.
5569 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5571 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5573 return icon_view->priv->text_column;
5577 * gtk_icon_view_set_markup_column:
5578 * @icon_view: A #GtkIconView.
5579 * @column: A column in the currently used model, or -1 to display no text
5581 * Sets the column with markup information for @icon_view to be
5582 * @column. The markup column must be of type #G_TYPE_STRING.
5583 * If the markup column is set to something, it overrides
5584 * the text column set by gtk_icon_view_set_text_column().
5589 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5592 if (column == icon_view->priv->markup_column)
5596 icon_view->priv->markup_column = -1;
5599 if (icon_view->priv->model != NULL)
5603 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5605 g_return_if_fail (column_type == G_TYPE_STRING);
5608 icon_view->priv->markup_column = column;
5611 gtk_icon_view_stop_editing (icon_view, TRUE);
5613 update_text_cell (icon_view);
5615 gtk_icon_view_invalidate_sizes (icon_view);
5616 gtk_icon_view_queue_layout (icon_view);
5618 g_object_notify (G_OBJECT (icon_view), "markup-column");
5622 * gtk_icon_view_get_markup_column:
5623 * @icon_view: A #GtkIconView.
5625 * Returns the column with markup text for @icon_view.
5627 * Returns: the markup column, or -1 if it's unset.
5632 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5634 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5636 return icon_view->priv->markup_column;
5640 * gtk_icon_view_set_pixbuf_column:
5641 * @icon_view: A #GtkIconView.
5642 * @column: A column in the currently used model, or -1 to disable
5644 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5645 * column must be of type #GDK_TYPE_PIXBUF
5650 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5653 if (column == icon_view->priv->pixbuf_column)
5657 icon_view->priv->pixbuf_column = -1;
5660 if (icon_view->priv->model != NULL)
5664 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5666 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5669 icon_view->priv->pixbuf_column = column;
5672 gtk_icon_view_stop_editing (icon_view, TRUE);
5674 update_pixbuf_cell (icon_view);
5676 gtk_icon_view_invalidate_sizes (icon_view);
5677 gtk_icon_view_queue_layout (icon_view);
5679 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5684 * gtk_icon_view_get_pixbuf_column:
5685 * @icon_view: A #GtkIconView.
5687 * Returns the column with pixbufs for @icon_view.
5689 * Returns: the pixbuf column, or -1 if it's unset.
5694 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5696 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5698 return icon_view->priv->pixbuf_column;
5702 * gtk_icon_view_select_path:
5703 * @icon_view: A #GtkIconView.
5704 * @path: The #GtkTreePath to be selected.
5706 * Selects the row at @path.
5711 gtk_icon_view_select_path (GtkIconView *icon_view,
5714 GtkIconViewItem *item = NULL;
5716 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5717 g_return_if_fail (icon_view->priv->model != NULL);
5718 g_return_if_fail (path != NULL);
5720 if (gtk_tree_path_get_depth (path) > 0)
5721 item = g_list_nth_data (icon_view->priv->items,
5722 gtk_tree_path_get_indices(path)[0]);
5725 gtk_icon_view_select_item (icon_view, item);
5729 * gtk_icon_view_unselect_path:
5730 * @icon_view: A #GtkIconView.
5731 * @path: The #GtkTreePath to be unselected.
5733 * Unselects the row at @path.
5738 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5741 GtkIconViewItem *item;
5743 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5744 g_return_if_fail (icon_view->priv->model != NULL);
5745 g_return_if_fail (path != NULL);
5747 item = g_list_nth_data (icon_view->priv->items,
5748 gtk_tree_path_get_indices(path)[0]);
5753 gtk_icon_view_unselect_item (icon_view, item);
5757 * gtk_icon_view_get_selected_items:
5758 * @icon_view: A #GtkIconView.
5760 * Creates a list of paths of all selected items. Additionally, if you are
5761 * planning on modifying the model after calling this function, you may
5762 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5763 * To do this, you can use gtk_tree_row_reference_new().
5765 * To free the return value, use:
5767 * g_list_foreach (list, gtk_tree_path_free, NULL);
5768 * g_list_free (list);
5771 * Return value: A #GList containing a #GtkTreePath for each selected row.
5776 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5779 GList *selected = NULL;
5781 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5783 for (list = icon_view->priv->items; list != NULL; list = list->next)
5785 GtkIconViewItem *item = list->data;
5789 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5791 selected = g_list_prepend (selected, path);
5799 * gtk_icon_view_select_all:
5800 * @icon_view: A #GtkIconView.
5802 * Selects all the icons. @icon_view must has its selection mode set
5803 * to #GTK_SELECTION_MULTIPLE.
5808 gtk_icon_view_select_all (GtkIconView *icon_view)
5811 gboolean dirty = FALSE;
5813 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5815 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5818 for (items = icon_view->priv->items; items; items = items->next)
5820 GtkIconViewItem *item = items->data;
5822 if (!item->selected)
5825 item->selected = TRUE;
5826 gtk_icon_view_queue_draw_item (icon_view, item);
5831 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5835 * gtk_icon_view_unselect_all:
5836 * @icon_view: A #GtkIconView.
5838 * Unselects all the icons.
5843 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5845 gboolean dirty = FALSE;
5847 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5849 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5852 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5855 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5859 * gtk_icon_view_path_is_selected:
5860 * @icon_view: A #GtkIconView.
5861 * @path: A #GtkTreePath to check selection on.
5863 * Returns %TRUE if the icon pointed to by @path is currently
5864 * selected. If @path does not point to a valid location, %FALSE is returned.
5866 * Return value: %TRUE if @path is selected.
5871 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5874 GtkIconViewItem *item;
5876 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5877 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5878 g_return_val_if_fail (path != NULL, FALSE);
5880 item = g_list_nth_data (icon_view->priv->items,
5881 gtk_tree_path_get_indices(path)[0]);
5886 return item->selected;
5890 * gtk_icon_view_item_activated:
5891 * @icon_view: A #GtkIconView
5892 * @path: The #GtkTreePath to be activated
5894 * Activates the item determined by @path.
5899 gtk_icon_view_item_activated (GtkIconView *icon_view,
5902 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5903 g_return_if_fail (path != NULL);
5905 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5909 * gtk_icon_view_set_orientation:
5910 * @icon_view: a #GtkIconView
5911 * @orientation: the relative position of texts and icons
5913 * Sets the ::orientation property which determines whether the labels
5914 * are drawn beside the icons instead of below.
5919 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5920 GtkOrientation orientation)
5922 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5924 if (icon_view->priv->orientation != orientation)
5926 icon_view->priv->orientation = orientation;
5928 gtk_icon_view_stop_editing (icon_view, TRUE);
5929 gtk_icon_view_invalidate_sizes (icon_view);
5930 gtk_icon_view_queue_layout (icon_view);
5932 update_text_cell (icon_view);
5933 update_pixbuf_cell (icon_view);
5935 g_object_notify (G_OBJECT (icon_view), "orientation");
5940 * gtk_icon_view_get_orientation:
5941 * @icon_view: a #GtkIconView
5943 * Returns the value of the ::orientation property which determines
5944 * whether the labels are drawn beside the icons instead of below.
5946 * Return value: the relative position of texts and icons
5951 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5953 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5954 GTK_ORIENTATION_VERTICAL);
5956 return icon_view->priv->orientation;
5960 * gtk_icon_view_set_columns:
5961 * @icon_view: a #GtkIconView
5962 * @columns: the number of columns
5964 * Sets the ::columns property which determines in how
5965 * many columns the icons are arranged. If @columns is
5966 * -1, the number of columns will be chosen automatically
5967 * to fill the available area.
5972 gtk_icon_view_set_columns (GtkIconView *icon_view,
5975 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5977 if (icon_view->priv->columns != columns)
5979 icon_view->priv->columns = columns;
5981 gtk_icon_view_stop_editing (icon_view, TRUE);
5982 gtk_icon_view_queue_layout (icon_view);
5984 g_object_notify (G_OBJECT (icon_view), "columns");
5989 * gtk_icon_view_get_columns:
5990 * @icon_view: a #GtkIconView
5992 * Returns the value of the ::columns property.
5994 * Return value: the number of columns, or -1
5999 gtk_icon_view_get_columns (GtkIconView *icon_view)
6001 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6003 return icon_view->priv->columns;
6007 * gtk_icon_view_set_item_width:
6008 * @icon_view: a #GtkIconView
6009 * @item_width: the width for each item
6011 * Sets the ::item-width property which specifies the width
6012 * to use for each item. If it is set to -1, the icon view will
6013 * automatically determine a suitable item size.
6018 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6021 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6023 if (icon_view->priv->item_width != item_width)
6025 icon_view->priv->item_width = item_width;
6027 gtk_icon_view_stop_editing (icon_view, TRUE);
6028 gtk_icon_view_invalidate_sizes (icon_view);
6029 gtk_icon_view_queue_layout (icon_view);
6031 update_text_cell (icon_view);
6033 g_object_notify (G_OBJECT (icon_view), "item-width");
6038 * gtk_icon_view_get_item_width:
6039 * @icon_view: a #GtkIconView
6041 * Returns the value of the ::item-width property.
6043 * Return value: the width of a single item, or -1
6048 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6050 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6052 return icon_view->priv->item_width;
6057 * gtk_icon_view_set_spacing:
6058 * @icon_view: a #GtkIconView
6059 * @spacing: the spacing
6061 * Sets the ::spacing property which specifies the space
6062 * which is inserted between the cells (i.e. the icon and
6063 * the text) of an item.
6068 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6071 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6073 if (icon_view->priv->spacing != spacing)
6075 icon_view->priv->spacing = spacing;
6077 gtk_icon_view_stop_editing (icon_view, TRUE);
6078 gtk_icon_view_invalidate_sizes (icon_view);
6079 gtk_icon_view_queue_layout (icon_view);
6081 g_object_notify (G_OBJECT (icon_view), "spacing");
6086 * gtk_icon_view_get_spacing:
6087 * @icon_view: a #GtkIconView
6089 * Returns the value of the ::spacing property.
6091 * Return value: the space between cells
6096 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6098 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6100 return icon_view->priv->spacing;
6104 * gtk_icon_view_set_row_spacing:
6105 * @icon_view: a #GtkIconView
6106 * @row_spacing: the row spacing
6108 * Sets the ::row-spacing property which specifies the space
6109 * which is inserted between the rows of the icon view.
6114 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6117 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6119 if (icon_view->priv->row_spacing != row_spacing)
6121 icon_view->priv->row_spacing = row_spacing;
6123 gtk_icon_view_stop_editing (icon_view, TRUE);
6124 gtk_icon_view_invalidate_sizes (icon_view);
6125 gtk_icon_view_queue_layout (icon_view);
6127 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6132 * gtk_icon_view_get_row_spacing:
6133 * @icon_view: a #GtkIconView
6135 * Returns the value of the ::row-spacing property.
6137 * Return value: the space between rows
6142 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6144 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6146 return icon_view->priv->row_spacing;
6150 * gtk_icon_view_set_column_spacing:
6151 * @icon_view: a #GtkIconView
6152 * @column_spacing: the column spacing
6154 * Sets the ::column-spacing property which specifies the space
6155 * which is inserted between the columns of the icon view.
6160 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6161 gint column_spacing)
6163 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6165 if (icon_view->priv->column_spacing != column_spacing)
6167 icon_view->priv->column_spacing = column_spacing;
6169 gtk_icon_view_stop_editing (icon_view, TRUE);
6170 gtk_icon_view_invalidate_sizes (icon_view);
6171 gtk_icon_view_queue_layout (icon_view);
6173 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6178 * gtk_icon_view_get_column_spacing:
6179 * @icon_view: a #GtkIconView
6181 * Returns the value of the ::column-spacing property.
6183 * Return value: the space between columns
6188 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6190 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6192 return icon_view->priv->column_spacing;
6196 * gtk_icon_view_set_margin:
6197 * @icon_view: a #GtkIconView
6198 * @margin: the margin
6200 * Sets the ::margin property which specifies the space
6201 * which is inserted at the top, bottom, left and right
6207 gtk_icon_view_set_margin (GtkIconView *icon_view,
6210 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6212 if (icon_view->priv->margin != margin)
6214 icon_view->priv->margin = margin;
6216 gtk_icon_view_stop_editing (icon_view, TRUE);
6217 gtk_icon_view_invalidate_sizes (icon_view);
6218 gtk_icon_view_queue_layout (icon_view);
6220 g_object_notify (G_OBJECT (icon_view), "margin");
6225 * gtk_icon_view_get_margin:
6226 * @icon_view: a #GtkIconView
6228 * Returns the value of the ::margin property.
6230 * Return value: the space at the borders
6235 gtk_icon_view_get_margin (GtkIconView *icon_view)
6237 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6239 return icon_view->priv->margin;
6243 /* Get/set whether drag_motion requested the drag data and
6244 * drag_data_received should thus not actually insert the data,
6245 * since the data doesn't result from a drop.
6248 set_status_pending (GdkDragContext *context,
6249 GdkDragAction suggested_action)
6251 g_object_set_data (G_OBJECT (context),
6252 I_("gtk-icon-view-status-pending"),
6253 GINT_TO_POINTER (suggested_action));
6256 static GdkDragAction
6257 get_status_pending (GdkDragContext *context)
6259 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6260 "gtk-icon-view-status-pending"));
6264 unset_reorderable (GtkIconView *icon_view)
6266 if (icon_view->priv->reorderable)
6268 icon_view->priv->reorderable = FALSE;
6269 g_object_notify (G_OBJECT (icon_view), "reorderable");
6274 set_source_row (GdkDragContext *context,
6275 GtkTreeModel *model,
6276 GtkTreePath *source_row)
6279 g_object_set_data_full (G_OBJECT (context),
6280 I_("gtk-icon-view-source-row"),
6281 gtk_tree_row_reference_new (model, source_row),
6282 (GDestroyNotify) gtk_tree_row_reference_free);
6284 g_object_set_data_full (G_OBJECT (context),
6285 I_("gtk-icon-view-source-row"),
6290 get_source_row (GdkDragContext *context)
6292 GtkTreeRowReference *ref;
6294 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6297 return gtk_tree_row_reference_get_path (ref);
6304 GtkTreeRowReference *dest_row;
6305 gboolean empty_view_drop;
6306 gboolean drop_append_mode;
6310 dest_row_free (gpointer data)
6312 DestRow *dr = (DestRow *)data;
6314 gtk_tree_row_reference_free (dr->dest_row);
6319 set_dest_row (GdkDragContext *context,
6320 GtkTreeModel *model,
6321 GtkTreePath *dest_row,
6322 gboolean empty_view_drop,
6323 gboolean drop_append_mode)
6329 g_object_set_data_full (G_OBJECT (context),
6330 I_("gtk-icon-view-dest-row"),
6335 dr = g_new0 (DestRow, 1);
6337 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6338 dr->empty_view_drop = empty_view_drop;
6339 dr->drop_append_mode = drop_append_mode;
6340 g_object_set_data_full (G_OBJECT (context),
6341 I_("gtk-icon-view-dest-row"),
6342 dr, (GDestroyNotify) dest_row_free);
6346 get_dest_row (GdkDragContext *context)
6350 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6354 GtkTreePath *path = NULL;
6357 path = gtk_tree_row_reference_get_path (dr->dest_row);
6358 else if (dr->empty_view_drop)
6359 path = gtk_tree_path_new_from_indices (0, -1);
6363 if (path && dr->drop_append_mode)
6364 gtk_tree_path_next (path);
6373 check_model_dnd (GtkTreeModel *model,
6374 GType required_iface,
6375 const gchar *signal)
6377 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6379 g_warning ("You must override the default '%s' handler "
6380 "on GtkIconView when using models that don't support "
6381 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6382 "is to connect to '%s' and call "
6383 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6384 "the default handler from running. Look at the source code "
6385 "for the default handler in gtkiconview.c to get an idea what "
6386 "your handler should do. (gtkiconview.c is in the GTK+ source "
6387 "code.) If you're using GTK+ from a language other than C, "
6388 "there may be a more natural way to override default handlers, e.g. via derivation.",
6389 signal, g_type_name (required_iface), signal);
6397 remove_scroll_timeout (GtkIconView *icon_view)
6399 if (icon_view->priv->scroll_timeout_id != 0)
6401 g_source_remove (icon_view->priv->scroll_timeout_id);
6403 icon_view->priv->scroll_timeout_id = 0;
6408 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6410 gint px, py, x, y, width, height;
6411 gint hoffset, voffset;
6414 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6415 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6417 /* see if we are near the edge. */
6418 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6420 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6422 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6424 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6428 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6429 icon_view->priv->vadjustment->lower,
6430 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6431 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6435 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6436 icon_view->priv->hadjustment->lower,
6437 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6438 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6444 drag_scroll_timeout (gpointer data)
6446 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6448 gtk_icon_view_autoscroll (icon_view);
6455 set_destination (GtkIconView *icon_view,
6456 GdkDragContext *context,
6459 GdkDragAction *suggested_action,
6463 GtkTreePath *path = NULL;
6464 GtkIconViewDropPosition pos;
6465 GtkIconViewDropPosition old_pos;
6466 GtkTreePath *old_dest_path = NULL;
6467 gboolean can_drop = FALSE;
6469 widget = GTK_WIDGET (icon_view);
6471 *suggested_action = 0;
6474 if (!icon_view->priv->dest_set)
6476 /* someone unset us as a drag dest, note that if
6477 * we return FALSE drag_leave isn't called
6480 gtk_icon_view_set_drag_dest_item (icon_view,
6482 GTK_ICON_VIEW_DROP_LEFT);
6484 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6486 return FALSE; /* no longer a drop site */
6489 *target = gtk_drag_dest_find_target (widget, context,
6490 gtk_drag_dest_get_target_list (widget));
6491 if (*target == GDK_NONE)
6494 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6497 GtkTreeModel *model;
6499 /* the row got dropped on empty space, let's setup a special case
6503 gtk_tree_path_free (path);
6505 model = gtk_icon_view_get_model (icon_view);
6507 n_children = gtk_tree_model_iter_n_children (model, NULL);
6510 pos = GTK_ICON_VIEW_DROP_BELOW;
6511 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6515 pos = GTK_ICON_VIEW_DROP_ABOVE;
6516 path = gtk_tree_path_new_from_indices (0, -1);
6526 gtk_icon_view_get_drag_dest_item (icon_view,
6531 gtk_tree_path_free (old_dest_path);
6533 if (TRUE /* FIXME if the location droppable predicate */)
6541 GtkWidget *source_widget;
6543 *suggested_action = context->suggested_action;
6544 source_widget = gtk_drag_get_source_widget (context);
6546 if (source_widget == widget)
6548 /* Default to MOVE, unless the user has
6549 * pressed ctrl or shift to affect available actions
6551 if ((context->actions & GDK_ACTION_MOVE) != 0)
6552 *suggested_action = GDK_ACTION_MOVE;
6555 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6560 /* can't drop here */
6561 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6563 GTK_ICON_VIEW_DROP_LEFT);
6567 gtk_tree_path_free (path);
6573 get_logical_destination (GtkIconView *icon_view,
6574 gboolean *drop_append_mode)
6576 /* adjust path to point to the row the drop goes in front of */
6577 GtkTreePath *path = NULL;
6578 GtkIconViewDropPosition pos;
6580 *drop_append_mode = FALSE;
6582 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6587 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6588 pos == GTK_ICON_VIEW_DROP_BELOW)
6591 GtkTreeModel *model = icon_view->priv->model;
6593 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6594 !gtk_tree_model_iter_next (model, &iter))
6595 *drop_append_mode = TRUE;
6598 *drop_append_mode = FALSE;
6599 gtk_tree_path_next (path);
6607 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6608 GdkEventMotion *event)
6610 GtkWidget *widget = GTK_WIDGET (icon_view);
6611 GdkDragContext *context;
6612 GtkTreePath *path = NULL;
6614 GtkTreeModel *model;
6615 gboolean retval = FALSE;
6617 if (!icon_view->priv->source_set)
6620 if (icon_view->priv->pressed_button < 0)
6623 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6624 icon_view->priv->press_start_x,
6625 icon_view->priv->press_start_y,
6626 event->x, event->y))
6629 model = gtk_icon_view_get_model (icon_view);
6634 button = icon_view->priv->pressed_button;
6635 icon_view->priv->pressed_button = -1;
6637 path = gtk_icon_view_get_path_at_pos (icon_view,
6638 icon_view->priv->press_start_x,
6639 icon_view->priv->press_start_y);
6644 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6645 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6649 /* FIXME Check whether we're a start button, if not return FALSE and
6653 /* Now we can begin the drag */
6657 context = gtk_drag_begin (widget,
6658 gtk_drag_source_get_target_list (widget),
6659 icon_view->priv->source_actions,
6663 set_source_row (context, model, path);
6667 gtk_tree_path_free (path);
6672 /* Source side drag signals */
6674 gtk_icon_view_drag_begin (GtkWidget *widget,
6675 GdkDragContext *context)
6677 GtkIconView *icon_view;
6678 GtkIconViewItem *item;
6683 icon_view = GTK_ICON_VIEW (widget);
6685 /* if the user uses a custom DnD impl, we don't set the icon here */
6686 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6689 item = gtk_icon_view_get_item_at_coords (icon_view,
6690 icon_view->priv->press_start_x,
6691 icon_view->priv->press_start_y,
6695 g_return_if_fail (item != NULL);
6697 x = icon_view->priv->press_start_x - item->x + 1;
6698 y = icon_view->priv->press_start_y - item->y + 1;
6700 path = gtk_tree_path_new_from_indices (item->index, -1);
6701 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6702 gtk_tree_path_free (path);
6704 gtk_drag_set_icon_pixmap (context,
6705 gdk_drawable_get_colormap (icon),
6710 g_object_unref (icon);
6714 gtk_icon_view_drag_end (GtkWidget *widget,
6715 GdkDragContext *context)
6721 gtk_icon_view_drag_data_get (GtkWidget *widget,
6722 GdkDragContext *context,
6723 GtkSelectionData *selection_data,
6727 GtkIconView *icon_view;
6728 GtkTreeModel *model;
6729 GtkTreePath *source_row;
6731 icon_view = GTK_ICON_VIEW (widget);
6732 model = gtk_icon_view_get_model (icon_view);
6737 if (!icon_view->priv->source_set)
6740 source_row = get_source_row (context);
6742 if (source_row == NULL)
6745 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6746 * any model; for DragSource models there are some other targets
6750 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6751 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6756 /* If drag_data_get does nothing, try providing row data. */
6757 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6758 gtk_tree_set_row_drag_data (selection_data,
6763 gtk_tree_path_free (source_row);
6767 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6768 GdkDragContext *context)
6770 GtkTreeModel *model;
6771 GtkIconView *icon_view;
6772 GtkTreePath *source_row;
6774 icon_view = GTK_ICON_VIEW (widget);
6775 model = gtk_icon_view_get_model (icon_view);
6777 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6780 if (!icon_view->priv->source_set)
6783 source_row = get_source_row (context);
6785 if (source_row == NULL)
6788 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6791 gtk_tree_path_free (source_row);
6793 set_source_row (context, NULL, NULL);
6796 /* Target side drag signals */
6798 gtk_icon_view_drag_leave (GtkWidget *widget,
6799 GdkDragContext *context,
6802 GtkIconView *icon_view;
6804 icon_view = GTK_ICON_VIEW (widget);
6806 /* unset any highlight row */
6807 gtk_icon_view_set_drag_dest_item (icon_view,
6809 GTK_ICON_VIEW_DROP_LEFT);
6811 remove_scroll_timeout (icon_view);
6815 gtk_icon_view_drag_motion (GtkWidget *widget,
6816 GdkDragContext *context,
6821 GtkTreePath *path = NULL;
6822 GtkIconViewDropPosition pos;
6823 GtkIconView *icon_view;
6824 GdkDragAction suggested_action = 0;
6828 icon_view = GTK_ICON_VIEW (widget);
6830 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6833 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6835 /* we only know this *after* set_desination_row */
6836 empty = icon_view->priv->empty_view_drop;
6838 if (path == NULL && !empty)
6840 /* Can't drop here. */
6841 gdk_drag_status (context, 0, time);
6845 if (icon_view->priv->scroll_timeout_id == 0)
6847 icon_view->priv->scroll_timeout_id =
6848 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6851 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6853 /* Request data so we can use the source row when
6854 * determining whether to accept the drop
6856 set_status_pending (context, suggested_action);
6857 gtk_drag_get_data (widget, context, target, time);
6861 set_status_pending (context, 0);
6862 gdk_drag_status (context, suggested_action, time);
6867 gtk_tree_path_free (path);
6873 gtk_icon_view_drag_drop (GtkWidget *widget,
6874 GdkDragContext *context,
6879 GtkIconView *icon_view;
6881 GdkDragAction suggested_action = 0;
6882 GdkAtom target = GDK_NONE;
6883 GtkTreeModel *model;
6884 gboolean drop_append_mode;
6886 icon_view = GTK_ICON_VIEW (widget);
6887 model = gtk_icon_view_get_model (icon_view);
6889 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6891 if (!icon_view->priv->dest_set)
6894 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6897 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6900 path = get_logical_destination (icon_view, &drop_append_mode);
6902 if (target != GDK_NONE && path != NULL)
6904 /* in case a motion had requested drag data, change things so we
6905 * treat drag data receives as a drop.
6907 set_status_pending (context, 0);
6908 set_dest_row (context, model, path,
6909 icon_view->priv->empty_view_drop, drop_append_mode);
6913 gtk_tree_path_free (path);
6915 /* Unset this thing */
6916 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6918 if (target != GDK_NONE)
6920 gtk_drag_get_data (widget, context, target, time);
6928 gtk_icon_view_drag_data_received (GtkWidget *widget,
6929 GdkDragContext *context,
6932 GtkSelectionData *selection_data,
6937 gboolean accepted = FALSE;
6938 GtkTreeModel *model;
6939 GtkIconView *icon_view;
6940 GtkTreePath *dest_row;
6941 GdkDragAction suggested_action;
6942 gboolean drop_append_mode;
6944 icon_view = GTK_ICON_VIEW (widget);
6945 model = gtk_icon_view_get_model (icon_view);
6947 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6950 if (!icon_view->priv->dest_set)
6953 suggested_action = get_status_pending (context);
6955 if (suggested_action)
6957 /* We are getting this data due to a request in drag_motion,
6958 * rather than due to a request in drag_drop, so we are just
6959 * supposed to call drag_status, not actually paste in the
6962 path = get_logical_destination (icon_view, &drop_append_mode);
6965 suggested_action = 0;
6967 if (suggested_action)
6969 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6972 suggested_action = 0;
6975 gdk_drag_status (context, suggested_action, time);
6978 gtk_tree_path_free (path);
6980 /* If you can't drop, remove user drop indicator until the next motion */
6981 if (suggested_action == 0)
6982 gtk_icon_view_set_drag_dest_item (icon_view,
6984 GTK_ICON_VIEW_DROP_LEFT);
6989 dest_row = get_dest_row (context);
6991 if (dest_row == NULL)
6994 if (selection_data->length >= 0)
6996 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7002 gtk_drag_finish (context,
7004 (context->action == GDK_ACTION_MOVE),
7007 gtk_tree_path_free (dest_row);
7010 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7013 /* Drag-and-Drop support */
7015 * gtk_icon_view_enable_model_drag_source:
7016 * @icon_view: a #GtkIconTreeView
7017 * @start_button_mask: Mask of allowed buttons to start drag
7018 * @targets: the table of targets that the drag will support
7019 * @n_targets: the number of items in @targets
7020 * @actions: the bitmask of possible actions for a drag from this
7023 * Turns @icon_view into a drag source for automatic DND. Calling this
7024 * method sets #GtkIconView:reorderable to %FALSE.
7029 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7030 GdkModifierType start_button_mask,
7031 const GtkTargetEntry *targets,
7033 GdkDragAction actions)
7035 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7037 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7039 icon_view->priv->start_button_mask = start_button_mask;
7040 icon_view->priv->source_actions = actions;
7042 icon_view->priv->source_set = TRUE;
7044 unset_reorderable (icon_view);
7048 * gtk_icon_view_enable_model_drag_dest:
7049 * @icon_view: a #GtkIconView
7050 * @targets: the table of targets that the drag will support
7051 * @n_targets: the number of items in @targets
7052 * @actions: the bitmask of possible actions for a drag to this
7055 * Turns @icon_view into a drop destination for automatic DND. Calling this
7056 * method sets #GtkIconView:reorderable to %FALSE.
7061 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7062 const GtkTargetEntry *targets,
7064 GdkDragAction actions)
7066 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7068 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7070 icon_view->priv->dest_actions = actions;
7072 icon_view->priv->dest_set = TRUE;
7074 unset_reorderable (icon_view);
7078 * gtk_icon_view_unset_model_drag_source:
7079 * @icon_view: a #GtkIconView
7081 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7082 * method sets #GtkIconView:reorderable to %FALSE.
7087 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7089 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7091 if (icon_view->priv->source_set)
7093 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7094 icon_view->priv->source_set = FALSE;
7097 unset_reorderable (icon_view);
7101 * gtk_icon_view_unset_model_drag_dest:
7102 * @icon_view: a #GtkIconView
7104 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7105 * method sets #GtkIconView:reorderable to %FALSE.
7110 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7112 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7114 if (icon_view->priv->dest_set)
7116 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7117 icon_view->priv->dest_set = FALSE;
7120 unset_reorderable (icon_view);
7123 /* These are useful to implement your own custom stuff. */
7125 * gtk_icon_view_set_drag_dest_item:
7126 * @icon_view: a #GtkIconView
7127 * @path: The path of the item to highlight, or %NULL.
7128 * @pos: Specifies where to drop, relative to the item
7130 * Sets the item that is highlighted for feedback.
7135 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7137 GtkIconViewDropPosition pos)
7139 /* Note; this function is exported to allow a custom DND
7140 * implementation, so it can't touch TreeViewDragInfo
7143 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7145 if (icon_view->priv->dest_item)
7147 GtkTreePath *current_path;
7148 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7149 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7150 icon_view->priv->dest_item = NULL;
7152 gtk_icon_view_queue_draw_path (icon_view, current_path);
7153 gtk_tree_path_free (current_path);
7156 /* special case a drop on an empty model */
7157 icon_view->priv->empty_view_drop = FALSE;
7158 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7159 && gtk_tree_path_get_depth (path) == 1
7160 && gtk_tree_path_get_indices (path)[0] == 0)
7164 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7167 if (n_children == 0)
7168 icon_view->priv->empty_view_drop = TRUE;
7171 icon_view->priv->dest_pos = pos;
7175 icon_view->priv->dest_item =
7176 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7177 icon_view->priv->model, path);
7179 gtk_icon_view_queue_draw_path (icon_view, path);
7184 * gtk_icon_view_get_drag_dest_item:
7185 * @icon_view: a #GtkIconView
7186 * @path: Return location for the path of the highlighted item, or %NULL.
7187 * @pos: Return location for the drop position, or %NULL
7189 * Gets information about the item that is highlighted for feedback.
7194 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7196 GtkIconViewDropPosition *pos)
7198 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7202 if (icon_view->priv->dest_item)
7203 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7209 *pos = icon_view->priv->dest_pos;
7213 * gtk_icon_view_get_dest_item_at_pos:
7214 * @icon_view: a #GtkIconView
7215 * @drag_x: the position to determine the destination item for
7216 * @drag_y: the position to determine the destination item for
7217 * @path: Return location for the path of the item, or %NULL.
7218 * @pos: Return location for the drop position, or %NULL
7220 * Determines the destination item for a given position.
7222 * Return value: whether there is an item at the given position.
7227 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7231 GtkIconViewDropPosition *pos)
7233 GtkIconViewItem *item;
7235 /* Note; this function is exported to allow a custom DND
7236 * implementation, so it can't touch TreeViewDragInfo
7239 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7240 g_return_val_if_fail (drag_x >= 0, FALSE);
7241 g_return_val_if_fail (drag_y >= 0, FALSE);
7242 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7248 item = gtk_icon_view_get_item_at_coords (icon_view,
7249 drag_x + icon_view->priv->hadjustment->value,
7250 drag_y + icon_view->priv->vadjustment->value,
7257 *path = gtk_tree_path_new_from_indices (item->index, -1);
7261 if (drag_x < item->x + item->width / 4)
7262 *pos = GTK_ICON_VIEW_DROP_LEFT;
7263 else if (drag_x > item->x + item->width * 3 / 4)
7264 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7265 else if (drag_y < item->y + item->height / 4)
7266 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7267 else if (drag_y > item->y + item->height * 3 / 4)
7268 *pos = GTK_ICON_VIEW_DROP_BELOW;
7270 *pos = GTK_ICON_VIEW_DROP_INTO;
7277 * gtk_icon_view_create_drag_icon:
7278 * @icon_view: a #GtkIconView
7279 * @path: a #GtkTreePath in @icon_view
7281 * Creates a #GdkPixmap representation of the item at @path.
7282 * This image is used for a drag icon.
7284 * Return value: a newly-allocated pixmap of the drag icon.
7289 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7294 GdkPixmap *drawable;
7299 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7300 g_return_val_if_fail (path != NULL, NULL);
7302 widget = GTK_WIDGET (icon_view);
7304 if (!GTK_WIDGET_REALIZED (widget))
7307 index = gtk_tree_path_get_indices (path)[0];
7309 for (l = icon_view->priv->items; l; l = l->next)
7311 GtkIconViewItem *item = l->data;
7313 if (index == item->index)
7315 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7320 cr = gdk_cairo_create (drawable);
7321 cairo_set_line_width (cr, 1.);
7323 gdk_cairo_set_source_color
7324 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7325 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7330 area.width = item->width;
7331 area.height = item->height;
7333 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7334 drawable, 1, 1, FALSE);
7336 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7337 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7350 * gtk_icon_view_get_reorderable:
7351 * @icon_view: a #GtkIconView
7353 * Retrieves whether the user can reorder the list via drag-and-drop.
7354 * See gtk_icon_view_set_reorderable().
7356 * Return value: %TRUE if the list can be reordered.
7361 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7363 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7365 return icon_view->priv->reorderable;
7368 static const GtkTargetEntry item_targets[] = {
7369 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7374 * gtk_icon_view_set_reorderable:
7375 * @icon_view: A #GtkIconView.
7376 * @reorderable: %TRUE, if the list of items can be reordered.
7378 * This function is a convenience function to allow you to reorder models that
7379 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7380 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7381 * the user can reorder the model by dragging and dropping rows. The
7382 * developer can listen to these changes by connecting to the model's
7383 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7384 * the icon view as a drag source and destination. Therefore, drag and
7385 * drop can not be used in a reorderable view for any other purpose.
7387 * This function does not give you any degree of control over the order -- any
7388 * reordering is allowed. If more control is needed, you should probably
7389 * handle drag and drop manually.
7394 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7395 gboolean reorderable)
7397 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7399 reorderable = reorderable != FALSE;
7401 if (icon_view->priv->reorderable == reorderable)
7406 gtk_icon_view_enable_model_drag_source (icon_view,
7409 G_N_ELEMENTS (item_targets),
7411 gtk_icon_view_enable_model_drag_dest (icon_view,
7413 G_N_ELEMENTS (item_targets),
7418 gtk_icon_view_unset_model_drag_source (icon_view);
7419 gtk_icon_view_unset_model_drag_dest (icon_view);
7422 icon_view->priv->reorderable = reorderable;
7424 g_object_notify (G_OBJECT (icon_view), "reorderable");
7428 /* Accessibility Support */
7430 static gpointer accessible_parent_class;
7431 static gpointer accessible_item_parent_class;
7432 static GQuark accessible_private_data_quark = 0;
7434 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7435 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7436 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7438 static GType gtk_icon_view_item_accessible_get_type (void);
7449 GtkIconViewItem *item;
7453 AtkStateSet *state_set;
7457 GtkTextBuffer *text_buffer;
7459 gchar *action_descriptions[LAST_ACTION];
7460 gchar *image_description;
7461 guint action_idle_handler;
7462 } GtkIconViewItemAccessible;
7464 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7470 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7475 typedef struct _GtkIconViewItemAccessibleClass
7477 AtkObjectClass parent_class;
7479 } GtkIconViewItemAccessibleClass;
7481 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7484 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7486 GtkIconViewItemAccessible *item;
7487 GtkIconView *icon_view;
7490 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7491 item->action_idle_handler = 0;
7493 if (item->widget != NULL)
7495 icon_view = GTK_ICON_VIEW (item->widget);
7496 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7497 gtk_icon_view_item_activated (icon_view, path);
7498 gtk_tree_path_free (path);
7505 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7508 GtkIconViewItemAccessible *item;
7510 if (i < 0 || i >= LAST_ACTION)
7513 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7515 if (!GTK_IS_ICON_VIEW (item->widget))
7518 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7523 case ACTION_ACTIVATE:
7524 if (!item->action_idle_handler)
7525 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7528 g_assert_not_reached ();
7536 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7541 static const gchar *
7542 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7545 GtkIconViewItemAccessible *item;
7547 if (i < 0 || i >= LAST_ACTION)
7550 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7552 if (item->action_descriptions[i])
7553 return item->action_descriptions[i];
7555 return gtk_icon_view_item_accessible_action_descriptions[i];
7558 static const gchar *
7559 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7562 if (i < 0 || i >= LAST_ACTION)
7565 return gtk_icon_view_item_accessible_action_names[i];
7569 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7571 const gchar *description)
7573 GtkIconViewItemAccessible *item;
7575 if (i < 0 || i >= LAST_ACTION)
7578 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7580 g_free (item->action_descriptions[i]);
7582 item->action_descriptions[i] = g_strdup (description);
7588 atk_action_item_interface_init (AtkActionIface *iface)
7590 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7591 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7592 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7593 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7594 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7597 static const gchar *
7598 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7600 GtkIconViewItemAccessible *item;
7602 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7604 return item->image_description;
7608 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7609 const gchar *description)
7611 GtkIconViewItemAccessible *item;
7613 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7615 g_free (item->image_description);
7616 item->image_description = g_strdup (description);
7622 get_pixbuf_box (GtkIconView *icon_view,
7623 GtkIconViewItem *item,
7628 for (l = icon_view->priv->cell_list; l; l = l->next)
7630 GtkIconViewCellInfo *info = l->data;
7632 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7634 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7644 get_text (GtkIconView *icon_view,
7645 GtkIconViewItem *item)
7650 for (l = icon_view->priv->cell_list; l; l = l->next)
7652 GtkIconViewCellInfo *info = l->data;
7654 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7656 g_object_get (info->cell, "text", &text, NULL);
7666 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7670 GtkIconViewItemAccessible *item;
7673 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7675 if (!GTK_IS_ICON_VIEW (item->widget))
7678 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7681 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7684 *height = box.height;
7689 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7692 AtkCoordType coord_type)
7694 GtkIconViewItemAccessible *item;
7697 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7699 if (!GTK_IS_ICON_VIEW (item->widget))
7702 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7705 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7707 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7709 *x+= box.x - item->item->x;
7710 *y+= box.y - item->item->y;
7716 atk_image_item_interface_init (AtkImageIface *iface)
7718 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7719 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7720 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7721 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7725 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7729 GtkIconViewItemAccessible *item;
7730 GtkTextIter start, end;
7731 GtkTextBuffer *buffer;
7733 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7735 if (!GTK_IS_ICON_VIEW (item->widget))
7738 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7741 buffer = item->text_buffer;
7742 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7744 gtk_text_buffer_get_end_iter (buffer, &end);
7746 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7748 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7752 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7755 GtkIconViewItemAccessible *item;
7756 GtkTextIter start, end;
7757 GtkTextBuffer *buffer;
7761 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7763 if (!GTK_IS_ICON_VIEW (item->widget))
7766 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7769 buffer = item->text_buffer;
7770 if (offset >= gtk_text_buffer_get_char_count (buffer))
7773 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7775 gtk_text_iter_forward_char (&end);
7776 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7777 unichar = g_utf8_get_char (string);
7785 get_pango_text_offsets (PangoLayout *layout,
7786 GtkTextBuffer *buffer,
7788 AtkTextBoundary boundary_type,
7792 GtkTextIter *start_iter,
7793 GtkTextIter *end_iter)
7795 PangoLayoutIter *iter;
7796 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7797 gint index, start_index, end_index;
7799 gboolean found = FALSE;
7801 text = pango_layout_get_text (layout);
7802 index = g_utf8_offset_to_pointer (text, offset) - text;
7803 iter = pango_layout_get_iter (layout);
7806 line = pango_layout_iter_get_line_readonly (iter);
7807 start_index = line->start_index;
7808 end_index = start_index + line->length;
7810 if (index >= start_index && index <= end_index)
7813 * Found line for offset
7819 * We want the previous line
7823 switch (boundary_type)
7825 case ATK_TEXT_BOUNDARY_LINE_START:
7826 end_index = start_index;
7827 start_index = prev_line->start_index;
7829 case ATK_TEXT_BOUNDARY_LINE_END:
7831 start_index = prev_prev_line->start_index +
7832 prev_prev_line->length;
7833 end_index = prev_line->start_index + prev_line->length;
7836 g_assert_not_reached();
7840 start_index = end_index = 0;
7843 switch (boundary_type)
7845 case ATK_TEXT_BOUNDARY_LINE_START:
7846 if (pango_layout_iter_next_line (iter))
7847 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7849 case ATK_TEXT_BOUNDARY_LINE_END:
7851 start_index = prev_line->start_index +
7855 g_assert_not_reached();
7860 * We want the next line
7862 if (pango_layout_iter_next_line (iter))
7864 line = pango_layout_iter_get_line_readonly (iter);
7865 switch (boundary_type)
7867 case ATK_TEXT_BOUNDARY_LINE_START:
7868 start_index = line->start_index;
7869 if (pango_layout_iter_next_line (iter))
7870 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7872 end_index = start_index + line->length;
7874 case ATK_TEXT_BOUNDARY_LINE_END:
7875 start_index = end_index;
7876 end_index = line->start_index + line->length;
7879 g_assert_not_reached();
7883 start_index = end_index;
7889 prev_prev_line = prev_line;
7892 while (pango_layout_iter_next_line (iter));
7896 start_index = prev_line->start_index + prev_line->length;
7897 end_index = start_index;
7899 pango_layout_iter_free (iter);
7900 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7901 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7903 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7904 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7909 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7911 AtkTextBoundary boundary_type,
7915 GtkIconViewItemAccessible *item;
7916 GtkTextIter start, end;
7917 GtkTextBuffer *buffer;
7919 GtkIconView *icon_view;
7922 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7924 if (!GTK_IS_ICON_VIEW (item->widget))
7927 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7930 buffer = item->text_buffer;
7932 if (!gtk_text_buffer_get_char_count (buffer))
7936 return g_strdup ("");
7938 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7942 switch (boundary_type)
7944 case ATK_TEXT_BOUNDARY_CHAR:
7945 gtk_text_iter_backward_char(&start);
7947 case ATK_TEXT_BOUNDARY_WORD_START:
7948 if (!gtk_text_iter_starts_word (&start))
7949 gtk_text_iter_backward_word_start (&start);
7951 gtk_text_iter_backward_word_start(&start);
7953 case ATK_TEXT_BOUNDARY_WORD_END:
7954 if (gtk_text_iter_inside_word (&start) &&
7955 !gtk_text_iter_starts_word (&start))
7956 gtk_text_iter_backward_word_start (&start);
7957 while (!gtk_text_iter_ends_word (&start))
7959 if (!gtk_text_iter_backward_char (&start))
7963 gtk_text_iter_backward_word_start(&start);
7964 while (!gtk_text_iter_ends_word (&start))
7966 if (!gtk_text_iter_backward_char (&start))
7970 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7971 if (!gtk_text_iter_starts_sentence (&start))
7972 gtk_text_iter_backward_sentence_start (&start);
7974 gtk_text_iter_backward_sentence_start (&start);
7976 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7977 if (gtk_text_iter_inside_sentence (&start) &&
7978 !gtk_text_iter_starts_sentence (&start))
7979 gtk_text_iter_backward_sentence_start (&start);
7980 while (!gtk_text_iter_ends_sentence (&start))
7982 if (!gtk_text_iter_backward_char (&start))
7986 gtk_text_iter_backward_sentence_start (&start);
7987 while (!gtk_text_iter_ends_sentence (&start))
7989 if (!gtk_text_iter_backward_char (&start))
7993 case ATK_TEXT_BOUNDARY_LINE_START:
7994 case ATK_TEXT_BOUNDARY_LINE_END:
7996 icon_view = GTK_ICON_VIEW (item->widget);
7997 /* FIXME we probably have to use GailTextCell to salvage this */
7998 gtk_icon_view_update_item_text (icon_view, item->item);
7999 get_pango_text_offsets (icon_view->priv->layout,
8012 *start_offset = gtk_text_iter_get_offset (&start);
8013 *end_offset = gtk_text_iter_get_offset (&end);
8015 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8019 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8021 AtkTextBoundary boundary_type,
8025 GtkIconViewItemAccessible *item;
8026 GtkTextIter start, end;
8027 GtkTextBuffer *buffer;
8029 GtkIconView *icon_view;
8032 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8034 if (!GTK_IS_ICON_VIEW (item->widget))
8037 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8040 buffer = item->text_buffer;
8042 if (!gtk_text_buffer_get_char_count (buffer))
8046 return g_strdup ("");
8048 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8052 switch (boundary_type)
8054 case ATK_TEXT_BOUNDARY_CHAR:
8055 gtk_text_iter_forward_char (&end);
8057 case ATK_TEXT_BOUNDARY_WORD_START:
8058 if (!gtk_text_iter_starts_word (&start))
8059 gtk_text_iter_backward_word_start (&start);
8060 if (gtk_text_iter_inside_word (&end))
8061 gtk_text_iter_forward_word_end (&end);
8062 while (!gtk_text_iter_starts_word (&end))
8064 if (!gtk_text_iter_forward_char (&end))
8068 case ATK_TEXT_BOUNDARY_WORD_END:
8069 if (gtk_text_iter_inside_word (&start) &&
8070 !gtk_text_iter_starts_word (&start))
8071 gtk_text_iter_backward_word_start (&start);
8072 while (!gtk_text_iter_ends_word (&start))
8074 if (!gtk_text_iter_backward_char (&start))
8077 gtk_text_iter_forward_word_end (&end);
8079 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8080 if (!gtk_text_iter_starts_sentence (&start))
8081 gtk_text_iter_backward_sentence_start (&start);
8082 if (gtk_text_iter_inside_sentence (&end))
8083 gtk_text_iter_forward_sentence_end (&end);
8084 while (!gtk_text_iter_starts_sentence (&end))
8086 if (!gtk_text_iter_forward_char (&end))
8090 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8091 if (gtk_text_iter_inside_sentence (&start) &&
8092 !gtk_text_iter_starts_sentence (&start))
8093 gtk_text_iter_backward_sentence_start (&start);
8094 while (!gtk_text_iter_ends_sentence (&start))
8096 if (!gtk_text_iter_backward_char (&start))
8099 gtk_text_iter_forward_sentence_end (&end);
8101 case ATK_TEXT_BOUNDARY_LINE_START:
8102 case ATK_TEXT_BOUNDARY_LINE_END:
8104 icon_view = GTK_ICON_VIEW (item->widget);
8105 /* FIXME we probably have to use GailTextCell to salvage this */
8106 gtk_icon_view_update_item_text (icon_view, item->item);
8107 get_pango_text_offsets (icon_view->priv->layout,
8121 *start_offset = gtk_text_iter_get_offset (&start);
8122 *end_offset = gtk_text_iter_get_offset (&end);
8124 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8128 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8130 AtkTextBoundary boundary_type,
8134 GtkIconViewItemAccessible *item;
8135 GtkTextIter start, end;
8136 GtkTextBuffer *buffer;
8138 GtkIconView *icon_view;
8141 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8143 if (!GTK_IS_ICON_VIEW (item->widget))
8146 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8149 buffer = item->text_buffer;
8151 if (!gtk_text_buffer_get_char_count (buffer))
8155 return g_strdup ("");
8157 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8161 switch (boundary_type)
8163 case ATK_TEXT_BOUNDARY_CHAR:
8164 gtk_text_iter_forward_char(&start);
8165 gtk_text_iter_forward_chars(&end, 2);
8167 case ATK_TEXT_BOUNDARY_WORD_START:
8168 if (gtk_text_iter_inside_word (&end))
8169 gtk_text_iter_forward_word_end (&end);
8170 while (!gtk_text_iter_starts_word (&end))
8172 if (!gtk_text_iter_forward_char (&end))
8176 if (!gtk_text_iter_is_end (&end))
8178 gtk_text_iter_forward_word_end (&end);
8179 while (!gtk_text_iter_starts_word (&end))
8181 if (!gtk_text_iter_forward_char (&end))
8186 case ATK_TEXT_BOUNDARY_WORD_END:
8187 gtk_text_iter_forward_word_end (&end);
8189 if (!gtk_text_iter_is_end (&end))
8190 gtk_text_iter_forward_word_end (&end);
8192 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8193 if (gtk_text_iter_inside_sentence (&end))
8194 gtk_text_iter_forward_sentence_end (&end);
8195 while (!gtk_text_iter_starts_sentence (&end))
8197 if (!gtk_text_iter_forward_char (&end))
8201 if (!gtk_text_iter_is_end (&end))
8203 gtk_text_iter_forward_sentence_end (&end);
8204 while (!gtk_text_iter_starts_sentence (&end))
8206 if (!gtk_text_iter_forward_char (&end))
8211 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8212 gtk_text_iter_forward_sentence_end (&end);
8214 if (!gtk_text_iter_is_end (&end))
8215 gtk_text_iter_forward_sentence_end (&end);
8217 case ATK_TEXT_BOUNDARY_LINE_START:
8218 case ATK_TEXT_BOUNDARY_LINE_END:
8220 icon_view = GTK_ICON_VIEW (item->widget);
8221 /* FIXME we probably have to use GailTextCell to salvage this */
8222 gtk_icon_view_update_item_text (icon_view, item->item);
8223 get_pango_text_offsets (icon_view->priv->layout,
8235 *start_offset = gtk_text_iter_get_offset (&start);
8236 *end_offset = gtk_text_iter_get_offset (&end);
8238 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8242 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8244 GtkIconViewItemAccessible *item;
8246 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8248 if (!GTK_IS_ICON_VIEW (item->widget))
8251 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8254 return gtk_text_buffer_get_char_count (item->text_buffer);
8258 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8264 AtkCoordType coord_type)
8266 GtkIconViewItemAccessible *item;
8268 GtkIconView *icon_view;
8269 PangoRectangle char_rect;
8270 const gchar *item_text;
8274 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8276 if (!GTK_IS_ICON_VIEW (item->widget))
8279 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8283 icon_view = GTK_ICON_VIEW (item->widget);
8284 /* FIXME we probably have to use GailTextCell to salvage this */
8285 gtk_icon_view_update_item_text (icon_view, item->item);
8286 item_text = pango_layout_get_text (icon_view->priv->layout);
8287 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8288 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8290 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8291 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8292 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8293 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8294 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8295 *width = char_rect.width / PANGO_SCALE;
8296 *height = char_rect.height / PANGO_SCALE;
8301 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8304 AtkCoordType coord_type)
8306 GtkIconViewItemAccessible *item;
8309 GtkIconView *icon_view;
8310 const gchar *item_text;
8315 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8317 if (!GTK_IS_ICON_VIEW (item->widget))
8320 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8324 icon_view = GTK_ICON_VIEW (item->widget);
8325 /* FIXME we probably have to use GailTextCell to salvage this */
8326 gtk_icon_view_update_item_text (icon_view, item->item);
8327 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8328 x -= l_x + item->item->layout_x - item->item->x;
8329 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8330 y -= l_y + item->item->layout_y - item->item->y;
8331 item_text = pango_layout_get_text (icon_view->priv->layout);
8332 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8343 offset = g_utf8_strlen (item_text, -1);
8345 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8351 atk_text_item_interface_init (AtkTextIface *iface)
8353 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8354 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8355 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8356 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8357 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8358 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8359 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8360 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8364 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8369 AtkCoordType coord_type)
8371 GtkIconViewItemAccessible *item;
8372 AtkObject *parent_obj;
8375 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8377 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8378 if (!GTK_IS_WIDGET (item->widget))
8381 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8384 *width = item->item->width;
8385 *height = item->item->height;
8386 if (gtk_icon_view_item_accessible_is_showing (item))
8388 parent_obj = gtk_widget_get_accessible (item->widget);
8389 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8390 *x = l_x + item->item->x;
8391 *y = l_y + item->item->y;
8401 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8403 GtkIconViewItemAccessible *item;
8404 GtkWidget *toplevel;
8406 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8408 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8409 if (!GTK_IS_WIDGET (item->widget))
8412 gtk_widget_grab_focus (item->widget);
8413 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8414 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8415 if (GTK_WIDGET_TOPLEVEL (toplevel))
8416 gtk_window_present (GTK_WINDOW (toplevel));
8422 atk_component_item_interface_init (AtkComponentIface *iface)
8424 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8425 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8429 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8430 AtkStateType state_type,
8431 gboolean emit_signal)
8435 rc = atk_state_set_add_state (item->state_set, state_type);
8437 * The signal should only be generated if the value changed,
8438 * not when the item is set up. So states that are set
8439 * initially should pass FALSE as the emit_signal argument.
8444 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8445 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8446 if (state_type == ATK_STATE_VISIBLE)
8447 g_signal_emit_by_name (item, "visible-data-changed");
8454 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8455 AtkStateType state_type,
8456 gboolean emit_signal)
8458 if (atk_state_set_contains_state (item->state_set, state_type))
8462 rc = atk_state_set_remove_state (item->state_set, state_type);
8464 * The signal should only be generated if the value changed,
8465 * not when the item is set up. So states that are set
8466 * initially should pass FALSE as the emit_signal argument.
8471 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8472 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8473 if (state_type == ATK_STATE_VISIBLE)
8474 g_signal_emit_by_name (item, "visible-data-changed");
8484 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8486 GtkIconView *icon_view;
8487 GdkRectangle visible_rect;
8488 gboolean is_showing;
8491 * An item is considered "SHOWING" if any part of the item is in the
8492 * visible rectangle.
8495 if (!GTK_IS_ICON_VIEW (item->widget))
8498 if (item->item == NULL)
8501 icon_view = GTK_ICON_VIEW (item->widget);
8503 if (icon_view->priv->hadjustment)
8504 visible_rect.x += icon_view->priv->hadjustment->value;
8506 if (icon_view->priv->hadjustment)
8507 visible_rect.y += icon_view->priv->vadjustment->value;
8508 visible_rect.width = item->widget->allocation.width;
8509 visible_rect.height = item->widget->allocation.height;
8511 if (((item->item->x + item->item->width) < visible_rect.x) ||
8512 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8513 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8514 (item->item->y > (visible_rect.y + visible_rect.height)))
8523 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8524 gboolean emit_signal)
8526 if (gtk_icon_view_item_accessible_is_showing (item))
8527 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8530 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8535 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8539 item->state_set = atk_state_set_new ();
8541 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8542 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8543 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8544 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8545 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8547 for (i = 0; i < LAST_ACTION; i++)
8548 item->action_descriptions[i] = NULL;
8550 item->image_description = NULL;
8552 item->action_idle_handler = 0;
8556 gtk_icon_view_item_accessible_finalize (GObject *object)
8558 GtkIconViewItemAccessible *item;
8561 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8563 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8566 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8568 if (item->state_set)
8569 g_object_unref (item->state_set);
8571 if (item->text_buffer)
8572 g_object_unref (item->text_buffer);
8574 for (i = 0; i < LAST_ACTION; i++)
8575 g_free (item->action_descriptions[i]);
8577 g_free (item->image_description);
8579 if (item->action_idle_handler)
8581 g_source_remove (item->action_idle_handler);
8582 item->action_idle_handler = 0;
8585 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8588 static G_CONST_RETURN gchar*
8589 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8595 GtkIconViewItemAccessible *item;
8596 GtkTextIter start_iter;
8597 GtkTextIter end_iter;
8599 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8601 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8602 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8604 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8609 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8611 GtkIconViewItemAccessible *item;
8613 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8614 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8617 return gtk_widget_get_accessible (item->widget);
8623 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8625 GtkIconViewItemAccessible *item;
8627 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8628 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8630 return item->item->index;
8633 static AtkStateSet *
8634 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8636 GtkIconViewItemAccessible *item;
8637 GtkIconView *icon_view;
8639 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8640 g_return_val_if_fail (item->state_set, NULL);
8645 icon_view = GTK_ICON_VIEW (item->widget);
8646 if (icon_view->priv->cursor_item == item->item)
8647 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8649 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8650 if (item->item->selected)
8651 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8653 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8655 return g_object_ref (item->state_set);
8659 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8661 GObjectClass *gobject_class;
8663 accessible_item_parent_class = g_type_class_peek_parent (klass);
8665 gobject_class = (GObjectClass *)klass;
8667 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8669 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8670 klass->get_name = gtk_icon_view_item_accessible_get_name;
8671 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8672 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8676 gtk_icon_view_item_accessible_get_type (void)
8678 static GType type = 0;
8682 const GTypeInfo tinfo =
8684 sizeof (GtkIconViewItemAccessibleClass),
8685 (GBaseInitFunc) NULL, /* base init */
8686 (GBaseFinalizeFunc) NULL, /* base finalize */
8687 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8688 (GClassFinalizeFunc) NULL, /* class finalize */
8689 NULL, /* class data */
8690 sizeof (GtkIconViewItemAccessible), /* instance size */
8691 0, /* nb preallocs */
8692 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8693 NULL /* value table */
8696 static const GInterfaceInfo atk_component_info =
8698 (GInterfaceInitFunc) atk_component_item_interface_init,
8699 (GInterfaceFinalizeFunc) NULL,
8702 static const GInterfaceInfo atk_action_info =
8704 (GInterfaceInitFunc) atk_action_item_interface_init,
8705 (GInterfaceFinalizeFunc) NULL,
8708 static const GInterfaceInfo atk_image_info =
8710 (GInterfaceInitFunc) atk_image_item_interface_init,
8711 (GInterfaceFinalizeFunc) NULL,
8714 static const GInterfaceInfo atk_text_info =
8716 (GInterfaceInitFunc) atk_text_item_interface_init,
8717 (GInterfaceFinalizeFunc) NULL,
8721 type = g_type_register_static (ATK_TYPE_OBJECT,
8722 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8723 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8724 &atk_component_info);
8725 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8727 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8729 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8736 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8737 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8738 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8740 static GType gtk_icon_view_accessible_get_type (void);
8745 } GtkIconViewAccessible;
8751 } GtkIconViewItemAccessibleInfo;
8757 GtkAdjustment *old_hadj;
8758 GtkAdjustment *old_vadj;
8760 GtkTreeModel *model;
8762 } GtkIconViewAccessiblePrivate;
8764 static GtkIconViewAccessiblePrivate *
8765 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8767 return g_object_get_qdata (G_OBJECT (accessible),
8768 accessible_private_data_quark);
8772 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8776 GtkIconViewItemAccessibleInfo *info;
8777 GtkIconViewItemAccessibleInfo *tmp_info;
8778 GtkIconViewAccessiblePrivate *priv;
8781 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8783 info->index = index;
8785 priv = gtk_icon_view_accessible_get_priv (accessible);
8786 items = priv->items;
8789 tmp_info = items->data;
8790 if (tmp_info->index > index)
8792 items = items->next;
8794 priv->items = g_list_insert_before (priv->items, items, info);
8795 priv->old_hadj = NULL;
8796 priv->old_vadj = NULL;
8800 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8802 GtkIconView *icon_view;
8805 widget = GTK_ACCESSIBLE (accessible)->widget;
8809 icon_view = GTK_ICON_VIEW (widget);
8811 return g_list_length (icon_view->priv->items);
8815 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8818 GtkIconViewAccessiblePrivate *priv;
8819 GtkIconViewItemAccessibleInfo *info;
8822 priv = gtk_icon_view_accessible_get_priv (accessible);
8823 items = priv->items;
8828 if (info->index == index)
8830 items = items->next;
8836 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8839 GtkIconView *icon_view;
8843 GtkIconViewItemAccessible *a11y_item;
8845 widget = GTK_ACCESSIBLE (accessible)->widget;
8849 icon_view = GTK_ICON_VIEW (widget);
8850 icons = g_list_nth (icon_view->priv->items, index);
8854 GtkIconViewItem *item = icons->data;
8856 g_return_val_if_fail (item->index == index, NULL);
8857 obj = gtk_icon_view_accessible_find_child (accessible, index);
8862 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8863 gtk_icon_view_item_accessible_info_new (accessible,
8866 obj->role = ATK_ROLE_ICON;
8867 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8868 a11y_item->item = item;
8869 a11y_item->widget = widget;
8870 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8872 gtk_icon_view_set_cell_data (icon_view, item);
8873 text = get_text (icon_view, item);
8876 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8880 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8881 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8889 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8892 GtkIconViewAccessiblePrivate *priv;
8893 GtkIconViewItemAccessibleInfo *info;
8894 GtkIconViewItemAccessible *item;
8897 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8901 gboolean act_on_item;
8903 widget = GTK_ACCESSIBLE (view)->widget;
8907 items = priv->items;
8909 act_on_item = (list == NULL);
8914 info = (GtkIconViewItemAccessibleInfo *)items->data;
8915 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8917 if (act_on_item == FALSE && list == items)
8921 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8923 items = items->next;
8929 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8930 GtkIconView *icon_view)
8933 GtkIconViewAccessible *view;
8936 * The scrollbars have changed
8938 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8939 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8941 gtk_icon_view_accessible_traverse_items (view, NULL);
8945 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8946 GtkAdjustment *hadj,
8947 GtkAdjustment *vadj)
8950 GtkIconViewAccessiblePrivate *priv;
8952 atk_obj = gtk_widget_get_accessible (widget);
8953 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8955 if (priv->old_hadj != hadj)
8959 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8960 (gpointer *)&priv->old_hadj);
8962 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8963 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8966 priv->old_hadj = hadj;
8969 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8970 (gpointer *)&priv->old_hadj);
8971 g_signal_connect (hadj,
8973 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8977 if (priv->old_vadj != vadj)
8981 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8982 (gpointer *)&priv->old_vadj);
8984 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8985 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8988 priv->old_vadj = vadj;
8991 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8992 (gpointer *)&priv->old_vadj);
8993 g_signal_connect (vadj,
8995 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9002 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9010 GtkIconView *icon_view;
9011 GtkIconViewItem *item;
9012 GtkIconViewAccessible *a11y_view;
9013 GtkIconViewItemAccessible *a11y_item;
9017 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9018 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9019 index = gtk_tree_path_get_indices(path)[0];
9020 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9021 gtk_icon_view_accessible_find_child (atk_obj, index));
9025 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9026 icon_view = GTK_ICON_VIEW (widget);
9027 item = a11y_item->item;
9029 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9031 if (!name || strcmp (name, "") == 0)
9033 gtk_icon_view_set_cell_data (icon_view, item);
9034 text = get_text (icon_view, item);
9037 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9043 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9049 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9054 GtkIconViewAccessiblePrivate *priv;
9055 GtkIconViewItemAccessibleInfo *info;
9056 GtkIconViewAccessible *view;
9057 GtkIconViewItemAccessible *item;
9063 index = gtk_tree_path_get_indices(path)[0];
9064 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9065 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9066 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9068 items = priv->items;
9073 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9074 if (info->index != item->item->index)
9076 if (info->index < index)
9077 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9079 if (tmp_list == NULL)
9082 info->index = item->item->index;
9085 items = items->next;
9087 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9088 g_signal_emit_by_name (atk_obj, "children-changed::add",
9094 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9098 GtkIconViewAccessiblePrivate *priv;
9099 GtkIconViewItemAccessibleInfo *info;
9100 GtkIconViewAccessible *view;
9101 GtkIconViewItemAccessible *item;
9104 GList *deleted_item;
9108 index = gtk_tree_path_get_indices(path)[0];
9109 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9110 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9111 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9113 items = priv->items;
9115 deleted_item = NULL;
9120 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9121 if (info->index == index)
9123 deleted_item = items;
9125 if (info->index != item->item->index)
9127 if (tmp_list == NULL)
9130 info->index = item->item->index;
9133 items = items->next;
9135 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9138 info = deleted_item->data;
9139 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9140 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9142 priv->items = g_list_remove_link (priv->items, deleted_item);
9150 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9151 GtkIconViewItemAccessibleInfo *i2)
9153 return i1->index - i2->index;
9157 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9163 GtkIconViewAccessiblePrivate *priv;
9164 GtkIconViewItemAccessibleInfo *info;
9165 GtkIconView *icon_view;
9166 GtkIconViewItemAccessible *item;
9172 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9173 icon_view = GTK_ICON_VIEW (user_data);
9174 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9176 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9178 order = g_new (gint, length);
9179 for (i = 0; i < length; i++)
9180 order [new_order[i]] = i;
9182 items = priv->items;
9186 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9187 info->index = order[info->index];
9188 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9189 items = items->next;
9192 priv->items = g_list_sort (priv->items,
9193 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9199 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9204 obj = G_OBJECT (model);
9205 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9206 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9207 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9208 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9212 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9216 obj = G_OBJECT (icon_view->priv->model);
9217 g_signal_connect_data (obj, "row-changed",
9218 (GCallback) gtk_icon_view_accessible_model_row_changed,
9219 icon_view, NULL, 0);
9220 g_signal_connect_data (obj, "row-inserted",
9221 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9222 icon_view, NULL, G_CONNECT_AFTER);
9223 g_signal_connect_data (obj, "row-deleted",
9224 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9225 icon_view, NULL, G_CONNECT_AFTER);
9226 g_signal_connect_data (obj, "rows-reordered",
9227 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9228 icon_view, NULL, G_CONNECT_AFTER);
9232 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9234 GtkIconViewItemAccessibleInfo *info;
9237 items = priv->items;
9240 info = (GtkIconViewItemAccessibleInfo *) items->data;
9241 g_object_unref (info->item);
9242 g_free (items->data);
9243 items = items->next;
9245 g_list_free (priv->items);
9250 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9253 GtkIconView *icon_view;
9256 GtkIconViewAccessiblePrivate *priv;
9258 if (strcmp (pspec->name, "model") == 0)
9260 widget = GTK_WIDGET (obj);
9261 atk_obj = gtk_widget_get_accessible (widget);
9262 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9265 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9266 (gpointer *)&priv->model);
9267 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9269 gtk_icon_view_accessible_clear_cache (priv);
9271 icon_view = GTK_ICON_VIEW (obj);
9272 priv->model = icon_view->priv->model;
9273 /* If there is no model the GtkIconView is probably being destroyed */
9276 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9277 gtk_icon_view_accessible_connect_model_signals (icon_view);
9285 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9288 GtkIconViewAccessiblePrivate *priv;
9289 GtkIconView *icon_view;
9291 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9292 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9294 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9295 g_object_set_qdata (G_OBJECT (accessible),
9296 accessible_private_data_quark,
9299 icon_view = GTK_ICON_VIEW (data);
9300 if (icon_view->priv->hadjustment)
9302 priv->old_hadj = icon_view->priv->hadjustment;
9303 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9304 g_signal_connect (icon_view->priv->hadjustment,
9306 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9309 if (icon_view->priv->vadjustment)
9311 priv->old_vadj = icon_view->priv->vadjustment;
9312 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9313 g_signal_connect (icon_view->priv->vadjustment,
9315 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9318 g_signal_connect_after (data,
9319 "set-scroll-adjustments",
9320 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9322 g_signal_connect (data,
9324 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9327 priv->model = icon_view->priv->model;
9330 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9331 gtk_icon_view_accessible_connect_model_signals (icon_view);
9334 accessible->role = ATK_ROLE_LAYERED_PANE;
9338 gtk_icon_view_accessible_finalize (GObject *object)
9340 GtkIconViewAccessiblePrivate *priv;
9342 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9343 gtk_icon_view_accessible_clear_cache (priv);
9347 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9351 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9352 GtkAccessible *accessible)
9355 GtkIconViewAccessiblePrivate *priv;
9357 atk_obj = ATK_OBJECT (accessible);
9358 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9361 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9362 (gpointer *)&priv->old_hadj);
9364 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9365 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9367 priv->old_hadj = NULL;
9371 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9372 (gpointer *)&priv->old_vadj);
9374 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9375 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9377 priv->old_vadj = NULL;
9382 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9384 if (accessible->widget)
9386 g_signal_connect_after (accessible->widget,
9388 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9391 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9395 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9397 GObjectClass *gobject_class;
9398 GtkAccessibleClass *accessible_class;
9400 accessible_parent_class = g_type_class_peek_parent (klass);
9402 gobject_class = (GObjectClass *)klass;
9403 accessible_class = (GtkAccessibleClass *)klass;
9405 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9407 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9408 klass->ref_child = gtk_icon_view_accessible_ref_child;
9409 klass->initialize = gtk_icon_view_accessible_initialize;
9411 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9413 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9417 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9420 AtkCoordType coord_type)
9423 GtkIconView *icon_view;
9424 GtkIconViewItem *item;
9427 widget = GTK_ACCESSIBLE (component)->widget;
9429 /* State is defunct */
9432 icon_view = GTK_ICON_VIEW (widget);
9433 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9434 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9436 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9442 atk_component_interface_init (AtkComponentIface *iface)
9444 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9448 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9452 GtkIconView *icon_view;
9453 GtkIconViewItem *item;
9455 widget = GTK_ACCESSIBLE (selection)->widget;
9459 icon_view = GTK_ICON_VIEW (widget);
9461 item = g_list_nth_data (icon_view->priv->items, i);
9466 gtk_icon_view_select_item (icon_view, item);
9472 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9475 GtkIconView *icon_view;
9477 widget = GTK_ACCESSIBLE (selection)->widget;
9481 icon_view = GTK_ICON_VIEW (widget);
9482 gtk_icon_view_unselect_all (icon_view);
9488 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9493 GtkIconView *icon_view;
9494 GtkIconViewItem *item;
9496 widget = GTK_ACCESSIBLE (selection)->widget;
9500 icon_view = GTK_ICON_VIEW (widget);
9502 l = icon_view->priv->items;
9509 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9520 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9523 GtkIconView *icon_view;
9524 GtkIconViewItem *item;
9528 widget = GTK_ACCESSIBLE (selection)->widget;
9532 icon_view = GTK_ICON_VIEW (widget);
9534 l = icon_view->priv->items;
9550 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9554 GtkIconView *icon_view;
9555 GtkIconViewItem *item;
9557 widget = GTK_ACCESSIBLE (selection)->widget;
9561 icon_view = GTK_ICON_VIEW (widget);
9563 item = g_list_nth_data (icon_view->priv->items, i);
9567 return item->selected;
9571 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9575 GtkIconView *icon_view;
9576 GtkIconViewItem *item;
9580 widget = GTK_ACCESSIBLE (selection)->widget;
9584 icon_view = GTK_ICON_VIEW (widget);
9585 l = icon_view->priv->items;
9594 gtk_icon_view_unselect_item (icon_view, item);
9606 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9609 GtkIconView *icon_view;
9611 widget = GTK_ACCESSIBLE (selection)->widget;
9615 icon_view = GTK_ICON_VIEW (widget);
9616 gtk_icon_view_select_all (icon_view);
9621 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9623 iface->add_selection = gtk_icon_view_accessible_add_selection;
9624 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9625 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9626 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9627 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9628 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9629 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9633 gtk_icon_view_accessible_get_type (void)
9635 static GType type = 0;
9639 static GTypeInfo tinfo =
9642 (GBaseInitFunc) NULL, /* base init */
9643 (GBaseFinalizeFunc) NULL, /* base finalize */
9644 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9645 (GClassFinalizeFunc) NULL, /* class finalize */
9646 NULL, /* class data */
9647 0, /* instance size */
9648 0, /* nb preallocs */
9649 (GInstanceInitFunc) NULL, /* instance init */
9650 NULL /* value table */
9652 static const GInterfaceInfo atk_component_info =
9654 (GInterfaceInitFunc) atk_component_interface_init,
9655 (GInterfaceFinalizeFunc) NULL,
9658 static const GInterfaceInfo atk_selection_info =
9660 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9661 (GInterfaceFinalizeFunc) NULL,
9666 * Figure out the size of the class and instance
9667 * we are deriving from
9669 AtkObjectFactory *factory;
9672 GType derived_atk_type;
9674 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9675 factory = atk_registry_get_factory (atk_get_default_registry (),
9677 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9678 g_type_query (derived_atk_type, &query);
9679 tinfo.class_size = query.class_size;
9680 tinfo.instance_size = query.instance_size;
9682 type = g_type_register_static (derived_atk_type,
9683 I_("GtkIconViewAccessible"),
9685 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9686 &atk_component_info);
9687 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9688 &atk_selection_info);
9694 gtk_icon_view_accessible_new (GObject *obj)
9696 AtkObject *accessible;
9698 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9700 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9701 atk_object_initialize (accessible, obj);
9707 gtk_icon_view_accessible_factory_get_accessible_type (void)
9709 return gtk_icon_view_accessible_get_type ();
9713 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9715 return gtk_icon_view_accessible_new (obj);
9719 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9721 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9722 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9726 gtk_icon_view_accessible_factory_get_type (void)
9728 static GType type = 0;
9732 const GTypeInfo tinfo =
9734 sizeof (AtkObjectFactoryClass),
9735 NULL, /* base_init */
9736 NULL, /* base_finalize */
9737 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9738 NULL, /* class_finalize */
9739 NULL, /* class_data */
9740 sizeof (AtkObjectFactory),
9741 0, /* n_preallocs */
9745 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9746 I_("GtkIconViewAccessibleFactory"),
9754 gtk_icon_view_get_accessible (GtkWidget *widget)
9756 static gboolean first_time = TRUE;
9760 AtkObjectFactory *factory;
9761 AtkRegistry *registry;
9763 GType derived_atk_type;
9766 * Figure out whether accessibility is enabled by looking at the
9767 * type of the accessible object which would be created for
9768 * the parent type of GtkIconView.
9770 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9772 registry = atk_get_default_registry ();
9773 factory = atk_registry_get_factory (registry,
9775 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9776 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9777 atk_registry_set_factory_type (registry,
9779 gtk_icon_view_accessible_factory_get_type ());
9782 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9786 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9787 GtkBuilder *builder,
9789 const gchar *tagname,
9790 GMarkupParser *parser,
9793 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9794 tagname, parser, data))
9797 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9798 tagname, parser, data);
9802 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9803 GtkBuilder *builder,
9805 const gchar *tagname,
9808 if (strcmp (tagname, "attributes") == 0)
9809 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9812 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9818 #define __GTK_ICON_VIEW_C__
9819 #include "gtkaliasdef.c"