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 "gtkcellsizerequest.h"
33 #include "gtkmarshalers.h"
34 #include "gtkbindings.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.h"
43 #include "gtksizerequest.h"
44 #include "gtktreednd.h"
45 #include "gtkprivate.h"
50 * @short_description: A widget which displays a list of icons in a grid
52 * #GtkIconView provides an alternative view on a list model.
53 * It displays the model as a grid of icons with labels. Like
54 * #GtkTreeView, it allows to select one or multiple items
55 * (depending on the selection mode, see gtk_icon_view_set_selection_mode()).
56 * In addition to selection with the arrow keys, #GtkIconView supports
57 * rubberband selection, which is controlled by dragging the pointer.
60 #define SCROLL_EDGE_SIZE 15
62 typedef struct _GtkIconViewItem GtkIconViewItem;
63 struct _GtkIconViewItem
71 gint x, y, width, height;
74 * box[i] is the actual area occupied by cell i,
75 * before, after are used to calculate the cell
76 * area relative to the box.
77 * See gtk_icon_view_get_cell_area().
85 guint selected_before_rubberbanding : 1;
89 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
90 struct _GtkIconViewCellInfo
92 GtkCellRenderer *cell;
102 GtkCellLayoutDataFunc func;
104 GDestroyNotify destroy;
107 typedef struct _GtkIconViewChild GtkIconViewChild;
108 struct _GtkIconViewChild
111 GtkIconViewItem *item;
115 struct _GtkIconViewPrivate
119 GtkSelectionMode selection_mode;
121 GdkWindow *bin_window;
129 GtkAdjustment *hadjustment;
130 GtkAdjustment *vadjustment;
132 guint layout_idle_id;
134 gboolean doing_rubberband;
135 gint rubberband_x1, rubberband_y1;
136 gint rubberband_x2, rubberband_y2;
137 GdkDevice *rubberband_device;
139 guint scroll_timeout_id;
140 gint scroll_value_diff;
141 gint event_last_x, event_last_y;
143 GtkIconViewItem *anchor_item;
144 GtkIconViewItem *cursor_item;
145 GtkIconViewItem *edited_item;
146 GtkCellEditable *editable;
148 GtkIconViewItem *last_single_clicked;
155 GtkOrientation item_orientation;
175 GdkModifierType start_button_mask;
180 GdkDragAction source_actions;
181 GdkDragAction dest_actions;
183 GtkTreeRowReference *dest_item;
184 GtkIconViewDropPosition dest_pos;
187 GtkTreeRowReference *scroll_to_path;
188 gfloat scroll_to_row_align;
189 gfloat scroll_to_col_align;
190 guint scroll_to_use_align : 1;
192 guint source_set : 1;
194 guint reorderable : 1;
195 guint empty_view_drop :1;
197 guint ctrl_pressed : 1;
198 guint shift_pressed : 1;
200 guint draw_focus : 1;
213 ACTIVATE_CURSOR_ITEM,
225 PROP_ITEM_ORIENTATION,
239 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
240 static void gtk_icon_view_finalize (GObject *object);
241 static void gtk_icon_view_set_property (GObject *object,
245 static void gtk_icon_view_get_property (GObject *object,
250 /* GtkObject vfuncs */
251 static void gtk_icon_view_destroy (GtkObject *object);
253 /* GtkWidget vfuncs */
254 static void gtk_icon_view_realize (GtkWidget *widget);
255 static void gtk_icon_view_unrealize (GtkWidget *widget);
256 static void gtk_icon_view_style_set (GtkWidget *widget,
257 GtkStyle *previous_style);
258 static void gtk_icon_view_state_changed (GtkWidget *widget,
259 GtkStateType previous_state);
260 static void gtk_icon_view_size_request (GtkWidget *widget,
261 GtkRequisition *requisition);
262 static void gtk_icon_view_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static gboolean gtk_icon_view_expose (GtkWidget *widget,
265 GdkEventExpose *expose);
266 static gboolean gtk_icon_view_motion (GtkWidget *widget,
267 GdkEventMotion *event);
268 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
269 GdkEventButton *event);
270 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
271 GdkEventButton *event);
272 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
274 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
276 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
279 /* GtkContainer vfuncs */
280 static void gtk_icon_view_remove (GtkContainer *container,
282 static void gtk_icon_view_forall (GtkContainer *container,
283 gboolean include_internals,
284 GtkCallback callback,
285 gpointer callback_data);
287 /* GtkIconView vfuncs */
288 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
290 GtkAdjustment *vadj);
291 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
292 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
293 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
294 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
295 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
297 /* Internal functions */
298 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
299 GtkIconView *icon_view);
300 static void gtk_icon_view_layout (GtkIconView *icon_view);
301 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
304 GtkIconViewItem *item,
306 GdkDrawable *drawable,
309 gboolean draw_focus);
310 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
313 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
315 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
316 GtkIconViewItem *item);
317 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
318 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
319 GtkIconViewItem *item,
321 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
325 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
326 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
327 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
328 GtkIconViewItem *item,
333 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
334 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
335 GtkIconViewItem *item);
336 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
337 GtkIconViewItem *item,
339 static void gtk_icon_view_update_rubberband (gpointer data);
340 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
341 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
342 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
345 GtkMovementStep step,
347 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
348 GtkMovementStep step,
350 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
352 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
354 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
356 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
358 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
359 GtkIconViewItem *item);
360 static void gtk_icon_view_select_item (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
363 GtkIconViewItem *item);
364 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
365 GtkIconViewItem *anchor,
366 GtkIconViewItem *cursor);
367 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
370 gboolean only_in_cell,
371 GtkIconViewCellInfo **cell_at_pos);
372 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
373 GtkIconViewItem *item,
374 GtkIconViewCellInfo *cell_info,
375 GdkRectangle *cell_area);
376 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
377 GtkIconViewItem *item,
378 GtkIconViewCellInfo *info,
380 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
381 GtkCellRenderer *renderer);
382 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
383 GtkIconViewItem *item);
384 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
385 GtkCellRenderer *renderer,
387 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
388 GtkCellRenderer *renderer,
390 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
391 GtkCellRenderer *renderer,
392 const gchar *attribute,
394 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
395 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
396 GtkCellRenderer *renderer);
397 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
398 GtkCellRenderer *cell,
399 GtkCellLayoutDataFunc func,
401 GDestroyNotify destroy);
402 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
403 GtkCellRenderer *cell,
405 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
407 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
408 GtkIconViewItem *item,
409 GtkIconViewCellInfo *cell_info,
411 static void gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
412 GtkIconViewItem *item);
413 static void gtk_icon_view_put (GtkIconView *icon_view,
415 GtkIconViewItem *item,
417 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
418 GtkIconView *icon_view);
419 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
420 GtkIconViewItem *item,
421 GtkIconViewCellInfo *cell_info,
423 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
424 gboolean cancel_editing);
426 /* Source side drag signals */
427 static void gtk_icon_view_drag_begin (GtkWidget *widget,
428 GdkDragContext *context);
429 static void gtk_icon_view_drag_end (GtkWidget *widget,
430 GdkDragContext *context);
431 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
432 GdkDragContext *context,
433 GtkSelectionData *selection_data,
436 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
437 GdkDragContext *context);
439 /* Target side drag signals */
440 static void gtk_icon_view_drag_leave (GtkWidget *widget,
441 GdkDragContext *context,
443 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
444 GdkDragContext *context,
448 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
449 GdkDragContext *context,
453 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
454 GdkDragContext *context,
457 GtkSelectionData *selection_data,
460 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
461 GdkEventMotion *event);
463 static void remove_scroll_timeout (GtkIconView *icon_view);
465 static void adjust_wrap_width (GtkIconView *icon_view,
466 GtkIconViewItem *item);
469 static GtkBuildableIface *parent_buildable_iface;
470 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
471 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
474 const gchar *tagname,
475 GMarkupParser *parser,
477 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
480 const gchar *tagname,
483 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
485 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
486 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
487 gtk_icon_view_cell_layout_init)
488 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
489 gtk_icon_view_buildable_init))
492 gtk_icon_view_class_init (GtkIconViewClass *klass)
494 GObjectClass *gobject_class;
495 GtkObjectClass *object_class;
496 GtkWidgetClass *widget_class;
497 GtkContainerClass *container_class;
498 GtkBindingSet *binding_set;
500 binding_set = gtk_binding_set_by_class (klass);
502 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
504 gobject_class = (GObjectClass *) klass;
505 object_class = (GtkObjectClass *) klass;
506 widget_class = (GtkWidgetClass *) klass;
507 container_class = (GtkContainerClass *) klass;
509 gobject_class->finalize = gtk_icon_view_finalize;
510 gobject_class->set_property = gtk_icon_view_set_property;
511 gobject_class->get_property = gtk_icon_view_get_property;
513 object_class->destroy = gtk_icon_view_destroy;
515 widget_class->realize = gtk_icon_view_realize;
516 widget_class->unrealize = gtk_icon_view_unrealize;
517 widget_class->style_set = gtk_icon_view_style_set;
518 widget_class->get_accessible = gtk_icon_view_get_accessible;
519 widget_class->size_request = gtk_icon_view_size_request;
520 widget_class->size_allocate = gtk_icon_view_size_allocate;
521 widget_class->expose_event = gtk_icon_view_expose;
522 widget_class->motion_notify_event = gtk_icon_view_motion;
523 widget_class->button_press_event = gtk_icon_view_button_press;
524 widget_class->button_release_event = gtk_icon_view_button_release;
525 widget_class->key_press_event = gtk_icon_view_key_press;
526 widget_class->key_release_event = gtk_icon_view_key_release;
527 widget_class->drag_begin = gtk_icon_view_drag_begin;
528 widget_class->drag_end = gtk_icon_view_drag_end;
529 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
530 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
531 widget_class->drag_leave = gtk_icon_view_drag_leave;
532 widget_class->drag_motion = gtk_icon_view_drag_motion;
533 widget_class->drag_drop = gtk_icon_view_drag_drop;
534 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
535 widget_class->state_changed = gtk_icon_view_state_changed;
537 container_class->remove = gtk_icon_view_remove;
538 container_class->forall = gtk_icon_view_forall;
540 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
541 klass->select_all = gtk_icon_view_real_select_all;
542 klass->unselect_all = gtk_icon_view_real_unselect_all;
543 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
544 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
545 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
546 klass->move_cursor = gtk_icon_view_real_move_cursor;
550 * GtkIconView:selection-mode:
552 * The ::selection-mode property specifies the selection mode of
553 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
554 * is enabled, for the other modes, only keyboard selection is possible.
558 g_object_class_install_property (gobject_class,
560 g_param_spec_enum ("selection-mode",
561 P_("Selection mode"),
562 P_("The selection mode"),
563 GTK_TYPE_SELECTION_MODE,
564 GTK_SELECTION_SINGLE,
565 GTK_PARAM_READWRITE));
568 * GtkIconView:pixbuf-column:
570 * The ::pixbuf-column property contains the number of the model column
571 * containing the pixbufs which are displayed. The pixbuf column must be
572 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
573 * display of pixbufs.
577 g_object_class_install_property (gobject_class,
579 g_param_spec_int ("pixbuf-column",
581 P_("Model column used to retrieve the icon pixbuf from"),
583 GTK_PARAM_READWRITE));
586 * GtkIconView:text-column:
588 * The ::text-column property contains the number of the model column
589 * containing the texts which are displayed. The text column must be
590 * of type #G_TYPE_STRING. If this property and the :markup-column
591 * property are both set to -1, no texts are displayed.
595 g_object_class_install_property (gobject_class,
597 g_param_spec_int ("text-column",
599 P_("Model column used to retrieve the text from"),
601 GTK_PARAM_READWRITE));
605 * GtkIconView:markup-column:
607 * The ::markup-column property contains the number of the model column
608 * containing markup information to be displayed. The markup column must be
609 * of type #G_TYPE_STRING. If this property and the :text-column property
610 * are both set to column numbers, it overrides the text column.
611 * If both are set to -1, no texts are displayed.
615 g_object_class_install_property (gobject_class,
617 g_param_spec_int ("markup-column",
619 P_("Model column used to retrieve the text if using Pango markup"),
621 GTK_PARAM_READWRITE));
623 g_object_class_install_property (gobject_class,
625 g_param_spec_object ("model",
626 P_("Icon View Model"),
627 P_("The model for the icon view"),
629 GTK_PARAM_READWRITE));
632 * GtkIconView:columns:
634 * The columns property contains the number of the columns in which the
635 * items should be displayed. If it is -1, the number of columns will
636 * be chosen automatically to fill the available area.
640 g_object_class_install_property (gobject_class,
642 g_param_spec_int ("columns",
643 P_("Number of columns"),
644 P_("Number of columns to display"),
646 GTK_PARAM_READWRITE));
650 * GtkIconView:item-width:
652 * The item-width property specifies the width to use for each item.
653 * If it is set to -1, the icon view will automatically determine a
654 * suitable item size.
658 g_object_class_install_property (gobject_class,
660 g_param_spec_int ("item-width",
661 P_("Width for each item"),
662 P_("The width used for each item"),
664 GTK_PARAM_READWRITE));
667 * GtkIconView:spacing:
669 * The spacing property specifies the space which is inserted between
670 * the cells (i.e. the icon and the text) of an item.
674 g_object_class_install_property (gobject_class,
676 g_param_spec_int ("spacing",
678 P_("Space which is inserted between cells of an item"),
680 GTK_PARAM_READWRITE));
683 * GtkIconView:row-spacing:
685 * The row-spacing property specifies the space which is inserted between
686 * the rows of the icon view.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_int ("row-spacing",
694 P_("Space which is inserted between grid rows"),
696 GTK_PARAM_READWRITE));
699 * GtkIconView:column-spacing:
701 * The column-spacing property specifies the space which is inserted between
702 * the columns of the icon view.
706 g_object_class_install_property (gobject_class,
708 g_param_spec_int ("column-spacing",
709 P_("Column Spacing"),
710 P_("Space which is inserted between grid columns"),
712 GTK_PARAM_READWRITE));
715 * GtkIconView:margin:
717 * The margin property specifies the space which is inserted
718 * at the edges of the icon view.
722 g_object_class_install_property (gobject_class,
724 g_param_spec_int ("margin",
726 P_("Space which is inserted at the edges of the icon view"),
728 GTK_PARAM_READWRITE));
731 * GtkIconView:item-orientation:
733 * The item-orientation property specifies how the cells (i.e. the icon and
734 * the text) of the item are positioned relative to each other.
738 g_object_class_install_property (gobject_class,
739 PROP_ITEM_ORIENTATION,
740 g_param_spec_enum ("item-orientation",
741 P_("Item Orientation"),
742 P_("How the text and icon of each item are positioned relative to each other"),
743 GTK_TYPE_ORIENTATION,
744 GTK_ORIENTATION_VERTICAL,
745 GTK_PARAM_READWRITE));
748 * GtkIconView:reorderable:
750 * The reorderable property specifies if the items can be reordered
755 g_object_class_install_property (gobject_class,
757 g_param_spec_boolean ("reorderable",
759 P_("View is reorderable"),
763 g_object_class_install_property (gobject_class,
765 g_param_spec_int ("tooltip-column",
766 P_("Tooltip Column"),
767 P_("The column in the model containing the tooltip texts for the items"),
771 GTK_PARAM_READWRITE));
774 * GtkIconView:item-padding:
776 * The item-padding property specifies the padding around each
777 * of the icon view's item.
781 g_object_class_install_property (gobject_class,
783 g_param_spec_int ("item-padding",
785 P_("Padding around icon view items"),
787 GTK_PARAM_READWRITE));
791 /* Style properties */
792 gtk_widget_class_install_style_property (widget_class,
793 g_param_spec_boxed ("selection-box-color",
794 P_("Selection Box Color"),
795 P_("Color of the selection box"),
797 GTK_PARAM_READABLE));
799 gtk_widget_class_install_style_property (widget_class,
800 g_param_spec_uchar ("selection-box-alpha",
801 P_("Selection Box Alpha"),
802 P_("Opacity of the selection box"),
805 GTK_PARAM_READABLE));
809 * GtkIconView::set-scroll-adjustments
810 * @horizontal: the horizontal #GtkAdjustment
811 * @vertical: the vertical #GtkAdjustment
813 * Set the scroll adjustments for the icon view. Usually scrolled containers
814 * like #GtkScrolledWindow will emit this signal to connect two instances
815 * of #GtkScrollbar to the scroll directions of the #GtkIconView.
817 widget_class->set_scroll_adjustments_signal =
818 g_signal_new (I_("set-scroll-adjustments"),
819 G_TYPE_FROM_CLASS (gobject_class),
821 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
823 _gtk_marshal_VOID__OBJECT_OBJECT,
825 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
828 * GtkIconView::item-activated:
829 * @iconview: the object on which the signal is emitted
830 * @path: the #GtkTreePath for the activated item
832 * The ::item-activated signal is emitted when the method
833 * gtk_icon_view_item_activated() is called or the user double
834 * clicks an item. It is also emitted when a non-editable item
835 * is selected and one of the keys: Space, Return or Enter is
838 icon_view_signals[ITEM_ACTIVATED] =
839 g_signal_new (I_("item-activated"),
840 G_TYPE_FROM_CLASS (gobject_class),
842 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
844 g_cclosure_marshal_VOID__BOXED,
849 * GtkIconView::selection-changed:
850 * @iconview: the object on which the signal is emitted
852 * The ::selection-changed signal is emitted when the selection
853 * (i.e. the set of selected items) changes.
855 icon_view_signals[SELECTION_CHANGED] =
856 g_signal_new (I_("selection-changed"),
857 G_TYPE_FROM_CLASS (gobject_class),
859 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
861 g_cclosure_marshal_VOID__VOID,
865 * GtkIconView::select-all:
866 * @iconview: the object on which the signal is emitted
868 * A <link linkend="keybinding-signals">keybinding signal</link>
869 * which gets emitted when the user selects all items.
871 * Applications should not connect to it, but may emit it with
872 * g_signal_emit_by_name() if they need to control selection
875 * The default binding for this signal is Ctrl-a.
877 icon_view_signals[SELECT_ALL] =
878 g_signal_new (I_("select-all"),
879 G_TYPE_FROM_CLASS (gobject_class),
880 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
881 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
883 g_cclosure_marshal_VOID__VOID,
887 * GtkIconView::unselect-all:
888 * @iconview: the object on which the signal is emitted
890 * A <link linkend="keybinding-signals">keybinding signal</link>
891 * which gets emitted when the user unselects all items.
893 * Applications should not connect to it, but may emit it with
894 * g_signal_emit_by_name() if they need to control selection
897 * The default binding for this signal is Ctrl-Shift-a.
899 icon_view_signals[UNSELECT_ALL] =
900 g_signal_new (I_("unselect-all"),
901 G_TYPE_FROM_CLASS (gobject_class),
902 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
903 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
905 g_cclosure_marshal_VOID__VOID,
909 * GtkIconView::select-cursor-item:
910 * @iconview: the object on which the signal is emitted
912 * A <link linkend="keybinding-signals">keybinding signal</link>
913 * which gets emitted when the user selects the item that is currently
916 * Applications should not connect to it, but may emit it with
917 * g_signal_emit_by_name() if they need to control selection
920 * There is no default binding for this signal.
922 icon_view_signals[SELECT_CURSOR_ITEM] =
923 g_signal_new (I_("select-cursor-item"),
924 G_TYPE_FROM_CLASS (gobject_class),
925 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
926 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
928 g_cclosure_marshal_VOID__VOID,
932 * GtkIconView::toggle-cursor-item:
933 * @iconview: the object on which the signal is emitted
935 * A <link linkend="keybinding-signals">keybinding signal</link>
936 * which gets emitted when the user toggles whether the currently
937 * focused item is selected or not. The exact effect of this
938 * depend on the selection mode.
940 * Applications should not connect to it, but may emit it with
941 * g_signal_emit_by_name() if they need to control selection
944 * There is no default binding for this signal is Ctrl-Space.
946 icon_view_signals[TOGGLE_CURSOR_ITEM] =
947 g_signal_new (I_("toggle-cursor-item"),
948 G_TYPE_FROM_CLASS (gobject_class),
949 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
950 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
952 g_cclosure_marshal_VOID__VOID,
956 * GtkIconView::activate-cursor-item:
957 * @iconview: the object on which the signal is emitted
959 * A <link linkend="keybinding-signals">keybinding signal</link>
960 * which gets emitted when the user activates the currently
963 * Applications should not connect to it, but may emit it with
964 * g_signal_emit_by_name() if they need to control activation
967 * The default bindings for this signal are Space, Return and Enter.
969 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
970 g_signal_new (I_("activate-cursor-item"),
971 G_TYPE_FROM_CLASS (gobject_class),
972 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
973 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
975 _gtk_marshal_BOOLEAN__VOID,
979 * GtkIconView::move-cursor:
980 * @iconview: the object which received the signal
981 * @step: the granularity of the move, as a #GtkMovementStep
982 * @count: the number of @step units to move
984 * The ::move-cursor signal is a
985 * <link linkend="keybinding-signals">keybinding signal</link>
986 * which gets emitted when the user initiates a cursor movement.
988 * Applications should not connect to it, but may emit it with
989 * g_signal_emit_by_name() if they need to control the cursor
992 * The default bindings for this signal include
994 * <listitem>Arrow keys which move by individual steps</listitem>
995 * <listitem>Home/End keys which move to the first/last item</listitem>
996 * <listitem>PageUp/PageDown which move by "pages"</listitem>
999 * All of these will extend the selection when combined with
1000 * the Shift modifier.
1002 icon_view_signals[MOVE_CURSOR] =
1003 g_signal_new (I_("move-cursor"),
1004 G_TYPE_FROM_CLASS (gobject_class),
1005 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1006 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
1008 _gtk_marshal_BOOLEAN__ENUM_INT,
1010 GTK_TYPE_MOVEMENT_STEP,
1014 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK,
1016 gtk_binding_entry_add_signal (binding_set, GDK_KEY_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
1018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, GDK_CONTROL_MASK,
1019 "toggle-cursor-item", 0);
1020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, GDK_CONTROL_MASK,
1021 "toggle-cursor-item", 0);
1023 gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
1024 "activate-cursor-item", 0);
1025 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
1026 "activate-cursor-item", 0);
1027 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
1028 "activate-cursor-item", 0);
1029 gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
1030 "activate-cursor-item", 0);
1031 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
1032 "activate-cursor-item", 0);
1034 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Up, 0,
1035 GTK_MOVEMENT_DISPLAY_LINES, -1);
1036 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Up, 0,
1037 GTK_MOVEMENT_DISPLAY_LINES, -1);
1039 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Down, 0,
1040 GTK_MOVEMENT_DISPLAY_LINES, 1);
1041 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Down, 0,
1042 GTK_MOVEMENT_DISPLAY_LINES, 1);
1044 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_p, GDK_CONTROL_MASK,
1045 GTK_MOVEMENT_DISPLAY_LINES, -1);
1047 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_n, GDK_CONTROL_MASK,
1048 GTK_MOVEMENT_DISPLAY_LINES, 1);
1050 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Home, 0,
1051 GTK_MOVEMENT_BUFFER_ENDS, -1);
1052 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Home, 0,
1053 GTK_MOVEMENT_BUFFER_ENDS, -1);
1055 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_End, 0,
1056 GTK_MOVEMENT_BUFFER_ENDS, 1);
1057 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_End, 0,
1058 GTK_MOVEMENT_BUFFER_ENDS, 1);
1060 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Up, 0,
1061 GTK_MOVEMENT_PAGES, -1);
1062 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Up, 0,
1063 GTK_MOVEMENT_PAGES, -1);
1065 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Page_Down, 0,
1066 GTK_MOVEMENT_PAGES, 1);
1067 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Page_Down, 0,
1068 GTK_MOVEMENT_PAGES, 1);
1070 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Right, 0,
1071 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1072 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_Left, 0,
1073 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1075 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Right, 0,
1076 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
1077 gtk_icon_view_add_move_binding (binding_set, GDK_KEY_KP_Left, 0,
1078 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
1082 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
1084 parent_buildable_iface = g_type_interface_peek_parent (iface);
1085 iface->add_child = _gtk_cell_layout_buildable_add_child;
1086 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
1087 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
1091 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
1093 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
1094 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
1095 iface->clear = gtk_icon_view_cell_layout_clear;
1096 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
1097 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
1098 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
1099 iface->reorder = gtk_icon_view_cell_layout_reorder;
1100 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
1104 gtk_icon_view_init (GtkIconView *icon_view)
1106 icon_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (icon_view,
1108 GtkIconViewPrivate);
1110 icon_view->priv->width = 0;
1111 icon_view->priv->height = 0;
1112 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
1113 icon_view->priv->pressed_button = -1;
1114 icon_view->priv->press_start_x = -1;
1115 icon_view->priv->press_start_y = -1;
1116 icon_view->priv->text_column = -1;
1117 icon_view->priv->markup_column = -1;
1118 icon_view->priv->pixbuf_column = -1;
1119 icon_view->priv->text_cell = -1;
1120 icon_view->priv->pixbuf_cell = -1;
1121 icon_view->priv->tooltip_column = -1;
1123 gtk_widget_set_can_focus (GTK_WIDGET (icon_view), TRUE);
1125 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
1127 icon_view->priv->cell_list = NULL;
1128 icon_view->priv->n_cells = 0;
1129 icon_view->priv->cursor_cell = -1;
1131 icon_view->priv->item_orientation = GTK_ORIENTATION_VERTICAL;
1133 icon_view->priv->columns = -1;
1134 icon_view->priv->item_width = -1;
1135 icon_view->priv->spacing = 0;
1136 icon_view->priv->row_spacing = 6;
1137 icon_view->priv->column_spacing = 6;
1138 icon_view->priv->margin = 6;
1139 icon_view->priv->item_padding = 6;
1141 icon_view->priv->draw_focus = TRUE;
1145 gtk_icon_view_destroy (GtkObject *object)
1147 GtkIconView *icon_view;
1149 icon_view = GTK_ICON_VIEW (object);
1151 gtk_icon_view_stop_editing (icon_view, TRUE);
1153 gtk_icon_view_set_model (icon_view, NULL);
1155 if (icon_view->priv->layout_idle_id != 0)
1157 g_source_remove (icon_view->priv->layout_idle_id);
1158 icon_view->priv->layout_idle_id = 0;
1161 if (icon_view->priv->scroll_to_path != NULL)
1163 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1164 icon_view->priv->scroll_to_path = NULL;
1167 remove_scroll_timeout (icon_view);
1169 if (icon_view->priv->hadjustment != NULL)
1171 g_object_unref (icon_view->priv->hadjustment);
1172 icon_view->priv->hadjustment = NULL;
1175 if (icon_view->priv->vadjustment != NULL)
1177 g_object_unref (icon_view->priv->vadjustment);
1178 icon_view->priv->vadjustment = NULL;
1181 GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy (object);
1184 /* GObject methods */
1186 gtk_icon_view_finalize (GObject *object)
1188 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1190 G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize (object);
1195 gtk_icon_view_set_property (GObject *object,
1197 const GValue *value,
1200 GtkIconView *icon_view;
1202 icon_view = GTK_ICON_VIEW (object);
1206 case PROP_SELECTION_MODE:
1207 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1209 case PROP_PIXBUF_COLUMN:
1210 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1212 case PROP_TEXT_COLUMN:
1213 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1215 case PROP_MARKUP_COLUMN:
1216 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1219 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1221 case PROP_ITEM_ORIENTATION:
1222 gtk_icon_view_set_item_orientation (icon_view, g_value_get_enum (value));
1225 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1227 case PROP_ITEM_WIDTH:
1228 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1231 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1233 case PROP_ROW_SPACING:
1234 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1236 case PROP_COLUMN_SPACING:
1237 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1240 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1242 case PROP_REORDERABLE:
1243 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1246 case PROP_TOOLTIP_COLUMN:
1247 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1250 case PROP_ITEM_PADDING:
1251 gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
1255 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1261 gtk_icon_view_get_property (GObject *object,
1266 GtkIconView *icon_view;
1268 icon_view = GTK_ICON_VIEW (object);
1272 case PROP_SELECTION_MODE:
1273 g_value_set_enum (value, icon_view->priv->selection_mode);
1275 case PROP_PIXBUF_COLUMN:
1276 g_value_set_int (value, icon_view->priv->pixbuf_column);
1278 case PROP_TEXT_COLUMN:
1279 g_value_set_int (value, icon_view->priv->text_column);
1281 case PROP_MARKUP_COLUMN:
1282 g_value_set_int (value, icon_view->priv->markup_column);
1285 g_value_set_object (value, icon_view->priv->model);
1287 case PROP_ITEM_ORIENTATION:
1288 g_value_set_enum (value, icon_view->priv->item_orientation);
1291 g_value_set_int (value, icon_view->priv->columns);
1293 case PROP_ITEM_WIDTH:
1294 g_value_set_int (value, icon_view->priv->item_width);
1297 g_value_set_int (value, icon_view->priv->spacing);
1299 case PROP_ROW_SPACING:
1300 g_value_set_int (value, icon_view->priv->row_spacing);
1302 case PROP_COLUMN_SPACING:
1303 g_value_set_int (value, icon_view->priv->column_spacing);
1306 g_value_set_int (value, icon_view->priv->margin);
1308 case PROP_REORDERABLE:
1309 g_value_set_boolean (value, icon_view->priv->reorderable);
1311 case PROP_TOOLTIP_COLUMN:
1312 g_value_set_int (value, icon_view->priv->tooltip_column);
1315 case PROP_ITEM_PADDING:
1316 g_value_set_int (value, icon_view->priv->item_padding);
1320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1325 /* GtkWidget signals */
1327 gtk_icon_view_realize (GtkWidget *widget)
1329 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1330 GtkAllocation allocation;
1332 GdkWindowAttr attributes;
1333 gint attributes_mask;
1335 gtk_widget_set_realized (widget, TRUE);
1337 gtk_widget_get_allocation (widget, &allocation);
1339 /* Make the main, clipping window */
1340 attributes.window_type = GDK_WINDOW_CHILD;
1341 attributes.x = allocation.x;
1342 attributes.y = allocation.y;
1343 attributes.width = allocation.width;
1344 attributes.height = allocation.height;
1345 attributes.wclass = GDK_INPUT_OUTPUT;
1346 attributes.visual = gtk_widget_get_visual (widget);
1347 attributes.colormap = gtk_widget_get_colormap (widget);
1348 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1350 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1352 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1353 &attributes, attributes_mask);
1354 gtk_widget_set_window (widget, window);
1355 gdk_window_set_user_data (window, widget);
1357 gtk_widget_get_allocation (widget, &allocation);
1359 /* Make the window for the icon view */
1362 attributes.width = MAX (icon_view->priv->width, allocation.width);
1363 attributes.height = MAX (icon_view->priv->height, allocation.height);
1364 attributes.event_mask = (GDK_EXPOSURE_MASK |
1366 GDK_POINTER_MOTION_MASK |
1367 GDK_BUTTON_PRESS_MASK |
1368 GDK_BUTTON_RELEASE_MASK |
1369 GDK_KEY_PRESS_MASK |
1370 GDK_KEY_RELEASE_MASK) |
1371 gtk_widget_get_events (widget);
1373 icon_view->priv->bin_window = gdk_window_new (window,
1374 &attributes, attributes_mask);
1375 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1377 gtk_widget_style_attach (widget);
1378 gdk_window_set_background (icon_view->priv->bin_window,
1379 >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1381 gdk_window_show (icon_view->priv->bin_window);
1385 gtk_icon_view_unrealize (GtkWidget *widget)
1387 GtkIconView *icon_view;
1389 icon_view = GTK_ICON_VIEW (widget);
1391 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1392 gdk_window_destroy (icon_view->priv->bin_window);
1393 icon_view->priv->bin_window = NULL;
1395 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
1399 gtk_icon_view_state_changed (GtkWidget *widget,
1400 GtkStateType previous_state)
1402 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1406 if (gtk_widget_get_realized (widget))
1408 style = gtk_widget_get_style (widget);
1409 state = gtk_widget_get_state (widget);
1411 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1412 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1415 gtk_widget_queue_draw (widget);
1419 gtk_icon_view_style_set (GtkWidget *widget,
1420 GtkStyle *previous_style)
1422 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1426 if (gtk_widget_get_realized (widget))
1428 style = gtk_widget_get_style (widget);
1429 state = gtk_widget_get_state (widget);
1431 gdk_window_set_background (gtk_widget_get_window (widget), &style->base[state]);
1432 gdk_window_set_background (icon_view->priv->bin_window, &style->base[state]);
1435 gtk_widget_queue_resize (widget);
1439 gtk_icon_view_size_request (GtkWidget *widget,
1440 GtkRequisition *requisition)
1442 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1445 requisition->width = icon_view->priv->width;
1446 requisition->height = icon_view->priv->height;
1448 tmp_list = icon_view->priv->children;
1452 GtkIconViewChild *child = tmp_list->data;
1453 GtkRequisition child_requisition;
1455 tmp_list = tmp_list->next;
1457 if (gtk_widget_get_visible (child->widget))
1458 gtk_size_request_get_size (GTK_SIZE_REQUEST (child->widget),
1459 &child_requisition, NULL);
1464 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1468 for (list = icon_view->priv->children; list; list = list->next)
1470 GtkIconViewChild *child = list->data;
1471 GtkAllocation allocation;
1473 /* totally ignore our child's requisition */
1474 if (child->cell < 0)
1476 allocation.x = child->item->x + icon_view->priv->item_padding;
1477 allocation.y = child->item->y + icon_view->priv->item_padding;
1478 allocation.width = child->item->width - icon_view->priv->item_padding * 2;
1479 allocation.height = child->item->height - icon_view->priv->item_padding * 2;
1483 GdkRectangle *box = &child->item->box[child->cell];
1485 allocation.x = box->x;
1486 allocation.y = box->y;
1487 allocation.width = box->width;
1488 allocation.height = box->height;
1491 gtk_widget_size_allocate (child->widget, &allocation);
1496 gtk_icon_view_size_allocate (GtkWidget *widget,
1497 GtkAllocation *allocation)
1499 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1501 GtkAdjustment *hadjustment, *vadjustment;
1503 gtk_widget_set_allocation (widget, allocation);
1505 if (gtk_widget_get_realized (widget))
1507 gdk_window_move_resize (gtk_widget_get_window (widget),
1508 allocation->x, allocation->y,
1509 allocation->width, allocation->height);
1510 gdk_window_resize (icon_view->priv->bin_window,
1511 MAX (icon_view->priv->width, allocation->width),
1512 MAX (icon_view->priv->height, allocation->height));
1515 gtk_icon_view_layout (icon_view);
1517 gtk_icon_view_allocate_children (icon_view);
1519 hadjustment = icon_view->priv->hadjustment;
1520 vadjustment = icon_view->priv->vadjustment;
1522 hadjustment->page_size = allocation->width;
1523 hadjustment->page_increment = allocation->width * 0.9;
1524 hadjustment->step_increment = allocation->width * 0.1;
1525 hadjustment->lower = 0;
1526 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1528 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1529 gtk_adjustment_set_value (hadjustment, hadjustment->upper - hadjustment->page_size);
1531 vadjustment->page_size = allocation->height;
1532 vadjustment->page_increment = allocation->height * 0.9;
1533 vadjustment->step_increment = allocation->height * 0.1;
1534 vadjustment->lower = 0;
1535 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1537 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1538 gtk_adjustment_set_value (vadjustment, vadjustment->upper - vadjustment->page_size);
1540 if (gtk_widget_get_realized (widget) &&
1541 icon_view->priv->scroll_to_path)
1544 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1545 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1546 icon_view->priv->scroll_to_path = NULL;
1548 gtk_icon_view_scroll_to_path (icon_view, path,
1549 icon_view->priv->scroll_to_use_align,
1550 icon_view->priv->scroll_to_row_align,
1551 icon_view->priv->scroll_to_col_align);
1552 gtk_tree_path_free (path);
1556 gtk_adjustment_changed (hadjustment);
1557 gtk_adjustment_changed (vadjustment);
1562 gtk_icon_view_expose (GtkWidget *widget,
1563 GdkEventExpose *expose)
1565 GtkIconView *icon_view;
1570 GtkIconViewDropPosition dest_pos;
1571 GtkIconViewItem *dest_item = NULL;
1573 icon_view = GTK_ICON_VIEW (widget);
1575 if (expose->window != icon_view->priv->bin_window)
1578 /* If a layout has been scheduled, do it now so that all
1579 * cell view items have valid sizes before we proceed. */
1580 if (icon_view->priv->layout_idle_id != 0)
1581 gtk_icon_view_layout (icon_view);
1583 cr = gdk_cairo_create (icon_view->priv->bin_window);
1584 cairo_set_line_width (cr, 1.);
1586 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1590 dest_index = gtk_tree_path_get_indices (path)[0];
1591 gtk_tree_path_free (path);
1596 for (icons = icon_view->priv->items; icons; icons = icons->next)
1598 GtkIconViewItem *item = icons->data;
1603 area.width = item->width;
1604 area.height = item->height;
1606 if (cairo_region_contains_rectangle (expose->region, &area) == CAIRO_REGION_OVERLAP_OUT)
1609 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1610 icon_view->priv->bin_window,
1612 icon_view->priv->draw_focus);
1614 if (dest_index == item->index)
1623 style = gtk_widget_get_style (widget);
1624 state = gtk_widget_get_state (widget);
1628 case GTK_ICON_VIEW_DROP_INTO:
1629 gtk_paint_focus (style, icon_view->priv->bin_window,
1632 "iconview-drop-indicator",
1633 dest_item->x, dest_item->y,
1634 dest_item->width, dest_item->height);
1636 case GTK_ICON_VIEW_DROP_ABOVE:
1637 gtk_paint_focus (style, icon_view->priv->bin_window,
1640 "iconview-drop-indicator",
1641 dest_item->x, dest_item->y - 1,
1642 dest_item->width, 2);
1644 case GTK_ICON_VIEW_DROP_LEFT:
1645 gtk_paint_focus (style, icon_view->priv->bin_window,
1648 "iconview-drop-indicator",
1649 dest_item->x - 1, dest_item->y,
1650 2, dest_item->height);
1652 case GTK_ICON_VIEW_DROP_BELOW:
1653 gtk_paint_focus (style, icon_view->priv->bin_window,
1656 "iconview-drop-indicator",
1657 dest_item->x, dest_item->y + dest_item->height - 1,
1658 dest_item->width, 2);
1660 case GTK_ICON_VIEW_DROP_RIGHT:
1661 gtk_paint_focus (style, icon_view->priv->bin_window,
1664 "iconview-drop-indicator",
1665 dest_item->x + dest_item->width - 1, dest_item->y,
1666 2, dest_item->height);
1667 case GTK_ICON_VIEW_NO_DROP: ;
1672 if (icon_view->priv->doing_rubberband)
1674 cairo_rectangle_int_t rectangle;
1677 n_rectangles = cairo_region_num_rectangles (expose->region);
1679 while (n_rectangles--)
1681 cairo_region_get_rectangle (expose->region, n_rectangles, &rectangle);
1682 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangle);
1688 GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event (widget, expose);
1694 rubberband_scroll_timeout (gpointer data)
1696 GtkIconView *icon_view = data;
1698 gtk_adjustment_set_value (icon_view->priv->vadjustment,
1699 icon_view->priv->vadjustment->value +
1700 icon_view->priv->scroll_value_diff);
1702 gtk_icon_view_update_rubberband (icon_view);
1708 gtk_icon_view_motion (GtkWidget *widget,
1709 GdkEventMotion *event)
1711 GtkAllocation allocation;
1712 GtkIconView *icon_view;
1715 icon_view = GTK_ICON_VIEW (widget);
1717 gtk_icon_view_maybe_begin_drag (icon_view, event);
1719 if (icon_view->priv->doing_rubberband)
1721 gtk_icon_view_update_rubberband (widget);
1723 abs_y = event->y - icon_view->priv->height *
1724 (icon_view->priv->vadjustment->value /
1725 (icon_view->priv->vadjustment->upper -
1726 icon_view->priv->vadjustment->lower));
1728 gtk_widget_get_allocation (widget, &allocation);
1730 if (abs_y < 0 || abs_y > allocation.height)
1733 icon_view->priv->scroll_value_diff = abs_y;
1735 icon_view->priv->scroll_value_diff = abs_y - allocation.height;
1737 icon_view->priv->event_last_x = event->x;
1738 icon_view->priv->event_last_y = event->y;
1740 if (icon_view->priv->scroll_timeout_id == 0)
1741 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1745 remove_scroll_timeout (icon_view);
1752 gtk_icon_view_remove (GtkContainer *container,
1755 GtkIconView *icon_view;
1756 GtkIconViewChild *child = NULL;
1759 icon_view = GTK_ICON_VIEW (container);
1761 tmp_list = icon_view->priv->children;
1764 child = tmp_list->data;
1765 if (child->widget == widget)
1767 gtk_widget_unparent (widget);
1769 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1770 g_list_free_1 (tmp_list);
1775 tmp_list = tmp_list->next;
1780 gtk_icon_view_forall (GtkContainer *container,
1781 gboolean include_internals,
1782 GtkCallback callback,
1783 gpointer callback_data)
1785 GtkIconView *icon_view;
1786 GtkIconViewChild *child = NULL;
1789 icon_view = GTK_ICON_VIEW (container);
1791 tmp_list = icon_view->priv->children;
1794 child = tmp_list->data;
1795 tmp_list = tmp_list->next;
1797 (* callback) (child->widget, callback_data);
1802 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1803 GtkIconViewItem *item,
1804 GtkIconViewCellInfo *info,
1809 GdkRectangle cell_area;
1810 gboolean visible, mode;
1812 gtk_icon_view_set_cell_data (icon_view, item);
1814 g_object_get (info->cell,
1815 "visible", &visible,
1819 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1821 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1823 path = gtk_tree_path_new_from_indices (item->index, -1);
1824 path_string = gtk_tree_path_to_string (path);
1825 gtk_tree_path_free (path);
1827 gtk_cell_renderer_activate (info->cell,
1829 GTK_WIDGET (icon_view),
1835 g_free (path_string);
1840 gtk_icon_view_item_selected_changed (GtkIconView *icon_view,
1841 GtkIconViewItem *item)
1844 AtkObject *item_obj;
1846 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
1849 item_obj = atk_object_ref_accessible_child (obj, item->index);
1850 if (item_obj != NULL)
1852 atk_object_notify_state_change (item_obj, ATK_STATE_SELECTED, item->selected);
1853 g_object_unref (item_obj);
1859 gtk_icon_view_put (GtkIconView *icon_view,
1861 GtkIconViewItem *item,
1864 GtkIconViewChild *child;
1866 child = g_new (GtkIconViewChild, 1);
1868 child->widget = widget;
1872 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1874 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
1875 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1877 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1881 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1882 GtkIconView *icon_view)
1885 GtkIconViewItem *item;
1887 if (icon_view->priv->edited_item == NULL)
1890 item = icon_view->priv->edited_item;
1891 icon_view->priv->edited_item = NULL;
1892 icon_view->priv->editable = NULL;
1893 for (l = icon_view->priv->cell_list; l; l = l->next)
1895 GtkIconViewCellInfo *info = l->data;
1897 info->editing = FALSE;
1900 if (gtk_widget_has_focus (GTK_WIDGET (editable)))
1901 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1903 g_signal_handlers_disconnect_by_func (editable,
1904 gtk_icon_view_remove_widget,
1907 gtk_container_remove (GTK_CONTAINER (icon_view),
1908 GTK_WIDGET (editable));
1910 gtk_icon_view_queue_draw_item (icon_view, item);
1915 gtk_icon_view_start_editing (GtkIconView *icon_view,
1916 GtkIconViewItem *item,
1917 GtkIconViewCellInfo *info,
1922 GdkRectangle cell_area;
1923 gboolean visible, mode;
1924 GtkCellEditable *editable;
1926 gtk_icon_view_set_cell_data (icon_view, item);
1928 g_object_get (info->cell,
1929 "visible", &visible,
1932 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1934 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1936 path = gtk_tree_path_new_from_indices (item->index, -1);
1937 path_string = gtk_tree_path_to_string (path);
1938 gtk_tree_path_free (path);
1940 editable = gtk_cell_renderer_start_editing (info->cell,
1942 GTK_WIDGET (icon_view),
1947 g_free (path_string);
1949 /* the rest corresponds to tree_view_real_start_editing... */
1950 icon_view->priv->edited_item = item;
1951 icon_view->priv->editable = editable;
1952 info->editing = TRUE;
1954 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1956 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1958 gtk_widget_grab_focus (GTK_WIDGET (editable));
1959 g_signal_connect (editable, "remove-widget",
1960 G_CALLBACK (gtk_icon_view_remove_widget),
1967 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1968 gboolean cancel_editing)
1970 GtkCellRenderer *cell = NULL;
1971 GtkIconViewItem *item;
1974 if (icon_view->priv->edited_item == NULL)
1978 * This is very evil. We need to do this, because
1979 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1980 * later on. If gtk_icon_view_row_changed notices
1981 * icon_view->priv->edited_item != NULL, it'll call
1982 * gtk_icon_view_stop_editing again. Bad things will happen then.
1984 * Please read that again if you intend to modify anything here.
1987 item = icon_view->priv->edited_item;
1988 icon_view->priv->edited_item = NULL;
1990 for (l = icon_view->priv->cell_list; l; l = l->next)
1992 GtkIconViewCellInfo *info = l->data;
2004 gtk_cell_renderer_stop_editing (cell, cancel_editing);
2005 if (!cancel_editing)
2006 gtk_cell_editable_editing_done (icon_view->priv->editable);
2008 icon_view->priv->edited_item = item;
2010 gtk_cell_editable_remove_widget (icon_view->priv->editable);
2014 * gtk_icon_view_set_cursor:
2015 * @icon_view: A #GtkIconView
2016 * @path: A #GtkTreePath
2017 * @cell: (allow-none): One of the cell renderers of @icon_view, or %NULL
2018 * @start_editing: %TRUE if the specified cell should start being edited.
2020 * Sets the current keyboard focus to be at @path, and selects it. This is
2021 * useful when you want to focus the user's attention on a particular item.
2022 * If @cell is not %NULL, then focus is given to the cell specified by
2023 * it. Additionally, if @start_editing is %TRUE, then editing should be
2024 * started in the specified cell.
2026 * This function is often followed by <literal>gtk_widget_grab_focus
2027 * (icon_view)</literal> in order to give keyboard focus to the widget.
2028 * Please note that editing can only happen when the widget is realized.
2033 gtk_icon_view_set_cursor (GtkIconView *icon_view,
2035 GtkCellRenderer *cell,
2036 gboolean start_editing)
2038 GtkIconViewItem *item = NULL;
2039 GtkIconViewCellInfo *info = NULL;
2043 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
2044 g_return_if_fail (path != NULL);
2045 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
2047 gtk_icon_view_stop_editing (icon_view, TRUE);
2049 if (gtk_tree_path_get_depth (path) == 1)
2050 item = g_list_nth_data (icon_view->priv->items,
2051 gtk_tree_path_get_indices(path)[0]);
2057 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2061 if (info->cell == cell)
2070 g_return_if_fail (cell == NULL || info != NULL);
2072 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
2073 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
2075 if (info && start_editing)
2076 gtk_icon_view_start_editing (icon_view, item, info, NULL);
2080 * gtk_icon_view_get_cursor:
2081 * @icon_view: A #GtkIconView
2082 * @path: (allow-none): Return location for the current cursor path, or %NULL
2083 * @cell: (allow-none): Return location the current focus cell, or %NULL
2085 * Fills in @path and @cell with the current cursor path and cell.
2086 * If the cursor isn't currently set, then *@path will be %NULL.
2087 * If no cell currently has focus, then *@cell will be %NULL.
2089 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
2091 * Return value: %TRUE if the cursor is set.
2096 gtk_icon_view_get_cursor (GtkIconView *icon_view,
2098 GtkCellRenderer **cell)
2100 GtkIconViewItem *item;
2101 GtkIconViewCellInfo *info;
2103 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
2105 item = icon_view->priv->cursor_item;
2106 if (icon_view->priv->cursor_cell < 0)
2109 info = g_list_nth_data (icon_view->priv->cell_list,
2110 icon_view->priv->cursor_cell);
2115 *path = gtk_tree_path_new_from_indices (item->index, -1);
2128 return (item != NULL);
2132 gtk_icon_view_button_press (GtkWidget *widget,
2133 GdkEventButton *event)
2135 GtkIconView *icon_view;
2136 GtkIconViewItem *item;
2137 GtkIconViewCellInfo *info = NULL;
2138 gboolean dirty = FALSE;
2139 GtkCellRendererMode mode;
2140 gint cursor_cell = -1;
2142 icon_view = GTK_ICON_VIEW (widget);
2144 if (event->window != icon_view->priv->bin_window)
2147 if (!gtk_widget_has_focus (widget))
2148 gtk_widget_grab_focus (widget);
2150 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2152 item = gtk_icon_view_get_item_at_coords (icon_view,
2158 * We consider only the the cells' area as the item area if the
2159 * item is not selected, but if it *is* selected, the complete
2160 * selection rectangle is considered to be part of the item.
2162 if (item != NULL && (info != NULL || item->selected))
2166 g_object_get (info->cell, "mode", &mode, NULL);
2168 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
2169 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2170 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
2173 gtk_icon_view_scroll_to_item (icon_view, item);
2175 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2177 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2179 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
2180 (event->state & GDK_SHIFT_MASK))
2182 gtk_icon_view_unselect_all_internal (icon_view);
2184 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2185 if (!icon_view->priv->anchor_item)
2186 icon_view->priv->anchor_item = item;
2188 gtk_icon_view_select_all_between (icon_view,
2189 icon_view->priv->anchor_item,
2195 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2196 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2197 (event->state & GDK_CONTROL_MASK))
2199 item->selected = !item->selected;
2200 gtk_icon_view_queue_draw_item (icon_view, item);
2205 gtk_icon_view_unselect_all_internal (icon_view);
2207 item->selected = TRUE;
2208 gtk_icon_view_queue_draw_item (icon_view, item);
2211 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2212 icon_view->priv->anchor_item = item;
2215 /* Save press to possibly begin a drag */
2216 if (icon_view->priv->pressed_button < 0)
2218 icon_view->priv->pressed_button = event->button;
2219 icon_view->priv->press_start_x = event->x;
2220 icon_view->priv->press_start_y = event->y;
2223 if (!icon_view->priv->last_single_clicked)
2224 icon_view->priv->last_single_clicked = item;
2226 /* cancel the current editing, if it exists */
2227 gtk_icon_view_stop_editing (icon_view, TRUE);
2231 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2232 gtk_icon_view_item_activate_cell (icon_view, item, info,
2234 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2235 gtk_icon_view_start_editing (icon_view, item, info,
2241 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2242 !(event->state & GDK_CONTROL_MASK))
2244 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2247 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2248 gtk_icon_view_start_rubberbanding (icon_view, event->device, event->x, event->y);
2251 /* don't draw keyboard focus around an clicked-on item */
2252 icon_view->priv->draw_focus = FALSE;
2255 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2257 item = gtk_icon_view_get_item_at_coords (icon_view,
2262 if (item && item == icon_view->priv->last_single_clicked)
2266 path = gtk_tree_path_new_from_indices (item->index, -1);
2267 gtk_icon_view_item_activated (icon_view, path);
2268 gtk_tree_path_free (path);
2271 icon_view->priv->last_single_clicked = NULL;
2272 icon_view->priv->pressed_button = -1;
2276 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2278 return event->button == 1;
2282 gtk_icon_view_button_release (GtkWidget *widget,
2283 GdkEventButton *event)
2285 GtkIconView *icon_view;
2287 icon_view = GTK_ICON_VIEW (widget);
2289 if (icon_view->priv->pressed_button == event->button)
2290 icon_view->priv->pressed_button = -1;
2292 gtk_icon_view_stop_rubberbanding (icon_view);
2294 remove_scroll_timeout (icon_view);
2300 gtk_icon_view_key_press (GtkWidget *widget,
2303 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2305 if (icon_view->priv->doing_rubberband)
2307 if (event->keyval == GDK_KEY_Escape)
2308 gtk_icon_view_stop_rubberbanding (icon_view);
2313 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2317 gtk_icon_view_key_release (GtkWidget *widget,
2320 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2322 if (icon_view->priv->doing_rubberband)
2325 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event (widget, event);
2329 gtk_icon_view_update_rubberband (gpointer data)
2331 GtkIconView *icon_view;
2333 GdkRectangle old_area;
2334 GdkRectangle new_area;
2335 GdkRectangle common;
2336 cairo_region_t *invalid_region;
2338 icon_view = GTK_ICON_VIEW (data);
2340 gdk_window_get_device_position (icon_view->priv->bin_window,
2341 icon_view->priv->rubberband_device,
2347 old_area.x = MIN (icon_view->priv->rubberband_x1,
2348 icon_view->priv->rubberband_x2);
2349 old_area.y = MIN (icon_view->priv->rubberband_y1,
2350 icon_view->priv->rubberband_y2);
2351 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2352 icon_view->priv->rubberband_x1) + 1;
2353 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2354 icon_view->priv->rubberband_y1) + 1;
2356 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2357 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2358 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2359 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2361 invalid_region = cairo_region_create_rectangle (&old_area);
2362 cairo_region_union_rectangle (invalid_region, &new_area);
2364 gdk_rectangle_intersect (&old_area, &new_area, &common);
2365 if (common.width > 2 && common.height > 2)
2367 cairo_region_t *common_region;
2369 /* make sure the border is invalidated */
2375 common_region = cairo_region_create_rectangle (&common);
2377 cairo_region_subtract (invalid_region, common_region);
2378 cairo_region_destroy (common_region);
2381 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2383 cairo_region_destroy (invalid_region);
2385 icon_view->priv->rubberband_x2 = x;
2386 icon_view->priv->rubberband_y2 = y;
2388 gtk_icon_view_update_rubberband_selection (icon_view);
2392 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2399 if (icon_view->priv->rubberband_device)
2402 for (items = icon_view->priv->items; items; items = items->next)
2404 GtkIconViewItem *item = items->data;
2406 item->selected_before_rubberbanding = item->selected;
2409 icon_view->priv->rubberband_x1 = x;
2410 icon_view->priv->rubberband_y1 = y;
2411 icon_view->priv->rubberband_x2 = x;
2412 icon_view->priv->rubberband_y2 = y;
2414 icon_view->priv->doing_rubberband = TRUE;
2415 icon_view->priv->rubberband_device = device;
2417 gtk_device_grab_add (GTK_WIDGET (icon_view), device, TRUE);
2421 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2423 if (!icon_view->priv->doing_rubberband)
2426 gtk_device_grab_remove (GTK_WIDGET (icon_view),
2427 icon_view->priv->rubberband_device);
2429 icon_view->priv->doing_rubberband = FALSE;
2430 icon_view->priv->rubberband_device = NULL;
2432 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2436 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2439 gint x, y, width, height;
2440 gboolean dirty = FALSE;
2442 x = MIN (icon_view->priv->rubberband_x1,
2443 icon_view->priv->rubberband_x2);
2444 y = MIN (icon_view->priv->rubberband_y1,
2445 icon_view->priv->rubberband_y2);
2446 width = ABS (icon_view->priv->rubberband_x1 -
2447 icon_view->priv->rubberband_x2);
2448 height = ABS (icon_view->priv->rubberband_y1 -
2449 icon_view->priv->rubberband_y2);
2451 for (items = icon_view->priv->items; items; items = items->next)
2453 GtkIconViewItem *item = items->data;
2457 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2458 x, y, width, height);
2460 selected = is_in ^ item->selected_before_rubberbanding;
2462 if (item->selected != selected)
2464 item->selected = selected;
2466 gtk_icon_view_queue_draw_item (icon_view, item);
2471 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2475 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2476 GtkIconViewItem *item,
2485 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2486 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2489 for (l = icon_view->priv->cell_list; l; l = l->next)
2491 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2493 if (!gtk_cell_renderer_get_visible (info->cell))
2496 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2498 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2499 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2507 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2509 gboolean dirty = FALSE;
2512 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2515 for (items = icon_view->priv->items; items; items = items->next)
2517 GtkIconViewItem *item = items->data;
2521 item->selected = FALSE;
2523 gtk_icon_view_queue_draw_item (icon_view, item);
2524 gtk_icon_view_item_selected_changed (icon_view, item);
2532 /* GtkIconView signals */
2534 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2535 GtkAdjustment *hadj,
2536 GtkAdjustment *vadj)
2538 gboolean need_adjust = FALSE;
2541 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2543 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2545 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2547 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2549 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2551 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2552 0, 0, NULL, NULL, icon_view);
2553 g_object_unref (icon_view->priv->hadjustment);
2556 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2558 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2559 0, 0, NULL, NULL, icon_view);
2560 g_object_unref (icon_view->priv->vadjustment);
2563 if (icon_view->priv->hadjustment != hadj)
2565 icon_view->priv->hadjustment = hadj;
2566 g_object_ref_sink (icon_view->priv->hadjustment);
2568 g_signal_connect (icon_view->priv->hadjustment, "value-changed",
2569 G_CALLBACK (gtk_icon_view_adjustment_changed),
2574 if (icon_view->priv->vadjustment != vadj)
2576 icon_view->priv->vadjustment = vadj;
2577 g_object_ref_sink (icon_view->priv->vadjustment);
2579 g_signal_connect (icon_view->priv->vadjustment, "value-changed",
2580 G_CALLBACK (gtk_icon_view_adjustment_changed),
2586 gtk_icon_view_adjustment_changed (NULL, icon_view);
2590 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2592 gtk_icon_view_select_all (icon_view);
2596 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2598 gtk_icon_view_unselect_all (icon_view);
2602 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2604 gtk_icon_view_unselect_all (icon_view);
2606 if (icon_view->priv->cursor_item != NULL)
2607 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2611 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2614 GtkCellRendererMode mode;
2615 GtkIconViewCellInfo *info = NULL;
2617 if (!icon_view->priv->cursor_item)
2620 info = g_list_nth_data (icon_view->priv->cell_list,
2621 icon_view->priv->cursor_cell);
2625 g_object_get (info->cell, "mode", &mode, NULL);
2627 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2629 gtk_icon_view_item_activate_cell (icon_view,
2630 icon_view->priv->cursor_item,
2634 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2636 gtk_icon_view_start_editing (icon_view,
2637 icon_view->priv->cursor_item,
2643 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2644 gtk_icon_view_item_activated (icon_view, path);
2645 gtk_tree_path_free (path);
2651 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2653 if (!icon_view->priv->cursor_item)
2656 switch (icon_view->priv->selection_mode)
2658 case GTK_SELECTION_NONE:
2660 case GTK_SELECTION_BROWSE:
2661 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2663 case GTK_SELECTION_SINGLE:
2664 if (icon_view->priv->cursor_item->selected)
2665 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2667 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2669 case GTK_SELECTION_MULTIPLE:
2670 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2671 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2673 gtk_icon_view_item_selected_changed (icon_view, icon_view->priv->cursor_item);
2674 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2679 /* Internal functions */
2681 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2682 GtkIconView *icon_view)
2684 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2686 gdk_window_move (icon_view->priv->bin_window,
2687 - icon_view->priv->hadjustment->value,
2688 - icon_view->priv->vadjustment->value);
2690 if (icon_view->priv->doing_rubberband)
2691 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2693 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2698 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2703 gint *maximum_width)
2705 GtkAllocation allocation;
2706 GtkWidget *widget = GTK_WIDGET (icon_view);
2708 gint x, current_width;
2709 GList *items, *last_item;
2716 rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
2717 max_height = g_new0 (gint, icon_view->priv->n_cells);
2724 gtk_widget_style_get (widget,
2725 "focus-line-width", &focus_width,
2728 x += icon_view->priv->margin + focus_width;
2729 current_width += 2 * (icon_view->priv->margin + focus_width);
2734 GtkIconViewItem *item = items->data;
2736 gtk_icon_view_calculate_item_size (icon_view, item);
2737 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2739 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2741 current_width += item->width;
2743 if (items != first_item)
2745 gtk_widget_get_allocation (widget, &allocation);
2747 if ((icon_view->priv->columns <= 0 && current_width > allocation.width) ||
2748 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2752 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2754 item->y = *y + focus_width;
2757 x = current_width - (icon_view->priv->margin + focus_width);
2759 for (i = 0; i < icon_view->priv->n_cells; i++)
2760 max_height[i] = MAX (max_height[i], item->box[i].height);
2762 if (current_width > *maximum_width)
2763 *maximum_width = current_width;
2769 items = items->next;
2774 /* Now go through the row again and align the icons */
2775 for (items = first_item; items != last_item; items = items->next)
2777 GtkIconViewItem *item = items->data;
2781 item->x = *maximum_width - item->width - item->x;
2782 item->col = col - 1 - item->col;
2785 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2787 /* We may want to readjust the new y coordinate. */
2788 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2789 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2792 g_free (max_height);
2798 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2801 if (upper != adj->upper)
2803 gdouble min = MAX (0.0, upper - adj->page_size);
2804 gboolean value_changed = FALSE;
2808 if (adj->value > min)
2811 value_changed = TRUE;
2814 gtk_adjustment_changed (adj);
2817 gtk_adjustment_value_changed (adj);
2822 gtk_icon_view_layout (GtkIconView *icon_view)
2824 GtkAllocation allocation;
2827 gint y = 0, maximum_width = 0;
2830 gboolean size_changed = FALSE;
2832 if (icon_view->priv->layout_idle_id != 0)
2834 g_source_remove (icon_view->priv->layout_idle_id);
2835 icon_view->priv->layout_idle_id = 0;
2838 if (icon_view->priv->model == NULL)
2841 widget = GTK_WIDGET (icon_view);
2843 item_width = icon_view->priv->item_width;
2847 for (icons = icon_view->priv->items; icons; icons = icons->next)
2849 GtkIconViewItem *item = icons->data;
2850 gtk_icon_view_calculate_item_size (icon_view, item);
2851 item_width = MAX (item_width, item->width);
2856 icons = icon_view->priv->items;
2857 y += icon_view->priv->margin;
2862 gtk_icon_view_set_cell_data (icon_view, icons->data);
2863 adjust_wrap_width (icon_view, icons->data);
2868 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2870 &y, &maximum_width);
2873 while (icons != NULL);
2875 if (maximum_width != icon_view->priv->width)
2877 icon_view->priv->width = maximum_width;
2878 size_changed = TRUE;
2881 y += icon_view->priv->margin;
2883 if (y != icon_view->priv->height)
2885 icon_view->priv->height = y;
2886 size_changed = TRUE;
2889 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2890 icon_view->priv->width);
2891 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2892 icon_view->priv->height);
2895 gtk_widget_queue_resize_no_redraw (widget);
2897 gtk_widget_get_allocation (widget, &allocation);
2898 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
2899 gdk_window_resize (icon_view->priv->bin_window,
2900 MAX (icon_view->priv->width, allocation.width),
2901 MAX (icon_view->priv->height, allocation.height));
2903 if (icon_view->priv->scroll_to_path)
2907 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2908 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2909 icon_view->priv->scroll_to_path = NULL;
2911 gtk_icon_view_scroll_to_path (icon_view, path,
2912 icon_view->priv->scroll_to_use_align,
2913 icon_view->priv->scroll_to_row_align,
2914 icon_view->priv->scroll_to_col_align);
2915 gtk_tree_path_free (path);
2918 gtk_widget_queue_draw (widget);
2922 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2923 GtkIconViewItem *item,
2924 GtkIconViewCellInfo *info,
2925 GdkRectangle *cell_area)
2927 g_return_if_fail (info->position < item->n_cells);
2929 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
2931 cell_area->x = item->box[info->position].x - item->before[info->position];
2932 cell_area->y = item->y + icon_view->priv->item_padding;
2933 cell_area->width = item->box[info->position].width +
2934 item->before[info->position] + item->after[info->position];
2935 cell_area->height = item->height - icon_view->priv->item_padding * 2;
2939 cell_area->x = item->x + icon_view->priv->item_padding;
2940 cell_area->y = item->box[info->position].y - item->before[info->position];
2941 cell_area->width = item->width - icon_view->priv->item_padding * 2;
2942 cell_area->height = item->box[info->position].height +
2943 item->before[info->position] + item->after[info->position];
2948 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2949 GtkIconViewItem *item,
2950 GtkIconViewCellInfo *info,
2953 g_return_if_fail (info->position < item->n_cells);
2955 *box = item->box[info->position];
2958 /* try to guess a reasonable wrap width for an implicit text cell renderer
2961 adjust_wrap_width (GtkIconView *icon_view,
2962 GtkIconViewItem *item)
2964 GtkIconViewCellInfo *text_info;
2965 GtkIconViewCellInfo *pixbuf_info;
2968 if (icon_view->priv->text_cell != -1 &&
2969 icon_view->priv->pixbuf_cell != -1)
2971 GtkRequisition min_size;
2974 text_info = g_list_nth_data (icon_view->priv->cell_list,
2975 icon_view->priv->text_cell);
2976 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2977 icon_view->priv->pixbuf_cell);
2979 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (pixbuf_info->cell),
2980 GTK_WIDGET (icon_view),
2983 if (icon_view->priv->item_width > 0)
2984 item_width = icon_view->priv->item_width;
2986 item_width = item->width;
2988 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
2989 wrap_width = item_width;
2991 if (item->width == -1 && item_width <= 0)
2992 wrap_width = MAX (2 * min_size.width, 50);
2994 wrap_width = item_width - min_size.width - icon_view->priv->spacing;
2997 wrap_width -= icon_view->priv->item_padding * 2;
2999 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
3000 g_object_set (text_info->cell, "width", wrap_width, NULL);
3005 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
3006 GtkIconViewItem *item)
3008 GtkRequisition min_size;
3012 if (item->width != -1 && item->height != -1)
3015 if (item->n_cells != icon_view->priv->n_cells)
3017 g_free (item->before);
3018 g_free (item->after);
3021 item->before = g_new0 (gint, icon_view->priv->n_cells);
3022 item->after = g_new0 (gint, icon_view->priv->n_cells);
3023 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
3025 item->n_cells = icon_view->priv->n_cells;
3028 gtk_icon_view_set_cell_data (icon_view, item);
3030 spacing = icon_view->priv->spacing;
3034 for (l = icon_view->priv->cell_list; l; l = l->next)
3036 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3038 if (!gtk_cell_renderer_get_visible (info->cell))
3041 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
3042 GTK_WIDGET (icon_view),
3044 item->box[info->position].width = min_size.width;
3045 item->box[info->position].height = min_size.height;
3047 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3049 item->width += item->box[info->position].width
3050 + (info->position > 0 ? spacing : 0);
3051 item->height = MAX (item->height, item->box[info->position].height);
3055 item->width = MAX (item->width, item->box[info->position].width);
3056 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
3060 item->width += icon_view->priv->item_padding * 2;
3061 item->height += icon_view->priv->item_padding * 2;
3065 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
3066 GtkIconViewItem *item,
3069 GtkRequisition min_size;
3070 GdkRectangle cell_area;
3076 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
3078 gtk_icon_view_set_cell_data (icon_view, item);
3080 spacing = icon_view->priv->spacing;
3083 for (i = 0; i < icon_view->priv->n_cells; i++)
3085 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3086 item->height = MAX (item->height, max_height[i]);
3088 item->height += max_height[i] + (i > 0 ? spacing : 0);
3091 cell_area.x = item->x + icon_view->priv->item_padding;
3092 cell_area.y = item->y + icon_view->priv->item_padding;
3094 for (k = 0; k < 2; k++)
3095 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3097 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3099 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3102 if (!gtk_cell_renderer_get_visible (info->cell))
3105 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3107 /* We should not subtract icon_view->priv->item_padding from item->height,
3108 * because item->height is recalculated above using
3109 * max_height which does not contain item padding.
3111 cell_area.width = item->box[info->position].width;
3112 cell_area.height = item->height;
3116 /* item->width is not recalculated and thus needs to be
3117 * corrected for the padding.
3119 cell_area.width = item->width - 2 * icon_view->priv->item_padding;
3120 cell_area.height = max_height[i];
3123 gtk_cell_size_request_get_size (GTK_CELL_SIZE_REQUEST (info->cell),
3124 GTK_WIDGET (icon_view),
3126 item->box[info->position].width = min_size.width;
3127 item->box[info->position].height = min_size.height;
3129 _gtk_cell_renderer_calc_offset (info->cell, &cell_area,
3130 gtk_widget_get_direction (GTK_WIDGET (icon_view)),
3131 item->box[info->position].width, item->box[info->position].height,
3132 &item->box[info->position].x, &item->box[info->position].y);
3133 item->box[info->position].x += cell_area.x;
3134 item->box[info->position].y += cell_area.y;
3136 if (icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3138 item->before[info->position] = item->box[info->position].x - cell_area.x;
3139 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
3140 cell_area.x += cell_area.width + spacing;
3144 if (item->box[info->position].width > item->width - icon_view->priv->item_padding * 2)
3146 item->width = item->box[info->position].width + icon_view->priv->item_padding * 2;
3147 cell_area.width = item->width;
3149 item->before[info->position] = item->box[info->position].y - cell_area.y;
3150 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
3151 cell_area.y += cell_area.height + spacing;
3155 if (rtl && icon_view->priv->item_orientation == GTK_ORIENTATION_HORIZONTAL)
3157 for (i = 0; i < icon_view->priv->n_cells; i++)
3159 item->box[i].x = item->x + item->width -
3160 (item->box[i].x + item->box[i].width - item->x);
3164 item->height += icon_view->priv->item_padding * 2;
3168 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
3170 g_list_foreach (icon_view->priv->items,
3171 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
3175 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
3182 gtk_icon_view_paint_item (GtkIconView *icon_view,
3184 GtkIconViewItem *item,
3186 GdkDrawable *drawable,
3189 gboolean draw_focus)
3193 GdkRectangle cell_area, box;
3197 GtkCellRendererState flags;
3199 GtkWidget *widget = GTK_WIDGET (icon_view);
3201 if (icon_view->priv->model == NULL)
3204 gtk_icon_view_set_cell_data (icon_view, item);
3206 style = gtk_widget_get_style (widget);
3207 gtk_widget_style_get (widget,
3208 "focus-line-width", &focus_width,
3211 padding = focus_width;
3215 flags = GTK_CELL_RENDERER_SELECTED;
3216 if (gtk_widget_has_focus (widget))
3217 state = GTK_STATE_SELECTED;
3219 state = GTK_STATE_ACTIVE;
3224 state = GTK_STATE_NORMAL;
3229 gtk_paint_flat_box (style,
3230 GDK_WINDOW (drawable),
3237 item->width, item->height);
3240 for (l = icon_view->priv->cell_list; l; l = l->next)
3242 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3244 if (!gtk_cell_renderer_get_visible (info->cell))
3247 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3249 cell_area.x = x - item->x + cell_area.x;
3250 cell_area.y = y - item->y + cell_area.y;
3252 gtk_cell_renderer_render (info->cell,
3255 &cell_area, &cell_area, area, flags);
3259 gtk_widget_has_focus (widget) &&
3260 item == icon_view->priv->cursor_item)
3262 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3264 GtkCellRendererMode mode;
3265 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3267 if (!gtk_cell_renderer_get_visible (info->cell))
3270 /* If found a editable/activatable cell, draw focus on it. */
3271 g_object_get (info->cell, "mode", &mode, NULL);
3272 if (icon_view->priv->cursor_cell < 0 &&
3273 mode != GTK_CELL_RENDERER_MODE_INERT)
3274 icon_view->priv->cursor_cell = i;
3276 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3278 if (i == icon_view->priv->cursor_cell)
3280 gtk_paint_focus (style,
3286 x - item->x + box.x - padding,
3287 y - item->y + box.y - padding,
3288 box.width + 2 * padding,
3289 box.height + 2 * padding);
3294 /* If there are no editable/activatable cells, draw focus
3295 * around the whole item.
3297 if (icon_view->priv->cursor_cell < 0)
3298 gtk_paint_focus (style,
3306 item->width + 2 * padding,
3307 item->height + 2 * padding);
3312 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3317 GdkRectangle rubber_rect;
3318 GdkColor *fill_color_gdk;
3319 guchar fill_color_alpha;
3321 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3322 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3323 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3324 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3326 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3329 gtk_widget_style_get (GTK_WIDGET (icon_view),
3330 "selection-box-color", &fill_color_gdk,
3331 "selection-box-alpha", &fill_color_alpha,
3334 if (!fill_color_gdk)
3335 fill_color_gdk = gdk_color_copy (>k_widget_get_style (GTK_WIDGET (icon_view))->base[GTK_STATE_SELECTED]);
3337 cairo_set_source_rgba (cr,
3338 fill_color_gdk->red / 65535.,
3339 fill_color_gdk->green / 65535.,
3340 fill_color_gdk->blue / 65535.,
3341 fill_color_alpha / 255.);
3344 gdk_cairo_rectangle (cr, &rect);
3348 /* Draw the border without alpha */
3349 cairo_set_source_rgb (cr,
3350 fill_color_gdk->red / 65535.,
3351 fill_color_gdk->green / 65535.,
3352 fill_color_gdk->blue / 65535.);
3353 cairo_rectangle (cr,
3354 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3355 rubber_rect.width - 1, rubber_rect.height - 1);
3359 gdk_color_free (fill_color_gdk);
3363 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3369 index = gtk_tree_path_get_indices (path)[0];
3371 for (l = icon_view->priv->items; l; l = l->next)
3373 GtkIconViewItem *item = l->data;
3375 if (item->index == index)
3377 gtk_icon_view_queue_draw_item (icon_view, item);
3384 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3385 GtkIconViewItem *item)
3390 gtk_widget_style_get (GTK_WIDGET (icon_view),
3391 "focus-line-width", &focus_width,
3394 rect.x = item->x - focus_width;
3395 rect.y = item->y - focus_width;
3396 rect.width = item->width + 2 * focus_width;
3397 rect.height = item->height + 2 * focus_width;
3399 if (icon_view->priv->bin_window)
3400 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3404 layout_callback (gpointer user_data)
3406 GtkIconView *icon_view;
3408 icon_view = GTK_ICON_VIEW (user_data);
3410 icon_view->priv->layout_idle_id = 0;
3412 gtk_icon_view_layout (icon_view);
3418 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3420 if (icon_view->priv->layout_idle_id != 0)
3423 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3427 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3428 GtkIconViewItem *item,
3432 AtkObject *item_obj;
3433 AtkObject *cursor_item_obj;
3435 if (icon_view->priv->cursor_item == item &&
3436 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3439 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3440 if (icon_view->priv->cursor_item != NULL)
3442 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3445 cursor_item_obj = atk_object_ref_accessible_child (obj, icon_view->priv->cursor_item->index);
3446 if (cursor_item_obj != NULL)
3447 atk_object_notify_state_change (cursor_item_obj, ATK_STATE_FOCUSED, FALSE);
3450 icon_view->priv->cursor_item = item;
3451 if (cursor_cell >= 0)
3452 icon_view->priv->cursor_cell = cursor_cell;
3454 gtk_icon_view_queue_draw_item (icon_view, item);
3456 /* Notify that accessible focus object has changed */
3457 item_obj = atk_object_ref_accessible_child (obj, item->index);
3459 if (item_obj != NULL)
3461 atk_focus_tracker_notify (item_obj);
3462 atk_object_notify_state_change (item_obj, ATK_STATE_FOCUSED, TRUE);
3463 g_object_unref (item_obj);
3468 static GtkIconViewItem *
3469 gtk_icon_view_item_new (void)
3471 GtkIconViewItem *item;
3473 item = g_new0 (GtkIconViewItem, 1);
3482 gtk_icon_view_item_free (GtkIconViewItem *item)
3484 g_return_if_fail (item != NULL);
3486 g_free (item->before);
3487 g_free (item->after);
3494 static GtkIconViewItem *
3495 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3498 gboolean only_in_cell,
3499 GtkIconViewCellInfo **cell_at_pos)
3505 *cell_at_pos = NULL;
3507 for (items = icon_view->priv->items; items; items = items->next)
3509 GtkIconViewItem *item = items->data;
3511 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3512 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3514 if (only_in_cell || cell_at_pos)
3516 gtk_icon_view_set_cell_data (icon_view, item);
3518 for (l = icon_view->priv->cell_list; l; l = l->next)
3520 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3522 if (!gtk_cell_renderer_get_visible (info->cell))
3525 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3527 if ((x >= box.x && x <= box.x + box.width &&
3528 y >= box.y && y <= box.y + box.height) ||
3530 x <= box.x + box.width &&
3532 y <= box.y + box.height))
3535 *cell_at_pos = info;
3553 gtk_icon_view_select_item (GtkIconView *icon_view,
3554 GtkIconViewItem *item)
3556 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3557 g_return_if_fail (item != NULL);
3562 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3564 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3565 gtk_icon_view_unselect_all_internal (icon_view);
3567 item->selected = TRUE;
3569 gtk_icon_view_item_selected_changed (icon_view, item);
3570 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3572 gtk_icon_view_queue_draw_item (icon_view, item);
3577 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3578 GtkIconViewItem *item)
3580 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3581 g_return_if_fail (item != NULL);
3583 if (!item->selected)
3586 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3587 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3590 item->selected = FALSE;
3592 gtk_icon_view_item_selected_changed (icon_view, item);
3593 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3595 gtk_icon_view_queue_draw_item (icon_view, item);
3599 verify_items (GtkIconView *icon_view)
3604 for (items = icon_view->priv->items; items; items = items->next)
3606 GtkIconViewItem *item = items->data;
3608 if (item->index != i)
3609 g_error ("List item does not match its index: "
3610 "item index %d and list index %d\n", item->index, i);
3617 gtk_icon_view_row_changed (GtkTreeModel *model,
3622 GtkIconViewItem *item;
3624 GtkIconView *icon_view;
3626 icon_view = GTK_ICON_VIEW (data);
3628 gtk_icon_view_stop_editing (icon_view, TRUE);
3630 index = gtk_tree_path_get_indices(path)[0];
3631 item = g_list_nth_data (icon_view->priv->items, index);
3633 gtk_icon_view_item_invalidate_size (item);
3634 gtk_icon_view_queue_layout (icon_view);
3636 verify_items (icon_view);
3640 gtk_icon_view_row_inserted (GtkTreeModel *model,
3646 GtkIconViewItem *item;
3647 gboolean iters_persist;
3648 GtkIconView *icon_view;
3651 icon_view = GTK_ICON_VIEW (data);
3653 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3655 index = gtk_tree_path_get_indices(path)[0];
3657 item = gtk_icon_view_item_new ();
3662 item->index = index;
3664 /* FIXME: We can be more efficient here,
3665 we can store a tail pointer and use that when
3666 appending (which is a rather common operation)
3668 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3671 list = g_list_nth (icon_view->priv->items, index + 1);
3672 for (; list; list = list->next)
3679 verify_items (icon_view);
3681 gtk_icon_view_queue_layout (icon_view);
3685 gtk_icon_view_row_deleted (GtkTreeModel *model,
3690 GtkIconView *icon_view;
3691 GtkIconViewItem *item;
3693 gboolean emit = FALSE;
3695 icon_view = GTK_ICON_VIEW (data);
3697 index = gtk_tree_path_get_indices(path)[0];
3699 list = g_list_nth (icon_view->priv->items, index);
3702 gtk_icon_view_stop_editing (icon_view, TRUE);
3704 if (item == icon_view->priv->anchor_item)
3705 icon_view->priv->anchor_item = NULL;
3707 if (item == icon_view->priv->cursor_item)
3708 icon_view->priv->cursor_item = NULL;
3713 gtk_icon_view_item_free (item);
3715 for (next = list->next; next; next = next->next)
3722 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3724 verify_items (icon_view);
3726 gtk_icon_view_queue_layout (icon_view);
3729 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3733 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3734 GtkTreePath *parent,
3741 GtkIconView *icon_view;
3742 GList *items = NULL, *list;
3743 GtkIconViewItem **item_array;
3746 icon_view = GTK_ICON_VIEW (data);
3748 gtk_icon_view_stop_editing (icon_view, TRUE);
3750 length = gtk_tree_model_iter_n_children (model, NULL);
3752 order = g_new (gint, length);
3753 for (i = 0; i < length; i++)
3754 order [new_order[i]] = i;
3756 item_array = g_new (GtkIconViewItem *, length);
3757 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3758 item_array[order[i]] = list->data;
3761 for (i = length - 1; i >= 0; i--)
3763 item_array[i]->index = i;
3764 items = g_list_prepend (items, item_array[i]);
3767 g_free (item_array);
3768 g_list_free (icon_view->priv->items);
3769 icon_view->priv->items = items;
3771 gtk_icon_view_queue_layout (icon_view);
3773 verify_items (icon_view);
3777 gtk_icon_view_build_items (GtkIconView *icon_view)
3781 gboolean iters_persist;
3782 GList *items = NULL;
3784 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3786 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3794 GtkIconViewItem *item = gtk_icon_view_item_new ();
3803 items = g_list_prepend (items, item);
3805 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3807 icon_view->priv->items = g_list_reverse (items);
3811 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3814 GtkMovementStep step,
3818 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3819 I_("move-cursor"), 2,
3823 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3828 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3831 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3836 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3843 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3844 GtkMovementStep step,
3847 GdkModifierType state;
3849 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3850 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3851 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3852 step == GTK_MOVEMENT_DISPLAY_LINES ||
3853 step == GTK_MOVEMENT_PAGES ||
3854 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3856 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
3859 gtk_icon_view_stop_editing (icon_view, FALSE);
3860 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3862 if (gtk_get_current_event_state (&state))
3864 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3865 icon_view->priv->ctrl_pressed = TRUE;
3866 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3867 icon_view->priv->shift_pressed = TRUE;
3869 /* else we assume not pressed */
3873 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3874 case GTK_MOVEMENT_VISUAL_POSITIONS:
3875 gtk_icon_view_move_cursor_left_right (icon_view, count);
3877 case GTK_MOVEMENT_DISPLAY_LINES:
3878 gtk_icon_view_move_cursor_up_down (icon_view, count);
3880 case GTK_MOVEMENT_PAGES:
3881 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3883 case GTK_MOVEMENT_BUFFER_ENDS:
3884 gtk_icon_view_move_cursor_start_end (icon_view, count);
3887 g_assert_not_reached ();
3890 icon_view->priv->ctrl_pressed = FALSE;
3891 icon_view->priv->shift_pressed = FALSE;
3893 icon_view->priv->draw_focus = TRUE;
3898 static GtkIconViewItem *
3899 find_item (GtkIconView *icon_view,
3900 GtkIconViewItem *current,
3906 GtkIconViewItem *item;
3908 /* FIXME: this could be more efficient
3910 row = current->row + row_ofs;
3911 col = current->col + col_ofs;
3913 for (items = icon_view->priv->items; items; items = items->next)
3916 if (item->row == row && item->col == col)
3924 find_cell (GtkIconView *icon_view,
3925 GtkIconViewItem *item,
3927 GtkOrientation orientation,
3937 if (icon_view->priv->item_orientation != orientation)
3940 gtk_icon_view_set_cell_data (icon_view, item);
3942 focusable = g_new0 (gint, icon_view->priv->n_cells);
3946 for (k = 0; k < 2; k++)
3947 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3949 GtkCellRendererMode mode;
3950 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3952 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3955 if (!gtk_cell_renderer_get_visible (info->cell))
3958 g_object_get (info->cell, "mode", &mode, NULL);
3959 if (mode != GTK_CELL_RENDERER_MODE_INERT)
3962 current = n_focusable;
3964 focusable[n_focusable] = i;
3970 if (n_focusable == 0)
3978 current = step > 0 ? 0 : n_focusable - 1;
3979 cell = focusable[current];
3982 if (current + *count < 0)
3985 *count = current + *count;
3987 else if (current + *count > n_focusable - 1)
3990 *count = current + *count - (n_focusable - 1);
3994 cell = focusable[current + *count];
4003 static GtkIconViewItem *
4004 find_item_page_up_down (GtkIconView *icon_view,
4005 GtkIconViewItem *current,
4012 y = current->y + count * icon_view->priv->vadjustment->page_size;
4014 item = g_list_find (icon_view->priv->items, current);
4019 for (next = item->next; next; next = next->next)
4021 if (((GtkIconViewItem *)next->data)->col == col)
4024 if (!next || ((GtkIconViewItem *)next->data)->y > y)
4034 for (next = item->prev; next; next = next->prev)
4036 if (((GtkIconViewItem *)next->data)->col == col)
4039 if (!next || ((GtkIconViewItem *)next->data)->y < y)
4053 gtk_icon_view_select_all_between (GtkIconView *icon_view,
4054 GtkIconViewItem *anchor,
4055 GtkIconViewItem *cursor)
4058 GtkIconViewItem *item;
4059 gint row1, row2, col1, col2;
4060 gboolean dirty = FALSE;
4062 if (anchor->row < cursor->row)
4073 if (anchor->col < cursor->col)
4084 for (items = icon_view->priv->items; items; items = items->next)
4088 if (row1 <= item->row && item->row <= row2 &&
4089 col1 <= item->col && item->col <= col2)
4091 if (!item->selected)
4094 item->selected = TRUE;
4095 gtk_icon_view_item_selected_changed (icon_view, item);
4097 gtk_icon_view_queue_draw_item (icon_view, item);
4105 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
4108 GtkIconViewItem *item;
4110 gboolean dirty = FALSE;
4112 GtkDirectionType direction;
4114 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4117 direction = count < 0 ? GTK_DIR_UP : GTK_DIR_DOWN;
4119 if (!icon_view->priv->cursor_item)
4124 list = icon_view->priv->items;
4126 list = g_list_last (icon_view->priv->items);
4128 item = list ? list->data : NULL;
4133 item = icon_view->priv->cursor_item;
4134 cell = icon_view->priv->cursor_cell;
4135 step = count > 0 ? 1 : -1;
4138 cell = find_cell (icon_view, item, cell,
4139 GTK_ORIENTATION_VERTICAL,
4144 item = find_item (icon_view, item, step, 0);
4145 count = count - step;
4151 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4153 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4155 gtk_widget_child_focus (toplevel,
4156 direction == GTK_DIR_UP ?
4157 GTK_DIR_TAB_BACKWARD :
4158 GTK_DIR_TAB_FORWARD);
4164 if (icon_view->priv->ctrl_pressed ||
4165 !icon_view->priv->shift_pressed ||
4166 !icon_view->priv->anchor_item ||
4167 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4168 icon_view->priv->anchor_item = item;
4170 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4172 if (!icon_view->priv->ctrl_pressed &&
4173 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4175 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4176 dirty = gtk_icon_view_select_all_between (icon_view,
4177 icon_view->priv->anchor_item,
4181 gtk_icon_view_scroll_to_item (icon_view, item);
4184 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4188 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
4191 GtkIconViewItem *item;
4192 gboolean dirty = FALSE;
4194 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4197 if (!icon_view->priv->cursor_item)
4202 list = icon_view->priv->items;
4204 list = g_list_last (icon_view->priv->items);
4206 item = list ? list->data : NULL;
4209 item = find_item_page_up_down (icon_view,
4210 icon_view->priv->cursor_item,
4213 if (item == icon_view->priv->cursor_item)
4214 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4219 if (icon_view->priv->ctrl_pressed ||
4220 !icon_view->priv->shift_pressed ||
4221 !icon_view->priv->anchor_item ||
4222 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4223 icon_view->priv->anchor_item = item;
4225 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4227 if (!icon_view->priv->ctrl_pressed &&
4228 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4230 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4231 dirty = gtk_icon_view_select_all_between (icon_view,
4232 icon_view->priv->anchor_item,
4236 gtk_icon_view_scroll_to_item (icon_view, item);
4239 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4243 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4246 GtkIconViewItem *item;
4248 gboolean dirty = FALSE;
4250 GtkDirectionType direction;
4252 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4255 direction = count < 0 ? GTK_DIR_LEFT : GTK_DIR_RIGHT;
4257 if (!icon_view->priv->cursor_item)
4262 list = icon_view->priv->items;
4264 list = g_list_last (icon_view->priv->items);
4266 item = list ? list->data : NULL;
4270 item = icon_view->priv->cursor_item;
4271 cell = icon_view->priv->cursor_cell;
4272 step = count > 0 ? 1 : -1;
4275 cell = find_cell (icon_view, item, cell,
4276 GTK_ORIENTATION_HORIZONTAL,
4281 item = find_item (icon_view, item, 0, step);
4282 count = count - step;
4288 if (!gtk_widget_keynav_failed (GTK_WIDGET (icon_view), direction))
4290 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_view));
4292 gtk_widget_child_focus (toplevel,
4293 direction == GTK_DIR_LEFT ?
4294 GTK_DIR_TAB_BACKWARD :
4295 GTK_DIR_TAB_FORWARD);
4301 if (icon_view->priv->ctrl_pressed ||
4302 !icon_view->priv->shift_pressed ||
4303 !icon_view->priv->anchor_item ||
4304 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4305 icon_view->priv->anchor_item = item;
4307 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4309 if (!icon_view->priv->ctrl_pressed &&
4310 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4312 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4313 dirty = gtk_icon_view_select_all_between (icon_view,
4314 icon_view->priv->anchor_item,
4318 gtk_icon_view_scroll_to_item (icon_view, item);
4321 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4325 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4328 GtkIconViewItem *item;
4330 gboolean dirty = FALSE;
4332 if (!gtk_widget_has_focus (GTK_WIDGET (icon_view)))
4336 list = icon_view->priv->items;
4338 list = g_list_last (icon_view->priv->items);
4340 item = list ? list->data : NULL;
4342 if (item == icon_view->priv->cursor_item)
4343 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4348 if (icon_view->priv->ctrl_pressed ||
4349 !icon_view->priv->shift_pressed ||
4350 !icon_view->priv->anchor_item ||
4351 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4352 icon_view->priv->anchor_item = item;
4354 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4356 if (!icon_view->priv->ctrl_pressed &&
4357 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4359 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4360 dirty = gtk_icon_view_select_all_between (icon_view,
4361 icon_view->priv->anchor_item,
4365 gtk_icon_view_scroll_to_item (icon_view, item);
4368 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4372 * gtk_icon_view_scroll_to_path:
4373 * @icon_view: A #GtkIconView.
4374 * @path: The path of the item to move to.
4375 * @use_align: whether to use alignment arguments, or %FALSE.
4376 * @row_align: The vertical alignment of the item specified by @path.
4377 * @col_align: The horizontal alignment of the item specified by @path.
4379 * Moves the alignments of @icon_view to the position specified by @path.
4380 * @row_align determines where the row is placed, and @col_align determines
4381 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4382 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4385 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4386 * tree does the minimum amount of work to scroll the item onto the screen.
4387 * This means that the item will be scrolled to the edge closest to its current
4388 * position. If the item is currently visible on the screen, nothing is done.
4390 * This function only works if the model is set, and @path is a valid row on
4391 * the model. If the model changes before the @icon_view is realized, the
4392 * centered path will be modified to reflect this change.
4397 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4403 GtkIconViewItem *item = NULL;
4406 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4407 g_return_if_fail (path != NULL);
4408 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4409 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4411 widget = GTK_WIDGET (icon_view);
4413 if (gtk_tree_path_get_depth (path) > 0)
4414 item = g_list_nth_data (icon_view->priv->items,
4415 gtk_tree_path_get_indices(path)[0]);
4417 if (!item || item->width < 0 ||
4418 !gtk_widget_get_realized (widget))
4420 if (icon_view->priv->scroll_to_path)
4421 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4423 icon_view->priv->scroll_to_path = NULL;
4426 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4428 icon_view->priv->scroll_to_use_align = use_align;
4429 icon_view->priv->scroll_to_row_align = row_align;
4430 icon_view->priv->scroll_to_col_align = col_align;
4437 GtkAllocation allocation;
4442 gtk_widget_style_get (widget,
4443 "focus-line-width", &focus_width,
4446 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4448 gtk_widget_get_allocation (widget, &allocation);
4450 offset = y + item->y - focus_width - row_align * (allocation.height - item->height);
4452 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4453 icon_view->priv->vadjustment->value + offset);
4455 offset = x + item->x - focus_width - col_align * (allocation.width - item->width);
4457 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4458 icon_view->priv->hadjustment->value + offset);
4460 gtk_adjustment_changed (icon_view->priv->hadjustment);
4461 gtk_adjustment_changed (icon_view->priv->vadjustment);
4464 gtk_icon_view_scroll_to_item (icon_view, item);
4469 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4470 GtkIconViewItem *item)
4472 GtkAllocation allocation;
4473 GtkWidget *widget = GTK_WIDGET (icon_view);
4474 gint x, y, width, height;
4477 gtk_widget_style_get (widget,
4478 "focus-line-width", &focus_width,
4481 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4483 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4485 gtk_widget_get_allocation (widget, &allocation);
4487 if (y + item->y - focus_width < 0)
4488 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4489 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4490 else if (y + item->y + item->height + focus_width > allocation.height)
4491 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4492 icon_view->priv->vadjustment->value + y + item->y + item->height
4493 + focus_width - allocation.height);
4495 if (x + item->x - focus_width < 0)
4496 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4497 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4498 else if (x + item->x + item->width + focus_width > allocation.width)
4499 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4500 icon_view->priv->hadjustment->value + x + item->x + item->width
4501 + focus_width - allocation.width);
4503 gtk_adjustment_changed (icon_view->priv->hadjustment);
4504 gtk_adjustment_changed (icon_view->priv->vadjustment);
4507 /* GtkCellLayout implementation */
4508 static GtkIconViewCellInfo *
4509 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4510 GtkCellRenderer *renderer)
4514 for (i = icon_view->priv->cell_list; i; i = i->next)
4516 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4518 if (info->cell == renderer)
4526 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4527 GtkIconViewItem *item)
4530 gboolean iters_persist;
4533 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4539 path = gtk_tree_path_new_from_indices (item->index, -1);
4540 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4542 gtk_tree_path_free (path);
4547 for (i = icon_view->priv->cell_list; i; i = i->next)
4550 GtkIconViewCellInfo *info = i->data;
4552 g_object_freeze_notify (G_OBJECT (info->cell));
4554 for (j = info->attributes; j && j->next; j = j->next->next)
4556 gchar *property = j->data;
4557 gint column = GPOINTER_TO_INT (j->next->data);
4558 GValue value = {0, };
4560 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4562 g_object_set_property (G_OBJECT (info->cell),
4564 g_value_unset (&value);
4568 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4570 icon_view->priv->model,
4574 g_object_thaw_notify (G_OBJECT (info->cell));
4579 free_cell_attributes (GtkIconViewCellInfo *info)
4583 list = info->attributes;
4584 while (list && list->next)
4586 g_free (list->data);
4587 list = list->next->next;
4590 g_slist_free (info->attributes);
4591 info->attributes = NULL;
4595 free_cell_info (GtkIconViewCellInfo *info)
4597 free_cell_attributes (info);
4599 g_object_unref (info->cell);
4602 (* info->destroy) (info->func_data);
4608 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4609 GtkCellRenderer *renderer,
4612 GtkIconViewCellInfo *info;
4613 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4615 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4616 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4618 g_object_ref_sink (renderer);
4620 info = g_new0 (GtkIconViewCellInfo, 1);
4621 info->cell = renderer;
4622 info->expand = expand ? TRUE : FALSE;
4623 info->pack = GTK_PACK_START;
4624 info->position = icon_view->priv->n_cells;
4626 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4627 icon_view->priv->n_cells++;
4631 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4632 GtkCellRenderer *renderer,
4635 GtkIconViewCellInfo *info;
4636 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4638 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4639 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4641 g_object_ref_sink (renderer);
4643 info = g_new0 (GtkIconViewCellInfo, 1);
4644 info->cell = renderer;
4645 info->expand = expand ? TRUE : FALSE;
4646 info->pack = GTK_PACK_END;
4647 info->position = icon_view->priv->n_cells;
4649 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4650 icon_view->priv->n_cells++;
4654 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4655 GtkCellRenderer *renderer,
4656 const gchar *attribute,
4659 GtkIconViewCellInfo *info;
4660 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4662 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4663 g_return_if_fail (info != NULL);
4665 info->attributes = g_slist_prepend (info->attributes,
4666 GINT_TO_POINTER (column));
4667 info->attributes = g_slist_prepend (info->attributes,
4668 g_strdup (attribute));
4672 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4674 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4676 while (icon_view->priv->cell_list)
4678 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4679 free_cell_info (info);
4680 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4681 icon_view->priv->cell_list);
4684 icon_view->priv->n_cells = 0;
4688 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4689 GtkCellRenderer *cell,
4690 GtkCellLayoutDataFunc func,
4692 GDestroyNotify destroy)
4694 GtkIconViewCellInfo *info;
4695 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4697 info = gtk_icon_view_get_cell_info (icon_view, cell);
4698 g_return_if_fail (info != NULL);
4702 GDestroyNotify d = info->destroy;
4704 info->destroy = NULL;
4705 d (info->func_data);
4709 info->func_data = func_data;
4710 info->destroy = destroy;
4714 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4715 GtkCellRenderer *renderer)
4717 GtkIconViewCellInfo *info;
4719 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4721 free_cell_attributes (info);
4725 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4726 GtkCellRenderer *cell,
4729 GtkIconView *icon_view;
4731 GtkIconViewCellInfo *info;
4734 icon_view = GTK_ICON_VIEW (layout);
4736 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4738 info = gtk_icon_view_get_cell_info (icon_view, cell);
4740 g_return_if_fail (info != NULL);
4741 g_return_if_fail (position >= 0);
4743 link = g_list_find (icon_view->priv->cell_list, info);
4745 g_return_if_fail (link != NULL);
4747 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4749 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4752 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4759 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4763 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4765 GtkIconView *icon_view = (GtkIconView *)layout;
4766 GList *retval = NULL, *l;
4768 for (l = icon_view->priv->cell_list; l; l = l->next)
4770 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4772 retval = g_list_prepend (retval, info->cell);
4775 return g_list_reverse (retval);
4782 * gtk_icon_view_new:
4784 * Creates a new #GtkIconView widget
4786 * Return value: A newly created #GtkIconView widget
4791 gtk_icon_view_new (void)
4793 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4797 * gtk_icon_view_new_with_model:
4798 * @model: The model.
4800 * Creates a new #GtkIconView widget with the model @model.
4802 * Return value: A newly created #GtkIconView widget.
4807 gtk_icon_view_new_with_model (GtkTreeModel *model)
4809 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4813 * gtk_icon_view_convert_widget_to_bin_window_coords:
4814 * @icon_view: a #GtkIconView
4815 * @wx: X coordinate relative to the widget
4816 * @wy: Y coordinate relative to the widget
4817 * @bx: return location for bin_window X coordinate
4818 * @by: return location for bin_window Y coordinate
4820 * Converts widget coordinates to coordinates for the bin_window,
4821 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4826 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4834 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4836 if (icon_view->priv->bin_window)
4837 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4848 * gtk_icon_view_get_path_at_pos:
4849 * @icon_view: A #GtkIconView.
4850 * @x: The x position to be identified
4851 * @y: The y position to be identified
4853 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4854 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4855 * the cell at the specified position.
4856 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4857 * widget coordinates to bin_window coordinates.
4859 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4860 * if no icon exists at that position.
4865 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4869 GtkIconViewItem *item;
4872 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4874 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4879 path = gtk_tree_path_new_from_indices (item->index, -1);
4885 * gtk_icon_view_get_item_at_pos:
4886 * @icon_view: A #GtkIconView.
4887 * @x: The x position to be identified
4888 * @y: The y position to be identified
4889 * @path: (allow-none): Return location for the path, or %NULL
4890 * @cell: Return location for the renderer responsible for the cell
4891 * at (@x, @y), or %NULL
4893 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4894 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4895 * obtains the cell at the specified position. The returned path should
4896 * be freed with gtk_tree_path_free().
4897 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4898 * widget coordinates to bin_window coordinates.
4900 * Return value: %TRUE if an item exists at the specified position
4905 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4909 GtkCellRenderer **cell)
4911 GtkIconViewItem *item;
4912 GtkIconViewCellInfo *info;
4914 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4916 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4921 *path = gtk_tree_path_new_from_indices (item->index, -1);
4934 return (item != NULL);
4938 * gtk_icon_view_set_tooltip_item:
4939 * @icon_view: a #GtkIconView
4940 * @tooltip: a #GtkTooltip
4941 * @path: a #GtkTreePath
4943 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4944 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4945 * See also gtk_tooltip_set_tip_area().
4950 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4951 GtkTooltip *tooltip,
4954 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4955 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4957 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4961 * gtk_icon_view_set_tooltip_cell:
4962 * @icon_view: a #GtkIconView
4963 * @tooltip: a #GtkTooltip
4964 * @path: a #GtkTreePath
4965 * @cell: (allow-none): a #GtkCellRenderer or %NULL
4967 * Sets the tip area of @tooltip to the area which @cell occupies in
4968 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4970 * See also gtk_icon_view_set_tooltip_column() for a simpler alternative.
4975 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4976 GtkTooltip *tooltip,
4978 GtkCellRenderer *cell)
4981 GtkIconViewItem *item = NULL;
4982 GtkIconViewCellInfo *info = NULL;
4985 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4986 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4987 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4989 if (gtk_tree_path_get_depth (path) > 0)
4990 item = g_list_nth_data (icon_view->priv->items,
4991 gtk_tree_path_get_indices(path)[0]);
4998 info = gtk_icon_view_get_cell_info (icon_view, cell);
4999 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
5005 rect.width = item->width;
5006 rect.height = item->height;
5009 if (icon_view->priv->bin_window)
5011 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
5016 gtk_tooltip_set_tip_area (tooltip, &rect);
5021 * gtk_icon_view_get_tooltip_context:
5022 * @icon_view: an #GtkIconView
5023 * @x: the x coordinate (relative to widget coordinates)
5024 * @y: the y coordinate (relative to widget coordinates)
5025 * @keyboard_tip: whether this is a keyboard tooltip or not
5026 * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
5027 * @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
5028 * @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
5030 * This function is supposed to be used in a #GtkWidget::query-tooltip
5031 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
5032 * which are received in the signal handler, should be passed to this
5033 * function without modification.
5035 * The return value indicates whether there is an icon view item at the given
5036 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
5037 * tooltips the item returned will be the cursor item. When %TRUE, then any of
5038 * @model, @path and @iter which have been provided will be set to point to
5039 * that row and the corresponding model. @x and @y will always be converted
5040 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
5042 * Return value: whether or not the given tooltip context points to a item
5047 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
5050 gboolean keyboard_tip,
5051 GtkTreeModel **model,
5055 GtkTreePath *tmppath = NULL;
5057 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5058 g_return_val_if_fail (x != NULL, FALSE);
5059 g_return_val_if_fail (y != NULL, FALSE);
5063 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
5070 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
5073 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
5078 *model = gtk_icon_view_get_model (icon_view);
5081 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
5087 gtk_tree_path_free (tmppath);
5093 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
5096 gboolean keyboard_tip,
5097 GtkTooltip *tooltip,
5103 GtkTreeModel *model;
5104 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
5106 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
5109 &model, &path, &iter))
5112 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
5116 gtk_tree_path_free (path);
5120 gtk_tooltip_set_markup (tooltip, str);
5121 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
5123 gtk_tree_path_free (path);
5131 * gtk_icon_view_set_tooltip_column:
5132 * @icon_view: a #GtkIconView
5133 * @column: an integer, which is a valid column number for @icon_view's model
5135 * If you only plan to have simple (text-only) tooltips on full items, you
5136 * can use this function to have #GtkIconView handle these automatically
5137 * for you. @column should be set to the column in @icon_view's model
5138 * containing the tooltip texts, or -1 to disable this feature.
5140 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
5141 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
5146 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
5149 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5151 if (column == icon_view->priv->tooltip_column)
5156 g_signal_handlers_disconnect_by_func (icon_view,
5157 gtk_icon_view_set_tooltip_query_cb,
5159 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
5163 if (icon_view->priv->tooltip_column == -1)
5165 g_signal_connect (icon_view, "query-tooltip",
5166 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
5167 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
5171 icon_view->priv->tooltip_column = column;
5172 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
5176 * gtk_icon_view_get_tooltip_column:
5177 * @icon_view: a #GtkIconView
5179 * Returns the column of @icon_view's model which is being used for
5180 * displaying tooltips on @icon_view's rows.
5182 * Return value: the index of the tooltip column that is currently being
5183 * used, or -1 if this is disabled.
5188 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
5190 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
5192 return icon_view->priv->tooltip_column;
5196 * gtk_icon_view_get_visible_range:
5197 * @icon_view: A #GtkIconView
5198 * @start_path: (allow-none): Return location for start of region, or %NULL
5199 * @end_path: (allow-none): Return location for end of region, or %NULL
5201 * Sets @start_path and @end_path to be the first and last visible path.
5202 * Note that there may be invisible paths in between.
5204 * Both paths should be freed with gtk_tree_path_free() after use.
5206 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
5211 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
5212 GtkTreePath **start_path,
5213 GtkTreePath **end_path)
5215 gint start_index = -1;
5216 gint end_index = -1;
5219 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5221 if (icon_view->priv->hadjustment == NULL ||
5222 icon_view->priv->vadjustment == NULL)
5225 if (start_path == NULL && end_path == NULL)
5228 for (icons = icon_view->priv->items; icons; icons = icons->next)
5230 GtkIconViewItem *item = icons->data;
5232 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
5233 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
5234 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
5235 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
5237 if (start_index == -1)
5238 start_index = item->index;
5239 end_index = item->index;
5243 if (start_path && start_index != -1)
5244 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
5245 if (end_path && end_index != -1)
5246 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
5248 return start_index != -1;
5252 * gtk_icon_view_selected_foreach:
5253 * @icon_view: A #GtkIconView.
5254 * @func: (scope call): The function to call for each selected icon.
5255 * @data: User data to pass to the function.
5257 * Calls a function for each selected icon. Note that the model or
5258 * selection cannot be modified from within this function.
5263 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5264 GtkIconViewForeachFunc func,
5269 for (list = icon_view->priv->items; list; list = list->next)
5271 GtkIconViewItem *item = list->data;
5272 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5275 (* func) (icon_view, path, data);
5277 gtk_tree_path_free (path);
5282 * gtk_icon_view_set_selection_mode:
5283 * @icon_view: A #GtkIconView.
5284 * @mode: The selection mode
5286 * Sets the selection mode of the @icon_view.
5291 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5292 GtkSelectionMode mode)
5294 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5296 if (mode == icon_view->priv->selection_mode)
5299 if (mode == GTK_SELECTION_NONE ||
5300 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5301 gtk_icon_view_unselect_all (icon_view);
5303 icon_view->priv->selection_mode = mode;
5305 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5309 * gtk_icon_view_get_selection_mode:
5310 * @icon_view: A #GtkIconView.
5312 * Gets the selection mode of the @icon_view.
5314 * Return value: the current selection mode
5319 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5321 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5323 return icon_view->priv->selection_mode;
5327 * gtk_icon_view_set_model:
5328 * @icon_view: A #GtkIconView.
5329 * @model: (allow-none): The model.
5331 * Sets the model for a #GtkIconView.
5332 * If the @icon_view already has a model set, it will remove
5333 * it before setting the new model. If @model is %NULL, then
5334 * it will unset the old model.
5339 gtk_icon_view_set_model (GtkIconView *icon_view,
5340 GtkTreeModel *model)
5342 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5343 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5345 if (icon_view->priv->model == model)
5348 if (icon_view->priv->scroll_to_path)
5350 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5351 icon_view->priv->scroll_to_path = NULL;
5354 gtk_icon_view_stop_editing (icon_view, TRUE);
5360 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5362 if (icon_view->priv->pixbuf_column != -1)
5364 column_type = gtk_tree_model_get_column_type (model,
5365 icon_view->priv->pixbuf_column);
5367 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5370 if (icon_view->priv->text_column != -1)
5372 column_type = gtk_tree_model_get_column_type (model,
5373 icon_view->priv->text_column);
5375 g_return_if_fail (column_type == G_TYPE_STRING);
5378 if (icon_view->priv->markup_column != -1)
5380 column_type = gtk_tree_model_get_column_type (model,
5381 icon_view->priv->markup_column);
5383 g_return_if_fail (column_type == G_TYPE_STRING);
5388 if (icon_view->priv->model)
5390 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5391 gtk_icon_view_row_changed,
5393 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5394 gtk_icon_view_row_inserted,
5396 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5397 gtk_icon_view_row_deleted,
5399 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5400 gtk_icon_view_rows_reordered,
5403 g_object_unref (icon_view->priv->model);
5405 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5406 g_list_free (icon_view->priv->items);
5407 icon_view->priv->items = NULL;
5408 icon_view->priv->anchor_item = NULL;
5409 icon_view->priv->cursor_item = NULL;
5410 icon_view->priv->last_single_clicked = NULL;
5411 icon_view->priv->width = 0;
5412 icon_view->priv->height = 0;
5415 icon_view->priv->model = model;
5417 if (icon_view->priv->model)
5419 g_object_ref (icon_view->priv->model);
5420 g_signal_connect (icon_view->priv->model,
5422 G_CALLBACK (gtk_icon_view_row_changed),
5424 g_signal_connect (icon_view->priv->model,
5426 G_CALLBACK (gtk_icon_view_row_inserted),
5428 g_signal_connect (icon_view->priv->model,
5430 G_CALLBACK (gtk_icon_view_row_deleted),
5432 g_signal_connect (icon_view->priv->model,
5434 G_CALLBACK (gtk_icon_view_rows_reordered),
5437 gtk_icon_view_build_items (icon_view);
5439 gtk_icon_view_queue_layout (icon_view);
5442 g_object_notify (G_OBJECT (icon_view), "model");
5444 if (gtk_widget_get_realized (GTK_WIDGET (icon_view)))
5445 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5449 * gtk_icon_view_get_model:
5450 * @icon_view: a #GtkIconView
5452 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5455 * Return value: (transfer none): A #GtkTreeModel, or %NULL if none is
5456 * currently being used.
5461 gtk_icon_view_get_model (GtkIconView *icon_view)
5463 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5465 return icon_view->priv->model;
5469 update_text_cell (GtkIconView *icon_view)
5471 GtkIconViewCellInfo *info;
5475 if (icon_view->priv->text_column == -1 &&
5476 icon_view->priv->markup_column == -1)
5478 if (icon_view->priv->text_cell != -1)
5480 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5481 icon_view->priv->pixbuf_cell--;
5483 info = g_list_nth_data (icon_view->priv->cell_list,
5484 icon_view->priv->text_cell);
5486 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5488 free_cell_info (info);
5490 icon_view->priv->n_cells--;
5491 icon_view->priv->text_cell = -1;
5496 if (icon_view->priv->text_cell == -1)
5498 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5499 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5500 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5503 if (info->cell == cell)
5505 icon_view->priv->text_cell = i;
5511 info = g_list_nth_data (icon_view->priv->cell_list,
5512 icon_view->priv->text_cell);
5514 if (icon_view->priv->markup_column != -1)
5515 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5517 "markup", icon_view->priv->markup_column,
5520 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5522 "text", icon_view->priv->text_column,
5525 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5526 g_object_set (info->cell,
5527 "alignment", PANGO_ALIGN_CENTER,
5528 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5533 g_object_set (info->cell,
5534 "alignment", PANGO_ALIGN_LEFT,
5535 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5543 update_pixbuf_cell (GtkIconView *icon_view)
5545 GtkIconViewCellInfo *info;
5549 if (icon_view->priv->pixbuf_column == -1)
5551 if (icon_view->priv->pixbuf_cell != -1)
5553 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5554 icon_view->priv->text_cell--;
5556 info = g_list_nth_data (icon_view->priv->cell_list,
5557 icon_view->priv->pixbuf_cell);
5559 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5561 free_cell_info (info);
5563 icon_view->priv->n_cells--;
5564 icon_view->priv->pixbuf_cell = -1;
5569 if (icon_view->priv->pixbuf_cell == -1)
5571 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5573 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5574 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5577 if (info->cell == cell)
5579 icon_view->priv->pixbuf_cell = i;
5585 info = g_list_nth_data (icon_view->priv->cell_list,
5586 icon_view->priv->pixbuf_cell);
5588 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5590 "pixbuf", icon_view->priv->pixbuf_column,
5593 if (icon_view->priv->item_orientation == GTK_ORIENTATION_VERTICAL)
5594 g_object_set (info->cell,
5599 g_object_set (info->cell,
5607 * gtk_icon_view_set_text_column:
5608 * @icon_view: A #GtkIconView.
5609 * @column: A column in the currently used model, or -1 to display no text
5611 * Sets the column with text for @icon_view to be @column. The text
5612 * column must be of type #G_TYPE_STRING.
5617 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5620 if (column == icon_view->priv->text_column)
5624 icon_view->priv->text_column = -1;
5627 if (icon_view->priv->model != NULL)
5631 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5633 g_return_if_fail (column_type == G_TYPE_STRING);
5636 icon_view->priv->text_column = column;
5639 gtk_icon_view_stop_editing (icon_view, TRUE);
5641 update_text_cell (icon_view);
5643 gtk_icon_view_invalidate_sizes (icon_view);
5644 gtk_icon_view_queue_layout (icon_view);
5646 g_object_notify (G_OBJECT (icon_view), "text-column");
5650 * gtk_icon_view_get_text_column:
5651 * @icon_view: A #GtkIconView.
5653 * Returns the column with text for @icon_view.
5655 * Returns: the text column, or -1 if it's unset.
5660 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5662 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5664 return icon_view->priv->text_column;
5668 * gtk_icon_view_set_markup_column:
5669 * @icon_view: A #GtkIconView.
5670 * @column: A column in the currently used model, or -1 to display no text
5672 * Sets the column with markup information for @icon_view to be
5673 * @column. The markup column must be of type #G_TYPE_STRING.
5674 * If the markup column is set to something, it overrides
5675 * the text column set by gtk_icon_view_set_text_column().
5680 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5683 if (column == icon_view->priv->markup_column)
5687 icon_view->priv->markup_column = -1;
5690 if (icon_view->priv->model != NULL)
5694 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5696 g_return_if_fail (column_type == G_TYPE_STRING);
5699 icon_view->priv->markup_column = column;
5702 gtk_icon_view_stop_editing (icon_view, TRUE);
5704 update_text_cell (icon_view);
5706 gtk_icon_view_invalidate_sizes (icon_view);
5707 gtk_icon_view_queue_layout (icon_view);
5709 g_object_notify (G_OBJECT (icon_view), "markup-column");
5713 * gtk_icon_view_get_markup_column:
5714 * @icon_view: A #GtkIconView.
5716 * Returns the column with markup text for @icon_view.
5718 * Returns: the markup column, or -1 if it's unset.
5723 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5725 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5727 return icon_view->priv->markup_column;
5731 * gtk_icon_view_set_pixbuf_column:
5732 * @icon_view: A #GtkIconView.
5733 * @column: A column in the currently used model, or -1 to disable
5735 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5736 * column must be of type #GDK_TYPE_PIXBUF
5741 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5744 if (column == icon_view->priv->pixbuf_column)
5748 icon_view->priv->pixbuf_column = -1;
5751 if (icon_view->priv->model != NULL)
5755 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5757 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5760 icon_view->priv->pixbuf_column = column;
5763 gtk_icon_view_stop_editing (icon_view, TRUE);
5765 update_pixbuf_cell (icon_view);
5767 gtk_icon_view_invalidate_sizes (icon_view);
5768 gtk_icon_view_queue_layout (icon_view);
5770 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5775 * gtk_icon_view_get_pixbuf_column:
5776 * @icon_view: A #GtkIconView.
5778 * Returns the column with pixbufs for @icon_view.
5780 * Returns: the pixbuf column, or -1 if it's unset.
5785 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5787 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5789 return icon_view->priv->pixbuf_column;
5793 * gtk_icon_view_select_path:
5794 * @icon_view: A #GtkIconView.
5795 * @path: The #GtkTreePath to be selected.
5797 * Selects the row at @path.
5802 gtk_icon_view_select_path (GtkIconView *icon_view,
5805 GtkIconViewItem *item = NULL;
5807 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5808 g_return_if_fail (icon_view->priv->model != NULL);
5809 g_return_if_fail (path != NULL);
5811 if (gtk_tree_path_get_depth (path) > 0)
5812 item = g_list_nth_data (icon_view->priv->items,
5813 gtk_tree_path_get_indices(path)[0]);
5816 gtk_icon_view_select_item (icon_view, item);
5820 * gtk_icon_view_unselect_path:
5821 * @icon_view: A #GtkIconView.
5822 * @path: The #GtkTreePath to be unselected.
5824 * Unselects the row at @path.
5829 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5832 GtkIconViewItem *item;
5834 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5835 g_return_if_fail (icon_view->priv->model != NULL);
5836 g_return_if_fail (path != NULL);
5838 item = g_list_nth_data (icon_view->priv->items,
5839 gtk_tree_path_get_indices(path)[0]);
5844 gtk_icon_view_unselect_item (icon_view, item);
5848 * gtk_icon_view_get_selected_items:
5849 * @icon_view: A #GtkIconView.
5851 * Creates a list of paths of all selected items. Additionally, if you are
5852 * planning on modifying the model after calling this function, you may
5853 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5854 * To do this, you can use gtk_tree_row_reference_new().
5856 * To free the return value, use:
5858 * g_list_foreach (list, (GFunc)gtk_tree_path_free, NULL);
5859 * g_list_free (list);
5862 * Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
5867 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5870 GList *selected = NULL;
5872 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5874 for (list = icon_view->priv->items; list != NULL; list = list->next)
5876 GtkIconViewItem *item = list->data;
5880 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5882 selected = g_list_prepend (selected, path);
5890 * gtk_icon_view_select_all:
5891 * @icon_view: A #GtkIconView.
5893 * Selects all the icons. @icon_view must has its selection mode set
5894 * to #GTK_SELECTION_MULTIPLE.
5899 gtk_icon_view_select_all (GtkIconView *icon_view)
5902 gboolean dirty = FALSE;
5904 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5906 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5909 for (items = icon_view->priv->items; items; items = items->next)
5911 GtkIconViewItem *item = items->data;
5913 if (!item->selected)
5916 item->selected = TRUE;
5917 gtk_icon_view_queue_draw_item (icon_view, item);
5922 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5926 * gtk_icon_view_unselect_all:
5927 * @icon_view: A #GtkIconView.
5929 * Unselects all the icons.
5934 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5936 gboolean dirty = FALSE;
5938 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5940 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5943 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5946 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5950 * gtk_icon_view_path_is_selected:
5951 * @icon_view: A #GtkIconView.
5952 * @path: A #GtkTreePath to check selection on.
5954 * Returns %TRUE if the icon pointed to by @path is currently
5955 * selected. If @path does not point to a valid location, %FALSE is returned.
5957 * Return value: %TRUE if @path is selected.
5962 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5965 GtkIconViewItem *item;
5967 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5968 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5969 g_return_val_if_fail (path != NULL, FALSE);
5971 item = g_list_nth_data (icon_view->priv->items,
5972 gtk_tree_path_get_indices(path)[0]);
5977 return item->selected;
5981 * gtk_icon_view_get_item_row:
5982 * @icon_view: a #GtkIconView
5983 * @path: the #GtkTreePath of the item
5985 * Gets the row in which the item @path is currently
5986 * displayed. Row numbers start at 0.
5988 * Returns: The row in which the item is displayed
5993 gtk_icon_view_get_item_row (GtkIconView *icon_view,
5996 GtkIconViewItem *item;
5998 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5999 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6000 g_return_val_if_fail (path != NULL, -1);
6002 item = g_list_nth_data (icon_view->priv->items,
6003 gtk_tree_path_get_indices(path)[0]);
6012 * gtk_icon_view_get_item_column:
6013 * @icon_view: a #GtkIconView
6014 * @path: the #GtkTreePath of the item
6016 * Gets the column in which the item @path is currently
6017 * displayed. Column numbers start at 0.
6019 * Returns: The column in which the item is displayed
6024 gtk_icon_view_get_item_column (GtkIconView *icon_view,
6027 GtkIconViewItem *item;
6029 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6030 g_return_val_if_fail (icon_view->priv->model != NULL, -1);
6031 g_return_val_if_fail (path != NULL, -1);
6033 item = g_list_nth_data (icon_view->priv->items,
6034 gtk_tree_path_get_indices(path)[0]);
6043 * gtk_icon_view_item_activated:
6044 * @icon_view: A #GtkIconView
6045 * @path: The #GtkTreePath to be activated
6047 * Activates the item determined by @path.
6052 gtk_icon_view_item_activated (GtkIconView *icon_view,
6055 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6056 g_return_if_fail (path != NULL);
6058 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
6062 * gtk_icon_view_set_item_orientation:
6063 * @icon_view: a #GtkIconView
6064 * @orientation: the relative position of texts and icons
6066 * Sets the ::item-orientation property which determines whether the labels
6067 * are drawn beside the icons instead of below.
6072 gtk_icon_view_set_item_orientation (GtkIconView *icon_view,
6073 GtkOrientation orientation)
6075 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6077 if (icon_view->priv->item_orientation != orientation)
6079 icon_view->priv->item_orientation = orientation;
6081 gtk_icon_view_stop_editing (icon_view, TRUE);
6082 gtk_icon_view_invalidate_sizes (icon_view);
6083 gtk_icon_view_queue_layout (icon_view);
6085 update_text_cell (icon_view);
6086 update_pixbuf_cell (icon_view);
6088 g_object_notify (G_OBJECT (icon_view), "item-orientation");
6093 * gtk_icon_view_get_item_orientation:
6094 * @icon_view: a #GtkIconView
6096 * Returns the value of the ::item-orientation property which determines
6097 * whether the labels are drawn beside the icons instead of below.
6099 * Return value: the relative position of texts and icons
6104 gtk_icon_view_get_item_orientation (GtkIconView *icon_view)
6106 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
6107 GTK_ORIENTATION_VERTICAL);
6109 return icon_view->priv->item_orientation;
6113 * gtk_icon_view_set_columns:
6114 * @icon_view: a #GtkIconView
6115 * @columns: the number of columns
6117 * Sets the ::columns property which determines in how
6118 * many columns the icons are arranged. If @columns is
6119 * -1, the number of columns will be chosen automatically
6120 * to fill the available area.
6125 gtk_icon_view_set_columns (GtkIconView *icon_view,
6128 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6130 if (icon_view->priv->columns != columns)
6132 icon_view->priv->columns = columns;
6134 gtk_icon_view_stop_editing (icon_view, TRUE);
6135 gtk_icon_view_queue_layout (icon_view);
6137 g_object_notify (G_OBJECT (icon_view), "columns");
6142 * gtk_icon_view_get_columns:
6143 * @icon_view: a #GtkIconView
6145 * Returns the value of the ::columns property.
6147 * Return value: the number of columns, or -1
6152 gtk_icon_view_get_columns (GtkIconView *icon_view)
6154 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6156 return icon_view->priv->columns;
6160 * gtk_icon_view_set_item_width:
6161 * @icon_view: a #GtkIconView
6162 * @item_width: the width for each item
6164 * Sets the ::item-width property which specifies the width
6165 * to use for each item. If it is set to -1, the icon view will
6166 * automatically determine a suitable item size.
6171 gtk_icon_view_set_item_width (GtkIconView *icon_view,
6174 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6176 if (icon_view->priv->item_width != item_width)
6178 icon_view->priv->item_width = item_width;
6180 gtk_icon_view_stop_editing (icon_view, TRUE);
6181 gtk_icon_view_invalidate_sizes (icon_view);
6182 gtk_icon_view_queue_layout (icon_view);
6184 update_text_cell (icon_view);
6186 g_object_notify (G_OBJECT (icon_view), "item-width");
6191 * gtk_icon_view_get_item_width:
6192 * @icon_view: a #GtkIconView
6194 * Returns the value of the ::item-width property.
6196 * Return value: the width of a single item, or -1
6201 gtk_icon_view_get_item_width (GtkIconView *icon_view)
6203 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6205 return icon_view->priv->item_width;
6210 * gtk_icon_view_set_spacing:
6211 * @icon_view: a #GtkIconView
6212 * @spacing: the spacing
6214 * Sets the ::spacing property which specifies the space
6215 * which is inserted between the cells (i.e. the icon and
6216 * the text) of an item.
6221 gtk_icon_view_set_spacing (GtkIconView *icon_view,
6224 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6226 if (icon_view->priv->spacing != spacing)
6228 icon_view->priv->spacing = spacing;
6230 gtk_icon_view_stop_editing (icon_view, TRUE);
6231 gtk_icon_view_invalidate_sizes (icon_view);
6232 gtk_icon_view_queue_layout (icon_view);
6234 g_object_notify (G_OBJECT (icon_view), "spacing");
6239 * gtk_icon_view_get_spacing:
6240 * @icon_view: a #GtkIconView
6242 * Returns the value of the ::spacing property.
6244 * Return value: the space between cells
6249 gtk_icon_view_get_spacing (GtkIconView *icon_view)
6251 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6253 return icon_view->priv->spacing;
6257 * gtk_icon_view_set_row_spacing:
6258 * @icon_view: a #GtkIconView
6259 * @row_spacing: the row spacing
6261 * Sets the ::row-spacing property which specifies the space
6262 * which is inserted between the rows of the icon view.
6267 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
6270 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6272 if (icon_view->priv->row_spacing != row_spacing)
6274 icon_view->priv->row_spacing = row_spacing;
6276 gtk_icon_view_stop_editing (icon_view, TRUE);
6277 gtk_icon_view_invalidate_sizes (icon_view);
6278 gtk_icon_view_queue_layout (icon_view);
6280 g_object_notify (G_OBJECT (icon_view), "row-spacing");
6285 * gtk_icon_view_get_row_spacing:
6286 * @icon_view: a #GtkIconView
6288 * Returns the value of the ::row-spacing property.
6290 * Return value: the space between rows
6295 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
6297 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6299 return icon_view->priv->row_spacing;
6303 * gtk_icon_view_set_column_spacing:
6304 * @icon_view: a #GtkIconView
6305 * @column_spacing: the column spacing
6307 * Sets the ::column-spacing property which specifies the space
6308 * which is inserted between the columns of the icon view.
6313 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
6314 gint column_spacing)
6316 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6318 if (icon_view->priv->column_spacing != column_spacing)
6320 icon_view->priv->column_spacing = column_spacing;
6322 gtk_icon_view_stop_editing (icon_view, TRUE);
6323 gtk_icon_view_invalidate_sizes (icon_view);
6324 gtk_icon_view_queue_layout (icon_view);
6326 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6331 * gtk_icon_view_get_column_spacing:
6332 * @icon_view: a #GtkIconView
6334 * Returns the value of the ::column-spacing property.
6336 * Return value: the space between columns
6341 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6343 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6345 return icon_view->priv->column_spacing;
6349 * gtk_icon_view_set_margin:
6350 * @icon_view: a #GtkIconView
6351 * @margin: the margin
6353 * Sets the ::margin property which specifies the space
6354 * which is inserted at the top, bottom, left and right
6360 gtk_icon_view_set_margin (GtkIconView *icon_view,
6363 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6365 if (icon_view->priv->margin != margin)
6367 icon_view->priv->margin = margin;
6369 gtk_icon_view_stop_editing (icon_view, TRUE);
6370 gtk_icon_view_invalidate_sizes (icon_view);
6371 gtk_icon_view_queue_layout (icon_view);
6373 g_object_notify (G_OBJECT (icon_view), "margin");
6378 * gtk_icon_view_get_margin:
6379 * @icon_view: a #GtkIconView
6381 * Returns the value of the ::margin property.
6383 * Return value: the space at the borders
6388 gtk_icon_view_get_margin (GtkIconView *icon_view)
6390 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6392 return icon_view->priv->margin;
6396 * gtk_icon_view_set_item_padding:
6397 * @icon_view: a #GtkIconView
6398 * @item_padding: the item padding
6400 * Sets the #GtkIconView:item-padding property which specifies the padding
6401 * around each of the icon view's items.
6406 gtk_icon_view_set_item_padding (GtkIconView *icon_view,
6409 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6411 if (icon_view->priv->item_padding != item_padding)
6413 icon_view->priv->item_padding = item_padding;
6415 gtk_icon_view_stop_editing (icon_view, TRUE);
6416 gtk_icon_view_invalidate_sizes (icon_view);
6417 gtk_icon_view_queue_layout (icon_view);
6419 g_object_notify (G_OBJECT (icon_view), "item-padding");
6424 * gtk_icon_view_get_item_padding:
6425 * @icon_view: a #GtkIconView
6427 * Returns the value of the ::item-padding property.
6429 * Return value: the padding around items
6434 gtk_icon_view_get_item_padding (GtkIconView *icon_view)
6436 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6438 return icon_view->priv->item_padding;
6441 /* Get/set whether drag_motion requested the drag data and
6442 * drag_data_received should thus not actually insert the data,
6443 * since the data doesn't result from a drop.
6446 set_status_pending (GdkDragContext *context,
6447 GdkDragAction suggested_action)
6449 g_object_set_data (G_OBJECT (context),
6450 I_("gtk-icon-view-status-pending"),
6451 GINT_TO_POINTER (suggested_action));
6454 static GdkDragAction
6455 get_status_pending (GdkDragContext *context)
6457 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6458 "gtk-icon-view-status-pending"));
6462 unset_reorderable (GtkIconView *icon_view)
6464 if (icon_view->priv->reorderable)
6466 icon_view->priv->reorderable = FALSE;
6467 g_object_notify (G_OBJECT (icon_view), "reorderable");
6472 set_source_row (GdkDragContext *context,
6473 GtkTreeModel *model,
6474 GtkTreePath *source_row)
6477 g_object_set_data_full (G_OBJECT (context),
6478 I_("gtk-icon-view-source-row"),
6479 gtk_tree_row_reference_new (model, source_row),
6480 (GDestroyNotify) gtk_tree_row_reference_free);
6482 g_object_set_data_full (G_OBJECT (context),
6483 I_("gtk-icon-view-source-row"),
6488 get_source_row (GdkDragContext *context)
6490 GtkTreeRowReference *ref;
6492 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6495 return gtk_tree_row_reference_get_path (ref);
6502 GtkTreeRowReference *dest_row;
6503 gboolean empty_view_drop;
6504 gboolean drop_append_mode;
6508 dest_row_free (gpointer data)
6510 DestRow *dr = (DestRow *)data;
6512 gtk_tree_row_reference_free (dr->dest_row);
6517 set_dest_row (GdkDragContext *context,
6518 GtkTreeModel *model,
6519 GtkTreePath *dest_row,
6520 gboolean empty_view_drop,
6521 gboolean drop_append_mode)
6527 g_object_set_data_full (G_OBJECT (context),
6528 I_("gtk-icon-view-dest-row"),
6533 dr = g_new0 (DestRow, 1);
6535 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6536 dr->empty_view_drop = empty_view_drop;
6537 dr->drop_append_mode = drop_append_mode;
6538 g_object_set_data_full (G_OBJECT (context),
6539 I_("gtk-icon-view-dest-row"),
6540 dr, (GDestroyNotify) dest_row_free);
6544 get_dest_row (GdkDragContext *context)
6548 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6552 GtkTreePath *path = NULL;
6555 path = gtk_tree_row_reference_get_path (dr->dest_row);
6556 else if (dr->empty_view_drop)
6557 path = gtk_tree_path_new_from_indices (0, -1);
6561 if (path && dr->drop_append_mode)
6562 gtk_tree_path_next (path);
6571 check_model_dnd (GtkTreeModel *model,
6572 GType required_iface,
6573 const gchar *signal)
6575 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6577 g_warning ("You must override the default '%s' handler "
6578 "on GtkIconView when using models that don't support "
6579 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6580 "is to connect to '%s' and call "
6581 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6582 "the default handler from running. Look at the source code "
6583 "for the default handler in gtkiconview.c to get an idea what "
6584 "your handler should do. (gtkiconview.c is in the GTK+ source "
6585 "code.) If you're using GTK+ from a language other than C, "
6586 "there may be a more natural way to override default handlers, e.g. via derivation.",
6587 signal, g_type_name (required_iface), signal);
6595 remove_scroll_timeout (GtkIconView *icon_view)
6597 if (icon_view->priv->scroll_timeout_id != 0)
6599 g_source_remove (icon_view->priv->scroll_timeout_id);
6601 icon_view->priv->scroll_timeout_id = 0;
6606 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6609 gint px, py, x, y, width, height;
6610 gint hoffset, voffset;
6612 window = gtk_widget_get_window (GTK_WIDGET (icon_view));
6614 gdk_window_get_pointer (window, &px, &py, NULL);
6615 gdk_window_get_geometry (window, &x, &y, &width, &height, NULL);
6617 /* see if we are near the edge. */
6618 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6620 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6622 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6624 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6627 gtk_adjustment_set_value (icon_view->priv->vadjustment,
6628 icon_view->priv->vadjustment->value + voffset);
6631 gtk_adjustment_set_value (icon_view->priv->hadjustment,
6632 icon_view->priv->hadjustment->value + hoffset);
6637 drag_scroll_timeout (gpointer data)
6639 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6641 gtk_icon_view_autoscroll (icon_view);
6648 set_destination (GtkIconView *icon_view,
6649 GdkDragContext *context,
6652 GdkDragAction *suggested_action,
6656 GtkTreePath *path = NULL;
6657 GtkIconViewDropPosition pos;
6658 GtkIconViewDropPosition old_pos;
6659 GtkTreePath *old_dest_path = NULL;
6660 gboolean can_drop = FALSE;
6662 widget = GTK_WIDGET (icon_view);
6664 *suggested_action = 0;
6667 if (!icon_view->priv->dest_set)
6669 /* someone unset us as a drag dest, note that if
6670 * we return FALSE drag_leave isn't called
6673 gtk_icon_view_set_drag_dest_item (icon_view,
6675 GTK_ICON_VIEW_DROP_LEFT);
6677 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6679 return FALSE; /* no longer a drop site */
6682 *target = gtk_drag_dest_find_target (widget, context,
6683 gtk_drag_dest_get_target_list (widget));
6684 if (*target == GDK_NONE)
6687 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6690 GtkTreeModel *model;
6692 /* the row got dropped on empty space, let's setup a special case
6696 gtk_tree_path_free (path);
6698 model = gtk_icon_view_get_model (icon_view);
6700 n_children = gtk_tree_model_iter_n_children (model, NULL);
6703 pos = GTK_ICON_VIEW_DROP_BELOW;
6704 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6708 pos = GTK_ICON_VIEW_DROP_ABOVE;
6709 path = gtk_tree_path_new_from_indices (0, -1);
6719 gtk_icon_view_get_drag_dest_item (icon_view,
6724 gtk_tree_path_free (old_dest_path);
6726 if (TRUE /* FIXME if the location droppable predicate */)
6734 GtkWidget *source_widget;
6736 *suggested_action = context->suggested_action;
6737 source_widget = gtk_drag_get_source_widget (context);
6739 if (source_widget == widget)
6741 /* Default to MOVE, unless the user has
6742 * pressed ctrl or shift to affect available actions
6744 if ((context->actions & GDK_ACTION_MOVE) != 0)
6745 *suggested_action = GDK_ACTION_MOVE;
6748 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6753 /* can't drop here */
6754 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6756 GTK_ICON_VIEW_DROP_LEFT);
6760 gtk_tree_path_free (path);
6766 get_logical_destination (GtkIconView *icon_view,
6767 gboolean *drop_append_mode)
6769 /* adjust path to point to the row the drop goes in front of */
6770 GtkTreePath *path = NULL;
6771 GtkIconViewDropPosition pos;
6773 *drop_append_mode = FALSE;
6775 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6780 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6781 pos == GTK_ICON_VIEW_DROP_BELOW)
6784 GtkTreeModel *model = icon_view->priv->model;
6786 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6787 !gtk_tree_model_iter_next (model, &iter))
6788 *drop_append_mode = TRUE;
6791 *drop_append_mode = FALSE;
6792 gtk_tree_path_next (path);
6800 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6801 GdkEventMotion *event)
6803 GtkWidget *widget = GTK_WIDGET (icon_view);
6804 GdkDragContext *context;
6805 GtkTreePath *path = NULL;
6807 GtkTreeModel *model;
6808 gboolean retval = FALSE;
6810 if (!icon_view->priv->source_set)
6813 if (icon_view->priv->pressed_button < 0)
6816 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6817 icon_view->priv->press_start_x,
6818 icon_view->priv->press_start_y,
6819 event->x, event->y))
6822 model = gtk_icon_view_get_model (icon_view);
6827 button = icon_view->priv->pressed_button;
6828 icon_view->priv->pressed_button = -1;
6830 path = gtk_icon_view_get_path_at_pos (icon_view,
6831 icon_view->priv->press_start_x,
6832 icon_view->priv->press_start_y);
6837 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6838 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6842 /* FIXME Check whether we're a start button, if not return FALSE and
6846 /* Now we can begin the drag */
6850 context = gtk_drag_begin (widget,
6851 gtk_drag_source_get_target_list (widget),
6852 icon_view->priv->source_actions,
6856 set_source_row (context, model, path);
6860 gtk_tree_path_free (path);
6865 /* Source side drag signals */
6867 gtk_icon_view_drag_begin (GtkWidget *widget,
6868 GdkDragContext *context)
6870 GtkIconView *icon_view;
6871 GtkIconViewItem *item;
6876 icon_view = GTK_ICON_VIEW (widget);
6878 /* if the user uses a custom DnD impl, we don't set the icon here */
6879 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6882 item = gtk_icon_view_get_item_at_coords (icon_view,
6883 icon_view->priv->press_start_x,
6884 icon_view->priv->press_start_y,
6888 g_return_if_fail (item != NULL);
6890 x = icon_view->priv->press_start_x - item->x + 1;
6891 y = icon_view->priv->press_start_y - item->y + 1;
6893 path = gtk_tree_path_new_from_indices (item->index, -1);
6894 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6895 gtk_tree_path_free (path);
6897 gtk_drag_set_icon_pixmap (context,
6898 gdk_drawable_get_colormap (icon),
6903 g_object_unref (icon);
6907 gtk_icon_view_drag_end (GtkWidget *widget,
6908 GdkDragContext *context)
6914 gtk_icon_view_drag_data_get (GtkWidget *widget,
6915 GdkDragContext *context,
6916 GtkSelectionData *selection_data,
6920 GtkIconView *icon_view;
6921 GtkTreeModel *model;
6922 GtkTreePath *source_row;
6924 icon_view = GTK_ICON_VIEW (widget);
6925 model = gtk_icon_view_get_model (icon_view);
6930 if (!icon_view->priv->source_set)
6933 source_row = get_source_row (context);
6935 if (source_row == NULL)
6938 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6939 * any model; for DragSource models there are some other targets
6943 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6944 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6949 /* If drag_data_get does nothing, try providing row data. */
6950 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6951 gtk_tree_set_row_drag_data (selection_data,
6956 gtk_tree_path_free (source_row);
6960 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6961 GdkDragContext *context)
6963 GtkTreeModel *model;
6964 GtkIconView *icon_view;
6965 GtkTreePath *source_row;
6967 icon_view = GTK_ICON_VIEW (widget);
6968 model = gtk_icon_view_get_model (icon_view);
6970 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag-data-delete"))
6973 if (!icon_view->priv->source_set)
6976 source_row = get_source_row (context);
6978 if (source_row == NULL)
6981 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6984 gtk_tree_path_free (source_row);
6986 set_source_row (context, NULL, NULL);
6989 /* Target side drag signals */
6991 gtk_icon_view_drag_leave (GtkWidget *widget,
6992 GdkDragContext *context,
6995 GtkIconView *icon_view;
6997 icon_view = GTK_ICON_VIEW (widget);
6999 /* unset any highlight row */
7000 gtk_icon_view_set_drag_dest_item (icon_view,
7002 GTK_ICON_VIEW_DROP_LEFT);
7004 remove_scroll_timeout (icon_view);
7008 gtk_icon_view_drag_motion (GtkWidget *widget,
7009 GdkDragContext *context,
7014 GtkTreePath *path = NULL;
7015 GtkIconViewDropPosition pos;
7016 GtkIconView *icon_view;
7017 GdkDragAction suggested_action = 0;
7021 icon_view = GTK_ICON_VIEW (widget);
7023 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7026 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
7028 /* we only know this *after* set_desination_row */
7029 empty = icon_view->priv->empty_view_drop;
7031 if (path == NULL && !empty)
7033 /* Can't drop here. */
7034 gdk_drag_status (context, 0, time);
7038 if (icon_view->priv->scroll_timeout_id == 0)
7040 icon_view->priv->scroll_timeout_id =
7041 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
7044 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
7046 /* Request data so we can use the source row when
7047 * determining whether to accept the drop
7049 set_status_pending (context, suggested_action);
7050 gtk_drag_get_data (widget, context, target, time);
7054 set_status_pending (context, 0);
7055 gdk_drag_status (context, suggested_action, time);
7060 gtk_tree_path_free (path);
7066 gtk_icon_view_drag_drop (GtkWidget *widget,
7067 GdkDragContext *context,
7072 GtkIconView *icon_view;
7074 GdkDragAction suggested_action = 0;
7075 GdkAtom target = GDK_NONE;
7076 GtkTreeModel *model;
7077 gboolean drop_append_mode;
7079 icon_view = GTK_ICON_VIEW (widget);
7080 model = gtk_icon_view_get_model (icon_view);
7082 remove_scroll_timeout (GTK_ICON_VIEW (widget));
7084 if (!icon_view->priv->dest_set)
7087 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-drop"))
7090 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
7093 path = get_logical_destination (icon_view, &drop_append_mode);
7095 if (target != GDK_NONE && path != NULL)
7097 /* in case a motion had requested drag data, change things so we
7098 * treat drag data receives as a drop.
7100 set_status_pending (context, 0);
7101 set_dest_row (context, model, path,
7102 icon_view->priv->empty_view_drop, drop_append_mode);
7106 gtk_tree_path_free (path);
7108 /* Unset this thing */
7109 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
7111 if (target != GDK_NONE)
7113 gtk_drag_get_data (widget, context, target, time);
7121 gtk_icon_view_drag_data_received (GtkWidget *widget,
7122 GdkDragContext *context,
7125 GtkSelectionData *selection_data,
7130 gboolean accepted = FALSE;
7131 GtkTreeModel *model;
7132 GtkIconView *icon_view;
7133 GtkTreePath *dest_row;
7134 GdkDragAction suggested_action;
7135 gboolean drop_append_mode;
7137 icon_view = GTK_ICON_VIEW (widget);
7138 model = gtk_icon_view_get_model (icon_view);
7140 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag-data-received"))
7143 if (!icon_view->priv->dest_set)
7146 suggested_action = get_status_pending (context);
7148 if (suggested_action)
7150 /* We are getting this data due to a request in drag_motion,
7151 * rather than due to a request in drag_drop, so we are just
7152 * supposed to call drag_status, not actually paste in the
7155 path = get_logical_destination (icon_view, &drop_append_mode);
7158 suggested_action = 0;
7160 if (suggested_action)
7162 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
7165 suggested_action = 0;
7168 gdk_drag_status (context, suggested_action, time);
7171 gtk_tree_path_free (path);
7173 /* If you can't drop, remove user drop indicator until the next motion */
7174 if (suggested_action == 0)
7175 gtk_icon_view_set_drag_dest_item (icon_view,
7177 GTK_ICON_VIEW_DROP_LEFT);
7182 dest_row = get_dest_row (context);
7184 if (dest_row == NULL)
7187 if (selection_data->length >= 0)
7189 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
7195 gtk_drag_finish (context,
7197 (context->action == GDK_ACTION_MOVE),
7200 gtk_tree_path_free (dest_row);
7203 set_dest_row (context, NULL, NULL, FALSE, FALSE);
7206 /* Drag-and-Drop support */
7208 * gtk_icon_view_enable_model_drag_source:
7209 * @icon_view: a #GtkIconTreeView
7210 * @start_button_mask: Mask of allowed buttons to start drag
7211 * @targets: the table of targets that the drag will support
7212 * @n_targets: the number of items in @targets
7213 * @actions: the bitmask of possible actions for a drag from this
7216 * Turns @icon_view into a drag source for automatic DND. Calling this
7217 * method sets #GtkIconView:reorderable to %FALSE.
7222 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
7223 GdkModifierType start_button_mask,
7224 const GtkTargetEntry *targets,
7226 GdkDragAction actions)
7228 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7230 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7232 icon_view->priv->start_button_mask = start_button_mask;
7233 icon_view->priv->source_actions = actions;
7235 icon_view->priv->source_set = TRUE;
7237 unset_reorderable (icon_view);
7241 * gtk_icon_view_enable_model_drag_dest:
7242 * @icon_view: a #GtkIconView
7243 * @targets: the table of targets that the drag will support
7244 * @n_targets: the number of items in @targets
7245 * @actions: the bitmask of possible actions for a drag to this
7248 * Turns @icon_view into a drop destination for automatic DND. Calling this
7249 * method sets #GtkIconView:reorderable to %FALSE.
7254 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
7255 const GtkTargetEntry *targets,
7257 GdkDragAction actions)
7259 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7261 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, targets, n_targets, actions);
7263 icon_view->priv->dest_actions = actions;
7265 icon_view->priv->dest_set = TRUE;
7267 unset_reorderable (icon_view);
7271 * gtk_icon_view_unset_model_drag_source:
7272 * @icon_view: a #GtkIconView
7274 * Undoes the effect of gtk_icon_view_enable_model_drag_source(). Calling this
7275 * method sets #GtkIconView:reorderable to %FALSE.
7280 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
7282 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7284 if (icon_view->priv->source_set)
7286 gtk_drag_source_unset (GTK_WIDGET (icon_view));
7287 icon_view->priv->source_set = FALSE;
7290 unset_reorderable (icon_view);
7294 * gtk_icon_view_unset_model_drag_dest:
7295 * @icon_view: a #GtkIconView
7297 * Undoes the effect of gtk_icon_view_enable_model_drag_dest(). Calling this
7298 * method sets #GtkIconView:reorderable to %FALSE.
7303 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
7305 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7307 if (icon_view->priv->dest_set)
7309 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
7310 icon_view->priv->dest_set = FALSE;
7313 unset_reorderable (icon_view);
7316 /* These are useful to implement your own custom stuff. */
7318 * gtk_icon_view_set_drag_dest_item:
7319 * @icon_view: a #GtkIconView
7320 * @path: (allow-none): The path of the item to highlight, or %NULL.
7321 * @pos: Specifies where to drop, relative to the item
7323 * Sets the item that is highlighted for feedback.
7328 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
7330 GtkIconViewDropPosition pos)
7332 /* Note; this function is exported to allow a custom DND
7333 * implementation, so it can't touch TreeViewDragInfo
7336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7338 if (icon_view->priv->dest_item)
7340 GtkTreePath *current_path;
7341 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7342 gtk_tree_row_reference_free (icon_view->priv->dest_item);
7343 icon_view->priv->dest_item = NULL;
7345 gtk_icon_view_queue_draw_path (icon_view, current_path);
7346 gtk_tree_path_free (current_path);
7349 /* special case a drop on an empty model */
7350 icon_view->priv->empty_view_drop = FALSE;
7351 if (pos == GTK_ICON_VIEW_DROP_ABOVE && path
7352 && gtk_tree_path_get_depth (path) == 1
7353 && gtk_tree_path_get_indices (path)[0] == 0)
7357 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7360 if (n_children == 0)
7361 icon_view->priv->empty_view_drop = TRUE;
7364 icon_view->priv->dest_pos = pos;
7368 icon_view->priv->dest_item =
7369 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7370 icon_view->priv->model, path);
7372 gtk_icon_view_queue_draw_path (icon_view, path);
7377 * gtk_icon_view_get_drag_dest_item:
7378 * @icon_view: a #GtkIconView
7379 * @path: (allow-none): Return location for the path of the highlighted item, or %NULL.
7380 * @pos: (allow-none): Return location for the drop position, or %NULL
7382 * Gets information about the item that is highlighted for feedback.
7387 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7389 GtkIconViewDropPosition *pos)
7391 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7395 if (icon_view->priv->dest_item)
7396 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7402 *pos = icon_view->priv->dest_pos;
7406 * gtk_icon_view_get_dest_item_at_pos:
7407 * @icon_view: a #GtkIconView
7408 * @drag_x: the position to determine the destination item for
7409 * @drag_y: the position to determine the destination item for
7410 * @path: (allow-none): Return location for the path of the item, or %NULL.
7411 * @pos: (allow-none): Return location for the drop position, or %NULL
7413 * Determines the destination item for a given position.
7415 * Return value: whether there is an item at the given position.
7420 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7424 GtkIconViewDropPosition *pos)
7426 GtkIconViewItem *item;
7428 /* Note; this function is exported to allow a custom DND
7429 * implementation, so it can't touch TreeViewDragInfo
7432 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7433 g_return_val_if_fail (drag_x >= 0, FALSE);
7434 g_return_val_if_fail (drag_y >= 0, FALSE);
7435 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7441 item = gtk_icon_view_get_item_at_coords (icon_view,
7442 drag_x + icon_view->priv->hadjustment->value,
7443 drag_y + icon_view->priv->vadjustment->value,
7450 *path = gtk_tree_path_new_from_indices (item->index, -1);
7454 if (drag_x < item->x + item->width / 4)
7455 *pos = GTK_ICON_VIEW_DROP_LEFT;
7456 else if (drag_x > item->x + item->width * 3 / 4)
7457 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7458 else if (drag_y < item->y + item->height / 4)
7459 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7460 else if (drag_y > item->y + item->height * 3 / 4)
7461 *pos = GTK_ICON_VIEW_DROP_BELOW;
7463 *pos = GTK_ICON_VIEW_DROP_INTO;
7470 * gtk_icon_view_create_drag_icon:
7471 * @icon_view: a #GtkIconView
7472 * @path: a #GtkTreePath in @icon_view
7474 * Creates a #GdkPixmap representation of the item at @path.
7475 * This image is used for a drag icon.
7477 * Return value: (transfer full): a newly-allocated pixmap of the drag icon.
7482 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7487 GdkPixmap *drawable;
7492 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7493 g_return_val_if_fail (path != NULL, NULL);
7495 widget = GTK_WIDGET (icon_view);
7497 if (!gtk_widget_get_realized (widget))
7500 index = gtk_tree_path_get_indices (path)[0];
7502 for (l = icon_view->priv->items; l; l = l->next)
7504 GtkIconViewItem *item = l->data;
7506 if (index == item->index)
7508 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7513 cr = gdk_cairo_create (drawable);
7514 cairo_set_line_width (cr, 1.);
7516 gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
7517 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7522 area.width = item->width;
7523 area.height = item->height;
7525 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7526 drawable, 1, 1, FALSE);
7528 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7529 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7542 * gtk_icon_view_get_reorderable:
7543 * @icon_view: a #GtkIconView
7545 * Retrieves whether the user can reorder the list via drag-and-drop.
7546 * See gtk_icon_view_set_reorderable().
7548 * Return value: %TRUE if the list can be reordered.
7553 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7555 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7557 return icon_view->priv->reorderable;
7560 static const GtkTargetEntry item_targets[] = {
7561 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7566 * gtk_icon_view_set_reorderable:
7567 * @icon_view: A #GtkIconView.
7568 * @reorderable: %TRUE, if the list of items can be reordered.
7570 * This function is a convenience function to allow you to reorder models that
7571 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7572 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7573 * the user can reorder the model by dragging and dropping rows. The
7574 * developer can listen to these changes by connecting to the model's
7575 * row_inserted and row_deleted signals. The reordering is implemented by setting up
7576 * the icon view as a drag source and destination. Therefore, drag and
7577 * drop can not be used in a reorderable view for any other purpose.
7579 * This function does not give you any degree of control over the order -- any
7580 * reordering is allowed. If more control is needed, you should probably
7581 * handle drag and drop manually.
7586 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7587 gboolean reorderable)
7589 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7591 reorderable = reorderable != FALSE;
7593 if (icon_view->priv->reorderable == reorderable)
7598 gtk_icon_view_enable_model_drag_source (icon_view,
7601 G_N_ELEMENTS (item_targets),
7603 gtk_icon_view_enable_model_drag_dest (icon_view,
7605 G_N_ELEMENTS (item_targets),
7610 gtk_icon_view_unset_model_drag_source (icon_view);
7611 gtk_icon_view_unset_model_drag_dest (icon_view);
7614 icon_view->priv->reorderable = reorderable;
7616 g_object_notify (G_OBJECT (icon_view), "reorderable");
7620 /* Accessibility Support */
7622 static gpointer accessible_parent_class;
7623 static gpointer accessible_item_parent_class;
7624 static GQuark accessible_private_data_quark = 0;
7626 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7627 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7628 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7630 static GType gtk_icon_view_item_accessible_get_type (void);
7641 GtkIconViewItem *item;
7645 AtkStateSet *state_set;
7649 GtkTextBuffer *text_buffer;
7651 gchar *action_descriptions[LAST_ACTION];
7652 gchar *image_description;
7653 guint action_idle_handler;
7654 } GtkIconViewItemAccessible;
7656 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7662 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7667 typedef struct _GtkIconViewItemAccessibleClass
7669 AtkObjectClass parent_class;
7671 } GtkIconViewItemAccessibleClass;
7673 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7676 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7678 GtkIconViewItemAccessible *item;
7679 GtkIconView *icon_view;
7682 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7683 item->action_idle_handler = 0;
7685 if (item->widget != NULL)
7687 icon_view = GTK_ICON_VIEW (item->widget);
7688 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7689 gtk_icon_view_item_activated (icon_view, path);
7690 gtk_tree_path_free (path);
7697 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7700 GtkIconViewItemAccessible *item;
7702 if (i < 0 || i >= LAST_ACTION)
7705 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7707 if (!GTK_IS_ICON_VIEW (item->widget))
7710 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7715 case ACTION_ACTIVATE:
7716 if (!item->action_idle_handler)
7717 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7720 g_assert_not_reached ();
7728 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7733 static const gchar *
7734 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7737 GtkIconViewItemAccessible *item;
7739 if (i < 0 || i >= LAST_ACTION)
7742 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7744 if (item->action_descriptions[i])
7745 return item->action_descriptions[i];
7747 return gtk_icon_view_item_accessible_action_descriptions[i];
7750 static const gchar *
7751 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7754 if (i < 0 || i >= LAST_ACTION)
7757 return gtk_icon_view_item_accessible_action_names[i];
7761 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7763 const gchar *description)
7765 GtkIconViewItemAccessible *item;
7767 if (i < 0 || i >= LAST_ACTION)
7770 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7772 g_free (item->action_descriptions[i]);
7774 item->action_descriptions[i] = g_strdup (description);
7780 atk_action_item_interface_init (AtkActionIface *iface)
7782 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7783 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7784 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7785 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7786 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7789 static const gchar *
7790 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7792 GtkIconViewItemAccessible *item;
7794 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7796 return item->image_description;
7800 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7801 const gchar *description)
7803 GtkIconViewItemAccessible *item;
7805 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7807 g_free (item->image_description);
7808 item->image_description = g_strdup (description);
7814 get_pixbuf_box (GtkIconView *icon_view,
7815 GtkIconViewItem *item,
7820 for (l = icon_view->priv->cell_list; l; l = l->next)
7822 GtkIconViewCellInfo *info = l->data;
7824 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7826 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7836 get_text (GtkIconView *icon_view,
7837 GtkIconViewItem *item)
7842 for (l = icon_view->priv->cell_list; l; l = l->next)
7844 GtkIconViewCellInfo *info = l->data;
7846 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7848 g_object_get (info->cell, "text", &text, NULL);
7858 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7862 GtkIconViewItemAccessible *item;
7865 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7867 if (!GTK_IS_ICON_VIEW (item->widget))
7870 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7873 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7876 *height = box.height;
7881 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7884 AtkCoordType coord_type)
7886 GtkIconViewItemAccessible *item;
7889 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7891 if (!GTK_IS_ICON_VIEW (item->widget))
7894 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7897 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7899 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7901 *x+= box.x - item->item->x;
7902 *y+= box.y - item->item->y;
7908 atk_image_item_interface_init (AtkImageIface *iface)
7910 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7911 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7912 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7913 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7917 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7921 GtkIconViewItemAccessible *item;
7922 GtkTextIter start, end;
7923 GtkTextBuffer *buffer;
7925 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7927 if (!GTK_IS_ICON_VIEW (item->widget))
7930 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7933 buffer = item->text_buffer;
7934 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7936 gtk_text_buffer_get_end_iter (buffer, &end);
7938 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7940 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7944 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7947 GtkIconViewItemAccessible *item;
7948 GtkTextIter start, end;
7949 GtkTextBuffer *buffer;
7953 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7955 if (!GTK_IS_ICON_VIEW (item->widget))
7958 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7961 buffer = item->text_buffer;
7962 if (offset >= gtk_text_buffer_get_char_count (buffer))
7965 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7967 gtk_text_iter_forward_char (&end);
7968 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7969 unichar = g_utf8_get_char (string);
7977 get_pango_text_offsets (PangoLayout *layout,
7978 GtkTextBuffer *buffer,
7980 AtkTextBoundary boundary_type,
7984 GtkTextIter *start_iter,
7985 GtkTextIter *end_iter)
7987 PangoLayoutIter *iter;
7988 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7989 gint index, start_index, end_index;
7991 gboolean found = FALSE;
7993 text = pango_layout_get_text (layout);
7994 index = g_utf8_offset_to_pointer (text, offset) - text;
7995 iter = pango_layout_get_iter (layout);
7998 line = pango_layout_iter_get_line_readonly (iter);
7999 start_index = line->start_index;
8000 end_index = start_index + line->length;
8002 if (index >= start_index && index <= end_index)
8005 * Found line for offset
8011 * We want the previous line
8015 switch (boundary_type)
8017 case ATK_TEXT_BOUNDARY_LINE_START:
8018 end_index = start_index;
8019 start_index = prev_line->start_index;
8021 case ATK_TEXT_BOUNDARY_LINE_END:
8023 start_index = prev_prev_line->start_index +
8024 prev_prev_line->length;
8025 end_index = prev_line->start_index + prev_line->length;
8028 g_assert_not_reached();
8032 start_index = end_index = 0;
8035 switch (boundary_type)
8037 case ATK_TEXT_BOUNDARY_LINE_START:
8038 if (pango_layout_iter_next_line (iter))
8039 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8041 case ATK_TEXT_BOUNDARY_LINE_END:
8043 start_index = prev_line->start_index +
8047 g_assert_not_reached();
8052 * We want the next line
8054 if (pango_layout_iter_next_line (iter))
8056 line = pango_layout_iter_get_line_readonly (iter);
8057 switch (boundary_type)
8059 case ATK_TEXT_BOUNDARY_LINE_START:
8060 start_index = line->start_index;
8061 if (pango_layout_iter_next_line (iter))
8062 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
8064 end_index = start_index + line->length;
8066 case ATK_TEXT_BOUNDARY_LINE_END:
8067 start_index = end_index;
8068 end_index = line->start_index + line->length;
8071 g_assert_not_reached();
8075 start_index = end_index;
8081 prev_prev_line = prev_line;
8084 while (pango_layout_iter_next_line (iter));
8088 start_index = prev_line->start_index + prev_line->length;
8089 end_index = start_index;
8091 pango_layout_iter_free (iter);
8092 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
8093 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
8095 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
8096 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
8101 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
8103 AtkTextBoundary boundary_type,
8107 GtkIconViewItemAccessible *item;
8108 GtkTextIter start, end;
8109 GtkTextBuffer *buffer;
8111 GtkIconView *icon_view;
8114 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8116 if (!GTK_IS_ICON_VIEW (item->widget))
8119 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8122 buffer = item->text_buffer;
8124 if (!gtk_text_buffer_get_char_count (buffer))
8128 return g_strdup ("");
8130 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8134 switch (boundary_type)
8136 case ATK_TEXT_BOUNDARY_CHAR:
8137 gtk_text_iter_backward_char(&start);
8139 case ATK_TEXT_BOUNDARY_WORD_START:
8140 if (!gtk_text_iter_starts_word (&start))
8141 gtk_text_iter_backward_word_start (&start);
8143 gtk_text_iter_backward_word_start(&start);
8145 case ATK_TEXT_BOUNDARY_WORD_END:
8146 if (gtk_text_iter_inside_word (&start) &&
8147 !gtk_text_iter_starts_word (&start))
8148 gtk_text_iter_backward_word_start (&start);
8149 while (!gtk_text_iter_ends_word (&start))
8151 if (!gtk_text_iter_backward_char (&start))
8155 gtk_text_iter_backward_word_start(&start);
8156 while (!gtk_text_iter_ends_word (&start))
8158 if (!gtk_text_iter_backward_char (&start))
8162 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8163 if (!gtk_text_iter_starts_sentence (&start))
8164 gtk_text_iter_backward_sentence_start (&start);
8166 gtk_text_iter_backward_sentence_start (&start);
8168 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8169 if (gtk_text_iter_inside_sentence (&start) &&
8170 !gtk_text_iter_starts_sentence (&start))
8171 gtk_text_iter_backward_sentence_start (&start);
8172 while (!gtk_text_iter_ends_sentence (&start))
8174 if (!gtk_text_iter_backward_char (&start))
8178 gtk_text_iter_backward_sentence_start (&start);
8179 while (!gtk_text_iter_ends_sentence (&start))
8181 if (!gtk_text_iter_backward_char (&start))
8185 case ATK_TEXT_BOUNDARY_LINE_START:
8186 case ATK_TEXT_BOUNDARY_LINE_END:
8188 icon_view = GTK_ICON_VIEW (item->widget);
8189 /* FIXME we probably have to use GailTextCell to salvage this */
8190 gtk_icon_view_update_item_text (icon_view, item->item);
8191 get_pango_text_offsets (icon_view->priv->layout,
8204 *start_offset = gtk_text_iter_get_offset (&start);
8205 *end_offset = gtk_text_iter_get_offset (&end);
8207 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8211 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
8213 AtkTextBoundary boundary_type,
8217 GtkIconViewItemAccessible *item;
8218 GtkTextIter start, end;
8219 GtkTextBuffer *buffer;
8221 GtkIconView *icon_view;
8224 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8226 if (!GTK_IS_ICON_VIEW (item->widget))
8229 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8232 buffer = item->text_buffer;
8234 if (!gtk_text_buffer_get_char_count (buffer))
8238 return g_strdup ("");
8240 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8244 switch (boundary_type)
8246 case ATK_TEXT_BOUNDARY_CHAR:
8247 gtk_text_iter_forward_char (&end);
8249 case ATK_TEXT_BOUNDARY_WORD_START:
8250 if (!gtk_text_iter_starts_word (&start))
8251 gtk_text_iter_backward_word_start (&start);
8252 if (gtk_text_iter_inside_word (&end))
8253 gtk_text_iter_forward_word_end (&end);
8254 while (!gtk_text_iter_starts_word (&end))
8256 if (!gtk_text_iter_forward_char (&end))
8260 case ATK_TEXT_BOUNDARY_WORD_END:
8261 if (gtk_text_iter_inside_word (&start) &&
8262 !gtk_text_iter_starts_word (&start))
8263 gtk_text_iter_backward_word_start (&start);
8264 while (!gtk_text_iter_ends_word (&start))
8266 if (!gtk_text_iter_backward_char (&start))
8269 gtk_text_iter_forward_word_end (&end);
8271 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8272 if (!gtk_text_iter_starts_sentence (&start))
8273 gtk_text_iter_backward_sentence_start (&start);
8274 if (gtk_text_iter_inside_sentence (&end))
8275 gtk_text_iter_forward_sentence_end (&end);
8276 while (!gtk_text_iter_starts_sentence (&end))
8278 if (!gtk_text_iter_forward_char (&end))
8282 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8283 if (gtk_text_iter_inside_sentence (&start) &&
8284 !gtk_text_iter_starts_sentence (&start))
8285 gtk_text_iter_backward_sentence_start (&start);
8286 while (!gtk_text_iter_ends_sentence (&start))
8288 if (!gtk_text_iter_backward_char (&start))
8291 gtk_text_iter_forward_sentence_end (&end);
8293 case ATK_TEXT_BOUNDARY_LINE_START:
8294 case ATK_TEXT_BOUNDARY_LINE_END:
8296 icon_view = GTK_ICON_VIEW (item->widget);
8297 /* FIXME we probably have to use GailTextCell to salvage this */
8298 gtk_icon_view_update_item_text (icon_view, item->item);
8299 get_pango_text_offsets (icon_view->priv->layout,
8313 *start_offset = gtk_text_iter_get_offset (&start);
8314 *end_offset = gtk_text_iter_get_offset (&end);
8316 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8320 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
8322 AtkTextBoundary boundary_type,
8326 GtkIconViewItemAccessible *item;
8327 GtkTextIter start, end;
8328 GtkTextBuffer *buffer;
8330 GtkIconView *icon_view;
8333 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8335 if (!GTK_IS_ICON_VIEW (item->widget))
8338 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8341 buffer = item->text_buffer;
8343 if (!gtk_text_buffer_get_char_count (buffer))
8347 return g_strdup ("");
8349 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8353 switch (boundary_type)
8355 case ATK_TEXT_BOUNDARY_CHAR:
8356 gtk_text_iter_forward_char(&start);
8357 gtk_text_iter_forward_chars(&end, 2);
8359 case ATK_TEXT_BOUNDARY_WORD_START:
8360 if (gtk_text_iter_inside_word (&end))
8361 gtk_text_iter_forward_word_end (&end);
8362 while (!gtk_text_iter_starts_word (&end))
8364 if (!gtk_text_iter_forward_char (&end))
8368 if (!gtk_text_iter_is_end (&end))
8370 gtk_text_iter_forward_word_end (&end);
8371 while (!gtk_text_iter_starts_word (&end))
8373 if (!gtk_text_iter_forward_char (&end))
8378 case ATK_TEXT_BOUNDARY_WORD_END:
8379 gtk_text_iter_forward_word_end (&end);
8381 if (!gtk_text_iter_is_end (&end))
8382 gtk_text_iter_forward_word_end (&end);
8384 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8385 if (gtk_text_iter_inside_sentence (&end))
8386 gtk_text_iter_forward_sentence_end (&end);
8387 while (!gtk_text_iter_starts_sentence (&end))
8389 if (!gtk_text_iter_forward_char (&end))
8393 if (!gtk_text_iter_is_end (&end))
8395 gtk_text_iter_forward_sentence_end (&end);
8396 while (!gtk_text_iter_starts_sentence (&end))
8398 if (!gtk_text_iter_forward_char (&end))
8403 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8404 gtk_text_iter_forward_sentence_end (&end);
8406 if (!gtk_text_iter_is_end (&end))
8407 gtk_text_iter_forward_sentence_end (&end);
8409 case ATK_TEXT_BOUNDARY_LINE_START:
8410 case ATK_TEXT_BOUNDARY_LINE_END:
8412 icon_view = GTK_ICON_VIEW (item->widget);
8413 /* FIXME we probably have to use GailTextCell to salvage this */
8414 gtk_icon_view_update_item_text (icon_view, item->item);
8415 get_pango_text_offsets (icon_view->priv->layout,
8427 *start_offset = gtk_text_iter_get_offset (&start);
8428 *end_offset = gtk_text_iter_get_offset (&end);
8430 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8434 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8436 GtkIconViewItemAccessible *item;
8438 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8440 if (!GTK_IS_ICON_VIEW (item->widget))
8443 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8446 return gtk_text_buffer_get_char_count (item->text_buffer);
8450 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8456 AtkCoordType coord_type)
8458 GtkIconViewItemAccessible *item;
8460 GtkIconView *icon_view;
8461 PangoRectangle char_rect;
8462 const gchar *item_text;
8466 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8468 if (!GTK_IS_ICON_VIEW (item->widget))
8471 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8475 icon_view = GTK_ICON_VIEW (item->widget);
8476 /* FIXME we probably have to use GailTextCell to salvage this */
8477 gtk_icon_view_update_item_text (icon_view, item->item);
8478 item_text = pango_layout_get_text (icon_view->priv->layout);
8479 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8480 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8482 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8483 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8484 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8485 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8486 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8487 *width = char_rect.width / PANGO_SCALE;
8488 *height = char_rect.height / PANGO_SCALE;
8493 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8496 AtkCoordType coord_type)
8498 GtkIconViewItemAccessible *item;
8501 GtkIconView *icon_view;
8502 const gchar *item_text;
8507 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8509 if (!GTK_IS_ICON_VIEW (item->widget))
8512 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8516 icon_view = GTK_ICON_VIEW (item->widget);
8517 /* FIXME we probably have to use GailTextCell to salvage this */
8518 gtk_icon_view_update_item_text (icon_view, item->item);
8519 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8520 x -= l_x + item->item->layout_x - item->item->x;
8521 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8522 y -= l_y + item->item->layout_y - item->item->y;
8523 item_text = pango_layout_get_text (icon_view->priv->layout);
8524 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8535 offset = g_utf8_strlen (item_text, -1);
8537 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8543 atk_text_item_interface_init (AtkTextIface *iface)
8545 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8546 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8547 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8548 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8549 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8550 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8551 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8552 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8556 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8561 AtkCoordType coord_type)
8563 GtkIconViewItemAccessible *item;
8564 AtkObject *parent_obj;
8567 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8569 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8570 if (!GTK_IS_WIDGET (item->widget))
8573 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8576 *width = item->item->width;
8577 *height = item->item->height;
8578 if (gtk_icon_view_item_accessible_is_showing (item))
8580 parent_obj = gtk_widget_get_accessible (item->widget);
8581 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8582 *x = l_x + item->item->x;
8583 *y = l_y + item->item->y;
8593 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8595 GtkIconViewItemAccessible *item;
8596 GtkWidget *toplevel;
8598 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8600 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8601 if (!GTK_IS_WIDGET (item->widget))
8604 gtk_widget_grab_focus (item->widget);
8605 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8606 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8607 if (gtk_widget_is_toplevel (toplevel))
8608 gtk_window_present (GTK_WINDOW (toplevel));
8614 atk_component_item_interface_init (AtkComponentIface *iface)
8616 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8617 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8621 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8622 AtkStateType state_type,
8623 gboolean emit_signal)
8627 rc = atk_state_set_add_state (item->state_set, state_type);
8629 * The signal should only be generated if the value changed,
8630 * not when the item is set up. So states that are set
8631 * initially should pass FALSE as the emit_signal argument.
8636 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8637 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8638 if (state_type == ATK_STATE_VISIBLE)
8639 g_signal_emit_by_name (item, "visible-data-changed");
8646 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8647 AtkStateType state_type,
8648 gboolean emit_signal)
8650 if (atk_state_set_contains_state (item->state_set, state_type))
8654 rc = atk_state_set_remove_state (item->state_set, state_type);
8656 * The signal should only be generated if the value changed,
8657 * not when the item is set up. So states that are set
8658 * initially should pass FALSE as the emit_signal argument.
8663 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8664 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8665 if (state_type == ATK_STATE_VISIBLE)
8666 g_signal_emit_by_name (item, "visible-data-changed");
8676 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8678 GtkAllocation allocation;
8679 GtkIconView *icon_view;
8680 GdkRectangle visible_rect;
8681 gboolean is_showing;
8684 * An item is considered "SHOWING" if any part of the item is in the
8685 * visible rectangle.
8688 if (!GTK_IS_ICON_VIEW (item->widget))
8691 if (item->item == NULL)
8694 gtk_widget_get_allocation (item->widget, &allocation);
8696 icon_view = GTK_ICON_VIEW (item->widget);
8698 if (icon_view->priv->hadjustment)
8699 visible_rect.x += icon_view->priv->hadjustment->value;
8701 if (icon_view->priv->hadjustment)
8702 visible_rect.y += icon_view->priv->vadjustment->value;
8703 visible_rect.width = allocation.width;
8704 visible_rect.height = allocation.height;
8706 if (((item->item->x + item->item->width) < visible_rect.x) ||
8707 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8708 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8709 (item->item->y > (visible_rect.y + visible_rect.height)))
8718 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8719 gboolean emit_signal)
8721 if (gtk_icon_view_item_accessible_is_showing (item))
8722 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8725 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8730 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8734 item->state_set = atk_state_set_new ();
8736 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8737 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8738 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8739 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8740 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8742 for (i = 0; i < LAST_ACTION; i++)
8743 item->action_descriptions[i] = NULL;
8745 item->image_description = NULL;
8747 item->action_idle_handler = 0;
8751 gtk_icon_view_item_accessible_finalize (GObject *object)
8753 GtkIconViewItemAccessible *item;
8756 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8758 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8761 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8763 if (item->state_set)
8764 g_object_unref (item->state_set);
8766 if (item->text_buffer)
8767 g_object_unref (item->text_buffer);
8769 for (i = 0; i < LAST_ACTION; i++)
8770 g_free (item->action_descriptions[i]);
8772 g_free (item->image_description);
8774 if (item->action_idle_handler)
8776 g_source_remove (item->action_idle_handler);
8777 item->action_idle_handler = 0;
8780 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8783 static G_CONST_RETURN gchar*
8784 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8790 GtkIconViewItemAccessible *item;
8791 GtkTextIter start_iter;
8792 GtkTextIter end_iter;
8794 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8796 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8797 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8799 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8804 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8806 GtkIconViewItemAccessible *item;
8808 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8809 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8812 return gtk_widget_get_accessible (item->widget);
8818 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8820 GtkIconViewItemAccessible *item;
8822 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8823 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8825 return item->item->index;
8828 static AtkStateSet *
8829 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8831 GtkIconViewItemAccessible *item;
8832 GtkIconView *icon_view;
8834 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8835 g_return_val_if_fail (item->state_set, NULL);
8840 icon_view = GTK_ICON_VIEW (item->widget);
8841 if (icon_view->priv->cursor_item == item->item)
8842 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8844 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8845 if (item->item->selected)
8846 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTED);
8848 atk_state_set_remove_state (item->state_set, ATK_STATE_SELECTED);
8850 return g_object_ref (item->state_set);
8854 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8856 GObjectClass *gobject_class;
8858 accessible_item_parent_class = g_type_class_peek_parent (klass);
8860 gobject_class = (GObjectClass *)klass;
8862 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8864 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8865 klass->get_name = gtk_icon_view_item_accessible_get_name;
8866 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8867 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8871 gtk_icon_view_item_accessible_get_type (void)
8873 static GType type = 0;
8877 const GTypeInfo tinfo =
8879 sizeof (GtkIconViewItemAccessibleClass),
8880 (GBaseInitFunc) NULL, /* base init */
8881 (GBaseFinalizeFunc) NULL, /* base finalize */
8882 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8883 (GClassFinalizeFunc) NULL, /* class finalize */
8884 NULL, /* class data */
8885 sizeof (GtkIconViewItemAccessible), /* instance size */
8886 0, /* nb preallocs */
8887 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8888 NULL /* value table */
8891 const GInterfaceInfo atk_component_info =
8893 (GInterfaceInitFunc) atk_component_item_interface_init,
8894 (GInterfaceFinalizeFunc) NULL,
8897 const GInterfaceInfo atk_action_info =
8899 (GInterfaceInitFunc) atk_action_item_interface_init,
8900 (GInterfaceFinalizeFunc) NULL,
8903 const GInterfaceInfo atk_image_info =
8905 (GInterfaceInitFunc) atk_image_item_interface_init,
8906 (GInterfaceFinalizeFunc) NULL,
8909 const GInterfaceInfo atk_text_info =
8911 (GInterfaceInitFunc) atk_text_item_interface_init,
8912 (GInterfaceFinalizeFunc) NULL,
8916 type = g_type_register_static (ATK_TYPE_OBJECT,
8917 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8918 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8919 &atk_component_info);
8920 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8922 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8924 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8931 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8932 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8933 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8935 static GType gtk_icon_view_accessible_get_type (void);
8940 } GtkIconViewAccessible;
8946 } GtkIconViewItemAccessibleInfo;
8952 GtkAdjustment *old_hadj;
8953 GtkAdjustment *old_vadj;
8955 GtkTreeModel *model;
8957 } GtkIconViewAccessiblePrivate;
8959 static GtkIconViewAccessiblePrivate *
8960 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8962 return g_object_get_qdata (G_OBJECT (accessible),
8963 accessible_private_data_quark);
8967 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8971 GtkIconViewItemAccessibleInfo *info;
8972 GtkIconViewItemAccessibleInfo *tmp_info;
8973 GtkIconViewAccessiblePrivate *priv;
8976 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8978 info->index = index;
8980 priv = gtk_icon_view_accessible_get_priv (accessible);
8981 items = priv->items;
8984 tmp_info = items->data;
8985 if (tmp_info->index > index)
8987 items = items->next;
8989 priv->items = g_list_insert_before (priv->items, items, info);
8990 priv->old_hadj = NULL;
8991 priv->old_vadj = NULL;
8995 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8997 GtkIconView *icon_view;
9000 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9004 icon_view = GTK_ICON_VIEW (widget);
9006 return g_list_length (icon_view->priv->items);
9010 gtk_icon_view_accessible_find_child (AtkObject *accessible,
9013 GtkIconViewAccessiblePrivate *priv;
9014 GtkIconViewItemAccessibleInfo *info;
9017 priv = gtk_icon_view_accessible_get_priv (accessible);
9018 items = priv->items;
9023 if (info->index == index)
9025 items = items->next;
9031 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
9034 GtkIconView *icon_view;
9038 GtkIconViewItemAccessible *a11y_item;
9040 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9044 icon_view = GTK_ICON_VIEW (widget);
9045 icons = g_list_nth (icon_view->priv->items, index);
9049 GtkIconViewItem *item = icons->data;
9051 g_return_val_if_fail (item->index == index, NULL);
9052 obj = gtk_icon_view_accessible_find_child (accessible, index);
9057 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
9058 gtk_icon_view_item_accessible_info_new (accessible,
9061 obj->role = ATK_ROLE_ICON;
9062 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
9063 a11y_item->item = item;
9064 a11y_item->widget = widget;
9065 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
9067 gtk_icon_view_set_cell_data (icon_view, item);
9068 text = get_text (icon_view, item);
9071 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9075 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
9076 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
9084 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
9087 GtkIconViewAccessiblePrivate *priv;
9088 GtkIconViewItemAccessibleInfo *info;
9089 GtkIconViewItemAccessible *item;
9092 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
9096 gboolean act_on_item;
9098 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (view));
9102 items = priv->items;
9104 act_on_item = (list == NULL);
9109 info = (GtkIconViewItemAccessibleInfo *)items->data;
9110 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9112 if (act_on_item == FALSE && list == items)
9116 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
9118 items = items->next;
9124 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
9125 GtkIconView *icon_view)
9128 GtkIconViewAccessible *view;
9131 * The scrollbars have changed
9133 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
9134 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
9136 gtk_icon_view_accessible_traverse_items (view, NULL);
9140 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
9141 GtkAdjustment *hadj,
9142 GtkAdjustment *vadj)
9145 GtkIconViewAccessiblePrivate *priv;
9147 atk_obj = gtk_widget_get_accessible (widget);
9148 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9150 if (priv->old_hadj != hadj)
9154 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9155 (gpointer *)&priv->old_hadj);
9157 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9158 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9161 priv->old_hadj = hadj;
9164 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
9165 (gpointer *)&priv->old_hadj);
9166 g_signal_connect (hadj,
9168 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9172 if (priv->old_vadj != vadj)
9176 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9177 (gpointer *)&priv->old_vadj);
9179 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9180 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9183 priv->old_vadj = vadj;
9186 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
9187 (gpointer *)&priv->old_vadj);
9188 g_signal_connect (vadj,
9190 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9197 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
9205 GtkIconView *icon_view;
9206 GtkIconViewItem *item;
9207 GtkIconViewAccessible *a11y_view;
9208 GtkIconViewItemAccessible *a11y_item;
9212 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9213 a11y_view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9214 index = gtk_tree_path_get_indices(path)[0];
9215 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (
9216 gtk_icon_view_accessible_find_child (atk_obj, index));
9220 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (atk_obj));
9221 icon_view = GTK_ICON_VIEW (widget);
9222 item = a11y_item->item;
9224 name = gtk_icon_view_item_accessible_get_name (ATK_OBJECT (a11y_item));
9226 if (!name || strcmp (name, "") == 0)
9228 gtk_icon_view_set_cell_data (icon_view, item);
9229 text = get_text (icon_view, item);
9232 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
9238 g_signal_emit_by_name (atk_obj, "visible-data-changed");
9244 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
9249 GtkIconViewAccessiblePrivate *priv;
9250 GtkIconViewItemAccessibleInfo *info;
9251 GtkIconViewAccessible *view;
9252 GtkIconViewItemAccessible *item;
9258 index = gtk_tree_path_get_indices(path)[0];
9259 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9260 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9261 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9263 items = priv->items;
9268 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9269 if (info->index != item->item->index)
9271 if (info->index < index)
9272 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
9274 if (tmp_list == NULL)
9277 info->index = item->item->index;
9280 items = items->next;
9282 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9283 g_signal_emit_by_name (atk_obj, "children-changed::add",
9289 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
9293 GtkIconViewAccessiblePrivate *priv;
9294 GtkIconViewItemAccessibleInfo *info;
9295 GtkIconViewAccessible *view;
9296 GtkIconViewItemAccessible *item;
9299 GList *deleted_item;
9303 index = gtk_tree_path_get_indices(path)[0];
9304 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9305 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
9306 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9308 items = priv->items;
9310 deleted_item = NULL;
9315 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9316 if (info->index == index)
9318 deleted_item = items;
9320 if (info->index != item->item->index)
9322 if (tmp_list == NULL)
9325 info->index = item->item->index;
9328 items = items->next;
9330 gtk_icon_view_accessible_traverse_items (view, tmp_list);
9333 info = deleted_item->data;
9334 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
9335 g_signal_emit_by_name (atk_obj, "children-changed::remove",
9337 priv->items = g_list_remove_link (priv->items, deleted_item);
9345 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
9346 GtkIconViewItemAccessibleInfo *i2)
9348 return i1->index - i2->index;
9352 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
9358 GtkIconViewAccessiblePrivate *priv;
9359 GtkIconViewItemAccessibleInfo *info;
9360 GtkIconView *icon_view;
9361 GtkIconViewItemAccessible *item;
9367 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
9368 icon_view = GTK_ICON_VIEW (user_data);
9369 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9371 length = gtk_tree_model_iter_n_children (tree_model, NULL);
9373 order = g_new (gint, length);
9374 for (i = 0; i < length; i++)
9375 order [new_order[i]] = i;
9377 items = priv->items;
9381 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
9382 info->index = order[info->index];
9383 item->item = g_list_nth_data (icon_view->priv->items, info->index);
9384 items = items->next;
9387 priv->items = g_list_sort (priv->items,
9388 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9394 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9399 obj = G_OBJECT (model);
9400 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9401 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9402 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9403 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9407 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9411 obj = G_OBJECT (icon_view->priv->model);
9412 g_signal_connect_data (obj, "row-changed",
9413 (GCallback) gtk_icon_view_accessible_model_row_changed,
9414 icon_view, NULL, 0);
9415 g_signal_connect_data (obj, "row-inserted",
9416 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9417 icon_view, NULL, G_CONNECT_AFTER);
9418 g_signal_connect_data (obj, "row-deleted",
9419 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9420 icon_view, NULL, G_CONNECT_AFTER);
9421 g_signal_connect_data (obj, "rows-reordered",
9422 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9423 icon_view, NULL, G_CONNECT_AFTER);
9427 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9429 GtkIconViewItemAccessibleInfo *info;
9432 items = priv->items;
9435 info = (GtkIconViewItemAccessibleInfo *) items->data;
9436 g_object_unref (info->item);
9437 g_free (items->data);
9438 items = items->next;
9440 g_list_free (priv->items);
9445 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9448 GtkIconView *icon_view;
9451 GtkIconViewAccessiblePrivate *priv;
9453 if (strcmp (pspec->name, "model") == 0)
9455 widget = GTK_WIDGET (obj);
9456 atk_obj = gtk_widget_get_accessible (widget);
9457 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9460 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9461 (gpointer *)&priv->model);
9462 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9464 gtk_icon_view_accessible_clear_cache (priv);
9466 icon_view = GTK_ICON_VIEW (obj);
9467 priv->model = icon_view->priv->model;
9468 /* If there is no model the GtkIconView is probably being destroyed */
9471 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9472 gtk_icon_view_accessible_connect_model_signals (icon_view);
9480 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9483 GtkIconViewAccessiblePrivate *priv;
9484 GtkIconView *icon_view;
9486 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9487 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9489 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9490 g_object_set_qdata (G_OBJECT (accessible),
9491 accessible_private_data_quark,
9494 icon_view = GTK_ICON_VIEW (data);
9495 if (icon_view->priv->hadjustment)
9497 priv->old_hadj = icon_view->priv->hadjustment;
9498 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9499 g_signal_connect (icon_view->priv->hadjustment,
9501 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9504 if (icon_view->priv->vadjustment)
9506 priv->old_vadj = icon_view->priv->vadjustment;
9507 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9508 g_signal_connect (icon_view->priv->vadjustment,
9510 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9513 g_signal_connect_after (data,
9514 "set-scroll-adjustments",
9515 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9517 g_signal_connect (data,
9519 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9522 priv->model = icon_view->priv->model;
9525 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9526 gtk_icon_view_accessible_connect_model_signals (icon_view);
9529 accessible->role = ATK_ROLE_LAYERED_PANE;
9533 gtk_icon_view_accessible_finalize (GObject *object)
9535 GtkIconViewAccessiblePrivate *priv;
9537 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9538 gtk_icon_view_accessible_clear_cache (priv);
9542 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9546 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9547 GtkAccessible *accessible)
9550 GtkIconViewAccessiblePrivate *priv;
9552 atk_obj = ATK_OBJECT (accessible);
9553 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9556 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9557 (gpointer *)&priv->old_hadj);
9559 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9560 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9562 priv->old_hadj = NULL;
9566 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9567 (gpointer *)&priv->old_vadj);
9569 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9570 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9572 priv->old_vadj = NULL;
9577 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9581 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
9584 g_signal_connect_after (widget,
9586 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9589 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9593 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9595 GObjectClass *gobject_class;
9596 GtkAccessibleClass *accessible_class;
9598 accessible_parent_class = g_type_class_peek_parent (klass);
9600 gobject_class = (GObjectClass *)klass;
9601 accessible_class = (GtkAccessibleClass *)klass;
9603 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9605 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9606 klass->ref_child = gtk_icon_view_accessible_ref_child;
9607 klass->initialize = gtk_icon_view_accessible_initialize;
9609 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9611 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9615 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9618 AtkCoordType coord_type)
9621 GtkIconView *icon_view;
9622 GtkIconViewItem *item;
9625 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (component));
9627 /* State is defunct */
9630 icon_view = GTK_ICON_VIEW (widget);
9631 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9632 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9634 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9640 atk_component_interface_init (AtkComponentIface *iface)
9642 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9646 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9650 GtkIconView *icon_view;
9651 GtkIconViewItem *item;
9653 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9657 icon_view = GTK_ICON_VIEW (widget);
9659 item = g_list_nth_data (icon_view->priv->items, i);
9664 gtk_icon_view_select_item (icon_view, item);
9670 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9673 GtkIconView *icon_view;
9675 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9679 icon_view = GTK_ICON_VIEW (widget);
9680 gtk_icon_view_unselect_all (icon_view);
9686 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9691 GtkIconView *icon_view;
9692 GtkIconViewItem *item;
9694 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9698 icon_view = GTK_ICON_VIEW (widget);
9700 l = icon_view->priv->items;
9707 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9718 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9721 GtkIconView *icon_view;
9722 GtkIconViewItem *item;
9726 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9730 icon_view = GTK_ICON_VIEW (widget);
9732 l = icon_view->priv->items;
9748 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9752 GtkIconView *icon_view;
9753 GtkIconViewItem *item;
9755 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9759 icon_view = GTK_ICON_VIEW (widget);
9761 item = g_list_nth_data (icon_view->priv->items, i);
9765 return item->selected;
9769 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9773 GtkIconView *icon_view;
9774 GtkIconViewItem *item;
9778 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9782 icon_view = GTK_ICON_VIEW (widget);
9783 l = icon_view->priv->items;
9792 gtk_icon_view_unselect_item (icon_view, item);
9804 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9807 GtkIconView *icon_view;
9809 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
9813 icon_view = GTK_ICON_VIEW (widget);
9814 gtk_icon_view_select_all (icon_view);
9819 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9821 iface->add_selection = gtk_icon_view_accessible_add_selection;
9822 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9823 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9824 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9825 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9826 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9827 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9831 gtk_icon_view_accessible_get_type (void)
9833 static GType type = 0;
9840 (GBaseInitFunc) NULL, /* base init */
9841 (GBaseFinalizeFunc) NULL, /* base finalize */
9842 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9843 (GClassFinalizeFunc) NULL, /* class finalize */
9844 NULL, /* class data */
9845 0, /* instance size */
9846 0, /* nb preallocs */
9847 (GInstanceInitFunc) NULL, /* instance init */
9848 NULL /* value table */
9850 const GInterfaceInfo atk_component_info =
9852 (GInterfaceInitFunc) atk_component_interface_init,
9853 (GInterfaceFinalizeFunc) NULL,
9856 const GInterfaceInfo atk_selection_info =
9858 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9859 (GInterfaceFinalizeFunc) NULL,
9864 * Figure out the size of the class and instance
9865 * we are deriving from
9867 AtkObjectFactory *factory;
9870 GType derived_atk_type;
9872 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9873 factory = atk_registry_get_factory (atk_get_default_registry (),
9875 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9876 g_type_query (derived_atk_type, &query);
9877 tinfo.class_size = query.class_size;
9878 tinfo.instance_size = query.instance_size;
9880 type = g_type_register_static (derived_atk_type,
9881 I_("GtkIconViewAccessible"),
9883 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9884 &atk_component_info);
9885 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9886 &atk_selection_info);
9892 gtk_icon_view_accessible_new (GObject *obj)
9894 AtkObject *accessible;
9896 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9898 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9899 atk_object_initialize (accessible, obj);
9905 gtk_icon_view_accessible_factory_get_accessible_type (void)
9907 return gtk_icon_view_accessible_get_type ();
9911 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9913 return gtk_icon_view_accessible_new (obj);
9917 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9919 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9920 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9924 gtk_icon_view_accessible_factory_get_type (void)
9926 static GType type = 0;
9930 const GTypeInfo tinfo =
9932 sizeof (AtkObjectFactoryClass),
9933 NULL, /* base_init */
9934 NULL, /* base_finalize */
9935 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9936 NULL, /* class_finalize */
9937 NULL, /* class_data */
9938 sizeof (AtkObjectFactory),
9939 0, /* n_preallocs */
9943 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9944 I_("GtkIconViewAccessibleFactory"),
9952 gtk_icon_view_get_accessible (GtkWidget *widget)
9954 static gboolean first_time = TRUE;
9958 AtkObjectFactory *factory;
9959 AtkRegistry *registry;
9961 GType derived_atk_type;
9964 * Figure out whether accessibility is enabled by looking at the
9965 * type of the accessible object which would be created for
9966 * the parent type of GtkIconView.
9968 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9970 registry = atk_get_default_registry ();
9971 factory = atk_registry_get_factory (registry,
9973 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9974 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9975 atk_registry_set_factory_type (registry,
9977 gtk_icon_view_accessible_factory_get_type ());
9980 return GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible (widget);
9984 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9985 GtkBuilder *builder,
9987 const gchar *tagname,
9988 GMarkupParser *parser,
9991 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9992 tagname, parser, data))
9995 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9996 tagname, parser, data);
10000 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
10001 GtkBuilder *builder,
10003 const gchar *tagname,
10006 if (strcmp (tagname, "attributes") == 0)
10007 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
10010 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,