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
50 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
52 typedef struct _GtkIconViewItem GtkIconViewItem;
53 struct _GtkIconViewItem
61 gint x, y, width, height;
64 * box[i] is the actual area occupied by cell i,
65 * before, after are used to calculate the cell
66 * area relative to the box.
67 * See gtk_icon_view_get_cell_area().
75 guint selected_before_rubberbanding : 1;
79 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
80 struct _GtkIconViewCellInfo
82 GtkCellRenderer *cell;
92 GtkCellLayoutDataFunc func;
94 GDestroyNotify destroy;
97 typedef struct _GtkIconViewChild GtkIconViewChild;
98 struct _GtkIconViewChild
101 GtkIconViewItem *item;
105 struct _GtkIconViewPrivate
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gboolean doing_rubberband;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
134 GtkIconViewItem *edited_item;
135 GtkCellEditable *editable;
137 GtkIconViewItem *last_single_clicked;
144 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,
228 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
229 static void gtk_icon_view_finalize (GObject *object);
230 static void gtk_icon_view_set_property (GObject *object,
234 static void gtk_icon_view_get_property (GObject *object,
239 /* GtkObject vfuncs */
240 static void gtk_icon_view_destroy (GtkObject *object);
242 /* GtkWidget vfuncs */
243 static void gtk_icon_view_realize (GtkWidget *widget);
244 static void gtk_icon_view_unrealize (GtkWidget *widget);
245 static void gtk_icon_view_style_set (GtkWidget *widget,
246 GtkStyle *previous_style);
247 static void gtk_icon_view_state_changed (GtkWidget *widget,
248 GtkStateType previous_state);
249 static void gtk_icon_view_size_request (GtkWidget *widget,
250 GtkRequisition *requisition);
251 static void gtk_icon_view_size_allocate (GtkWidget *widget,
252 GtkAllocation *allocation);
253 static gboolean gtk_icon_view_expose (GtkWidget *widget,
254 GdkEventExpose *expose);
255 static gboolean gtk_icon_view_motion (GtkWidget *widget,
256 GdkEventMotion *event);
257 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
258 GdkEventButton *event);
259 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
260 GdkEventButton *event);
261 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
263 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
265 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
268 /* GtkContainer vfuncs */
269 static void gtk_icon_view_remove (GtkContainer *container,
271 static void gtk_icon_view_forall (GtkContainer *container,
272 gboolean include_internals,
273 GtkCallback callback,
274 gpointer callback_data);
276 /* GtkIconView vfuncs */
277 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
279 GtkAdjustment *vadj);
280 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
282 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
283 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
284 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
286 /* Internal functions */
287 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
288 GtkIconView *icon_view);
289 static void gtk_icon_view_layout (GtkIconView *icon_view);
290 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
293 GtkIconViewItem *item,
295 GdkDrawable *drawable,
298 gboolean draw_focus);
299 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
302 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
304 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
305 GtkIconViewItem *item);
306 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
307 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
308 GtkIconViewItem *item,
310 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
313 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
314 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
315 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
316 GtkIconViewItem *item,
321 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
322 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
323 GtkIconViewItem *item);
324 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
325 GtkIconViewItem *item,
327 static void gtk_icon_view_update_rubberband (gpointer data);
328 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
329 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
330 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
333 GtkMovementStep step,
335 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
336 GtkMovementStep step,
338 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
340 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
342 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
344 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
346 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
347 GtkIconViewItem *item);
348 static void gtk_icon_view_select_item (GtkIconView *icon_view,
349 GtkIconViewItem *item);
350 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
351 GtkIconViewItem *item);
352 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
353 GtkIconViewItem *anchor,
354 GtkIconViewItem *cursor);
355 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
358 gboolean only_in_cell,
359 GtkIconViewCellInfo **cell_at_pos);
360 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
361 GtkIconViewItem *item,
362 GtkIconViewCellInfo *cell_info,
363 GdkRectangle *cell_area);
364 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
365 GtkIconViewItem *item,
366 GtkIconViewCellInfo *info,
368 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
369 GtkCellRenderer *renderer);
370 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
371 GtkIconViewItem *item);
372 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
378 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
379 GtkCellRenderer *renderer,
380 const gchar *attribute,
382 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
383 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
384 GtkCellRenderer *renderer);
385 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
386 GtkCellRenderer *cell,
387 GtkCellLayoutDataFunc func,
389 GDestroyNotify destroy);
390 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
391 GtkCellRenderer *cell,
393 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
395 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
396 GtkIconViewItem *item,
397 GtkIconViewCellInfo *cell_info,
399 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
400 GtkIconViewItem *item);
401 static void gtk_icon_view_put (GtkIconView *icon_view,
403 GtkIconViewItem *item,
405 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
406 GtkIconView *icon_view);
407 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
408 GtkIconViewItem *item,
409 GtkIconViewCellInfo *cell_info,
411 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
412 gboolean cancel_editing);
414 /* Source side drag signals */
415 static void gtk_icon_view_drag_begin (GtkWidget *widget,
416 GdkDragContext *context);
417 static void gtk_icon_view_drag_end (GtkWidget *widget,
418 GdkDragContext *context);
419 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
420 GdkDragContext *context,
421 GtkSelectionData *selection_data,
424 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
425 GdkDragContext *context);
427 /* Target side drag signals */
428 static void gtk_icon_view_drag_leave (GtkWidget *widget,
429 GdkDragContext *context,
431 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
432 GdkDragContext *context,
436 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
437 GdkDragContext *context,
441 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
442 GdkDragContext *context,
445 GtkSelectionData *selection_data,
448 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
449 GdkEventMotion *event);
451 static void remove_scroll_timeout (GtkIconView *icon_view);
453 static void adjust_wrap_width (GtkIconView *icon_view,
454 GtkIconViewItem *item);
457 static GtkBuildableIface *parent_buildable_iface;
458 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
459 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
462 const gchar *tagname,
463 GMarkupParser *parser,
465 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
468 const gchar *tagname,
471 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
473 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
474 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
475 gtk_icon_view_cell_layout_init)
476 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
477 gtk_icon_view_buildable_init))
480 gtk_icon_view_class_init (GtkIconViewClass *klass)
482 GObjectClass *gobject_class;
483 GtkObjectClass *object_class;
484 GtkWidgetClass *widget_class;
485 GtkContainerClass *container_class;
486 GtkBindingSet *binding_set;
488 binding_set = gtk_binding_set_by_class (klass);
490 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
492 gobject_class = (GObjectClass *) klass;
493 object_class = (GtkObjectClass *) klass;
494 widget_class = (GtkWidgetClass *) klass;
495 container_class = (GtkContainerClass *) klass;
497 gobject_class->finalize = gtk_icon_view_finalize;
498 gobject_class->set_property = gtk_icon_view_set_property;
499 gobject_class->get_property = gtk_icon_view_get_property;
501 object_class->destroy = gtk_icon_view_destroy;
503 widget_class->realize = gtk_icon_view_realize;
504 widget_class->unrealize = gtk_icon_view_unrealize;
505 widget_class->style_set = gtk_icon_view_style_set;
506 widget_class->get_accessible = gtk_icon_view_get_accessible;
507 widget_class->size_request = gtk_icon_view_size_request;
508 widget_class->size_allocate = gtk_icon_view_size_allocate;
509 widget_class->expose_event = gtk_icon_view_expose;
510 widget_class->motion_notify_event = gtk_icon_view_motion;
511 widget_class->button_press_event = gtk_icon_view_button_press;
512 widget_class->button_release_event = gtk_icon_view_button_release;
513 widget_class->key_press_event = gtk_icon_view_key_press;
514 widget_class->key_release_event = gtk_icon_view_key_release;
515 widget_class->drag_begin = gtk_icon_view_drag_begin;
516 widget_class->drag_end = gtk_icon_view_drag_end;
517 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
518 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
519 widget_class->drag_leave = gtk_icon_view_drag_leave;
520 widget_class->drag_motion = gtk_icon_view_drag_motion;
521 widget_class->drag_drop = gtk_icon_view_drag_drop;
522 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
523 widget_class->state_changed = gtk_icon_view_state_changed;
525 container_class->remove = gtk_icon_view_remove;
526 container_class->forall = gtk_icon_view_forall;
528 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
529 klass->select_all = gtk_icon_view_real_select_all;
530 klass->unselect_all = gtk_icon_view_real_unselect_all;
531 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
532 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
533 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
534 klass->move_cursor = gtk_icon_view_real_move_cursor;
538 * GtkIconView:selection-mode:
540 * The ::selection-mode property specifies the selection mode of
541 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
542 * is enabled, for the other modes, only keyboard selection is possible.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_enum ("selection-mode",
549 P_("Selection mode"),
550 P_("The selection mode"),
551 GTK_TYPE_SELECTION_MODE,
552 GTK_SELECTION_SINGLE,
553 GTK_PARAM_READWRITE));
556 * GtkIconView:pixbuf-column:
558 * The ::pixbuf-column property contains the number of the model column
559 * containing the pixbufs which are displayed. The pixbuf column must be
560 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
561 * display of pixbufs.
565 g_object_class_install_property (gobject_class,
567 g_param_spec_int ("pixbuf-column",
569 P_("Model column used to retrieve the icon pixbuf from"),
571 GTK_PARAM_READWRITE));
574 * GtkIconView:text-column:
576 * The ::text-column property contains the number of the model column
577 * containing the texts which are displayed. The text column must be
578 * of type #G_TYPE_STRING. If this property and the :markup-column
579 * property are both set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("text-column",
587 P_("Model column used to retrieve the text from"),
589 GTK_PARAM_READWRITE));
593 * GtkIconView:markup-column:
595 * The ::markup-column property contains the number of the model column
596 * containing markup information to be displayed. The markup column must be
597 * of type #G_TYPE_STRING. If this property and the :text-column property
598 * are both set to column numbers, it overrides the text column.
599 * If both are set to -1, no texts are displayed.
603 g_object_class_install_property (gobject_class,
605 g_param_spec_int ("markup-column",
607 P_("Model column used to retrieve the text if using Pango markup"),
609 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_object ("model",
614 P_("Icon View Model"),
615 P_("The model for the icon view"),
617 GTK_PARAM_READWRITE));
620 * GtkIconView:columns:
622 * The columns property contains the number of the columns in which the
623 * items should be displayed. If it is -1, the number of columns will
624 * be chosen automatically to fill the available area.
628 g_object_class_install_property (gobject_class,
630 g_param_spec_int ("columns",
631 P_("Number of columns"),
632 P_("Number of columns to display"),
634 GTK_PARAM_READWRITE));
638 * GtkIconView:item-width:
640 * The item-width property specifies the width to use for each item.
641 * If it is set to -1, the icon view will automatically determine a
642 * suitable item size.
646 g_object_class_install_property (gobject_class,
648 g_param_spec_int ("item-width",
649 P_("Width for each item"),
650 P_("The width used for each item"),
652 GTK_PARAM_READWRITE));
655 * GtkIconView:spacing:
657 * The spacing property specifies the space which is inserted between
658 * the cells (i.e. the icon and the text) of an item.
662 g_object_class_install_property (gobject_class,
664 g_param_spec_int ("spacing",
666 P_("Space which is inserted between cells of an item"),
668 GTK_PARAM_READWRITE));
671 * GtkIconView:row-spacing:
673 * The row-spacing property specifies the space which is inserted between
674 * the rows of the icon view.
678 g_object_class_install_property (gobject_class,
680 g_param_spec_int ("row-spacing",
682 P_("Space which is inserted between grid rows"),
684 GTK_PARAM_READWRITE));
687 * GtkIconView:column-spacing:
689 * The column-spacing property specifies the space which is inserted between
690 * the columns of the icon view.
694 g_object_class_install_property (gobject_class,
696 g_param_spec_int ("column-spacing",
697 P_("Column Spacing"),
698 P_("Space which is inserted between grid columns"),
700 GTK_PARAM_READWRITE));
703 * GtkIconView:margin:
705 * The margin property specifies the space which is inserted
706 * at the edges of the icon view.
710 g_object_class_install_property (gobject_class,
712 g_param_spec_int ("margin",
714 P_("Space which is inserted at the edges of the icon view"),
716 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));
762 * GtkIconView:item-padding:
764 * The item-padding property specifies the padding around each
765 * of the icon view's item.
769 g_object_class_install_property (gobject_class,
771 g_param_spec_int ("item-padding",
773 P_("Padding around icon view items"),
775 GTK_PARAM_READWRITE));
779 /* Style properties */
780 gtk_widget_class_install_style_property (widget_class,
781 g_param_spec_boxed ("selection-box-color",
782 P_("Selection Box Color"),
783 P_("Color of the selection box"),
785 GTK_PARAM_READABLE));
787 gtk_widget_class_install_style_property (widget_class,
788 g_param_spec_uchar ("selection-box-alpha",
789 P_("Selection Box Alpha"),
790 P_("Opacity of the selection box"),
793 GTK_PARAM_READABLE));
797 * GtkIconView::set-scroll-adjustments
798 * @horizontal: the horizontal #GtkAdjustment
799 * @vertical: the vertical #GtkAdjustment
801 * Set the scroll adjustments for the icon view. Usually scrolled containers
802 * like #GtkScrolledWindow will emit this signal to connect two instances
803 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
805 widget_class->set_scroll_adjustments_signal =
806 g_signal_new (I_("set-scroll-adjustments"),
807 G_TYPE_FROM_CLASS (gobject_class),
809 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
811 _gtk_marshal_VOID__OBJECT_OBJECT,
813 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
816 * GtkIconView::item-activated:
817 * @iconview: the object on which the signal is emitted
818 * @path: the #GtkTreePath for the activated item
820 * The ::item-activated signal is emitted when the method
821 * gtk_icon_view_item_activated() is called or the user double
822 * clicks an item. It is also emitted when a non-editable item
823 * is selected and one of the keys: Space, Return or Enter is
826 icon_view_signals[ITEM_ACTIVATED] =
827 g_signal_new (I_("item-activated"),
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
832 g_cclosure_marshal_VOID__BOXED,
837 * GtkIconView::selection-changed:
838 * @iconview: the object on which the signal is emitted
840 * The ::selection-changed signal is emitted when the selection
841 * (i.e. the set of selected items) changes.
843 icon_view_signals[SELECTION_CHANGED] =
844 g_signal_new (I_("selection-changed"),
845 G_TYPE_FROM_CLASS (gobject_class),
847 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
849 g_cclosure_marshal_VOID__VOID,
853 * GtkIconView::select-all:
854 * @iconview: the object on which the signal is emitted
856 * A <link linkend="keybinding-signals">keybinding signal</link>
857 * which gets emitted when the user selects all items.
859 * Applications should not connect to it, but may emit it with
860 * g_signal_emit_by_name() if they need to control selection
863 * The default binding for this signal is Ctrl-a.
865 icon_view_signals[SELECT_ALL] =
866 g_signal_new (I_("select-all"),
867 G_TYPE_FROM_CLASS (gobject_class),
868 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
869 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
871 g_cclosure_marshal_VOID__VOID,
875 * GtkIconView::unselect-all:
876 * @iconview: the object on which the signal is emitted
878 * A <link linkend="keybinding-signals">keybinding signal</link>
879 * which gets emitted when the user unselects all items.
881 * Applications should not connect to it, but may emit it with
882 * g_signal_emit_by_name() if they need to control selection
885 * The default binding for this signal is Ctrl-Shift-a.
887 icon_view_signals[UNSELECT_ALL] =
888 g_signal_new (I_("unselect-all"),
889 G_TYPE_FROM_CLASS (gobject_class),
890 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
891 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
893 g_cclosure_marshal_VOID__VOID,
897 * GtkIconView::select-cursor-item:
898 * @iconview: the object on which the signal is emitted
900 * A <link linkend="keybinding-signals">keybinding signal</link>
901 * which gets emitted when the user selects the item that is currently
904 * Applications should not connect to it, but may emit it with
905 * g_signal_emit_by_name() if they need to control selection
908 * There is no default binding for this signal.
910 icon_view_signals[SELECT_CURSOR_ITEM] =
911 g_signal_new (I_("select-cursor-item"),
912 G_TYPE_FROM_CLASS (gobject_class),
913 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
914 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
916 g_cclosure_marshal_VOID__VOID,
920 * GtkIconView::toggle-cursor-item:
921 * @iconview: the object on which the signal is emitted
923 * A <link linkend="keybinding-signals">keybinding signal</link>
924 * which gets emitted when the user toggles whether the currently
925 * focused item is selected or not. The exact effect of this
926 * depend on the selection mode.
928 * Applications should not connect to it, but may emit it with
929 * g_signal_emit_by_name() if they need to control selection
932 * There is no default binding for this signal is Ctrl-Space.
934 icon_view_signals[TOGGLE_CURSOR_ITEM] =
935 g_signal_new (I_("toggle-cursor-item"),
936 G_TYPE_FROM_CLASS (gobject_class),
937 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
938 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
940 g_cclosure_marshal_VOID__VOID,
944 * GtkIconView::activate-cursor-item:
945 * @iconview: the object on which the signal is emitted
947 * A <link linkend="keybinding-signals">keybinding signal</link>
948 * which gets emitted when the user activates the currently
951 * Applications should not connect to it, but may emit it with
952 * g_signal_emit_by_name() if they need to control activation
955 * The default bindings for this signal are Space, Return and Enter.
957 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
958 g_signal_new (I_("activate-cursor-item"),
959 G_TYPE_FROM_CLASS (gobject_class),
960 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
961 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
963 _gtk_marshal_BOOLEAN__VOID,
967 * GtkIconView::move-cursor:
968 * @iconview: the object which received the signal
969 * @step: the granularity of the move, as a #GtkMovementStep
970 * @count: the number of @step units to move
972 * The ::move-cursor signal is a
973 * <link linkend="keybinding-signals">keybinding signal</link>
974 * which gets emitted when the user initiates a cursor movement.
976 * Applications should not connect to it, but may emit it with
977 * g_signal_emit_by_name() if they need to control the cursor
980 * The default bindings for this signal include
982 * <listitem>Arrow keys which move by individual steps</listitem>
983 * <listitem>Home/End keys which move to the first/last item</listitem>
984 * <listitem>PageUp/PageDown which move by "pages"</listitem>
987 * All of these will extend the selection when combined with
988 * the Shift modifier.
990 icon_view_signals[MOVE_CURSOR] =
991 g_signal_new (I_("move-cursor"),
992 G_TYPE_FROM_CLASS (gobject_class),
993 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
994 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
996 _gtk_marshal_BOOLEAN__ENUM_INT,
998 GTK_TYPE_MOVEMENT_STEP,
1002 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1004 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1006 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1007 "toggle-cursor-item", 0);
1008 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1009 "toggle-cursor-item", 0);
1011 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1012 "activate-cursor-item", 0);
1013 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1014 "activate-cursor-item", 0);
1015 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1016 "activate-cursor-item", 0);
1017 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1018 "activate-cursor-item", 0);
1019 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1020 "activate-cursor-item", 0);
1022 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1023 GTK_MOVEMENT_DISPLAY_LINES, -1);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1025 GTK_MOVEMENT_DISPLAY_LINES, -1);
1027 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1028 GTK_MOVEMENT_DISPLAY_LINES, 1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1030 GTK_MOVEMENT_DISPLAY_LINES, 1);
1032 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1033 GTK_MOVEMENT_DISPLAY_LINES, -1);
1035 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1036 GTK_MOVEMENT_DISPLAY_LINES, 1);
1038 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1039 GTK_MOVEMENT_BUFFER_ENDS, -1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1041 GTK_MOVEMENT_BUFFER_ENDS, -1);
1043 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1044 GTK_MOVEMENT_BUFFER_ENDS, 1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1046 GTK_MOVEMENT_BUFFER_ENDS, 1);
1048 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1049 GTK_MOVEMENT_PAGES, -1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1051 GTK_MOVEMENT_PAGES, -1);
1053 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1054 GTK_MOVEMENT_PAGES, 1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1056 GTK_MOVEMENT_PAGES, 1);
1058 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1059 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1061 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1063 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1064 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1066 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1070 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1072 parent_buildable_iface = g_type_interface_peek_parent (iface);
1073 iface->add_child = _gtk_cell_layout_buildable_add_child;
1074 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1075 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1079 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1081 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1082 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1083 iface->clear = gtk_icon_view_cell_layout_clear;
1084 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1085 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1086 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1087 iface->reorder = gtk_icon_view_cell_layout_reorder;
1088 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1092 gtk_icon_view_init (GtkIconView *icon_view)
1094 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1096 icon_view->priv->width = 0;
1097 icon_view->priv->height = 0;
1098 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1099 icon_view->priv->pressed_button = -1;
1100 icon_view->priv->press_start_x = -1;
1101 icon_view->priv->press_start_y = -1;
1102 icon_view->priv->text_column = -1;
1103 icon_view->priv->markup_column = -1;
1104 icon_view->priv->pixbuf_column = -1;
1105 icon_view->priv->text_cell = -1;
1106 icon_view->priv->pixbuf_cell = -1;
1107 icon_view->priv->tooltip_column = -1;
1109 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
1111 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1113 icon_view->priv->cell_list = NULL;
1114 icon_view->priv->n_cells = 0;
1115 icon_view->priv->cursor_cell = -1;
1117 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1119 icon_view->priv->columns = -1;
1120 icon_view->priv->item_width = -1;
1121 icon_view->priv->spacing = 0;
1122 icon_view->priv->row_spacing = 6;
1123 icon_view->priv->column_spacing = 6;
1124 icon_view->priv->margin = 6;
1125 icon_view->priv->item_padding = 6;
1127 icon_view->priv->draw_focus = TRUE;
1131 gtk_icon_view_destroy (GtkObject *object)
1133 GtkIconView *icon_view;
1135 icon_view = GTK_ICON_VIEW (object);
1137 gtk_icon_view_stop_editing (icon_view, TRUE);
1139 gtk_icon_view_set_model (icon_view, NULL);
1141 if (icon_view->priv->layout_idle_id != 0)
1143 g_source_remove (icon_view->priv->layout_idle_id);
1144 icon_view->priv->layout_idle_id = 0;
1147 if (icon_view->priv->scroll_to_path != NULL)
1149 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1150 icon_view->priv->scroll_to_path = NULL;
1153 remove_scroll_timeout (icon_view);
1155 if (icon_view->priv->hadjustment != NULL)
1157 g_object_unref (icon_view->priv->hadjustment);
1158 icon_view->priv->hadjustment = NULL;
1161 if (icon_view->priv->vadjustment != NULL)
1163 g_object_unref (icon_view->priv->vadjustment);
1164 icon_view->priv->vadjustment = NULL;
1167 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1170 /* GObject methods */
1172 gtk_icon_view_finalize (GObject *object)
1174 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1176 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1181 gtk_icon_view_set_property (GObject *object,
1183 const GValue *value,
1186 GtkIconView *icon_view;
1188 icon_view = GTK_ICON_VIEW (object);
1192 case PROP_SELECTION_MODE:
1193 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1195 case PROP_PIXBUF_COLUMN:
1196 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1198 case PROP_TEXT_COLUMN:
1199 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1201 case PROP_MARKUP_COLUMN:
1202 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1205 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1207 case PROP_ORIENTATION:
1208 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1211 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1213 case PROP_ITEM_WIDTH:
1214 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1217 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1219 case PROP_ROW_SPACING:
1220 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1222 case PROP_COLUMN_SPACING:
1223 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1226 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1228 case PROP_REORDERABLE:
1229 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1232 case PROP_TOOLTIP_COLUMN:
1233 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1236 case PROP_ITEM_PADDING:
1237 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1247 gtk_icon_view_get_property (GObject *object,
1252 GtkIconView *icon_view;
1254 icon_view = GTK_ICON_VIEW (object);
1258 case PROP_SELECTION_MODE:
1259 g_value_set_enum (value, icon_view->priv->selection_mode);
1261 case PROP_PIXBUF_COLUMN:
1262 g_value_set_int (value, icon_view->priv->pixbuf_column);
1264 case PROP_TEXT_COLUMN:
1265 g_value_set_int (value, icon_view->priv->text_column);
1267 case PROP_MARKUP_COLUMN:
1268 g_value_set_int (value, icon_view->priv->markup_column);
1271 g_value_set_object (value, icon_view->priv->model);
1273 case PROP_ORIENTATION:
1274 g_value_set_enum (value, icon_view->priv->orientation);
1277 g_value_set_int (value, icon_view->priv->columns);
1279 case PROP_ITEM_WIDTH:
1280 g_value_set_int (value, icon_view->priv->item_width);
1283 g_value_set_int (value, icon_view->priv->spacing);
1285 case PROP_ROW_SPACING:
1286 g_value_set_int (value, icon_view->priv->row_spacing);
1288 case PROP_COLUMN_SPACING:
1289 g_value_set_int (value, icon_view->priv->column_spacing);
1292 g_value_set_int (value, icon_view->priv->margin);
1294 case PROP_REORDERABLE:
1295 g_value_set_boolean (value, icon_view->priv->reorderable);
1297 case PROP_TOOLTIP_COLUMN:
1298 g_value_set_int (value, icon_view->priv->tooltip_column);
1301 case PROP_ITEM_PADDING:
1302 g_value_set_int (value, icon_view->priv->item_padding);
1306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1311 /* GtkWidget signals */
1313 gtk_icon_view_realize (GtkWidget *widget)
1315 GtkIconView *icon_view;
1316 GdkWindowAttr attributes;
1317 gint attributes_mask;
1319 icon_view = GTK_ICON_VIEW (widget);
1321 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1323 /* Make the main, clipping window */
1324 attributes.window_type = GDK_WINDOW_CHILD;
1325 attributes.x = widget->allocation.x;
1326 attributes.y = widget->allocation.y;
1327 attributes.width = widget->allocation.width;
1328 attributes.height = widget->allocation.height;
1329 attributes.wclass = GDK_INPUT_OUTPUT;
1330 attributes.visual = gtk_widget_get_visual (widget);
1331 attributes.colormap = gtk_widget_get_colormap (widget);
1332 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1334 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1336 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1337 &attributes, attributes_mask);
1338 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1339 gdk_window_set_user_data (widget->window, widget);
1341 /* Make the window for the icon view */
1344 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1345 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1346 attributes.event_mask = (GDK_EXPOSURE_MASK |
1348 GDK_POINTER_MOTION_MASK |
1349 GDK_BUTTON_PRESS_MASK |
1350 GDK_BUTTON_RELEASE_MASK |
1351 GDK_KEY_PRESS_MASK |
1352 GDK_KEY_RELEASE_MASK) |
1353 gtk_widget_get_events (widget);
1355 icon_view->priv->bin_window = gdk_window_new (widget->window,
1356 &attributes, attributes_mask);
1357 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1359 widget->style = gtk_style_attach (widget->style, widget->window);
1360 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1362 gdk_window_show (icon_view->priv->bin_window);
1366 gtk_icon_view_unrealize (GtkWidget *widget)
1368 GtkIconView *icon_view;
1370 icon_view = GTK_ICON_VIEW (widget);
1372 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1373 gdk_window_destroy (icon_view->priv->bin_window);
1374 icon_view->priv->bin_window = NULL;
1376 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1380 gtk_icon_view_state_changed (GtkWidget *widget,
1381 GtkStateType previous_state)
1383 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1385 if (GTK_WIDGET_REALIZED (widget))
1387 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1388 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1391 gtk_widget_queue_draw (widget);
1395 gtk_icon_view_style_set (GtkWidget *widget,
1396 GtkStyle *previous_style)
1398 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1400 if (GTK_WIDGET_REALIZED (widget))
1402 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1403 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1406 gtk_widget_queue_resize (widget);
1410 gtk_icon_view_size_request (GtkWidget *widget,
1411 GtkRequisition *requisition)
1413 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1416 requisition->width = icon_view->priv->width;
1417 requisition->height = icon_view->priv->height;
1419 tmp_list = icon_view->priv->children;
1423 GtkIconViewChild *child = tmp_list->data;
1424 GtkRequisition child_requisition;
1426 tmp_list = tmp_list->next;
1428 if (GTK_WIDGET_VISIBLE (child->widget))
1429 gtk_widget_size_request (child->widget, &child_requisition);
1434 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1438 for (list = icon_view->priv->children; list; list = list->next)
1440 GtkIconViewChild *child = list->data;
1441 GtkAllocation allocation;
1443 /* totally ignore our child's requisition */
1444 if (child->cell < 0)
1446 allocation.x = child->item->x + icon_view->priv->item_padding;
1447 allocation.y = child->item->y + icon_view->priv->item_padding;
1448 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1449 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1453 GdkRectangle *box = &child->item->box[child->cell];
1455 allocation.x = box->x;
1456 allocation.y = box->y;
1457 allocation.width = box->width;
1458 allocation.height = box->height;
1461 gtk_widget_size_allocate (child->widget, &allocation);
1466 gtk_icon_view_size_allocate (GtkWidget *widget,
1467 GtkAllocation *allocation)
1469 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1471 GtkAdjustment *hadjustment, *vadjustment;
1473 widget->allocation = *allocation;
1475 if (GTK_WIDGET_REALIZED (widget))
1477 gdk_window_move_resize (widget->window,
1478 allocation->x, allocation->y,
1479 allocation->width, allocation->height);
1480 gdk_window_resize (icon_view->priv->bin_window,
1481 MAX (icon_view->priv->width, allocation->width),
1482 MAX (icon_view->priv->height, allocation->height));
1485 gtk_icon_view_layout (icon_view);
1487 gtk_icon_view_allocate_children (icon_view);
1489 hadjustment = icon_view->priv->hadjustment;
1490 vadjustment = icon_view->priv->vadjustment;
1492 hadjustment->page_size = allocation->width;
1493 hadjustment->page_increment = allocation->width * 0.9;
1494 hadjustment->step_increment = allocation->width * 0.1;
1495 hadjustment->lower = 0;
1496 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1498 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1499 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1501 vadjustment->page_size = allocation->height;
1502 vadjustment->page_increment = allocation->height * 0.9;
1503 vadjustment->step_increment = allocation->height * 0.1;
1504 vadjustment->lower = 0;
1505 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1507 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1508 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1510 if (GTK_WIDGET_REALIZED (widget) &&
1511 icon_view->priv->scroll_to_path)
1514 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1515 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1516 icon_view->priv->scroll_to_path = NULL;
1518 gtk_icon_view_scroll_to_path (icon_view, path,
1519 icon_view->priv->scroll_to_use_align,
1520 icon_view->priv->scroll_to_row_align,
1521 icon_view->priv->scroll_to_col_align);
1522 gtk_tree_path_free (path);
1526 gtk_adjustment_changed (hadjustment);
1527 gtk_adjustment_changed (vadjustment);
1532 gtk_icon_view_expose (GtkWidget *widget,
1533 GdkEventExpose *expose)
1535 GtkIconView *icon_view;
1540 GtkIconViewDropPosition dest_pos;
1541 GtkIconViewItem *dest_item = NULL;
1543 icon_view = GTK_ICON_VIEW (widget);
1545 if (expose->window != icon_view->priv->bin_window)
1548 cr = gdk_cairo_create (icon_view->priv->bin_window);
1549 cairo_set_line_width (cr, 1.);
1551 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1555 dest_index = gtk_tree_path_get_indices (path)[0];
1556 gtk_tree_path_free (path);
1561 for (icons = icon_view->priv->items; icons; icons = icons->next)
1563 GtkIconViewItem *item = icons->data;
1568 area.width = item->width;
1569 area.height = item->height;
1571 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1574 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1575 icon_view->priv->bin_window,
1577 icon_view->priv->draw_focus);
1579 if (dest_index == item->index)
1587 case GTK_ICON_VIEW_DROP_INTO:
1588 gtk_paint_focus (widget->style,
1589 icon_view->priv->bin_window,
1590 GTK_WIDGET_STATE (widget),
1593 "iconview-drop-indicator",
1594 dest_item->x, dest_item->y,
1595 dest_item->width, dest_item->height);
1597 case GTK_ICON_VIEW_DROP_ABOVE:
1598 gtk_paint_focus (widget->style,
1599 icon_view->priv->bin_window,
1600 GTK_WIDGET_STATE (widget),
1603 "iconview-drop-indicator",
1604 dest_item->x, dest_item->y - 1,
1605 dest_item->width, 2);
1607 case GTK_ICON_VIEW_DROP_LEFT:
1608 gtk_paint_focus (widget->style,
1609 icon_view->priv->bin_window,
1610 GTK_WIDGET_STATE (widget),
1613 "iconview-drop-indicator",
1614 dest_item->x - 1, dest_item->y,
1615 2, dest_item->height);
1617 case GTK_ICON_VIEW_DROP_BELOW:
1618 gtk_paint_focus (widget->style,
1619 icon_view->priv->bin_window,
1620 GTK_WIDGET_STATE (widget),
1623 "iconview-drop-indicator",
1624 dest_item->x, dest_item->y + dest_item->height - 1,
1625 dest_item->width, 2);
1627 case GTK_ICON_VIEW_DROP_RIGHT:
1628 gtk_paint_focus (widget->style,
1629 icon_view->priv->bin_window,
1630 GTK_WIDGET_STATE (widget),
1633 "iconview-drop-indicator",
1634 dest_item->x + dest_item->width - 1, dest_item->y,
1635 2, dest_item->height);
1636 case GTK_ICON_VIEW_NO_DROP: ;
1641 if (icon_view->priv->doing_rubberband)
1643 GdkRectangle *rectangles;
1646 gdk_region_get_rectangles (expose->region,
1650 while (n_rectangles--)
1651 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1653 g_free (rectangles);
1658 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1664 rubberband_scroll_timeout (gpointer data)
1666 GtkIconView *icon_view;
1671 value = MIN (icon_view->priv->vadjustment->value +
1672 icon_view->priv->scroll_value_diff,
1673 icon_view->priv->vadjustment->upper -
1674 icon_view->priv->vadjustment->page_size);
1676 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1678 gtk_icon_view_update_rubberband (icon_view);
1684 gtk_icon_view_motion (GtkWidget *widget,
1685 GdkEventMotion *event)
1687 GtkIconView *icon_view;
1690 icon_view = GTK_ICON_VIEW (widget);
1692 gtk_icon_view_maybe_begin_drag (icon_view, event);
1694 if (icon_view->priv->doing_rubberband)
1696 gtk_icon_view_update_rubberband (widget);
1698 abs_y = event->y - icon_view->priv->height *
1699 (icon_view->priv->vadjustment->value /
1700 (icon_view->priv->vadjustment->upper -
1701 icon_view->priv->vadjustment->lower));
1703 if (abs_y < 0 || abs_y > widget->allocation.height)
1706 icon_view->priv->scroll_value_diff = abs_y;
1708 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1710 icon_view->priv->event_last_x = event->x;
1711 icon_view->priv->event_last_y = event->y;
1713 if (icon_view->priv->scroll_timeout_id == 0)
1714 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1718 remove_scroll_timeout (icon_view);
1725 gtk_icon_view_remove (GtkContainer *container,
1728 GtkIconView *icon_view;
1729 GtkIconViewChild *child = NULL;
1732 icon_view = GTK_ICON_VIEW (container);
1734 tmp_list = icon_view->priv->children;
1737 child = tmp_list->data;
1738 if (child->widget == widget)
1740 gtk_widget_unparent (widget);
1742 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1743 g_list_free_1 (tmp_list);
1748 tmp_list = tmp_list->next;
1753 gtk_icon_view_forall (GtkContainer *container,
1754 gboolean include_internals,
1755 GtkCallback callback,
1756 gpointer callback_data)
1758 GtkIconView *icon_view;
1759 GtkIconViewChild *child = NULL;
1762 icon_view = GTK_ICON_VIEW (container);
1764 tmp_list = icon_view->priv->children;
1767 child = tmp_list->data;
1768 tmp_list = tmp_list->next;
1770 (* callback) (child->widget, callback_data);
1775 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1776 GtkIconViewItem *item,
1777 GtkIconViewCellInfo *info,
1782 GdkRectangle cell_area;
1783 gboolean visible, mode;
1785 gtk_icon_view_set_cell_data (icon_view, item);
1787 g_object_get (info->cell,
1788 "visible", &visible,
1792 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1794 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1796 path = gtk_tree_path_new_from_indices (item->index, -1);
1797 path_string = gtk_tree_path_to_string (path);
1798 gtk_tree_path_free (path);
1800 gtk_cell_renderer_activate (info->cell,
1802 GTK_WIDGET (icon_view),
1808 g_free (path_string);
1813 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1814 GtkIconViewItem *item)
1817 AtkObject *item_obj;
1819 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1822 item_obj = atk_object_ref_accessible_child (obj, item->index);
1823 if (item_obj != NULL)
1825 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1826 g_object_unref (item_obj);
1832 gtk_icon_view_put (GtkIconView *icon_view,
1834 GtkIconViewItem *item,
1837 GtkIconViewChild *child;
1839 child = g_new (GtkIconViewChild, 1);
1841 child->widget = widget;
1845 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1847 if (GTK_WIDGET_REALIZED (icon_view))
1848 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1850 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1854 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1855 GtkIconView *icon_view)
1858 GtkIconViewItem *item;
1860 if (icon_view->priv->edited_item == NULL)
1863 item = icon_view->priv->edited_item;
1864 icon_view->priv->edited_item = NULL;
1865 icon_view->priv->editable = NULL;
1866 for (l = icon_view->priv->cell_list; l; l = l->next)
1868 GtkIconViewCellInfo *info = l->data;
1870 info->editing = FALSE;
1873 if (GTK_WIDGET_HAS_FOCUS (editable))
1874 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1876 g_signal_handlers_disconnect_by_func (editable,
1877 gtk_icon_view_remove_widget,
1880 gtk_container_remove (GTK_CONTAINER (icon_view),
1881 GTK_WIDGET (editable));
1883 gtk_icon_view_queue_draw_item (icon_view, item);
1888 gtk_icon_view_start_editing (GtkIconView *icon_view,
1889 GtkIconViewItem *item,
1890 GtkIconViewCellInfo *info,
1895 GdkRectangle cell_area;
1896 gboolean visible, mode;
1897 GtkCellEditable *editable;
1899 gtk_icon_view_set_cell_data (icon_view, item);
1901 g_object_get (info->cell,
1902 "visible", &visible,
1905 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1907 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1909 path = gtk_tree_path_new_from_indices (item->index, -1);
1910 path_string = gtk_tree_path_to_string (path);
1911 gtk_tree_path_free (path);
1913 editable = gtk_cell_renderer_start_editing (info->cell,
1915 GTK_WIDGET (icon_view),
1920 g_free (path_string);
1922 /* the rest corresponds to tree_view_real_start_editing... */
1923 icon_view->priv->edited_item = item;
1924 icon_view->priv->editable = editable;
1925 info->editing = TRUE;
1927 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1929 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1931 gtk_widget_grab_focus (GTK_WIDGET (editable));
1932 g_signal_connect (editable, "remove-widget",
1933 G_CALLBACK (gtk_icon_view_remove_widget),
1940 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1941 gboolean cancel_editing)
1943 GtkCellRenderer *cell = NULL;
1944 GtkIconViewItem *item;
1947 if (icon_view->priv->edited_item == NULL)
1951 * This is very evil. We need to do this, because
1952 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1953 * later on. If gtk_icon_view_row_changed notices
1954 * icon_view->priv->edited_item != NULL, it'll call
1955 * gtk_icon_view_stop_editing again. Bad things will happen then.
1957 * Please read that again if you intend to modify anything here.
1960 item = icon_view->priv->edited_item;
1961 icon_view->priv->edited_item = NULL;
1963 for (l = icon_view->priv->cell_list; l; l = l->next)
1965 GtkIconViewCellInfo *info = l->data;
1977 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1978 if (!cancel_editing)
1979 gtk_cell_editable_editing_done (icon_view->priv->editable);
1981 icon_view->priv->edited_item = item;
1983 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1987 * gtk_icon_view_set_cursor:
1988 * @icon_view: A #GtkIconView
1989 * @path: A #GtkTreePath
1990 * @cell: One of the cell renderers of @icon_view, or %NULL
1991 * @start_editing: %TRUE if the specified cell should start being edited.
1993 * Sets the current keyboard focus to be at @path, and selects it. This is
1994 * useful when you want to focus the user's attention on a particular item.
1995 * If @cell is not %NULL, then focus is given to the cell specified by
1996 * it. Additionally, if @start_editing is %TRUE, then editing should be
1997 * started in the specified cell.
1999 * This function is often followed by <literal>gtk_widget_grab_focus
2000 * (icon_view)</literal> in order to give keyboard focus to the widget.
2001 * Please note that editing can only happen when the widget is realized.
2006 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2008 GtkCellRenderer *cell,
2009 gboolean start_editing)
2011 GtkIconViewItem *item = NULL;
2012 GtkIconViewCellInfo *info = NULL;
2016 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2017 g_return_if_fail (path != NULL);
2018 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2020 gtk_icon_view_stop_editing (icon_view, TRUE);
2022 if (gtk_tree_path_get_depth (path) == 1)
2023 item = g_list_nth_data (icon_view->priv->items,
2024 gtk_tree_path_get_indices(path)[0]);
2030 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2034 if (info->cell == cell)
2043 g_return_if_fail (cell == NULL || info != NULL);
2045 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2046 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2048 if (info && start_editing)
2049 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2053 * gtk_icon_view_get_cursor:
2054 * @icon_view: A #GtkIconView
2055 * @path: Return location for the current cursor path, or %NULL
2056 * @cell: Return location the current focus cell, or %NULL
2058 * Fills in @path and @cell with the current cursor path and cell.
2059 * If the cursor isn't currently set, then *@path will be %NULL.
2060 * If no cell currently has focus, then *@cell will be %NULL.
2062 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2064 * Return value: %TRUE if the cursor is set.
2069 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2071 GtkCellRenderer **cell)
2073 GtkIconViewItem *item;
2074 GtkIconViewCellInfo *info;
2076 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2078 item = icon_view->priv->cursor_item;
2079 if (icon_view->priv->cursor_cell < 0)
2082 info = g_list_nth_data (icon_view->priv->cell_list,
2083 icon_view->priv->cursor_cell);
2088 *path = gtk_tree_path_new_from_indices (item->index, -1);
2101 return (item != NULL);
2105 gtk_icon_view_button_press (GtkWidget *widget,
2106 GdkEventButton *event)
2108 GtkIconView *icon_view;
2109 GtkIconViewItem *item;
2110 GtkIconViewCellInfo *info = NULL;
2111 gboolean dirty = FALSE;
2112 GtkCellRendererMode mode;
2113 gint cursor_cell = -1;
2115 icon_view = GTK_ICON_VIEW (widget);
2117 if (event->window != icon_view->priv->bin_window)
2120 if (!GTK_WIDGET_HAS_FOCUS (widget))
2121 gtk_widget_grab_focus (widget);
2123 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2125 item = gtk_icon_view_get_item_at_coords (icon_view,
2131 * We consider only the the cells' area as the item area if the
2132 * item is not selected, but if it *is* selected, the complete
2133 * selection rectangle is considered to be part of the item.
2135 if (item != NULL && (info != NULL || item->selected))
2139 g_object_get (info->cell, "mode", &mode, NULL);
2141 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2142 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2143 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2146 gtk_icon_view_scroll_to_item (icon_view, item);
2148 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2150 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2152 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2153 (event->state & GDK_SHIFT_MASK))
2155 gtk_icon_view_unselect_all_internal (icon_view);
2157 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2158 if (!icon_view->priv->anchor_item)
2159 icon_view->priv->anchor_item = item;
2161 gtk_icon_view_select_all_between (icon_view,
2162 icon_view->priv->anchor_item,
2168 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2169 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2170 (event->state & GDK_CONTROL_MASK))
2172 item->selected = !item->selected;
2173 gtk_icon_view_queue_draw_item (icon_view, item);
2178 gtk_icon_view_unselect_all_internal (icon_view);
2180 item->selected = TRUE;
2181 gtk_icon_view_queue_draw_item (icon_view, item);
2184 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2185 icon_view->priv->anchor_item = item;
2188 /* Save press to possibly begin a drag */
2189 if (icon_view->priv->pressed_button < 0)
2191 icon_view->priv->pressed_button = event->button;
2192 icon_view->priv->press_start_x = event->x;
2193 icon_view->priv->press_start_y = event->y;
2196 if (!icon_view->priv->last_single_clicked)
2197 icon_view->priv->last_single_clicked = item;
2199 /* cancel the current editing, if it exists */
2200 gtk_icon_view_stop_editing (icon_view, TRUE);
2204 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2205 gtk_icon_view_item_activate_cell (icon_view, item, info,
2207 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2208 gtk_icon_view_start_editing (icon_view, item, info,
2214 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2215 !(event->state & GDK_CONTROL_MASK))
2217 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2220 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2221 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2224 /* don't draw keyboard focus around an clicked-on item */
2225 icon_view->priv->draw_focus = FALSE;
2228 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2230 item = gtk_icon_view_get_item_at_coords (icon_view,
2235 if (item && item == icon_view->priv->last_single_clicked)
2239 path = gtk_tree_path_new_from_indices (item->index, -1);
2240 gtk_icon_view_item_activated (icon_view, path);
2241 gtk_tree_path_free (path);
2244 icon_view->priv->last_single_clicked = NULL;
2245 icon_view->priv->pressed_button = -1;
2249 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2251 return event->button == 1;
2255 gtk_icon_view_button_release (GtkWidget *widget,
2256 GdkEventButton *event)
2258 GtkIconView *icon_view;
2260 icon_view = GTK_ICON_VIEW (widget);
2262 if (icon_view->priv->pressed_button == event->button)
2263 icon_view->priv->pressed_button = -1;
2265 gtk_icon_view_stop_rubberbanding (icon_view);
2267 remove_scroll_timeout (icon_view);
2273 gtk_icon_view_key_press (GtkWidget *widget,
2276 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2278 if (icon_view->priv->doing_rubberband)
2280 if (event->keyval == GDK_Escape)
2281 gtk_icon_view_stop_rubberbanding (icon_view);
2286 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2290 gtk_icon_view_key_release (GtkWidget *widget,
2293 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2295 if (icon_view->priv->doing_rubberband)
2298 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2302 gtk_icon_view_update_rubberband (gpointer data)
2304 GtkIconView *icon_view;
2306 GdkRectangle old_area;
2307 GdkRectangle new_area;
2308 GdkRectangle common;
2309 GdkRegion *invalid_region;
2311 icon_view = GTK_ICON_VIEW (data);
2313 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2318 old_area.x = MIN (icon_view->priv->rubberband_x1,
2319 icon_view->priv->rubberband_x2);
2320 old_area.y = MIN (icon_view->priv->rubberband_y1,
2321 icon_view->priv->rubberband_y2);
2322 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2323 icon_view->priv->rubberband_x1) + 1;
2324 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2325 icon_view->priv->rubberband_y1) + 1;
2327 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2328 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2329 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2330 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2332 invalid_region = gdk_region_rectangle (&old_area);
2333 gdk_region_union_with_rect (invalid_region, &new_area);
2335 gdk_rectangle_intersect (&old_area, &new_area, &common);
2336 if (common.width > 2 && common.height > 2)
2338 GdkRegion *common_region;
2340 /* make sure the border is invalidated */
2346 common_region = gdk_region_rectangle (&common);
2348 gdk_region_subtract (invalid_region, common_region);
2349 gdk_region_destroy (common_region);
2352 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2354 gdk_region_destroy (invalid_region);
2356 icon_view->priv->rubberband_x2 = x;
2357 icon_view->priv->rubberband_y2 = y;
2359 gtk_icon_view_update_rubberband_selection (icon_view);
2363 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2369 g_assert (!icon_view->priv->doing_rubberband);
2371 for (items = icon_view->priv->items; items; items = items->next)
2373 GtkIconViewItem *item = items->data;
2375 item->selected_before_rubberbanding = item->selected;
2378 icon_view->priv->rubberband_x1 = x;
2379 icon_view->priv->rubberband_y1 = y;
2380 icon_view->priv->rubberband_x2 = x;
2381 icon_view->priv->rubberband_y2 = y;
2383 icon_view->priv->doing_rubberband = TRUE;
2385 gtk_grab_add (GTK_WIDGET (icon_view));
2389 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2391 if (!icon_view->priv->doing_rubberband)
2394 icon_view->priv->doing_rubberband = FALSE;
2396 gtk_grab_remove (GTK_WIDGET (icon_view));
2398 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2402 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2405 gint x, y, width, height;
2406 gboolean dirty = FALSE;
2408 x = MIN (icon_view->priv->rubberband_x1,
2409 icon_view->priv->rubberband_x2);
2410 y = MIN (icon_view->priv->rubberband_y1,
2411 icon_view->priv->rubberband_y2);
2412 width = ABS (icon_view->priv->rubberband_x1 -
2413 icon_view->priv->rubberband_x2);
2414 height = ABS (icon_view->priv->rubberband_y1 -
2415 icon_view->priv->rubberband_y2);
2417 for (items = icon_view->priv->items; items; items = items->next)
2419 GtkIconViewItem *item = items->data;
2423 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2424 x, y, width, height);
2426 selected = is_in ^ item->selected_before_rubberbanding;
2428 if (item->selected != selected)
2430 item->selected = selected;
2432 gtk_icon_view_queue_draw_item (icon_view, item);
2437 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2441 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2442 GtkIconViewItem *item,
2451 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2452 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2455 for (l = icon_view->priv->cell_list; l; l = l->next)
2457 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2459 if (!info->cell->visible)
2462 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2464 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2465 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2473 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2475 gboolean dirty = FALSE;
2478 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2481 for (items = icon_view->priv->items; items; items = items->next)
2483 GtkIconViewItem *item = items->data;
2487 item->selected = FALSE;
2489 gtk_icon_view_queue_draw_item (icon_view, item);
2490 gtk_icon_view_item_selected_changed (icon_view, item);
2498 /* GtkIconView signals */
2500 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2501 GtkAdjustment *hadj,
2502 GtkAdjustment *vadj)
2504 gboolean need_adjust = FALSE;
2507 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2509 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2511 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2513 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2515 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2517 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2518 0, 0, NULL, NULL, icon_view);
2519 g_object_unref (icon_view->priv->hadjustment);
2522 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2524 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2525 0, 0, NULL, NULL, icon_view);
2526 g_object_unref (icon_view->priv->vadjustment);
2529 if (icon_view->priv->hadjustment != hadj)
2531 icon_view->priv->hadjustment = hadj;
2532 g_object_ref_sink (icon_view->priv->hadjustment);
2534 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2535 G_CALLBACK (gtk_icon_view_adjustment_changed),
2540 if (icon_view->priv->vadjustment != vadj)
2542 icon_view->priv->vadjustment = vadj;
2543 g_object_ref_sink (icon_view->priv->vadjustment);
2545 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2546 G_CALLBACK (gtk_icon_view_adjustment_changed),
2552 gtk_icon_view_adjustment_changed (NULL, icon_view);
2556 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2558 gtk_icon_view_select_all (icon_view);
2562 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2564 gtk_icon_view_unselect_all (icon_view);
2568 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2570 gtk_icon_view_unselect_all (icon_view);
2572 if (icon_view->priv->cursor_item != NULL)
2573 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2577 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2580 GtkCellRendererMode mode;
2581 GtkIconViewCellInfo *info = NULL;
2583 if (!icon_view->priv->cursor_item)
2586 info = g_list_nth_data (icon_view->priv->cell_list,
2587 icon_view->priv->cursor_cell);
2591 g_object_get (info->cell, "mode", &mode, NULL);
2593 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2595 gtk_icon_view_item_activate_cell (icon_view,
2596 icon_view->priv->cursor_item,
2600 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2602 gtk_icon_view_start_editing (icon_view,
2603 icon_view->priv->cursor_item,
2609 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2610 gtk_icon_view_item_activated (icon_view, path);
2611 gtk_tree_path_free (path);
2617 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2619 if (!icon_view->priv->cursor_item)
2622 switch (icon_view->priv->selection_mode)
2624 case GTK_SELECTION_NONE:
2626 case GTK_SELECTION_BROWSE:
2627 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2629 case GTK_SELECTION_SINGLE:
2630 if (icon_view->priv->cursor_item->selected)
2631 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2633 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2635 case GTK_SELECTION_MULTIPLE:
2636 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2637 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2639 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2640 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2645 /* Internal functions */
2647 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2648 GtkIconView *icon_view)
2650 if (GTK_WIDGET_REALIZED (icon_view))
2652 gdk_window_move (icon_view->priv->bin_window,
2653 - icon_view->priv->hadjustment->value,
2654 - icon_view->priv->vadjustment->value);
2656 if (icon_view->priv->doing_rubberband)
2657 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2659 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2664 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2669 gint *maximum_width)
2672 gint x, current_width;
2673 GList *items, *last_item;
2680 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2681 max_height = g_new0 (gint, icon_view->priv->n_cells);
2688 gtk_widget_style_get (GTK_WIDGET (icon_view),
2689 "focus-line-width", &focus_width,
2692 x += icon_view->priv->margin + focus_width;
2693 current_width += 2 * (icon_view->priv->margin + focus_width);
2698 GtkIconViewItem *item = items->data;
2700 gtk_icon_view_calculate_item_size (icon_view, item);
2701 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2703 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2705 current_width += item->width;
2707 if (items != first_item)
2709 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2710 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2714 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2716 item->y = *y + focus_width;
2719 x = current_width - (icon_view->priv->margin + focus_width);
2721 for (i = 0; i < icon_view->priv->n_cells; i++)
2722 max_height[i] = MAX (max_height[i], item->box[i].height);
2724 if (current_width > *maximum_width)
2725 *maximum_width = current_width;
2731 items = items->next;
2736 /* Now go through the row again and align the icons */
2737 for (items = first_item; items != last_item; items = items->next)
2739 GtkIconViewItem *item = items->data;
2743 item->x = *maximum_width - item->width - item->x;
2744 item->col = col - 1 - item->col;
2747 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2749 /* We may want to readjust the new y coordinate. */
2750 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2751 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2754 g_free (max_height);
2760 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2763 if (upper != adj->upper)
2765 gdouble min = MAX (0.0, upper - adj->page_size);
2766 gboolean value_changed = FALSE;
2770 if (adj->value > min)
2773 value_changed = TRUE;
2776 gtk_adjustment_changed (adj);
2779 gtk_adjustment_value_changed (adj);
2784 gtk_icon_view_layout (GtkIconView *icon_view)
2786 gint y = 0, maximum_width = 0;
2792 if (icon_view->priv->layout_idle_id != 0)
2794 g_source_remove (icon_view->priv->layout_idle_id);
2795 icon_view->priv->layout_idle_id = 0;
2798 if (icon_view->priv->model == NULL)
2801 widget = GTK_WIDGET (icon_view);
2803 item_width = icon_view->priv->item_width;
2807 for (icons = icon_view->priv->items; icons; icons = icons->next)
2809 GtkIconViewItem *item = icons->data;
2810 gtk_icon_view_calculate_item_size (icon_view, item);
2811 item_width = MAX (item_width, item->width);
2816 icons = icon_view->priv->items;
2817 y += icon_view->priv->margin;
2822 gtk_icon_view_set_cell_data (icon_view, icons->data);
2823 adjust_wrap_width (icon_view, icons->data);
2828 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2830 &y, &maximum_width);
2833 while (icons != NULL);
2835 if (maximum_width != icon_view->priv->width)
2836 icon_view->priv->width = maximum_width;
2838 y += icon_view->priv->margin;
2840 if (y != icon_view->priv->height)
2841 icon_view->priv->height = y;
2843 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2844 icon_view->priv->width);
2845 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2846 icon_view->priv->height);
2848 if (icon_view->priv->width != widget->requisition.width ||
2849 icon_view->priv->height != widget->requisition.height)
2850 gtk_widget_queue_resize_no_redraw (widget);
2852 if (GTK_WIDGET_REALIZED (icon_view))
2853 gdk_window_resize (icon_view->priv->bin_window,
2854 MAX (icon_view->priv->width, widget->allocation.width),
2855 MAX (icon_view->priv->height, widget->allocation.height));
2857 if (icon_view->priv->scroll_to_path)
2861 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2862 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2863 icon_view->priv->scroll_to_path = NULL;
2865 gtk_icon_view_scroll_to_path (icon_view, path,
2866 icon_view->priv->scroll_to_use_align,
2867 icon_view->priv->scroll_to_row_align,
2868 icon_view->priv->scroll_to_col_align);
2869 gtk_tree_path_free (path);
2872 gtk_widget_queue_draw (widget);
2876 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2877 GtkIconViewItem *item,
2878 GtkIconViewCellInfo *info,
2879 GdkRectangle *cell_area)
2881 g_return_if_fail (info->position < item->n_cells);
2883 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2885 cell_area->x = item->box[info->position].x - item->before[info->position];
2886 cell_area->y = item->y + icon_view->priv->item_padding;
2887 cell_area->width = item->box[info->position].width +
2888 item->before[info->position] + item->after[info->position];
2889 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2893 cell_area->x = item->x + icon_view->priv->item_padding;
2894 cell_area->y = item->box[info->position].y - item->before[info->position];
2895 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2896 cell_area->height = item->box[info->position].height +
2897 item->before[info->position] + item->after[info->position];
2902 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2903 GtkIconViewItem *item,
2904 GtkIconViewCellInfo *info,
2907 g_return_if_fail (info->position < item->n_cells);
2909 *box = item->box[info->position];
2912 /* try to guess a reasonable wrap width for an implicit text cell renderer
2915 adjust_wrap_width (GtkIconView *icon_view,
2916 GtkIconViewItem *item)
2918 GtkIconViewCellInfo *text_info;
2919 GtkIconViewCellInfo *pixbuf_info;
2920 gint pixbuf_width, wrap_width;
2922 if (icon_view->priv->text_cell != -1 &&
2923 icon_view->priv->pixbuf_cell != -1)
2927 text_info = g_list_nth_data (icon_view->priv->cell_list,
2928 icon_view->priv->text_cell);
2929 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2930 icon_view->priv->pixbuf_cell);
2932 gtk_cell_renderer_get_size (pixbuf_info->cell,
2933 GTK_WIDGET (icon_view),
2939 if (icon_view->priv->item_width > 0)
2940 item_width = icon_view->priv->item_width;
2942 item_width = item->width;
2944 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2945 wrap_width = item_width;
2947 if (item->width == -1 && item_width <= 0)
2948 wrap_width = MAX (2 * pixbuf_width, 50);
2950 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2953 wrap_width -= icon_view->priv->item_padding * 2;
2955 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2956 g_object_set (text_info->cell, "width", wrap_width, NULL);
2961 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2962 GtkIconViewItem *item)
2967 if (item->width != -1 && item->height != -1)
2970 if (item->n_cells != icon_view->priv->n_cells)
2972 g_free (item->before);
2973 g_free (item->after);
2976 item->before = g_new0 (gint, icon_view->priv->n_cells);
2977 item->after = g_new0 (gint, icon_view->priv->n_cells);
2978 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2980 item->n_cells = icon_view->priv->n_cells;
2983 gtk_icon_view_set_cell_data (icon_view, item);
2985 spacing = icon_view->priv->spacing;
2989 for (l = icon_view->priv->cell_list; l; l = l->next)
2991 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2993 if (!info->cell->visible)
2996 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2998 &item->box[info->position].width,
2999 &item->box[info->position].height);
3001 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3003 item->width += item->box[info->position].width
3004 + (info->position > 0 ? spacing : 0);
3005 item->height = MAX (item->height, item->box[info->position].height);
3009 item->width = MAX (item->width, item->box[info->position].width);
3010 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3014 item->width += icon_view->priv->item_padding * 2;
3015 item->height += icon_view->priv->item_padding * 2;
3019 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3020 GtkIconViewItem *item,
3023 GdkRectangle cell_area;
3029 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3031 gtk_icon_view_set_cell_data (icon_view, item);
3033 spacing = icon_view->priv->spacing;
3036 for (i = 0; i < icon_view->priv->n_cells; i++)
3038 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3039 item->height = MAX (item->height, max_height[i]);
3041 item->height += max_height[i] + (i > 0 ? spacing : 0);
3044 cell_area.x = item->x + icon_view->priv->item_padding;
3045 cell_area.y = item->y + icon_view->priv->item_padding;
3047 for (k = 0; k < 2; k++)
3048 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3050 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3052 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3055 if (!info->cell->visible)
3058 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3060 /* We should not subtract icon_view->priv->item_padding from item->height,
3061 * because item->height is recalculated above using
3062 * max_height which does not contain item padding.
3064 cell_area.width = item->box[info->position].width;
3065 cell_area.height = item->height;
3069 /* item->width is not recalculated and thus needs to be
3070 * corrected for the padding.
3072 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3073 cell_area.height = max_height[i];
3076 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3078 &item->box[info->position].x, &item->box[info->position].y,
3079 &item->box[info->position].width, &item->box[info->position].height);
3081 item->box[info->position].x += cell_area.x;
3082 item->box[info->position].y += cell_area.y;
3083 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3085 item->before[info->position] = item->box[info->position].x - cell_area.x;
3086 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3087 cell_area.x += cell_area.width + spacing;
3091 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3093 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3094 cell_area.width = item->width;
3096 item->before[info->position] = item->box[info->position].y - cell_area.y;
3097 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3098 cell_area.y += cell_area.height + spacing;
3102 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3104 for (i = 0; i < icon_view->priv->n_cells; i++)
3106 item->box[i].x = item->x + item->width -
3107 (item->box[i].x + item->box[i].width - item->x);
3111 item->height += icon_view->priv->item_padding * 2;
3115 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3117 g_list_foreach (icon_view->priv->items,
3118 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3122 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3129 gtk_icon_view_paint_item (GtkIconView *icon_view,
3131 GtkIconViewItem *item,
3133 GdkDrawable *drawable,
3136 gboolean draw_focus)
3140 GdkRectangle cell_area, box;
3144 GtkCellRendererState flags;
3146 if (icon_view->priv->model == NULL)
3149 gtk_icon_view_set_cell_data (icon_view, item);
3151 gtk_widget_style_get (GTK_WIDGET (icon_view),
3152 "focus-line-width", &focus_width,
3155 padding = focus_width;
3159 flags = GTK_CELL_RENDERER_SELECTED;
3160 if (GTK_WIDGET_HAS_FOCUS (icon_view))
3161 state = GTK_STATE_SELECTED;
3163 state = GTK_STATE_ACTIVE;
3168 state = GTK_STATE_NORMAL;
3171 #ifdef DEBUG_ICON_VIEW
3172 gdk_draw_rectangle (drawable,
3173 GTK_WIDGET (icon_view)->style->black_gc,
3176 item->width, item->height);
3181 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3182 (GdkWindow *) drawable,
3186 GTK_WIDGET (icon_view),
3189 item->width, item->height);
3192 for (l = icon_view->priv->cell_list; l; l = l->next)
3194 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3196 if (!info->cell->visible)
3199 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3201 #ifdef DEBUG_ICON_VIEW
3202 gdk_draw_rectangle (drawable,
3203 GTK_WIDGET (icon_view)->style->black_gc,
3205 x - item->x + cell_area.x,
3206 y - item->y + cell_area.y,
3207 cell_area.width, cell_area.height);
3209 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3211 gdk_draw_rectangle (drawable,
3212 GTK_WIDGET (icon_view)->style->black_gc,
3214 x - item->x + box.x,
3215 y - item->y + box.y,
3216 box.width, box.height);
3219 cell_area.x = x - item->x + cell_area.x;
3220 cell_area.y = y - item->y + cell_area.y;
3222 gtk_cell_renderer_render (info->cell,
3224 GTK_WIDGET (icon_view),
3225 &cell_area, &cell_area, area, flags);
3229 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3230 item == icon_view->priv->cursor_item)
3232 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3234 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3236 if (!info->cell->visible)
3239 /* If found a editable/activatable cell, draw focus on it. */
3240 if (icon_view->priv->cursor_cell < 0 &&
3241 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3242 icon_view->priv->cursor_cell = i;
3244 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3246 if (i == icon_view->priv->cursor_cell)
3248 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3252 GTK_WIDGET (icon_view),
3254 x - item->x + box.x - padding,
3255 y - item->y + box.y - padding,
3256 box.width + 2 * padding,
3257 box.height + 2 * padding);
3262 /* If there are no editable/activatable cells, draw focus
3263 * around the whole item.
3265 if (icon_view->priv->cursor_cell < 0)
3266 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3270 GTK_WIDGET (icon_view),
3274 item->width + 2 * padding,
3275 item->height + 2 * padding);
3280 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3285 GdkRectangle rubber_rect;
3286 GdkColor *fill_color_gdk;
3287 guchar fill_color_alpha;
3289 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3290 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3291 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3292 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3294 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3297 gtk_widget_style_get (GTK_WIDGET (icon_view),
3298 "selection-box-color", &fill_color_gdk,
3299 "selection-box-alpha", &fill_color_alpha,
3302 if (!fill_color_gdk)
3303 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3305 cairo_set_source_rgba (cr,
3306 fill_color_gdk->red / 65535.,
3307 fill_color_gdk->green / 65535.,
3308 fill_color_gdk->blue / 65535.,
3309 fill_color_alpha / 255.);
3312 gdk_cairo_rectangle (cr, &rect);
3316 /* Draw the border without alpha */
3317 cairo_set_source_rgb (cr,
3318 fill_color_gdk->red / 65535.,
3319 fill_color_gdk->green / 65535.,
3320 fill_color_gdk->blue / 65535.);
3321 cairo_rectangle (cr,
3322 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3323 rubber_rect.width - 1, rubber_rect.height - 1);
3327 gdk_color_free (fill_color_gdk);
3331 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3337 index = gtk_tree_path_get_indices (path)[0];
3339 for (l = icon_view->priv->items; l; l = l->next)
3341 GtkIconViewItem *item = l->data;
3343 if (item->index == index)
3345 gtk_icon_view_queue_draw_item (icon_view, item);
3352 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3353 GtkIconViewItem *item)
3358 gtk_widget_style_get (GTK_WIDGET (icon_view),
3359 "focus-line-width", &focus_width,
3362 rect.x = item->x - focus_width;
3363 rect.y = item->y - focus_width;
3364 rect.width = item->width + 2 * focus_width;
3365 rect.height = item->height + 2 * focus_width;
3367 if (icon_view->priv->bin_window)
3368 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3372 layout_callback (gpointer user_data)
3374 GtkIconView *icon_view;
3376 icon_view = GTK_ICON_VIEW (user_data);
3378 icon_view->priv->layout_idle_id = 0;
3380 gtk_icon_view_layout (icon_view);
3386 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3388 if (icon_view->priv->layout_idle_id != 0)
3391 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3395 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3396 GtkIconViewItem *item,
3400 AtkObject *item_obj;
3401 AtkObject *cursor_item_obj;
3403 if (icon_view->priv->cursor_item == item &&
3404 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3407 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3408 if (icon_view->priv->cursor_item != NULL)
3410 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3413 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3414 if (cursor_item_obj != NULL)
3415 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3418 icon_view->priv->cursor_item = item;
3419 if (cursor_cell >= 0)
3420 icon_view->priv->cursor_cell = cursor_cell;
3422 gtk_icon_view_queue_draw_item (icon_view, item);
3424 /* Notify that accessible focus object has changed */
3425 item_obj = atk_object_ref_accessible_child (obj, item->index);
3427 if (item_obj != NULL)
3429 atk_focus_tracker_notify (item_obj);
3430 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3431 g_object_unref (item_obj);
3436 static GtkIconViewItem *
3437 gtk_icon_view_item_new (void)
3439 GtkIconViewItem *item;
3441 item = g_new0 (GtkIconViewItem, 1);
3450 gtk_icon_view_item_free (GtkIconViewItem *item)
3452 g_return_if_fail (item != NULL);
3454 g_free (item->before);
3455 g_free (item->after);
3462 static GtkIconViewItem *
3463 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3466 gboolean only_in_cell,
3467 GtkIconViewCellInfo **cell_at_pos)
3472 for (items = icon_view->priv->items; items; items = items->next)
3474 GtkIconViewItem *item = items->data;
3476 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3477 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3479 if (only_in_cell || cell_at_pos)
3481 gtk_icon_view_set_cell_data (icon_view, item);
3483 for (l = icon_view->priv->cell_list; l; l = l->next)
3485 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3487 if (!info->cell->visible)
3490 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3492 if ((x >= box.x && x <= box.x + box.width &&
3493 y >= box.y && y <= box.y + box.height) ||
3495 x <= box.x + box.width &&
3497 y <= box.y + box.height))
3500 *cell_at_pos = info;
3507 *cell_at_pos = NULL;
3521 gtk_icon_view_select_item (GtkIconView *icon_view,
3522 GtkIconViewItem *item)
3524 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3525 g_return_if_fail (item != NULL);
3530 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3532 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3533 gtk_icon_view_unselect_all_internal (icon_view);
3535 item->selected = TRUE;
3537 gtk_icon_view_item_selected_changed (icon_view, item);
3538 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3540 gtk_icon_view_queue_draw_item (icon_view, item);
3545 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3546 GtkIconViewItem *item)
3548 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3549 g_return_if_fail (item != NULL);
3551 if (!item->selected)
3554 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3555 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3558 item->selected = FALSE;
3560 gtk_icon_view_item_selected_changed (icon_view, item);
3561 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3563 gtk_icon_view_queue_draw_item (icon_view, item);
3567 verify_items (GtkIconView *icon_view)
3572 for (items = icon_view->priv->items; items; items = items->next)
3574 GtkIconViewItem *item = items->data;
3576 if (item->index != i)
3577 g_error ("List item does not match its index: "
3578 "item index %d and list index %d\n", item->index, i);
3585 gtk_icon_view_row_changed (GtkTreeModel *model,
3590 GtkIconViewItem *item;
3592 GtkIconView *icon_view;
3594 icon_view = GTK_ICON_VIEW (data);
3596 gtk_icon_view_stop_editing (icon_view, TRUE);
3598 index = gtk_tree_path_get_indices(path)[0];
3599 item = g_list_nth_data (icon_view->priv->items, index);
3601 gtk_icon_view_item_invalidate_size (item);
3602 gtk_icon_view_queue_layout (icon_view);
3604 verify_items (icon_view);
3608 gtk_icon_view_row_inserted (GtkTreeModel *model,
3614 GtkIconViewItem *item;
3615 gboolean iters_persist;
3616 GtkIconView *icon_view;
3619 icon_view = GTK_ICON_VIEW (data);
3621 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3623 index = gtk_tree_path_get_indices(path)[0];
3625 item = gtk_icon_view_item_new ();
3630 item->index = index;
3632 /* FIXME: We can be more efficient here,
3633 we can store a tail pointer and use that when
3634 appending (which is a rather common operation)
3636 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3639 list = g_list_nth (icon_view->priv->items, index + 1);
3640 for (; list; list = list->next)
3647 verify_items (icon_view);
3649 gtk_icon_view_queue_layout (icon_view);
3653 gtk_icon_view_row_deleted (GtkTreeModel *model,
3658 GtkIconView *icon_view;
3659 GtkIconViewItem *item;
3661 gboolean emit = FALSE;
3663 icon_view = GTK_ICON_VIEW (data);
3665 index = gtk_tree_path_get_indices(path)[0];
3667 list = g_list_nth (icon_view->priv->items, index);
3670 gtk_icon_view_stop_editing (icon_view, TRUE);
3672 if (item == icon_view->priv->anchor_item)
3673 icon_view->priv->anchor_item = NULL;
3675 if (item == icon_view->priv->cursor_item)
3676 icon_view->priv->cursor_item = NULL;
3681 gtk_icon_view_item_free (item);
3683 for (next = list->next; next; next = next->next)
3690 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3692 verify_items (icon_view);
3694 gtk_icon_view_queue_layout (icon_view);
3697 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3701 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3702 GtkTreePath *parent,
3709 GtkIconView *icon_view;
3710 GList *items = NULL, *list;
3711 GtkIconViewItem **item_array;
3714 icon_view = GTK_ICON_VIEW (data);
3716 gtk_icon_view_stop_editing (icon_view, TRUE);
3718 length = gtk_tree_model_iter_n_children (model, NULL);
3720 order = g_new (gint, length);
3721 for (i = 0; i < length; i++)
3722 order [new_order[i]] = i;
3724 item_array = g_new (GtkIconViewItem *, length);
3725 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3726 item_array[order[i]] = list->data;
3729 for (i = length - 1; i >= 0; i--)
3731 item_array[i]->index = i;
3732 items = g_list_prepend (items, item_array[i]);
3735 g_free (item_array);
3736 g_list_free (icon_view->priv->items);
3737 icon_view->priv->items = items;
3739 gtk_icon_view_queue_layout (icon_view);
3741 verify_items (icon_view);
3745 gtk_icon_view_build_items (GtkIconView *icon_view)
3749 gboolean iters_persist;
3750 GList *items = NULL;
3752 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3754 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3762 GtkIconViewItem *item = gtk_icon_view_item_new ();
3771 items = g_list_prepend (items, item);
3773 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3775 icon_view->priv->items = g_list_reverse (items);
3779 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3782 GtkMovementStep step,
3786 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3787 I_("move-cursor"), 2,
3791 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3796 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3799 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3804 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3811 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3812 GtkMovementStep step,
3815 GdkModifierType state;
3817 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3818 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3819 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3820 step == GTK_MOVEMENT_DISPLAY_LINES ||
3821 step == GTK_MOVEMENT_PAGES ||
3822 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3824 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3827 gtk_icon_view_stop_editing (icon_view, FALSE);
3828 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3830 if (gtk_get_current_event_state (&state))
3832 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3833 icon_view->priv->ctrl_pressed = TRUE;
3834 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3835 icon_view->priv->shift_pressed = TRUE;
3837 /* else we assume not pressed */
3841 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3842 case GTK_MOVEMENT_VISUAL_POSITIONS:
3843 gtk_icon_view_move_cursor_left_right (icon_view, count);
3845 case GTK_MOVEMENT_DISPLAY_LINES:
3846 gtk_icon_view_move_cursor_up_down (icon_view, count);
3848 case GTK_MOVEMENT_PAGES:
3849 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3851 case GTK_MOVEMENT_BUFFER_ENDS:
3852 gtk_icon_view_move_cursor_start_end (icon_view, count);
3855 g_assert_not_reached ();
3858 icon_view->priv->ctrl_pressed = FALSE;
3859 icon_view->priv->shift_pressed = FALSE;
3861 icon_view->priv->draw_focus = TRUE;
3866 static GtkIconViewItem *
3867 find_item (GtkIconView *icon_view,
3868 GtkIconViewItem *current,
3874 GtkIconViewItem *item;
3876 /* FIXME: this could be more efficient
3878 row = current->row + row_ofs;
3879 col = current->col + col_ofs;
3881 for (items = icon_view->priv->items; items; items = items->next)
3884 if (item->row == row && item->col == col)
3892 find_cell (GtkIconView *icon_view,
3893 GtkIconViewItem *item,
3895 GtkOrientation orientation,
3905 if (icon_view->priv->orientation != orientation)
3908 gtk_icon_view_set_cell_data (icon_view, item);
3910 focusable = g_new0 (gint, icon_view->priv->n_cells);
3914 for (k = 0; k < 2; k++)
3915 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3917 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3919 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3922 if (!info->cell->visible)
3925 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3928 current = n_focusable;
3930 focusable[n_focusable] = i;
3936 if (n_focusable == 0)
3944 current = step > 0 ? 0 : n_focusable - 1;
3945 cell = focusable[current];
3948 if (current + *count < 0)
3951 *count = current + *count;
3953 else if (current + *count > n_focusable - 1)
3956 *count = current + *count - (n_focusable - 1);
3960 cell = focusable[current + *count];
3969 static GtkIconViewItem *
3970 find_item_page_up_down (GtkIconView *icon_view,
3971 GtkIconViewItem *current,
3978 y = current->y + count * icon_view->priv->vadjustment->page_size;
3980 item = g_list_find (icon_view->priv->items, current);
3985 for (next = item->next; next; next = next->next)
3987 if (((GtkIconViewItem *)next->data)->col == col)
3990 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4000 for (next = item->prev; next; next = next->prev)
4002 if (((GtkIconViewItem *)next->data)->col == col)
4005 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4019 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4020 GtkIconViewItem *anchor,
4021 GtkIconViewItem *cursor)
4024 GtkIconViewItem *item;
4025 gint row1, row2, col1, col2;
4026 gboolean dirty = FALSE;
4028 if (anchor->row < cursor->row)
4039 if (anchor->col < cursor->col)
4050 for (items = icon_view->priv->items; items; items = items->next)
4054 if (row1 <= item->row && item->row <= row2 &&
4055 col1 <= item->col && item->col <= col2)
4057 if (!item->selected)
4060 item->selected = TRUE;
4061 gtk_icon_view_item_selected_changed (icon_view, item);
4063 gtk_icon_view_queue_draw_item (icon_view, item);
4071 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4074 GtkIconViewItem *item;
4076 gboolean dirty = FALSE;
4079 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4082 if (!icon_view->priv->cursor_item)
4087 list = icon_view->priv->items;
4089 list = g_list_last (icon_view->priv->items);
4091 item = list ? list->data : NULL;
4096 item = icon_view->priv->cursor_item;
4097 cell = icon_view->priv->cursor_cell;
4098 step = count > 0 ? 1 : -1;
4101 cell = find_cell (icon_view, item, cell,
4102 GTK_ORIENTATION_VERTICAL,
4107 item = find_item (icon_view, item, step, 0);
4108 count = count - step;
4114 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4118 if (icon_view->priv->ctrl_pressed ||
4119 !icon_view->priv->shift_pressed ||
4120 !icon_view->priv->anchor_item ||
4121 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4122 icon_view->priv->anchor_item = item;
4124 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4126 if (!icon_view->priv->ctrl_pressed &&
4127 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4129 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4130 dirty = gtk_icon_view_select_all_between (icon_view,
4131 icon_view->priv->anchor_item,
4135 gtk_icon_view_scroll_to_item (icon_view, item);
4138 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4142 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4145 GtkIconViewItem *item;
4146 gboolean dirty = FALSE;
4148 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4151 if (!icon_view->priv->cursor_item)
4156 list = icon_view->priv->items;
4158 list = g_list_last (icon_view->priv->items);
4160 item = list ? list->data : NULL;
4163 item = find_item_page_up_down (icon_view,
4164 icon_view->priv->cursor_item,
4167 if (item == icon_view->priv->cursor_item)
4168 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4173 if (icon_view->priv->ctrl_pressed ||
4174 !icon_view->priv->shift_pressed ||
4175 !icon_view->priv->anchor_item ||
4176 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4177 icon_view->priv->anchor_item = item;
4179 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4181 if (!icon_view->priv->ctrl_pressed &&
4182 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4184 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4185 dirty = gtk_icon_view_select_all_between (icon_view,
4186 icon_view->priv->anchor_item,
4190 gtk_icon_view_scroll_to_item (icon_view, item);
4193 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4197 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4200 GtkIconViewItem *item;
4202 gboolean dirty = FALSE;
4205 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4208 if (!icon_view->priv->cursor_item)
4213 list = icon_view->priv->items;
4215 list = g_list_last (icon_view->priv->items);
4217 item = list ? list->data : NULL;
4221 item = icon_view->priv->cursor_item;
4222 cell = icon_view->priv->cursor_cell;
4223 step = count > 0 ? 1 : -1;
4226 cell = find_cell (icon_view, item, cell,
4227 GTK_ORIENTATION_HORIZONTAL,
4232 item = find_item (icon_view, item, 0, step);
4233 count = count - step;
4239 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4243 if (icon_view->priv->ctrl_pressed ||
4244 !icon_view->priv->shift_pressed ||
4245 !icon_view->priv->anchor_item ||
4246 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4247 icon_view->priv->anchor_item = item;
4249 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4251 if (!icon_view->priv->ctrl_pressed &&
4252 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4254 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4255 dirty = gtk_icon_view_select_all_between (icon_view,
4256 icon_view->priv->anchor_item,
4260 gtk_icon_view_scroll_to_item (icon_view, item);
4263 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4267 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4270 GtkIconViewItem *item;
4272 gboolean dirty = FALSE;
4274 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4278 list = icon_view->priv->items;
4280 list = g_list_last (icon_view->priv->items);
4282 item = list ? list->data : NULL;
4284 if (item == icon_view->priv->cursor_item)
4285 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4290 if (icon_view->priv->ctrl_pressed ||
4291 !icon_view->priv->shift_pressed ||
4292 !icon_view->priv->anchor_item ||
4293 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4294 icon_view->priv->anchor_item = item;
4296 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4298 if (!icon_view->priv->ctrl_pressed &&
4299 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4301 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4302 dirty = gtk_icon_view_select_all_between (icon_view,
4303 icon_view->priv->anchor_item,
4307 gtk_icon_view_scroll_to_item (icon_view, item);
4310 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4314 * gtk_icon_view_scroll_to_path:
4315 * @icon_view: A #GtkIconView.
4316 * @path: The path of the item to move to.
4317 * @use_align: whether to use alignment arguments, or %FALSE.
4318 * @row_align: The vertical alignment of the item specified by @path.
4319 * @col_align: The horizontal alignment of the item specified by @path.
4321 * Moves the alignments of @icon_view to the position specified by @path.
4322 * @row_align determines where the row is placed, and @col_align determines
4323 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4324 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4327 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4328 * tree does the minimum amount of work to scroll the item onto the screen.
4329 * This means that the item will be scrolled to the edge closest to its current
4330 * position. If the item is currently visible on the screen, nothing is done.
4332 * This function only works if the model is set, and @path is a valid row on
4333 * the model. If the model changes before the @icon_view is realized, the
4334 * centered path will be modified to reflect this change.
4339 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4345 GtkIconViewItem *item = NULL;
4347 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4348 g_return_if_fail (path != NULL);
4349 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4350 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4352 if (gtk_tree_path_get_depth (path) > 0)
4353 item = g_list_nth_data (icon_view->priv->items,
4354 gtk_tree_path_get_indices(path)[0]);
4356 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4358 if (icon_view->priv->scroll_to_path)
4359 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4361 icon_view->priv->scroll_to_path = NULL;
4364 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4366 icon_view->priv->scroll_to_use_align = use_align;
4367 icon_view->priv->scroll_to_row_align = row_align;
4368 icon_view->priv->scroll_to_col_align = col_align;
4377 gfloat offset, value;
4379 gtk_widget_style_get (GTK_WIDGET (icon_view),
4380 "focus-line-width", &focus_width,
4383 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4385 offset = y + item->y - focus_width -
4386 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4387 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4388 icon_view->priv->vadjustment->lower,
4389 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4390 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4392 offset = x + item->x - focus_width -
4393 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4394 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4395 icon_view->priv->hadjustment->lower,
4396 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4397 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4399 gtk_adjustment_changed (icon_view->priv->hadjustment);
4400 gtk_adjustment_changed (icon_view->priv->vadjustment);
4403 gtk_icon_view_scroll_to_item (icon_view, item);
4408 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4409 GtkIconViewItem *item)
4411 gint x, y, width, height;
4414 gtk_widget_style_get (GTK_WIDGET (icon_view),
4415 "focus-line-width", &focus_width,
4418 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4420 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4422 if (y + item->y - focus_width < 0)
4423 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4424 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4425 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4426 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4427 icon_view->priv->vadjustment->value + y + item->y + item->height
4428 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4430 if (x + item->x - focus_width < 0)
4431 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4432 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4433 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4434 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4435 icon_view->priv->hadjustment->value + x + item->x + item->width
4436 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4438 gtk_adjustment_changed (icon_view->priv->hadjustment);
4439 gtk_adjustment_changed (icon_view->priv->vadjustment);
4442 /* GtkCellLayout implementation */
4443 static GtkIconViewCellInfo *
4444 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4445 GtkCellRenderer *renderer)
4449 for (i = icon_view->priv->cell_list; i; i = i->next)
4451 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4453 if (info->cell == renderer)
4461 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4462 GtkIconViewItem *item)
4465 gboolean iters_persist;
4468 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4474 path = gtk_tree_path_new_from_indices (item->index, -1);
4475 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4477 gtk_tree_path_free (path);
4482 for (i = icon_view->priv->cell_list; i; i = i->next)
4485 GtkIconViewCellInfo *info = i->data;
4487 g_object_freeze_notify (G_OBJECT (info->cell));
4489 for (j = info->attributes; j && j->next; j = j->next->next)
4491 gchar *property = j->data;
4492 gint column = GPOINTER_TO_INT (j->next->data);
4493 GValue value = {0, };
4495 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4497 g_object_set_property (G_OBJECT (info->cell),
4499 g_value_unset (&value);
4503 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4505 icon_view->priv->model,
4509 g_object_thaw_notify (G_OBJECT (info->cell));
4514 free_cell_attributes (GtkIconViewCellInfo *info)
4518 list = info->attributes;
4519 while (list && list->next)
4521 g_free (list->data);
4522 list = list->next->next;
4525 g_slist_free (info->attributes);
4526 info->attributes = NULL;
4530 free_cell_info (GtkIconViewCellInfo *info)
4532 free_cell_attributes (info);
4534 g_object_unref (info->cell);
4537 (* info->destroy) (info->func_data);
4543 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4544 GtkCellRenderer *renderer,
4547 GtkIconViewCellInfo *info;
4548 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4550 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4551 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4553 g_object_ref_sink (renderer);
4555 info = g_new0 (GtkIconViewCellInfo, 1);
4556 info->cell = renderer;
4557 info->expand = expand ? TRUE : FALSE;
4558 info->pack = GTK_PACK_START;
4559 info->position = icon_view->priv->n_cells;
4561 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4562 icon_view->priv->n_cells++;
4566 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4567 GtkCellRenderer *renderer,
4570 GtkIconViewCellInfo *info;
4571 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4573 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4574 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4576 g_object_ref_sink (renderer);
4578 info = g_new0 (GtkIconViewCellInfo, 1);
4579 info->cell = renderer;
4580 info->expand = expand ? TRUE : FALSE;
4581 info->pack = GTK_PACK_END;
4582 info->position = icon_view->priv->n_cells;
4584 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4585 icon_view->priv->n_cells++;
4589 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4590 GtkCellRenderer *renderer,
4591 const gchar *attribute,
4594 GtkIconViewCellInfo *info;
4595 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4597 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4598 g_return_if_fail (info != NULL);
4600 info->attributes = g_slist_prepend (info->attributes,
4601 GINT_TO_POINTER (column));
4602 info->attributes = g_slist_prepend (info->attributes,
4603 g_strdup (attribute));
4607 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4609 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4611 while (icon_view->priv->cell_list)
4613 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4614 free_cell_info (info);
4615 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4616 icon_view->priv->cell_list);
4619 icon_view->priv->n_cells = 0;
4623 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4624 GtkCellRenderer *cell,
4625 GtkCellLayoutDataFunc func,
4627 GDestroyNotify destroy)
4629 GtkIconViewCellInfo *info;
4630 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4632 info = gtk_icon_view_get_cell_info (icon_view, cell);
4633 g_return_if_fail (info != NULL);
4637 GDestroyNotify d = info->destroy;
4639 info->destroy = NULL;
4640 d (info->func_data);
4644 info->func_data = func_data;
4645 info->destroy = destroy;
4649 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4650 GtkCellRenderer *renderer)
4652 GtkIconViewCellInfo *info;
4654 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4656 free_cell_attributes (info);
4660 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4661 GtkCellRenderer *cell,
4664 GtkIconView *icon_view;
4666 GtkIconViewCellInfo *info;
4669 icon_view = GTK_ICON_VIEW (layout);
4671 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4673 info = gtk_icon_view_get_cell_info (icon_view, cell);
4675 g_return_if_fail (info != NULL);
4676 g_return_if_fail (position >= 0);
4678 link = g_list_find (icon_view->priv->cell_list, info);
4680 g_return_if_fail (link != NULL);
4682 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4684 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4687 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4694 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4698 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4700 GtkIconView *icon_view = (GtkIconView *)layout;
4701 GList *retval = NULL, *l;
4703 for (l = icon_view->priv->cell_list; l; l = l->next)
4705 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4707 retval = g_list_prepend (retval, info->cell);
4710 return g_list_reverse (retval);
4717 * gtk_icon_view_new:
4719 * Creates a new #GtkIconView widget
4721 * Return value: A newly created #GtkIconView widget
4726 gtk_icon_view_new (void)
4728 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4732 * gtk_icon_view_new_with_model:
4733 * @model: The model.
4735 * Creates a new #GtkIconView widget with the model @model.
4737 * Return value: A newly created #GtkIconView widget.
4742 gtk_icon_view_new_with_model (GtkTreeModel *model)
4744 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4748 * gtk_icon_view_convert_widget_to_bin_window_coords:
4749 * @icon_view: a #GtkIconView
4750 * @wx: X coordinate relative to the widget
4751 * @wy: Y coordinate relative to the widget
4752 * @bx: return location for bin_window X coordinate
4753 * @by: return location for bin_window Y coordinate
4755 * Converts widget coordinates to coordinates for the bin_window,
4756 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4761 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4769 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4771 if (icon_view->priv->bin_window)
4772 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4783 * gtk_icon_view_get_path_at_pos:
4784 * @icon_view: A #GtkIconView.
4785 * @x: The x position to be identified
4786 * @y: The y position to be identified
4788 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4789 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4790 * the cell at the specified position.
4791 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4792 * widget coordinates to bin_window coordinates.
4794 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4795 * if no icon exists at that position.
4800 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4804 GtkIconViewItem *item;
4807 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4809 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4814 path = gtk_tree_path_new_from_indices (item->index, -1);
4820 * gtk_icon_view_get_item_at_pos:
4821 * @icon_view: A #GtkIconView.
4822 * @x: The x position to be identified
4823 * @y: The y position to be identified
4824 * @path: Return location for the path, or %NULL
4825 * @cell: Return location for the renderer responsible for the cell
4826 * at (@x, @y), or %NULL
4828 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4829 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4830 * obtains the cell at the specified position. The returned path should
4831 * be freed with gtk_tree_path_free().
4832 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4833 * widget coordinates to bin_window coordinates.
4835 * Return value: %TRUE if an item exists at the specified position
4840 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4844 GtkCellRenderer **cell)
4846 GtkIconViewItem *item;
4847 GtkIconViewCellInfo *info;
4849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4851 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4856 *path = gtk_tree_path_new_from_indices (item->index, -1);
4869 return (item != NULL);
4873 * gtk_icon_view_set_tooltip_item:
4874 * @icon_view: a #GtkIconView
4875 * @tooltip: a #GtkTooltip
4876 * @path: a #GtkTreePath
4878 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4879 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4880 * See also gtk_tooltip_set_tip_area().
4885 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4886 GtkTooltip *tooltip,
4889 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4890 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4892 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4896 * gtk_icon_view_set_tooltip_cell:
4897 * @icon_view: a #GtkIconView
4898 * @tooltip: a #GtkTooltip
4899 * @path: a #GtkTreePath
4900 * @cell: a #GtkCellRenderer or %NULL
4902 * Sets the tip area of @tooltip to the area which @cell occupies in
4903 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4905 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4910 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4911 GtkTooltip *tooltip,
4913 GtkCellRenderer *cell)
4916 GtkIconViewItem *item = NULL;
4917 GtkIconViewCellInfo *info = NULL;
4920 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4921 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4922 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4924 if (gtk_tree_path_get_depth (path) > 0)
4925 item = g_list_nth_data (icon_view->priv->items,
4926 gtk_tree_path_get_indices(path)[0]);
4933 info = gtk_icon_view_get_cell_info (icon_view, cell);
4934 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4940 rect.width = item->width;
4941 rect.height = item->height;
4944 if (icon_view->priv->bin_window)
4946 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4951 gtk_tooltip_set_tip_area (tooltip, &rect);
4956 * gtk_icon_view_get_tooltip_context:
4957 * @icon_view: an #GtkIconView
4958 * @x: the x coordinate (relative to widget coordinates)
4959 * @y: the y coordinate (relative to widget coordinates)
4960 * @keyboard_tip: whether this is a keyboard tooltip or not
4961 * @model: a pointer to receive a #GtkTreeModel or %NULL
4962 * @path: a pointer to receive a #GtkTreePath or %NULL
4963 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4965 * This function is supposed to be used in a #GtkWidget::query-tooltip
4966 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4967 * which are received in the signal handler, should be passed to this
4968 * function without modification.
4970 * The return value indicates whether there is an icon view item at the given
4971 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4972 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4973 * @model, @path and @iter which have been provided will be set to point to
4974 * that row and the corresponding model. @x and @y will always be converted
4975 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4977 * Return value: whether or not the given tooltip context points to a item
4982 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4985 gboolean keyboard_tip,
4986 GtkTreeModel **model,
4990 GtkTreePath *tmppath = NULL;
4992 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4993 g_return_val_if_fail (x != NULL, FALSE);
4994 g_return_val_if_fail (y != NULL, FALSE);
4998 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5005 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5008 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5013 *model = gtk_icon_view_get_model (icon_view);
5016 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5022 gtk_tree_path_free (tmppath);
5028 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5031 gboolean keyboard_tip,
5032 GtkTooltip *tooltip,
5038 GtkTreeModel *model;
5039 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5041 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5044 &model, &path, &iter))
5047 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5051 gtk_tree_path_free (path);
5055 gtk_tooltip_set_markup (tooltip, str);
5056 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5058 gtk_tree_path_free (path);
5066 * gtk_icon_view_set_tooltip_column:
5067 * @icon_view: a #GtkIconView
5068 * @column: an integer, which is a valid column number for @icon_view's model
5070 * If you only plan to have simple (text-only) tooltips on full items, you
5071 * can use this function to have #GtkIconView handle these automatically
5072 * for you. @column should be set to the column in @icon_view's model
5073 * containing the tooltip texts, or -1 to disable this feature.
5075 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5076 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5081 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5084 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5086 if (column == icon_view->priv->tooltip_column)
5091 g_signal_handlers_disconnect_by_func (icon_view,
5092 gtk_icon_view_set_tooltip_query_cb,
5094 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5098 if (icon_view->priv->tooltip_column == -1)
5100 g_signal_connect (icon_view, "query-tooltip",
5101 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5102 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5106 icon_view->priv->tooltip_column = column;
5107 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5111 * gtk_icon_view_get_tooltip_column:
5112 * @icon_view: a #GtkIconView
5114 * Returns the column of @icon_view's model which is being used for
5115 * displaying tooltips on @icon_view's rows.
5117 * Return value: the index of the tooltip column that is currently being
5118 * used, or -1 if this is disabled.
5123 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5125 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5127 return icon_view->priv->tooltip_column;
5131 * gtk_icon_view_get_visible_range:
5132 * @icon_view: A #GtkIconView
5133 * @start_path: Return location for start of region, or %NULL
5134 * @end_path: Return location for end of region, or %NULL
5136 * Sets @start_path and @end_path to be the first and last visible path.
5137 * Note that there may be invisible paths in between.
5139 * Both paths should be freed with gtk_tree_path_free() after use.
5141 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5146 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5147 GtkTreePath **start_path,
5148 GtkTreePath **end_path)
5150 gint start_index = -1;
5151 gint end_index = -1;
5154 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5156 if (icon_view->priv->hadjustment == NULL ||
5157 icon_view->priv->vadjustment == NULL)
5160 if (start_path == NULL && end_path == NULL)
5163 for (icons = icon_view->priv->items; icons; icons = icons->next)
5165 GtkIconViewItem *item = icons->data;
5167 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5168 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5169 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5170 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5172 if (start_index == -1)
5173 start_index = item->index;
5174 end_index = item->index;
5178 if (start_path && start_index != -1)
5179 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5180 if (end_path && end_index != -1)
5181 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5183 return start_index != -1;
5187 * gtk_icon_view_selected_foreach:
5188 * @icon_view: A #GtkIconView.
5189 * @func: The funcion to call for each selected icon.
5190 * @data: User data to pass to the function.
5192 * Calls a function for each selected icon. Note that the model or
5193 * selection cannot be modified from within this function.
5198 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5199 GtkIconViewForeachFunc func,
5204 for (list = icon_view->priv->items; list; list = list->next)
5206 GtkIconViewItem *item = list->data;
5207 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5210 (* func) (icon_view, path, data);
5212 gtk_tree_path_free (path);
5217 * gtk_icon_view_set_selection_mode:
5218 * @icon_view: A #GtkIconView.
5219 * @mode: The selection mode
5221 * Sets the selection mode of the @icon_view.
5226 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5227 GtkSelectionMode mode)
5229 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5231 if (mode == icon_view->priv->selection_mode)
5234 if (mode == GTK_SELECTION_NONE ||
5235 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5236 gtk_icon_view_unselect_all (icon_view);
5238 icon_view->priv->selection_mode = mode;
5240 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5244 * gtk_icon_view_get_selection_mode:
5245 * @icon_view: A #GtkIconView.
5247 * Gets the selection mode of the @icon_view.
5249 * Return value: the current selection mode
5254 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5256 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5258 return icon_view->priv->selection_mode;
5262 * gtk_icon_view_set_model:
5263 * @icon_view: A #GtkIconView.
5264 * @model: The model.
5266 * Sets the model for a #GtkIconView.
5267 * If the @icon_view already has a model set, it will remove
5268 * it before setting the new model. If @model is %NULL, then
5269 * it will unset the old model.
5274 gtk_icon_view_set_model (GtkIconView *icon_view,
5275 GtkTreeModel *model)
5277 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5278 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5280 if (icon_view->priv->model == model)
5283 if (icon_view->priv->scroll_to_path)
5285 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5286 icon_view->priv->scroll_to_path = NULL;
5289 gtk_icon_view_stop_editing (icon_view, TRUE);
5295 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5297 if (icon_view->priv->pixbuf_column != -1)
5299 column_type = gtk_tree_model_get_column_type (model,
5300 icon_view->priv->pixbuf_column);
5302 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5305 if (icon_view->priv->text_column != -1)
5307 column_type = gtk_tree_model_get_column_type (model,
5308 icon_view->priv->text_column);
5310 g_return_if_fail (column_type == G_TYPE_STRING);
5313 if (icon_view->priv->markup_column != -1)
5315 column_type = gtk_tree_model_get_column_type (model,
5316 icon_view->priv->markup_column);
5318 g_return_if_fail (column_type == G_TYPE_STRING);
5323 if (icon_view->priv->model)
5325 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5326 gtk_icon_view_row_changed,
5328 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5329 gtk_icon_view_row_inserted,
5331 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5332 gtk_icon_view_row_deleted,
5334 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5335 gtk_icon_view_rows_reordered,
5338 g_object_unref (icon_view->priv->model);
5340 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5341 g_list_free (icon_view->priv->items);
5342 icon_view->priv->items = NULL;
5343 icon_view->priv->anchor_item = NULL;
5344 icon_view->priv->cursor_item = NULL;
5345 icon_view->priv->last_single_clicked = NULL;
5346 icon_view->priv->width = 0;
5347 icon_view->priv->height = 0;
5350 icon_view->priv->model = model;
5352 if (icon_view->priv->model)
5354 g_object_ref (icon_view->priv->model);
5355 g_signal_connect (icon_view->priv->model,
5357 G_CALLBACK (gtk_icon_view_row_changed),
5359 g_signal_connect (icon_view->priv->model,
5361 G_CALLBACK (gtk_icon_view_row_inserted),
5363 g_signal_connect (icon_view->priv->model,
5365 G_CALLBACK (gtk_icon_view_row_deleted),
5367 g_signal_connect (icon_view->priv->model,
5369 G_CALLBACK (gtk_icon_view_rows_reordered),
5372 gtk_icon_view_build_items (icon_view);
5374 gtk_icon_view_queue_layout (icon_view);
5377 g_object_notify (G_OBJECT (icon_view), "model");
5379 if (GTK_WIDGET_REALIZED (icon_view))
5380 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5384 * gtk_icon_view_get_model:
5385 * @icon_view: a #GtkIconView
5387 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5390 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5395 gtk_icon_view_get_model (GtkIconView *icon_view)
5397 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5399 return icon_view->priv->model;
5403 update_text_cell (GtkIconView *icon_view)
5405 GtkIconViewCellInfo *info;
5409 if (icon_view->priv->text_column == -1 &&
5410 icon_view->priv->markup_column == -1)
5412 if (icon_view->priv->text_cell != -1)
5414 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5415 icon_view->priv->pixbuf_cell--;
5417 info = g_list_nth_data (icon_view->priv->cell_list,
5418 icon_view->priv->text_cell);
5420 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5422 free_cell_info (info);
5424 icon_view->priv->n_cells--;
5425 icon_view->priv->text_cell = -1;
5430 if (icon_view->priv->text_cell == -1)
5432 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5433 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5434 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5437 if (info->cell == cell)
5439 icon_view->priv->text_cell = i;
5445 info = g_list_nth_data (icon_view->priv->cell_list,
5446 icon_view->priv->text_cell);
5448 if (icon_view->priv->markup_column != -1)
5449 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5451 "markup", icon_view->priv->markup_column,
5454 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5456 "text", icon_view->priv->text_column,
5459 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5460 g_object_set (info->cell,
5461 "alignment", PANGO_ALIGN_CENTER,
5462 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5467 g_object_set (info->cell,
5468 "alignment", PANGO_ALIGN_LEFT,
5469 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5477 update_pixbuf_cell (GtkIconView *icon_view)
5479 GtkIconViewCellInfo *info;
5483 if (icon_view->priv->pixbuf_column == -1)
5485 if (icon_view->priv->pixbuf_cell != -1)
5487 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5488 icon_view->priv->text_cell--;
5490 info = g_list_nth_data (icon_view->priv->cell_list,
5491 icon_view->priv->pixbuf_cell);
5493 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5495 free_cell_info (info);
5497 icon_view->priv->n_cells--;
5498 icon_view->priv->pixbuf_cell = -1;
5503 if (icon_view->priv->pixbuf_cell == -1)
5505 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5507 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5508 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5511 if (info->cell == cell)
5513 icon_view->priv->pixbuf_cell = i;
5519 info = g_list_nth_data (icon_view->priv->cell_list,
5520 icon_view->priv->pixbuf_cell);
5522 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5524 "pixbuf", icon_view->priv->pixbuf_column,
5527 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5528 g_object_set (info->cell,
5533 g_object_set (info->cell,
5541 * gtk_icon_view_set_text_column:
5542 * @icon_view: A #GtkIconView.
5543 * @column: A column in the currently used model, or -1 to display no text
5545 * Sets the column with text for @icon_view to be @column. The text
5546 * column must be of type #G_TYPE_STRING.
5551 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5554 if (column == icon_view->priv->text_column)
5558 icon_view->priv->text_column = -1;
5561 if (icon_view->priv->model != NULL)
5565 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5567 g_return_if_fail (column_type == G_TYPE_STRING);
5570 icon_view->priv->text_column = column;
5573 gtk_icon_view_stop_editing (icon_view, TRUE);
5575 update_text_cell (icon_view);
5577 gtk_icon_view_invalidate_sizes (icon_view);
5578 gtk_icon_view_queue_layout (icon_view);
5580 g_object_notify (G_OBJECT (icon_view), "text-column");
5584 * gtk_icon_view_get_text_column:
5585 * @icon_view: A #GtkIconView.
5587 * Returns the column with text for @icon_view.
5589 * Returns: the text column, or -1 if it's unset.
5594 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5596 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5598 return icon_view->priv->text_column;
5602 * gtk_icon_view_set_markup_column:
5603 * @icon_view: A #GtkIconView.
5604 * @column: A column in the currently used model, or -1 to display no text
5606 * Sets the column with markup information for @icon_view to be
5607 * @column. The markup column must be of type #G_TYPE_STRING.
5608 * If the markup column is set to something, it overrides
5609 * the text column set by gtk_icon_view_set_text_column().
5614 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5617 if (column == icon_view->priv->markup_column)
5621 icon_view->priv->markup_column = -1;
5624 if (icon_view->priv->model != NULL)
5628 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5630 g_return_if_fail (column_type == G_TYPE_STRING);
5633 icon_view->priv->markup_column = column;
5636 gtk_icon_view_stop_editing (icon_view, TRUE);
5638 update_text_cell (icon_view);
5640 gtk_icon_view_invalidate_sizes (icon_view);
5641 gtk_icon_view_queue_layout (icon_view);
5643 g_object_notify (G_OBJECT (icon_view), "markup-column");
5647 * gtk_icon_view_get_markup_column:
5648 * @icon_view: A #GtkIconView.
5650 * Returns the column with markup text for @icon_view.
5652 * Returns: the markup column, or -1 if it's unset.
5657 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5659 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5661 return icon_view->priv->markup_column;
5665 * gtk_icon_view_set_pixbuf_column:
5666 * @icon_view: A #GtkIconView.
5667 * @column: A column in the currently used model, or -1 to disable
5669 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5670 * column must be of type #GDK_TYPE_PIXBUF
5675 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5678 if (column == icon_view->priv->pixbuf_column)
5682 icon_view->priv->pixbuf_column = -1;
5685 if (icon_view->priv->model != NULL)
5689 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5691 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5694 icon_view->priv->pixbuf_column = column;
5697 gtk_icon_view_stop_editing (icon_view, TRUE);
5699 update_pixbuf_cell (icon_view);
5701 gtk_icon_view_invalidate_sizes (icon_view);
5702 gtk_icon_view_queue_layout (icon_view);
5704 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5709 * gtk_icon_view_get_pixbuf_column:
5710 * @icon_view: A #GtkIconView.
5712 * Returns the column with pixbufs for @icon_view.
5714 * Returns: the pixbuf column, or -1 if it's unset.
5719 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5721 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5723 return icon_view->priv->pixbuf_column;
5727 * gtk_icon_view_select_path:
5728 * @icon_view: A #GtkIconView.
5729 * @path: The #GtkTreePath to be selected.
5731 * Selects the row at @path.
5736 gtk_icon_view_select_path (GtkIconView *icon_view,
5739 GtkIconViewItem *item = NULL;
5741 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5742 g_return_if_fail (icon_view->priv->model != NULL);
5743 g_return_if_fail (path != NULL);
5745 if (gtk_tree_path_get_depth (path) > 0)
5746 item = g_list_nth_data (icon_view->priv->items,
5747 gtk_tree_path_get_indices(path)[0]);
5750 gtk_icon_view_select_item (icon_view, item);
5754 * gtk_icon_view_unselect_path:
5755 * @icon_view: A #GtkIconView.
5756 * @path: The #GtkTreePath to be unselected.
5758 * Unselects the row at @path.
5763 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5766 GtkIconViewItem *item;
5768 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5769 g_return_if_fail (icon_view->priv->model != NULL);
5770 g_return_if_fail (path != NULL);
5772 item = g_list_nth_data (icon_view->priv->items,
5773 gtk_tree_path_get_indices(path)[0]);
5778 gtk_icon_view_unselect_item (icon_view, item);
5782 * gtk_icon_view_get_selected_items:
5783 * @icon_view: A #GtkIconView.
5785 * Creates a list of paths of all selected items. Additionally, if you are
5786 * planning on modifying the model after calling this function, you may
5787 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5788 * To do this, you can use gtk_tree_row_reference_new().
5790 * To free the return value, use:
5792 * g_list_foreach (list, gtk_tree_path_free, NULL);
5793 * g_list_free (list);
5796 * Return value: A #GList containing a #GtkTreePath for each selected row.
5801 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5804 GList *selected = NULL;
5806 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5808 for (list = icon_view->priv->items; list != NULL; list = list->next)
5810 GtkIconViewItem *item = list->data;
5814 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5816 selected = g_list_prepend (selected, path);
5824 * gtk_icon_view_select_all:
5825 * @icon_view: A #GtkIconView.
5827 * Selects all the icons. @icon_view must has its selection mode set
5828 * to #GTK_SELECTION_MULTIPLE.
5833 gtk_icon_view_select_all (GtkIconView *icon_view)
5836 gboolean dirty = FALSE;
5838 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5840 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5843 for (items = icon_view->priv->items; items; items = items->next)
5845 GtkIconViewItem *item = items->data;
5847 if (!item->selected)
5850 item->selected = TRUE;
5851 gtk_icon_view_queue_draw_item (icon_view, item);
5856 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5860 * gtk_icon_view_unselect_all:
5861 * @icon_view: A #GtkIconView.
5863 * Unselects all the icons.
5868 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5870 gboolean dirty = FALSE;
5872 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5874 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5877 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5880 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5884 * gtk_icon_view_path_is_selected:
5885 * @icon_view: A #GtkIconView.
5886 * @path: A #GtkTreePath to check selection on.
5888 * Returns %TRUE if the icon pointed to by @path is currently
5889 * selected. If @path does not point to a valid location, %FALSE is returned.
5891 * Return value: %TRUE if @path is selected.
5896 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5899 GtkIconViewItem *item;
5901 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5902 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5903 g_return_val_if_fail (path != NULL, FALSE);
5905 item = g_list_nth_data (icon_view->priv->items,
5906 gtk_tree_path_get_indices(path)[0]);
5911 return item->selected;
5915 * gtk_icon_view_item_activated:
5916 * @icon_view: A #GtkIconView
5917 * @path: The #GtkTreePath to be activated
5919 * Activates the item determined by @path.
5924 gtk_icon_view_item_activated (GtkIconView *icon_view,
5927 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5928 g_return_if_fail (path != NULL);
5930 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5934 * gtk_icon_view_set_orientation:
5935 * @icon_view: a #GtkIconView
5936 * @orientation: the relative position of texts and icons
5938 * Sets the ::orientation property which determines whether the labels
5939 * are drawn beside the icons instead of below.
5944 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5945 GtkOrientation orientation)
5947 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5949 if (icon_view->priv->orientation != orientation)
5951 icon_view->priv->orientation = orientation;
5953 gtk_icon_view_stop_editing (icon_view, TRUE);
5954 gtk_icon_view_invalidate_sizes (icon_view);
5955 gtk_icon_view_queue_layout (icon_view);
5957 update_text_cell (icon_view);
5958 update_pixbuf_cell (icon_view);
5960 g_object_notify (G_OBJECT (icon_view), "orientation");
5965 * gtk_icon_view_get_orientation:
5966 * @icon_view: a #GtkIconView
5968 * Returns the value of the ::orientation property which determines
5969 * whether the labels are drawn beside the icons instead of below.
5971 * Return value: the relative position of texts and icons
5976 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5978 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5979 GTK_ORIENTATION_VERTICAL);
5981 return icon_view->priv->orientation;
5985 * gtk_icon_view_set_columns:
5986 * @icon_view: a #GtkIconView
5987 * @columns: the number of columns
5989 * Sets the ::columns property which determines in how
5990 * many columns the icons are arranged. If @columns is
5991 * -1, the number of columns will be chosen automatically
5992 * to fill the available area.
5997 gtk_icon_view_set_columns (GtkIconView *icon_view,
6000 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6002 if (icon_view->priv->columns != columns)
6004 icon_view->priv->columns = columns;
6006 gtk_icon_view_stop_editing (icon_view, TRUE);
6007 gtk_icon_view_queue_layout (icon_view);
6009 g_object_notify (G_OBJECT (icon_view), "columns");
6014 * gtk_icon_view_get_columns:
6015 * @icon_view: a #GtkIconView
6017 * Returns the value of the ::columns property.
6019 * Return value: the number of columns, or -1
6024 gtk_icon_view_get_columns (GtkIconView *icon_view)
6026 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6028 return icon_view->priv->columns;
6032 * gtk_icon_view_set_item_width:
6033 * @icon_view: a #GtkIconView
6034 * @item_width: the width for each item
6036 * Sets the ::item-width property which specifies the width
6037 * to use for each item. If it is set to -1, the icon view will
6038 * automatically determine a suitable item size.
6043 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6046 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6048 if (icon_view->priv->item_width != item_width)
6050 icon_view->priv->item_width = item_width;
6052 gtk_icon_view_stop_editing (icon_view, TRUE);
6053 gtk_icon_view_invalidate_sizes (icon_view);
6054 gtk_icon_view_queue_layout (icon_view);
6056 update_text_cell (icon_view);
6058 g_object_notify (G_OBJECT (icon_view), "item-width");
6063 * gtk_icon_view_get_item_width:
6064 * @icon_view: a #GtkIconView
6066 * Returns the value of the ::item-width property.
6068 * Return value: the width of a single item, or -1
6073 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6075 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6077 return icon_view->priv->item_width;
6082 * gtk_icon_view_set_spacing:
6083 * @icon_view: a #GtkIconView
6084 * @spacing: the spacing
6086 * Sets the ::spacing property which specifies the space
6087 * which is inserted between the cells (i.e. the icon and
6088 * the text) of an item.
6093 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6096 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6098 if (icon_view->priv->spacing != spacing)
6100 icon_view->priv->spacing = spacing;
6102 gtk_icon_view_stop_editing (icon_view, TRUE);
6103 gtk_icon_view_invalidate_sizes (icon_view);
6104 gtk_icon_view_queue_layout (icon_view);
6106 g_object_notify (G_OBJECT (icon_view), "spacing");
6111 * gtk_icon_view_get_spacing:
6112 * @icon_view: a #GtkIconView
6114 * Returns the value of the ::spacing property.
6116 * Return value: the space between cells
6121 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6123 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6125 return icon_view->priv->spacing;
6129 * gtk_icon_view_set_row_spacing:
6130 * @icon_view: a #GtkIconView
6131 * @row_spacing: the row spacing
6133 * Sets the ::row-spacing property which specifies the space
6134 * which is inserted between the rows of the icon view.
6139 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6142 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6144 if (icon_view->priv->row_spacing != row_spacing)
6146 icon_view->priv->row_spacing = row_spacing;
6148 gtk_icon_view_stop_editing (icon_view, TRUE);
6149 gtk_icon_view_invalidate_sizes (icon_view);
6150 gtk_icon_view_queue_layout (icon_view);
6152 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6157 * gtk_icon_view_get_row_spacing:
6158 * @icon_view: a #GtkIconView
6160 * Returns the value of the ::row-spacing property.
6162 * Return value: the space between rows
6167 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6169 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6171 return icon_view->priv->row_spacing;
6175 * gtk_icon_view_set_column_spacing:
6176 * @icon_view: a #GtkIconView
6177 * @column_spacing: the column spacing
6179 * Sets the ::column-spacing property which specifies the space
6180 * which is inserted between the columns of the icon view.
6185 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6186 gint column_spacing)
6188 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6190 if (icon_view->priv->column_spacing != column_spacing)
6192 icon_view->priv->column_spacing = column_spacing;
6194 gtk_icon_view_stop_editing (icon_view, TRUE);
6195 gtk_icon_view_invalidate_sizes (icon_view);
6196 gtk_icon_view_queue_layout (icon_view);
6198 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6203 * gtk_icon_view_get_column_spacing:
6204 * @icon_view: a #GtkIconView
6206 * Returns the value of the ::column-spacing property.
6208 * Return value: the space between columns
6213 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6215 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6217 return icon_view->priv->column_spacing;
6221 * gtk_icon_view_set_margin:
6222 * @icon_view: a #GtkIconView
6223 * @margin: the margin
6225 * Sets the ::margin property which specifies the space
6226 * which is inserted at the top, bottom, left and right
6232 gtk_icon_view_set_margin (GtkIconView *icon_view,
6235 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6237 if (icon_view->priv->margin != margin)
6239 icon_view->priv->margin = margin;
6241 gtk_icon_view_stop_editing (icon_view, TRUE);
6242 gtk_icon_view_invalidate_sizes (icon_view);
6243 gtk_icon_view_queue_layout (icon_view);
6245 g_object_notify (G_OBJECT (icon_view), "margin");
6250 * gtk_icon_view_get_margin:
6251 * @icon_view: a #GtkIconView
6253 * Returns the value of the ::margin property.
6255 * Return value: the space at the borders
6260 gtk_icon_view_get_margin (GtkIconView *icon_view)
6262 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6264 return icon_view->priv->margin;
6268 * gtk_icon_view_set_item_padding:
6269 * @icon_view: a #GtkIconView
6270 * @column_spacing: the item padding
6272 * Sets the ::item-padding property which specifies the padding
6273 * around each of the icon view's items.
6278 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6281 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6283 if (icon_view->priv->item_padding != item_padding)
6285 icon_view->priv->item_padding = item_padding;
6287 gtk_icon_view_stop_editing (icon_view, TRUE);
6288 gtk_icon_view_invalidate_sizes (icon_view);
6289 gtk_icon_view_queue_layout (icon_view);
6291 g_object_notify (G_OBJECT (icon_view), "item-padding");
6296 * gtk_icon_view_get_item_padding:
6297 * @icon_view: a #GtkIconView
6299 * Returns the value of the ::item-padding property.
6301 * Return value: the padding around items
6306 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6308 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6310 return icon_view->priv->item_padding;
6313 /* Get/set whether drag_motion requested the drag data and
6314 * drag_data_received should thus not actually insert the data,
6315 * since the data doesn't result from a drop.
6318 set_status_pending (GdkDragContext *context,
6319 GdkDragAction suggested_action)
6321 g_object_set_data (G_OBJECT (context),
6322 I_("gtk-icon-view-status-pending"),
6323 GINT_TO_POINTER (suggested_action));
6326 static GdkDragAction
6327 get_status_pending (GdkDragContext *context)
6329 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6330 "gtk-icon-view-status-pending"));
6334 unset_reorderable (GtkIconView *icon_view)
6336 if (icon_view->priv->reorderable)
6338 icon_view->priv->reorderable = FALSE;
6339 g_object_notify (G_OBJECT (icon_view), "reorderable");
6344 set_source_row (GdkDragContext *context,
6345 GtkTreeModel *model,
6346 GtkTreePath *source_row)
6349 g_object_set_data_full (G_OBJECT (context),
6350 I_("gtk-icon-view-source-row"),
6351 gtk_tree_row_reference_new (model, source_row),
6352 (GDestroyNotify) gtk_tree_row_reference_free);
6354 g_object_set_data_full (G_OBJECT (context),
6355 I_("gtk-icon-view-source-row"),
6360 get_source_row (GdkDragContext *context)
6362 GtkTreeRowReference *ref;
6364 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6367 return gtk_tree_row_reference_get_path (ref);
6374 GtkTreeRowReference *dest_row;
6375 gboolean empty_view_drop;
6376 gboolean drop_append_mode;
6380 dest_row_free (gpointer data)
6382 DestRow *dr = (DestRow *)data;
6384 gtk_tree_row_reference_free (dr->dest_row);
6389 set_dest_row (GdkDragContext *context,
6390 GtkTreeModel *model,
6391 GtkTreePath *dest_row,
6392 gboolean empty_view_drop,
6393 gboolean drop_append_mode)
6399 g_object_set_data_full (G_OBJECT (context),
6400 I_("gtk-icon-view-dest-row"),
6405 dr = g_new0 (DestRow, 1);
6407 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6408 dr->empty_view_drop = empty_view_drop;
6409 dr->drop_append_mode = drop_append_mode;
6410 g_object_set_data_full (G_OBJECT (context),
6411 I_("gtk-icon-view-dest-row"),
6412 dr, (GDestroyNotify) dest_row_free);
6416 get_dest_row (GdkDragContext *context)
6420 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6424 GtkTreePath *path = NULL;
6427 path = gtk_tree_row_reference_get_path (dr->dest_row);
6428 else if (dr->empty_view_drop)
6429 path = gtk_tree_path_new_from_indices (0, -1);
6433 if (path && dr->drop_append_mode)
6434 gtk_tree_path_next (path);
6443 check_model_dnd (GtkTreeModel *model,
6444 GType required_iface,
6445 const gchar *signal)
6447 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6449 g_warning ("You must override the default '%s' handler "
6450 "on GtkIconView when using models that don't support "
6451 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6452 "is to connect to '%s' and call "
6453 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6454 "the default handler from running. Look at the source code "
6455 "for the default handler in gtkiconview.c to get an idea what "
6456 "your handler should do. (gtkiconview.c is in the GTK+ source "
6457 "code.) If you're using GTK+ from a language other than C, "
6458 "there may be a more natural way to override default handlers, e.g. via derivation.",
6459 signal, g_type_name (required_iface), signal);
6467 remove_scroll_timeout (GtkIconView *icon_view)
6469 if (icon_view->priv->scroll_timeout_id != 0)
6471 g_source_remove (icon_view->priv->scroll_timeout_id);
6473 icon_view->priv->scroll_timeout_id = 0;
6478 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6480 gint px, py, x, y, width, height;
6481 gint hoffset, voffset;
6484 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6485 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6487 /* see if we are near the edge. */
6488 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6490 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6492 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6494 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6498 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6499 icon_view->priv->vadjustment->lower,
6500 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6501 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6505 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6506 icon_view->priv->hadjustment->lower,
6507 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6508 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6514 drag_scroll_timeout (gpointer data)
6516 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6518 gtk_icon_view_autoscroll (icon_view);
6525 set_destination (GtkIconView *icon_view,
6526 GdkDragContext *context,
6529 GdkDragAction *suggested_action,
6533 GtkTreePath *path = NULL;
6534 GtkIconViewDropPosition pos;
6535 GtkIconViewDropPosition old_pos;
6536 GtkTreePath *old_dest_path = NULL;
6537 gboolean can_drop = FALSE;
6539 widget = GTK_WIDGET (icon_view);
6541 *suggested_action = 0;
6544 if (!icon_view->priv->dest_set)
6546 /* someone unset us as a drag dest, note that if
6547 * we return FALSE drag_leave isn't called
6550 gtk_icon_view_set_drag_dest_item (icon_view,
6552 GTK_ICON_VIEW_DROP_LEFT);
6554 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6556 return FALSE; /* no longer a drop site */
6559 *target = gtk_drag_dest_find_target (widget, context,
6560 gtk_drag_dest_get_target_list (widget));
6561 if (*target == GDK_NONE)
6564 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6567 GtkTreeModel *model;
6569 /* the row got dropped on empty space, let's setup a special case
6573 gtk_tree_path_free (path);
6575 model = gtk_icon_view_get_model (icon_view);
6577 n_children = gtk_tree_model_iter_n_children (model, NULL);
6580 pos = GTK_ICON_VIEW_DROP_BELOW;
6581 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6585 pos = GTK_ICON_VIEW_DROP_ABOVE;
6586 path = gtk_tree_path_new_from_indices (0, -1);
6596 gtk_icon_view_get_drag_dest_item (icon_view,
6601 gtk_tree_path_free (old_dest_path);
6603 if (TRUE /* FIXME if the location droppable predicate */)
6611 GtkWidget *source_widget;
6613 *suggested_action = context->suggested_action;
6614 source_widget = gtk_drag_get_source_widget (context);
6616 if (source_widget == widget)
6618 /* Default to MOVE, unless the user has
6619 * pressed ctrl or shift to affect available actions
6621 if ((context->actions & GDK_ACTION_MOVE) != 0)
6622 *suggested_action = GDK_ACTION_MOVE;
6625 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6630 /* can't drop here */
6631 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6633 GTK_ICON_VIEW_DROP_LEFT);
6637 gtk_tree_path_free (path);
6643 get_logical_destination (GtkIconView *icon_view,
6644 gboolean *drop_append_mode)
6646 /* adjust path to point to the row the drop goes in front of */
6647 GtkTreePath *path = NULL;
6648 GtkIconViewDropPosition pos;
6650 *drop_append_mode = FALSE;
6652 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6657 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6658 pos == GTK_ICON_VIEW_DROP_BELOW)
6661 GtkTreeModel *model = icon_view->priv->model;
6663 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6664 !gtk_tree_model_iter_next (model, &iter))
6665 *drop_append_mode = TRUE;
6668 *drop_append_mode = FALSE;
6669 gtk_tree_path_next (path);
6677 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6678 GdkEventMotion *event)
6680 GtkWidget *widget = GTK_WIDGET (icon_view);
6681 GdkDragContext *context;
6682 GtkTreePath *path = NULL;
6684 GtkTreeModel *model;
6685 gboolean retval = FALSE;
6687 if (!icon_view->priv->source_set)
6690 if (icon_view->priv->pressed_button < 0)
6693 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6694 icon_view->priv->press_start_x,
6695 icon_view->priv->press_start_y,
6696 event->x, event->y))
6699 model = gtk_icon_view_get_model (icon_view);
6704 button = icon_view->priv->pressed_button;
6705 icon_view->priv->pressed_button = -1;
6707 path = gtk_icon_view_get_path_at_pos (icon_view,
6708 icon_view->priv->press_start_x,
6709 icon_view->priv->press_start_y);
6714 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6715 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6719 /* FIXME Check whether we're a start button, if not return FALSE and
6723 /* Now we can begin the drag */
6727 context = gtk_drag_begin (widget,
6728 gtk_drag_source_get_target_list (widget),
6729 icon_view->priv->source_actions,
6733 set_source_row (context, model, path);
6737 gtk_tree_path_free (path);
6742 /* Source side drag signals */
6744 gtk_icon_view_drag_begin (GtkWidget *widget,
6745 GdkDragContext *context)
6747 GtkIconView *icon_view;
6748 GtkIconViewItem *item;
6753 icon_view = GTK_ICON_VIEW (widget);
6755 /* if the user uses a custom DnD impl, we don't set the icon here */
6756 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6759 item = gtk_icon_view_get_item_at_coords (icon_view,
6760 icon_view->priv->press_start_x,
6761 icon_view->priv->press_start_y,
6765 g_return_if_fail (item != NULL);
6767 x = icon_view->priv->press_start_x - item->x + 1;
6768 y = icon_view->priv->press_start_y - item->y + 1;
6770 path = gtk_tree_path_new_from_indices (item->index, -1);
6771 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6772 gtk_tree_path_free (path);
6774 gtk_drag_set_icon_pixmap (context,
6775 gdk_drawable_get_colormap (icon),
6780 g_object_unref (icon);
6784 gtk_icon_view_drag_end (GtkWidget *widget,
6785 GdkDragContext *context)
6791 gtk_icon_view_drag_data_get (GtkWidget *widget,
6792 GdkDragContext *context,
6793 GtkSelectionData *selection_data,
6797 GtkIconView *icon_view;
6798 GtkTreeModel *model;
6799 GtkTreePath *source_row;
6801 icon_view = GTK_ICON_VIEW (widget);
6802 model = gtk_icon_view_get_model (icon_view);
6807 if (!icon_view->priv->source_set)
6810 source_row = get_source_row (context);
6812 if (source_row == NULL)
6815 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6816 * any model; for DragSource models there are some other targets
6820 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6821 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6826 /* If drag_data_get does nothing, try providing row data. */
6827 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6828 gtk_tree_set_row_drag_data (selection_data,
6833 gtk_tree_path_free (source_row);
6837 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6838 GdkDragContext *context)
6840 GtkTreeModel *model;
6841 GtkIconView *icon_view;
6842 GtkTreePath *source_row;
6844 icon_view = GTK_ICON_VIEW (widget);
6845 model = gtk_icon_view_get_model (icon_view);
6847 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6850 if (!icon_view->priv->source_set)
6853 source_row = get_source_row (context);
6855 if (source_row == NULL)
6858 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6861 gtk_tree_path_free (source_row);
6863 set_source_row (context, NULL, NULL);
6866 /* Target side drag signals */
6868 gtk_icon_view_drag_leave (GtkWidget *widget,
6869 GdkDragContext *context,
6872 GtkIconView *icon_view;
6874 icon_view = GTK_ICON_VIEW (widget);
6876 /* unset any highlight row */
6877 gtk_icon_view_set_drag_dest_item (icon_view,
6879 GTK_ICON_VIEW_DROP_LEFT);
6881 remove_scroll_timeout (icon_view);
6885 gtk_icon_view_drag_motion (GtkWidget *widget,
6886 GdkDragContext *context,
6891 GtkTreePath *path = NULL;
6892 GtkIconViewDropPosition pos;
6893 GtkIconView *icon_view;
6894 GdkDragAction suggested_action = 0;
6898 icon_view = GTK_ICON_VIEW (widget);
6900 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6903 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6905 /* we only know this *after* set_desination_row */
6906 empty = icon_view->priv->empty_view_drop;
6908 if (path == NULL && !empty)
6910 /* Can't drop here. */
6911 gdk_drag_status (context, 0, time);
6915 if (icon_view->priv->scroll_timeout_id == 0)
6917 icon_view->priv->scroll_timeout_id =
6918 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6921 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6923 /* Request data so we can use the source row when
6924 * determining whether to accept the drop
6926 set_status_pending (context, suggested_action);
6927 gtk_drag_get_data (widget, context, target, time);
6931 set_status_pending (context, 0);
6932 gdk_drag_status (context, suggested_action, time);
6937 gtk_tree_path_free (path);
6943 gtk_icon_view_drag_drop (GtkWidget *widget,
6944 GdkDragContext *context,
6949 GtkIconView *icon_view;
6951 GdkDragAction suggested_action = 0;
6952 GdkAtom target = GDK_NONE;
6953 GtkTreeModel *model;
6954 gboolean drop_append_mode;
6956 icon_view = GTK_ICON_VIEW (widget);
6957 model = gtk_icon_view_get_model (icon_view);
6959 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6961 if (!icon_view->priv->dest_set)
6964 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6967 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6970 path = get_logical_destination (icon_view, &drop_append_mode);
6972 if (target != GDK_NONE && path != NULL)
6974 /* in case a motion had requested drag data, change things so we
6975 * treat drag data receives as a drop.
6977 set_status_pending (context, 0);
6978 set_dest_row (context, model, path,
6979 icon_view->priv->empty_view_drop, drop_append_mode);
6983 gtk_tree_path_free (path);
6985 /* Unset this thing */
6986 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6988 if (target != GDK_NONE)
6990 gtk_drag_get_data (widget, context, target, time);
6998 gtk_icon_view_drag_data_received (GtkWidget *widget,
6999 GdkDragContext *context,
7002 GtkSelectionData *selection_data,
7007 gboolean accepted = FALSE;
7008 GtkTreeModel *model;
7009 GtkIconView *icon_view;
7010 GtkTreePath *dest_row;
7011 GdkDragAction suggested_action;
7012 gboolean drop_append_mode;
7014 icon_view = GTK_ICON_VIEW (widget);
7015 model = gtk_icon_view_get_model (icon_view);
7017 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7020 if (!icon_view->priv->dest_set)
7023 suggested_action = get_status_pending (context);
7025 if (suggested_action)
7027 /* We are getting this data due to a request in drag_motion,
7028 * rather than due to a request in drag_drop, so we are just
7029 * supposed to call drag_status, not actually paste in the
7032 path = get_logical_destination (icon_view, &drop_append_mode);
7035 suggested_action = 0;
7037 if (suggested_action)
7039 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7042 suggested_action = 0;
7045 gdk_drag_status (context, suggested_action, time);
7048 gtk_tree_path_free (path);
7050 /* If you can't drop, remove user drop indicator until the next motion */
7051 if (suggested_action == 0)
7052 gtk_icon_view_set_drag_dest_item (icon_view,
7054 GTK_ICON_VIEW_DROP_LEFT);
7059 dest_row = get_dest_row (context);
7061 if (dest_row == NULL)
7064 if (selection_data->length >= 0)
7066 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7072 gtk_drag_finish (context,
7074 (context->action == GDK_ACTION_MOVE),
7077 gtk_tree_path_free (dest_row);
7080 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7083 /* Drag-and-Drop support */
7085 * gtk_icon_view_enable_model_drag_source:
7086 * @icon_view: a #GtkIconTreeView
7087 * @start_button_mask: Mask of allowed buttons to start drag
7088 * @targets: the table of targets that the drag will support
7089 * @n_targets: the number of items in @targets
7090 * @actions: the bitmask of possible actions for a drag from this
7093 * Turns @icon_view into a drag source for automatic DND. Calling this
7094 * method sets #GtkIconView:reorderable to %FALSE.
7099 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7100 GdkModifierType start_button_mask,
7101 const GtkTargetEntry *targets,
7103 GdkDragAction actions)
7105 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7107 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7109 icon_view->priv->start_button_mask = start_button_mask;
7110 icon_view->priv->source_actions = actions;
7112 icon_view->priv->source_set = TRUE;
7114 unset_reorderable (icon_view);
7118 * gtk_icon_view_enable_model_drag_dest:
7119 * @icon_view: a #GtkIconView
7120 * @targets: the table of targets that the drag will support
7121 * @n_targets: the number of items in @targets
7122 * @actions: the bitmask of possible actions for a drag to this
7125 * Turns @icon_view into a drop destination for automatic DND. Calling this
7126 * method sets #GtkIconView:reorderable to %FALSE.
7131 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7132 const GtkTargetEntry *targets,
7134 GdkDragAction actions)
7136 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7138 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7140 icon_view->priv->dest_actions = actions;
7142 icon_view->priv->dest_set = TRUE;
7144 unset_reorderable (icon_view);
7148 * gtk_icon_view_unset_model_drag_source:
7149 * @icon_view: a #GtkIconView
7151 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7152 * method sets #GtkIconView:reorderable to %FALSE.
7157 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7159 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7161 if (icon_view->priv->source_set)
7163 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7164 icon_view->priv->source_set = FALSE;
7167 unset_reorderable (icon_view);
7171 * gtk_icon_view_unset_model_drag_dest:
7172 * @icon_view: a #GtkIconView
7174 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7175 * method sets #GtkIconView:reorderable to %FALSE.
7180 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7182 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7184 if (icon_view->priv->dest_set)
7186 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7187 icon_view->priv->dest_set = FALSE;
7190 unset_reorderable (icon_view);
7193 /* These are useful to implement your own custom stuff. */
7195 * gtk_icon_view_set_drag_dest_item:
7196 * @icon_view: a #GtkIconView
7197 * @path: The path of the item to highlight, or %NULL.
7198 * @pos: Specifies where to drop, relative to the item
7200 * Sets the item that is highlighted for feedback.
7205 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7207 GtkIconViewDropPosition pos)
7209 /* Note; this function is exported to allow a custom DND
7210 * implementation, so it can't touch TreeViewDragInfo
7213 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7215 if (icon_view->priv->dest_item)
7217 GtkTreePath *current_path;
7218 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7219 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7220 icon_view->priv->dest_item = NULL;
7222 gtk_icon_view_queue_draw_path (icon_view, current_path);
7223 gtk_tree_path_free (current_path);
7226 /* special case a drop on an empty model */
7227 icon_view->priv->empty_view_drop = FALSE;
7228 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7229 && gtk_tree_path_get_depth (path) == 1
7230 && gtk_tree_path_get_indices (path)[0] == 0)
7234 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7237 if (n_children == 0)
7238 icon_view->priv->empty_view_drop = TRUE;
7241 icon_view->priv->dest_pos = pos;
7245 icon_view->priv->dest_item =
7246 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7247 icon_view->priv->model, path);
7249 gtk_icon_view_queue_draw_path (icon_view, path);
7254 * gtk_icon_view_get_drag_dest_item:
7255 * @icon_view: a #GtkIconView
7256 * @path: Return location for the path of the highlighted item, or %NULL.
7257 * @pos: Return location for the drop position, or %NULL
7259 * Gets information about the item that is highlighted for feedback.
7264 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7266 GtkIconViewDropPosition *pos)
7268 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7272 if (icon_view->priv->dest_item)
7273 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7279 *pos = icon_view->priv->dest_pos;
7283 * gtk_icon_view_get_dest_item_at_pos:
7284 * @icon_view: a #GtkIconView
7285 * @drag_x: the position to determine the destination item for
7286 * @drag_y: the position to determine the destination item for
7287 * @path: Return location for the path of the item, or %NULL.
7288 * @pos: Return location for the drop position, or %NULL
7290 * Determines the destination item for a given position.
7292 * Return value: whether there is an item at the given position.
7297 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7301 GtkIconViewDropPosition *pos)
7303 GtkIconViewItem *item;
7305 /* Note; this function is exported to allow a custom DND
7306 * implementation, so it can't touch TreeViewDragInfo
7309 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7310 g_return_val_if_fail (drag_x >= 0, FALSE);
7311 g_return_val_if_fail (drag_y >= 0, FALSE);
7312 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7318 item = gtk_icon_view_get_item_at_coords (icon_view,
7319 drag_x + icon_view->priv->hadjustment->value,
7320 drag_y + icon_view->priv->vadjustment->value,
7327 *path = gtk_tree_path_new_from_indices (item->index, -1);
7331 if (drag_x < item->x + item->width / 4)
7332 *pos = GTK_ICON_VIEW_DROP_LEFT;
7333 else if (drag_x > item->x + item->width * 3 / 4)
7334 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7335 else if (drag_y < item->y + item->height / 4)
7336 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7337 else if (drag_y > item->y + item->height * 3 / 4)
7338 *pos = GTK_ICON_VIEW_DROP_BELOW;
7340 *pos = GTK_ICON_VIEW_DROP_INTO;
7347 * gtk_icon_view_create_drag_icon:
7348 * @icon_view: a #GtkIconView
7349 * @path: a #GtkTreePath in @icon_view
7351 * Creates a #GdkPixmap representation of the item at @path.
7352 * This image is used for a drag icon.
7354 * Return value: a newly-allocated pixmap of the drag icon.
7359 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7364 GdkPixmap *drawable;
7369 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7370 g_return_val_if_fail (path != NULL, NULL);
7372 widget = GTK_WIDGET (icon_view);
7374 if (!GTK_WIDGET_REALIZED (widget))
7377 index = gtk_tree_path_get_indices (path)[0];
7379 for (l = icon_view->priv->items; l; l = l->next)
7381 GtkIconViewItem *item = l->data;
7383 if (index == item->index)
7385 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7390 cr = gdk_cairo_create (drawable);
7391 cairo_set_line_width (cr, 1.);
7393 gdk_cairo_set_source_color
7394 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7395 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7400 area.width = item->width;
7401 area.height = item->height;
7403 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7404 drawable, 1, 1, FALSE);
7406 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7407 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7420 * gtk_icon_view_get_reorderable:
7421 * @icon_view: a #GtkIconView
7423 * Retrieves whether the user can reorder the list via drag-and-drop.
7424 * See gtk_icon_view_set_reorderable().
7426 * Return value: %TRUE if the list can be reordered.
7431 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7433 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7435 return icon_view->priv->reorderable;
7438 static const GtkTargetEntry item_targets[] = {
7439 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7444 * gtk_icon_view_set_reorderable:
7445 * @icon_view: A #GtkIconView.
7446 * @reorderable: %TRUE, if the list of items can be reordered.
7448 * This function is a convenience function to allow you to reorder models that
7449 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7450 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7451 * the user can reorder the model by dragging and dropping rows. The
7452 * developer can listen to these changes by connecting to the model's
7453 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7454 * the icon view as a drag source and destination. Therefore, drag and
7455 * drop can not be used in a reorderable view for any other purpose.
7457 * This function does not give you any degree of control over the order -- any
7458 * reordering is allowed. If more control is needed, you should probably
7459 * handle drag and drop manually.
7464 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7465 gboolean reorderable)
7467 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7469 reorderable = reorderable != FALSE;
7471 if (icon_view->priv->reorderable == reorderable)
7476 gtk_icon_view_enable_model_drag_source (icon_view,
7479 G_N_ELEMENTS (item_targets),
7481 gtk_icon_view_enable_model_drag_dest (icon_view,
7483 G_N_ELEMENTS (item_targets),
7488 gtk_icon_view_unset_model_drag_source (icon_view);
7489 gtk_icon_view_unset_model_drag_dest (icon_view);
7492 icon_view->priv->reorderable = reorderable;
7494 g_object_notify (G_OBJECT (icon_view), "reorderable");
7498 /* Accessibility Support */
7500 static gpointer accessible_parent_class;
7501 static gpointer accessible_item_parent_class;
7502 static GQuark accessible_private_data_quark = 0;
7504 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7505 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7506 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7508 static GType gtk_icon_view_item_accessible_get_type (void);
7519 GtkIconViewItem *item;
7523 AtkStateSet *state_set;
7527 GtkTextBuffer *text_buffer;
7529 gchar *action_descriptions[LAST_ACTION];
7530 gchar *image_description;
7531 guint action_idle_handler;
7532 } GtkIconViewItemAccessible;
7534 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7540 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7545 typedef struct _GtkIconViewItemAccessibleClass
7547 AtkObjectClass parent_class;
7549 } GtkIconViewItemAccessibleClass;
7551 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7554 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7556 GtkIconViewItemAccessible *item;
7557 GtkIconView *icon_view;
7560 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7561 item->action_idle_handler = 0;
7563 if (item->widget != NULL)
7565 icon_view = GTK_ICON_VIEW (item->widget);
7566 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7567 gtk_icon_view_item_activated (icon_view, path);
7568 gtk_tree_path_free (path);
7575 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7578 GtkIconViewItemAccessible *item;
7580 if (i < 0 || i >= LAST_ACTION)
7583 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7585 if (!GTK_IS_ICON_VIEW (item->widget))
7588 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7593 case ACTION_ACTIVATE:
7594 if (!item->action_idle_handler)
7595 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7598 g_assert_not_reached ();
7606 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7611 static const gchar *
7612 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7615 GtkIconViewItemAccessible *item;
7617 if (i < 0 || i >= LAST_ACTION)
7620 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7622 if (item->action_descriptions[i])
7623 return item->action_descriptions[i];
7625 return gtk_icon_view_item_accessible_action_descriptions[i];
7628 static const gchar *
7629 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7632 if (i < 0 || i >= LAST_ACTION)
7635 return gtk_icon_view_item_accessible_action_names[i];
7639 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7641 const gchar *description)
7643 GtkIconViewItemAccessible *item;
7645 if (i < 0 || i >= LAST_ACTION)
7648 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7650 g_free (item->action_descriptions[i]);
7652 item->action_descriptions[i] = g_strdup (description);
7658 atk_action_item_interface_init (AtkActionIface *iface)
7660 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7661 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7662 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7663 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7664 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7667 static const gchar *
7668 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7670 GtkIconViewItemAccessible *item;
7672 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7674 return item->image_description;
7678 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7679 const gchar *description)
7681 GtkIconViewItemAccessible *item;
7683 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7685 g_free (item->image_description);
7686 item->image_description = g_strdup (description);
7692 get_pixbuf_box (GtkIconView *icon_view,
7693 GtkIconViewItem *item,
7698 for (l = icon_view->priv->cell_list; l; l = l->next)
7700 GtkIconViewCellInfo *info = l->data;
7702 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7704 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7714 get_text (GtkIconView *icon_view,
7715 GtkIconViewItem *item)
7720 for (l = icon_view->priv->cell_list; l; l = l->next)
7722 GtkIconViewCellInfo *info = l->data;
7724 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7726 g_object_get (info->cell, "text", &text, NULL);
7736 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7740 GtkIconViewItemAccessible *item;
7743 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7745 if (!GTK_IS_ICON_VIEW (item->widget))
7748 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7751 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7754 *height = box.height;
7759 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7762 AtkCoordType coord_type)
7764 GtkIconViewItemAccessible *item;
7767 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7769 if (!GTK_IS_ICON_VIEW (item->widget))
7772 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7775 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7777 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7779 *x+= box.x - item->item->x;
7780 *y+= box.y - item->item->y;
7786 atk_image_item_interface_init (AtkImageIface *iface)
7788 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7789 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7790 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7791 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7795 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7799 GtkIconViewItemAccessible *item;
7800 GtkTextIter start, end;
7801 GtkTextBuffer *buffer;
7803 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7805 if (!GTK_IS_ICON_VIEW (item->widget))
7808 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7811 buffer = item->text_buffer;
7812 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7814 gtk_text_buffer_get_end_iter (buffer, &end);
7816 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7818 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7822 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7825 GtkIconViewItemAccessible *item;
7826 GtkTextIter start, end;
7827 GtkTextBuffer *buffer;
7831 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7833 if (!GTK_IS_ICON_VIEW (item->widget))
7836 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7839 buffer = item->text_buffer;
7840 if (offset >= gtk_text_buffer_get_char_count (buffer))
7843 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7845 gtk_text_iter_forward_char (&end);
7846 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7847 unichar = g_utf8_get_char (string);
7855 get_pango_text_offsets (PangoLayout *layout,
7856 GtkTextBuffer *buffer,
7858 AtkTextBoundary boundary_type,
7862 GtkTextIter *start_iter,
7863 GtkTextIter *end_iter)
7865 PangoLayoutIter *iter;
7866 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7867 gint index, start_index, end_index;
7869 gboolean found = FALSE;
7871 text = pango_layout_get_text (layout);
7872 index = g_utf8_offset_to_pointer (text, offset) - text;
7873 iter = pango_layout_get_iter (layout);
7876 line = pango_layout_iter_get_line_readonly (iter);
7877 start_index = line->start_index;
7878 end_index = start_index + line->length;
7880 if (index >= start_index && index <= end_index)
7883 * Found line for offset
7889 * We want the previous line
7893 switch (boundary_type)
7895 case ATK_TEXT_BOUNDARY_LINE_START:
7896 end_index = start_index;
7897 start_index = prev_line->start_index;
7899 case ATK_TEXT_BOUNDARY_LINE_END:
7901 start_index = prev_prev_line->start_index +
7902 prev_prev_line->length;
7903 end_index = prev_line->start_index + prev_line->length;
7906 g_assert_not_reached();
7910 start_index = end_index = 0;
7913 switch (boundary_type)
7915 case ATK_TEXT_BOUNDARY_LINE_START:
7916 if (pango_layout_iter_next_line (iter))
7917 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7919 case ATK_TEXT_BOUNDARY_LINE_END:
7921 start_index = prev_line->start_index +
7925 g_assert_not_reached();
7930 * We want the next line
7932 if (pango_layout_iter_next_line (iter))
7934 line = pango_layout_iter_get_line_readonly (iter);
7935 switch (boundary_type)
7937 case ATK_TEXT_BOUNDARY_LINE_START:
7938 start_index = line->start_index;
7939 if (pango_layout_iter_next_line (iter))
7940 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7942 end_index = start_index + line->length;
7944 case ATK_TEXT_BOUNDARY_LINE_END:
7945 start_index = end_index;
7946 end_index = line->start_index + line->length;
7949 g_assert_not_reached();
7953 start_index = end_index;
7959 prev_prev_line = prev_line;
7962 while (pango_layout_iter_next_line (iter));
7966 start_index = prev_line->start_index + prev_line->length;
7967 end_index = start_index;
7969 pango_layout_iter_free (iter);
7970 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7971 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7973 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7974 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7979 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7981 AtkTextBoundary boundary_type,
7985 GtkIconViewItemAccessible *item;
7986 GtkTextIter start, end;
7987 GtkTextBuffer *buffer;
7989 GtkIconView *icon_view;
7992 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7994 if (!GTK_IS_ICON_VIEW (item->widget))
7997 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8000 buffer = item->text_buffer;
8002 if (!gtk_text_buffer_get_char_count (buffer))
8006 return g_strdup ("");
8008 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8012 switch (boundary_type)
8014 case ATK_TEXT_BOUNDARY_CHAR:
8015 gtk_text_iter_backward_char(&start);
8017 case ATK_TEXT_BOUNDARY_WORD_START:
8018 if (!gtk_text_iter_starts_word (&start))
8019 gtk_text_iter_backward_word_start (&start);
8021 gtk_text_iter_backward_word_start(&start);
8023 case ATK_TEXT_BOUNDARY_WORD_END:
8024 if (gtk_text_iter_inside_word (&start) &&
8025 !gtk_text_iter_starts_word (&start))
8026 gtk_text_iter_backward_word_start (&start);
8027 while (!gtk_text_iter_ends_word (&start))
8029 if (!gtk_text_iter_backward_char (&start))
8033 gtk_text_iter_backward_word_start(&start);
8034 while (!gtk_text_iter_ends_word (&start))
8036 if (!gtk_text_iter_backward_char (&start))
8040 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8041 if (!gtk_text_iter_starts_sentence (&start))
8042 gtk_text_iter_backward_sentence_start (&start);
8044 gtk_text_iter_backward_sentence_start (&start);
8046 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8047 if (gtk_text_iter_inside_sentence (&start) &&
8048 !gtk_text_iter_starts_sentence (&start))
8049 gtk_text_iter_backward_sentence_start (&start);
8050 while (!gtk_text_iter_ends_sentence (&start))
8052 if (!gtk_text_iter_backward_char (&start))
8056 gtk_text_iter_backward_sentence_start (&start);
8057 while (!gtk_text_iter_ends_sentence (&start))
8059 if (!gtk_text_iter_backward_char (&start))
8063 case ATK_TEXT_BOUNDARY_LINE_START:
8064 case ATK_TEXT_BOUNDARY_LINE_END:
8066 icon_view = GTK_ICON_VIEW (item->widget);
8067 /* FIXME we probably have to use GailTextCell to salvage this */
8068 gtk_icon_view_update_item_text (icon_view, item->item);
8069 get_pango_text_offsets (icon_view->priv->layout,
8082 *start_offset = gtk_text_iter_get_offset (&start);
8083 *end_offset = gtk_text_iter_get_offset (&end);
8085 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8089 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8091 AtkTextBoundary boundary_type,
8095 GtkIconViewItemAccessible *item;
8096 GtkTextIter start, end;
8097 GtkTextBuffer *buffer;
8099 GtkIconView *icon_view;
8102 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8104 if (!GTK_IS_ICON_VIEW (item->widget))
8107 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8110 buffer = item->text_buffer;
8112 if (!gtk_text_buffer_get_char_count (buffer))
8116 return g_strdup ("");
8118 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8122 switch (boundary_type)
8124 case ATK_TEXT_BOUNDARY_CHAR:
8125 gtk_text_iter_forward_char (&end);
8127 case ATK_TEXT_BOUNDARY_WORD_START:
8128 if (!gtk_text_iter_starts_word (&start))
8129 gtk_text_iter_backward_word_start (&start);
8130 if (gtk_text_iter_inside_word (&end))
8131 gtk_text_iter_forward_word_end (&end);
8132 while (!gtk_text_iter_starts_word (&end))
8134 if (!gtk_text_iter_forward_char (&end))
8138 case ATK_TEXT_BOUNDARY_WORD_END:
8139 if (gtk_text_iter_inside_word (&start) &&
8140 !gtk_text_iter_starts_word (&start))
8141 gtk_text_iter_backward_word_start (&start);
8142 while (!gtk_text_iter_ends_word (&start))
8144 if (!gtk_text_iter_backward_char (&start))
8147 gtk_text_iter_forward_word_end (&end);
8149 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8150 if (!gtk_text_iter_starts_sentence (&start))
8151 gtk_text_iter_backward_sentence_start (&start);
8152 if (gtk_text_iter_inside_sentence (&end))
8153 gtk_text_iter_forward_sentence_end (&end);
8154 while (!gtk_text_iter_starts_sentence (&end))
8156 if (!gtk_text_iter_forward_char (&end))
8160 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8161 if (gtk_text_iter_inside_sentence (&start) &&
8162 !gtk_text_iter_starts_sentence (&start))
8163 gtk_text_iter_backward_sentence_start (&start);
8164 while (!gtk_text_iter_ends_sentence (&start))
8166 if (!gtk_text_iter_backward_char (&start))
8169 gtk_text_iter_forward_sentence_end (&end);
8171 case ATK_TEXT_BOUNDARY_LINE_START:
8172 case ATK_TEXT_BOUNDARY_LINE_END:
8174 icon_view = GTK_ICON_VIEW (item->widget);
8175 /* FIXME we probably have to use GailTextCell to salvage this */
8176 gtk_icon_view_update_item_text (icon_view, item->item);
8177 get_pango_text_offsets (icon_view->priv->layout,
8191 *start_offset = gtk_text_iter_get_offset (&start);
8192 *end_offset = gtk_text_iter_get_offset (&end);
8194 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8198 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8200 AtkTextBoundary boundary_type,
8204 GtkIconViewItemAccessible *item;
8205 GtkTextIter start, end;
8206 GtkTextBuffer *buffer;
8208 GtkIconView *icon_view;
8211 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8213 if (!GTK_IS_ICON_VIEW (item->widget))
8216 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8219 buffer = item->text_buffer;
8221 if (!gtk_text_buffer_get_char_count (buffer))
8225 return g_strdup ("");
8227 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8231 switch (boundary_type)
8233 case ATK_TEXT_BOUNDARY_CHAR:
8234 gtk_text_iter_forward_char(&start);
8235 gtk_text_iter_forward_chars(&end, 2);
8237 case ATK_TEXT_BOUNDARY_WORD_START:
8238 if (gtk_text_iter_inside_word (&end))
8239 gtk_text_iter_forward_word_end (&end);
8240 while (!gtk_text_iter_starts_word (&end))
8242 if (!gtk_text_iter_forward_char (&end))
8246 if (!gtk_text_iter_is_end (&end))
8248 gtk_text_iter_forward_word_end (&end);
8249 while (!gtk_text_iter_starts_word (&end))
8251 if (!gtk_text_iter_forward_char (&end))
8256 case ATK_TEXT_BOUNDARY_WORD_END:
8257 gtk_text_iter_forward_word_end (&end);
8259 if (!gtk_text_iter_is_end (&end))
8260 gtk_text_iter_forward_word_end (&end);
8262 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8263 if (gtk_text_iter_inside_sentence (&end))
8264 gtk_text_iter_forward_sentence_end (&end);
8265 while (!gtk_text_iter_starts_sentence (&end))
8267 if (!gtk_text_iter_forward_char (&end))
8271 if (!gtk_text_iter_is_end (&end))
8273 gtk_text_iter_forward_sentence_end (&end);
8274 while (!gtk_text_iter_starts_sentence (&end))
8276 if (!gtk_text_iter_forward_char (&end))
8281 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8282 gtk_text_iter_forward_sentence_end (&end);
8284 if (!gtk_text_iter_is_end (&end))
8285 gtk_text_iter_forward_sentence_end (&end);
8287 case ATK_TEXT_BOUNDARY_LINE_START:
8288 case ATK_TEXT_BOUNDARY_LINE_END:
8290 icon_view = GTK_ICON_VIEW (item->widget);
8291 /* FIXME we probably have to use GailTextCell to salvage this */
8292 gtk_icon_view_update_item_text (icon_view, item->item);
8293 get_pango_text_offsets (icon_view->priv->layout,
8305 *start_offset = gtk_text_iter_get_offset (&start);
8306 *end_offset = gtk_text_iter_get_offset (&end);
8308 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8312 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8314 GtkIconViewItemAccessible *item;
8316 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8318 if (!GTK_IS_ICON_VIEW (item->widget))
8321 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8324 return gtk_text_buffer_get_char_count (item->text_buffer);
8328 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8334 AtkCoordType coord_type)
8336 GtkIconViewItemAccessible *item;
8338 GtkIconView *icon_view;
8339 PangoRectangle char_rect;
8340 const gchar *item_text;
8344 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8346 if (!GTK_IS_ICON_VIEW (item->widget))
8349 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8353 icon_view = GTK_ICON_VIEW (item->widget);
8354 /* FIXME we probably have to use GailTextCell to salvage this */
8355 gtk_icon_view_update_item_text (icon_view, item->item);
8356 item_text = pango_layout_get_text (icon_view->priv->layout);
8357 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8358 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8360 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8361 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8362 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8363 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8364 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8365 *width = char_rect.width / PANGO_SCALE;
8366 *height = char_rect.height / PANGO_SCALE;
8371 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8374 AtkCoordType coord_type)
8376 GtkIconViewItemAccessible *item;
8379 GtkIconView *icon_view;
8380 const gchar *item_text;
8385 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8387 if (!GTK_IS_ICON_VIEW (item->widget))
8390 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8394 icon_view = GTK_ICON_VIEW (item->widget);
8395 /* FIXME we probably have to use GailTextCell to salvage this */
8396 gtk_icon_view_update_item_text (icon_view, item->item);
8397 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8398 x -= l_x + item->item->layout_x - item->item->x;
8399 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8400 y -= l_y + item->item->layout_y - item->item->y;
8401 item_text = pango_layout_get_text (icon_view->priv->layout);
8402 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8413 offset = g_utf8_strlen (item_text, -1);
8415 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8421 atk_text_item_interface_init (AtkTextIface *iface)
8423 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8424 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8425 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8426 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8427 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8428 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8429 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8430 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8434 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8439 AtkCoordType coord_type)
8441 GtkIconViewItemAccessible *item;
8442 AtkObject *parent_obj;
8445 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8447 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8448 if (!GTK_IS_WIDGET (item->widget))
8451 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8454 *width = item->item->width;
8455 *height = item->item->height;
8456 if (gtk_icon_view_item_accessible_is_showing (item))
8458 parent_obj = gtk_widget_get_accessible (item->widget);
8459 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8460 *x = l_x + item->item->x;
8461 *y = l_y + item->item->y;
8471 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8473 GtkIconViewItemAccessible *item;
8474 GtkWidget *toplevel;
8476 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8478 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8479 if (!GTK_IS_WIDGET (item->widget))
8482 gtk_widget_grab_focus (item->widget);
8483 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8484 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8485 if (GTK_WIDGET_TOPLEVEL (toplevel))
8486 gtk_window_present (GTK_WINDOW (toplevel));
8492 atk_component_item_interface_init (AtkComponentIface *iface)
8494 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8495 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8499 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8500 AtkStateType state_type,
8501 gboolean emit_signal)
8505 rc = atk_state_set_add_state (item->state_set, state_type);
8507 * The signal should only be generated if the value changed,
8508 * not when the item is set up. So states that are set
8509 * initially should pass FALSE as the emit_signal argument.
8514 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8515 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8516 if (state_type == ATK_STATE_VISIBLE)
8517 g_signal_emit_by_name (item, "visible-data-changed");
8524 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8525 AtkStateType state_type,
8526 gboolean emit_signal)
8528 if (atk_state_set_contains_state (item->state_set, state_type))
8532 rc = atk_state_set_remove_state (item->state_set, state_type);
8534 * The signal should only be generated if the value changed,
8535 * not when the item is set up. So states that are set
8536 * initially should pass FALSE as the emit_signal argument.
8541 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8542 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8543 if (state_type == ATK_STATE_VISIBLE)
8544 g_signal_emit_by_name (item, "visible-data-changed");
8554 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8556 GtkIconView *icon_view;
8557 GdkRectangle visible_rect;
8558 gboolean is_showing;
8561 * An item is considered "SHOWING" if any part of the item is in the
8562 * visible rectangle.
8565 if (!GTK_IS_ICON_VIEW (item->widget))
8568 if (item->item == NULL)
8571 icon_view = GTK_ICON_VIEW (item->widget);
8573 if (icon_view->priv->hadjustment)
8574 visible_rect.x += icon_view->priv->hadjustment->value;
8576 if (icon_view->priv->hadjustment)
8577 visible_rect.y += icon_view->priv->vadjustment->value;
8578 visible_rect.width = item->widget->allocation.width;
8579 visible_rect.height = item->widget->allocation.height;
8581 if (((item->item->x + item->item->width) < visible_rect.x) ||
8582 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8583 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8584 (item->item->y > (visible_rect.y + visible_rect.height)))
8593 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8594 gboolean emit_signal)
8596 if (gtk_icon_view_item_accessible_is_showing (item))
8597 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8600 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8605 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8609 item->state_set = atk_state_set_new ();
8611 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8612 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8613 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8614 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8615 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8617 for (i = 0; i < LAST_ACTION; i++)
8618 item->action_descriptions[i] = NULL;
8620 item->image_description = NULL;
8622 item->action_idle_handler = 0;
8626 gtk_icon_view_item_accessible_finalize (GObject *object)
8628 GtkIconViewItemAccessible *item;
8631 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8633 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8636 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8638 if (item->state_set)
8639 g_object_unref (item->state_set);
8641 if (item->text_buffer)
8642 g_object_unref (item->text_buffer);
8644 for (i = 0; i < LAST_ACTION; i++)
8645 g_free (item->action_descriptions[i]);
8647 g_free (item->image_description);
8649 if (item->action_idle_handler)
8651 g_source_remove (item->action_idle_handler);
8652 item->action_idle_handler = 0;
8655 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8658 static G_CONST_RETURN gchar*
8659 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8665 GtkIconViewItemAccessible *item;
8666 GtkTextIter start_iter;
8667 GtkTextIter end_iter;
8669 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8671 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8672 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8674 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8679 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8681 GtkIconViewItemAccessible *item;
8683 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8684 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8687 return gtk_widget_get_accessible (item->widget);
8693 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8695 GtkIconViewItemAccessible *item;
8697 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8698 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8700 return item->item->index;
8703 static AtkStateSet *
8704 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8706 GtkIconViewItemAccessible *item;
8707 GtkIconView *icon_view;
8709 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8710 g_return_val_if_fail (item->state_set, NULL);
8715 icon_view = GTK_ICON_VIEW (item->widget);
8716 if (icon_view->priv->cursor_item == item->item)
8717 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8719 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8720 if (item->item->selected)
8721 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8723 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8725 return g_object_ref (item->state_set);
8729 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8731 GObjectClass *gobject_class;
8733 accessible_item_parent_class = g_type_class_peek_parent (klass);
8735 gobject_class = (GObjectClass *)klass;
8737 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8739 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8740 klass->get_name = gtk_icon_view_item_accessible_get_name;
8741 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8742 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8746 gtk_icon_view_item_accessible_get_type (void)
8748 static GType type = 0;
8752 const GTypeInfo tinfo =
8754 sizeof (GtkIconViewItemAccessibleClass),
8755 (GBaseInitFunc) NULL, /* base init */
8756 (GBaseFinalizeFunc) NULL, /* base finalize */
8757 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8758 (GClassFinalizeFunc) NULL, /* class finalize */
8759 NULL, /* class data */
8760 sizeof (GtkIconViewItemAccessible), /* instance size */
8761 0, /* nb preallocs */
8762 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8763 NULL /* value table */
8766 static const GInterfaceInfo atk_component_info =
8768 (GInterfaceInitFunc) atk_component_item_interface_init,
8769 (GInterfaceFinalizeFunc) NULL,
8772 static const GInterfaceInfo atk_action_info =
8774 (GInterfaceInitFunc) atk_action_item_interface_init,
8775 (GInterfaceFinalizeFunc) NULL,
8778 static const GInterfaceInfo atk_image_info =
8780 (GInterfaceInitFunc) atk_image_item_interface_init,
8781 (GInterfaceFinalizeFunc) NULL,
8784 static const GInterfaceInfo atk_text_info =
8786 (GInterfaceInitFunc) atk_text_item_interface_init,
8787 (GInterfaceFinalizeFunc) NULL,
8791 type = g_type_register_static (ATK_TYPE_OBJECT,
8792 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8793 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8794 &atk_component_info);
8795 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8797 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8799 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8806 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8807 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8808 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8810 static GType gtk_icon_view_accessible_get_type (void);
8815 } GtkIconViewAccessible;
8821 } GtkIconViewItemAccessibleInfo;
8827 GtkAdjustment *old_hadj;
8828 GtkAdjustment *old_vadj;
8830 GtkTreeModel *model;
8832 } GtkIconViewAccessiblePrivate;
8834 static GtkIconViewAccessiblePrivate *
8835 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8837 return g_object_get_qdata (G_OBJECT (accessible),
8838 accessible_private_data_quark);
8842 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8846 GtkIconViewItemAccessibleInfo *info;
8847 GtkIconViewItemAccessibleInfo *tmp_info;
8848 GtkIconViewAccessiblePrivate *priv;
8851 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8853 info->index = index;
8855 priv = gtk_icon_view_accessible_get_priv (accessible);
8856 items = priv->items;
8859 tmp_info = items->data;
8860 if (tmp_info->index > index)
8862 items = items->next;
8864 priv->items = g_list_insert_before (priv->items, items, info);
8865 priv->old_hadj = NULL;
8866 priv->old_vadj = NULL;
8870 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8872 GtkIconView *icon_view;
8875 widget = GTK_ACCESSIBLE (accessible)->widget;
8879 icon_view = GTK_ICON_VIEW (widget);
8881 return g_list_length (icon_view->priv->items);
8885 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8888 GtkIconViewAccessiblePrivate *priv;
8889 GtkIconViewItemAccessibleInfo *info;
8892 priv = gtk_icon_view_accessible_get_priv (accessible);
8893 items = priv->items;
8898 if (info->index == index)
8900 items = items->next;
8906 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8909 GtkIconView *icon_view;
8913 GtkIconViewItemAccessible *a11y_item;
8915 widget = GTK_ACCESSIBLE (accessible)->widget;
8919 icon_view = GTK_ICON_VIEW (widget);
8920 icons = g_list_nth (icon_view->priv->items, index);
8924 GtkIconViewItem *item = icons->data;
8926 g_return_val_if_fail (item->index == index, NULL);
8927 obj = gtk_icon_view_accessible_find_child (accessible, index);
8932 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8933 gtk_icon_view_item_accessible_info_new (accessible,
8936 obj->role = ATK_ROLE_ICON;
8937 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8938 a11y_item->item = item;
8939 a11y_item->widget = widget;
8940 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8942 gtk_icon_view_set_cell_data (icon_view, item);
8943 text = get_text (icon_view, item);
8946 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8950 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8951 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8959 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8962 GtkIconViewAccessiblePrivate *priv;
8963 GtkIconViewItemAccessibleInfo *info;
8964 GtkIconViewItemAccessible *item;
8967 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8971 gboolean act_on_item;
8973 widget = GTK_ACCESSIBLE (view)->widget;
8977 items = priv->items;
8979 act_on_item = (list == NULL);
8984 info = (GtkIconViewItemAccessibleInfo *)items->data;
8985 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8987 if (act_on_item == FALSE && list == items)
8991 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8993 items = items->next;
8999 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9000 GtkIconView *icon_view)
9003 GtkIconViewAccessible *view;
9006 * The scrollbars have changed
9008 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9009 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9011 gtk_icon_view_accessible_traverse_items (view, NULL);
9015 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9016 GtkAdjustment *hadj,
9017 GtkAdjustment *vadj)
9020 GtkIconViewAccessiblePrivate *priv;
9022 atk_obj = gtk_widget_get_accessible (widget);
9023 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9025 if (priv->old_hadj != hadj)
9029 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9030 (gpointer *)&priv->old_hadj);
9032 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9033 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9036 priv->old_hadj = hadj;
9039 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9040 (gpointer *)&priv->old_hadj);
9041 g_signal_connect (hadj,
9043 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9047 if (priv->old_vadj != vadj)
9051 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9052 (gpointer *)&priv->old_vadj);
9054 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9055 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9058 priv->old_vadj = vadj;
9061 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9062 (gpointer *)&priv->old_vadj);
9063 g_signal_connect (vadj,
9065 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9072 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9080 GtkIconView *icon_view;
9081 GtkIconViewItem *item;
9082 GtkIconViewAccessible *a11y_view;
9083 GtkIconViewItemAccessible *a11y_item;
9087 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9088 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9089 index = gtk_tree_path_get_indices(path)[0];
9090 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9091 gtk_icon_view_accessible_find_child (atk_obj, index));
9095 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9096 icon_view = GTK_ICON_VIEW (widget);
9097 item = a11y_item->item;
9099 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9101 if (!name || strcmp (name, "") == 0)
9103 gtk_icon_view_set_cell_data (icon_view, item);
9104 text = get_text (icon_view, item);
9107 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9113 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9119 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9124 GtkIconViewAccessiblePrivate *priv;
9125 GtkIconViewItemAccessibleInfo *info;
9126 GtkIconViewAccessible *view;
9127 GtkIconViewItemAccessible *item;
9133 index = gtk_tree_path_get_indices(path)[0];
9134 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9135 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9136 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9138 items = priv->items;
9143 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9144 if (info->index != item->item->index)
9146 if (info->index < index)
9147 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9149 if (tmp_list == NULL)
9152 info->index = item->item->index;
9155 items = items->next;
9157 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9158 g_signal_emit_by_name (atk_obj, "children-changed::add",
9164 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9168 GtkIconViewAccessiblePrivate *priv;
9169 GtkIconViewItemAccessibleInfo *info;
9170 GtkIconViewAccessible *view;
9171 GtkIconViewItemAccessible *item;
9174 GList *deleted_item;
9178 index = gtk_tree_path_get_indices(path)[0];
9179 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9180 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9181 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9183 items = priv->items;
9185 deleted_item = NULL;
9190 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9191 if (info->index == index)
9193 deleted_item = items;
9195 if (info->index != item->item->index)
9197 if (tmp_list == NULL)
9200 info->index = item->item->index;
9203 items = items->next;
9205 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9208 info = deleted_item->data;
9209 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9210 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9212 priv->items = g_list_remove_link (priv->items, deleted_item);
9220 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9221 GtkIconViewItemAccessibleInfo *i2)
9223 return i1->index - i2->index;
9227 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9233 GtkIconViewAccessiblePrivate *priv;
9234 GtkIconViewItemAccessibleInfo *info;
9235 GtkIconView *icon_view;
9236 GtkIconViewItemAccessible *item;
9242 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9243 icon_view = GTK_ICON_VIEW (user_data);
9244 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9246 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9248 order = g_new (gint, length);
9249 for (i = 0; i < length; i++)
9250 order [new_order[i]] = i;
9252 items = priv->items;
9256 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9257 info->index = order[info->index];
9258 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9259 items = items->next;
9262 priv->items = g_list_sort (priv->items,
9263 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9269 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9274 obj = G_OBJECT (model);
9275 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9276 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9277 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9278 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9282 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9286 obj = G_OBJECT (icon_view->priv->model);
9287 g_signal_connect_data (obj, "row-changed",
9288 (GCallback) gtk_icon_view_accessible_model_row_changed,
9289 icon_view, NULL, 0);
9290 g_signal_connect_data (obj, "row-inserted",
9291 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9292 icon_view, NULL, G_CONNECT_AFTER);
9293 g_signal_connect_data (obj, "row-deleted",
9294 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9295 icon_view, NULL, G_CONNECT_AFTER);
9296 g_signal_connect_data (obj, "rows-reordered",
9297 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9298 icon_view, NULL, G_CONNECT_AFTER);
9302 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9304 GtkIconViewItemAccessibleInfo *info;
9307 items = priv->items;
9310 info = (GtkIconViewItemAccessibleInfo *) items->data;
9311 g_object_unref (info->item);
9312 g_free (items->data);
9313 items = items->next;
9315 g_list_free (priv->items);
9320 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9323 GtkIconView *icon_view;
9326 GtkIconViewAccessiblePrivate *priv;
9328 if (strcmp (pspec->name, "model") == 0)
9330 widget = GTK_WIDGET (obj);
9331 atk_obj = gtk_widget_get_accessible (widget);
9332 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9335 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9336 (gpointer *)&priv->model);
9337 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9339 gtk_icon_view_accessible_clear_cache (priv);
9341 icon_view = GTK_ICON_VIEW (obj);
9342 priv->model = icon_view->priv->model;
9343 /* If there is no model the GtkIconView is probably being destroyed */
9346 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9347 gtk_icon_view_accessible_connect_model_signals (icon_view);
9355 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9358 GtkIconViewAccessiblePrivate *priv;
9359 GtkIconView *icon_view;
9361 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9362 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9364 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9365 g_object_set_qdata (G_OBJECT (accessible),
9366 accessible_private_data_quark,
9369 icon_view = GTK_ICON_VIEW (data);
9370 if (icon_view->priv->hadjustment)
9372 priv->old_hadj = icon_view->priv->hadjustment;
9373 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9374 g_signal_connect (icon_view->priv->hadjustment,
9376 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9379 if (icon_view->priv->vadjustment)
9381 priv->old_vadj = icon_view->priv->vadjustment;
9382 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9383 g_signal_connect (icon_view->priv->vadjustment,
9385 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9388 g_signal_connect_after (data,
9389 "set-scroll-adjustments",
9390 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9392 g_signal_connect (data,
9394 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9397 priv->model = icon_view->priv->model;
9400 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9401 gtk_icon_view_accessible_connect_model_signals (icon_view);
9404 accessible->role = ATK_ROLE_LAYERED_PANE;
9408 gtk_icon_view_accessible_finalize (GObject *object)
9410 GtkIconViewAccessiblePrivate *priv;
9412 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9413 gtk_icon_view_accessible_clear_cache (priv);
9417 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9421 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9422 GtkAccessible *accessible)
9425 GtkIconViewAccessiblePrivate *priv;
9427 atk_obj = ATK_OBJECT (accessible);
9428 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9431 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9432 (gpointer *)&priv->old_hadj);
9434 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9435 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9437 priv->old_hadj = NULL;
9441 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9442 (gpointer *)&priv->old_vadj);
9444 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9445 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9447 priv->old_vadj = NULL;
9452 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9454 if (accessible->widget)
9456 g_signal_connect_after (accessible->widget,
9458 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9461 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9465 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9467 GObjectClass *gobject_class;
9468 GtkAccessibleClass *accessible_class;
9470 accessible_parent_class = g_type_class_peek_parent (klass);
9472 gobject_class = (GObjectClass *)klass;
9473 accessible_class = (GtkAccessibleClass *)klass;
9475 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9477 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9478 klass->ref_child = gtk_icon_view_accessible_ref_child;
9479 klass->initialize = gtk_icon_view_accessible_initialize;
9481 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9483 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9487 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9490 AtkCoordType coord_type)
9493 GtkIconView *icon_view;
9494 GtkIconViewItem *item;
9497 widget = GTK_ACCESSIBLE (component)->widget;
9499 /* State is defunct */
9502 icon_view = GTK_ICON_VIEW (widget);
9503 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9504 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9506 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9512 atk_component_interface_init (AtkComponentIface *iface)
9514 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9518 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9522 GtkIconView *icon_view;
9523 GtkIconViewItem *item;
9525 widget = GTK_ACCESSIBLE (selection)->widget;
9529 icon_view = GTK_ICON_VIEW (widget);
9531 item = g_list_nth_data (icon_view->priv->items, i);
9536 gtk_icon_view_select_item (icon_view, item);
9542 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9545 GtkIconView *icon_view;
9547 widget = GTK_ACCESSIBLE (selection)->widget;
9551 icon_view = GTK_ICON_VIEW (widget);
9552 gtk_icon_view_unselect_all (icon_view);
9558 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9563 GtkIconView *icon_view;
9564 GtkIconViewItem *item;
9566 widget = GTK_ACCESSIBLE (selection)->widget;
9570 icon_view = GTK_ICON_VIEW (widget);
9572 l = icon_view->priv->items;
9579 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9590 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9593 GtkIconView *icon_view;
9594 GtkIconViewItem *item;
9598 widget = GTK_ACCESSIBLE (selection)->widget;
9602 icon_view = GTK_ICON_VIEW (widget);
9604 l = icon_view->priv->items;
9620 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9624 GtkIconView *icon_view;
9625 GtkIconViewItem *item;
9627 widget = GTK_ACCESSIBLE (selection)->widget;
9631 icon_view = GTK_ICON_VIEW (widget);
9633 item = g_list_nth_data (icon_view->priv->items, i);
9637 return item->selected;
9641 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9645 GtkIconView *icon_view;
9646 GtkIconViewItem *item;
9650 widget = GTK_ACCESSIBLE (selection)->widget;
9654 icon_view = GTK_ICON_VIEW (widget);
9655 l = icon_view->priv->items;
9664 gtk_icon_view_unselect_item (icon_view, item);
9676 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9679 GtkIconView *icon_view;
9681 widget = GTK_ACCESSIBLE (selection)->widget;
9685 icon_view = GTK_ICON_VIEW (widget);
9686 gtk_icon_view_select_all (icon_view);
9691 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9693 iface->add_selection = gtk_icon_view_accessible_add_selection;
9694 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9695 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9696 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9697 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9698 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9699 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9703 gtk_icon_view_accessible_get_type (void)
9705 static GType type = 0;
9709 static GTypeInfo tinfo =
9712 (GBaseInitFunc) NULL, /* base init */
9713 (GBaseFinalizeFunc) NULL, /* base finalize */
9714 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9715 (GClassFinalizeFunc) NULL, /* class finalize */
9716 NULL, /* class data */
9717 0, /* instance size */
9718 0, /* nb preallocs */
9719 (GInstanceInitFunc) NULL, /* instance init */
9720 NULL /* value table */
9722 static const GInterfaceInfo atk_component_info =
9724 (GInterfaceInitFunc) atk_component_interface_init,
9725 (GInterfaceFinalizeFunc) NULL,
9728 static const GInterfaceInfo atk_selection_info =
9730 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9731 (GInterfaceFinalizeFunc) NULL,
9736 * Figure out the size of the class and instance
9737 * we are deriving from
9739 AtkObjectFactory *factory;
9742 GType derived_atk_type;
9744 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9745 factory = atk_registry_get_factory (atk_get_default_registry (),
9747 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9748 g_type_query (derived_atk_type, &query);
9749 tinfo.class_size = query.class_size;
9750 tinfo.instance_size = query.instance_size;
9752 type = g_type_register_static (derived_atk_type,
9753 I_("GtkIconViewAccessible"),
9755 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9756 &atk_component_info);
9757 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9758 &atk_selection_info);
9764 gtk_icon_view_accessible_new (GObject *obj)
9766 AtkObject *accessible;
9768 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9770 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9771 atk_object_initialize (accessible, obj);
9777 gtk_icon_view_accessible_factory_get_accessible_type (void)
9779 return gtk_icon_view_accessible_get_type ();
9783 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9785 return gtk_icon_view_accessible_new (obj);
9789 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9791 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9792 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9796 gtk_icon_view_accessible_factory_get_type (void)
9798 static GType type = 0;
9802 const GTypeInfo tinfo =
9804 sizeof (AtkObjectFactoryClass),
9805 NULL, /* base_init */
9806 NULL, /* base_finalize */
9807 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9808 NULL, /* class_finalize */
9809 NULL, /* class_data */
9810 sizeof (AtkObjectFactory),
9811 0, /* n_preallocs */
9815 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9816 I_("GtkIconViewAccessibleFactory"),
9824 gtk_icon_view_get_accessible (GtkWidget *widget)
9826 static gboolean first_time = TRUE;
9830 AtkObjectFactory *factory;
9831 AtkRegistry *registry;
9833 GType derived_atk_type;
9836 * Figure out whether accessibility is enabled by looking at the
9837 * type of the accessible object which would be created for
9838 * the parent type of GtkIconView.
9840 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9842 registry = atk_get_default_registry ();
9843 factory = atk_registry_get_factory (registry,
9845 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9846 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9847 atk_registry_set_factory_type (registry,
9849 gtk_icon_view_accessible_factory_get_type ());
9852 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9856 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9857 GtkBuilder *builder,
9859 const gchar *tagname,
9860 GMarkupParser *parser,
9863 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9864 tagname, parser, data))
9867 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9868 tagname, parser, data);
9872 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9873 GtkBuilder *builder,
9875 const gchar *tagname,
9878 if (strcmp (tagname, "attributes") == 0)
9879 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9882 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9888 #define __GTK_ICON_VIEW_C__
9889 #include "gtkaliasdef.c"