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"
49 * @short_description: A widget which displays a list of icons in a grid
51 * #GtkIconView provides an alternative view on a list model.
52 * It displays the model as a grid of icons with labels. Like
53 * #GtkTreeView, it allows to select one or multiple items
54 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
55 * In addition to selection with the arrow keys, #GtkIconView supports
56 * rubberband selection, which is controlled by dragging the pointer.
59 #undef DEBUG_ICON_VIEW
61 #define SCROLL_EDGE_SIZE 15
63 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
65 typedef struct _GtkIconViewItem GtkIconViewItem;
66 struct _GtkIconViewItem
74 gint x, y, width, height;
77 * box[i] is the actual area occupied by cell i,
78 * before, after are used to calculate the cell
79 * area relative to the box.
80 * See gtk_icon_view_get_cell_area().
88 guint selected_before_rubberbanding : 1;
92 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
93 struct _GtkIconViewCellInfo
95 GtkCellRenderer *cell;
105 GtkCellLayoutDataFunc func;
107 GDestroyNotify destroy;
110 typedef struct _GtkIconViewChild GtkIconViewChild;
111 struct _GtkIconViewChild
114 GtkIconViewItem *item;
118 struct _GtkIconViewPrivate
122 GtkSelectionMode selection_mode;
124 GdkWindow *bin_window;
132 GtkAdjustment *hadjustment;
133 GtkAdjustment *vadjustment;
135 guint layout_idle_id;
137 gboolean doing_rubberband;
138 gint rubberband_x1, rubberband_y1;
139 gint rubberband_x2, rubberband_y2;
140 GdkDevice *rubberband_device;
142 guint scroll_timeout_id;
143 gint scroll_value_diff;
144 gint event_last_x, event_last_y;
146 GtkIconViewItem *anchor_item;
147 GtkIconViewItem *cursor_item;
148 GtkIconViewItem *edited_item;
149 GtkCellEditable *editable;
151 GtkIconViewItem *last_single_clicked;
158 GtkOrientation orientation;
178 GdkModifierType start_button_mask;
183 GdkDragAction source_actions;
184 GdkDragAction dest_actions;
186 GtkTreeRowReference *dest_item;
187 GtkIconViewDropPosition dest_pos;
190 GtkTreeRowReference *scroll_to_path;
191 gfloat scroll_to_row_align;
192 gfloat scroll_to_col_align;
193 guint scroll_to_use_align : 1;
195 guint source_set : 1;
197 guint reorderable : 1;
198 guint empty_view_drop :1;
200 guint ctrl_pressed : 1;
201 guint shift_pressed : 1;
203 guint draw_focus : 1;
216 ACTIVATE_CURSOR_ITEM,
242 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
243 static void gtk_icon_view_finalize (GObject *object);
244 static void gtk_icon_view_set_property (GObject *object,
248 static void gtk_icon_view_get_property (GObject *object,
253 /* GtkObject vfuncs */
254 static void gtk_icon_view_destroy (GtkObject *object);
256 /* GtkWidget vfuncs */
257 static void gtk_icon_view_realize (GtkWidget *widget);
258 static void gtk_icon_view_unrealize (GtkWidget *widget);
259 static void gtk_icon_view_style_set (GtkWidget *widget,
260 GtkStyle *previous_style);
261 static void gtk_icon_view_state_changed (GtkWidget *widget,
262 GtkStateType previous_state);
263 static void gtk_icon_view_size_request (GtkWidget *widget,
264 GtkRequisition *requisition);
265 static void gtk_icon_view_size_allocate (GtkWidget *widget,
266 GtkAllocation *allocation);
267 static gboolean gtk_icon_view_expose (GtkWidget *widget,
268 GdkEventExpose *expose);
269 static gboolean gtk_icon_view_motion (GtkWidget *widget,
270 GdkEventMotion *event);
271 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
272 GdkEventButton *event);
273 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
274 GdkEventButton *event);
275 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
277 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
279 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
282 /* GtkContainer vfuncs */
283 static void gtk_icon_view_remove (GtkContainer *container,
285 static void gtk_icon_view_forall (GtkContainer *container,
286 gboolean include_internals,
287 GtkCallback callback,
288 gpointer callback_data);
290 /* GtkIconView vfuncs */
291 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
293 GtkAdjustment *vadj);
294 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
295 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
296 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
297 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
298 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
300 /* Internal functions */
301 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
302 GtkIconView *icon_view);
303 static void gtk_icon_view_layout (GtkIconView *icon_view);
304 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
307 GtkIconViewItem *item,
309 GdkDrawable *drawable,
312 gboolean draw_focus);
313 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
316 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
318 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
319 GtkIconViewItem *item);
320 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
321 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
322 GtkIconViewItem *item,
324 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
328 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
329 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
330 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
331 GtkIconViewItem *item,
336 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
337 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
338 GtkIconViewItem *item);
339 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
340 GtkIconViewItem *item,
342 static void gtk_icon_view_update_rubberband (gpointer data);
343 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
344 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
345 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
348 GtkMovementStep step,
350 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
351 GtkMovementStep step,
353 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
355 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
357 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
359 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
361 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
362 GtkIconViewItem *item);
363 static void gtk_icon_view_select_item (GtkIconView *icon_view,
364 GtkIconViewItem *item);
365 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
366 GtkIconViewItem *item);
367 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
368 GtkIconViewItem *anchor,
369 GtkIconViewItem *cursor);
370 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
373 gboolean only_in_cell,
374 GtkIconViewCellInfo **cell_at_pos);
375 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
376 GtkIconViewItem *item,
377 GtkIconViewCellInfo *cell_info,
378 GdkRectangle *cell_area);
379 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
380 GtkIconViewItem *item,
381 GtkIconViewCellInfo *info,
383 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
384 GtkCellRenderer *renderer);
385 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
386 GtkIconViewItem *item);
387 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
388 GtkCellRenderer *renderer,
390 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
391 GtkCellRenderer *renderer,
393 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
394 GtkCellRenderer *renderer,
395 const gchar *attribute,
397 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
398 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
399 GtkCellRenderer *renderer);
400 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
401 GtkCellRenderer *cell,
402 GtkCellLayoutDataFunc func,
404 GDestroyNotify destroy);
405 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
406 GtkCellRenderer *cell,
408 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
410 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
411 GtkIconViewItem *item,
412 GtkIconViewCellInfo *cell_info,
414 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
415 GtkIconViewItem *item);
416 static void gtk_icon_view_put (GtkIconView *icon_view,
418 GtkIconViewItem *item,
420 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
421 GtkIconView *icon_view);
422 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
423 GtkIconViewItem *item,
424 GtkIconViewCellInfo *cell_info,
426 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
427 gboolean cancel_editing);
429 /* Source side drag signals */
430 static void gtk_icon_view_drag_begin (GtkWidget *widget,
431 GdkDragContext *context);
432 static void gtk_icon_view_drag_end (GtkWidget *widget,
433 GdkDragContext *context);
434 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
435 GdkDragContext *context,
436 GtkSelectionData *selection_data,
439 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
440 GdkDragContext *context);
442 /* Target side drag signals */
443 static void gtk_icon_view_drag_leave (GtkWidget *widget,
444 GdkDragContext *context,
446 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
447 GdkDragContext *context,
451 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
452 GdkDragContext *context,
456 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
457 GdkDragContext *context,
460 GtkSelectionData *selection_data,
463 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
464 GdkEventMotion *event);
466 static void remove_scroll_timeout (GtkIconView *icon_view);
468 static void adjust_wrap_width (GtkIconView *icon_view,
469 GtkIconViewItem *item);
472 static GtkBuildableIface *parent_buildable_iface;
473 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
474 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
477 const gchar *tagname,
478 GMarkupParser *parser,
480 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
483 const gchar *tagname,
486 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
488 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
489 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
490 gtk_icon_view_cell_layout_init)
491 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
492 gtk_icon_view_buildable_init))
495 gtk_icon_view_class_init (GtkIconViewClass *klass)
497 GObjectClass *gobject_class;
498 GtkObjectClass *object_class;
499 GtkWidgetClass *widget_class;
500 GtkContainerClass *container_class;
501 GtkBindingSet *binding_set;
503 binding_set = gtk_binding_set_by_class (klass);
505 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
507 gobject_class = (GObjectClass *) klass;
508 object_class = (GtkObjectClass *) klass;
509 widget_class = (GtkWidgetClass *) klass;
510 container_class = (GtkContainerClass *) klass;
512 gobject_class->finalize = gtk_icon_view_finalize;
513 gobject_class->set_property = gtk_icon_view_set_property;
514 gobject_class->get_property = gtk_icon_view_get_property;
516 object_class->destroy = gtk_icon_view_destroy;
518 widget_class->realize = gtk_icon_view_realize;
519 widget_class->unrealize = gtk_icon_view_unrealize;
520 widget_class->style_set = gtk_icon_view_style_set;
521 widget_class->get_accessible = gtk_icon_view_get_accessible;
522 widget_class->size_request = gtk_icon_view_size_request;
523 widget_class->size_allocate = gtk_icon_view_size_allocate;
524 widget_class->expose_event = gtk_icon_view_expose;
525 widget_class->motion_notify_event = gtk_icon_view_motion;
526 widget_class->button_press_event = gtk_icon_view_button_press;
527 widget_class->button_release_event = gtk_icon_view_button_release;
528 widget_class->key_press_event = gtk_icon_view_key_press;
529 widget_class->key_release_event = gtk_icon_view_key_release;
530 widget_class->drag_begin = gtk_icon_view_drag_begin;
531 widget_class->drag_end = gtk_icon_view_drag_end;
532 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
533 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
534 widget_class->drag_leave = gtk_icon_view_drag_leave;
535 widget_class->drag_motion = gtk_icon_view_drag_motion;
536 widget_class->drag_drop = gtk_icon_view_drag_drop;
537 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
538 widget_class->state_changed = gtk_icon_view_state_changed;
540 container_class->remove = gtk_icon_view_remove;
541 container_class->forall = gtk_icon_view_forall;
543 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
544 klass->select_all = gtk_icon_view_real_select_all;
545 klass->unselect_all = gtk_icon_view_real_unselect_all;
546 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
547 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
548 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
549 klass->move_cursor = gtk_icon_view_real_move_cursor;
553 * GtkIconView:selection-mode:
555 * The ::selection-mode property specifies the selection mode of
556 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
557 * is enabled, for the other modes, only keyboard selection is possible.
561 g_object_class_install_property (gobject_class,
563 g_param_spec_enum ("selection-mode",
564 P_("Selection mode"),
565 P_("The selection mode"),
566 GTK_TYPE_SELECTION_MODE,
567 GTK_SELECTION_SINGLE,
568 GTK_PARAM_READWRITE));
571 * GtkIconView:pixbuf-column:
573 * The ::pixbuf-column property contains the number of the model column
574 * containing the pixbufs which are displayed. The pixbuf column must be
575 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
576 * display of pixbufs.
580 g_object_class_install_property (gobject_class,
582 g_param_spec_int ("pixbuf-column",
584 P_("Model column used to retrieve the icon pixbuf from"),
586 GTK_PARAM_READWRITE));
589 * GtkIconView:text-column:
591 * The ::text-column property contains the number of the model column
592 * containing the texts which are displayed. The text column must be
593 * of type #G_TYPE_STRING. If this property and the :markup-column
594 * property are both set to -1, no texts are displayed.
598 g_object_class_install_property (gobject_class,
600 g_param_spec_int ("text-column",
602 P_("Model column used to retrieve the text from"),
604 GTK_PARAM_READWRITE));
608 * GtkIconView:markup-column:
610 * The ::markup-column property contains the number of the model column
611 * containing markup information to be displayed. The markup column must be
612 * of type #G_TYPE_STRING. If this property and the :text-column property
613 * are both set to column numbers, it overrides the text column.
614 * If both are set to -1, no texts are displayed.
618 g_object_class_install_property (gobject_class,
620 g_param_spec_int ("markup-column",
622 P_("Model column used to retrieve the text if using Pango markup"),
624 GTK_PARAM_READWRITE));
626 g_object_class_install_property (gobject_class,
628 g_param_spec_object ("model",
629 P_("Icon View Model"),
630 P_("The model for the icon view"),
632 GTK_PARAM_READWRITE));
635 * GtkIconView:columns:
637 * The columns property contains the number of the columns in which the
638 * items should be displayed. If it is -1, the number of columns will
639 * be chosen automatically to fill the available area.
643 g_object_class_install_property (gobject_class,
645 g_param_spec_int ("columns",
646 P_("Number of columns"),
647 P_("Number of columns to display"),
649 GTK_PARAM_READWRITE));
653 * GtkIconView:item-width:
655 * The item-width property specifies the width to use for each item.
656 * If it is set to -1, the icon view will automatically determine a
657 * suitable item size.
661 g_object_class_install_property (gobject_class,
663 g_param_spec_int ("item-width",
664 P_("Width for each item"),
665 P_("The width used for each item"),
667 GTK_PARAM_READWRITE));
670 * GtkIconView:spacing:
672 * The spacing property specifies the space which is inserted between
673 * the cells (i.e. the icon and the text) of an item.
677 g_object_class_install_property (gobject_class,
679 g_param_spec_int ("spacing",
681 P_("Space which is inserted between cells of an item"),
683 GTK_PARAM_READWRITE));
686 * GtkIconView:row-spacing:
688 * The row-spacing property specifies the space which is inserted between
689 * the rows of the icon view.
693 g_object_class_install_property (gobject_class,
695 g_param_spec_int ("row-spacing",
697 P_("Space which is inserted between grid rows"),
699 GTK_PARAM_READWRITE));
702 * GtkIconView:column-spacing:
704 * The column-spacing property specifies the space which is inserted between
705 * the columns of the icon view.
709 g_object_class_install_property (gobject_class,
711 g_param_spec_int ("column-spacing",
712 P_("Column Spacing"),
713 P_("Space which is inserted between grid columns"),
715 GTK_PARAM_READWRITE));
718 * GtkIconView:margin:
720 * The margin property specifies the space which is inserted
721 * at the edges of the icon view.
725 g_object_class_install_property (gobject_class,
727 g_param_spec_int ("margin",
729 P_("Space which is inserted at the edges of the icon view"),
731 GTK_PARAM_READWRITE));
734 * GtkIconView:orientation:
736 * The orientation property specifies how the cells (i.e. the icon and
737 * the text) of the item are positioned relative to each other.
741 g_object_class_install_property (gobject_class,
743 g_param_spec_enum ("orientation",
745 P_("How the text and icon of each item are positioned relative to each other"),
746 GTK_TYPE_ORIENTATION,
747 GTK_ORIENTATION_VERTICAL,
748 GTK_PARAM_READWRITE));
751 * GtkIconView:reorderable:
753 * The reorderable property specifies if the items can be reordered
758 g_object_class_install_property (gobject_class,
760 g_param_spec_boolean ("reorderable",
762 P_("View is reorderable"),
766 g_object_class_install_property (gobject_class,
768 g_param_spec_int ("tooltip-column",
769 P_("Tooltip Column"),
770 P_("The column in the model containing the tooltip texts for the items"),
774 GTK_PARAM_READWRITE));
777 * GtkIconView:item-padding:
779 * The item-padding property specifies the padding around each
780 * of the icon view's item.
784 g_object_class_install_property (gobject_class,
786 g_param_spec_int ("item-padding",
788 P_("Padding around icon view items"),
790 GTK_PARAM_READWRITE));
794 /* Style properties */
795 gtk_widget_class_install_style_property (widget_class,
796 g_param_spec_boxed ("selection-box-color",
797 P_("Selection Box Color"),
798 P_("Color of the selection box"),
800 GTK_PARAM_READABLE));
802 gtk_widget_class_install_style_property (widget_class,
803 g_param_spec_uchar ("selection-box-alpha",
804 P_("Selection Box Alpha"),
805 P_("Opacity of the selection box"),
808 GTK_PARAM_READABLE));
812 * GtkIconView::set-scroll-adjustments
813 * @horizontal: the horizontal #GtkAdjustment
814 * @vertical: the vertical #GtkAdjustment
816 * Set the scroll adjustments for the icon view. Usually scrolled containers
817 * like #GtkScrolledWindow will emit this signal to connect two instances
818 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
820 widget_class->set_scroll_adjustments_signal =
821 g_signal_new (I_("set-scroll-adjustments"),
822 G_TYPE_FROM_CLASS (gobject_class),
824 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
826 _gtk_marshal_VOID__OBJECT_OBJECT,
828 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
831 * GtkIconView::item-activated:
832 * @iconview: the object on which the signal is emitted
833 * @path: the #GtkTreePath for the activated item
835 * The ::item-activated signal is emitted when the method
836 * gtk_icon_view_item_activated() is called or the user double
837 * clicks an item. It is also emitted when a non-editable item
838 * is selected and one of the keys: Space, Return or Enter is
841 icon_view_signals[ITEM_ACTIVATED] =
842 g_signal_new (I_("item-activated"),
843 G_TYPE_FROM_CLASS (gobject_class),
845 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
847 g_cclosure_marshal_VOID__BOXED,
852 * GtkIconView::selection-changed:
853 * @iconview: the object on which the signal is emitted
855 * The ::selection-changed signal is emitted when the selection
856 * (i.e. the set of selected items) changes.
858 icon_view_signals[SELECTION_CHANGED] =
859 g_signal_new (I_("selection-changed"),
860 G_TYPE_FROM_CLASS (gobject_class),
862 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
864 g_cclosure_marshal_VOID__VOID,
868 * GtkIconView::select-all:
869 * @iconview: the object on which the signal is emitted
871 * A <link linkend="keybinding-signals">keybinding signal</link>
872 * which gets emitted when the user selects all items.
874 * Applications should not connect to it, but may emit it with
875 * g_signal_emit_by_name() if they need to control selection
878 * The default binding for this signal is Ctrl-a.
880 icon_view_signals[SELECT_ALL] =
881 g_signal_new (I_("select-all"),
882 G_TYPE_FROM_CLASS (gobject_class),
883 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
884 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
886 g_cclosure_marshal_VOID__VOID,
890 * GtkIconView::unselect-all:
891 * @iconview: the object on which the signal is emitted
893 * A <link linkend="keybinding-signals">keybinding signal</link>
894 * which gets emitted when the user unselects all items.
896 * Applications should not connect to it, but may emit it with
897 * g_signal_emit_by_name() if they need to control selection
900 * The default binding for this signal is Ctrl-Shift-a.
902 icon_view_signals[UNSELECT_ALL] =
903 g_signal_new (I_("unselect-all"),
904 G_TYPE_FROM_CLASS (gobject_class),
905 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
906 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
908 g_cclosure_marshal_VOID__VOID,
912 * GtkIconView::select-cursor-item:
913 * @iconview: the object on which the signal is emitted
915 * A <link linkend="keybinding-signals">keybinding signal</link>
916 * which gets emitted when the user selects the item that is currently
919 * Applications should not connect to it, but may emit it with
920 * g_signal_emit_by_name() if they need to control selection
923 * There is no default binding for this signal.
925 icon_view_signals[SELECT_CURSOR_ITEM] =
926 g_signal_new (I_("select-cursor-item"),
927 G_TYPE_FROM_CLASS (gobject_class),
928 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
929 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
931 g_cclosure_marshal_VOID__VOID,
935 * GtkIconView::toggle-cursor-item:
936 * @iconview: the object on which the signal is emitted
938 * A <link linkend="keybinding-signals">keybinding signal</link>
939 * which gets emitted when the user toggles whether the currently
940 * focused item is selected or not. The exact effect of this
941 * depend on the selection mode.
943 * Applications should not connect to it, but may emit it with
944 * g_signal_emit_by_name() if they need to control selection
947 * There is no default binding for this signal is Ctrl-Space.
949 icon_view_signals[TOGGLE_CURSOR_ITEM] =
950 g_signal_new (I_("toggle-cursor-item"),
951 G_TYPE_FROM_CLASS (gobject_class),
952 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
953 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
955 g_cclosure_marshal_VOID__VOID,
959 * GtkIconView::activate-cursor-item:
960 * @iconview: the object on which the signal is emitted
962 * A <link linkend="keybinding-signals">keybinding signal</link>
963 * which gets emitted when the user activates the currently
966 * Applications should not connect to it, but may emit it with
967 * g_signal_emit_by_name() if they need to control activation
970 * The default bindings for this signal are Space, Return and Enter.
972 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
973 g_signal_new (I_("activate-cursor-item"),
974 G_TYPE_FROM_CLASS (gobject_class),
975 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
976 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
978 _gtk_marshal_BOOLEAN__VOID,
982 * GtkIconView::move-cursor:
983 * @iconview: the object which received the signal
984 * @step: the granularity of the move, as a #GtkMovementStep
985 * @count: the number of @step units to move
987 * The ::move-cursor signal is a
988 * <link linkend="keybinding-signals">keybinding signal</link>
989 * which gets emitted when the user initiates a cursor movement.
991 * Applications should not connect to it, but may emit it with
992 * g_signal_emit_by_name() if they need to control the cursor
995 * The default bindings for this signal include
997 * <listitem>Arrow keys which move by individual steps</listitem>
998 * <listitem>Home/End keys which move to the first/last item</listitem>
999 * <listitem>PageUp/PageDown which move by "pages"</listitem>
1002 * All of these will extend the selection when combined with
1003 * the Shift modifier.
1005 icon_view_signals[MOVE_CURSOR] =
1006 g_signal_new (I_("move-cursor"),
1007 G_TYPE_FROM_CLASS (gobject_class),
1008 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1009 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1011 _gtk_marshal_BOOLEAN__ENUM_INT,
1013 GTK_TYPE_MOVEMENT_STEP,
1017 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
1019 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1021 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
1022 "toggle-cursor-item", 0);
1023 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
1024 "toggle-cursor-item", 0);
1026 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
1027 "activate-cursor-item", 0);
1028 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
1029 "activate-cursor-item", 0);
1030 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
1031 "activate-cursor-item", 0);
1032 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
1033 "activate-cursor-item", 0);
1034 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
1035 "activate-cursor-item", 0);
1037 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
1038 GTK_MOVEMENT_DISPLAY_LINES, -1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
1040 GTK_MOVEMENT_DISPLAY_LINES, -1);
1042 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
1043 GTK_MOVEMENT_DISPLAY_LINES, 1);
1044 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
1045 GTK_MOVEMENT_DISPLAY_LINES, 1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
1048 GTK_MOVEMENT_DISPLAY_LINES, -1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
1051 GTK_MOVEMENT_DISPLAY_LINES, 1);
1053 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
1054 GTK_MOVEMENT_BUFFER_ENDS, -1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
1056 GTK_MOVEMENT_BUFFER_ENDS, -1);
1058 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
1059 GTK_MOVEMENT_BUFFER_ENDS, 1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
1061 GTK_MOVEMENT_BUFFER_ENDS, 1);
1063 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
1064 GTK_MOVEMENT_PAGES, -1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
1066 GTK_MOVEMENT_PAGES, -1);
1068 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
1069 GTK_MOVEMENT_PAGES, 1);
1070 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
1071 GTK_MOVEMENT_PAGES, 1);
1073 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
1074 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1075 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
1076 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1078 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
1079 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1080 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
1081 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1085 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1087 parent_buildable_iface = g_type_interface_peek_parent (iface);
1088 iface->add_child = _gtk_cell_layout_buildable_add_child;
1089 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1090 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1094 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1096 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1097 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1098 iface->clear = gtk_icon_view_cell_layout_clear;
1099 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1100 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1101 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1102 iface->reorder = gtk_icon_view_cell_layout_reorder;
1103 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1107 gtk_icon_view_init (GtkIconView *icon_view)
1109 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
1111 icon_view->priv->width = 0;
1112 icon_view->priv->height = 0;
1113 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1114 icon_view->priv->pressed_button = -1;
1115 icon_view->priv->press_start_x = -1;
1116 icon_view->priv->press_start_y = -1;
1117 icon_view->priv->text_column = -1;
1118 icon_view->priv->markup_column = -1;
1119 icon_view->priv->pixbuf_column = -1;
1120 icon_view->priv->text_cell = -1;
1121 icon_view->priv->pixbuf_cell = -1;
1122 icon_view->priv->tooltip_column = -1;
1124 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1126 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1128 icon_view->priv->cell_list = NULL;
1129 icon_view->priv->n_cells = 0;
1130 icon_view->priv->cursor_cell = -1;
1132 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
1134 icon_view->priv->columns = -1;
1135 icon_view->priv->item_width = -1;
1136 icon_view->priv->spacing = 0;
1137 icon_view->priv->row_spacing = 6;
1138 icon_view->priv->column_spacing = 6;
1139 icon_view->priv->margin = 6;
1140 icon_view->priv->item_padding = 6;
1142 icon_view->priv->draw_focus = TRUE;
1146 gtk_icon_view_destroy (GtkObject *object)
1148 GtkIconView *icon_view;
1150 icon_view = GTK_ICON_VIEW (object);
1152 gtk_icon_view_stop_editing (icon_view, TRUE);
1154 gtk_icon_view_set_model (icon_view, NULL);
1156 if (icon_view->priv->layout_idle_id != 0)
1158 g_source_remove (icon_view->priv->layout_idle_id);
1159 icon_view->priv->layout_idle_id = 0;
1162 if (icon_view->priv->scroll_to_path != NULL)
1164 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1165 icon_view->priv->scroll_to_path = NULL;
1168 remove_scroll_timeout (icon_view);
1170 if (icon_view->priv->hadjustment != NULL)
1172 g_object_unref (icon_view->priv->hadjustment);
1173 icon_view->priv->hadjustment = NULL;
1176 if (icon_view->priv->vadjustment != NULL)
1178 g_object_unref (icon_view->priv->vadjustment);
1179 icon_view->priv->vadjustment = NULL;
1182 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1185 /* GObject methods */
1187 gtk_icon_view_finalize (GObject *object)
1189 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1191 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1196 gtk_icon_view_set_property (GObject *object,
1198 const GValue *value,
1201 GtkIconView *icon_view;
1203 icon_view = GTK_ICON_VIEW (object);
1207 case PROP_SELECTION_MODE:
1208 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1210 case PROP_PIXBUF_COLUMN:
1211 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1213 case PROP_TEXT_COLUMN:
1214 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1216 case PROP_MARKUP_COLUMN:
1217 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1220 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1222 case PROP_ORIENTATION:
1223 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1226 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1228 case PROP_ITEM_WIDTH:
1229 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1232 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1234 case PROP_ROW_SPACING:
1235 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1237 case PROP_COLUMN_SPACING:
1238 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1241 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1243 case PROP_REORDERABLE:
1244 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1247 case PROP_TOOLTIP_COLUMN:
1248 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1251 case PROP_ITEM_PADDING:
1252 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1256 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1262 gtk_icon_view_get_property (GObject *object,
1267 GtkIconView *icon_view;
1269 icon_view = GTK_ICON_VIEW (object);
1273 case PROP_SELECTION_MODE:
1274 g_value_set_enum (value, icon_view->priv->selection_mode);
1276 case PROP_PIXBUF_COLUMN:
1277 g_value_set_int (value, icon_view->priv->pixbuf_column);
1279 case PROP_TEXT_COLUMN:
1280 g_value_set_int (value, icon_view->priv->text_column);
1282 case PROP_MARKUP_COLUMN:
1283 g_value_set_int (value, icon_view->priv->markup_column);
1286 g_value_set_object (value, icon_view->priv->model);
1288 case PROP_ORIENTATION:
1289 g_value_set_enum (value, icon_view->priv->orientation);
1292 g_value_set_int (value, icon_view->priv->columns);
1294 case PROP_ITEM_WIDTH:
1295 g_value_set_int (value, icon_view->priv->item_width);
1298 g_value_set_int (value, icon_view->priv->spacing);
1300 case PROP_ROW_SPACING:
1301 g_value_set_int (value, icon_view->priv->row_spacing);
1303 case PROP_COLUMN_SPACING:
1304 g_value_set_int (value, icon_view->priv->column_spacing);
1307 g_value_set_int (value, icon_view->priv->margin);
1309 case PROP_REORDERABLE:
1310 g_value_set_boolean (value, icon_view->priv->reorderable);
1312 case PROP_TOOLTIP_COLUMN:
1313 g_value_set_int (value, icon_view->priv->tooltip_column);
1316 case PROP_ITEM_PADDING:
1317 g_value_set_int (value, icon_view->priv->item_padding);
1321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1326 /* GtkWidget signals */
1328 gtk_icon_view_realize (GtkWidget *widget)
1330 GtkIconView *icon_view;
1331 GdkWindowAttr attributes;
1332 gint attributes_mask;
1334 icon_view = GTK_ICON_VIEW (widget);
1336 gtk_widget_set_realized (widget, TRUE);
1338 /* Make the main, clipping window */
1339 attributes.window_type = GDK_WINDOW_CHILD;
1340 attributes.x = widget->allocation.x;
1341 attributes.y = widget->allocation.y;
1342 attributes.width = widget->allocation.width;
1343 attributes.height = widget->allocation.height;
1344 attributes.wclass = GDK_INPUT_OUTPUT;
1345 attributes.visual = gtk_widget_get_visual (widget);
1346 attributes.colormap = gtk_widget_get_colormap (widget);
1347 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1349 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1351 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1352 &attributes, attributes_mask);
1353 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1354 gdk_window_set_user_data (widget->window, widget);
1356 /* Make the window for the icon view */
1359 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1360 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1361 attributes.event_mask = (GDK_EXPOSURE_MASK |
1363 GDK_POINTER_MOTION_MASK |
1364 GDK_BUTTON_PRESS_MASK |
1365 GDK_BUTTON_RELEASE_MASK |
1366 GDK_KEY_PRESS_MASK |
1367 GDK_KEY_RELEASE_MASK) |
1368 gtk_widget_get_events (widget);
1370 icon_view->priv->bin_window = gdk_window_new (widget->window,
1371 &attributes, attributes_mask);
1372 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1374 widget->style = gtk_style_attach (widget->style, widget->window);
1375 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1377 gdk_window_show (icon_view->priv->bin_window);
1381 gtk_icon_view_unrealize (GtkWidget *widget)
1383 GtkIconView *icon_view;
1385 icon_view = GTK_ICON_VIEW (widget);
1387 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1388 gdk_window_destroy (icon_view->priv->bin_window);
1389 icon_view->priv->bin_window = NULL;
1391 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1395 gtk_icon_view_state_changed (GtkWidget *widget,
1396 GtkStateType previous_state)
1398 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1400 if (gtk_widget_get_realized (widget))
1402 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1403 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1406 gtk_widget_queue_draw (widget);
1410 gtk_icon_view_style_set (GtkWidget *widget,
1411 GtkStyle *previous_style)
1413 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1415 if (gtk_widget_get_realized (widget))
1417 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1418 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1421 gtk_widget_queue_resize (widget);
1425 gtk_icon_view_size_request (GtkWidget *widget,
1426 GtkRequisition *requisition)
1428 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1431 requisition->width = icon_view->priv->width;
1432 requisition->height = icon_view->priv->height;
1434 tmp_list = icon_view->priv->children;
1438 GtkIconViewChild *child = tmp_list->data;
1439 GtkRequisition child_requisition;
1441 tmp_list = tmp_list->next;
1443 if (gtk_widget_get_visible (child->widget))
1444 gtk_widget_size_request (child->widget, &child_requisition);
1449 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1453 for (list = icon_view->priv->children; list; list = list->next)
1455 GtkIconViewChild *child = list->data;
1456 GtkAllocation allocation;
1458 /* totally ignore our child's requisition */
1459 if (child->cell < 0)
1461 allocation.x = child->item->x + icon_view->priv->item_padding;
1462 allocation.y = child->item->y + icon_view->priv->item_padding;
1463 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1464 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1468 GdkRectangle *box = &child->item->box[child->cell];
1470 allocation.x = box->x;
1471 allocation.y = box->y;
1472 allocation.width = box->width;
1473 allocation.height = box->height;
1476 gtk_widget_size_allocate (child->widget, &allocation);
1481 gtk_icon_view_size_allocate (GtkWidget *widget,
1482 GtkAllocation *allocation)
1484 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1486 GtkAdjustment *hadjustment, *vadjustment;
1488 widget->allocation = *allocation;
1490 if (gtk_widget_get_realized (widget))
1492 gdk_window_move_resize (widget->window,
1493 allocation->x, allocation->y,
1494 allocation->width, allocation->height);
1495 gdk_window_resize (icon_view->priv->bin_window,
1496 MAX (icon_view->priv->width, allocation->width),
1497 MAX (icon_view->priv->height, allocation->height));
1500 gtk_icon_view_layout (icon_view);
1502 gtk_icon_view_allocate_children (icon_view);
1504 hadjustment = icon_view->priv->hadjustment;
1505 vadjustment = icon_view->priv->vadjustment;
1507 hadjustment->page_size = allocation->width;
1508 hadjustment->page_increment = allocation->width * 0.9;
1509 hadjustment->step_increment = allocation->width * 0.1;
1510 hadjustment->lower = 0;
1511 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1513 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1514 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1516 vadjustment->page_size = allocation->height;
1517 vadjustment->page_increment = allocation->height * 0.9;
1518 vadjustment->step_increment = allocation->height * 0.1;
1519 vadjustment->lower = 0;
1520 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1522 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1523 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1525 if (gtk_widget_get_realized (widget) &&
1526 icon_view->priv->scroll_to_path)
1529 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1530 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1531 icon_view->priv->scroll_to_path = NULL;
1533 gtk_icon_view_scroll_to_path (icon_view, path,
1534 icon_view->priv->scroll_to_use_align,
1535 icon_view->priv->scroll_to_row_align,
1536 icon_view->priv->scroll_to_col_align);
1537 gtk_tree_path_free (path);
1541 gtk_adjustment_changed (hadjustment);
1542 gtk_adjustment_changed (vadjustment);
1547 gtk_icon_view_expose (GtkWidget *widget,
1548 GdkEventExpose *expose)
1550 GtkIconView *icon_view;
1555 GtkIconViewDropPosition dest_pos;
1556 GtkIconViewItem *dest_item = NULL;
1558 icon_view = GTK_ICON_VIEW (widget);
1560 if (expose->window != icon_view->priv->bin_window)
1563 /* If a layout has been scheduled, do it now so that all
1564 * cell view items have valid sizes before we proceed. */
1565 if (icon_view->priv->layout_idle_id != 0)
1566 gtk_icon_view_layout (icon_view);
1568 cr = gdk_cairo_create (icon_view->priv->bin_window);
1569 cairo_set_line_width (cr, 1.);
1571 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1575 dest_index = gtk_tree_path_get_indices (path)[0];
1576 gtk_tree_path_free (path);
1581 for (icons = icon_view->priv->items; icons; icons = icons->next)
1583 GtkIconViewItem *item = icons->data;
1588 area.width = item->width;
1589 area.height = item->height;
1591 if (cairo_region_contains_rectangle (expose->region, &area) == CAIRO_REGION_OVERLAP_OUT)
1594 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1595 icon_view->priv->bin_window,
1597 icon_view->priv->draw_focus);
1599 if (dest_index == item->index)
1607 case GTK_ICON_VIEW_DROP_INTO:
1608 gtk_paint_focus (widget->style,
1609 icon_view->priv->bin_window,
1610 gtk_widget_get_state (widget),
1613 "iconview-drop-indicator",
1614 dest_item->x, dest_item->y,
1615 dest_item->width, dest_item->height);
1617 case GTK_ICON_VIEW_DROP_ABOVE:
1618 gtk_paint_focus (widget->style,
1619 icon_view->priv->bin_window,
1620 gtk_widget_get_state (widget),
1623 "iconview-drop-indicator",
1624 dest_item->x, dest_item->y - 1,
1625 dest_item->width, 2);
1627 case GTK_ICON_VIEW_DROP_LEFT:
1628 gtk_paint_focus (widget->style,
1629 icon_view->priv->bin_window,
1630 gtk_widget_get_state (widget),
1633 "iconview-drop-indicator",
1634 dest_item->x - 1, dest_item->y,
1635 2, dest_item->height);
1637 case GTK_ICON_VIEW_DROP_BELOW:
1638 gtk_paint_focus (widget->style,
1639 icon_view->priv->bin_window,
1640 gtk_widget_get_state (widget),
1643 "iconview-drop-indicator",
1644 dest_item->x, dest_item->y + dest_item->height - 1,
1645 dest_item->width, 2);
1647 case GTK_ICON_VIEW_DROP_RIGHT:
1648 gtk_paint_focus (widget->style,
1649 icon_view->priv->bin_window,
1650 gtk_widget_get_state (widget),
1653 "iconview-drop-indicator",
1654 dest_item->x + dest_item->width - 1, dest_item->y,
1655 2, dest_item->height);
1656 case GTK_ICON_VIEW_NO_DROP: ;
1661 if (icon_view->priv->doing_rubberband)
1663 cairo_rectangle_int_t rectangle;
1666 n_rectangles = cairo_region_num_rectangles (expose->region);
1668 while (n_rectangles--)
1670 cairo_region_get_rectangle (expose->region, n_rectangles--, &rectangle);
1671 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangle);
1677 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1683 rubberband_scroll_timeout (gpointer data)
1685 GtkIconView *icon_view = data;
1687 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1688 icon_view->priv->vadjustment->value +
1689 icon_view->priv->scroll_value_diff);
1691 gtk_icon_view_update_rubberband (icon_view);
1697 gtk_icon_view_motion (GtkWidget *widget,
1698 GdkEventMotion *event)
1700 GtkIconView *icon_view;
1703 icon_view = GTK_ICON_VIEW (widget);
1705 gtk_icon_view_maybe_begin_drag (icon_view, event);
1707 if (icon_view->priv->doing_rubberband)
1709 gtk_icon_view_update_rubberband (widget);
1711 abs_y = event->y - icon_view->priv->height *
1712 (icon_view->priv->vadjustment->value /
1713 (icon_view->priv->vadjustment->upper -
1714 icon_view->priv->vadjustment->lower));
1716 if (abs_y < 0 || abs_y > widget->allocation.height)
1719 icon_view->priv->scroll_value_diff = abs_y;
1721 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1723 icon_view->priv->event_last_x = event->x;
1724 icon_view->priv->event_last_y = event->y;
1726 if (icon_view->priv->scroll_timeout_id == 0)
1727 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1731 remove_scroll_timeout (icon_view);
1738 gtk_icon_view_remove (GtkContainer *container,
1741 GtkIconView *icon_view;
1742 GtkIconViewChild *child = NULL;
1745 icon_view = GTK_ICON_VIEW (container);
1747 tmp_list = icon_view->priv->children;
1750 child = tmp_list->data;
1751 if (child->widget == widget)
1753 gtk_widget_unparent (widget);
1755 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1756 g_list_free_1 (tmp_list);
1761 tmp_list = tmp_list->next;
1766 gtk_icon_view_forall (GtkContainer *container,
1767 gboolean include_internals,
1768 GtkCallback callback,
1769 gpointer callback_data)
1771 GtkIconView *icon_view;
1772 GtkIconViewChild *child = NULL;
1775 icon_view = GTK_ICON_VIEW (container);
1777 tmp_list = icon_view->priv->children;
1780 child = tmp_list->data;
1781 tmp_list = tmp_list->next;
1783 (* callback) (child->widget, callback_data);
1788 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1789 GtkIconViewItem *item,
1790 GtkIconViewCellInfo *info,
1795 GdkRectangle cell_area;
1796 gboolean visible, mode;
1798 gtk_icon_view_set_cell_data (icon_view, item);
1800 g_object_get (info->cell,
1801 "visible", &visible,
1805 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1807 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1809 path = gtk_tree_path_new_from_indices (item->index, -1);
1810 path_string = gtk_tree_path_to_string (path);
1811 gtk_tree_path_free (path);
1813 gtk_cell_renderer_activate (info->cell,
1815 GTK_WIDGET (icon_view),
1821 g_free (path_string);
1826 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1827 GtkIconViewItem *item)
1830 AtkObject *item_obj;
1832 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1835 item_obj = atk_object_ref_accessible_child (obj, item->index);
1836 if (item_obj != NULL)
1838 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1839 g_object_unref (item_obj);
1845 gtk_icon_view_put (GtkIconView *icon_view,
1847 GtkIconViewItem *item,
1850 GtkIconViewChild *child;
1852 child = g_new (GtkIconViewChild, 1);
1854 child->widget = widget;
1858 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1860 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1861 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1863 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1867 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1868 GtkIconView *icon_view)
1871 GtkIconViewItem *item;
1873 if (icon_view->priv->edited_item == NULL)
1876 item = icon_view->priv->edited_item;
1877 icon_view->priv->edited_item = NULL;
1878 icon_view->priv->editable = NULL;
1879 for (l = icon_view->priv->cell_list; l; l = l->next)
1881 GtkIconViewCellInfo *info = l->data;
1883 info->editing = FALSE;
1886 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1887 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1889 g_signal_handlers_disconnect_by_func (editable,
1890 gtk_icon_view_remove_widget,
1893 gtk_container_remove (GTK_CONTAINER (icon_view),
1894 GTK_WIDGET (editable));
1896 gtk_icon_view_queue_draw_item (icon_view, item);
1901 gtk_icon_view_start_editing (GtkIconView *icon_view,
1902 GtkIconViewItem *item,
1903 GtkIconViewCellInfo *info,
1908 GdkRectangle cell_area;
1909 gboolean visible, mode;
1910 GtkCellEditable *editable;
1912 gtk_icon_view_set_cell_data (icon_view, item);
1914 g_object_get (info->cell,
1915 "visible", &visible,
1918 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1920 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1922 path = gtk_tree_path_new_from_indices (item->index, -1);
1923 path_string = gtk_tree_path_to_string (path);
1924 gtk_tree_path_free (path);
1926 editable = gtk_cell_renderer_start_editing (info->cell,
1928 GTK_WIDGET (icon_view),
1933 g_free (path_string);
1935 /* the rest corresponds to tree_view_real_start_editing... */
1936 icon_view->priv->edited_item = item;
1937 icon_view->priv->editable = editable;
1938 info->editing = TRUE;
1940 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1942 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1944 gtk_widget_grab_focus (GTK_WIDGET (editable));
1945 g_signal_connect (editable, "remove-widget",
1946 G_CALLBACK (gtk_icon_view_remove_widget),
1953 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1954 gboolean cancel_editing)
1956 GtkCellRenderer *cell = NULL;
1957 GtkIconViewItem *item;
1960 if (icon_view->priv->edited_item == NULL)
1964 * This is very evil. We need to do this, because
1965 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1966 * later on. If gtk_icon_view_row_changed notices
1967 * icon_view->priv->edited_item != NULL, it'll call
1968 * gtk_icon_view_stop_editing again. Bad things will happen then.
1970 * Please read that again if you intend to modify anything here.
1973 item = icon_view->priv->edited_item;
1974 icon_view->priv->edited_item = NULL;
1976 for (l = icon_view->priv->cell_list; l; l = l->next)
1978 GtkIconViewCellInfo *info = l->data;
1990 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1991 if (!cancel_editing)
1992 gtk_cell_editable_editing_done (icon_view->priv->editable);
1994 icon_view->priv->edited_item = item;
1996 gtk_cell_editable_remove_widget (icon_view->priv->editable);
2000 * gtk_icon_view_set_cursor:
2001 * @icon_view: A #GtkIconView
2002 * @path: A #GtkTreePath
2003 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2004 * @start_editing: %TRUE if the specified cell should start being edited.
2006 * Sets the current keyboard focus to be at @path, and selects it. This is
2007 * useful when you want to focus the user's attention on a particular item.
2008 * If @cell is not %NULL, then focus is given to the cell specified by
2009 * it. Additionally, if @start_editing is %TRUE, then editing should be
2010 * started in the specified cell.
2012 * This function is often followed by <literal>gtk_widget_grab_focus
2013 * (icon_view)</literal> in order to give keyboard focus to the widget.
2014 * Please note that editing can only happen when the widget is realized.
2019 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2021 GtkCellRenderer *cell,
2022 gboolean start_editing)
2024 GtkIconViewItem *item = NULL;
2025 GtkIconViewCellInfo *info = NULL;
2029 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2030 g_return_if_fail (path != NULL);
2031 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2033 gtk_icon_view_stop_editing (icon_view, TRUE);
2035 if (gtk_tree_path_get_depth (path) == 1)
2036 item = g_list_nth_data (icon_view->priv->items,
2037 gtk_tree_path_get_indices(path)[0]);
2043 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2047 if (info->cell == cell)
2056 g_return_if_fail (cell == NULL || info != NULL);
2058 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2059 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2061 if (info && start_editing)
2062 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2066 * gtk_icon_view_get_cursor:
2067 * @icon_view: A #GtkIconView
2068 * @path: (allow-none): Return location for the current cursor path, or %NULL
2069 * @cell: (allow-none): Return location the current focus cell, or %NULL
2071 * Fills in @path and @cell with the current cursor path and cell.
2072 * If the cursor isn't currently set, then *@path will be %NULL.
2073 * If no cell currently has focus, then *@cell will be %NULL.
2075 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2077 * Return value: %TRUE if the cursor is set.
2082 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2084 GtkCellRenderer **cell)
2086 GtkIconViewItem *item;
2087 GtkIconViewCellInfo *info;
2089 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2091 item = icon_view->priv->cursor_item;
2092 if (icon_view->priv->cursor_cell < 0)
2095 info = g_list_nth_data (icon_view->priv->cell_list,
2096 icon_view->priv->cursor_cell);
2101 *path = gtk_tree_path_new_from_indices (item->index, -1);
2114 return (item != NULL);
2118 gtk_icon_view_button_press (GtkWidget *widget,
2119 GdkEventButton *event)
2121 GtkIconView *icon_view;
2122 GtkIconViewItem *item;
2123 GtkIconViewCellInfo *info = NULL;
2124 gboolean dirty = FALSE;
2125 GtkCellRendererMode mode;
2126 gint cursor_cell = -1;
2128 icon_view = GTK_ICON_VIEW (widget);
2130 if (event->window != icon_view->priv->bin_window)
2133 if (!gtk_widget_has_focus (widget))
2134 gtk_widget_grab_focus (widget);
2136 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2138 item = gtk_icon_view_get_item_at_coords (icon_view,
2144 * We consider only the the cells' area as the item area if the
2145 * item is not selected, but if it *is* selected, the complete
2146 * selection rectangle is considered to be part of the item.
2148 if (item != NULL && (info != NULL || item->selected))
2152 g_object_get (info->cell, "mode", &mode, NULL);
2154 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2155 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2156 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2159 gtk_icon_view_scroll_to_item (icon_view, item);
2161 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2163 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2165 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2166 (event->state & GDK_SHIFT_MASK))
2168 gtk_icon_view_unselect_all_internal (icon_view);
2170 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2171 if (!icon_view->priv->anchor_item)
2172 icon_view->priv->anchor_item = item;
2174 gtk_icon_view_select_all_between (icon_view,
2175 icon_view->priv->anchor_item,
2181 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2182 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2183 (event->state & GDK_CONTROL_MASK))
2185 item->selected = !item->selected;
2186 gtk_icon_view_queue_draw_item (icon_view, item);
2191 gtk_icon_view_unselect_all_internal (icon_view);
2193 item->selected = TRUE;
2194 gtk_icon_view_queue_draw_item (icon_view, item);
2197 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2198 icon_view->priv->anchor_item = item;
2201 /* Save press to possibly begin a drag */
2202 if (icon_view->priv->pressed_button < 0)
2204 icon_view->priv->pressed_button = event->button;
2205 icon_view->priv->press_start_x = event->x;
2206 icon_view->priv->press_start_y = event->y;
2209 if (!icon_view->priv->last_single_clicked)
2210 icon_view->priv->last_single_clicked = item;
2212 /* cancel the current editing, if it exists */
2213 gtk_icon_view_stop_editing (icon_view, TRUE);
2217 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2218 gtk_icon_view_item_activate_cell (icon_view, item, info,
2220 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2221 gtk_icon_view_start_editing (icon_view, item, info,
2227 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2228 !(event->state & GDK_CONTROL_MASK))
2230 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2233 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2234 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2237 /* don't draw keyboard focus around an clicked-on item */
2238 icon_view->priv->draw_focus = FALSE;
2241 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2243 item = gtk_icon_view_get_item_at_coords (icon_view,
2248 if (item && item == icon_view->priv->last_single_clicked)
2252 path = gtk_tree_path_new_from_indices (item->index, -1);
2253 gtk_icon_view_item_activated (icon_view, path);
2254 gtk_tree_path_free (path);
2257 icon_view->priv->last_single_clicked = NULL;
2258 icon_view->priv->pressed_button = -1;
2262 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2264 return event->button == 1;
2268 gtk_icon_view_button_release (GtkWidget *widget,
2269 GdkEventButton *event)
2271 GtkIconView *icon_view;
2273 icon_view = GTK_ICON_VIEW (widget);
2275 if (icon_view->priv->pressed_button == event->button)
2276 icon_view->priv->pressed_button = -1;
2278 gtk_icon_view_stop_rubberbanding (icon_view);
2280 remove_scroll_timeout (icon_view);
2286 gtk_icon_view_key_press (GtkWidget *widget,
2289 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2291 if (icon_view->priv->doing_rubberband)
2293 if (event->keyval == GDK_Escape)
2294 gtk_icon_view_stop_rubberbanding (icon_view);
2299 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2303 gtk_icon_view_key_release (GtkWidget *widget,
2306 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2308 if (icon_view->priv->doing_rubberband)
2311 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2315 gtk_icon_view_update_rubberband (gpointer data)
2317 GtkIconView *icon_view;
2319 GdkRectangle old_area;
2320 GdkRectangle new_area;
2321 GdkRectangle common;
2322 cairo_region_t *invalid_region;
2324 icon_view = GTK_ICON_VIEW (data);
2326 gdk_window_get_device_position (icon_view->priv->bin_window,
2327 icon_view->priv->rubberband_device,
2333 old_area.x = MIN (icon_view->priv->rubberband_x1,
2334 icon_view->priv->rubberband_x2);
2335 old_area.y = MIN (icon_view->priv->rubberband_y1,
2336 icon_view->priv->rubberband_y2);
2337 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2338 icon_view->priv->rubberband_x1) + 1;
2339 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2340 icon_view->priv->rubberband_y1) + 1;
2342 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2343 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2344 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2345 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2347 invalid_region = cairo_region_create_rectangle (&old_area);
2348 cairo_region_union_rectangle (invalid_region, &new_area);
2350 gdk_rectangle_intersect (&old_area, &new_area, &common);
2351 if (common.width > 2 && common.height > 2)
2353 cairo_region_t *common_region;
2355 /* make sure the border is invalidated */
2361 common_region = cairo_region_create_rectangle (&common);
2363 cairo_region_subtract (invalid_region, common_region);
2364 cairo_region_destroy (common_region);
2367 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2369 cairo_region_destroy (invalid_region);
2371 icon_view->priv->rubberband_x2 = x;
2372 icon_view->priv->rubberband_y2 = y;
2374 gtk_icon_view_update_rubberband_selection (icon_view);
2378 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2385 if (icon_view->priv->rubberband_device)
2388 for (items = icon_view->priv->items; items; items = items->next)
2390 GtkIconViewItem *item = items->data;
2392 item->selected_before_rubberbanding = item->selected;
2395 icon_view->priv->rubberband_x1 = x;
2396 icon_view->priv->rubberband_y1 = y;
2397 icon_view->priv->rubberband_x2 = x;
2398 icon_view->priv->rubberband_y2 = y;
2400 icon_view->priv->doing_rubberband = TRUE;
2401 icon_view->priv->rubberband_device = device;
2403 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2407 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2409 if (!icon_view->priv->doing_rubberband)
2412 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2413 icon_view->priv->rubberband_device);
2415 icon_view->priv->doing_rubberband = FALSE;
2416 icon_view->priv->rubberband_device = NULL;
2418 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2422 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2425 gint x, y, width, height;
2426 gboolean dirty = FALSE;
2428 x = MIN (icon_view->priv->rubberband_x1,
2429 icon_view->priv->rubberband_x2);
2430 y = MIN (icon_view->priv->rubberband_y1,
2431 icon_view->priv->rubberband_y2);
2432 width = ABS (icon_view->priv->rubberband_x1 -
2433 icon_view->priv->rubberband_x2);
2434 height = ABS (icon_view->priv->rubberband_y1 -
2435 icon_view->priv->rubberband_y2);
2437 for (items = icon_view->priv->items; items; items = items->next)
2439 GtkIconViewItem *item = items->data;
2443 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2444 x, y, width, height);
2446 selected = is_in ^ item->selected_before_rubberbanding;
2448 if (item->selected != selected)
2450 item->selected = selected;
2452 gtk_icon_view_queue_draw_item (icon_view, item);
2457 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2461 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2462 GtkIconViewItem *item,
2471 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2472 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2475 for (l = icon_view->priv->cell_list; l; l = l->next)
2477 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2479 if (!info->cell->visible)
2482 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2484 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2485 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2493 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2495 gboolean dirty = FALSE;
2498 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2501 for (items = icon_view->priv->items; items; items = items->next)
2503 GtkIconViewItem *item = items->data;
2507 item->selected = FALSE;
2509 gtk_icon_view_queue_draw_item (icon_view, item);
2510 gtk_icon_view_item_selected_changed (icon_view, item);
2518 /* GtkIconView signals */
2520 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2521 GtkAdjustment *hadj,
2522 GtkAdjustment *vadj)
2524 gboolean need_adjust = FALSE;
2527 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2529 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2531 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2533 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2535 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2537 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2538 0, 0, NULL, NULL, icon_view);
2539 g_object_unref (icon_view->priv->hadjustment);
2542 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2544 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2545 0, 0, NULL, NULL, icon_view);
2546 g_object_unref (icon_view->priv->vadjustment);
2549 if (icon_view->priv->hadjustment != hadj)
2551 icon_view->priv->hadjustment = hadj;
2552 g_object_ref_sink (icon_view->priv->hadjustment);
2554 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2555 G_CALLBACK (gtk_icon_view_adjustment_changed),
2560 if (icon_view->priv->vadjustment != vadj)
2562 icon_view->priv->vadjustment = vadj;
2563 g_object_ref_sink (icon_view->priv->vadjustment);
2565 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2566 G_CALLBACK (gtk_icon_view_adjustment_changed),
2572 gtk_icon_view_adjustment_changed (NULL, icon_view);
2576 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2578 gtk_icon_view_select_all (icon_view);
2582 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2584 gtk_icon_view_unselect_all (icon_view);
2588 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2590 gtk_icon_view_unselect_all (icon_view);
2592 if (icon_view->priv->cursor_item != NULL)
2593 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2597 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2600 GtkCellRendererMode mode;
2601 GtkIconViewCellInfo *info = NULL;
2603 if (!icon_view->priv->cursor_item)
2606 info = g_list_nth_data (icon_view->priv->cell_list,
2607 icon_view->priv->cursor_cell);
2611 g_object_get (info->cell, "mode", &mode, NULL);
2613 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2615 gtk_icon_view_item_activate_cell (icon_view,
2616 icon_view->priv->cursor_item,
2620 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2622 gtk_icon_view_start_editing (icon_view,
2623 icon_view->priv->cursor_item,
2629 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2630 gtk_icon_view_item_activated (icon_view, path);
2631 gtk_tree_path_free (path);
2637 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2639 if (!icon_view->priv->cursor_item)
2642 switch (icon_view->priv->selection_mode)
2644 case GTK_SELECTION_NONE:
2646 case GTK_SELECTION_BROWSE:
2647 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2649 case GTK_SELECTION_SINGLE:
2650 if (icon_view->priv->cursor_item->selected)
2651 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2653 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2655 case GTK_SELECTION_MULTIPLE:
2656 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2657 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2659 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2660 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2665 /* Internal functions */
2667 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2668 GtkIconView *icon_view)
2670 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2672 gdk_window_move (icon_view->priv->bin_window,
2673 - icon_view->priv->hadjustment->value,
2674 - icon_view->priv->vadjustment->value);
2676 if (icon_view->priv->doing_rubberband)
2677 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2679 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2684 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2689 gint *maximum_width)
2692 gint x, current_width;
2693 GList *items, *last_item;
2700 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2701 max_height = g_new0 (gint, icon_view->priv->n_cells);
2708 gtk_widget_style_get (GTK_WIDGET (icon_view),
2709 "focus-line-width", &focus_width,
2712 x += icon_view->priv->margin + focus_width;
2713 current_width += 2 * (icon_view->priv->margin + focus_width);
2718 GtkIconViewItem *item = items->data;
2720 gtk_icon_view_calculate_item_size (icon_view, item);
2721 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2723 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2725 current_width += item->width;
2727 if (items != first_item)
2729 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2730 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2734 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2736 item->y = *y + focus_width;
2739 x = current_width - (icon_view->priv->margin + focus_width);
2741 for (i = 0; i < icon_view->priv->n_cells; i++)
2742 max_height[i] = MAX (max_height[i], item->box[i].height);
2744 if (current_width > *maximum_width)
2745 *maximum_width = current_width;
2751 items = items->next;
2756 /* Now go through the row again and align the icons */
2757 for (items = first_item; items != last_item; items = items->next)
2759 GtkIconViewItem *item = items->data;
2763 item->x = *maximum_width - item->width - item->x;
2764 item->col = col - 1 - item->col;
2767 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2769 /* We may want to readjust the new y coordinate. */
2770 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2771 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2774 g_free (max_height);
2780 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2783 if (upper != adj->upper)
2785 gdouble min = MAX (0.0, upper - adj->page_size);
2786 gboolean value_changed = FALSE;
2790 if (adj->value > min)
2793 value_changed = TRUE;
2796 gtk_adjustment_changed (adj);
2799 gtk_adjustment_value_changed (adj);
2804 gtk_icon_view_layout (GtkIconView *icon_view)
2806 gint y = 0, maximum_width = 0;
2812 if (icon_view->priv->layout_idle_id != 0)
2814 g_source_remove (icon_view->priv->layout_idle_id);
2815 icon_view->priv->layout_idle_id = 0;
2818 if (icon_view->priv->model == NULL)
2821 widget = GTK_WIDGET (icon_view);
2823 item_width = icon_view->priv->item_width;
2827 for (icons = icon_view->priv->items; icons; icons = icons->next)
2829 GtkIconViewItem *item = icons->data;
2830 gtk_icon_view_calculate_item_size (icon_view, item);
2831 item_width = MAX (item_width, item->width);
2836 icons = icon_view->priv->items;
2837 y += icon_view->priv->margin;
2842 gtk_icon_view_set_cell_data (icon_view, icons->data);
2843 adjust_wrap_width (icon_view, icons->data);
2848 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2850 &y, &maximum_width);
2853 while (icons != NULL);
2855 if (maximum_width != icon_view->priv->width)
2856 icon_view->priv->width = maximum_width;
2858 y += icon_view->priv->margin;
2860 if (y != icon_view->priv->height)
2861 icon_view->priv->height = y;
2863 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2864 icon_view->priv->width);
2865 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2866 icon_view->priv->height);
2868 if (icon_view->priv->width != widget->requisition.width ||
2869 icon_view->priv->height != widget->requisition.height)
2870 gtk_widget_queue_resize_no_redraw (widget);
2872 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2873 gdk_window_resize (icon_view->priv->bin_window,
2874 MAX (icon_view->priv->width, widget->allocation.width),
2875 MAX (icon_view->priv->height, widget->allocation.height));
2877 if (icon_view->priv->scroll_to_path)
2881 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2882 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2883 icon_view->priv->scroll_to_path = NULL;
2885 gtk_icon_view_scroll_to_path (icon_view, path,
2886 icon_view->priv->scroll_to_use_align,
2887 icon_view->priv->scroll_to_row_align,
2888 icon_view->priv->scroll_to_col_align);
2889 gtk_tree_path_free (path);
2892 gtk_widget_queue_draw (widget);
2896 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2897 GtkIconViewItem *item,
2898 GtkIconViewCellInfo *info,
2899 GdkRectangle *cell_area)
2901 g_return_if_fail (info->position < item->n_cells);
2903 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2905 cell_area->x = item->box[info->position].x - item->before[info->position];
2906 cell_area->y = item->y + icon_view->priv->item_padding;
2907 cell_area->width = item->box[info->position].width +
2908 item->before[info->position] + item->after[info->position];
2909 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2913 cell_area->x = item->x + icon_view->priv->item_padding;
2914 cell_area->y = item->box[info->position].y - item->before[info->position];
2915 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2916 cell_area->height = item->box[info->position].height +
2917 item->before[info->position] + item->after[info->position];
2922 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2923 GtkIconViewItem *item,
2924 GtkIconViewCellInfo *info,
2927 g_return_if_fail (info->position < item->n_cells);
2929 *box = item->box[info->position];
2932 /* try to guess a reasonable wrap width for an implicit text cell renderer
2935 adjust_wrap_width (GtkIconView *icon_view,
2936 GtkIconViewItem *item)
2938 GtkIconViewCellInfo *text_info;
2939 GtkIconViewCellInfo *pixbuf_info;
2940 gint pixbuf_width, wrap_width;
2942 if (icon_view->priv->text_cell != -1 &&
2943 icon_view->priv->pixbuf_cell != -1)
2947 text_info = g_list_nth_data (icon_view->priv->cell_list,
2948 icon_view->priv->text_cell);
2949 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2950 icon_view->priv->pixbuf_cell);
2952 gtk_cell_renderer_get_size (pixbuf_info->cell,
2953 GTK_WIDGET (icon_view),
2959 if (icon_view->priv->item_width > 0)
2960 item_width = icon_view->priv->item_width;
2962 item_width = item->width;
2964 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2965 wrap_width = item_width;
2967 if (item->width == -1 && item_width <= 0)
2968 wrap_width = MAX (2 * pixbuf_width, 50);
2970 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2973 wrap_width -= icon_view->priv->item_padding * 2;
2975 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2976 g_object_set (text_info->cell, "width", wrap_width, NULL);
2981 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2982 GtkIconViewItem *item)
2987 if (item->width != -1 && item->height != -1)
2990 if (item->n_cells != icon_view->priv->n_cells)
2992 g_free (item->before);
2993 g_free (item->after);
2996 item->before = g_new0 (gint, icon_view->priv->n_cells);
2997 item->after = g_new0 (gint, icon_view->priv->n_cells);
2998 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
3000 item->n_cells = icon_view->priv->n_cells;
3003 gtk_icon_view_set_cell_data (icon_view, item);
3005 spacing = icon_view->priv->spacing;
3009 for (l = icon_view->priv->cell_list; l; l = l->next)
3011 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3013 if (!info->cell->visible)
3016 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3018 &item->box[info->position].width,
3019 &item->box[info->position].height);
3021 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3023 item->width += item->box[info->position].width
3024 + (info->position > 0 ? spacing : 0);
3025 item->height = MAX (item->height, item->box[info->position].height);
3029 item->width = MAX (item->width, item->box[info->position].width);
3030 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3034 item->width += icon_view->priv->item_padding * 2;
3035 item->height += icon_view->priv->item_padding * 2;
3039 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3040 GtkIconViewItem *item,
3043 GdkRectangle cell_area;
3049 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3051 gtk_icon_view_set_cell_data (icon_view, item);
3053 spacing = icon_view->priv->spacing;
3056 for (i = 0; i < icon_view->priv->n_cells; i++)
3058 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3059 item->height = MAX (item->height, max_height[i]);
3061 item->height += max_height[i] + (i > 0 ? spacing : 0);
3064 cell_area.x = item->x + icon_view->priv->item_padding;
3065 cell_area.y = item->y + icon_view->priv->item_padding;
3067 for (k = 0; k < 2; k++)
3068 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3070 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3072 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3075 if (!info->cell->visible)
3078 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3080 /* We should not subtract icon_view->priv->item_padding from item->height,
3081 * because item->height is recalculated above using
3082 * max_height which does not contain item padding.
3084 cell_area.width = item->box[info->position].width;
3085 cell_area.height = item->height;
3089 /* item->width is not recalculated and thus needs to be
3090 * corrected for the padding.
3092 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3093 cell_area.height = max_height[i];
3096 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
3098 &item->box[info->position].x, &item->box[info->position].y,
3099 &item->box[info->position].width, &item->box[info->position].height);
3101 item->box[info->position].x += cell_area.x;
3102 item->box[info->position].y += cell_area.y;
3103 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3105 item->before[info->position] = item->box[info->position].x - cell_area.x;
3106 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3107 cell_area.x += cell_area.width + spacing;
3111 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3113 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3114 cell_area.width = item->width;
3116 item->before[info->position] = item->box[info->position].y - cell_area.y;
3117 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3118 cell_area.y += cell_area.height + spacing;
3122 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
3124 for (i = 0; i < icon_view->priv->n_cells; i++)
3126 item->box[i].x = item->x + item->width -
3127 (item->box[i].x + item->box[i].width - item->x);
3131 item->height += icon_view->priv->item_padding * 2;
3135 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3137 g_list_foreach (icon_view->priv->items,
3138 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3142 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3149 gtk_icon_view_paint_item (GtkIconView *icon_view,
3151 GtkIconViewItem *item,
3153 GdkDrawable *drawable,
3156 gboolean draw_focus)
3160 GdkRectangle cell_area, box;
3164 GtkCellRendererState flags;
3166 if (icon_view->priv->model == NULL)
3169 gtk_icon_view_set_cell_data (icon_view, item);
3171 gtk_widget_style_get (GTK_WIDGET (icon_view),
3172 "focus-line-width", &focus_width,
3175 padding = focus_width;
3179 flags = GTK_CELL_RENDERER_SELECTED;
3180 if (gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3181 state = GTK_STATE_SELECTED;
3183 state = GTK_STATE_ACTIVE;
3188 state = GTK_STATE_NORMAL;
3191 #ifdef DEBUG_ICON_VIEW
3192 gdk_draw_rectangle (drawable,
3193 GTK_WIDGET (icon_view)->style->black_gc,
3196 item->width, item->height);
3201 gtk_paint_flat_box (GTK_WIDGET (icon_view)->style,
3202 (GdkWindow *) drawable,
3206 GTK_WIDGET (icon_view),
3209 item->width, item->height);
3212 for (l = icon_view->priv->cell_list; l; l = l->next)
3214 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3216 if (!info->cell->visible)
3219 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3221 #ifdef DEBUG_ICON_VIEW
3222 gdk_draw_rectangle (drawable,
3223 GTK_WIDGET (icon_view)->style->black_gc,
3225 x - item->x + cell_area.x,
3226 y - item->y + cell_area.y,
3227 cell_area.width, cell_area.height);
3229 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3231 gdk_draw_rectangle (drawable,
3232 GTK_WIDGET (icon_view)->style->black_gc,
3234 x - item->x + box.x,
3235 y - item->y + box.y,
3236 box.width, box.height);
3239 cell_area.x = x - item->x + cell_area.x;
3240 cell_area.y = y - item->y + cell_area.y;
3242 gtk_cell_renderer_render (info->cell,
3244 GTK_WIDGET (icon_view),
3245 &cell_area, &cell_area, area, flags);
3249 gtk_widget_has_focus (GTK_WIDGET (icon_view)) &&
3250 item == icon_view->priv->cursor_item)
3252 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3254 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3256 if (!info->cell->visible)
3259 /* If found a editable/activatable cell, draw focus on it. */
3260 if (icon_view->priv->cursor_cell < 0 &&
3261 info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3262 icon_view->priv->cursor_cell = i;
3264 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3266 if (i == icon_view->priv->cursor_cell)
3268 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3272 GTK_WIDGET (icon_view),
3274 x - item->x + box.x - padding,
3275 y - item->y + box.y - padding,
3276 box.width + 2 * padding,
3277 box.height + 2 * padding);
3282 /* If there are no editable/activatable cells, draw focus
3283 * around the whole item.
3285 if (icon_view->priv->cursor_cell < 0)
3286 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3290 GTK_WIDGET (icon_view),
3294 item->width + 2 * padding,
3295 item->height + 2 * padding);
3300 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3305 GdkRectangle rubber_rect;
3306 GdkColor *fill_color_gdk;
3307 guchar fill_color_alpha;
3309 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3310 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3311 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3312 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3314 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3317 gtk_widget_style_get (GTK_WIDGET (icon_view),
3318 "selection-box-color", &fill_color_gdk,
3319 "selection-box-alpha", &fill_color_alpha,
3322 if (!fill_color_gdk)
3323 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3325 cairo_set_source_rgba (cr,
3326 fill_color_gdk->red / 65535.,
3327 fill_color_gdk->green / 65535.,
3328 fill_color_gdk->blue / 65535.,
3329 fill_color_alpha / 255.);
3332 gdk_cairo_rectangle (cr, &rect);
3336 /* Draw the border without alpha */
3337 cairo_set_source_rgb (cr,
3338 fill_color_gdk->red / 65535.,
3339 fill_color_gdk->green / 65535.,
3340 fill_color_gdk->blue / 65535.);
3341 cairo_rectangle (cr,
3342 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3343 rubber_rect.width - 1, rubber_rect.height - 1);
3347 gdk_color_free (fill_color_gdk);
3351 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3357 index = gtk_tree_path_get_indices (path)[0];
3359 for (l = icon_view->priv->items; l; l = l->next)
3361 GtkIconViewItem *item = l->data;
3363 if (item->index == index)
3365 gtk_icon_view_queue_draw_item (icon_view, item);
3372 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3373 GtkIconViewItem *item)
3378 gtk_widget_style_get (GTK_WIDGET (icon_view),
3379 "focus-line-width", &focus_width,
3382 rect.x = item->x - focus_width;
3383 rect.y = item->y - focus_width;
3384 rect.width = item->width + 2 * focus_width;
3385 rect.height = item->height + 2 * focus_width;
3387 if (icon_view->priv->bin_window)
3388 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3392 layout_callback (gpointer user_data)
3394 GtkIconView *icon_view;
3396 icon_view = GTK_ICON_VIEW (user_data);
3398 icon_view->priv->layout_idle_id = 0;
3400 gtk_icon_view_layout (icon_view);
3406 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3408 if (icon_view->priv->layout_idle_id != 0)
3411 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3415 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3416 GtkIconViewItem *item,
3420 AtkObject *item_obj;
3421 AtkObject *cursor_item_obj;
3423 if (icon_view->priv->cursor_item == item &&
3424 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3427 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3428 if (icon_view->priv->cursor_item != NULL)
3430 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3433 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3434 if (cursor_item_obj != NULL)
3435 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3438 icon_view->priv->cursor_item = item;
3439 if (cursor_cell >= 0)
3440 icon_view->priv->cursor_cell = cursor_cell;
3442 gtk_icon_view_queue_draw_item (icon_view, item);
3444 /* Notify that accessible focus object has changed */
3445 item_obj = atk_object_ref_accessible_child (obj, item->index);
3447 if (item_obj != NULL)
3449 atk_focus_tracker_notify (item_obj);
3450 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3451 g_object_unref (item_obj);
3456 static GtkIconViewItem *
3457 gtk_icon_view_item_new (void)
3459 GtkIconViewItem *item;
3461 item = g_new0 (GtkIconViewItem, 1);
3470 gtk_icon_view_item_free (GtkIconViewItem *item)
3472 g_return_if_fail (item != NULL);
3474 g_free (item->before);
3475 g_free (item->after);
3482 static GtkIconViewItem *
3483 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3486 gboolean only_in_cell,
3487 GtkIconViewCellInfo **cell_at_pos)
3493 *cell_at_pos = NULL;
3495 for (items = icon_view->priv->items; items; items = items->next)
3497 GtkIconViewItem *item = items->data;
3499 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3500 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3502 if (only_in_cell || cell_at_pos)
3504 gtk_icon_view_set_cell_data (icon_view, item);
3506 for (l = icon_view->priv->cell_list; l; l = l->next)
3508 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3510 if (!info->cell->visible)
3513 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3515 if ((x >= box.x && x <= box.x + box.width &&
3516 y >= box.y && y <= box.y + box.height) ||
3518 x <= box.x + box.width &&
3520 y <= box.y + box.height))
3523 *cell_at_pos = info;
3541 gtk_icon_view_select_item (GtkIconView *icon_view,
3542 GtkIconViewItem *item)
3544 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3545 g_return_if_fail (item != NULL);
3550 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3552 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3553 gtk_icon_view_unselect_all_internal (icon_view);
3555 item->selected = TRUE;
3557 gtk_icon_view_item_selected_changed (icon_view, item);
3558 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3560 gtk_icon_view_queue_draw_item (icon_view, item);
3565 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3566 GtkIconViewItem *item)
3568 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3569 g_return_if_fail (item != NULL);
3571 if (!item->selected)
3574 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3575 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3578 item->selected = FALSE;
3580 gtk_icon_view_item_selected_changed (icon_view, item);
3581 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3583 gtk_icon_view_queue_draw_item (icon_view, item);
3587 verify_items (GtkIconView *icon_view)
3592 for (items = icon_view->priv->items; items; items = items->next)
3594 GtkIconViewItem *item = items->data;
3596 if (item->index != i)
3597 g_error ("List item does not match its index: "
3598 "item index %d and list index %d\n", item->index, i);
3605 gtk_icon_view_row_changed (GtkTreeModel *model,
3610 GtkIconViewItem *item;
3612 GtkIconView *icon_view;
3614 icon_view = GTK_ICON_VIEW (data);
3616 gtk_icon_view_stop_editing (icon_view, TRUE);
3618 index = gtk_tree_path_get_indices(path)[0];
3619 item = g_list_nth_data (icon_view->priv->items, index);
3621 gtk_icon_view_item_invalidate_size (item);
3622 gtk_icon_view_queue_layout (icon_view);
3624 verify_items (icon_view);
3628 gtk_icon_view_row_inserted (GtkTreeModel *model,
3634 GtkIconViewItem *item;
3635 gboolean iters_persist;
3636 GtkIconView *icon_view;
3639 icon_view = GTK_ICON_VIEW (data);
3641 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3643 index = gtk_tree_path_get_indices(path)[0];
3645 item = gtk_icon_view_item_new ();
3650 item->index = index;
3652 /* FIXME: We can be more efficient here,
3653 we can store a tail pointer and use that when
3654 appending (which is a rather common operation)
3656 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3659 list = g_list_nth (icon_view->priv->items, index + 1);
3660 for (; list; list = list->next)
3667 verify_items (icon_view);
3669 gtk_icon_view_queue_layout (icon_view);
3673 gtk_icon_view_row_deleted (GtkTreeModel *model,
3678 GtkIconView *icon_view;
3679 GtkIconViewItem *item;
3681 gboolean emit = FALSE;
3683 icon_view = GTK_ICON_VIEW (data);
3685 index = gtk_tree_path_get_indices(path)[0];
3687 list = g_list_nth (icon_view->priv->items, index);
3690 gtk_icon_view_stop_editing (icon_view, TRUE);
3692 if (item == icon_view->priv->anchor_item)
3693 icon_view->priv->anchor_item = NULL;
3695 if (item == icon_view->priv->cursor_item)
3696 icon_view->priv->cursor_item = NULL;
3701 gtk_icon_view_item_free (item);
3703 for (next = list->next; next; next = next->next)
3710 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3712 verify_items (icon_view);
3714 gtk_icon_view_queue_layout (icon_view);
3717 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3721 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3722 GtkTreePath *parent,
3729 GtkIconView *icon_view;
3730 GList *items = NULL, *list;
3731 GtkIconViewItem **item_array;
3734 icon_view = GTK_ICON_VIEW (data);
3736 gtk_icon_view_stop_editing (icon_view, TRUE);
3738 length = gtk_tree_model_iter_n_children (model, NULL);
3740 order = g_new (gint, length);
3741 for (i = 0; i < length; i++)
3742 order [new_order[i]] = i;
3744 item_array = g_new (GtkIconViewItem *, length);
3745 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3746 item_array[order[i]] = list->data;
3749 for (i = length - 1; i >= 0; i--)
3751 item_array[i]->index = i;
3752 items = g_list_prepend (items, item_array[i]);
3755 g_free (item_array);
3756 g_list_free (icon_view->priv->items);
3757 icon_view->priv->items = items;
3759 gtk_icon_view_queue_layout (icon_view);
3761 verify_items (icon_view);
3765 gtk_icon_view_build_items (GtkIconView *icon_view)
3769 gboolean iters_persist;
3770 GList *items = NULL;
3772 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3774 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3782 GtkIconViewItem *item = gtk_icon_view_item_new ();
3791 items = g_list_prepend (items, item);
3793 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3795 icon_view->priv->items = g_list_reverse (items);
3799 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3802 GtkMovementStep step,
3806 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3807 I_("move-cursor"), 2,
3811 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3816 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3819 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3824 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3831 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3832 GtkMovementStep step,
3835 GdkModifierType state;
3837 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3838 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3839 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3840 step == GTK_MOVEMENT_DISPLAY_LINES ||
3841 step == GTK_MOVEMENT_PAGES ||
3842 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3844 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3847 gtk_icon_view_stop_editing (icon_view, FALSE);
3848 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3850 if (gtk_get_current_event_state (&state))
3852 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3853 icon_view->priv->ctrl_pressed = TRUE;
3854 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3855 icon_view->priv->shift_pressed = TRUE;
3857 /* else we assume not pressed */
3861 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3862 case GTK_MOVEMENT_VISUAL_POSITIONS:
3863 gtk_icon_view_move_cursor_left_right (icon_view, count);
3865 case GTK_MOVEMENT_DISPLAY_LINES:
3866 gtk_icon_view_move_cursor_up_down (icon_view, count);
3868 case GTK_MOVEMENT_PAGES:
3869 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3871 case GTK_MOVEMENT_BUFFER_ENDS:
3872 gtk_icon_view_move_cursor_start_end (icon_view, count);
3875 g_assert_not_reached ();
3878 icon_view->priv->ctrl_pressed = FALSE;
3879 icon_view->priv->shift_pressed = FALSE;
3881 icon_view->priv->draw_focus = TRUE;
3886 static GtkIconViewItem *
3887 find_item (GtkIconView *icon_view,
3888 GtkIconViewItem *current,
3894 GtkIconViewItem *item;
3896 /* FIXME: this could be more efficient
3898 row = current->row + row_ofs;
3899 col = current->col + col_ofs;
3901 for (items = icon_view->priv->items; items; items = items->next)
3904 if (item->row == row && item->col == col)
3912 find_cell (GtkIconView *icon_view,
3913 GtkIconViewItem *item,
3915 GtkOrientation orientation,
3925 if (icon_view->priv->orientation != orientation)
3928 gtk_icon_view_set_cell_data (icon_view, item);
3930 focusable = g_new0 (gint, icon_view->priv->n_cells);
3934 for (k = 0; k < 2; k++)
3935 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3937 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3939 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3942 if (!info->cell->visible)
3945 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3948 current = n_focusable;
3950 focusable[n_focusable] = i;
3956 if (n_focusable == 0)
3964 current = step > 0 ? 0 : n_focusable - 1;
3965 cell = focusable[current];
3968 if (current + *count < 0)
3971 *count = current + *count;
3973 else if (current + *count > n_focusable - 1)
3976 *count = current + *count - (n_focusable - 1);
3980 cell = focusable[current + *count];
3989 static GtkIconViewItem *
3990 find_item_page_up_down (GtkIconView *icon_view,
3991 GtkIconViewItem *current,
3998 y = current->y + count * icon_view->priv->vadjustment->page_size;
4000 item = g_list_find (icon_view->priv->items, current);
4005 for (next = item->next; next; next = next->next)
4007 if (((GtkIconViewItem *)next->data)->col == col)
4010 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4020 for (next = item->prev; next; next = next->prev)
4022 if (((GtkIconViewItem *)next->data)->col == col)
4025 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4039 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4040 GtkIconViewItem *anchor,
4041 GtkIconViewItem *cursor)
4044 GtkIconViewItem *item;
4045 gint row1, row2, col1, col2;
4046 gboolean dirty = FALSE;
4048 if (anchor->row < cursor->row)
4059 if (anchor->col < cursor->col)
4070 for (items = icon_view->priv->items; items; items = items->next)
4074 if (row1 <= item->row && item->row <= row2 &&
4075 col1 <= item->col && item->col <= col2)
4077 if (!item->selected)
4080 item->selected = TRUE;
4081 gtk_icon_view_item_selected_changed (icon_view, item);
4083 gtk_icon_view_queue_draw_item (icon_view, item);
4091 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4094 GtkIconViewItem *item;
4096 gboolean dirty = FALSE;
4098 GtkDirectionType direction;
4100 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4103 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4105 if (!icon_view->priv->cursor_item)
4110 list = icon_view->priv->items;
4112 list = g_list_last (icon_view->priv->items);
4114 item = list ? list->data : NULL;
4119 item = icon_view->priv->cursor_item;
4120 cell = icon_view->priv->cursor_cell;
4121 step = count > 0 ? 1 : -1;
4124 cell = find_cell (icon_view, item, cell,
4125 GTK_ORIENTATION_VERTICAL,
4130 item = find_item (icon_view, item, step, 0);
4131 count = count - step;
4137 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4139 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4141 gtk_widget_child_focus (toplevel,
4142 direction == GTK_DIR_UP ?
4143 GTK_DIR_TAB_BACKWARD :
4144 GTK_DIR_TAB_FORWARD);
4150 if (icon_view->priv->ctrl_pressed ||
4151 !icon_view->priv->shift_pressed ||
4152 !icon_view->priv->anchor_item ||
4153 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4154 icon_view->priv->anchor_item = item;
4156 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4158 if (!icon_view->priv->ctrl_pressed &&
4159 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4161 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4162 dirty = gtk_icon_view_select_all_between (icon_view,
4163 icon_view->priv->anchor_item,
4167 gtk_icon_view_scroll_to_item (icon_view, item);
4170 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4174 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4177 GtkIconViewItem *item;
4178 gboolean dirty = FALSE;
4180 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4183 if (!icon_view->priv->cursor_item)
4188 list = icon_view->priv->items;
4190 list = g_list_last (icon_view->priv->items);
4192 item = list ? list->data : NULL;
4195 item = find_item_page_up_down (icon_view,
4196 icon_view->priv->cursor_item,
4199 if (item == icon_view->priv->cursor_item)
4200 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4205 if (icon_view->priv->ctrl_pressed ||
4206 !icon_view->priv->shift_pressed ||
4207 !icon_view->priv->anchor_item ||
4208 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4209 icon_view->priv->anchor_item = item;
4211 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4213 if (!icon_view->priv->ctrl_pressed &&
4214 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4216 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4217 dirty = gtk_icon_view_select_all_between (icon_view,
4218 icon_view->priv->anchor_item,
4222 gtk_icon_view_scroll_to_item (icon_view, item);
4225 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4229 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4232 GtkIconViewItem *item;
4234 gboolean dirty = FALSE;
4236 GtkDirectionType direction;
4238 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4241 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4243 if (!icon_view->priv->cursor_item)
4248 list = icon_view->priv->items;
4250 list = g_list_last (icon_view->priv->items);
4252 item = list ? list->data : NULL;
4256 item = icon_view->priv->cursor_item;
4257 cell = icon_view->priv->cursor_cell;
4258 step = count > 0 ? 1 : -1;
4261 cell = find_cell (icon_view, item, cell,
4262 GTK_ORIENTATION_HORIZONTAL,
4267 item = find_item (icon_view, item, 0, step);
4268 count = count - step;
4274 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4276 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4278 gtk_widget_child_focus (toplevel,
4279 direction == GTK_DIR_LEFT ?
4280 GTK_DIR_TAB_BACKWARD :
4281 GTK_DIR_TAB_FORWARD);
4287 if (icon_view->priv->ctrl_pressed ||
4288 !icon_view->priv->shift_pressed ||
4289 !icon_view->priv->anchor_item ||
4290 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4291 icon_view->priv->anchor_item = item;
4293 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4295 if (!icon_view->priv->ctrl_pressed &&
4296 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4298 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4299 dirty = gtk_icon_view_select_all_between (icon_view,
4300 icon_view->priv->anchor_item,
4304 gtk_icon_view_scroll_to_item (icon_view, item);
4307 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4311 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4314 GtkIconViewItem *item;
4316 gboolean dirty = FALSE;
4318 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4322 list = icon_view->priv->items;
4324 list = g_list_last (icon_view->priv->items);
4326 item = list ? list->data : NULL;
4328 if (item == icon_view->priv->cursor_item)
4329 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4334 if (icon_view->priv->ctrl_pressed ||
4335 !icon_view->priv->shift_pressed ||
4336 !icon_view->priv->anchor_item ||
4337 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4338 icon_view->priv->anchor_item = item;
4340 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4342 if (!icon_view->priv->ctrl_pressed &&
4343 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4345 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4346 dirty = gtk_icon_view_select_all_between (icon_view,
4347 icon_view->priv->anchor_item,
4351 gtk_icon_view_scroll_to_item (icon_view, item);
4354 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4358 * gtk_icon_view_scroll_to_path:
4359 * @icon_view: A #GtkIconView.
4360 * @path: The path of the item to move to.
4361 * @use_align: whether to use alignment arguments, or %FALSE.
4362 * @row_align: The vertical alignment of the item specified by @path.
4363 * @col_align: The horizontal alignment of the item specified by @path.
4365 * Moves the alignments of @icon_view to the position specified by @path.
4366 * @row_align determines where the row is placed, and @col_align determines
4367 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4368 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4371 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4372 * tree does the minimum amount of work to scroll the item onto the screen.
4373 * This means that the item will be scrolled to the edge closest to its current
4374 * position. If the item is currently visible on the screen, nothing is done.
4376 * This function only works if the model is set, and @path is a valid row on
4377 * the model. If the model changes before the @icon_view is realized, the
4378 * centered path will be modified to reflect this change.
4383 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4389 GtkIconViewItem *item = NULL;
4391 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4392 g_return_if_fail (path != NULL);
4393 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4394 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4396 if (gtk_tree_path_get_depth (path) > 0)
4397 item = g_list_nth_data (icon_view->priv->items,
4398 gtk_tree_path_get_indices(path)[0]);
4400 if (!item || item->width < 0 ||
4401 !gtk_widget_get_realized (GTK_WIDGET (icon_view)))
4403 if (icon_view->priv->scroll_to_path)
4404 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4406 icon_view->priv->scroll_to_path = NULL;
4409 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4411 icon_view->priv->scroll_to_use_align = use_align;
4412 icon_view->priv->scroll_to_row_align = row_align;
4413 icon_view->priv->scroll_to_col_align = col_align;
4424 gtk_widget_style_get (GTK_WIDGET (icon_view),
4425 "focus-line-width", &focus_width,
4428 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4430 offset = y + item->y - focus_width -
4431 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4433 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4434 icon_view->priv->vadjustment->value + offset);
4436 offset = x + item->x - focus_width -
4437 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4439 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4440 icon_view->priv->hadjustment->value + offset);
4442 gtk_adjustment_changed (icon_view->priv->hadjustment);
4443 gtk_adjustment_changed (icon_view->priv->vadjustment);
4446 gtk_icon_view_scroll_to_item (icon_view, item);
4451 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4452 GtkIconViewItem *item)
4454 gint x, y, width, height;
4457 gtk_widget_style_get (GTK_WIDGET (icon_view),
4458 "focus-line-width", &focus_width,
4461 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4463 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4465 if (y + item->y - focus_width < 0)
4466 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4467 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4468 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4469 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4470 icon_view->priv->vadjustment->value + y + item->y + item->height
4471 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4473 if (x + item->x - focus_width < 0)
4474 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4475 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4476 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4477 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4478 icon_view->priv->hadjustment->value + x + item->x + item->width
4479 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4481 gtk_adjustment_changed (icon_view->priv->hadjustment);
4482 gtk_adjustment_changed (icon_view->priv->vadjustment);
4485 /* GtkCellLayout implementation */
4486 static GtkIconViewCellInfo *
4487 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4488 GtkCellRenderer *renderer)
4492 for (i = icon_view->priv->cell_list; i; i = i->next)
4494 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4496 if (info->cell == renderer)
4504 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4505 GtkIconViewItem *item)
4508 gboolean iters_persist;
4511 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4517 path = gtk_tree_path_new_from_indices (item->index, -1);
4518 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4520 gtk_tree_path_free (path);
4525 for (i = icon_view->priv->cell_list; i; i = i->next)
4528 GtkIconViewCellInfo *info = i->data;
4530 g_object_freeze_notify (G_OBJECT (info->cell));
4532 for (j = info->attributes; j && j->next; j = j->next->next)
4534 gchar *property = j->data;
4535 gint column = GPOINTER_TO_INT (j->next->data);
4536 GValue value = {0, };
4538 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4540 g_object_set_property (G_OBJECT (info->cell),
4542 g_value_unset (&value);
4546 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4548 icon_view->priv->model,
4552 g_object_thaw_notify (G_OBJECT (info->cell));
4557 free_cell_attributes (GtkIconViewCellInfo *info)
4561 list = info->attributes;
4562 while (list && list->next)
4564 g_free (list->data);
4565 list = list->next->next;
4568 g_slist_free (info->attributes);
4569 info->attributes = NULL;
4573 free_cell_info (GtkIconViewCellInfo *info)
4575 free_cell_attributes (info);
4577 g_object_unref (info->cell);
4580 (* info->destroy) (info->func_data);
4586 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4587 GtkCellRenderer *renderer,
4590 GtkIconViewCellInfo *info;
4591 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4593 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4594 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4596 g_object_ref_sink (renderer);
4598 info = g_new0 (GtkIconViewCellInfo, 1);
4599 info->cell = renderer;
4600 info->expand = expand ? TRUE : FALSE;
4601 info->pack = GTK_PACK_START;
4602 info->position = icon_view->priv->n_cells;
4604 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4605 icon_view->priv->n_cells++;
4609 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4610 GtkCellRenderer *renderer,
4613 GtkIconViewCellInfo *info;
4614 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4616 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4617 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4619 g_object_ref_sink (renderer);
4621 info = g_new0 (GtkIconViewCellInfo, 1);
4622 info->cell = renderer;
4623 info->expand = expand ? TRUE : FALSE;
4624 info->pack = GTK_PACK_END;
4625 info->position = icon_view->priv->n_cells;
4627 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4628 icon_view->priv->n_cells++;
4632 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4633 GtkCellRenderer *renderer,
4634 const gchar *attribute,
4637 GtkIconViewCellInfo *info;
4638 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4640 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4641 g_return_if_fail (info != NULL);
4643 info->attributes = g_slist_prepend (info->attributes,
4644 GINT_TO_POINTER (column));
4645 info->attributes = g_slist_prepend (info->attributes,
4646 g_strdup (attribute));
4650 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4652 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4654 while (icon_view->priv->cell_list)
4656 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4657 free_cell_info (info);
4658 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4659 icon_view->priv->cell_list);
4662 icon_view->priv->n_cells = 0;
4666 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4667 GtkCellRenderer *cell,
4668 GtkCellLayoutDataFunc func,
4670 GDestroyNotify destroy)
4672 GtkIconViewCellInfo *info;
4673 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4675 info = gtk_icon_view_get_cell_info (icon_view, cell);
4676 g_return_if_fail (info != NULL);
4680 GDestroyNotify d = info->destroy;
4682 info->destroy = NULL;
4683 d (info->func_data);
4687 info->func_data = func_data;
4688 info->destroy = destroy;
4692 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4693 GtkCellRenderer *renderer)
4695 GtkIconViewCellInfo *info;
4697 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4699 free_cell_attributes (info);
4703 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4704 GtkCellRenderer *cell,
4707 GtkIconView *icon_view;
4709 GtkIconViewCellInfo *info;
4712 icon_view = GTK_ICON_VIEW (layout);
4714 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4716 info = gtk_icon_view_get_cell_info (icon_view, cell);
4718 g_return_if_fail (info != NULL);
4719 g_return_if_fail (position >= 0);
4721 link = g_list_find (icon_view->priv->cell_list, info);
4723 g_return_if_fail (link != NULL);
4725 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4727 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4730 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4737 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4741 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4743 GtkIconView *icon_view = (GtkIconView *)layout;
4744 GList *retval = NULL, *l;
4746 for (l = icon_view->priv->cell_list; l; l = l->next)
4748 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4750 retval = g_list_prepend (retval, info->cell);
4753 return g_list_reverse (retval);
4760 * gtk_icon_view_new:
4762 * Creates a new #GtkIconView widget
4764 * Return value: A newly created #GtkIconView widget
4769 gtk_icon_view_new (void)
4771 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4775 * gtk_icon_view_new_with_model:
4776 * @model: The model.
4778 * Creates a new #GtkIconView widget with the model @model.
4780 * Return value: A newly created #GtkIconView widget.
4785 gtk_icon_view_new_with_model (GtkTreeModel *model)
4787 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4791 * gtk_icon_view_convert_widget_to_bin_window_coords:
4792 * @icon_view: a #GtkIconView
4793 * @wx: X coordinate relative to the widget
4794 * @wy: Y coordinate relative to the widget
4795 * @bx: return location for bin_window X coordinate
4796 * @by: return location for bin_window Y coordinate
4798 * Converts widget coordinates to coordinates for the bin_window,
4799 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4804 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4812 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4814 if (icon_view->priv->bin_window)
4815 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4826 * gtk_icon_view_get_path_at_pos:
4827 * @icon_view: A #GtkIconView.
4828 * @x: The x position to be identified
4829 * @y: The y position to be identified
4831 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4832 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4833 * the cell at the specified position.
4834 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4835 * widget coordinates to bin_window coordinates.
4837 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4838 * if no icon exists at that position.
4843 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4847 GtkIconViewItem *item;
4850 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4852 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4857 path = gtk_tree_path_new_from_indices (item->index, -1);
4863 * gtk_icon_view_get_item_at_pos:
4864 * @icon_view: A #GtkIconView.
4865 * @x: The x position to be identified
4866 * @y: The y position to be identified
4867 * @path: (allow-none): Return location for the path, or %NULL
4868 * @cell: Return location for the renderer responsible for the cell
4869 * at (@x, @y), or %NULL
4871 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4872 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4873 * obtains the cell at the specified position. The returned path should
4874 * be freed with gtk_tree_path_free().
4875 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4876 * widget coordinates to bin_window coordinates.
4878 * Return value: %TRUE if an item exists at the specified position
4883 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4887 GtkCellRenderer **cell)
4889 GtkIconViewItem *item;
4890 GtkIconViewCellInfo *info;
4892 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4894 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4899 *path = gtk_tree_path_new_from_indices (item->index, -1);
4912 return (item != NULL);
4916 * gtk_icon_view_set_tooltip_item:
4917 * @icon_view: a #GtkIconView
4918 * @tooltip: a #GtkTooltip
4919 * @path: a #GtkTreePath
4921 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4922 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4923 * See also gtk_tooltip_set_tip_area().
4928 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4929 GtkTooltip *tooltip,
4932 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4933 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4935 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4939 * gtk_icon_view_set_tooltip_cell:
4940 * @icon_view: a #GtkIconView
4941 * @tooltip: a #GtkTooltip
4942 * @path: a #GtkTreePath
4943 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4945 * Sets the tip area of @tooltip to the area which @cell occupies in
4946 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4948 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4953 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4954 GtkTooltip *tooltip,
4956 GtkCellRenderer *cell)
4959 GtkIconViewItem *item = NULL;
4960 GtkIconViewCellInfo *info = NULL;
4963 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4964 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4965 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4967 if (gtk_tree_path_get_depth (path) > 0)
4968 item = g_list_nth_data (icon_view->priv->items,
4969 gtk_tree_path_get_indices(path)[0]);
4976 info = gtk_icon_view_get_cell_info (icon_view, cell);
4977 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4983 rect.width = item->width;
4984 rect.height = item->height;
4987 if (icon_view->priv->bin_window)
4989 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4994 gtk_tooltip_set_tip_area (tooltip, &rect);
4999 * gtk_icon_view_get_tooltip_context:
5000 * @icon_view: an #GtkIconView
5001 * @x: the x coordinate (relative to widget coordinates)
5002 * @y: the y coordinate (relative to widget coordinates)
5003 * @keyboard_tip: whether this is a keyboard tooltip or not
5004 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5005 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
5006 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5008 * This function is supposed to be used in a #GtkWidget::query-tooltip
5009 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5010 * which are received in the signal handler, should be passed to this
5011 * function without modification.
5013 * The return value indicates whether there is an icon view item at the given
5014 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5015 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5016 * @model, @path and @iter which have been provided will be set to point to
5017 * that row and the corresponding model. @x and @y will always be converted
5018 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5020 * Return value: whether or not the given tooltip context points to a item
5025 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5028 gboolean keyboard_tip,
5029 GtkTreeModel **model,
5033 GtkTreePath *tmppath = NULL;
5035 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5036 g_return_val_if_fail (x != NULL, FALSE);
5037 g_return_val_if_fail (y != NULL, FALSE);
5041 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5048 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5051 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5056 *model = gtk_icon_view_get_model (icon_view);
5059 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5065 gtk_tree_path_free (tmppath);
5071 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5074 gboolean keyboard_tip,
5075 GtkTooltip *tooltip,
5081 GtkTreeModel *model;
5082 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5084 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5087 &model, &path, &iter))
5090 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5094 gtk_tree_path_free (path);
5098 gtk_tooltip_set_markup (tooltip, str);
5099 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5101 gtk_tree_path_free (path);
5109 * gtk_icon_view_set_tooltip_column:
5110 * @icon_view: a #GtkIconView
5111 * @column: an integer, which is a valid column number for @icon_view's model
5113 * If you only plan to have simple (text-only) tooltips on full items, you
5114 * can use this function to have #GtkIconView handle these automatically
5115 * for you. @column should be set to the column in @icon_view's model
5116 * containing the tooltip texts, or -1 to disable this feature.
5118 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5119 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5124 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5127 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5129 if (column == icon_view->priv->tooltip_column)
5134 g_signal_handlers_disconnect_by_func (icon_view,
5135 gtk_icon_view_set_tooltip_query_cb,
5137 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5141 if (icon_view->priv->tooltip_column == -1)
5143 g_signal_connect (icon_view, "query-tooltip",
5144 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5145 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5149 icon_view->priv->tooltip_column = column;
5150 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5154 * gtk_icon_view_get_tooltip_column:
5155 * @icon_view: a #GtkIconView
5157 * Returns the column of @icon_view's model which is being used for
5158 * displaying tooltips on @icon_view's rows.
5160 * Return value: the index of the tooltip column that is currently being
5161 * used, or -1 if this is disabled.
5166 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5168 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5170 return icon_view->priv->tooltip_column;
5174 * gtk_icon_view_get_visible_range:
5175 * @icon_view: A #GtkIconView
5176 * @start_path: (allow-none): Return location for start of region, or %NULL
5177 * @end_path: (allow-none): Return location for end of region, or %NULL
5179 * Sets @start_path and @end_path to be the first and last visible path.
5180 * Note that there may be invisible paths in between.
5182 * Both paths should be freed with gtk_tree_path_free() after use.
5184 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5189 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5190 GtkTreePath **start_path,
5191 GtkTreePath **end_path)
5193 gint start_index = -1;
5194 gint end_index = -1;
5197 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5199 if (icon_view->priv->hadjustment == NULL ||
5200 icon_view->priv->vadjustment == NULL)
5203 if (start_path == NULL && end_path == NULL)
5206 for (icons = icon_view->priv->items; icons; icons = icons->next)
5208 GtkIconViewItem *item = icons->data;
5210 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5211 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5212 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5213 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5215 if (start_index == -1)
5216 start_index = item->index;
5217 end_index = item->index;
5221 if (start_path && start_index != -1)
5222 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5223 if (end_path && end_index != -1)
5224 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5226 return start_index != -1;
5230 * gtk_icon_view_selected_foreach:
5231 * @icon_view: A #GtkIconView.
5232 * @func: The function to call for each selected icon.
5233 * @data: User data to pass to the function.
5235 * Calls a function for each selected icon. Note that the model or
5236 * selection cannot be modified from within this function.
5241 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5242 GtkIconViewForeachFunc func,
5247 for (list = icon_view->priv->items; list; list = list->next)
5249 GtkIconViewItem *item = list->data;
5250 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5253 (* func) (icon_view, path, data);
5255 gtk_tree_path_free (path);
5260 * gtk_icon_view_set_selection_mode:
5261 * @icon_view: A #GtkIconView.
5262 * @mode: The selection mode
5264 * Sets the selection mode of the @icon_view.
5269 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5270 GtkSelectionMode mode)
5272 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5274 if (mode == icon_view->priv->selection_mode)
5277 if (mode == GTK_SELECTION_NONE ||
5278 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5279 gtk_icon_view_unselect_all (icon_view);
5281 icon_view->priv->selection_mode = mode;
5283 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5287 * gtk_icon_view_get_selection_mode:
5288 * @icon_view: A #GtkIconView.
5290 * Gets the selection mode of the @icon_view.
5292 * Return value: the current selection mode
5297 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5299 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5301 return icon_view->priv->selection_mode;
5305 * gtk_icon_view_set_model:
5306 * @icon_view: A #GtkIconView.
5307 * @model: (allow-none): The model.
5309 * Sets the model for a #GtkIconView.
5310 * If the @icon_view already has a model set, it will remove
5311 * it before setting the new model. If @model is %NULL, then
5312 * it will unset the old model.
5317 gtk_icon_view_set_model (GtkIconView *icon_view,
5318 GtkTreeModel *model)
5320 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5321 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5323 if (icon_view->priv->model == model)
5326 if (icon_view->priv->scroll_to_path)
5328 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5329 icon_view->priv->scroll_to_path = NULL;
5332 gtk_icon_view_stop_editing (icon_view, TRUE);
5338 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5340 if (icon_view->priv->pixbuf_column != -1)
5342 column_type = gtk_tree_model_get_column_type (model,
5343 icon_view->priv->pixbuf_column);
5345 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5348 if (icon_view->priv->text_column != -1)
5350 column_type = gtk_tree_model_get_column_type (model,
5351 icon_view->priv->text_column);
5353 g_return_if_fail (column_type == G_TYPE_STRING);
5356 if (icon_view->priv->markup_column != -1)
5358 column_type = gtk_tree_model_get_column_type (model,
5359 icon_view->priv->markup_column);
5361 g_return_if_fail (column_type == G_TYPE_STRING);
5366 if (icon_view->priv->model)
5368 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5369 gtk_icon_view_row_changed,
5371 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5372 gtk_icon_view_row_inserted,
5374 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5375 gtk_icon_view_row_deleted,
5377 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5378 gtk_icon_view_rows_reordered,
5381 g_object_unref (icon_view->priv->model);
5383 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5384 g_list_free (icon_view->priv->items);
5385 icon_view->priv->items = NULL;
5386 icon_view->priv->anchor_item = NULL;
5387 icon_view->priv->cursor_item = NULL;
5388 icon_view->priv->last_single_clicked = NULL;
5389 icon_view->priv->width = 0;
5390 icon_view->priv->height = 0;
5393 icon_view->priv->model = model;
5395 if (icon_view->priv->model)
5397 g_object_ref (icon_view->priv->model);
5398 g_signal_connect (icon_view->priv->model,
5400 G_CALLBACK (gtk_icon_view_row_changed),
5402 g_signal_connect (icon_view->priv->model,
5404 G_CALLBACK (gtk_icon_view_row_inserted),
5406 g_signal_connect (icon_view->priv->model,
5408 G_CALLBACK (gtk_icon_view_row_deleted),
5410 g_signal_connect (icon_view->priv->model,
5412 G_CALLBACK (gtk_icon_view_rows_reordered),
5415 gtk_icon_view_build_items (icon_view);
5417 gtk_icon_view_queue_layout (icon_view);
5420 g_object_notify (G_OBJECT (icon_view), "model");
5422 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5423 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5427 * gtk_icon_view_get_model:
5428 * @icon_view: a #GtkIconView
5430 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5433 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5438 gtk_icon_view_get_model (GtkIconView *icon_view)
5440 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5442 return icon_view->priv->model;
5446 update_text_cell (GtkIconView *icon_view)
5448 GtkIconViewCellInfo *info;
5452 if (icon_view->priv->text_column == -1 &&
5453 icon_view->priv->markup_column == -1)
5455 if (icon_view->priv->text_cell != -1)
5457 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5458 icon_view->priv->pixbuf_cell--;
5460 info = g_list_nth_data (icon_view->priv->cell_list,
5461 icon_view->priv->text_cell);
5463 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5465 free_cell_info (info);
5467 icon_view->priv->n_cells--;
5468 icon_view->priv->text_cell = -1;
5473 if (icon_view->priv->text_cell == -1)
5475 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5476 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5477 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5480 if (info->cell == cell)
5482 icon_view->priv->text_cell = i;
5488 info = g_list_nth_data (icon_view->priv->cell_list,
5489 icon_view->priv->text_cell);
5491 if (icon_view->priv->markup_column != -1)
5492 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5494 "markup", icon_view->priv->markup_column,
5497 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5499 "text", icon_view->priv->text_column,
5502 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5503 g_object_set (info->cell,
5504 "alignment", PANGO_ALIGN_CENTER,
5505 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5510 g_object_set (info->cell,
5511 "alignment", PANGO_ALIGN_LEFT,
5512 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5520 update_pixbuf_cell (GtkIconView *icon_view)
5522 GtkIconViewCellInfo *info;
5526 if (icon_view->priv->pixbuf_column == -1)
5528 if (icon_view->priv->pixbuf_cell != -1)
5530 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5531 icon_view->priv->text_cell--;
5533 info = g_list_nth_data (icon_view->priv->cell_list,
5534 icon_view->priv->pixbuf_cell);
5536 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5538 free_cell_info (info);
5540 icon_view->priv->n_cells--;
5541 icon_view->priv->pixbuf_cell = -1;
5546 if (icon_view->priv->pixbuf_cell == -1)
5548 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5550 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5551 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5554 if (info->cell == cell)
5556 icon_view->priv->pixbuf_cell = i;
5562 info = g_list_nth_data (icon_view->priv->cell_list,
5563 icon_view->priv->pixbuf_cell);
5565 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5567 "pixbuf", icon_view->priv->pixbuf_column,
5570 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5571 g_object_set (info->cell,
5576 g_object_set (info->cell,
5584 * gtk_icon_view_set_text_column:
5585 * @icon_view: A #GtkIconView.
5586 * @column: A column in the currently used model, or -1 to display no text
5588 * Sets the column with text for @icon_view to be @column. The text
5589 * column must be of type #G_TYPE_STRING.
5594 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5597 if (column == icon_view->priv->text_column)
5601 icon_view->priv->text_column = -1;
5604 if (icon_view->priv->model != NULL)
5608 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5610 g_return_if_fail (column_type == G_TYPE_STRING);
5613 icon_view->priv->text_column = column;
5616 gtk_icon_view_stop_editing (icon_view, TRUE);
5618 update_text_cell (icon_view);
5620 gtk_icon_view_invalidate_sizes (icon_view);
5621 gtk_icon_view_queue_layout (icon_view);
5623 g_object_notify (G_OBJECT (icon_view), "text-column");
5627 * gtk_icon_view_get_text_column:
5628 * @icon_view: A #GtkIconView.
5630 * Returns the column with text for @icon_view.
5632 * Returns: the text column, or -1 if it's unset.
5637 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5639 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5641 return icon_view->priv->text_column;
5645 * gtk_icon_view_set_markup_column:
5646 * @icon_view: A #GtkIconView.
5647 * @column: A column in the currently used model, or -1 to display no text
5649 * Sets the column with markup information for @icon_view to be
5650 * @column. The markup column must be of type #G_TYPE_STRING.
5651 * If the markup column is set to something, it overrides
5652 * the text column set by gtk_icon_view_set_text_column().
5657 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5660 if (column == icon_view->priv->markup_column)
5664 icon_view->priv->markup_column = -1;
5667 if (icon_view->priv->model != NULL)
5671 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5673 g_return_if_fail (column_type == G_TYPE_STRING);
5676 icon_view->priv->markup_column = column;
5679 gtk_icon_view_stop_editing (icon_view, TRUE);
5681 update_text_cell (icon_view);
5683 gtk_icon_view_invalidate_sizes (icon_view);
5684 gtk_icon_view_queue_layout (icon_view);
5686 g_object_notify (G_OBJECT (icon_view), "markup-column");
5690 * gtk_icon_view_get_markup_column:
5691 * @icon_view: A #GtkIconView.
5693 * Returns the column with markup text for @icon_view.
5695 * Returns: the markup column, or -1 if it's unset.
5700 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5702 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5704 return icon_view->priv->markup_column;
5708 * gtk_icon_view_set_pixbuf_column:
5709 * @icon_view: A #GtkIconView.
5710 * @column: A column in the currently used model, or -1 to disable
5712 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5713 * column must be of type #GDK_TYPE_PIXBUF
5718 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5721 if (column == icon_view->priv->pixbuf_column)
5725 icon_view->priv->pixbuf_column = -1;
5728 if (icon_view->priv->model != NULL)
5732 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5734 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5737 icon_view->priv->pixbuf_column = column;
5740 gtk_icon_view_stop_editing (icon_view, TRUE);
5742 update_pixbuf_cell (icon_view);
5744 gtk_icon_view_invalidate_sizes (icon_view);
5745 gtk_icon_view_queue_layout (icon_view);
5747 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5752 * gtk_icon_view_get_pixbuf_column:
5753 * @icon_view: A #GtkIconView.
5755 * Returns the column with pixbufs for @icon_view.
5757 * Returns: the pixbuf column, or -1 if it's unset.
5762 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5764 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5766 return icon_view->priv->pixbuf_column;
5770 * gtk_icon_view_select_path:
5771 * @icon_view: A #GtkIconView.
5772 * @path: The #GtkTreePath to be selected.
5774 * Selects the row at @path.
5779 gtk_icon_view_select_path (GtkIconView *icon_view,
5782 GtkIconViewItem *item = NULL;
5784 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5785 g_return_if_fail (icon_view->priv->model != NULL);
5786 g_return_if_fail (path != NULL);
5788 if (gtk_tree_path_get_depth (path) > 0)
5789 item = g_list_nth_data (icon_view->priv->items,
5790 gtk_tree_path_get_indices(path)[0]);
5793 gtk_icon_view_select_item (icon_view, item);
5797 * gtk_icon_view_unselect_path:
5798 * @icon_view: A #GtkIconView.
5799 * @path: The #GtkTreePath to be unselected.
5801 * Unselects the row at @path.
5806 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5809 GtkIconViewItem *item;
5811 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5812 g_return_if_fail (icon_view->priv->model != NULL);
5813 g_return_if_fail (path != NULL);
5815 item = g_list_nth_data (icon_view->priv->items,
5816 gtk_tree_path_get_indices(path)[0]);
5821 gtk_icon_view_unselect_item (icon_view, item);
5825 * gtk_icon_view_get_selected_items:
5826 * @icon_view: A #GtkIconView.
5828 * Creates a list of paths of all selected items. Additionally, if you are
5829 * planning on modifying the model after calling this function, you may
5830 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5831 * To do this, you can use gtk_tree_row_reference_new().
5833 * To free the return value, use:
5835 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5836 * g_list_free (list);
5839 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5844 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5847 GList *selected = NULL;
5849 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5851 for (list = icon_view->priv->items; list != NULL; list = list->next)
5853 GtkIconViewItem *item = list->data;
5857 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5859 selected = g_list_prepend (selected, path);
5867 * gtk_icon_view_select_all:
5868 * @icon_view: A #GtkIconView.
5870 * Selects all the icons. @icon_view must has its selection mode set
5871 * to #GTK_SELECTION_MULTIPLE.
5876 gtk_icon_view_select_all (GtkIconView *icon_view)
5879 gboolean dirty = FALSE;
5881 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5883 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5886 for (items = icon_view->priv->items; items; items = items->next)
5888 GtkIconViewItem *item = items->data;
5890 if (!item->selected)
5893 item->selected = TRUE;
5894 gtk_icon_view_queue_draw_item (icon_view, item);
5899 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5903 * gtk_icon_view_unselect_all:
5904 * @icon_view: A #GtkIconView.
5906 * Unselects all the icons.
5911 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5913 gboolean dirty = FALSE;
5915 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5917 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5920 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5923 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5927 * gtk_icon_view_path_is_selected:
5928 * @icon_view: A #GtkIconView.
5929 * @path: A #GtkTreePath to check selection on.
5931 * Returns %TRUE if the icon pointed to by @path is currently
5932 * selected. If @path does not point to a valid location, %FALSE is returned.
5934 * Return value: %TRUE if @path is selected.
5939 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5942 GtkIconViewItem *item;
5944 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5945 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5946 g_return_val_if_fail (path != NULL, FALSE);
5948 item = g_list_nth_data (icon_view->priv->items,
5949 gtk_tree_path_get_indices(path)[0]);
5954 return item->selected;
5958 * gtk_icon_view_get_item_row:
5959 * @icon_view: a #GtkIconView
5960 * @path: the #GtkTreePath of the item
5962 * Gets the row in which the item @path is currently
5963 * displayed. Row numbers start at 0.
5965 * Returns: The row in which the item is displayed
5970 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5973 GtkIconViewItem *item;
5975 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5976 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5977 g_return_val_if_fail (path != NULL, FALSE);
5979 item = g_list_nth_data (icon_view->priv->items,
5980 gtk_tree_path_get_indices(path)[0]);
5989 * gtk_icon_view_get_item_column:
5990 * @icon_view: a #GtkIconView
5991 * @path: the #GtkTreePath of the item
5993 * Gets the column in which the item @path is currently
5994 * displayed. Column numbers start at 0.
5996 * Returns: The column in which the item is displayed
6001 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6004 GtkIconViewItem *item;
6006 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6007 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
6008 g_return_val_if_fail (path != NULL, FALSE);
6010 item = g_list_nth_data (icon_view->priv->items,
6011 gtk_tree_path_get_indices(path)[0]);
6020 * gtk_icon_view_item_activated:
6021 * @icon_view: A #GtkIconView
6022 * @path: The #GtkTreePath to be activated
6024 * Activates the item determined by @path.
6029 gtk_icon_view_item_activated (GtkIconView *icon_view,
6032 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6033 g_return_if_fail (path != NULL);
6035 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6039 * gtk_icon_view_set_orientation:
6040 * @icon_view: a #GtkIconView
6041 * @orientation: the relative position of texts and icons
6043 * Sets the ::orientation property which determines whether the labels
6044 * are drawn beside the icons instead of below.
6049 gtk_icon_view_set_orientation (GtkIconView *icon_view,
6050 GtkOrientation orientation)
6052 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6054 if (icon_view->priv->orientation != orientation)
6056 icon_view->priv->orientation = orientation;
6058 gtk_icon_view_stop_editing (icon_view, TRUE);
6059 gtk_icon_view_invalidate_sizes (icon_view);
6060 gtk_icon_view_queue_layout (icon_view);
6062 update_text_cell (icon_view);
6063 update_pixbuf_cell (icon_view);
6065 g_object_notify (G_OBJECT (icon_view), "orientation");
6070 * gtk_icon_view_get_orientation:
6071 * @icon_view: a #GtkIconView
6073 * Returns the value of the ::orientation property which determines
6074 * whether the labels are drawn beside the icons instead of below.
6076 * Return value: the relative position of texts and icons
6081 gtk_icon_view_get_orientation (GtkIconView *icon_view)
6083 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6084 GTK_ORIENTATION_VERTICAL);
6086 return icon_view->priv->orientation;
6090 * gtk_icon_view_set_columns:
6091 * @icon_view: a #GtkIconView
6092 * @columns: the number of columns
6094 * Sets the ::columns property which determines in how
6095 * many columns the icons are arranged. If @columns is
6096 * -1, the number of columns will be chosen automatically
6097 * to fill the available area.
6102 gtk_icon_view_set_columns (GtkIconView *icon_view,
6105 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6107 if (icon_view->priv->columns != columns)
6109 icon_view->priv->columns = columns;
6111 gtk_icon_view_stop_editing (icon_view, TRUE);
6112 gtk_icon_view_queue_layout (icon_view);
6114 g_object_notify (G_OBJECT (icon_view), "columns");
6119 * gtk_icon_view_get_columns:
6120 * @icon_view: a #GtkIconView
6122 * Returns the value of the ::columns property.
6124 * Return value: the number of columns, or -1
6129 gtk_icon_view_get_columns (GtkIconView *icon_view)
6131 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6133 return icon_view->priv->columns;
6137 * gtk_icon_view_set_item_width:
6138 * @icon_view: a #GtkIconView
6139 * @item_width: the width for each item
6141 * Sets the ::item-width property which specifies the width
6142 * to use for each item. If it is set to -1, the icon view will
6143 * automatically determine a suitable item size.
6148 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6151 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6153 if (icon_view->priv->item_width != item_width)
6155 icon_view->priv->item_width = item_width;
6157 gtk_icon_view_stop_editing (icon_view, TRUE);
6158 gtk_icon_view_invalidate_sizes (icon_view);
6159 gtk_icon_view_queue_layout (icon_view);
6161 update_text_cell (icon_view);
6163 g_object_notify (G_OBJECT (icon_view), "item-width");
6168 * gtk_icon_view_get_item_width:
6169 * @icon_view: a #GtkIconView
6171 * Returns the value of the ::item-width property.
6173 * Return value: the width of a single item, or -1
6178 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6180 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6182 return icon_view->priv->item_width;
6187 * gtk_icon_view_set_spacing:
6188 * @icon_view: a #GtkIconView
6189 * @spacing: the spacing
6191 * Sets the ::spacing property which specifies the space
6192 * which is inserted between the cells (i.e. the icon and
6193 * the text) of an item.
6198 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6201 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6203 if (icon_view->priv->spacing != spacing)
6205 icon_view->priv->spacing = spacing;
6207 gtk_icon_view_stop_editing (icon_view, TRUE);
6208 gtk_icon_view_invalidate_sizes (icon_view);
6209 gtk_icon_view_queue_layout (icon_view);
6211 g_object_notify (G_OBJECT (icon_view), "spacing");
6216 * gtk_icon_view_get_spacing:
6217 * @icon_view: a #GtkIconView
6219 * Returns the value of the ::spacing property.
6221 * Return value: the space between cells
6226 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6228 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6230 return icon_view->priv->spacing;
6234 * gtk_icon_view_set_row_spacing:
6235 * @icon_view: a #GtkIconView
6236 * @row_spacing: the row spacing
6238 * Sets the ::row-spacing property which specifies the space
6239 * which is inserted between the rows of the icon view.
6244 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6247 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6249 if (icon_view->priv->row_spacing != row_spacing)
6251 icon_view->priv->row_spacing = row_spacing;
6253 gtk_icon_view_stop_editing (icon_view, TRUE);
6254 gtk_icon_view_invalidate_sizes (icon_view);
6255 gtk_icon_view_queue_layout (icon_view);
6257 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6262 * gtk_icon_view_get_row_spacing:
6263 * @icon_view: a #GtkIconView
6265 * Returns the value of the ::row-spacing property.
6267 * Return value: the space between rows
6272 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6274 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6276 return icon_view->priv->row_spacing;
6280 * gtk_icon_view_set_column_spacing:
6281 * @icon_view: a #GtkIconView
6282 * @column_spacing: the column spacing
6284 * Sets the ::column-spacing property which specifies the space
6285 * which is inserted between the columns of the icon view.
6290 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6291 gint column_spacing)
6293 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6295 if (icon_view->priv->column_spacing != column_spacing)
6297 icon_view->priv->column_spacing = column_spacing;
6299 gtk_icon_view_stop_editing (icon_view, TRUE);
6300 gtk_icon_view_invalidate_sizes (icon_view);
6301 gtk_icon_view_queue_layout (icon_view);
6303 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6308 * gtk_icon_view_get_column_spacing:
6309 * @icon_view: a #GtkIconView
6311 * Returns the value of the ::column-spacing property.
6313 * Return value: the space between columns
6318 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6320 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6322 return icon_view->priv->column_spacing;
6326 * gtk_icon_view_set_margin:
6327 * @icon_view: a #GtkIconView
6328 * @margin: the margin
6330 * Sets the ::margin property which specifies the space
6331 * which is inserted at the top, bottom, left and right
6337 gtk_icon_view_set_margin (GtkIconView *icon_view,
6340 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6342 if (icon_view->priv->margin != margin)
6344 icon_view->priv->margin = margin;
6346 gtk_icon_view_stop_editing (icon_view, TRUE);
6347 gtk_icon_view_invalidate_sizes (icon_view);
6348 gtk_icon_view_queue_layout (icon_view);
6350 g_object_notify (G_OBJECT (icon_view), "margin");
6355 * gtk_icon_view_get_margin:
6356 * @icon_view: a #GtkIconView
6358 * Returns the value of the ::margin property.
6360 * Return value: the space at the borders
6365 gtk_icon_view_get_margin (GtkIconView *icon_view)
6367 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6369 return icon_view->priv->margin;
6373 * gtk_icon_view_set_item_padding:
6374 * @icon_view: a #GtkIconView
6375 * @item_padding: the item padding
6377 * Sets the #GtkIconView:item-padding property which specifies the padding
6378 * around each of the icon view's items.
6383 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6386 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6388 if (icon_view->priv->item_padding != item_padding)
6390 icon_view->priv->item_padding = item_padding;
6392 gtk_icon_view_stop_editing (icon_view, TRUE);
6393 gtk_icon_view_invalidate_sizes (icon_view);
6394 gtk_icon_view_queue_layout (icon_view);
6396 g_object_notify (G_OBJECT (icon_view), "item-padding");
6401 * gtk_icon_view_get_item_padding:
6402 * @icon_view: a #GtkIconView
6404 * Returns the value of the ::item-padding property.
6406 * Return value: the padding around items
6411 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6413 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6415 return icon_view->priv->item_padding;
6418 /* Get/set whether drag_motion requested the drag data and
6419 * drag_data_received should thus not actually insert the data,
6420 * since the data doesn't result from a drop.
6423 set_status_pending (GdkDragContext *context,
6424 GdkDragAction suggested_action)
6426 g_object_set_data (G_OBJECT (context),
6427 I_("gtk-icon-view-status-pending"),
6428 GINT_TO_POINTER (suggested_action));
6431 static GdkDragAction
6432 get_status_pending (GdkDragContext *context)
6434 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6435 "gtk-icon-view-status-pending"));
6439 unset_reorderable (GtkIconView *icon_view)
6441 if (icon_view->priv->reorderable)
6443 icon_view->priv->reorderable = FALSE;
6444 g_object_notify (G_OBJECT (icon_view), "reorderable");
6449 set_source_row (GdkDragContext *context,
6450 GtkTreeModel *model,
6451 GtkTreePath *source_row)
6454 g_object_set_data_full (G_OBJECT (context),
6455 I_("gtk-icon-view-source-row"),
6456 gtk_tree_row_reference_new (model, source_row),
6457 (GDestroyNotify) gtk_tree_row_reference_free);
6459 g_object_set_data_full (G_OBJECT (context),
6460 I_("gtk-icon-view-source-row"),
6465 get_source_row (GdkDragContext *context)
6467 GtkTreeRowReference *ref;
6469 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6472 return gtk_tree_row_reference_get_path (ref);
6479 GtkTreeRowReference *dest_row;
6480 gboolean empty_view_drop;
6481 gboolean drop_append_mode;
6485 dest_row_free (gpointer data)
6487 DestRow *dr = (DestRow *)data;
6489 gtk_tree_row_reference_free (dr->dest_row);
6494 set_dest_row (GdkDragContext *context,
6495 GtkTreeModel *model,
6496 GtkTreePath *dest_row,
6497 gboolean empty_view_drop,
6498 gboolean drop_append_mode)
6504 g_object_set_data_full (G_OBJECT (context),
6505 I_("gtk-icon-view-dest-row"),
6510 dr = g_new0 (DestRow, 1);
6512 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6513 dr->empty_view_drop = empty_view_drop;
6514 dr->drop_append_mode = drop_append_mode;
6515 g_object_set_data_full (G_OBJECT (context),
6516 I_("gtk-icon-view-dest-row"),
6517 dr, (GDestroyNotify) dest_row_free);
6521 get_dest_row (GdkDragContext *context)
6525 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6529 GtkTreePath *path = NULL;
6532 path = gtk_tree_row_reference_get_path (dr->dest_row);
6533 else if (dr->empty_view_drop)
6534 path = gtk_tree_path_new_from_indices (0, -1);
6538 if (path && dr->drop_append_mode)
6539 gtk_tree_path_next (path);
6548 check_model_dnd (GtkTreeModel *model,
6549 GType required_iface,
6550 const gchar *signal)
6552 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6554 g_warning ("You must override the default '%s' handler "
6555 "on GtkIconView when using models that don't support "
6556 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6557 "is to connect to '%s' and call "
6558 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6559 "the default handler from running. Look at the source code "
6560 "for the default handler in gtkiconview.c to get an idea what "
6561 "your handler should do. (gtkiconview.c is in the GTK+ source "
6562 "code.) If you're using GTK+ from a language other than C, "
6563 "there may be a more natural way to override default handlers, e.g. via derivation.",
6564 signal, g_type_name (required_iface), signal);
6572 remove_scroll_timeout (GtkIconView *icon_view)
6574 if (icon_view->priv->scroll_timeout_id != 0)
6576 g_source_remove (icon_view->priv->scroll_timeout_id);
6578 icon_view->priv->scroll_timeout_id = 0;
6583 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6585 gint px, py, x, y, width, height;
6586 gint hoffset, voffset;
6588 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6589 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6591 /* see if we are near the edge. */
6592 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6594 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6596 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6598 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6601 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6602 icon_view->priv->vadjustment->value + voffset);
6605 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6606 icon_view->priv->hadjustment->value + hoffset);
6611 drag_scroll_timeout (gpointer data)
6613 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6615 gtk_icon_view_autoscroll (icon_view);
6622 set_destination (GtkIconView *icon_view,
6623 GdkDragContext *context,
6626 GdkDragAction *suggested_action,
6630 GtkTreePath *path = NULL;
6631 GtkIconViewDropPosition pos;
6632 GtkIconViewDropPosition old_pos;
6633 GtkTreePath *old_dest_path = NULL;
6634 gboolean can_drop = FALSE;
6636 widget = GTK_WIDGET (icon_view);
6638 *suggested_action = 0;
6641 if (!icon_view->priv->dest_set)
6643 /* someone unset us as a drag dest, note that if
6644 * we return FALSE drag_leave isn't called
6647 gtk_icon_view_set_drag_dest_item (icon_view,
6649 GTK_ICON_VIEW_DROP_LEFT);
6651 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6653 return FALSE; /* no longer a drop site */
6656 *target = gtk_drag_dest_find_target (widget, context,
6657 gtk_drag_dest_get_target_list (widget));
6658 if (*target == GDK_NONE)
6661 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6664 GtkTreeModel *model;
6666 /* the row got dropped on empty space, let's setup a special case
6670 gtk_tree_path_free (path);
6672 model = gtk_icon_view_get_model (icon_view);
6674 n_children = gtk_tree_model_iter_n_children (model, NULL);
6677 pos = GTK_ICON_VIEW_DROP_BELOW;
6678 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6682 pos = GTK_ICON_VIEW_DROP_ABOVE;
6683 path = gtk_tree_path_new_from_indices (0, -1);
6693 gtk_icon_view_get_drag_dest_item (icon_view,
6698 gtk_tree_path_free (old_dest_path);
6700 if (TRUE /* FIXME if the location droppable predicate */)
6708 GtkWidget *source_widget;
6710 *suggested_action = context->suggested_action;
6711 source_widget = gtk_drag_get_source_widget (context);
6713 if (source_widget == widget)
6715 /* Default to MOVE, unless the user has
6716 * pressed ctrl or shift to affect available actions
6718 if ((context->actions & GDK_ACTION_MOVE) != 0)
6719 *suggested_action = GDK_ACTION_MOVE;
6722 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6727 /* can't drop here */
6728 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6730 GTK_ICON_VIEW_DROP_LEFT);
6734 gtk_tree_path_free (path);
6740 get_logical_destination (GtkIconView *icon_view,
6741 gboolean *drop_append_mode)
6743 /* adjust path to point to the row the drop goes in front of */
6744 GtkTreePath *path = NULL;
6745 GtkIconViewDropPosition pos;
6747 *drop_append_mode = FALSE;
6749 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6754 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6755 pos == GTK_ICON_VIEW_DROP_BELOW)
6758 GtkTreeModel *model = icon_view->priv->model;
6760 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6761 !gtk_tree_model_iter_next (model, &iter))
6762 *drop_append_mode = TRUE;
6765 *drop_append_mode = FALSE;
6766 gtk_tree_path_next (path);
6774 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6775 GdkEventMotion *event)
6777 GtkWidget *widget = GTK_WIDGET (icon_view);
6778 GdkDragContext *context;
6779 GtkTreePath *path = NULL;
6781 GtkTreeModel *model;
6782 gboolean retval = FALSE;
6784 if (!icon_view->priv->source_set)
6787 if (icon_view->priv->pressed_button < 0)
6790 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6791 icon_view->priv->press_start_x,
6792 icon_view->priv->press_start_y,
6793 event->x, event->y))
6796 model = gtk_icon_view_get_model (icon_view);
6801 button = icon_view->priv->pressed_button;
6802 icon_view->priv->pressed_button = -1;
6804 path = gtk_icon_view_get_path_at_pos (icon_view,
6805 icon_view->priv->press_start_x,
6806 icon_view->priv->press_start_y);
6811 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6812 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6816 /* FIXME Check whether we're a start button, if not return FALSE and
6820 /* Now we can begin the drag */
6824 context = gtk_drag_begin (widget,
6825 gtk_drag_source_get_target_list (widget),
6826 icon_view->priv->source_actions,
6830 set_source_row (context, model, path);
6834 gtk_tree_path_free (path);
6839 /* Source side drag signals */
6841 gtk_icon_view_drag_begin (GtkWidget *widget,
6842 GdkDragContext *context)
6844 GtkIconView *icon_view;
6845 GtkIconViewItem *item;
6850 icon_view = GTK_ICON_VIEW (widget);
6852 /* if the user uses a custom DnD impl, we don't set the icon here */
6853 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6856 item = gtk_icon_view_get_item_at_coords (icon_view,
6857 icon_view->priv->press_start_x,
6858 icon_view->priv->press_start_y,
6862 g_return_if_fail (item != NULL);
6864 x = icon_view->priv->press_start_x - item->x + 1;
6865 y = icon_view->priv->press_start_y - item->y + 1;
6867 path = gtk_tree_path_new_from_indices (item->index, -1);
6868 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6869 gtk_tree_path_free (path);
6871 gtk_drag_set_icon_pixmap (context,
6872 gdk_drawable_get_colormap (icon),
6877 g_object_unref (icon);
6881 gtk_icon_view_drag_end (GtkWidget *widget,
6882 GdkDragContext *context)
6888 gtk_icon_view_drag_data_get (GtkWidget *widget,
6889 GdkDragContext *context,
6890 GtkSelectionData *selection_data,
6894 GtkIconView *icon_view;
6895 GtkTreeModel *model;
6896 GtkTreePath *source_row;
6898 icon_view = GTK_ICON_VIEW (widget);
6899 model = gtk_icon_view_get_model (icon_view);
6904 if (!icon_view->priv->source_set)
6907 source_row = get_source_row (context);
6909 if (source_row == NULL)
6912 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6913 * any model; for DragSource models there are some other targets
6917 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6918 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6923 /* If drag_data_get does nothing, try providing row data. */
6924 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6925 gtk_tree_set_row_drag_data (selection_data,
6930 gtk_tree_path_free (source_row);
6934 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6935 GdkDragContext *context)
6937 GtkTreeModel *model;
6938 GtkIconView *icon_view;
6939 GtkTreePath *source_row;
6941 icon_view = GTK_ICON_VIEW (widget);
6942 model = gtk_icon_view_get_model (icon_view);
6944 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6947 if (!icon_view->priv->source_set)
6950 source_row = get_source_row (context);
6952 if (source_row == NULL)
6955 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6958 gtk_tree_path_free (source_row);
6960 set_source_row (context, NULL, NULL);
6963 /* Target side drag signals */
6965 gtk_icon_view_drag_leave (GtkWidget *widget,
6966 GdkDragContext *context,
6969 GtkIconView *icon_view;
6971 icon_view = GTK_ICON_VIEW (widget);
6973 /* unset any highlight row */
6974 gtk_icon_view_set_drag_dest_item (icon_view,
6976 GTK_ICON_VIEW_DROP_LEFT);
6978 remove_scroll_timeout (icon_view);
6982 gtk_icon_view_drag_motion (GtkWidget *widget,
6983 GdkDragContext *context,
6988 GtkTreePath *path = NULL;
6989 GtkIconViewDropPosition pos;
6990 GtkIconView *icon_view;
6991 GdkDragAction suggested_action = 0;
6995 icon_view = GTK_ICON_VIEW (widget);
6997 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7000 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7002 /* we only know this *after* set_desination_row */
7003 empty = icon_view->priv->empty_view_drop;
7005 if (path == NULL && !empty)
7007 /* Can't drop here. */
7008 gdk_drag_status (context, 0, time);
7012 if (icon_view->priv->scroll_timeout_id == 0)
7014 icon_view->priv->scroll_timeout_id =
7015 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7018 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7020 /* Request data so we can use the source row when
7021 * determining whether to accept the drop
7023 set_status_pending (context, suggested_action);
7024 gtk_drag_get_data (widget, context, target, time);
7028 set_status_pending (context, 0);
7029 gdk_drag_status (context, suggested_action, time);
7034 gtk_tree_path_free (path);
7040 gtk_icon_view_drag_drop (GtkWidget *widget,
7041 GdkDragContext *context,
7046 GtkIconView *icon_view;
7048 GdkDragAction suggested_action = 0;
7049 GdkAtom target = GDK_NONE;
7050 GtkTreeModel *model;
7051 gboolean drop_append_mode;
7053 icon_view = GTK_ICON_VIEW (widget);
7054 model = gtk_icon_view_get_model (icon_view);
7056 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7058 if (!icon_view->priv->dest_set)
7061 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7064 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7067 path = get_logical_destination (icon_view, &drop_append_mode);
7069 if (target != GDK_NONE && path != NULL)
7071 /* in case a motion had requested drag data, change things so we
7072 * treat drag data receives as a drop.
7074 set_status_pending (context, 0);
7075 set_dest_row (context, model, path,
7076 icon_view->priv->empty_view_drop, drop_append_mode);
7080 gtk_tree_path_free (path);
7082 /* Unset this thing */
7083 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7085 if (target != GDK_NONE)
7087 gtk_drag_get_data (widget, context, target, time);
7095 gtk_icon_view_drag_data_received (GtkWidget *widget,
7096 GdkDragContext *context,
7099 GtkSelectionData *selection_data,
7104 gboolean accepted = FALSE;
7105 GtkTreeModel *model;
7106 GtkIconView *icon_view;
7107 GtkTreePath *dest_row;
7108 GdkDragAction suggested_action;
7109 gboolean drop_append_mode;
7111 icon_view = GTK_ICON_VIEW (widget);
7112 model = gtk_icon_view_get_model (icon_view);
7114 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7117 if (!icon_view->priv->dest_set)
7120 suggested_action = get_status_pending (context);
7122 if (suggested_action)
7124 /* We are getting this data due to a request in drag_motion,
7125 * rather than due to a request in drag_drop, so we are just
7126 * supposed to call drag_status, not actually paste in the
7129 path = get_logical_destination (icon_view, &drop_append_mode);
7132 suggested_action = 0;
7134 if (suggested_action)
7136 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7139 suggested_action = 0;
7142 gdk_drag_status (context, suggested_action, time);
7145 gtk_tree_path_free (path);
7147 /* If you can't drop, remove user drop indicator until the next motion */
7148 if (suggested_action == 0)
7149 gtk_icon_view_set_drag_dest_item (icon_view,
7151 GTK_ICON_VIEW_DROP_LEFT);
7156 dest_row = get_dest_row (context);
7158 if (dest_row == NULL)
7161 if (selection_data->length >= 0)
7163 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7169 gtk_drag_finish (context,
7171 (context->action == GDK_ACTION_MOVE),
7174 gtk_tree_path_free (dest_row);
7177 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7180 /* Drag-and-Drop support */
7182 * gtk_icon_view_enable_model_drag_source:
7183 * @icon_view: a #GtkIconTreeView
7184 * @start_button_mask: Mask of allowed buttons to start drag
7185 * @targets: the table of targets that the drag will support
7186 * @n_targets: the number of items in @targets
7187 * @actions: the bitmask of possible actions for a drag from this
7190 * Turns @icon_view into a drag source for automatic DND. Calling this
7191 * method sets #GtkIconView:reorderable to %FALSE.
7196 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7197 GdkModifierType start_button_mask,
7198 const GtkTargetEntry *targets,
7200 GdkDragAction actions)
7202 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7204 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7206 icon_view->priv->start_button_mask = start_button_mask;
7207 icon_view->priv->source_actions = actions;
7209 icon_view->priv->source_set = TRUE;
7211 unset_reorderable (icon_view);
7215 * gtk_icon_view_enable_model_drag_dest:
7216 * @icon_view: a #GtkIconView
7217 * @targets: the table of targets that the drag will support
7218 * @n_targets: the number of items in @targets
7219 * @actions: the bitmask of possible actions for a drag to this
7222 * Turns @icon_view into a drop destination for automatic DND. Calling this
7223 * method sets #GtkIconView:reorderable to %FALSE.
7228 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7229 const GtkTargetEntry *targets,
7231 GdkDragAction actions)
7233 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7235 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7237 icon_view->priv->dest_actions = actions;
7239 icon_view->priv->dest_set = TRUE;
7241 unset_reorderable (icon_view);
7245 * gtk_icon_view_unset_model_drag_source:
7246 * @icon_view: a #GtkIconView
7248 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7249 * method sets #GtkIconView:reorderable to %FALSE.
7254 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7256 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7258 if (icon_view->priv->source_set)
7260 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7261 icon_view->priv->source_set = FALSE;
7264 unset_reorderable (icon_view);
7268 * gtk_icon_view_unset_model_drag_dest:
7269 * @icon_view: a #GtkIconView
7271 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7272 * method sets #GtkIconView:reorderable to %FALSE.
7277 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7279 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7281 if (icon_view->priv->dest_set)
7283 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7284 icon_view->priv->dest_set = FALSE;
7287 unset_reorderable (icon_view);
7290 /* These are useful to implement your own custom stuff. */
7292 * gtk_icon_view_set_drag_dest_item:
7293 * @icon_view: a #GtkIconView
7294 * @path: (allow-none): The path of the item to highlight, or %NULL.
7295 * @pos: Specifies where to drop, relative to the item
7297 * Sets the item that is highlighted for feedback.
7302 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7304 GtkIconViewDropPosition pos)
7306 /* Note; this function is exported to allow a custom DND
7307 * implementation, so it can't touch TreeViewDragInfo
7310 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7312 if (icon_view->priv->dest_item)
7314 GtkTreePath *current_path;
7315 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7316 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7317 icon_view->priv->dest_item = NULL;
7319 gtk_icon_view_queue_draw_path (icon_view, current_path);
7320 gtk_tree_path_free (current_path);
7323 /* special case a drop on an empty model */
7324 icon_view->priv->empty_view_drop = FALSE;
7325 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7326 && gtk_tree_path_get_depth (path) == 1
7327 && gtk_tree_path_get_indices (path)[0] == 0)
7331 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7334 if (n_children == 0)
7335 icon_view->priv->empty_view_drop = TRUE;
7338 icon_view->priv->dest_pos = pos;
7342 icon_view->priv->dest_item =
7343 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7344 icon_view->priv->model, path);
7346 gtk_icon_view_queue_draw_path (icon_view, path);
7351 * gtk_icon_view_get_drag_dest_item:
7352 * @icon_view: a #GtkIconView
7353 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7354 * @pos: (allow-none): Return location for the drop position, or %NULL
7356 * Gets information about the item that is highlighted for feedback.
7361 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7363 GtkIconViewDropPosition *pos)
7365 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7369 if (icon_view->priv->dest_item)
7370 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7376 *pos = icon_view->priv->dest_pos;
7380 * gtk_icon_view_get_dest_item_at_pos:
7381 * @icon_view: a #GtkIconView
7382 * @drag_x: the position to determine the destination item for
7383 * @drag_y: the position to determine the destination item for
7384 * @path: (allow-none): Return location for the path of the item, or %NULL.
7385 * @pos: (allow-none): Return location for the drop position, or %NULL
7387 * Determines the destination item for a given position.
7389 * Return value: whether there is an item at the given position.
7394 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7398 GtkIconViewDropPosition *pos)
7400 GtkIconViewItem *item;
7402 /* Note; this function is exported to allow a custom DND
7403 * implementation, so it can't touch TreeViewDragInfo
7406 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7407 g_return_val_if_fail (drag_x >= 0, FALSE);
7408 g_return_val_if_fail (drag_y >= 0, FALSE);
7409 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7415 item = gtk_icon_view_get_item_at_coords (icon_view,
7416 drag_x + icon_view->priv->hadjustment->value,
7417 drag_y + icon_view->priv->vadjustment->value,
7424 *path = gtk_tree_path_new_from_indices (item->index, -1);
7428 if (drag_x < item->x + item->width / 4)
7429 *pos = GTK_ICON_VIEW_DROP_LEFT;
7430 else if (drag_x > item->x + item->width * 3 / 4)
7431 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7432 else if (drag_y < item->y + item->height / 4)
7433 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7434 else if (drag_y > item->y + item->height * 3 / 4)
7435 *pos = GTK_ICON_VIEW_DROP_BELOW;
7437 *pos = GTK_ICON_VIEW_DROP_INTO;
7444 * gtk_icon_view_create_drag_icon:
7445 * @icon_view: a #GtkIconView
7446 * @path: a #GtkTreePath in @icon_view
7448 * Creates a #GdkPixmap representation of the item at @path.
7449 * This image is used for a drag icon.
7451 * Return value: a newly-allocated pixmap of the drag icon.
7456 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7461 GdkPixmap *drawable;
7466 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7467 g_return_val_if_fail (path != NULL, NULL);
7469 widget = GTK_WIDGET (icon_view);
7471 if (!gtk_widget_get_realized (widget))
7474 index = gtk_tree_path_get_indices (path)[0];
7476 for (l = icon_view->priv->items; l; l = l->next)
7478 GtkIconViewItem *item = l->data;
7480 if (index == item->index)
7482 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7487 cr = gdk_cairo_create (drawable);
7488 cairo_set_line_width (cr, 1.);
7490 gdk_cairo_set_source_color
7491 (cr, &widget->style->base[gtk_widget_get_state (widget)]);
7492 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7497 area.width = item->width;
7498 area.height = item->height;
7500 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7501 drawable, 1, 1, FALSE);
7503 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7504 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7517 * gtk_icon_view_get_reorderable:
7518 * @icon_view: a #GtkIconView
7520 * Retrieves whether the user can reorder the list via drag-and-drop.
7521 * See gtk_icon_view_set_reorderable().
7523 * Return value: %TRUE if the list can be reordered.
7528 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7530 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7532 return icon_view->priv->reorderable;
7535 static const GtkTargetEntry item_targets[] = {
7536 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7541 * gtk_icon_view_set_reorderable:
7542 * @icon_view: A #GtkIconView.
7543 * @reorderable: %TRUE, if the list of items can be reordered.
7545 * This function is a convenience function to allow you to reorder models that
7546 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7547 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7548 * the user can reorder the model by dragging and dropping rows. The
7549 * developer can listen to these changes by connecting to the model's
7550 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7551 * the icon view as a drag source and destination. Therefore, drag and
7552 * drop can not be used in a reorderable view for any other purpose.
7554 * This function does not give you any degree of control over the order -- any
7555 * reordering is allowed. If more control is needed, you should probably
7556 * handle drag and drop manually.
7561 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7562 gboolean reorderable)
7564 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7566 reorderable = reorderable != FALSE;
7568 if (icon_view->priv->reorderable == reorderable)
7573 gtk_icon_view_enable_model_drag_source (icon_view,
7576 G_N_ELEMENTS (item_targets),
7578 gtk_icon_view_enable_model_drag_dest (icon_view,
7580 G_N_ELEMENTS (item_targets),
7585 gtk_icon_view_unset_model_drag_source (icon_view);
7586 gtk_icon_view_unset_model_drag_dest (icon_view);
7589 icon_view->priv->reorderable = reorderable;
7591 g_object_notify (G_OBJECT (icon_view), "reorderable");
7595 /* Accessibility Support */
7597 static gpointer accessible_parent_class;
7598 static gpointer accessible_item_parent_class;
7599 static GQuark accessible_private_data_quark = 0;
7601 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7602 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7603 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7605 static GType gtk_icon_view_item_accessible_get_type (void);
7616 GtkIconViewItem *item;
7620 AtkStateSet *state_set;
7624 GtkTextBuffer *text_buffer;
7626 gchar *action_descriptions[LAST_ACTION];
7627 gchar *image_description;
7628 guint action_idle_handler;
7629 } GtkIconViewItemAccessible;
7631 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7637 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7642 typedef struct _GtkIconViewItemAccessibleClass
7644 AtkObjectClass parent_class;
7646 } GtkIconViewItemAccessibleClass;
7648 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7651 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7653 GtkIconViewItemAccessible *item;
7654 GtkIconView *icon_view;
7657 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7658 item->action_idle_handler = 0;
7660 if (item->widget != NULL)
7662 icon_view = GTK_ICON_VIEW (item->widget);
7663 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7664 gtk_icon_view_item_activated (icon_view, path);
7665 gtk_tree_path_free (path);
7672 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7675 GtkIconViewItemAccessible *item;
7677 if (i < 0 || i >= LAST_ACTION)
7680 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7682 if (!GTK_IS_ICON_VIEW (item->widget))
7685 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7690 case ACTION_ACTIVATE:
7691 if (!item->action_idle_handler)
7692 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7695 g_assert_not_reached ();
7703 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7708 static const gchar *
7709 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7712 GtkIconViewItemAccessible *item;
7714 if (i < 0 || i >= LAST_ACTION)
7717 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7719 if (item->action_descriptions[i])
7720 return item->action_descriptions[i];
7722 return gtk_icon_view_item_accessible_action_descriptions[i];
7725 static const gchar *
7726 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7729 if (i < 0 || i >= LAST_ACTION)
7732 return gtk_icon_view_item_accessible_action_names[i];
7736 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7738 const gchar *description)
7740 GtkIconViewItemAccessible *item;
7742 if (i < 0 || i >= LAST_ACTION)
7745 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7747 g_free (item->action_descriptions[i]);
7749 item->action_descriptions[i] = g_strdup (description);
7755 atk_action_item_interface_init (AtkActionIface *iface)
7757 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7758 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7759 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7760 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7761 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7764 static const gchar *
7765 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7767 GtkIconViewItemAccessible *item;
7769 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7771 return item->image_description;
7775 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7776 const gchar *description)
7778 GtkIconViewItemAccessible *item;
7780 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7782 g_free (item->image_description);
7783 item->image_description = g_strdup (description);
7789 get_pixbuf_box (GtkIconView *icon_view,
7790 GtkIconViewItem *item,
7795 for (l = icon_view->priv->cell_list; l; l = l->next)
7797 GtkIconViewCellInfo *info = l->data;
7799 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7801 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7811 get_text (GtkIconView *icon_view,
7812 GtkIconViewItem *item)
7817 for (l = icon_view->priv->cell_list; l; l = l->next)
7819 GtkIconViewCellInfo *info = l->data;
7821 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7823 g_object_get (info->cell, "text", &text, NULL);
7833 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7837 GtkIconViewItemAccessible *item;
7840 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7842 if (!GTK_IS_ICON_VIEW (item->widget))
7845 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7848 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7851 *height = box.height;
7856 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7859 AtkCoordType coord_type)
7861 GtkIconViewItemAccessible *item;
7864 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7866 if (!GTK_IS_ICON_VIEW (item->widget))
7869 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7872 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7874 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7876 *x+= box.x - item->item->x;
7877 *y+= box.y - item->item->y;
7883 atk_image_item_interface_init (AtkImageIface *iface)
7885 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7886 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7887 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7888 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7892 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7896 GtkIconViewItemAccessible *item;
7897 GtkTextIter start, end;
7898 GtkTextBuffer *buffer;
7900 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7902 if (!GTK_IS_ICON_VIEW (item->widget))
7905 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7908 buffer = item->text_buffer;
7909 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7911 gtk_text_buffer_get_end_iter (buffer, &end);
7913 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7915 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7919 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7922 GtkIconViewItemAccessible *item;
7923 GtkTextIter start, end;
7924 GtkTextBuffer *buffer;
7928 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7930 if (!GTK_IS_ICON_VIEW (item->widget))
7933 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7936 buffer = item->text_buffer;
7937 if (offset >= gtk_text_buffer_get_char_count (buffer))
7940 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7942 gtk_text_iter_forward_char (&end);
7943 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7944 unichar = g_utf8_get_char (string);
7952 get_pango_text_offsets (PangoLayout *layout,
7953 GtkTextBuffer *buffer,
7955 AtkTextBoundary boundary_type,
7959 GtkTextIter *start_iter,
7960 GtkTextIter *end_iter)
7962 PangoLayoutIter *iter;
7963 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7964 gint index, start_index, end_index;
7966 gboolean found = FALSE;
7968 text = pango_layout_get_text (layout);
7969 index = g_utf8_offset_to_pointer (text, offset) - text;
7970 iter = pango_layout_get_iter (layout);
7973 line = pango_layout_iter_get_line_readonly (iter);
7974 start_index = line->start_index;
7975 end_index = start_index + line->length;
7977 if (index >= start_index && index <= end_index)
7980 * Found line for offset
7986 * We want the previous line
7990 switch (boundary_type)
7992 case ATK_TEXT_BOUNDARY_LINE_START:
7993 end_index = start_index;
7994 start_index = prev_line->start_index;
7996 case ATK_TEXT_BOUNDARY_LINE_END:
7998 start_index = prev_prev_line->start_index +
7999 prev_prev_line->length;
8000 end_index = prev_line->start_index + prev_line->length;
8003 g_assert_not_reached();
8007 start_index = end_index = 0;
8010 switch (boundary_type)
8012 case ATK_TEXT_BOUNDARY_LINE_START:
8013 if (pango_layout_iter_next_line (iter))
8014 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8016 case ATK_TEXT_BOUNDARY_LINE_END:
8018 start_index = prev_line->start_index +
8022 g_assert_not_reached();
8027 * We want the next line
8029 if (pango_layout_iter_next_line (iter))
8031 line = pango_layout_iter_get_line_readonly (iter);
8032 switch (boundary_type)
8034 case ATK_TEXT_BOUNDARY_LINE_START:
8035 start_index = line->start_index;
8036 if (pango_layout_iter_next_line (iter))
8037 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8039 end_index = start_index + line->length;
8041 case ATK_TEXT_BOUNDARY_LINE_END:
8042 start_index = end_index;
8043 end_index = line->start_index + line->length;
8046 g_assert_not_reached();
8050 start_index = end_index;
8056 prev_prev_line = prev_line;
8059 while (pango_layout_iter_next_line (iter));
8063 start_index = prev_line->start_index + prev_line->length;
8064 end_index = start_index;
8066 pango_layout_iter_free (iter);
8067 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8068 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8070 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8071 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8076 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8078 AtkTextBoundary boundary_type,
8082 GtkIconViewItemAccessible *item;
8083 GtkTextIter start, end;
8084 GtkTextBuffer *buffer;
8086 GtkIconView *icon_view;
8089 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8091 if (!GTK_IS_ICON_VIEW (item->widget))
8094 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8097 buffer = item->text_buffer;
8099 if (!gtk_text_buffer_get_char_count (buffer))
8103 return g_strdup ("");
8105 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8109 switch (boundary_type)
8111 case ATK_TEXT_BOUNDARY_CHAR:
8112 gtk_text_iter_backward_char(&start);
8114 case ATK_TEXT_BOUNDARY_WORD_START:
8115 if (!gtk_text_iter_starts_word (&start))
8116 gtk_text_iter_backward_word_start (&start);
8118 gtk_text_iter_backward_word_start(&start);
8120 case ATK_TEXT_BOUNDARY_WORD_END:
8121 if (gtk_text_iter_inside_word (&start) &&
8122 !gtk_text_iter_starts_word (&start))
8123 gtk_text_iter_backward_word_start (&start);
8124 while (!gtk_text_iter_ends_word (&start))
8126 if (!gtk_text_iter_backward_char (&start))
8130 gtk_text_iter_backward_word_start(&start);
8131 while (!gtk_text_iter_ends_word (&start))
8133 if (!gtk_text_iter_backward_char (&start))
8137 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8138 if (!gtk_text_iter_starts_sentence (&start))
8139 gtk_text_iter_backward_sentence_start (&start);
8141 gtk_text_iter_backward_sentence_start (&start);
8143 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8144 if (gtk_text_iter_inside_sentence (&start) &&
8145 !gtk_text_iter_starts_sentence (&start))
8146 gtk_text_iter_backward_sentence_start (&start);
8147 while (!gtk_text_iter_ends_sentence (&start))
8149 if (!gtk_text_iter_backward_char (&start))
8153 gtk_text_iter_backward_sentence_start (&start);
8154 while (!gtk_text_iter_ends_sentence (&start))
8156 if (!gtk_text_iter_backward_char (&start))
8160 case ATK_TEXT_BOUNDARY_LINE_START:
8161 case ATK_TEXT_BOUNDARY_LINE_END:
8163 icon_view = GTK_ICON_VIEW (item->widget);
8164 /* FIXME we probably have to use GailTextCell to salvage this */
8165 gtk_icon_view_update_item_text (icon_view, item->item);
8166 get_pango_text_offsets (icon_view->priv->layout,
8179 *start_offset = gtk_text_iter_get_offset (&start);
8180 *end_offset = gtk_text_iter_get_offset (&end);
8182 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8186 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8188 AtkTextBoundary boundary_type,
8192 GtkIconViewItemAccessible *item;
8193 GtkTextIter start, end;
8194 GtkTextBuffer *buffer;
8196 GtkIconView *icon_view;
8199 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8201 if (!GTK_IS_ICON_VIEW (item->widget))
8204 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8207 buffer = item->text_buffer;
8209 if (!gtk_text_buffer_get_char_count (buffer))
8213 return g_strdup ("");
8215 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8219 switch (boundary_type)
8221 case ATK_TEXT_BOUNDARY_CHAR:
8222 gtk_text_iter_forward_char (&end);
8224 case ATK_TEXT_BOUNDARY_WORD_START:
8225 if (!gtk_text_iter_starts_word (&start))
8226 gtk_text_iter_backward_word_start (&start);
8227 if (gtk_text_iter_inside_word (&end))
8228 gtk_text_iter_forward_word_end (&end);
8229 while (!gtk_text_iter_starts_word (&end))
8231 if (!gtk_text_iter_forward_char (&end))
8235 case ATK_TEXT_BOUNDARY_WORD_END:
8236 if (gtk_text_iter_inside_word (&start) &&
8237 !gtk_text_iter_starts_word (&start))
8238 gtk_text_iter_backward_word_start (&start);
8239 while (!gtk_text_iter_ends_word (&start))
8241 if (!gtk_text_iter_backward_char (&start))
8244 gtk_text_iter_forward_word_end (&end);
8246 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8247 if (!gtk_text_iter_starts_sentence (&start))
8248 gtk_text_iter_backward_sentence_start (&start);
8249 if (gtk_text_iter_inside_sentence (&end))
8250 gtk_text_iter_forward_sentence_end (&end);
8251 while (!gtk_text_iter_starts_sentence (&end))
8253 if (!gtk_text_iter_forward_char (&end))
8257 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8258 if (gtk_text_iter_inside_sentence (&start) &&
8259 !gtk_text_iter_starts_sentence (&start))
8260 gtk_text_iter_backward_sentence_start (&start);
8261 while (!gtk_text_iter_ends_sentence (&start))
8263 if (!gtk_text_iter_backward_char (&start))
8266 gtk_text_iter_forward_sentence_end (&end);
8268 case ATK_TEXT_BOUNDARY_LINE_START:
8269 case ATK_TEXT_BOUNDARY_LINE_END:
8271 icon_view = GTK_ICON_VIEW (item->widget);
8272 /* FIXME we probably have to use GailTextCell to salvage this */
8273 gtk_icon_view_update_item_text (icon_view, item->item);
8274 get_pango_text_offsets (icon_view->priv->layout,
8288 *start_offset = gtk_text_iter_get_offset (&start);
8289 *end_offset = gtk_text_iter_get_offset (&end);
8291 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8295 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8297 AtkTextBoundary boundary_type,
8301 GtkIconViewItemAccessible *item;
8302 GtkTextIter start, end;
8303 GtkTextBuffer *buffer;
8305 GtkIconView *icon_view;
8308 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8310 if (!GTK_IS_ICON_VIEW (item->widget))
8313 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8316 buffer = item->text_buffer;
8318 if (!gtk_text_buffer_get_char_count (buffer))
8322 return g_strdup ("");
8324 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8328 switch (boundary_type)
8330 case ATK_TEXT_BOUNDARY_CHAR:
8331 gtk_text_iter_forward_char(&start);
8332 gtk_text_iter_forward_chars(&end, 2);
8334 case ATK_TEXT_BOUNDARY_WORD_START:
8335 if (gtk_text_iter_inside_word (&end))
8336 gtk_text_iter_forward_word_end (&end);
8337 while (!gtk_text_iter_starts_word (&end))
8339 if (!gtk_text_iter_forward_char (&end))
8343 if (!gtk_text_iter_is_end (&end))
8345 gtk_text_iter_forward_word_end (&end);
8346 while (!gtk_text_iter_starts_word (&end))
8348 if (!gtk_text_iter_forward_char (&end))
8353 case ATK_TEXT_BOUNDARY_WORD_END:
8354 gtk_text_iter_forward_word_end (&end);
8356 if (!gtk_text_iter_is_end (&end))
8357 gtk_text_iter_forward_word_end (&end);
8359 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8360 if (gtk_text_iter_inside_sentence (&end))
8361 gtk_text_iter_forward_sentence_end (&end);
8362 while (!gtk_text_iter_starts_sentence (&end))
8364 if (!gtk_text_iter_forward_char (&end))
8368 if (!gtk_text_iter_is_end (&end))
8370 gtk_text_iter_forward_sentence_end (&end);
8371 while (!gtk_text_iter_starts_sentence (&end))
8373 if (!gtk_text_iter_forward_char (&end))
8378 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8379 gtk_text_iter_forward_sentence_end (&end);
8381 if (!gtk_text_iter_is_end (&end))
8382 gtk_text_iter_forward_sentence_end (&end);
8384 case ATK_TEXT_BOUNDARY_LINE_START:
8385 case ATK_TEXT_BOUNDARY_LINE_END:
8387 icon_view = GTK_ICON_VIEW (item->widget);
8388 /* FIXME we probably have to use GailTextCell to salvage this */
8389 gtk_icon_view_update_item_text (icon_view, item->item);
8390 get_pango_text_offsets (icon_view->priv->layout,
8402 *start_offset = gtk_text_iter_get_offset (&start);
8403 *end_offset = gtk_text_iter_get_offset (&end);
8405 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8409 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8411 GtkIconViewItemAccessible *item;
8413 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8415 if (!GTK_IS_ICON_VIEW (item->widget))
8418 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8421 return gtk_text_buffer_get_char_count (item->text_buffer);
8425 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8431 AtkCoordType coord_type)
8433 GtkIconViewItemAccessible *item;
8435 GtkIconView *icon_view;
8436 PangoRectangle char_rect;
8437 const gchar *item_text;
8441 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8443 if (!GTK_IS_ICON_VIEW (item->widget))
8446 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8450 icon_view = GTK_ICON_VIEW (item->widget);
8451 /* FIXME we probably have to use GailTextCell to salvage this */
8452 gtk_icon_view_update_item_text (icon_view, item->item);
8453 item_text = pango_layout_get_text (icon_view->priv->layout);
8454 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8455 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8457 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8458 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8459 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8460 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8461 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8462 *width = char_rect.width / PANGO_SCALE;
8463 *height = char_rect.height / PANGO_SCALE;
8468 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8471 AtkCoordType coord_type)
8473 GtkIconViewItemAccessible *item;
8476 GtkIconView *icon_view;
8477 const gchar *item_text;
8482 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8484 if (!GTK_IS_ICON_VIEW (item->widget))
8487 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8491 icon_view = GTK_ICON_VIEW (item->widget);
8492 /* FIXME we probably have to use GailTextCell to salvage this */
8493 gtk_icon_view_update_item_text (icon_view, item->item);
8494 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8495 x -= l_x + item->item->layout_x - item->item->x;
8496 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8497 y -= l_y + item->item->layout_y - item->item->y;
8498 item_text = pango_layout_get_text (icon_view->priv->layout);
8499 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8510 offset = g_utf8_strlen (item_text, -1);
8512 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8518 atk_text_item_interface_init (AtkTextIface *iface)
8520 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8521 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8522 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8523 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8524 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8525 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8526 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8527 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8531 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8536 AtkCoordType coord_type)
8538 GtkIconViewItemAccessible *item;
8539 AtkObject *parent_obj;
8542 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8544 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8545 if (!GTK_IS_WIDGET (item->widget))
8548 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8551 *width = item->item->width;
8552 *height = item->item->height;
8553 if (gtk_icon_view_item_accessible_is_showing (item))
8555 parent_obj = gtk_widget_get_accessible (item->widget);
8556 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8557 *x = l_x + item->item->x;
8558 *y = l_y + item->item->y;
8568 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8570 GtkIconViewItemAccessible *item;
8571 GtkWidget *toplevel;
8573 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8575 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8576 if (!GTK_IS_WIDGET (item->widget))
8579 gtk_widget_grab_focus (item->widget);
8580 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8581 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8582 if (gtk_widget_is_toplevel (toplevel))
8583 gtk_window_present (GTK_WINDOW (toplevel));
8589 atk_component_item_interface_init (AtkComponentIface *iface)
8591 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8592 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8596 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8597 AtkStateType state_type,
8598 gboolean emit_signal)
8602 rc = atk_state_set_add_state (item->state_set, state_type);
8604 * The signal should only be generated if the value changed,
8605 * not when the item is set up. So states that are set
8606 * initially should pass FALSE as the emit_signal argument.
8611 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8612 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8613 if (state_type == ATK_STATE_VISIBLE)
8614 g_signal_emit_by_name (item, "visible-data-changed");
8621 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8622 AtkStateType state_type,
8623 gboolean emit_signal)
8625 if (atk_state_set_contains_state (item->state_set, state_type))
8629 rc = atk_state_set_remove_state (item->state_set, state_type);
8631 * The signal should only be generated if the value changed,
8632 * not when the item is set up. So states that are set
8633 * initially should pass FALSE as the emit_signal argument.
8638 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8639 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8640 if (state_type == ATK_STATE_VISIBLE)
8641 g_signal_emit_by_name (item, "visible-data-changed");
8651 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8653 GtkIconView *icon_view;
8654 GdkRectangle visible_rect;
8655 gboolean is_showing;
8658 * An item is considered "SHOWING" if any part of the item is in the
8659 * visible rectangle.
8662 if (!GTK_IS_ICON_VIEW (item->widget))
8665 if (item->item == NULL)
8668 icon_view = GTK_ICON_VIEW (item->widget);
8670 if (icon_view->priv->hadjustment)
8671 visible_rect.x += icon_view->priv->hadjustment->value;
8673 if (icon_view->priv->hadjustment)
8674 visible_rect.y += icon_view->priv->vadjustment->value;
8675 visible_rect.width = item->widget->allocation.width;
8676 visible_rect.height = item->widget->allocation.height;
8678 if (((item->item->x + item->item->width) < visible_rect.x) ||
8679 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8680 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8681 (item->item->y > (visible_rect.y + visible_rect.height)))
8690 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8691 gboolean emit_signal)
8693 if (gtk_icon_view_item_accessible_is_showing (item))
8694 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8697 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8702 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8706 item->state_set = atk_state_set_new ();
8708 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8709 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8710 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8711 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8712 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8714 for (i = 0; i < LAST_ACTION; i++)
8715 item->action_descriptions[i] = NULL;
8717 item->image_description = NULL;
8719 item->action_idle_handler = 0;
8723 gtk_icon_view_item_accessible_finalize (GObject *object)
8725 GtkIconViewItemAccessible *item;
8728 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8730 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8733 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8735 if (item->state_set)
8736 g_object_unref (item->state_set);
8738 if (item->text_buffer)
8739 g_object_unref (item->text_buffer);
8741 for (i = 0; i < LAST_ACTION; i++)
8742 g_free (item->action_descriptions[i]);
8744 g_free (item->image_description);
8746 if (item->action_idle_handler)
8748 g_source_remove (item->action_idle_handler);
8749 item->action_idle_handler = 0;
8752 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8755 static G_CONST_RETURN gchar*
8756 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8762 GtkIconViewItemAccessible *item;
8763 GtkTextIter start_iter;
8764 GtkTextIter end_iter;
8766 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8768 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8769 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8771 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8776 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8778 GtkIconViewItemAccessible *item;
8780 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8781 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8784 return gtk_widget_get_accessible (item->widget);
8790 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8792 GtkIconViewItemAccessible *item;
8794 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8795 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8797 return item->item->index;
8800 static AtkStateSet *
8801 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8803 GtkIconViewItemAccessible *item;
8804 GtkIconView *icon_view;
8806 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8807 g_return_val_if_fail (item->state_set, NULL);
8812 icon_view = GTK_ICON_VIEW (item->widget);
8813 if (icon_view->priv->cursor_item == item->item)
8814 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8816 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8817 if (item->item->selected)
8818 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8820 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8822 return g_object_ref (item->state_set);
8826 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8828 GObjectClass *gobject_class;
8830 accessible_item_parent_class = g_type_class_peek_parent (klass);
8832 gobject_class = (GObjectClass *)klass;
8834 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8836 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8837 klass->get_name = gtk_icon_view_item_accessible_get_name;
8838 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8839 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8843 gtk_icon_view_item_accessible_get_type (void)
8845 static GType type = 0;
8849 const GTypeInfo tinfo =
8851 sizeof (GtkIconViewItemAccessibleClass),
8852 (GBaseInitFunc) NULL, /* base init */
8853 (GBaseFinalizeFunc) NULL, /* base finalize */
8854 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8855 (GClassFinalizeFunc) NULL, /* class finalize */
8856 NULL, /* class data */
8857 sizeof (GtkIconViewItemAccessible), /* instance size */
8858 0, /* nb preallocs */
8859 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8860 NULL /* value table */
8863 const GInterfaceInfo atk_component_info =
8865 (GInterfaceInitFunc) atk_component_item_interface_init,
8866 (GInterfaceFinalizeFunc) NULL,
8869 const GInterfaceInfo atk_action_info =
8871 (GInterfaceInitFunc) atk_action_item_interface_init,
8872 (GInterfaceFinalizeFunc) NULL,
8875 const GInterfaceInfo atk_image_info =
8877 (GInterfaceInitFunc) atk_image_item_interface_init,
8878 (GInterfaceFinalizeFunc) NULL,
8881 const GInterfaceInfo atk_text_info =
8883 (GInterfaceInitFunc) atk_text_item_interface_init,
8884 (GInterfaceFinalizeFunc) NULL,
8888 type = g_type_register_static (ATK_TYPE_OBJECT,
8889 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8890 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8891 &atk_component_info);
8892 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8894 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8896 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8903 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8904 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8905 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8907 static GType gtk_icon_view_accessible_get_type (void);
8912 } GtkIconViewAccessible;
8918 } GtkIconViewItemAccessibleInfo;
8924 GtkAdjustment *old_hadj;
8925 GtkAdjustment *old_vadj;
8927 GtkTreeModel *model;
8929 } GtkIconViewAccessiblePrivate;
8931 static GtkIconViewAccessiblePrivate *
8932 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8934 return g_object_get_qdata (G_OBJECT (accessible),
8935 accessible_private_data_quark);
8939 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8943 GtkIconViewItemAccessibleInfo *info;
8944 GtkIconViewItemAccessibleInfo *tmp_info;
8945 GtkIconViewAccessiblePrivate *priv;
8948 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8950 info->index = index;
8952 priv = gtk_icon_view_accessible_get_priv (accessible);
8953 items = priv->items;
8956 tmp_info = items->data;
8957 if (tmp_info->index > index)
8959 items = items->next;
8961 priv->items = g_list_insert_before (priv->items, items, info);
8962 priv->old_hadj = NULL;
8963 priv->old_vadj = NULL;
8967 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8969 GtkIconView *icon_view;
8972 widget = GTK_ACCESSIBLE (accessible)->widget;
8976 icon_view = GTK_ICON_VIEW (widget);
8978 return g_list_length (icon_view->priv->items);
8982 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8985 GtkIconViewAccessiblePrivate *priv;
8986 GtkIconViewItemAccessibleInfo *info;
8989 priv = gtk_icon_view_accessible_get_priv (accessible);
8990 items = priv->items;
8995 if (info->index == index)
8997 items = items->next;
9003 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9006 GtkIconView *icon_view;
9010 GtkIconViewItemAccessible *a11y_item;
9012 widget = GTK_ACCESSIBLE (accessible)->widget;
9016 icon_view = GTK_ICON_VIEW (widget);
9017 icons = g_list_nth (icon_view->priv->items, index);
9021 GtkIconViewItem *item = icons->data;
9023 g_return_val_if_fail (item->index == index, NULL);
9024 obj = gtk_icon_view_accessible_find_child (accessible, index);
9029 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9030 gtk_icon_view_item_accessible_info_new (accessible,
9033 obj->role = ATK_ROLE_ICON;
9034 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9035 a11y_item->item = item;
9036 a11y_item->widget = widget;
9037 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9039 gtk_icon_view_set_cell_data (icon_view, item);
9040 text = get_text (icon_view, item);
9043 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9047 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9048 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9056 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9059 GtkIconViewAccessiblePrivate *priv;
9060 GtkIconViewItemAccessibleInfo *info;
9061 GtkIconViewItemAccessible *item;
9064 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9068 gboolean act_on_item;
9070 widget = GTK_ACCESSIBLE (view)->widget;
9074 items = priv->items;
9076 act_on_item = (list == NULL);
9081 info = (GtkIconViewItemAccessibleInfo *)items->data;
9082 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9084 if (act_on_item == FALSE && list == items)
9088 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9090 items = items->next;
9096 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9097 GtkIconView *icon_view)
9100 GtkIconViewAccessible *view;
9103 * The scrollbars have changed
9105 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9106 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9108 gtk_icon_view_accessible_traverse_items (view, NULL);
9112 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9113 GtkAdjustment *hadj,
9114 GtkAdjustment *vadj)
9117 GtkIconViewAccessiblePrivate *priv;
9119 atk_obj = gtk_widget_get_accessible (widget);
9120 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9122 if (priv->old_hadj != hadj)
9126 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9127 (gpointer *)&priv->old_hadj);
9129 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9130 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9133 priv->old_hadj = hadj;
9136 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9137 (gpointer *)&priv->old_hadj);
9138 g_signal_connect (hadj,
9140 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9144 if (priv->old_vadj != vadj)
9148 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9149 (gpointer *)&priv->old_vadj);
9151 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9152 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9155 priv->old_vadj = vadj;
9158 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9159 (gpointer *)&priv->old_vadj);
9160 g_signal_connect (vadj,
9162 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9169 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9177 GtkIconView *icon_view;
9178 GtkIconViewItem *item;
9179 GtkIconViewAccessible *a11y_view;
9180 GtkIconViewItemAccessible *a11y_item;
9184 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9185 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9186 index = gtk_tree_path_get_indices(path)[0];
9187 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9188 gtk_icon_view_accessible_find_child (atk_obj, index));
9192 widget = GTK_ACCESSIBLE (atk_obj)->widget;
9193 icon_view = GTK_ICON_VIEW (widget);
9194 item = a11y_item->item;
9196 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9198 if (!name || strcmp (name, "") == 0)
9200 gtk_icon_view_set_cell_data (icon_view, item);
9201 text = get_text (icon_view, item);
9204 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9210 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9216 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9221 GtkIconViewAccessiblePrivate *priv;
9222 GtkIconViewItemAccessibleInfo *info;
9223 GtkIconViewAccessible *view;
9224 GtkIconViewItemAccessible *item;
9230 index = gtk_tree_path_get_indices(path)[0];
9231 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9232 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9233 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9235 items = priv->items;
9240 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9241 if (info->index != item->item->index)
9243 if (info->index < index)
9244 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9246 if (tmp_list == NULL)
9249 info->index = item->item->index;
9252 items = items->next;
9254 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9255 g_signal_emit_by_name (atk_obj, "children-changed::add",
9261 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9265 GtkIconViewAccessiblePrivate *priv;
9266 GtkIconViewItemAccessibleInfo *info;
9267 GtkIconViewAccessible *view;
9268 GtkIconViewItemAccessible *item;
9271 GList *deleted_item;
9275 index = gtk_tree_path_get_indices(path)[0];
9276 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9277 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9278 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9280 items = priv->items;
9282 deleted_item = NULL;
9287 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9288 if (info->index == index)
9290 deleted_item = items;
9292 if (info->index != item->item->index)
9294 if (tmp_list == NULL)
9297 info->index = item->item->index;
9300 items = items->next;
9302 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9305 info = deleted_item->data;
9306 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9307 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9309 priv->items = g_list_remove_link (priv->items, deleted_item);
9317 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9318 GtkIconViewItemAccessibleInfo *i2)
9320 return i1->index - i2->index;
9324 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9330 GtkIconViewAccessiblePrivate *priv;
9331 GtkIconViewItemAccessibleInfo *info;
9332 GtkIconView *icon_view;
9333 GtkIconViewItemAccessible *item;
9339 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9340 icon_view = GTK_ICON_VIEW (user_data);
9341 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9343 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9345 order = g_new (gint, length);
9346 for (i = 0; i < length; i++)
9347 order [new_order[i]] = i;
9349 items = priv->items;
9353 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9354 info->index = order[info->index];
9355 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9356 items = items->next;
9359 priv->items = g_list_sort (priv->items,
9360 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9366 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9371 obj = G_OBJECT (model);
9372 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9373 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9374 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9375 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9379 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9383 obj = G_OBJECT (icon_view->priv->model);
9384 g_signal_connect_data (obj, "row-changed",
9385 (GCallback) gtk_icon_view_accessible_model_row_changed,
9386 icon_view, NULL, 0);
9387 g_signal_connect_data (obj, "row-inserted",
9388 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9389 icon_view, NULL, G_CONNECT_AFTER);
9390 g_signal_connect_data (obj, "row-deleted",
9391 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9392 icon_view, NULL, G_CONNECT_AFTER);
9393 g_signal_connect_data (obj, "rows-reordered",
9394 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9395 icon_view, NULL, G_CONNECT_AFTER);
9399 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9401 GtkIconViewItemAccessibleInfo *info;
9404 items = priv->items;
9407 info = (GtkIconViewItemAccessibleInfo *) items->data;
9408 g_object_unref (info->item);
9409 g_free (items->data);
9410 items = items->next;
9412 g_list_free (priv->items);
9417 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9420 GtkIconView *icon_view;
9423 GtkIconViewAccessiblePrivate *priv;
9425 if (strcmp (pspec->name, "model") == 0)
9427 widget = GTK_WIDGET (obj);
9428 atk_obj = gtk_widget_get_accessible (widget);
9429 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9432 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9433 (gpointer *)&priv->model);
9434 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9436 gtk_icon_view_accessible_clear_cache (priv);
9438 icon_view = GTK_ICON_VIEW (obj);
9439 priv->model = icon_view->priv->model;
9440 /* If there is no model the GtkIconView is probably being destroyed */
9443 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9444 gtk_icon_view_accessible_connect_model_signals (icon_view);
9452 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9455 GtkIconViewAccessiblePrivate *priv;
9456 GtkIconView *icon_view;
9458 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9459 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9461 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9462 g_object_set_qdata (G_OBJECT (accessible),
9463 accessible_private_data_quark,
9466 icon_view = GTK_ICON_VIEW (data);
9467 if (icon_view->priv->hadjustment)
9469 priv->old_hadj = icon_view->priv->hadjustment;
9470 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9471 g_signal_connect (icon_view->priv->hadjustment,
9473 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9476 if (icon_view->priv->vadjustment)
9478 priv->old_vadj = icon_view->priv->vadjustment;
9479 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9480 g_signal_connect (icon_view->priv->vadjustment,
9482 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9485 g_signal_connect_after (data,
9486 "set-scroll-adjustments",
9487 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9489 g_signal_connect (data,
9491 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9494 priv->model = icon_view->priv->model;
9497 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9498 gtk_icon_view_accessible_connect_model_signals (icon_view);
9501 accessible->role = ATK_ROLE_LAYERED_PANE;
9505 gtk_icon_view_accessible_finalize (GObject *object)
9507 GtkIconViewAccessiblePrivate *priv;
9509 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9510 gtk_icon_view_accessible_clear_cache (priv);
9514 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9518 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9519 GtkAccessible *accessible)
9522 GtkIconViewAccessiblePrivate *priv;
9524 atk_obj = ATK_OBJECT (accessible);
9525 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9528 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9529 (gpointer *)&priv->old_hadj);
9531 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9532 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9534 priv->old_hadj = NULL;
9538 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9539 (gpointer *)&priv->old_vadj);
9541 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9542 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9544 priv->old_vadj = NULL;
9549 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9551 if (accessible->widget)
9553 g_signal_connect_after (accessible->widget,
9555 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9558 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9562 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9564 GObjectClass *gobject_class;
9565 GtkAccessibleClass *accessible_class;
9567 accessible_parent_class = g_type_class_peek_parent (klass);
9569 gobject_class = (GObjectClass *)klass;
9570 accessible_class = (GtkAccessibleClass *)klass;
9572 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9574 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9575 klass->ref_child = gtk_icon_view_accessible_ref_child;
9576 klass->initialize = gtk_icon_view_accessible_initialize;
9578 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9580 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9584 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9587 AtkCoordType coord_type)
9590 GtkIconView *icon_view;
9591 GtkIconViewItem *item;
9594 widget = GTK_ACCESSIBLE (component)->widget;
9596 /* State is defunct */
9599 icon_view = GTK_ICON_VIEW (widget);
9600 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9601 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9603 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9609 atk_component_interface_init (AtkComponentIface *iface)
9611 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9615 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9619 GtkIconView *icon_view;
9620 GtkIconViewItem *item;
9622 widget = GTK_ACCESSIBLE (selection)->widget;
9626 icon_view = GTK_ICON_VIEW (widget);
9628 item = g_list_nth_data (icon_view->priv->items, i);
9633 gtk_icon_view_select_item (icon_view, item);
9639 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9642 GtkIconView *icon_view;
9644 widget = GTK_ACCESSIBLE (selection)->widget;
9648 icon_view = GTK_ICON_VIEW (widget);
9649 gtk_icon_view_unselect_all (icon_view);
9655 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9660 GtkIconView *icon_view;
9661 GtkIconViewItem *item;
9663 widget = GTK_ACCESSIBLE (selection)->widget;
9667 icon_view = GTK_ICON_VIEW (widget);
9669 l = icon_view->priv->items;
9676 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9687 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9690 GtkIconView *icon_view;
9691 GtkIconViewItem *item;
9695 widget = GTK_ACCESSIBLE (selection)->widget;
9699 icon_view = GTK_ICON_VIEW (widget);
9701 l = icon_view->priv->items;
9717 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9721 GtkIconView *icon_view;
9722 GtkIconViewItem *item;
9724 widget = GTK_ACCESSIBLE (selection)->widget;
9728 icon_view = GTK_ICON_VIEW (widget);
9730 item = g_list_nth_data (icon_view->priv->items, i);
9734 return item->selected;
9738 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9742 GtkIconView *icon_view;
9743 GtkIconViewItem *item;
9747 widget = GTK_ACCESSIBLE (selection)->widget;
9751 icon_view = GTK_ICON_VIEW (widget);
9752 l = icon_view->priv->items;
9761 gtk_icon_view_unselect_item (icon_view, item);
9773 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9776 GtkIconView *icon_view;
9778 widget = GTK_ACCESSIBLE (selection)->widget;
9782 icon_view = GTK_ICON_VIEW (widget);
9783 gtk_icon_view_select_all (icon_view);
9788 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9790 iface->add_selection = gtk_icon_view_accessible_add_selection;
9791 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9792 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9793 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9794 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9795 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9796 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9800 gtk_icon_view_accessible_get_type (void)
9802 static GType type = 0;
9809 (GBaseInitFunc) NULL, /* base init */
9810 (GBaseFinalizeFunc) NULL, /* base finalize */
9811 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9812 (GClassFinalizeFunc) NULL, /* class finalize */
9813 NULL, /* class data */
9814 0, /* instance size */
9815 0, /* nb preallocs */
9816 (GInstanceInitFunc) NULL, /* instance init */
9817 NULL /* value table */
9819 const GInterfaceInfo atk_component_info =
9821 (GInterfaceInitFunc) atk_component_interface_init,
9822 (GInterfaceFinalizeFunc) NULL,
9825 const GInterfaceInfo atk_selection_info =
9827 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9828 (GInterfaceFinalizeFunc) NULL,
9833 * Figure out the size of the class and instance
9834 * we are deriving from
9836 AtkObjectFactory *factory;
9839 GType derived_atk_type;
9841 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9842 factory = atk_registry_get_factory (atk_get_default_registry (),
9844 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9845 g_type_query (derived_atk_type, &query);
9846 tinfo.class_size = query.class_size;
9847 tinfo.instance_size = query.instance_size;
9849 type = g_type_register_static (derived_atk_type,
9850 I_("GtkIconViewAccessible"),
9852 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9853 &atk_component_info);
9854 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9855 &atk_selection_info);
9861 gtk_icon_view_accessible_new (GObject *obj)
9863 AtkObject *accessible;
9865 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9867 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9868 atk_object_initialize (accessible, obj);
9874 gtk_icon_view_accessible_factory_get_accessible_type (void)
9876 return gtk_icon_view_accessible_get_type ();
9880 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9882 return gtk_icon_view_accessible_new (obj);
9886 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9888 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9889 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9893 gtk_icon_view_accessible_factory_get_type (void)
9895 static GType type = 0;
9899 const GTypeInfo tinfo =
9901 sizeof (AtkObjectFactoryClass),
9902 NULL, /* base_init */
9903 NULL, /* base_finalize */
9904 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9905 NULL, /* class_finalize */
9906 NULL, /* class_data */
9907 sizeof (AtkObjectFactory),
9908 0, /* n_preallocs */
9912 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9913 I_("GtkIconViewAccessibleFactory"),
9921 gtk_icon_view_get_accessible (GtkWidget *widget)
9923 static gboolean first_time = TRUE;
9927 AtkObjectFactory *factory;
9928 AtkRegistry *registry;
9930 GType derived_atk_type;
9933 * Figure out whether accessibility is enabled by looking at the
9934 * type of the accessible object which would be created for
9935 * the parent type of GtkIconView.
9937 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9939 registry = atk_get_default_registry ();
9940 factory = atk_registry_get_factory (registry,
9942 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9943 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9944 atk_registry_set_factory_type (registry,
9946 gtk_icon_view_accessible_factory_get_type ());
9949 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9953 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9954 GtkBuilder *builder,
9956 const gchar *tagname,
9957 GMarkupParser *parser,
9960 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9961 tagname, parser, data))
9964 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9965 tagname, parser, data);
9969 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9970 GtkBuilder *builder,
9972 const gchar *tagname,
9975 if (strcmp (tagname, "attributes") == 0)
9976 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9979 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9985 #define __GTK_ICON_VIEW_C__
9986 #include "gtkaliasdef.c"