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;
127 GdkDevice *rubberband_device;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
165 GdkModifierType start_button_mask;
170 GdkDragAction source_actions;
171 GdkDragAction dest_actions;
173 GtkTreeRowReference *dest_item;
174 GtkIconViewDropPosition dest_pos;
177 GtkTreeRowReference *scroll_to_path;
178 gfloat scroll_to_row_align;
179 gfloat scroll_to_col_align;
180 guint scroll_to_use_align : 1;
182 guint source_set : 1;
184 guint reorderable : 1;
185 guint empty_view_drop :1;
187 guint ctrl_pressed : 1;
188 guint shift_pressed : 1;
190 guint draw_focus : 1;
203 ACTIVATE_CURSOR_ITEM,
229 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
230 static void gtk_icon_view_finalize (GObject *object);
231 static void gtk_icon_view_set_property (GObject *object,
235 static void gtk_icon_view_get_property (GObject *object,
240 /* GtkObject vfuncs */
241 static void gtk_icon_view_destroy (GtkObject *object);
243 /* GtkWidget vfuncs */
244 static void gtk_icon_view_realize (GtkWidget *widget);
245 static void gtk_icon_view_unrealize (GtkWidget *widget);
246 static void gtk_icon_view_style_set (GtkWidget *widget,
247 GtkStyle *previous_style);
248 static void gtk_icon_view_state_changed (GtkWidget *widget,
249 GtkStateType previous_state);
250 static void gtk_icon_view_size_request (GtkWidget *widget,
251 GtkRequisition *requisition);
252 static void gtk_icon_view_size_allocate (GtkWidget *widget,
253 GtkAllocation *allocation);
254 static gboolean gtk_icon_view_expose (GtkWidget *widget,
255 GdkEventExpose *expose);
256 static gboolean gtk_icon_view_motion (GtkWidget *widget,
257 GdkEventMotion *event);
258 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
259 GdkEventButton *event);
260 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
261 GdkEventButton *event);
262 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
264 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
266 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
269 /* GtkContainer vfuncs */
270 static void gtk_icon_view_remove (GtkContainer *container,
272 static void gtk_icon_view_forall (GtkContainer *container,
273 gboolean include_internals,
274 GtkCallback callback,
275 gpointer callback_data);
277 /* GtkIconView vfuncs */
278 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
280 GtkAdjustment *vadj);
281 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
282 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
283 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
284 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
285 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
287 /* Internal functions */
288 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
289 GtkIconView *icon_view);
290 static void gtk_icon_view_layout (GtkIconView *icon_view);
291 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
294 GtkIconViewItem *item,
296 GdkDrawable *drawable,
299 gboolean draw_focus);
300 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
303 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
305 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
306 GtkIconViewItem *item);
307 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
308 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
309 GtkIconViewItem *item,
311 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
315 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
316 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
317 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
318 GtkIconViewItem *item,
323 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
324 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
325 GtkIconViewItem *item);
326 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
327 GtkIconViewItem *item,
329 static void gtk_icon_view_update_rubberband (gpointer data);
330 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
331 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
332 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
335 GtkMovementStep step,
337 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
338 GtkMovementStep step,
340 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
342 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
344 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
346 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
348 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
349 GtkIconViewItem *item);
350 static void gtk_icon_view_select_item (GtkIconView *icon_view,
351 GtkIconViewItem *item);
352 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
353 GtkIconViewItem *item);
354 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
355 GtkIconViewItem *anchor,
356 GtkIconViewItem *cursor);
357 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
360 gboolean only_in_cell,
361 GtkIconViewCellInfo **cell_at_pos);
362 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
363 GtkIconViewItem *item,
364 GtkIconViewCellInfo *cell_info,
365 GdkRectangle *cell_area);
366 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
367 GtkIconViewItem *item,
368 GtkIconViewCellInfo *info,
370 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
371 GtkCellRenderer *renderer);
372 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
373 GtkIconViewItem *item);
374 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
375 GtkCellRenderer *renderer,
377 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
378 GtkCellRenderer *renderer,
380 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
381 GtkCellRenderer *renderer,
382 const gchar *attribute,
384 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
385 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
386 GtkCellRenderer *renderer);
387 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
388 GtkCellRenderer *cell,
389 GtkCellLayoutDataFunc func,
391 GDestroyNotify destroy);
392 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
393 GtkCellRenderer *cell,
395 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
397 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
398 GtkIconViewItem *item,
399 GtkIconViewCellInfo *cell_info,
401 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
402 GtkIconViewItem *item);
403 static void gtk_icon_view_put (GtkIconView *icon_view,
405 GtkIconViewItem *item,
407 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
408 GtkIconView *icon_view);
409 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
410 GtkIconViewItem *item,
411 GtkIconViewCellInfo *cell_info,
413 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
414 gboolean cancel_editing);
416 /* Source side drag signals */
417 static void gtk_icon_view_drag_begin (GtkWidget *widget,
418 GdkDragContext *context);
419 static void gtk_icon_view_drag_end (GtkWidget *widget,
420 GdkDragContext *context);
421 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
422 GdkDragContext *context,
423 GtkSelectionData *selection_data,
426 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
427 GdkDragContext *context);
429 /* Target side drag signals */
430 static void gtk_icon_view_drag_leave (GtkWidget *widget,
431 GdkDragContext *context,
433 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
434 GdkDragContext *context,
438 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
439 GdkDragContext *context,
443 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
444 GdkDragContext *context,
447 GtkSelectionData *selection_data,
450 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
451 GdkEventMotion *event);
453 static void remove_scroll_timeout (GtkIconView *icon_view);
455 static void adjust_wrap_width (GtkIconView *icon_view,
456 GtkIconViewItem *item);
459 static GtkBuildableIface *parent_buildable_iface;
460 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
461 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
464 const gchar *tagname,
465 GMarkupParser *parser,
467 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
470 const gchar *tagname,
473 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
475 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
476 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
477 gtk_icon_view_cell_layout_init)
478 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
479 gtk_icon_view_buildable_init))
482 gtk_icon_view_class_init (GtkIconViewClass *klass)
484 GObjectClass *gobject_class;
485 GtkObjectClass *object_class;
486 GtkWidgetClass *widget_class;
487 GtkContainerClass *container_class;
488 GtkBindingSet *binding_set;
490 binding_set = gtk_binding_set_by_class (klass);
492 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
494 gobject_class = (GObjectClass *) klass;
495 object_class = (GtkObjectClass *) klass;
496 widget_class = (GtkWidgetClass *) klass;
497 container_class = (GtkContainerClass *) klass;
499 gobject_class->finalize = gtk_icon_view_finalize;
500 gobject_class->set_property = gtk_icon_view_set_property;
501 gobject_class->get_property = gtk_icon_view_get_property;
503 object_class->destroy = gtk_icon_view_destroy;
505 widget_class->realize = gtk_icon_view_realize;
506 widget_class->unrealize = gtk_icon_view_unrealize;
507 widget_class->style_set = gtk_icon_view_style_set;
508 widget_class->get_accessible = gtk_icon_view_get_accessible;
509 widget_class->size_request = gtk_icon_view_size_request;
510 widget_class->size_allocate = gtk_icon_view_size_allocate;
511 widget_class->expose_event = gtk_icon_view_expose;
512 widget_class->motion_notify_event = gtk_icon_view_motion;
513 widget_class->button_press_event = gtk_icon_view_button_press;
514 widget_class->button_release_event = gtk_icon_view_button_release;
515 widget_class->key_press_event = gtk_icon_view_key_press;
516 widget_class->key_release_event = gtk_icon_view_key_release;
517 widget_class->drag_begin = gtk_icon_view_drag_begin;
518 widget_class->drag_end = gtk_icon_view_drag_end;
519 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
520 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
521 widget_class->drag_leave = gtk_icon_view_drag_leave;
522 widget_class->drag_motion = gtk_icon_view_drag_motion;
523 widget_class->drag_drop = gtk_icon_view_drag_drop;
524 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
525 widget_class->state_changed = gtk_icon_view_state_changed;
527 container_class->remove = gtk_icon_view_remove;
528 container_class->forall = gtk_icon_view_forall;
530 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
531 klass->select_all = gtk_icon_view_real_select_all;
532 klass->unselect_all = gtk_icon_view_real_unselect_all;
533 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
534 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
535 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
536 klass->move_cursor = gtk_icon_view_real_move_cursor;
540 * GtkIconView:selection-mode:
542 * The ::selection-mode property specifies the selection mode of
543 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
544 * is enabled, for the other modes, only keyboard selection is possible.
548 g_object_class_install_property (gobject_class,
550 g_param_spec_enum ("selection-mode",
551 P_("Selection mode"),
552 P_("The selection mode"),
553 GTK_TYPE_SELECTION_MODE,
554 GTK_SELECTION_SINGLE,
555 GTK_PARAM_READWRITE));
558 * GtkIconView:pixbuf-column:
560 * The ::pixbuf-column property contains the number of the model column
561 * containing the pixbufs which are displayed. The pixbuf column must be
562 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
563 * display of pixbufs.
567 g_object_class_install_property (gobject_class,
569 g_param_spec_int ("pixbuf-column",
571 P_("Model column used to retrieve the icon pixbuf from"),
573 GTK_PARAM_READWRITE));
576 * GtkIconView:text-column:
578 * The ::text-column property contains the number of the model column
579 * containing the texts which are displayed. The text column must be
580 * of type #G_TYPE_STRING. If this property and the :markup-column
581 * property are both set to -1, no texts are displayed.
585 g_object_class_install_property (gobject_class,
587 g_param_spec_int ("text-column",
589 P_("Model column used to retrieve the text from"),
591 GTK_PARAM_READWRITE));
595 * GtkIconView:markup-column:
597 * The ::markup-column property contains the number of the model column
598 * containing markup information to be displayed. The markup column must be
599 * of type #G_TYPE_STRING. If this property and the :text-column property
600 * are both set to column numbers, it overrides the text column.
601 * If both are set to -1, no texts are displayed.
605 g_object_class_install_property (gobject_class,
607 g_param_spec_int ("markup-column",
609 P_("Model column used to retrieve the text if using Pango markup"),
611 GTK_PARAM_READWRITE));
613 g_object_class_install_property (gobject_class,
615 g_param_spec_object ("model",
616 P_("Icon View Model"),
617 P_("The model for the icon view"),
619 GTK_PARAM_READWRITE));
622 * GtkIconView:columns:
624 * The columns property contains the number of the columns in which the
625 * items should be displayed. If it is -1, the number of columns will
626 * be chosen automatically to fill the available area.
630 g_object_class_install_property (gobject_class,
632 g_param_spec_int ("columns",
633 P_("Number of columns"),
634 P_("Number of columns to display"),
636 GTK_PARAM_READWRITE));
640 * GtkIconView:item-width:
642 * The item-width property specifies the width to use for each item.
643 * If it is set to -1, the icon view will automatically determine a
644 * suitable item size.
648 g_object_class_install_property (gobject_class,
650 g_param_spec_int ("item-width",
651 P_("Width for each item"),
652 P_("The width used for each item"),
654 GTK_PARAM_READWRITE));
657 * GtkIconView:spacing:
659 * The spacing property specifies the space which is inserted between
660 * the cells (i.e. the icon and the text) of an item.
664 g_object_class_install_property (gobject_class,
666 g_param_spec_int ("spacing",
668 P_("Space which is inserted between cells of an item"),
670 GTK_PARAM_READWRITE));
673 * GtkIconView:row-spacing:
675 * The row-spacing property specifies the space which is inserted between
676 * the rows of the icon view.
680 g_object_class_install_property (gobject_class,
682 g_param_spec_int ("row-spacing",
684 P_("Space which is inserted between grid rows"),
686 GTK_PARAM_READWRITE));
689 * GtkIconView:column-spacing:
691 * The column-spacing property specifies the space which is inserted between
692 * the columns of the icon view.
696 g_object_class_install_property (gobject_class,
698 g_param_spec_int ("column-spacing",
699 P_("Column Spacing"),
700 P_("Space which is inserted between grid columns"),
702 GTK_PARAM_READWRITE));
705 * GtkIconView:margin:
707 * The margin property specifies the space which is inserted
708 * at the edges of the icon view.
712 g_object_class_install_property (gobject_class,
714 g_param_spec_int ("margin",
716 P_("Space which is inserted at the edges of the icon view"),
718 GTK_PARAM_READWRITE));
721 * GtkIconView:orientation:
723 * The orientation property specifies how the cells (i.e. the icon and
724 * the text) of the item are positioned relative to each other.
728 g_object_class_install_property (gobject_class,
730 g_param_spec_enum ("orientation",
732 P_("How the text and icon of each item are positioned relative to each other"),
733 GTK_TYPE_ORIENTATION,
734 GTK_ORIENTATION_VERTICAL,
735 GTK_PARAM_READWRITE));
738 * GtkIconView:reorderable:
740 * The reorderable property specifies if the items can be reordered
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("reorderable",
749 P_("View is reorderable"),
753 g_object_class_install_property (gobject_class,
755 g_param_spec_int ("tooltip-column",
756 P_("Tooltip Column"),
757 P_("The column in the model containing the tooltip texts for the items"),
761 GTK_PARAM_READWRITE));
764 * GtkIconView:item-padding:
766 * The item-padding property specifies the padding around each
767 * of the icon view's item.
771 g_object_class_install_property (gobject_class,
773 g_param_spec_int ("item-padding",
775 P_("Padding around icon view items"),
777 GTK_PARAM_READWRITE));
781 /* Style properties */
782 gtk_widget_class_install_style_property (widget_class,
783 g_param_spec_boxed ("selection-box-color",
784 P_("Selection Box Color"),
785 P_("Color of the selection box"),
787 GTK_PARAM_READABLE));
789 gtk_widget_class_install_style_property (widget_class,
790 g_param_spec_uchar ("selection-box-alpha",
791 P_("Selection Box Alpha"),
792 P_("Opacity of the selection box"),
795 GTK_PARAM_READABLE));
799 * GtkIconView::set-scroll-adjustments
800 * @horizontal: the horizontal #GtkAdjustment
801 * @vertical: the vertical #GtkAdjustment
803 * Set the scroll adjustments for the icon view. Usually scrolled containers
804 * like #GtkScrolledWindow will emit this signal to connect two instances
805 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
807 widget_class->set_scroll_adjustments_signal =
808 g_signal_new (I_("set-scroll-adjustments"),
809 G_TYPE_FROM_CLASS (gobject_class),
811 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
813 _gtk_marshal_VOID__OBJECT_OBJECT,
815 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
818 * GtkIconView::item-activated:
819 * @iconview: the object on which the signal is emitted
820 * @path: the #GtkTreePath for the activated item
822 * The ::item-activated signal is emitted when the method
823 * gtk_icon_view_item_activated() is called or the user double
824 * clicks an item. It is also emitted when a non-editable item
825 * is selected and one of the keys: Space, Return or Enter is
828 icon_view_signals[ITEM_ACTIVATED] =
829 g_signal_new (I_("item-activated"),
830 G_TYPE_FROM_CLASS (gobject_class),
832 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
834 g_cclosure_marshal_VOID__BOXED,
839 * GtkIconView::selection-changed:
840 * @iconview: the object on which the signal is emitted
842 * The ::selection-changed signal is emitted when the selection
843 * (i.e. the set of selected items) changes.
845 icon_view_signals[SELECTION_CHANGED] =
846 g_signal_new (I_("selection-changed"),
847 G_TYPE_FROM_CLASS (gobject_class),
849 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
851 g_cclosure_marshal_VOID__VOID,
855 * GtkIconView::select-all:
856 * @iconview: the object on which the signal is emitted
858 * A <link linkend="keybinding-signals">keybinding signal</link>
859 * which gets emitted when the user selects all items.
861 * Applications should not connect to it, but may emit it with
862 * g_signal_emit_by_name() if they need to control selection
865 * The default binding for this signal is Ctrl-a.
867 icon_view_signals[SELECT_ALL] =
868 g_signal_new (I_("select-all"),
869 G_TYPE_FROM_CLASS (gobject_class),
870 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
871 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
873 g_cclosure_marshal_VOID__VOID,
877 * GtkIconView::unselect-all:
878 * @iconview: the object on which the signal is emitted
880 * A <link linkend="keybinding-signals">keybinding signal</link>
881 * which gets emitted when the user unselects all items.
883 * Applications should not connect to it, but may emit it with
884 * g_signal_emit_by_name() if they need to control selection
887 * The default binding for this signal is Ctrl-Shift-a.
889 icon_view_signals[UNSELECT_ALL] =
890 g_signal_new (I_("unselect-all"),
891 G_TYPE_FROM_CLASS (gobject_class),
892 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
893 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
895 g_cclosure_marshal_VOID__VOID,
899 * GtkIconView::select-cursor-item:
900 * @iconview: the object on which the signal is emitted
902 * A <link linkend="keybinding-signals">keybinding signal</link>
903 * which gets emitted when the user selects the item that is currently
906 * Applications should not connect to it, but may emit it with
907 * g_signal_emit_by_name() if they need to control selection
910 * There is no default binding for this signal.
912 icon_view_signals[SELECT_CURSOR_ITEM] =
913 g_signal_new (I_("select-cursor-item"),
914 G_TYPE_FROM_CLASS (gobject_class),
915 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
916 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
918 g_cclosure_marshal_VOID__VOID,
922 * GtkIconView::toggle-cursor-item:
923 * @iconview: the object on which the signal is emitted
925 * A <link linkend="keybinding-signals">keybinding signal</link>
926 * which gets emitted when the user toggles whether the currently
927 * focused item is selected or not. The exact effect of this
928 * depend on the selection mode.
930 * Applications should not connect to it, but may emit it with
931 * g_signal_emit_by_name() if they need to control selection
934 * There is no default binding for this signal is Ctrl-Space.
936 icon_view_signals[TOGGLE_CURSOR_ITEM] =
937 g_signal_new (I_("toggle-cursor-item"),
938 G_TYPE_FROM_CLASS (gobject_class),
939 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
940 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
942 g_cclosure_marshal_VOID__VOID,
946 * GtkIconView::activate-cursor-item:
947 * @iconview: the object on which the signal is emitted
949 * A <link linkend="keybinding-signals">keybinding signal</link>
950 * which gets emitted when the user activates the currently
953 * Applications should not connect to it, but may emit it with
954 * g_signal_emit_by_name() if they need to control activation
957 * The default bindings for this signal are Space, Return and Enter.
959 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
960 g_signal_new (I_("activate-cursor-item"),
961 G_TYPE_FROM_CLASS (gobject_class),
962 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
963 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
965 _gtk_marshal_BOOLEAN__VOID,
969 * GtkIconView::move-cursor:
970 * @iconview: the object which received the signal
971 * @step: the granularity of the move, as a #GtkMovementStep
972 * @count: the number of @step units to move
974 * The ::move-cursor signal is a
975 * <link linkend="keybinding-signals">keybinding signal</link>
976 * which gets emitted when the user initiates a cursor movement.
978 * Applications should not connect to it, but may emit it with
979 * g_signal_emit_by_name() if they need to control the cursor
982 * The default bindings for this signal include
984 * <listitem>Arrow keys which move by individual steps</listitem>
985 * <listitem>Home/End keys which move to the first/last item</listitem>
986 * <listitem>PageUp/PageDown which move by "pages"</listitem>
989 * All of these will extend the selection when combined with
990 * the Shift modifier.
992 icon_view_signals[MOVE_CURSOR] =
993 g_signal_new (I_("move-cursor"),
994 G_TYPE_FROM_CLASS (gobject_class),
995 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
996 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
998 _gtk_marshal_BOOLEAN__ENUM_INT,
1000 GTK_TYPE_MOVEMENT_STEP,
1004 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1006 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1008 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1009 "toggle-cursor-item", 0);
1010 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1011 "toggle-cursor-item", 0);
1013 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1014 "activate-cursor-item", 0);
1015 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1016 "activate-cursor-item", 0);
1017 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1018 "activate-cursor-item", 0);
1019 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1020 "activate-cursor-item", 0);
1021 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1022 "activate-cursor-item", 0);
1024 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1025 GTK_MOVEMENT_DISPLAY_LINES, -1);
1026 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1027 GTK_MOVEMENT_DISPLAY_LINES, -1);
1029 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1030 GTK_MOVEMENT_DISPLAY_LINES, 1);
1031 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1032 GTK_MOVEMENT_DISPLAY_LINES, 1);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1035 GTK_MOVEMENT_DISPLAY_LINES, -1);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1038 GTK_MOVEMENT_DISPLAY_LINES, 1);
1040 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1041 GTK_MOVEMENT_BUFFER_ENDS, -1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1043 GTK_MOVEMENT_BUFFER_ENDS, -1);
1045 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1046 GTK_MOVEMENT_BUFFER_ENDS, 1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1048 GTK_MOVEMENT_BUFFER_ENDS, 1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1051 GTK_MOVEMENT_PAGES, -1);
1052 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1053 GTK_MOVEMENT_PAGES, -1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1056 GTK_MOVEMENT_PAGES, 1);
1057 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1058 GTK_MOVEMENT_PAGES, 1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1061 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1062 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1063 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1066 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1067 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1068 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1072 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1074 parent_buildable_iface = g_type_interface_peek_parent (iface);
1075 iface->add_child = _gtk_cell_layout_buildable_add_child;
1076 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1077 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1081 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1083 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1084 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1085 iface->clear = gtk_icon_view_cell_layout_clear;
1086 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1087 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1088 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1089 iface->reorder = gtk_icon_view_cell_layout_reorder;
1090 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1094 gtk_icon_view_init (GtkIconView *icon_view)
1096 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1098 icon_view->priv->width = 0;
1099 icon_view->priv->height = 0;
1100 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1101 icon_view->priv->pressed_button = -1;
1102 icon_view->priv->press_start_x = -1;
1103 icon_view->priv->press_start_y = -1;
1104 icon_view->priv->text_column = -1;
1105 icon_view->priv->markup_column = -1;
1106 icon_view->priv->pixbuf_column = -1;
1107 icon_view->priv->text_cell = -1;
1108 icon_view->priv->pixbuf_cell = -1;
1109 icon_view->priv->tooltip_column = -1;
1111 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1113 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1115 icon_view->priv->cell_list = NULL;
1116 icon_view->priv->n_cells = 0;
1117 icon_view->priv->cursor_cell = -1;
1119 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1121 icon_view->priv->columns = -1;
1122 icon_view->priv->item_width = -1;
1123 icon_view->priv->spacing = 0;
1124 icon_view->priv->row_spacing = 6;
1125 icon_view->priv->column_spacing = 6;
1126 icon_view->priv->margin = 6;
1127 icon_view->priv->item_padding = 6;
1129 icon_view->priv->draw_focus = TRUE;
1133 gtk_icon_view_destroy (GtkObject *object)
1135 GtkIconView *icon_view;
1137 icon_view = GTK_ICON_VIEW (object);
1139 gtk_icon_view_stop_editing (icon_view, TRUE);
1141 gtk_icon_view_set_model (icon_view, NULL);
1143 if (icon_view->priv->layout_idle_id != 0)
1145 g_source_remove (icon_view->priv->layout_idle_id);
1146 icon_view->priv->layout_idle_id = 0;
1149 if (icon_view->priv->scroll_to_path != NULL)
1151 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1152 icon_view->priv->scroll_to_path = NULL;
1155 remove_scroll_timeout (icon_view);
1157 if (icon_view->priv->hadjustment != NULL)
1159 g_object_unref (icon_view->priv->hadjustment);
1160 icon_view->priv->hadjustment = NULL;
1163 if (icon_view->priv->vadjustment != NULL)
1165 g_object_unref (icon_view->priv->vadjustment);
1166 icon_view->priv->vadjustment = NULL;
1169 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1172 /* GObject methods */
1174 gtk_icon_view_finalize (GObject *object)
1176 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1178 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1183 gtk_icon_view_set_property (GObject *object,
1185 const GValue *value,
1188 GtkIconView *icon_view;
1190 icon_view = GTK_ICON_VIEW (object);
1194 case PROP_SELECTION_MODE:
1195 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1197 case PROP_PIXBUF_COLUMN:
1198 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1200 case PROP_TEXT_COLUMN:
1201 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1203 case PROP_MARKUP_COLUMN:
1204 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1207 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1209 case PROP_ORIENTATION:
1210 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1213 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1215 case PROP_ITEM_WIDTH:
1216 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1219 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1221 case PROP_ROW_SPACING:
1222 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1224 case PROP_COLUMN_SPACING:
1225 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1228 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1230 case PROP_REORDERABLE:
1231 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1234 case PROP_TOOLTIP_COLUMN:
1235 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1238 case PROP_ITEM_PADDING:
1239 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1249 gtk_icon_view_get_property (GObject *object,
1254 GtkIconView *icon_view;
1256 icon_view = GTK_ICON_VIEW (object);
1260 case PROP_SELECTION_MODE:
1261 g_value_set_enum (value, icon_view->priv->selection_mode);
1263 case PROP_PIXBUF_COLUMN:
1264 g_value_set_int (value, icon_view->priv->pixbuf_column);
1266 case PROP_TEXT_COLUMN:
1267 g_value_set_int (value, icon_view->priv->text_column);
1269 case PROP_MARKUP_COLUMN:
1270 g_value_set_int (value, icon_view->priv->markup_column);
1273 g_value_set_object (value, icon_view->priv->model);
1275 case PROP_ORIENTATION:
1276 g_value_set_enum (value, icon_view->priv->orientation);
1279 g_value_set_int (value, icon_view->priv->columns);
1281 case PROP_ITEM_WIDTH:
1282 g_value_set_int (value, icon_view->priv->item_width);
1285 g_value_set_int (value, icon_view->priv->spacing);
1287 case PROP_ROW_SPACING:
1288 g_value_set_int (value, icon_view->priv->row_spacing);
1290 case PROP_COLUMN_SPACING:
1291 g_value_set_int (value, icon_view->priv->column_spacing);
1294 g_value_set_int (value, icon_view->priv->margin);
1296 case PROP_REORDERABLE:
1297 g_value_set_boolean (value, icon_view->priv->reorderable);
1299 case PROP_TOOLTIP_COLUMN:
1300 g_value_set_int (value, icon_view->priv->tooltip_column);
1303 case PROP_ITEM_PADDING:
1304 g_value_set_int (value, icon_view->priv->item_padding);
1308 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1313 /* GtkWidget signals */
1315 gtk_icon_view_realize (GtkWidget *widget)
1317 GtkIconView *icon_view;
1318 GdkWindowAttr attributes;
1319 gint attributes_mask;
1321 icon_view = GTK_ICON_VIEW (widget);
1323 gtk_widget_set_realized (widget, TRUE);
1325 /* Make the main, clipping window */
1326 attributes.window_type = GDK_WINDOW_CHILD;
1327 attributes.x = widget->allocation.x;
1328 attributes.y = widget->allocation.y;
1329 attributes.width = widget->allocation.width;
1330 attributes.height = widget->allocation.height;
1331 attributes.wclass = GDK_INPUT_OUTPUT;
1332 attributes.visual = gtk_widget_get_visual (widget);
1333 attributes.colormap = gtk_widget_get_colormap (widget);
1334 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1336 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1338 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1339 &attributes, attributes_mask);
1340 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1341 gdk_window_set_user_data (widget->window, widget);
1343 /* Make the window for the icon view */
1346 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1347 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1348 attributes.event_mask = (GDK_EXPOSURE_MASK |
1350 GDK_POINTER_MOTION_MASK |
1351 GDK_BUTTON_PRESS_MASK |
1352 GDK_BUTTON_RELEASE_MASK |
1353 GDK_KEY_PRESS_MASK |
1354 GDK_KEY_RELEASE_MASK) |
1355 gtk_widget_get_events (widget);
1357 icon_view->priv->bin_window = gdk_window_new (widget->window,
1358 &attributes, attributes_mask);
1359 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1361 widget->style = gtk_style_attach (widget->style, widget->window);
1362 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1364 gdk_window_show (icon_view->priv->bin_window);
1368 gtk_icon_view_unrealize (GtkWidget *widget)
1370 GtkIconView *icon_view;
1372 icon_view = GTK_ICON_VIEW (widget);
1374 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1375 gdk_window_destroy (icon_view->priv->bin_window);
1376 icon_view->priv->bin_window = NULL;
1378 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1382 gtk_icon_view_state_changed (GtkWidget *widget,
1383 GtkStateType previous_state)
1385 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1387 if (gtk_widget_get_realized (widget))
1389 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1390 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1393 gtk_widget_queue_draw (widget);
1397 gtk_icon_view_style_set (GtkWidget *widget,
1398 GtkStyle *previous_style)
1400 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1402 if (gtk_widget_get_realized (widget))
1404 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1405 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1408 gtk_widget_queue_resize (widget);
1412 gtk_icon_view_size_request (GtkWidget *widget,
1413 GtkRequisition *requisition)
1415 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1418 requisition->width = icon_view->priv->width;
1419 requisition->height = icon_view->priv->height;
1421 tmp_list = icon_view->priv->children;
1425 GtkIconViewChild *child = tmp_list->data;
1426 GtkRequisition child_requisition;
1428 tmp_list = tmp_list->next;
1430 if (gtk_widget_get_visible (child->widget))
1431 gtk_widget_size_request (child->widget, &child_requisition);
1436 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1440 for (list = icon_view->priv->children; list; list = list->next)
1442 GtkIconViewChild *child = list->data;
1443 GtkAllocation allocation;
1445 /* totally ignore our child's requisition */
1446 if (child->cell < 0)
1448 allocation.x = child->item->x + icon_view->priv->item_padding;
1449 allocation.y = child->item->y + icon_view->priv->item_padding;
1450 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1451 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1455 GdkRectangle *box = &child->item->box[child->cell];
1457 allocation.x = box->x;
1458 allocation.y = box->y;
1459 allocation.width = box->width;
1460 allocation.height = box->height;
1463 gtk_widget_size_allocate (child->widget, &allocation);
1468 gtk_icon_view_size_allocate (GtkWidget *widget,
1469 GtkAllocation *allocation)
1471 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1473 GtkAdjustment *hadjustment, *vadjustment;
1475 widget->allocation = *allocation;
1477 if (gtk_widget_get_realized (widget))
1479 gdk_window_move_resize (widget->window,
1480 allocation->x, allocation->y,
1481 allocation->width, allocation->height);
1482 gdk_window_resize (icon_view->priv->bin_window,
1483 MAX (icon_view->priv->width, allocation->width),
1484 MAX (icon_view->priv->height, allocation->height));
1487 gtk_icon_view_layout (icon_view);
1489 gtk_icon_view_allocate_children (icon_view);
1491 hadjustment = icon_view->priv->hadjustment;
1492 vadjustment = icon_view->priv->vadjustment;
1494 hadjustment->page_size = allocation->width;
1495 hadjustment->page_increment = allocation->width * 0.9;
1496 hadjustment->step_increment = allocation->width * 0.1;
1497 hadjustment->lower = 0;
1498 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1500 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1501 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1503 vadjustment->page_size = allocation->height;
1504 vadjustment->page_increment = allocation->height * 0.9;
1505 vadjustment->step_increment = allocation->height * 0.1;
1506 vadjustment->lower = 0;
1507 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1509 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1510 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1512 if (gtk_widget_get_realized (widget) &&
1513 icon_view->priv->scroll_to_path)
1516 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1517 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1518 icon_view->priv->scroll_to_path = NULL;
1520 gtk_icon_view_scroll_to_path (icon_view, path,
1521 icon_view->priv->scroll_to_use_align,
1522 icon_view->priv->scroll_to_row_align,
1523 icon_view->priv->scroll_to_col_align);
1524 gtk_tree_path_free (path);
1528 gtk_adjustment_changed (hadjustment);
1529 gtk_adjustment_changed (vadjustment);
1534 gtk_icon_view_expose (GtkWidget *widget,
1535 GdkEventExpose *expose)
1537 GtkIconView *icon_view;
1542 GtkIconViewDropPosition dest_pos;
1543 GtkIconViewItem *dest_item = NULL;
1545 icon_view = GTK_ICON_VIEW (widget);
1547 if (expose->window != icon_view->priv->bin_window)
1550 /* If a layout has been scheduled, do it now so that all
1551 * cell view items have valid sizes before we proceed. */
1552 if (icon_view->priv->layout_idle_id != 0)
1553 gtk_icon_view_layout (icon_view);
1555 cr = gdk_cairo_create (icon_view->priv->bin_window);
1556 cairo_set_line_width (cr, 1.);
1558 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1562 dest_index = gtk_tree_path_get_indices (path)[0];
1563 gtk_tree_path_free (path);
1568 for (icons = icon_view->priv->items; icons; icons = icons->next)
1570 GtkIconViewItem *item = icons->data;
1575 area.width = item->width;
1576 area.height = item->height;
1578 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1581 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1582 icon_view->priv->bin_window,
1584 icon_view->priv->draw_focus);
1586 if (dest_index == item->index)
1594 case GTK_ICON_VIEW_DROP_INTO:
1595 gtk_paint_focus (widget->style,
1596 icon_view->priv->bin_window,
1597 gtk_widget_get_state (widget),
1600 "iconview-drop-indicator",
1601 dest_item->x, dest_item->y,
1602 dest_item->width, dest_item->height);
1604 case GTK_ICON_VIEW_DROP_ABOVE:
1605 gtk_paint_focus (widget->style,
1606 icon_view->priv->bin_window,
1607 gtk_widget_get_state (widget),
1610 "iconview-drop-indicator",
1611 dest_item->x, dest_item->y - 1,
1612 dest_item->width, 2);
1614 case GTK_ICON_VIEW_DROP_LEFT:
1615 gtk_paint_focus (widget->style,
1616 icon_view->priv->bin_window,
1617 gtk_widget_get_state (widget),
1620 "iconview-drop-indicator",
1621 dest_item->x - 1, dest_item->y,
1622 2, dest_item->height);
1624 case GTK_ICON_VIEW_DROP_BELOW:
1625 gtk_paint_focus (widget->style,
1626 icon_view->priv->bin_window,
1627 gtk_widget_get_state (widget),
1630 "iconview-drop-indicator",
1631 dest_item->x, dest_item->y + dest_item->height - 1,
1632 dest_item->width, 2);
1634 case GTK_ICON_VIEW_DROP_RIGHT:
1635 gtk_paint_focus (widget->style,
1636 icon_view->priv->bin_window,
1637 gtk_widget_get_state (widget),
1640 "iconview-drop-indicator",
1641 dest_item->x + dest_item->width - 1, dest_item->y,
1642 2, dest_item->height);
1643 case GTK_ICON_VIEW_NO_DROP: ;
1648 if (icon_view->priv->doing_rubberband)
1650 GdkRectangle *rectangles;
1653 gdk_region_get_rectangles (expose->region,
1657 while (n_rectangles--)
1658 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1660 g_free (rectangles);
1665 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1671 rubberband_scroll_timeout (gpointer data)
1673 GtkIconView *icon_view = data;
1675 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1676 icon_view->priv->vadjustment->value +
1677 icon_view->priv->scroll_value_diff);
1679 gtk_icon_view_update_rubberband (icon_view);
1685 gtk_icon_view_motion (GtkWidget *widget,
1686 GdkEventMotion *event)
1688 GtkIconView *icon_view;
1691 icon_view = GTK_ICON_VIEW (widget);
1693 gtk_icon_view_maybe_begin_drag (icon_view, event);
1695 if (icon_view->priv->doing_rubberband)
1697 gtk_icon_view_update_rubberband (widget);
1699 abs_y = event->y - icon_view->priv->height *
1700 (icon_view->priv->vadjustment->value /
1701 (icon_view->priv->vadjustment->upper -
1702 icon_view->priv->vadjustment->lower));
1704 if (abs_y < 0 || abs_y > widget->allocation.height)
1707 icon_view->priv->scroll_value_diff = abs_y;
1709 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1711 icon_view->priv->event_last_x = event->x;
1712 icon_view->priv->event_last_y = event->y;
1714 if (icon_view->priv->scroll_timeout_id == 0)
1715 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1719 remove_scroll_timeout (icon_view);
1726 gtk_icon_view_remove (GtkContainer *container,
1729 GtkIconView *icon_view;
1730 GtkIconViewChild *child = NULL;
1733 icon_view = GTK_ICON_VIEW (container);
1735 tmp_list = icon_view->priv->children;
1738 child = tmp_list->data;
1739 if (child->widget == widget)
1741 gtk_widget_unparent (widget);
1743 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1744 g_list_free_1 (tmp_list);
1749 tmp_list = tmp_list->next;
1754 gtk_icon_view_forall (GtkContainer *container,
1755 gboolean include_internals,
1756 GtkCallback callback,
1757 gpointer callback_data)
1759 GtkIconView *icon_view;
1760 GtkIconViewChild *child = NULL;
1763 icon_view = GTK_ICON_VIEW (container);
1765 tmp_list = icon_view->priv->children;
1768 child = tmp_list->data;
1769 tmp_list = tmp_list->next;
1771 (* callback) (child->widget, callback_data);
1776 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1777 GtkIconViewItem *item,
1778 GtkIconViewCellInfo *info,
1783 GdkRectangle cell_area;
1784 gboolean visible, mode;
1786 gtk_icon_view_set_cell_data (icon_view, item);
1788 g_object_get (info->cell,
1789 "visible", &visible,
1793 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1795 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1797 path = gtk_tree_path_new_from_indices (item->index, -1);
1798 path_string = gtk_tree_path_to_string (path);
1799 gtk_tree_path_free (path);
1801 gtk_cell_renderer_activate (info->cell,
1803 GTK_WIDGET (icon_view),
1809 g_free (path_string);
1814 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1815 GtkIconViewItem *item)
1818 AtkObject *item_obj;
1820 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1823 item_obj = atk_object_ref_accessible_child (obj, item->index);
1824 if (item_obj != NULL)
1826 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1827 g_object_unref (item_obj);
1833 gtk_icon_view_put (GtkIconView *icon_view,
1835 GtkIconViewItem *item,
1838 GtkIconViewChild *child;
1840 child = g_new (GtkIconViewChild, 1);
1842 child->widget = widget;
1846 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1848 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1849 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1851 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1855 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1856 GtkIconView *icon_view)
1859 GtkIconViewItem *item;
1861 if (icon_view->priv->edited_item == NULL)
1864 item = icon_view->priv->edited_item;
1865 icon_view->priv->edited_item = NULL;
1866 icon_view->priv->editable = NULL;
1867 for (l = icon_view->priv->cell_list; l; l = l->next)
1869 GtkIconViewCellInfo *info = l->data;
1871 info->editing = FALSE;
1874 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1875 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1877 g_signal_handlers_disconnect_by_func (editable,
1878 gtk_icon_view_remove_widget,
1881 gtk_container_remove (GTK_CONTAINER (icon_view),
1882 GTK_WIDGET (editable));
1884 gtk_icon_view_queue_draw_item (icon_view, item);
1889 gtk_icon_view_start_editing (GtkIconView *icon_view,
1890 GtkIconViewItem *item,
1891 GtkIconViewCellInfo *info,
1896 GdkRectangle cell_area;
1897 gboolean visible, mode;
1898 GtkCellEditable *editable;
1900 gtk_icon_view_set_cell_data (icon_view, item);
1902 g_object_get (info->cell,
1903 "visible", &visible,
1906 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1908 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1910 path = gtk_tree_path_new_from_indices (item->index, -1);
1911 path_string = gtk_tree_path_to_string (path);
1912 gtk_tree_path_free (path);
1914 editable = gtk_cell_renderer_start_editing (info->cell,
1916 GTK_WIDGET (icon_view),
1921 g_free (path_string);
1923 /* the rest corresponds to tree_view_real_start_editing... */
1924 icon_view->priv->edited_item = item;
1925 icon_view->priv->editable = editable;
1926 info->editing = TRUE;
1928 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1930 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1932 gtk_widget_grab_focus (GTK_WIDGET (editable));
1933 g_signal_connect (editable, "remove-widget",
1934 G_CALLBACK (gtk_icon_view_remove_widget),
1941 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1942 gboolean cancel_editing)
1944 GtkCellRenderer *cell = NULL;
1945 GtkIconViewItem *item;
1948 if (icon_view->priv->edited_item == NULL)
1952 * This is very evil. We need to do this, because
1953 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1954 * later on. If gtk_icon_view_row_changed notices
1955 * icon_view->priv->edited_item != NULL, it'll call
1956 * gtk_icon_view_stop_editing again. Bad things will happen then.
1958 * Please read that again if you intend to modify anything here.
1961 item = icon_view->priv->edited_item;
1962 icon_view->priv->edited_item = NULL;
1964 for (l = icon_view->priv->cell_list; l; l = l->next)
1966 GtkIconViewCellInfo *info = l->data;
1978 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1979 if (!cancel_editing)
1980 gtk_cell_editable_editing_done (icon_view->priv->editable);
1982 icon_view->priv->edited_item = item;
1984 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1988 * gtk_icon_view_set_cursor:
1989 * @icon_view: A #GtkIconView
1990 * @path: A #GtkTreePath
1991 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
1992 * @start_editing: %TRUE if the specified cell should start being edited.
1994 * Sets the current keyboard focus to be at @path, and selects it. This is
1995 * useful when you want to focus the user's attention on a particular item.
1996 * If @cell is not %NULL, then focus is given to the cell specified by
1997 * it. Additionally, if @start_editing is %TRUE, then editing should be
1998 * started in the specified cell.
2000 * This function is often followed by <literal>gtk_widget_grab_focus
2001 * (icon_view)</literal> in order to give keyboard focus to the widget.
2002 * Please note that editing can only happen when the widget is realized.
2007 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2009 GtkCellRenderer *cell,
2010 gboolean start_editing)
2012 GtkIconViewItem *item = NULL;
2013 GtkIconViewCellInfo *info = NULL;
2017 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2018 g_return_if_fail (path != NULL);
2019 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2021 gtk_icon_view_stop_editing (icon_view, TRUE);
2023 if (gtk_tree_path_get_depth (path) == 1)
2024 item = g_list_nth_data (icon_view->priv->items,
2025 gtk_tree_path_get_indices(path)[0]);
2031 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2035 if (info->cell == cell)
2044 g_return_if_fail (cell == NULL || info != NULL);
2046 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2047 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2049 if (info && start_editing)
2050 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2054 * gtk_icon_view_get_cursor:
2055 * @icon_view: A #GtkIconView
2056 * @path: (allow-none): Return location for the current cursor path, or %NULL
2057 * @cell: (allow-none): Return location the current focus cell, or %NULL
2059 * Fills in @path and @cell with the current cursor path and cell.
2060 * If the cursor isn't currently set, then *@path will be %NULL.
2061 * If no cell currently has focus, then *@cell will be %NULL.
2063 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2065 * Return value: %TRUE if the cursor is set.
2070 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2072 GtkCellRenderer **cell)
2074 GtkIconViewItem *item;
2075 GtkIconViewCellInfo *info;
2077 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2079 item = icon_view->priv->cursor_item;
2080 if (icon_view->priv->cursor_cell < 0)
2083 info = g_list_nth_data (icon_view->priv->cell_list,
2084 icon_view->priv->cursor_cell);
2089 *path = gtk_tree_path_new_from_indices (item->index, -1);
2102 return (item != NULL);
2106 gtk_icon_view_button_press (GtkWidget *widget,
2107 GdkEventButton *event)
2109 GtkIconView *icon_view;
2110 GtkIconViewItem *item;
2111 GtkIconViewCellInfo *info = NULL;
2112 gboolean dirty = FALSE;
2113 GtkCellRendererMode mode;
2114 gint cursor_cell = -1;
2116 icon_view = GTK_ICON_VIEW (widget);
2118 if (event->window != icon_view->priv->bin_window)
2121 if (!gtk_widget_has_focus (widget))
2122 gtk_widget_grab_focus (widget);
2124 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2126 item = gtk_icon_view_get_item_at_coords (icon_view,
2132 * We consider only the the cells' area as the item area if the
2133 * item is not selected, but if it *is* selected, the complete
2134 * selection rectangle is considered to be part of the item.
2136 if (item != NULL && (info != NULL || item->selected))
2140 g_object_get (info->cell, "mode", &mode, NULL);
2142 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2143 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2144 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2147 gtk_icon_view_scroll_to_item (icon_view, item);
2149 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2151 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2153 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2154 (event->state & GDK_SHIFT_MASK))
2156 gtk_icon_view_unselect_all_internal (icon_view);
2158 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2159 if (!icon_view->priv->anchor_item)
2160 icon_view->priv->anchor_item = item;
2162 gtk_icon_view_select_all_between (icon_view,
2163 icon_view->priv->anchor_item,
2169 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2170 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2171 (event->state & GDK_CONTROL_MASK))
2173 item->selected = !item->selected;
2174 gtk_icon_view_queue_draw_item (icon_view, item);
2179 gtk_icon_view_unselect_all_internal (icon_view);
2181 item->selected = TRUE;
2182 gtk_icon_view_queue_draw_item (icon_view, item);
2185 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2186 icon_view->priv->anchor_item = item;
2189 /* Save press to possibly begin a drag */
2190 if (icon_view->priv->pressed_button < 0)
2192 icon_view->priv->pressed_button = event->button;
2193 icon_view->priv->press_start_x = event->x;
2194 icon_view->priv->press_start_y = event->y;
2197 if (!icon_view->priv->last_single_clicked)
2198 icon_view->priv->last_single_clicked = item;
2200 /* cancel the current editing, if it exists */
2201 gtk_icon_view_stop_editing (icon_view, TRUE);
2205 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2206 gtk_icon_view_item_activate_cell (icon_view, item, info,
2208 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2209 gtk_icon_view_start_editing (icon_view, item, info,
2215 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2216 !(event->state & GDK_CONTROL_MASK))
2218 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2221 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2222 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2225 /* don't draw keyboard focus around an clicked-on item */
2226 icon_view->priv->draw_focus = FALSE;
2229 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2231 item = gtk_icon_view_get_item_at_coords (icon_view,
2236 if (item && item == icon_view->priv->last_single_clicked)
2240 path = gtk_tree_path_new_from_indices (item->index, -1);
2241 gtk_icon_view_item_activated (icon_view, path);
2242 gtk_tree_path_free (path);
2245 icon_view->priv->last_single_clicked = NULL;
2246 icon_view->priv->pressed_button = -1;
2250 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2252 return event->button == 1;
2256 gtk_icon_view_button_release (GtkWidget *widget,
2257 GdkEventButton *event)
2259 GtkIconView *icon_view;
2261 icon_view = GTK_ICON_VIEW (widget);
2263 if (icon_view->priv->pressed_button == event->button)
2264 icon_view->priv->pressed_button = -1;
2266 gtk_icon_view_stop_rubberbanding (icon_view);
2268 remove_scroll_timeout (icon_view);
2274 gtk_icon_view_key_press (GtkWidget *widget,
2277 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2279 if (icon_view->priv->doing_rubberband)
2281 if (event->keyval == GDK_Escape)
2282 gtk_icon_view_stop_rubberbanding (icon_view);
2287 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2291 gtk_icon_view_key_release (GtkWidget *widget,
2294 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2296 if (icon_view->priv->doing_rubberband)
2299 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2303 gtk_icon_view_update_rubberband (gpointer data)
2305 GtkIconView *icon_view;
2307 GdkRectangle old_area;
2308 GdkRectangle new_area;
2309 GdkRectangle common;
2310 GdkRegion *invalid_region;
2312 icon_view = GTK_ICON_VIEW (data);
2314 gdk_window_get_device_position (icon_view->priv->bin_window,
2315 icon_view->priv->rubberband_device,
2321 old_area.x = MIN (icon_view->priv->rubberband_x1,
2322 icon_view->priv->rubberband_x2);
2323 old_area.y = MIN (icon_view->priv->rubberband_y1,
2324 icon_view->priv->rubberband_y2);
2325 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2326 icon_view->priv->rubberband_x1) + 1;
2327 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2328 icon_view->priv->rubberband_y1) + 1;
2330 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2331 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2332 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2333 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2335 invalid_region = gdk_region_rectangle (&old_area);
2336 gdk_region_union_with_rect (invalid_region, &new_area);
2338 gdk_rectangle_intersect (&old_area, &new_area, &common);
2339 if (common.width > 2 && common.height > 2)
2341 GdkRegion *common_region;
2343 /* make sure the border is invalidated */
2349 common_region = gdk_region_rectangle (&common);
2351 gdk_region_subtract (invalid_region, common_region);
2352 gdk_region_destroy (common_region);
2355 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2357 gdk_region_destroy (invalid_region);
2359 icon_view->priv->rubberband_x2 = x;
2360 icon_view->priv->rubberband_y2 = y;
2362 gtk_icon_view_update_rubberband_selection (icon_view);
2366 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2373 if (icon_view->priv->rubberband_device)
2376 for (items = icon_view->priv->items; items; items = items->next)
2378 GtkIconViewItem *item = items->data;
2380 item->selected_before_rubberbanding = item->selected;
2383 icon_view->priv->rubberband_x1 = x;
2384 icon_view->priv->rubberband_y1 = y;
2385 icon_view->priv->rubberband_x2 = x;
2386 icon_view->priv->rubberband_y2 = y;
2388 icon_view->priv->doing_rubberband = TRUE;
2389 icon_view->priv->rubberband_device = device;
2391 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2395 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2397 if (!icon_view->priv->doing_rubberband)
2400 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2401 icon_view->priv->rubberband_device);
2403 icon_view->priv->doing_rubberband = FALSE;
2404 icon_view->priv->rubberband_device = NULL;
2406 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2410 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2413 gint x, y, width, height;
2414 gboolean dirty = FALSE;
2416 x = MIN (icon_view->priv->rubberband_x1,
2417 icon_view->priv->rubberband_x2);
2418 y = MIN (icon_view->priv->rubberband_y1,
2419 icon_view->priv->rubberband_y2);
2420 width = ABS (icon_view->priv->rubberband_x1 -
2421 icon_view->priv->rubberband_x2);
2422 height = ABS (icon_view->priv->rubberband_y1 -
2423 icon_view->priv->rubberband_y2);
2425 for (items = icon_view->priv->items; items; items = items->next)
2427 GtkIconViewItem *item = items->data;
2431 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2432 x, y, width, height);
2434 selected = is_in ^ item->selected_before_rubberbanding;
2436 if (item->selected != selected)
2438 item->selected = selected;
2440 gtk_icon_view_queue_draw_item (icon_view, item);
2445 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2449 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2450 GtkIconViewItem *item,
2459 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2460 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2463 for (l = icon_view->priv->cell_list; l; l = l->next)
2465 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2467 if (!info->cell->visible)
2470 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2472 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2473 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2481 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2483 gboolean dirty = FALSE;
2486 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2489 for (items = icon_view->priv->items; items; items = items->next)
2491 GtkIconViewItem *item = items->data;
2495 item->selected = FALSE;
2497 gtk_icon_view_queue_draw_item (icon_view, item);
2498 gtk_icon_view_item_selected_changed (icon_view, item);
2506 /* GtkIconView signals */
2508 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2509 GtkAdjustment *hadj,
2510 GtkAdjustment *vadj)
2512 gboolean need_adjust = FALSE;
2515 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2517 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2519 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2521 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2523 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2525 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2526 0, 0, NULL, NULL, icon_view);
2527 g_object_unref (icon_view->priv->hadjustment);
2530 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2532 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2533 0, 0, NULL, NULL, icon_view);
2534 g_object_unref (icon_view->priv->vadjustment);
2537 if (icon_view->priv->hadjustment != hadj)
2539 icon_view->priv->hadjustment = hadj;
2540 g_object_ref_sink (icon_view->priv->hadjustment);
2542 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2543 G_CALLBACK (gtk_icon_view_adjustment_changed),
2548 if (icon_view->priv->vadjustment != vadj)
2550 icon_view->priv->vadjustment = vadj;
2551 g_object_ref_sink (icon_view->priv->vadjustment);
2553 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2554 G_CALLBACK (gtk_icon_view_adjustment_changed),
2560 gtk_icon_view_adjustment_changed (NULL, icon_view);
2564 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2566 gtk_icon_view_select_all (icon_view);
2570 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2572 gtk_icon_view_unselect_all (icon_view);
2576 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2578 gtk_icon_view_unselect_all (icon_view);
2580 if (icon_view->priv->cursor_item != NULL)
2581 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2585 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2588 GtkCellRendererMode mode;
2589 GtkIconViewCellInfo *info = NULL;
2591 if (!icon_view->priv->cursor_item)
2594 info = g_list_nth_data (icon_view->priv->cell_list,
2595 icon_view->priv->cursor_cell);
2599 g_object_get (info->cell, "mode", &mode, NULL);
2601 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2603 gtk_icon_view_item_activate_cell (icon_view,
2604 icon_view->priv->cursor_item,
2608 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2610 gtk_icon_view_start_editing (icon_view,
2611 icon_view->priv->cursor_item,
2617 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2618 gtk_icon_view_item_activated (icon_view, path);
2619 gtk_tree_path_free (path);
2625 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2627 if (!icon_view->priv->cursor_item)
2630 switch (icon_view->priv->selection_mode)
2632 case GTK_SELECTION_NONE:
2634 case GTK_SELECTION_BROWSE:
2635 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2637 case GTK_SELECTION_SINGLE:
2638 if (icon_view->priv->cursor_item->selected)
2639 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2641 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2643 case GTK_SELECTION_MULTIPLE:
2644 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2645 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2647 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2648 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2653 /* Internal functions */
2655 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2656 GtkIconView *icon_view)
2658 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2660 gdk_window_move (icon_view->priv->bin_window,
2661 - icon_view->priv->hadjustment->value,
2662 - icon_view->priv->vadjustment->value);
2664 if (icon_view->priv->doing_rubberband)
2665 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2667 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2672 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2677 gint *maximum_width)
2680 gint x, current_width;
2681 GList *items, *last_item;
2688 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2689 max_height = g_new0 (gint, icon_view->priv->n_cells);
2696 gtk_widget_style_get (GTK_WIDGET (icon_view),
2697 "focus-line-width", &focus_width,
2700 x += icon_view->priv->margin + focus_width;
2701 current_width += 2 * (icon_view->priv->margin + focus_width);
2706 GtkIconViewItem *item = items->data;
2708 gtk_icon_view_calculate_item_size (icon_view, item);
2709 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2711 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2713 current_width += item->width;
2715 if (items != first_item)
2717 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2718 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2722 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2724 item->y = *y + focus_width;
2727 x = current_width - (icon_view->priv->margin + focus_width);
2729 for (i = 0; i < icon_view->priv->n_cells; i++)
2730 max_height[i] = MAX (max_height[i], item->box[i].height);
2732 if (current_width > *maximum_width)
2733 *maximum_width = current_width;
2739 items = items->next;
2744 /* Now go through the row again and align the icons */
2745 for (items = first_item; items != last_item; items = items->next)
2747 GtkIconViewItem *item = items->data;
2751 item->x = *maximum_width - item->width - item->x;
2752 item->col = col - 1 - item->col;
2755 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2757 /* We may want to readjust the new y coordinate. */
2758 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2759 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2762 g_free (max_height);
2768 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2771 if (upper != adj->upper)
2773 gdouble min = MAX (0.0, upper - adj->page_size);
2774 gboolean value_changed = FALSE;
2778 if (adj->value > min)
2781 value_changed = TRUE;
2784 gtk_adjustment_changed (adj);
2787 gtk_adjustment_value_changed (adj);
2792 gtk_icon_view_layout (GtkIconView *icon_view)
2794 gint y = 0, maximum_width = 0;
2800 if (icon_view->priv->layout_idle_id != 0)
2802 g_source_remove (icon_view->priv->layout_idle_id);
2803 icon_view->priv->layout_idle_id = 0;
2806 if (icon_view->priv->model == NULL)
2809 widget = GTK_WIDGET (icon_view);
2811 item_width = icon_view->priv->item_width;
2815 for (icons = icon_view->priv->items; icons; icons = icons->next)
2817 GtkIconViewItem *item = icons->data;
2818 gtk_icon_view_calculate_item_size (icon_view, item);
2819 item_width = MAX (item_width, item->width);
2824 icons = icon_view->priv->items;
2825 y += icon_view->priv->margin;
2830 gtk_icon_view_set_cell_data (icon_view, icons->data);
2831 adjust_wrap_width (icon_view, icons->data);
2836 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2838 &y, &maximum_width);
2841 while (icons != NULL);
2843 if (maximum_width != icon_view->priv->width)
2844 icon_view->priv->width = maximum_width;
2846 y += icon_view->priv->margin;
2848 if (y != icon_view->priv->height)
2849 icon_view->priv->height = y;
2851 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2852 icon_view->priv->width);
2853 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2854 icon_view->priv->height);
2856 if (icon_view->priv->width != widget->requisition.width ||
2857 icon_view->priv->height != widget->requisition.height)
2858 gtk_widget_queue_resize_no_redraw (widget);
2860 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2861 gdk_window_resize (icon_view->priv->bin_window,
2862 MAX (icon_view->priv->width, widget->allocation.width),
2863 MAX (icon_view->priv->height, widget->allocation.height));
2865 if (icon_view->priv->scroll_to_path)
2869 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2870 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2871 icon_view->priv->scroll_to_path = NULL;
2873 gtk_icon_view_scroll_to_path (icon_view, path,
2874 icon_view->priv->scroll_to_use_align,
2875 icon_view->priv->scroll_to_row_align,
2876 icon_view->priv->scroll_to_col_align);
2877 gtk_tree_path_free (path);
2880 gtk_widget_queue_draw (widget);
2884 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2885 GtkIconViewItem *item,
2886 GtkIconViewCellInfo *info,
2887 GdkRectangle *cell_area)
2889 g_return_if_fail (info->position < item->n_cells);
2891 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2893 cell_area->x = item->box[info->position].x - item->before[info->position];
2894 cell_area->y = item->y + icon_view->priv->item_padding;
2895 cell_area->width = item->box[info->position].width +
2896 item->before[info->position] + item->after[info->position];
2897 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2901 cell_area->x = item->x + icon_view->priv->item_padding;
2902 cell_area->y = item->box[info->position].y - item->before[info->position];
2903 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2904 cell_area->height = item->box[info->position].height +
2905 item->before[info->position] + item->after[info->position];
2910 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2911 GtkIconViewItem *item,
2912 GtkIconViewCellInfo *info,
2915 g_return_if_fail (info->position < item->n_cells);
2917 *box = item->box[info->position];
2920 /* try to guess a reasonable wrap width for an implicit text cell renderer
2923 adjust_wrap_width (GtkIconView *icon_view,
2924 GtkIconViewItem *item)
2926 GtkIconViewCellInfo *text_info;
2927 GtkIconViewCellInfo *pixbuf_info;
2928 gint pixbuf_width, wrap_width;
2930 if (icon_view->priv->text_cell != -1 &&
2931 icon_view->priv->pixbuf_cell != -1)
2935 text_info = g_list_nth_data (icon_view->priv->cell_list,
2936 icon_view->priv->text_cell);
2937 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2938 icon_view->priv->pixbuf_cell);
2940 gtk_cell_renderer_get_size (pixbuf_info->cell,
2941 GTK_WIDGET (icon_view),
2947 if (icon_view->priv->item_width > 0)
2948 item_width = icon_view->priv->item_width;
2950 item_width = item->width;
2952 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2953 wrap_width = item_width;
2955 if (item->width == -1 && item_width <= 0)
2956 wrap_width = MAX (2 * pixbuf_width, 50);
2958 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2961 wrap_width -= icon_view->priv->item_padding * 2;
2963 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2964 g_object_set (text_info->cell, "width", wrap_width, NULL);
2969 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2970 GtkIconViewItem *item)
2975 if (item->width != -1 && item->height != -1)
2978 if (item->n_cells != icon_view->priv->n_cells)
2980 g_free (item->before);
2981 g_free (item->after);
2984 item->before = g_new0 (gint, icon_view->priv->n_cells);
2985 item->after = g_new0 (gint, icon_view->priv->n_cells);
2986 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2988 item->n_cells = icon_view->priv->n_cells;
2991 gtk_icon_view_set_cell_data (icon_view, item);
2993 spacing = icon_view->priv->spacing;
2997 for (l = icon_view->priv->cell_list; l; l = l->next)
2999 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3001 if (!info->cell->visible)
3004 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3006 &item->box[info->position].width,
3007 &item->box[info->position].height);
3009 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3011 item->width += item->box[info->position].width
3012 + (info->position > 0 ? spacing : 0);
3013 item->height = MAX (item->height, item->box[info->position].height);
3017 item->width = MAX (item->width, item->box[info->position].width);
3018 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3022 item->width += icon_view->priv->item_padding * 2;
3023 item->height += icon_view->priv->item_padding * 2;
3027 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3028 GtkIconViewItem *item,
3031 GdkRectangle cell_area;
3037 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3039 gtk_icon_view_set_cell_data (icon_view, item);
3041 spacing = icon_view->priv->spacing;
3044 for (i = 0; i < icon_view->priv->n_cells; i++)
3046 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3047 item->height = MAX (item->height, max_height[i]);
3049 item->height += max_height[i] + (i > 0 ? spacing : 0);
3052 cell_area.x = item->x + icon_view->priv->item_padding;
3053 cell_area.y = item->y + icon_view->priv->item_padding;
3055 for (k = 0; k < 2; k++)
3056 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3058 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3060 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3063 if (!info->cell->visible)
3066 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3068 /* We should not subtract icon_view->priv->item_padding from item->height,
3069 * because item->height is recalculated above using
3070 * max_height which does not contain item padding.
3072 cell_area.width = item->box[info->position].width;
3073 cell_area.height = item->height;
3077 /* item->width is not recalculated and thus needs to be
3078 * corrected for the padding.
3080 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3081 cell_area.height = max_height[i];
3084 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3086 &item->box[info->position].x, &item->box[info->position].y,
3087 &item->box[info->position].width, &item->box[info->position].height);
3089 item->box[info->position].x += cell_area.x;
3090 item->box[info->position].y += cell_area.y;
3091 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3093 item->before[info->position] = item->box[info->position].x - cell_area.x;
3094 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3095 cell_area.x += cell_area.width + spacing;
3099 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3101 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3102 cell_area.width = item->width;
3104 item->before[info->position] = item->box[info->position].y - cell_area.y;
3105 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3106 cell_area.y += cell_area.height + spacing;
3110 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3112 for (i = 0; i < icon_view->priv->n_cells; i++)
3114 item->box[i].x = item->x + item->width -
3115 (item->box[i].x + item->box[i].width - item->x);
3119 item->height += icon_view->priv->item_padding * 2;
3123 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3125 g_list_foreach (icon_view->priv->items,
3126 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3130 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3137 gtk_icon_view_paint_item (GtkIconView *icon_view,
3139 GtkIconViewItem *item,
3141 GdkDrawable *drawable,
3144 gboolean draw_focus)
3148 GdkRectangle cell_area, box;
3152 GtkCellRendererState flags;
3154 if (icon_view->priv->model == NULL)
3157 gtk_icon_view_set_cell_data (icon_view, item);
3159 gtk_widget_style_get (GTK_WIDGET (icon_view),
3160 "focus-line-width", &focus_width,
3163 padding = focus_width;
3167 flags = GTK_CELL_RENDERER_SELECTED;
3168 if (gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3169 state = GTK_STATE_SELECTED;
3171 state = GTK_STATE_ACTIVE;
3176 state = GTK_STATE_NORMAL;
3179 #ifdef DEBUG_ICON_VIEW
3180 gdk_draw_rectangle (drawable,
3181 GTK_WIDGET (icon_view)->style->black_gc,
3184 item->width, item->height);
3189 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3190 (GdkWindow *) drawable,
3194 GTK_WIDGET (icon_view),
3197 item->width, item->height);
3200 for (l = icon_view->priv->cell_list; l; l = l->next)
3202 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3204 if (!info->cell->visible)
3207 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3209 #ifdef DEBUG_ICON_VIEW
3210 gdk_draw_rectangle (drawable,
3211 GTK_WIDGET (icon_view)->style->black_gc,
3213 x - item->x + cell_area.x,
3214 y - item->y + cell_area.y,
3215 cell_area.width, cell_area.height);
3217 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3219 gdk_draw_rectangle (drawable,
3220 GTK_WIDGET (icon_view)->style->black_gc,
3222 x - item->x + box.x,
3223 y - item->y + box.y,
3224 box.width, box.height);
3227 cell_area.x = x - item->x + cell_area.x;
3228 cell_area.y = y - item->y + cell_area.y;
3230 gtk_cell_renderer_render (info->cell,
3232 GTK_WIDGET (icon_view),
3233 &cell_area, &cell_area, area, flags);
3237 gtk_widget_has_focus (GTK_WIDGET (icon_view)) &&
3238 item == icon_view->priv->cursor_item)
3240 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3242 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3244 if (!info->cell->visible)
3247 /* If found a editable/activatable cell, draw focus on it. */
3248 if (icon_view->priv->cursor_cell < 0 &&
3249 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3250 icon_view->priv->cursor_cell = i;
3252 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3254 if (i == icon_view->priv->cursor_cell)
3256 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3260 GTK_WIDGET (icon_view),
3262 x - item->x + box.x - padding,
3263 y - item->y + box.y - padding,
3264 box.width + 2 * padding,
3265 box.height + 2 * padding);
3270 /* If there are no editable/activatable cells, draw focus
3271 * around the whole item.
3273 if (icon_view->priv->cursor_cell < 0)
3274 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3278 GTK_WIDGET (icon_view),
3282 item->width + 2 * padding,
3283 item->height + 2 * padding);
3288 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3293 GdkRectangle rubber_rect;
3294 GdkColor *fill_color_gdk;
3295 guchar fill_color_alpha;
3297 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3298 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3299 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3300 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3302 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3305 gtk_widget_style_get (GTK_WIDGET (icon_view),
3306 "selection-box-color", &fill_color_gdk,
3307 "selection-box-alpha", &fill_color_alpha,
3310 if (!fill_color_gdk)
3311 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3313 cairo_set_source_rgba (cr,
3314 fill_color_gdk->red / 65535.,
3315 fill_color_gdk->green / 65535.,
3316 fill_color_gdk->blue / 65535.,
3317 fill_color_alpha / 255.);
3320 gdk_cairo_rectangle (cr, &rect);
3324 /* Draw the border without alpha */
3325 cairo_set_source_rgb (cr,
3326 fill_color_gdk->red / 65535.,
3327 fill_color_gdk->green / 65535.,
3328 fill_color_gdk->blue / 65535.);
3329 cairo_rectangle (cr,
3330 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3331 rubber_rect.width - 1, rubber_rect.height - 1);
3335 gdk_color_free (fill_color_gdk);
3339 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3345 index = gtk_tree_path_get_indices (path)[0];
3347 for (l = icon_view->priv->items; l; l = l->next)
3349 GtkIconViewItem *item = l->data;
3351 if (item->index == index)
3353 gtk_icon_view_queue_draw_item (icon_view, item);
3360 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3361 GtkIconViewItem *item)
3366 gtk_widget_style_get (GTK_WIDGET (icon_view),
3367 "focus-line-width", &focus_width,
3370 rect.x = item->x - focus_width;
3371 rect.y = item->y - focus_width;
3372 rect.width = item->width + 2 * focus_width;
3373 rect.height = item->height + 2 * focus_width;
3375 if (icon_view->priv->bin_window)
3376 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3380 layout_callback (gpointer user_data)
3382 GtkIconView *icon_view;
3384 icon_view = GTK_ICON_VIEW (user_data);
3386 icon_view->priv->layout_idle_id = 0;
3388 gtk_icon_view_layout (icon_view);
3394 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3396 if (icon_view->priv->layout_idle_id != 0)
3399 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3403 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3404 GtkIconViewItem *item,
3408 AtkObject *item_obj;
3409 AtkObject *cursor_item_obj;
3411 if (icon_view->priv->cursor_item == item &&
3412 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3415 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3416 if (icon_view->priv->cursor_item != NULL)
3418 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3421 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3422 if (cursor_item_obj != NULL)
3423 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3426 icon_view->priv->cursor_item = item;
3427 if (cursor_cell >= 0)
3428 icon_view->priv->cursor_cell = cursor_cell;
3430 gtk_icon_view_queue_draw_item (icon_view, item);
3432 /* Notify that accessible focus object has changed */
3433 item_obj = atk_object_ref_accessible_child (obj, item->index);
3435 if (item_obj != NULL)
3437 atk_focus_tracker_notify (item_obj);
3438 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3439 g_object_unref (item_obj);
3444 static GtkIconViewItem *
3445 gtk_icon_view_item_new (void)
3447 GtkIconViewItem *item;
3449 item = g_new0 (GtkIconViewItem, 1);
3458 gtk_icon_view_item_free (GtkIconViewItem *item)
3460 g_return_if_fail (item != NULL);
3462 g_free (item->before);
3463 g_free (item->after);
3470 static GtkIconViewItem *
3471 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3474 gboolean only_in_cell,
3475 GtkIconViewCellInfo **cell_at_pos)
3481 *cell_at_pos = NULL;
3483 for (items = icon_view->priv->items; items; items = items->next)
3485 GtkIconViewItem *item = items->data;
3487 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3488 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3490 if (only_in_cell || cell_at_pos)
3492 gtk_icon_view_set_cell_data (icon_view, item);
3494 for (l = icon_view->priv->cell_list; l; l = l->next)
3496 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3498 if (!info->cell->visible)
3501 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3503 if ((x >= box.x && x <= box.x + box.width &&
3504 y >= box.y && y <= box.y + box.height) ||
3506 x <= box.x + box.width &&
3508 y <= box.y + box.height))
3511 *cell_at_pos = info;
3529 gtk_icon_view_select_item (GtkIconView *icon_view,
3530 GtkIconViewItem *item)
3532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3533 g_return_if_fail (item != NULL);
3538 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3540 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3541 gtk_icon_view_unselect_all_internal (icon_view);
3543 item->selected = TRUE;
3545 gtk_icon_view_item_selected_changed (icon_view, item);
3546 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3548 gtk_icon_view_queue_draw_item (icon_view, item);
3553 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3554 GtkIconViewItem *item)
3556 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3557 g_return_if_fail (item != NULL);
3559 if (!item->selected)
3562 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3563 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3566 item->selected = FALSE;
3568 gtk_icon_view_item_selected_changed (icon_view, item);
3569 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3571 gtk_icon_view_queue_draw_item (icon_view, item);
3575 verify_items (GtkIconView *icon_view)
3580 for (items = icon_view->priv->items; items; items = items->next)
3582 GtkIconViewItem *item = items->data;
3584 if (item->index != i)
3585 g_error ("List item does not match its index: "
3586 "item index %d and list index %d\n", item->index, i);
3593 gtk_icon_view_row_changed (GtkTreeModel *model,
3598 GtkIconViewItem *item;
3600 GtkIconView *icon_view;
3602 icon_view = GTK_ICON_VIEW (data);
3604 gtk_icon_view_stop_editing (icon_view, TRUE);
3606 index = gtk_tree_path_get_indices(path)[0];
3607 item = g_list_nth_data (icon_view->priv->items, index);
3609 gtk_icon_view_item_invalidate_size (item);
3610 gtk_icon_view_queue_layout (icon_view);
3612 verify_items (icon_view);
3616 gtk_icon_view_row_inserted (GtkTreeModel *model,
3622 GtkIconViewItem *item;
3623 gboolean iters_persist;
3624 GtkIconView *icon_view;
3627 icon_view = GTK_ICON_VIEW (data);
3629 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3631 index = gtk_tree_path_get_indices(path)[0];
3633 item = gtk_icon_view_item_new ();
3638 item->index = index;
3640 /* FIXME: We can be more efficient here,
3641 we can store a tail pointer and use that when
3642 appending (which is a rather common operation)
3644 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3647 list = g_list_nth (icon_view->priv->items, index + 1);
3648 for (; list; list = list->next)
3655 verify_items (icon_view);
3657 gtk_icon_view_queue_layout (icon_view);
3661 gtk_icon_view_row_deleted (GtkTreeModel *model,
3666 GtkIconView *icon_view;
3667 GtkIconViewItem *item;
3669 gboolean emit = FALSE;
3671 icon_view = GTK_ICON_VIEW (data);
3673 index = gtk_tree_path_get_indices(path)[0];
3675 list = g_list_nth (icon_view->priv->items, index);
3678 gtk_icon_view_stop_editing (icon_view, TRUE);
3680 if (item == icon_view->priv->anchor_item)
3681 icon_view->priv->anchor_item = NULL;
3683 if (item == icon_view->priv->cursor_item)
3684 icon_view->priv->cursor_item = NULL;
3689 gtk_icon_view_item_free (item);
3691 for (next = list->next; next; next = next->next)
3698 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3700 verify_items (icon_view);
3702 gtk_icon_view_queue_layout (icon_view);
3705 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3709 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3710 GtkTreePath *parent,
3717 GtkIconView *icon_view;
3718 GList *items = NULL, *list;
3719 GtkIconViewItem **item_array;
3722 icon_view = GTK_ICON_VIEW (data);
3724 gtk_icon_view_stop_editing (icon_view, TRUE);
3726 length = gtk_tree_model_iter_n_children (model, NULL);
3728 order = g_new (gint, length);
3729 for (i = 0; i < length; i++)
3730 order [new_order[i]] = i;
3732 item_array = g_new (GtkIconViewItem *, length);
3733 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3734 item_array[order[i]] = list->data;
3737 for (i = length - 1; i >= 0; i--)
3739 item_array[i]->index = i;
3740 items = g_list_prepend (items, item_array[i]);
3743 g_free (item_array);
3744 g_list_free (icon_view->priv->items);
3745 icon_view->priv->items = items;
3747 gtk_icon_view_queue_layout (icon_view);
3749 verify_items (icon_view);
3753 gtk_icon_view_build_items (GtkIconView *icon_view)
3757 gboolean iters_persist;
3758 GList *items = NULL;
3760 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3762 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3770 GtkIconViewItem *item = gtk_icon_view_item_new ();
3779 items = g_list_prepend (items, item);
3781 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3783 icon_view->priv->items = g_list_reverse (items);
3787 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3790 GtkMovementStep step,
3794 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3795 I_("move-cursor"), 2,
3799 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3804 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3807 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3812 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3819 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3820 GtkMovementStep step,
3823 GdkModifierType state;
3825 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3826 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3827 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3828 step == GTK_MOVEMENT_DISPLAY_LINES ||
3829 step == GTK_MOVEMENT_PAGES ||
3830 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3832 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3835 gtk_icon_view_stop_editing (icon_view, FALSE);
3836 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3838 if (gtk_get_current_event_state (&state))
3840 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3841 icon_view->priv->ctrl_pressed = TRUE;
3842 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3843 icon_view->priv->shift_pressed = TRUE;
3845 /* else we assume not pressed */
3849 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3850 case GTK_MOVEMENT_VISUAL_POSITIONS:
3851 gtk_icon_view_move_cursor_left_right (icon_view, count);
3853 case GTK_MOVEMENT_DISPLAY_LINES:
3854 gtk_icon_view_move_cursor_up_down (icon_view, count);
3856 case GTK_MOVEMENT_PAGES:
3857 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3859 case GTK_MOVEMENT_BUFFER_ENDS:
3860 gtk_icon_view_move_cursor_start_end (icon_view, count);
3863 g_assert_not_reached ();
3866 icon_view->priv->ctrl_pressed = FALSE;
3867 icon_view->priv->shift_pressed = FALSE;
3869 icon_view->priv->draw_focus = TRUE;
3874 static GtkIconViewItem *
3875 find_item (GtkIconView *icon_view,
3876 GtkIconViewItem *current,
3882 GtkIconViewItem *item;
3884 /* FIXME: this could be more efficient
3886 row = current->row + row_ofs;
3887 col = current->col + col_ofs;
3889 for (items = icon_view->priv->items; items; items = items->next)
3892 if (item->row == row && item->col == col)
3900 find_cell (GtkIconView *icon_view,
3901 GtkIconViewItem *item,
3903 GtkOrientation orientation,
3913 if (icon_view->priv->orientation != orientation)
3916 gtk_icon_view_set_cell_data (icon_view, item);
3918 focusable = g_new0 (gint, icon_view->priv->n_cells);
3922 for (k = 0; k < 2; k++)
3923 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3925 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3927 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3930 if (!info->cell->visible)
3933 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3936 current = n_focusable;
3938 focusable[n_focusable] = i;
3944 if (n_focusable == 0)
3952 current = step > 0 ? 0 : n_focusable - 1;
3953 cell = focusable[current];
3956 if (current + *count < 0)
3959 *count = current + *count;
3961 else if (current + *count > n_focusable - 1)
3964 *count = current + *count - (n_focusable - 1);
3968 cell = focusable[current + *count];
3977 static GtkIconViewItem *
3978 find_item_page_up_down (GtkIconView *icon_view,
3979 GtkIconViewItem *current,
3986 y = current->y + count * icon_view->priv->vadjustment->page_size;
3988 item = g_list_find (icon_view->priv->items, current);
3993 for (next = item->next; next; next = next->next)
3995 if (((GtkIconViewItem *)next->data)->col == col)
3998 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4008 for (next = item->prev; next; next = next->prev)
4010 if (((GtkIconViewItem *)next->data)->col == col)
4013 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4027 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4028 GtkIconViewItem *anchor,
4029 GtkIconViewItem *cursor)
4032 GtkIconViewItem *item;
4033 gint row1, row2, col1, col2;
4034 gboolean dirty = FALSE;
4036 if (anchor->row < cursor->row)
4047 if (anchor->col < cursor->col)
4058 for (items = icon_view->priv->items; items; items = items->next)
4062 if (row1 <= item->row && item->row <= row2 &&
4063 col1 <= item->col && item->col <= col2)
4065 if (!item->selected)
4068 item->selected = TRUE;
4069 gtk_icon_view_item_selected_changed (icon_view, item);
4071 gtk_icon_view_queue_draw_item (icon_view, item);
4079 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4082 GtkIconViewItem *item;
4084 gboolean dirty = FALSE;
4087 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4090 if (!icon_view->priv->cursor_item)
4095 list = icon_view->priv->items;
4097 list = g_list_last (icon_view->priv->items);
4099 item = list ? list->data : NULL;
4104 item = icon_view->priv->cursor_item;
4105 cell = icon_view->priv->cursor_cell;
4106 step = count > 0 ? 1 : -1;
4109 cell = find_cell (icon_view, item, cell,
4110 GTK_ORIENTATION_VERTICAL,
4115 item = find_item (icon_view, item, step, 0);
4116 count = count - step;
4122 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4126 if (icon_view->priv->ctrl_pressed ||
4127 !icon_view->priv->shift_pressed ||
4128 !icon_view->priv->anchor_item ||
4129 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4130 icon_view->priv->anchor_item = item;
4132 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4134 if (!icon_view->priv->ctrl_pressed &&
4135 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4137 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4138 dirty = gtk_icon_view_select_all_between (icon_view,
4139 icon_view->priv->anchor_item,
4143 gtk_icon_view_scroll_to_item (icon_view, item);
4146 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4150 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4153 GtkIconViewItem *item;
4154 gboolean dirty = FALSE;
4156 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4159 if (!icon_view->priv->cursor_item)
4164 list = icon_view->priv->items;
4166 list = g_list_last (icon_view->priv->items);
4168 item = list ? list->data : NULL;
4171 item = find_item_page_up_down (icon_view,
4172 icon_view->priv->cursor_item,
4175 if (item == icon_view->priv->cursor_item)
4176 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4181 if (icon_view->priv->ctrl_pressed ||
4182 !icon_view->priv->shift_pressed ||
4183 !icon_view->priv->anchor_item ||
4184 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4185 icon_view->priv->anchor_item = item;
4187 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4189 if (!icon_view->priv->ctrl_pressed &&
4190 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4192 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4193 dirty = gtk_icon_view_select_all_between (icon_view,
4194 icon_view->priv->anchor_item,
4198 gtk_icon_view_scroll_to_item (icon_view, item);
4201 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4205 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4208 GtkIconViewItem *item;
4210 gboolean dirty = FALSE;
4213 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4216 if (!icon_view->priv->cursor_item)
4221 list = icon_view->priv->items;
4223 list = g_list_last (icon_view->priv->items);
4225 item = list ? list->data : NULL;
4229 item = icon_view->priv->cursor_item;
4230 cell = icon_view->priv->cursor_cell;
4231 step = count > 0 ? 1 : -1;
4234 cell = find_cell (icon_view, item, cell,
4235 GTK_ORIENTATION_HORIZONTAL,
4240 item = find_item (icon_view, item, 0, step);
4241 count = count - step;
4247 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4251 if (icon_view->priv->ctrl_pressed ||
4252 !icon_view->priv->shift_pressed ||
4253 !icon_view->priv->anchor_item ||
4254 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4255 icon_view->priv->anchor_item = item;
4257 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4259 if (!icon_view->priv->ctrl_pressed &&
4260 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4262 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4263 dirty = gtk_icon_view_select_all_between (icon_view,
4264 icon_view->priv->anchor_item,
4268 gtk_icon_view_scroll_to_item (icon_view, item);
4271 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4275 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4278 GtkIconViewItem *item;
4280 gboolean dirty = FALSE;
4282 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4286 list = icon_view->priv->items;
4288 list = g_list_last (icon_view->priv->items);
4290 item = list ? list->data : NULL;
4292 if (item == icon_view->priv->cursor_item)
4293 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4298 if (icon_view->priv->ctrl_pressed ||
4299 !icon_view->priv->shift_pressed ||
4300 !icon_view->priv->anchor_item ||
4301 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4302 icon_view->priv->anchor_item = item;
4304 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4306 if (!icon_view->priv->ctrl_pressed &&
4307 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4309 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4310 dirty = gtk_icon_view_select_all_between (icon_view,
4311 icon_view->priv->anchor_item,
4315 gtk_icon_view_scroll_to_item (icon_view, item);
4318 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4322 * gtk_icon_view_scroll_to_path:
4323 * @icon_view: A #GtkIconView.
4324 * @path: The path of the item to move to.
4325 * @use_align: whether to use alignment arguments, or %FALSE.
4326 * @row_align: The vertical alignment of the item specified by @path.
4327 * @col_align: The horizontal alignment of the item specified by @path.
4329 * Moves the alignments of @icon_view to the position specified by @path.
4330 * @row_align determines where the row is placed, and @col_align determines
4331 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4332 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4335 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4336 * tree does the minimum amount of work to scroll the item onto the screen.
4337 * This means that the item will be scrolled to the edge closest to its current
4338 * position. If the item is currently visible on the screen, nothing is done.
4340 * This function only works if the model is set, and @path is a valid row on
4341 * the model. If the model changes before the @icon_view is realized, the
4342 * centered path will be modified to reflect this change.
4347 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4353 GtkIconViewItem *item = NULL;
4355 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4356 g_return_if_fail (path != NULL);
4357 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4358 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4360 if (gtk_tree_path_get_depth (path) > 0)
4361 item = g_list_nth_data (icon_view->priv->items,
4362 gtk_tree_path_get_indices(path)[0]);
4364 if (!item || item->width < 0 ||
4365 !gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4367 if (icon_view->priv->scroll_to_path)
4368 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4370 icon_view->priv->scroll_to_path = NULL;
4373 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4375 icon_view->priv->scroll_to_use_align = use_align;
4376 icon_view->priv->scroll_to_row_align = row_align;
4377 icon_view->priv->scroll_to_col_align = col_align;
4388 gtk_widget_style_get (GTK_WIDGET (icon_view),
4389 "focus-line-width", &focus_width,
4392 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4394 offset = y + item->y - focus_width -
4395 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4397 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4398 icon_view->priv->vadjustment->value + offset);
4400 offset = x + item->x - focus_width -
4401 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4403 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4404 icon_view->priv->hadjustment->value + offset);
4406 gtk_adjustment_changed (icon_view->priv->hadjustment);
4407 gtk_adjustment_changed (icon_view->priv->vadjustment);
4410 gtk_icon_view_scroll_to_item (icon_view, item);
4415 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4416 GtkIconViewItem *item)
4418 gint x, y, width, height;
4421 gtk_widget_style_get (GTK_WIDGET (icon_view),
4422 "focus-line-width", &focus_width,
4425 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4427 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4429 if (y + item->y - focus_width < 0)
4430 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4431 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4432 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4433 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4434 icon_view->priv->vadjustment->value + y + item->y + item->height
4435 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4437 if (x + item->x - focus_width < 0)
4438 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4439 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4440 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4441 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4442 icon_view->priv->hadjustment->value + x + item->x + item->width
4443 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4445 gtk_adjustment_changed (icon_view->priv->hadjustment);
4446 gtk_adjustment_changed (icon_view->priv->vadjustment);
4449 /* GtkCellLayout implementation */
4450 static GtkIconViewCellInfo *
4451 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4452 GtkCellRenderer *renderer)
4456 for (i = icon_view->priv->cell_list; i; i = i->next)
4458 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4460 if (info->cell == renderer)
4468 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4469 GtkIconViewItem *item)
4472 gboolean iters_persist;
4475 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4481 path = gtk_tree_path_new_from_indices (item->index, -1);
4482 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4484 gtk_tree_path_free (path);
4489 for (i = icon_view->priv->cell_list; i; i = i->next)
4492 GtkIconViewCellInfo *info = i->data;
4494 g_object_freeze_notify (G_OBJECT (info->cell));
4496 for (j = info->attributes; j && j->next; j = j->next->next)
4498 gchar *property = j->data;
4499 gint column = GPOINTER_TO_INT (j->next->data);
4500 GValue value = {0, };
4502 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4504 g_object_set_property (G_OBJECT (info->cell),
4506 g_value_unset (&value);
4510 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4512 icon_view->priv->model,
4516 g_object_thaw_notify (G_OBJECT (info->cell));
4521 free_cell_attributes (GtkIconViewCellInfo *info)
4525 list = info->attributes;
4526 while (list && list->next)
4528 g_free (list->data);
4529 list = list->next->next;
4532 g_slist_free (info->attributes);
4533 info->attributes = NULL;
4537 free_cell_info (GtkIconViewCellInfo *info)
4539 free_cell_attributes (info);
4541 g_object_unref (info->cell);
4544 (* info->destroy) (info->func_data);
4550 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4551 GtkCellRenderer *renderer,
4554 GtkIconViewCellInfo *info;
4555 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4557 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4558 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4560 g_object_ref_sink (renderer);
4562 info = g_new0 (GtkIconViewCellInfo, 1);
4563 info->cell = renderer;
4564 info->expand = expand ? TRUE : FALSE;
4565 info->pack = GTK_PACK_START;
4566 info->position = icon_view->priv->n_cells;
4568 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4569 icon_view->priv->n_cells++;
4573 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4574 GtkCellRenderer *renderer,
4577 GtkIconViewCellInfo *info;
4578 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4580 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4581 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4583 g_object_ref_sink (renderer);
4585 info = g_new0 (GtkIconViewCellInfo, 1);
4586 info->cell = renderer;
4587 info->expand = expand ? TRUE : FALSE;
4588 info->pack = GTK_PACK_END;
4589 info->position = icon_view->priv->n_cells;
4591 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4592 icon_view->priv->n_cells++;
4596 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4597 GtkCellRenderer *renderer,
4598 const gchar *attribute,
4601 GtkIconViewCellInfo *info;
4602 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4604 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4605 g_return_if_fail (info != NULL);
4607 info->attributes = g_slist_prepend (info->attributes,
4608 GINT_TO_POINTER (column));
4609 info->attributes = g_slist_prepend (info->attributes,
4610 g_strdup (attribute));
4614 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4616 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4618 while (icon_view->priv->cell_list)
4620 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4621 free_cell_info (info);
4622 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4623 icon_view->priv->cell_list);
4626 icon_view->priv->n_cells = 0;
4630 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4631 GtkCellRenderer *cell,
4632 GtkCellLayoutDataFunc func,
4634 GDestroyNotify destroy)
4636 GtkIconViewCellInfo *info;
4637 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4639 info = gtk_icon_view_get_cell_info (icon_view, cell);
4640 g_return_if_fail (info != NULL);
4644 GDestroyNotify d = info->destroy;
4646 info->destroy = NULL;
4647 d (info->func_data);
4651 info->func_data = func_data;
4652 info->destroy = destroy;
4656 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4657 GtkCellRenderer *renderer)
4659 GtkIconViewCellInfo *info;
4661 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4663 free_cell_attributes (info);
4667 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4668 GtkCellRenderer *cell,
4671 GtkIconView *icon_view;
4673 GtkIconViewCellInfo *info;
4676 icon_view = GTK_ICON_VIEW (layout);
4678 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4680 info = gtk_icon_view_get_cell_info (icon_view, cell);
4682 g_return_if_fail (info != NULL);
4683 g_return_if_fail (position >= 0);
4685 link = g_list_find (icon_view->priv->cell_list, info);
4687 g_return_if_fail (link != NULL);
4689 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4691 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4694 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4701 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4705 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4707 GtkIconView *icon_view = (GtkIconView *)layout;
4708 GList *retval = NULL, *l;
4710 for (l = icon_view->priv->cell_list; l; l = l->next)
4712 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4714 retval = g_list_prepend (retval, info->cell);
4717 return g_list_reverse (retval);
4724 * gtk_icon_view_new:
4726 * Creates a new #GtkIconView widget
4728 * Return value: A newly created #GtkIconView widget
4733 gtk_icon_view_new (void)
4735 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4739 * gtk_icon_view_new_with_model:
4740 * @model: The model.
4742 * Creates a new #GtkIconView widget with the model @model.
4744 * Return value: A newly created #GtkIconView widget.
4749 gtk_icon_view_new_with_model (GtkTreeModel *model)
4751 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4755 * gtk_icon_view_convert_widget_to_bin_window_coords:
4756 * @icon_view: a #GtkIconView
4757 * @wx: X coordinate relative to the widget
4758 * @wy: Y coordinate relative to the widget
4759 * @bx: return location for bin_window X coordinate
4760 * @by: return location for bin_window Y coordinate
4762 * Converts widget coordinates to coordinates for the bin_window,
4763 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4768 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4776 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4778 if (icon_view->priv->bin_window)
4779 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4790 * gtk_icon_view_get_path_at_pos:
4791 * @icon_view: A #GtkIconView.
4792 * @x: The x position to be identified
4793 * @y: The y position to be identified
4795 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4796 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4797 * the cell at the specified position.
4798 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4799 * widget coordinates to bin_window coordinates.
4801 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4802 * if no icon exists at that position.
4807 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4811 GtkIconViewItem *item;
4814 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4816 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4821 path = gtk_tree_path_new_from_indices (item->index, -1);
4827 * gtk_icon_view_get_item_at_pos:
4828 * @icon_view: A #GtkIconView.
4829 * @x: The x position to be identified
4830 * @y: The y position to be identified
4831 * @path: (allow-none): Return location for the path, or %NULL
4832 * @cell: Return location for the renderer responsible for the cell
4833 * at (@x, @y), or %NULL
4835 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4836 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4837 * obtains the cell at the specified position. The returned path should
4838 * be freed with gtk_tree_path_free().
4839 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4840 * widget coordinates to bin_window coordinates.
4842 * Return value: %TRUE if an item exists at the specified position
4847 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4851 GtkCellRenderer **cell)
4853 GtkIconViewItem *item;
4854 GtkIconViewCellInfo *info;
4856 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4858 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4863 *path = gtk_tree_path_new_from_indices (item->index, -1);
4876 return (item != NULL);
4880 * gtk_icon_view_set_tooltip_item:
4881 * @icon_view: a #GtkIconView
4882 * @tooltip: a #GtkTooltip
4883 * @path: a #GtkTreePath
4885 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4886 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4887 * See also gtk_tooltip_set_tip_area().
4892 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4893 GtkTooltip *tooltip,
4896 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4897 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4899 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4903 * gtk_icon_view_set_tooltip_cell:
4904 * @icon_view: a #GtkIconView
4905 * @tooltip: a #GtkTooltip
4906 * @path: a #GtkTreePath
4907 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4909 * Sets the tip area of @tooltip to the area which @cell occupies in
4910 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4912 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4917 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4918 GtkTooltip *tooltip,
4920 GtkCellRenderer *cell)
4923 GtkIconViewItem *item = NULL;
4924 GtkIconViewCellInfo *info = NULL;
4927 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4928 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4929 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4931 if (gtk_tree_path_get_depth (path) > 0)
4932 item = g_list_nth_data (icon_view->priv->items,
4933 gtk_tree_path_get_indices(path)[0]);
4940 info = gtk_icon_view_get_cell_info (icon_view, cell);
4941 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4947 rect.width = item->width;
4948 rect.height = item->height;
4951 if (icon_view->priv->bin_window)
4953 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4958 gtk_tooltip_set_tip_area (tooltip, &rect);
4963 * gtk_icon_view_get_tooltip_context:
4964 * @icon_view: an #GtkIconView
4965 * @x: the x coordinate (relative to widget coordinates)
4966 * @y: the y coordinate (relative to widget coordinates)
4967 * @keyboard_tip: whether this is a keyboard tooltip or not
4968 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
4969 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
4970 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
4972 * This function is supposed to be used in a #GtkWidget::query-tooltip
4973 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4974 * which are received in the signal handler, should be passed to this
4975 * function without modification.
4977 * The return value indicates whether there is an icon view item at the given
4978 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4979 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4980 * @model, @path and @iter which have been provided will be set to point to
4981 * that row and the corresponding model. @x and @y will always be converted
4982 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4984 * Return value: whether or not the given tooltip context points to a item
4989 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4992 gboolean keyboard_tip,
4993 GtkTreeModel **model,
4997 GtkTreePath *tmppath = NULL;
4999 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5000 g_return_val_if_fail (x != NULL, FALSE);
5001 g_return_val_if_fail (y != NULL, FALSE);
5005 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5012 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5015 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5020 *model = gtk_icon_view_get_model (icon_view);
5023 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5029 gtk_tree_path_free (tmppath);
5035 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5038 gboolean keyboard_tip,
5039 GtkTooltip *tooltip,
5045 GtkTreeModel *model;
5046 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5048 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5051 &model, &path, &iter))
5054 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5058 gtk_tree_path_free (path);
5062 gtk_tooltip_set_markup (tooltip, str);
5063 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5065 gtk_tree_path_free (path);
5073 * gtk_icon_view_set_tooltip_column:
5074 * @icon_view: a #GtkIconView
5075 * @column: an integer, which is a valid column number for @icon_view's model
5077 * If you only plan to have simple (text-only) tooltips on full items, you
5078 * can use this function to have #GtkIconView handle these automatically
5079 * for you. @column should be set to the column in @icon_view's model
5080 * containing the tooltip texts, or -1 to disable this feature.
5082 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5083 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5088 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5091 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5093 if (column == icon_view->priv->tooltip_column)
5098 g_signal_handlers_disconnect_by_func (icon_view,
5099 gtk_icon_view_set_tooltip_query_cb,
5101 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5105 if (icon_view->priv->tooltip_column == -1)
5107 g_signal_connect (icon_view, "query-tooltip",
5108 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5109 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5113 icon_view->priv->tooltip_column = column;
5114 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5118 * gtk_icon_view_get_tooltip_column:
5119 * @icon_view: a #GtkIconView
5121 * Returns the column of @icon_view's model which is being used for
5122 * displaying tooltips on @icon_view's rows.
5124 * Return value: the index of the tooltip column that is currently being
5125 * used, or -1 if this is disabled.
5130 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5132 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5134 return icon_view->priv->tooltip_column;
5138 * gtk_icon_view_get_visible_range:
5139 * @icon_view: A #GtkIconView
5140 * @start_path: (allow-none): Return location for start of region, or %NULL
5141 * @end_path: (allow-none): Return location for end of region, or %NULL
5143 * Sets @start_path and @end_path to be the first and last visible path.
5144 * Note that there may be invisible paths in between.
5146 * Both paths should be freed with gtk_tree_path_free() after use.
5148 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5153 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5154 GtkTreePath **start_path,
5155 GtkTreePath **end_path)
5157 gint start_index = -1;
5158 gint end_index = -1;
5161 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5163 if (icon_view->priv->hadjustment == NULL ||
5164 icon_view->priv->vadjustment == NULL)
5167 if (start_path == NULL && end_path == NULL)
5170 for (icons = icon_view->priv->items; icons; icons = icons->next)
5172 GtkIconViewItem *item = icons->data;
5174 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5175 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5176 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5177 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5179 if (start_index == -1)
5180 start_index = item->index;
5181 end_index = item->index;
5185 if (start_path && start_index != -1)
5186 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5187 if (end_path && end_index != -1)
5188 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5190 return start_index != -1;
5194 * gtk_icon_view_selected_foreach:
5195 * @icon_view: A #GtkIconView.
5196 * @func: The funcion to call for each selected icon.
5197 * @data: User data to pass to the function.
5199 * Calls a function for each selected icon. Note that the model or
5200 * selection cannot be modified from within this function.
5205 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5206 GtkIconViewForeachFunc func,
5211 for (list = icon_view->priv->items; list; list = list->next)
5213 GtkIconViewItem *item = list->data;
5214 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5217 (* func) (icon_view, path, data);
5219 gtk_tree_path_free (path);
5224 * gtk_icon_view_set_selection_mode:
5225 * @icon_view: A #GtkIconView.
5226 * @mode: The selection mode
5228 * Sets the selection mode of the @icon_view.
5233 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5234 GtkSelectionMode mode)
5236 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5238 if (mode == icon_view->priv->selection_mode)
5241 if (mode == GTK_SELECTION_NONE ||
5242 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5243 gtk_icon_view_unselect_all (icon_view);
5245 icon_view->priv->selection_mode = mode;
5247 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5251 * gtk_icon_view_get_selection_mode:
5252 * @icon_view: A #GtkIconView.
5254 * Gets the selection mode of the @icon_view.
5256 * Return value: the current selection mode
5261 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5263 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5265 return icon_view->priv->selection_mode;
5269 * gtk_icon_view_set_model:
5270 * @icon_view: A #GtkIconView.
5271 * @model: (allow-none): The model.
5273 * Sets the model for a #GtkIconView.
5274 * If the @icon_view already has a model set, it will remove
5275 * it before setting the new model. If @model is %NULL, then
5276 * it will unset the old model.
5281 gtk_icon_view_set_model (GtkIconView *icon_view,
5282 GtkTreeModel *model)
5284 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5285 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5287 if (icon_view->priv->model == model)
5290 if (icon_view->priv->scroll_to_path)
5292 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5293 icon_view->priv->scroll_to_path = NULL;
5296 gtk_icon_view_stop_editing (icon_view, TRUE);
5302 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5304 if (icon_view->priv->pixbuf_column != -1)
5306 column_type = gtk_tree_model_get_column_type (model,
5307 icon_view->priv->pixbuf_column);
5309 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5312 if (icon_view->priv->text_column != -1)
5314 column_type = gtk_tree_model_get_column_type (model,
5315 icon_view->priv->text_column);
5317 g_return_if_fail (column_type == G_TYPE_STRING);
5320 if (icon_view->priv->markup_column != -1)
5322 column_type = gtk_tree_model_get_column_type (model,
5323 icon_view->priv->markup_column);
5325 g_return_if_fail (column_type == G_TYPE_STRING);
5330 if (icon_view->priv->model)
5332 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5333 gtk_icon_view_row_changed,
5335 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5336 gtk_icon_view_row_inserted,
5338 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5339 gtk_icon_view_row_deleted,
5341 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5342 gtk_icon_view_rows_reordered,
5345 g_object_unref (icon_view->priv->model);
5347 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5348 g_list_free (icon_view->priv->items);
5349 icon_view->priv->items = NULL;
5350 icon_view->priv->anchor_item = NULL;
5351 icon_view->priv->cursor_item = NULL;
5352 icon_view->priv->last_single_clicked = NULL;
5353 icon_view->priv->width = 0;
5354 icon_view->priv->height = 0;
5357 icon_view->priv->model = model;
5359 if (icon_view->priv->model)
5361 g_object_ref (icon_view->priv->model);
5362 g_signal_connect (icon_view->priv->model,
5364 G_CALLBACK (gtk_icon_view_row_changed),
5366 g_signal_connect (icon_view->priv->model,
5368 G_CALLBACK (gtk_icon_view_row_inserted),
5370 g_signal_connect (icon_view->priv->model,
5372 G_CALLBACK (gtk_icon_view_row_deleted),
5374 g_signal_connect (icon_view->priv->model,
5376 G_CALLBACK (gtk_icon_view_rows_reordered),
5379 gtk_icon_view_build_items (icon_view);
5381 gtk_icon_view_queue_layout (icon_view);
5384 g_object_notify (G_OBJECT (icon_view), "model");
5386 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5387 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5391 * gtk_icon_view_get_model:
5392 * @icon_view: a #GtkIconView
5394 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5397 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5402 gtk_icon_view_get_model (GtkIconView *icon_view)
5404 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5406 return icon_view->priv->model;
5410 update_text_cell (GtkIconView *icon_view)
5412 GtkIconViewCellInfo *info;
5416 if (icon_view->priv->text_column == -1 &&
5417 icon_view->priv->markup_column == -1)
5419 if (icon_view->priv->text_cell != -1)
5421 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5422 icon_view->priv->pixbuf_cell--;
5424 info = g_list_nth_data (icon_view->priv->cell_list,
5425 icon_view->priv->text_cell);
5427 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5429 free_cell_info (info);
5431 icon_view->priv->n_cells--;
5432 icon_view->priv->text_cell = -1;
5437 if (icon_view->priv->text_cell == -1)
5439 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5440 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5441 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5444 if (info->cell == cell)
5446 icon_view->priv->text_cell = i;
5452 info = g_list_nth_data (icon_view->priv->cell_list,
5453 icon_view->priv->text_cell);
5455 if (icon_view->priv->markup_column != -1)
5456 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5458 "markup", icon_view->priv->markup_column,
5461 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5463 "text", icon_view->priv->text_column,
5466 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5467 g_object_set (info->cell,
5468 "alignment", PANGO_ALIGN_CENTER,
5469 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5474 g_object_set (info->cell,
5475 "alignment", PANGO_ALIGN_LEFT,
5476 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5484 update_pixbuf_cell (GtkIconView *icon_view)
5486 GtkIconViewCellInfo *info;
5490 if (icon_view->priv->pixbuf_column == -1)
5492 if (icon_view->priv->pixbuf_cell != -1)
5494 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5495 icon_view->priv->text_cell--;
5497 info = g_list_nth_data (icon_view->priv->cell_list,
5498 icon_view->priv->pixbuf_cell);
5500 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5502 free_cell_info (info);
5504 icon_view->priv->n_cells--;
5505 icon_view->priv->pixbuf_cell = -1;
5510 if (icon_view->priv->pixbuf_cell == -1)
5512 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5514 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5515 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5518 if (info->cell == cell)
5520 icon_view->priv->pixbuf_cell = i;
5526 info = g_list_nth_data (icon_view->priv->cell_list,
5527 icon_view->priv->pixbuf_cell);
5529 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5531 "pixbuf", icon_view->priv->pixbuf_column,
5534 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5535 g_object_set (info->cell,
5540 g_object_set (info->cell,
5548 * gtk_icon_view_set_text_column:
5549 * @icon_view: A #GtkIconView.
5550 * @column: A column in the currently used model, or -1 to display no text
5552 * Sets the column with text for @icon_view to be @column. The text
5553 * column must be of type #G_TYPE_STRING.
5558 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5561 if (column == icon_view->priv->text_column)
5565 icon_view->priv->text_column = -1;
5568 if (icon_view->priv->model != NULL)
5572 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5574 g_return_if_fail (column_type == G_TYPE_STRING);
5577 icon_view->priv->text_column = column;
5580 gtk_icon_view_stop_editing (icon_view, TRUE);
5582 update_text_cell (icon_view);
5584 gtk_icon_view_invalidate_sizes (icon_view);
5585 gtk_icon_view_queue_layout (icon_view);
5587 g_object_notify (G_OBJECT (icon_view), "text-column");
5591 * gtk_icon_view_get_text_column:
5592 * @icon_view: A #GtkIconView.
5594 * Returns the column with text for @icon_view.
5596 * Returns: the text column, or -1 if it's unset.
5601 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5603 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5605 return icon_view->priv->text_column;
5609 * gtk_icon_view_set_markup_column:
5610 * @icon_view: A #GtkIconView.
5611 * @column: A column in the currently used model, or -1 to display no text
5613 * Sets the column with markup information for @icon_view to be
5614 * @column. The markup column must be of type #G_TYPE_STRING.
5615 * If the markup column is set to something, it overrides
5616 * the text column set by gtk_icon_view_set_text_column().
5621 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5624 if (column == icon_view->priv->markup_column)
5628 icon_view->priv->markup_column = -1;
5631 if (icon_view->priv->model != NULL)
5635 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5637 g_return_if_fail (column_type == G_TYPE_STRING);
5640 icon_view->priv->markup_column = column;
5643 gtk_icon_view_stop_editing (icon_view, TRUE);
5645 update_text_cell (icon_view);
5647 gtk_icon_view_invalidate_sizes (icon_view);
5648 gtk_icon_view_queue_layout (icon_view);
5650 g_object_notify (G_OBJECT (icon_view), "markup-column");
5654 * gtk_icon_view_get_markup_column:
5655 * @icon_view: A #GtkIconView.
5657 * Returns the column with markup text for @icon_view.
5659 * Returns: the markup column, or -1 if it's unset.
5664 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5666 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5668 return icon_view->priv->markup_column;
5672 * gtk_icon_view_set_pixbuf_column:
5673 * @icon_view: A #GtkIconView.
5674 * @column: A column in the currently used model, or -1 to disable
5676 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5677 * column must be of type #GDK_TYPE_PIXBUF
5682 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5685 if (column == icon_view->priv->pixbuf_column)
5689 icon_view->priv->pixbuf_column = -1;
5692 if (icon_view->priv->model != NULL)
5696 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5698 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5701 icon_view->priv->pixbuf_column = column;
5704 gtk_icon_view_stop_editing (icon_view, TRUE);
5706 update_pixbuf_cell (icon_view);
5708 gtk_icon_view_invalidate_sizes (icon_view);
5709 gtk_icon_view_queue_layout (icon_view);
5711 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5716 * gtk_icon_view_get_pixbuf_column:
5717 * @icon_view: A #GtkIconView.
5719 * Returns the column with pixbufs for @icon_view.
5721 * Returns: the pixbuf column, or -1 if it's unset.
5726 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5728 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5730 return icon_view->priv->pixbuf_column;
5734 * gtk_icon_view_select_path:
5735 * @icon_view: A #GtkIconView.
5736 * @path: The #GtkTreePath to be selected.
5738 * Selects the row at @path.
5743 gtk_icon_view_select_path (GtkIconView *icon_view,
5746 GtkIconViewItem *item = NULL;
5748 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5749 g_return_if_fail (icon_view->priv->model != NULL);
5750 g_return_if_fail (path != NULL);
5752 if (gtk_tree_path_get_depth (path) > 0)
5753 item = g_list_nth_data (icon_view->priv->items,
5754 gtk_tree_path_get_indices(path)[0]);
5757 gtk_icon_view_select_item (icon_view, item);
5761 * gtk_icon_view_unselect_path:
5762 * @icon_view: A #GtkIconView.
5763 * @path: The #GtkTreePath to be unselected.
5765 * Unselects the row at @path.
5770 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5773 GtkIconViewItem *item;
5775 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5776 g_return_if_fail (icon_view->priv->model != NULL);
5777 g_return_if_fail (path != NULL);
5779 item = g_list_nth_data (icon_view->priv->items,
5780 gtk_tree_path_get_indices(path)[0]);
5785 gtk_icon_view_unselect_item (icon_view, item);
5789 * gtk_icon_view_get_selected_items:
5790 * @icon_view: A #GtkIconView.
5792 * Creates a list of paths of all selected items. Additionally, if you are
5793 * planning on modifying the model after calling this function, you may
5794 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5795 * To do this, you can use gtk_tree_row_reference_new().
5797 * To free the return value, use:
5799 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5800 * g_list_free (list);
5803 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5808 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5811 GList *selected = NULL;
5813 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5815 for (list = icon_view->priv->items; list != NULL; list = list->next)
5817 GtkIconViewItem *item = list->data;
5821 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5823 selected = g_list_prepend (selected, path);
5831 * gtk_icon_view_select_all:
5832 * @icon_view: A #GtkIconView.
5834 * Selects all the icons. @icon_view must has its selection mode set
5835 * to #GTK_SELECTION_MULTIPLE.
5840 gtk_icon_view_select_all (GtkIconView *icon_view)
5843 gboolean dirty = FALSE;
5845 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5847 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5850 for (items = icon_view->priv->items; items; items = items->next)
5852 GtkIconViewItem *item = items->data;
5854 if (!item->selected)
5857 item->selected = TRUE;
5858 gtk_icon_view_queue_draw_item (icon_view, item);
5863 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5867 * gtk_icon_view_unselect_all:
5868 * @icon_view: A #GtkIconView.
5870 * Unselects all the icons.
5875 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5877 gboolean dirty = FALSE;
5879 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5881 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5884 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5887 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5891 * gtk_icon_view_path_is_selected:
5892 * @icon_view: A #GtkIconView.
5893 * @path: A #GtkTreePath to check selection on.
5895 * Returns %TRUE if the icon pointed to by @path is currently
5896 * selected. If @path does not point to a valid location, %FALSE is returned.
5898 * Return value: %TRUE if @path is selected.
5903 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5906 GtkIconViewItem *item;
5908 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5909 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5910 g_return_val_if_fail (path != NULL, FALSE);
5912 item = g_list_nth_data (icon_view->priv->items,
5913 gtk_tree_path_get_indices(path)[0]);
5918 return item->selected;
5922 * gtk_icon_view_item_activated:
5923 * @icon_view: A #GtkIconView
5924 * @path: The #GtkTreePath to be activated
5926 * Activates the item determined by @path.
5931 gtk_icon_view_item_activated (GtkIconView *icon_view,
5934 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5935 g_return_if_fail (path != NULL);
5937 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5941 * gtk_icon_view_set_orientation:
5942 * @icon_view: a #GtkIconView
5943 * @orientation: the relative position of texts and icons
5945 * Sets the ::orientation property which determines whether the labels
5946 * are drawn beside the icons instead of below.
5951 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5952 GtkOrientation orientation)
5954 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5956 if (icon_view->priv->orientation != orientation)
5958 icon_view->priv->orientation = orientation;
5960 gtk_icon_view_stop_editing (icon_view, TRUE);
5961 gtk_icon_view_invalidate_sizes (icon_view);
5962 gtk_icon_view_queue_layout (icon_view);
5964 update_text_cell (icon_view);
5965 update_pixbuf_cell (icon_view);
5967 g_object_notify (G_OBJECT (icon_view), "orientation");
5972 * gtk_icon_view_get_orientation:
5973 * @icon_view: a #GtkIconView
5975 * Returns the value of the ::orientation property which determines
5976 * whether the labels are drawn beside the icons instead of below.
5978 * Return value: the relative position of texts and icons
5983 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5985 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5986 GTK_ORIENTATION_VERTICAL);
5988 return icon_view->priv->orientation;
5992 * gtk_icon_view_set_columns:
5993 * @icon_view: a #GtkIconView
5994 * @columns: the number of columns
5996 * Sets the ::columns property which determines in how
5997 * many columns the icons are arranged. If @columns is
5998 * -1, the number of columns will be chosen automatically
5999 * to fill the available area.
6004 gtk_icon_view_set_columns (GtkIconView *icon_view,
6007 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6009 if (icon_view->priv->columns != columns)
6011 icon_view->priv->columns = columns;
6013 gtk_icon_view_stop_editing (icon_view, TRUE);
6014 gtk_icon_view_queue_layout (icon_view);
6016 g_object_notify (G_OBJECT (icon_view), "columns");
6021 * gtk_icon_view_get_columns:
6022 * @icon_view: a #GtkIconView
6024 * Returns the value of the ::columns property.
6026 * Return value: the number of columns, or -1
6031 gtk_icon_view_get_columns (GtkIconView *icon_view)
6033 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6035 return icon_view->priv->columns;
6039 * gtk_icon_view_set_item_width:
6040 * @icon_view: a #GtkIconView
6041 * @item_width: the width for each item
6043 * Sets the ::item-width property which specifies the width
6044 * to use for each item. If it is set to -1, the icon view will
6045 * automatically determine a suitable item size.
6050 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6053 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6055 if (icon_view->priv->item_width != item_width)
6057 icon_view->priv->item_width = item_width;
6059 gtk_icon_view_stop_editing (icon_view, TRUE);
6060 gtk_icon_view_invalidate_sizes (icon_view);
6061 gtk_icon_view_queue_layout (icon_view);
6063 update_text_cell (icon_view);
6065 g_object_notify (G_OBJECT (icon_view), "item-width");
6070 * gtk_icon_view_get_item_width:
6071 * @icon_view: a #GtkIconView
6073 * Returns the value of the ::item-width property.
6075 * Return value: the width of a single item, or -1
6080 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6082 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6084 return icon_view->priv->item_width;
6089 * gtk_icon_view_set_spacing:
6090 * @icon_view: a #GtkIconView
6091 * @spacing: the spacing
6093 * Sets the ::spacing property which specifies the space
6094 * which is inserted between the cells (i.e. the icon and
6095 * the text) of an item.
6100 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6103 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6105 if (icon_view->priv->spacing != spacing)
6107 icon_view->priv->spacing = spacing;
6109 gtk_icon_view_stop_editing (icon_view, TRUE);
6110 gtk_icon_view_invalidate_sizes (icon_view);
6111 gtk_icon_view_queue_layout (icon_view);
6113 g_object_notify (G_OBJECT (icon_view), "spacing");
6118 * gtk_icon_view_get_spacing:
6119 * @icon_view: a #GtkIconView
6121 * Returns the value of the ::spacing property.
6123 * Return value: the space between cells
6128 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6130 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6132 return icon_view->priv->spacing;
6136 * gtk_icon_view_set_row_spacing:
6137 * @icon_view: a #GtkIconView
6138 * @row_spacing: the row spacing
6140 * Sets the ::row-spacing property which specifies the space
6141 * which is inserted between the rows of the icon view.
6146 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6149 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6151 if (icon_view->priv->row_spacing != row_spacing)
6153 icon_view->priv->row_spacing = row_spacing;
6155 gtk_icon_view_stop_editing (icon_view, TRUE);
6156 gtk_icon_view_invalidate_sizes (icon_view);
6157 gtk_icon_view_queue_layout (icon_view);
6159 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6164 * gtk_icon_view_get_row_spacing:
6165 * @icon_view: a #GtkIconView
6167 * Returns the value of the ::row-spacing property.
6169 * Return value: the space between rows
6174 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6176 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6178 return icon_view->priv->row_spacing;
6182 * gtk_icon_view_set_column_spacing:
6183 * @icon_view: a #GtkIconView
6184 * @column_spacing: the column spacing
6186 * Sets the ::column-spacing property which specifies the space
6187 * which is inserted between the columns of the icon view.
6192 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6193 gint column_spacing)
6195 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6197 if (icon_view->priv->column_spacing != column_spacing)
6199 icon_view->priv->column_spacing = column_spacing;
6201 gtk_icon_view_stop_editing (icon_view, TRUE);
6202 gtk_icon_view_invalidate_sizes (icon_view);
6203 gtk_icon_view_queue_layout (icon_view);
6205 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6210 * gtk_icon_view_get_column_spacing:
6211 * @icon_view: a #GtkIconView
6213 * Returns the value of the ::column-spacing property.
6215 * Return value: the space between columns
6220 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6222 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6224 return icon_view->priv->column_spacing;
6228 * gtk_icon_view_set_margin:
6229 * @icon_view: a #GtkIconView
6230 * @margin: the margin
6232 * Sets the ::margin property which specifies the space
6233 * which is inserted at the top, bottom, left and right
6239 gtk_icon_view_set_margin (GtkIconView *icon_view,
6242 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6244 if (icon_view->priv->margin != margin)
6246 icon_view->priv->margin = margin;
6248 gtk_icon_view_stop_editing (icon_view, TRUE);
6249 gtk_icon_view_invalidate_sizes (icon_view);
6250 gtk_icon_view_queue_layout (icon_view);
6252 g_object_notify (G_OBJECT (icon_view), "margin");
6257 * gtk_icon_view_get_margin:
6258 * @icon_view: a #GtkIconView
6260 * Returns the value of the ::margin property.
6262 * Return value: the space at the borders
6267 gtk_icon_view_get_margin (GtkIconView *icon_view)
6269 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6271 return icon_view->priv->margin;
6275 * gtk_icon_view_set_item_padding:
6276 * @icon_view: a #GtkIconView
6277 * @item_padding: the item padding
6279 * Sets the #GtkIconView:item-padding property which specifies the padding
6280 * around each of the icon view's items.
6285 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6288 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6290 if (icon_view->priv->item_padding != item_padding)
6292 icon_view->priv->item_padding = item_padding;
6294 gtk_icon_view_stop_editing (icon_view, TRUE);
6295 gtk_icon_view_invalidate_sizes (icon_view);
6296 gtk_icon_view_queue_layout (icon_view);
6298 g_object_notify (G_OBJECT (icon_view), "item-padding");
6303 * gtk_icon_view_get_item_padding:
6304 * @icon_view: a #GtkIconView
6306 * Returns the value of the ::item-padding property.
6308 * Return value: the padding around items
6313 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6315 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6317 return icon_view->priv->item_padding;
6320 /* Get/set whether drag_motion requested the drag data and
6321 * drag_data_received should thus not actually insert the data,
6322 * since the data doesn't result from a drop.
6325 set_status_pending (GdkDragContext *context,
6326 GdkDragAction suggested_action)
6328 g_object_set_data (G_OBJECT (context),
6329 I_("gtk-icon-view-status-pending"),
6330 GINT_TO_POINTER (suggested_action));
6333 static GdkDragAction
6334 get_status_pending (GdkDragContext *context)
6336 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6337 "gtk-icon-view-status-pending"));
6341 unset_reorderable (GtkIconView *icon_view)
6343 if (icon_view->priv->reorderable)
6345 icon_view->priv->reorderable = FALSE;
6346 g_object_notify (G_OBJECT (icon_view), "reorderable");
6351 set_source_row (GdkDragContext *context,
6352 GtkTreeModel *model,
6353 GtkTreePath *source_row)
6356 g_object_set_data_full (G_OBJECT (context),
6357 I_("gtk-icon-view-source-row"),
6358 gtk_tree_row_reference_new (model, source_row),
6359 (GDestroyNotify) gtk_tree_row_reference_free);
6361 g_object_set_data_full (G_OBJECT (context),
6362 I_("gtk-icon-view-source-row"),
6367 get_source_row (GdkDragContext *context)
6369 GtkTreeRowReference *ref;
6371 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6374 return gtk_tree_row_reference_get_path (ref);
6381 GtkTreeRowReference *dest_row;
6382 gboolean empty_view_drop;
6383 gboolean drop_append_mode;
6387 dest_row_free (gpointer data)
6389 DestRow *dr = (DestRow *)data;
6391 gtk_tree_row_reference_free (dr->dest_row);
6396 set_dest_row (GdkDragContext *context,
6397 GtkTreeModel *model,
6398 GtkTreePath *dest_row,
6399 gboolean empty_view_drop,
6400 gboolean drop_append_mode)
6406 g_object_set_data_full (G_OBJECT (context),
6407 I_("gtk-icon-view-dest-row"),
6412 dr = g_new0 (DestRow, 1);
6414 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6415 dr->empty_view_drop = empty_view_drop;
6416 dr->drop_append_mode = drop_append_mode;
6417 g_object_set_data_full (G_OBJECT (context),
6418 I_("gtk-icon-view-dest-row"),
6419 dr, (GDestroyNotify) dest_row_free);
6423 get_dest_row (GdkDragContext *context)
6427 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6431 GtkTreePath *path = NULL;
6434 path = gtk_tree_row_reference_get_path (dr->dest_row);
6435 else if (dr->empty_view_drop)
6436 path = gtk_tree_path_new_from_indices (0, -1);
6440 if (path && dr->drop_append_mode)
6441 gtk_tree_path_next (path);
6450 check_model_dnd (GtkTreeModel *model,
6451 GType required_iface,
6452 const gchar *signal)
6454 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6456 g_warning ("You must override the default '%s' handler "
6457 "on GtkIconView when using models that don't support "
6458 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6459 "is to connect to '%s' and call "
6460 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6461 "the default handler from running. Look at the source code "
6462 "for the default handler in gtkiconview.c to get an idea what "
6463 "your handler should do. (gtkiconview.c is in the GTK+ source "
6464 "code.) If you're using GTK+ from a language other than C, "
6465 "there may be a more natural way to override default handlers, e.g. via derivation.",
6466 signal, g_type_name (required_iface), signal);
6474 remove_scroll_timeout (GtkIconView *icon_view)
6476 if (icon_view->priv->scroll_timeout_id != 0)
6478 g_source_remove (icon_view->priv->scroll_timeout_id);
6480 icon_view->priv->scroll_timeout_id = 0;
6485 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6487 gint px, py, x, y, width, height;
6488 gint hoffset, voffset;
6490 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6491 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6493 /* see if we are near the edge. */
6494 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6496 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6498 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6500 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6503 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6504 icon_view->priv->vadjustment->value + voffset);
6507 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6508 icon_view->priv->hadjustment->value + hoffset);
6513 drag_scroll_timeout (gpointer data)
6515 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6517 gtk_icon_view_autoscroll (icon_view);
6524 set_destination (GtkIconView *icon_view,
6525 GdkDragContext *context,
6528 GdkDragAction *suggested_action,
6532 GtkTreePath *path = NULL;
6533 GtkIconViewDropPosition pos;
6534 GtkIconViewDropPosition old_pos;
6535 GtkTreePath *old_dest_path = NULL;
6536 gboolean can_drop = FALSE;
6538 widget = GTK_WIDGET (icon_view);
6540 *suggested_action = 0;
6543 if (!icon_view->priv->dest_set)
6545 /* someone unset us as a drag dest, note that if
6546 * we return FALSE drag_leave isn't called
6549 gtk_icon_view_set_drag_dest_item (icon_view,
6551 GTK_ICON_VIEW_DROP_LEFT);
6553 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6555 return FALSE; /* no longer a drop site */
6558 *target = gtk_drag_dest_find_target (widget, context,
6559 gtk_drag_dest_get_target_list (widget));
6560 if (*target == GDK_NONE)
6563 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6566 GtkTreeModel *model;
6568 /* the row got dropped on empty space, let's setup a special case
6572 gtk_tree_path_free (path);
6574 model = gtk_icon_view_get_model (icon_view);
6576 n_children = gtk_tree_model_iter_n_children (model, NULL);
6579 pos = GTK_ICON_VIEW_DROP_BELOW;
6580 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6584 pos = GTK_ICON_VIEW_DROP_ABOVE;
6585 path = gtk_tree_path_new_from_indices (0, -1);
6595 gtk_icon_view_get_drag_dest_item (icon_view,
6600 gtk_tree_path_free (old_dest_path);
6602 if (TRUE /* FIXME if the location droppable predicate */)
6610 GtkWidget *source_widget;
6612 *suggested_action = context->suggested_action;
6613 source_widget = gtk_drag_get_source_widget (context);
6615 if (source_widget == widget)
6617 /* Default to MOVE, unless the user has
6618 * pressed ctrl or shift to affect available actions
6620 if ((context->actions & GDK_ACTION_MOVE) != 0)
6621 *suggested_action = GDK_ACTION_MOVE;
6624 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6629 /* can't drop here */
6630 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6632 GTK_ICON_VIEW_DROP_LEFT);
6636 gtk_tree_path_free (path);
6642 get_logical_destination (GtkIconView *icon_view,
6643 gboolean *drop_append_mode)
6645 /* adjust path to point to the row the drop goes in front of */
6646 GtkTreePath *path = NULL;
6647 GtkIconViewDropPosition pos;
6649 *drop_append_mode = FALSE;
6651 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6656 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6657 pos == GTK_ICON_VIEW_DROP_BELOW)
6660 GtkTreeModel *model = icon_view->priv->model;
6662 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6663 !gtk_tree_model_iter_next (model, &iter))
6664 *drop_append_mode = TRUE;
6667 *drop_append_mode = FALSE;
6668 gtk_tree_path_next (path);
6676 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6677 GdkEventMotion *event)
6679 GtkWidget *widget = GTK_WIDGET (icon_view);
6680 GdkDragContext *context;
6681 GtkTreePath *path = NULL;
6683 GtkTreeModel *model;
6684 gboolean retval = FALSE;
6686 if (!icon_view->priv->source_set)
6689 if (icon_view->priv->pressed_button < 0)
6692 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6693 icon_view->priv->press_start_x,
6694 icon_view->priv->press_start_y,
6695 event->x, event->y))
6698 model = gtk_icon_view_get_model (icon_view);
6703 button = icon_view->priv->pressed_button;
6704 icon_view->priv->pressed_button = -1;
6706 path = gtk_icon_view_get_path_at_pos (icon_view,
6707 icon_view->priv->press_start_x,
6708 icon_view->priv->press_start_y);
6713 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6714 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6718 /* FIXME Check whether we're a start button, if not return FALSE and
6722 /* Now we can begin the drag */
6726 context = gtk_drag_begin (widget,
6727 gtk_drag_source_get_target_list (widget),
6728 icon_view->priv->source_actions,
6732 set_source_row (context, model, path);
6736 gtk_tree_path_free (path);
6741 /* Source side drag signals */
6743 gtk_icon_view_drag_begin (GtkWidget *widget,
6744 GdkDragContext *context)
6746 GtkIconView *icon_view;
6747 GtkIconViewItem *item;
6752 icon_view = GTK_ICON_VIEW (widget);
6754 /* if the user uses a custom DnD impl, we don't set the icon here */
6755 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6758 item = gtk_icon_view_get_item_at_coords (icon_view,
6759 icon_view->priv->press_start_x,
6760 icon_view->priv->press_start_y,
6764 g_return_if_fail (item != NULL);
6766 x = icon_view->priv->press_start_x - item->x + 1;
6767 y = icon_view->priv->press_start_y - item->y + 1;
6769 path = gtk_tree_path_new_from_indices (item->index, -1);
6770 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6771 gtk_tree_path_free (path);
6773 gtk_drag_set_icon_pixmap (context,
6774 gdk_drawable_get_colormap (icon),
6779 g_object_unref (icon);
6783 gtk_icon_view_drag_end (GtkWidget *widget,
6784 GdkDragContext *context)
6790 gtk_icon_view_drag_data_get (GtkWidget *widget,
6791 GdkDragContext *context,
6792 GtkSelectionData *selection_data,
6796 GtkIconView *icon_view;
6797 GtkTreeModel *model;
6798 GtkTreePath *source_row;
6800 icon_view = GTK_ICON_VIEW (widget);
6801 model = gtk_icon_view_get_model (icon_view);
6806 if (!icon_view->priv->source_set)
6809 source_row = get_source_row (context);
6811 if (source_row == NULL)
6814 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6815 * any model; for DragSource models there are some other targets
6819 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6820 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6825 /* If drag_data_get does nothing, try providing row data. */
6826 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6827 gtk_tree_set_row_drag_data (selection_data,
6832 gtk_tree_path_free (source_row);
6836 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6837 GdkDragContext *context)
6839 GtkTreeModel *model;
6840 GtkIconView *icon_view;
6841 GtkTreePath *source_row;
6843 icon_view = GTK_ICON_VIEW (widget);
6844 model = gtk_icon_view_get_model (icon_view);
6846 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6849 if (!icon_view->priv->source_set)
6852 source_row = get_source_row (context);
6854 if (source_row == NULL)
6857 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6860 gtk_tree_path_free (source_row);
6862 set_source_row (context, NULL, NULL);
6865 /* Target side drag signals */
6867 gtk_icon_view_drag_leave (GtkWidget *widget,
6868 GdkDragContext *context,
6871 GtkIconView *icon_view;
6873 icon_view = GTK_ICON_VIEW (widget);
6875 /* unset any highlight row */
6876 gtk_icon_view_set_drag_dest_item (icon_view,
6878 GTK_ICON_VIEW_DROP_LEFT);
6880 remove_scroll_timeout (icon_view);
6884 gtk_icon_view_drag_motion (GtkWidget *widget,
6885 GdkDragContext *context,
6890 GtkTreePath *path = NULL;
6891 GtkIconViewDropPosition pos;
6892 GtkIconView *icon_view;
6893 GdkDragAction suggested_action = 0;
6897 icon_view = GTK_ICON_VIEW (widget);
6899 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6902 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6904 /* we only know this *after* set_desination_row */
6905 empty = icon_view->priv->empty_view_drop;
6907 if (path == NULL && !empty)
6909 /* Can't drop here. */
6910 gdk_drag_status (context, 0, time);
6914 if (icon_view->priv->scroll_timeout_id == 0)
6916 icon_view->priv->scroll_timeout_id =
6917 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6920 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6922 /* Request data so we can use the source row when
6923 * determining whether to accept the drop
6925 set_status_pending (context, suggested_action);
6926 gtk_drag_get_data (widget, context, target, time);
6930 set_status_pending (context, 0);
6931 gdk_drag_status (context, suggested_action, time);
6936 gtk_tree_path_free (path);
6942 gtk_icon_view_drag_drop (GtkWidget *widget,
6943 GdkDragContext *context,
6948 GtkIconView *icon_view;
6950 GdkDragAction suggested_action = 0;
6951 GdkAtom target = GDK_NONE;
6952 GtkTreeModel *model;
6953 gboolean drop_append_mode;
6955 icon_view = GTK_ICON_VIEW (widget);
6956 model = gtk_icon_view_get_model (icon_view);
6958 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6960 if (!icon_view->priv->dest_set)
6963 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
6966 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6969 path = get_logical_destination (icon_view, &drop_append_mode);
6971 if (target != GDK_NONE && path != NULL)
6973 /* in case a motion had requested drag data, change things so we
6974 * treat drag data receives as a drop.
6976 set_status_pending (context, 0);
6977 set_dest_row (context, model, path,
6978 icon_view->priv->empty_view_drop, drop_append_mode);
6982 gtk_tree_path_free (path);
6984 /* Unset this thing */
6985 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6987 if (target != GDK_NONE)
6989 gtk_drag_get_data (widget, context, target, time);
6997 gtk_icon_view_drag_data_received (GtkWidget *widget,
6998 GdkDragContext *context,
7001 GtkSelectionData *selection_data,
7006 gboolean accepted = FALSE;
7007 GtkTreeModel *model;
7008 GtkIconView *icon_view;
7009 GtkTreePath *dest_row;
7010 GdkDragAction suggested_action;
7011 gboolean drop_append_mode;
7013 icon_view = GTK_ICON_VIEW (widget);
7014 model = gtk_icon_view_get_model (icon_view);
7016 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7019 if (!icon_view->priv->dest_set)
7022 suggested_action = get_status_pending (context);
7024 if (suggested_action)
7026 /* We are getting this data due to a request in drag_motion,
7027 * rather than due to a request in drag_drop, so we are just
7028 * supposed to call drag_status, not actually paste in the
7031 path = get_logical_destination (icon_view, &drop_append_mode);
7034 suggested_action = 0;
7036 if (suggested_action)
7038 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7041 suggested_action = 0;
7044 gdk_drag_status (context, suggested_action, time);
7047 gtk_tree_path_free (path);
7049 /* If you can't drop, remove user drop indicator until the next motion */
7050 if (suggested_action == 0)
7051 gtk_icon_view_set_drag_dest_item (icon_view,
7053 GTK_ICON_VIEW_DROP_LEFT);
7058 dest_row = get_dest_row (context);
7060 if (dest_row == NULL)
7063 if (selection_data->length >= 0)
7065 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7071 gtk_drag_finish (context,
7073 (context->action == GDK_ACTION_MOVE),
7076 gtk_tree_path_free (dest_row);
7079 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7082 /* Drag-and-Drop support */
7084 * gtk_icon_view_enable_model_drag_source:
7085 * @icon_view: a #GtkIconTreeView
7086 * @start_button_mask: Mask of allowed buttons to start drag
7087 * @targets: the table of targets that the drag will support
7088 * @n_targets: the number of items in @targets
7089 * @actions: the bitmask of possible actions for a drag from this
7092 * Turns @icon_view into a drag source for automatic DND. Calling this
7093 * method sets #GtkIconView:reorderable to %FALSE.
7098 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7099 GdkModifierType start_button_mask,
7100 const GtkTargetEntry *targets,
7102 GdkDragAction actions)
7104 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7106 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7108 icon_view->priv->start_button_mask = start_button_mask;
7109 icon_view->priv->source_actions = actions;
7111 icon_view->priv->source_set = TRUE;
7113 unset_reorderable (icon_view);
7117 * gtk_icon_view_enable_model_drag_dest:
7118 * @icon_view: a #GtkIconView
7119 * @targets: the table of targets that the drag will support
7120 * @n_targets: the number of items in @targets
7121 * @actions: the bitmask of possible actions for a drag to this
7124 * Turns @icon_view into a drop destination for automatic DND. Calling this
7125 * method sets #GtkIconView:reorderable to %FALSE.
7130 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7131 const GtkTargetEntry *targets,
7133 GdkDragAction actions)
7135 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7137 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7139 icon_view->priv->dest_actions = actions;
7141 icon_view->priv->dest_set = TRUE;
7143 unset_reorderable (icon_view);
7147 * gtk_icon_view_unset_model_drag_source:
7148 * @icon_view: a #GtkIconView
7150 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7151 * method sets #GtkIconView:reorderable to %FALSE.
7156 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7158 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7160 if (icon_view->priv->source_set)
7162 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7163 icon_view->priv->source_set = FALSE;
7166 unset_reorderable (icon_view);
7170 * gtk_icon_view_unset_model_drag_dest:
7171 * @icon_view: a #GtkIconView
7173 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7174 * method sets #GtkIconView:reorderable to %FALSE.
7179 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7181 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7183 if (icon_view->priv->dest_set)
7185 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7186 icon_view->priv->dest_set = FALSE;
7189 unset_reorderable (icon_view);
7192 /* These are useful to implement your own custom stuff. */
7194 * gtk_icon_view_set_drag_dest_item:
7195 * @icon_view: a #GtkIconView
7196 * @path: (allow-none): The path of the item to highlight, or %NULL.
7197 * @pos: Specifies where to drop, relative to the item
7199 * Sets the item that is highlighted for feedback.
7204 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7206 GtkIconViewDropPosition pos)
7208 /* Note; this function is exported to allow a custom DND
7209 * implementation, so it can't touch TreeViewDragInfo
7212 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7214 if (icon_view->priv->dest_item)
7216 GtkTreePath *current_path;
7217 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7218 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7219 icon_view->priv->dest_item = NULL;
7221 gtk_icon_view_queue_draw_path (icon_view, current_path);
7222 gtk_tree_path_free (current_path);
7225 /* special case a drop on an empty model */
7226 icon_view->priv->empty_view_drop = FALSE;
7227 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7228 && gtk_tree_path_get_depth (path) == 1
7229 && gtk_tree_path_get_indices (path)[0] == 0)
7233 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7236 if (n_children == 0)
7237 icon_view->priv->empty_view_drop = TRUE;
7240 icon_view->priv->dest_pos = pos;
7244 icon_view->priv->dest_item =
7245 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7246 icon_view->priv->model, path);
7248 gtk_icon_view_queue_draw_path (icon_view, path);
7253 * gtk_icon_view_get_drag_dest_item:
7254 * @icon_view: a #GtkIconView
7255 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7256 * @pos: (allow-none): Return location for the drop position, or %NULL
7258 * Gets information about the item that is highlighted for feedback.
7263 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7265 GtkIconViewDropPosition *pos)
7267 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7271 if (icon_view->priv->dest_item)
7272 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7278 *pos = icon_view->priv->dest_pos;
7282 * gtk_icon_view_get_dest_item_at_pos:
7283 * @icon_view: a #GtkIconView
7284 * @drag_x: the position to determine the destination item for
7285 * @drag_y: the position to determine the destination item for
7286 * @path: (allow-none): Return location for the path of the item, or %NULL.
7287 * @pos: (allow-none): Return location for the drop position, or %NULL
7289 * Determines the destination item for a given position.
7291 * Return value: whether there is an item at the given position.
7296 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7300 GtkIconViewDropPosition *pos)
7302 GtkIconViewItem *item;
7304 /* Note; this function is exported to allow a custom DND
7305 * implementation, so it can't touch TreeViewDragInfo
7308 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7309 g_return_val_if_fail (drag_x >= 0, FALSE);
7310 g_return_val_if_fail (drag_y >= 0, FALSE);
7311 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7317 item = gtk_icon_view_get_item_at_coords (icon_view,
7318 drag_x + icon_view->priv->hadjustment->value,
7319 drag_y + icon_view->priv->vadjustment->value,
7326 *path = gtk_tree_path_new_from_indices (item->index, -1);
7330 if (drag_x < item->x + item->width / 4)
7331 *pos = GTK_ICON_VIEW_DROP_LEFT;
7332 else if (drag_x > item->x + item->width * 3 / 4)
7333 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7334 else if (drag_y < item->y + item->height / 4)
7335 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7336 else if (drag_y > item->y + item->height * 3 / 4)
7337 *pos = GTK_ICON_VIEW_DROP_BELOW;
7339 *pos = GTK_ICON_VIEW_DROP_INTO;
7346 * gtk_icon_view_create_drag_icon:
7347 * @icon_view: a #GtkIconView
7348 * @path: a #GtkTreePath in @icon_view
7350 * Creates a #GdkPixmap representation of the item at @path.
7351 * This image is used for a drag icon.
7353 * Return value: a newly-allocated pixmap of the drag icon.
7358 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7363 GdkPixmap *drawable;
7368 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7369 g_return_val_if_fail (path != NULL, NULL);
7371 widget = GTK_WIDGET (icon_view);
7373 if (!gtk_widget_get_realized (widget))
7376 index = gtk_tree_path_get_indices (path)[0];
7378 for (l = icon_view->priv->items; l; l = l->next)
7380 GtkIconViewItem *item = l->data;
7382 if (index == item->index)
7384 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7389 cr = gdk_cairo_create (drawable);
7390 cairo_set_line_width (cr, 1.);
7392 gdk_cairo_set_source_color
7393 (cr, &widget->style->base[gtk_widget_get_state (widget)]);
7394 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7399 area.width = item->width;
7400 area.height = item->height;
7402 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7403 drawable, 1, 1, FALSE);
7405 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7406 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7419 * gtk_icon_view_get_reorderable:
7420 * @icon_view: a #GtkIconView
7422 * Retrieves whether the user can reorder the list via drag-and-drop.
7423 * See gtk_icon_view_set_reorderable().
7425 * Return value: %TRUE if the list can be reordered.
7430 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7432 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7434 return icon_view->priv->reorderable;
7437 static const GtkTargetEntry item_targets[] = {
7438 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7443 * gtk_icon_view_set_reorderable:
7444 * @icon_view: A #GtkIconView.
7445 * @reorderable: %TRUE, if the list of items can be reordered.
7447 * This function is a convenience function to allow you to reorder models that
7448 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7449 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7450 * the user can reorder the model by dragging and dropping rows. The
7451 * developer can listen to these changes by connecting to the model's
7452 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7453 * the icon view as a drag source and destination. Therefore, drag and
7454 * drop can not be used in a reorderable view for any other purpose.
7456 * This function does not give you any degree of control over the order -- any
7457 * reordering is allowed. If more control is needed, you should probably
7458 * handle drag and drop manually.
7463 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7464 gboolean reorderable)
7466 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7468 reorderable = reorderable != FALSE;
7470 if (icon_view->priv->reorderable == reorderable)
7475 gtk_icon_view_enable_model_drag_source (icon_view,
7478 G_N_ELEMENTS (item_targets),
7480 gtk_icon_view_enable_model_drag_dest (icon_view,
7482 G_N_ELEMENTS (item_targets),
7487 gtk_icon_view_unset_model_drag_source (icon_view);
7488 gtk_icon_view_unset_model_drag_dest (icon_view);
7491 icon_view->priv->reorderable = reorderable;
7493 g_object_notify (G_OBJECT (icon_view), "reorderable");
7497 /* Accessibility Support */
7499 static gpointer accessible_parent_class;
7500 static gpointer accessible_item_parent_class;
7501 static GQuark accessible_private_data_quark = 0;
7503 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7504 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7505 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7507 static GType gtk_icon_view_item_accessible_get_type (void);
7518 GtkIconViewItem *item;
7522 AtkStateSet *state_set;
7526 GtkTextBuffer *text_buffer;
7528 gchar *action_descriptions[LAST_ACTION];
7529 gchar *image_description;
7530 guint action_idle_handler;
7531 } GtkIconViewItemAccessible;
7533 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7539 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7544 typedef struct _GtkIconViewItemAccessibleClass
7546 AtkObjectClass parent_class;
7548 } GtkIconViewItemAccessibleClass;
7550 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7553 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7555 GtkIconViewItemAccessible *item;
7556 GtkIconView *icon_view;
7559 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7560 item->action_idle_handler = 0;
7562 if (item->widget != NULL)
7564 icon_view = GTK_ICON_VIEW (item->widget);
7565 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7566 gtk_icon_view_item_activated (icon_view, path);
7567 gtk_tree_path_free (path);
7574 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7577 GtkIconViewItemAccessible *item;
7579 if (i < 0 || i >= LAST_ACTION)
7582 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7584 if (!GTK_IS_ICON_VIEW (item->widget))
7587 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7592 case ACTION_ACTIVATE:
7593 if (!item->action_idle_handler)
7594 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7597 g_assert_not_reached ();
7605 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7610 static const gchar *
7611 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7614 GtkIconViewItemAccessible *item;
7616 if (i < 0 || i >= LAST_ACTION)
7619 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7621 if (item->action_descriptions[i])
7622 return item->action_descriptions[i];
7624 return gtk_icon_view_item_accessible_action_descriptions[i];
7627 static const gchar *
7628 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7631 if (i < 0 || i >= LAST_ACTION)
7634 return gtk_icon_view_item_accessible_action_names[i];
7638 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7640 const gchar *description)
7642 GtkIconViewItemAccessible *item;
7644 if (i < 0 || i >= LAST_ACTION)
7647 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7649 g_free (item->action_descriptions[i]);
7651 item->action_descriptions[i] = g_strdup (description);
7657 atk_action_item_interface_init (AtkActionIface *iface)
7659 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7660 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7661 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7662 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7663 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7666 static const gchar *
7667 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7669 GtkIconViewItemAccessible *item;
7671 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7673 return item->image_description;
7677 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7678 const gchar *description)
7680 GtkIconViewItemAccessible *item;
7682 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7684 g_free (item->image_description);
7685 item->image_description = g_strdup (description);
7691 get_pixbuf_box (GtkIconView *icon_view,
7692 GtkIconViewItem *item,
7697 for (l = icon_view->priv->cell_list; l; l = l->next)
7699 GtkIconViewCellInfo *info = l->data;
7701 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7703 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7713 get_text (GtkIconView *icon_view,
7714 GtkIconViewItem *item)
7719 for (l = icon_view->priv->cell_list; l; l = l->next)
7721 GtkIconViewCellInfo *info = l->data;
7723 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7725 g_object_get (info->cell, "text", &text, NULL);
7735 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7739 GtkIconViewItemAccessible *item;
7742 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7744 if (!GTK_IS_ICON_VIEW (item->widget))
7747 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7750 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7753 *height = box.height;
7758 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7761 AtkCoordType coord_type)
7763 GtkIconViewItemAccessible *item;
7766 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7768 if (!GTK_IS_ICON_VIEW (item->widget))
7771 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7774 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7776 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7778 *x+= box.x - item->item->x;
7779 *y+= box.y - item->item->y;
7785 atk_image_item_interface_init (AtkImageIface *iface)
7787 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7788 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7789 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7790 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7794 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7798 GtkIconViewItemAccessible *item;
7799 GtkTextIter start, end;
7800 GtkTextBuffer *buffer;
7802 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7804 if (!GTK_IS_ICON_VIEW (item->widget))
7807 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7810 buffer = item->text_buffer;
7811 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7813 gtk_text_buffer_get_end_iter (buffer, &end);
7815 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7817 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7821 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7824 GtkIconViewItemAccessible *item;
7825 GtkTextIter start, end;
7826 GtkTextBuffer *buffer;
7830 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7832 if (!GTK_IS_ICON_VIEW (item->widget))
7835 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7838 buffer = item->text_buffer;
7839 if (offset >= gtk_text_buffer_get_char_count (buffer))
7842 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7844 gtk_text_iter_forward_char (&end);
7845 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7846 unichar = g_utf8_get_char (string);
7854 get_pango_text_offsets (PangoLayout *layout,
7855 GtkTextBuffer *buffer,
7857 AtkTextBoundary boundary_type,
7861 GtkTextIter *start_iter,
7862 GtkTextIter *end_iter)
7864 PangoLayoutIter *iter;
7865 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7866 gint index, start_index, end_index;
7868 gboolean found = FALSE;
7870 text = pango_layout_get_text (layout);
7871 index = g_utf8_offset_to_pointer (text, offset) - text;
7872 iter = pango_layout_get_iter (layout);
7875 line = pango_layout_iter_get_line_readonly (iter);
7876 start_index = line->start_index;
7877 end_index = start_index + line->length;
7879 if (index >= start_index && index <= end_index)
7882 * Found line for offset
7888 * We want the previous line
7892 switch (boundary_type)
7894 case ATK_TEXT_BOUNDARY_LINE_START:
7895 end_index = start_index;
7896 start_index = prev_line->start_index;
7898 case ATK_TEXT_BOUNDARY_LINE_END:
7900 start_index = prev_prev_line->start_index +
7901 prev_prev_line->length;
7902 end_index = prev_line->start_index + prev_line->length;
7905 g_assert_not_reached();
7909 start_index = end_index = 0;
7912 switch (boundary_type)
7914 case ATK_TEXT_BOUNDARY_LINE_START:
7915 if (pango_layout_iter_next_line (iter))
7916 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7918 case ATK_TEXT_BOUNDARY_LINE_END:
7920 start_index = prev_line->start_index +
7924 g_assert_not_reached();
7929 * We want the next line
7931 if (pango_layout_iter_next_line (iter))
7933 line = pango_layout_iter_get_line_readonly (iter);
7934 switch (boundary_type)
7936 case ATK_TEXT_BOUNDARY_LINE_START:
7937 start_index = line->start_index;
7938 if (pango_layout_iter_next_line (iter))
7939 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7941 end_index = start_index + line->length;
7943 case ATK_TEXT_BOUNDARY_LINE_END:
7944 start_index = end_index;
7945 end_index = line->start_index + line->length;
7948 g_assert_not_reached();
7952 start_index = end_index;
7958 prev_prev_line = prev_line;
7961 while (pango_layout_iter_next_line (iter));
7965 start_index = prev_line->start_index + prev_line->length;
7966 end_index = start_index;
7968 pango_layout_iter_free (iter);
7969 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7970 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7972 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7973 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7978 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7980 AtkTextBoundary boundary_type,
7984 GtkIconViewItemAccessible *item;
7985 GtkTextIter start, end;
7986 GtkTextBuffer *buffer;
7988 GtkIconView *icon_view;
7991 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7993 if (!GTK_IS_ICON_VIEW (item->widget))
7996 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7999 buffer = item->text_buffer;
8001 if (!gtk_text_buffer_get_char_count (buffer))
8005 return g_strdup ("");
8007 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8011 switch (boundary_type)
8013 case ATK_TEXT_BOUNDARY_CHAR:
8014 gtk_text_iter_backward_char(&start);
8016 case ATK_TEXT_BOUNDARY_WORD_START:
8017 if (!gtk_text_iter_starts_word (&start))
8018 gtk_text_iter_backward_word_start (&start);
8020 gtk_text_iter_backward_word_start(&start);
8022 case ATK_TEXT_BOUNDARY_WORD_END:
8023 if (gtk_text_iter_inside_word (&start) &&
8024 !gtk_text_iter_starts_word (&start))
8025 gtk_text_iter_backward_word_start (&start);
8026 while (!gtk_text_iter_ends_word (&start))
8028 if (!gtk_text_iter_backward_char (&start))
8032 gtk_text_iter_backward_word_start(&start);
8033 while (!gtk_text_iter_ends_word (&start))
8035 if (!gtk_text_iter_backward_char (&start))
8039 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8040 if (!gtk_text_iter_starts_sentence (&start))
8041 gtk_text_iter_backward_sentence_start (&start);
8043 gtk_text_iter_backward_sentence_start (&start);
8045 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8046 if (gtk_text_iter_inside_sentence (&start) &&
8047 !gtk_text_iter_starts_sentence (&start))
8048 gtk_text_iter_backward_sentence_start (&start);
8049 while (!gtk_text_iter_ends_sentence (&start))
8051 if (!gtk_text_iter_backward_char (&start))
8055 gtk_text_iter_backward_sentence_start (&start);
8056 while (!gtk_text_iter_ends_sentence (&start))
8058 if (!gtk_text_iter_backward_char (&start))
8062 case ATK_TEXT_BOUNDARY_LINE_START:
8063 case ATK_TEXT_BOUNDARY_LINE_END:
8065 icon_view = GTK_ICON_VIEW (item->widget);
8066 /* FIXME we probably have to use GailTextCell to salvage this */
8067 gtk_icon_view_update_item_text (icon_view, item->item);
8068 get_pango_text_offsets (icon_view->priv->layout,
8081 *start_offset = gtk_text_iter_get_offset (&start);
8082 *end_offset = gtk_text_iter_get_offset (&end);
8084 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8088 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8090 AtkTextBoundary boundary_type,
8094 GtkIconViewItemAccessible *item;
8095 GtkTextIter start, end;
8096 GtkTextBuffer *buffer;
8098 GtkIconView *icon_view;
8101 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8103 if (!GTK_IS_ICON_VIEW (item->widget))
8106 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8109 buffer = item->text_buffer;
8111 if (!gtk_text_buffer_get_char_count (buffer))
8115 return g_strdup ("");
8117 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8121 switch (boundary_type)
8123 case ATK_TEXT_BOUNDARY_CHAR:
8124 gtk_text_iter_forward_char (&end);
8126 case ATK_TEXT_BOUNDARY_WORD_START:
8127 if (!gtk_text_iter_starts_word (&start))
8128 gtk_text_iter_backward_word_start (&start);
8129 if (gtk_text_iter_inside_word (&end))
8130 gtk_text_iter_forward_word_end (&end);
8131 while (!gtk_text_iter_starts_word (&end))
8133 if (!gtk_text_iter_forward_char (&end))
8137 case ATK_TEXT_BOUNDARY_WORD_END:
8138 if (gtk_text_iter_inside_word (&start) &&
8139 !gtk_text_iter_starts_word (&start))
8140 gtk_text_iter_backward_word_start (&start);
8141 while (!gtk_text_iter_ends_word (&start))
8143 if (!gtk_text_iter_backward_char (&start))
8146 gtk_text_iter_forward_word_end (&end);
8148 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8149 if (!gtk_text_iter_starts_sentence (&start))
8150 gtk_text_iter_backward_sentence_start (&start);
8151 if (gtk_text_iter_inside_sentence (&end))
8152 gtk_text_iter_forward_sentence_end (&end);
8153 while (!gtk_text_iter_starts_sentence (&end))
8155 if (!gtk_text_iter_forward_char (&end))
8159 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8160 if (gtk_text_iter_inside_sentence (&start) &&
8161 !gtk_text_iter_starts_sentence (&start))
8162 gtk_text_iter_backward_sentence_start (&start);
8163 while (!gtk_text_iter_ends_sentence (&start))
8165 if (!gtk_text_iter_backward_char (&start))
8168 gtk_text_iter_forward_sentence_end (&end);
8170 case ATK_TEXT_BOUNDARY_LINE_START:
8171 case ATK_TEXT_BOUNDARY_LINE_END:
8173 icon_view = GTK_ICON_VIEW (item->widget);
8174 /* FIXME we probably have to use GailTextCell to salvage this */
8175 gtk_icon_view_update_item_text (icon_view, item->item);
8176 get_pango_text_offsets (icon_view->priv->layout,
8190 *start_offset = gtk_text_iter_get_offset (&start);
8191 *end_offset = gtk_text_iter_get_offset (&end);
8193 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8197 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8199 AtkTextBoundary boundary_type,
8203 GtkIconViewItemAccessible *item;
8204 GtkTextIter start, end;
8205 GtkTextBuffer *buffer;
8207 GtkIconView *icon_view;
8210 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8212 if (!GTK_IS_ICON_VIEW (item->widget))
8215 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8218 buffer = item->text_buffer;
8220 if (!gtk_text_buffer_get_char_count (buffer))
8224 return g_strdup ("");
8226 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8230 switch (boundary_type)
8232 case ATK_TEXT_BOUNDARY_CHAR:
8233 gtk_text_iter_forward_char(&start);
8234 gtk_text_iter_forward_chars(&end, 2);
8236 case ATK_TEXT_BOUNDARY_WORD_START:
8237 if (gtk_text_iter_inside_word (&end))
8238 gtk_text_iter_forward_word_end (&end);
8239 while (!gtk_text_iter_starts_word (&end))
8241 if (!gtk_text_iter_forward_char (&end))
8245 if (!gtk_text_iter_is_end (&end))
8247 gtk_text_iter_forward_word_end (&end);
8248 while (!gtk_text_iter_starts_word (&end))
8250 if (!gtk_text_iter_forward_char (&end))
8255 case ATK_TEXT_BOUNDARY_WORD_END:
8256 gtk_text_iter_forward_word_end (&end);
8258 if (!gtk_text_iter_is_end (&end))
8259 gtk_text_iter_forward_word_end (&end);
8261 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8262 if (gtk_text_iter_inside_sentence (&end))
8263 gtk_text_iter_forward_sentence_end (&end);
8264 while (!gtk_text_iter_starts_sentence (&end))
8266 if (!gtk_text_iter_forward_char (&end))
8270 if (!gtk_text_iter_is_end (&end))
8272 gtk_text_iter_forward_sentence_end (&end);
8273 while (!gtk_text_iter_starts_sentence (&end))
8275 if (!gtk_text_iter_forward_char (&end))
8280 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8281 gtk_text_iter_forward_sentence_end (&end);
8283 if (!gtk_text_iter_is_end (&end))
8284 gtk_text_iter_forward_sentence_end (&end);
8286 case ATK_TEXT_BOUNDARY_LINE_START:
8287 case ATK_TEXT_BOUNDARY_LINE_END:
8289 icon_view = GTK_ICON_VIEW (item->widget);
8290 /* FIXME we probably have to use GailTextCell to salvage this */
8291 gtk_icon_view_update_item_text (icon_view, item->item);
8292 get_pango_text_offsets (icon_view->priv->layout,
8304 *start_offset = gtk_text_iter_get_offset (&start);
8305 *end_offset = gtk_text_iter_get_offset (&end);
8307 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8311 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8313 GtkIconViewItemAccessible *item;
8315 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8317 if (!GTK_IS_ICON_VIEW (item->widget))
8320 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8323 return gtk_text_buffer_get_char_count (item->text_buffer);
8327 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8333 AtkCoordType coord_type)
8335 GtkIconViewItemAccessible *item;
8337 GtkIconView *icon_view;
8338 PangoRectangle char_rect;
8339 const gchar *item_text;
8343 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8345 if (!GTK_IS_ICON_VIEW (item->widget))
8348 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8352 icon_view = GTK_ICON_VIEW (item->widget);
8353 /* FIXME we probably have to use GailTextCell to salvage this */
8354 gtk_icon_view_update_item_text (icon_view, item->item);
8355 item_text = pango_layout_get_text (icon_view->priv->layout);
8356 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8357 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8359 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8360 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8361 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8362 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8363 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8364 *width = char_rect.width / PANGO_SCALE;
8365 *height = char_rect.height / PANGO_SCALE;
8370 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8373 AtkCoordType coord_type)
8375 GtkIconViewItemAccessible *item;
8378 GtkIconView *icon_view;
8379 const gchar *item_text;
8384 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8386 if (!GTK_IS_ICON_VIEW (item->widget))
8389 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8393 icon_view = GTK_ICON_VIEW (item->widget);
8394 /* FIXME we probably have to use GailTextCell to salvage this */
8395 gtk_icon_view_update_item_text (icon_view, item->item);
8396 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8397 x -= l_x + item->item->layout_x - item->item->x;
8398 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8399 y -= l_y + item->item->layout_y - item->item->y;
8400 item_text = pango_layout_get_text (icon_view->priv->layout);
8401 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8412 offset = g_utf8_strlen (item_text, -1);
8414 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8420 atk_text_item_interface_init (AtkTextIface *iface)
8422 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8423 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8424 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8425 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8426 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8427 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8428 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8429 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8433 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8438 AtkCoordType coord_type)
8440 GtkIconViewItemAccessible *item;
8441 AtkObject *parent_obj;
8444 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8446 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8447 if (!GTK_IS_WIDGET (item->widget))
8450 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8453 *width = item->item->width;
8454 *height = item->item->height;
8455 if (gtk_icon_view_item_accessible_is_showing (item))
8457 parent_obj = gtk_widget_get_accessible (item->widget);
8458 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8459 *x = l_x + item->item->x;
8460 *y = l_y + item->item->y;
8470 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8472 GtkIconViewItemAccessible *item;
8473 GtkWidget *toplevel;
8475 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8477 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8478 if (!GTK_IS_WIDGET (item->widget))
8481 gtk_widget_grab_focus (item->widget);
8482 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8483 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8484 if (gtk_widget_is_toplevel (toplevel))
8485 gtk_window_present (GTK_WINDOW (toplevel));
8491 atk_component_item_interface_init (AtkComponentIface *iface)
8493 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8494 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8498 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8499 AtkStateType state_type,
8500 gboolean emit_signal)
8504 rc = atk_state_set_add_state (item->state_set, state_type);
8506 * The signal should only be generated if the value changed,
8507 * not when the item is set up. So states that are set
8508 * initially should pass FALSE as the emit_signal argument.
8513 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8514 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8515 if (state_type == ATK_STATE_VISIBLE)
8516 g_signal_emit_by_name (item, "visible-data-changed");
8523 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8524 AtkStateType state_type,
8525 gboolean emit_signal)
8527 if (atk_state_set_contains_state (item->state_set, state_type))
8531 rc = atk_state_set_remove_state (item->state_set, state_type);
8533 * The signal should only be generated if the value changed,
8534 * not when the item is set up. So states that are set
8535 * initially should pass FALSE as the emit_signal argument.
8540 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8541 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8542 if (state_type == ATK_STATE_VISIBLE)
8543 g_signal_emit_by_name (item, "visible-data-changed");
8553 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8555 GtkIconView *icon_view;
8556 GdkRectangle visible_rect;
8557 gboolean is_showing;
8560 * An item is considered "SHOWING" if any part of the item is in the
8561 * visible rectangle.
8564 if (!GTK_IS_ICON_VIEW (item->widget))
8567 if (item->item == NULL)
8570 icon_view = GTK_ICON_VIEW (item->widget);
8572 if (icon_view->priv->hadjustment)
8573 visible_rect.x += icon_view->priv->hadjustment->value;
8575 if (icon_view->priv->hadjustment)
8576 visible_rect.y += icon_view->priv->vadjustment->value;
8577 visible_rect.width = item->widget->allocation.width;
8578 visible_rect.height = item->widget->allocation.height;
8580 if (((item->item->x + item->item->width) < visible_rect.x) ||
8581 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8582 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8583 (item->item->y > (visible_rect.y + visible_rect.height)))
8592 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8593 gboolean emit_signal)
8595 if (gtk_icon_view_item_accessible_is_showing (item))
8596 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8599 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8604 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8608 item->state_set = atk_state_set_new ();
8610 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8611 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8612 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8613 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8614 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8616 for (i = 0; i < LAST_ACTION; i++)
8617 item->action_descriptions[i] = NULL;
8619 item->image_description = NULL;
8621 item->action_idle_handler = 0;
8625 gtk_icon_view_item_accessible_finalize (GObject *object)
8627 GtkIconViewItemAccessible *item;
8630 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8632 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8635 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8637 if (item->state_set)
8638 g_object_unref (item->state_set);
8640 if (item->text_buffer)
8641 g_object_unref (item->text_buffer);
8643 for (i = 0; i < LAST_ACTION; i++)
8644 g_free (item->action_descriptions[i]);
8646 g_free (item->image_description);
8648 if (item->action_idle_handler)
8650 g_source_remove (item->action_idle_handler);
8651 item->action_idle_handler = 0;
8654 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8657 static G_CONST_RETURN gchar*
8658 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8664 GtkIconViewItemAccessible *item;
8665 GtkTextIter start_iter;
8666 GtkTextIter end_iter;
8668 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8670 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8671 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8673 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8678 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8680 GtkIconViewItemAccessible *item;
8682 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8683 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8686 return gtk_widget_get_accessible (item->widget);
8692 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8694 GtkIconViewItemAccessible *item;
8696 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8697 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8699 return item->item->index;
8702 static AtkStateSet *
8703 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8705 GtkIconViewItemAccessible *item;
8706 GtkIconView *icon_view;
8708 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8709 g_return_val_if_fail (item->state_set, NULL);
8714 icon_view = GTK_ICON_VIEW (item->widget);
8715 if (icon_view->priv->cursor_item == item->item)
8716 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8718 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8719 if (item->item->selected)
8720 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8722 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8724 return g_object_ref (item->state_set);
8728 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8730 GObjectClass *gobject_class;
8732 accessible_item_parent_class = g_type_class_peek_parent (klass);
8734 gobject_class = (GObjectClass *)klass;
8736 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8738 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8739 klass->get_name = gtk_icon_view_item_accessible_get_name;
8740 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8741 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8745 gtk_icon_view_item_accessible_get_type (void)
8747 static GType type = 0;
8751 const GTypeInfo tinfo =
8753 sizeof (GtkIconViewItemAccessibleClass),
8754 (GBaseInitFunc) NULL, /* base init */
8755 (GBaseFinalizeFunc) NULL, /* base finalize */
8756 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8757 (GClassFinalizeFunc) NULL, /* class finalize */
8758 NULL, /* class data */
8759 sizeof (GtkIconViewItemAccessible), /* instance size */
8760 0, /* nb preallocs */
8761 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8762 NULL /* value table */
8765 const GInterfaceInfo atk_component_info =
8767 (GInterfaceInitFunc) atk_component_item_interface_init,
8768 (GInterfaceFinalizeFunc) NULL,
8771 const GInterfaceInfo atk_action_info =
8773 (GInterfaceInitFunc) atk_action_item_interface_init,
8774 (GInterfaceFinalizeFunc) NULL,
8777 const GInterfaceInfo atk_image_info =
8779 (GInterfaceInitFunc) atk_image_item_interface_init,
8780 (GInterfaceFinalizeFunc) NULL,
8783 const GInterfaceInfo atk_text_info =
8785 (GInterfaceInitFunc) atk_text_item_interface_init,
8786 (GInterfaceFinalizeFunc) NULL,
8790 type = g_type_register_static (ATK_TYPE_OBJECT,
8791 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8792 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8793 &atk_component_info);
8794 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8796 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8798 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8805 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8806 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8807 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8809 static GType gtk_icon_view_accessible_get_type (void);
8814 } GtkIconViewAccessible;
8820 } GtkIconViewItemAccessibleInfo;
8826 GtkAdjustment *old_hadj;
8827 GtkAdjustment *old_vadj;
8829 GtkTreeModel *model;
8831 } GtkIconViewAccessiblePrivate;
8833 static GtkIconViewAccessiblePrivate *
8834 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8836 return g_object_get_qdata (G_OBJECT (accessible),
8837 accessible_private_data_quark);
8841 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8845 GtkIconViewItemAccessibleInfo *info;
8846 GtkIconViewItemAccessibleInfo *tmp_info;
8847 GtkIconViewAccessiblePrivate *priv;
8850 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8852 info->index = index;
8854 priv = gtk_icon_view_accessible_get_priv (accessible);
8855 items = priv->items;
8858 tmp_info = items->data;
8859 if (tmp_info->index > index)
8861 items = items->next;
8863 priv->items = g_list_insert_before (priv->items, items, info);
8864 priv->old_hadj = NULL;
8865 priv->old_vadj = NULL;
8869 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8871 GtkIconView *icon_view;
8874 widget = GTK_ACCESSIBLE (accessible)->widget;
8878 icon_view = GTK_ICON_VIEW (widget);
8880 return g_list_length (icon_view->priv->items);
8884 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8887 GtkIconViewAccessiblePrivate *priv;
8888 GtkIconViewItemAccessibleInfo *info;
8891 priv = gtk_icon_view_accessible_get_priv (accessible);
8892 items = priv->items;
8897 if (info->index == index)
8899 items = items->next;
8905 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8908 GtkIconView *icon_view;
8912 GtkIconViewItemAccessible *a11y_item;
8914 widget = GTK_ACCESSIBLE (accessible)->widget;
8918 icon_view = GTK_ICON_VIEW (widget);
8919 icons = g_list_nth (icon_view->priv->items, index);
8923 GtkIconViewItem *item = icons->data;
8925 g_return_val_if_fail (item->index == index, NULL);
8926 obj = gtk_icon_view_accessible_find_child (accessible, index);
8931 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8932 gtk_icon_view_item_accessible_info_new (accessible,
8935 obj->role = ATK_ROLE_ICON;
8936 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8937 a11y_item->item = item;
8938 a11y_item->widget = widget;
8939 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8941 gtk_icon_view_set_cell_data (icon_view, item);
8942 text = get_text (icon_view, item);
8945 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8949 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8950 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8958 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8961 GtkIconViewAccessiblePrivate *priv;
8962 GtkIconViewItemAccessibleInfo *info;
8963 GtkIconViewItemAccessible *item;
8966 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8970 gboolean act_on_item;
8972 widget = GTK_ACCESSIBLE (view)->widget;
8976 items = priv->items;
8978 act_on_item = (list == NULL);
8983 info = (GtkIconViewItemAccessibleInfo *)items->data;
8984 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8986 if (act_on_item == FALSE && list == items)
8990 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8992 items = items->next;
8998 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8999 GtkIconView *icon_view)
9002 GtkIconViewAccessible *view;
9005 * The scrollbars have changed
9007 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9008 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9010 gtk_icon_view_accessible_traverse_items (view, NULL);
9014 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9015 GtkAdjustment *hadj,
9016 GtkAdjustment *vadj)
9019 GtkIconViewAccessiblePrivate *priv;
9021 atk_obj = gtk_widget_get_accessible (widget);
9022 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9024 if (priv->old_hadj != hadj)
9028 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9029 (gpointer *)&priv->old_hadj);
9031 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9032 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9035 priv->old_hadj = hadj;
9038 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9039 (gpointer *)&priv->old_hadj);
9040 g_signal_connect (hadj,
9042 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9046 if (priv->old_vadj != vadj)
9050 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9051 (gpointer *)&priv->old_vadj);
9053 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9054 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9057 priv->old_vadj = vadj;
9060 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9061 (gpointer *)&priv->old_vadj);
9062 g_signal_connect (vadj,
9064 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9071 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9079 GtkIconView *icon_view;
9080 GtkIconViewItem *item;
9081 GtkIconViewAccessible *a11y_view;
9082 GtkIconViewItemAccessible *a11y_item;
9086 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9087 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9088 index = gtk_tree_path_get_indices(path)[0];
9089 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9090 gtk_icon_view_accessible_find_child (atk_obj, index));
9094 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9095 icon_view = GTK_ICON_VIEW (widget);
9096 item = a11y_item->item;
9098 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9100 if (!name || strcmp (name, "") == 0)
9102 gtk_icon_view_set_cell_data (icon_view, item);
9103 text = get_text (icon_view, item);
9106 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9112 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9118 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9123 GtkIconViewAccessiblePrivate *priv;
9124 GtkIconViewItemAccessibleInfo *info;
9125 GtkIconViewAccessible *view;
9126 GtkIconViewItemAccessible *item;
9132 index = gtk_tree_path_get_indices(path)[0];
9133 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9134 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9135 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9137 items = priv->items;
9142 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9143 if (info->index != item->item->index)
9145 if (info->index < index)
9146 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9148 if (tmp_list == NULL)
9151 info->index = item->item->index;
9154 items = items->next;
9156 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9157 g_signal_emit_by_name (atk_obj, "children-changed::add",
9163 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9167 GtkIconViewAccessiblePrivate *priv;
9168 GtkIconViewItemAccessibleInfo *info;
9169 GtkIconViewAccessible *view;
9170 GtkIconViewItemAccessible *item;
9173 GList *deleted_item;
9177 index = gtk_tree_path_get_indices(path)[0];
9178 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9179 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9180 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9182 items = priv->items;
9184 deleted_item = NULL;
9189 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9190 if (info->index == index)
9192 deleted_item = items;
9194 if (info->index != item->item->index)
9196 if (tmp_list == NULL)
9199 info->index = item->item->index;
9202 items = items->next;
9204 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9207 info = deleted_item->data;
9208 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9209 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9211 priv->items = g_list_remove_link (priv->items, deleted_item);
9219 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9220 GtkIconViewItemAccessibleInfo *i2)
9222 return i1->index - i2->index;
9226 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9232 GtkIconViewAccessiblePrivate *priv;
9233 GtkIconViewItemAccessibleInfo *info;
9234 GtkIconView *icon_view;
9235 GtkIconViewItemAccessible *item;
9241 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9242 icon_view = GTK_ICON_VIEW (user_data);
9243 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9245 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9247 order = g_new (gint, length);
9248 for (i = 0; i < length; i++)
9249 order [new_order[i]] = i;
9251 items = priv->items;
9255 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9256 info->index = order[info->index];
9257 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9258 items = items->next;
9261 priv->items = g_list_sort (priv->items,
9262 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9268 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9273 obj = G_OBJECT (model);
9274 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9275 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9276 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9277 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9281 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9285 obj = G_OBJECT (icon_view->priv->model);
9286 g_signal_connect_data (obj, "row-changed",
9287 (GCallback) gtk_icon_view_accessible_model_row_changed,
9288 icon_view, NULL, 0);
9289 g_signal_connect_data (obj, "row-inserted",
9290 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9291 icon_view, NULL, G_CONNECT_AFTER);
9292 g_signal_connect_data (obj, "row-deleted",
9293 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9294 icon_view, NULL, G_CONNECT_AFTER);
9295 g_signal_connect_data (obj, "rows-reordered",
9296 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9297 icon_view, NULL, G_CONNECT_AFTER);
9301 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9303 GtkIconViewItemAccessibleInfo *info;
9306 items = priv->items;
9309 info = (GtkIconViewItemAccessibleInfo *) items->data;
9310 g_object_unref (info->item);
9311 g_free (items->data);
9312 items = items->next;
9314 g_list_free (priv->items);
9319 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9322 GtkIconView *icon_view;
9325 GtkIconViewAccessiblePrivate *priv;
9327 if (strcmp (pspec->name, "model") == 0)
9329 widget = GTK_WIDGET (obj);
9330 atk_obj = gtk_widget_get_accessible (widget);
9331 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9334 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9335 (gpointer *)&priv->model);
9336 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9338 gtk_icon_view_accessible_clear_cache (priv);
9340 icon_view = GTK_ICON_VIEW (obj);
9341 priv->model = icon_view->priv->model;
9342 /* If there is no model the GtkIconView is probably being destroyed */
9345 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9346 gtk_icon_view_accessible_connect_model_signals (icon_view);
9354 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9357 GtkIconViewAccessiblePrivate *priv;
9358 GtkIconView *icon_view;
9360 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9361 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9363 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9364 g_object_set_qdata (G_OBJECT (accessible),
9365 accessible_private_data_quark,
9368 icon_view = GTK_ICON_VIEW (data);
9369 if (icon_view->priv->hadjustment)
9371 priv->old_hadj = icon_view->priv->hadjustment;
9372 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9373 g_signal_connect (icon_view->priv->hadjustment,
9375 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9378 if (icon_view->priv->vadjustment)
9380 priv->old_vadj = icon_view->priv->vadjustment;
9381 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9382 g_signal_connect (icon_view->priv->vadjustment,
9384 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9387 g_signal_connect_after (data,
9388 "set-scroll-adjustments",
9389 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9391 g_signal_connect (data,
9393 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9396 priv->model = icon_view->priv->model;
9399 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9400 gtk_icon_view_accessible_connect_model_signals (icon_view);
9403 accessible->role = ATK_ROLE_LAYERED_PANE;
9407 gtk_icon_view_accessible_finalize (GObject *object)
9409 GtkIconViewAccessiblePrivate *priv;
9411 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9412 gtk_icon_view_accessible_clear_cache (priv);
9416 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9420 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9421 GtkAccessible *accessible)
9424 GtkIconViewAccessiblePrivate *priv;
9426 atk_obj = ATK_OBJECT (accessible);
9427 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9430 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9431 (gpointer *)&priv->old_hadj);
9433 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9434 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9436 priv->old_hadj = NULL;
9440 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9441 (gpointer *)&priv->old_vadj);
9443 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9444 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9446 priv->old_vadj = NULL;
9451 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9453 if (accessible->widget)
9455 g_signal_connect_after (accessible->widget,
9457 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9460 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9464 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9466 GObjectClass *gobject_class;
9467 GtkAccessibleClass *accessible_class;
9469 accessible_parent_class = g_type_class_peek_parent (klass);
9471 gobject_class = (GObjectClass *)klass;
9472 accessible_class = (GtkAccessibleClass *)klass;
9474 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9476 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9477 klass->ref_child = gtk_icon_view_accessible_ref_child;
9478 klass->initialize = gtk_icon_view_accessible_initialize;
9480 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9482 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9486 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9489 AtkCoordType coord_type)
9492 GtkIconView *icon_view;
9493 GtkIconViewItem *item;
9496 widget = GTK_ACCESSIBLE (component)->widget;
9498 /* State is defunct */
9501 icon_view = GTK_ICON_VIEW (widget);
9502 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9503 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9505 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9511 atk_component_interface_init (AtkComponentIface *iface)
9513 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9517 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9521 GtkIconView *icon_view;
9522 GtkIconViewItem *item;
9524 widget = GTK_ACCESSIBLE (selection)->widget;
9528 icon_view = GTK_ICON_VIEW (widget);
9530 item = g_list_nth_data (icon_view->priv->items, i);
9535 gtk_icon_view_select_item (icon_view, item);
9541 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9544 GtkIconView *icon_view;
9546 widget = GTK_ACCESSIBLE (selection)->widget;
9550 icon_view = GTK_ICON_VIEW (widget);
9551 gtk_icon_view_unselect_all (icon_view);
9557 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9562 GtkIconView *icon_view;
9563 GtkIconViewItem *item;
9565 widget = GTK_ACCESSIBLE (selection)->widget;
9569 icon_view = GTK_ICON_VIEW (widget);
9571 l = icon_view->priv->items;
9578 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9589 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9592 GtkIconView *icon_view;
9593 GtkIconViewItem *item;
9597 widget = GTK_ACCESSIBLE (selection)->widget;
9601 icon_view = GTK_ICON_VIEW (widget);
9603 l = icon_view->priv->items;
9619 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9623 GtkIconView *icon_view;
9624 GtkIconViewItem *item;
9626 widget = GTK_ACCESSIBLE (selection)->widget;
9630 icon_view = GTK_ICON_VIEW (widget);
9632 item = g_list_nth_data (icon_view->priv->items, i);
9636 return item->selected;
9640 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9644 GtkIconView *icon_view;
9645 GtkIconViewItem *item;
9649 widget = GTK_ACCESSIBLE (selection)->widget;
9653 icon_view = GTK_ICON_VIEW (widget);
9654 l = icon_view->priv->items;
9663 gtk_icon_view_unselect_item (icon_view, item);
9675 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9678 GtkIconView *icon_view;
9680 widget = GTK_ACCESSIBLE (selection)->widget;
9684 icon_view = GTK_ICON_VIEW (widget);
9685 gtk_icon_view_select_all (icon_view);
9690 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9692 iface->add_selection = gtk_icon_view_accessible_add_selection;
9693 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9694 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9695 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9696 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9697 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9698 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9702 gtk_icon_view_accessible_get_type (void)
9704 static GType type = 0;
9711 (GBaseInitFunc) NULL, /* base init */
9712 (GBaseFinalizeFunc) NULL, /* base finalize */
9713 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9714 (GClassFinalizeFunc) NULL, /* class finalize */
9715 NULL, /* class data */
9716 0, /* instance size */
9717 0, /* nb preallocs */
9718 (GInstanceInitFunc) NULL, /* instance init */
9719 NULL /* value table */
9721 const GInterfaceInfo atk_component_info =
9723 (GInterfaceInitFunc) atk_component_interface_init,
9724 (GInterfaceFinalizeFunc) NULL,
9727 const GInterfaceInfo atk_selection_info =
9729 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9730 (GInterfaceFinalizeFunc) NULL,
9735 * Figure out the size of the class and instance
9736 * we are deriving from
9738 AtkObjectFactory *factory;
9741 GType derived_atk_type;
9743 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9744 factory = atk_registry_get_factory (atk_get_default_registry (),
9746 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9747 g_type_query (derived_atk_type, &query);
9748 tinfo.class_size = query.class_size;
9749 tinfo.instance_size = query.instance_size;
9751 type = g_type_register_static (derived_atk_type,
9752 I_("GtkIconViewAccessible"),
9754 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9755 &atk_component_info);
9756 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9757 &atk_selection_info);
9763 gtk_icon_view_accessible_new (GObject *obj)
9765 AtkObject *accessible;
9767 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9769 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9770 atk_object_initialize (accessible, obj);
9776 gtk_icon_view_accessible_factory_get_accessible_type (void)
9778 return gtk_icon_view_accessible_get_type ();
9782 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9784 return gtk_icon_view_accessible_new (obj);
9788 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9790 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9791 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9795 gtk_icon_view_accessible_factory_get_type (void)
9797 static GType type = 0;
9801 const GTypeInfo tinfo =
9803 sizeof (AtkObjectFactoryClass),
9804 NULL, /* base_init */
9805 NULL, /* base_finalize */
9806 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9807 NULL, /* class_finalize */
9808 NULL, /* class_data */
9809 sizeof (AtkObjectFactory),
9810 0, /* n_preallocs */
9814 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9815 I_("GtkIconViewAccessibleFactory"),
9823 gtk_icon_view_get_accessible (GtkWidget *widget)
9825 static gboolean first_time = TRUE;
9829 AtkObjectFactory *factory;
9830 AtkRegistry *registry;
9832 GType derived_atk_type;
9835 * Figure out whether accessibility is enabled by looking at the
9836 * type of the accessible object which would be created for
9837 * the parent type of GtkIconView.
9839 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9841 registry = atk_get_default_registry ();
9842 factory = atk_registry_get_factory (registry,
9844 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9845 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9846 atk_registry_set_factory_type (registry,
9848 gtk_icon_view_accessible_factory_get_type ());
9851 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9855 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9856 GtkBuilder *builder,
9858 const gchar *tagname,
9859 GMarkupParser *parser,
9862 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9863 tagname, parser, data))
9866 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9867 tagname, parser, data);
9871 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9872 GtkBuilder *builder,
9874 const gchar *tagname,
9877 if (strcmp (tagname, "attributes") == 0)
9878 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9881 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9887 #define __GTK_ICON_VIEW_C__
9888 #include "gtkaliasdef.c"