2 * Copyright (C) 2002, 2004 Anders Carlsson <andersca@gnu.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #include <gdk/gdkkeysyms.h>
27 #include "gtkiconview.h"
28 #include "gtkcelllayout.h"
29 #include "gtkcellrenderer.h"
30 #include "gtkcellrenderertext.h"
31 #include "gtkcellrendererpixbuf.h"
32 #include "gtkmarshalers.h"
33 #include "gtkbindings.h"
36 #include "gtksignal.h"
38 #include "gtkaccessible.h"
39 #include "gtkwindow.h"
41 #include "gtkcombobox.h"
42 #include "gtktextbuffer.h"
43 #include "gtktreednd.h"
44 #include "gtkprivate.h"
47 #undef DEBUG_ICON_VIEW
49 #define SCROLL_EDGE_SIZE 15
51 #define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
53 typedef struct _GtkIconViewItem GtkIconViewItem;
54 struct _GtkIconViewItem
62 gint x, y, width, height;
65 * box[i] is the actual area occupied by cell i,
66 * before, after are used to calculate the cell
67 * area relative to the box.
68 * See gtk_icon_view_get_cell_area().
76 guint selected_before_rubberbanding : 1;
80 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
81 struct _GtkIconViewCellInfo
83 GtkCellRenderer *cell;
93 GtkCellLayoutDataFunc func;
95 GDestroyNotify destroy;
98 typedef struct _GtkIconViewChild GtkIconViewChild;
99 struct _GtkIconViewChild
102 GtkIconViewItem *item;
106 struct _GtkIconViewPrivate
110 GtkSelectionMode selection_mode;
112 GdkWindow *bin_window;
120 GtkAdjustment *hadjustment;
121 GtkAdjustment *vadjustment;
123 guint layout_idle_id;
125 gboolean doing_rubberband;
126 gint rubberband_x1, rubberband_y1;
127 gint rubberband_x2, rubberband_y2;
129 guint scroll_timeout_id;
130 gint scroll_value_diff;
131 gint event_last_x, event_last_y;
133 GtkIconViewItem *anchor_item;
134 GtkIconViewItem *cursor_item;
135 GtkIconViewItem *edited_item;
136 GtkCellEditable *editable;
138 GtkIconViewItem *last_single_clicked;
145 GtkOrientation orientation;
164 GdkModifierType start_button_mask;
169 GtkTargetList *source_targets;
170 GdkDragAction source_actions;
172 GtkTargetList *dest_targets;
173 GdkDragAction dest_actions;
175 GtkTreeRowReference *dest_item;
176 GtkIconViewDropPosition dest_pos;
179 GtkTreeRowReference *scroll_to_path;
180 gfloat scroll_to_row_align;
181 gfloat scroll_to_col_align;
182 guint scroll_to_use_align : 1;
184 guint source_set : 1;
186 guint reorderable : 1;
187 guint empty_view_drop :1;
189 guint ctrl_pressed : 1;
190 guint shift_pressed : 1;
203 ACTIVATE_CURSOR_ITEM,
228 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
229 static void gtk_icon_view_finalize (GObject *object);
230 static void gtk_icon_view_set_property (GObject *object,
234 static void gtk_icon_view_get_property (GObject *object,
239 /* GtkObject vfuncs */
240 static void gtk_icon_view_destroy (GtkObject *object);
242 /* GtkWidget vfuncs */
243 static void gtk_icon_view_realize (GtkWidget *widget);
244 static void gtk_icon_view_unrealize (GtkWidget *widget);
245 static void gtk_icon_view_style_set (GtkWidget *widget,
246 GtkStyle *previous_style);
247 static void gtk_icon_view_state_changed (GtkWidget *widget,
248 GtkStateType previous_state);
249 static void gtk_icon_view_size_request (GtkWidget *widget,
250 GtkRequisition *requisition);
251 static void gtk_icon_view_size_allocate (GtkWidget *widget,
252 GtkAllocation *allocation);
253 static gboolean gtk_icon_view_expose (GtkWidget *widget,
254 GdkEventExpose *expose);
255 static gboolean gtk_icon_view_motion (GtkWidget *widget,
256 GdkEventMotion *event);
257 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
258 GdkEventButton *event);
259 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
260 GdkEventButton *event);
261 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
263 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
265 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
268 /* GtkContainer vfuncs */
269 static void gtk_icon_view_remove (GtkContainer *container,
271 static void gtk_icon_view_forall (GtkContainer *container,
272 gboolean include_internals,
273 GtkCallback callback,
274 gpointer callback_data);
276 /* GtkIconView vfuncs */
277 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
279 GtkAdjustment *vadj);
280 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
281 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
282 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
283 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
284 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
286 /* Internal functions */
287 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
288 GtkIconView *icon_view);
289 static void gtk_icon_view_layout (GtkIconView *icon_view);
290 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
293 GtkIconViewItem *item,
295 GdkDrawable *drawable,
298 gboolean draw_focus);
299 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
302 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
304 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
305 GtkIconViewItem *item);
306 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
307 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
308 GtkIconViewItem *item,
310 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
313 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
314 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
315 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
316 GtkIconViewItem *item,
321 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
322 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
323 GtkIconViewItem *item);
324 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
325 GtkIconViewItem *item,
327 static void gtk_icon_view_update_rubberband (gpointer data);
328 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
329 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
330 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
333 GtkMovementStep step,
335 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
336 GtkMovementStep step,
338 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
340 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
342 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
344 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
346 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
347 GtkIconViewItem *item);
348 static void gtk_icon_view_select_item (GtkIconView *icon_view,
349 GtkIconViewItem *item);
350 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
351 GtkIconViewItem *item);
352 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
353 GtkIconViewItem *anchor,
354 GtkIconViewItem *cursor);
355 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
358 gboolean only_in_cell,
359 GtkIconViewCellInfo **cell_at_pos);
360 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
361 GtkIconViewItem *item,
362 GtkIconViewCellInfo *cell_info,
363 GdkRectangle *cell_area);
364 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
365 GtkIconViewItem *item,
366 GtkIconViewCellInfo *info,
368 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
369 GtkCellRenderer *renderer);
370 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
371 GtkIconViewItem *item);
372 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
378 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
379 GtkCellRenderer *renderer,
380 const gchar *attribute,
382 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
383 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
384 GtkCellRenderer *renderer);
385 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
386 GtkCellRenderer *cell,
387 GtkCellLayoutDataFunc func,
389 GDestroyNotify destroy);
390 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
391 GtkCellRenderer *cell,
393 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
395 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
396 GtkIconViewItem *item,
397 GtkIconViewCellInfo *cell_info,
399 static void gtk_icon_view_put (GtkIconView *icon_view,
401 GtkIconViewItem *item,
403 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
404 GtkIconView *icon_view);
405 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
406 GtkIconViewItem *item,
407 GtkIconViewCellInfo *cell_info,
409 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
410 gboolean cancel_editing);
412 /* Source side drag signals */
413 static void gtk_icon_view_drag_begin (GtkWidget *widget,
414 GdkDragContext *context);
415 static void gtk_icon_view_drag_end (GtkWidget *widget,
416 GdkDragContext *context);
417 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
418 GdkDragContext *context,
419 GtkSelectionData *selection_data,
422 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
423 GdkDragContext *context);
425 /* Target side drag signals */
426 static void gtk_icon_view_drag_leave (GtkWidget *widget,
427 GdkDragContext *context,
429 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
430 GdkDragContext *context,
434 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
435 GdkDragContext *context,
439 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
440 GdkDragContext *context,
443 GtkSelectionData *selection_data,
446 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
447 GdkEventMotion *event);
449 static void remove_scroll_timeout (GtkIconView *icon_view);
450 static void clear_dest_info (GtkIconView *icon_view);
451 static void clear_source_info (GtkIconView *icon_view);
453 static void adjust_wrap_width (GtkIconView *icon_view,
454 GtkIconViewItem *item);
457 static GtkBuildableIface *parent_buildable_iface;
458 static void gtk_icon_view_buildable_init (GtkBuildableIface *iface);
459 static gboolean gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
462 const gchar *tagname,
463 GMarkupParser *parser,
465 static void gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
468 const gchar *tagname,
471 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
473 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
474 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
475 gtk_icon_view_cell_layout_init)
476 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
477 gtk_icon_view_buildable_init))
480 gtk_icon_view_class_init (GtkIconViewClass *klass)
482 GObjectClass *gobject_class;
483 GtkObjectClass *object_class;
484 GtkWidgetClass *widget_class;
485 GtkContainerClass *container_class;
486 GtkBindingSet *binding_set;
488 binding_set = gtk_binding_set_by_class (klass);
490 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
492 gobject_class = (GObjectClass *) klass;
493 object_class = (GtkObjectClass *) klass;
494 widget_class = (GtkWidgetClass *) klass;
495 container_class = (GtkContainerClass *) klass;
497 gobject_class->finalize = gtk_icon_view_finalize;
498 gobject_class->set_property = gtk_icon_view_set_property;
499 gobject_class->get_property = gtk_icon_view_get_property;
501 object_class->destroy = gtk_icon_view_destroy;
503 widget_class->realize = gtk_icon_view_realize;
504 widget_class->unrealize = gtk_icon_view_unrealize;
505 widget_class->style_set = gtk_icon_view_style_set;
506 widget_class->get_accessible = gtk_icon_view_get_accessible;
507 widget_class->size_request = gtk_icon_view_size_request;
508 widget_class->size_allocate = gtk_icon_view_size_allocate;
509 widget_class->expose_event = gtk_icon_view_expose;
510 widget_class->motion_notify_event = gtk_icon_view_motion;
511 widget_class->button_press_event = gtk_icon_view_button_press;
512 widget_class->button_release_event = gtk_icon_view_button_release;
513 widget_class->key_press_event = gtk_icon_view_key_press;
514 widget_class->key_release_event = gtk_icon_view_key_release;
515 widget_class->drag_begin = gtk_icon_view_drag_begin;
516 widget_class->drag_end = gtk_icon_view_drag_end;
517 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
518 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
519 widget_class->drag_leave = gtk_icon_view_drag_leave;
520 widget_class->drag_motion = gtk_icon_view_drag_motion;
521 widget_class->drag_drop = gtk_icon_view_drag_drop;
522 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
523 widget_class->state_changed = gtk_icon_view_state_changed;
525 container_class->remove = gtk_icon_view_remove;
526 container_class->forall = gtk_icon_view_forall;
528 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
529 klass->select_all = gtk_icon_view_real_select_all;
530 klass->unselect_all = gtk_icon_view_real_unselect_all;
531 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
532 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
533 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
534 klass->move_cursor = gtk_icon_view_real_move_cursor;
538 * GtkIconView:selection-mode:
540 * The ::selection-mode property specifies the selection mode of
541 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
542 * is enabled, for the other modes, only keyboard selection is possible.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_enum ("selection-mode",
549 P_("Selection mode"),
550 P_("The selection mode"),
551 GTK_TYPE_SELECTION_MODE,
552 GTK_SELECTION_SINGLE,
553 GTK_PARAM_READWRITE));
556 * GtkIconView:pixbuf-column:
558 * The ::pixbuf-column property contains the number of the model column
559 * containing the pixbufs which are displayed. The pixbuf column must be
560 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
561 * display of pixbufs.
565 g_object_class_install_property (gobject_class,
567 g_param_spec_int ("pixbuf-column",
569 P_("Model column used to retrieve the icon pixbuf from"),
571 GTK_PARAM_READWRITE));
574 * GtkIconView:text-column:
576 * The ::text-column property contains the number of the model column
577 * containing the texts which are displayed. The text column must be
578 * of type #G_TYPE_STRING. If this property and the :markup-column
579 * property are both set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("text-column",
587 P_("Model column used to retrieve the text from"),
589 GTK_PARAM_READWRITE));
593 * GtkIconView:markup-column:
595 * The ::markup-column property contains the number of the model column
596 * containing markup information to be displayed. The markup column must be
597 * of type #G_TYPE_STRING. If this property and the :text-column property
598 * are both set to column numbers, it overrides the text column.
599 * If both are set to -1, no texts are displayed.
603 g_object_class_install_property (gobject_class,
605 g_param_spec_int ("markup-column",
607 P_("Model column used to retrieve the text if using Pango markup"),
609 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_object ("model",
614 P_("Icon View Model"),
615 P_("The model for the icon view"),
617 GTK_PARAM_READWRITE));
620 * GtkIconView:columns:
622 * The columns property contains the number of the columns in which the
623 * items should be displayed. If it is -1, the number of columns will
624 * be chosen automatically to fill the available area.
628 g_object_class_install_property (gobject_class,
630 g_param_spec_int ("columns",
631 P_("Number of columns"),
632 P_("Number of columns to display"),
634 GTK_PARAM_READWRITE));
638 * GtkIconView:item-width:
640 * The item-width property specifies the width to use for each item.
641 * If it is set to -1, the icon view will automatically determine a
642 * suitable item size.
646 g_object_class_install_property (gobject_class,
648 g_param_spec_int ("item-width",
649 P_("Width for each item"),
650 P_("The width used for each item"),
652 GTK_PARAM_READWRITE));
655 * GtkIconView:spacing:
657 * The spacing property specifies the space which is inserted between
658 * the cells (i.e. the icon and the text) of an item.
662 g_object_class_install_property (gobject_class,
664 g_param_spec_int ("spacing",
666 P_("Space which is inserted between cells of an item"),
668 GTK_PARAM_READWRITE));
671 * GtkIconView:row-spacing:
673 * The row-spacing property specifies the space which is inserted between
674 * the rows of the icon view.
678 g_object_class_install_property (gobject_class,
680 g_param_spec_int ("row-spacing",
682 P_("Space which is inserted between grid rows"),
684 GTK_PARAM_READWRITE));
687 * GtkIconView:column-spacing:
689 * The column-spacing property specifies the space which is inserted between
690 * the columns of the icon view.
694 g_object_class_install_property (gobject_class,
696 g_param_spec_int ("column-spacing",
697 P_("Column Spacing"),
698 P_("Space which is inserted between grid columns"),
700 GTK_PARAM_READWRITE));
703 * GtkIconView:margin:
705 * The margin property specifies the space which is inserted
706 * at the edges of the icon view.
710 g_object_class_install_property (gobject_class,
712 g_param_spec_int ("margin",
714 P_("Space which is inserted at the edges of the icon view"),
716 GTK_PARAM_READWRITE));
720 * GtkIconView:orientation:
722 * The orientation property specifies how the cells (i.e. the icon and
723 * the text) of the item are positioned relative to each other.
727 g_object_class_install_property (gobject_class,
729 g_param_spec_enum ("orientation",
731 P_("How the text and icon of each item are positioned relative to each other"),
732 GTK_TYPE_ORIENTATION,
733 GTK_ORIENTATION_VERTICAL,
734 GTK_PARAM_READWRITE));
737 * GtkIconView:reorderable:
739 * The reorderable property specifies if the items can be reordered
744 g_object_class_install_property (gobject_class,
746 g_param_spec_boolean ("reorderable",
748 P_("View is reorderable"),
752 g_object_class_install_property (gobject_class,
754 g_param_spec_int ("tooltip-column",
755 P_("Tooltip Column"),
756 P_("The column in the model containing the tooltip texts for the items"),
760 GTK_PARAM_READWRITE));
764 /* Style properties */
765 gtk_widget_class_install_style_property (widget_class,
766 g_param_spec_boxed ("selection-box-color",
767 P_("Selection Box Color"),
768 P_("Color of the selection box"),
770 GTK_PARAM_READABLE));
772 gtk_widget_class_install_style_property (widget_class,
773 g_param_spec_uchar ("selection-box-alpha",
774 P_("Selection Box Alpha"),
775 P_("Opacity of the selection box"),
778 GTK_PARAM_READABLE));
781 widget_class->set_scroll_adjustments_signal =
782 g_signal_new (I_("set_scroll_adjustments"),
783 G_TYPE_FROM_CLASS (gobject_class),
785 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
787 _gtk_marshal_VOID__OBJECT_OBJECT,
789 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
791 icon_view_signals[ITEM_ACTIVATED] =
792 g_signal_new (I_("item_activated"),
793 G_TYPE_FROM_CLASS (gobject_class),
795 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
797 g_cclosure_marshal_VOID__BOXED,
801 icon_view_signals[SELECTION_CHANGED] =
802 g_signal_new (I_("selection-changed"),
803 G_TYPE_FROM_CLASS (gobject_class),
805 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
807 g_cclosure_marshal_VOID__VOID,
810 icon_view_signals[SELECT_ALL] =
811 g_signal_new (I_("select_all"),
812 G_TYPE_FROM_CLASS (gobject_class),
813 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
814 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
816 g_cclosure_marshal_VOID__VOID,
819 icon_view_signals[UNSELECT_ALL] =
820 g_signal_new (I_("unselect_all"),
821 G_TYPE_FROM_CLASS (gobject_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
825 g_cclosure_marshal_VOID__VOID,
828 icon_view_signals[SELECT_CURSOR_ITEM] =
829 g_signal_new (I_("select_cursor_item"),
830 G_TYPE_FROM_CLASS (gobject_class),
831 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
832 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
834 g_cclosure_marshal_VOID__VOID,
837 icon_view_signals[TOGGLE_CURSOR_ITEM] =
838 g_signal_new (I_("toggle_cursor_item"),
839 G_TYPE_FROM_CLASS (gobject_class),
840 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
841 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
843 g_cclosure_marshal_VOID__VOID,
846 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
847 g_signal_new (I_("activate_cursor_item"),
848 G_TYPE_FROM_CLASS (gobject_class),
849 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
850 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
852 _gtk_marshal_BOOLEAN__VOID,
855 icon_view_signals[MOVE_CURSOR] =
856 g_signal_new (I_("move_cursor"),
857 G_TYPE_FROM_CLASS (gobject_class),
858 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
859 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
861 _gtk_marshal_BOOLEAN__ENUM_INT,
863 GTK_TYPE_MOVEMENT_STEP,
867 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
869 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
871 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
872 "toggle_cursor_item", 0);
873 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, GDK_CONTROL_MASK,
874 "toggle_cursor_item", 0);
876 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
877 "activate_cursor_item", 0);
878 gtk_binding_entry_add_signal (binding_set, GDK_KP_Space, 0,
879 "activate_cursor_item", 0);
880 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
881 "activate_cursor_item", 0);
882 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
883 "activate_cursor_item", 0);
884 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
885 "activate_cursor_item", 0);
887 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
888 GTK_MOVEMENT_DISPLAY_LINES, -1);
889 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
890 GTK_MOVEMENT_DISPLAY_LINES, -1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
893 GTK_MOVEMENT_DISPLAY_LINES, 1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
895 GTK_MOVEMENT_DISPLAY_LINES, 1);
897 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
898 GTK_MOVEMENT_DISPLAY_LINES, -1);
900 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
901 GTK_MOVEMENT_DISPLAY_LINES, 1);
903 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
904 GTK_MOVEMENT_BUFFER_ENDS, -1);
905 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
906 GTK_MOVEMENT_BUFFER_ENDS, -1);
908 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
909 GTK_MOVEMENT_BUFFER_ENDS, 1);
910 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
911 GTK_MOVEMENT_BUFFER_ENDS, 1);
913 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
914 GTK_MOVEMENT_PAGES, -1);
915 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
916 GTK_MOVEMENT_PAGES, -1);
918 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
919 GTK_MOVEMENT_PAGES, 1);
920 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
921 GTK_MOVEMENT_PAGES, 1);
923 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
924 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
925 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
926 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
928 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
929 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
930 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
931 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
935 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
937 parent_buildable_iface = g_type_interface_peek_parent (iface);
938 iface->add_child = _gtk_cell_layout_buildable_add_child;
939 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
940 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
944 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
946 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
947 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
948 iface->clear = gtk_icon_view_cell_layout_clear;
949 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
950 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
951 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
952 iface->reorder = gtk_icon_view_cell_layout_reorder;
953 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
957 gtk_icon_view_init (GtkIconView *icon_view)
959 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
961 icon_view->priv->width = 0;
962 icon_view->priv->height = 0;
963 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
964 icon_view->priv->pressed_button = -1;
965 icon_view->priv->press_start_x = -1;
966 icon_view->priv->press_start_y = -1;
967 icon_view->priv->text_column = -1;
968 icon_view->priv->markup_column = -1;
969 icon_view->priv->pixbuf_column = -1;
970 icon_view->priv->text_cell = -1;
971 icon_view->priv->pixbuf_cell = -1;
972 icon_view->priv->tooltip_column = -1;
974 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
976 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
978 icon_view->priv->cell_list = NULL;
979 icon_view->priv->n_cells = 0;
980 icon_view->priv->cursor_cell = -1;
982 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
984 icon_view->priv->columns = -1;
985 icon_view->priv->item_width = -1;
986 icon_view->priv->spacing = 0;
987 icon_view->priv->row_spacing = 6;
988 icon_view->priv->column_spacing = 6;
989 icon_view->priv->margin = 6;
993 gtk_icon_view_destroy (GtkObject *object)
995 GtkIconView *icon_view;
997 icon_view = GTK_ICON_VIEW (object);
999 gtk_icon_view_stop_editing (icon_view, TRUE);
1001 gtk_icon_view_set_model (icon_view, NULL);
1003 if (icon_view->priv->layout_idle_id != 0)
1005 g_source_remove (icon_view->priv->layout_idle_id);
1006 icon_view->priv->layout_idle_id = 0;
1009 if (icon_view->priv->scroll_to_path != NULL)
1011 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1012 icon_view->priv->scroll_to_path = NULL;
1015 remove_scroll_timeout (icon_view);
1017 if (icon_view->priv->hadjustment != NULL)
1019 g_object_unref (icon_view->priv->hadjustment);
1020 icon_view->priv->hadjustment = NULL;
1023 if (icon_view->priv->vadjustment != NULL)
1025 g_object_unref (icon_view->priv->vadjustment);
1026 icon_view->priv->vadjustment = NULL;
1029 clear_dest_info (icon_view);
1030 clear_source_info (icon_view);
1032 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1035 /* GObject methods */
1037 gtk_icon_view_finalize (GObject *object)
1039 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1041 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1046 gtk_icon_view_set_property (GObject *object,
1048 const GValue *value,
1051 GtkIconView *icon_view;
1053 icon_view = GTK_ICON_VIEW (object);
1057 case PROP_SELECTION_MODE:
1058 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1060 case PROP_PIXBUF_COLUMN:
1061 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1063 case PROP_TEXT_COLUMN:
1064 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1066 case PROP_MARKUP_COLUMN:
1067 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1070 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1072 case PROP_ORIENTATION:
1073 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1076 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1078 case PROP_ITEM_WIDTH:
1079 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1082 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1084 case PROP_ROW_SPACING:
1085 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1087 case PROP_COLUMN_SPACING:
1088 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1091 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1093 case PROP_REORDERABLE:
1094 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1097 case PROP_TOOLTIP_COLUMN:
1098 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1108 gtk_icon_view_get_property (GObject *object,
1113 GtkIconView *icon_view;
1115 icon_view = GTK_ICON_VIEW (object);
1119 case PROP_SELECTION_MODE:
1120 g_value_set_enum (value, icon_view->priv->selection_mode);
1122 case PROP_PIXBUF_COLUMN:
1123 g_value_set_int (value, icon_view->priv->pixbuf_column);
1125 case PROP_TEXT_COLUMN:
1126 g_value_set_int (value, icon_view->priv->text_column);
1128 case PROP_MARKUP_COLUMN:
1129 g_value_set_int (value, icon_view->priv->markup_column);
1132 g_value_set_object (value, icon_view->priv->model);
1134 case PROP_ORIENTATION:
1135 g_value_set_enum (value, icon_view->priv->orientation);
1138 g_value_set_int (value, icon_view->priv->columns);
1140 case PROP_ITEM_WIDTH:
1141 g_value_set_int (value, icon_view->priv->item_width);
1144 g_value_set_int (value, icon_view->priv->spacing);
1146 case PROP_ROW_SPACING:
1147 g_value_set_int (value, icon_view->priv->row_spacing);
1149 case PROP_COLUMN_SPACING:
1150 g_value_set_int (value, icon_view->priv->column_spacing);
1153 g_value_set_int (value, icon_view->priv->margin);
1155 case PROP_REORDERABLE:
1156 g_value_set_boolean (value, icon_view->priv->reorderable);
1158 case PROP_TOOLTIP_COLUMN:
1159 g_value_set_int (value, icon_view->priv->tooltip_column);
1163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1168 /* GtkWidget signals */
1170 gtk_icon_view_realize (GtkWidget *widget)
1172 GtkIconView *icon_view;
1173 GdkWindowAttr attributes;
1174 gint attributes_mask;
1176 icon_view = GTK_ICON_VIEW (widget);
1178 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1180 /* Make the main, clipping window */
1181 attributes.window_type = GDK_WINDOW_CHILD;
1182 attributes.x = widget->allocation.x;
1183 attributes.y = widget->allocation.y;
1184 attributes.width = widget->allocation.width;
1185 attributes.height = widget->allocation.height;
1186 attributes.wclass = GDK_INPUT_OUTPUT;
1187 attributes.visual = gtk_widget_get_visual (widget);
1188 attributes.colormap = gtk_widget_get_colormap (widget);
1189 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1191 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1193 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1194 &attributes, attributes_mask);
1195 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1196 gdk_window_set_user_data (widget->window, widget);
1198 /* Make the window for the icon view */
1201 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1202 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1203 attributes.event_mask = (GDK_EXPOSURE_MASK |
1205 GDK_POINTER_MOTION_MASK |
1206 GDK_BUTTON_PRESS_MASK |
1207 GDK_BUTTON_RELEASE_MASK |
1208 GDK_KEY_PRESS_MASK |
1209 GDK_KEY_RELEASE_MASK) |
1210 gtk_widget_get_events (widget);
1212 icon_view->priv->bin_window = gdk_window_new (widget->window,
1213 &attributes, attributes_mask);
1214 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1216 widget->style = gtk_style_attach (widget->style, widget->window);
1217 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1219 gdk_window_show (icon_view->priv->bin_window);
1223 gtk_icon_view_unrealize (GtkWidget *widget)
1225 GtkIconView *icon_view;
1227 icon_view = GTK_ICON_VIEW (widget);
1229 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1230 gdk_window_destroy (icon_view->priv->bin_window);
1231 icon_view->priv->bin_window = NULL;
1233 /* GtkWidget::unrealize destroys children and widget->window */
1234 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1235 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1239 gtk_icon_view_state_changed (GtkWidget *widget,
1240 GtkStateType previous_state)
1242 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1244 if (GTK_WIDGET_REALIZED (widget))
1246 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1247 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1250 gtk_widget_queue_draw (widget);
1254 gtk_icon_view_style_set (GtkWidget *widget,
1255 GtkStyle *previous_style)
1257 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1259 if (GTK_WIDGET_REALIZED (widget))
1261 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1262 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1265 gtk_widget_queue_resize (widget);
1269 gtk_icon_view_size_request (GtkWidget *widget,
1270 GtkRequisition *requisition)
1272 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1275 requisition->width = icon_view->priv->width;
1276 requisition->height = icon_view->priv->height;
1278 tmp_list = icon_view->priv->children;
1282 GtkIconViewChild *child = tmp_list->data;
1283 GtkRequisition child_requisition;
1285 tmp_list = tmp_list->next;
1287 if (GTK_WIDGET_VISIBLE (child->widget))
1288 gtk_widget_size_request (child->widget, &child_requisition);
1293 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1297 for (list = icon_view->priv->children; list; list = list->next)
1299 GtkIconViewChild *child = list->data;
1300 GtkAllocation allocation;
1302 /* totally ignore our child's requisition */
1303 if (child->cell < 0)
1305 allocation.x = child->item->x;
1306 allocation.y = child->item->y;
1307 allocation.width = child->item->width;
1308 allocation.height = child->item->height;
1312 GdkRectangle *box = &child->item->box[child->cell];
1314 allocation.x = box->x;
1315 allocation.y = box->y;
1316 allocation.width = box->width;
1317 allocation.height = box->height;
1320 gtk_widget_size_allocate (child->widget, &allocation);
1325 gtk_icon_view_size_allocate (GtkWidget *widget,
1326 GtkAllocation *allocation)
1328 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1330 GtkAdjustment *hadjustment, *vadjustment;
1332 widget->allocation = *allocation;
1334 if (GTK_WIDGET_REALIZED (widget))
1336 gdk_window_move_resize (widget->window,
1337 allocation->x, allocation->y,
1338 allocation->width, allocation->height);
1339 gdk_window_resize (icon_view->priv->bin_window,
1340 MAX (icon_view->priv->width, allocation->width),
1341 MAX (icon_view->priv->height, allocation->height));
1344 gtk_icon_view_layout (icon_view);
1346 gtk_icon_view_allocate_children (icon_view);
1348 hadjustment = icon_view->priv->hadjustment;
1349 vadjustment = icon_view->priv->vadjustment;
1351 hadjustment->page_size = allocation->width;
1352 hadjustment->page_increment = allocation->width * 0.9;
1353 hadjustment->step_increment = allocation->width * 0.1;
1354 hadjustment->lower = 0;
1355 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1357 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1358 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1360 vadjustment->page_size = allocation->height;
1361 vadjustment->page_increment = allocation->height * 0.9;
1362 vadjustment->step_increment = allocation->height * 0.1;
1363 vadjustment->lower = 0;
1364 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1366 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1367 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1369 if (GTK_WIDGET_REALIZED (widget) &&
1370 icon_view->priv->scroll_to_path)
1373 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1374 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1375 icon_view->priv->scroll_to_path = NULL;
1377 gtk_icon_view_scroll_to_path (icon_view, path,
1378 icon_view->priv->scroll_to_use_align,
1379 icon_view->priv->scroll_to_row_align,
1380 icon_view->priv->scroll_to_col_align);
1381 gtk_tree_path_free (path);
1385 gtk_adjustment_changed (hadjustment);
1386 gtk_adjustment_changed (vadjustment);
1391 gtk_icon_view_expose (GtkWidget *widget,
1392 GdkEventExpose *expose)
1394 GtkIconView *icon_view;
1399 GtkIconViewDropPosition dest_pos;
1400 GtkIconViewItem *dest_item = NULL;
1402 icon_view = GTK_ICON_VIEW (widget);
1404 if (expose->window != icon_view->priv->bin_window)
1407 cr = gdk_cairo_create (icon_view->priv->bin_window);
1408 cairo_set_line_width (cr, 1.);
1410 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1414 dest_index = gtk_tree_path_get_indices (path)[0];
1415 gtk_tree_path_free (path);
1420 for (icons = icon_view->priv->items; icons; icons = icons->next)
1422 GtkIconViewItem *item = icons->data;
1427 area.width = item->width;
1428 area.height = item->height;
1430 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1433 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1434 icon_view->priv->bin_window,
1435 item->x, item->y, TRUE);
1437 if (dest_index == item->index)
1445 case GTK_ICON_VIEW_DROP_INTO:
1446 gtk_paint_focus (widget->style,
1447 icon_view->priv->bin_window,
1448 GTK_WIDGET_STATE (widget),
1451 "iconview-drop-indicator",
1452 dest_item->x, dest_item->y,
1453 dest_item->width, dest_item->height);
1455 case GTK_ICON_VIEW_DROP_ABOVE:
1456 gtk_paint_focus (widget->style,
1457 icon_view->priv->bin_window,
1458 GTK_WIDGET_STATE (widget),
1461 "iconview-drop-indicator",
1462 dest_item->x, dest_item->y - 1,
1463 dest_item->width, 2);
1465 case GTK_ICON_VIEW_DROP_LEFT:
1466 gtk_paint_focus (widget->style,
1467 icon_view->priv->bin_window,
1468 GTK_WIDGET_STATE (widget),
1471 "iconview-drop-indicator",
1472 dest_item->x - 1, dest_item->y,
1473 2, dest_item->height);
1475 case GTK_ICON_VIEW_DROP_BELOW:
1476 gtk_paint_focus (widget->style,
1477 icon_view->priv->bin_window,
1478 GTK_WIDGET_STATE (widget),
1481 "iconview-drop-indicator",
1482 dest_item->x, dest_item->y + dest_item->height - 1,
1483 dest_item->width, 2);
1485 case GTK_ICON_VIEW_DROP_RIGHT:
1486 gtk_paint_focus (widget->style,
1487 icon_view->priv->bin_window,
1488 GTK_WIDGET_STATE (widget),
1491 "iconview-drop-indicator",
1492 dest_item->x + dest_item->width - 1, dest_item->y,
1493 2, dest_item->height);
1494 case GTK_ICON_VIEW_NO_DROP: ;
1499 if (icon_view->priv->doing_rubberband)
1501 GdkRectangle *rectangles;
1504 gdk_region_get_rectangles (expose->region,
1508 while (n_rectangles--)
1509 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1511 g_free (rectangles);
1516 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1522 rubberband_scroll_timeout (gpointer data)
1524 GtkIconView *icon_view;
1529 value = MIN (icon_view->priv->vadjustment->value +
1530 icon_view->priv->scroll_value_diff,
1531 icon_view->priv->vadjustment->upper -
1532 icon_view->priv->vadjustment->page_size);
1534 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1536 gtk_icon_view_update_rubberband (icon_view);
1542 gtk_icon_view_motion (GtkWidget *widget,
1543 GdkEventMotion *event)
1545 GtkIconView *icon_view;
1548 icon_view = GTK_ICON_VIEW (widget);
1550 gtk_icon_view_maybe_begin_drag (icon_view, event);
1552 if (icon_view->priv->doing_rubberband)
1554 gtk_icon_view_update_rubberband (widget);
1556 abs_y = event->y - icon_view->priv->height *
1557 (icon_view->priv->vadjustment->value /
1558 (icon_view->priv->vadjustment->upper -
1559 icon_view->priv->vadjustment->lower));
1561 if (abs_y < 0 || abs_y > widget->allocation.height)
1564 icon_view->priv->scroll_value_diff = abs_y;
1566 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1568 icon_view->priv->event_last_x = event->x;
1569 icon_view->priv->event_last_y = event->y;
1571 if (icon_view->priv->scroll_timeout_id == 0)
1572 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1576 remove_scroll_timeout (icon_view);
1583 gtk_icon_view_remove (GtkContainer *container,
1586 GtkIconView *icon_view;
1587 GtkIconViewChild *child = NULL;
1590 icon_view = GTK_ICON_VIEW (container);
1592 tmp_list = icon_view->priv->children;
1595 child = tmp_list->data;
1596 if (child->widget == widget)
1598 gtk_widget_unparent (widget);
1600 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1601 g_list_free_1 (tmp_list);
1606 tmp_list = tmp_list->next;
1611 gtk_icon_view_forall (GtkContainer *container,
1612 gboolean include_internals,
1613 GtkCallback callback,
1614 gpointer callback_data)
1616 GtkIconView *icon_view;
1617 GtkIconViewChild *child = NULL;
1620 icon_view = GTK_ICON_VIEW (container);
1622 tmp_list = icon_view->priv->children;
1625 child = tmp_list->data;
1626 tmp_list = tmp_list->next;
1628 (* callback) (child->widget, callback_data);
1633 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1634 GtkIconViewItem *item,
1635 GtkIconViewCellInfo *info,
1640 GdkRectangle cell_area;
1641 gboolean visible, mode;
1643 gtk_icon_view_set_cell_data (icon_view, item);
1645 g_object_get (info->cell,
1646 "visible", &visible,
1650 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1652 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1654 path = gtk_tree_path_new_from_indices (item->index, -1);
1655 path_string = gtk_tree_path_to_string (path);
1656 gtk_tree_path_free (path);
1658 gtk_cell_renderer_activate (info->cell,
1660 GTK_WIDGET (icon_view),
1666 g_free (path_string);
1671 gtk_icon_view_put (GtkIconView *icon_view,
1673 GtkIconViewItem *item,
1676 GtkIconViewChild *child;
1678 child = g_new (GtkIconViewChild, 1);
1680 child->widget = widget;
1684 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1686 if (GTK_WIDGET_REALIZED (icon_view))
1687 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1689 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1693 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1694 GtkIconView *icon_view)
1697 GtkIconViewItem *item;
1699 if (icon_view->priv->edited_item == NULL)
1702 item = icon_view->priv->edited_item;
1703 icon_view->priv->edited_item = NULL;
1704 icon_view->priv->editable = NULL;
1705 for (l = icon_view->priv->cell_list; l; l = l->next)
1707 GtkIconViewCellInfo *info = l->data;
1709 info->editing = FALSE;
1712 if (GTK_WIDGET_HAS_FOCUS (editable))
1713 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1715 g_signal_handlers_disconnect_by_func (editable,
1716 gtk_icon_view_remove_widget,
1719 gtk_container_remove (GTK_CONTAINER (icon_view),
1720 GTK_WIDGET (editable));
1722 gtk_icon_view_queue_draw_item (icon_view, item);
1727 gtk_icon_view_start_editing (GtkIconView *icon_view,
1728 GtkIconViewItem *item,
1729 GtkIconViewCellInfo *info,
1734 GdkRectangle cell_area;
1735 gboolean visible, mode;
1736 GtkCellEditable *editable;
1738 gtk_icon_view_set_cell_data (icon_view, item);
1740 g_object_get (info->cell,
1741 "visible", &visible,
1744 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1746 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1748 path = gtk_tree_path_new_from_indices (item->index, -1);
1749 path_string = gtk_tree_path_to_string (path);
1750 gtk_tree_path_free (path);
1752 editable = gtk_cell_renderer_start_editing (info->cell,
1754 GTK_WIDGET (icon_view),
1759 g_free (path_string);
1761 /* FIXME ugly special case */
1762 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1763 g_object_set (editable, "has-frame", TRUE, NULL);
1765 /* the rest corresponds to tree_view_real_start_editing... */
1766 icon_view->priv->edited_item = item;
1767 icon_view->priv->editable = editable;
1768 info->editing = TRUE;
1770 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1772 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1774 gtk_widget_grab_focus (GTK_WIDGET (editable));
1775 g_signal_connect (editable, "remove_widget",
1776 G_CALLBACK (gtk_icon_view_remove_widget),
1783 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1784 gboolean cancel_editing)
1786 GtkCellRenderer *cell = NULL;
1787 GtkIconViewItem *item;
1790 if (icon_view->priv->edited_item == NULL)
1794 * This is very evil. We need to do this, because
1795 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1796 * later on. If gtk_icon_view_row_changed notices
1797 * icon_view->priv->edited_item != NULL, it'll call
1798 * gtk_icon_view_stop_editing again. Bad things will happen then.
1800 * Please read that again if you intend to modify anything here.
1803 item = icon_view->priv->edited_item;
1804 icon_view->priv->edited_item = NULL;
1806 for (l = icon_view->priv->cell_list; l; l = l->next)
1808 GtkIconViewCellInfo *info = l->data;
1820 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1821 if (!cancel_editing)
1822 gtk_cell_editable_editing_done (icon_view->priv->editable);
1824 icon_view->priv->edited_item = item;
1826 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1830 * gtk_icon_view_set_cursor:
1831 * @icon_view: A #GtkIconView
1832 * @path: A #GtkTreePath
1833 * @cell: One of the cell renderers of @icon_view, or %NULL
1834 * @start_editing: %TRUE if the specified cell should start being edited.
1836 * Sets the current keyboard focus to be at @path, and selects it. This is
1837 * useful when you want to focus the user's attention on a particular item.
1838 * If @cell is not %NULL, then focus is given to the cell specified by
1839 * it. Additionally, if @start_editing is %TRUE, then editing should be
1840 * started in the specified cell.
1842 * This function is often followed by <literal>gtk_widget_grab_focus
1843 * (icon_view)</literal> in order to give keyboard focus to the widget.
1844 * Please note that editing can only happen when the widget is realized.
1849 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1851 GtkCellRenderer *cell,
1852 gboolean start_editing)
1854 GtkIconViewItem *item = NULL;
1855 GtkIconViewCellInfo *info = NULL;
1859 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1860 g_return_if_fail (path != NULL);
1861 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1863 gtk_icon_view_stop_editing (icon_view, TRUE);
1865 if (gtk_tree_path_get_depth (path) == 1)
1866 item = g_list_nth_data (icon_view->priv->items,
1867 gtk_tree_path_get_indices(path)[0]);
1873 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1877 if (info->cell == cell)
1886 g_return_if_fail (cell == NULL || info != NULL);
1888 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1889 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1891 if (info && start_editing)
1892 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1896 * gtk_icon_view_get_cursor:
1897 * @icon_view: A #GtkIconView
1898 * @path: Return location for the current cursor path, or %NULL
1899 * @cell: Return location the current focus cell, or %NULL
1901 * Fills in @path and @cell with the current cursor path and cell.
1902 * If the cursor isn't currently set, then *@path will be %NULL.
1903 * If no cell currently has focus, then *@cell will be %NULL.
1905 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1907 * Return value: %TRUE if the cursor is set.
1912 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1914 GtkCellRenderer **cell)
1916 GtkIconViewItem *item;
1917 GtkIconViewCellInfo *info;
1919 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1921 item = icon_view->priv->cursor_item;
1922 if (icon_view->priv->cursor_cell < 0)
1925 info = g_list_nth_data (icon_view->priv->cell_list,
1926 icon_view->priv->cursor_cell);
1931 *path = gtk_tree_path_new_from_indices (item->index, -1);
1944 return (item != NULL);
1948 gtk_icon_view_button_press (GtkWidget *widget,
1949 GdkEventButton *event)
1951 GtkIconView *icon_view;
1952 GtkIconViewItem *item;
1953 GtkIconViewCellInfo *info = NULL;
1954 gboolean dirty = FALSE;
1955 GtkCellRendererMode mode;
1958 icon_view = GTK_ICON_VIEW (widget);
1960 if (event->window != icon_view->priv->bin_window)
1963 if (!GTK_WIDGET_HAS_FOCUS (widget))
1964 gtk_widget_grab_focus (widget);
1966 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1968 item = gtk_icon_view_get_item_at_coords (icon_view,
1974 g_object_get (info->cell, "mode", &mode, NULL);
1976 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1977 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1978 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1982 gtk_icon_view_scroll_to_item (icon_view, item);
1984 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1986 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1988 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1989 (event->state & GDK_SHIFT_MASK))
1991 gtk_icon_view_unselect_all_internal (icon_view);
1993 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1994 if (!icon_view->priv->anchor_item)
1995 icon_view->priv->anchor_item = item;
1997 gtk_icon_view_select_all_between (icon_view,
1998 icon_view->priv->anchor_item,
2004 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2005 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2006 (event->state & GDK_CONTROL_MASK))
2008 item->selected = !item->selected;
2009 gtk_icon_view_queue_draw_item (icon_view, item);
2014 if (!item->selected)
2016 gtk_icon_view_unselect_all_internal (icon_view);
2018 item->selected = TRUE;
2019 gtk_icon_view_queue_draw_item (icon_view, item);
2023 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2024 icon_view->priv->anchor_item = item;
2027 /* Save press to possibly begin a drag */
2028 if (icon_view->priv->pressed_button < 0)
2030 icon_view->priv->pressed_button = event->button;
2031 icon_view->priv->press_start_x = event->x;
2032 icon_view->priv->press_start_y = event->y;
2035 if (!icon_view->priv->last_single_clicked)
2036 icon_view->priv->last_single_clicked = item;
2038 /* cancel the current editing, if it exists */
2039 gtk_icon_view_stop_editing (icon_view, TRUE);
2041 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2042 gtk_icon_view_item_activate_cell (icon_view, item, info,
2044 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2045 gtk_icon_view_start_editing (icon_view, item, info,
2050 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2051 !(event->state & GDK_CONTROL_MASK))
2053 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2056 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2057 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2062 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2064 item = gtk_icon_view_get_item_at_coords (icon_view,
2069 if (item && item == icon_view->priv->last_single_clicked)
2073 path = gtk_tree_path_new_from_indices (item->index, -1);
2074 gtk_icon_view_item_activated (icon_view, path);
2075 gtk_tree_path_free (path);
2078 icon_view->priv->last_single_clicked = NULL;
2079 icon_view->priv->pressed_button = -1;
2083 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2085 return event->button == 1;
2089 gtk_icon_view_button_release (GtkWidget *widget,
2090 GdkEventButton *event)
2092 GtkIconView *icon_view;
2094 icon_view = GTK_ICON_VIEW (widget);
2096 if (icon_view->priv->pressed_button == event->button)
2097 icon_view->priv->pressed_button = -1;
2099 gtk_icon_view_stop_rubberbanding (icon_view);
2101 remove_scroll_timeout (icon_view);
2107 gtk_icon_view_key_press (GtkWidget *widget,
2110 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2112 if (icon_view->priv->doing_rubberband)
2114 if (event->keyval == GDK_Escape)
2115 gtk_icon_view_stop_rubberbanding (icon_view);
2120 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2124 gtk_icon_view_key_release (GtkWidget *widget,
2127 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2129 if (icon_view->priv->doing_rubberband)
2132 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2136 gtk_icon_view_update_rubberband (gpointer data)
2138 GtkIconView *icon_view;
2140 GdkRectangle old_area;
2141 GdkRectangle new_area;
2142 GdkRectangle common;
2143 GdkRegion *invalid_region;
2145 icon_view = GTK_ICON_VIEW (data);
2147 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2152 old_area.x = MIN (icon_view->priv->rubberband_x1,
2153 icon_view->priv->rubberband_x2);
2154 old_area.y = MIN (icon_view->priv->rubberband_y1,
2155 icon_view->priv->rubberband_y2);
2156 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2157 icon_view->priv->rubberband_x1) + 1;
2158 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2159 icon_view->priv->rubberband_y1) + 1;
2161 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2162 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2163 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2164 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2166 invalid_region = gdk_region_rectangle (&old_area);
2167 gdk_region_union_with_rect (invalid_region, &new_area);
2169 gdk_rectangle_intersect (&old_area, &new_area, &common);
2170 if (common.width > 2 && common.height > 2)
2172 GdkRegion *common_region;
2174 /* make sure the border is invalidated */
2180 common_region = gdk_region_rectangle (&common);
2182 gdk_region_subtract (invalid_region, common_region);
2183 gdk_region_destroy (common_region);
2186 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2188 gdk_region_destroy (invalid_region);
2190 icon_view->priv->rubberband_x2 = x;
2191 icon_view->priv->rubberband_y2 = y;
2193 gtk_icon_view_update_rubberband_selection (icon_view);
2197 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2203 g_assert (!icon_view->priv->doing_rubberband);
2205 for (items = icon_view->priv->items; items; items = items->next)
2207 GtkIconViewItem *item = items->data;
2209 item->selected_before_rubberbanding = item->selected;
2212 icon_view->priv->rubberband_x1 = x;
2213 icon_view->priv->rubberband_y1 = y;
2214 icon_view->priv->rubberband_x2 = x;
2215 icon_view->priv->rubberband_y2 = y;
2217 icon_view->priv->doing_rubberband = TRUE;
2219 gtk_grab_add (GTK_WIDGET (icon_view));
2223 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2225 if (!icon_view->priv->doing_rubberband)
2228 icon_view->priv->doing_rubberband = FALSE;
2230 gtk_grab_remove (GTK_WIDGET (icon_view));
2232 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2236 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2239 gint x, y, width, height;
2240 gboolean dirty = FALSE;
2242 x = MIN (icon_view->priv->rubberband_x1,
2243 icon_view->priv->rubberband_x2);
2244 y = MIN (icon_view->priv->rubberband_y1,
2245 icon_view->priv->rubberband_y2);
2246 width = ABS (icon_view->priv->rubberband_x1 -
2247 icon_view->priv->rubberband_x2);
2248 height = ABS (icon_view->priv->rubberband_y1 -
2249 icon_view->priv->rubberband_y2);
2251 for (items = icon_view->priv->items; items; items = items->next)
2253 GtkIconViewItem *item = items->data;
2257 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2258 x, y, width, height);
2260 selected = is_in ^ item->selected_before_rubberbanding;
2262 if (item->selected != selected)
2264 item->selected = selected;
2266 gtk_icon_view_queue_draw_item (icon_view, item);
2271 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2275 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2276 GtkIconViewItem *item,
2285 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2286 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2289 for (l = icon_view->priv->cell_list; l; l = l->next)
2291 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2293 if (!info->cell->visible)
2296 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2298 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2299 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2307 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2309 gboolean dirty = FALSE;
2312 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2315 for (items = icon_view->priv->items; items; items = items->next)
2317 GtkIconViewItem *item = items->data;
2321 item->selected = FALSE;
2323 gtk_icon_view_queue_draw_item (icon_view, item);
2331 /* GtkIconView signals */
2333 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2334 GtkAdjustment *hadj,
2335 GtkAdjustment *vadj)
2337 gboolean need_adjust = FALSE;
2340 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2342 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2344 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2346 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2348 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2350 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2351 0, 0, NULL, NULL, icon_view);
2352 g_object_unref (icon_view->priv->hadjustment);
2355 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2357 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2358 0, 0, NULL, NULL, icon_view);
2359 g_object_unref (icon_view->priv->vadjustment);
2362 if (icon_view->priv->hadjustment != hadj)
2364 icon_view->priv->hadjustment = hadj;
2365 g_object_ref_sink (icon_view->priv->hadjustment);
2367 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2368 G_CALLBACK (gtk_icon_view_adjustment_changed),
2373 if (icon_view->priv->vadjustment != vadj)
2375 icon_view->priv->vadjustment = vadj;
2376 g_object_ref_sink (icon_view->priv->vadjustment);
2378 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2379 G_CALLBACK (gtk_icon_view_adjustment_changed),
2385 gtk_icon_view_adjustment_changed (NULL, icon_view);
2389 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2391 gtk_icon_view_select_all (icon_view);
2395 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2397 gtk_icon_view_unselect_all (icon_view);
2401 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2403 gtk_icon_view_unselect_all (icon_view);
2405 if (icon_view->priv->cursor_item != NULL)
2406 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2410 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2413 GtkCellRendererMode mode;
2414 GtkIconViewCellInfo *info = NULL;
2416 if (!icon_view->priv->cursor_item)
2419 info = g_list_nth_data (icon_view->priv->cell_list,
2420 icon_view->priv->cursor_cell);
2424 g_object_get (info->cell, "mode", &mode, NULL);
2426 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2428 gtk_icon_view_item_activate_cell (icon_view,
2429 icon_view->priv->cursor_item,
2433 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2435 gtk_icon_view_start_editing (icon_view,
2436 icon_view->priv->cursor_item,
2442 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2443 gtk_icon_view_item_activated (icon_view, path);
2444 gtk_tree_path_free (path);
2450 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2452 if (!icon_view->priv->cursor_item)
2455 switch (icon_view->priv->selection_mode)
2457 case GTK_SELECTION_NONE:
2459 case GTK_SELECTION_BROWSE:
2460 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2462 case GTK_SELECTION_SINGLE:
2463 if (icon_view->priv->cursor_item->selected)
2464 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2466 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2468 case GTK_SELECTION_MULTIPLE:
2469 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2470 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2472 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2477 /* Internal functions */
2479 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2480 GtkIconView *icon_view)
2482 if (GTK_WIDGET_REALIZED (icon_view))
2484 gdk_window_move (icon_view->priv->bin_window,
2485 - icon_view->priv->hadjustment->value,
2486 - icon_view->priv->vadjustment->value);
2488 if (icon_view->priv->doing_rubberband)
2489 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2491 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2496 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2501 gint *maximum_width)
2504 gint x, current_width;
2505 GList *items, *last_item;
2512 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2513 max_height = g_new0 (gint, icon_view->priv->n_cells);
2520 gtk_widget_style_get (GTK_WIDGET (icon_view),
2521 "focus-line-width", &focus_width,
2524 x += icon_view->priv->margin + focus_width;
2525 current_width += 2 * (icon_view->priv->margin + focus_width);
2530 GtkIconViewItem *item = items->data;
2532 gtk_icon_view_calculate_item_size (icon_view, item);
2533 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2535 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2537 current_width += item->width;
2539 if (items != first_item)
2541 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2542 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2546 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2548 item->y = *y + focus_width;
2549 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2551 x = current_width - (icon_view->priv->margin + focus_width);
2553 for (i = 0; i < icon_view->priv->n_cells; i++)
2554 max_height[i] = MAX (max_height[i], item->box[i].height);
2556 if (current_width > *maximum_width)
2557 *maximum_width = current_width;
2563 items = items->next;
2568 /* Now go through the row again and align the icons */
2569 for (items = first_item; items != last_item; items = items->next)
2571 GtkIconViewItem *item = items->data;
2573 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2575 /* We may want to readjust the new y coordinate. */
2576 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2577 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2580 item->col = col - 1 - item->col;
2583 g_free (max_height);
2589 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2592 if (upper != adj->upper)
2594 gdouble min = MAX (0.0, upper - adj->page_size);
2595 gboolean value_changed = FALSE;
2599 if (adj->value > min)
2602 value_changed = TRUE;
2605 gtk_adjustment_changed (adj);
2608 gtk_adjustment_value_changed (adj);
2613 gtk_icon_view_layout (GtkIconView *icon_view)
2615 gint y = 0, maximum_width = 0;
2621 if (icon_view->priv->layout_idle_id != 0)
2623 g_source_remove (icon_view->priv->layout_idle_id);
2624 icon_view->priv->layout_idle_id = 0;
2627 if (icon_view->priv->model == NULL)
2630 widget = GTK_WIDGET (icon_view);
2632 item_width = icon_view->priv->item_width;
2636 for (icons = icon_view->priv->items; icons; icons = icons->next)
2638 GtkIconViewItem *item = icons->data;
2639 gtk_icon_view_calculate_item_size (icon_view, item);
2640 item_width = MAX (item_width, item->width);
2645 icons = icon_view->priv->items;
2646 y += icon_view->priv->margin;
2651 gtk_icon_view_set_cell_data (icon_view, icons->data);
2652 adjust_wrap_width (icon_view, icons->data);
2657 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2659 &y, &maximum_width);
2662 while (icons != NULL);
2664 if (maximum_width != icon_view->priv->width)
2665 icon_view->priv->width = maximum_width;
2667 y += icon_view->priv->margin;
2669 if (y != icon_view->priv->height)
2670 icon_view->priv->height = y;
2672 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2673 icon_view->priv->width);
2674 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2675 icon_view->priv->height);
2677 if (icon_view->priv->width != widget->requisition.width ||
2678 icon_view->priv->height != widget->requisition.height)
2679 gtk_widget_queue_resize_no_redraw (widget);
2681 if (GTK_WIDGET_REALIZED (icon_view))
2682 gdk_window_resize (icon_view->priv->bin_window,
2683 MAX (icon_view->priv->width, widget->allocation.width),
2684 MAX (icon_view->priv->height, widget->allocation.height));
2686 if (icon_view->priv->scroll_to_path)
2690 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2691 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2692 icon_view->priv->scroll_to_path = NULL;
2694 gtk_icon_view_scroll_to_path (icon_view, path,
2695 icon_view->priv->scroll_to_use_align,
2696 icon_view->priv->scroll_to_row_align,
2697 icon_view->priv->scroll_to_col_align);
2698 gtk_tree_path_free (path);
2701 gtk_widget_queue_draw (widget);
2705 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2706 GtkIconViewItem *item,
2707 GtkIconViewCellInfo *info,
2708 GdkRectangle *cell_area)
2710 g_return_if_fail (info->position < item->n_cells);
2712 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2714 cell_area->x = item->box[info->position].x - item->before[info->position];
2715 cell_area->y = item->y;
2716 cell_area->width = item->box[info->position].width +
2717 item->before[info->position] + item->after[info->position];
2718 cell_area->height = item->height;
2722 cell_area->x = item->x;
2723 cell_area->y = item->box[info->position].y - item->before[info->position];
2724 cell_area->width = item->width;
2725 cell_area->height = item->box[info->position].height +
2726 item->before[info->position] + item->after[info->position];
2731 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2732 GtkIconViewItem *item,
2733 GtkIconViewCellInfo *info,
2736 g_return_if_fail (info->position < item->n_cells);
2738 *box = item->box[info->position];
2741 /* try to guess a reasonable wrap width for an implicit text cell renderer
2744 adjust_wrap_width (GtkIconView *icon_view,
2745 GtkIconViewItem *item)
2747 GtkIconViewCellInfo *text_info;
2748 GtkIconViewCellInfo *pixbuf_info;
2749 gint pixbuf_width, wrap_width;
2751 if (icon_view->priv->text_cell != -1 &&
2752 icon_view->priv->pixbuf_cell != -1)
2756 text_info = g_list_nth_data (icon_view->priv->cell_list,
2757 icon_view->priv->text_cell);
2758 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2759 icon_view->priv->pixbuf_cell);
2761 gtk_cell_renderer_get_size (pixbuf_info->cell,
2762 GTK_WIDGET (icon_view),
2768 if (icon_view->priv->item_width > 0)
2769 item_width = icon_view->priv->item_width;
2771 item_width = item->width;
2773 if (item->width == -1)
2776 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2778 wrap_width = MAX (2 * pixbuf_width, 50);
2780 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2781 wrap_width = item_width;
2783 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2785 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2786 g_object_set (text_info->cell, "width", wrap_width, NULL);
2791 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2792 GtkIconViewItem *item)
2797 if (item->width != -1 && item->height != -1)
2800 if (item->n_cells != icon_view->priv->n_cells)
2802 g_free (item->before);
2803 g_free (item->after);
2806 item->before = g_new0 (gint, icon_view->priv->n_cells);
2807 item->after = g_new0 (gint, icon_view->priv->n_cells);
2808 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2810 item->n_cells = icon_view->priv->n_cells;
2813 gtk_icon_view_set_cell_data (icon_view, item);
2815 spacing = icon_view->priv->spacing;
2819 for (l = icon_view->priv->cell_list; l; l = l->next)
2821 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2823 if (!info->cell->visible)
2826 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2828 &item->box[info->position].width,
2829 &item->box[info->position].height);
2831 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2833 item->width += item->box[info->position].width
2834 + (info->position > 0 ? spacing : 0);
2835 item->height = MAX (item->height, item->box[info->position].height);
2839 item->width = MAX (item->width, item->box[info->position].width);
2840 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2846 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2847 GtkIconViewItem *item,
2850 GdkRectangle cell_area;
2856 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2858 gtk_icon_view_set_cell_data (icon_view, item);
2860 spacing = icon_view->priv->spacing;
2863 for (i = 0; i < icon_view->priv->n_cells; i++)
2865 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2866 item->height = MAX (item->height, max_height[i]);
2868 item->height += max_height[i] + (i > 0 ? spacing : 0);
2871 cell_area.x = item->x;
2872 cell_area.y = item->y;
2874 for (k = 0; k < 2; k++)
2875 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2877 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2879 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2882 if (!info->cell->visible)
2885 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2887 cell_area.width = item->box[info->position].width;
2888 cell_area.height = item->height;
2892 cell_area.width = item->width;
2893 cell_area.height = max_height[i];
2896 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2898 &item->box[info->position].x, &item->box[info->position].y,
2899 &item->box[info->position].width, &item->box[info->position].height);
2901 item->box[info->position].x += cell_area.x;
2902 item->box[info->position].y += cell_area.y;
2903 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2905 item->before[info->position] = item->box[info->position].x - cell_area.x;
2906 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2907 cell_area.x += cell_area.width + spacing;
2911 if (item->box[info->position].width > item->width)
2913 item->width = item->box[info->position].width;
2914 cell_area.width = item->width;
2916 item->before[info->position] = item->box[info->position].y - cell_area.y;
2917 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2918 cell_area.y += cell_area.height + spacing;
2922 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2924 for (i = 0; i < icon_view->priv->n_cells; i++)
2926 item->box[i].x = item->x + item->width -
2927 (item->box[i].x + item->box[i].width - item->x);
2933 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2935 g_list_foreach (icon_view->priv->items,
2936 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2940 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2947 gtk_icon_view_paint_item (GtkIconView *icon_view,
2949 GtkIconViewItem *item,
2951 GdkDrawable *drawable,
2954 gboolean draw_focus)
2956 gint focus_width, focus_pad;
2958 GdkRectangle cell_area, box;
2962 GtkCellRendererState flags;
2964 if (icon_view->priv->model == NULL)
2967 gtk_icon_view_set_cell_data (icon_view, item);
2969 gtk_widget_style_get (GTK_WIDGET (icon_view),
2970 "focus-line-width", &focus_width,
2971 "focus-padding", &focus_pad,
2974 padding = focus_width;
2978 flags = GTK_CELL_RENDERER_SELECTED;
2979 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2980 state = GTK_STATE_SELECTED;
2982 state = GTK_STATE_ACTIVE;
2987 state = GTK_STATE_NORMAL;
2990 #ifdef DEBUG_ICON_VIEW
2991 gdk_draw_rectangle (drawable,
2992 GTK_WIDGET (icon_view)->style->black_gc,
2995 item->width, item->height);
2999 for (l = icon_view->priv->cell_list; l; l = l->next)
3001 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3003 if (!info->cell->visible)
3006 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3008 /* FIXME we hardwire background drawing behind text
3009 * cell renderers here
3011 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3013 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
3014 cairo_rectangle (cr,
3015 x - item->x + box.x,
3016 y - item->y + box.y,
3017 box.width, box.height);
3022 for (l = icon_view->priv->cell_list; l; l = l->next)
3024 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3026 if (!info->cell->visible)
3029 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3031 #ifdef DEBUG_ICON_VIEW
3032 gdk_draw_rectangle (drawable,
3033 GTK_WIDGET (icon_view)->style->black_gc,
3035 x - item->x + cell_area.x,
3036 y - item->y + cell_area.y,
3037 cell_area.width, cell_area.height);
3039 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3041 gdk_draw_rectangle (drawable,
3042 GTK_WIDGET (icon_view)->style->black_gc,
3044 x - item->x + box.x,
3045 y - item->y + box.y,
3046 box.width, box.height);
3049 cell_area.x = x - item->x + cell_area.x;
3050 cell_area.y = y - item->y + cell_area.y;
3052 gtk_cell_renderer_render (info->cell,
3054 GTK_WIDGET (icon_view),
3055 &cell_area, &cell_area, area, flags);
3059 /* FIXME where to draw the focus with generic cell renderers ? */
3061 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3062 item == icon_view->priv->cursor_item)
3063 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3065 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3067 if (!info->cell->visible)
3070 if (icon_view->priv->cursor_cell < 0 &&
3071 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3072 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3073 icon_view->priv->cursor_cell = i;
3075 if (i == icon_view->priv->cursor_cell)
3077 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3079 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3083 GTK_WIDGET (icon_view),
3085 x - item->x + box.x - padding,
3086 y - item->y + box.y - padding,
3087 box.width + 2 * padding,
3088 box.height + 2 * padding);
3095 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3100 GdkRectangle rubber_rect;
3101 GdkColor *fill_color_gdk;
3102 guchar fill_color_alpha;
3104 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3105 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3106 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3107 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3109 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3112 gtk_widget_style_get (GTK_WIDGET (icon_view),
3113 "selection-box-color", &fill_color_gdk,
3114 "selection-box-alpha", &fill_color_alpha,
3117 if (!fill_color_gdk)
3118 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3120 cairo_set_source_rgba (cr,
3121 fill_color_gdk->red / 65535.,
3122 fill_color_gdk->green / 65535.,
3123 fill_color_gdk->blue / 65535.,
3124 fill_color_alpha / 255.);
3127 gdk_cairo_rectangle (cr, &rect);
3131 /* Draw the border without alpha */
3132 cairo_set_source_rgb (cr,
3133 fill_color_gdk->red / 65535.,
3134 fill_color_gdk->green / 65535.,
3135 fill_color_gdk->blue / 65535.);
3136 cairo_rectangle (cr,
3137 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3138 rubber_rect.width - 1, rubber_rect.height - 1);
3142 gdk_color_free (fill_color_gdk);
3146 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3152 index = gtk_tree_path_get_indices (path)[0];
3154 for (l = icon_view->priv->items; l; l = l->next)
3156 GtkIconViewItem *item = l->data;
3158 if (item->index == index)
3160 gtk_icon_view_queue_draw_item (icon_view, item);
3167 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3168 GtkIconViewItem *item)
3173 gtk_widget_style_get (GTK_WIDGET (icon_view),
3174 "focus-line-width", &focus_width,
3177 rect.x = item->x - focus_width;
3178 rect.y = item->y - focus_width;
3179 rect.width = item->width + 2 * focus_width;
3180 rect.height = item->height + 2 * focus_width;
3182 if (icon_view->priv->bin_window)
3183 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3187 layout_callback (gpointer user_data)
3189 GtkIconView *icon_view;
3191 icon_view = GTK_ICON_VIEW (user_data);
3193 icon_view->priv->layout_idle_id = 0;
3195 gtk_icon_view_layout (icon_view);
3201 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3203 if (icon_view->priv->layout_idle_id != 0)
3206 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3210 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3211 GtkIconViewItem *item,
3215 AtkObject *item_obj;
3217 if (icon_view->priv->cursor_item == item &&
3218 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3221 if (icon_view->priv->cursor_item != NULL)
3222 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3224 icon_view->priv->cursor_item = item;
3225 if (cursor_cell >= 0)
3226 icon_view->priv->cursor_cell = cursor_cell;
3228 gtk_icon_view_queue_draw_item (icon_view, item);
3230 /* Notify that accessible focus object has changed */
3231 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3232 item_obj = atk_object_ref_accessible_child (obj, item->index);
3234 if (item_obj != NULL)
3236 atk_focus_tracker_notify (item_obj);
3237 g_object_unref (item_obj);
3242 static GtkIconViewItem *
3243 gtk_icon_view_item_new (void)
3245 GtkIconViewItem *item;
3247 item = g_new0 (GtkIconViewItem, 1);
3256 gtk_icon_view_item_free (GtkIconViewItem *item)
3258 g_return_if_fail (item != NULL);
3260 g_free (item->before);
3261 g_free (item->after);
3268 static GtkIconViewItem *
3269 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3272 gboolean only_in_cell,
3273 GtkIconViewCellInfo **cell_at_pos)
3278 for (items = icon_view->priv->items; items; items = items->next)
3280 GtkIconViewItem *item = items->data;
3282 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3283 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3285 if (only_in_cell || cell_at_pos)
3287 gtk_icon_view_set_cell_data (icon_view, item);
3289 for (l = icon_view->priv->cell_list; l; l = l->next)
3291 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3293 if (!info->cell->visible)
3296 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3298 if ((x >= box.x && x <= box.x + box.width &&
3299 y >= box.y && y <= box.y + box.height) ||
3301 x <= box.x + box.width &&
3303 y <= box.y + box.height))
3306 *cell_at_pos = info;
3316 *cell_at_pos = NULL;
3327 gtk_icon_view_select_item (GtkIconView *icon_view,
3328 GtkIconViewItem *item)
3330 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3331 g_return_if_fail (item != NULL);
3336 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3338 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3339 gtk_icon_view_unselect_all_internal (icon_view);
3341 item->selected = TRUE;
3343 gtk_icon_view_queue_draw_item (icon_view, item);
3345 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3350 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3351 GtkIconViewItem *item)
3353 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3354 g_return_if_fail (item != NULL);
3356 if (!item->selected)
3359 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3360 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3363 item->selected = FALSE;
3365 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3367 gtk_icon_view_queue_draw_item (icon_view, item);
3371 verify_items (GtkIconView *icon_view)
3376 for (items = icon_view->priv->items; items; items = items->next)
3378 GtkIconViewItem *item = items->data;
3380 if (item->index != i)
3381 g_error ("List item does not match its index: "
3382 "item index %d and list index %d\n", item->index, i);
3389 gtk_icon_view_row_changed (GtkTreeModel *model,
3394 GtkIconViewItem *item;
3396 GtkIconView *icon_view;
3398 icon_view = GTK_ICON_VIEW (data);
3400 gtk_icon_view_stop_editing (icon_view, TRUE);
3402 index = gtk_tree_path_get_indices(path)[0];
3403 item = g_list_nth_data (icon_view->priv->items, index);
3405 gtk_icon_view_item_invalidate_size (item);
3406 gtk_icon_view_queue_layout (icon_view);
3408 verify_items (icon_view);
3412 gtk_icon_view_row_inserted (GtkTreeModel *model,
3418 GtkIconViewItem *item;
3419 gboolean iters_persist;
3420 GtkIconView *icon_view;
3423 icon_view = GTK_ICON_VIEW (data);
3425 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3427 index = gtk_tree_path_get_indices(path)[0];
3429 item = gtk_icon_view_item_new ();
3434 item->index = index;
3436 /* FIXME: We can be more efficient here,
3437 we can store a tail pointer and use that when
3438 appending (which is a rather common operation)
3440 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3443 list = g_list_nth (icon_view->priv->items, index + 1);
3444 for (; list; list = list->next)
3451 verify_items (icon_view);
3453 gtk_icon_view_queue_layout (icon_view);
3457 gtk_icon_view_row_deleted (GtkTreeModel *model,
3462 GtkIconView *icon_view;
3463 GtkIconViewItem *item;
3465 gboolean emit = FALSE;
3467 icon_view = GTK_ICON_VIEW (data);
3469 index = gtk_tree_path_get_indices(path)[0];
3471 list = g_list_nth (icon_view->priv->items, index);
3474 gtk_icon_view_stop_editing (icon_view, TRUE);
3476 if (item == icon_view->priv->anchor_item)
3477 icon_view->priv->anchor_item = NULL;
3479 if (item == icon_view->priv->cursor_item)
3480 icon_view->priv->cursor_item = NULL;
3485 gtk_icon_view_item_free (item);
3487 for (next = list->next; next; next = next->next)
3494 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3496 verify_items (icon_view);
3498 gtk_icon_view_queue_layout (icon_view);
3501 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3505 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3506 GtkTreePath *parent,
3513 GtkIconView *icon_view;
3514 GList *items = NULL, *list;
3515 GtkIconViewItem **item_array;
3518 icon_view = GTK_ICON_VIEW (data);
3520 gtk_icon_view_stop_editing (icon_view, TRUE);
3522 length = gtk_tree_model_iter_n_children (model, NULL);
3524 order = g_new (gint, length);
3525 for (i = 0; i < length; i++)
3526 order [new_order[i]] = i;
3528 item_array = g_new (GtkIconViewItem *, length);
3529 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3530 item_array[order[i]] = list->data;
3533 for (i = length - 1; i >= 0; i--)
3535 item_array[i]->index = i;
3536 items = g_list_prepend (items, item_array[i]);
3539 g_free (item_array);
3540 g_list_free (icon_view->priv->items);
3541 icon_view->priv->items = items;
3543 gtk_icon_view_queue_layout (icon_view);
3545 verify_items (icon_view);
3549 gtk_icon_view_build_items (GtkIconView *icon_view)
3553 gboolean iters_persist;
3554 GList *items = NULL;
3556 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3558 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3566 GtkIconViewItem *item = gtk_icon_view_item_new ();
3575 items = g_list_prepend (items, item);
3577 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3579 icon_view->priv->items = g_list_reverse (items);
3583 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3586 GtkMovementStep step,
3590 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3591 I_("move_cursor"), 2,
3595 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3600 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3603 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3608 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3615 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3616 GtkMovementStep step,
3619 GdkModifierType state;
3621 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3622 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3623 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3624 step == GTK_MOVEMENT_DISPLAY_LINES ||
3625 step == GTK_MOVEMENT_PAGES ||
3626 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3628 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3631 gtk_icon_view_stop_editing (icon_view, FALSE);
3632 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3634 if (gtk_get_current_event_state (&state))
3636 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3637 icon_view->priv->ctrl_pressed = TRUE;
3638 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3639 icon_view->priv->shift_pressed = TRUE;
3641 /* else we assume not pressed */
3645 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3646 case GTK_MOVEMENT_VISUAL_POSITIONS:
3647 gtk_icon_view_move_cursor_left_right (icon_view, count);
3649 case GTK_MOVEMENT_DISPLAY_LINES:
3650 gtk_icon_view_move_cursor_up_down (icon_view, count);
3652 case GTK_MOVEMENT_PAGES:
3653 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3655 case GTK_MOVEMENT_BUFFER_ENDS:
3656 gtk_icon_view_move_cursor_start_end (icon_view, count);
3659 g_assert_not_reached ();
3662 icon_view->priv->ctrl_pressed = FALSE;
3663 icon_view->priv->shift_pressed = FALSE;
3668 static GtkIconViewItem *
3669 find_item (GtkIconView *icon_view,
3670 GtkIconViewItem *current,
3676 GtkIconViewItem *item;
3678 /* FIXME: this could be more efficient
3680 row = current->row + row_ofs;
3681 col = current->col + col_ofs;
3683 for (items = icon_view->priv->items; items; items = items->next)
3686 if (item->row == row && item->col == col)
3694 find_cell (GtkIconView *icon_view,
3695 GtkIconViewItem *item,
3697 GtkOrientation orientation,
3708 if (icon_view->priv->orientation != orientation)
3711 gtk_icon_view_set_cell_data (icon_view, item);
3713 focusable = g_new0 (gint, icon_view->priv->n_cells);
3718 for (k = 0; k < 2; k++)
3719 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3721 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3723 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3726 if (!info->cell->visible)
3729 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3732 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3735 current = n_focusable;
3737 focusable[n_focusable] = i;
3743 if (n_focusable == 0)
3744 focusable[n_focusable++] = first_text;
3748 current = step > 0 ? 0 : n_focusable - 1;
3749 cell = focusable[current];
3752 if (current + *count < 0)
3755 *count = current + *count;
3757 else if (current + *count > n_focusable - 1)
3760 *count = current + *count - (n_focusable - 1);
3764 cell = focusable[current + *count];
3773 static GtkIconViewItem *
3774 find_item_page_up_down (GtkIconView *icon_view,
3775 GtkIconViewItem *current,
3782 y = current->y + count * icon_view->priv->vadjustment->page_size;
3784 item = g_list_find (icon_view->priv->items, current);
3789 for (next = item->next; next; next = next->next)
3791 if (((GtkIconViewItem *)next->data)->col == col)
3794 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3804 for (next = item->prev; next; next = next->prev)
3806 if (((GtkIconViewItem *)next->data)->col == col)
3809 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3823 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3824 GtkIconViewItem *anchor,
3825 GtkIconViewItem *cursor)
3828 GtkIconViewItem *item;
3829 gint row1, row2, col1, col2;
3830 gboolean dirty = FALSE;
3832 if (anchor->row < cursor->row)
3843 if (anchor->col < cursor->col)
3854 for (items = icon_view->priv->items; items; items = items->next)
3858 if (row1 <= item->row && item->row <= row2 &&
3859 col1 <= item->col && item->col <= col2)
3861 if (!item->selected)
3864 item->selected = TRUE;
3866 gtk_icon_view_queue_draw_item (icon_view, item);
3874 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3877 GtkIconViewItem *item;
3879 gboolean dirty = FALSE;
3882 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3885 if (!icon_view->priv->cursor_item)
3890 list = icon_view->priv->items;
3892 list = g_list_last (icon_view->priv->items);
3894 item = list ? list->data : NULL;
3899 item = icon_view->priv->cursor_item;
3900 cell = icon_view->priv->cursor_cell;
3901 step = count > 0 ? 1 : -1;
3904 cell = find_cell (icon_view, item, cell,
3905 GTK_ORIENTATION_VERTICAL,
3910 item = find_item (icon_view, item, step, 0);
3911 count = count - step;
3917 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3921 if (icon_view->priv->ctrl_pressed ||
3922 !icon_view->priv->shift_pressed ||
3923 !icon_view->priv->anchor_item ||
3924 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3925 icon_view->priv->anchor_item = item;
3927 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3929 if (!icon_view->priv->ctrl_pressed &&
3930 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3932 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3933 dirty = gtk_icon_view_select_all_between (icon_view,
3934 icon_view->priv->anchor_item,
3938 gtk_icon_view_scroll_to_item (icon_view, item);
3941 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3945 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3948 GtkIconViewItem *item;
3949 gboolean dirty = FALSE;
3951 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3954 if (!icon_view->priv->cursor_item)
3959 list = icon_view->priv->items;
3961 list = g_list_last (icon_view->priv->items);
3963 item = list ? list->data : NULL;
3966 item = find_item_page_up_down (icon_view,
3967 icon_view->priv->cursor_item,
3970 if (item == icon_view->priv->cursor_item)
3971 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3976 if (icon_view->priv->ctrl_pressed ||
3977 !icon_view->priv->shift_pressed ||
3978 !icon_view->priv->anchor_item ||
3979 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3980 icon_view->priv->anchor_item = item;
3982 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3984 if (!icon_view->priv->ctrl_pressed &&
3985 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3987 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3988 dirty = gtk_icon_view_select_all_between (icon_view,
3989 icon_view->priv->anchor_item,
3993 gtk_icon_view_scroll_to_item (icon_view, item);
3996 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4000 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4003 GtkIconViewItem *item;
4005 gboolean dirty = FALSE;
4008 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4011 if (!icon_view->priv->cursor_item)
4016 list = icon_view->priv->items;
4018 list = g_list_last (icon_view->priv->items);
4020 item = list ? list->data : NULL;
4024 item = icon_view->priv->cursor_item;
4025 cell = icon_view->priv->cursor_cell;
4026 step = count > 0 ? 1 : -1;
4029 cell = find_cell (icon_view, item, cell,
4030 GTK_ORIENTATION_HORIZONTAL,
4035 item = find_item (icon_view, item, 0, step);
4036 count = count - step;
4042 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4046 if (icon_view->priv->ctrl_pressed ||
4047 !icon_view->priv->shift_pressed ||
4048 !icon_view->priv->anchor_item ||
4049 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4050 icon_view->priv->anchor_item = item;
4052 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4054 if (!icon_view->priv->ctrl_pressed &&
4055 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4057 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4058 dirty = gtk_icon_view_select_all_between (icon_view,
4059 icon_view->priv->anchor_item,
4063 gtk_icon_view_scroll_to_item (icon_view, item);
4066 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4070 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4073 GtkIconViewItem *item;
4075 gboolean dirty = FALSE;
4077 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4081 list = icon_view->priv->items;
4083 list = g_list_last (icon_view->priv->items);
4085 item = list ? list->data : NULL;
4087 if (item == icon_view->priv->cursor_item)
4088 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4093 if (icon_view->priv->ctrl_pressed ||
4094 !icon_view->priv->shift_pressed ||
4095 !icon_view->priv->anchor_item ||
4096 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4097 icon_view->priv->anchor_item = item;
4099 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4101 if (!icon_view->priv->ctrl_pressed &&
4102 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4104 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4105 dirty = gtk_icon_view_select_all_between (icon_view,
4106 icon_view->priv->anchor_item,
4110 gtk_icon_view_scroll_to_item (icon_view, item);
4113 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4117 * gtk_icon_view_scroll_to_path:
4118 * @icon_view: A #GtkIconView.
4119 * @path: The path of the item to move to.
4120 * @use_align: whether to use alignment arguments, or %FALSE.
4121 * @row_align: The vertical alignment of the item specified by @path.
4122 * @col_align: The horizontal alignment of the item specified by @path.
4124 * Moves the alignments of @icon_view to the position specified by @path.
4125 * @row_align determines where the row is placed, and @col_align determines
4126 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4127 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4130 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4131 * tree does the minimum amount of work to scroll the item onto the screen.
4132 * This means that the item will be scrolled to the edge closest to its current
4133 * position. If the item is currently visible on the screen, nothing is done.
4135 * This function only works if the model is set, and @path is a valid row on
4136 * the model. If the model changes before the @icon_view is realized, the
4137 * centered path will be modified to reflect this change.
4142 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4148 GtkIconViewItem *item = NULL;
4150 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4151 g_return_if_fail (path != NULL);
4152 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4153 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4155 if (gtk_tree_path_get_depth (path) > 0)
4156 item = g_list_nth_data (icon_view->priv->items,
4157 gtk_tree_path_get_indices(path)[0]);
4159 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4161 if (icon_view->priv->scroll_to_path)
4162 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4164 icon_view->priv->scroll_to_path = NULL;
4167 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4169 icon_view->priv->scroll_to_use_align = use_align;
4170 icon_view->priv->scroll_to_row_align = row_align;
4171 icon_view->priv->scroll_to_col_align = col_align;
4180 gfloat offset, value;
4182 gtk_widget_style_get (GTK_WIDGET (icon_view),
4183 "focus-line-width", &focus_width,
4186 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4188 offset = y + item->y - focus_width -
4189 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4190 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4191 icon_view->priv->vadjustment->lower,
4192 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4193 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4195 offset = x + item->x - focus_width -
4196 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4197 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4198 icon_view->priv->hadjustment->lower,
4199 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4200 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4202 gtk_adjustment_changed (icon_view->priv->hadjustment);
4203 gtk_adjustment_changed (icon_view->priv->vadjustment);
4206 gtk_icon_view_scroll_to_item (icon_view, item);
4211 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4212 GtkIconViewItem *item)
4214 gint x, y, width, height;
4217 gtk_widget_style_get (GTK_WIDGET (icon_view),
4218 "focus-line-width", &focus_width,
4221 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4223 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4225 if (y + item->y - focus_width < 0)
4226 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4227 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4228 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4229 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4230 icon_view->priv->vadjustment->value + y + item->y + item->height
4231 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4233 if (x + item->x - focus_width < 0)
4234 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4235 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4236 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4237 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4238 icon_view->priv->hadjustment->value + x + item->x + item->width
4239 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4241 gtk_adjustment_changed (icon_view->priv->hadjustment);
4242 gtk_adjustment_changed (icon_view->priv->vadjustment);
4245 /* GtkCellLayout implementation */
4246 static GtkIconViewCellInfo *
4247 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4248 GtkCellRenderer *renderer)
4252 for (i = icon_view->priv->cell_list; i; i = i->next)
4254 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4256 if (info->cell == renderer)
4264 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4265 GtkIconViewItem *item)
4268 gboolean iters_persist;
4271 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4277 path = gtk_tree_path_new_from_indices (item->index, -1);
4278 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4280 gtk_tree_path_free (path);
4285 for (i = icon_view->priv->cell_list; i; i = i->next)
4288 GtkIconViewCellInfo *info = i->data;
4290 g_object_freeze_notify (G_OBJECT (info->cell));
4292 for (j = info->attributes; j && j->next; j = j->next->next)
4294 gchar *property = j->data;
4295 gint column = GPOINTER_TO_INT (j->next->data);
4296 GValue value = {0, };
4298 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4300 g_object_set_property (G_OBJECT (info->cell),
4302 g_value_unset (&value);
4306 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4308 icon_view->priv->model,
4312 g_object_thaw_notify (G_OBJECT (info->cell));
4317 free_cell_attributes (GtkIconViewCellInfo *info)
4321 list = info->attributes;
4322 while (list && list->next)
4324 g_free (list->data);
4325 list = list->next->next;
4328 g_slist_free (info->attributes);
4329 info->attributes = NULL;
4333 free_cell_info (GtkIconViewCellInfo *info)
4335 free_cell_attributes (info);
4337 g_object_unref (info->cell);
4340 (* info->destroy) (info->func_data);
4346 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4347 GtkCellRenderer *renderer,
4350 GtkIconViewCellInfo *info;
4351 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4353 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4354 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4356 g_object_ref_sink (renderer);
4358 info = g_new0 (GtkIconViewCellInfo, 1);
4359 info->cell = renderer;
4360 info->expand = expand ? TRUE : FALSE;
4361 info->pack = GTK_PACK_START;
4362 info->position = icon_view->priv->n_cells;
4364 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4365 icon_view->priv->n_cells++;
4369 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4370 GtkCellRenderer *renderer,
4373 GtkIconViewCellInfo *info;
4374 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4376 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4377 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4379 g_object_ref_sink (renderer);
4381 info = g_new0 (GtkIconViewCellInfo, 1);
4382 info->cell = renderer;
4383 info->expand = expand ? TRUE : FALSE;
4384 info->pack = GTK_PACK_END;
4385 info->position = icon_view->priv->n_cells;
4387 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4388 icon_view->priv->n_cells++;
4392 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4393 GtkCellRenderer *renderer,
4394 const gchar *attribute,
4397 GtkIconViewCellInfo *info;
4398 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4400 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4401 g_return_if_fail (info != NULL);
4403 info->attributes = g_slist_prepend (info->attributes,
4404 GINT_TO_POINTER (column));
4405 info->attributes = g_slist_prepend (info->attributes,
4406 g_strdup (attribute));
4410 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4412 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4414 while (icon_view->priv->cell_list)
4416 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4417 free_cell_info (info);
4418 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4419 icon_view->priv->cell_list);
4422 icon_view->priv->n_cells = 0;
4426 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4427 GtkCellRenderer *cell,
4428 GtkCellLayoutDataFunc func,
4430 GDestroyNotify destroy)
4432 GtkIconViewCellInfo *info;
4433 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4435 info = gtk_icon_view_get_cell_info (icon_view, cell);
4436 g_return_if_fail (info != NULL);
4440 GDestroyNotify d = info->destroy;
4442 info->destroy = NULL;
4443 d (info->func_data);
4447 info->func_data = func_data;
4448 info->destroy = destroy;
4452 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4453 GtkCellRenderer *renderer)
4455 GtkIconViewCellInfo *info;
4457 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4459 free_cell_attributes (info);
4463 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4464 GtkCellRenderer *cell,
4467 GtkIconView *icon_view;
4469 GtkIconViewCellInfo *info;
4472 icon_view = GTK_ICON_VIEW (layout);
4474 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4476 info = gtk_icon_view_get_cell_info (icon_view, cell);
4478 g_return_if_fail (info != NULL);
4479 g_return_if_fail (position >= 0);
4481 link = g_list_find (icon_view->priv->cell_list, info);
4483 g_return_if_fail (link != NULL);
4485 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4487 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4490 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4497 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4501 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4503 GtkIconView *icon_view = (GtkIconView *)layout;
4504 GList *retval = NULL, *l;
4506 for (l = icon_view->priv->cell_list; l; l = l->next)
4508 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4510 retval = g_list_prepend (retval, info->cell);
4513 return g_list_reverse (retval);
4520 * gtk_icon_view_new:
4522 * Creates a new #GtkIconView widget
4524 * Return value: A newly created #GtkIconView widget
4529 gtk_icon_view_new (void)
4531 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4535 * gtk_icon_view_new_with_model:
4536 * @model: The model.
4538 * Creates a new #GtkIconView widget with the model @model.
4540 * Return value: A newly created #GtkIconView widget.
4545 gtk_icon_view_new_with_model (GtkTreeModel *model)
4547 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4551 * gtk_icon_view_convert_widget_to_bin_window_coords:
4552 * @wx: X coordinate relative to the widget
4553 * @wy: Y coordinate relative to the widget
4554 * @bx: return location for bin_window X coordinate
4555 * @by: return location for bin_window Y coordinate
4557 * Converts widget coordinates to coordinates for the bin_window,
4558 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4563 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4571 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4573 if (icon_view->priv->bin_window)
4574 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4585 * gtk_icon_view_get_path_at_pos:
4586 * @icon_view: A #GtkIconView.
4587 * @x: The x position to be identified
4588 * @y: The y position to be identified
4590 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4591 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4592 * the cell at the specified position.
4593 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4594 * widget coordinates to bin_window coordinates.
4596 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4597 * if no icon exists at that position.
4602 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4606 GtkIconViewItem *item;
4609 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4611 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4616 path = gtk_tree_path_new_from_indices (item->index, -1);
4622 * gtk_icon_view_get_item_at_pos:
4623 * @icon_view: A #GtkIconView.
4624 * @x: The x position to be identified
4625 * @y: The y position to be identified
4626 * @path: Return location for the path, or %NULL
4627 * @cell: Return location for the renderer responsible for the cell
4628 * at (@x, @y), or %NULL
4630 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4631 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4632 * obtains the cell at the specified position. The returned path should
4633 * be freed with gtk_tree_path_free().
4634 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4635 * widget coordinates to bin_window coordinates.
4637 * Return value: %TRUE if an item exists at the specified position
4642 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4646 GtkCellRenderer **cell)
4648 GtkIconViewItem *item;
4649 GtkIconViewCellInfo *info;
4651 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4653 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4658 *path = gtk_tree_path_new_from_indices (item->index, -1);
4671 return (item != NULL);
4675 * gtk_icon_view_set_tooltip_item:
4676 * @icon_view: a #GtkIconView
4677 * @tooltip: a #GtkTooltip
4678 * @path: a #GtkTreePath
4680 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4681 * See also gtk_tooltip_set_tip_area().
4686 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4687 GtkTooltip *tooltip,
4690 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4691 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4693 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4697 * gtk_icon_view_set_tooltip_cell:
4698 * @icon_view: a #GtkIconView
4699 * @tooltip: a #GtkTooltip
4700 * @path: a #GtkTreePath
4701 * @cell: a #GtkCellRenderer or %NULL
4703 * Sets the tip area of @tooltip to the area which @cell occupies in
4704 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4709 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4710 GtkTooltip *tooltip,
4712 GtkCellRenderer *cell)
4715 GtkIconViewItem *item = NULL;
4716 GtkIconViewCellInfo *info = NULL;
4719 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4720 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4721 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4723 if (gtk_tree_path_get_depth (path) > 0)
4724 item = g_list_nth_data (icon_view->priv->items,
4725 gtk_tree_path_get_indices(path)[0]);
4732 info = gtk_icon_view_get_cell_info (icon_view, cell);
4733 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4739 rect.width = item->width;
4740 rect.height = item->height;
4743 if (icon_view->priv->bin_window)
4745 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4750 gtk_tooltip_set_tip_area (tooltip, &rect);
4755 * gtk_icon_view_get_tooltip_context:
4756 * @icon_view: an #GtkIconView
4757 * @x: the x coordinate (relative to widget coordinates)
4758 * @y: the y coordinate (relative to widget coordinates)
4759 * @keyboard_tip: whether this is a keyboard tooltip or not
4760 * @model: a pointer to receive a #GtkTreeModel or %NULL
4761 * @path: a pointer to receive a #GtkTreePath or %NULL
4762 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4764 * This function is supposed to be used in a #GtkWidget::query-tooltip
4765 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4766 * which are received in the signal handler, should be passed to this
4767 * function without modification.
4769 * The return value indicates whether there is an icon view item at the given
4770 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4771 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4772 * @model, @path and @iter which have been provided will be set to point to
4773 * that row and the corresponding model. @x and @y will always be converted
4774 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4776 * Return value: whether or not the given tooltip context points to a item
4781 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4784 gboolean keyboard_tip,
4785 GtkTreeModel **model,
4789 GtkTreePath *tmppath = NULL;
4791 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4792 g_return_val_if_fail (x != NULL, FALSE);
4793 g_return_val_if_fail (y != NULL, FALSE);
4797 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4804 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4807 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4812 *model = gtk_icon_view_get_model (icon_view);
4815 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4821 gtk_tree_path_free (tmppath);
4827 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4830 gboolean keyboard_tip,
4831 GtkTooltip *tooltip,
4837 GtkTreeModel *model;
4838 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4840 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4843 &model, &path, &iter))
4846 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4850 gtk_tree_path_free (path);
4854 gtk_tooltip_set_markup (tooltip, str);
4855 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4857 gtk_tree_path_free (path);
4865 * gtk_icon_view_set_tooltip_column:
4866 * @icon_view: a #GtkIconView
4868 * @column: an integer, which is a valid column number for @icon_view's model
4870 * If you only plan to have simple (text-only) tooltips on full items, you
4871 * can use this function to have #GtkIconView handle these automatically
4872 * for you. @column should be set to the column in @icon_view's model
4873 * containing the tooltip texts, or -1 to disable this feature.
4875 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4876 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4881 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4884 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4886 if (column == icon_view->priv->tooltip_column)
4891 g_signal_handlers_disconnect_by_func (icon_view,
4892 gtk_icon_view_set_tooltip_query_cb,
4894 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4898 if (icon_view->priv->tooltip_column == -1)
4900 g_signal_connect (icon_view, "query-tooltip",
4901 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4902 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4906 icon_view->priv->tooltip_column = column;
4907 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4911 * gtk_icon_view_get_tooltip_column:
4912 * @icon_view: a #GtkIconView
4914 * Returns the column of @icon_view's model which is being used for
4915 * displaying tooltips on @icon_view's rows.
4917 * Return value: the index of the tooltip column that is currently being
4918 * used, or -1 if this is disabled.
4923 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4925 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4927 return icon_view->priv->tooltip_column;
4931 * gtk_icon_view_get_visible_range:
4932 * @icon_view: A #GtkIconView
4933 * @start_path: Return location for start of region, or %NULL
4934 * @end_path: Return location for end of region, or %NULL
4936 * Sets @start_path and @end_path to be the first and last visible path.
4937 * Note that there may be invisible paths in between.
4939 * Both paths should be freed with gtk_tree_path_free() after use.
4941 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4946 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4947 GtkTreePath **start_path,
4948 GtkTreePath **end_path)
4950 gint start_index = -1;
4951 gint end_index = -1;
4954 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4956 if (icon_view->priv->hadjustment == NULL ||
4957 icon_view->priv->vadjustment == NULL)
4960 if (start_path == NULL && end_path == NULL)
4963 for (icons = icon_view->priv->items; icons; icons = icons->next)
4965 GtkIconViewItem *item = icons->data;
4967 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4968 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4969 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4970 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4972 if (start_index == -1)
4973 start_index = item->index;
4974 end_index = item->index;
4978 if (start_path && start_index != -1)
4979 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4980 if (end_path && end_index != -1)
4981 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4983 return start_index != -1;
4987 * gtk_icon_view_selected_foreach:
4988 * @icon_view: A #GtkIconView.
4989 * @func: The funcion to call for each selected icon.
4990 * @data: User data to pass to the function.
4992 * Calls a function for each selected icon. Note that the model or
4993 * selection cannot be modified from within this function.
4998 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4999 GtkIconViewForeachFunc func,
5004 for (list = icon_view->priv->items; list; list = list->next)
5006 GtkIconViewItem *item = list->data;
5007 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5010 (* func) (icon_view, path, data);
5012 gtk_tree_path_free (path);
5017 * gtk_icon_view_set_selection_mode:
5018 * @icon_view: A #GtkIconView.
5019 * @mode: The selection mode
5021 * Sets the selection mode of the @icon_view.
5026 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5027 GtkSelectionMode mode)
5029 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5031 if (mode == icon_view->priv->selection_mode)
5034 if (mode == GTK_SELECTION_NONE ||
5035 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5036 gtk_icon_view_unselect_all (icon_view);
5038 icon_view->priv->selection_mode = mode;
5040 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5044 * gtk_icon_view_get_selection_mode:
5045 * @icon_view: A #GtkIconView.
5047 * Gets the selection mode of the @icon_view.
5049 * Return value: the current selection mode
5054 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5056 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5058 return icon_view->priv->selection_mode;
5062 * gtk_icon_view_set_model:
5063 * @icon_view: A #GtkIconView.
5064 * @model: The model.
5066 * Sets the model for a #GtkIconView.
5067 * If the @icon_view already has a model set, it will remove
5068 * it before setting the new model. If @model is %NULL, then
5069 * it will unset the old model.
5074 gtk_icon_view_set_model (GtkIconView *icon_view,
5075 GtkTreeModel *model)
5077 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5078 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5080 if (icon_view->priv->model == model)
5083 if (icon_view->priv->scroll_to_path)
5085 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5086 icon_view->priv->scroll_to_path = NULL;
5089 gtk_icon_view_stop_editing (icon_view, TRUE);
5095 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5097 if (icon_view->priv->pixbuf_column != -1)
5099 column_type = gtk_tree_model_get_column_type (model,
5100 icon_view->priv->pixbuf_column);
5102 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5105 if (icon_view->priv->text_column != -1)
5107 column_type = gtk_tree_model_get_column_type (model,
5108 icon_view->priv->text_column);
5110 g_return_if_fail (column_type == G_TYPE_STRING);
5113 if (icon_view->priv->markup_column != -1)
5115 column_type = gtk_tree_model_get_column_type (model,
5116 icon_view->priv->markup_column);
5118 g_return_if_fail (column_type == G_TYPE_STRING);
5123 if (icon_view->priv->model)
5125 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5126 gtk_icon_view_row_changed,
5128 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5129 gtk_icon_view_row_inserted,
5131 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5132 gtk_icon_view_row_deleted,
5134 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5135 gtk_icon_view_rows_reordered,
5138 g_object_unref (icon_view->priv->model);
5140 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5141 g_list_free (icon_view->priv->items);
5142 icon_view->priv->items = NULL;
5143 icon_view->priv->anchor_item = NULL;
5144 icon_view->priv->cursor_item = NULL;
5145 icon_view->priv->last_single_clicked = NULL;
5146 icon_view->priv->width = 0;
5147 icon_view->priv->height = 0;
5150 icon_view->priv->model = model;
5152 if (icon_view->priv->model)
5154 g_object_ref (icon_view->priv->model);
5155 g_signal_connect (icon_view->priv->model,
5157 G_CALLBACK (gtk_icon_view_row_changed),
5159 g_signal_connect (icon_view->priv->model,
5161 G_CALLBACK (gtk_icon_view_row_inserted),
5163 g_signal_connect (icon_view->priv->model,
5165 G_CALLBACK (gtk_icon_view_row_deleted),
5167 g_signal_connect (icon_view->priv->model,
5169 G_CALLBACK (gtk_icon_view_rows_reordered),
5172 gtk_icon_view_build_items (icon_view);
5174 gtk_icon_view_queue_layout (icon_view);
5177 g_object_notify (G_OBJECT (icon_view), "model");
5179 if (GTK_WIDGET_REALIZED (icon_view))
5180 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5184 * gtk_icon_view_get_model:
5185 * @icon_view: a #GtkIconView
5187 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5190 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5195 gtk_icon_view_get_model (GtkIconView *icon_view)
5197 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5199 return icon_view->priv->model;
5203 update_text_cell (GtkIconView *icon_view)
5205 GtkIconViewCellInfo *info;
5209 if (icon_view->priv->text_column == -1 &&
5210 icon_view->priv->markup_column == -1)
5212 if (icon_view->priv->text_cell != -1)
5214 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5215 icon_view->priv->pixbuf_cell--;
5217 info = g_list_nth_data (icon_view->priv->cell_list,
5218 icon_view->priv->text_cell);
5220 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5222 free_cell_info (info);
5224 icon_view->priv->n_cells--;
5225 icon_view->priv->text_cell = -1;
5230 if (icon_view->priv->text_cell == -1)
5232 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5233 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5234 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5237 if (info->cell == cell)
5239 icon_view->priv->text_cell = i;
5245 info = g_list_nth_data (icon_view->priv->cell_list,
5246 icon_view->priv->text_cell);
5248 if (icon_view->priv->markup_column != -1)
5249 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5251 "markup", icon_view->priv->markup_column,
5254 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5256 "text", icon_view->priv->text_column,
5259 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5260 g_object_set (info->cell,
5261 "alignment", PANGO_ALIGN_CENTER,
5262 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5267 g_object_set (info->cell,
5268 "alignment", PANGO_ALIGN_LEFT,
5269 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5277 update_pixbuf_cell (GtkIconView *icon_view)
5279 GtkIconViewCellInfo *info;
5283 if (icon_view->priv->pixbuf_column == -1)
5285 if (icon_view->priv->pixbuf_cell != -1)
5287 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5288 icon_view->priv->text_cell--;
5290 info = g_list_nth_data (icon_view->priv->cell_list,
5291 icon_view->priv->pixbuf_cell);
5293 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5295 free_cell_info (info);
5297 icon_view->priv->n_cells--;
5298 icon_view->priv->pixbuf_cell = -1;
5303 if (icon_view->priv->pixbuf_cell == -1)
5305 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5307 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5308 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5311 if (info->cell == cell)
5313 icon_view->priv->pixbuf_cell = i;
5319 info = g_list_nth_data (icon_view->priv->cell_list,
5320 icon_view->priv->pixbuf_cell);
5322 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5324 "pixbuf", icon_view->priv->pixbuf_column,
5327 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5328 g_object_set (info->cell,
5329 "follow-state", TRUE,
5334 g_object_set (info->cell,
5335 "follow-state", TRUE,
5343 * gtk_icon_view_set_text_column:
5344 * @icon_view: A #GtkIconView.
5345 * @column: A column in the currently used model, or -1 to display no text
5347 * Sets the column with text for @icon_view to be @column. The text
5348 * column must be of type #G_TYPE_STRING.
5353 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5356 if (column == icon_view->priv->text_column)
5360 icon_view->priv->text_column = -1;
5363 if (icon_view->priv->model != NULL)
5367 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5369 g_return_if_fail (column_type == G_TYPE_STRING);
5372 icon_view->priv->text_column = column;
5375 gtk_icon_view_stop_editing (icon_view, TRUE);
5377 update_text_cell (icon_view);
5379 gtk_icon_view_invalidate_sizes (icon_view);
5380 gtk_icon_view_queue_layout (icon_view);
5382 g_object_notify (G_OBJECT (icon_view), "text-column");
5386 * gtk_icon_view_get_text_column:
5387 * @icon_view: A #GtkIconView.
5389 * Returns the column with text for @icon_view.
5391 * Returns: the text column, or -1 if it's unset.
5396 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5398 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5400 return icon_view->priv->text_column;
5404 * gtk_icon_view_set_markup_column:
5405 * @icon_view: A #GtkIconView.
5406 * @column: A column in the currently used model, or -1 to display no text
5408 * Sets the column with markup information for @icon_view to be
5409 * @column. The markup column must be of type #G_TYPE_STRING.
5410 * If the markup column is set to something, it overrides
5411 * the text column set by gtk_icon_view_set_text_column().
5416 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5419 if (column == icon_view->priv->markup_column)
5423 icon_view->priv->markup_column = -1;
5426 if (icon_view->priv->model != NULL)
5430 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5432 g_return_if_fail (column_type == G_TYPE_STRING);
5435 icon_view->priv->markup_column = column;
5438 gtk_icon_view_stop_editing (icon_view, TRUE);
5440 update_text_cell (icon_view);
5442 gtk_icon_view_invalidate_sizes (icon_view);
5443 gtk_icon_view_queue_layout (icon_view);
5445 g_object_notify (G_OBJECT (icon_view), "markup-column");
5449 * gtk_icon_view_get_markup_column:
5450 * @icon_view: A #GtkIconView.
5452 * Returns the column with markup text for @icon_view.
5454 * Returns: the markup column, or -1 if it's unset.
5459 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5461 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5463 return icon_view->priv->markup_column;
5467 * gtk_icon_view_set_pixbuf_column:
5468 * @icon_view: A #GtkIconView.
5469 * @column: A column in the currently used model, or -1 to disable
5471 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5472 * column must be of type #GDK_TYPE_PIXBUF
5477 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5480 if (column == icon_view->priv->pixbuf_column)
5484 icon_view->priv->pixbuf_column = -1;
5487 if (icon_view->priv->model != NULL)
5491 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5493 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5496 icon_view->priv->pixbuf_column = column;
5499 gtk_icon_view_stop_editing (icon_view, TRUE);
5501 update_pixbuf_cell (icon_view);
5503 gtk_icon_view_invalidate_sizes (icon_view);
5504 gtk_icon_view_queue_layout (icon_view);
5506 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5511 * gtk_icon_view_get_pixbuf_column:
5512 * @icon_view: A #GtkIconView.
5514 * Returns the column with pixbufs for @icon_view.
5516 * Returns: the pixbuf column, or -1 if it's unset.
5521 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5523 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5525 return icon_view->priv->pixbuf_column;
5529 * gtk_icon_view_select_path:
5530 * @icon_view: A #GtkIconView.
5531 * @path: The #GtkTreePath to be selected.
5533 * Selects the row at @path.
5538 gtk_icon_view_select_path (GtkIconView *icon_view,
5541 GtkIconViewItem *item = NULL;
5543 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5544 g_return_if_fail (icon_view->priv->model != NULL);
5545 g_return_if_fail (path != NULL);
5547 if (gtk_tree_path_get_depth (path) > 0)
5548 item = g_list_nth_data (icon_view->priv->items,
5549 gtk_tree_path_get_indices(path)[0]);
5552 gtk_icon_view_select_item (icon_view, item);
5556 * gtk_icon_view_unselect_path:
5557 * @icon_view: A #GtkIconView.
5558 * @path: The #GtkTreePath to be unselected.
5560 * Unselects the row at @path.
5565 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5568 GtkIconViewItem *item;
5570 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5571 g_return_if_fail (icon_view->priv->model != NULL);
5572 g_return_if_fail (path != NULL);
5574 item = g_list_nth_data (icon_view->priv->items,
5575 gtk_tree_path_get_indices(path)[0]);
5580 gtk_icon_view_unselect_item (icon_view, item);
5584 * gtk_icon_view_get_selected_items:
5585 * @icon_view: A #GtkIconView.
5587 * Creates a list of paths of all selected items. Additionally, if you are
5588 * planning on modifying the model after calling this function, you may
5589 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5590 * To do this, you can use gtk_tree_row_reference_new().
5592 * To free the return value, use:
5594 * g_list_foreach (list, gtk_tree_path_free, NULL);
5595 * g_list_free (list);
5598 * Return value: A #GList containing a #GtkTreePath for each selected row.
5603 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5606 GList *selected = NULL;
5608 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5610 for (list = icon_view->priv->items; list != NULL; list = list->next)
5612 GtkIconViewItem *item = list->data;
5616 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5618 selected = g_list_prepend (selected, path);
5626 * gtk_icon_view_select_all:
5627 * @icon_view: A #GtkIconView.
5629 * Selects all the icons. @icon_view must has its selection mode set
5630 * to #GTK_SELECTION_MULTIPLE.
5635 gtk_icon_view_select_all (GtkIconView *icon_view)
5638 gboolean dirty = FALSE;
5640 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5642 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5645 for (items = icon_view->priv->items; items; items = items->next)
5647 GtkIconViewItem *item = items->data;
5649 if (!item->selected)
5652 item->selected = TRUE;
5653 gtk_icon_view_queue_draw_item (icon_view, item);
5658 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5662 * gtk_icon_view_unselect_all:
5663 * @icon_view: A #GtkIconView.
5665 * Unselects all the icons.
5670 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5672 gboolean dirty = FALSE;
5674 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5676 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5679 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5682 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5686 * gtk_icon_view_path_is_selected:
5687 * @icon_view: A #GtkIconView.
5688 * @path: A #GtkTreePath to check selection on.
5690 * Returns %TRUE if the icon pointed to by @path is currently
5691 * selected. If @path does not point to a valid location, %FALSE is returned.
5693 * Return value: %TRUE if @path is selected.
5698 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5701 GtkIconViewItem *item;
5703 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5704 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5705 g_return_val_if_fail (path != NULL, FALSE);
5707 item = g_list_nth_data (icon_view->priv->items,
5708 gtk_tree_path_get_indices(path)[0]);
5713 return item->selected;
5717 * gtk_icon_view_item_activated:
5718 * @icon_view: A #GtkIconView
5719 * @path: The #GtkTreePath to be activated
5721 * Activates the item determined by @path.
5726 gtk_icon_view_item_activated (GtkIconView *icon_view,
5729 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5730 g_return_if_fail (path != NULL);
5732 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5736 * gtk_icon_view_set_orientation:
5737 * @icon_view: a #GtkIconView
5738 * @orientation: the relative position of texts and icons
5740 * Sets the ::orientation property which determines whether the labels
5741 * are drawn beside the icons instead of below.
5746 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5747 GtkOrientation orientation)
5749 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5751 if (icon_view->priv->orientation != orientation)
5753 icon_view->priv->orientation = orientation;
5755 gtk_icon_view_stop_editing (icon_view, TRUE);
5756 gtk_icon_view_invalidate_sizes (icon_view);
5757 gtk_icon_view_queue_layout (icon_view);
5759 update_text_cell (icon_view);
5760 update_pixbuf_cell (icon_view);
5762 g_object_notify (G_OBJECT (icon_view), "orientation");
5767 * gtk_icon_view_get_orientation:
5768 * @icon_view: a #GtkIconView
5770 * Returns the value of the ::orientation property which determines
5771 * whether the labels are drawn beside the icons instead of below.
5773 * Return value: the relative position of texts and icons
5778 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5780 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5781 GTK_ORIENTATION_VERTICAL);
5783 return icon_view->priv->orientation;
5787 * gtk_icon_view_set_columns:
5788 * @icon_view: a #GtkIconView
5789 * @columns: the number of columns
5791 * Sets the ::columns property which determines in how
5792 * many columns the icons are arranged. If @columns is
5793 * -1, the number of columns will be chosen automatically
5794 * to fill the available area.
5799 gtk_icon_view_set_columns (GtkIconView *icon_view,
5802 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5804 if (icon_view->priv->columns != columns)
5806 icon_view->priv->columns = columns;
5808 gtk_icon_view_stop_editing (icon_view, TRUE);
5809 gtk_icon_view_queue_layout (icon_view);
5811 g_object_notify (G_OBJECT (icon_view), "columns");
5816 * gtk_icon_view_get_columns:
5817 * @icon_view: a #GtkIconView
5819 * Returns the value of the ::columns property.
5821 * Return value: the number of columns, or -1
5826 gtk_icon_view_get_columns (GtkIconView *icon_view)
5828 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5830 return icon_view->priv->columns;
5834 * gtk_icon_view_set_item_width:
5835 * @icon_view: a #GtkIconView
5836 * @item_width: the width for each item
5838 * Sets the ::item-width property which specifies the width
5839 * to use for each item. If it is set to -1, the icon view will
5840 * automatically determine a suitable item size.
5845 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5848 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5850 if (icon_view->priv->item_width != item_width)
5852 icon_view->priv->item_width = item_width;
5854 gtk_icon_view_stop_editing (icon_view, TRUE);
5855 gtk_icon_view_invalidate_sizes (icon_view);
5856 gtk_icon_view_queue_layout (icon_view);
5858 update_text_cell (icon_view);
5860 g_object_notify (G_OBJECT (icon_view), "item-width");
5865 * gtk_icon_view_get_item_width:
5866 * @icon_view: a #GtkIconView
5868 * Returns the value of the ::item-width property.
5870 * Return value: the width of a single item, or -1
5875 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5877 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5879 return icon_view->priv->item_width;
5884 * gtk_icon_view_set_spacing:
5885 * @icon_view: a #GtkIconView
5886 * @spacing: the spacing
5888 * Sets the ::spacing property which specifies the space
5889 * which is inserted between the cells (i.e. the icon and
5890 * the text) of an item.
5895 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5898 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5900 if (icon_view->priv->spacing != spacing)
5902 icon_view->priv->spacing = spacing;
5904 gtk_icon_view_stop_editing (icon_view, TRUE);
5905 gtk_icon_view_invalidate_sizes (icon_view);
5906 gtk_icon_view_queue_layout (icon_view);
5908 g_object_notify (G_OBJECT (icon_view), "spacing");
5913 * gtk_icon_view_get_spacing:
5914 * @icon_view: a #GtkIconView
5916 * Returns the value of the ::spacing property.
5918 * Return value: the space between cells
5923 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5925 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5927 return icon_view->priv->spacing;
5931 * gtk_icon_view_set_row_spacing:
5932 * @icon_view: a #GtkIconView
5933 * @row_spacing: the row spacing
5935 * Sets the ::row-spacing property which specifies the space
5936 * which is inserted between the rows of the icon view.
5941 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5944 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5946 if (icon_view->priv->row_spacing != row_spacing)
5948 icon_view->priv->row_spacing = row_spacing;
5950 gtk_icon_view_stop_editing (icon_view, TRUE);
5951 gtk_icon_view_invalidate_sizes (icon_view);
5952 gtk_icon_view_queue_layout (icon_view);
5954 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5959 * gtk_icon_view_get_row_spacing:
5960 * @icon_view: a #GtkIconView
5962 * Returns the value of the ::row-spacing property.
5964 * Return value: the space between rows
5969 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5971 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5973 return icon_view->priv->row_spacing;
5977 * gtk_icon_view_set_column_spacing:
5978 * @icon_view: a #GtkIconView
5979 * @column_spacing: the column spacing
5981 * Sets the ::column-spacing property which specifies the space
5982 * which is inserted between the columns of the icon view.
5987 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5988 gint column_spacing)
5990 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5992 if (icon_view->priv->column_spacing != column_spacing)
5994 icon_view->priv->column_spacing = column_spacing;
5996 gtk_icon_view_stop_editing (icon_view, TRUE);
5997 gtk_icon_view_invalidate_sizes (icon_view);
5998 gtk_icon_view_queue_layout (icon_view);
6000 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6005 * gtk_icon_view_get_column_spacing:
6006 * @icon_view: a #GtkIconView
6008 * Returns the value of the ::column-spacing property.
6010 * Return value: the space between columns
6015 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6017 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6019 return icon_view->priv->column_spacing;
6023 * gtk_icon_view_set_margin:
6024 * @icon_view: a #GtkIconView
6025 * @margin: the margin
6027 * Sets the ::margin property which specifies the space
6028 * which is inserted at the top, bottom, left and right
6034 gtk_icon_view_set_margin (GtkIconView *icon_view,
6037 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6039 if (icon_view->priv->margin != margin)
6041 icon_view->priv->margin = margin;
6043 gtk_icon_view_stop_editing (icon_view, TRUE);
6044 gtk_icon_view_invalidate_sizes (icon_view);
6045 gtk_icon_view_queue_layout (icon_view);
6047 g_object_notify (G_OBJECT (icon_view), "margin");
6052 * gtk_icon_view_get_margin:
6053 * @icon_view: a #GtkIconView
6055 * Returns the value of the ::margin property.
6057 * Return value: the space at the borders
6062 gtk_icon_view_get_margin (GtkIconView *icon_view)
6064 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6066 return icon_view->priv->margin;
6070 /* Get/set whether drag_motion requested the drag data and
6071 * drag_data_received should thus not actually insert the data,
6072 * since the data doesn't result from a drop.
6075 set_status_pending (GdkDragContext *context,
6076 GdkDragAction suggested_action)
6078 g_object_set_data (G_OBJECT (context),
6079 I_("gtk-icon-view-status-pending"),
6080 GINT_TO_POINTER (suggested_action));
6083 static GdkDragAction
6084 get_status_pending (GdkDragContext *context)
6086 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6087 "gtk-icon-view-status-pending"));
6091 unset_reorderable (GtkIconView *icon_view)
6093 if (icon_view->priv->reorderable)
6095 icon_view->priv->reorderable = FALSE;
6096 g_object_notify (G_OBJECT (icon_view), "reorderable");
6101 clear_source_info (GtkIconView *icon_view)
6103 if (icon_view->priv->source_targets)
6104 gtk_target_list_unref (icon_view->priv->source_targets);
6105 icon_view->priv->source_targets = NULL;
6107 icon_view->priv->source_set = FALSE;
6111 clear_dest_info (GtkIconView *icon_view)
6113 if (icon_view->priv->dest_targets)
6114 gtk_target_list_unref (icon_view->priv->dest_targets);
6115 icon_view->priv->dest_targets = NULL;
6117 icon_view->priv->dest_set = FALSE;
6121 set_source_row (GdkDragContext *context,
6122 GtkTreeModel *model,
6123 GtkTreePath *source_row)
6126 g_object_set_data_full (G_OBJECT (context),
6127 I_("gtk-icon-view-source-row"),
6128 gtk_tree_row_reference_new (model, source_row),
6129 (GDestroyNotify) gtk_tree_row_reference_free);
6131 g_object_set_data_full (G_OBJECT (context),
6132 I_("gtk-icon-view-source-row"),
6137 get_source_row (GdkDragContext *context)
6139 GtkTreeRowReference *ref;
6141 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6144 return gtk_tree_row_reference_get_path (ref);
6151 GtkTreeRowReference *dest_row;
6152 gboolean empty_view_drop;
6153 gboolean drop_append_mode;
6157 dest_row_free (gpointer data)
6159 DestRow *dr = (DestRow *)data;
6161 gtk_tree_row_reference_free (dr->dest_row);
6166 set_dest_row (GdkDragContext *context,
6167 GtkTreeModel *model,
6168 GtkTreePath *dest_row,
6169 gboolean empty_view_drop,
6170 gboolean drop_append_mode)
6176 g_object_set_data_full (G_OBJECT (context),
6177 I_("gtk-icon-view-dest-row"),
6182 dr = g_new0 (DestRow, 1);
6184 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6185 dr->empty_view_drop = empty_view_drop;
6186 dr->drop_append_mode = drop_append_mode;
6187 g_object_set_data_full (G_OBJECT (context),
6188 I_("gtk-icon-view-dest-row"),
6189 dr, (GDestroyNotify) dest_row_free);
6193 get_dest_row (GdkDragContext *context)
6197 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6201 GtkTreePath *path = NULL;
6204 path = gtk_tree_row_reference_get_path (dr->dest_row);
6205 else if (dr->empty_view_drop)
6206 path = gtk_tree_path_new_from_indices (0, -1);
6210 if (path && dr->drop_append_mode)
6211 gtk_tree_path_next (path);
6220 check_model_dnd (GtkTreeModel *model,
6221 GType required_iface,
6222 const gchar *signal)
6224 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6226 g_warning ("You must override the default '%s' handler "
6227 "on GtkIconView when using models that don't support "
6228 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6229 "is to connect to '%s' and call "
6230 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6231 "the default handler from running. Look at the source code "
6232 "for the default handler in gtkiconview.c to get an idea what "
6233 "your handler should do. (gtkiconview.c is in the GTK+ source "
6234 "code.) If you're using GTK+ from a language other than C, "
6235 "there may be a more natural way to override default handlers, e.g. via derivation.",
6236 signal, g_type_name (required_iface), signal);
6244 remove_scroll_timeout (GtkIconView *icon_view)
6246 if (icon_view->priv->scroll_timeout_id != 0)
6248 g_source_remove (icon_view->priv->scroll_timeout_id);
6250 icon_view->priv->scroll_timeout_id = 0;
6255 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6257 gint px, py, x, y, width, height;
6258 gint hoffset, voffset;
6261 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6262 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6264 /* see if we are near the edge. */
6265 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6267 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6269 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6271 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6275 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6276 icon_view->priv->vadjustment->lower,
6277 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6278 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6282 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6283 icon_view->priv->hadjustment->lower,
6284 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6285 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6291 drag_scroll_timeout (gpointer data)
6293 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6295 gtk_icon_view_autoscroll (icon_view);
6302 set_destination (GtkIconView *icon_view,
6303 GdkDragContext *context,
6306 GdkDragAction *suggested_action,
6310 GtkTreePath *path = NULL;
6311 GtkIconViewDropPosition pos;
6312 GtkIconViewDropPosition old_pos;
6313 GtkTreePath *old_dest_path = NULL;
6314 gboolean can_drop = FALSE;
6316 widget = GTK_WIDGET (icon_view);
6318 *suggested_action = 0;
6321 if (!icon_view->priv->dest_set)
6323 /* someone unset us as a drag dest, note that if
6324 * we return FALSE drag_leave isn't called
6327 gtk_icon_view_set_drag_dest_item (icon_view,
6329 GTK_ICON_VIEW_DROP_LEFT);
6331 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6333 return FALSE; /* no longer a drop site */
6336 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6337 if (*target == GDK_NONE)
6340 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6343 GtkTreeModel *model;
6345 /* the row got dropped on empty space, let's setup a special case
6349 gtk_tree_path_free (path);
6351 model = gtk_icon_view_get_model (icon_view);
6353 n_children = gtk_tree_model_iter_n_children (model, NULL);
6356 pos = GTK_ICON_VIEW_DROP_BELOW;
6357 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6361 pos = GTK_ICON_VIEW_DROP_ABOVE;
6362 path = gtk_tree_path_new_from_indices (0, -1);
6372 gtk_icon_view_get_drag_dest_item (icon_view,
6377 gtk_tree_path_free (old_dest_path);
6379 if (TRUE /* FIXME if the location droppable predicate */)
6387 GtkWidget *source_widget;
6389 *suggested_action = context->suggested_action;
6390 source_widget = gtk_drag_get_source_widget (context);
6392 if (source_widget == widget)
6394 /* Default to MOVE, unless the user has
6395 * pressed ctrl or shift to affect available actions
6397 if ((context->actions & GDK_ACTION_MOVE) != 0)
6398 *suggested_action = GDK_ACTION_MOVE;
6401 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6406 /* can't drop here */
6407 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6409 GTK_ICON_VIEW_DROP_LEFT);
6413 gtk_tree_path_free (path);
6419 get_logical_destination (GtkIconView *icon_view,
6420 gboolean *drop_append_mode)
6422 /* adjust path to point to the row the drop goes in front of */
6423 GtkTreePath *path = NULL;
6424 GtkIconViewDropPosition pos;
6426 *drop_append_mode = FALSE;
6428 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6433 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6434 pos == GTK_ICON_VIEW_DROP_BELOW)
6437 GtkTreeModel *model = icon_view->priv->model;
6439 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6440 !gtk_tree_model_iter_next (model, &iter))
6441 *drop_append_mode = TRUE;
6444 *drop_append_mode = FALSE;
6445 gtk_tree_path_next (path);
6453 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6454 GdkEventMotion *event)
6456 GdkDragContext *context;
6457 GtkTreePath *path = NULL;
6459 GtkTreeModel *model;
6460 gboolean retval = FALSE;
6462 if (!icon_view->priv->source_set)
6465 if (icon_view->priv->pressed_button < 0)
6468 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6469 icon_view->priv->press_start_x,
6470 icon_view->priv->press_start_y,
6471 event->x, event->y))
6474 model = gtk_icon_view_get_model (icon_view);
6479 button = icon_view->priv->pressed_button;
6480 icon_view->priv->pressed_button = -1;
6482 path = gtk_icon_view_get_path_at_pos (icon_view,
6483 icon_view->priv->press_start_x,
6484 icon_view->priv->press_start_y);
6489 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6490 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6494 /* FIXME Check whether we're a start button, if not return FALSE and
6498 /* Now we can begin the drag */
6502 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6503 icon_view->priv->source_targets,
6504 icon_view->priv->source_actions,
6508 set_source_row (context, model, path);
6512 gtk_tree_path_free (path);
6517 /* Source side drag signals */
6519 gtk_icon_view_drag_begin (GtkWidget *widget,
6520 GdkDragContext *context)
6522 GtkIconView *icon_view;
6523 GtkIconViewItem *item;
6528 icon_view = GTK_ICON_VIEW (widget);
6530 /* if the user uses a custom DnD impl, we don't set the icon here */
6531 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6534 item = gtk_icon_view_get_item_at_coords (icon_view,
6535 icon_view->priv->press_start_x,
6536 icon_view->priv->press_start_y,
6540 g_return_if_fail (item != NULL);
6542 x = icon_view->priv->press_start_x - item->x + 1;
6543 y = icon_view->priv->press_start_y - item->y + 1;
6545 path = gtk_tree_path_new_from_indices (item->index, -1);
6546 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6547 gtk_tree_path_free (path);
6549 gtk_drag_set_icon_pixmap (context,
6550 gdk_drawable_get_colormap (icon),
6555 g_object_unref (icon);
6559 gtk_icon_view_drag_end (GtkWidget *widget,
6560 GdkDragContext *context)
6566 gtk_icon_view_drag_data_get (GtkWidget *widget,
6567 GdkDragContext *context,
6568 GtkSelectionData *selection_data,
6572 GtkIconView *icon_view;
6573 GtkTreeModel *model;
6574 GtkTreePath *source_row;
6576 icon_view = GTK_ICON_VIEW (widget);
6577 model = gtk_icon_view_get_model (icon_view);
6582 if (!icon_view->priv->dest_set)
6585 source_row = get_source_row (context);
6587 if (source_row == NULL)
6590 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6591 * any model; for DragSource models there are some other targets
6595 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6596 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6601 /* If drag_data_get does nothing, try providing row data. */
6602 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6603 gtk_tree_set_row_drag_data (selection_data,
6608 gtk_tree_path_free (source_row);
6612 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6613 GdkDragContext *context)
6615 GtkTreeModel *model;
6616 GtkIconView *icon_view;
6617 GtkTreePath *source_row;
6619 icon_view = GTK_ICON_VIEW (widget);
6620 model = gtk_icon_view_get_model (icon_view);
6622 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6625 if (!icon_view->priv->dest_set)
6628 source_row = get_source_row (context);
6630 if (source_row == NULL)
6633 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6636 gtk_tree_path_free (source_row);
6638 set_source_row (context, NULL, NULL);
6641 /* Target side drag signals */
6643 gtk_icon_view_drag_leave (GtkWidget *widget,
6644 GdkDragContext *context,
6647 GtkIconView *icon_view;
6649 icon_view = GTK_ICON_VIEW (widget);
6651 /* unset any highlight row */
6652 gtk_icon_view_set_drag_dest_item (icon_view,
6654 GTK_ICON_VIEW_DROP_LEFT);
6656 remove_scroll_timeout (icon_view);
6660 gtk_icon_view_drag_motion (GtkWidget *widget,
6661 GdkDragContext *context,
6666 GtkTreePath *path = NULL;
6667 GtkIconViewDropPosition pos;
6668 GtkIconView *icon_view;
6669 GdkDragAction suggested_action = 0;
6673 icon_view = GTK_ICON_VIEW (widget);
6675 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6678 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6680 /* we only know this *after* set_desination_row */
6681 empty = icon_view->priv->empty_view_drop;
6683 if (path == NULL && !empty)
6685 /* Can't drop here. */
6686 gdk_drag_status (context, 0, time);
6690 if (icon_view->priv->scroll_timeout_id == 0)
6692 icon_view->priv->scroll_timeout_id =
6693 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6696 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6698 /* Request data so we can use the source row when
6699 * determining whether to accept the drop
6701 set_status_pending (context, suggested_action);
6702 gtk_drag_get_data (widget, context, target, time);
6706 set_status_pending (context, 0);
6707 gdk_drag_status (context, suggested_action, time);
6712 gtk_tree_path_free (path);
6718 gtk_icon_view_drag_drop (GtkWidget *widget,
6719 GdkDragContext *context,
6724 GtkIconView *icon_view;
6726 GdkDragAction suggested_action = 0;
6727 GdkAtom target = GDK_NONE;
6728 GtkTreeModel *model;
6729 gboolean drop_append_mode;
6731 icon_view = GTK_ICON_VIEW (widget);
6732 model = gtk_icon_view_get_model (icon_view);
6734 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6736 if (!icon_view->priv->dest_set)
6739 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6742 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6745 path = get_logical_destination (icon_view, &drop_append_mode);
6747 if (target != GDK_NONE && path != NULL)
6749 /* in case a motion had requested drag data, change things so we
6750 * treat drag data receives as a drop.
6752 set_status_pending (context, 0);
6753 set_dest_row (context, model, path,
6754 icon_view->priv->empty_view_drop, drop_append_mode);
6758 gtk_tree_path_free (path);
6760 /* Unset this thing */
6761 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6763 if (target != GDK_NONE)
6765 gtk_drag_get_data (widget, context, target, time);
6773 gtk_icon_view_drag_data_received (GtkWidget *widget,
6774 GdkDragContext *context,
6777 GtkSelectionData *selection_data,
6782 gboolean accepted = FALSE;
6783 GtkTreeModel *model;
6784 GtkIconView *icon_view;
6785 GtkTreePath *dest_row;
6786 GdkDragAction suggested_action;
6787 gboolean drop_append_mode;
6789 icon_view = GTK_ICON_VIEW (widget);
6790 model = gtk_icon_view_get_model (icon_view);
6792 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6795 if (!icon_view->priv->dest_set)
6798 suggested_action = get_status_pending (context);
6800 if (suggested_action)
6802 /* We are getting this data due to a request in drag_motion,
6803 * rather than due to a request in drag_drop, so we are just
6804 * supposed to call drag_status, not actually paste in the
6807 path = get_logical_destination (icon_view, &drop_append_mode);
6810 suggested_action = 0;
6812 if (suggested_action)
6814 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6817 suggested_action = 0;
6820 gdk_drag_status (context, suggested_action, time);
6823 gtk_tree_path_free (path);
6825 /* If you can't drop, remove user drop indicator until the next motion */
6826 if (suggested_action == 0)
6827 gtk_icon_view_set_drag_dest_item (icon_view,
6829 GTK_ICON_VIEW_DROP_LEFT);
6834 dest_row = get_dest_row (context);
6836 if (dest_row == NULL)
6839 if (selection_data->length >= 0)
6841 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6847 gtk_drag_finish (context,
6849 (context->action == GDK_ACTION_MOVE),
6852 gtk_tree_path_free (dest_row);
6855 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6858 /* Drag-and-Drop support */
6860 * gtk_icon_view_enable_model_drag_source:
6861 * @icon_view: a #GtkIconTreeView
6862 * @start_button_mask: Mask of allowed buttons to start drag
6863 * @targets: the table of targets that the drag will support
6864 * @n_targets: the number of items in @targets
6865 * @actions: the bitmask of possible actions for a drag from this
6868 * Turns @icon_view into a drag source for automatic DND.
6873 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6874 GdkModifierType start_button_mask,
6875 const GtkTargetEntry *targets,
6877 GdkDragAction actions)
6879 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6881 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6883 clear_source_info (icon_view);
6884 icon_view->priv->start_button_mask = start_button_mask;
6885 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6886 icon_view->priv->source_actions = actions;
6888 icon_view->priv->source_set = TRUE;
6890 unset_reorderable (icon_view);
6894 * gtk_icon_view_enable_model_drag_dest:
6895 * @icon_view: a #GtkIconView
6896 * @targets: the table of targets that the drag will support
6897 * @n_targets: the number of items in @targets
6898 * @actions: the bitmask of possible actions for a drag to this
6901 * Turns @icon_view into a drop destination for automatic DND.
6906 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6907 const GtkTargetEntry *targets,
6909 GdkDragAction actions)
6911 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6913 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6915 clear_dest_info (icon_view);
6917 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6918 icon_view->priv->dest_actions = actions;
6920 icon_view->priv->dest_set = TRUE;
6922 unset_reorderable (icon_view);
6926 * gtk_icon_view_unset_model_drag_source:
6927 * @icon_view: a #GtkIconView
6929 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6934 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6936 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6938 if (icon_view->priv->source_set)
6940 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6941 clear_source_info (icon_view);
6944 unset_reorderable (icon_view);
6948 * gtk_icon_view_unset_model_drag_dest:
6949 * @icon_view: a #GtkIconView
6951 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6956 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6958 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6960 if (icon_view->priv->dest_set)
6962 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6963 clear_dest_info (icon_view);
6966 unset_reorderable (icon_view);
6969 /* These are useful to implement your own custom stuff. */
6971 * gtk_icon_view_set_drag_dest_item:
6972 * @icon_view: a #GtkIconView
6973 * @path: The path of the item to highlight, or %NULL.
6974 * @pos: Specifies where to drop, relative to the item
6976 * Sets the item that is highlighted for feedback.
6981 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6983 GtkIconViewDropPosition pos)
6985 /* Note; this function is exported to allow a custom DND
6986 * implementation, so it can't touch TreeViewDragInfo
6989 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6991 if (icon_view->priv->dest_item)
6993 GtkTreePath *current_path;
6994 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6995 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6996 icon_view->priv->dest_item = NULL;
6998 gtk_icon_view_queue_draw_path (icon_view, current_path);
6999 gtk_tree_path_free (current_path);
7002 /* special case a drop on an empty model */
7003 icon_view->priv->empty_view_drop = FALSE;
7004 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7005 && gtk_tree_path_get_depth (path) == 1
7006 && gtk_tree_path_get_indices (path)[0] == 0)
7010 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7013 if (n_children == 0)
7014 icon_view->priv->empty_view_drop = TRUE;
7017 icon_view->priv->dest_pos = pos;
7021 icon_view->priv->dest_item =
7022 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7023 icon_view->priv->model, path);
7025 gtk_icon_view_queue_draw_path (icon_view, path);
7030 * gtk_icon_view_get_drag_dest_item:
7031 * @icon_view: a #GtkIconView
7032 * @path: Return location for the path of the highlighted item, or %NULL.
7033 * @pos: Return location for the drop position, or %NULL
7035 * Gets information about the item that is highlighted for feedback.
7040 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7042 GtkIconViewDropPosition *pos)
7044 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7048 if (icon_view->priv->dest_item)
7049 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7055 *pos = icon_view->priv->dest_pos;
7059 * gtk_icon_view_get_dest_item_at_pos:
7060 * @icon_view: a #GtkIconView
7061 * @drag_x: the position to determine the destination item for
7062 * @drag_y: the position to determine the destination item for
7063 * @path: Return location for the path of the item, or %NULL.
7064 * @pos: Return location for the drop position, or %NULL
7066 * Determines the destination item for a given position.
7068 * Return value: whether there is an item at the given position.
7073 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7077 GtkIconViewDropPosition *pos)
7079 GtkIconViewItem *item;
7081 /* Note; this function is exported to allow a custom DND
7082 * implementation, so it can't touch TreeViewDragInfo
7085 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7086 g_return_val_if_fail (drag_x >= 0, FALSE);
7087 g_return_val_if_fail (drag_y >= 0, FALSE);
7088 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7094 item = gtk_icon_view_get_item_at_coords (icon_view,
7095 drag_x + icon_view->priv->hadjustment->value,
7096 drag_y + icon_view->priv->vadjustment->value,
7103 *path = gtk_tree_path_new_from_indices (item->index, -1);
7107 if (drag_x < item->x + item->width / 4)
7108 *pos = GTK_ICON_VIEW_DROP_LEFT;
7109 else if (drag_x > item->x + item->width * 3 / 4)
7110 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7111 else if (drag_y < item->y + item->height / 4)
7112 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7113 else if (drag_y > item->y + item->height * 3 / 4)
7114 *pos = GTK_ICON_VIEW_DROP_BELOW;
7116 *pos = GTK_ICON_VIEW_DROP_INTO;
7123 * gtk_icon_view_create_drag_icon:
7124 * @icon_view: a #GtkIconView
7125 * @path: a #GtkTreePath in @icon_view
7127 * Creates a #GdkPixmap representation of the item at @path.
7128 * This image is used for a drag icon.
7130 * Return value: a newly-allocated pixmap of the drag icon.
7135 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7140 GdkPixmap *drawable;
7145 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7146 g_return_val_if_fail (path != NULL, NULL);
7148 widget = GTK_WIDGET (icon_view);
7150 if (!GTK_WIDGET_REALIZED (widget))
7153 index = gtk_tree_path_get_indices (path)[0];
7155 for (l = icon_view->priv->items; l; l = l->next)
7157 GtkIconViewItem *item = l->data;
7159 if (index == item->index)
7161 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7166 cr = gdk_cairo_create (drawable);
7167 cairo_set_line_width (cr, 1.);
7169 gdk_cairo_set_source_color
7170 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7171 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7176 area.width = item->width;
7177 area.height = item->height;
7179 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7180 drawable, 1, 1, FALSE);
7182 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7183 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7196 * gtk_icon_view_get_reorderable:
7197 * @icon_view: a #GtkIconView
7199 * Retrieves whether the user can reorder the list via drag-and-drop.
7200 * See gtk_icon_view_set_reorderable().
7202 * Return value: %TRUE if the list can be reordered.
7207 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7209 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7211 return icon_view->priv->reorderable;
7214 static const GtkTargetEntry item_targets[] = {
7215 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7220 * gtk_icon_view_set_reorderable:
7221 * @icon_view: A #GtkIconView.
7222 * @reorderable: %TRUE, if the list of items can be reordered.
7224 * This function is a convenience function to allow you to reorder models that
7225 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7226 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7227 * the user can reorder the model by dragging and dropping rows. The
7228 * developer can listen to these changes by connecting to the model's
7229 * row_inserted and row_deleted signals.
7231 * This function does not give you any degree of control over the order -- any
7232 * reordering is allowed. If more control is needed, you should probably
7233 * handle drag and drop manually.
7238 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7239 gboolean reorderable)
7241 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7243 reorderable = reorderable != FALSE;
7245 if (icon_view->priv->reorderable == reorderable)
7250 gtk_icon_view_enable_model_drag_source (icon_view,
7253 G_N_ELEMENTS (item_targets),
7255 gtk_icon_view_enable_model_drag_dest (icon_view,
7257 G_N_ELEMENTS (item_targets),
7262 gtk_icon_view_unset_model_drag_source (icon_view);
7263 gtk_icon_view_unset_model_drag_dest (icon_view);
7266 icon_view->priv->reorderable = reorderable;
7268 g_object_notify (G_OBJECT (icon_view), "reorderable");
7272 /* Accessibility Support */
7274 static gpointer accessible_parent_class;
7275 static gpointer accessible_item_parent_class;
7276 static GQuark accessible_private_data_quark = 0;
7278 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7279 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7280 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7282 static GType gtk_icon_view_item_accessible_get_type (void);
7293 GtkIconViewItem *item;
7297 AtkStateSet *state_set;
7301 GtkTextBuffer *text_buffer;
7303 gchar *action_descriptions[LAST_ACTION];
7304 gchar *image_description;
7305 guint action_idle_handler;
7306 } GtkIconViewItemAccessible;
7308 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7314 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7319 typedef struct _GtkIconViewItemAccessibleClass
7321 AtkObjectClass parent_class;
7323 } GtkIconViewItemAccessibleClass;
7325 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7328 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7330 GtkIconViewItemAccessible *item;
7331 GtkIconView *icon_view;
7334 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7335 item->action_idle_handler = 0;
7337 if (item->widget != NULL)
7339 icon_view = GTK_ICON_VIEW (item->widget);
7340 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7341 gtk_icon_view_item_activated (icon_view, path);
7342 gtk_tree_path_free (path);
7349 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7352 GtkIconViewItemAccessible *item;
7354 if (i < 0 || i >= LAST_ACTION)
7357 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7359 if (!GTK_IS_ICON_VIEW (item->widget))
7362 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7367 case ACTION_ACTIVATE:
7368 if (!item->action_idle_handler)
7369 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7372 g_assert_not_reached ();
7380 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7385 static const gchar *
7386 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7389 GtkIconViewItemAccessible *item;
7391 if (i < 0 || i >= LAST_ACTION)
7394 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7396 if (item->action_descriptions[i])
7397 return item->action_descriptions[i];
7399 return gtk_icon_view_item_accessible_action_descriptions[i];
7402 static const gchar *
7403 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7406 if (i < 0 || i >= LAST_ACTION)
7409 return gtk_icon_view_item_accessible_action_names[i];
7413 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7415 const gchar *description)
7417 GtkIconViewItemAccessible *item;
7419 if (i < 0 || i >= LAST_ACTION)
7422 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7424 g_free (item->action_descriptions[i]);
7426 item->action_descriptions[i] = g_strdup (description);
7432 atk_action_item_interface_init (AtkActionIface *iface)
7434 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7435 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7436 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7437 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7438 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7441 static const gchar *
7442 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7444 GtkIconViewItemAccessible *item;
7446 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7448 return item->image_description;
7452 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7453 const gchar *description)
7455 GtkIconViewItemAccessible *item;
7457 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7459 g_free (item->image_description);
7460 item->image_description = g_strdup (item->image_description);
7466 get_pixbuf_box (GtkIconView *icon_view,
7467 GtkIconViewItem *item,
7472 for (l = icon_view->priv->cell_list; l; l = l->next)
7474 GtkIconViewCellInfo *info = l->data;
7476 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7478 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7488 get_text (GtkIconView *icon_view,
7489 GtkIconViewItem *item)
7494 for (l = icon_view->priv->cell_list; l; l = l->next)
7496 GtkIconViewCellInfo *info = l->data;
7498 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7500 g_object_get (info->cell, "text", &text, NULL);
7510 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7514 GtkIconViewItemAccessible *item;
7517 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7519 if (!GTK_IS_ICON_VIEW (item->widget))
7522 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7525 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7528 *height = box.height;
7533 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7536 AtkCoordType coord_type)
7538 GtkIconViewItemAccessible *item;
7541 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7543 if (!GTK_IS_ICON_VIEW (item->widget))
7546 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7549 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7551 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7553 *x+= box.x - item->item->x;
7554 *y+= box.y - item->item->y;
7560 atk_image_item_interface_init (AtkImageIface *iface)
7562 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7563 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7564 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7565 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7569 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7573 GtkIconViewItemAccessible *item;
7574 GtkTextIter start, end;
7575 GtkTextBuffer *buffer;
7577 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7579 if (!GTK_IS_ICON_VIEW (item->widget))
7582 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7585 buffer = item->text_buffer;
7586 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7588 gtk_text_buffer_get_end_iter (buffer, &end);
7590 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7592 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7596 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7599 GtkIconViewItemAccessible *item;
7600 GtkTextIter start, end;
7601 GtkTextBuffer *buffer;
7605 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7607 if (!GTK_IS_ICON_VIEW (item->widget))
7610 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7613 buffer = item->text_buffer;
7614 if (offset >= gtk_text_buffer_get_char_count (buffer))
7617 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7619 gtk_text_iter_forward_char (&end);
7620 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7621 unichar = g_utf8_get_char (string);
7629 get_pango_text_offsets (PangoLayout *layout,
7630 GtkTextBuffer *buffer,
7632 AtkTextBoundary boundary_type,
7636 GtkTextIter *start_iter,
7637 GtkTextIter *end_iter)
7639 PangoLayoutIter *iter;
7640 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7641 gint index, start_index, end_index;
7643 gboolean found = FALSE;
7645 text = pango_layout_get_text (layout);
7646 index = g_utf8_offset_to_pointer (text, offset) - text;
7647 iter = pango_layout_get_iter (layout);
7650 line = pango_layout_iter_get_line_readonly (iter);
7651 start_index = line->start_index;
7652 end_index = start_index + line->length;
7654 if (index >= start_index && index <= end_index)
7657 * Found line for offset
7663 * We want the previous line
7667 switch (boundary_type)
7669 case ATK_TEXT_BOUNDARY_LINE_START:
7670 end_index = start_index;
7671 start_index = prev_line->start_index;
7673 case ATK_TEXT_BOUNDARY_LINE_END:
7675 start_index = prev_prev_line->start_index +
7676 prev_prev_line->length;
7677 end_index = prev_line->start_index + prev_line->length;
7680 g_assert_not_reached();
7684 start_index = end_index = 0;
7687 switch (boundary_type)
7689 case ATK_TEXT_BOUNDARY_LINE_START:
7690 if (pango_layout_iter_next_line (iter))
7691 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7693 case ATK_TEXT_BOUNDARY_LINE_END:
7695 start_index = prev_line->start_index +
7699 g_assert_not_reached();
7704 * We want the next line
7706 if (pango_layout_iter_next_line (iter))
7708 line = pango_layout_iter_get_line_readonly (iter);
7709 switch (boundary_type)
7711 case ATK_TEXT_BOUNDARY_LINE_START:
7712 start_index = line->start_index;
7713 if (pango_layout_iter_next_line (iter))
7714 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7716 end_index = start_index + line->length;
7718 case ATK_TEXT_BOUNDARY_LINE_END:
7719 start_index = end_index;
7720 end_index = line->start_index + line->length;
7723 g_assert_not_reached();
7727 start_index = end_index;
7733 prev_prev_line = prev_line;
7736 while (pango_layout_iter_next_line (iter));
7740 start_index = prev_line->start_index + prev_line->length;
7741 end_index = start_index;
7743 pango_layout_iter_free (iter);
7744 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7745 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7747 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7748 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7753 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7755 AtkTextBoundary boundary_type,
7759 GtkIconViewItemAccessible *item;
7760 GtkTextIter start, end;
7761 GtkTextBuffer *buffer;
7763 GtkIconView *icon_view;
7766 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7768 if (!GTK_IS_ICON_VIEW (item->widget))
7771 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7774 buffer = item->text_buffer;
7776 if (!gtk_text_buffer_get_char_count (buffer))
7780 return g_strdup ("");
7782 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7786 switch (boundary_type)
7788 case ATK_TEXT_BOUNDARY_CHAR:
7789 gtk_text_iter_backward_char(&start);
7791 case ATK_TEXT_BOUNDARY_WORD_START:
7792 if (!gtk_text_iter_starts_word (&start))
7793 gtk_text_iter_backward_word_start (&start);
7795 gtk_text_iter_backward_word_start(&start);
7797 case ATK_TEXT_BOUNDARY_WORD_END:
7798 if (gtk_text_iter_inside_word (&start) &&
7799 !gtk_text_iter_starts_word (&start))
7800 gtk_text_iter_backward_word_start (&start);
7801 while (!gtk_text_iter_ends_word (&start))
7803 if (!gtk_text_iter_backward_char (&start))
7807 gtk_text_iter_backward_word_start(&start);
7808 while (!gtk_text_iter_ends_word (&start))
7810 if (!gtk_text_iter_backward_char (&start))
7814 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7815 if (!gtk_text_iter_starts_sentence (&start))
7816 gtk_text_iter_backward_sentence_start (&start);
7818 gtk_text_iter_backward_sentence_start (&start);
7820 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7821 if (gtk_text_iter_inside_sentence (&start) &&
7822 !gtk_text_iter_starts_sentence (&start))
7823 gtk_text_iter_backward_sentence_start (&start);
7824 while (!gtk_text_iter_ends_sentence (&start))
7826 if (!gtk_text_iter_backward_char (&start))
7830 gtk_text_iter_backward_sentence_start (&start);
7831 while (!gtk_text_iter_ends_sentence (&start))
7833 if (!gtk_text_iter_backward_char (&start))
7837 case ATK_TEXT_BOUNDARY_LINE_START:
7838 case ATK_TEXT_BOUNDARY_LINE_END:
7840 icon_view = GTK_ICON_VIEW (item->widget);
7841 /* FIXME we probably have to use GailTextCell to salvage this */
7842 gtk_icon_view_update_item_text (icon_view, item->item);
7843 get_pango_text_offsets (icon_view->priv->layout,
7856 *start_offset = gtk_text_iter_get_offset (&start);
7857 *end_offset = gtk_text_iter_get_offset (&end);
7859 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7863 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7865 AtkTextBoundary boundary_type,
7869 GtkIconViewItemAccessible *item;
7870 GtkTextIter start, end;
7871 GtkTextBuffer *buffer;
7873 GtkIconView *icon_view;
7876 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7878 if (!GTK_IS_ICON_VIEW (item->widget))
7881 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7884 buffer = item->text_buffer;
7886 if (!gtk_text_buffer_get_char_count (buffer))
7890 return g_strdup ("");
7892 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7896 switch (boundary_type)
7898 case ATK_TEXT_BOUNDARY_CHAR:
7899 gtk_text_iter_forward_char (&end);
7901 case ATK_TEXT_BOUNDARY_WORD_START:
7902 if (!gtk_text_iter_starts_word (&start))
7903 gtk_text_iter_backward_word_start (&start);
7904 if (gtk_text_iter_inside_word (&end))
7905 gtk_text_iter_forward_word_end (&end);
7906 while (!gtk_text_iter_starts_word (&end))
7908 if (!gtk_text_iter_forward_char (&end))
7912 case ATK_TEXT_BOUNDARY_WORD_END:
7913 if (gtk_text_iter_inside_word (&start) &&
7914 !gtk_text_iter_starts_word (&start))
7915 gtk_text_iter_backward_word_start (&start);
7916 while (!gtk_text_iter_ends_word (&start))
7918 if (!gtk_text_iter_backward_char (&start))
7921 gtk_text_iter_forward_word_end (&end);
7923 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7924 if (!gtk_text_iter_starts_sentence (&start))
7925 gtk_text_iter_backward_sentence_start (&start);
7926 if (gtk_text_iter_inside_sentence (&end))
7927 gtk_text_iter_forward_sentence_end (&end);
7928 while (!gtk_text_iter_starts_sentence (&end))
7930 if (!gtk_text_iter_forward_char (&end))
7934 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7935 if (gtk_text_iter_inside_sentence (&start) &&
7936 !gtk_text_iter_starts_sentence (&start))
7937 gtk_text_iter_backward_sentence_start (&start);
7938 while (!gtk_text_iter_ends_sentence (&start))
7940 if (!gtk_text_iter_backward_char (&start))
7943 gtk_text_iter_forward_sentence_end (&end);
7945 case ATK_TEXT_BOUNDARY_LINE_START:
7946 case ATK_TEXT_BOUNDARY_LINE_END:
7948 icon_view = GTK_ICON_VIEW (item->widget);
7949 /* FIXME we probably have to use GailTextCell to salvage this */
7950 gtk_icon_view_update_item_text (icon_view, item->item);
7951 get_pango_text_offsets (icon_view->priv->layout,
7965 *start_offset = gtk_text_iter_get_offset (&start);
7966 *end_offset = gtk_text_iter_get_offset (&end);
7968 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7972 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7974 AtkTextBoundary boundary_type,
7978 GtkIconViewItemAccessible *item;
7979 GtkTextIter start, end;
7980 GtkTextBuffer *buffer;
7982 GtkIconView *icon_view;
7985 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7987 if (!GTK_IS_ICON_VIEW (item->widget))
7990 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7993 buffer = item->text_buffer;
7995 if (!gtk_text_buffer_get_char_count (buffer))
7999 return g_strdup ("");
8001 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8005 switch (boundary_type)
8007 case ATK_TEXT_BOUNDARY_CHAR:
8008 gtk_text_iter_forward_char(&start);
8009 gtk_text_iter_forward_chars(&end, 2);
8011 case ATK_TEXT_BOUNDARY_WORD_START:
8012 if (gtk_text_iter_inside_word (&end))
8013 gtk_text_iter_forward_word_end (&end);
8014 while (!gtk_text_iter_starts_word (&end))
8016 if (!gtk_text_iter_forward_char (&end))
8020 if (!gtk_text_iter_is_end (&end))
8022 gtk_text_iter_forward_word_end (&end);
8023 while (!gtk_text_iter_starts_word (&end))
8025 if (!gtk_text_iter_forward_char (&end))
8030 case ATK_TEXT_BOUNDARY_WORD_END:
8031 gtk_text_iter_forward_word_end (&end);
8033 if (!gtk_text_iter_is_end (&end))
8034 gtk_text_iter_forward_word_end (&end);
8036 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8037 if (gtk_text_iter_inside_sentence (&end))
8038 gtk_text_iter_forward_sentence_end (&end);
8039 while (!gtk_text_iter_starts_sentence (&end))
8041 if (!gtk_text_iter_forward_char (&end))
8045 if (!gtk_text_iter_is_end (&end))
8047 gtk_text_iter_forward_sentence_end (&end);
8048 while (!gtk_text_iter_starts_sentence (&end))
8050 if (!gtk_text_iter_forward_char (&end))
8055 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8056 gtk_text_iter_forward_sentence_end (&end);
8058 if (!gtk_text_iter_is_end (&end))
8059 gtk_text_iter_forward_sentence_end (&end);
8061 case ATK_TEXT_BOUNDARY_LINE_START:
8062 case ATK_TEXT_BOUNDARY_LINE_END:
8064 icon_view = GTK_ICON_VIEW (item->widget);
8065 /* FIXME we probably have to use GailTextCell to salvage this */
8066 gtk_icon_view_update_item_text (icon_view, item->item);
8067 get_pango_text_offsets (icon_view->priv->layout,
8079 *start_offset = gtk_text_iter_get_offset (&start);
8080 *end_offset = gtk_text_iter_get_offset (&end);
8082 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8086 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8088 GtkIconViewItemAccessible *item;
8090 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8092 if (!GTK_IS_ICON_VIEW (item->widget))
8095 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8098 return gtk_text_buffer_get_char_count (item->text_buffer);
8102 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8108 AtkCoordType coord_type)
8110 GtkIconViewItemAccessible *item;
8112 GtkIconView *icon_view;
8113 PangoRectangle char_rect;
8114 const gchar *item_text;
8118 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8120 if (!GTK_IS_ICON_VIEW (item->widget))
8123 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8127 icon_view = GTK_ICON_VIEW (item->widget);
8128 /* FIXME we probably have to use GailTextCell to salvage this */
8129 gtk_icon_view_update_item_text (icon_view, item->item);
8130 item_text = pango_layout_get_text (icon_view->priv->layout);
8131 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8132 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8134 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8135 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8136 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8137 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8138 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8139 *width = char_rect.width / PANGO_SCALE;
8140 *height = char_rect.height / PANGO_SCALE;
8145 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8148 AtkCoordType coord_type)
8150 GtkIconViewItemAccessible *item;
8153 GtkIconView *icon_view;
8154 const gchar *item_text;
8159 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8161 if (!GTK_IS_ICON_VIEW (item->widget))
8164 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8168 icon_view = GTK_ICON_VIEW (item->widget);
8169 /* FIXME we probably have to use GailTextCell to salvage this */
8170 gtk_icon_view_update_item_text (icon_view, item->item);
8171 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8172 x -= l_x + item->item->layout_x - item->item->x;
8173 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8174 y -= l_y + item->item->layout_y - item->item->y;
8175 item_text = pango_layout_get_text (icon_view->priv->layout);
8176 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8187 offset = g_utf8_strlen (item_text, -1);
8189 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8195 atk_text_item_interface_init (AtkTextIface *iface)
8197 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8198 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8199 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8200 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8201 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8202 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8203 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8204 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8208 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8213 AtkCoordType coord_type)
8215 GtkIconViewItemAccessible *item;
8216 AtkObject *parent_obj;
8219 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8221 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8222 if (!GTK_IS_WIDGET (item->widget))
8225 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8228 *width = item->item->width;
8229 *height = item->item->height;
8230 if (gtk_icon_view_item_accessible_is_showing (item))
8232 parent_obj = gtk_widget_get_accessible (item->widget);
8233 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8234 *x = l_x + item->item->x;
8235 *y = l_y + item->item->y;
8245 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8247 GtkIconViewItemAccessible *item;
8248 GtkWidget *toplevel;
8250 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8252 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8253 if (!GTK_IS_WIDGET (item->widget))
8256 gtk_widget_grab_focus (item->widget);
8257 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8258 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8259 if (GTK_WIDGET_TOPLEVEL (toplevel))
8260 gtk_window_present (GTK_WINDOW (toplevel));
8266 atk_component_item_interface_init (AtkComponentIface *iface)
8268 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8269 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8273 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8274 AtkStateType state_type,
8275 gboolean emit_signal)
8279 rc = atk_state_set_add_state (item->state_set, state_type);
8281 * The signal should only be generated if the value changed,
8282 * not when the item is set up. So states that are set
8283 * initially should pass FALSE as the emit_signal argument.
8288 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8289 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8290 if (state_type == ATK_STATE_VISIBLE)
8291 g_signal_emit_by_name (item, "visible_data_changed");
8298 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8299 AtkStateType state_type,
8300 gboolean emit_signal)
8302 if (atk_state_set_contains_state (item->state_set, state_type))
8306 rc = atk_state_set_remove_state (item->state_set, state_type);
8308 * The signal should only be generated if the value changed,
8309 * not when the item is set up. So states that are set
8310 * initially should pass FALSE as the emit_signal argument.
8315 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8316 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8317 if (state_type == ATK_STATE_VISIBLE)
8318 g_signal_emit_by_name (item, "visible_data_changed");
8328 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8330 GtkIconView *icon_view;
8331 GdkRectangle visible_rect;
8332 gboolean is_showing;
8335 * An item is considered "SHOWING" if any part of the item is in the
8336 * visible rectangle.
8339 if (!GTK_IS_ICON_VIEW (item->widget))
8342 if (item->item == NULL)
8345 icon_view = GTK_ICON_VIEW (item->widget);
8347 if (icon_view->priv->hadjustment)
8348 visible_rect.x += icon_view->priv->hadjustment->value;
8350 if (icon_view->priv->hadjustment)
8351 visible_rect.y += icon_view->priv->vadjustment->value;
8352 visible_rect.width = item->widget->allocation.width;
8353 visible_rect.height = item->widget->allocation.height;
8355 if (((item->item->x + item->item->width) < visible_rect.x) ||
8356 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8357 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8358 (item->item->y > (visible_rect.y + visible_rect.height)))
8367 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8368 gboolean emit_signal)
8370 if (gtk_icon_view_item_accessible_is_showing (item))
8371 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8374 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8379 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8383 item->state_set = atk_state_set_new ();
8385 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8386 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8387 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8388 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8389 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8391 for (i = 0; i < LAST_ACTION; i++)
8392 item->action_descriptions[i] = NULL;
8394 item->image_description = NULL;
8396 item->action_idle_handler = 0;
8400 gtk_icon_view_item_accessible_finalize (GObject *object)
8402 GtkIconViewItemAccessible *item;
8405 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8407 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8410 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8412 if (item->state_set)
8413 g_object_unref (item->state_set);
8415 if (item->text_buffer)
8416 g_object_unref (item->text_buffer);
8418 for (i = 0; i < LAST_ACTION; i++)
8419 g_free (item->action_descriptions[i]);
8421 g_free (item->image_description);
8423 if (item->action_idle_handler)
8425 g_source_remove (item->action_idle_handler);
8426 item->action_idle_handler = 0;
8429 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8432 static G_CONST_RETURN gchar*
8433 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8439 GtkIconViewItemAccessible *item;
8440 GtkTextIter start_iter;
8441 GtkTextIter end_iter;
8443 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8445 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8446 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8448 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8453 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8455 GtkIconViewItemAccessible *item;
8457 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8458 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8461 return gtk_widget_get_accessible (item->widget);
8467 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8469 GtkIconViewItemAccessible *item;
8471 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8472 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8474 return item->item->index;
8477 static AtkStateSet *
8478 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8480 GtkIconViewItemAccessible *item;
8481 GtkIconView *icon_view;
8483 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8484 g_return_val_if_fail (item->state_set, NULL);
8489 icon_view = GTK_ICON_VIEW (item->widget);
8490 if (icon_view->priv->cursor_item == item->item)
8491 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8493 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8495 return g_object_ref (item->state_set);
8499 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8501 GObjectClass *gobject_class;
8503 accessible_item_parent_class = g_type_class_peek_parent (klass);
8505 gobject_class = (GObjectClass *)klass;
8507 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8509 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8510 klass->get_name = gtk_icon_view_item_accessible_get_name;
8511 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8512 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8516 gtk_icon_view_item_accessible_get_type (void)
8518 static GType type = 0;
8522 const GTypeInfo tinfo =
8524 sizeof (GtkIconViewItemAccessibleClass),
8525 (GBaseInitFunc) NULL, /* base init */
8526 (GBaseFinalizeFunc) NULL, /* base finalize */
8527 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8528 (GClassFinalizeFunc) NULL, /* class finalize */
8529 NULL, /* class data */
8530 sizeof (GtkIconViewItemAccessible), /* instance size */
8531 0, /* nb preallocs */
8532 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8533 NULL /* value table */
8536 static const GInterfaceInfo atk_component_info =
8538 (GInterfaceInitFunc) atk_component_item_interface_init,
8539 (GInterfaceFinalizeFunc) NULL,
8542 static const GInterfaceInfo atk_action_info =
8544 (GInterfaceInitFunc) atk_action_item_interface_init,
8545 (GInterfaceFinalizeFunc) NULL,
8548 static const GInterfaceInfo atk_image_info =
8550 (GInterfaceInitFunc) atk_image_item_interface_init,
8551 (GInterfaceFinalizeFunc) NULL,
8554 static const GInterfaceInfo atk_text_info =
8556 (GInterfaceInitFunc) atk_text_item_interface_init,
8557 (GInterfaceFinalizeFunc) NULL,
8561 type = g_type_register_static (ATK_TYPE_OBJECT,
8562 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8563 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8564 &atk_component_info);
8565 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8567 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8569 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8576 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8577 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8578 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8580 static GType gtk_icon_view_accessible_get_type (void);
8585 } GtkIconViewAccessible;
8591 } GtkIconViewItemAccessibleInfo;
8597 GtkAdjustment *old_hadj;
8598 GtkAdjustment *old_vadj;
8600 GtkTreeModel *model;
8602 } GtkIconViewAccessiblePrivate;
8604 static GtkIconViewAccessiblePrivate *
8605 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8607 return g_object_get_qdata (G_OBJECT (accessible),
8608 accessible_private_data_quark);
8612 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8616 GtkIconViewItemAccessibleInfo *info;
8617 GtkIconViewItemAccessibleInfo *tmp_info;
8618 GtkIconViewAccessiblePrivate *priv;
8621 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8623 info->index = index;
8625 priv = gtk_icon_view_accessible_get_priv (accessible);
8626 items = priv->items;
8629 tmp_info = items->data;
8630 if (tmp_info->index > index)
8632 items = items->next;
8634 priv->items = g_list_insert_before (priv->items, items, info);
8635 priv->old_hadj = NULL;
8636 priv->old_vadj = NULL;
8640 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8642 GtkIconView *icon_view;
8645 widget = GTK_ACCESSIBLE (accessible)->widget;
8649 icon_view = GTK_ICON_VIEW (widget);
8651 return g_list_length (icon_view->priv->items);
8655 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8658 GtkIconViewAccessiblePrivate *priv;
8659 GtkIconViewItemAccessibleInfo *info;
8662 priv = gtk_icon_view_accessible_get_priv (accessible);
8663 items = priv->items;
8668 if (info->index == index)
8670 items = items->next;
8676 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8679 GtkIconView *icon_view;
8683 GtkIconViewItemAccessible *a11y_item;
8685 widget = GTK_ACCESSIBLE (accessible)->widget;
8689 icon_view = GTK_ICON_VIEW (widget);
8690 icons = g_list_nth (icon_view->priv->items, index);
8694 GtkIconViewItem *item = icons->data;
8696 g_return_val_if_fail (item->index == index, NULL);
8697 obj = gtk_icon_view_accessible_find_child (accessible, index);
8702 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8703 gtk_icon_view_item_accessible_info_new (accessible,
8706 obj->role = ATK_ROLE_ICON;
8707 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8708 a11y_item->item = item;
8709 a11y_item->widget = widget;
8710 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8712 gtk_icon_view_set_cell_data (icon_view, item);
8713 text = get_text (icon_view, item);
8716 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8720 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8721 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8729 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8732 GtkIconViewAccessiblePrivate *priv;
8733 GtkIconViewItemAccessibleInfo *info;
8734 GtkIconViewItemAccessible *item;
8737 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8741 gboolean act_on_item;
8743 widget = GTK_ACCESSIBLE (view)->widget;
8747 items = priv->items;
8749 act_on_item = (list == NULL);
8754 info = (GtkIconViewItemAccessibleInfo *)items->data;
8755 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8757 if (act_on_item == FALSE && list == items)
8761 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8763 items = items->next;
8769 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8770 GtkIconView *icon_view)
8773 GtkIconViewAccessible *view;
8776 * The scrollbars have changed
8778 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8779 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8781 gtk_icon_view_accessible_traverse_items (view, NULL);
8785 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8786 GtkAdjustment *hadj,
8787 GtkAdjustment *vadj)
8790 GtkIconViewAccessiblePrivate *priv;
8792 atk_obj = gtk_widget_get_accessible (widget);
8793 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8795 if (priv->old_hadj != hadj)
8799 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8800 (gpointer *)&priv->old_hadj);
8802 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8803 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8806 priv->old_hadj = hadj;
8809 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8810 (gpointer *)&priv->old_hadj);
8811 g_signal_connect (hadj,
8813 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8817 if (priv->old_vadj != vadj)
8821 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8822 (gpointer *)&priv->old_vadj);
8824 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8825 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8828 priv->old_vadj = vadj;
8831 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8832 (gpointer *)&priv->old_vadj);
8833 g_signal_connect (vadj,
8835 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8842 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8849 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8850 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8856 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8861 GtkIconViewAccessiblePrivate *priv;
8862 GtkIconViewItemAccessibleInfo *info;
8863 GtkIconViewAccessible *view;
8864 GtkIconViewItemAccessible *item;
8870 index = gtk_tree_path_get_indices(path)[0];
8871 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8872 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8873 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8875 items = priv->items;
8880 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8881 if (info->index != item->item->index)
8883 if (info->index < index)
8884 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8886 if (tmp_list == NULL)
8889 info->index = item->item->index;
8892 items = items->next;
8894 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8895 g_signal_emit_by_name (atk_obj, "children_changed::add",
8901 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8905 GtkIconViewAccessiblePrivate *priv;
8906 GtkIconViewItemAccessibleInfo *info;
8907 GtkIconViewAccessible *view;
8908 GtkIconViewItemAccessible *item;
8911 GList *deleted_item;
8915 index = gtk_tree_path_get_indices(path)[0];
8916 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8917 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8918 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8920 items = priv->items;
8922 deleted_item = NULL;
8927 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8928 if (info->index == index)
8930 deleted_item = items;
8932 if (info->index != item->item->index)
8934 if (tmp_list == NULL)
8937 info->index = item->item->index;
8940 items = items->next;
8942 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8945 info = deleted_item->data;
8946 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8948 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8952 priv->items = g_list_remove_link (priv->items, deleted_item);
8960 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8961 GtkIconViewItemAccessibleInfo *i2)
8963 return i1->index - i2->index;
8967 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8973 GtkIconViewAccessiblePrivate *priv;
8974 GtkIconViewItemAccessibleInfo *info;
8975 GtkIconView *icon_view;
8976 GtkIconViewItemAccessible *item;
8980 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8981 icon_view = GTK_ICON_VIEW (user_data);
8982 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8984 items = priv->items;
8988 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8989 info->index = new_order[info->index];
8990 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8991 items = items->next;
8993 priv->items = g_list_sort (priv->items,
8994 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9000 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9005 obj = G_OBJECT (model);
9006 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9007 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9008 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9009 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9013 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9017 obj = G_OBJECT (icon_view->priv->model);
9018 g_signal_connect_data (obj, "row_changed",
9019 (GCallback) gtk_icon_view_accessible_model_row_changed,
9020 icon_view, NULL, 0);
9021 g_signal_connect_data (obj, "row_inserted",
9022 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9023 icon_view, NULL, G_CONNECT_AFTER);
9024 g_signal_connect_data (obj, "row_deleted",
9025 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9026 icon_view, NULL, G_CONNECT_AFTER);
9027 g_signal_connect_data (obj, "rows_reordered",
9028 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9029 icon_view, NULL, G_CONNECT_AFTER);
9033 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9035 GtkIconViewItemAccessibleInfo *info;
9038 items = priv->items;
9041 info = (GtkIconViewItemAccessibleInfo *) items->data;
9042 g_object_unref (info->item);
9043 g_free (items->data);
9044 items = items->next;
9046 g_list_free (priv->items);
9051 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9054 GtkIconView *icon_view;
9057 GtkIconViewAccessiblePrivate *priv;
9059 if (strcmp (pspec->name, "model") == 0)
9061 widget = GTK_WIDGET (obj);
9062 atk_obj = gtk_widget_get_accessible (widget);
9063 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9066 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9067 (gpointer *)&priv->model);
9068 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9070 gtk_icon_view_accessible_clear_cache (priv);
9072 icon_view = GTK_ICON_VIEW (obj);
9073 priv->model = icon_view->priv->model;
9074 /* If there is no model the GtkIconView is probably being destroyed */
9077 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9078 gtk_icon_view_accessible_connect_model_signals (icon_view);
9086 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9089 GtkIconViewAccessiblePrivate *priv;
9090 GtkIconView *icon_view;
9092 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9093 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9095 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9096 g_object_set_qdata (G_OBJECT (accessible),
9097 accessible_private_data_quark,
9100 icon_view = GTK_ICON_VIEW (data);
9101 if (icon_view->priv->hadjustment)
9103 priv->old_hadj = icon_view->priv->hadjustment;
9104 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9105 g_signal_connect (icon_view->priv->hadjustment,
9107 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9110 if (icon_view->priv->vadjustment)
9112 priv->old_vadj = icon_view->priv->vadjustment;
9113 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9114 g_signal_connect (icon_view->priv->vadjustment,
9116 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9119 g_signal_connect_after (data,
9120 "set_scroll_adjustments",
9121 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9123 g_signal_connect (data,
9125 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9128 priv->model = icon_view->priv->model;
9131 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9132 gtk_icon_view_accessible_connect_model_signals (icon_view);
9135 accessible->role = ATK_ROLE_LAYERED_PANE;
9139 gtk_icon_view_accessible_finalize (GObject *object)
9141 GtkIconViewAccessiblePrivate *priv;
9143 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9144 gtk_icon_view_accessible_clear_cache (priv);
9148 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9152 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9153 GtkAccessible *accessible)
9156 GtkIconViewAccessiblePrivate *priv;
9158 atk_obj = ATK_OBJECT (accessible);
9159 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9162 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9163 (gpointer *)&priv->old_hadj);
9165 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9166 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9168 priv->old_hadj = NULL;
9172 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9173 (gpointer *)&priv->old_vadj);
9175 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9176 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9178 priv->old_vadj = NULL;
9183 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9185 if (accessible->widget)
9187 g_signal_connect_after (accessible->widget,
9189 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9192 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9196 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9198 GObjectClass *gobject_class;
9199 GtkAccessibleClass *accessible_class;
9201 accessible_parent_class = g_type_class_peek_parent (klass);
9203 gobject_class = (GObjectClass *)klass;
9204 accessible_class = (GtkAccessibleClass *)klass;
9206 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9208 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9209 klass->ref_child = gtk_icon_view_accessible_ref_child;
9210 klass->initialize = gtk_icon_view_accessible_initialize;
9212 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9214 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9218 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9221 AtkCoordType coord_type)
9224 GtkIconView *icon_view;
9225 GtkIconViewItem *item;
9228 widget = GTK_ACCESSIBLE (component)->widget;
9230 /* State is defunct */
9233 icon_view = GTK_ICON_VIEW (widget);
9234 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9235 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9237 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9243 atk_component_interface_init (AtkComponentIface *iface)
9245 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9249 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9253 GtkIconView *icon_view;
9254 GtkIconViewItem *item;
9256 widget = GTK_ACCESSIBLE (selection)->widget;
9260 icon_view = GTK_ICON_VIEW (widget);
9262 item = g_list_nth_data (icon_view->priv->items, i);
9267 gtk_icon_view_select_item (icon_view, item);
9273 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9276 GtkIconView *icon_view;
9278 widget = GTK_ACCESSIBLE (selection)->widget;
9282 icon_view = GTK_ICON_VIEW (widget);
9283 gtk_icon_view_unselect_all (icon_view);
9289 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9294 GtkIconView *icon_view;
9295 GtkIconViewItem *item;
9297 widget = GTK_ACCESSIBLE (selection)->widget;
9301 icon_view = GTK_ICON_VIEW (widget);
9303 l = icon_view->priv->items;
9310 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9321 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9324 GtkIconView *icon_view;
9325 GtkIconViewItem *item;
9329 widget = GTK_ACCESSIBLE (selection)->widget;
9333 icon_view = GTK_ICON_VIEW (widget);
9335 l = icon_view->priv->items;
9351 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9355 GtkIconView *icon_view;
9356 GtkIconViewItem *item;
9358 widget = GTK_ACCESSIBLE (selection)->widget;
9362 icon_view = GTK_ICON_VIEW (widget);
9364 item = g_list_nth_data (icon_view->priv->items, i);
9368 return item->selected;
9372 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9376 GtkIconView *icon_view;
9377 GtkIconViewItem *item;
9381 widget = GTK_ACCESSIBLE (selection)->widget;
9385 icon_view = GTK_ICON_VIEW (widget);
9386 l = icon_view->priv->items;
9395 gtk_icon_view_unselect_item (icon_view, item);
9407 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9410 GtkIconView *icon_view;
9412 widget = GTK_ACCESSIBLE (selection)->widget;
9416 icon_view = GTK_ICON_VIEW (widget);
9417 gtk_icon_view_select_all (icon_view);
9422 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9424 iface->add_selection = gtk_icon_view_accessible_add_selection;
9425 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9426 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9427 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9428 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9429 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9430 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9434 gtk_icon_view_accessible_get_type (void)
9436 static GType type = 0;
9440 static GTypeInfo tinfo =
9443 (GBaseInitFunc) NULL, /* base init */
9444 (GBaseFinalizeFunc) NULL, /* base finalize */
9445 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9446 (GClassFinalizeFunc) NULL, /* class finalize */
9447 NULL, /* class data */
9448 0, /* instance size */
9449 0, /* nb preallocs */
9450 (GInstanceInitFunc) NULL, /* instance init */
9451 NULL /* value table */
9453 static const GInterfaceInfo atk_component_info =
9455 (GInterfaceInitFunc) atk_component_interface_init,
9456 (GInterfaceFinalizeFunc) NULL,
9459 static const GInterfaceInfo atk_selection_info =
9461 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9462 (GInterfaceFinalizeFunc) NULL,
9467 * Figure out the size of the class and instance
9468 * we are deriving from
9470 AtkObjectFactory *factory;
9473 GType derived_atk_type;
9475 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9476 factory = atk_registry_get_factory (atk_get_default_registry (),
9478 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9479 g_type_query (derived_atk_type, &query);
9480 tinfo.class_size = query.class_size;
9481 tinfo.instance_size = query.instance_size;
9483 type = g_type_register_static (derived_atk_type,
9484 I_("GtkIconViewAccessible"),
9486 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9487 &atk_component_info);
9488 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9489 &atk_selection_info);
9495 gtk_icon_view_accessible_new (GObject *obj)
9497 AtkObject *accessible;
9499 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9501 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9502 atk_object_initialize (accessible, obj);
9508 gtk_icon_view_accessible_factory_get_accessible_type (void)
9510 return gtk_icon_view_accessible_get_type ();
9514 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9516 return gtk_icon_view_accessible_new (obj);
9520 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9522 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9523 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9527 gtk_icon_view_accessible_factory_get_type (void)
9529 static GType type = 0;
9533 const GTypeInfo tinfo =
9535 sizeof (AtkObjectFactoryClass),
9536 NULL, /* base_init */
9537 NULL, /* base_finalize */
9538 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9539 NULL, /* class_finalize */
9540 NULL, /* class_data */
9541 sizeof (AtkObjectFactory),
9542 0, /* n_preallocs */
9546 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9547 I_("GtkIconViewAccessibleFactory"),
9555 gtk_icon_view_get_accessible (GtkWidget *widget)
9557 static gboolean first_time = TRUE;
9561 AtkObjectFactory *factory;
9562 AtkRegistry *registry;
9564 GType derived_atk_type;
9567 * Figure out whether accessibility is enabled by looking at the
9568 * type of the accessible object which would be created for
9569 * the parent type of GtkIconView.
9571 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9573 registry = atk_get_default_registry ();
9574 factory = atk_registry_get_factory (registry,
9576 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9577 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9578 atk_registry_set_factory_type (registry,
9580 gtk_icon_view_accessible_factory_get_type ());
9583 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9587 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9588 GtkBuilder *builder,
9590 const gchar *tagname,
9591 GMarkupParser *parser,
9594 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9595 tagname, parser, data))
9598 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9599 tagname, parser, data);
9603 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9604 GtkBuilder *builder,
9606 const gchar *tagname,
9609 if (strcmp (tagname, "attributes") == 0)
9610 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9613 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9619 #define __GTK_ICON_VIEW_C__
9620 #include "gtkaliasdef.c"