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);
874 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
875 "activate_cursor_item", 0);
876 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
877 "activate_cursor_item", 0);
878 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
879 "activate_cursor_item", 0);
880 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
881 "activate_cursor_item", 0);
883 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
884 GTK_MOVEMENT_DISPLAY_LINES, -1);
885 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
886 GTK_MOVEMENT_DISPLAY_LINES, -1);
888 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
889 GTK_MOVEMENT_DISPLAY_LINES, 1);
890 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
891 GTK_MOVEMENT_DISPLAY_LINES, 1);
893 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
894 GTK_MOVEMENT_DISPLAY_LINES, -1);
896 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
897 GTK_MOVEMENT_DISPLAY_LINES, 1);
899 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
900 GTK_MOVEMENT_BUFFER_ENDS, -1);
901 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
902 GTK_MOVEMENT_BUFFER_ENDS, -1);
904 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
905 GTK_MOVEMENT_BUFFER_ENDS, 1);
906 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
907 GTK_MOVEMENT_BUFFER_ENDS, 1);
909 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
910 GTK_MOVEMENT_PAGES, -1);
911 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
912 GTK_MOVEMENT_PAGES, -1);
914 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
915 GTK_MOVEMENT_PAGES, 1);
916 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
917 GTK_MOVEMENT_PAGES, 1);
919 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
920 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
921 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
922 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
924 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
925 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
926 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
927 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
931 gtk_icon_view_buildable_init (GtkBuildableIface *iface)
933 parent_buildable_iface = g_type_interface_peek_parent (iface);
934 iface->add_child = _gtk_cell_layout_buildable_add_child;
935 iface->custom_tag_start = gtk_icon_view_buildable_custom_tag_start;
936 iface->custom_tag_end = gtk_icon_view_buildable_custom_tag_end;
940 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
942 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
943 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
944 iface->clear = gtk_icon_view_cell_layout_clear;
945 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
946 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
947 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
948 iface->reorder = gtk_icon_view_cell_layout_reorder;
949 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
953 gtk_icon_view_init (GtkIconView *icon_view)
955 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
957 icon_view->priv->width = 0;
958 icon_view->priv->height = 0;
959 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
960 icon_view->priv->pressed_button = -1;
961 icon_view->priv->press_start_x = -1;
962 icon_view->priv->press_start_y = -1;
963 icon_view->priv->text_column = -1;
964 icon_view->priv->markup_column = -1;
965 icon_view->priv->pixbuf_column = -1;
966 icon_view->priv->text_cell = -1;
967 icon_view->priv->pixbuf_cell = -1;
968 icon_view->priv->tooltip_column = -1;
970 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
972 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
974 icon_view->priv->cell_list = NULL;
975 icon_view->priv->n_cells = 0;
976 icon_view->priv->cursor_cell = -1;
978 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
980 icon_view->priv->columns = -1;
981 icon_view->priv->item_width = -1;
982 icon_view->priv->spacing = 0;
983 icon_view->priv->row_spacing = 6;
984 icon_view->priv->column_spacing = 6;
985 icon_view->priv->margin = 6;
989 gtk_icon_view_destroy (GtkObject *object)
991 GtkIconView *icon_view;
993 icon_view = GTK_ICON_VIEW (object);
995 gtk_icon_view_stop_editing (icon_view, TRUE);
997 gtk_icon_view_set_model (icon_view, NULL);
999 if (icon_view->priv->layout_idle_id != 0)
1001 g_source_remove (icon_view->priv->layout_idle_id);
1002 icon_view->priv->layout_idle_id = 0;
1005 if (icon_view->priv->scroll_to_path != NULL)
1007 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1008 icon_view->priv->scroll_to_path = NULL;
1011 remove_scroll_timeout (icon_view);
1013 if (icon_view->priv->hadjustment != NULL)
1015 g_object_unref (icon_view->priv->hadjustment);
1016 icon_view->priv->hadjustment = NULL;
1019 if (icon_view->priv->vadjustment != NULL)
1021 g_object_unref (icon_view->priv->vadjustment);
1022 icon_view->priv->vadjustment = NULL;
1025 clear_dest_info (icon_view);
1026 clear_source_info (icon_view);
1028 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
1031 /* GObject methods */
1033 gtk_icon_view_finalize (GObject *object)
1035 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
1037 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1042 gtk_icon_view_set_property (GObject *object,
1044 const GValue *value,
1047 GtkIconView *icon_view;
1049 icon_view = GTK_ICON_VIEW (object);
1053 case PROP_SELECTION_MODE:
1054 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1056 case PROP_PIXBUF_COLUMN:
1057 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1059 case PROP_TEXT_COLUMN:
1060 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1062 case PROP_MARKUP_COLUMN:
1063 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1066 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1068 case PROP_ORIENTATION:
1069 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1072 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1074 case PROP_ITEM_WIDTH:
1075 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1078 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1080 case PROP_ROW_SPACING:
1081 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1083 case PROP_COLUMN_SPACING:
1084 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1087 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1089 case PROP_REORDERABLE:
1090 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1093 case PROP_TOOLTIP_COLUMN:
1094 gtk_icon_view_set_tooltip_column (icon_view, g_value_get_int (value));
1098 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1104 gtk_icon_view_get_property (GObject *object,
1109 GtkIconView *icon_view;
1111 icon_view = GTK_ICON_VIEW (object);
1115 case PROP_SELECTION_MODE:
1116 g_value_set_enum (value, icon_view->priv->selection_mode);
1118 case PROP_PIXBUF_COLUMN:
1119 g_value_set_int (value, icon_view->priv->pixbuf_column);
1121 case PROP_TEXT_COLUMN:
1122 g_value_set_int (value, icon_view->priv->text_column);
1124 case PROP_MARKUP_COLUMN:
1125 g_value_set_int (value, icon_view->priv->markup_column);
1128 g_value_set_object (value, icon_view->priv->model);
1130 case PROP_ORIENTATION:
1131 g_value_set_enum (value, icon_view->priv->orientation);
1134 g_value_set_int (value, icon_view->priv->columns);
1136 case PROP_ITEM_WIDTH:
1137 g_value_set_int (value, icon_view->priv->item_width);
1140 g_value_set_int (value, icon_view->priv->spacing);
1142 case PROP_ROW_SPACING:
1143 g_value_set_int (value, icon_view->priv->row_spacing);
1145 case PROP_COLUMN_SPACING:
1146 g_value_set_int (value, icon_view->priv->column_spacing);
1149 g_value_set_int (value, icon_view->priv->margin);
1151 case PROP_REORDERABLE:
1152 g_value_set_boolean (value, icon_view->priv->reorderable);
1154 case PROP_TOOLTIP_COLUMN:
1155 g_value_set_int (value, icon_view->priv->tooltip_column);
1159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1164 /* GtkWidget signals */
1166 gtk_icon_view_realize (GtkWidget *widget)
1168 GtkIconView *icon_view;
1169 GdkWindowAttr attributes;
1170 gint attributes_mask;
1172 icon_view = GTK_ICON_VIEW (widget);
1174 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1176 /* Make the main, clipping window */
1177 attributes.window_type = GDK_WINDOW_CHILD;
1178 attributes.x = widget->allocation.x;
1179 attributes.y = widget->allocation.y;
1180 attributes.width = widget->allocation.width;
1181 attributes.height = widget->allocation.height;
1182 attributes.wclass = GDK_INPUT_OUTPUT;
1183 attributes.visual = gtk_widget_get_visual (widget);
1184 attributes.colormap = gtk_widget_get_colormap (widget);
1185 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1187 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1189 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1190 &attributes, attributes_mask);
1191 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1192 gdk_window_set_user_data (widget->window, widget);
1194 /* Make the window for the icon view */
1197 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1198 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1199 attributes.event_mask = (GDK_EXPOSURE_MASK |
1201 GDK_POINTER_MOTION_MASK |
1202 GDK_BUTTON_PRESS_MASK |
1203 GDK_BUTTON_RELEASE_MASK |
1204 GDK_KEY_PRESS_MASK |
1205 GDK_KEY_RELEASE_MASK) |
1206 gtk_widget_get_events (widget);
1208 icon_view->priv->bin_window = gdk_window_new (widget->window,
1209 &attributes, attributes_mask);
1210 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1212 widget->style = gtk_style_attach (widget->style, widget->window);
1213 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1215 gdk_window_show (icon_view->priv->bin_window);
1219 gtk_icon_view_unrealize (GtkWidget *widget)
1221 GtkIconView *icon_view;
1223 icon_view = GTK_ICON_VIEW (widget);
1225 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1226 gdk_window_destroy (icon_view->priv->bin_window);
1227 icon_view->priv->bin_window = NULL;
1229 /* GtkWidget::unrealize destroys children and widget->window */
1230 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1231 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1235 gtk_icon_view_state_changed (GtkWidget *widget,
1236 GtkStateType previous_state)
1238 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1240 if (GTK_WIDGET_REALIZED (widget))
1242 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1243 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1246 gtk_widget_queue_draw (widget);
1250 gtk_icon_view_style_set (GtkWidget *widget,
1251 GtkStyle *previous_style)
1253 GtkIconView *icon_view;
1255 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1257 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;
1275 icon_view = GTK_ICON_VIEW (widget);
1277 requisition->width = icon_view->priv->width;
1278 requisition->height = icon_view->priv->height;
1280 tmp_list = icon_view->priv->children;
1284 GtkIconViewChild *child = tmp_list->data;
1285 GtkRequisition child_requisition;
1287 tmp_list = tmp_list->next;
1289 if (GTK_WIDGET_VISIBLE (child->widget))
1290 gtk_widget_size_request (child->widget, &child_requisition);
1295 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1299 for (list = icon_view->priv->children; list; list = list->next)
1301 GtkIconViewChild *child = list->data;
1302 GtkAllocation allocation;
1304 /* totally ignore our child's requisition */
1305 if (child->cell < 0)
1307 allocation.x = child->item->x;
1308 allocation.y = child->item->y;
1309 allocation.width = child->item->width;
1310 allocation.height = child->item->height;
1314 GdkRectangle *box = &child->item->box[child->cell];
1316 allocation.x = box->x;
1317 allocation.y = box->y;
1318 allocation.width = box->width;
1319 allocation.height = box->height;
1322 gtk_widget_size_allocate (child->widget, &allocation);
1327 gtk_icon_view_size_allocate (GtkWidget *widget,
1328 GtkAllocation *allocation)
1330 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1332 GtkAdjustment *hadjustment, *vadjustment;
1334 widget->allocation = *allocation;
1336 if (GTK_WIDGET_REALIZED (widget))
1338 gdk_window_move_resize (widget->window,
1339 allocation->x, allocation->y,
1340 allocation->width, allocation->height);
1341 gdk_window_resize (icon_view->priv->bin_window,
1342 MAX (icon_view->priv->width, allocation->width),
1343 MAX (icon_view->priv->height, allocation->height));
1346 gtk_icon_view_layout (icon_view);
1348 gtk_icon_view_allocate_children (icon_view);
1350 hadjustment = icon_view->priv->hadjustment;
1351 vadjustment = icon_view->priv->vadjustment;
1353 hadjustment->page_size = allocation->width;
1354 hadjustment->page_increment = allocation->width * 0.9;
1355 hadjustment->step_increment = allocation->width * 0.1;
1356 hadjustment->lower = 0;
1357 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1359 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1360 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1362 vadjustment->page_size = allocation->height;
1363 vadjustment->page_increment = allocation->height * 0.9;
1364 vadjustment->step_increment = allocation->height * 0.1;
1365 vadjustment->lower = 0;
1366 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1368 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1369 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1371 if (GTK_WIDGET_REALIZED (widget) &&
1372 icon_view->priv->scroll_to_path)
1375 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1376 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1377 icon_view->priv->scroll_to_path = NULL;
1379 gtk_icon_view_scroll_to_path (icon_view, path,
1380 icon_view->priv->scroll_to_use_align,
1381 icon_view->priv->scroll_to_row_align,
1382 icon_view->priv->scroll_to_col_align);
1383 gtk_tree_path_free (path);
1387 gtk_adjustment_changed (hadjustment);
1388 gtk_adjustment_changed (vadjustment);
1393 gtk_icon_view_expose (GtkWidget *widget,
1394 GdkEventExpose *expose)
1396 GtkIconView *icon_view;
1401 GtkIconViewDropPosition dest_pos;
1402 GtkIconViewItem *dest_item = NULL;
1404 icon_view = GTK_ICON_VIEW (widget);
1406 if (expose->window != icon_view->priv->bin_window)
1409 cr = gdk_cairo_create (icon_view->priv->bin_window);
1410 cairo_set_line_width (cr, 1.);
1412 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1416 dest_index = gtk_tree_path_get_indices (path)[0];
1417 gtk_tree_path_free (path);
1422 for (icons = icon_view->priv->items; icons; icons = icons->next)
1424 GtkIconViewItem *item = icons->data;
1429 area.width = item->width;
1430 area.height = item->height;
1432 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1435 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1436 icon_view->priv->bin_window,
1437 item->x, item->y, TRUE);
1439 if (dest_index == item->index)
1447 case GTK_ICON_VIEW_DROP_INTO:
1448 gtk_paint_focus (widget->style,
1449 icon_view->priv->bin_window,
1450 GTK_WIDGET_STATE (widget),
1453 "iconview-drop-indicator",
1454 dest_item->x, dest_item->y,
1455 dest_item->width, dest_item->height);
1457 case GTK_ICON_VIEW_DROP_ABOVE:
1458 gtk_paint_focus (widget->style,
1459 icon_view->priv->bin_window,
1460 GTK_WIDGET_STATE (widget),
1463 "iconview-drop-indicator",
1464 dest_item->x, dest_item->y - 1,
1465 dest_item->width, 2);
1467 case GTK_ICON_VIEW_DROP_LEFT:
1468 gtk_paint_focus (widget->style,
1469 icon_view->priv->bin_window,
1470 GTK_WIDGET_STATE (widget),
1473 "iconview-drop-indicator",
1474 dest_item->x - 1, dest_item->y,
1475 2, dest_item->height);
1477 case GTK_ICON_VIEW_DROP_BELOW:
1478 gtk_paint_focus (widget->style,
1479 icon_view->priv->bin_window,
1480 GTK_WIDGET_STATE (widget),
1483 "iconview-drop-indicator",
1484 dest_item->x, dest_item->y + dest_item->height - 1,
1485 dest_item->width, 2);
1487 case GTK_ICON_VIEW_DROP_RIGHT:
1488 gtk_paint_focus (widget->style,
1489 icon_view->priv->bin_window,
1490 GTK_WIDGET_STATE (widget),
1493 "iconview-drop-indicator",
1494 dest_item->x + dest_item->width - 1, dest_item->y,
1495 2, dest_item->height);
1496 case GTK_ICON_VIEW_NO_DROP: ;
1501 if (icon_view->priv->doing_rubberband)
1503 GdkRectangle *rectangles;
1506 gdk_region_get_rectangles (expose->region,
1510 while (n_rectangles--)
1511 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1513 g_free (rectangles);
1518 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1524 rubberband_scroll_timeout (gpointer data)
1526 GtkIconView *icon_view;
1531 value = MIN (icon_view->priv->vadjustment->value +
1532 icon_view->priv->scroll_value_diff,
1533 icon_view->priv->vadjustment->upper -
1534 icon_view->priv->vadjustment->page_size);
1536 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1538 gtk_icon_view_update_rubberband (icon_view);
1544 gtk_icon_view_motion (GtkWidget *widget,
1545 GdkEventMotion *event)
1547 GtkIconView *icon_view;
1550 icon_view = GTK_ICON_VIEW (widget);
1552 gtk_icon_view_maybe_begin_drag (icon_view, event);
1554 if (icon_view->priv->doing_rubberband)
1556 gtk_icon_view_update_rubberband (widget);
1558 abs_y = event->y - icon_view->priv->height *
1559 (icon_view->priv->vadjustment->value /
1560 (icon_view->priv->vadjustment->upper -
1561 icon_view->priv->vadjustment->lower));
1563 if (abs_y < 0 || abs_y > widget->allocation.height)
1566 icon_view->priv->scroll_value_diff = abs_y;
1568 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1570 icon_view->priv->event_last_x = event->x;
1571 icon_view->priv->event_last_y = event->y;
1573 if (icon_view->priv->scroll_timeout_id == 0)
1574 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1578 remove_scroll_timeout (icon_view);
1585 gtk_icon_view_remove (GtkContainer *container,
1588 GtkIconView *icon_view;
1589 GtkIconViewChild *child = NULL;
1592 icon_view = GTK_ICON_VIEW (container);
1594 tmp_list = icon_view->priv->children;
1597 child = tmp_list->data;
1598 if (child->widget == widget)
1600 gtk_widget_unparent (widget);
1602 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1603 g_list_free_1 (tmp_list);
1608 tmp_list = tmp_list->next;
1613 gtk_icon_view_forall (GtkContainer *container,
1614 gboolean include_internals,
1615 GtkCallback callback,
1616 gpointer callback_data)
1618 GtkIconView *icon_view;
1619 GtkIconViewChild *child = NULL;
1622 icon_view = GTK_ICON_VIEW (container);
1624 tmp_list = icon_view->priv->children;
1627 child = tmp_list->data;
1628 tmp_list = tmp_list->next;
1630 (* callback) (child->widget, callback_data);
1635 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1636 GtkIconViewItem *item,
1637 GtkIconViewCellInfo *info,
1642 GdkRectangle cell_area;
1643 gboolean visible, mode;
1645 gtk_icon_view_set_cell_data (icon_view, item);
1647 g_object_get (info->cell,
1648 "visible", &visible,
1652 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1654 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1656 path = gtk_tree_path_new_from_indices (item->index, -1);
1657 path_string = gtk_tree_path_to_string (path);
1658 gtk_tree_path_free (path);
1660 gtk_cell_renderer_activate (info->cell,
1662 GTK_WIDGET (icon_view),
1668 g_free (path_string);
1673 gtk_icon_view_put (GtkIconView *icon_view,
1675 GtkIconViewItem *item,
1678 GtkIconViewChild *child;
1680 child = g_new (GtkIconViewChild, 1);
1682 child->widget = widget;
1686 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1688 if (GTK_WIDGET_REALIZED (icon_view))
1689 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1691 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1695 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1696 GtkIconView *icon_view)
1699 GtkIconViewItem *item;
1701 if (icon_view->priv->edited_item == NULL)
1704 item = icon_view->priv->edited_item;
1705 icon_view->priv->edited_item = NULL;
1706 icon_view->priv->editable = NULL;
1707 for (l = icon_view->priv->cell_list; l; l = l->next)
1709 GtkIconViewCellInfo *info = l->data;
1711 info->editing = FALSE;
1714 if (GTK_WIDGET_HAS_FOCUS (editable))
1715 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1717 g_signal_handlers_disconnect_by_func (editable,
1718 gtk_icon_view_remove_widget,
1721 gtk_container_remove (GTK_CONTAINER (icon_view),
1722 GTK_WIDGET (editable));
1724 gtk_icon_view_queue_draw_item (icon_view, item);
1729 gtk_icon_view_start_editing (GtkIconView *icon_view,
1730 GtkIconViewItem *item,
1731 GtkIconViewCellInfo *info,
1736 GdkRectangle cell_area;
1737 gboolean visible, mode;
1738 GtkCellEditable *editable;
1740 gtk_icon_view_set_cell_data (icon_view, item);
1742 g_object_get (info->cell,
1743 "visible", &visible,
1746 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1748 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1750 path = gtk_tree_path_new_from_indices (item->index, -1);
1751 path_string = gtk_tree_path_to_string (path);
1752 gtk_tree_path_free (path);
1754 editable = gtk_cell_renderer_start_editing (info->cell,
1756 GTK_WIDGET (icon_view),
1761 g_free (path_string);
1763 /* FIXME ugly special case */
1764 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1765 g_object_set (editable, "has-frame", TRUE, NULL);
1767 /* the rest corresponds to tree_view_real_start_editing... */
1768 icon_view->priv->edited_item = item;
1769 icon_view->priv->editable = editable;
1770 info->editing = TRUE;
1772 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1774 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1776 gtk_widget_grab_focus (GTK_WIDGET (editable));
1777 g_signal_connect (editable, "remove_widget",
1778 G_CALLBACK (gtk_icon_view_remove_widget),
1785 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1786 gboolean cancel_editing)
1788 GtkCellRenderer *cell = NULL;
1789 GtkIconViewItem *item;
1792 if (icon_view->priv->edited_item == NULL)
1796 * This is very evil. We need to do this, because
1797 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1798 * later on. If gtk_icon_view_row_changed notices
1799 * icon_view->priv->edited_item != NULL, it'll call
1800 * gtk_icon_view_stop_editing again. Bad things will happen then.
1802 * Please read that again if you intend to modify anything here.
1805 item = icon_view->priv->edited_item;
1806 icon_view->priv->edited_item = NULL;
1808 for (l = icon_view->priv->cell_list; l; l = l->next)
1810 GtkIconViewCellInfo *info = l->data;
1822 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1823 if (!cancel_editing)
1824 gtk_cell_editable_editing_done (icon_view->priv->editable);
1826 icon_view->priv->edited_item = item;
1828 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1832 * gtk_icon_view_set_cursor:
1833 * @icon_view: A #GtkIconView
1834 * @path: A #GtkTreePath
1835 * @cell: One of the cell renderers of @icon_view, or %NULL
1836 * @start_editing: %TRUE if the specified cell should start being edited.
1838 * Sets the current keyboard focus to be at @path, and selects it. This is
1839 * useful when you want to focus the user's attention on a particular item.
1840 * If @cell is not %NULL, then focus is given to the cell specified by
1841 * it. Additionally, if @start_editing is %TRUE, then editing should be
1842 * started in the specified cell.
1844 * This function is often followed by <literal>gtk_widget_grab_focus
1845 * (icon_view)</literal> in order to give keyboard focus to the widget.
1846 * Please note that editing can only happen when the widget is realized.
1851 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1853 GtkCellRenderer *cell,
1854 gboolean start_editing)
1856 GtkIconViewItem *item = NULL;
1857 GtkIconViewCellInfo *info = NULL;
1861 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1862 g_return_if_fail (path != NULL);
1863 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1865 gtk_icon_view_stop_editing (icon_view, TRUE);
1867 if (gtk_tree_path_get_depth (path) == 1)
1868 item = g_list_nth_data (icon_view->priv->items,
1869 gtk_tree_path_get_indices(path)[0]);
1875 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1879 if (info->cell == cell)
1888 g_return_if_fail (cell == NULL || info != NULL);
1890 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1891 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1893 if (info && start_editing)
1894 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1898 * gtk_icon_view_get_cursor:
1899 * @icon_view: A #GtkIconView
1900 * @path: Return location for the current cursor path, or %NULL
1901 * @cell: Return location the current focus cell, or %NULL
1903 * Fills in @path and @cell with the current cursor path and cell.
1904 * If the cursor isn't currently set, then *@path will be %NULL.
1905 * If no cell currently has focus, then *@cell will be %NULL.
1907 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1909 * Return value: %TRUE if the cursor is set.
1914 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1916 GtkCellRenderer **cell)
1918 GtkIconViewItem *item;
1919 GtkIconViewCellInfo *info;
1921 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1923 item = icon_view->priv->cursor_item;
1924 if (icon_view->priv->cursor_cell < 0)
1927 info = g_list_nth_data (icon_view->priv->cell_list,
1928 icon_view->priv->cursor_cell);
1933 *path = gtk_tree_path_new_from_indices (item->index, -1);
1946 return (item != NULL);
1950 gtk_icon_view_button_press (GtkWidget *widget,
1951 GdkEventButton *event)
1953 GtkIconView *icon_view;
1954 GtkIconViewItem *item;
1955 GtkIconViewCellInfo *info = NULL;
1956 gboolean dirty = FALSE;
1957 GtkCellRendererMode mode;
1960 icon_view = GTK_ICON_VIEW (widget);
1962 if (event->window != icon_view->priv->bin_window)
1965 if (!GTK_WIDGET_HAS_FOCUS (widget))
1966 gtk_widget_grab_focus (widget);
1968 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1970 item = gtk_icon_view_get_item_at_coords (icon_view,
1976 g_object_get (info->cell, "mode", &mode, NULL);
1978 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1979 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1980 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1984 gtk_icon_view_scroll_to_item (icon_view, item);
1986 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1988 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1990 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1991 (event->state & GDK_SHIFT_MASK))
1993 gtk_icon_view_unselect_all_internal (icon_view);
1995 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1996 if (!icon_view->priv->anchor_item)
1997 icon_view->priv->anchor_item = item;
1999 gtk_icon_view_select_all_between (icon_view,
2000 icon_view->priv->anchor_item,
2006 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
2007 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
2008 (event->state & GDK_CONTROL_MASK))
2010 item->selected = !item->selected;
2011 gtk_icon_view_queue_draw_item (icon_view, item);
2016 if (!item->selected)
2018 gtk_icon_view_unselect_all_internal (icon_view);
2020 item->selected = TRUE;
2021 gtk_icon_view_queue_draw_item (icon_view, item);
2025 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
2026 icon_view->priv->anchor_item = item;
2029 /* Save press to possibly begin a drag */
2030 if (icon_view->priv->pressed_button < 0)
2032 icon_view->priv->pressed_button = event->button;
2033 icon_view->priv->press_start_x = event->x;
2034 icon_view->priv->press_start_y = event->y;
2037 if (!icon_view->priv->last_single_clicked)
2038 icon_view->priv->last_single_clicked = item;
2040 /* cancel the current editing, if it exists */
2041 gtk_icon_view_stop_editing (icon_view, TRUE);
2043 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2044 gtk_icon_view_item_activate_cell (icon_view, item, info,
2046 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2047 gtk_icon_view_start_editing (icon_view, item, info,
2052 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2053 !(event->state & GDK_CONTROL_MASK))
2055 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2058 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2059 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2064 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2066 item = gtk_icon_view_get_item_at_coords (icon_view,
2071 if (item && item == icon_view->priv->last_single_clicked)
2075 path = gtk_tree_path_new_from_indices (item->index, -1);
2076 gtk_icon_view_item_activated (icon_view, path);
2077 gtk_tree_path_free (path);
2080 icon_view->priv->last_single_clicked = NULL;
2081 icon_view->priv->pressed_button = -1;
2085 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2087 return event->button == 1;
2091 gtk_icon_view_button_release (GtkWidget *widget,
2092 GdkEventButton *event)
2094 GtkIconView *icon_view;
2096 icon_view = GTK_ICON_VIEW (widget);
2098 if (icon_view->priv->pressed_button == event->button)
2099 icon_view->priv->pressed_button = -1;
2101 gtk_icon_view_stop_rubberbanding (icon_view);
2103 remove_scroll_timeout (icon_view);
2109 gtk_icon_view_key_press (GtkWidget *widget,
2112 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2114 if (icon_view->priv->doing_rubberband)
2116 if (event->keyval == GDK_Escape)
2117 gtk_icon_view_stop_rubberbanding (icon_view);
2122 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2126 gtk_icon_view_key_release (GtkWidget *widget,
2129 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2131 if (icon_view->priv->doing_rubberband)
2134 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2138 gtk_icon_view_update_rubberband (gpointer data)
2140 GtkIconView *icon_view;
2142 GdkRectangle old_area;
2143 GdkRectangle new_area;
2144 GdkRectangle common;
2145 GdkRegion *invalid_region;
2147 icon_view = GTK_ICON_VIEW (data);
2149 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2154 old_area.x = MIN (icon_view->priv->rubberband_x1,
2155 icon_view->priv->rubberband_x2);
2156 old_area.y = MIN (icon_view->priv->rubberband_y1,
2157 icon_view->priv->rubberband_y2);
2158 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2159 icon_view->priv->rubberband_x1) + 1;
2160 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2161 icon_view->priv->rubberband_y1) + 1;
2163 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2164 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2165 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2166 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2168 invalid_region = gdk_region_rectangle (&old_area);
2169 gdk_region_union_with_rect (invalid_region, &new_area);
2171 gdk_rectangle_intersect (&old_area, &new_area, &common);
2172 if (common.width > 2 && common.height > 2)
2174 GdkRegion *common_region;
2176 /* make sure the border is invalidated */
2182 common_region = gdk_region_rectangle (&common);
2184 gdk_region_subtract (invalid_region, common_region);
2185 gdk_region_destroy (common_region);
2188 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2190 gdk_region_destroy (invalid_region);
2192 icon_view->priv->rubberband_x2 = x;
2193 icon_view->priv->rubberband_y2 = y;
2195 gtk_icon_view_update_rubberband_selection (icon_view);
2199 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2205 g_assert (!icon_view->priv->doing_rubberband);
2207 for (items = icon_view->priv->items; items; items = items->next)
2209 GtkIconViewItem *item = items->data;
2211 item->selected_before_rubberbanding = item->selected;
2214 icon_view->priv->rubberband_x1 = x;
2215 icon_view->priv->rubberband_y1 = y;
2216 icon_view->priv->rubberband_x2 = x;
2217 icon_view->priv->rubberband_y2 = y;
2219 icon_view->priv->doing_rubberband = TRUE;
2221 gtk_grab_add (GTK_WIDGET (icon_view));
2225 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2227 if (!icon_view->priv->doing_rubberband)
2230 icon_view->priv->doing_rubberband = FALSE;
2232 gtk_grab_remove (GTK_WIDGET (icon_view));
2234 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2238 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2241 gint x, y, width, height;
2242 gboolean dirty = FALSE;
2244 x = MIN (icon_view->priv->rubberband_x1,
2245 icon_view->priv->rubberband_x2);
2246 y = MIN (icon_view->priv->rubberband_y1,
2247 icon_view->priv->rubberband_y2);
2248 width = ABS (icon_view->priv->rubberband_x1 -
2249 icon_view->priv->rubberband_x2);
2250 height = ABS (icon_view->priv->rubberband_y1 -
2251 icon_view->priv->rubberband_y2);
2253 for (items = icon_view->priv->items; items; items = items->next)
2255 GtkIconViewItem *item = items->data;
2259 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2260 x, y, width, height);
2262 selected = is_in ^ item->selected_before_rubberbanding;
2264 if (item->selected != selected)
2266 item->selected = selected;
2268 gtk_icon_view_queue_draw_item (icon_view, item);
2273 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2277 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2278 GtkIconViewItem *item,
2287 if (MIN (x + width, item->x + item->width) - MAX (x, item->x) <= 0 ||
2288 MIN (y + height, item->y + item->height) - MAX (y, item->y) <= 0)
2291 for (l = icon_view->priv->cell_list; l; l = l->next)
2293 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2295 if (!info->cell->visible)
2298 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2300 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2301 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2309 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2311 gboolean dirty = FALSE;
2314 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2317 for (items = icon_view->priv->items; items; items = items->next)
2319 GtkIconViewItem *item = items->data;
2323 item->selected = FALSE;
2325 gtk_icon_view_queue_draw_item (icon_view, item);
2333 /* GtkIconView signals */
2335 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2336 GtkAdjustment *hadj,
2337 GtkAdjustment *vadj)
2339 gboolean need_adjust = FALSE;
2342 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2344 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2346 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2348 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2350 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2352 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2353 0, 0, NULL, NULL, icon_view);
2354 g_object_unref (icon_view->priv->hadjustment);
2357 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2359 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2360 0, 0, NULL, NULL, icon_view);
2361 g_object_unref (icon_view->priv->vadjustment);
2364 if (icon_view->priv->hadjustment != hadj)
2366 icon_view->priv->hadjustment = hadj;
2367 g_object_ref_sink (icon_view->priv->hadjustment);
2369 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2370 G_CALLBACK (gtk_icon_view_adjustment_changed),
2375 if (icon_view->priv->vadjustment != vadj)
2377 icon_view->priv->vadjustment = vadj;
2378 g_object_ref_sink (icon_view->priv->vadjustment);
2380 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2381 G_CALLBACK (gtk_icon_view_adjustment_changed),
2387 gtk_icon_view_adjustment_changed (NULL, icon_view);
2391 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2393 gtk_icon_view_select_all (icon_view);
2397 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2399 gtk_icon_view_unselect_all (icon_view);
2403 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2405 gtk_icon_view_unselect_all (icon_view);
2407 if (icon_view->priv->cursor_item != NULL)
2408 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2412 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2415 GtkCellRendererMode mode;
2416 GtkIconViewCellInfo *info = NULL;
2418 if (!icon_view->priv->cursor_item)
2421 info = g_list_nth_data (icon_view->priv->cell_list,
2422 icon_view->priv->cursor_cell);
2426 g_object_get (info->cell, "mode", &mode, NULL);
2428 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2430 gtk_icon_view_item_activate_cell (icon_view,
2431 icon_view->priv->cursor_item,
2435 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2437 gtk_icon_view_start_editing (icon_view,
2438 icon_view->priv->cursor_item,
2444 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2445 gtk_icon_view_item_activated (icon_view, path);
2446 gtk_tree_path_free (path);
2452 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2454 if (!icon_view->priv->cursor_item)
2457 switch (icon_view->priv->selection_mode)
2459 case GTK_SELECTION_NONE:
2461 case GTK_SELECTION_BROWSE:
2462 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2464 case GTK_SELECTION_SINGLE:
2465 if (icon_view->priv->cursor_item->selected)
2466 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2468 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2470 case GTK_SELECTION_MULTIPLE:
2471 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2472 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2474 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2479 /* Internal functions */
2481 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2482 GtkIconView *icon_view)
2484 if (GTK_WIDGET_REALIZED (icon_view))
2486 gdk_window_move (icon_view->priv->bin_window,
2487 - icon_view->priv->hadjustment->value,
2488 - icon_view->priv->vadjustment->value);
2490 if (icon_view->priv->doing_rubberband)
2491 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2493 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2498 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2503 gint *maximum_width)
2506 gint x, current_width;
2507 GList *items, *last_item;
2514 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2515 max_height = g_new0 (gint, icon_view->priv->n_cells);
2522 gtk_widget_style_get (GTK_WIDGET (icon_view),
2523 "focus-line-width", &focus_width,
2526 x += icon_view->priv->margin + focus_width;
2527 current_width += 2 * (icon_view->priv->margin + focus_width);
2532 GtkIconViewItem *item = items->data;
2534 gtk_icon_view_calculate_item_size (icon_view, item);
2535 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2537 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2539 current_width += item->width;
2541 if (items != first_item)
2543 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2544 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2548 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2550 item->y = *y + focus_width;
2551 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2553 x = current_width - (icon_view->priv->margin + focus_width);
2555 for (i = 0; i < icon_view->priv->n_cells; i++)
2556 max_height[i] = MAX (max_height[i], item->box[i].height);
2558 if (current_width > *maximum_width)
2559 *maximum_width = current_width;
2565 items = items->next;
2570 /* Now go through the row again and align the icons */
2571 for (items = first_item; items != last_item; items = items->next)
2573 GtkIconViewItem *item = items->data;
2575 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2577 /* We may want to readjust the new y coordinate. */
2578 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2579 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2582 item->col = col - 1 - item->col;
2585 g_free (max_height);
2591 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2594 if (upper != adj->upper)
2596 gdouble min = MAX (0.0, upper - adj->page_size);
2597 gboolean value_changed = FALSE;
2601 if (adj->value > min)
2604 value_changed = TRUE;
2607 gtk_adjustment_changed (adj);
2610 gtk_adjustment_value_changed (adj);
2615 gtk_icon_view_layout (GtkIconView *icon_view)
2617 gint y = 0, maximum_width = 0;
2623 if (icon_view->priv->layout_idle_id != 0)
2625 g_source_remove (icon_view->priv->layout_idle_id);
2626 icon_view->priv->layout_idle_id = 0;
2629 if (icon_view->priv->model == NULL)
2632 widget = GTK_WIDGET (icon_view);
2634 item_width = icon_view->priv->item_width;
2638 for (icons = icon_view->priv->items; icons; icons = icons->next)
2640 GtkIconViewItem *item = icons->data;
2641 gtk_icon_view_calculate_item_size (icon_view, item);
2642 item_width = MAX (item_width, item->width);
2647 icons = icon_view->priv->items;
2648 y += icon_view->priv->margin;
2653 gtk_icon_view_set_cell_data (icon_view, icons->data);
2654 adjust_wrap_width (icon_view, icons->data);
2659 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2661 &y, &maximum_width);
2664 while (icons != NULL);
2666 if (maximum_width != icon_view->priv->width)
2667 icon_view->priv->width = maximum_width;
2669 y += icon_view->priv->margin;
2671 if (y != icon_view->priv->height)
2672 icon_view->priv->height = y;
2674 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2675 icon_view->priv->width);
2676 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2677 icon_view->priv->height);
2679 if (icon_view->priv->width != widget->requisition.width ||
2680 icon_view->priv->height != widget->requisition.height)
2681 gtk_widget_queue_resize_no_redraw (widget);
2683 if (GTK_WIDGET_REALIZED (icon_view))
2684 gdk_window_resize (icon_view->priv->bin_window,
2685 MAX (icon_view->priv->width, widget->allocation.width),
2686 MAX (icon_view->priv->height, widget->allocation.height));
2688 if (icon_view->priv->scroll_to_path)
2692 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2693 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2694 icon_view->priv->scroll_to_path = NULL;
2696 gtk_icon_view_scroll_to_path (icon_view, path,
2697 icon_view->priv->scroll_to_use_align,
2698 icon_view->priv->scroll_to_row_align,
2699 icon_view->priv->scroll_to_col_align);
2700 gtk_tree_path_free (path);
2703 gtk_widget_queue_draw (widget);
2707 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2708 GtkIconViewItem *item,
2709 GtkIconViewCellInfo *info,
2710 GdkRectangle *cell_area)
2712 g_return_if_fail (info->position < item->n_cells);
2714 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2716 cell_area->x = item->box[info->position].x - item->before[info->position];
2717 cell_area->y = item->y;
2718 cell_area->width = item->box[info->position].width +
2719 item->before[info->position] + item->after[info->position];
2720 cell_area->height = item->height;
2724 cell_area->x = item->x;
2725 cell_area->y = item->box[info->position].y - item->before[info->position];
2726 cell_area->width = item->width;
2727 cell_area->height = item->box[info->position].height +
2728 item->before[info->position] + item->after[info->position];
2733 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2734 GtkIconViewItem *item,
2735 GtkIconViewCellInfo *info,
2738 g_return_if_fail (info->position < item->n_cells);
2740 *box = item->box[info->position];
2743 /* try to guess a reasonable wrap width for an implicit text cell renderer
2746 adjust_wrap_width (GtkIconView *icon_view,
2747 GtkIconViewItem *item)
2749 GtkIconViewCellInfo *text_info;
2750 GtkIconViewCellInfo *pixbuf_info;
2751 gint pixbuf_width, wrap_width;
2753 if (icon_view->priv->text_cell != -1 &&
2754 icon_view->priv->pixbuf_cell != -1)
2758 text_info = g_list_nth_data (icon_view->priv->cell_list,
2759 icon_view->priv->text_cell);
2760 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2761 icon_view->priv->pixbuf_cell);
2763 gtk_cell_renderer_get_size (pixbuf_info->cell,
2764 GTK_WIDGET (icon_view),
2770 if (icon_view->priv->item_width > 0)
2771 item_width = icon_view->priv->item_width;
2773 item_width = item->width;
2775 if (item->width == -1)
2778 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2780 wrap_width = MAX (2 * pixbuf_width, 50);
2782 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2783 wrap_width = item_width;
2785 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2787 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2788 g_object_set (text_info->cell, "width", wrap_width, NULL);
2793 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2794 GtkIconViewItem *item)
2799 if (item->width != -1 && item->height != -1)
2802 if (item->n_cells != icon_view->priv->n_cells)
2804 g_free (item->before);
2805 g_free (item->after);
2808 item->before = g_new0 (gint, icon_view->priv->n_cells);
2809 item->after = g_new0 (gint, icon_view->priv->n_cells);
2810 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2812 item->n_cells = icon_view->priv->n_cells;
2815 gtk_icon_view_set_cell_data (icon_view, item);
2817 spacing = icon_view->priv->spacing;
2821 for (l = icon_view->priv->cell_list; l; l = l->next)
2823 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2825 if (!info->cell->visible)
2828 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2830 &item->box[info->position].width,
2831 &item->box[info->position].height);
2833 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2835 item->width += item->box[info->position].width
2836 + (info->position > 0 ? spacing : 0);
2837 item->height = MAX (item->height, item->box[info->position].height);
2841 item->width = MAX (item->width, item->box[info->position].width);
2842 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2848 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2849 GtkIconViewItem *item,
2852 GdkRectangle cell_area;
2858 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2860 gtk_icon_view_set_cell_data (icon_view, item);
2862 spacing = icon_view->priv->spacing;
2865 for (i = 0; i < icon_view->priv->n_cells; i++)
2867 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2868 item->height = MAX (item->height, max_height[i]);
2870 item->height += max_height[i] + (i > 0 ? spacing : 0);
2873 cell_area.x = item->x;
2874 cell_area.y = item->y;
2876 for (k = 0; k < 2; k++)
2877 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2879 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2881 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2884 if (!info->cell->visible)
2887 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2889 cell_area.width = item->box[info->position].width;
2890 cell_area.height = item->height;
2894 cell_area.width = item->width;
2895 cell_area.height = max_height[i];
2898 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2900 &item->box[info->position].x, &item->box[info->position].y,
2901 &item->box[info->position].width, &item->box[info->position].height);
2903 item->box[info->position].x += cell_area.x;
2904 item->box[info->position].y += cell_area.y;
2905 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2907 item->before[info->position] = item->box[info->position].x - cell_area.x;
2908 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2909 cell_area.x += cell_area.width + spacing;
2913 if (item->box[info->position].width > item->width)
2915 item->width = item->box[info->position].width;
2916 cell_area.width = item->width;
2918 item->before[info->position] = item->box[info->position].y - cell_area.y;
2919 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2920 cell_area.y += cell_area.height + spacing;
2924 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2926 for (i = 0; i < icon_view->priv->n_cells; i++)
2928 item->box[i].x = item->x + item->width -
2929 (item->box[i].x + item->box[i].width - item->x);
2935 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2937 g_list_foreach (icon_view->priv->items,
2938 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2942 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2949 gtk_icon_view_paint_item (GtkIconView *icon_view,
2951 GtkIconViewItem *item,
2953 GdkDrawable *drawable,
2956 gboolean draw_focus)
2958 gint focus_width, focus_pad;
2960 GdkRectangle cell_area, box;
2964 GtkCellRendererState flags;
2966 if (icon_view->priv->model == NULL)
2969 gtk_icon_view_set_cell_data (icon_view, item);
2971 gtk_widget_style_get (GTK_WIDGET (icon_view),
2972 "focus-line-width", &focus_width,
2973 "focus-padding", &focus_pad,
2976 padding = focus_width;
2980 flags = GTK_CELL_RENDERER_SELECTED;
2981 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2982 state = GTK_STATE_SELECTED;
2984 state = GTK_STATE_ACTIVE;
2989 state = GTK_STATE_NORMAL;
2992 #ifdef DEBUG_ICON_VIEW
2993 gdk_draw_rectangle (drawable,
2994 GTK_WIDGET (icon_view)->style->black_gc,
2997 item->width, item->height);
3001 for (l = icon_view->priv->cell_list; l; l = l->next)
3003 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3005 if (!info->cell->visible)
3008 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3010 /* FIXME we hardwire background drawing behind text
3011 * cell renderers here
3013 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3015 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
3016 cairo_rectangle (cr,
3017 x - item->x + box.x,
3018 y - item->y + box.y,
3019 box.width, box.height);
3024 for (l = icon_view->priv->cell_list; l; l = l->next)
3026 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3028 if (!info->cell->visible)
3031 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
3033 #ifdef DEBUG_ICON_VIEW
3034 gdk_draw_rectangle (drawable,
3035 GTK_WIDGET (icon_view)->style->black_gc,
3037 x - item->x + cell_area.x,
3038 y - item->y + cell_area.y,
3039 cell_area.width, cell_area.height);
3041 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3043 gdk_draw_rectangle (drawable,
3044 GTK_WIDGET (icon_view)->style->black_gc,
3046 x - item->x + box.x,
3047 y - item->y + box.y,
3048 box.width, box.height);
3051 cell_area.x = x - item->x + cell_area.x;
3052 cell_area.y = y - item->y + cell_area.y;
3054 gtk_cell_renderer_render (info->cell,
3056 GTK_WIDGET (icon_view),
3057 &cell_area, &cell_area, area, flags);
3061 /* FIXME where to draw the focus with generic cell renderers ? */
3063 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3064 item == icon_view->priv->cursor_item)
3065 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3067 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3069 if (!info->cell->visible)
3072 if (icon_view->priv->cursor_cell < 0 &&
3073 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3074 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3075 icon_view->priv->cursor_cell = i;
3077 if (i == icon_view->priv->cursor_cell)
3079 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3081 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3085 GTK_WIDGET (icon_view),
3087 x - item->x + box.x - padding,
3088 y - item->y + box.y - padding,
3089 box.width + 2 * padding,
3090 box.height + 2 * padding);
3097 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3102 GdkRectangle rubber_rect;
3103 GdkColor *fill_color_gdk;
3104 guchar fill_color_alpha;
3106 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3107 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3108 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3109 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3111 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3114 gtk_widget_style_get (GTK_WIDGET (icon_view),
3115 "selection-box-color", &fill_color_gdk,
3116 "selection-box-alpha", &fill_color_alpha,
3119 if (!fill_color_gdk)
3120 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3122 cairo_set_source_rgba (cr,
3123 fill_color_gdk->red / 65535.,
3124 fill_color_gdk->green / 65535.,
3125 fill_color_gdk->blue / 65535.,
3126 fill_color_alpha / 255.);
3129 gdk_cairo_rectangle (cr, &rect);
3133 /* Draw the border without alpha */
3134 cairo_set_source_rgb (cr,
3135 fill_color_gdk->red / 65535.,
3136 fill_color_gdk->green / 65535.,
3137 fill_color_gdk->blue / 65535.);
3138 cairo_rectangle (cr,
3139 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3140 rubber_rect.width - 1, rubber_rect.height - 1);
3144 gdk_color_free (fill_color_gdk);
3148 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3154 index = gtk_tree_path_get_indices (path)[0];
3156 for (l = icon_view->priv->items; l; l = l->next)
3158 GtkIconViewItem *item = l->data;
3160 if (item->index == index)
3162 gtk_icon_view_queue_draw_item (icon_view, item);
3169 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3170 GtkIconViewItem *item)
3175 gtk_widget_style_get (GTK_WIDGET (icon_view),
3176 "focus-line-width", &focus_width,
3179 rect.x = item->x - focus_width;
3180 rect.y = item->y - focus_width;
3181 rect.width = item->width + 2 * focus_width;
3182 rect.height = item->height + 2 * focus_width;
3184 if (icon_view->priv->bin_window)
3185 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3189 layout_callback (gpointer user_data)
3191 GtkIconView *icon_view;
3193 icon_view = GTK_ICON_VIEW (user_data);
3195 icon_view->priv->layout_idle_id = 0;
3197 gtk_icon_view_layout (icon_view);
3203 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3205 if (icon_view->priv->layout_idle_id != 0)
3208 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3212 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3213 GtkIconViewItem *item,
3217 AtkObject *item_obj;
3219 if (icon_view->priv->cursor_item == item &&
3220 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3223 if (icon_view->priv->cursor_item != NULL)
3224 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3226 icon_view->priv->cursor_item = item;
3227 if (cursor_cell >= 0)
3228 icon_view->priv->cursor_cell = cursor_cell;
3230 gtk_icon_view_queue_draw_item (icon_view, item);
3232 /* Notify that accessible focus object has changed */
3233 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3234 item_obj = atk_object_ref_accessible_child (obj, item->index);
3236 if (item_obj != NULL)
3238 atk_focus_tracker_notify (item_obj);
3239 g_object_unref (item_obj);
3244 static GtkIconViewItem *
3245 gtk_icon_view_item_new (void)
3247 GtkIconViewItem *item;
3249 item = g_new0 (GtkIconViewItem, 1);
3258 gtk_icon_view_item_free (GtkIconViewItem *item)
3260 g_return_if_fail (item != NULL);
3262 g_free (item->before);
3263 g_free (item->after);
3270 static GtkIconViewItem *
3271 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3274 gboolean only_in_cell,
3275 GtkIconViewCellInfo **cell_at_pos)
3280 for (items = icon_view->priv->items; items; items = items->next)
3282 GtkIconViewItem *item = items->data;
3284 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3285 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3287 if (only_in_cell || cell_at_pos)
3289 gtk_icon_view_set_cell_data (icon_view, item);
3291 for (l = icon_view->priv->cell_list; l; l = l->next)
3293 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3295 if (!info->cell->visible)
3298 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3300 if ((x >= box.x && x <= box.x + box.width &&
3301 y >= box.y && y <= box.y + box.height) ||
3303 x <= box.x + box.width &&
3305 y <= box.y + box.height))
3308 *cell_at_pos = info;
3318 *cell_at_pos = NULL;
3329 gtk_icon_view_select_item (GtkIconView *icon_view,
3330 GtkIconViewItem *item)
3332 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3333 g_return_if_fail (item != NULL);
3338 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3340 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3341 gtk_icon_view_unselect_all_internal (icon_view);
3343 item->selected = TRUE;
3345 gtk_icon_view_queue_draw_item (icon_view, item);
3347 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3352 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3353 GtkIconViewItem *item)
3355 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3356 g_return_if_fail (item != NULL);
3358 if (!item->selected)
3361 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3362 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3365 item->selected = FALSE;
3367 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3369 gtk_icon_view_queue_draw_item (icon_view, item);
3373 verify_items (GtkIconView *icon_view)
3378 for (items = icon_view->priv->items; items; items = items->next)
3380 GtkIconViewItem *item = items->data;
3382 if (item->index != i)
3383 g_error ("List item does not match its index: "
3384 "item index %d and list index %d\n", item->index, i);
3391 gtk_icon_view_row_changed (GtkTreeModel *model,
3396 GtkIconViewItem *item;
3398 GtkIconView *icon_view;
3400 icon_view = GTK_ICON_VIEW (data);
3402 gtk_icon_view_stop_editing (icon_view, TRUE);
3404 index = gtk_tree_path_get_indices(path)[0];
3405 item = g_list_nth_data (icon_view->priv->items, index);
3407 gtk_icon_view_item_invalidate_size (item);
3408 gtk_icon_view_queue_layout (icon_view);
3410 verify_items (icon_view);
3414 gtk_icon_view_row_inserted (GtkTreeModel *model,
3420 GtkIconViewItem *item;
3421 gboolean iters_persist;
3422 GtkIconView *icon_view;
3425 icon_view = GTK_ICON_VIEW (data);
3427 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3429 index = gtk_tree_path_get_indices(path)[0];
3431 item = gtk_icon_view_item_new ();
3436 item->index = index;
3438 /* FIXME: We can be more efficient here,
3439 we can store a tail pointer and use that when
3440 appending (which is a rather common operation)
3442 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3445 list = g_list_nth (icon_view->priv->items, index + 1);
3446 for (; list; list = list->next)
3453 verify_items (icon_view);
3455 gtk_icon_view_queue_layout (icon_view);
3459 gtk_icon_view_row_deleted (GtkTreeModel *model,
3464 GtkIconView *icon_view;
3465 GtkIconViewItem *item;
3467 gboolean emit = FALSE;
3469 icon_view = GTK_ICON_VIEW (data);
3471 index = gtk_tree_path_get_indices(path)[0];
3473 list = g_list_nth (icon_view->priv->items, index);
3476 gtk_icon_view_stop_editing (icon_view, TRUE);
3478 if (item == icon_view->priv->anchor_item)
3479 icon_view->priv->anchor_item = NULL;
3481 if (item == icon_view->priv->cursor_item)
3482 icon_view->priv->cursor_item = NULL;
3487 gtk_icon_view_item_free (item);
3489 for (next = list->next; next; next = next->next)
3496 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3498 verify_items (icon_view);
3500 gtk_icon_view_queue_layout (icon_view);
3503 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3507 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3508 GtkTreePath *parent,
3515 GtkIconView *icon_view;
3516 GList *items = NULL, *list;
3517 GtkIconViewItem **item_array;
3520 icon_view = GTK_ICON_VIEW (data);
3522 gtk_icon_view_stop_editing (icon_view, TRUE);
3524 length = gtk_tree_model_iter_n_children (model, NULL);
3526 order = g_new (gint, length);
3527 for (i = 0; i < length; i++)
3528 order [new_order[i]] = i;
3530 item_array = g_new (GtkIconViewItem *, length);
3531 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3532 item_array[order[i]] = list->data;
3535 for (i = length - 1; i >= 0; i--)
3537 item_array[i]->index = i;
3538 items = g_list_prepend (items, item_array[i]);
3541 g_free (item_array);
3542 g_list_free (icon_view->priv->items);
3543 icon_view->priv->items = items;
3545 gtk_icon_view_queue_layout (icon_view);
3547 verify_items (icon_view);
3551 gtk_icon_view_build_items (GtkIconView *icon_view)
3555 gboolean iters_persist;
3556 GList *items = NULL;
3558 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3560 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3568 GtkIconViewItem *item = gtk_icon_view_item_new ();
3577 items = g_list_prepend (items, item);
3579 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3581 icon_view->priv->items = g_list_reverse (items);
3585 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3588 GtkMovementStep step,
3592 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3593 I_("move_cursor"), 2,
3597 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3602 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3605 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3610 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3617 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3618 GtkMovementStep step,
3621 GdkModifierType state;
3623 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3624 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3625 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3626 step == GTK_MOVEMENT_DISPLAY_LINES ||
3627 step == GTK_MOVEMENT_PAGES ||
3628 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3630 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3633 gtk_icon_view_stop_editing (icon_view, FALSE);
3634 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3636 if (gtk_get_current_event_state (&state))
3638 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3639 icon_view->priv->ctrl_pressed = TRUE;
3640 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3641 icon_view->priv->shift_pressed = TRUE;
3643 /* else we assume not pressed */
3647 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3648 case GTK_MOVEMENT_VISUAL_POSITIONS:
3649 gtk_icon_view_move_cursor_left_right (icon_view, count);
3651 case GTK_MOVEMENT_DISPLAY_LINES:
3652 gtk_icon_view_move_cursor_up_down (icon_view, count);
3654 case GTK_MOVEMENT_PAGES:
3655 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3657 case GTK_MOVEMENT_BUFFER_ENDS:
3658 gtk_icon_view_move_cursor_start_end (icon_view, count);
3661 g_assert_not_reached ();
3664 icon_view->priv->ctrl_pressed = FALSE;
3665 icon_view->priv->shift_pressed = FALSE;
3670 static GtkIconViewItem *
3671 find_item (GtkIconView *icon_view,
3672 GtkIconViewItem *current,
3678 GtkIconViewItem *item;
3680 /* FIXME: this could be more efficient
3682 row = current->row + row_ofs;
3683 col = current->col + col_ofs;
3685 for (items = icon_view->priv->items; items; items = items->next)
3688 if (item->row == row && item->col == col)
3696 find_cell (GtkIconView *icon_view,
3697 GtkIconViewItem *item,
3699 GtkOrientation orientation,
3710 if (icon_view->priv->orientation != orientation)
3713 gtk_icon_view_set_cell_data (icon_view, item);
3715 focusable = g_new0 (gint, icon_view->priv->n_cells);
3720 for (k = 0; k < 2; k++)
3721 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3723 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3725 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3728 if (!info->cell->visible)
3731 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3734 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3737 current = n_focusable;
3739 focusable[n_focusable] = i;
3745 if (n_focusable == 0)
3746 focusable[n_focusable++] = first_text;
3750 current = step > 0 ? 0 : n_focusable - 1;
3751 cell = focusable[current];
3754 if (current + *count < 0)
3757 *count = current + *count;
3759 else if (current + *count > n_focusable - 1)
3762 *count = current + *count - (n_focusable - 1);
3766 cell = focusable[current + *count];
3775 static GtkIconViewItem *
3776 find_item_page_up_down (GtkIconView *icon_view,
3777 GtkIconViewItem *current,
3784 y = current->y + count * icon_view->priv->vadjustment->page_size;
3786 item = g_list_find (icon_view->priv->items, current);
3791 for (next = item->next; next; next = next->next)
3793 if (((GtkIconViewItem *)next->data)->col == col)
3796 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3806 for (next = item->prev; next; next = next->prev)
3808 if (((GtkIconViewItem *)next->data)->col == col)
3811 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3825 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3826 GtkIconViewItem *anchor,
3827 GtkIconViewItem *cursor)
3830 GtkIconViewItem *item;
3831 gint row1, row2, col1, col2;
3832 gboolean dirty = FALSE;
3834 if (anchor->row < cursor->row)
3845 if (anchor->col < cursor->col)
3856 for (items = icon_view->priv->items; items; items = items->next)
3860 if (row1 <= item->row && item->row <= row2 &&
3861 col1 <= item->col && item->col <= col2)
3863 if (!item->selected)
3866 item->selected = TRUE;
3868 gtk_icon_view_queue_draw_item (icon_view, item);
3876 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3879 GtkIconViewItem *item;
3881 gboolean dirty = FALSE;
3884 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3887 if (!icon_view->priv->cursor_item)
3892 list = icon_view->priv->items;
3894 list = g_list_last (icon_view->priv->items);
3896 item = list ? list->data : NULL;
3901 item = icon_view->priv->cursor_item;
3902 cell = icon_view->priv->cursor_cell;
3903 step = count > 0 ? 1 : -1;
3906 cell = find_cell (icon_view, item, cell,
3907 GTK_ORIENTATION_VERTICAL,
3912 item = find_item (icon_view, item, step, 0);
3913 count = count - step;
3919 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3923 if (icon_view->priv->ctrl_pressed ||
3924 !icon_view->priv->shift_pressed ||
3925 !icon_view->priv->anchor_item ||
3926 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3927 icon_view->priv->anchor_item = item;
3929 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3931 if (!icon_view->priv->ctrl_pressed &&
3932 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3934 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3935 dirty = gtk_icon_view_select_all_between (icon_view,
3936 icon_view->priv->anchor_item,
3940 gtk_icon_view_scroll_to_item (icon_view, item);
3943 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3947 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3950 GtkIconViewItem *item;
3951 gboolean dirty = FALSE;
3953 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3956 if (!icon_view->priv->cursor_item)
3961 list = icon_view->priv->items;
3963 list = g_list_last (icon_view->priv->items);
3965 item = list ? list->data : NULL;
3968 item = find_item_page_up_down (icon_view,
3969 icon_view->priv->cursor_item,
3972 if (item == icon_view->priv->cursor_item)
3973 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3978 if (icon_view->priv->ctrl_pressed ||
3979 !icon_view->priv->shift_pressed ||
3980 !icon_view->priv->anchor_item ||
3981 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3982 icon_view->priv->anchor_item = item;
3984 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3986 if (!icon_view->priv->ctrl_pressed &&
3987 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3989 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3990 dirty = gtk_icon_view_select_all_between (icon_view,
3991 icon_view->priv->anchor_item,
3995 gtk_icon_view_scroll_to_item (icon_view, item);
3998 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4002 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
4005 GtkIconViewItem *item;
4007 gboolean dirty = FALSE;
4010 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4013 if (!icon_view->priv->cursor_item)
4018 list = icon_view->priv->items;
4020 list = g_list_last (icon_view->priv->items);
4022 item = list ? list->data : NULL;
4026 item = icon_view->priv->cursor_item;
4027 cell = icon_view->priv->cursor_cell;
4028 step = count > 0 ? 1 : -1;
4031 cell = find_cell (icon_view, item, cell,
4032 GTK_ORIENTATION_HORIZONTAL,
4037 item = find_item (icon_view, item, 0, step);
4038 count = count - step;
4044 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4048 if (icon_view->priv->ctrl_pressed ||
4049 !icon_view->priv->shift_pressed ||
4050 !icon_view->priv->anchor_item ||
4051 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4052 icon_view->priv->anchor_item = item;
4054 gtk_icon_view_set_cursor_item (icon_view, item, cell);
4056 if (!icon_view->priv->ctrl_pressed &&
4057 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4059 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4060 dirty = gtk_icon_view_select_all_between (icon_view,
4061 icon_view->priv->anchor_item,
4065 gtk_icon_view_scroll_to_item (icon_view, item);
4068 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4072 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4075 GtkIconViewItem *item;
4077 gboolean dirty = FALSE;
4079 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4083 list = icon_view->priv->items;
4085 list = g_list_last (icon_view->priv->items);
4087 item = list ? list->data : NULL;
4089 if (item == icon_view->priv->cursor_item)
4090 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4095 if (icon_view->priv->ctrl_pressed ||
4096 !icon_view->priv->shift_pressed ||
4097 !icon_view->priv->anchor_item ||
4098 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4099 icon_view->priv->anchor_item = item;
4101 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4103 if (!icon_view->priv->ctrl_pressed &&
4104 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4106 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4107 dirty = gtk_icon_view_select_all_between (icon_view,
4108 icon_view->priv->anchor_item,
4112 gtk_icon_view_scroll_to_item (icon_view, item);
4115 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4119 * gtk_icon_view_scroll_to_path:
4120 * @icon_view: A #GtkIconView.
4121 * @path: The path of the item to move to.
4122 * @use_align: whether to use alignment arguments, or %FALSE.
4123 * @row_align: The vertical alignment of the item specified by @path.
4124 * @col_align: The horizontal alignment of the item specified by @path.
4126 * Moves the alignments of @icon_view to the position specified by @path.
4127 * @row_align determines where the row is placed, and @col_align determines
4128 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4129 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4132 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4133 * tree does the minimum amount of work to scroll the item onto the screen.
4134 * This means that the item will be scrolled to the edge closest to its current
4135 * position. If the item is currently visible on the screen, nothing is done.
4137 * This function only works if the model is set, and @path is a valid row on
4138 * the model. If the model changes before the @icon_view is realized, the
4139 * centered path will be modified to reflect this change.
4144 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4150 GtkIconViewItem *item = NULL;
4152 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4153 g_return_if_fail (path != NULL);
4154 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4155 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4157 if (gtk_tree_path_get_depth (path) > 0)
4158 item = g_list_nth_data (icon_view->priv->items,
4159 gtk_tree_path_get_indices(path)[0]);
4161 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4163 if (icon_view->priv->scroll_to_path)
4164 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4166 icon_view->priv->scroll_to_path = NULL;
4169 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4171 icon_view->priv->scroll_to_use_align = use_align;
4172 icon_view->priv->scroll_to_row_align = row_align;
4173 icon_view->priv->scroll_to_col_align = col_align;
4182 gfloat offset, value;
4184 gtk_widget_style_get (GTK_WIDGET (icon_view),
4185 "focus-line-width", &focus_width,
4188 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4190 offset = y + item->y - focus_width -
4191 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4192 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4193 icon_view->priv->vadjustment->lower,
4194 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4195 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4197 offset = x + item->x - focus_width -
4198 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4199 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4200 icon_view->priv->hadjustment->lower,
4201 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4202 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4204 gtk_adjustment_changed (icon_view->priv->hadjustment);
4205 gtk_adjustment_changed (icon_view->priv->vadjustment);
4208 gtk_icon_view_scroll_to_item (icon_view, item);
4213 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4214 GtkIconViewItem *item)
4216 gint x, y, width, height;
4219 gtk_widget_style_get (GTK_WIDGET (icon_view),
4220 "focus-line-width", &focus_width,
4223 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4225 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4227 if (y + item->y - focus_width < 0)
4228 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4229 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4230 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4231 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4232 icon_view->priv->vadjustment->value + y + item->y + item->height
4233 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4235 if (x + item->x - focus_width < 0)
4236 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4237 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4238 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4239 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4240 icon_view->priv->hadjustment->value + x + item->x + item->width
4241 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4243 gtk_adjustment_changed (icon_view->priv->hadjustment);
4244 gtk_adjustment_changed (icon_view->priv->vadjustment);
4247 /* GtkCellLayout implementation */
4248 static GtkIconViewCellInfo *
4249 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4250 GtkCellRenderer *renderer)
4254 for (i = icon_view->priv->cell_list; i; i = i->next)
4256 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4258 if (info->cell == renderer)
4266 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4267 GtkIconViewItem *item)
4270 gboolean iters_persist;
4273 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4279 path = gtk_tree_path_new_from_indices (item->index, -1);
4280 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4282 gtk_tree_path_free (path);
4287 for (i = icon_view->priv->cell_list; i; i = i->next)
4290 GtkIconViewCellInfo *info = i->data;
4292 g_object_freeze_notify (G_OBJECT (info->cell));
4294 for (j = info->attributes; j && j->next; j = j->next->next)
4296 gchar *property = j->data;
4297 gint column = GPOINTER_TO_INT (j->next->data);
4298 GValue value = {0, };
4300 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4302 g_object_set_property (G_OBJECT (info->cell),
4304 g_value_unset (&value);
4308 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4310 icon_view->priv->model,
4314 g_object_thaw_notify (G_OBJECT (info->cell));
4319 free_cell_attributes (GtkIconViewCellInfo *info)
4323 list = info->attributes;
4324 while (list && list->next)
4326 g_free (list->data);
4327 list = list->next->next;
4330 g_slist_free (info->attributes);
4331 info->attributes = NULL;
4335 free_cell_info (GtkIconViewCellInfo *info)
4337 free_cell_attributes (info);
4339 g_object_unref (info->cell);
4342 (* info->destroy) (info->func_data);
4348 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4349 GtkCellRenderer *renderer,
4352 GtkIconViewCellInfo *info;
4353 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4355 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4356 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4358 g_object_ref_sink (renderer);
4360 info = g_new0 (GtkIconViewCellInfo, 1);
4361 info->cell = renderer;
4362 info->expand = expand ? TRUE : FALSE;
4363 info->pack = GTK_PACK_START;
4364 info->position = icon_view->priv->n_cells;
4366 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4367 icon_view->priv->n_cells++;
4371 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4372 GtkCellRenderer *renderer,
4375 GtkIconViewCellInfo *info;
4376 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4378 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4379 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4381 g_object_ref_sink (renderer);
4383 info = g_new0 (GtkIconViewCellInfo, 1);
4384 info->cell = renderer;
4385 info->expand = expand ? TRUE : FALSE;
4386 info->pack = GTK_PACK_END;
4387 info->position = icon_view->priv->n_cells;
4389 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4390 icon_view->priv->n_cells++;
4394 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4395 GtkCellRenderer *renderer,
4396 const gchar *attribute,
4399 GtkIconViewCellInfo *info;
4400 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4402 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4403 g_return_if_fail (info != NULL);
4405 info->attributes = g_slist_prepend (info->attributes,
4406 GINT_TO_POINTER (column));
4407 info->attributes = g_slist_prepend (info->attributes,
4408 g_strdup (attribute));
4412 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4414 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4416 while (icon_view->priv->cell_list)
4418 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4419 free_cell_info (info);
4420 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4421 icon_view->priv->cell_list);
4424 icon_view->priv->n_cells = 0;
4428 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4429 GtkCellRenderer *cell,
4430 GtkCellLayoutDataFunc func,
4432 GDestroyNotify destroy)
4434 GtkIconViewCellInfo *info;
4435 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4437 info = gtk_icon_view_get_cell_info (icon_view, cell);
4438 g_return_if_fail (info != NULL);
4442 GDestroyNotify d = info->destroy;
4444 info->destroy = NULL;
4445 d (info->func_data);
4449 info->func_data = func_data;
4450 info->destroy = destroy;
4454 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4455 GtkCellRenderer *renderer)
4457 GtkIconViewCellInfo *info;
4459 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4461 free_cell_attributes (info);
4465 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4466 GtkCellRenderer *cell,
4469 GtkIconView *icon_view;
4471 GtkIconViewCellInfo *info;
4474 icon_view = GTK_ICON_VIEW (layout);
4476 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4478 info = gtk_icon_view_get_cell_info (icon_view, cell);
4480 g_return_if_fail (info != NULL);
4481 g_return_if_fail (position >= 0);
4483 link = g_list_find (icon_view->priv->cell_list, info);
4485 g_return_if_fail (link != NULL);
4487 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4489 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4492 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4499 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4503 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4505 GtkIconView *icon_view = (GtkIconView *)layout;
4506 GList *retval = NULL, *l;
4508 for (l = icon_view->priv->cell_list; l; l = l->next)
4510 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4512 retval = g_list_prepend (retval, info->cell);
4515 return g_list_reverse (retval);
4522 * gtk_icon_view_new:
4524 * Creates a new #GtkIconView widget
4526 * Return value: A newly created #GtkIconView widget
4531 gtk_icon_view_new (void)
4533 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4537 * gtk_icon_view_new_with_model:
4538 * @model: The model.
4540 * Creates a new #GtkIconView widget with the model @model.
4542 * Return value: A newly created #GtkIconView widget.
4547 gtk_icon_view_new_with_model (GtkTreeModel *model)
4549 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4553 * gtk_icon_view_convert_widget_to_bin_window_coords:
4554 * @wx: X coordinate relative to the widget
4555 * @wy: Y coordinate relative to the widget
4556 * @bx: return location for bin_window X coordinate
4557 * @by: return location for bin_window Y coordinate
4559 * Converts widget coordinates to coordinates for the bin_window,
4560 * as expected by e.g. gtk_icon_view_get_path_at_pos().
4565 gtk_icon_view_convert_widget_to_bin_window_coords (GtkIconView *icon_view,
4573 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4575 if (icon_view->priv->bin_window)
4576 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4587 * gtk_icon_view_get_path_at_pos:
4588 * @icon_view: A #GtkIconView.
4589 * @x: The x position to be identified
4590 * @y: The y position to be identified
4592 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4593 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4594 * the cell at the specified position.
4595 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4596 * widget coordinates to bin_window coordinates.
4598 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4599 * if no icon exists at that position.
4604 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4608 GtkIconViewItem *item;
4611 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4613 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4618 path = gtk_tree_path_new_from_indices (item->index, -1);
4624 * gtk_icon_view_get_item_at_pos:
4625 * @icon_view: A #GtkIconView.
4626 * @x: The x position to be identified
4627 * @y: The y position to be identified
4628 * @path: Return location for the path, or %NULL
4629 * @cell: Return location for the renderer responsible for the cell
4630 * at (@x, @y), or %NULL
4632 * Finds the path at the point (@x, @y), relative to bin_window coordinates.
4633 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4634 * obtains the cell at the specified position. The returned path should
4635 * be freed with gtk_tree_path_free().
4636 * See gtk_icon_view_convert_widget_to_bin_window_coords() for converting
4637 * widget coordinates to bin_window coordinates.
4639 * Return value: %TRUE if an item exists at the specified position
4644 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4648 GtkCellRenderer **cell)
4650 GtkIconViewItem *item;
4651 GtkIconViewCellInfo *info;
4653 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4655 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4660 *path = gtk_tree_path_new_from_indices (item->index, -1);
4673 return (item != NULL);
4677 * gtk_icon_view_set_tooltip_item:
4678 * @icon_view: a #GtkIconView
4679 * @tooltip: a #GtkTooltip
4680 * @path: a #GtkTreePath
4682 * Sets the tip area of @tooltip to be the area covered by the item at @path.
4683 * See also gtk_tooltip_set_tip_area().
4688 gtk_icon_view_set_tooltip_item (GtkIconView *icon_view,
4689 GtkTooltip *tooltip,
4692 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4693 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4695 gtk_icon_view_set_tooltip_cell (icon_view, tooltip, path, NULL);
4699 * gtk_icon_view_set_tooltip_cell:
4700 * @icon_view: a #GtkIconView
4701 * @tooltip: a #GtkTooltip
4702 * @path: a #GtkTreePath
4703 * @cell: a #GtkCellRenderer or %NULL
4705 * Sets the tip area of @tooltip to the area which @cell occupies in
4706 * the item pointed to by @path. See also gtk_tooltip_set_tip_area().
4711 gtk_icon_view_set_tooltip_cell (GtkIconView *icon_view,
4712 GtkTooltip *tooltip,
4714 GtkCellRenderer *cell)
4717 GtkIconViewItem *item = NULL;
4718 GtkIconViewCellInfo *info = NULL;
4721 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4722 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
4723 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
4725 if (gtk_tree_path_get_depth (path) > 0)
4726 item = g_list_nth_data (icon_view->priv->items,
4727 gtk_tree_path_get_indices(path)[0]);
4734 info = gtk_icon_view_get_cell_info (icon_view, cell);
4735 gtk_icon_view_get_cell_area (icon_view, item, info, &rect);
4741 rect.width = item->width;
4742 rect.height = item->height;
4745 if (icon_view->priv->bin_window)
4747 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4752 gtk_tooltip_set_tip_area (tooltip, &rect);
4757 * gtk_icon_view_get_tooltip_context:
4758 * @icon_view: an #GtkIconView
4759 * @x: the x coordinate (relative to widget coordinates)
4760 * @y: the y coordinate (relative to widget coordinates)
4761 * @keyboard_tip: whether this is a keyboard tooltip or not
4762 * @model: a pointer to receive a #GtkTreeModel or %NULL
4763 * @path: a pointer to receive a #GtkTreePath or %NULL
4764 * @iter: a pointer to receive a #GtkTreeIter or %NULL
4766 * This function is supposed to be used in a #GtkWidget::query-tooltip
4767 * signal handler for #GtkIconView. The @x, @y and @keyboard_tip values
4768 * which are received in the signal handler, should be passed to this
4769 * function without modification.
4771 * The return value indicates whether there is an icon view item at the given
4772 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
4773 * tooltips the item returned will be the cursor item. When %TRUE, then any of
4774 * @model, @path and @iter which have been provided will be set to point to
4775 * that row and the corresponding model. @x and @y will always be converted
4776 * to be relative to @icon_view's bin_window if @keyboard_tooltip is %FALSE.
4778 * Return value: whether or not the given tooltip context points to a item
4783 gtk_icon_view_get_tooltip_context (GtkIconView *icon_view,
4786 gboolean keyboard_tip,
4787 GtkTreeModel **model,
4791 GtkTreePath *tmppath = NULL;
4793 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4794 g_return_val_if_fail (x != NULL, FALSE);
4795 g_return_val_if_fail (y != NULL, FALSE);
4799 gtk_icon_view_get_cursor (icon_view, &tmppath, NULL);
4806 gtk_icon_view_convert_widget_to_bin_window_coords (icon_view, *x, *y,
4809 if (!gtk_icon_view_get_item_at_pos (icon_view, *x, *y, &tmppath, NULL))
4814 *model = gtk_icon_view_get_model (icon_view);
4817 gtk_tree_model_get_iter (gtk_icon_view_get_model (icon_view),
4823 gtk_tree_path_free (tmppath);
4829 gtk_icon_view_set_tooltip_query_cb (GtkWidget *widget,
4832 gboolean keyboard_tip,
4833 GtkTooltip *tooltip,
4839 GtkTreeModel *model;
4840 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
4842 if (!gtk_icon_view_get_tooltip_context (GTK_ICON_VIEW (widget),
4845 &model, &path, &iter))
4848 gtk_tree_model_get (model, &iter, icon_view->priv->tooltip_column, &str, -1);
4852 gtk_tree_path_free (path);
4856 gtk_tooltip_set_markup (tooltip, str);
4857 gtk_icon_view_set_tooltip_item (icon_view, tooltip, path);
4859 gtk_tree_path_free (path);
4867 * gtk_icon_view_set_tooltip_column:
4868 * @icon_view: a #GtkIconView
4870 * @column: an integer, which is a valid column number for @icon_view's model
4872 * If you only plan to have simple (text-only) tooltips on full items, you
4873 * can use this function to have #GtkIconView handle these automatically
4874 * for you. @column should be set to the column in @icon_view's model
4875 * containing the tooltip texts, or -1 to disable this feature.
4877 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
4878 * @icon_view will connect a #GtkWidget::query-tooltip signal handler.
4883 gtk_icon_view_set_tooltip_column (GtkIconView *icon_view,
4886 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4888 if (column == icon_view->priv->tooltip_column)
4893 g_signal_handlers_disconnect_by_func (icon_view,
4894 gtk_icon_view_set_tooltip_query_cb,
4896 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), FALSE);
4900 if (icon_view->priv->tooltip_column == -1)
4902 g_signal_connect (icon_view, "query-tooltip",
4903 G_CALLBACK (gtk_icon_view_set_tooltip_query_cb), NULL);
4904 gtk_widget_set_has_tooltip (GTK_WIDGET (icon_view), TRUE);
4908 icon_view->priv->tooltip_column = column;
4909 g_object_notify (G_OBJECT (icon_view), "tooltip-column");
4913 * gtk_icon_view_get_tooltip_column:
4914 * @icon_view: a #GtkIconView
4916 * Returns the column of @icon_view's model which is being used for
4917 * displaying tooltips on @icon_view's rows.
4919 * Return value: the index of the tooltip column that is currently being
4920 * used, or -1 if this is disabled.
4925 gtk_icon_view_get_tooltip_column (GtkIconView *icon_view)
4927 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), 0);
4929 return icon_view->priv->tooltip_column;
4933 * gtk_icon_view_get_visible_range:
4934 * @icon_view: A #GtkIconView
4935 * @start_path: Return location for start of region, or %NULL
4936 * @end_path: Return location for end of region, or %NULL
4938 * Sets @start_path and @end_path to be the first and last visible path.
4939 * Note that there may be invisible paths in between.
4941 * Both paths should be freed with gtk_tree_path_free() after use.
4943 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4948 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4949 GtkTreePath **start_path,
4950 GtkTreePath **end_path)
4952 gint start_index = -1;
4953 gint end_index = -1;
4956 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4958 if (icon_view->priv->hadjustment == NULL ||
4959 icon_view->priv->vadjustment == NULL)
4962 if (start_path == NULL && end_path == NULL)
4965 for (icons = icon_view->priv->items; icons; icons = icons->next)
4967 GtkIconViewItem *item = icons->data;
4969 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4970 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4971 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4972 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4974 if (start_index == -1)
4975 start_index = item->index;
4976 end_index = item->index;
4980 if (start_path && start_index != -1)
4981 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4982 if (end_path && end_index != -1)
4983 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4985 return start_index != -1;
4989 * gtk_icon_view_selected_foreach:
4990 * @icon_view: A #GtkIconView.
4991 * @func: The funcion to call for each selected icon.
4992 * @data: User data to pass to the function.
4994 * Calls a function for each selected icon. Note that the model or
4995 * selection cannot be modified from within this function.
5000 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
5001 GtkIconViewForeachFunc func,
5006 for (list = icon_view->priv->items; list; list = list->next)
5008 GtkIconViewItem *item = list->data;
5009 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5012 (* func) (icon_view, path, data);
5014 gtk_tree_path_free (path);
5019 * gtk_icon_view_set_selection_mode:
5020 * @icon_view: A #GtkIconView.
5021 * @mode: The selection mode
5023 * Sets the selection mode of the @icon_view.
5028 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
5029 GtkSelectionMode mode)
5031 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5033 if (mode == icon_view->priv->selection_mode)
5036 if (mode == GTK_SELECTION_NONE ||
5037 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
5038 gtk_icon_view_unselect_all (icon_view);
5040 icon_view->priv->selection_mode = mode;
5042 g_object_notify (G_OBJECT (icon_view), "selection-mode");
5046 * gtk_icon_view_get_selection_mode:
5047 * @icon_view: A #GtkIconView.
5049 * Gets the selection mode of the @icon_view.
5051 * Return value: the current selection mode
5056 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
5058 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
5060 return icon_view->priv->selection_mode;
5064 * gtk_icon_view_set_model:
5065 * @icon_view: A #GtkIconView.
5066 * @model: The model.
5068 * Sets the model for a #GtkIconView.
5069 * If the @icon_view already has a model set, it will remove
5070 * it before setting the new model. If @model is %NULL, then
5071 * it will unset the old model.
5076 gtk_icon_view_set_model (GtkIconView *icon_view,
5077 GtkTreeModel *model)
5079 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5080 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
5082 if (icon_view->priv->model == model)
5085 if (icon_view->priv->scroll_to_path)
5087 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
5088 icon_view->priv->scroll_to_path = NULL;
5091 gtk_icon_view_stop_editing (icon_view, TRUE);
5097 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
5099 if (icon_view->priv->pixbuf_column != -1)
5101 column_type = gtk_tree_model_get_column_type (model,
5102 icon_view->priv->pixbuf_column);
5104 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5107 if (icon_view->priv->text_column != -1)
5109 column_type = gtk_tree_model_get_column_type (model,
5110 icon_view->priv->text_column);
5112 g_return_if_fail (column_type == G_TYPE_STRING);
5115 if (icon_view->priv->markup_column != -1)
5117 column_type = gtk_tree_model_get_column_type (model,
5118 icon_view->priv->markup_column);
5120 g_return_if_fail (column_type == G_TYPE_STRING);
5125 if (icon_view->priv->model)
5127 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5128 gtk_icon_view_row_changed,
5130 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5131 gtk_icon_view_row_inserted,
5133 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5134 gtk_icon_view_row_deleted,
5136 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
5137 gtk_icon_view_rows_reordered,
5140 g_object_unref (icon_view->priv->model);
5142 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
5143 g_list_free (icon_view->priv->items);
5144 icon_view->priv->items = NULL;
5145 icon_view->priv->anchor_item = NULL;
5146 icon_view->priv->cursor_item = NULL;
5147 icon_view->priv->last_single_clicked = NULL;
5148 icon_view->priv->width = 0;
5149 icon_view->priv->height = 0;
5152 icon_view->priv->model = model;
5154 if (icon_view->priv->model)
5156 g_object_ref (icon_view->priv->model);
5157 g_signal_connect (icon_view->priv->model,
5159 G_CALLBACK (gtk_icon_view_row_changed),
5161 g_signal_connect (icon_view->priv->model,
5163 G_CALLBACK (gtk_icon_view_row_inserted),
5165 g_signal_connect (icon_view->priv->model,
5167 G_CALLBACK (gtk_icon_view_row_deleted),
5169 g_signal_connect (icon_view->priv->model,
5171 G_CALLBACK (gtk_icon_view_rows_reordered),
5174 gtk_icon_view_build_items (icon_view);
5176 gtk_icon_view_queue_layout (icon_view);
5179 g_object_notify (G_OBJECT (icon_view), "model");
5181 if (GTK_WIDGET_REALIZED (icon_view))
5182 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
5186 * gtk_icon_view_get_model:
5187 * @icon_view: a #GtkIconView
5189 * Returns the model the #GtkIconView is based on. Returns %NULL if the
5192 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
5197 gtk_icon_view_get_model (GtkIconView *icon_view)
5199 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5201 return icon_view->priv->model;
5205 update_text_cell (GtkIconView *icon_view)
5207 GtkIconViewCellInfo *info;
5211 if (icon_view->priv->text_column == -1 &&
5212 icon_view->priv->markup_column == -1)
5214 if (icon_view->priv->text_cell != -1)
5216 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
5217 icon_view->priv->pixbuf_cell--;
5219 info = g_list_nth_data (icon_view->priv->cell_list,
5220 icon_view->priv->text_cell);
5222 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5224 free_cell_info (info);
5226 icon_view->priv->n_cells--;
5227 icon_view->priv->text_cell = -1;
5232 if (icon_view->priv->text_cell == -1)
5234 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
5235 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5236 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5239 if (info->cell == cell)
5241 icon_view->priv->text_cell = i;
5247 info = g_list_nth_data (icon_view->priv->cell_list,
5248 icon_view->priv->text_cell);
5250 if (icon_view->priv->markup_column != -1)
5251 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5253 "markup", icon_view->priv->markup_column,
5256 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5258 "text", icon_view->priv->text_column,
5261 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5262 g_object_set (info->cell,
5263 "alignment", PANGO_ALIGN_CENTER,
5264 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5269 g_object_set (info->cell,
5270 "alignment", PANGO_ALIGN_LEFT,
5271 "wrap-mode", PANGO_WRAP_WORD_CHAR,
5279 update_pixbuf_cell (GtkIconView *icon_view)
5281 GtkIconViewCellInfo *info;
5285 if (icon_view->priv->pixbuf_column == -1)
5287 if (icon_view->priv->pixbuf_cell != -1)
5289 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
5290 icon_view->priv->text_cell--;
5292 info = g_list_nth_data (icon_view->priv->cell_list,
5293 icon_view->priv->pixbuf_cell);
5295 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
5297 free_cell_info (info);
5299 icon_view->priv->n_cells--;
5300 icon_view->priv->pixbuf_cell = -1;
5305 if (icon_view->priv->pixbuf_cell == -1)
5307 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
5309 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
5310 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
5313 if (info->cell == cell)
5315 icon_view->priv->pixbuf_cell = i;
5321 info = g_list_nth_data (icon_view->priv->cell_list,
5322 icon_view->priv->pixbuf_cell);
5324 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
5326 "pixbuf", icon_view->priv->pixbuf_column,
5329 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
5330 g_object_set (info->cell,
5331 "follow-state", TRUE,
5336 g_object_set (info->cell,
5337 "follow-state", TRUE,
5345 * gtk_icon_view_set_text_column:
5346 * @icon_view: A #GtkIconView.
5347 * @column: A column in the currently used model, or -1 to display no text
5349 * Sets the column with text for @icon_view to be @column. The text
5350 * column must be of type #G_TYPE_STRING.
5355 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5358 if (column == icon_view->priv->text_column)
5362 icon_view->priv->text_column = -1;
5365 if (icon_view->priv->model != NULL)
5369 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5371 g_return_if_fail (column_type == G_TYPE_STRING);
5374 icon_view->priv->text_column = column;
5377 gtk_icon_view_stop_editing (icon_view, TRUE);
5379 update_text_cell (icon_view);
5381 gtk_icon_view_invalidate_sizes (icon_view);
5382 gtk_icon_view_queue_layout (icon_view);
5384 g_object_notify (G_OBJECT (icon_view), "text-column");
5388 * gtk_icon_view_get_text_column:
5389 * @icon_view: A #GtkIconView.
5391 * Returns the column with text for @icon_view.
5393 * Returns: the text column, or -1 if it's unset.
5398 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5400 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5402 return icon_view->priv->text_column;
5406 * gtk_icon_view_set_markup_column:
5407 * @icon_view: A #GtkIconView.
5408 * @column: A column in the currently used model, or -1 to display no text
5410 * Sets the column with markup information for @icon_view to be
5411 * @column. The markup column must be of type #G_TYPE_STRING.
5412 * If the markup column is set to something, it overrides
5413 * the text column set by gtk_icon_view_set_text_column().
5418 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5421 if (column == icon_view->priv->markup_column)
5425 icon_view->priv->markup_column = -1;
5428 if (icon_view->priv->model != NULL)
5432 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5434 g_return_if_fail (column_type == G_TYPE_STRING);
5437 icon_view->priv->markup_column = column;
5440 gtk_icon_view_stop_editing (icon_view, TRUE);
5442 update_text_cell (icon_view);
5444 gtk_icon_view_invalidate_sizes (icon_view);
5445 gtk_icon_view_queue_layout (icon_view);
5447 g_object_notify (G_OBJECT (icon_view), "markup-column");
5451 * gtk_icon_view_get_markup_column:
5452 * @icon_view: A #GtkIconView.
5454 * Returns the column with markup text for @icon_view.
5456 * Returns: the markup column, or -1 if it's unset.
5461 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5463 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5465 return icon_view->priv->markup_column;
5469 * gtk_icon_view_set_pixbuf_column:
5470 * @icon_view: A #GtkIconView.
5471 * @column: A column in the currently used model, or -1 to disable
5473 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5474 * column must be of type #GDK_TYPE_PIXBUF
5479 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5482 if (column == icon_view->priv->pixbuf_column)
5486 icon_view->priv->pixbuf_column = -1;
5489 if (icon_view->priv->model != NULL)
5493 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5495 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5498 icon_view->priv->pixbuf_column = column;
5501 gtk_icon_view_stop_editing (icon_view, TRUE);
5503 update_pixbuf_cell (icon_view);
5505 gtk_icon_view_invalidate_sizes (icon_view);
5506 gtk_icon_view_queue_layout (icon_view);
5508 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5513 * gtk_icon_view_get_pixbuf_column:
5514 * @icon_view: A #GtkIconView.
5516 * Returns the column with pixbufs for @icon_view.
5518 * Returns: the pixbuf column, or -1 if it's unset.
5523 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5525 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5527 return icon_view->priv->pixbuf_column;
5531 * gtk_icon_view_select_path:
5532 * @icon_view: A #GtkIconView.
5533 * @path: The #GtkTreePath to be selected.
5535 * Selects the row at @path.
5540 gtk_icon_view_select_path (GtkIconView *icon_view,
5543 GtkIconViewItem *item = NULL;
5545 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5546 g_return_if_fail (icon_view->priv->model != NULL);
5547 g_return_if_fail (path != NULL);
5549 if (gtk_tree_path_get_depth (path) > 0)
5550 item = g_list_nth_data (icon_view->priv->items,
5551 gtk_tree_path_get_indices(path)[0]);
5554 gtk_icon_view_select_item (icon_view, item);
5558 * gtk_icon_view_unselect_path:
5559 * @icon_view: A #GtkIconView.
5560 * @path: The #GtkTreePath to be unselected.
5562 * Unselects the row at @path.
5567 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5570 GtkIconViewItem *item;
5572 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5573 g_return_if_fail (icon_view->priv->model != NULL);
5574 g_return_if_fail (path != NULL);
5576 item = g_list_nth_data (icon_view->priv->items,
5577 gtk_tree_path_get_indices(path)[0]);
5582 gtk_icon_view_unselect_item (icon_view, item);
5586 * gtk_icon_view_get_selected_items:
5587 * @icon_view: A #GtkIconView.
5589 * Creates a list of paths of all selected items. Additionally, if you are
5590 * planning on modifying the model after calling this function, you may
5591 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5592 * To do this, you can use gtk_tree_row_reference_new().
5594 * To free the return value, use:
5596 * g_list_foreach (list, gtk_tree_path_free, NULL);
5597 * g_list_free (list);
5600 * Return value: A #GList containing a #GtkTreePath for each selected row.
5605 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5608 GList *selected = NULL;
5610 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5612 for (list = icon_view->priv->items; list != NULL; list = list->next)
5614 GtkIconViewItem *item = list->data;
5618 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5620 selected = g_list_prepend (selected, path);
5628 * gtk_icon_view_select_all:
5629 * @icon_view: A #GtkIconView.
5631 * Selects all the icons. @icon_view must has its selection mode set
5632 * to #GTK_SELECTION_MULTIPLE.
5637 gtk_icon_view_select_all (GtkIconView *icon_view)
5640 gboolean dirty = FALSE;
5642 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5644 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5647 for (items = icon_view->priv->items; items; items = items->next)
5649 GtkIconViewItem *item = items->data;
5651 if (!item->selected)
5654 item->selected = TRUE;
5655 gtk_icon_view_queue_draw_item (icon_view, item);
5660 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5664 * gtk_icon_view_unselect_all:
5665 * @icon_view: A #GtkIconView.
5667 * Unselects all the icons.
5672 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5674 gboolean dirty = FALSE;
5676 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5678 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5681 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5684 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5688 * gtk_icon_view_path_is_selected:
5689 * @icon_view: A #GtkIconView.
5690 * @path: A #GtkTreePath to check selection on.
5692 * Returns %TRUE if the icon pointed to by @path is currently
5693 * selected. If @path does not point to a valid location, %FALSE is returned.
5695 * Return value: %TRUE if @path is selected.
5700 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5703 GtkIconViewItem *item;
5705 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5706 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5707 g_return_val_if_fail (path != NULL, FALSE);
5709 item = g_list_nth_data (icon_view->priv->items,
5710 gtk_tree_path_get_indices(path)[0]);
5715 return item->selected;
5719 * gtk_icon_view_item_activated:
5720 * @icon_view: A #GtkIconView
5721 * @path: The #GtkTreePath to be activated
5723 * Activates the item determined by @path.
5728 gtk_icon_view_item_activated (GtkIconView *icon_view,
5731 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5732 g_return_if_fail (path != NULL);
5734 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5738 * gtk_icon_view_set_orientation:
5739 * @icon_view: a #GtkIconView
5740 * @orientation: the relative position of texts and icons
5742 * Sets the ::orientation property which determines whether the labels
5743 * are drawn beside the icons instead of below.
5748 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5749 GtkOrientation orientation)
5751 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5753 if (icon_view->priv->orientation != orientation)
5755 icon_view->priv->orientation = orientation;
5757 gtk_icon_view_stop_editing (icon_view, TRUE);
5758 gtk_icon_view_invalidate_sizes (icon_view);
5759 gtk_icon_view_queue_layout (icon_view);
5761 update_text_cell (icon_view);
5762 update_pixbuf_cell (icon_view);
5764 g_object_notify (G_OBJECT (icon_view), "orientation");
5769 * gtk_icon_view_get_orientation:
5770 * @icon_view: a #GtkIconView
5772 * Returns the value of the ::orientation property which determines
5773 * whether the labels are drawn beside the icons instead of below.
5775 * Return value: the relative position of texts and icons
5780 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5782 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5783 GTK_ORIENTATION_VERTICAL);
5785 return icon_view->priv->orientation;
5789 * gtk_icon_view_set_columns:
5790 * @icon_view: a #GtkIconView
5791 * @columns: the number of columns
5793 * Sets the ::columns property which determines in how
5794 * many columns the icons are arranged. If @columns is
5795 * -1, the number of columns will be chosen automatically
5796 * to fill the available area.
5801 gtk_icon_view_set_columns (GtkIconView *icon_view,
5804 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5806 if (icon_view->priv->columns != columns)
5808 icon_view->priv->columns = columns;
5810 gtk_icon_view_stop_editing (icon_view, TRUE);
5811 gtk_icon_view_queue_layout (icon_view);
5813 g_object_notify (G_OBJECT (icon_view), "columns");
5818 * gtk_icon_view_get_columns:
5819 * @icon_view: a #GtkIconView
5821 * Returns the value of the ::columns property.
5823 * Return value: the number of columns, or -1
5828 gtk_icon_view_get_columns (GtkIconView *icon_view)
5830 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5832 return icon_view->priv->columns;
5836 * gtk_icon_view_set_item_width:
5837 * @icon_view: a #GtkIconView
5838 * @item_width: the width for each item
5840 * Sets the ::item-width property which specifies the width
5841 * to use for each item. If it is set to -1, the icon view will
5842 * automatically determine a suitable item size.
5847 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5850 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5852 if (icon_view->priv->item_width != item_width)
5854 icon_view->priv->item_width = item_width;
5856 gtk_icon_view_stop_editing (icon_view, TRUE);
5857 gtk_icon_view_invalidate_sizes (icon_view);
5858 gtk_icon_view_queue_layout (icon_view);
5860 update_text_cell (icon_view);
5862 g_object_notify (G_OBJECT (icon_view), "item-width");
5867 * gtk_icon_view_get_item_width:
5868 * @icon_view: a #GtkIconView
5870 * Returns the value of the ::item-width property.
5872 * Return value: the width of a single item, or -1
5877 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5879 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5881 return icon_view->priv->item_width;
5886 * gtk_icon_view_set_spacing:
5887 * @icon_view: a #GtkIconView
5888 * @spacing: the spacing
5890 * Sets the ::spacing property which specifies the space
5891 * which is inserted between the cells (i.e. the icon and
5892 * the text) of an item.
5897 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5900 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5902 if (icon_view->priv->spacing != spacing)
5904 icon_view->priv->spacing = spacing;
5906 gtk_icon_view_stop_editing (icon_view, TRUE);
5907 gtk_icon_view_invalidate_sizes (icon_view);
5908 gtk_icon_view_queue_layout (icon_view);
5910 g_object_notify (G_OBJECT (icon_view), "spacing");
5915 * gtk_icon_view_get_spacing:
5916 * @icon_view: a #GtkIconView
5918 * Returns the value of the ::spacing property.
5920 * Return value: the space between cells
5925 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5927 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5929 return icon_view->priv->spacing;
5933 * gtk_icon_view_set_row_spacing:
5934 * @icon_view: a #GtkIconView
5935 * @row_spacing: the row spacing
5937 * Sets the ::row-spacing property which specifies the space
5938 * which is inserted between the rows of the icon view.
5943 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5946 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5948 if (icon_view->priv->row_spacing != row_spacing)
5950 icon_view->priv->row_spacing = row_spacing;
5952 gtk_icon_view_stop_editing (icon_view, TRUE);
5953 gtk_icon_view_invalidate_sizes (icon_view);
5954 gtk_icon_view_queue_layout (icon_view);
5956 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5961 * gtk_icon_view_get_row_spacing:
5962 * @icon_view: a #GtkIconView
5964 * Returns the value of the ::row-spacing property.
5966 * Return value: the space between rows
5971 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5973 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5975 return icon_view->priv->row_spacing;
5979 * gtk_icon_view_set_column_spacing:
5980 * @icon_view: a #GtkIconView
5981 * @column_spacing: the column spacing
5983 * Sets the ::column-spacing property which specifies the space
5984 * which is inserted between the columns of the icon view.
5989 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5990 gint column_spacing)
5992 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5994 if (icon_view->priv->column_spacing != column_spacing)
5996 icon_view->priv->column_spacing = column_spacing;
5998 gtk_icon_view_stop_editing (icon_view, TRUE);
5999 gtk_icon_view_invalidate_sizes (icon_view);
6000 gtk_icon_view_queue_layout (icon_view);
6002 g_object_notify (G_OBJECT (icon_view), "column-spacing");
6007 * gtk_icon_view_get_column_spacing:
6008 * @icon_view: a #GtkIconView
6010 * Returns the value of the ::column-spacing property.
6012 * Return value: the space between columns
6017 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
6019 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6021 return icon_view->priv->column_spacing;
6025 * gtk_icon_view_set_margin:
6026 * @icon_view: a #GtkIconView
6027 * @margin: the margin
6029 * Sets the ::margin property which specifies the space
6030 * which is inserted at the top, bottom, left and right
6036 gtk_icon_view_set_margin (GtkIconView *icon_view,
6039 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6041 if (icon_view->priv->margin != margin)
6043 icon_view->priv->margin = margin;
6045 gtk_icon_view_stop_editing (icon_view, TRUE);
6046 gtk_icon_view_invalidate_sizes (icon_view);
6047 gtk_icon_view_queue_layout (icon_view);
6049 g_object_notify (G_OBJECT (icon_view), "margin");
6054 * gtk_icon_view_get_margin:
6055 * @icon_view: a #GtkIconView
6057 * Returns the value of the ::margin property.
6059 * Return value: the space at the borders
6064 gtk_icon_view_get_margin (GtkIconView *icon_view)
6066 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
6068 return icon_view->priv->margin;
6072 /* Get/set whether drag_motion requested the drag data and
6073 * drag_data_received should thus not actually insert the data,
6074 * since the data doesn't result from a drop.
6077 set_status_pending (GdkDragContext *context,
6078 GdkDragAction suggested_action)
6080 g_object_set_data (G_OBJECT (context),
6081 I_("gtk-icon-view-status-pending"),
6082 GINT_TO_POINTER (suggested_action));
6085 static GdkDragAction
6086 get_status_pending (GdkDragContext *context)
6088 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
6089 "gtk-icon-view-status-pending"));
6093 unset_reorderable (GtkIconView *icon_view)
6095 if (icon_view->priv->reorderable)
6097 icon_view->priv->reorderable = FALSE;
6098 g_object_notify (G_OBJECT (icon_view), "reorderable");
6103 clear_source_info (GtkIconView *icon_view)
6105 if (icon_view->priv->source_targets)
6106 gtk_target_list_unref (icon_view->priv->source_targets);
6107 icon_view->priv->source_targets = NULL;
6109 icon_view->priv->source_set = FALSE;
6113 clear_dest_info (GtkIconView *icon_view)
6115 if (icon_view->priv->dest_targets)
6116 gtk_target_list_unref (icon_view->priv->dest_targets);
6117 icon_view->priv->dest_targets = NULL;
6119 icon_view->priv->dest_set = FALSE;
6123 set_source_row (GdkDragContext *context,
6124 GtkTreeModel *model,
6125 GtkTreePath *source_row)
6128 g_object_set_data_full (G_OBJECT (context),
6129 I_("gtk-icon-view-source-row"),
6130 gtk_tree_row_reference_new (model, source_row),
6131 (GDestroyNotify) gtk_tree_row_reference_free);
6133 g_object_set_data_full (G_OBJECT (context),
6134 I_("gtk-icon-view-source-row"),
6139 get_source_row (GdkDragContext *context)
6141 GtkTreeRowReference *ref;
6143 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
6146 return gtk_tree_row_reference_get_path (ref);
6153 GtkTreeRowReference *dest_row;
6154 gboolean empty_view_drop;
6155 gboolean drop_append_mode;
6159 dest_row_free (gpointer data)
6161 DestRow *dr = (DestRow *)data;
6163 gtk_tree_row_reference_free (dr->dest_row);
6168 set_dest_row (GdkDragContext *context,
6169 GtkTreeModel *model,
6170 GtkTreePath *dest_row,
6171 gboolean empty_view_drop,
6172 gboolean drop_append_mode)
6178 g_object_set_data_full (G_OBJECT (context),
6179 I_("gtk-icon-view-dest-row"),
6184 dr = g_new0 (DestRow, 1);
6186 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
6187 dr->empty_view_drop = empty_view_drop;
6188 dr->drop_append_mode = drop_append_mode;
6189 g_object_set_data_full (G_OBJECT (context),
6190 I_("gtk-icon-view-dest-row"),
6191 dr, (GDestroyNotify) dest_row_free);
6195 get_dest_row (GdkDragContext *context)
6199 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
6203 GtkTreePath *path = NULL;
6206 path = gtk_tree_row_reference_get_path (dr->dest_row);
6207 else if (dr->empty_view_drop)
6208 path = gtk_tree_path_new_from_indices (0, -1);
6212 if (path && dr->drop_append_mode)
6213 gtk_tree_path_next (path);
6222 check_model_dnd (GtkTreeModel *model,
6223 GType required_iface,
6224 const gchar *signal)
6226 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
6228 g_warning ("You must override the default '%s' handler "
6229 "on GtkIconView when using models that don't support "
6230 "the %s interface and enabling drag-and-drop. The simplest way to do this "
6231 "is to connect to '%s' and call "
6232 "g_signal_stop_emission_by_name() in your signal handler to prevent "
6233 "the default handler from running. Look at the source code "
6234 "for the default handler in gtkiconview.c to get an idea what "
6235 "your handler should do. (gtkiconview.c is in the GTK+ source "
6236 "code.) If you're using GTK+ from a language other than C, "
6237 "there may be a more natural way to override default handlers, e.g. via derivation.",
6238 signal, g_type_name (required_iface), signal);
6246 remove_scroll_timeout (GtkIconView *icon_view)
6248 if (icon_view->priv->scroll_timeout_id != 0)
6250 g_source_remove (icon_view->priv->scroll_timeout_id);
6252 icon_view->priv->scroll_timeout_id = 0;
6257 gtk_icon_view_autoscroll (GtkIconView *icon_view)
6259 gint px, py, x, y, width, height;
6260 gint hoffset, voffset;
6263 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
6264 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
6266 /* see if we are near the edge. */
6267 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
6269 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
6271 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
6273 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
6277 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
6278 icon_view->priv->vadjustment->lower,
6279 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
6280 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
6284 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
6285 icon_view->priv->hadjustment->lower,
6286 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
6287 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
6293 drag_scroll_timeout (gpointer data)
6295 GtkIconView *icon_view = GTK_ICON_VIEW (data);
6297 gtk_icon_view_autoscroll (icon_view);
6304 set_destination (GtkIconView *icon_view,
6305 GdkDragContext *context,
6308 GdkDragAction *suggested_action,
6312 GtkTreePath *path = NULL;
6313 GtkIconViewDropPosition pos;
6314 GtkIconViewDropPosition old_pos;
6315 GtkTreePath *old_dest_path = NULL;
6316 gboolean can_drop = FALSE;
6318 widget = GTK_WIDGET (icon_view);
6320 *suggested_action = 0;
6323 if (!icon_view->priv->dest_set)
6325 /* someone unset us as a drag dest, note that if
6326 * we return FALSE drag_leave isn't called
6329 gtk_icon_view_set_drag_dest_item (icon_view,
6331 GTK_ICON_VIEW_DROP_LEFT);
6333 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6335 return FALSE; /* no longer a drop site */
6338 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
6339 if (*target == GDK_NONE)
6342 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
6345 GtkTreeModel *model;
6347 /* the row got dropped on empty space, let's setup a special case
6351 gtk_tree_path_free (path);
6353 model = gtk_icon_view_get_model (icon_view);
6355 n_children = gtk_tree_model_iter_n_children (model, NULL);
6358 pos = GTK_ICON_VIEW_DROP_BELOW;
6359 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6363 pos = GTK_ICON_VIEW_DROP_ABOVE;
6364 path = gtk_tree_path_new_from_indices (0, -1);
6374 gtk_icon_view_get_drag_dest_item (icon_view,
6379 gtk_tree_path_free (old_dest_path);
6381 if (TRUE /* FIXME if the location droppable predicate */)
6389 GtkWidget *source_widget;
6391 *suggested_action = context->suggested_action;
6392 source_widget = gtk_drag_get_source_widget (context);
6394 if (source_widget == widget)
6396 /* Default to MOVE, unless the user has
6397 * pressed ctrl or shift to affect available actions
6399 if ((context->actions & GDK_ACTION_MOVE) != 0)
6400 *suggested_action = GDK_ACTION_MOVE;
6403 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6408 /* can't drop here */
6409 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6411 GTK_ICON_VIEW_DROP_LEFT);
6415 gtk_tree_path_free (path);
6421 get_logical_destination (GtkIconView *icon_view,
6422 gboolean *drop_append_mode)
6424 /* adjust path to point to the row the drop goes in front of */
6425 GtkTreePath *path = NULL;
6426 GtkIconViewDropPosition pos;
6428 *drop_append_mode = FALSE;
6430 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6435 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6436 pos == GTK_ICON_VIEW_DROP_BELOW)
6439 GtkTreeModel *model = icon_view->priv->model;
6441 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6442 !gtk_tree_model_iter_next (model, &iter))
6443 *drop_append_mode = TRUE;
6446 *drop_append_mode = FALSE;
6447 gtk_tree_path_next (path);
6455 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6456 GdkEventMotion *event)
6458 GdkDragContext *context;
6459 GtkTreePath *path = NULL;
6461 GtkTreeModel *model;
6462 gboolean retval = FALSE;
6464 if (!icon_view->priv->source_set)
6467 if (icon_view->priv->pressed_button < 0)
6470 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6471 icon_view->priv->press_start_x,
6472 icon_view->priv->press_start_y,
6473 event->x, event->y))
6476 model = gtk_icon_view_get_model (icon_view);
6481 button = icon_view->priv->pressed_button;
6482 icon_view->priv->pressed_button = -1;
6484 path = gtk_icon_view_get_path_at_pos (icon_view,
6485 icon_view->priv->press_start_x,
6486 icon_view->priv->press_start_y);
6491 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6492 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6496 /* FIXME Check whether we're a start button, if not return FALSE and
6500 /* Now we can begin the drag */
6504 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6505 icon_view->priv->source_targets,
6506 icon_view->priv->source_actions,
6510 set_source_row (context, model, path);
6514 gtk_tree_path_free (path);
6519 /* Source side drag signals */
6521 gtk_icon_view_drag_begin (GtkWidget *widget,
6522 GdkDragContext *context)
6524 GtkIconView *icon_view;
6525 GtkIconViewItem *item;
6530 icon_view = GTK_ICON_VIEW (widget);
6532 /* if the user uses a custom DnD impl, we don't set the icon here */
6533 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6536 item = gtk_icon_view_get_item_at_coords (icon_view,
6537 icon_view->priv->press_start_x,
6538 icon_view->priv->press_start_y,
6542 g_return_if_fail (item != NULL);
6544 x = icon_view->priv->press_start_x - item->x + 1;
6545 y = icon_view->priv->press_start_y - item->y + 1;
6547 path = gtk_tree_path_new_from_indices (item->index, -1);
6548 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6549 gtk_tree_path_free (path);
6551 gtk_drag_set_icon_pixmap (context,
6552 gdk_drawable_get_colormap (icon),
6557 g_object_unref (icon);
6561 gtk_icon_view_drag_end (GtkWidget *widget,
6562 GdkDragContext *context)
6568 gtk_icon_view_drag_data_get (GtkWidget *widget,
6569 GdkDragContext *context,
6570 GtkSelectionData *selection_data,
6574 GtkIconView *icon_view;
6575 GtkTreeModel *model;
6576 GtkTreePath *source_row;
6578 icon_view = GTK_ICON_VIEW (widget);
6579 model = gtk_icon_view_get_model (icon_view);
6584 if (!icon_view->priv->dest_set)
6587 source_row = get_source_row (context);
6589 if (source_row == NULL)
6592 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6593 * any model; for DragSource models there are some other targets
6597 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6598 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6603 /* If drag_data_get does nothing, try providing row data. */
6604 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6605 gtk_tree_set_row_drag_data (selection_data,
6610 gtk_tree_path_free (source_row);
6614 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6615 GdkDragContext *context)
6617 GtkTreeModel *model;
6618 GtkIconView *icon_view;
6619 GtkTreePath *source_row;
6621 icon_view = GTK_ICON_VIEW (widget);
6622 model = gtk_icon_view_get_model (icon_view);
6624 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6627 if (!icon_view->priv->dest_set)
6630 source_row = get_source_row (context);
6632 if (source_row == NULL)
6635 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6638 gtk_tree_path_free (source_row);
6640 set_source_row (context, NULL, NULL);
6643 /* Target side drag signals */
6645 gtk_icon_view_drag_leave (GtkWidget *widget,
6646 GdkDragContext *context,
6649 GtkIconView *icon_view;
6651 icon_view = GTK_ICON_VIEW (widget);
6653 /* unset any highlight row */
6654 gtk_icon_view_set_drag_dest_item (icon_view,
6656 GTK_ICON_VIEW_DROP_LEFT);
6658 remove_scroll_timeout (icon_view);
6662 gtk_icon_view_drag_motion (GtkWidget *widget,
6663 GdkDragContext *context,
6668 GtkTreePath *path = NULL;
6669 GtkIconViewDropPosition pos;
6670 GtkIconView *icon_view;
6671 GdkDragAction suggested_action = 0;
6675 icon_view = GTK_ICON_VIEW (widget);
6677 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6680 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6682 /* we only know this *after* set_desination_row */
6683 empty = icon_view->priv->empty_view_drop;
6685 if (path == NULL && !empty)
6687 /* Can't drop here. */
6688 gdk_drag_status (context, 0, time);
6692 if (icon_view->priv->scroll_timeout_id == 0)
6694 icon_view->priv->scroll_timeout_id =
6695 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6698 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6700 /* Request data so we can use the source row when
6701 * determining whether to accept the drop
6703 set_status_pending (context, suggested_action);
6704 gtk_drag_get_data (widget, context, target, time);
6708 set_status_pending (context, 0);
6709 gdk_drag_status (context, suggested_action, time);
6714 gtk_tree_path_free (path);
6720 gtk_icon_view_drag_drop (GtkWidget *widget,
6721 GdkDragContext *context,
6726 GtkIconView *icon_view;
6728 GdkDragAction suggested_action = 0;
6729 GdkAtom target = GDK_NONE;
6730 GtkTreeModel *model;
6731 gboolean drop_append_mode;
6733 icon_view = GTK_ICON_VIEW (widget);
6734 model = gtk_icon_view_get_model (icon_view);
6736 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6738 if (!icon_view->priv->dest_set)
6741 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6744 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6747 path = get_logical_destination (icon_view, &drop_append_mode);
6749 if (target != GDK_NONE && path != NULL)
6751 /* in case a motion had requested drag data, change things so we
6752 * treat drag data receives as a drop.
6754 set_status_pending (context, 0);
6755 set_dest_row (context, model, path,
6756 icon_view->priv->empty_view_drop, drop_append_mode);
6760 gtk_tree_path_free (path);
6762 /* Unset this thing */
6763 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6765 if (target != GDK_NONE)
6767 gtk_drag_get_data (widget, context, target, time);
6775 gtk_icon_view_drag_data_received (GtkWidget *widget,
6776 GdkDragContext *context,
6779 GtkSelectionData *selection_data,
6784 gboolean accepted = FALSE;
6785 GtkTreeModel *model;
6786 GtkIconView *icon_view;
6787 GtkTreePath *dest_row;
6788 GdkDragAction suggested_action;
6789 gboolean drop_append_mode;
6791 icon_view = GTK_ICON_VIEW (widget);
6792 model = gtk_icon_view_get_model (icon_view);
6794 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6797 if (!icon_view->priv->dest_set)
6800 suggested_action = get_status_pending (context);
6802 if (suggested_action)
6804 /* We are getting this data due to a request in drag_motion,
6805 * rather than due to a request in drag_drop, so we are just
6806 * supposed to call drag_status, not actually paste in the
6809 path = get_logical_destination (icon_view, &drop_append_mode);
6812 suggested_action = 0;
6814 if (suggested_action)
6816 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6819 suggested_action = 0;
6822 gdk_drag_status (context, suggested_action, time);
6825 gtk_tree_path_free (path);
6827 /* If you can't drop, remove user drop indicator until the next motion */
6828 if (suggested_action == 0)
6829 gtk_icon_view_set_drag_dest_item (icon_view,
6831 GTK_ICON_VIEW_DROP_LEFT);
6836 dest_row = get_dest_row (context);
6838 if (dest_row == NULL)
6841 if (selection_data->length >= 0)
6843 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6849 gtk_drag_finish (context,
6851 (context->action == GDK_ACTION_MOVE),
6854 gtk_tree_path_free (dest_row);
6857 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6860 /* Drag-and-Drop support */
6862 * gtk_icon_view_enable_model_drag_source:
6863 * @icon_view: a #GtkIconTreeView
6864 * @start_button_mask: Mask of allowed buttons to start drag
6865 * @targets: the table of targets that the drag will support
6866 * @n_targets: the number of items in @targets
6867 * @actions: the bitmask of possible actions for a drag from this
6870 * Turns @icon_view into a drag source for automatic DND.
6875 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6876 GdkModifierType start_button_mask,
6877 const GtkTargetEntry *targets,
6879 GdkDragAction actions)
6881 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6883 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6885 clear_source_info (icon_view);
6886 icon_view->priv->start_button_mask = start_button_mask;
6887 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6888 icon_view->priv->source_actions = actions;
6890 icon_view->priv->source_set = TRUE;
6892 unset_reorderable (icon_view);
6896 * gtk_icon_view_enable_model_drag_dest:
6897 * @icon_view: a #GtkIconView
6898 * @targets: the table of targets that the drag will support
6899 * @n_targets: the number of items in @targets
6900 * @actions: the bitmask of possible actions for a drag to this
6903 * Turns @icon_view into a drop destination for automatic DND.
6908 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6909 const GtkTargetEntry *targets,
6911 GdkDragAction actions)
6913 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6915 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6917 clear_dest_info (icon_view);
6919 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6920 icon_view->priv->dest_actions = actions;
6922 icon_view->priv->dest_set = TRUE;
6924 unset_reorderable (icon_view);
6928 * gtk_icon_view_unset_model_drag_source:
6929 * @icon_view: a #GtkIconView
6931 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6936 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6938 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6940 if (icon_view->priv->source_set)
6942 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6943 clear_source_info (icon_view);
6946 unset_reorderable (icon_view);
6950 * gtk_icon_view_unset_model_drag_dest:
6951 * @icon_view: a #GtkIconView
6953 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6958 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6960 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6962 if (icon_view->priv->dest_set)
6964 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6965 clear_dest_info (icon_view);
6968 unset_reorderable (icon_view);
6971 /* These are useful to implement your own custom stuff. */
6973 * gtk_icon_view_set_drag_dest_item:
6974 * @icon_view: a #GtkIconView
6975 * @path: The path of the item to highlight, or %NULL.
6976 * @pos: Specifies where to drop, relative to the item
6978 * Sets the item that is highlighted for feedback.
6983 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6985 GtkIconViewDropPosition pos)
6987 /* Note; this function is exported to allow a custom DND
6988 * implementation, so it can't touch TreeViewDragInfo
6991 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6993 if (icon_view->priv->dest_item)
6995 GtkTreePath *current_path;
6996 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6997 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6998 icon_view->priv->dest_item = NULL;
7000 gtk_icon_view_queue_draw_path (icon_view, current_path);
7001 gtk_tree_path_free (current_path);
7004 /* special case a drop on an empty model */
7005 icon_view->priv->empty_view_drop = FALSE;
7006 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
7007 && gtk_tree_path_get_depth (path) == 1
7008 && gtk_tree_path_get_indices (path)[0] == 0)
7012 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
7015 if (n_children == 0)
7016 icon_view->priv->empty_view_drop = TRUE;
7019 icon_view->priv->dest_pos = pos;
7023 icon_view->priv->dest_item =
7024 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
7025 icon_view->priv->model, path);
7027 gtk_icon_view_queue_draw_path (icon_view, path);
7032 * gtk_icon_view_get_drag_dest_item:
7033 * @icon_view: a #GtkIconView
7034 * @path: Return location for the path of the highlighted item, or %NULL.
7035 * @pos: Return location for the drop position, or %NULL
7037 * Gets information about the item that is highlighted for feedback.
7042 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
7044 GtkIconViewDropPosition *pos)
7046 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7050 if (icon_view->priv->dest_item)
7051 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
7057 *pos = icon_view->priv->dest_pos;
7061 * gtk_icon_view_get_dest_item_at_pos:
7062 * @icon_view: a #GtkIconView
7063 * @drag_x: the position to determine the destination item for
7064 * @drag_y: the position to determine the destination item for
7065 * @path: Return location for the path of the item, or %NULL.
7066 * @pos: Return location for the drop position, or %NULL
7068 * Determines the destination item for a given position.
7070 * Return value: whether there is an item at the given position.
7075 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
7079 GtkIconViewDropPosition *pos)
7081 GtkIconViewItem *item;
7083 /* Note; this function is exported to allow a custom DND
7084 * implementation, so it can't touch TreeViewDragInfo
7087 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7088 g_return_val_if_fail (drag_x >= 0, FALSE);
7089 g_return_val_if_fail (drag_y >= 0, FALSE);
7090 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
7096 item = gtk_icon_view_get_item_at_coords (icon_view,
7097 drag_x + icon_view->priv->hadjustment->value,
7098 drag_y + icon_view->priv->vadjustment->value,
7105 *path = gtk_tree_path_new_from_indices (item->index, -1);
7109 if (drag_x < item->x + item->width / 4)
7110 *pos = GTK_ICON_VIEW_DROP_LEFT;
7111 else if (drag_x > item->x + item->width * 3 / 4)
7112 *pos = GTK_ICON_VIEW_DROP_RIGHT;
7113 else if (drag_y < item->y + item->height / 4)
7114 *pos = GTK_ICON_VIEW_DROP_ABOVE;
7115 else if (drag_y > item->y + item->height * 3 / 4)
7116 *pos = GTK_ICON_VIEW_DROP_BELOW;
7118 *pos = GTK_ICON_VIEW_DROP_INTO;
7125 * gtk_icon_view_create_drag_icon:
7126 * @icon_view: a #GtkIconView
7127 * @path: a #GtkTreePath in @icon_view
7129 * Creates a #GdkPixmap representation of the item at @path.
7130 * This image is used for a drag icon.
7132 * Return value: a newly-allocated pixmap of the drag icon.
7137 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
7142 GdkPixmap *drawable;
7147 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
7148 g_return_val_if_fail (path != NULL, NULL);
7150 widget = GTK_WIDGET (icon_view);
7152 if (!GTK_WIDGET_REALIZED (widget))
7155 index = gtk_tree_path_get_indices (path)[0];
7157 for (l = icon_view->priv->items; l; l = l->next)
7159 GtkIconViewItem *item = l->data;
7161 if (index == item->index)
7163 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
7168 cr = gdk_cairo_create (drawable);
7169 cairo_set_line_width (cr, 1.);
7171 gdk_cairo_set_source_color
7172 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
7173 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
7178 area.width = item->width;
7179 area.height = item->height;
7181 gtk_icon_view_paint_item (icon_view, cr, item, &area,
7182 drawable, 1, 1, FALSE);
7184 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
7185 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
7198 * gtk_icon_view_get_reorderable:
7199 * @icon_view: a #GtkIconView
7201 * Retrieves whether the user can reorder the list via drag-and-drop.
7202 * See gtk_icon_view_set_reorderable().
7204 * Return value: %TRUE if the list can be reordered.
7209 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
7211 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
7213 return icon_view->priv->reorderable;
7216 static const GtkTargetEntry item_targets[] = {
7217 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
7222 * gtk_icon_view_set_reorderable:
7223 * @icon_view: A #GtkIconView.
7224 * @reorderable: %TRUE, if the list of items can be reordered.
7226 * This function is a convenience function to allow you to reorder models that
7227 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
7228 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
7229 * the user can reorder the model by dragging and dropping rows. The
7230 * developer can listen to these changes by connecting to the model's
7231 * row_inserted and row_deleted signals.
7233 * This function does not give you any degree of control over the order -- any
7234 * reordering is allowed. If more control is needed, you should probably
7235 * handle drag and drop manually.
7240 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
7241 gboolean reorderable)
7243 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
7245 reorderable = reorderable != FALSE;
7247 if (icon_view->priv->reorderable == reorderable)
7252 gtk_icon_view_enable_model_drag_source (icon_view,
7255 G_N_ELEMENTS (item_targets),
7257 gtk_icon_view_enable_model_drag_dest (icon_view,
7259 G_N_ELEMENTS (item_targets),
7264 gtk_icon_view_unset_model_drag_source (icon_view);
7265 gtk_icon_view_unset_model_drag_dest (icon_view);
7268 icon_view->priv->reorderable = reorderable;
7270 g_object_notify (G_OBJECT (icon_view), "reorderable");
7274 /* Accessibility Support */
7276 static gpointer accessible_parent_class;
7277 static gpointer accessible_item_parent_class;
7278 static GQuark accessible_private_data_quark = 0;
7280 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
7281 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
7282 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
7284 static GType gtk_icon_view_item_accessible_get_type (void);
7295 GtkIconViewItem *item;
7299 AtkStateSet *state_set;
7303 GtkTextBuffer *text_buffer;
7305 gchar *action_descriptions[LAST_ACTION];
7306 gchar *image_description;
7307 guint action_idle_handler;
7308 } GtkIconViewItemAccessible;
7310 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
7316 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
7321 typedef struct _GtkIconViewItemAccessibleClass
7323 AtkObjectClass parent_class;
7325 } GtkIconViewItemAccessibleClass;
7327 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
7330 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
7332 GtkIconViewItemAccessible *item;
7333 GtkIconView *icon_view;
7336 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
7337 item->action_idle_handler = 0;
7339 if (item->widget != NULL)
7341 icon_view = GTK_ICON_VIEW (item->widget);
7342 path = gtk_tree_path_new_from_indices (item->item->index, -1);
7343 gtk_icon_view_item_activated (icon_view, path);
7344 gtk_tree_path_free (path);
7351 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7354 GtkIconViewItemAccessible *item;
7356 if (i < 0 || i >= LAST_ACTION)
7359 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7361 if (!GTK_IS_ICON_VIEW (item->widget))
7364 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7369 case ACTION_ACTIVATE:
7370 if (!item->action_idle_handler)
7371 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7374 g_assert_not_reached ();
7382 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7387 static const gchar *
7388 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7391 GtkIconViewItemAccessible *item;
7393 if (i < 0 || i >= LAST_ACTION)
7396 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7398 if (item->action_descriptions[i])
7399 return item->action_descriptions[i];
7401 return gtk_icon_view_item_accessible_action_descriptions[i];
7404 static const gchar *
7405 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7408 if (i < 0 || i >= LAST_ACTION)
7411 return gtk_icon_view_item_accessible_action_names[i];
7415 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7417 const gchar *description)
7419 GtkIconViewItemAccessible *item;
7421 if (i < 0 || i >= LAST_ACTION)
7424 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7426 g_free (item->action_descriptions[i]);
7428 item->action_descriptions[i] = g_strdup (description);
7434 atk_action_item_interface_init (AtkActionIface *iface)
7436 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7437 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7438 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7439 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7440 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7443 static const gchar *
7444 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7446 GtkIconViewItemAccessible *item;
7448 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7450 return item->image_description;
7454 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7455 const gchar *description)
7457 GtkIconViewItemAccessible *item;
7459 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7461 g_free (item->image_description);
7462 item->image_description = g_strdup (item->image_description);
7468 get_pixbuf_box (GtkIconView *icon_view,
7469 GtkIconViewItem *item,
7474 for (l = icon_view->priv->cell_list; l; l = l->next)
7476 GtkIconViewCellInfo *info = l->data;
7478 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7480 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7490 get_text (GtkIconView *icon_view,
7491 GtkIconViewItem *item)
7496 for (l = icon_view->priv->cell_list; l; l = l->next)
7498 GtkIconViewCellInfo *info = l->data;
7500 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7502 g_object_get (info->cell, "text", &text, NULL);
7512 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7516 GtkIconViewItemAccessible *item;
7519 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7521 if (!GTK_IS_ICON_VIEW (item->widget))
7524 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7527 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7530 *height = box.height;
7535 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7538 AtkCoordType coord_type)
7540 GtkIconViewItemAccessible *item;
7543 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7545 if (!GTK_IS_ICON_VIEW (item->widget))
7548 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7551 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7553 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7555 *x+= box.x - item->item->x;
7556 *y+= box.y - item->item->y;
7562 atk_image_item_interface_init (AtkImageIface *iface)
7564 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7565 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7566 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7567 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7571 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7575 GtkIconViewItemAccessible *item;
7576 GtkTextIter start, end;
7577 GtkTextBuffer *buffer;
7579 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7581 if (!GTK_IS_ICON_VIEW (item->widget))
7584 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7587 buffer = item->text_buffer;
7588 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7590 gtk_text_buffer_get_end_iter (buffer, &end);
7592 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7594 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7598 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7601 GtkIconViewItemAccessible *item;
7602 GtkTextIter start, end;
7603 GtkTextBuffer *buffer;
7607 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7609 if (!GTK_IS_ICON_VIEW (item->widget))
7612 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7615 buffer = item->text_buffer;
7616 if (offset >= gtk_text_buffer_get_char_count (buffer))
7619 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7621 gtk_text_iter_forward_char (&end);
7622 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7623 unichar = g_utf8_get_char (string);
7631 get_pango_text_offsets (PangoLayout *layout,
7632 GtkTextBuffer *buffer,
7634 AtkTextBoundary boundary_type,
7638 GtkTextIter *start_iter,
7639 GtkTextIter *end_iter)
7641 PangoLayoutIter *iter;
7642 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7643 gint index, start_index, end_index;
7645 gboolean found = FALSE;
7647 text = pango_layout_get_text (layout);
7648 index = g_utf8_offset_to_pointer (text, offset) - text;
7649 iter = pango_layout_get_iter (layout);
7652 line = pango_layout_iter_get_line_readonly (iter);
7653 start_index = line->start_index;
7654 end_index = start_index + line->length;
7656 if (index >= start_index && index <= end_index)
7659 * Found line for offset
7665 * We want the previous line
7669 switch (boundary_type)
7671 case ATK_TEXT_BOUNDARY_LINE_START:
7672 end_index = start_index;
7673 start_index = prev_line->start_index;
7675 case ATK_TEXT_BOUNDARY_LINE_END:
7677 start_index = prev_prev_line->start_index +
7678 prev_prev_line->length;
7679 end_index = prev_line->start_index + prev_line->length;
7682 g_assert_not_reached();
7686 start_index = end_index = 0;
7689 switch (boundary_type)
7691 case ATK_TEXT_BOUNDARY_LINE_START:
7692 if (pango_layout_iter_next_line (iter))
7693 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7695 case ATK_TEXT_BOUNDARY_LINE_END:
7697 start_index = prev_line->start_index +
7701 g_assert_not_reached();
7706 * We want the next line
7708 if (pango_layout_iter_next_line (iter))
7710 line = pango_layout_iter_get_line_readonly (iter);
7711 switch (boundary_type)
7713 case ATK_TEXT_BOUNDARY_LINE_START:
7714 start_index = line->start_index;
7715 if (pango_layout_iter_next_line (iter))
7716 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7718 end_index = start_index + line->length;
7720 case ATK_TEXT_BOUNDARY_LINE_END:
7721 start_index = end_index;
7722 end_index = line->start_index + line->length;
7725 g_assert_not_reached();
7729 start_index = end_index;
7735 prev_prev_line = prev_line;
7738 while (pango_layout_iter_next_line (iter));
7742 start_index = prev_line->start_index + prev_line->length;
7743 end_index = start_index;
7745 pango_layout_iter_free (iter);
7746 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7747 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7749 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7750 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7755 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7757 AtkTextBoundary boundary_type,
7761 GtkIconViewItemAccessible *item;
7762 GtkTextIter start, end;
7763 GtkTextBuffer *buffer;
7765 GtkIconView *icon_view;
7768 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7770 if (!GTK_IS_ICON_VIEW (item->widget))
7773 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7776 buffer = item->text_buffer;
7778 if (!gtk_text_buffer_get_char_count (buffer))
7782 return g_strdup ("");
7784 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7788 switch (boundary_type)
7790 case ATK_TEXT_BOUNDARY_CHAR:
7791 gtk_text_iter_backward_char(&start);
7793 case ATK_TEXT_BOUNDARY_WORD_START:
7794 if (!gtk_text_iter_starts_word (&start))
7795 gtk_text_iter_backward_word_start (&start);
7797 gtk_text_iter_backward_word_start(&start);
7799 case ATK_TEXT_BOUNDARY_WORD_END:
7800 if (gtk_text_iter_inside_word (&start) &&
7801 !gtk_text_iter_starts_word (&start))
7802 gtk_text_iter_backward_word_start (&start);
7803 while (!gtk_text_iter_ends_word (&start))
7805 if (!gtk_text_iter_backward_char (&start))
7809 gtk_text_iter_backward_word_start(&start);
7810 while (!gtk_text_iter_ends_word (&start))
7812 if (!gtk_text_iter_backward_char (&start))
7816 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7817 if (!gtk_text_iter_starts_sentence (&start))
7818 gtk_text_iter_backward_sentence_start (&start);
7820 gtk_text_iter_backward_sentence_start (&start);
7822 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7823 if (gtk_text_iter_inside_sentence (&start) &&
7824 !gtk_text_iter_starts_sentence (&start))
7825 gtk_text_iter_backward_sentence_start (&start);
7826 while (!gtk_text_iter_ends_sentence (&start))
7828 if (!gtk_text_iter_backward_char (&start))
7832 gtk_text_iter_backward_sentence_start (&start);
7833 while (!gtk_text_iter_ends_sentence (&start))
7835 if (!gtk_text_iter_backward_char (&start))
7839 case ATK_TEXT_BOUNDARY_LINE_START:
7840 case ATK_TEXT_BOUNDARY_LINE_END:
7842 icon_view = GTK_ICON_VIEW (item->widget);
7843 /* FIXME we probably have to use GailTextCell to salvage this */
7844 gtk_icon_view_update_item_text (icon_view, item->item);
7845 get_pango_text_offsets (icon_view->priv->layout,
7858 *start_offset = gtk_text_iter_get_offset (&start);
7859 *end_offset = gtk_text_iter_get_offset (&end);
7861 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7865 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7867 AtkTextBoundary boundary_type,
7871 GtkIconViewItemAccessible *item;
7872 GtkTextIter start, end;
7873 GtkTextBuffer *buffer;
7875 GtkIconView *icon_view;
7878 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7880 if (!GTK_IS_ICON_VIEW (item->widget))
7883 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7886 buffer = item->text_buffer;
7888 if (!gtk_text_buffer_get_char_count (buffer))
7892 return g_strdup ("");
7894 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7898 switch (boundary_type)
7900 case ATK_TEXT_BOUNDARY_CHAR:
7901 gtk_text_iter_forward_char (&end);
7903 case ATK_TEXT_BOUNDARY_WORD_START:
7904 if (!gtk_text_iter_starts_word (&start))
7905 gtk_text_iter_backward_word_start (&start);
7906 if (gtk_text_iter_inside_word (&end))
7907 gtk_text_iter_forward_word_end (&end);
7908 while (!gtk_text_iter_starts_word (&end))
7910 if (!gtk_text_iter_forward_char (&end))
7914 case ATK_TEXT_BOUNDARY_WORD_END:
7915 if (gtk_text_iter_inside_word (&start) &&
7916 !gtk_text_iter_starts_word (&start))
7917 gtk_text_iter_backward_word_start (&start);
7918 while (!gtk_text_iter_ends_word (&start))
7920 if (!gtk_text_iter_backward_char (&start))
7923 gtk_text_iter_forward_word_end (&end);
7925 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7926 if (!gtk_text_iter_starts_sentence (&start))
7927 gtk_text_iter_backward_sentence_start (&start);
7928 if (gtk_text_iter_inside_sentence (&end))
7929 gtk_text_iter_forward_sentence_end (&end);
7930 while (!gtk_text_iter_starts_sentence (&end))
7932 if (!gtk_text_iter_forward_char (&end))
7936 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7937 if (gtk_text_iter_inside_sentence (&start) &&
7938 !gtk_text_iter_starts_sentence (&start))
7939 gtk_text_iter_backward_sentence_start (&start);
7940 while (!gtk_text_iter_ends_sentence (&start))
7942 if (!gtk_text_iter_backward_char (&start))
7945 gtk_text_iter_forward_sentence_end (&end);
7947 case ATK_TEXT_BOUNDARY_LINE_START:
7948 case ATK_TEXT_BOUNDARY_LINE_END:
7950 icon_view = GTK_ICON_VIEW (item->widget);
7951 /* FIXME we probably have to use GailTextCell to salvage this */
7952 gtk_icon_view_update_item_text (icon_view, item->item);
7953 get_pango_text_offsets (icon_view->priv->layout,
7967 *start_offset = gtk_text_iter_get_offset (&start);
7968 *end_offset = gtk_text_iter_get_offset (&end);
7970 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7974 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7976 AtkTextBoundary boundary_type,
7980 GtkIconViewItemAccessible *item;
7981 GtkTextIter start, end;
7982 GtkTextBuffer *buffer;
7984 GtkIconView *icon_view;
7987 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7989 if (!GTK_IS_ICON_VIEW (item->widget))
7992 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7995 buffer = item->text_buffer;
7997 if (!gtk_text_buffer_get_char_count (buffer))
8001 return g_strdup ("");
8003 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
8007 switch (boundary_type)
8009 case ATK_TEXT_BOUNDARY_CHAR:
8010 gtk_text_iter_forward_char(&start);
8011 gtk_text_iter_forward_chars(&end, 2);
8013 case ATK_TEXT_BOUNDARY_WORD_START:
8014 if (gtk_text_iter_inside_word (&end))
8015 gtk_text_iter_forward_word_end (&end);
8016 while (!gtk_text_iter_starts_word (&end))
8018 if (!gtk_text_iter_forward_char (&end))
8022 if (!gtk_text_iter_is_end (&end))
8024 gtk_text_iter_forward_word_end (&end);
8025 while (!gtk_text_iter_starts_word (&end))
8027 if (!gtk_text_iter_forward_char (&end))
8032 case ATK_TEXT_BOUNDARY_WORD_END:
8033 gtk_text_iter_forward_word_end (&end);
8035 if (!gtk_text_iter_is_end (&end))
8036 gtk_text_iter_forward_word_end (&end);
8038 case ATK_TEXT_BOUNDARY_SENTENCE_START:
8039 if (gtk_text_iter_inside_sentence (&end))
8040 gtk_text_iter_forward_sentence_end (&end);
8041 while (!gtk_text_iter_starts_sentence (&end))
8043 if (!gtk_text_iter_forward_char (&end))
8047 if (!gtk_text_iter_is_end (&end))
8049 gtk_text_iter_forward_sentence_end (&end);
8050 while (!gtk_text_iter_starts_sentence (&end))
8052 if (!gtk_text_iter_forward_char (&end))
8057 case ATK_TEXT_BOUNDARY_SENTENCE_END:
8058 gtk_text_iter_forward_sentence_end (&end);
8060 if (!gtk_text_iter_is_end (&end))
8061 gtk_text_iter_forward_sentence_end (&end);
8063 case ATK_TEXT_BOUNDARY_LINE_START:
8064 case ATK_TEXT_BOUNDARY_LINE_END:
8066 icon_view = GTK_ICON_VIEW (item->widget);
8067 /* FIXME we probably have to use GailTextCell to salvage this */
8068 gtk_icon_view_update_item_text (icon_view, item->item);
8069 get_pango_text_offsets (icon_view->priv->layout,
8081 *start_offset = gtk_text_iter_get_offset (&start);
8082 *end_offset = gtk_text_iter_get_offset (&end);
8084 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
8088 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
8090 GtkIconViewItemAccessible *item;
8092 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8094 if (!GTK_IS_ICON_VIEW (item->widget))
8097 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8100 return gtk_text_buffer_get_char_count (item->text_buffer);
8104 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
8110 AtkCoordType coord_type)
8112 GtkIconViewItemAccessible *item;
8114 GtkIconView *icon_view;
8115 PangoRectangle char_rect;
8116 const gchar *item_text;
8120 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8122 if (!GTK_IS_ICON_VIEW (item->widget))
8125 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8129 icon_view = GTK_ICON_VIEW (item->widget);
8130 /* FIXME we probably have to use GailTextCell to salvage this */
8131 gtk_icon_view_update_item_text (icon_view, item->item);
8132 item_text = pango_layout_get_text (icon_view->priv->layout);
8133 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
8134 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
8136 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
8137 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
8138 /* Look at gtk_icon_view_paint_item() to see where the text is. */
8139 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8140 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
8141 *width = char_rect.width / PANGO_SCALE;
8142 *height = char_rect.height / PANGO_SCALE;
8147 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
8150 AtkCoordType coord_type)
8152 GtkIconViewItemAccessible *item;
8155 GtkIconView *icon_view;
8156 const gchar *item_text;
8161 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
8163 if (!GTK_IS_ICON_VIEW (item->widget))
8166 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8170 icon_view = GTK_ICON_VIEW (item->widget);
8171 /* FIXME we probably have to use GailTextCell to salvage this */
8172 gtk_icon_view_update_item_text (icon_view, item->item);
8173 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
8174 x -= l_x + item->item->layout_x - item->item->x;
8175 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
8176 y -= l_y + item->item->layout_y - item->item->y;
8177 item_text = pango_layout_get_text (icon_view->priv->layout);
8178 if (!pango_layout_xy_to_index (icon_view->priv->layout,
8189 offset = g_utf8_strlen (item_text, -1);
8191 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
8197 atk_text_item_interface_init (AtkTextIface *iface)
8199 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
8200 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
8201 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
8202 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
8203 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
8204 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
8205 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
8206 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
8210 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
8215 AtkCoordType coord_type)
8217 GtkIconViewItemAccessible *item;
8218 AtkObject *parent_obj;
8221 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
8223 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8224 if (!GTK_IS_WIDGET (item->widget))
8227 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
8230 *width = item->item->width;
8231 *height = item->item->height;
8232 if (gtk_icon_view_item_accessible_is_showing (item))
8234 parent_obj = gtk_widget_get_accessible (item->widget);
8235 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
8236 *x = l_x + item->item->x;
8237 *y = l_y + item->item->y;
8247 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
8249 GtkIconViewItemAccessible *item;
8250 GtkWidget *toplevel;
8252 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
8254 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
8255 if (!GTK_IS_WIDGET (item->widget))
8258 gtk_widget_grab_focus (item->widget);
8259 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
8260 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
8261 if (GTK_WIDGET_TOPLEVEL (toplevel))
8262 gtk_window_present (GTK_WINDOW (toplevel));
8268 atk_component_item_interface_init (AtkComponentIface *iface)
8270 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
8271 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
8275 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
8276 AtkStateType state_type,
8277 gboolean emit_signal)
8281 rc = atk_state_set_add_state (item->state_set, state_type);
8283 * The signal should only be generated if the value changed,
8284 * not when the item is set up. So states that are set
8285 * initially should pass FALSE as the emit_signal argument.
8290 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
8291 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8292 if (state_type == ATK_STATE_VISIBLE)
8293 g_signal_emit_by_name (item, "visible_data_changed");
8300 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
8301 AtkStateType state_type,
8302 gboolean emit_signal)
8304 if (atk_state_set_contains_state (item->state_set, state_type))
8308 rc = atk_state_set_remove_state (item->state_set, state_type);
8310 * The signal should only be generated if the value changed,
8311 * not when the item is set up. So states that are set
8312 * initially should pass FALSE as the emit_signal argument.
8317 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
8318 /* If state_type is ATK_STATE_VISIBLE, additional notification */
8319 if (state_type == ATK_STATE_VISIBLE)
8320 g_signal_emit_by_name (item, "visible_data_changed");
8330 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
8332 GtkIconView *icon_view;
8333 GdkRectangle visible_rect;
8334 gboolean is_showing;
8337 * An item is considered "SHOWING" if any part of the item is in the
8338 * visible rectangle.
8341 if (!GTK_IS_ICON_VIEW (item->widget))
8344 if (item->item == NULL)
8347 icon_view = GTK_ICON_VIEW (item->widget);
8349 if (icon_view->priv->hadjustment)
8350 visible_rect.x += icon_view->priv->hadjustment->value;
8352 if (icon_view->priv->hadjustment)
8353 visible_rect.y += icon_view->priv->vadjustment->value;
8354 visible_rect.width = item->widget->allocation.width;
8355 visible_rect.height = item->widget->allocation.height;
8357 if (((item->item->x + item->item->width) < visible_rect.x) ||
8358 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8359 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8360 (item->item->y > (visible_rect.y + visible_rect.height)))
8369 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8370 gboolean emit_signal)
8372 if (gtk_icon_view_item_accessible_is_showing (item))
8373 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8376 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8381 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8385 item->state_set = atk_state_set_new ();
8387 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8388 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8389 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8390 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8391 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8393 for (i = 0; i < LAST_ACTION; i++)
8394 item->action_descriptions[i] = NULL;
8396 item->image_description = NULL;
8398 item->action_idle_handler = 0;
8402 gtk_icon_view_item_accessible_finalize (GObject *object)
8404 GtkIconViewItemAccessible *item;
8407 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8409 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8412 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8414 if (item->state_set)
8415 g_object_unref (item->state_set);
8417 if (item->text_buffer)
8418 g_object_unref (item->text_buffer);
8420 for (i = 0; i < LAST_ACTION; i++)
8421 g_free (item->action_descriptions[i]);
8423 g_free (item->image_description);
8425 if (item->action_idle_handler)
8427 g_source_remove (item->action_idle_handler);
8428 item->action_idle_handler = 0;
8431 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8434 static G_CONST_RETURN gchar*
8435 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8441 GtkIconViewItemAccessible *item;
8442 GtkTextIter start_iter;
8443 GtkTextIter end_iter;
8445 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8447 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8448 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8450 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8455 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8457 GtkIconViewItemAccessible *item;
8459 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8460 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8463 return gtk_widget_get_accessible (item->widget);
8469 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8471 GtkIconViewItemAccessible *item;
8473 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8474 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8476 return item->item->index;
8479 static AtkStateSet *
8480 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8482 GtkIconViewItemAccessible *item;
8483 GtkIconView *icon_view;
8485 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8486 g_return_val_if_fail (item->state_set, NULL);
8491 icon_view = GTK_ICON_VIEW (item->widget);
8492 if (icon_view->priv->cursor_item == item->item)
8493 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8495 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8497 return g_object_ref (item->state_set);
8501 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8503 GObjectClass *gobject_class;
8505 accessible_item_parent_class = g_type_class_peek_parent (klass);
8507 gobject_class = (GObjectClass *)klass;
8509 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8511 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8512 klass->get_name = gtk_icon_view_item_accessible_get_name;
8513 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8514 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8518 gtk_icon_view_item_accessible_get_type (void)
8520 static GType type = 0;
8524 const GTypeInfo tinfo =
8526 sizeof (GtkIconViewItemAccessibleClass),
8527 (GBaseInitFunc) NULL, /* base init */
8528 (GBaseFinalizeFunc) NULL, /* base finalize */
8529 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8530 (GClassFinalizeFunc) NULL, /* class finalize */
8531 NULL, /* class data */
8532 sizeof (GtkIconViewItemAccessible), /* instance size */
8533 0, /* nb preallocs */
8534 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8535 NULL /* value table */
8538 static const GInterfaceInfo atk_component_info =
8540 (GInterfaceInitFunc) atk_component_item_interface_init,
8541 (GInterfaceFinalizeFunc) NULL,
8544 static const GInterfaceInfo atk_action_info =
8546 (GInterfaceInitFunc) atk_action_item_interface_init,
8547 (GInterfaceFinalizeFunc) NULL,
8550 static const GInterfaceInfo atk_image_info =
8552 (GInterfaceInitFunc) atk_image_item_interface_init,
8553 (GInterfaceFinalizeFunc) NULL,
8556 static const GInterfaceInfo atk_text_info =
8558 (GInterfaceInitFunc) atk_text_item_interface_init,
8559 (GInterfaceFinalizeFunc) NULL,
8563 type = g_type_register_static (ATK_TYPE_OBJECT,
8564 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8565 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8566 &atk_component_info);
8567 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8569 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8571 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8578 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8579 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8580 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8582 static GType gtk_icon_view_accessible_get_type (void);
8587 } GtkIconViewAccessible;
8593 } GtkIconViewItemAccessibleInfo;
8599 GtkAdjustment *old_hadj;
8600 GtkAdjustment *old_vadj;
8602 GtkTreeModel *model;
8604 } GtkIconViewAccessiblePrivate;
8606 static GtkIconViewAccessiblePrivate *
8607 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8609 return g_object_get_qdata (G_OBJECT (accessible),
8610 accessible_private_data_quark);
8614 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8618 GtkIconViewItemAccessibleInfo *info;
8619 GtkIconViewItemAccessibleInfo *tmp_info;
8620 GtkIconViewAccessiblePrivate *priv;
8623 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8625 info->index = index;
8627 priv = gtk_icon_view_accessible_get_priv (accessible);
8628 items = priv->items;
8631 tmp_info = items->data;
8632 if (tmp_info->index > index)
8634 items = items->next;
8636 priv->items = g_list_insert_before (priv->items, items, info);
8637 priv->old_hadj = NULL;
8638 priv->old_vadj = NULL;
8642 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8644 GtkIconView *icon_view;
8647 widget = GTK_ACCESSIBLE (accessible)->widget;
8651 icon_view = GTK_ICON_VIEW (widget);
8653 return g_list_length (icon_view->priv->items);
8657 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8660 GtkIconViewAccessiblePrivate *priv;
8661 GtkIconViewItemAccessibleInfo *info;
8664 priv = gtk_icon_view_accessible_get_priv (accessible);
8665 items = priv->items;
8670 if (info->index == index)
8672 items = items->next;
8678 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8681 GtkIconView *icon_view;
8685 GtkIconViewItemAccessible *a11y_item;
8687 widget = GTK_ACCESSIBLE (accessible)->widget;
8691 icon_view = GTK_ICON_VIEW (widget);
8692 icons = g_list_nth (icon_view->priv->items, index);
8696 GtkIconViewItem *item = icons->data;
8698 g_return_val_if_fail (item->index == index, NULL);
8699 obj = gtk_icon_view_accessible_find_child (accessible, index);
8704 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8705 gtk_icon_view_item_accessible_info_new (accessible,
8708 obj->role = ATK_ROLE_ICON;
8709 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8710 a11y_item->item = item;
8711 a11y_item->widget = widget;
8712 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8714 gtk_icon_view_set_cell_data (icon_view, item);
8715 text = get_text (icon_view, item);
8718 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8722 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8723 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8731 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8734 GtkIconViewAccessiblePrivate *priv;
8735 GtkIconViewItemAccessibleInfo *info;
8736 GtkIconViewItemAccessible *item;
8739 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8743 gboolean act_on_item;
8745 widget = GTK_ACCESSIBLE (view)->widget;
8749 items = priv->items;
8751 act_on_item = (list == NULL);
8756 info = (GtkIconViewItemAccessibleInfo *)items->data;
8757 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8759 if (act_on_item == FALSE && list == items)
8763 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8765 items = items->next;
8771 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8772 GtkIconView *icon_view)
8775 GtkIconViewAccessible *view;
8778 * The scrollbars have changed
8780 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8781 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8783 gtk_icon_view_accessible_traverse_items (view, NULL);
8787 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8788 GtkAdjustment *hadj,
8789 GtkAdjustment *vadj)
8792 GtkIconViewAccessiblePrivate *priv;
8794 atk_obj = gtk_widget_get_accessible (widget);
8795 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8797 if (priv->old_hadj != hadj)
8801 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8802 (gpointer *)&priv->old_hadj);
8804 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8805 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8808 priv->old_hadj = hadj;
8811 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8812 (gpointer *)&priv->old_hadj);
8813 g_signal_connect (hadj,
8815 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8819 if (priv->old_vadj != vadj)
8823 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8824 (gpointer *)&priv->old_vadj);
8826 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8827 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8830 priv->old_vadj = vadj;
8833 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8834 (gpointer *)&priv->old_vadj);
8835 g_signal_connect (vadj,
8837 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8844 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8851 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8852 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8858 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8863 GtkIconViewAccessiblePrivate *priv;
8864 GtkIconViewItemAccessibleInfo *info;
8865 GtkIconViewAccessible *view;
8866 GtkIconViewItemAccessible *item;
8872 index = gtk_tree_path_get_indices(path)[0];
8873 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8874 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8875 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8877 items = priv->items;
8882 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8883 if (info->index != item->item->index)
8885 if (info->index < index)
8886 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8888 if (tmp_list == NULL)
8891 info->index = item->item->index;
8894 items = items->next;
8896 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8897 g_signal_emit_by_name (atk_obj, "children_changed::add",
8903 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8907 GtkIconViewAccessiblePrivate *priv;
8908 GtkIconViewItemAccessibleInfo *info;
8909 GtkIconViewAccessible *view;
8910 GtkIconViewItemAccessible *item;
8913 GList *deleted_item;
8917 index = gtk_tree_path_get_indices(path)[0];
8918 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8919 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8920 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8922 items = priv->items;
8924 deleted_item = NULL;
8929 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8930 if (info->index == index)
8932 deleted_item = items;
8934 if (info->index != item->item->index)
8936 if (tmp_list == NULL)
8939 info->index = item->item->index;
8942 items = items->next;
8944 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8947 info = deleted_item->data;
8948 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8950 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8954 priv->items = g_list_remove_link (priv->items, deleted_item);
8962 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8963 GtkIconViewItemAccessibleInfo *i2)
8965 return i1->index - i2->index;
8969 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8975 GtkIconViewAccessiblePrivate *priv;
8976 GtkIconViewItemAccessibleInfo *info;
8977 GtkIconView *icon_view;
8978 GtkIconViewItemAccessible *item;
8982 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8983 icon_view = GTK_ICON_VIEW (user_data);
8984 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8986 items = priv->items;
8990 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8991 info->index = new_order[info->index];
8992 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8993 items = items->next;
8995 priv->items = g_list_sort (priv->items,
8996 (GCompareFunc)gtk_icon_view_accessible_item_compare);
9002 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
9007 obj = G_OBJECT (model);
9008 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
9009 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
9010 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
9011 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
9015 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
9019 obj = G_OBJECT (icon_view->priv->model);
9020 g_signal_connect_data (obj, "row_changed",
9021 (GCallback) gtk_icon_view_accessible_model_row_changed,
9022 icon_view, NULL, 0);
9023 g_signal_connect_data (obj, "row_inserted",
9024 (GCallback) gtk_icon_view_accessible_model_row_inserted,
9025 icon_view, NULL, G_CONNECT_AFTER);
9026 g_signal_connect_data (obj, "row_deleted",
9027 (GCallback) gtk_icon_view_accessible_model_row_deleted,
9028 icon_view, NULL, G_CONNECT_AFTER);
9029 g_signal_connect_data (obj, "rows_reordered",
9030 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
9031 icon_view, NULL, G_CONNECT_AFTER);
9035 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
9037 GtkIconViewItemAccessibleInfo *info;
9040 items = priv->items;
9043 info = (GtkIconViewItemAccessibleInfo *) items->data;
9044 g_object_unref (info->item);
9045 g_free (items->data);
9046 items = items->next;
9048 g_list_free (priv->items);
9053 gtk_icon_view_accessible_notify_gtk (GObject *obj,
9056 GtkIconView *icon_view;
9059 GtkIconViewAccessiblePrivate *priv;
9061 if (strcmp (pspec->name, "model") == 0)
9063 widget = GTK_WIDGET (obj);
9064 atk_obj = gtk_widget_get_accessible (widget);
9065 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9068 g_object_remove_weak_pointer (G_OBJECT (priv->model),
9069 (gpointer *)&priv->model);
9070 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
9072 gtk_icon_view_accessible_clear_cache (priv);
9074 icon_view = GTK_ICON_VIEW (obj);
9075 priv->model = icon_view->priv->model;
9076 /* If there is no model the GtkIconView is probably being destroyed */
9079 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9080 gtk_icon_view_accessible_connect_model_signals (icon_view);
9088 gtk_icon_view_accessible_initialize (AtkObject *accessible,
9091 GtkIconViewAccessiblePrivate *priv;
9092 GtkIconView *icon_view;
9094 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
9095 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
9097 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
9098 g_object_set_qdata (G_OBJECT (accessible),
9099 accessible_private_data_quark,
9102 icon_view = GTK_ICON_VIEW (data);
9103 if (icon_view->priv->hadjustment)
9105 priv->old_hadj = icon_view->priv->hadjustment;
9106 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
9107 g_signal_connect (icon_view->priv->hadjustment,
9109 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9112 if (icon_view->priv->vadjustment)
9114 priv->old_vadj = icon_view->priv->vadjustment;
9115 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
9116 g_signal_connect (icon_view->priv->vadjustment,
9118 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
9121 g_signal_connect_after (data,
9122 "set_scroll_adjustments",
9123 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
9125 g_signal_connect (data,
9127 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
9130 priv->model = icon_view->priv->model;
9133 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
9134 gtk_icon_view_accessible_connect_model_signals (icon_view);
9137 accessible->role = ATK_ROLE_LAYERED_PANE;
9141 gtk_icon_view_accessible_finalize (GObject *object)
9143 GtkIconViewAccessiblePrivate *priv;
9145 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
9146 gtk_icon_view_accessible_clear_cache (priv);
9150 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
9154 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
9155 GtkAccessible *accessible)
9158 GtkIconViewAccessiblePrivate *priv;
9160 atk_obj = ATK_OBJECT (accessible);
9161 priv = gtk_icon_view_accessible_get_priv (atk_obj);
9164 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
9165 (gpointer *)&priv->old_hadj);
9167 g_signal_handlers_disconnect_by_func (priv->old_hadj,
9168 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9170 priv->old_hadj = NULL;
9174 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
9175 (gpointer *)&priv->old_vadj);
9177 g_signal_handlers_disconnect_by_func (priv->old_vadj,
9178 (gpointer) gtk_icon_view_accessible_adjustment_changed,
9180 priv->old_vadj = NULL;
9185 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
9187 if (accessible->widget)
9189 g_signal_connect_after (accessible->widget,
9191 G_CALLBACK (gtk_icon_view_accessible_destroyed),
9194 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
9198 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
9200 GObjectClass *gobject_class;
9201 GtkAccessibleClass *accessible_class;
9203 accessible_parent_class = g_type_class_peek_parent (klass);
9205 gobject_class = (GObjectClass *)klass;
9206 accessible_class = (GtkAccessibleClass *)klass;
9208 gobject_class->finalize = gtk_icon_view_accessible_finalize;
9210 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
9211 klass->ref_child = gtk_icon_view_accessible_ref_child;
9212 klass->initialize = gtk_icon_view_accessible_initialize;
9214 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
9216 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
9220 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
9223 AtkCoordType coord_type)
9226 GtkIconView *icon_view;
9227 GtkIconViewItem *item;
9230 widget = GTK_ACCESSIBLE (component)->widget;
9232 /* State is defunct */
9235 icon_view = GTK_ICON_VIEW (widget);
9236 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
9237 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
9239 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
9245 atk_component_interface_init (AtkComponentIface *iface)
9247 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
9251 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
9255 GtkIconView *icon_view;
9256 GtkIconViewItem *item;
9258 widget = GTK_ACCESSIBLE (selection)->widget;
9262 icon_view = GTK_ICON_VIEW (widget);
9264 item = g_list_nth_data (icon_view->priv->items, i);
9269 gtk_icon_view_select_item (icon_view, item);
9275 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
9278 GtkIconView *icon_view;
9280 widget = GTK_ACCESSIBLE (selection)->widget;
9284 icon_view = GTK_ICON_VIEW (widget);
9285 gtk_icon_view_unselect_all (icon_view);
9291 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
9296 GtkIconView *icon_view;
9297 GtkIconViewItem *item;
9299 widget = GTK_ACCESSIBLE (selection)->widget;
9303 icon_view = GTK_ICON_VIEW (widget);
9305 l = icon_view->priv->items;
9312 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
9323 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
9326 GtkIconView *icon_view;
9327 GtkIconViewItem *item;
9331 widget = GTK_ACCESSIBLE (selection)->widget;
9335 icon_view = GTK_ICON_VIEW (widget);
9337 l = icon_view->priv->items;
9353 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9357 GtkIconView *icon_view;
9358 GtkIconViewItem *item;
9360 widget = GTK_ACCESSIBLE (selection)->widget;
9364 icon_view = GTK_ICON_VIEW (widget);
9366 item = g_list_nth_data (icon_view->priv->items, i);
9370 return item->selected;
9374 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9378 GtkIconView *icon_view;
9379 GtkIconViewItem *item;
9383 widget = GTK_ACCESSIBLE (selection)->widget;
9387 icon_view = GTK_ICON_VIEW (widget);
9388 l = icon_view->priv->items;
9397 gtk_icon_view_unselect_item (icon_view, item);
9409 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9412 GtkIconView *icon_view;
9414 widget = GTK_ACCESSIBLE (selection)->widget;
9418 icon_view = GTK_ICON_VIEW (widget);
9419 gtk_icon_view_select_all (icon_view);
9424 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9426 iface->add_selection = gtk_icon_view_accessible_add_selection;
9427 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9428 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9429 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9430 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9431 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9432 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9436 gtk_icon_view_accessible_get_type (void)
9438 static GType type = 0;
9442 static GTypeInfo tinfo =
9445 (GBaseInitFunc) NULL, /* base init */
9446 (GBaseFinalizeFunc) NULL, /* base finalize */
9447 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9448 (GClassFinalizeFunc) NULL, /* class finalize */
9449 NULL, /* class data */
9450 0, /* instance size */
9451 0, /* nb preallocs */
9452 (GInstanceInitFunc) NULL, /* instance init */
9453 NULL /* value table */
9455 static const GInterfaceInfo atk_component_info =
9457 (GInterfaceInitFunc) atk_component_interface_init,
9458 (GInterfaceFinalizeFunc) NULL,
9461 static const GInterfaceInfo atk_selection_info =
9463 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9464 (GInterfaceFinalizeFunc) NULL,
9469 * Figure out the size of the class and instance
9470 * we are deriving from
9472 AtkObjectFactory *factory;
9475 GType derived_atk_type;
9477 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9478 factory = atk_registry_get_factory (atk_get_default_registry (),
9480 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9481 g_type_query (derived_atk_type, &query);
9482 tinfo.class_size = query.class_size;
9483 tinfo.instance_size = query.instance_size;
9485 type = g_type_register_static (derived_atk_type,
9486 I_("GtkIconViewAccessible"),
9488 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9489 &atk_component_info);
9490 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9491 &atk_selection_info);
9497 gtk_icon_view_accessible_new (GObject *obj)
9499 AtkObject *accessible;
9501 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9503 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9504 atk_object_initialize (accessible, obj);
9510 gtk_icon_view_accessible_factory_get_accessible_type (void)
9512 return gtk_icon_view_accessible_get_type ();
9516 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9518 return gtk_icon_view_accessible_new (obj);
9522 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9524 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9525 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9529 gtk_icon_view_accessible_factory_get_type (void)
9531 static GType type = 0;
9535 const GTypeInfo tinfo =
9537 sizeof (AtkObjectFactoryClass),
9538 NULL, /* base_init */
9539 NULL, /* base_finalize */
9540 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9541 NULL, /* class_finalize */
9542 NULL, /* class_data */
9543 sizeof (AtkObjectFactory),
9544 0, /* n_preallocs */
9548 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9549 I_("GtkIconViewAccessibleFactory"),
9557 gtk_icon_view_get_accessible (GtkWidget *widget)
9559 static gboolean first_time = TRUE;
9563 AtkObjectFactory *factory;
9564 AtkRegistry *registry;
9566 GType derived_atk_type;
9569 * Figure out whether accessibility is enabled by looking at the
9570 * type of the accessible object which would be created for
9571 * the parent type of GtkIconView.
9573 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9575 registry = atk_get_default_registry ();
9576 factory = atk_registry_get_factory (registry,
9578 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9579 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9580 atk_registry_set_factory_type (registry,
9582 gtk_icon_view_accessible_factory_get_type ());
9585 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9589 gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
9590 GtkBuilder *builder,
9592 const gchar *tagname,
9593 GMarkupParser *parser,
9596 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
9597 tagname, parser, data))
9600 return _gtk_cell_layout_buildable_custom_tag_start (buildable, builder, child,
9601 tagname, parser, data);
9605 gtk_icon_view_buildable_custom_tag_end (GtkBuildable *buildable,
9606 GtkBuilder *builder,
9608 const gchar *tagname,
9611 if (strcmp (tagname, "attributes") == 0)
9612 _gtk_cell_layout_buildable_custom_tag_end (buildable, builder, child, tagname,
9615 parent_buildable_iface->custom_tag_end (buildable, builder, child, tagname,
9621 #define __GTK_ICON_VIEW_C__
9622 #include "gtkaliasdef.c"