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 (item->width == -1)
2922 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2924 wrap_width = MAX (2 * pixbuf_width, 50);
2926 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2927 wrap_width = item_width;
2929 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2931 wrap_width -= ITEM_PADDING * 2;
2933 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2934 g_object_set (text_info->cell, "width", wrap_width, NULL);
2939 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2940 GtkIconViewItem *item)
2945 if (item->width != -1 && item->height != -1)
2948 if (item->n_cells != icon_view->priv->n_cells)
2950 g_free (item->before);
2951 g_free (item->after);
2954 item->before = g_new0 (gint, icon_view->priv->n_cells);
2955 item->after = g_new0 (gint, icon_view->priv->n_cells);
2956 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2958 item->n_cells = icon_view->priv->n_cells;
2961 gtk_icon_view_set_cell_data (icon_view, item);
2963 spacing = icon_view->priv->spacing;
2967 for (l = icon_view->priv->cell_list; l; l = l->next)
2969 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2971 if (!info->cell->visible)
2974 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2976 &item->box[info->position].width,
2977 &item->box[info->position].height);
2979 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2981 item->width += item->box[info->position].width
2982 + (info->position > 0 ? spacing : 0);
2983 item->height = MAX (item->height, item->box[info->position].height);
2987 item->width = MAX (item->width, item->box[info->position].width);
2988 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2992 item->width += ITEM_PADDING * 2;
2993 item->height += ITEM_PADDING * 2;
2997 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2998 GtkIconViewItem *item,
3001 GdkRectangle cell_area;
3007 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3009 gtk_icon_view_set_cell_data (icon_view, item);
3011 spacing = icon_view->priv->spacing;
3014 for (i = 0; i < icon_view->priv->n_cells; i++)
3016 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3017 item->height = MAX (item->height, max_height[i]);
3019 item->height += max_height[i] + (i > 0 ? spacing : 0);
3022 cell_area.x = item->x + ITEM_PADDING;
3023 cell_area.y = item->y + ITEM_PADDING;
3025 for (k = 0; k < 2; k++)
3026 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3028 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3030 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3033 if (!info->cell->visible)
3036 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3038 /* We should not subtract ITEM_PADDING from item->height,
3039 * because item->height is recalculated above using
3040 * max_height which does not contain item padding.
3042 cell_area.width = item->box[info->position].width;
3043 cell_area.height = item->height;
3047 /* item->width is not recalculated and thus needs to be
3048 * corrected for the padding.
3050 cell_area.width = item->width - 2 * ITEM_PADDING;
3051 cell_area.height = max_height[i];
3054 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3056 &item->box[info->position].x, &item->box[info->position].y,
3057 &item->box[info->position].width, &item->box[info->position].height);
3059 item->box[info->position].x += cell_area.x;
3060 item->box[info->position].y += cell_area.y;
3061 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3063 item->before[info->position] = item->box[info->position].x - cell_area.x;
3064 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3065 cell_area.x += cell_area.width + spacing;
3069 if (item->box[info->position].width > item->width - ITEM_PADDING * 2)
3071 item->width = item->box[info->position].width + ITEM_PADDING * 2;
3072 cell_area.width = item->width;
3074 item->before[info->position] = item->box[info->position].y - cell_area.y;
3075 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3076 cell_area.y += cell_area.height + spacing;
3080 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3082 for (i = 0; i < icon_view->priv->n_cells; i++)
3084 item->box[i].x = item->x + item->width -
3085 (item->box[i].x + item->box[i].width - item->x);
3089 item->height += ITEM_PADDING * 2;
3093 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3095 g_list_foreach (icon_view->priv->items,
3096 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3100 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3107 gtk_icon_view_paint_item (GtkIconView *icon_view,
3109 GtkIconViewItem *item,
3111 GdkDrawable *drawable,
3114 gboolean draw_focus)
3118 GdkRectangle cell_area, box;
3122 GtkCellRendererState flags;
3124 if (icon_view->priv->model == NULL)
3127 gtk_icon_view_set_cell_data (icon_view, item);
3129 gtk_widget_style_get (GTK_WIDGET (icon_view),
3130 "focus-line-width", &focus_width,
3133 padding = focus_width;
3137 flags = GTK_CELL_RENDERER_SELECTED;
3138 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3139 state = GTK_STATE_SELECTED;
3141 state = GTK_STATE_ACTIVE;
3146 state = GTK_STATE_NORMAL;
3149 #ifdef DEBUG_ICON_VIEW
3150 gdk_draw_rectangle (drawable,
3151 GTK_WIDGET (icon_view)->style->black_gc,
3154 item->width, item->height);
3159 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3160 (GdkWindow *) drawable,
3164 GTK_WIDGET (icon_view),
3167 item->width, item->height);
3170 for (l = icon_view->priv->cell_list; l; l = l->next)
3172 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3174 if (!info->cell->visible)
3177 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3179 #ifdef DEBUG_ICON_VIEW
3180 gdk_draw_rectangle (drawable,
3181 GTK_WIDGET (icon_view)->style->black_gc,
3183 x - item->x + cell_area.x,
3184 y - item->y + cell_area.y,
3185 cell_area.width, cell_area.height);
3187 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3189 gdk_draw_rectangle (drawable,
3190 GTK_WIDGET (icon_view)->style->black_gc,
3192 x - item->x + box.x,
3193 y - item->y + box.y,
3194 box.width, box.height);
3197 cell_area.x = x - item->x + cell_area.x;
3198 cell_area.y = y - item->y + cell_area.y;
3200 gtk_cell_renderer_render (info->cell,
3202 GTK_WIDGET (icon_view),
3203 &cell_area, &cell_area, area, flags);
3207 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3208 item == icon_view->priv->cursor_item)
3210 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3212 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3214 if (!info->cell->visible)
3217 /* If found a editable/activatable cell, draw focus on it. */
3218 if (icon_view->priv->cursor_cell < 0 &&
3219 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3220 icon_view->priv->cursor_cell = i;
3222 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3224 if (i == icon_view->priv->cursor_cell)
3226 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3230 GTK_WIDGET (icon_view),
3232 x - item->x + box.x - padding,
3233 y - item->y + box.y - padding,
3234 box.width + 2 * padding,
3235 box.height + 2 * padding);
3240 /* If there are no editable/activatable cells, draw focus
3241 * around the whole item.
3243 if (icon_view->priv->cursor_cell < 0)
3244 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3248 GTK_WIDGET (icon_view),
3252 item->width + 2 * padding,
3253 item->height + 2 * padding);
3258 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3263 GdkRectangle rubber_rect;
3264 GdkColor *fill_color_gdk;
3265 guchar fill_color_alpha;
3267 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3268 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3269 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3270 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3272 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3275 gtk_widget_style_get (GTK_WIDGET (icon_view),
3276 "selection-box-color", &fill_color_gdk,
3277 "selection-box-alpha", &fill_color_alpha,
3280 if (!fill_color_gdk)
3281 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3283 cairo_set_source_rgba (cr,
3284 fill_color_gdk->red / 65535.,
3285 fill_color_gdk->green / 65535.,
3286 fill_color_gdk->blue / 65535.,
3287 fill_color_alpha / 255.);
3290 gdk_cairo_rectangle (cr, &rect);
3294 /* Draw the border without alpha */
3295 cairo_set_source_rgb (cr,
3296 fill_color_gdk->red / 65535.,
3297 fill_color_gdk->green / 65535.,
3298 fill_color_gdk->blue / 65535.);
3299 cairo_rectangle (cr,
3300 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3301 rubber_rect.width - 1, rubber_rect.height - 1);
3305 gdk_color_free (fill_color_gdk);
3309 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3315 index = gtk_tree_path_get_indices (path)[0];
3317 for (l = icon_view->priv->items; l; l = l->next)
3319 GtkIconViewItem *item = l->data;
3321 if (item->index == index)
3323 gtk_icon_view_queue_draw_item (icon_view, item);
3330 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3331 GtkIconViewItem *item)
3336 gtk_widget_style_get (GTK_WIDGET (icon_view),
3337 "focus-line-width", &focus_width,
3340 rect.x = item->x - focus_width;
3341 rect.y = item->y - focus_width;
3342 rect.width = item->width + 2 * focus_width;
3343 rect.height = item->height + 2 * focus_width;
3345 if (icon_view->priv->bin_window)
3346 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3350 layout_callback (gpointer user_data)
3352 GtkIconView *icon_view;
3354 icon_view = GTK_ICON_VIEW (user_data);
3356 icon_view->priv->layout_idle_id = 0;
3358 gtk_icon_view_layout (icon_view);
3364 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3366 if (icon_view->priv->layout_idle_id != 0)
3369 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3373 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3374 GtkIconViewItem *item,
3378 AtkObject *item_obj;
3379 AtkObject *cursor_item_obj;
3381 if (icon_view->priv->cursor_item == item &&
3382 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3385 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3386 if (icon_view->priv->cursor_item != NULL)
3388 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3391 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3392 if (cursor_item_obj != NULL)
3393 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3396 icon_view->priv->cursor_item = item;
3397 if (cursor_cell >= 0)
3398 icon_view->priv->cursor_cell = cursor_cell;
3400 gtk_icon_view_queue_draw_item (icon_view, item);
3402 /* Notify that accessible focus object has changed */
3403 item_obj = atk_object_ref_accessible_child (obj, item->index);
3405 if (item_obj != NULL)
3407 atk_focus_tracker_notify (item_obj);
3408 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3409 g_object_unref (item_obj);
3414 static GtkIconViewItem *
3415 gtk_icon_view_item_new (void)
3417 GtkIconViewItem *item;
3419 item = g_new0 (GtkIconViewItem, 1);
3428 gtk_icon_view_item_free (GtkIconViewItem *item)
3430 g_return_if_fail (item != NULL);
3432 g_free (item->before);
3433 g_free (item->after);
3440 static GtkIconViewItem *
3441 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3444 gboolean only_in_cell,
3445 GtkIconViewCellInfo **cell_at_pos)
3450 for (items = icon_view->priv->items; items; items = items->next)
3452 GtkIconViewItem *item = items->data;
3454 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3455 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3457 if (only_in_cell || cell_at_pos)
3459 gtk_icon_view_set_cell_data (icon_view, item);
3461 for (l = icon_view->priv->cell_list; l; l = l->next)
3463 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3465 if (!info->cell->visible)
3468 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3470 if ((x >= box.x && x <= box.x + box.width &&
3471 y >= box.y && y <= box.y + box.height) ||
3473 x <= box.x + box.width &&
3475 y <= box.y + box.height))
3478 *cell_at_pos = info;
3488 *cell_at_pos = NULL;
3499 gtk_icon_view_select_item (GtkIconView *icon_view,
3500 GtkIconViewItem *item)
3502 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3503 g_return_if_fail (item != NULL);
3508 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3510 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3511 gtk_icon_view_unselect_all_internal (icon_view);
3513 item->selected = TRUE;
3515 gtk_icon_view_item_selected_changed (icon_view, item);
3516 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3518 gtk_icon_view_queue_draw_item (icon_view, item);
3523 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3524 GtkIconViewItem *item)
3526 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3527 g_return_if_fail (item != NULL);
3529 if (!item->selected)
3532 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3533 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3536 item->selected = FALSE;
3538 gtk_icon_view_item_selected_changed (icon_view, item);
3539 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3541 gtk_icon_view_queue_draw_item (icon_view, item);
3545 verify_items (GtkIconView *icon_view)
3550 for (items = icon_view->priv->items; items; items = items->next)
3552 GtkIconViewItem *item = items->data;
3554 if (item->index != i)
3555 g_error ("List item does not match its index: "
3556 "item index %d and list index %d\n", item->index, i);
3563 gtk_icon_view_row_changed (GtkTreeModel *model,
3568 GtkIconViewItem *item;
3570 GtkIconView *icon_view;
3572 icon_view = GTK_ICON_VIEW (data);
3574 gtk_icon_view_stop_editing (icon_view, TRUE);
3576 index = gtk_tree_path_get_indices(path)[0];
3577 item = g_list_nth_data (icon_view->priv->items, index);
3579 gtk_icon_view_item_invalidate_size (item);
3580 gtk_icon_view_queue_layout (icon_view);
3582 verify_items (icon_view);
3586 gtk_icon_view_row_inserted (GtkTreeModel *model,
3592 GtkIconViewItem *item;
3593 gboolean iters_persist;
3594 GtkIconView *icon_view;
3597 icon_view = GTK_ICON_VIEW (data);
3599 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3601 index = gtk_tree_path_get_indices(path)[0];
3603 item = gtk_icon_view_item_new ();
3608 item->index = index;
3610 /* FIXME: We can be more efficient here,
3611 we can store a tail pointer and use that when
3612 appending (which is a rather common operation)
3614 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3617 list = g_list_nth (icon_view->priv->items, index + 1);
3618 for (; list; list = list->next)
3625 verify_items (icon_view);
3627 gtk_icon_view_queue_layout (icon_view);
3631 gtk_icon_view_row_deleted (GtkTreeModel *model,
3636 GtkIconView *icon_view;
3637 GtkIconViewItem *item;
3639 gboolean emit = FALSE;
3641 icon_view = GTK_ICON_VIEW (data);
3643 index = gtk_tree_path_get_indices(path)[0];
3645 list = g_list_nth (icon_view->priv->items, index);
3648 gtk_icon_view_stop_editing (icon_view, TRUE);
3650 if (item == icon_view->priv->anchor_item)
3651 icon_view->priv->anchor_item = NULL;
3653 if (item == icon_view->priv->cursor_item)
3654 icon_view->priv->cursor_item = NULL;
3659 gtk_icon_view_item_free (item);
3661 for (next = list->next; next; next = next->next)
3668 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3670 verify_items (icon_view);
3672 gtk_icon_view_queue_layout (icon_view);
3675 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3679 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3680 GtkTreePath *parent,
3687 GtkIconView *icon_view;
3688 GList *items = NULL, *list;
3689 GtkIconViewItem **item_array;
3692 icon_view = GTK_ICON_VIEW (data);
3694 gtk_icon_view_stop_editing (icon_view, TRUE);
3696 length = gtk_tree_model_iter_n_children (model, NULL);
3698 order = g_new (gint, length);
3699 for (i = 0; i < length; i++)
3700 order [new_order[i]] = i;
3702 item_array = g_new (GtkIconViewItem *, length);
3703 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3704 item_array[order[i]] = list->data;
3707 for (i = length - 1; i >= 0; i--)
3709 item_array[i]->index = i;
3710 items = g_list_prepend (items, item_array[i]);
3713 g_free (item_array);
3714 g_list_free (icon_view->priv->items);
3715 icon_view->priv->items = items;
3717 gtk_icon_view_queue_layout (icon_view);
3719 verify_items (icon_view);
3723 gtk_icon_view_build_items (GtkIconView *icon_view)
3727 gboolean iters_persist;
3728 GList *items = NULL;
3730 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3732 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3740 GtkIconViewItem *item = gtk_icon_view_item_new ();
3749 items = g_list_prepend (items, item);
3751 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3753 icon_view->priv->items = g_list_reverse (items);
3757 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3760 GtkMovementStep step,
3764 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3765 I_("move-cursor"), 2,
3769 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3774 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3777 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3782 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3789 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3790 GtkMovementStep step,
3793 GdkModifierType state;
3795 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3796 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3797 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3798 step == GTK_MOVEMENT_DISPLAY_LINES ||
3799 step == GTK_MOVEMENT_PAGES ||
3800 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3802 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3805 gtk_icon_view_stop_editing (icon_view, FALSE);
3806 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3808 if (gtk_get_current_event_state (&state))
3810 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3811 icon_view->priv->ctrl_pressed = TRUE;
3812 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3813 icon_view->priv->shift_pressed = TRUE;
3815 /* else we assume not pressed */
3819 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3820 case GTK_MOVEMENT_VISUAL_POSITIONS:
3821 gtk_icon_view_move_cursor_left_right (icon_view, count);
3823 case GTK_MOVEMENT_DISPLAY_LINES:
3824 gtk_icon_view_move_cursor_up_down (icon_view, count);
3826 case GTK_MOVEMENT_PAGES:
3827 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3829 case GTK_MOVEMENT_BUFFER_ENDS:
3830 gtk_icon_view_move_cursor_start_end (icon_view, count);
3833 g_assert_not_reached ();
3836 icon_view->priv->ctrl_pressed = FALSE;
3837 icon_view->priv->shift_pressed = FALSE;
3839 icon_view->priv->draw_focus = TRUE;
3844 static GtkIconViewItem *
3845 find_item (GtkIconView *icon_view,
3846 GtkIconViewItem *current,
3852 GtkIconViewItem *item;
3854 /* FIXME: this could be more efficient
3856 row = current->row + row_ofs;
3857 col = current->col + col_ofs;
3859 for (items = icon_view->priv->items; items; items = items->next)
3862 if (item->row == row && item->col == col)
3870 find_cell (GtkIconView *icon_view,
3871 GtkIconViewItem *item,
3873 GtkOrientation orientation,
3883 if (icon_view->priv->orientation != orientation)
3886 gtk_icon_view_set_cell_data (icon_view, item);
3888 focusable = g_new0 (gint, icon_view->priv->n_cells);
3892 for (k = 0; k < 2; k++)
3893 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3895 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3897 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3900 if (!info->cell->visible)
3903 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3906 current = n_focusable;
3908 focusable[n_focusable] = i;
3914 if (n_focusable == 0)
3922 current = step > 0 ? 0 : n_focusable - 1;
3923 cell = focusable[current];
3926 if (current + *count < 0)
3929 *count = current + *count;
3931 else if (current + *count > n_focusable - 1)
3934 *count = current + *count - (n_focusable - 1);
3938 cell = focusable[current + *count];
3947 static GtkIconViewItem *
3948 find_item_page_up_down (GtkIconView *icon_view,
3949 GtkIconViewItem *current,
3956 y = current->y + count * icon_view->priv->vadjustment->page_size;
3958 item = g_list_find (icon_view->priv->items, current);
3963 for (next = item->next; next; next = next->next)
3965 if (((GtkIconViewItem *)next->data)->col == col)
3968 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3978 for (next = item->prev; next; next = next->prev)
3980 if (((GtkIconViewItem *)next->data)->col == col)
3983 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3997 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3998 GtkIconViewItem *anchor,
3999 GtkIconViewItem *cursor)
4002 GtkIconViewItem *item;
4003 gint row1, row2, col1, col2;
4004 gboolean dirty = FALSE;
4006 if (anchor->row < cursor->row)
4017 if (anchor->col < cursor->col)
4028 for (items = icon_view->priv->items; items; items = items->next)
4032 if (row1 <= item->row && item->row <= row2 &&
4033 col1 <= item->col && item->col <= col2)
4035 if (!item->selected)
4038 item->selected = TRUE;
4039 gtk_icon_view_item_selected_changed (icon_view, item);
4041 gtk_icon_view_queue_draw_item (icon_view, item);
4049 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4052 GtkIconViewItem *item;
4054 gboolean dirty = FALSE;
4057 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4060 if (!icon_view->priv->cursor_item)
4065 list = icon_view->priv->items;
4067 list = g_list_last (icon_view->priv->items);
4069 item = list ? list->data : NULL;
4074 item = icon_view->priv->cursor_item;
4075 cell = icon_view->priv->cursor_cell;
4076 step = count > 0 ? 1 : -1;
4079 cell = find_cell (icon_view, item, cell,
4080 GTK_ORIENTATION_VERTICAL,
4085 item = find_item (icon_view, item, step, 0);
4086 count = count - step;
4092 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4096 if (icon_view->priv->ctrl_pressed ||
4097 !icon_view->priv->shift_pressed ||
4098 !icon_view->priv->anchor_item ||
4099 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4100 icon_view->priv->anchor_item = item;
4102 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4104 if (!icon_view->priv->ctrl_pressed &&
4105 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4107 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4108 dirty = gtk_icon_view_select_all_between (icon_view,
4109 icon_view->priv->anchor_item,
4113 gtk_icon_view_scroll_to_item (icon_view, item);
4116 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4120 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4123 GtkIconViewItem *item;
4124 gboolean dirty = FALSE;
4126 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4129 if (!icon_view->priv->cursor_item)
4134 list = icon_view->priv->items;
4136 list = g_list_last (icon_view->priv->items);
4138 item = list ? list->data : NULL;
4141 item = find_item_page_up_down (icon_view,
4142 icon_view->priv->cursor_item,
4145 if (item == icon_view->priv->cursor_item)
4146 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4151 if (icon_view->priv->ctrl_pressed ||
4152 !icon_view->priv->shift_pressed ||
4153 !icon_view->priv->anchor_item ||
4154 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4155 icon_view->priv->anchor_item = item;
4157 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4159 if (!icon_view->priv->ctrl_pressed &&
4160 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4162 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4163 dirty = gtk_icon_view_select_all_between (icon_view,
4164 icon_view->priv->anchor_item,
4168 gtk_icon_view_scroll_to_item (icon_view, item);
4171 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4175 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4178 GtkIconViewItem *item;
4180 gboolean dirty = FALSE;
4183 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4186 if (!icon_view->priv->cursor_item)
4191 list = icon_view->priv->items;
4193 list = g_list_last (icon_view->priv->items);
4195 item = list ? list->data : NULL;
4199 item = icon_view->priv->cursor_item;
4200 cell = icon_view->priv->cursor_cell;
4201 step = count > 0 ? 1 : -1;
4204 cell = find_cell (icon_view, item, cell,
4205 GTK_ORIENTATION_HORIZONTAL,
4210 item = find_item (icon_view, item, 0, step);
4211 count = count - step;
4217 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4221 if (icon_view->priv->ctrl_pressed ||
4222 !icon_view->priv->shift_pressed ||
4223 !icon_view->priv->anchor_item ||
4224 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4225 icon_view->priv->anchor_item = item;
4227 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4229 if (!icon_view->priv->ctrl_pressed &&
4230 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4232 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4233 dirty = gtk_icon_view_select_all_between (icon_view,
4234 icon_view->priv->anchor_item,
4238 gtk_icon_view_scroll_to_item (icon_view, item);
4241 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4245 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4248 GtkIconViewItem *item;
4250 gboolean dirty = FALSE;
4252 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4256 list = icon_view->priv->items;
4258 list = g_list_last (icon_view->priv->items);
4260 item = list ? list->data : NULL;
4262 if (item == icon_view->priv->cursor_item)
4263 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4268 if (icon_view->priv->ctrl_pressed ||
4269 !icon_view->priv->shift_pressed ||
4270 !icon_view->priv->anchor_item ||
4271 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4272 icon_view->priv->anchor_item = item;
4274 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4276 if (!icon_view->priv->ctrl_pressed &&
4277 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4279 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4280 dirty = gtk_icon_view_select_all_between (icon_view,
4281 icon_view->priv->anchor_item,
4285 gtk_icon_view_scroll_to_item (icon_view, item);
4288 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4292 * gtk_icon_view_scroll_to_path:
4293 * @icon_view: A #GtkIconView.
4294 * @path: The path of the item to move to.
4295 * @use_align: whether to use alignment arguments, or %FALSE.
4296 * @row_align: The vertical alignment of the item specified by @path.
4297 * @col_align: The horizontal alignment of the item specified by @path.
4299 * Moves the alignments of @icon_view to the position specified by @path.
4300 * @row_align determines where the row is placed, and @col_align determines
4301 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4302 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4305 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4306 * tree does the minimum amount of work to scroll the item onto the screen.
4307 * This means that the item will be scrolled to the edge closest to its current
4308 * position. If the item is currently visible on the screen, nothing is done.
4310 * This function only works if the model is set, and @path is a valid row on
4311 * the model. If the model changes before the @icon_view is realized, the
4312 * centered path will be modified to reflect this change.
4317 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4323 GtkIconViewItem *item = NULL;
4325 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4326 g_return_if_fail (path != NULL);
4327 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4328 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4330 if (gtk_tree_path_get_depth (path) > 0)
4331 item = g_list_nth_data (icon_view->priv->items,
4332 gtk_tree_path_get_indices(path)[0]);
4334 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4336 if (icon_view->priv->scroll_to_path)
4337 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4339 icon_view->priv->scroll_to_path = NULL;
4342 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4344 icon_view->priv->scroll_to_use_align = use_align;
4345 icon_view->priv->scroll_to_row_align = row_align;
4346 icon_view->priv->scroll_to_col_align = col_align;
4355 gfloat offset, value;
4357 gtk_widget_style_get (GTK_WIDGET (icon_view),
4358 "focus-line-width", &focus_width,
4361 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4363 offset = y + item->y - focus_width -
4364 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4365 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4366 icon_view->priv->vadjustment->lower,
4367 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4368 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4370 offset = x + item->x - focus_width -
4371 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4372 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4373 icon_view->priv->hadjustment->lower,
4374 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4375 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4377 gtk_adjustment_changed (icon_view->priv->hadjustment);
4378 gtk_adjustment_changed (icon_view->priv->vadjustment);
4381 gtk_icon_view_scroll_to_item (icon_view, item);
4386 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4387 GtkIconViewItem *item)
4389 gint x, y, width, height;
4392 gtk_widget_style_get (GTK_WIDGET (icon_view),
4393 "focus-line-width", &focus_width,
4396 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4398 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4400 if (y + item->y - focus_width < 0)
4401 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4402 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4403 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4404 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4405 icon_view->priv->vadjustment->value + y + item->y + item->height
4406 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4408 if (x + item->x - focus_width < 0)
4409 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4410 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4411 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4412 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4413 icon_view->priv->hadjustment->value + x + item->x + item->width
4414 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4416 gtk_adjustment_changed (icon_view->priv->hadjustment);
4417 gtk_adjustment_changed (icon_view->priv->vadjustment);
4420 /* GtkCellLayout implementation */
4421 static GtkIconViewCellInfo *
4422 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4423 GtkCellRenderer *renderer)
4427 for (i = icon_view->priv->cell_list; i; i = i->next)
4429 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4431 if (info->cell == renderer)
4439 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4440 GtkIconViewItem *item)
4443 gboolean iters_persist;
4446 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4452 path = gtk_tree_path_new_from_indices (item->index, -1);
4453 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4455 gtk_tree_path_free (path);
4460 for (i = icon_view->priv->cell_list; i; i = i->next)
4463 GtkIconViewCellInfo *info = i->data;
4465 g_object_freeze_notify (G_OBJECT (info->cell));
4467 for (j = info->attributes; j && j->next; j = j->next->next)
4469 gchar *property = j->data;
4470 gint column = GPOINTER_TO_INT (j->next->data);
4471 GValue value = {0, };
4473 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4475 g_object_set_property (G_OBJECT (info->cell),
4477 g_value_unset (&value);
4481 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4483 icon_view->priv->model,
4487 g_object_thaw_notify (G_OBJECT (info->cell));
4492 free_cell_attributes (GtkIconViewCellInfo *info)
4496 list = info->attributes;
4497 while (list && list->next)
4499 g_free (list->data);
4500 list = list->next->next;
4503 g_slist_free (info->attributes);
4504 info->attributes = NULL;
4508 free_cell_info (GtkIconViewCellInfo *info)
4510 free_cell_attributes (info);
4512 g_object_unref (info->cell);
4515 (* info->destroy) (info->func_data);
4521 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4522 GtkCellRenderer *renderer,
4525 GtkIconViewCellInfo *info;
4526 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4528 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4529 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4531 g_object_ref_sink (renderer);
4533 info = g_new0 (GtkIconViewCellInfo, 1);
4534 info->cell = renderer;
4535 info->expand = expand ? TRUE : FALSE;
4536 info->pack = GTK_PACK_START;
4537 info->position = icon_view->priv->n_cells;
4539 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4540 icon_view->priv->n_cells++;
4544 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4545 GtkCellRenderer *renderer,
4548 GtkIconViewCellInfo *info;
4549 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4551 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4552 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4554 g_object_ref_sink (renderer);
4556 info = g_new0 (GtkIconViewCellInfo, 1);
4557 info->cell = renderer;
4558 info->expand = expand ? TRUE : FALSE;
4559 info->pack = GTK_PACK_END;
4560 info->position = icon_view->priv->n_cells;
4562 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4563 icon_view->priv->n_cells++;
4567 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4568 GtkCellRenderer *renderer,
4569 const gchar *attribute,
4572 GtkIconViewCellInfo *info;
4573 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4575 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4576 g_return_if_fail (info != NULL);
4578 info->attributes = g_slist_prepend (info->attributes,
4579 GINT_TO_POINTER (column));
4580 info->attributes = g_slist_prepend (info->attributes,
4581 g_strdup (attribute));
4585 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4587 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4589 while (icon_view->priv->cell_list)
4591 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4592 free_cell_info (info);
4593 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4594 icon_view->priv->cell_list);
4597 icon_view->priv->n_cells = 0;
4601 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4602 GtkCellRenderer *cell,
4603 GtkCellLayoutDataFunc func,
4605 GDestroyNotify destroy)
4607 GtkIconViewCellInfo *info;
4608 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4610 info = gtk_icon_view_get_cell_info (icon_view, cell);
4611 g_return_if_fail (info != NULL);
4615 GDestroyNotify d = info->destroy;
4617 info->destroy = NULL;
4618 d (info->func_data);
4622 info->func_data = func_data;
4623 info->destroy = destroy;
4627 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4628 GtkCellRenderer *renderer)
4630 GtkIconViewCellInfo *info;
4632 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4634 free_cell_attributes (info);
4638 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4639 GtkCellRenderer *cell,
4642 GtkIconView *icon_view;
4644 GtkIconViewCellInfo *info;
4647 icon_view = GTK_ICON_VIEW (layout);
4649 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4651 info = gtk_icon_view_get_cell_info (icon_view, cell);
4653 g_return_if_fail (info != NULL);
4654 g_return_if_fail (position >= 0);
4656 link = g_list_find (icon_view->priv->cell_list, info);
4658 g_return_if_fail (link != NULL);
4660 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4662 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4665 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4672 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4676 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4678 GtkIconView *icon_view = (GtkIconView *)layout;
4679 GList *retval = NULL, *l;
4681 for (l = icon_view->priv->cell_list; l; l = l->next)
4683 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4685 retval = g_list_prepend (retval, info->cell);
4688 return g_list_reverse (retval);
4695 * gtk_icon_view_new:
4697 * Creates a new #GtkIconView widget
4699 * Return value: A newly created #GtkIconView widget
4704 gtk_icon_view_new (void)
4706 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4710 * gtk_icon_view_new_with_model:
4711 * @model: The model.
4713 * Creates a new #GtkIconView widget with the model @model.
4715 * Return value: A newly created #GtkIconView widget.
4720 gtk_icon_view_new_with_model (GtkTreeModel *model)
4722 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4726 * gtk_icon_view_convert_widget_to_bin_window_coords:
4727 * @icon_view: a #GtkIconView
4728 * @wx: X coordinate relative to the widget
4729 * @wy: Y coordinate relative to the widget
4730 * @bx: return location for bin_window X coordinate
4731 * @by: return location for bin_window Y coordinate
4733 * Converts widget coordinates to coordinates for the bin_window,
4734 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4739 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4747 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4749 if (icon_view->priv->bin_window)
4750 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4761 * gtk_icon_view_get_path_at_pos:
4762 * @icon_view: A #GtkIconView.
4763 * @x: The x position to be identified
4764 * @y: The y position to be identified
4766 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4767 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4768 * the cell at the specified position.
4769 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4770 * widget coordinates to bin_window coordinates.
4772 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4773 * if no icon exists at that position.
4778 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4782 GtkIconViewItem *item;
4785 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4787 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4792 path = gtk_tree_path_new_from_indices (item->index, -1);
4798 * gtk_icon_view_get_item_at_pos:
4799 * @icon_view: A #GtkIconView.
4800 * @x: The x position to be identified
4801 * @y: The y position to be identified
4802 * @path: Return location for the path, or %NULL
4803 * @cell: Return location for the renderer responsible for the cell
4804 * at (@x, @y), or %NULL
4806 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4807 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4808 * obtains the cell at the specified position. The returned path should
4809 * be freed with gtk_tree_path_free().
4810 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4811 * widget coordinates to bin_window coordinates.
4813 * Return value: %TRUE if an item exists at the specified position
4818 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4822 GtkCellRenderer **cell)
4824 GtkIconViewItem *item;
4825 GtkIconViewCellInfo *info;
4827 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4829 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4834 *path = gtk_tree_path_new_from_indices (item->index, -1);
4847 return (item != NULL);
4851 * gtk_icon_view_set_tooltip_item:
4852 * @icon_view: a #GtkIconView
4853 * @tooltip: a #GtkTooltip
4854 * @path: a #GtkTreePath
4856 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4857 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4858 * See also gtk_tooltip_set_tip_area().
4863 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4864 GtkTooltip *tooltip,
4867 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4868 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4870 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4874 * gtk_icon_view_set_tooltip_cell:
4875 * @icon_view: a #GtkIconView
4876 * @tooltip: a #GtkTooltip
4877 * @path: a #GtkTreePath
4878 * @cell: a #GtkCellRenderer or %NULL
4880 * Sets the tip area of @tooltip to the area which @cell occupies in
4881 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4883 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4888 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4889 GtkTooltip *tooltip,
4891 GtkCellRenderer *cell)
4894 GtkIconViewItem *item = NULL;
4895 GtkIconViewCellInfo *info = NULL;
4898 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4899 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4900 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4902 if (gtk_tree_path_get_depth (path) > 0)
4903 item = g_list_nth_data (icon_view->priv->items,
4904 gtk_tree_path_get_indices(path)[0]);
4911 info = gtk_icon_view_get_cell_info (icon_view, cell);
4912 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4918 rect.width = item->width;
4919 rect.height = item->height;
4922 if (icon_view->priv->bin_window)
4924 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4929 gtk_tooltip_set_tip_area (tooltip, &rect);
4934 * gtk_icon_view_get_tooltip_context:
4935 * @icon_view: an #GtkIconView
4936 * @x: the x coordinate (relative to widget coordinates)
4937 * @y: the y coordinate (relative to widget coordinates)
4938 * @keyboard_tip: whether this is a keyboard tooltip or not
4939 * @model: a pointer to receive a #GtkTreeModel or %NULL
4940 * @path: a pointer to receive a #GtkTreePath or %NULL
4941 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4943 * This function is supposed to be used in a #GtkWidget::query-tooltip
4944 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4945 * which are received in the signal handler, should be passed to this
4946 * function without modification.
4948 * The return value indicates whether there is an icon view item at the given
4949 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4950 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4951 * @model, @path and @iter which have been provided will be set to point to
4952 * that row and the corresponding model. @x and @y will always be converted
4953 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4955 * Return value: whether or not the given tooltip context points to a item
4960 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4963 gboolean keyboard_tip,
4964 GtkTreeModel **model,
4968 GtkTreePath *tmppath = NULL;
4970 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4971 g_return_val_if_fail (x != NULL, FALSE);
4972 g_return_val_if_fail (y != NULL, FALSE);
4976 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4983 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4986 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4991 *model = gtk_icon_view_get_model (icon_view);
4994 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5000 gtk_tree_path_free (tmppath);
5006 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5009 gboolean keyboard_tip,
5010 GtkTooltip *tooltip,
5016 GtkTreeModel *model;
5017 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5019 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5022 &model, &path, &iter))
5025 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5029 gtk_tree_path_free (path);
5033 gtk_tooltip_set_markup (tooltip, str);
5034 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5036 gtk_tree_path_free (path);
5044 * gtk_icon_view_set_tooltip_column:
5045 * @icon_view: a #GtkIconView
5046 * @column: an integer, which is a valid column number for @icon_view's model
5048 * If you only plan to have simple (text-only) tooltips on full items, you
5049 * can use this function to have #GtkIconView handle these automatically
5050 * for you. @column should be set to the column in @icon_view's model
5051 * containing the tooltip texts, or -1 to disable this feature.
5053 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5054 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5059 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5062 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5064 if (column == icon_view->priv->tooltip_column)
5069 g_signal_handlers_disconnect_by_func (icon_view,
5070 gtk_icon_view_set_tooltip_query_cb,
5072 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5076 if (icon_view->priv->tooltip_column == -1)
5078 g_signal_connect (icon_view, "query-tooltip",
5079 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5080 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5084 icon_view->priv->tooltip_column = column;
5085 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5089 * gtk_icon_view_get_tooltip_column:
5090 * @icon_view: a #GtkIconView
5092 * Returns the column of @icon_view's model which is being used for
5093 * displaying tooltips on @icon_view's rows.
5095 * Return value: the index of the tooltip column that is currently being
5096 * used, or -1 if this is disabled.
5101 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5103 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5105 return icon_view->priv->tooltip_column;
5109 * gtk_icon_view_get_visible_range:
5110 * @icon_view: A #GtkIconView
5111 * @start_path: Return location for start of region, or %NULL
5112 * @end_path: Return location for end of region, or %NULL
5114 * Sets @start_path and @end_path to be the first and last visible path.
5115 * Note that there may be invisible paths in between.
5117 * Both paths should be freed with gtk_tree_path_free() after use.
5119 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5124 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5125 GtkTreePath **start_path,
5126 GtkTreePath **end_path)
5128 gint start_index = -1;
5129 gint end_index = -1;
5132 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5134 if (icon_view->priv->hadjustment == NULL ||
5135 icon_view->priv->vadjustment == NULL)
5138 if (start_path == NULL && end_path == NULL)
5141 for (icons = icon_view->priv->items; icons; icons = icons->next)
5143 GtkIconViewItem *item = icons->data;
5145 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5146 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5147 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5148 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5150 if (start_index == -1)
5151 start_index = item->index;
5152 end_index = item->index;
5156 if (start_path && start_index != -1)
5157 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5158 if (end_path && end_index != -1)
5159 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5161 return start_index != -1;
5165 * gtk_icon_view_selected_foreach:
5166 * @icon_view: A #GtkIconView.
5167 * @func: The funcion to call for each selected icon.
5168 * @data: User data to pass to the function.
5170 * Calls a function for each selected icon. Note that the model or
5171 * selection cannot be modified from within this function.
5176 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5177 GtkIconViewForeachFunc func,
5182 for (list = icon_view->priv->items; list; list = list->next)
5184 GtkIconViewItem *item = list->data;
5185 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5188 (* func) (icon_view, path, data);
5190 gtk_tree_path_free (path);
5195 * gtk_icon_view_set_selection_mode:
5196 * @icon_view: A #GtkIconView.
5197 * @mode: The selection mode
5199 * Sets the selection mode of the @icon_view.
5204 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5205 GtkSelectionMode mode)
5207 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5209 if (mode == icon_view->priv->selection_mode)
5212 if (mode == GTK_SELECTION_NONE ||
5213 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5214 gtk_icon_view_unselect_all (icon_view);
5216 icon_view->priv->selection_mode = mode;
5218 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5222 * gtk_icon_view_get_selection_mode:
5223 * @icon_view: A #GtkIconView.
5225 * Gets the selection mode of the @icon_view.
5227 * Return value: the current selection mode
5232 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5234 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5236 return icon_view->priv->selection_mode;
5240 * gtk_icon_view_set_model:
5241 * @icon_view: A #GtkIconView.
5242 * @model: The model.
5244 * Sets the model for a #GtkIconView.
5245 * If the @icon_view already has a model set, it will remove
5246 * it before setting the new model. If @model is %NULL, then
5247 * it will unset the old model.
5252 gtk_icon_view_set_model (GtkIconView *icon_view,
5253 GtkTreeModel *model)
5255 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5256 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5258 if (icon_view->priv->model == model)
5261 if (icon_view->priv->scroll_to_path)
5263 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5264 icon_view->priv->scroll_to_path = NULL;
5267 gtk_icon_view_stop_editing (icon_view, TRUE);
5273 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5275 if (icon_view->priv->pixbuf_column != -1)
5277 column_type = gtk_tree_model_get_column_type (model,
5278 icon_view->priv->pixbuf_column);
5280 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5283 if (icon_view->priv->text_column != -1)
5285 column_type = gtk_tree_model_get_column_type (model,
5286 icon_view->priv->text_column);
5288 g_return_if_fail (column_type == G_TYPE_STRING);
5291 if (icon_view->priv->markup_column != -1)
5293 column_type = gtk_tree_model_get_column_type (model,
5294 icon_view->priv->markup_column);
5296 g_return_if_fail (column_type == G_TYPE_STRING);
5301 if (icon_view->priv->model)
5303 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5304 gtk_icon_view_row_changed,
5306 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5307 gtk_icon_view_row_inserted,
5309 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5310 gtk_icon_view_row_deleted,
5312 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5313 gtk_icon_view_rows_reordered,
5316 g_object_unref (icon_view->priv->model);
5318 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5319 g_list_free (icon_view->priv->items);
5320 icon_view->priv->items = NULL;
5321 icon_view->priv->anchor_item = NULL;
5322 icon_view->priv->cursor_item = NULL;
5323 icon_view->priv->last_single_clicked = NULL;
5324 icon_view->priv->width = 0;
5325 icon_view->priv->height = 0;
5328 icon_view->priv->model = model;
5330 if (icon_view->priv->model)
5332 g_object_ref (icon_view->priv->model);
5333 g_signal_connect (icon_view->priv->model,
5335 G_CALLBACK (gtk_icon_view_row_changed),
5337 g_signal_connect (icon_view->priv->model,
5339 G_CALLBACK (gtk_icon_view_row_inserted),
5341 g_signal_connect (icon_view->priv->model,
5343 G_CALLBACK (gtk_icon_view_row_deleted),
5345 g_signal_connect (icon_view->priv->model,
5347 G_CALLBACK (gtk_icon_view_rows_reordered),
5350 gtk_icon_view_build_items (icon_view);
5352 gtk_icon_view_queue_layout (icon_view);
5355 g_object_notify (G_OBJECT (icon_view), "model");
5357 if (GTK_WIDGET_REALIZED (icon_view))
5358 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5362 * gtk_icon_view_get_model:
5363 * @icon_view: a #GtkIconView
5365 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5368 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5373 gtk_icon_view_get_model (GtkIconView *icon_view)
5375 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5377 return icon_view->priv->model;
5381 update_text_cell (GtkIconView *icon_view)
5383 GtkIconViewCellInfo *info;
5387 if (icon_view->priv->text_column == -1 &&
5388 icon_view->priv->markup_column == -1)
5390 if (icon_view->priv->text_cell != -1)
5392 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5393 icon_view->priv->pixbuf_cell--;
5395 info = g_list_nth_data (icon_view->priv->cell_list,
5396 icon_view->priv->text_cell);
5398 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5400 free_cell_info (info);
5402 icon_view->priv->n_cells--;
5403 icon_view->priv->text_cell = -1;
5408 if (icon_view->priv->text_cell == -1)
5410 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5411 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5412 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5415 if (info->cell == cell)
5417 icon_view->priv->text_cell = i;
5423 info = g_list_nth_data (icon_view->priv->cell_list,
5424 icon_view->priv->text_cell);
5426 if (icon_view->priv->markup_column != -1)
5427 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5429 "markup", icon_view->priv->markup_column,
5432 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5434 "text", icon_view->priv->text_column,
5437 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5438 g_object_set (info->cell,
5439 "alignment", PANGO_ALIGN_CENTER,
5440 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5445 g_object_set (info->cell,
5446 "alignment", PANGO_ALIGN_LEFT,
5447 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5455 update_pixbuf_cell (GtkIconView *icon_view)
5457 GtkIconViewCellInfo *info;
5461 if (icon_view->priv->pixbuf_column == -1)
5463 if (icon_view->priv->pixbuf_cell != -1)
5465 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5466 icon_view->priv->text_cell--;
5468 info = g_list_nth_data (icon_view->priv->cell_list,
5469 icon_view->priv->pixbuf_cell);
5471 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5473 free_cell_info (info);
5475 icon_view->priv->n_cells--;
5476 icon_view->priv->pixbuf_cell = -1;
5481 if (icon_view->priv->pixbuf_cell == -1)
5483 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5485 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5486 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5489 if (info->cell == cell)
5491 icon_view->priv->pixbuf_cell = i;
5497 info = g_list_nth_data (icon_view->priv->cell_list,
5498 icon_view->priv->pixbuf_cell);
5500 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5502 "pixbuf", icon_view->priv->pixbuf_column,
5505 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5506 g_object_set (info->cell,
5511 g_object_set (info->cell,
5519 * gtk_icon_view_set_text_column:
5520 * @icon_view: A #GtkIconView.
5521 * @column: A column in the currently used model, or -1 to display no text
5523 * Sets the column with text for @icon_view to be @column. The text
5524 * column must be of type #G_TYPE_STRING.
5529 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5532 if (column == icon_view->priv->text_column)
5536 icon_view->priv->text_column = -1;
5539 if (icon_view->priv->model != NULL)
5543 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5545 g_return_if_fail (column_type == G_TYPE_STRING);
5548 icon_view->priv->text_column = column;
5551 gtk_icon_view_stop_editing (icon_view, TRUE);
5553 update_text_cell (icon_view);
5555 gtk_icon_view_invalidate_sizes (icon_view);
5556 gtk_icon_view_queue_layout (icon_view);
5558 g_object_notify (G_OBJECT (icon_view), "text-column");
5562 * gtk_icon_view_get_text_column:
5563 * @icon_view: A #GtkIconView.
5565 * Returns the column with text for @icon_view.
5567 * Returns: the text column, or -1 if it's unset.
5572 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5574 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5576 return icon_view->priv->text_column;
5580 * gtk_icon_view_set_markup_column:
5581 * @icon_view: A #GtkIconView.
5582 * @column: A column in the currently used model, or -1 to display no text
5584 * Sets the column with markup information for @icon_view to be
5585 * @column. The markup column must be of type #G_TYPE_STRING.
5586 * If the markup column is set to something, it overrides
5587 * the text column set by gtk_icon_view_set_text_column().
5592 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5595 if (column == icon_view->priv->markup_column)
5599 icon_view->priv->markup_column = -1;
5602 if (icon_view->priv->model != NULL)
5606 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5608 g_return_if_fail (column_type == G_TYPE_STRING);
5611 icon_view->priv->markup_column = column;
5614 gtk_icon_view_stop_editing (icon_view, TRUE);
5616 update_text_cell (icon_view);
5618 gtk_icon_view_invalidate_sizes (icon_view);
5619 gtk_icon_view_queue_layout (icon_view);
5621 g_object_notify (G_OBJECT (icon_view), "markup-column");
5625 * gtk_icon_view_get_markup_column:
5626 * @icon_view: A #GtkIconView.
5628 * Returns the column with markup text for @icon_view.
5630 * Returns: the markup column, or -1 if it's unset.
5635 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5637 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5639 return icon_view->priv->markup_column;
5643 * gtk_icon_view_set_pixbuf_column:
5644 * @icon_view: A #GtkIconView.
5645 * @column: A column in the currently used model, or -1 to disable
5647 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5648 * column must be of type #GDK_TYPE_PIXBUF
5653 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5656 if (column == icon_view->priv->pixbuf_column)
5660 icon_view->priv->pixbuf_column = -1;
5663 if (icon_view->priv->model != NULL)
5667 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5669 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5672 icon_view->priv->pixbuf_column = column;
5675 gtk_icon_view_stop_editing (icon_view, TRUE);
5677 update_pixbuf_cell (icon_view);
5679 gtk_icon_view_invalidate_sizes (icon_view);
5680 gtk_icon_view_queue_layout (icon_view);
5682 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5687 * gtk_icon_view_get_pixbuf_column:
5688 * @icon_view: A #GtkIconView.
5690 * Returns the column with pixbufs for @icon_view.
5692 * Returns: the pixbuf column, or -1 if it's unset.
5697 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5699 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5701 return icon_view->priv->pixbuf_column;
5705 * gtk_icon_view_select_path:
5706 * @icon_view: A #GtkIconView.
5707 * @path: The #GtkTreePath to be selected.
5709 * Selects the row at @path.
5714 gtk_icon_view_select_path (GtkIconView *icon_view,
5717 GtkIconViewItem *item = NULL;
5719 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5720 g_return_if_fail (icon_view->priv->model != NULL);
5721 g_return_if_fail (path != NULL);
5723 if (gtk_tree_path_get_depth (path) > 0)
5724 item = g_list_nth_data (icon_view->priv->items,
5725 gtk_tree_path_get_indices(path)[0]);
5728 gtk_icon_view_select_item (icon_view, item);
5732 * gtk_icon_view_unselect_path:
5733 * @icon_view: A #GtkIconView.
5734 * @path: The #GtkTreePath to be unselected.
5736 * Unselects the row at @path.
5741 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5744 GtkIconViewItem *item;
5746 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5747 g_return_if_fail (icon_view->priv->model != NULL);
5748 g_return_if_fail (path != NULL);
5750 item = g_list_nth_data (icon_view->priv->items,
5751 gtk_tree_path_get_indices(path)[0]);
5756 gtk_icon_view_unselect_item (icon_view, item);
5760 * gtk_icon_view_get_selected_items:
5761 * @icon_view: A #GtkIconView.
5763 * Creates a list of paths of all selected items. Additionally, if you are
5764 * planning on modifying the model after calling this function, you may
5765 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5766 * To do this, you can use gtk_tree_row_reference_new().
5768 * To free the return value, use:
5770 * g_list_foreach (list, gtk_tree_path_free, NULL);
5771 * g_list_free (list);
5774 * Return value: A #GList containing a #GtkTreePath for each selected row.
5779 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5782 GList *selected = NULL;
5784 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5786 for (list = icon_view->priv->items; list != NULL; list = list->next)
5788 GtkIconViewItem *item = list->data;
5792 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5794 selected = g_list_prepend (selected, path);
5802 * gtk_icon_view_select_all:
5803 * @icon_view: A #GtkIconView.
5805 * Selects all the icons. @icon_view must has its selection mode set
5806 * to #GTK_SELECTION_MULTIPLE.
5811 gtk_icon_view_select_all (GtkIconView *icon_view)
5814 gboolean dirty = FALSE;
5816 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5818 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5821 for (items = icon_view->priv->items; items; items = items->next)
5823 GtkIconViewItem *item = items->data;
5825 if (!item->selected)
5828 item->selected = TRUE;
5829 gtk_icon_view_queue_draw_item (icon_view, item);
5834 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5838 * gtk_icon_view_unselect_all:
5839 * @icon_view: A #GtkIconView.
5841 * Unselects all the icons.
5846 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5848 gboolean dirty = FALSE;
5850 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5852 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5855 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5858 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5862 * gtk_icon_view_path_is_selected:
5863 * @icon_view: A #GtkIconView.
5864 * @path: A #GtkTreePath to check selection on.
5866 * Returns %TRUE if the icon pointed to by @path is currently
5867 * selected. If @path does not point to a valid location, %FALSE is returned.
5869 * Return value: %TRUE if @path is selected.
5874 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5877 GtkIconViewItem *item;
5879 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5880 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5881 g_return_val_if_fail (path != NULL, FALSE);
5883 item = g_list_nth_data (icon_view->priv->items,
5884 gtk_tree_path_get_indices(path)[0]);
5889 return item->selected;
5893 * gtk_icon_view_item_activated:
5894 * @icon_view: A #GtkIconView
5895 * @path: The #GtkTreePath to be activated
5897 * Activates the item determined by @path.
5902 gtk_icon_view_item_activated (GtkIconView *icon_view,
5905 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5906 g_return_if_fail (path != NULL);
5908 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5912 * gtk_icon_view_set_orientation:
5913 * @icon_view: a #GtkIconView
5914 * @orientation: the relative position of texts and icons
5916 * Sets the ::orientation property which determines whether the labels
5917 * are drawn beside the icons instead of below.
5922 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5923 GtkOrientation orientation)
5925 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5927 if (icon_view->priv->orientation != orientation)
5929 icon_view->priv->orientation = orientation;
5931 gtk_icon_view_stop_editing (icon_view, TRUE);
5932 gtk_icon_view_invalidate_sizes (icon_view);
5933 gtk_icon_view_queue_layout (icon_view);
5935 update_text_cell (icon_view);
5936 update_pixbuf_cell (icon_view);
5938 g_object_notify (G_OBJECT (icon_view), "orientation");
5943 * gtk_icon_view_get_orientation:
5944 * @icon_view: a #GtkIconView
5946 * Returns the value of the ::orientation property which determines
5947 * whether the labels are drawn beside the icons instead of below.
5949 * Return value: the relative position of texts and icons
5954 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5956 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5957 GTK_ORIENTATION_VERTICAL);
5959 return icon_view->priv->orientation;
5963 * gtk_icon_view_set_columns:
5964 * @icon_view: a #GtkIconView
5965 * @columns: the number of columns
5967 * Sets the ::columns property which determines in how
5968 * many columns the icons are arranged. If @columns is
5969 * -1, the number of columns will be chosen automatically
5970 * to fill the available area.
5975 gtk_icon_view_set_columns (GtkIconView *icon_view,
5978 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5980 if (icon_view->priv->columns != columns)
5982 icon_view->priv->columns = columns;
5984 gtk_icon_view_stop_editing (icon_view, TRUE);
5985 gtk_icon_view_queue_layout (icon_view);
5987 g_object_notify (G_OBJECT (icon_view), "columns");
5992 * gtk_icon_view_get_columns:
5993 * @icon_view: a #GtkIconView
5995 * Returns the value of the ::columns property.
5997 * Return value: the number of columns, or -1
6002 gtk_icon_view_get_columns (GtkIconView *icon_view)
6004 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6006 return icon_view->priv->columns;
6010 * gtk_icon_view_set_item_width:
6011 * @icon_view: a #GtkIconView
6012 * @item_width: the width for each item
6014 * Sets the ::item-width property which specifies the width
6015 * to use for each item. If it is set to -1, the icon view will
6016 * automatically determine a suitable item size.
6021 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6024 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6026 if (icon_view->priv->item_width != item_width)
6028 icon_view->priv->item_width = item_width;
6030 gtk_icon_view_stop_editing (icon_view, TRUE);
6031 gtk_icon_view_invalidate_sizes (icon_view);
6032 gtk_icon_view_queue_layout (icon_view);
6034 update_text_cell (icon_view);
6036 g_object_notify (G_OBJECT (icon_view), "item-width");
6041 * gtk_icon_view_get_item_width:
6042 * @icon_view: a #GtkIconView
6044 * Returns the value of the ::item-width property.
6046 * Return value: the width of a single item, or -1
6051 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6053 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6055 return icon_view->priv->item_width;
6060 * gtk_icon_view_set_spacing:
6061 * @icon_view: a #GtkIconView
6062 * @spacing: the spacing
6064 * Sets the ::spacing property which specifies the space
6065 * which is inserted between the cells (i.e. the icon and
6066 * the text) of an item.
6071 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6074 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6076 if (icon_view->priv->spacing != spacing)
6078 icon_view->priv->spacing = spacing;
6080 gtk_icon_view_stop_editing (icon_view, TRUE);
6081 gtk_icon_view_invalidate_sizes (icon_view);
6082 gtk_icon_view_queue_layout (icon_view);
6084 g_object_notify (G_OBJECT (icon_view), "spacing");
6089 * gtk_icon_view_get_spacing:
6090 * @icon_view: a #GtkIconView
6092 * Returns the value of the ::spacing property.
6094 * Return value: the space between cells
6099 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6101 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6103 return icon_view->priv->spacing;
6107 * gtk_icon_view_set_row_spacing:
6108 * @icon_view: a #GtkIconView
6109 * @row_spacing: the row spacing
6111 * Sets the ::row-spacing property which specifies the space
6112 * which is inserted between the rows of the icon view.
6117 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6120 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6122 if (icon_view->priv->row_spacing != row_spacing)
6124 icon_view->priv->row_spacing = row_spacing;
6126 gtk_icon_view_stop_editing (icon_view, TRUE);
6127 gtk_icon_view_invalidate_sizes (icon_view);
6128 gtk_icon_view_queue_layout (icon_view);
6130 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6135 * gtk_icon_view_get_row_spacing:
6136 * @icon_view: a #GtkIconView
6138 * Returns the value of the ::row-spacing property.
6140 * Return value: the space between rows
6145 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6147 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6149 return icon_view->priv->row_spacing;
6153 * gtk_icon_view_set_column_spacing:
6154 * @icon_view: a #GtkIconView
6155 * @column_spacing: the column spacing
6157 * Sets the ::column-spacing property which specifies the space
6158 * which is inserted between the columns of the icon view.
6163 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6164 gint column_spacing)
6166 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6168 if (icon_view->priv->column_spacing != column_spacing)
6170 icon_view->priv->column_spacing = column_spacing;
6172 gtk_icon_view_stop_editing (icon_view, TRUE);
6173 gtk_icon_view_invalidate_sizes (icon_view);
6174 gtk_icon_view_queue_layout (icon_view);
6176 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6181 * gtk_icon_view_get_column_spacing:
6182 * @icon_view: a #GtkIconView
6184 * Returns the value of the ::column-spacing property.
6186 * Return value: the space between columns
6191 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6193 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6195 return icon_view->priv->column_spacing;
6199 * gtk_icon_view_set_margin:
6200 * @icon_view: a #GtkIconView
6201 * @margin: the margin
6203 * Sets the ::margin property which specifies the space
6204 * which is inserted at the top, bottom, left and right
6210 gtk_icon_view_set_margin (GtkIconView *icon_view,
6213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6215 if (icon_view->priv->margin != margin)
6217 icon_view->priv->margin = margin;
6219 gtk_icon_view_stop_editing (icon_view, TRUE);
6220 gtk_icon_view_invalidate_sizes (icon_view);
6221 gtk_icon_view_queue_layout (icon_view);
6223 g_object_notify (G_OBJECT (icon_view), "margin");
6228 * gtk_icon_view_get_margin:
6229 * @icon_view: a #GtkIconView
6231 * Returns the value of the ::margin property.
6233 * Return value: the space at the borders
6238 gtk_icon_view_get_margin (GtkIconView *icon_view)
6240 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6242 return icon_view->priv->margin;
6246 /* Get/set whether drag_motion requested the drag data and
6247 * drag_data_received should thus not actually insert the data,
6248 * since the data doesn't result from a drop.
6251 set_status_pending (GdkDragContext *context,
6252 GdkDragAction suggested_action)
6254 g_object_set_data (G_OBJECT (context),
6255 I_("gtk-icon-view-status-pending"),
6256 GINT_TO_POINTER (suggested_action));
6259 static GdkDragAction
6260 get_status_pending (GdkDragContext *context)
6262 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6263 "gtk-icon-view-status-pending"));
6267 unset_reorderable (GtkIconView *icon_view)
6269 if (icon_view->priv->reorderable)
6271 icon_view->priv->reorderable = FALSE;
6272 g_object_notify (G_OBJECT (icon_view), "reorderable");
6277 set_source_row (GdkDragContext *context,
6278 GtkTreeModel *model,
6279 GtkTreePath *source_row)
6282 g_object_set_data_full (G_OBJECT (context),
6283 I_("gtk-icon-view-source-row"),
6284 gtk_tree_row_reference_new (model, source_row),
6285 (GDestroyNotify) gtk_tree_row_reference_free);
6287 g_object_set_data_full (G_OBJECT (context),
6288 I_("gtk-icon-view-source-row"),
6293 get_source_row (GdkDragContext *context)
6295 GtkTreeRowReference *ref;
6297 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6300 return gtk_tree_row_reference_get_path (ref);
6307 GtkTreeRowReference *dest_row;
6308 gboolean empty_view_drop;
6309 gboolean drop_append_mode;
6313 dest_row_free (gpointer data)
6315 DestRow *dr = (DestRow *)data;
6317 gtk_tree_row_reference_free (dr->dest_row);
6322 set_dest_row (GdkDragContext *context,
6323 GtkTreeModel *model,
6324 GtkTreePath *dest_row,
6325 gboolean empty_view_drop,
6326 gboolean drop_append_mode)
6332 g_object_set_data_full (G_OBJECT (context),
6333 I_("gtk-icon-view-dest-row"),
6338 dr = g_new0 (DestRow, 1);
6340 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6341 dr->empty_view_drop = empty_view_drop;
6342 dr->drop_append_mode = drop_append_mode;
6343 g_object_set_data_full (G_OBJECT (context),
6344 I_("gtk-icon-view-dest-row"),
6345 dr, (GDestroyNotify) dest_row_free);
6349 get_dest_row (GdkDragContext *context)
6353 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6357 GtkTreePath *path = NULL;
6360 path = gtk_tree_row_reference_get_path (dr->dest_row);
6361 else if (dr->empty_view_drop)
6362 path = gtk_tree_path_new_from_indices (0, -1);
6366 if (path && dr->drop_append_mode)
6367 gtk_tree_path_next (path);
6376 check_model_dnd (GtkTreeModel *model,
6377 GType required_iface,
6378 const gchar *signal)
6380 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6382 g_warning ("You must override the default '%s' handler "
6383 "on GtkIconView when using models that don't support "
6384 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6385 "is to connect to '%s' and call "
6386 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6387 "the default handler from running. Look at the source code "
6388 "for the default handler in gtkiconview.c to get an idea what "
6389 "your handler should do. (gtkiconview.c is in the GTK+ source "
6390 "code.) If you're using GTK+ from a language other than C, "
6391 "there may be a more natural way to override default handlers, e.g. via derivation.",
6392 signal, g_type_name (required_iface), signal);
6400 remove_scroll_timeout (GtkIconView *icon_view)
6402 if (icon_view->priv->scroll_timeout_id != 0)
6404 g_source_remove (icon_view->priv->scroll_timeout_id);
6406 icon_view->priv->scroll_timeout_id = 0;
6411 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6413 gint px, py, x, y, width, height;
6414 gint hoffset, voffset;
6417 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6418 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6420 /* see if we are near the edge. */
6421 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6423 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6425 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6427 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6431 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6432 icon_view->priv->vadjustment->lower,
6433 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6434 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6438 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6439 icon_view->priv->hadjustment->lower,
6440 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6441 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6447 drag_scroll_timeout (gpointer data)
6449 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6451 gtk_icon_view_autoscroll (icon_view);
6458 set_destination (GtkIconView *icon_view,
6459 GdkDragContext *context,
6462 GdkDragAction *suggested_action,
6466 GtkTreePath *path = NULL;
6467 GtkIconViewDropPosition pos;
6468 GtkIconViewDropPosition old_pos;
6469 GtkTreePath *old_dest_path = NULL;
6470 gboolean can_drop = FALSE;
6472 widget = GTK_WIDGET (icon_view);
6474 *suggested_action = 0;
6477 if (!icon_view->priv->dest_set)
6479 /* someone unset us as a drag dest, note that if
6480 * we return FALSE drag_leave isn't called
6483 gtk_icon_view_set_drag_dest_item (icon_view,
6485 GTK_ICON_VIEW_DROP_LEFT);
6487 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6489 return FALSE; /* no longer a drop site */
6492 *target = gtk_drag_dest_find_target (widget, context,
6493 gtk_drag_dest_get_target_list (widget));
6494 if (*target == GDK_NONE)
6497 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6500 GtkTreeModel *model;
6502 /* the row got dropped on empty space, let's setup a special case
6506 gtk_tree_path_free (path);
6508 model = gtk_icon_view_get_model (icon_view);
6510 n_children = gtk_tree_model_iter_n_children (model, NULL);
6513 pos = GTK_ICON_VIEW_DROP_BELOW;
6514 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6518 pos = GTK_ICON_VIEW_DROP_ABOVE;
6519 path = gtk_tree_path_new_from_indices (0, -1);
6529 gtk_icon_view_get_drag_dest_item (icon_view,
6534 gtk_tree_path_free (old_dest_path);
6536 if (TRUE /* FIXME if the location droppable predicate */)
6544 GtkWidget *source_widget;
6546 *suggested_action = context->suggested_action;
6547 source_widget = gtk_drag_get_source_widget (context);
6549 if (source_widget == widget)
6551 /* Default to MOVE, unless the user has
6552 * pressed ctrl or shift to affect available actions
6554 if ((context->actions & GDK_ACTION_MOVE) != 0)
6555 *suggested_action = GDK_ACTION_MOVE;
6558 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6563 /* can't drop here */
6564 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6566 GTK_ICON_VIEW_DROP_LEFT);
6570 gtk_tree_path_free (path);
6576 get_logical_destination (GtkIconView *icon_view,
6577 gboolean *drop_append_mode)
6579 /* adjust path to point to the row the drop goes in front of */
6580 GtkTreePath *path = NULL;
6581 GtkIconViewDropPosition pos;
6583 *drop_append_mode = FALSE;
6585 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6590 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6591 pos == GTK_ICON_VIEW_DROP_BELOW)
6594 GtkTreeModel *model = icon_view->priv->model;
6596 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6597 !gtk_tree_model_iter_next (model, &iter))
6598 *drop_append_mode = TRUE;
6601 *drop_append_mode = FALSE;
6602 gtk_tree_path_next (path);
6610 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6611 GdkEventMotion *event)
6613 GtkWidget *widget = GTK_WIDGET (icon_view);
6614 GdkDragContext *context;
6615 GtkTreePath *path = NULL;
6617 GtkTreeModel *model;
6618 gboolean retval = FALSE;
6620 if (!icon_view->priv->source_set)
6623 if (icon_view->priv->pressed_button < 0)
6626 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6627 icon_view->priv->press_start_x,
6628 icon_view->priv->press_start_y,
6629 event->x, event->y))
6632 model = gtk_icon_view_get_model (icon_view);
6637 button = icon_view->priv->pressed_button;
6638 icon_view->priv->pressed_button = -1;
6640 path = gtk_icon_view_get_path_at_pos (icon_view,
6641 icon_view->priv->press_start_x,
6642 icon_view->priv->press_start_y);
6647 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6648 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6652 /* FIXME Check whether we're a start button, if not return FALSE and
6656 /* Now we can begin the drag */
6660 context = gtk_drag_begin (widget,
6661 gtk_drag_source_get_target_list (widget),
6662 icon_view->priv->source_actions,
6666 set_source_row (context, model, path);
6670 gtk_tree_path_free (path);
6675 /* Source side drag signals */
6677 gtk_icon_view_drag_begin (GtkWidget *widget,
6678 GdkDragContext *context)
6680 GtkIconView *icon_view;
6681 GtkIconViewItem *item;
6686 icon_view = GTK_ICON_VIEW (widget);
6688 /* if the user uses a custom DnD impl, we don't set the icon here */
6689 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6692 item = gtk_icon_view_get_item_at_coords (icon_view,
6693 icon_view->priv->press_start_x,
6694 icon_view->priv->press_start_y,
6698 g_return_if_fail (item != NULL);
6700 x = icon_view->priv->press_start_x - item->x + 1;
6701 y = icon_view->priv->press_start_y - item->y + 1;
6703 path = gtk_tree_path_new_from_indices (item->index, -1);
6704 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6705 gtk_tree_path_free (path);
6707 gtk_drag_set_icon_pixmap (context,
6708 gdk_drawable_get_colormap (icon),
6713 g_object_unref (icon);
6717 gtk_icon_view_drag_end (GtkWidget *widget,
6718 GdkDragContext *context)
6724 gtk_icon_view_drag_data_get (GtkWidget *widget,
6725 GdkDragContext *context,
6726 GtkSelectionData *selection_data,
6730 GtkIconView *icon_view;
6731 GtkTreeModel *model;
6732 GtkTreePath *source_row;
6734 icon_view = GTK_ICON_VIEW (widget);
6735 model = gtk_icon_view_get_model (icon_view);
6740 if (!icon_view->priv->source_set)
6743 source_row = get_source_row (context);
6745 if (source_row == NULL)
6748 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6749 * any model; for DragSource models there are some other targets
6753 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6754 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6759 /* If drag_data_get does nothing, try providing row data. */
6760 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6761 gtk_tree_set_row_drag_data (selection_data,
6766 gtk_tree_path_free (source_row);
6770 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6771 GdkDragContext *context)
6773 GtkTreeModel *model;
6774 GtkIconView *icon_view;
6775 GtkTreePath *source_row;
6777 icon_view = GTK_ICON_VIEW (widget);
6778 model = gtk_icon_view_get_model (icon_view);
6780 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6783 if (!icon_view->priv->source_set)
6786 source_row = get_source_row (context);
6788 if (source_row == NULL)
6791 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6794 gtk_tree_path_free (source_row);
6796 set_source_row (context, NULL, NULL);
6799 /* Target side drag signals */
6801 gtk_icon_view_drag_leave (GtkWidget *widget,
6802 GdkDragContext *context,
6805 GtkIconView *icon_view;
6807 icon_view = GTK_ICON_VIEW (widget);
6809 /* unset any highlight row */
6810 gtk_icon_view_set_drag_dest_item (icon_view,
6812 GTK_ICON_VIEW_DROP_LEFT);
6814 remove_scroll_timeout (icon_view);
6818 gtk_icon_view_drag_motion (GtkWidget *widget,
6819 GdkDragContext *context,
6824 GtkTreePath *path = NULL;
6825 GtkIconViewDropPosition pos;
6826 GtkIconView *icon_view;
6827 GdkDragAction suggested_action = 0;
6831 icon_view = GTK_ICON_VIEW (widget);
6833 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6836 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6838 /* we only know this *after* set_desination_row */
6839 empty = icon_view->priv->empty_view_drop;
6841 if (path == NULL && !empty)
6843 /* Can't drop here. */
6844 gdk_drag_status (context, 0, time);
6848 if (icon_view->priv->scroll_timeout_id == 0)
6850 icon_view->priv->scroll_timeout_id =
6851 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6854 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6856 /* Request data so we can use the source row when
6857 * determining whether to accept the drop
6859 set_status_pending (context, suggested_action);
6860 gtk_drag_get_data (widget, context, target, time);
6864 set_status_pending (context, 0);
6865 gdk_drag_status (context, suggested_action, time);
6870 gtk_tree_path_free (path);
6876 gtk_icon_view_drag_drop (GtkWidget *widget,
6877 GdkDragContext *context,
6882 GtkIconView *icon_view;
6884 GdkDragAction suggested_action = 0;
6885 GdkAtom target = GDK_NONE;
6886 GtkTreeModel *model;
6887 gboolean drop_append_mode;
6889 icon_view = GTK_ICON_VIEW (widget);
6890 model = gtk_icon_view_get_model (icon_view);
6892 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6894 if (!icon_view->priv->dest_set)
6897 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6900 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6903 path = get_logical_destination (icon_view, &drop_append_mode);
6905 if (target != GDK_NONE && path != NULL)
6907 /* in case a motion had requested drag data, change things so we
6908 * treat drag data receives as a drop.
6910 set_status_pending (context, 0);
6911 set_dest_row (context, model, path,
6912 icon_view->priv->empty_view_drop, drop_append_mode);
6916 gtk_tree_path_free (path);
6918 /* Unset this thing */
6919 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6921 if (target != GDK_NONE)
6923 gtk_drag_get_data (widget, context, target, time);
6931 gtk_icon_view_drag_data_received (GtkWidget *widget,
6932 GdkDragContext *context,
6935 GtkSelectionData *selection_data,
6940 gboolean accepted = FALSE;
6941 GtkTreeModel *model;
6942 GtkIconView *icon_view;
6943 GtkTreePath *dest_row;
6944 GdkDragAction suggested_action;
6945 gboolean drop_append_mode;
6947 icon_view = GTK_ICON_VIEW (widget);
6948 model = gtk_icon_view_get_model (icon_view);
6950 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
6953 if (!icon_view->priv->dest_set)
6956 suggested_action = get_status_pending (context);
6958 if (suggested_action)
6960 /* We are getting this data due to a request in drag_motion,
6961 * rather than due to a request in drag_drop, so we are just
6962 * supposed to call drag_status, not actually paste in the
6965 path = get_logical_destination (icon_view, &drop_append_mode);
6968 suggested_action = 0;
6970 if (suggested_action)
6972 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6975 suggested_action = 0;
6978 gdk_drag_status (context, suggested_action, time);
6981 gtk_tree_path_free (path);
6983 /* If you can't drop, remove user drop indicator until the next motion */
6984 if (suggested_action == 0)
6985 gtk_icon_view_set_drag_dest_item (icon_view,
6987 GTK_ICON_VIEW_DROP_LEFT);
6992 dest_row = get_dest_row (context);
6994 if (dest_row == NULL)
6997 if (selection_data->length >= 0)
6999 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7005 gtk_drag_finish (context,
7007 (context->action == GDK_ACTION_MOVE),
7010 gtk_tree_path_free (dest_row);
7013 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7016 /* Drag-and-Drop support */
7018 * gtk_icon_view_enable_model_drag_source:
7019 * @icon_view: a #GtkIconTreeView
7020 * @start_button_mask: Mask of allowed buttons to start drag
7021 * @targets: the table of targets that the drag will support
7022 * @n_targets: the number of items in @targets
7023 * @actions: the bitmask of possible actions for a drag from this
7026 * Turns @icon_view into a drag source for automatic DND. Calling this
7027 * method sets #GtkIconView:reorderable to %FALSE.
7032 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7033 GdkModifierType start_button_mask,
7034 const GtkTargetEntry *targets,
7036 GdkDragAction actions)
7038 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7040 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7042 icon_view->priv->start_button_mask = start_button_mask;
7043 icon_view->priv->source_actions = actions;
7045 icon_view->priv->source_set = TRUE;
7047 unset_reorderable (icon_view);
7051 * gtk_icon_view_enable_model_drag_dest:
7052 * @icon_view: a #GtkIconView
7053 * @targets: the table of targets that the drag will support
7054 * @n_targets: the number of items in @targets
7055 * @actions: the bitmask of possible actions for a drag to this
7058 * Turns @icon_view into a drop destination for automatic DND. Calling this
7059 * method sets #GtkIconView:reorderable to %FALSE.
7064 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7065 const GtkTargetEntry *targets,
7067 GdkDragAction actions)
7069 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7071 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7073 icon_view->priv->dest_actions = actions;
7075 icon_view->priv->dest_set = TRUE;
7077 unset_reorderable (icon_view);
7081 * gtk_icon_view_unset_model_drag_source:
7082 * @icon_view: a #GtkIconView
7084 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7085 * method sets #GtkIconView:reorderable to %FALSE.
7090 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7092 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7094 if (icon_view->priv->source_set)
7096 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7097 icon_view->priv->source_set = FALSE;
7100 unset_reorderable (icon_view);
7104 * gtk_icon_view_unset_model_drag_dest:
7105 * @icon_view: a #GtkIconView
7107 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7108 * method sets #GtkIconView:reorderable to %FALSE.
7113 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7115 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7117 if (icon_view->priv->dest_set)
7119 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7120 icon_view->priv->dest_set = FALSE;
7123 unset_reorderable (icon_view);
7126 /* These are useful to implement your own custom stuff. */
7128 * gtk_icon_view_set_drag_dest_item:
7129 * @icon_view: a #GtkIconView
7130 * @path: The path of the item to highlight, or %NULL.
7131 * @pos: Specifies where to drop, relative to the item
7133 * Sets the item that is highlighted for feedback.
7138 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7140 GtkIconViewDropPosition pos)
7142 /* Note; this function is exported to allow a custom DND
7143 * implementation, so it can't touch TreeViewDragInfo
7146 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7148 if (icon_view->priv->dest_item)
7150 GtkTreePath *current_path;
7151 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7152 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7153 icon_view->priv->dest_item = NULL;
7155 gtk_icon_view_queue_draw_path (icon_view, current_path);
7156 gtk_tree_path_free (current_path);
7159 /* special case a drop on an empty model */
7160 icon_view->priv->empty_view_drop = FALSE;
7161 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7162 && gtk_tree_path_get_depth (path) == 1
7163 && gtk_tree_path_get_indices (path)[0] == 0)
7167 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7170 if (n_children == 0)
7171 icon_view->priv->empty_view_drop = TRUE;
7174 icon_view->priv->dest_pos = pos;
7178 icon_view->priv->dest_item =
7179 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7180 icon_view->priv->model, path);
7182 gtk_icon_view_queue_draw_path (icon_view, path);
7187 * gtk_icon_view_get_drag_dest_item:
7188 * @icon_view: a #GtkIconView
7189 * @path: Return location for the path of the highlighted item, or %NULL.
7190 * @pos: Return location for the drop position, or %NULL
7192 * Gets information about the item that is highlighted for feedback.
7197 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7199 GtkIconViewDropPosition *pos)
7201 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7205 if (icon_view->priv->dest_item)
7206 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7212 *pos = icon_view->priv->dest_pos;
7216 * gtk_icon_view_get_dest_item_at_pos:
7217 * @icon_view: a #GtkIconView
7218 * @drag_x: the position to determine the destination item for
7219 * @drag_y: the position to determine the destination item for
7220 * @path: Return location for the path of the item, or %NULL.
7221 * @pos: Return location for the drop position, or %NULL
7223 * Determines the destination item for a given position.
7225 * Return value: whether there is an item at the given position.
7230 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7234 GtkIconViewDropPosition *pos)
7236 GtkIconViewItem *item;
7238 /* Note; this function is exported to allow a custom DND
7239 * implementation, so it can't touch TreeViewDragInfo
7242 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7243 g_return_val_if_fail (drag_x >= 0, FALSE);
7244 g_return_val_if_fail (drag_y >= 0, FALSE);
7245 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7251 item = gtk_icon_view_get_item_at_coords (icon_view,
7252 drag_x + icon_view->priv->hadjustment->value,
7253 drag_y + icon_view->priv->vadjustment->value,
7260 *path = gtk_tree_path_new_from_indices (item->index, -1);
7264 if (drag_x < item->x + item->width / 4)
7265 *pos = GTK_ICON_VIEW_DROP_LEFT;
7266 else if (drag_x > item->x + item->width * 3 / 4)
7267 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7268 else if (drag_y < item->y + item->height / 4)
7269 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7270 else if (drag_y > item->y + item->height * 3 / 4)
7271 *pos = GTK_ICON_VIEW_DROP_BELOW;
7273 *pos = GTK_ICON_VIEW_DROP_INTO;
7280 * gtk_icon_view_create_drag_icon:
7281 * @icon_view: a #GtkIconView
7282 * @path: a #GtkTreePath in @icon_view
7284 * Creates a #GdkPixmap representation of the item at @path.
7285 * This image is used for a drag icon.
7287 * Return value: a newly-allocated pixmap of the drag icon.
7292 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7297 GdkPixmap *drawable;
7302 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7303 g_return_val_if_fail (path != NULL, NULL);
7305 widget = GTK_WIDGET (icon_view);
7307 if (!GTK_WIDGET_REALIZED (widget))
7310 index = gtk_tree_path_get_indices (path)[0];
7312 for (l = icon_view->priv->items; l; l = l->next)
7314 GtkIconViewItem *item = l->data;
7316 if (index == item->index)
7318 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7323 cr = gdk_cairo_create (drawable);
7324 cairo_set_line_width (cr, 1.);
7326 gdk_cairo_set_source_color
7327 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7328 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7333 area.width = item->width;
7334 area.height = item->height;
7336 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7337 drawable, 1, 1, FALSE);
7339 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7340 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7353 * gtk_icon_view_get_reorderable:
7354 * @icon_view: a #GtkIconView
7356 * Retrieves whether the user can reorder the list via drag-and-drop.
7357 * See gtk_icon_view_set_reorderable().
7359 * Return value: %TRUE if the list can be reordered.
7364 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7366 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7368 return icon_view->priv->reorderable;
7371 static const GtkTargetEntry item_targets[] = {
7372 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7377 * gtk_icon_view_set_reorderable:
7378 * @icon_view: A #GtkIconView.
7379 * @reorderable: %TRUE, if the list of items can be reordered.
7381 * This function is a convenience function to allow you to reorder models that
7382 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7383 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7384 * the user can reorder the model by dragging and dropping rows. The
7385 * developer can listen to these changes by connecting to the model's
7386 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7387 * the icon view as a drag source and destination. Therefore, drag and
7388 * drop can not be used in a reorderable view for any other purpose.
7390 * This function does not give you any degree of control over the order -- any
7391 * reordering is allowed. If more control is needed, you should probably
7392 * handle drag and drop manually.
7397 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7398 gboolean reorderable)
7400 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7402 reorderable = reorderable != FALSE;
7404 if (icon_view->priv->reorderable == reorderable)
7409 gtk_icon_view_enable_model_drag_source (icon_view,
7412 G_N_ELEMENTS (item_targets),
7414 gtk_icon_view_enable_model_drag_dest (icon_view,
7416 G_N_ELEMENTS (item_targets),
7421 gtk_icon_view_unset_model_drag_source (icon_view);
7422 gtk_icon_view_unset_model_drag_dest (icon_view);
7425 icon_view->priv->reorderable = reorderable;
7427 g_object_notify (G_OBJECT (icon_view), "reorderable");
7431 /* Accessibility Support */
7433 static gpointer accessible_parent_class;
7434 static gpointer accessible_item_parent_class;
7435 static GQuark accessible_private_data_quark = 0;
7437 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7438 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7439 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7441 static GType gtk_icon_view_item_accessible_get_type (void);
7452 GtkIconViewItem *item;
7456 AtkStateSet *state_set;
7460 GtkTextBuffer *text_buffer;
7462 gchar *action_descriptions[LAST_ACTION];
7463 gchar *image_description;
7464 guint action_idle_handler;
7465 } GtkIconViewItemAccessible;
7467 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7473 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7478 typedef struct _GtkIconViewItemAccessibleClass
7480 AtkObjectClass parent_class;
7482 } GtkIconViewItemAccessibleClass;
7484 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7487 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7489 GtkIconViewItemAccessible *item;
7490 GtkIconView *icon_view;
7493 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7494 item->action_idle_handler = 0;
7496 if (item->widget != NULL)
7498 icon_view = GTK_ICON_VIEW (item->widget);
7499 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7500 gtk_icon_view_item_activated (icon_view, path);
7501 gtk_tree_path_free (path);
7508 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7511 GtkIconViewItemAccessible *item;
7513 if (i < 0 || i >= LAST_ACTION)
7516 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7518 if (!GTK_IS_ICON_VIEW (item->widget))
7521 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7526 case ACTION_ACTIVATE:
7527 if (!item->action_idle_handler)
7528 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7531 g_assert_not_reached ();
7539 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7544 static const gchar *
7545 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7548 GtkIconViewItemAccessible *item;
7550 if (i < 0 || i >= LAST_ACTION)
7553 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7555 if (item->action_descriptions[i])
7556 return item->action_descriptions[i];
7558 return gtk_icon_view_item_accessible_action_descriptions[i];
7561 static const gchar *
7562 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7565 if (i < 0 || i >= LAST_ACTION)
7568 return gtk_icon_view_item_accessible_action_names[i];
7572 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7574 const gchar *description)
7576 GtkIconViewItemAccessible *item;
7578 if (i < 0 || i >= LAST_ACTION)
7581 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7583 g_free (item->action_descriptions[i]);
7585 item->action_descriptions[i] = g_strdup (description);
7591 atk_action_item_interface_init (AtkActionIface *iface)
7593 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7594 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7595 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7596 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7597 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7600 static const gchar *
7601 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7603 GtkIconViewItemAccessible *item;
7605 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7607 return item->image_description;
7611 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7612 const gchar *description)
7614 GtkIconViewItemAccessible *item;
7616 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7618 g_free (item->image_description);
7619 item->image_description = g_strdup (description);
7625 get_pixbuf_box (GtkIconView *icon_view,
7626 GtkIconViewItem *item,
7631 for (l = icon_view->priv->cell_list; l; l = l->next)
7633 GtkIconViewCellInfo *info = l->data;
7635 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7637 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7647 get_text (GtkIconView *icon_view,
7648 GtkIconViewItem *item)
7653 for (l = icon_view->priv->cell_list; l; l = l->next)
7655 GtkIconViewCellInfo *info = l->data;
7657 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7659 g_object_get (info->cell, "text", &text, NULL);
7669 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7673 GtkIconViewItemAccessible *item;
7676 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7678 if (!GTK_IS_ICON_VIEW (item->widget))
7681 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7684 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7687 *height = box.height;
7692 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7695 AtkCoordType coord_type)
7697 GtkIconViewItemAccessible *item;
7700 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7702 if (!GTK_IS_ICON_VIEW (item->widget))
7705 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7708 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7710 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7712 *x+= box.x - item->item->x;
7713 *y+= box.y - item->item->y;
7719 atk_image_item_interface_init (AtkImageIface *iface)
7721 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7722 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7723 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7724 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7728 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7732 GtkIconViewItemAccessible *item;
7733 GtkTextIter start, end;
7734 GtkTextBuffer *buffer;
7736 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7738 if (!GTK_IS_ICON_VIEW (item->widget))
7741 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7744 buffer = item->text_buffer;
7745 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7747 gtk_text_buffer_get_end_iter (buffer, &end);
7749 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7751 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7755 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7758 GtkIconViewItemAccessible *item;
7759 GtkTextIter start, end;
7760 GtkTextBuffer *buffer;
7764 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7766 if (!GTK_IS_ICON_VIEW (item->widget))
7769 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7772 buffer = item->text_buffer;
7773 if (offset >= gtk_text_buffer_get_char_count (buffer))
7776 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7778 gtk_text_iter_forward_char (&end);
7779 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7780 unichar = g_utf8_get_char (string);
7788 get_pango_text_offsets (PangoLayout *layout,
7789 GtkTextBuffer *buffer,
7791 AtkTextBoundary boundary_type,
7795 GtkTextIter *start_iter,
7796 GtkTextIter *end_iter)
7798 PangoLayoutIter *iter;
7799 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7800 gint index, start_index, end_index;
7802 gboolean found = FALSE;
7804 text = pango_layout_get_text (layout);
7805 index = g_utf8_offset_to_pointer (text, offset) - text;
7806 iter = pango_layout_get_iter (layout);
7809 line = pango_layout_iter_get_line_readonly (iter);
7810 start_index = line->start_index;
7811 end_index = start_index + line->length;
7813 if (index >= start_index && index <= end_index)
7816 * Found line for offset
7822 * We want the previous line
7826 switch (boundary_type)
7828 case ATK_TEXT_BOUNDARY_LINE_START:
7829 end_index = start_index;
7830 start_index = prev_line->start_index;
7832 case ATK_TEXT_BOUNDARY_LINE_END:
7834 start_index = prev_prev_line->start_index +
7835 prev_prev_line->length;
7836 end_index = prev_line->start_index + prev_line->length;
7839 g_assert_not_reached();
7843 start_index = end_index = 0;
7846 switch (boundary_type)
7848 case ATK_TEXT_BOUNDARY_LINE_START:
7849 if (pango_layout_iter_next_line (iter))
7850 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7852 case ATK_TEXT_BOUNDARY_LINE_END:
7854 start_index = prev_line->start_index +
7858 g_assert_not_reached();
7863 * We want the next line
7865 if (pango_layout_iter_next_line (iter))
7867 line = pango_layout_iter_get_line_readonly (iter);
7868 switch (boundary_type)
7870 case ATK_TEXT_BOUNDARY_LINE_START:
7871 start_index = line->start_index;
7872 if (pango_layout_iter_next_line (iter))
7873 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7875 end_index = start_index + line->length;
7877 case ATK_TEXT_BOUNDARY_LINE_END:
7878 start_index = end_index;
7879 end_index = line->start_index + line->length;
7882 g_assert_not_reached();
7886 start_index = end_index;
7892 prev_prev_line = prev_line;
7895 while (pango_layout_iter_next_line (iter));
7899 start_index = prev_line->start_index + prev_line->length;
7900 end_index = start_index;
7902 pango_layout_iter_free (iter);
7903 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7904 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7906 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7907 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7912 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7914 AtkTextBoundary boundary_type,
7918 GtkIconViewItemAccessible *item;
7919 GtkTextIter start, end;
7920 GtkTextBuffer *buffer;
7922 GtkIconView *icon_view;
7925 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7927 if (!GTK_IS_ICON_VIEW (item->widget))
7930 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7933 buffer = item->text_buffer;
7935 if (!gtk_text_buffer_get_char_count (buffer))
7939 return g_strdup ("");
7941 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7945 switch (boundary_type)
7947 case ATK_TEXT_BOUNDARY_CHAR:
7948 gtk_text_iter_backward_char(&start);
7950 case ATK_TEXT_BOUNDARY_WORD_START:
7951 if (!gtk_text_iter_starts_word (&start))
7952 gtk_text_iter_backward_word_start (&start);
7954 gtk_text_iter_backward_word_start(&start);
7956 case ATK_TEXT_BOUNDARY_WORD_END:
7957 if (gtk_text_iter_inside_word (&start) &&
7958 !gtk_text_iter_starts_word (&start))
7959 gtk_text_iter_backward_word_start (&start);
7960 while (!gtk_text_iter_ends_word (&start))
7962 if (!gtk_text_iter_backward_char (&start))
7966 gtk_text_iter_backward_word_start(&start);
7967 while (!gtk_text_iter_ends_word (&start))
7969 if (!gtk_text_iter_backward_char (&start))
7973 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7974 if (!gtk_text_iter_starts_sentence (&start))
7975 gtk_text_iter_backward_sentence_start (&start);
7977 gtk_text_iter_backward_sentence_start (&start);
7979 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7980 if (gtk_text_iter_inside_sentence (&start) &&
7981 !gtk_text_iter_starts_sentence (&start))
7982 gtk_text_iter_backward_sentence_start (&start);
7983 while (!gtk_text_iter_ends_sentence (&start))
7985 if (!gtk_text_iter_backward_char (&start))
7989 gtk_text_iter_backward_sentence_start (&start);
7990 while (!gtk_text_iter_ends_sentence (&start))
7992 if (!gtk_text_iter_backward_char (&start))
7996 case ATK_TEXT_BOUNDARY_LINE_START:
7997 case ATK_TEXT_BOUNDARY_LINE_END:
7999 icon_view = GTK_ICON_VIEW (item->widget);
8000 /* FIXME we probably have to use GailTextCell to salvage this */
8001 gtk_icon_view_update_item_text (icon_view, item->item);
8002 get_pango_text_offsets (icon_view->priv->layout,
8015 *start_offset = gtk_text_iter_get_offset (&start);
8016 *end_offset = gtk_text_iter_get_offset (&end);
8018 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8022 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8024 AtkTextBoundary boundary_type,
8028 GtkIconViewItemAccessible *item;
8029 GtkTextIter start, end;
8030 GtkTextBuffer *buffer;
8032 GtkIconView *icon_view;
8035 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8037 if (!GTK_IS_ICON_VIEW (item->widget))
8040 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8043 buffer = item->text_buffer;
8045 if (!gtk_text_buffer_get_char_count (buffer))
8049 return g_strdup ("");
8051 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8055 switch (boundary_type)
8057 case ATK_TEXT_BOUNDARY_CHAR:
8058 gtk_text_iter_forward_char (&end);
8060 case ATK_TEXT_BOUNDARY_WORD_START:
8061 if (!gtk_text_iter_starts_word (&start))
8062 gtk_text_iter_backward_word_start (&start);
8063 if (gtk_text_iter_inside_word (&end))
8064 gtk_text_iter_forward_word_end (&end);
8065 while (!gtk_text_iter_starts_word (&end))
8067 if (!gtk_text_iter_forward_char (&end))
8071 case ATK_TEXT_BOUNDARY_WORD_END:
8072 if (gtk_text_iter_inside_word (&start) &&
8073 !gtk_text_iter_starts_word (&start))
8074 gtk_text_iter_backward_word_start (&start);
8075 while (!gtk_text_iter_ends_word (&start))
8077 if (!gtk_text_iter_backward_char (&start))
8080 gtk_text_iter_forward_word_end (&end);
8082 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8083 if (!gtk_text_iter_starts_sentence (&start))
8084 gtk_text_iter_backward_sentence_start (&start);
8085 if (gtk_text_iter_inside_sentence (&end))
8086 gtk_text_iter_forward_sentence_end (&end);
8087 while (!gtk_text_iter_starts_sentence (&end))
8089 if (!gtk_text_iter_forward_char (&end))
8093 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8094 if (gtk_text_iter_inside_sentence (&start) &&
8095 !gtk_text_iter_starts_sentence (&start))
8096 gtk_text_iter_backward_sentence_start (&start);
8097 while (!gtk_text_iter_ends_sentence (&start))
8099 if (!gtk_text_iter_backward_char (&start))
8102 gtk_text_iter_forward_sentence_end (&end);
8104 case ATK_TEXT_BOUNDARY_LINE_START:
8105 case ATK_TEXT_BOUNDARY_LINE_END:
8107 icon_view = GTK_ICON_VIEW (item->widget);
8108 /* FIXME we probably have to use GailTextCell to salvage this */
8109 gtk_icon_view_update_item_text (icon_view, item->item);
8110 get_pango_text_offsets (icon_view->priv->layout,
8124 *start_offset = gtk_text_iter_get_offset (&start);
8125 *end_offset = gtk_text_iter_get_offset (&end);
8127 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8131 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8133 AtkTextBoundary boundary_type,
8137 GtkIconViewItemAccessible *item;
8138 GtkTextIter start, end;
8139 GtkTextBuffer *buffer;
8141 GtkIconView *icon_view;
8144 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8146 if (!GTK_IS_ICON_VIEW (item->widget))
8149 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8152 buffer = item->text_buffer;
8154 if (!gtk_text_buffer_get_char_count (buffer))
8158 return g_strdup ("");
8160 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8164 switch (boundary_type)
8166 case ATK_TEXT_BOUNDARY_CHAR:
8167 gtk_text_iter_forward_char(&start);
8168 gtk_text_iter_forward_chars(&end, 2);
8170 case ATK_TEXT_BOUNDARY_WORD_START:
8171 if (gtk_text_iter_inside_word (&end))
8172 gtk_text_iter_forward_word_end (&end);
8173 while (!gtk_text_iter_starts_word (&end))
8175 if (!gtk_text_iter_forward_char (&end))
8179 if (!gtk_text_iter_is_end (&end))
8181 gtk_text_iter_forward_word_end (&end);
8182 while (!gtk_text_iter_starts_word (&end))
8184 if (!gtk_text_iter_forward_char (&end))
8189 case ATK_TEXT_BOUNDARY_WORD_END:
8190 gtk_text_iter_forward_word_end (&end);
8192 if (!gtk_text_iter_is_end (&end))
8193 gtk_text_iter_forward_word_end (&end);
8195 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8196 if (gtk_text_iter_inside_sentence (&end))
8197 gtk_text_iter_forward_sentence_end (&end);
8198 while (!gtk_text_iter_starts_sentence (&end))
8200 if (!gtk_text_iter_forward_char (&end))
8204 if (!gtk_text_iter_is_end (&end))
8206 gtk_text_iter_forward_sentence_end (&end);
8207 while (!gtk_text_iter_starts_sentence (&end))
8209 if (!gtk_text_iter_forward_char (&end))
8214 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8215 gtk_text_iter_forward_sentence_end (&end);
8217 if (!gtk_text_iter_is_end (&end))
8218 gtk_text_iter_forward_sentence_end (&end);
8220 case ATK_TEXT_BOUNDARY_LINE_START:
8221 case ATK_TEXT_BOUNDARY_LINE_END:
8223 icon_view = GTK_ICON_VIEW (item->widget);
8224 /* FIXME we probably have to use GailTextCell to salvage this */
8225 gtk_icon_view_update_item_text (icon_view, item->item);
8226 get_pango_text_offsets (icon_view->priv->layout,
8238 *start_offset = gtk_text_iter_get_offset (&start);
8239 *end_offset = gtk_text_iter_get_offset (&end);
8241 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8245 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8247 GtkIconViewItemAccessible *item;
8249 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8251 if (!GTK_IS_ICON_VIEW (item->widget))
8254 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8257 return gtk_text_buffer_get_char_count (item->text_buffer);
8261 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8267 AtkCoordType coord_type)
8269 GtkIconViewItemAccessible *item;
8271 GtkIconView *icon_view;
8272 PangoRectangle char_rect;
8273 const gchar *item_text;
8277 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8279 if (!GTK_IS_ICON_VIEW (item->widget))
8282 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8286 icon_view = GTK_ICON_VIEW (item->widget);
8287 /* FIXME we probably have to use GailTextCell to salvage this */
8288 gtk_icon_view_update_item_text (icon_view, item->item);
8289 item_text = pango_layout_get_text (icon_view->priv->layout);
8290 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8291 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8293 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8294 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8295 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8296 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8297 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8298 *width = char_rect.width / PANGO_SCALE;
8299 *height = char_rect.height / PANGO_SCALE;
8304 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8307 AtkCoordType coord_type)
8309 GtkIconViewItemAccessible *item;
8312 GtkIconView *icon_view;
8313 const gchar *item_text;
8318 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8320 if (!GTK_IS_ICON_VIEW (item->widget))
8323 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8327 icon_view = GTK_ICON_VIEW (item->widget);
8328 /* FIXME we probably have to use GailTextCell to salvage this */
8329 gtk_icon_view_update_item_text (icon_view, item->item);
8330 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8331 x -= l_x + item->item->layout_x - item->item->x;
8332 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8333 y -= l_y + item->item->layout_y - item->item->y;
8334 item_text = pango_layout_get_text (icon_view->priv->layout);
8335 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8346 offset = g_utf8_strlen (item_text, -1);
8348 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8354 atk_text_item_interface_init (AtkTextIface *iface)
8356 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8357 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8358 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8359 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8360 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8361 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8362 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8363 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8367 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8372 AtkCoordType coord_type)
8374 GtkIconViewItemAccessible *item;
8375 AtkObject *parent_obj;
8378 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8380 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8381 if (!GTK_IS_WIDGET (item->widget))
8384 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8387 *width = item->item->width;
8388 *height = item->item->height;
8389 if (gtk_icon_view_item_accessible_is_showing (item))
8391 parent_obj = gtk_widget_get_accessible (item->widget);
8392 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8393 *x = l_x + item->item->x;
8394 *y = l_y + item->item->y;
8404 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8406 GtkIconViewItemAccessible *item;
8407 GtkWidget *toplevel;
8409 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8411 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8412 if (!GTK_IS_WIDGET (item->widget))
8415 gtk_widget_grab_focus (item->widget);
8416 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8417 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8418 if (GTK_WIDGET_TOPLEVEL (toplevel))
8419 gtk_window_present (GTK_WINDOW (toplevel));
8425 atk_component_item_interface_init (AtkComponentIface *iface)
8427 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8428 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8432 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8433 AtkStateType state_type,
8434 gboolean emit_signal)
8438 rc = atk_state_set_add_state (item->state_set, state_type);
8440 * The signal should only be generated if the value changed,
8441 * not when the item is set up. So states that are set
8442 * initially should pass FALSE as the emit_signal argument.
8447 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8448 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8449 if (state_type == ATK_STATE_VISIBLE)
8450 g_signal_emit_by_name (item, "visible-data-changed");
8457 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8458 AtkStateType state_type,
8459 gboolean emit_signal)
8461 if (atk_state_set_contains_state (item->state_set, state_type))
8465 rc = atk_state_set_remove_state (item->state_set, state_type);
8467 * The signal should only be generated if the value changed,
8468 * not when the item is set up. So states that are set
8469 * initially should pass FALSE as the emit_signal argument.
8474 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8475 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8476 if (state_type == ATK_STATE_VISIBLE)
8477 g_signal_emit_by_name (item, "visible-data-changed");
8487 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8489 GtkIconView *icon_view;
8490 GdkRectangle visible_rect;
8491 gboolean is_showing;
8494 * An item is considered "SHOWING" if any part of the item is in the
8495 * visible rectangle.
8498 if (!GTK_IS_ICON_VIEW (item->widget))
8501 if (item->item == NULL)
8504 icon_view = GTK_ICON_VIEW (item->widget);
8506 if (icon_view->priv->hadjustment)
8507 visible_rect.x += icon_view->priv->hadjustment->value;
8509 if (icon_view->priv->hadjustment)
8510 visible_rect.y += icon_view->priv->vadjustment->value;
8511 visible_rect.width = item->widget->allocation.width;
8512 visible_rect.height = item->widget->allocation.height;
8514 if (((item->item->x + item->item->width) < visible_rect.x) ||
8515 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8516 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8517 (item->item->y > (visible_rect.y + visible_rect.height)))
8526 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8527 gboolean emit_signal)
8529 if (gtk_icon_view_item_accessible_is_showing (item))
8530 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8533 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8538 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8542 item->state_set = atk_state_set_new ();
8544 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8545 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8546 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8547 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8548 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8550 for (i = 0; i < LAST_ACTION; i++)
8551 item->action_descriptions[i] = NULL;
8553 item->image_description = NULL;
8555 item->action_idle_handler = 0;
8559 gtk_icon_view_item_accessible_finalize (GObject *object)
8561 GtkIconViewItemAccessible *item;
8564 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8566 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8569 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8571 if (item->state_set)
8572 g_object_unref (item->state_set);
8574 if (item->text_buffer)
8575 g_object_unref (item->text_buffer);
8577 for (i = 0; i < LAST_ACTION; i++)
8578 g_free (item->action_descriptions[i]);
8580 g_free (item->image_description);
8582 if (item->action_idle_handler)
8584 g_source_remove (item->action_idle_handler);
8585 item->action_idle_handler = 0;
8588 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8591 static G_CONST_RETURN gchar*
8592 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8598 GtkIconViewItemAccessible *item;
8599 GtkTextIter start_iter;
8600 GtkTextIter end_iter;
8602 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8604 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8605 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8607 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8612 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8614 GtkIconViewItemAccessible *item;
8616 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8617 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8620 return gtk_widget_get_accessible (item->widget);
8626 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8628 GtkIconViewItemAccessible *item;
8630 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8631 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8633 return item->item->index;
8636 static AtkStateSet *
8637 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8639 GtkIconViewItemAccessible *item;
8640 GtkIconView *icon_view;
8642 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8643 g_return_val_if_fail (item->state_set, NULL);
8648 icon_view = GTK_ICON_VIEW (item->widget);
8649 if (icon_view->priv->cursor_item == item->item)
8650 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8652 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8653 if (item->item->selected)
8654 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8656 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8658 return g_object_ref (item->state_set);
8662 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8664 GObjectClass *gobject_class;
8666 accessible_item_parent_class = g_type_class_peek_parent (klass);
8668 gobject_class = (GObjectClass *)klass;
8670 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8672 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8673 klass->get_name = gtk_icon_view_item_accessible_get_name;
8674 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8675 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8679 gtk_icon_view_item_accessible_get_type (void)
8681 static GType type = 0;
8685 const GTypeInfo tinfo =
8687 sizeof (GtkIconViewItemAccessibleClass),
8688 (GBaseInitFunc) NULL, /* base init */
8689 (GBaseFinalizeFunc) NULL, /* base finalize */
8690 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8691 (GClassFinalizeFunc) NULL, /* class finalize */
8692 NULL, /* class data */
8693 sizeof (GtkIconViewItemAccessible), /* instance size */
8694 0, /* nb preallocs */
8695 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8696 NULL /* value table */
8699 static const GInterfaceInfo atk_component_info =
8701 (GInterfaceInitFunc) atk_component_item_interface_init,
8702 (GInterfaceFinalizeFunc) NULL,
8705 static const GInterfaceInfo atk_action_info =
8707 (GInterfaceInitFunc) atk_action_item_interface_init,
8708 (GInterfaceFinalizeFunc) NULL,
8711 static const GInterfaceInfo atk_image_info =
8713 (GInterfaceInitFunc) atk_image_item_interface_init,
8714 (GInterfaceFinalizeFunc) NULL,
8717 static const GInterfaceInfo atk_text_info =
8719 (GInterfaceInitFunc) atk_text_item_interface_init,
8720 (GInterfaceFinalizeFunc) NULL,
8724 type = g_type_register_static (ATK_TYPE_OBJECT,
8725 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8726 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8727 &atk_component_info);
8728 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8730 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8732 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8739 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8740 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8741 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8743 static GType gtk_icon_view_accessible_get_type (void);
8748 } GtkIconViewAccessible;
8754 } GtkIconViewItemAccessibleInfo;
8760 GtkAdjustment *old_hadj;
8761 GtkAdjustment *old_vadj;
8763 GtkTreeModel *model;
8765 } GtkIconViewAccessiblePrivate;
8767 static GtkIconViewAccessiblePrivate *
8768 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8770 return g_object_get_qdata (G_OBJECT (accessible),
8771 accessible_private_data_quark);
8775 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8779 GtkIconViewItemAccessibleInfo *info;
8780 GtkIconViewItemAccessibleInfo *tmp_info;
8781 GtkIconViewAccessiblePrivate *priv;
8784 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8786 info->index = index;
8788 priv = gtk_icon_view_accessible_get_priv (accessible);
8789 items = priv->items;
8792 tmp_info = items->data;
8793 if (tmp_info->index > index)
8795 items = items->next;
8797 priv->items = g_list_insert_before (priv->items, items, info);
8798 priv->old_hadj = NULL;
8799 priv->old_vadj = NULL;
8803 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8805 GtkIconView *icon_view;
8808 widget = GTK_ACCESSIBLE (accessible)->widget;
8812 icon_view = GTK_ICON_VIEW (widget);
8814 return g_list_length (icon_view->priv->items);
8818 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8821 GtkIconViewAccessiblePrivate *priv;
8822 GtkIconViewItemAccessibleInfo *info;
8825 priv = gtk_icon_view_accessible_get_priv (accessible);
8826 items = priv->items;
8831 if (info->index == index)
8833 items = items->next;
8839 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8842 GtkIconView *icon_view;
8846 GtkIconViewItemAccessible *a11y_item;
8848 widget = GTK_ACCESSIBLE (accessible)->widget;
8852 icon_view = GTK_ICON_VIEW (widget);
8853 icons = g_list_nth (icon_view->priv->items, index);
8857 GtkIconViewItem *item = icons->data;
8859 g_return_val_if_fail (item->index == index, NULL);
8860 obj = gtk_icon_view_accessible_find_child (accessible, index);
8865 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8866 gtk_icon_view_item_accessible_info_new (accessible,
8869 obj->role = ATK_ROLE_ICON;
8870 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8871 a11y_item->item = item;
8872 a11y_item->widget = widget;
8873 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8875 gtk_icon_view_set_cell_data (icon_view, item);
8876 text = get_text (icon_view, item);
8879 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8883 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8884 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8892 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8895 GtkIconViewAccessiblePrivate *priv;
8896 GtkIconViewItemAccessibleInfo *info;
8897 GtkIconViewItemAccessible *item;
8900 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8904 gboolean act_on_item;
8906 widget = GTK_ACCESSIBLE (view)->widget;
8910 items = priv->items;
8912 act_on_item = (list == NULL);
8917 info = (GtkIconViewItemAccessibleInfo *)items->data;
8918 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8920 if (act_on_item == FALSE && list == items)
8924 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8926 items = items->next;
8932 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8933 GtkIconView *icon_view)
8936 GtkIconViewAccessible *view;
8939 * The scrollbars have changed
8941 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8942 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8944 gtk_icon_view_accessible_traverse_items (view, NULL);
8948 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8949 GtkAdjustment *hadj,
8950 GtkAdjustment *vadj)
8953 GtkIconViewAccessiblePrivate *priv;
8955 atk_obj = gtk_widget_get_accessible (widget);
8956 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8958 if (priv->old_hadj != hadj)
8962 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8963 (gpointer *)&priv->old_hadj);
8965 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8966 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8969 priv->old_hadj = hadj;
8972 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8973 (gpointer *)&priv->old_hadj);
8974 g_signal_connect (hadj,
8976 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8980 if (priv->old_vadj != vadj)
8984 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8985 (gpointer *)&priv->old_vadj);
8987 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8988 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8991 priv->old_vadj = vadj;
8994 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8995 (gpointer *)&priv->old_vadj);
8996 g_signal_connect (vadj,
8998 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9005 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9013 GtkIconView *icon_view;
9014 GtkIconViewItem *item;
9015 GtkIconViewAccessible *a11y_view;
9016 GtkIconViewItemAccessible *a11y_item;
9020 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9021 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9022 index = gtk_tree_path_get_indices(path)[0];
9023 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9024 gtk_icon_view_accessible_find_child (atk_obj, index));
9028 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9029 icon_view = GTK_ICON_VIEW (widget);
9030 item = a11y_item->item;
9032 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9034 if (!name || strcmp (name, "") == 0)
9036 gtk_icon_view_set_cell_data (icon_view, item);
9037 text = get_text (icon_view, item);
9040 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9046 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9052 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9057 GtkIconViewAccessiblePrivate *priv;
9058 GtkIconViewItemAccessibleInfo *info;
9059 GtkIconViewAccessible *view;
9060 GtkIconViewItemAccessible *item;
9066 index = gtk_tree_path_get_indices(path)[0];
9067 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9068 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9069 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9071 items = priv->items;
9076 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9077 if (info->index != item->item->index)
9079 if (info->index < index)
9080 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9082 if (tmp_list == NULL)
9085 info->index = item->item->index;
9088 items = items->next;
9090 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9091 g_signal_emit_by_name (atk_obj, "children-changed::add",
9097 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9101 GtkIconViewAccessiblePrivate *priv;
9102 GtkIconViewItemAccessibleInfo *info;
9103 GtkIconViewAccessible *view;
9104 GtkIconViewItemAccessible *item;
9107 GList *deleted_item;
9111 index = gtk_tree_path_get_indices(path)[0];
9112 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9113 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9114 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9116 items = priv->items;
9118 deleted_item = NULL;
9123 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9124 if (info->index == index)
9126 deleted_item = items;
9128 if (info->index != item->item->index)
9130 if (tmp_list == NULL)
9133 info->index = item->item->index;
9136 items = items->next;
9138 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9141 info = deleted_item->data;
9142 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9143 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9145 priv->items = g_list_remove_link (priv->items, deleted_item);
9153 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9154 GtkIconViewItemAccessibleInfo *i2)
9156 return i1->index - i2->index;
9160 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9166 GtkIconViewAccessiblePrivate *priv;
9167 GtkIconViewItemAccessibleInfo *info;
9168 GtkIconView *icon_view;
9169 GtkIconViewItemAccessible *item;
9175 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9176 icon_view = GTK_ICON_VIEW (user_data);
9177 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9179 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9181 order = g_new (gint, length);
9182 for (i = 0; i < length; i++)
9183 order [new_order[i]] = i;
9185 items = priv->items;
9189 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9190 info->index = order[info->index];
9191 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9192 items = items->next;
9195 priv->items = g_list_sort (priv->items,
9196 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9202 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9207 obj = G_OBJECT (model);
9208 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9209 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9210 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9211 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9215 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9219 obj = G_OBJECT (icon_view->priv->model);
9220 g_signal_connect_data (obj, "row-changed",
9221 (GCallback) gtk_icon_view_accessible_model_row_changed,
9222 icon_view, NULL, 0);
9223 g_signal_connect_data (obj, "row-inserted",
9224 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9225 icon_view, NULL, G_CONNECT_AFTER);
9226 g_signal_connect_data (obj, "row-deleted",
9227 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9228 icon_view, NULL, G_CONNECT_AFTER);
9229 g_signal_connect_data (obj, "rows-reordered",
9230 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9231 icon_view, NULL, G_CONNECT_AFTER);
9235 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9237 GtkIconViewItemAccessibleInfo *info;
9240 items = priv->items;
9243 info = (GtkIconViewItemAccessibleInfo *) items->data;
9244 g_object_unref (info->item);
9245 g_free (items->data);
9246 items = items->next;
9248 g_list_free (priv->items);
9253 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9256 GtkIconView *icon_view;
9259 GtkIconViewAccessiblePrivate *priv;
9261 if (strcmp (pspec->name, "model") == 0)
9263 widget = GTK_WIDGET (obj);
9264 atk_obj = gtk_widget_get_accessible (widget);
9265 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9268 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9269 (gpointer *)&priv->model);
9270 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9272 gtk_icon_view_accessible_clear_cache (priv);
9274 icon_view = GTK_ICON_VIEW (obj);
9275 priv->model = icon_view->priv->model;
9276 /* If there is no model the GtkIconView is probably being destroyed */
9279 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9280 gtk_icon_view_accessible_connect_model_signals (icon_view);
9288 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9291 GtkIconViewAccessiblePrivate *priv;
9292 GtkIconView *icon_view;
9294 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9295 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9297 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9298 g_object_set_qdata (G_OBJECT (accessible),
9299 accessible_private_data_quark,
9302 icon_view = GTK_ICON_VIEW (data);
9303 if (icon_view->priv->hadjustment)
9305 priv->old_hadj = icon_view->priv->hadjustment;
9306 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9307 g_signal_connect (icon_view->priv->hadjustment,
9309 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9312 if (icon_view->priv->vadjustment)
9314 priv->old_vadj = icon_view->priv->vadjustment;
9315 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9316 g_signal_connect (icon_view->priv->vadjustment,
9318 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9321 g_signal_connect_after (data,
9322 "set-scroll-adjustments",
9323 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9325 g_signal_connect (data,
9327 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9330 priv->model = icon_view->priv->model;
9333 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9334 gtk_icon_view_accessible_connect_model_signals (icon_view);
9337 accessible->role = ATK_ROLE_LAYERED_PANE;
9341 gtk_icon_view_accessible_finalize (GObject *object)
9343 GtkIconViewAccessiblePrivate *priv;
9345 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9346 gtk_icon_view_accessible_clear_cache (priv);
9350 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9354 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9355 GtkAccessible *accessible)
9358 GtkIconViewAccessiblePrivate *priv;
9360 atk_obj = ATK_OBJECT (accessible);
9361 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9364 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9365 (gpointer *)&priv->old_hadj);
9367 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9368 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9370 priv->old_hadj = NULL;
9374 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9375 (gpointer *)&priv->old_vadj);
9377 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9378 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9380 priv->old_vadj = NULL;
9385 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9387 if (accessible->widget)
9389 g_signal_connect_after (accessible->widget,
9391 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9394 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9398 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9400 GObjectClass *gobject_class;
9401 GtkAccessibleClass *accessible_class;
9403 accessible_parent_class = g_type_class_peek_parent (klass);
9405 gobject_class = (GObjectClass *)klass;
9406 accessible_class = (GtkAccessibleClass *)klass;
9408 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9410 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9411 klass->ref_child = gtk_icon_view_accessible_ref_child;
9412 klass->initialize = gtk_icon_view_accessible_initialize;
9414 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9416 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9420 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9423 AtkCoordType coord_type)
9426 GtkIconView *icon_view;
9427 GtkIconViewItem *item;
9430 widget = GTK_ACCESSIBLE (component)->widget;
9432 /* State is defunct */
9435 icon_view = GTK_ICON_VIEW (widget);
9436 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9437 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9439 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9445 atk_component_interface_init (AtkComponentIface *iface)
9447 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9451 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9455 GtkIconView *icon_view;
9456 GtkIconViewItem *item;
9458 widget = GTK_ACCESSIBLE (selection)->widget;
9462 icon_view = GTK_ICON_VIEW (widget);
9464 item = g_list_nth_data (icon_view->priv->items, i);
9469 gtk_icon_view_select_item (icon_view, item);
9475 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9478 GtkIconView *icon_view;
9480 widget = GTK_ACCESSIBLE (selection)->widget;
9484 icon_view = GTK_ICON_VIEW (widget);
9485 gtk_icon_view_unselect_all (icon_view);
9491 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9496 GtkIconView *icon_view;
9497 GtkIconViewItem *item;
9499 widget = GTK_ACCESSIBLE (selection)->widget;
9503 icon_view = GTK_ICON_VIEW (widget);
9505 l = icon_view->priv->items;
9512 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9523 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9526 GtkIconView *icon_view;
9527 GtkIconViewItem *item;
9531 widget = GTK_ACCESSIBLE (selection)->widget;
9535 icon_view = GTK_ICON_VIEW (widget);
9537 l = icon_view->priv->items;
9553 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9557 GtkIconView *icon_view;
9558 GtkIconViewItem *item;
9560 widget = GTK_ACCESSIBLE (selection)->widget;
9564 icon_view = GTK_ICON_VIEW (widget);
9566 item = g_list_nth_data (icon_view->priv->items, i);
9570 return item->selected;
9574 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9578 GtkIconView *icon_view;
9579 GtkIconViewItem *item;
9583 widget = GTK_ACCESSIBLE (selection)->widget;
9587 icon_view = GTK_ICON_VIEW (widget);
9588 l = icon_view->priv->items;
9597 gtk_icon_view_unselect_item (icon_view, item);
9609 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9612 GtkIconView *icon_view;
9614 widget = GTK_ACCESSIBLE (selection)->widget;
9618 icon_view = GTK_ICON_VIEW (widget);
9619 gtk_icon_view_select_all (icon_view);
9624 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9626 iface->add_selection = gtk_icon_view_accessible_add_selection;
9627 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9628 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9629 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9630 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9631 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9632 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9636 gtk_icon_view_accessible_get_type (void)
9638 static GType type = 0;
9642 static GTypeInfo tinfo =
9645 (GBaseInitFunc) NULL, /* base init */
9646 (GBaseFinalizeFunc) NULL, /* base finalize */
9647 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9648 (GClassFinalizeFunc) NULL, /* class finalize */
9649 NULL, /* class data */
9650 0, /* instance size */
9651 0, /* nb preallocs */
9652 (GInstanceInitFunc) NULL, /* instance init */
9653 NULL /* value table */
9655 static const GInterfaceInfo atk_component_info =
9657 (GInterfaceInitFunc) atk_component_interface_init,
9658 (GInterfaceFinalizeFunc) NULL,
9661 static const GInterfaceInfo atk_selection_info =
9663 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9664 (GInterfaceFinalizeFunc) NULL,
9669 * Figure out the size of the class and instance
9670 * we are deriving from
9672 AtkObjectFactory *factory;
9675 GType derived_atk_type;
9677 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9678 factory = atk_registry_get_factory (atk_get_default_registry (),
9680 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9681 g_type_query (derived_atk_type, &query);
9682 tinfo.class_size = query.class_size;
9683 tinfo.instance_size = query.instance_size;
9685 type = g_type_register_static (derived_atk_type,
9686 I_("GtkIconViewAccessible"),
9688 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9689 &atk_component_info);
9690 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9691 &atk_selection_info);
9697 gtk_icon_view_accessible_new (GObject *obj)
9699 AtkObject *accessible;
9701 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9703 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9704 atk_object_initialize (accessible, obj);
9710 gtk_icon_view_accessible_factory_get_accessible_type (void)
9712 return gtk_icon_view_accessible_get_type ();
9716 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9718 return gtk_icon_view_accessible_new (obj);
9722 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9724 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9725 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9729 gtk_icon_view_accessible_factory_get_type (void)
9731 static GType type = 0;
9735 const GTypeInfo tinfo =
9737 sizeof (AtkObjectFactoryClass),
9738 NULL, /* base_init */
9739 NULL, /* base_finalize */
9740 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9741 NULL, /* class_finalize */
9742 NULL, /* class_data */
9743 sizeof (AtkObjectFactory),
9744 0, /* n_preallocs */
9748 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9749 I_("GtkIconViewAccessibleFactory"),
9757 gtk_icon_view_get_accessible (GtkWidget *widget)
9759 static gboolean first_time = TRUE;
9763 AtkObjectFactory *factory;
9764 AtkRegistry *registry;
9766 GType derived_atk_type;
9769 * Figure out whether accessibility is enabled by looking at the
9770 * type of the accessible object which would be created for
9771 * the parent type of GtkIconView.
9773 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9775 registry = atk_get_default_registry ();
9776 factory = atk_registry_get_factory (registry,
9778 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9779 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9780 atk_registry_set_factory_type (registry,
9782 gtk_icon_view_accessible_factory_get_type ());
9785 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9789 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9790 GtkBuilder *builder,
9792 const gchar *tagname,
9793 GMarkupParser *parser,
9796 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9797 tagname, parser, data))
9800 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9801 tagname, parser, data);
9805 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9806 GtkBuilder *builder,
9808 const gchar *tagname,
9811 if (strcmp (tagname, "attributes") == 0)
9812 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9815 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9821 #define __GTK_ICON_VIEW_C__
9822 #include "gtkaliasdef.c"